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/>.
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())
37 static Request
*instance();
41 class RequestDialog
: public CppConsUI::SplitDialog
{
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() {}
49 virtual void onScreenResized();
51 virtual PurpleRequestType
getRequestType() = 0;
58 // convenient var, same as dynamic_cast<ListBox *>(container)
59 CppConsUI::ListBox
*lbox
;
61 virtual void responseHandler(
62 CppConsUI::SplitDialog
&activator
, ResponseType response
) = 0;
65 CONSUI_DISABLE_COPY(RequestDialog
);
68 class InputTextDialog
: public RequestDialog
{
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();
79 CppConsUI::TextEntry
*entry
;
81 virtual void responseHandler(SplitDialog
&activator
, ResponseType response
);
84 CONSUI_DISABLE_COPY(InputTextDialog
);
87 class ChoiceDialog
: public RequestDialog
{
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
,
93 virtual ~ChoiceDialog() {}
95 virtual PurpleRequestType
getRequestType();
98 CppConsUI::ComboBox
*combo
;
100 virtual void responseHandler(SplitDialog
&activator
, ResponseType response
);
103 CONSUI_DISABLE_COPY(ChoiceDialog
);
106 class ActionDialog
: public RequestDialog
{
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();
115 virtual void responseHandler(SplitDialog
&activator
, ResponseType response
);
118 CONSUI_DISABLE_COPY(ActionDialog
);
120 void onActionChoice(CppConsUI::Button
&activator
, size_t i
, GCallback cb
);
123 class FieldsDialog
: public RequestDialog
{
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();
133 PurpleRequestFields
*fields
;
134 CppConsUI::TreeView
*treeview
;
136 class StringField
: public CppConsUI::Button
{
138 StringField(PurpleRequestField
*field
);
139 virtual ~StringField() {}
142 PurpleRequestField
*field
;
144 void onActivate(CppConsUI::Button
&activator
);
145 void responseHandler(CppConsUI::InputDialog
&activator
,
146 CppConsUI::AbstractDialog::ResponseType response
);
149 CONSUI_DISABLE_COPY(StringField
);
152 class IntegerField
: public CppConsUI::Button
{
154 IntegerField(PurpleRequestField
*field
);
155 virtual ~IntegerField() {}
158 PurpleRequestField
*field
;
160 void onActivate(CppConsUI::Button
&activator
);
161 void responseHandler(CppConsUI::InputDialog
&activator
,
162 CppConsUI::AbstractDialog::ResponseType response
);
165 CONSUI_DISABLE_COPY(IntegerField
);
168 class BooleanField
: public CppConsUI::CheckBox
{
170 BooleanField(PurpleRequestField
*field
);
171 virtual ~BooleanField() {}
174 PurpleRequestField
*field
;
176 void onToggle(CppConsUI::CheckBox
&activator
, bool new_state
);
179 CONSUI_DISABLE_COPY(BooleanField
);
182 class ChoiceField
: public CppConsUI::ComboBox
{
184 ChoiceField(PurpleRequestField
*field
);
185 virtual ~ChoiceField() {}
188 PurpleRequestField
*field
;
190 void onSelectionChanged(CppConsUI::ComboBox
&activator
, int new_entry
,
191 const char *title
, intptr_t data
);
194 CONSUI_DISABLE_COPY(ChoiceField
);
197 class ListFieldMultiple
: public CppConsUI::ListBox
{
199 ListFieldMultiple(PurpleRequestField
*field
);
200 virtual ~ListFieldMultiple() {}
203 PurpleRequestField
*field
;
205 class ListFieldItem
: public CppConsUI::CheckBox
{
207 ListFieldItem(PurpleRequestField
*field
, const char *text
);
208 virtual ~ListFieldItem() {}
211 PurpleRequestField
*field
;
213 void onToggle(CppConsUI::CheckBox
&activator
, bool new_state
);
216 CONSUI_DISABLE_COPY(ListFieldItem
);
220 CONSUI_DISABLE_COPY(ListFieldMultiple
);
223 class ListFieldSingle
: public CppConsUI::ComboBox
{
225 ListFieldSingle(PurpleRequestField
*field
);
226 virtual ~ListFieldSingle() {}
229 PurpleRequestField
*field
;
231 void onSelectionChanged(CppConsUI::ComboBox
&activator
, int new_entry
,
232 const char *title
, intptr_t data
);
235 CONSUI_DISABLE_COPY(ListFieldSingle
);
238 class LabelField
: public CppConsUI::Label
{
240 LabelField(PurpleRequestField
*field
);
241 virtual ~LabelField() {}
244 PurpleRequestField
*field
;
247 CONSUI_DISABLE_COPY(LabelField
);
250 class ImageField
: public CppConsUI::Button
{
252 ImageField(PurpleRequestField
*field
);
253 virtual ~ImageField() {}
256 PurpleRequestField
*field
;
258 void onActivate(CppConsUI::Button
&activator
);
261 CONSUI_DISABLE_COPY(ImageField
);
264 class AccountField
: public CppConsUI::ComboBox
{
266 AccountField(PurpleRequestField
*field
);
267 virtual ~AccountField() {}
270 PurpleRequestField
*field
;
272 void onAccountChanged(CppConsUI::Button
&activator
, size_t new_entry
,
273 const char *title
, intptr_t data
);
276 CONSUI_DISABLE_COPY(AccountField
);
279 virtual void responseHandler(
280 CppConsUI::SplitDialog
&activator
, ResponseType response
);
283 CONSUI_DISABLE_COPY(FieldsDialog
);
286 typedef std::set
<RequestDialog
*> Requests
;
290 PurpleRequestUiOps centerim_request_ui_ops
;
292 static Request
*my_instance
;
296 CONSUI_DISABLE_COPY(Request
);
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
,
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
,
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
,
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
,
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
,
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 : */