2 * Copyright (C) 2007 by Mark Pustjens <pustjens@dds.nl>
3 * Copyright (C) 2010-2013 by CenterIM developers
5 * This file is part of CenterIM.
7 * CenterIM is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * CenterIM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef __BUDDYLIST_H__
23 #define __BUDDYLIST_H__
25 #include "BuddyListNode.h"
27 #include <cppconsui/Button.h>
28 #include <cppconsui/CheckBox.h>
29 #include <cppconsui/ComboBox.h>
30 #include <cppconsui/TreeView.h>
31 #include <cppconsui/SplitDialog.h>
32 #include <cppconsui/Window.h>
34 #define BUDDYLIST (BuddyList::instance())
37 : public CppConsUI::Window
53 BUDDY_SORT_BY_ACTIVITY
56 enum ColorizationMode
{
62 static BuddyList
*instance();
65 virtual bool processInputText(const TermKeyKey
&key
);
68 virtual bool restoreFocus();
69 virtual void ungrabFocus();
73 virtual void onScreenResized();
75 // these functions are faster version of getting blist/* prefs
76 bool getShowEmptyGroupsPref() const { return show_empty_groups
; }
77 bool getShowOfflineBuddiesPref() const { return show_offline_buddies
; }
78 ListMode
getListMode() const { return list_mode
; }
79 GroupSortMode
getGroupSortMode() const { return group_sort_mode
; }
80 BuddySortMode
getBuddySortMode() const { return buddy_sort_mode
; }
81 ColorizationMode
getColorizationMode() const { return colorization_mode
; }
83 const char *getFilterString() const { return filter_buffer
; }
85 void updateNode(PurpleBlistNode
*node
);
91 UPDATE_GROUPS
= 1 << 0,
92 UPDATE_OTHERS
= 1 << 1
96 : public CppConsUI::Widget
99 Filter(BuddyList
*parent_
);
103 virtual void draw(CppConsUI::Curses::ViewPort area
);
109 CONSUI_DISABLE_COPY(Filter
);
113 : public CppConsUI::SplitDialog
116 AddWindow(const char *title
);
117 virtual ~AddWindow() {}
120 virtual void onScreenResized();
124 : public CppConsUI::ComboBox
127 explicit AccountOption(PurpleAccount
*default_account
= NULL
,
128 bool chat_only
= false);
129 virtual ~AccountOption() {}
134 CONSUI_DISABLE_COPY(AccountOption
);
138 : public CppConsUI::ComboBox
141 explicit GroupOption(const char *default_group
);
142 explicit GroupOption(PurpleGroup
*default_group
);
143 virtual ~GroupOption() {}
148 CONSUI_DISABLE_COPY(GroupOption
);
152 : public CppConsUI::Button
155 explicit StringOption(const char *text
, const char *value
= NULL
,
156 bool masked
= false);
157 virtual ~StringOption() {}
160 void onActivate(CppConsUI::Button
& activator
);
161 void responseHandler(CppConsUI::InputDialog
& activator
,
162 CppConsUI::AbstractDialog::ResponseType response
);
165 CONSUI_DISABLE_COPY(StringOption
);
169 : public CppConsUI::Button
172 explicit IntegerOption(const char *text
, const char *value
= NULL
,
173 bool masked
= false, int min
= INT_MIN
, int max
= INT_MAX
);
174 virtual ~IntegerOption() {}
180 void onActivate(CppConsUI::Button
& activator
);
181 void responseHandler(CppConsUI::InputDialog
& activator
,
182 CppConsUI::AbstractDialog::ResponseType response
);
185 CONSUI_DISABLE_COPY(IntegerOption
);
189 : public CppConsUI::CheckBox
192 explicit BooleanOption(const char *text
, bool checked
= true);
193 virtual ~BooleanOption() {}
198 CONSUI_DISABLE_COPY(BooleanOption
);
201 CppConsUI::TreeView
*treeview
;
203 virtual void onAddRequest(CppConsUI::Button
& activator
) = 0;
206 CONSUI_DISABLE_COPY(AddWindow
);
213 AddBuddyWindow(PurpleAccount
*account
, const char *username
,
214 const char *group
, const char *alias
);
215 virtual ~AddBuddyWindow() {}
218 AccountOption
*account_option
;
219 StringOption
*name_option
;
220 StringOption
*alias_option
;
221 GroupOption
*group_option
;
224 virtual void onAddRequest(CppConsUI::Button
& activator
);
227 CONSUI_DISABLE_COPY(AddBuddyWindow
);
234 AddChatWindow(PurpleAccount
*account
, const char *name
, const char *alias
,
236 virtual ~AddChatWindow() {}
239 typedef std::map
<std::string
, CppConsUI::TreeView::NodeReference
>
242 AccountOption
*account_option
;
243 CppConsUI::TreeView::NodeReference account_option_ref
;
244 StringOption
*alias_option
;
245 GroupOption
*group_option
;
246 BooleanOption
*autojoin_option
;
247 ChatInfoMap chat_info_map
;
250 virtual void onAddRequest(CppConsUI::Button
& activator
);
252 void populateChatInfo(PurpleAccount
*account
);
253 void onAccountChanged(CppConsUI::Button
& activator
, size_t new_entry
,
254 const char *title
, intptr_t data
);
257 CONSUI_DISABLE_COPY(AddChatWindow
);
265 virtual ~AddGroupWindow() {}
268 StringOption
*name_option
;
271 virtual void onAddRequest(CppConsUI::Button
& activator
);
274 CONSUI_DISABLE_COPY(AddGroupWindow
);
277 PurpleBlistUiOps centerim_blist_ui_ops
;
278 PurpleBuddyList
*buddylist
;
279 CppConsUI::TreeView
*treeview
;
281 bool show_empty_groups
;
282 bool show_offline_buddies
;
284 BuddySortMode buddy_sort_mode
;
285 GroupSortMode group_sort_mode
;
286 ColorizationMode colorization_mode
;
289 char filter_buffer
[256];
291 size_t filter_buffer_length
;
293 size_t filter_buffer_onscreen_width
;
295 static BuddyList
*my_instance
;
298 virtual ~BuddyList();
299 CONSUI_DISABLE_COPY(BuddyList
);
302 static void finalize();
303 friend class CenterIM
;
307 void updateList(int flags
);
308 void delayedGroupNodesInit();
309 void updateCachedPreference(const char *name
);
310 bool isAnyAccountConnected();
312 void actionOpenFilter();
313 void actionDeleteChar();
314 void declareBindables();
316 static void new_list_(PurpleBuddyList
*list
)
317 { BUDDYLIST
->new_list(list
); }
318 static void new_node_(PurpleBlistNode
*node
)
319 { BUDDYLIST
->new_node(node
); }
320 static void update_(PurpleBuddyList
*list
, PurpleBlistNode
*node
)
321 { BUDDYLIST
->update(list
, node
); }
322 static void remove_(PurpleBuddyList
*list
, PurpleBlistNode
*node
)
323 { BUDDYLIST
->remove(list
, node
); }
324 static void destroy_(PurpleBuddyList
*list
)
325 { BUDDYLIST
->destroy(list
); }
326 static void request_add_buddy_(PurpleAccount
*account
,
327 const char *username
, const char *group
, const char *alias
)
328 { BUDDYLIST
->request_add_buddy(account
, username
, group
, alias
); }
329 static void request_add_chat_(PurpleAccount
*account
,
330 PurpleGroup
*group
, const char *alias
, const char *name
)
331 { BUDDYLIST
->request_add_chat(account
, group
, alias
, name
); }
332 static void request_add_group_()
333 { BUDDYLIST
->request_add_group(); }
335 void new_list(PurpleBuddyList
*list
);
336 void new_node(PurpleBlistNode
*node
);
337 void update(PurpleBuddyList
*list
, PurpleBlistNode
*node
);
338 void remove(PurpleBuddyList
*list
, PurpleBlistNode
*node
);
339 void destroy(PurpleBuddyList
*list
);
340 void request_add_buddy(PurpleAccount
*account
, const char *username
,
341 const char *group
, const char *alias
);
342 void request_add_chat(PurpleAccount
*account
, PurpleGroup
*group
,
343 const char *alias
, const char *name
);
344 void request_add_group();
346 // called when any blist/* pref is changed
347 static void blist_pref_change_(const char *name
, PurplePrefType type
,
348 gconstpointer val
, gpointer data
)
349 { reinterpret_cast<BuddyList
*>(data
)->blist_pref_change(name
, type
,
351 void blist_pref_change(const char *name
, PurplePrefType type
,
355 #endif // __BUDDYLIST_H__
357 /* vim: set tabstop=2 shiftwidth=2 textwidth=78 expandtab : */