Use pkg-config to find ncursesw
[centerim5.git] / src / AccountStatusMenu.cpp
blob00307449f17744e01f19125a1da8f2a4ea62139d
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 #include "AccountStatusMenu.h"
21 #include "CenterIM.h"
23 AccountStatusMenu::AccountStatusMenu() : MenuWindow(0, 0, AUTOSIZE, AUTOSIZE)
25 setColorScheme(CenterIM::SCHEME_ACCOUNTSTATUSMENU);
28 TODO
29 AppendItem(_("All accounts"), sigc::mem_fun(this,
30 &AccountStatusMenu::Dummy));
31 AppendItem(_("Already logged in only"), sigc::mem_fun(this,
32 &AccountStatusMenu::Dummy));
33 AppendSeparator();
36 GList *list = purple_accounts_get_all_active();
37 for (GList *l = list; l != nullptr; l = l->next) {
38 PurpleAccount *account = reinterpret_cast<PurpleAccount *>(l->data);
40 char *text =
41 g_strdup_printf("[%s] %s", purple_account_get_protocol_name(account),
42 purple_account_get_username(account));
43 appendItem(
44 text, sigc::bind(sigc::mem_fun(this, &AccountStatusMenu::openStatusPopup),
45 account));
46 g_free(text);
48 g_list_free(list);
50 onScreenResized();
53 void AccountStatusMenu::onScreenResized()
55 CppConsUI::Rect chat = CENTERIM->getScreenArea(CenterIM::CHAT_AREA);
56 move(chat.x, chat.y);
59 void AccountStatusMenu::openStatusPopup(
60 CppConsUI::Button &activator, PurpleAccount *account)
62 auto status_popup = new StatusPopup(account);
63 status_popup->setReferenceWidget(activator);
64 status_popup->show();
67 AccountStatusMenu::StatusPopup::StatusPopup(PurpleAccount *account)
68 : MenuWindow(0, 0, AUTOSIZE, AUTOSIZE)
70 setColorScheme(CenterIM::SCHEME_ACCOUNTSTATUSMENU);
72 bool has_independents = false;
73 for (GList *iter = purple_account_get_status_types(account); iter != nullptr;
74 iter = iter->next) {
75 PurpleStatusType *status_type =
76 reinterpret_cast<PurpleStatusType *>(iter->data);
78 if (purple_status_type_is_independent(status_type)) {
79 has_independents = true;
80 continue;
83 bool active =
84 purple_presence_is_status_active(purple_account_get_presence(account),
85 purple_status_type_get_id(status_type));
87 char *label;
88 if (active)
89 label = g_strdup_printf("* %s", purple_status_type_get_name(status_type));
90 else
91 label = g_strdup(purple_status_type_get_name(status_type));
92 CppConsUI::Button *b =
93 appendItem(label, sigc::bind(sigc::mem_fun(this, &StatusPopup::setStatus),
94 account, status_type, true));
95 if (active)
96 b->grabFocus();
97 g_free(label);
100 if (has_independents) {
101 appendSeparator();
103 for (GList *iter = purple_account_get_status_types(account); iter;
104 iter = iter->next) {
105 PurpleStatusType *status_type =
106 reinterpret_cast<PurpleStatusType *>(iter->data);
108 if (!purple_status_type_is_independent(status_type))
109 continue;
111 bool active =
112 purple_presence_is_status_active(purple_account_get_presence(account),
113 purple_status_type_get_id(status_type));
115 char *label;
116 if (active)
117 label =
118 g_strdup_printf("* %s", purple_status_type_get_name(status_type));
119 else
120 label = g_strdup(purple_status_type_get_name(status_type));
121 CppConsUI::Button *b = appendItem(
122 label, sigc::bind(sigc::mem_fun(this, &StatusPopup::setStatus), account,
123 status_type, !active));
124 if (active)
125 b->grabFocus();
126 g_free(label);
130 onScreenResized();
133 void AccountStatusMenu::StatusPopup::setStatus(
134 CppConsUI::Button & /*activator*/, PurpleAccount *account,
135 PurpleStatusType *status_type, bool active)
137 purple_account_set_status(
138 account, purple_status_type_get_id(status_type), active, nullptr);
139 close();
142 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: