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 BUDDYLISTNODE_H
20 #define BUDDYLISTNODE_H
22 #include <cppconsui/Button.h>
23 #include <cppconsui/InputDialog.h>
24 #include <cppconsui/MenuWindow.h>
25 #include <cppconsui/MessageDialog.h>
26 #include <cppconsui/TreeView.h>
27 #include <libpurple/purple.h>
29 class BuddyListNode
: public CppConsUI::Button
{
31 static BuddyListNode
*createNode(PurpleBlistNode
*node
);
34 virtual void setParent(CppConsUI::Container
&parent
) override
;
36 virtual bool lessOrEqual(const BuddyListNode
&other
) const = 0;
37 virtual void update();
38 virtual void onActivate(CppConsUI::Button
&activator
) = 0;
40 virtual const char *toString() const = 0;
42 virtual void setRefNode(CppConsUI::TreeView::NodeReference n
);
43 virtual CppConsUI::TreeView::NodeReference
getRefNode() const { return ref_
; }
45 PurpleBlistNode
*getPurpleBlistNode() const { return blist_node_
; }
47 // Sorts in this node.
50 BuddyListNode
*getParentNode() const;
53 class ContextMenu
: public CppConsUI::MenuWindow
{
55 ContextMenu(BuddyListNode
&parent_node
);
56 virtual ~ContextMenu() override
{}
59 BuddyListNode
*parent_node_
;
61 void onMenuAction(Button
&activator
, PurpleCallback callback
, void *data
);
62 void appendMenuAction(MenuWindow
&menu
, PurpleMenuAction
*act
);
63 void appendProtocolMenu(PurpleConnection
*gc
);
64 void appendExtendedMenu();
67 CONSUI_DISABLE_COPY(ContextMenu
);
70 CppConsUI::TreeView
*treeview_
;
71 CppConsUI::TreeView::NodeReference ref_
;
73 PurpleBlistNode
*blist_node_
;
75 // Cached value of purple_blist_node_get_int(blist_node, "last_activity").
78 BuddyListNode(PurpleBlistNode
*node_
);
79 virtual ~BuddyListNode();
81 virtual void openContextMenu() = 0;
83 bool lessOrEqualByType(const BuddyListNode
&other
) const;
84 bool lessOrEqualByBuddySort(PurpleBuddy
*left
, PurpleBuddy
*right
) const;
86 // Called by BuddyListBuddy and BuddyListContact to get presence status char.
87 // Returned value should be used as a prefix of buddy/contact name.
88 const char *getBuddyStatus(PurpleBuddy
*buddy
) const;
90 // Returns weight of buddy status (available > away > offline...). Used for
92 int getBuddyStatusWeight(PurpleBuddy
*buddy
) const;
94 int getColorSchemeByBuddy(int base_scheme
, PurpleBuddy
*buddy
);
96 void updateFilterVisibility(const char *name
);
98 void retrieveUserInfoForName(PurpleConnection
*gc
, const char *name
) const;
101 CONSUI_DISABLE_COPY(BuddyListNode
);
103 void actionOpenContextMenu();
104 void declareBindables();
107 class BuddyListBuddy
: public BuddyListNode
{
108 friend class BuddyListNode
;
112 virtual bool lessOrEqual(const BuddyListNode
&other
) const override
;
113 virtual void update() override
;
114 virtual void onActivate(Button
&activator
) override
;
115 virtual const char *toString() const override
;
117 PurpleBuddy
*getPurpleBuddy() const { return buddy_
; }
118 void retrieveUserInfo();
121 class BuddyContextMenu
: public ContextMenu
{
123 BuddyContextMenu(BuddyListBuddy
&parent_buddy
);
124 virtual ~BuddyContextMenu() override
{}
127 BuddyListBuddy
*parent_buddy_
;
129 void onInformation(Button
&activator
);
131 void changeAliasResponseHandler(CppConsUI::InputDialog
&activator
,
132 CppConsUI::AbstractDialog::ResponseType response
);
133 void onChangeAlias(Button
&activator
);
135 void removeResponseHandler(CppConsUI::MessageDialog
&activator
,
136 CppConsUI::AbstractDialog::ResponseType response
);
137 void onRemove(Button
&activator
);
140 CONSUI_DISABLE_COPY(BuddyContextMenu
);
146 virtual int getAttributes(int property
, int subproperty
, int *attrs
,
147 CppConsUI::Error
&error
) const override
;
150 virtual void openContextMenu() override
;
152 void updateColorScheme();
155 BuddyListBuddy(PurpleBlistNode
*node
);
156 virtual ~BuddyListBuddy() override
{}
157 CONSUI_DISABLE_COPY(BuddyListBuddy
);
160 class BuddyListChat
: public BuddyListNode
{
161 friend class BuddyListNode
;
165 virtual bool lessOrEqual(const BuddyListNode
&other
) const override
;
166 virtual void update() override
;
167 virtual void onActivate(Button
&activator
) override
;
168 virtual const char *toString() const override
;
170 PurpleChat
*getPurpleChat() const { return chat_
; }
173 class ChatContextMenu
: public ContextMenu
{
175 ChatContextMenu(BuddyListChat
&parent_chat
);
176 virtual ~ChatContextMenu() override
{}
179 BuddyListChat
*parent_chat_
;
181 void changeAliasResponseHandler(CppConsUI::InputDialog
&activator
,
182 CppConsUI::AbstractDialog::ResponseType response
);
183 void onChangeAlias(Button
&activator
);
185 void removeResponseHandler(CppConsUI::MessageDialog
&activator
,
186 CppConsUI::AbstractDialog::ResponseType response
);
187 void onRemove(Button
&activator
);
190 CONSUI_DISABLE_COPY(ChatContextMenu
);
196 virtual void openContextMenu() override
;
199 BuddyListChat(PurpleBlistNode
*node
);
200 virtual ~BuddyListChat() override
{}
201 CONSUI_DISABLE_COPY(BuddyListChat
);
204 class BuddyListContact
: public BuddyListNode
{
205 friend class BuddyListNode
;
209 virtual bool lessOrEqual(const BuddyListNode
&other
) const override
;
210 virtual void update() override
;
211 virtual void onActivate(Button
&activator
) override
;
212 virtual const char *toString() const override
;
213 virtual void setRefNode(CppConsUI::TreeView::NodeReference n
) override
;
215 PurpleContact
*getPurpleContact() const { return contact_
; }
216 void retrieveUserInfo();
218 bool isCollapsed() const { return ref_
->isCollapsed(); }
219 void setCollapsed(bool collapsed
)
221 treeview_
->setCollapsed(ref_
, collapsed
);
225 class ContactContextMenu
: public ContextMenu
{
227 ContactContextMenu(BuddyListContact
&parent_contact
);
228 virtual ~ContactContextMenu() override
{}
231 BuddyListContact
*parent_contact_
;
233 void onExpandRequest(Button
&activator
, bool expand
);
234 void onInformation(Button
&activator
);
236 void changeAliasResponseHandler(CppConsUI::InputDialog
&activator
,
237 CppConsUI::AbstractDialog::ResponseType response
);
238 void onChangeAlias(Button
&activator
);
240 void removeResponseHandler(CppConsUI::MessageDialog
&activator
,
241 CppConsUI::AbstractDialog::ResponseType response
);
242 void onRemove(Button
&activator
);
244 void onMoveTo(Button
&activator
, PurpleGroup
*group
);
247 CONSUI_DISABLE_COPY(ContactContextMenu
);
250 PurpleContact
*contact_
;
253 virtual int getAttributes(int property
, int subproperty
, int *attrs
,
254 CppConsUI::Error
&error
) const override
;
257 virtual void openContextMenu() override
;
259 void updateColorScheme();
262 BuddyListContact(PurpleBlistNode
*node
);
263 virtual ~BuddyListContact() override
{}
264 CONSUI_DISABLE_COPY(BuddyListContact
);
267 class BuddyListGroup
: public BuddyListNode
{
268 friend class BuddyListNode
;
272 virtual bool lessOrEqual(const BuddyListNode
&other
) const override
;
273 virtual void update() override
;
274 virtual void onActivate(Button
&activator
) override
;
275 virtual const char *toString() const override
;
276 virtual void setRefNode(CppConsUI::TreeView::NodeReference n
) override
;
278 PurpleGroup
*getPurpleGroup() const { return group_
; }
280 void initCollapsedState();
283 class GroupContextMenu
: public ContextMenu
{
285 GroupContextMenu(BuddyListGroup
&parent_group
);
286 virtual ~GroupContextMenu() override
{}
289 BuddyListGroup
*parent_group_
;
291 void renameResponseHandler(CppConsUI::InputDialog
&activator
,
292 CppConsUI::AbstractDialog::ResponseType response
);
293 void onRename(Button
&activator
);
295 void removeResponseHandler(CppConsUI::MessageDialog
&activator
,
296 CppConsUI::AbstractDialog::ResponseType response
);
297 void onRemove(Button
&activator
);
299 void onMoveAfter(Button
&activator
, PurpleGroup
*group
);
302 CONSUI_DISABLE_COPY(GroupContextMenu
);
308 virtual void openContextMenu() override
;
311 BuddyListGroup(PurpleBlistNode
*node
);
312 virtual ~BuddyListGroup() override
{}
313 CONSUI_DISABLE_COPY(BuddyListGroup
);
316 #endif // BUDDYLISTNODE_H
318 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: