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