1 // Copyright (C) 2015 Wade Berrier <wberrier@gmail.com>
3 // This file is part of CenterIM.
5 // CenterIM is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // CenterIM is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with CenterIM. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef CONVERSATION_ROOMLIST_H
19 #define CONVERSATION_ROOMLIST_H
21 #include <cppconsui/Button.h>
22 #include <cppconsui/ListBox.h>
23 #include <libpurple/purple.h>
27 class ConversationRoomList
: public CppConsUI::ListBox
{
29 ConversationRoomList(int w
, int h
, PurpleConversation
*conv
)
30 : CppConsUI::ListBox(w
, h
), conv_(conv
)
33 virtual ~ConversationRoomList() override
{}
35 // Libpurple chatroom interfaces.
36 void add_users(GList
*cbuddies
, gboolean new_arrivals
);
38 const char *old_name
, const char *new_name
, const char *new_alias
);
39 void remove_users(GList
*users
);
40 void update_user(const char *user
);
43 // Represents a widget as well as pointer to libpurple data.
44 class Buddy
: public CppConsUI::Button
{
46 explicit Buddy(PurpleConvChatBuddy
*pbuddy
);
48 virtual ~Buddy() override
;
50 // Sets button text with displayName.
53 // Uses pbuddy info to generate button displayText. Returns a newly
54 // allocated string that must be freed by the caller.
55 char *displayText() const;
57 // Prefer alias if it exists, and fall back on name.
58 const char *displayName() const;
61 // void onActivate(Button &);
63 // Update purple buddy (for rename case).
64 void setPurpleBuddy(PurpleConvChatBuddy
*pbuddy
);
66 // Sorting method for: op/away/display_name
67 // if less than: give priority
68 // The idea that if more sorting methods are desired, they can be swapped
69 // out at runtime based on config.
70 static bool less_than_op_away_name(const Buddy
&lhs
, const Buddy
&rhs
);
72 bool operator==(const Buddy
&rhs
);
75 void readFlags(bool &is_op
, bool &is_typing
, bool &is_away
) const;
77 // Note: When remove_users op is called, this pointer is invalidated!.
78 PurpleConvChatBuddy
*pbuddy_
;
80 CONSUI_DISABLE_COPY(Buddy
);
83 typedef std::map
<std::string
, Buddy
*> Buddies
;
85 PurpleConversation
*conv_
;
87 // Have to keep this mapping to remove users
88 // because when libpurple calls remove_user, the user is already
89 // gone, along with the "ui_data"
90 // Otherwise could store "name" in Buddy and iterate through "children"
91 // NOTE: turns out that ui_data is new in libpurple 2.9, so for previous
92 // versions this map is required anyways... :/
95 // Move buddy to sorted position.
96 void moveToSortedPosition(Buddy
*buddy
);
99 CONSUI_DISABLE_COPY(ConversationRoomList
);
102 #endif // CONVERSATION_ROOMLIST_H
104 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: