1 // Copyright (C) 2007 Mark Pustjens <pustjens@dds.nl>
2 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
4 // This file is part of CenterIM.
6 // CenterIM is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // CenterIM is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with CenterIM. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef CONVERSATIONS_H
20 #define CONVERSATIONS_H
22 #include "Conversation.h"
24 #include <cppconsui/HorizontalListBox.h>
25 #include <cppconsui/Label.h>
26 #include <cppconsui/Spacer.h>
27 #include <cppconsui/Window.h>
28 #include <libpurple/purple.h>
31 #define CONVERSATIONS (Conversations::instance())
33 class Conversations
: public CppConsUI::Window
{
35 static Conversations
*instance();
38 virtual void onScreenResized() override
;
40 void focusActiveConversation();
41 void focusConversation(int i
);
42 void focusPrevConversation();
43 void focusNextConversation();
45 void setExpandedConversations(bool expanded
);
47 bool getSendTypingPref() const { return send_typing_
; }
52 CppConsUI::Label
*label
;
56 typedef std::vector
<ConvChild
> ConversationsVector
;
58 ConversationsVector conversations_
;
60 // Active conversation, -1 if none.
63 CppConsUI::HorizontalListBox
*outer_list_
;
64 CppConsUI::Spacer
*left_spacer_
;
65 CppConsUI::Spacer
*right_spacer_
;
66 CppConsUI::HorizontalListBox
*conv_list_
;
68 // Cached value of the "/purple/conversations/im/send_typing" preference.
71 PurpleConversationUiOps centerim_conv_ui_ops_
;
73 static Conversations
*my_instance_
;
76 virtual ~Conversations() override
;
77 CONSUI_DISABLE_COPY(Conversations
);
80 static void finalize();
81 friend class CenterIM
;
83 // Find PurpleConversation in conversations.
84 int findConversation(PurpleConversation
*conv
);
86 int prevActiveConversation(int current
);
87 int nextActiveConversation(int current
);
89 void activateConversation(int i
);
91 // Update a single conversation label.
92 void updateLabel(int i
);
93 // Update all conversation labels.
96 static void create_conversation_(PurpleConversation
*conv
)
98 CONVERSATIONS
->create_conversation(conv
);
100 static void destroy_conversation_(PurpleConversation
*conv
)
102 CONVERSATIONS
->destroy_conversation(conv
);
104 static void write_conv_(PurpleConversation
*conv
, const char *name
,
105 const char *alias
, const char *message
, PurpleMessageFlags flags
,
108 CONVERSATIONS
->write_conv(conv
, name
, alias
, message
, flags
, mtime
);
110 static void chat_add_users_(
111 PurpleConversation
*conv
, GList
*cbuddies
, gboolean new_arrivals
)
113 CONVERSATIONS
->chat_add_users(conv
, cbuddies
, new_arrivals
);
115 static void chat_rename_user_(PurpleConversation
*conv
, const char *old_name
,
116 const char *new_name
, const char *new_alias
)
118 CONVERSATIONS
->chat_rename_user(conv
, old_name
, new_name
, new_alias
);
120 static void chat_remove_users_(PurpleConversation
*conv
, GList
*users
)
122 CONVERSATIONS
->chat_remove_users(conv
, users
);
124 static void chat_update_user_(PurpleConversation
*conv
, const char *user
)
126 CONVERSATIONS
->chat_update_user(conv
, user
);
128 static void present_(PurpleConversation
*conv
)
130 CONVERSATIONS
->present(conv
);
133 // Internal utility to get a room list for a conversation. Returns nullptr if
135 ConversationRoomList
*getRoomList(PurpleConversation
*conv
);
137 void create_conversation(PurpleConversation
*conv
);
138 void destroy_conversation(PurpleConversation
*conv
);
139 void write_conv(PurpleConversation
*conv
, const char *name
, const char *alias
,
140 const char *message
, PurpleMessageFlags flags
, time_t mtime
);
142 PurpleConversation
*conv
, GList
*cbuddies
, gboolean new_arrivals
);
143 void chat_rename_user(PurpleConversation
*conv
, const char *old_name
,
144 const char *new_name
, const char *new_alias
);
145 void chat_remove_users(PurpleConversation
*conv
, GList
*users
);
146 void chat_update_user(PurpleConversation
*conv
, const char *user
);
147 void present(PurpleConversation
*conv
);
149 static void buddy_typing_(
150 PurpleAccount
*account
, const char *who
, gpointer data
)
152 reinterpret_cast<Conversations
*>(data
)->buddy_typing(account
, who
);
154 void buddy_typing(PurpleAccount
*account
, const char *who
);
156 static void account_signed_on_(PurpleConnection
*gc
, gpointer data
)
158 reinterpret_cast<Conversations
*>(data
)->account_signed_on(gc
);
160 void account_signed_on(PurpleConnection
*gc
);
162 // Called when "/purple/conversations/im/send_typing" preference changes.
163 static void send_typing_pref_change_(
164 const char *name
, PurplePrefType type
, gconstpointer val
, gpointer data
)
166 reinterpret_cast<Conversations
*>(data
)->send_typing_pref_change(
169 void send_typing_pref_change(
170 const char *name
, PurplePrefType type
, gconstpointer val
);
173 #endif // CONVERSATIONS_H
175 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: