Use correct package prefix for local macros in configure.ac
[centerim5.git] / src / GeneralMenu.cpp
blob67cd6367de47336a426ca2e5b48e923c766a2344
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 "GeneralMenu.h"
21 #include "AccountStatusMenu.h"
22 #include "AccountWindow.h"
23 #include "Accounts.h"
24 #include "Log.h"
25 #include "OptionWindow.h"
26 #include "PluginWindow.h"
28 #include "gettext.h"
30 GeneralMenu::GeneralMenu() : MenuWindow(0, 0, AUTOSIZE, AUTOSIZE)
32 setColorScheme(CenterIM::SCHEME_GENERALMENU);
34 appendItem(
35 _("Change status"), sigc::mem_fun(this, &GeneralMenu::openStatusWindow));
36 appendItem(
37 _("Accounts..."), sigc::mem_fun(this, &GeneralMenu::openAccountWindow));
38 appendItem(
39 _("Add buddy..."), sigc::mem_fun(this, &GeneralMenu::openAddBuddyRequest));
40 appendItem(
41 _("Add chat..."), sigc::mem_fun(this, &GeneralMenu::openAddChatRequest));
42 appendItem(
43 _("Add group..."), sigc::mem_fun(this, &GeneralMenu::openAddGroupRequest));
44 appendItem(_("Pending requests..."),
45 sigc::mem_fun(this, &GeneralMenu::openPendingRequests));
46 appendItem(_("Config options..."),
47 sigc::mem_fun(this, &GeneralMenu::openOptionWindow));
48 appendItem(
49 _("Plugins..."), sigc::mem_fun(this, &GeneralMenu::openPluginWindow));
50 appendSeparator();
51 #ifdef DEBUG
52 auto submenu = new MenuWindow(0, 0, AUTOSIZE, AUTOSIZE);
53 submenu->setColorScheme(CenterIM::SCHEME_GENERALMENU);
54 submenu->appendItem(
55 "Request input", sigc::mem_fun(this, &GeneralMenu::openRequestInputTest));
56 submenu->appendItem(
57 "Request choice", sigc::mem_fun(this, &GeneralMenu::openRequestChoiceTest));
58 submenu->appendItem(
59 "Request action", sigc::mem_fun(this, &GeneralMenu::openRequestActionTest));
60 submenu->appendItem(
61 "Request fields", sigc::mem_fun(this, &GeneralMenu::openRequestFieldsTest));
62 appendSubMenu("Debug...", *submenu);
63 appendSeparator();
64 #endif // DEBUG
65 appendItem(_("Quit"), sigc::hide(sigc::mem_fun(CENTERIM, &CenterIM::quit)));
67 onScreenResized();
70 void GeneralMenu::onScreenResized()
72 CppConsUI::Rect chat = CENTERIM->getScreenArea(CenterIM::CHAT_AREA);
73 move(chat.x, chat.y);
76 void GeneralMenu::openStatusWindow(CppConsUI::Button & /*activator*/)
78 auto win = new AccountStatusMenu;
79 win->show();
80 close();
83 void GeneralMenu::openAccountWindow(CppConsUI::Button & /*activator*/)
85 auto win = new AccountWindow;
86 win->show();
87 close();
90 void GeneralMenu::openAddBuddyRequest(CppConsUI::Button & /*activator*/)
92 purple_blist_request_add_buddy(nullptr, nullptr, nullptr, nullptr);
93 close();
96 void GeneralMenu::openAddChatRequest(CppConsUI::Button & /*activator*/)
98 purple_blist_request_add_chat(nullptr, nullptr, nullptr, nullptr);
99 close();
102 void GeneralMenu::openAddGroupRequest(CppConsUI::Button & /*activator*/)
104 purple_blist_request_add_group();
105 close();
108 void GeneralMenu::openPendingRequests(CppConsUI::Button & /*activator*/)
110 ACCOUNTS->openPendingRequests();
111 close();
114 void GeneralMenu::openOptionWindow(CppConsUI::Button & /*activator*/)
116 auto win = new OptionWindow;
117 win->show();
118 close();
121 void GeneralMenu::openPluginWindow(CppConsUI::Button & /*activator*/)
123 auto win = new PluginWindow;
124 win->show();
125 close();
128 #ifdef DEBUG
129 void GeneralMenu::openRequestInputTest(CppConsUI::Button & /*activator*/)
131 purple_request_input(nullptr, "Title", "Primary", "Secondary",
132 "default value", FALSE, FALSE, nullptr, "Ok", G_CALLBACK(input_ok_cb_),
133 "Cancel", nullptr, nullptr, nullptr, nullptr, this);
135 close();
138 void GeneralMenu::openRequestChoiceTest(CppConsUI::Button & /*activator*/)
140 purple_request_choice(nullptr, "Title", "Primary", "Secondary", 1, "Ok",
141 G_CALLBACK(choice_ok_cb_), "Cancel", nullptr, nullptr, nullptr, nullptr,
142 this, "Option 0", 0, "Option 1", 1, "Option 2", 2, nullptr);
144 close();
147 void GeneralMenu::openRequestActionTest(CppConsUI::Button & /*activator*/)
149 purple_request_action(nullptr, "Title", "Primary", "Secondary", 1, nullptr,
150 nullptr, nullptr, this, 3, "Action 0", G_CALLBACK(action_cb_), "Action 1",
151 nullptr, "Action 2", G_CALLBACK(action_cb_));
153 close();
156 void GeneralMenu::openRequestFieldsTest(CppConsUI::Button & /*activator*/)
158 PurpleRequestFields *fields = purple_request_fields_new();
159 PurpleRequestFieldGroup *g = purple_request_field_group_new("Group 0");
161 purple_request_fields_add_group(fields, g);
163 PurpleRequestField *f;
164 f = purple_request_field_string_new("text0", "String field 0", "def0", FALSE);
165 purple_request_field_group_add_field(g, f);
167 purple_request_field_string_new("text1", "String field 1", nullptr, FALSE);
168 purple_request_field_group_add_field(g, f);
169 f = purple_request_field_int_new("int0", "Int field 0", INT_MAX);
170 purple_request_field_group_add_field(g, f);
171 f = purple_request_field_bool_new("bool0", "Bool field 0", FALSE);
172 purple_request_field_group_add_field(g, f);
174 f = purple_request_field_choice_new("choice0", "Choice field 0", 2);
175 purple_request_field_choice_add(f, "One");
176 purple_request_field_choice_add(f, "Two");
177 purple_request_field_choice_add(f, "Three");
178 purple_request_field_choice_add(f, "Four");
179 purple_request_field_group_add_field(g, f);
181 f = purple_request_field_list_new("list0", "List field 0, multiple");
182 purple_request_field_list_set_multi_select(f, TRUE);
183 purple_request_field_list_add(f, "One", this);
184 purple_request_field_list_add(f, "Two", this);
185 purple_request_field_list_add(f, "Three", this);
186 purple_request_field_list_add(f, "Four", this);
187 purple_request_field_list_add_selected(f, "Three");
188 purple_request_field_group_add_field(g, f);
190 f = purple_request_field_list_new("list1", "List field 1, single");
191 purple_request_field_list_set_multi_select(f, FALSE);
192 purple_request_field_list_add(f, "One", this);
193 purple_request_field_list_add(f, "Two", this);
194 purple_request_field_list_add(f, "Three", this);
195 purple_request_field_list_add(f, "Four", this);
196 purple_request_field_list_add_selected(f, "Three");
197 purple_request_field_group_add_field(g, f);
199 f = purple_request_field_account_new("account0", "Account field 0", nullptr);
200 purple_request_field_account_set_show_all(f, TRUE);
201 purple_request_field_group_add_field(g, f);
203 purple_request_fields(nullptr, "Title", "Primary", "Secondary", fields, "Ok",
204 G_CALLBACK(fields_ok_cb_), "Cancel", nullptr, nullptr, nullptr, nullptr,
205 this);
207 close();
210 void GeneralMenu::input_ok_cb(const char *text)
212 LOG->debug("input_ok_cb: %s", text);
215 void GeneralMenu::choice_ok_cb(int selected)
217 LOG->debug("choice_ok_cb: %d", selected);
220 void GeneralMenu::action_cb(int action)
222 LOG->debug("action_cb: %d", action);
225 void GeneralMenu::fields_ok_cb(PurpleRequestFields *fields)
227 LOG->debug(
228 "fields_ok_cb: text0=%s, text1=%s, int0=%d, bool0=%d, choice0=%d\n",
229 purple_request_fields_get_string(fields, "text0"),
230 purple_request_fields_get_string(fields, "text1"),
231 purple_request_fields_get_integer(fields, "int0"),
232 purple_request_fields_get_bool(fields, "bool0"),
233 purple_request_fields_get_choice(fields, "choice0"));
235 for (GList *list = purple_request_field_list_get_selected(
236 purple_request_fields_get_field(fields, "list0"));
237 list != nullptr; list = list->next)
238 LOG->debug(
239 "fields_ok_cb: list0=%s", reinterpret_cast<const char *>(list->data));
241 for (GList *list = purple_request_field_list_get_selected(
242 purple_request_fields_get_field(fields, "list1"));
243 list != nullptr; list = list->next)
244 LOG->debug(
245 "fields_ok_cb: list1=%s", reinterpret_cast<const char *>(list->data));
247 PurpleAccount *account =
248 purple_request_fields_get_account(fields, "account0");
249 LOG->debug("fields_ok_cb: account0=[%s] %s",
250 purple_account_get_protocol_name(account),
251 purple_account_get_username(account));
253 #endif // DEBUG
255 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: