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 #include "AccountStatusMenu.h"
23 AccountStatusMenu::AccountStatusMenu() : MenuWindow(0, 0, AUTOSIZE
, AUTOSIZE
)
25 setColorScheme(CenterIM::SCHEME_ACCOUNTSTATUSMENU
);
29 AppendItem(_("All accounts"), sigc::mem_fun(this,
30 &AccountStatusMenu::Dummy));
31 AppendItem(_("Already logged in only"), sigc::mem_fun(this,
32 &AccountStatusMenu::Dummy));
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
);
41 g_strdup_printf("[%s] %s", purple_account_get_protocol_name(account
),
42 purple_account_get_username(account
));
44 text
, sigc::bind(sigc::mem_fun(this, &AccountStatusMenu::openStatusPopup
),
53 void AccountStatusMenu::onScreenResized()
55 CppConsUI::Rect chat
= CENTERIM
->getScreenArea(CenterIM::CHAT_AREA
);
59 void AccountStatusMenu::openStatusPopup(
60 CppConsUI::Button
&activator
, PurpleAccount
*account
)
62 auto status_popup
= new StatusPopup(account
);
63 status_popup
->setReferenceWidget(activator
);
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;
75 PurpleStatusType
*status_type
=
76 reinterpret_cast<PurpleStatusType
*>(iter
->data
);
78 if (purple_status_type_is_independent(status_type
)) {
79 has_independents
= true;
84 purple_presence_is_status_active(purple_account_get_presence(account
),
85 purple_status_type_get_id(status_type
));
89 label
= g_strdup_printf("* %s", purple_status_type_get_name(status_type
));
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));
100 if (has_independents
) {
103 for (GList
*iter
= purple_account_get_status_types(account
); iter
;
105 PurpleStatusType
*status_type
=
106 reinterpret_cast<PurpleStatusType
*>(iter
->data
);
108 if (!purple_status_type_is_independent(status_type
))
112 purple_presence_is_status_active(purple_account_get_presence(account
),
113 purple_status_type_get_id(status_type
));
118 g_strdup_printf("* %s", purple_status_type_get_name(status_type
));
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
));
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);
142 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: