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/>.
22 #include "BuddyListNode.h"
24 #include <cppconsui/Button.h>
25 #include <cppconsui/CheckBox.h>
26 #include <cppconsui/ComboBox.h>
27 #include <cppconsui/SplitDialog.h>
28 #include <cppconsui/TreeView.h>
29 #include <cppconsui/Window.h>
31 #define BUDDYLIST (BuddyList::instance())
33 class BuddyList
: public CppConsUI::Window
{
48 BUDDY_SORT_BY_ACTIVITY
,
51 enum ColorizationMode
{
57 static BuddyList
*instance();
60 virtual bool processInputText(const TermKeyKey
&key
) override
;
63 virtual bool restoreFocus() override
;
64 virtual void ungrabFocus() override
;
67 virtual void close() override
;
68 virtual void onScreenResized() override
;
70 // These functions are faster version of getting blist/* prefs.
71 bool getShowEmptyGroupsPref() const { return show_empty_groups_
; }
72 bool getShowOfflineBuddiesPref() const { return show_offline_buddies_
; }
73 ListMode
getListMode() const { return list_mode_
; }
74 GroupSortMode
getGroupSortMode() const { return group_sort_mode_
; }
75 BuddySortMode
getBuddySortMode() const { return buddy_sort_mode_
; }
76 ColorizationMode
getColorizationMode() const { return colorization_mode_
; }
78 const char *getFilterString() const { return filter_buffer_
; }
80 void updateNode(PurpleBlistNode
*node
);
84 UPDATE_GROUPS
= 1 << 0,
85 UPDATE_OTHERS
= 1 << 1,
88 class Filter
: public CppConsUI::Widget
{
90 Filter(BuddyList
*parent_blist
);
91 virtual ~Filter() override
{}
95 CppConsUI::Curses::ViewPort area
, CppConsUI::Error
&error
) override
;
98 BuddyList
*parent_blist_
;
101 CONSUI_DISABLE_COPY(Filter
);
104 class AddWindow
: public CppConsUI::SplitDialog
{
106 AddWindow(const char *title
);
107 virtual ~AddWindow() override
{}
110 virtual void onScreenResized() override
;
113 class AccountOption
: public CppConsUI::ComboBox
{
115 explicit AccountOption(
116 PurpleAccount
*default_account
= nullptr, bool chat_only
= false);
117 virtual ~AccountOption() override
{}
120 CONSUI_DISABLE_COPY(AccountOption
);
123 class GroupOption
: public CppConsUI::ComboBox
{
125 explicit GroupOption(const char *default_group
);
126 explicit GroupOption(PurpleGroup
*default_group
);
127 virtual ~GroupOption() override
{}
130 CONSUI_DISABLE_COPY(GroupOption
);
133 class StringOption
: public CppConsUI::Button
{
135 explicit StringOption(
136 const char *text
, const char *value
= nullptr, bool masked
= false);
137 virtual ~StringOption() override
{}
140 void onActivate(CppConsUI::Button
&activator
);
141 void responseHandler(CppConsUI::InputDialog
&activator
,
142 CppConsUI::AbstractDialog::ResponseType response
);
145 CONSUI_DISABLE_COPY(StringOption
);
148 class IntegerOption
: public CppConsUI::Button
{
150 explicit IntegerOption(const char *text
, const char *value
= nullptr,
151 bool masked
= false, int min
= INT_MIN
, int max
= INT_MAX
);
152 virtual ~IntegerOption() override
{}
158 void onActivate(CppConsUI::Button
&activator
);
159 void responseHandler(CppConsUI::InputDialog
&activator
,
160 CppConsUI::AbstractDialog::ResponseType response
);
163 CONSUI_DISABLE_COPY(IntegerOption
);
166 class BooleanOption
: public CppConsUI::CheckBox
{
168 explicit BooleanOption(const char *text
, bool checked
= true);
169 virtual ~BooleanOption() override
{}
172 CONSUI_DISABLE_COPY(BooleanOption
);
175 CppConsUI::TreeView
*treeview_
;
177 virtual void onAddRequest(CppConsUI::Button
&activator
) = 0;
180 CONSUI_DISABLE_COPY(AddWindow
);
183 class AddBuddyWindow
: public AddWindow
{
185 AddBuddyWindow(PurpleAccount
*account
, const char *username
,
186 const char *group
, const char *alias
);
187 virtual ~AddBuddyWindow() override
{}
190 AccountOption
*account_option_
;
191 StringOption
*name_option_
;
192 StringOption
*alias_option_
;
193 GroupOption
*group_option_
;
196 virtual void onAddRequest(CppConsUI::Button
&activator
) override
;
199 CONSUI_DISABLE_COPY(AddBuddyWindow
);
202 class AddChatWindow
: public AddWindow
{
204 AddChatWindow(PurpleAccount
*account
, const char *name
, const char *alias
,
206 virtual ~AddChatWindow() override
{}
209 typedef std::map
<std::string
, CppConsUI::TreeView::NodeReference
> ChatInfos
;
211 AccountOption
*account_option_
;
212 CppConsUI::TreeView::NodeReference account_option_ref_
;
213 StringOption
*alias_option_
;
214 GroupOption
*group_option_
;
215 BooleanOption
*autojoin_option_
;
216 ChatInfos chat_infos_
;
219 virtual void onAddRequest(CppConsUI::Button
&activator
) override
;
221 void populateChatInfo(PurpleAccount
*account
);
222 void onAccountChanged(CppConsUI::Button
&activator
, std::size_t new_entry
,
223 const char *title
, intptr_t data
);
226 CONSUI_DISABLE_COPY(AddChatWindow
);
229 class AddGroupWindow
: public AddWindow
{
232 virtual ~AddGroupWindow() override
{}
235 StringOption
*name_option_
;
238 virtual void onAddRequest(CppConsUI::Button
&activator
) override
;
241 CONSUI_DISABLE_COPY(AddGroupWindow
);
244 PurpleBlistUiOps centerim_blist_ui_ops_
;
245 PurpleBuddyList
*buddylist_
;
246 CppConsUI::TreeView
*treeview_
;
248 bool show_empty_groups_
;
249 bool show_offline_buddies_
;
251 BuddySortMode buddy_sort_mode_
;
252 GroupSortMode group_sort_mode_
;
253 ColorizationMode colorization_mode_
;
256 char filter_buffer_
[256];
258 std::size_t filter_buffer_length_
;
260 std::size_t filter_buffer_onscreen_width_
;
262 static BuddyList
*my_instance_
;
265 virtual ~BuddyList();
266 CONSUI_DISABLE_COPY(BuddyList
);
269 static void finalize();
270 friend class CenterIM
;
274 void updateList(int flags
);
275 void delayedGroupNodesInit();
276 void updateCachedPreference(const char *name
);
277 bool isAnyAccountConnected();
279 void actionOpenFilter();
280 void actionDeleteChar();
281 void declareBindables();
283 static void new_list_(PurpleBuddyList
*list
) { BUDDYLIST
->new_list(list
); }
284 static void new_node_(PurpleBlistNode
*node
) { BUDDYLIST
->new_node(node
); }
285 static void update_(PurpleBuddyList
*list
, PurpleBlistNode
*node
)
287 BUDDYLIST
->update(list
, node
);
289 static void remove_(PurpleBuddyList
*list
, PurpleBlistNode
*node
)
291 BUDDYLIST
->remove(list
, node
);
293 static void destroy_(PurpleBuddyList
*list
) { BUDDYLIST
->destroy(list
); }
294 static void request_add_buddy_(PurpleAccount
*account
, const char *username
,
295 const char *group
, const char *alias
)
297 BUDDYLIST
->request_add_buddy(account
, username
, group
, alias
);
299 static void request_add_chat_(PurpleAccount
*account
, PurpleGroup
*group
,
300 const char *alias
, const char *name
)
302 BUDDYLIST
->request_add_chat(account
, group
, alias
, name
);
304 static void request_add_group_() { BUDDYLIST
->request_add_group(); }
306 void new_list(PurpleBuddyList
*list
);
307 void new_node(PurpleBlistNode
*node
);
308 void update(PurpleBuddyList
*list
, PurpleBlistNode
*node
);
309 void remove(PurpleBuddyList
*list
, PurpleBlistNode
*node
);
310 void destroy(PurpleBuddyList
*list
);
311 void request_add_buddy(PurpleAccount
*account
, const char *username
,
312 const char *group
, const char *alias
);
313 void request_add_chat(PurpleAccount
*account
, PurpleGroup
*group
,
314 const char *alias
, const char *name
);
315 void request_add_group();
317 // Called when any blist/* pref is changed.
318 static void blist_pref_change_(
319 const char *name
, PurplePrefType type
, gconstpointer val
, gpointer data
)
321 reinterpret_cast<BuddyList
*>(data
)->blist_pref_change(name
, type
, val
);
323 void blist_pref_change(
324 const char *name
, PurplePrefType type
, gconstpointer val
);
327 #endif // BUDDYLIST_H
329 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: