Update AUTHORS file
[centerim5.git] / src / Request.h
blob2954e50791c5fee344f9cef50f48da1a7fff519d
1 /*
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 this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef __REQUEST_H__
22 #define __REQUEST_H__
24 #include <cppconsui/CheckBox.h>
25 #include <cppconsui/ComboBox.h>
26 #include <cppconsui/InputDialog.h>
27 #include <cppconsui/Label.h>
28 #include <cppconsui/TextEntry.h>
29 #include <cppconsui/TreeView.h>
30 #include <cppconsui/SplitDialog.h>
31 #include <libpurple/purple.h>
33 #define REQUEST (Request::instance())
35 class Request {
36 public:
37 static Request *instance();
39 protected:
40 private:
41 class RequestDialog : public CppConsUI::SplitDialog {
42 public:
43 RequestDialog(const char *title, const char *primary, const char *secondary,
44 const char *ok_text, GCallback ok_cb, const char *cancel_text,
45 GCallback cancel_cb, void *user_data);
46 virtual ~RequestDialog() {}
48 // FreeWindow
49 virtual void onScreenResized();
51 virtual PurpleRequestType getRequestType() = 0;
53 protected:
54 GCallback ok_cb;
55 GCallback cancel_cb;
56 void *user_data;
58 // convenient var, same as dynamic_cast<ListBox *>(container)
59 CppConsUI::ListBox *lbox;
61 virtual void responseHandler(
62 CppConsUI::SplitDialog &activator, ResponseType response) = 0;
64 private:
65 CONSUI_DISABLE_COPY(RequestDialog);
68 class InputTextDialog : public RequestDialog {
69 public:
70 InputTextDialog(const char *title, const char *primary,
71 const char *secondary, const char *default_value, bool masked,
72 const char *ok_text, GCallback ok_cb, const char *cancel_text,
73 GCallback cancel_cb, void *user_data);
74 virtual ~InputTextDialog() {}
76 virtual PurpleRequestType getRequestType();
78 protected:
79 CppConsUI::TextEntry *entry;
81 virtual void responseHandler(SplitDialog &activator, ResponseType response);
83 private:
84 CONSUI_DISABLE_COPY(InputTextDialog);
87 class ChoiceDialog : public RequestDialog {
88 public:
89 ChoiceDialog(const char *title, const char *primary, const char *secondary,
90 int default_value, const char *ok_text, GCallback ok_cb,
91 const char *cancel_text, GCallback cancel_cb, void *user_data,
92 va_list choices);
93 virtual ~ChoiceDialog() {}
95 virtual PurpleRequestType getRequestType();
97 protected:
98 CppConsUI::ComboBox *combo;
100 virtual void responseHandler(SplitDialog &activator, ResponseType response);
102 private:
103 CONSUI_DISABLE_COPY(ChoiceDialog);
106 class ActionDialog : public RequestDialog {
107 public:
108 ActionDialog(const char *title, const char *primary, const char *secondary,
109 int default_value, void *user_data, size_t action_count, va_list actions);
110 virtual ~ActionDialog() {}
112 virtual PurpleRequestType getRequestType();
114 protected:
115 virtual void responseHandler(SplitDialog &activator, ResponseType response);
117 private:
118 CONSUI_DISABLE_COPY(ActionDialog);
120 void onActionChoice(CppConsUI::Button &activator, size_t i, GCallback cb);
123 class FieldsDialog : public RequestDialog {
124 public:
125 FieldsDialog(const char *title, const char *primary, const char *secondary,
126 PurpleRequestFields *request_fields, const char *ok_text, GCallback ok_cb,
127 const char *cancel_text, GCallback cancel_cb, void *user_data);
128 virtual ~FieldsDialog() {}
130 virtual PurpleRequestType getRequestType();
132 protected:
133 PurpleRequestFields *fields;
134 CppConsUI::TreeView *treeview;
136 class StringField : public CppConsUI::Button {
137 public:
138 StringField(PurpleRequestField *field);
139 virtual ~StringField() {}
141 protected:
142 PurpleRequestField *field;
144 void onActivate(CppConsUI::Button &activator);
145 void responseHandler(CppConsUI::InputDialog &activator,
146 CppConsUI::AbstractDialog::ResponseType response);
148 private:
149 CONSUI_DISABLE_COPY(StringField);
152 class IntegerField : public CppConsUI::Button {
153 public:
154 IntegerField(PurpleRequestField *field);
155 virtual ~IntegerField() {}
157 protected:
158 PurpleRequestField *field;
160 void onActivate(CppConsUI::Button &activator);
161 void responseHandler(CppConsUI::InputDialog &activator,
162 CppConsUI::AbstractDialog::ResponseType response);
164 private:
165 CONSUI_DISABLE_COPY(IntegerField);
168 class BooleanField : public CppConsUI::CheckBox {
169 public:
170 BooleanField(PurpleRequestField *field);
171 virtual ~BooleanField() {}
173 protected:
174 PurpleRequestField *field;
176 void onToggle(CppConsUI::CheckBox &activator, bool new_state);
178 private:
179 CONSUI_DISABLE_COPY(BooleanField);
182 class ChoiceField : public CppConsUI::ComboBox {
183 public:
184 ChoiceField(PurpleRequestField *field);
185 virtual ~ChoiceField() {}
187 protected:
188 PurpleRequestField *field;
190 void onSelectionChanged(CppConsUI::ComboBox &activator, int new_entry,
191 const char *title, intptr_t data);
193 private:
194 CONSUI_DISABLE_COPY(ChoiceField);
197 class ListFieldMultiple : public CppConsUI::ListBox {
198 public:
199 ListFieldMultiple(PurpleRequestField *field);
200 virtual ~ListFieldMultiple() {}
202 protected:
203 PurpleRequestField *field;
205 class ListFieldItem : public CppConsUI::CheckBox {
206 public:
207 ListFieldItem(PurpleRequestField *field, const char *text);
208 virtual ~ListFieldItem() {}
210 protected:
211 PurpleRequestField *field;
213 void onToggle(CppConsUI::CheckBox &activator, bool new_state);
215 private:
216 CONSUI_DISABLE_COPY(ListFieldItem);
219 private:
220 CONSUI_DISABLE_COPY(ListFieldMultiple);
223 class ListFieldSingle : public CppConsUI::ComboBox {
224 public:
225 ListFieldSingle(PurpleRequestField *field);
226 virtual ~ListFieldSingle() {}
228 protected:
229 PurpleRequestField *field;
231 void onSelectionChanged(CppConsUI::ComboBox &activator, int new_entry,
232 const char *title, intptr_t data);
234 private:
235 CONSUI_DISABLE_COPY(ListFieldSingle);
238 class LabelField : public CppConsUI::Label {
239 public:
240 LabelField(PurpleRequestField *field);
241 virtual ~LabelField() {}
243 protected:
244 PurpleRequestField *field;
246 private:
247 CONSUI_DISABLE_COPY(LabelField);
250 class ImageField : public CppConsUI::Button {
251 public:
252 ImageField(PurpleRequestField *field);
253 virtual ~ImageField() {}
255 protected:
256 PurpleRequestField *field;
258 void onActivate(CppConsUI::Button &activator);
260 private:
261 CONSUI_DISABLE_COPY(ImageField);
264 class AccountField : public CppConsUI::ComboBox {
265 public:
266 AccountField(PurpleRequestField *field);
267 virtual ~AccountField() {}
269 protected:
270 PurpleRequestField *field;
272 void onAccountChanged(CppConsUI::Button &activator, size_t new_entry,
273 const char *title, intptr_t data);
275 private:
276 CONSUI_DISABLE_COPY(AccountField);
279 virtual void responseHandler(
280 CppConsUI::SplitDialog &activator, ResponseType response);
282 private:
283 CONSUI_DISABLE_COPY(FieldsDialog);
286 typedef std::set<RequestDialog *> Requests;
288 Requests requests;
290 PurpleRequestUiOps centerim_request_ui_ops;
292 static Request *my_instance;
294 Request();
295 ~Request();
296 CONSUI_DISABLE_COPY(Request);
298 static void init();
299 static void finalize();
300 friend class CenterIM;
302 void onDialogResponse(CppConsUI::SplitDialog &dialog,
303 CppConsUI::AbstractDialog::ResponseType response);
305 static void *request_input_(const char *title, const char *primary,
306 const char *secondary, const char *default_value, gboolean multiline,
307 gboolean masked, char *hint, const char *ok_text, GCallback ok_cb,
308 const char *cancel_text, GCallback cancel_cb, PurpleAccount *account,
309 const char *who, PurpleConversation *conv, void *user_data)
311 return REQUEST->request_input(title, primary, secondary, default_value,
312 multiline, masked, hint, ok_text, ok_cb, cancel_text, cancel_cb, account,
313 who, conv, user_data);
315 static void *request_choice_(const char *title, const char *primary,
316 const char *secondary, int default_value, const char *ok_text,
317 GCallback ok_cb, const char *cancel_text, GCallback cancel_cb,
318 PurpleAccount *account, const char *who, PurpleConversation *conv,
319 void *user_data, va_list choices)
321 return REQUEST->request_choice(title, primary, secondary, default_value,
322 ok_text, ok_cb, cancel_text, cancel_cb, account, who, conv, user_data,
323 choices);
325 static void *request_action_(const char *title, const char *primary,
326 const char *secondary, int default_action, PurpleAccount *account,
327 const char *who, PurpleConversation *conv, void *user_data,
328 size_t action_count, va_list actions)
330 return REQUEST->request_action(title, primary, secondary, default_action,
331 account, who, conv, user_data, action_count, actions);
333 static void *request_fields_(const char *title, const char *primary,
334 const char *secondary, PurpleRequestFields *fields, const char *ok_text,
335 GCallback ok_cb, const char *cancel_text, GCallback cancel_cb,
336 PurpleAccount *account, const char *who, PurpleConversation *conv,
337 void *user_data)
339 return REQUEST->request_fields(title, primary, secondary, fields, ok_text,
340 ok_cb, cancel_text, cancel_cb, account, who, conv, user_data);
342 static void *request_file_(const char *title, const char *filename,
343 gboolean savedialog, GCallback ok_cb, GCallback cancel_cb,
344 PurpleAccount *account, const char *who, PurpleConversation *conv,
345 void *user_data)
347 return REQUEST->request_file(title, filename, savedialog, ok_cb, cancel_cb,
348 account, who, conv, user_data);
350 static void close_request_(PurpleRequestType type, void *ui_handle)
352 REQUEST->close_request(type, ui_handle);
354 static void *request_folder_(const char *title, const char *dirname,
355 GCallback ok_cb, GCallback cancel_cb, PurpleAccount *account,
356 const char *who, PurpleConversation *conv, void *user_data)
358 return REQUEST->request_folder(
359 title, dirname, ok_cb, cancel_cb, account, who, conv, user_data);
361 static void *request_action_with_icon_(const char *title, const char *primary,
362 const char *secondary, int default_action, PurpleAccount *account,
363 const char *who, PurpleConversation *conv, gconstpointer icon_data,
364 gsize icon_size, void *user_data, size_t action_count, va_list actions)
366 return REQUEST->request_action_with_icon(title, primary, secondary,
367 default_action, account, who, conv, icon_data, icon_size, user_data,
368 action_count, actions);
371 void *request_input(const char *title, const char *primary,
372 const char *secondary, const char *default_value, gboolean multiline,
373 gboolean masked, char *hint, const char *ok_text, GCallback ok_cb,
374 const char *cancel_text, GCallback cancel_cb, PurpleAccount *account,
375 const char *who, PurpleConversation *conv, void *user_data);
376 void *request_choice(const char *title, const char *primary,
377 const char *secondary, int default_value, const char *ok_text,
378 GCallback ok_cb, const char *cancel_text, GCallback cancel_cb,
379 PurpleAccount *account, const char *who, PurpleConversation *conv,
380 void *user_data, va_list choices);
381 void *request_action(const char *title, const char *primary,
382 const char *secondary, int default_action, PurpleAccount *account,
383 const char *who, PurpleConversation *conv, void *user_data,
384 size_t action_count, va_list actions);
385 void *request_fields(const char *title, const char *primary,
386 const char *secondary, PurpleRequestFields *fields, 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);
390 void *request_file(const char *title, const char *filename,
391 gboolean savedialog, GCallback ok_cb, GCallback cancel_cb,
392 PurpleAccount *account, const char *who, PurpleConversation *conv,
393 void *user_data);
394 void close_request(PurpleRequestType type, void *ui_handle);
395 void *request_folder(const char *title, const char *dirname, GCallback ok_cb,
396 GCallback cancel_cb, PurpleAccount *account, const char *who,
397 PurpleConversation *conv, void *user_data);
398 void *request_action_with_icon(const char *title, const char *primary,
399 const char *secondary, int default_action, PurpleAccount *account,
400 const char *who, PurpleConversation *conv, gconstpointer icon_data,
401 gsize icon_size, void *user_data, size_t action_count, va_list actions);
404 #endif // __REQUEST_H__
406 /* vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab : */