Mercurial > pidgin.yaz
annotate finch/gntrequest.c @ 16067:361c15e0b320
some doc changes
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 11 Apr 2007 18:02:18 +0000 |
parents | 0f1ab43db297 |
children | 87019c619be0 |
rev | line source |
---|---|
15818 | 1 /** |
2 * @file gntrequest.c GNT Request API | |
3 * @ingroup gntui | |
4 * | |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15844
diff
changeset
|
5 * finch |
15818 | 6 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15844
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15818 | 8 * to list here. Please refer to the COPYRIGHT file distributed with this |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #include <gnt.h> | |
26 #include <gntbox.h> | |
27 #include <gntbutton.h> | |
28 #include <gntcheckbox.h> | |
29 #include <gntcombobox.h> | |
30 #include <gntentry.h> | |
15930
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
31 #include <gntfilesel.h> |
15818 | 32 #include <gntlabel.h> |
33 #include <gntline.h> | |
34 #include <gnttree.h> | |
35 | |
15823 | 36 #include "finch.h" |
15818 | 37 #include "gntrequest.h" |
38 #include "util.c" | |
39 | |
40 typedef struct | |
41 { | |
42 void *user_data; | |
15930
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
43 GntWidget *dialog; |
15818 | 44 GCallback *cbs; |
15823 | 45 } PurpleGntFileRequest; |
15818 | 46 |
47 static GntWidget * | |
48 setup_request_window(const char *title, const char *primary, | |
15823 | 49 const char *secondary, PurpleRequestType type) |
15818 | 50 { |
51 GntWidget *window; | |
52 | |
53 window = gnt_vbox_new(FALSE); | |
54 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | |
55 gnt_box_set_title(GNT_BOX(window), title); | |
56 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID); | |
57 | |
58 if (primary) | |
59 gnt_box_add_widget(GNT_BOX(window), | |
60 gnt_label_new_with_format(primary, GNT_TEXT_FLAG_BOLD)); | |
61 if (secondary) | |
62 gnt_box_add_widget(GNT_BOX(window), gnt_label_new(secondary)); | |
63 | |
15823 | 64 g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(purple_request_close), |
15818 | 65 GINT_TO_POINTER(type)); |
66 | |
67 return window; | |
68 } | |
69 | |
70 static GntWidget * | |
71 setup_button_box(gpointer userdata, gpointer cb, gpointer data, ...) | |
72 { | |
73 GntWidget *box, *button; | |
74 va_list list; | |
75 const char *text; | |
76 gpointer callback; | |
77 | |
78 box = gnt_hbox_new(FALSE); | |
79 | |
80 va_start(list, data); | |
81 | |
82 while ((text = va_arg(list, const char *))) | |
83 { | |
84 callback = va_arg(list, gpointer); | |
85 button = gnt_button_new(text); | |
86 gnt_box_add_widget(GNT_BOX(box), button); | |
87 g_object_set_data(G_OBJECT(button), "activate-callback", callback); | |
88 g_object_set_data(G_OBJECT(button), "activate-userdata", userdata); | |
89 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(cb), data); | |
90 } | |
91 | |
92 va_end(list); | |
93 return box; | |
94 } | |
95 | |
96 static void | |
97 notify_input_cb(GntWidget *button, GntWidget *entry) | |
98 { | |
15823 | 99 PurpleRequestInputCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); |
15818 | 100 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); |
101 const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); | |
102 | |
103 if (callback) | |
104 callback(data, text); | |
105 | |
106 while (button->parent) | |
107 button = button->parent; | |
108 | |
15823 | 109 purple_request_close(PURPLE_REQUEST_INPUT, button); |
15818 | 110 } |
111 | |
112 static void * | |
113 finch_request_input(const char *title, const char *primary, | |
114 const char *secondary, const char *default_value, | |
115 gboolean multiline, gboolean masked, gchar *hint, | |
116 const char *ok_text, GCallback ok_cb, | |
117 const char *cancel_text, GCallback cancel_cb, | |
118 void *user_data) | |
119 { | |
120 GntWidget *window, *box, *entry; | |
121 | |
15823 | 122 window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_INPUT); |
15818 | 123 |
124 entry = gnt_entry_new(default_value); | |
125 if (masked) | |
126 gnt_entry_set_masked(GNT_ENTRY(entry), TRUE); | |
127 gnt_box_add_widget(GNT_BOX(window), entry); | |
128 | |
129 box = setup_button_box(user_data, notify_input_cb, entry, | |
130 ok_text, ok_cb, cancel_text, cancel_cb, NULL); | |
131 gnt_box_add_widget(GNT_BOX(window), box); | |
132 | |
133 gnt_widget_show(window); | |
134 | |
135 return window; | |
136 } | |
137 | |
138 static void | |
15823 | 139 finch_close_request(PurpleRequestType type, gpointer ui_handle) |
15818 | 140 { |
141 GntWidget *widget = GNT_WIDGET(ui_handle); | |
142 while (widget->parent) | |
143 widget = widget->parent; | |
144 gnt_widget_destroy(widget); | |
145 } | |
146 | |
147 static void | |
148 request_choice_cb(GntWidget *button, GntComboBox *combo) | |
149 { | |
15823 | 150 PurpleRequestChoiceCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); |
15818 | 151 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); |
152 int choice = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo))) - 1; | |
153 | |
154 if (callback) | |
155 callback(data, choice); | |
156 | |
157 while (button->parent) | |
158 button = button->parent; | |
159 | |
15823 | 160 purple_request_close(PURPLE_REQUEST_INPUT, button); |
15818 | 161 } |
162 | |
163 static void * | |
164 finch_request_choice(const char *title, const char *primary, | |
165 const char *secondary, unsigned int default_value, | |
166 const char *ok_text, GCallback ok_cb, | |
167 const char *cancel_text, GCallback cancel_cb, | |
168 void *user_data, va_list choices) | |
169 { | |
170 GntWidget *window, *combo, *box; | |
171 const char *text; | |
172 int val; | |
173 | |
15823 | 174 window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_CHOICE); |
15818 | 175 |
176 combo = gnt_combo_box_new(); | |
177 gnt_box_add_widget(GNT_BOX(window), combo); | |
178 while ((text = va_arg(choices, const char *))) | |
179 { | |
180 val = va_arg(choices, int); | |
181 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(val + 1), text); | |
182 } | |
183 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), GINT_TO_POINTER(default_value + 1)); | |
184 | |
185 box = setup_button_box(user_data, request_choice_cb, combo, | |
186 ok_text, ok_cb, cancel_text, cancel_cb, NULL); | |
187 gnt_box_add_widget(GNT_BOX(window), box); | |
188 | |
189 gnt_widget_show(window); | |
190 | |
191 return window; | |
192 } | |
193 | |
194 static void | |
195 request_action_cb(GntWidget *button, GntWidget *window) | |
196 { | |
15823 | 197 PurpleRequestActionCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); |
15818 | 198 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); |
199 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button), "activate-id")); | |
200 | |
201 if (callback) | |
202 callback(data, id); | |
203 | |
15823 | 204 purple_request_close(PURPLE_REQUEST_ACTION, window); |
15818 | 205 } |
206 | |
207 static void* | |
208 finch_request_action(const char *title, const char *primary, | |
209 const char *secondary, unsigned int default_value, | |
210 void *user_data, size_t actioncount, | |
211 va_list actions) | |
212 { | |
213 GntWidget *window, *box, *button; | |
214 int i; | |
215 | |
15823 | 216 window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_ACTION); |
15818 | 217 |
218 box = gnt_hbox_new(FALSE); | |
219 gnt_box_add_widget(GNT_BOX(window), box); | |
220 for (i = 0; i < actioncount; i++) | |
221 { | |
222 const char *text = va_arg(actions, const char *); | |
15823 | 223 PurpleRequestActionCb callback = va_arg(actions, PurpleRequestActionCb); |
15818 | 224 |
225 button = gnt_button_new(text); | |
226 gnt_box_add_widget(GNT_BOX(box), button); | |
227 | |
228 g_object_set_data(G_OBJECT(button), "activate-callback", callback); | |
229 g_object_set_data(G_OBJECT(button), "activate-userdata", user_data); | |
230 g_object_set_data(G_OBJECT(button), "activate-id", GINT_TO_POINTER(i)); | |
231 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(request_action_cb), window); | |
232 } | |
233 | |
234 gnt_widget_show(window); | |
235 | |
236 return window; | |
237 } | |
238 | |
239 static void | |
15823 | 240 request_fields_cb(GntWidget *button, PurpleRequestFields *fields) |
15818 | 241 { |
15823 | 242 PurpleRequestFieldsCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); |
15818 | 243 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); |
244 GList *list; | |
245 | |
15823 | 246 /* Update the data of the fields. GtkPurple does this differently. Instead of |
15818 | 247 * updating the fields at the end like here, it updates the appropriate field |
248 * instantly whenever a change is made. That allows it to make sure the | |
249 * 'required' fields are entered before the user can hit OK. It's not the case | |
250 * here, althought it can be done. I am not honouring the 'required' fields | |
251 * for the moment. */ | |
15823 | 252 for (list = purple_request_fields_get_groups(fields); list; list = list->next) |
15818 | 253 { |
15823 | 254 PurpleRequestFieldGroup *group = list->data; |
255 GList *fields = purple_request_field_group_get_fields(group); | |
15818 | 256 |
257 for (; fields ; fields = fields->next) | |
258 { | |
15823 | 259 PurpleRequestField *field = fields->data; |
260 PurpleRequestFieldType type = purple_request_field_get_type(field); | |
261 if (type == PURPLE_REQUEST_FIELD_BOOLEAN) | |
15818 | 262 { |
263 GntWidget *check = field->ui_data; | |
264 gboolean value = gnt_check_box_get_checked(GNT_CHECK_BOX(check)); | |
15823 | 265 purple_request_field_bool_set_value(field, value); |
15818 | 266 } |
15823 | 267 else if (type == PURPLE_REQUEST_FIELD_STRING) |
15818 | 268 { |
269 GntWidget *entry = field->ui_data; | |
270 const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); | |
15823 | 271 purple_request_field_string_set_value(field, (text && *text) ? text : NULL); |
15818 | 272 } |
15823 | 273 else if (type == PURPLE_REQUEST_FIELD_INTEGER) |
15818 | 274 { |
275 GntWidget *entry = field->ui_data; | |
276 const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); | |
277 int value = (text && *text) ? atoi(text) : 0; | |
15823 | 278 purple_request_field_int_set_value(field, value); |
15818 | 279 } |
15823 | 280 else if (type == PURPLE_REQUEST_FIELD_CHOICE) |
15818 | 281 { |
282 GntWidget *combo = field->ui_data; | |
283 int id; | |
284 id = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo))); | |
15823 | 285 purple_request_field_choice_set_value(field, id); |
15818 | 286 } |
15823 | 287 else if (type == PURPLE_REQUEST_FIELD_LIST) |
15818 | 288 { |
289 GList *list = NULL; | |
15823 | 290 if (purple_request_field_list_get_multi_select(field)) |
15818 | 291 { |
292 const GList *iter; | |
293 GntWidget *tree = field->ui_data; | |
294 | |
15823 | 295 iter = purple_request_field_list_get_items(field); |
15818 | 296 for (; iter; iter = iter->next) |
297 { | |
298 const char *text = iter->data; | |
15823 | 299 gpointer key = purple_request_field_list_get_data(field, text); |
15818 | 300 if (gnt_tree_get_choice(GNT_TREE(tree), key)) |
301 list = g_list_prepend(list, key); | |
302 } | |
303 } | |
304 else | |
305 { | |
306 GntWidget *combo = field->ui_data; | |
307 gpointer data = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)); | |
308 list = g_list_append(list, data); | |
309 } | |
310 | |
15823 | 311 purple_request_field_list_set_selected(field, list); |
15818 | 312 g_list_free(list); |
313 } | |
15823 | 314 else if (type == PURPLE_REQUEST_FIELD_ACCOUNT) |
15818 | 315 { |
316 GntWidget *combo = field->ui_data; | |
15823 | 317 PurpleAccount *acc = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)); |
318 purple_request_field_account_set_value(field, acc); | |
15818 | 319 } |
320 } | |
321 } | |
322 | |
323 if (callback) | |
324 callback(data, fields); | |
325 | |
326 while (button->parent) | |
327 button = button->parent; | |
328 | |
15823 | 329 purple_request_close(PURPLE_REQUEST_FIELDS, button); |
15818 | 330 } |
331 | |
332 static void * | |
333 finch_request_fields(const char *title, const char *primary, | |
15823 | 334 const char *secondary, PurpleRequestFields *allfields, |
15818 | 335 const char *ok, GCallback ok_cb, |
336 const char *cancel, GCallback cancel_cb, | |
337 void *userdata) | |
338 { | |
339 GntWidget *window, *box; | |
340 GList *grlist; | |
341 | |
15823 | 342 window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_FIELDS); |
15818 | 343 |
344 /* This is how it's going to work: the request-groups are going to be | |
345 * stacked vertically one after the other. A GntLine will be separating | |
346 * the groups. */ | |
347 box = gnt_vbox_new(FALSE); | |
348 gnt_box_set_pad(GNT_BOX(box), 0); | |
349 gnt_box_set_fill(GNT_BOX(box), TRUE); | |
15823 | 350 for (grlist = purple_request_fields_get_groups(allfields); grlist; grlist = grlist->next) |
15818 | 351 { |
15823 | 352 PurpleRequestFieldGroup *group = grlist->data; |
353 GList *fields = purple_request_field_group_get_fields(group); | |
15818 | 354 GntWidget *hbox; |
15823 | 355 const char *title = purple_request_field_group_get_title(group); |
15818 | 356 |
357 if (title) | |
358 gnt_box_add_widget(GNT_BOX(box), | |
359 gnt_label_new_with_format(title, GNT_TEXT_FLAG_BOLD)); | |
360 | |
361 for (; fields ; fields = fields->next) | |
362 { | |
363 /* XXX: Break each of the fields into a separate function? */ | |
15823 | 364 PurpleRequestField *field = fields->data; |
365 PurpleRequestFieldType type = purple_request_field_get_type(field); | |
366 const char *label = purple_request_field_get_label(field); | |
15818 | 367 |
368 hbox = gnt_hbox_new(TRUE); /* hrm */ | |
369 gnt_box_add_widget(GNT_BOX(box), hbox); | |
370 | |
15823 | 371 if (type != PURPLE_REQUEST_FIELD_BOOLEAN && label) |
15818 | 372 { |
373 GntWidget *l = gnt_label_new(label); | |
374 gnt_widget_set_size(l, 0, 1); | |
375 gnt_box_add_widget(GNT_BOX(hbox), l); | |
376 } | |
377 | |
15823 | 378 if (type == PURPLE_REQUEST_FIELD_BOOLEAN) |
15818 | 379 { |
380 GntWidget *check = gnt_check_box_new(label); | |
381 gnt_check_box_set_checked(GNT_CHECK_BOX(check), | |
15823 | 382 purple_request_field_bool_get_default_value(field)); |
15818 | 383 gnt_box_add_widget(GNT_BOX(hbox), check); |
384 field->ui_data = check; | |
385 } | |
15823 | 386 else if (type == PURPLE_REQUEST_FIELD_STRING) |
15818 | 387 { |
15830 | 388 const char *hint = purple_request_field_get_type_hint(field); |
15818 | 389 GntWidget *entry = gnt_entry_new( |
15823 | 390 purple_request_field_string_get_default_value(field)); |
15818 | 391 gnt_entry_set_masked(GNT_ENTRY(entry), |
15823 | 392 purple_request_field_string_is_masked(field)); |
15830 | 393 if (purple_str_has_prefix(hint, "screenname")) { |
394 PurpleBlistNode *node = purple_blist_get_root(); | |
395 gboolean offline = purple_str_has_suffix(hint, "all"); | |
396 for (; node; node = purple_blist_node_next(node, offline)) { | |
397 if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) | |
15827
f59cfcce68a8
Add auto-complete support in request-entries that have 'screenname' hint set. This can be useful in, for example, 'send im' dialog etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
398 continue; |
15830 | 399 gnt_entry_add_suggest(GNT_ENTRY(entry), purple_buddy_get_name((PurpleBuddy*)node)); |
15827
f59cfcce68a8
Add auto-complete support in request-entries that have 'screenname' hint set. This can be useful in, for example, 'send im' dialog etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
400 } |
f59cfcce68a8
Add auto-complete support in request-entries that have 'screenname' hint set. This can be useful in, for example, 'send im' dialog etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
401 gnt_entry_set_always_suggest(GNT_ENTRY(entry), TRUE); |
15844
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15830
diff
changeset
|
402 } else if (hint && !strcmp(hint, "group")) { |
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15830
diff
changeset
|
403 PurpleBlistNode *node; |
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15830
diff
changeset
|
404 for (node = purple_blist_get_root(); node; node = node->next) { |
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15830
diff
changeset
|
405 if (PURPLE_BLIST_NODE_IS_GROUP(node)) |
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15830
diff
changeset
|
406 gnt_entry_add_suggest(GNT_ENTRY(entry), ((PurpleGroup *)node)->name); |
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15830
diff
changeset
|
407 } |
15827
f59cfcce68a8
Add auto-complete support in request-entries that have 'screenname' hint set. This can be useful in, for example, 'send im' dialog etc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
408 } |
15818 | 409 gnt_box_add_widget(GNT_BOX(hbox), entry); |
410 field->ui_data = entry; | |
411 } | |
15823 | 412 else if (type == PURPLE_REQUEST_FIELD_INTEGER) |
15818 | 413 { |
414 char str[256]; | |
15823 | 415 int val = purple_request_field_int_get_default_value(field); |
15818 | 416 GntWidget *entry; |
417 | |
418 snprintf(str, sizeof(str), "%d", val); | |
419 entry = gnt_entry_new(str); | |
420 gnt_entry_set_flag(GNT_ENTRY(entry), GNT_ENTRY_FLAG_INT); | |
421 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
422 field->ui_data = entry; | |
423 } | |
15823 | 424 else if (type == PURPLE_REQUEST_FIELD_CHOICE) |
15818 | 425 { |
426 int id; | |
427 const GList *list; | |
428 GntWidget *combo = gnt_combo_box_new(); | |
429 gnt_box_add_widget(GNT_BOX(hbox), combo); | |
430 field->ui_data = combo; | |
431 | |
15823 | 432 list = purple_request_field_choice_get_labels(field); |
15818 | 433 for (id = 1; list; list = list->next, id++) |
434 { | |
435 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), | |
436 GINT_TO_POINTER(id), list->data); | |
437 } | |
438 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), | |
15823 | 439 GINT_TO_POINTER(purple_request_field_choice_get_default_value(field))); |
15818 | 440 } |
15823 | 441 else if (type == PURPLE_REQUEST_FIELD_LIST) |
15818 | 442 { |
443 const GList *list; | |
15823 | 444 gboolean multi = purple_request_field_list_get_multi_select(field); |
15818 | 445 if (multi) |
446 { | |
447 GntWidget *tree = gnt_tree_new(); | |
448 gnt_box_add_widget(GNT_BOX(hbox), tree); | |
449 field->ui_data = tree; | |
450 | |
15823 | 451 list = purple_request_field_list_get_items(field); |
15818 | 452 for (; list; list = list->next) |
453 { | |
454 const char *text = list->data; | |
15823 | 455 gpointer key = purple_request_field_list_get_data(field, text); |
15818 | 456 gnt_tree_add_choice(GNT_TREE(tree), key, |
457 gnt_tree_create_row(GNT_TREE(tree), text), NULL, NULL); | |
15823 | 458 if (purple_request_field_list_is_selected(field, text)) |
15818 | 459 gnt_tree_set_choice(GNT_TREE(tree), key, TRUE); |
460 } | |
461 } | |
462 else | |
463 { | |
464 GntWidget *combo = gnt_combo_box_new(); | |
465 gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); | |
466 gnt_box_add_widget(GNT_BOX(hbox), combo); | |
467 field->ui_data = combo; | |
468 | |
15823 | 469 list = purple_request_field_list_get_items(field); |
15818 | 470 for (; list; list = list->next) |
471 { | |
472 const char *text = list->data; | |
15823 | 473 gpointer key = purple_request_field_list_get_data(field, text); |
15818 | 474 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), key, text); |
15823 | 475 if (purple_request_field_list_is_selected(field, text)) |
15818 | 476 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), key); |
477 } | |
478 } | |
479 } | |
15823 | 480 else if (type == PURPLE_REQUEST_FIELD_ACCOUNT) |
15818 | 481 { |
482 gboolean all; | |
15823 | 483 PurpleAccount *def; |
15818 | 484 GList *list; |
485 GntWidget *combo = gnt_combo_box_new(); | |
486 gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); | |
487 gnt_box_add_widget(GNT_BOX(hbox), combo); | |
488 field->ui_data = combo; | |
489 | |
15823 | 490 all = purple_request_field_account_get_show_all(field); |
491 def = purple_request_field_account_get_default_value(field); | |
15818 | 492 |
493 if (all) | |
15823 | 494 list = purple_accounts_get_all(); |
15818 | 495 else |
15823 | 496 list = purple_connections_get_all(); |
15818 | 497 |
498 for (; list; list = list->next) | |
499 { | |
15823 | 500 PurpleAccount *account; |
15818 | 501 char *text; |
502 | |
503 if (all) | |
504 account = list->data; | |
505 else | |
15823 | 506 account = purple_connection_get_account(list->data); |
15818 | 507 |
508 text = g_strdup_printf("%s (%s)", | |
15823 | 509 purple_account_get_username(account), |
510 purple_account_get_protocol_name(account)); | |
15818 | 511 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), account, text); |
512 g_free(text); | |
513 if (account == def) | |
514 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), account); | |
515 } | |
516 gnt_widget_set_size(combo, 20, 3); /* ew */ | |
517 } | |
518 else | |
519 { | |
520 gnt_box_add_widget(GNT_BOX(hbox), | |
521 gnt_label_new_with_format(_("Not implemented yet."), | |
522 GNT_TEXT_FLAG_BOLD)); | |
523 } | |
524 } | |
525 if (grlist->next) | |
526 gnt_box_add_widget(GNT_BOX(box), gnt_hline_new()); | |
527 } | |
528 gnt_box_add_widget(GNT_BOX(window), box); | |
529 | |
530 box = setup_button_box(userdata, request_fields_cb, allfields, | |
531 ok, ok_cb, cancel, cancel_cb, NULL); | |
532 gnt_box_add_widget(GNT_BOX(window), box); | |
533 | |
534 gnt_widget_show(window); | |
535 | |
536 return window; | |
537 } | |
538 | |
539 static void | |
540 file_cancel_cb(GntWidget *wid, gpointer fq) | |
541 { | |
15823 | 542 PurpleGntFileRequest *data = fq; |
15818 | 543 if (data->cbs[1] != NULL) |
15823 | 544 ((PurpleRequestFileCb)data->cbs[1])(data->user_data, NULL); |
15818 | 545 |
15823 | 546 purple_request_close(PURPLE_REQUEST_FILE, data->dialog); |
15818 | 547 } |
548 | |
549 static void | |
550 file_ok_cb(GntWidget *wid, gpointer fq) | |
551 { | |
15823 | 552 PurpleGntFileRequest *data = fq; |
15930
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
553 char *file = gnt_file_sel_get_selected_file(GNT_FILE_SEL(data->dialog)); |
15818 | 554 if (data->cbs[0] != NULL) |
15930
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
555 ((PurpleRequestFileCb)data->cbs[0])(data->user_data, file); |
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
556 g_free(file); |
15818 | 557 |
15823 | 558 purple_request_close(PURPLE_REQUEST_FILE, data->dialog); |
15818 | 559 } |
560 | |
561 static void | |
15823 | 562 file_request_destroy(PurpleGntFileRequest *data) |
15818 | 563 { |
564 g_free(data->cbs); | |
565 g_free(data); | |
566 } | |
567 | |
568 static void * | |
569 finch_request_file(const char *title, const char *filename, | |
570 gboolean savedialog, | |
571 GCallback ok_cb, GCallback cancel_cb, | |
572 void *user_data) | |
573 { | |
15930
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
574 GntWidget *window = gnt_file_sel_new(); |
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
575 GntFileSel *sel = GNT_FILE_SEL(window); |
15823 | 576 PurpleGntFileRequest *data = g_new0(PurpleGntFileRequest, 1); |
15818 | 577 |
578 data->user_data = user_data; | |
579 data->cbs = g_new0(GCallback, 2); | |
580 data->cbs[0] = ok_cb; | |
581 data->cbs[1] = cancel_cb; | |
582 data->dialog = window; | |
583 gnt_box_set_title(GNT_BOX(window), title ? title : (savedialog ? _("Save File...") : _("Open File..."))); | |
15930
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
584 gnt_file_sel_set_current_location(sel, purple_home_dir()); /* XXX: */ |
15939 | 585 if (savedialog) |
586 gnt_file_sel_set_suggested_filename(sel, filename); | |
15930
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
587 g_signal_connect(G_OBJECT(sel->cancel), "activate", |
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
588 G_CALLBACK(file_cancel_cb), data); |
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
589 g_signal_connect(G_OBJECT(sel->select), "activate", |
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
590 G_CALLBACK(file_ok_cb), data); |
15818 | 591 g_signal_connect_swapped(G_OBJECT(window), "destroy", |
592 G_CALLBACK(file_request_destroy), data); | |
593 | |
594 gnt_widget_show(window); | |
595 | |
596 return window; | |
597 } | |
598 | |
15823 | 599 static PurpleRequestUiOps uiops = |
15818 | 600 { |
601 .request_input = finch_request_input, | |
602 .close_request = finch_close_request, | |
603 .request_choice = finch_request_choice, | |
604 .request_action = finch_request_action, | |
605 .request_fields = finch_request_fields, | |
606 .request_file = finch_request_file, | |
607 .request_folder = NULL /* No plans for this */ | |
608 }; | |
609 | |
15823 | 610 PurpleRequestUiOps *finch_request_get_ui_ops() |
15818 | 611 { |
612 return &uiops; | |
613 } | |
614 | |
615 void finch_request_init() | |
616 { | |
617 } | |
618 | |
619 void finch_request_uninit() | |
620 { | |
621 } | |
622 |