Update list of wide characters
[centerim5.git] / src / Request.h
blob1d77d1bcc419c313a6b8cdbed16105890837b68d
1 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
2 //
3 // This file is part of CenterIM.
4 //
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.
9 //
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 REQUEST_H
19 #define REQUEST_H
21 #include <cppconsui/CheckBox.h>
22 #include <cppconsui/ComboBox.h>
23 #include <cppconsui/InputDialog.h>
24 #include <cppconsui/Label.h>
25 #include <cppconsui/SplitDialog.h>
26 #include <cppconsui/TextEntry.h>
27 #include <cppconsui/TreeView.h>
28 #include <libpurple/purple.h>
30 #define REQUEST (Request::instance())
32 class Request {
33 public:
34 static Request *instance();
36 private:
37 class RequestDialog : public CppConsUI::SplitDialog {
38 public:
39 RequestDialog(const char *title, const char *primary, const char *secondary,
40 const char *ok_text, GCallback ok_cb, const char *cancel_text,
41 GCallback cancel_cb, void *user_data);
42 virtual ~RequestDialog() override {}
44 // FreeWindow
45 virtual void onScreenResized() override;
47 virtual PurpleRequestType getRequestType() = 0;
49 protected:
50 GCallback ok_cb_;
51 GCallback cancel_cb_;
52 void *user_data_;
54 // Convenience variable, same as dynamic_cast<ListBox *>(container).
55 CppConsUI::ListBox *lbox_;
57 virtual void responseHandler(
58 CppConsUI::SplitDialog &activator, ResponseType response) = 0;
60 private:
61 CONSUI_DISABLE_COPY(RequestDialog);
64 class InputTextDialog : public RequestDialog {
65 public:
66 InputTextDialog(const char *title, const char *primary,
67 const char *secondary, const char *default_value, bool masked,
68 const char *ok_text, GCallback ok_cb, const char *cancel_text,
69 GCallback cancel_cb, void *user_data);
70 virtual ~InputTextDialog() override {}
72 // RequestDialog
73 virtual PurpleRequestType getRequestType() override;
75 protected:
76 CppConsUI::TextEntry *entry_;
78 // RequestDialog
79 virtual void responseHandler(
80 SplitDialog &activator, ResponseType response) override;
82 private:
83 CONSUI_DISABLE_COPY(InputTextDialog);
86 class ChoiceDialog : public RequestDialog {
87 public:
88 ChoiceDialog(const char *title, const char *primary, const char *secondary,
89 int default_value, const char *ok_text, GCallback ok_cb,
90 const char *cancel_text, GCallback cancel_cb, void *user_data,
91 va_list choices);
92 virtual ~ChoiceDialog() override {}
94 // RequestDialog
95 virtual PurpleRequestType getRequestType() override;
97 protected:
98 CppConsUI::ComboBox *combo_;
100 // RequestDialog
101 virtual void responseHandler(
102 SplitDialog &activator, ResponseType response) override;
104 private:
105 CONSUI_DISABLE_COPY(ChoiceDialog);
108 class ActionDialog : public RequestDialog {
109 public:
110 ActionDialog(const char *title, const char *primary, const char *secondary,
111 int default_value, void *user_data, std::size_t action_count,
112 va_list actions);
113 virtual ~ActionDialog() override {}
115 // RequestDialog
116 virtual PurpleRequestType getRequestType() override;
118 protected:
119 // RequestDialog
120 virtual void responseHandler(
121 SplitDialog &activator, ResponseType response) override;
123 private:
124 CONSUI_DISABLE_COPY(ActionDialog);
126 void onActionChoice(
127 CppConsUI::Button &activator, std::size_t i, GCallback cb);
130 class FieldsDialog : public RequestDialog {
131 public:
132 FieldsDialog(const char *title, const char *primary, const char *secondary,
133 PurpleRequestFields *request_fields, const char *ok_text, GCallback ok_cb,
134 const char *cancel_text, GCallback cancel_cb, void *user_data);
135 virtual ~FieldsDialog() override {}
137 // RequestDialog
138 virtual PurpleRequestType getRequestType() override;
140 protected:
141 PurpleRequestFields *fields_;
142 CppConsUI::TreeView *treeview_;
144 class StringField : public CppConsUI::Button {
145 public:
146 StringField(PurpleRequestField *field);
147 virtual ~StringField() override {}
149 protected:
150 PurpleRequestField *field_;
152 void onActivate(CppConsUI::Button &activator);
153 void responseHandler(CppConsUI::InputDialog &activator,
154 CppConsUI::AbstractDialog::ResponseType response);
156 private:
157 CONSUI_DISABLE_COPY(StringField);
160 class IntegerField : public CppConsUI::Button {
161 public:
162 IntegerField(PurpleRequestField *field);
163 virtual ~IntegerField() override {}
165 protected:
166 PurpleRequestField *field_;
168 void onActivate(CppConsUI::Button &activator);
169 void responseHandler(CppConsUI::InputDialog &activator,
170 CppConsUI::AbstractDialog::ResponseType response);
172 private:
173 CONSUI_DISABLE_COPY(IntegerField);
176 class BooleanField : public CppConsUI::CheckBox {
177 public:
178 BooleanField(PurpleRequestField *field);
179 virtual ~BooleanField() override {}
181 protected:
182 PurpleRequestField *field_;
184 void onToggle(CppConsUI::CheckBox &activator, bool new_state);
186 private:
187 CONSUI_DISABLE_COPY(BooleanField);
190 class ChoiceField : public CppConsUI::ComboBox {
191 public:
192 ChoiceField(PurpleRequestField *field);
193 virtual ~ChoiceField() override {}
195 protected:
196 PurpleRequestField *field_;
198 void onSelectionChanged(CppConsUI::ComboBox &activator, int new_entry,
199 const char *title, intptr_t data);
201 private:
202 CONSUI_DISABLE_COPY(ChoiceField);
205 class ListFieldMultiple : public CppConsUI::ListBox {
206 public:
207 ListFieldMultiple(PurpleRequestField *field);
208 virtual ~ListFieldMultiple() override {}
210 protected:
211 PurpleRequestField *field_;
213 class ListFieldItem : public CppConsUI::CheckBox {
214 public:
215 ListFieldItem(PurpleRequestField *field, const char *text);
216 virtual ~ListFieldItem() override {}
218 protected:
219 PurpleRequestField *field_;
221 void onToggle(CppConsUI::CheckBox &activator, bool new_state);
223 private:
224 CONSUI_DISABLE_COPY(ListFieldItem);
227 private:
228 CONSUI_DISABLE_COPY(ListFieldMultiple);
231 class ListFieldSingle : public CppConsUI::ComboBox {
232 public:
233 ListFieldSingle(PurpleRequestField *field);
234 virtual ~ListFieldSingle() override {}
236 protected:
237 PurpleRequestField *field_;
239 void onSelectionChanged(CppConsUI::ComboBox &activator, int new_entry,
240 const char *title, intptr_t data);
242 private:
243 CONSUI_DISABLE_COPY(ListFieldSingle);
246 class LabelField : public CppConsUI::Label {
247 public:
248 LabelField(PurpleRequestField *field);
249 virtual ~LabelField() override {}
251 protected:
252 PurpleRequestField *field_;
254 private:
255 CONSUI_DISABLE_COPY(LabelField);
258 class ImageField : public CppConsUI::Button {
259 public:
260 ImageField(PurpleRequestField *field);
261 virtual ~ImageField() override {}
263 protected:
264 PurpleRequestField *field_;
266 void onActivate(CppConsUI::Button &activator);
268 private:
269 CONSUI_DISABLE_COPY(ImageField);
272 class AccountField : public CppConsUI::ComboBox {
273 public:
274 AccountField(PurpleRequestField *field);
275 virtual ~AccountField() override {}
277 protected:
278 PurpleRequestField *field_;
280 void onAccountChanged(CppConsUI::Button &activator, std::size_t new_entry,
281 const char *title, intptr_t data);
283 private:
284 CONSUI_DISABLE_COPY(AccountField);
287 // RequestDialog
288 virtual void responseHandler(
289 CppConsUI::SplitDialog &activator, ResponseType response) override;
291 private:
292 CONSUI_DISABLE_COPY(FieldsDialog);
295 typedef std::set<RequestDialog *> Requests;
297 Requests requests_;
299 PurpleRequestUiOps centerim_request_ui_ops_;
301 static Request *my_instance_;
303 Request();
304 ~Request();
305 CONSUI_DISABLE_COPY(Request);
307 static void init();
308 static void finalize();
309 friend class CenterIM;
311 void onDialogResponse(CppConsUI::SplitDialog &dialog,
312 CppConsUI::AbstractDialog::ResponseType response);
314 static void *request_input_(const char *title, const char *primary,
315 const char *secondary, const char *default_value, gboolean multiline,
316 gboolean masked, char *hint, const char *ok_text, GCallback ok_cb,
317 const char *cancel_text, GCallback cancel_cb, PurpleAccount *account,
318 const char *who, PurpleConversation *conv, void *user_data)
320 return REQUEST->request_input(title, primary, secondary, default_value,
321 multiline, masked, hint, ok_text, ok_cb, cancel_text, cancel_cb, account,
322 who, conv, user_data);
324 static void *request_choice_(const char *title, const char *primary,
325 const char *secondary, int default_value, const char *ok_text,
326 GCallback ok_cb, const char *cancel_text, GCallback cancel_cb,
327 PurpleAccount *account, const char *who, PurpleConversation *conv,
328 void *user_data, va_list choices)
330 return REQUEST->request_choice(title, primary, secondary, default_value,
331 ok_text, ok_cb, cancel_text, cancel_cb, account, who, conv, user_data,
332 choices);
334 static void *request_action_(const char *title, const char *primary,
335 const char *secondary, int default_action, PurpleAccount *account,
336 const char *who, PurpleConversation *conv, void *user_data,
337 std::size_t action_count, va_list actions)
339 return REQUEST->request_action(title, primary, secondary, default_action,
340 account, who, conv, user_data, action_count, actions);
342 static void *request_fields_(const char *title, const char *primary,
343 const char *secondary, PurpleRequestFields *fields, const char *ok_text,
344 GCallback ok_cb, const char *cancel_text, GCallback cancel_cb,
345 PurpleAccount *account, const char *who, PurpleConversation *conv,
346 void *user_data)
348 return REQUEST->request_fields(title, primary, secondary, fields, ok_text,
349 ok_cb, cancel_text, cancel_cb, account, who, conv, user_data);
351 static void *request_file_(const char *title, const char *filename,
352 gboolean savedialog, GCallback ok_cb, GCallback cancel_cb,
353 PurpleAccount *account, const char *who, PurpleConversation *conv,
354 void *user_data)
356 return REQUEST->request_file(title, filename, savedialog, ok_cb, cancel_cb,
357 account, who, conv, user_data);
359 static void close_request_(PurpleRequestType type, void *ui_handle)
361 REQUEST->close_request(type, ui_handle);
363 static void *request_folder_(const char *title, const char *dirname,
364 GCallback ok_cb, GCallback cancel_cb, PurpleAccount *account,
365 const char *who, PurpleConversation *conv, void *user_data)
367 return REQUEST->request_folder(
368 title, dirname, ok_cb, cancel_cb, account, who, conv, user_data);
370 static void *request_action_with_icon_(const char *title, const char *primary,
371 const char *secondary, int default_action, PurpleAccount *account,
372 const char *who, PurpleConversation *conv, gconstpointer icon_data,
373 gsize icon_size, void *user_data, std::size_t action_count, va_list actions)
375 return REQUEST->request_action_with_icon(title, primary, secondary,
376 default_action, account, who, conv, icon_data, icon_size, user_data,
377 action_count, actions);
380 void *request_input(const char *title, const char *primary,
381 const char *secondary, const char *default_value, gboolean multiline,
382 gboolean masked, char *hint, const char *ok_text, GCallback ok_cb,
383 const char *cancel_text, GCallback cancel_cb, PurpleAccount *account,
384 const char *who, PurpleConversation *conv, void *user_data);
385 void *request_choice(const char *title, const char *primary,
386 const char *secondary, int default_value, const char *ok_text,
387 GCallback ok_cb, const char *cancel_text, GCallback cancel_cb,
388 PurpleAccount *account, const char *who, PurpleConversation *conv,
389 void *user_data, va_list choices);
390 void *request_action(const char *title, const char *primary,
391 const char *secondary, int default_action, PurpleAccount *account,
392 const char *who, PurpleConversation *conv, void *user_data,
393 std::size_t action_count, va_list actions);
394 void *request_fields(const char *title, const char *primary,
395 const char *secondary, PurpleRequestFields *fields, const char *ok_text,
396 GCallback ok_cb, const char *cancel_text, GCallback cancel_cb,
397 PurpleAccount *account, const char *who, PurpleConversation *conv,
398 void *user_data);
399 void *request_file(const char *title, const char *filename,
400 gboolean savedialog, GCallback ok_cb, GCallback cancel_cb,
401 PurpleAccount *account, const char *who, PurpleConversation *conv,
402 void *user_data);
403 void close_request(PurpleRequestType type, void *ui_handle);
404 void *request_folder(const char *title, const char *dirname, GCallback ok_cb,
405 GCallback cancel_cb, PurpleAccount *account, const char *who,
406 PurpleConversation *conv, void *user_data);
407 void *request_action_with_icon(const char *title, const char *primary,
408 const char *secondary, int default_action, PurpleAccount *account,
409 const char *who, PurpleConversation *conv, gconstpointer icon_data,
410 gsize icon_size, void *user_data, std::size_t action_count,
411 va_list actions);
414 #endif // REQUEST_H
416 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: