Use correct package prefix for local macros in configure.ac
[centerim5.git] / src / BuddyList.h
blob26076fb5d70a192bb129e78bed6f07b17cb2b896
1 // Copyright (C) 2007 Mark Pustjens <pustjens@dds.nl>
2 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
3 //
4 // This file is part of CenterIM.
5 //
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 BUDDYLIST_H
20 #define BUDDYLIST_H
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 {
34 public:
35 enum ListMode {
36 LIST_NORMAL,
37 LIST_FLAT,
40 enum GroupSortMode {
41 GROUP_SORT_BY_USER,
42 GROUP_SORT_BY_NAME,
45 enum BuddySortMode {
46 BUDDY_SORT_BY_NAME,
47 BUDDY_SORT_BY_STATUS,
48 BUDDY_SORT_BY_ACTIVITY,
51 enum ColorizationMode {
52 COLOR_NONE,
53 COLOR_BY_STATUS,
54 COLOR_BY_ACCOUNT,
57 static BuddyList *instance();
59 // InputProcessor
60 virtual bool processInputText(const TermKeyKey &key) override;
62 // Widget
63 virtual bool restoreFocus() override;
64 virtual void ungrabFocus() override;
66 // FreeWindow
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);
82 private:
83 enum UpdateFlags {
84 UPDATE_GROUPS = 1 << 0,
85 UPDATE_OTHERS = 1 << 1,
88 class Filter : public CppConsUI::Widget {
89 public:
90 Filter(BuddyList *parent_blist);
91 virtual ~Filter() override {}
93 // Widget
94 virtual int draw(
95 CppConsUI::Curses::ViewPort area, CppConsUI::Error &error) override;
97 protected:
98 BuddyList *parent_blist_;
100 private:
101 CONSUI_DISABLE_COPY(Filter);
104 class AddWindow : public CppConsUI::SplitDialog {
105 public:
106 AddWindow(const char *title);
107 virtual ~AddWindow() override {}
109 // FreeWindow
110 virtual void onScreenResized() override;
112 protected:
113 class AccountOption : public CppConsUI::ComboBox {
114 public:
115 explicit AccountOption(
116 PurpleAccount *default_account = nullptr, bool chat_only = false);
117 virtual ~AccountOption() override {}
119 private:
120 CONSUI_DISABLE_COPY(AccountOption);
123 class GroupOption : public CppConsUI::ComboBox {
124 public:
125 explicit GroupOption(const char *default_group);
126 explicit GroupOption(PurpleGroup *default_group);
127 virtual ~GroupOption() override {}
129 private:
130 CONSUI_DISABLE_COPY(GroupOption);
133 class StringOption : public CppConsUI::Button {
134 public:
135 explicit StringOption(
136 const char *text, const char *value = nullptr, bool masked = false);
137 virtual ~StringOption() override {}
139 protected:
140 void onActivate(CppConsUI::Button &activator);
141 void responseHandler(CppConsUI::InputDialog &activator,
142 CppConsUI::AbstractDialog::ResponseType response);
144 private:
145 CONSUI_DISABLE_COPY(StringOption);
148 class IntegerOption : public CppConsUI::Button {
149 public:
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 {}
154 protected:
155 int min_value_;
156 int max_value_;
158 void onActivate(CppConsUI::Button &activator);
159 void responseHandler(CppConsUI::InputDialog &activator,
160 CppConsUI::AbstractDialog::ResponseType response);
162 private:
163 CONSUI_DISABLE_COPY(IntegerOption);
166 class BooleanOption : public CppConsUI::CheckBox {
167 public:
168 explicit BooleanOption(const char *text, bool checked = true);
169 virtual ~BooleanOption() override {}
171 private:
172 CONSUI_DISABLE_COPY(BooleanOption);
175 CppConsUI::TreeView *treeview_;
177 virtual void onAddRequest(CppConsUI::Button &activator) = 0;
179 private:
180 CONSUI_DISABLE_COPY(AddWindow);
183 class AddBuddyWindow : public AddWindow {
184 public:
185 AddBuddyWindow(PurpleAccount *account, const char *username,
186 const char *group, const char *alias);
187 virtual ~AddBuddyWindow() override {}
189 protected:
190 AccountOption *account_option_;
191 StringOption *name_option_;
192 StringOption *alias_option_;
193 GroupOption *group_option_;
195 // AddWindow
196 virtual void onAddRequest(CppConsUI::Button &activator) override;
198 private:
199 CONSUI_DISABLE_COPY(AddBuddyWindow);
202 class AddChatWindow : public AddWindow {
203 public:
204 AddChatWindow(PurpleAccount *account, const char *name, const char *alias,
205 const char *group);
206 virtual ~AddChatWindow() override {}
208 protected:
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_;
218 // AddWindow
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);
225 private:
226 CONSUI_DISABLE_COPY(AddChatWindow);
229 class AddGroupWindow : public AddWindow {
230 public:
231 AddGroupWindow();
232 virtual ~AddGroupWindow() override {}
234 protected:
235 StringOption *name_option_;
237 // AddWindow
238 virtual void onAddRequest(CppConsUI::Button &activator) override;
240 private:
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_;
250 ListMode list_mode_;
251 BuddySortMode buddy_sort_mode_;
252 GroupSortMode group_sort_mode_;
253 ColorizationMode colorization_mode_;
255 Filter *filter_;
256 char filter_buffer_[256];
257 // Length in bytes.
258 std::size_t filter_buffer_length_;
259 // Onscreen width.
260 std::size_t filter_buffer_onscreen_width_;
262 static BuddyList *my_instance_;
264 BuddyList();
265 virtual ~BuddyList();
266 CONSUI_DISABLE_COPY(BuddyList);
268 static void init();
269 static void finalize();
270 friend class CenterIM;
272 void load();
273 void rebuildList();
274 void updateList(int flags);
275 void delayedGroupNodesInit();
276 void updateCachedPreference(const char *name);
277 bool isAnyAccountConnected();
278 void filterHide();
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: