Avoid use of curses subpads
[centerim5.git] / src / BuddyList.h
blobb3cbe5075b1ffa54c3008111cfff312dbb3bbd70
1 /*
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())
36 class BuddyList
37 : public CppConsUI::Window
39 public:
40 enum ListMode {
41 LIST_NORMAL,
42 LIST_FLAT
45 enum GroupSortMode {
46 GROUP_SORT_BY_USER,
47 GROUP_SORT_BY_NAME
50 enum BuddySortMode {
51 BUDDY_SORT_BY_NAME,
52 BUDDY_SORT_BY_STATUS,
53 BUDDY_SORT_BY_ACTIVITY
56 enum ColorizationMode {
57 COLOR_NONE,
58 COLOR_BY_STATUS,
59 COLOR_BY_ACCOUNT
62 static BuddyList *instance();
64 // InputProcessor
65 virtual bool processInputText(const TermKeyKey &key);
67 // Widget
68 virtual bool restoreFocus();
69 virtual void ungrabFocus();
71 // FreeWindow
72 virtual void close();
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);
87 protected:
89 private:
90 enum UpdateFlags {
91 UPDATE_GROUPS = 1 << 0,
92 UPDATE_OTHERS = 1 << 1
95 class Filter
96 : public CppConsUI::Widget
98 public:
99 Filter(BuddyList *parent_);
100 virtual ~Filter() {}
102 // Widget
103 virtual void draw(CppConsUI::Curses::ViewPort area);
105 protected:
106 BuddyList *parent;
108 private:
109 CONSUI_DISABLE_COPY(Filter);
112 class AddWindow
113 : public CppConsUI::SplitDialog
115 public:
116 AddWindow(const char *title);
117 virtual ~AddWindow() {}
119 // FreeWindow
120 virtual void onScreenResized();
122 protected:
123 class AccountOption
124 : public CppConsUI::ComboBox
126 public:
127 explicit AccountOption(PurpleAccount *default_account = NULL,
128 bool chat_only = false);
129 virtual ~AccountOption() {}
131 protected:
133 private:
134 CONSUI_DISABLE_COPY(AccountOption);
137 class GroupOption
138 : public CppConsUI::ComboBox
140 public:
141 explicit GroupOption(const char *default_group);
142 explicit GroupOption(PurpleGroup *default_group);
143 virtual ~GroupOption() {}
145 protected:
147 private:
148 CONSUI_DISABLE_COPY(GroupOption);
151 class StringOption
152 : public CppConsUI::Button
154 public:
155 explicit StringOption(const char *text, const char *value = NULL,
156 bool masked = false);
157 virtual ~StringOption() {}
159 protected:
160 void onActivate(CppConsUI::Button& activator);
161 void responseHandler(CppConsUI::InputDialog& activator,
162 CppConsUI::AbstractDialog::ResponseType response);
164 private:
165 CONSUI_DISABLE_COPY(StringOption);
168 class IntegerOption
169 : public CppConsUI::Button
171 public:
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() {}
176 protected:
177 int min_value;
178 int max_value;
180 void onActivate(CppConsUI::Button& activator);
181 void responseHandler(CppConsUI::InputDialog& activator,
182 CppConsUI::AbstractDialog::ResponseType response);
184 private:
185 CONSUI_DISABLE_COPY(IntegerOption);
188 class BooleanOption
189 : public CppConsUI::CheckBox
191 public:
192 explicit BooleanOption(const char *text, bool checked = true);
193 virtual ~BooleanOption() {}
195 protected:
197 private:
198 CONSUI_DISABLE_COPY(BooleanOption);
201 CppConsUI::TreeView *treeview;
203 virtual void onAddRequest(CppConsUI::Button& activator) = 0;
205 private:
206 CONSUI_DISABLE_COPY(AddWindow);
209 class AddBuddyWindow
210 : public AddWindow
212 public:
213 AddBuddyWindow(PurpleAccount *account, const char *username,
214 const char *group, const char *alias);
215 virtual ~AddBuddyWindow() {}
217 protected:
218 AccountOption *account_option;
219 StringOption *name_option;
220 StringOption *alias_option;
221 GroupOption *group_option;
223 // AddWindow
224 virtual void onAddRequest(CppConsUI::Button& activator);
226 private:
227 CONSUI_DISABLE_COPY(AddBuddyWindow);
230 class AddChatWindow
231 : public AddWindow
233 public:
234 AddChatWindow(PurpleAccount *account, const char *name, const char *alias,
235 const char *group);
236 virtual ~AddChatWindow() {}
238 protected:
239 typedef std::map<std::string, CppConsUI::TreeView::NodeReference>
240 ChatInfoMap;
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;
249 // AddWindow
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);
256 private:
257 CONSUI_DISABLE_COPY(AddChatWindow);
260 class AddGroupWindow
261 : public AddWindow
263 public:
264 AddGroupWindow();
265 virtual ~AddGroupWindow() {}
267 protected:
268 StringOption *name_option;
270 // AddWindow
271 virtual void onAddRequest(CppConsUI::Button& activator);
273 private:
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;
283 ListMode list_mode;
284 BuddySortMode buddy_sort_mode;
285 GroupSortMode group_sort_mode;
286 ColorizationMode colorization_mode;
288 Filter *filter;
289 char filter_buffer[256];
290 // length in bytes
291 size_t filter_buffer_length;
292 // onscreen width
293 size_t filter_buffer_onscreen_width;
295 static BuddyList *my_instance;
297 BuddyList();
298 virtual ~BuddyList();
299 CONSUI_DISABLE_COPY(BuddyList);
301 static void init();
302 static void finalize();
303 friend class CenterIM;
305 void load();
306 void rebuildList();
307 void updateList(int flags);
308 void delayedGroupNodesInit();
309 void updateCachedPreference(const char *name);
310 bool isAnyAccountConnected();
311 void filterHide();
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,
350 val); }
351 void blist_pref_change(const char *name, PurplePrefType type,
352 gconstpointer val);
355 #endif // __BUDDYLIST_H__
357 /* vim: set tabstop=2 shiftwidth=2 textwidth=78 expandtab : */