Mercurial > pidgin.yaz
annotate finch/gntrequest.c @ 16310:8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 22 Apr 2007 23:55:24 +0000 |
parents | 0f0832c13fcb |
children | 08db93bbd798 |
rev | line source |
---|---|
15818 | 1 /** |
2 * @file gntrequest.c GNT Request API | |
16194
0f0832c13fcb
Rename the Doxygen group from gntui to finch and define the finch group
Richard Laager <rlaager@wiktel.com>
parents:
16164
diff
changeset
|
3 * @ingroup finch |
15818 | 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" |
16164
87019c619be0
Include header files, not source files. Bah.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15939
diff
changeset
|
38 #include "util.h" |
15818 | 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); | |
16310
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
142 if (type == PURPLE_REQUEST_FIELDS) { |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
143 PurpleRequestFields *fields = g_object_get_data(G_OBJECT(widget), "fields"); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
144 purple_request_fields_destroy(fields); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
145 } |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
146 |
15818 | 147 while (widget->parent) |
148 widget = widget->parent; | |
149 gnt_widget_destroy(widget); | |
150 } | |
151 | |
152 static void | |
153 request_choice_cb(GntWidget *button, GntComboBox *combo) | |
154 { | |
15823 | 155 PurpleRequestChoiceCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); |
15818 | 156 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); |
157 int choice = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo))) - 1; | |
158 | |
159 if (callback) | |
160 callback(data, choice); | |
161 | |
162 while (button->parent) | |
163 button = button->parent; | |
164 | |
15823 | 165 purple_request_close(PURPLE_REQUEST_INPUT, button); |
15818 | 166 } |
167 | |
168 static void * | |
169 finch_request_choice(const char *title, const char *primary, | |
170 const char *secondary, unsigned int default_value, | |
171 const char *ok_text, GCallback ok_cb, | |
172 const char *cancel_text, GCallback cancel_cb, | |
173 void *user_data, va_list choices) | |
174 { | |
175 GntWidget *window, *combo, *box; | |
176 const char *text; | |
177 int val; | |
178 | |
15823 | 179 window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_CHOICE); |
15818 | 180 |
181 combo = gnt_combo_box_new(); | |
182 gnt_box_add_widget(GNT_BOX(window), combo); | |
183 while ((text = va_arg(choices, const char *))) | |
184 { | |
185 val = va_arg(choices, int); | |
186 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), GINT_TO_POINTER(val + 1), text); | |
187 } | |
188 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), GINT_TO_POINTER(default_value + 1)); | |
189 | |
190 box = setup_button_box(user_data, request_choice_cb, combo, | |
191 ok_text, ok_cb, cancel_text, cancel_cb, NULL); | |
192 gnt_box_add_widget(GNT_BOX(window), box); | |
193 | |
194 gnt_widget_show(window); | |
195 | |
196 return window; | |
197 } | |
198 | |
199 static void | |
200 request_action_cb(GntWidget *button, GntWidget *window) | |
201 { | |
15823 | 202 PurpleRequestActionCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); |
15818 | 203 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); |
204 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button), "activate-id")); | |
205 | |
206 if (callback) | |
207 callback(data, id); | |
208 | |
15823 | 209 purple_request_close(PURPLE_REQUEST_ACTION, window); |
15818 | 210 } |
211 | |
212 static void* | |
213 finch_request_action(const char *title, const char *primary, | |
214 const char *secondary, unsigned int default_value, | |
215 void *user_data, size_t actioncount, | |
216 va_list actions) | |
217 { | |
218 GntWidget *window, *box, *button; | |
219 int i; | |
220 | |
15823 | 221 window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_ACTION); |
15818 | 222 |
223 box = gnt_hbox_new(FALSE); | |
224 gnt_box_add_widget(GNT_BOX(window), box); | |
225 for (i = 0; i < actioncount; i++) | |
226 { | |
227 const char *text = va_arg(actions, const char *); | |
15823 | 228 PurpleRequestActionCb callback = va_arg(actions, PurpleRequestActionCb); |
15818 | 229 |
230 button = gnt_button_new(text); | |
231 gnt_box_add_widget(GNT_BOX(box), button); | |
232 | |
233 g_object_set_data(G_OBJECT(button), "activate-callback", callback); | |
234 g_object_set_data(G_OBJECT(button), "activate-userdata", user_data); | |
235 g_object_set_data(G_OBJECT(button), "activate-id", GINT_TO_POINTER(i)); | |
236 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(request_action_cb), window); | |
237 } | |
238 | |
239 gnt_widget_show(window); | |
240 | |
241 return window; | |
242 } | |
243 | |
244 static void | |
15823 | 245 request_fields_cb(GntWidget *button, PurpleRequestFields *fields) |
15818 | 246 { |
15823 | 247 PurpleRequestFieldsCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); |
15818 | 248 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); |
249 GList *list; | |
250 | |
16310
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
251 /* Update the data of the fields. Pidgin does this differently. Instead of |
15818 | 252 * updating the fields at the end like here, it updates the appropriate field |
253 * instantly whenever a change is made. That allows it to make sure the | |
254 * 'required' fields are entered before the user can hit OK. It's not the case | |
255 * here, althought it can be done. I am not honouring the 'required' fields | |
256 * for the moment. */ | |
15823 | 257 for (list = purple_request_fields_get_groups(fields); list; list = list->next) |
15818 | 258 { |
15823 | 259 PurpleRequestFieldGroup *group = list->data; |
260 GList *fields = purple_request_field_group_get_fields(group); | |
15818 | 261 |
262 for (; fields ; fields = fields->next) | |
263 { | |
15823 | 264 PurpleRequestField *field = fields->data; |
265 PurpleRequestFieldType type = purple_request_field_get_type(field); | |
266 if (type == PURPLE_REQUEST_FIELD_BOOLEAN) | |
15818 | 267 { |
268 GntWidget *check = field->ui_data; | |
269 gboolean value = gnt_check_box_get_checked(GNT_CHECK_BOX(check)); | |
15823 | 270 purple_request_field_bool_set_value(field, value); |
15818 | 271 } |
15823 | 272 else if (type == PURPLE_REQUEST_FIELD_STRING) |
15818 | 273 { |
274 GntWidget *entry = field->ui_data; | |
275 const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); | |
15823 | 276 purple_request_field_string_set_value(field, (text && *text) ? text : NULL); |
15818 | 277 } |
15823 | 278 else if (type == PURPLE_REQUEST_FIELD_INTEGER) |
15818 | 279 { |
280 GntWidget *entry = field->ui_data; | |
281 const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); | |
282 int value = (text && *text) ? atoi(text) : 0; | |
15823 | 283 purple_request_field_int_set_value(field, value); |
15818 | 284 } |
15823 | 285 else if (type == PURPLE_REQUEST_FIELD_CHOICE) |
15818 | 286 { |
287 GntWidget *combo = field->ui_data; | |
288 int id; | |
289 id = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo))); | |
15823 | 290 purple_request_field_choice_set_value(field, id); |
15818 | 291 } |
15823 | 292 else if (type == PURPLE_REQUEST_FIELD_LIST) |
15818 | 293 { |
294 GList *list = NULL; | |
15823 | 295 if (purple_request_field_list_get_multi_select(field)) |
15818 | 296 { |
297 const GList *iter; | |
298 GntWidget *tree = field->ui_data; | |
299 | |
15823 | 300 iter = purple_request_field_list_get_items(field); |
15818 | 301 for (; iter; iter = iter->next) |
302 { | |
303 const char *text = iter->data; | |
15823 | 304 gpointer key = purple_request_field_list_get_data(field, text); |
15818 | 305 if (gnt_tree_get_choice(GNT_TREE(tree), key)) |
306 list = g_list_prepend(list, key); | |
307 } | |
308 } | |
309 else | |
310 { | |
311 GntWidget *combo = field->ui_data; | |
312 gpointer data = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)); | |
313 list = g_list_append(list, data); | |
314 } | |
315 | |
15823 | 316 purple_request_field_list_set_selected(field, list); |
15818 | 317 g_list_free(list); |
318 } | |
15823 | 319 else if (type == PURPLE_REQUEST_FIELD_ACCOUNT) |
15818 | 320 { |
321 GntWidget *combo = field->ui_data; | |
15823 | 322 PurpleAccount *acc = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)); |
323 purple_request_field_account_set_value(field, acc); | |
15818 | 324 } |
325 } | |
326 } | |
327 | |
328 if (callback) | |
329 callback(data, fields); | |
330 | |
331 while (button->parent) | |
332 button = button->parent; | |
333 | |
15823 | 334 purple_request_close(PURPLE_REQUEST_FIELDS, button); |
15818 | 335 } |
336 | |
337 static void * | |
338 finch_request_fields(const char *title, const char *primary, | |
15823 | 339 const char *secondary, PurpleRequestFields *allfields, |
15818 | 340 const char *ok, GCallback ok_cb, |
341 const char *cancel, GCallback cancel_cb, | |
342 void *userdata) | |
343 { | |
344 GntWidget *window, *box; | |
345 GList *grlist; | |
346 | |
15823 | 347 window = setup_request_window(title, primary, secondary, PURPLE_REQUEST_FIELDS); |
15818 | 348 |
349 /* This is how it's going to work: the request-groups are going to be | |
350 * stacked vertically one after the other. A GntLine will be separating | |
351 * the groups. */ | |
352 box = gnt_vbox_new(FALSE); | |
353 gnt_box_set_pad(GNT_BOX(box), 0); | |
354 gnt_box_set_fill(GNT_BOX(box), TRUE); | |
15823 | 355 for (grlist = purple_request_fields_get_groups(allfields); grlist; grlist = grlist->next) |
15818 | 356 { |
15823 | 357 PurpleRequestFieldGroup *group = grlist->data; |
358 GList *fields = purple_request_field_group_get_fields(group); | |
15818 | 359 GntWidget *hbox; |
15823 | 360 const char *title = purple_request_field_group_get_title(group); |
15818 | 361 |
362 if (title) | |
363 gnt_box_add_widget(GNT_BOX(box), | |
364 gnt_label_new_with_format(title, GNT_TEXT_FLAG_BOLD)); | |
365 | |
366 for (; fields ; fields = fields->next) | |
367 { | |
368 /* XXX: Break each of the fields into a separate function? */ | |
15823 | 369 PurpleRequestField *field = fields->data; |
370 PurpleRequestFieldType type = purple_request_field_get_type(field); | |
371 const char *label = purple_request_field_get_label(field); | |
15818 | 372 |
373 hbox = gnt_hbox_new(TRUE); /* hrm */ | |
374 gnt_box_add_widget(GNT_BOX(box), hbox); | |
375 | |
15823 | 376 if (type != PURPLE_REQUEST_FIELD_BOOLEAN && label) |
15818 | 377 { |
378 GntWidget *l = gnt_label_new(label); | |
379 gnt_widget_set_size(l, 0, 1); | |
380 gnt_box_add_widget(GNT_BOX(hbox), l); | |
381 } | |
382 | |
15823 | 383 if (type == PURPLE_REQUEST_FIELD_BOOLEAN) |
15818 | 384 { |
385 GntWidget *check = gnt_check_box_new(label); | |
386 gnt_check_box_set_checked(GNT_CHECK_BOX(check), | |
15823 | 387 purple_request_field_bool_get_default_value(field)); |
15818 | 388 gnt_box_add_widget(GNT_BOX(hbox), check); |
389 field->ui_data = check; | |
390 } | |
15823 | 391 else if (type == PURPLE_REQUEST_FIELD_STRING) |
15818 | 392 { |
15830 | 393 const char *hint = purple_request_field_get_type_hint(field); |
15818 | 394 GntWidget *entry = gnt_entry_new( |
15823 | 395 purple_request_field_string_get_default_value(field)); |
15818 | 396 gnt_entry_set_masked(GNT_ENTRY(entry), |
15823 | 397 purple_request_field_string_is_masked(field)); |
15830 | 398 if (purple_str_has_prefix(hint, "screenname")) { |
399 PurpleBlistNode *node = purple_blist_get_root(); | |
400 gboolean offline = purple_str_has_suffix(hint, "all"); | |
401 for (; node; node = purple_blist_node_next(node, offline)) { | |
402 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
|
403 continue; |
15830 | 404 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
|
405 } |
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
|
406 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
|
407 } else if (hint && !strcmp(hint, "group")) { |
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15830
diff
changeset
|
408 PurpleBlistNode *node; |
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15830
diff
changeset
|
409 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
|
410 if (PURPLE_BLIST_NODE_IS_GROUP(node)) |
e74c2488448b
Group autocomplete for buddy adding
Richard Nelson <wabz@pidgin.im>
parents:
15830
diff
changeset
|
411 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
|
412 } |
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
|
413 } |
15818 | 414 gnt_box_add_widget(GNT_BOX(hbox), entry); |
415 field->ui_data = entry; | |
416 } | |
15823 | 417 else if (type == PURPLE_REQUEST_FIELD_INTEGER) |
15818 | 418 { |
419 char str[256]; | |
15823 | 420 int val = purple_request_field_int_get_default_value(field); |
15818 | 421 GntWidget *entry; |
422 | |
423 snprintf(str, sizeof(str), "%d", val); | |
424 entry = gnt_entry_new(str); | |
425 gnt_entry_set_flag(GNT_ENTRY(entry), GNT_ENTRY_FLAG_INT); | |
426 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
427 field->ui_data = entry; | |
428 } | |
15823 | 429 else if (type == PURPLE_REQUEST_FIELD_CHOICE) |
15818 | 430 { |
431 int id; | |
432 const GList *list; | |
433 GntWidget *combo = gnt_combo_box_new(); | |
434 gnt_box_add_widget(GNT_BOX(hbox), combo); | |
435 field->ui_data = combo; | |
436 | |
15823 | 437 list = purple_request_field_choice_get_labels(field); |
15818 | 438 for (id = 1; list; list = list->next, id++) |
439 { | |
440 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), | |
441 GINT_TO_POINTER(id), list->data); | |
442 } | |
443 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), | |
15823 | 444 GINT_TO_POINTER(purple_request_field_choice_get_default_value(field))); |
15818 | 445 } |
15823 | 446 else if (type == PURPLE_REQUEST_FIELD_LIST) |
15818 | 447 { |
448 const GList *list; | |
15823 | 449 gboolean multi = purple_request_field_list_get_multi_select(field); |
15818 | 450 if (multi) |
451 { | |
452 GntWidget *tree = gnt_tree_new(); | |
453 gnt_box_add_widget(GNT_BOX(hbox), tree); | |
454 field->ui_data = tree; | |
455 | |
15823 | 456 list = purple_request_field_list_get_items(field); |
15818 | 457 for (; list; list = list->next) |
458 { | |
459 const char *text = list->data; | |
15823 | 460 gpointer key = purple_request_field_list_get_data(field, text); |
15818 | 461 gnt_tree_add_choice(GNT_TREE(tree), key, |
462 gnt_tree_create_row(GNT_TREE(tree), text), NULL, NULL); | |
15823 | 463 if (purple_request_field_list_is_selected(field, text)) |
15818 | 464 gnt_tree_set_choice(GNT_TREE(tree), key, TRUE); |
465 } | |
466 } | |
467 else | |
468 { | |
469 GntWidget *combo = gnt_combo_box_new(); | |
470 gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); | |
471 gnt_box_add_widget(GNT_BOX(hbox), combo); | |
472 field->ui_data = combo; | |
473 | |
15823 | 474 list = purple_request_field_list_get_items(field); |
15818 | 475 for (; list; list = list->next) |
476 { | |
477 const char *text = list->data; | |
15823 | 478 gpointer key = purple_request_field_list_get_data(field, text); |
15818 | 479 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), key, text); |
15823 | 480 if (purple_request_field_list_is_selected(field, text)) |
15818 | 481 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), key); |
482 } | |
483 } | |
484 } | |
15823 | 485 else if (type == PURPLE_REQUEST_FIELD_ACCOUNT) |
15818 | 486 { |
487 gboolean all; | |
15823 | 488 PurpleAccount *def; |
15818 | 489 GList *list; |
490 GntWidget *combo = gnt_combo_box_new(); | |
491 gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); | |
492 gnt_box_add_widget(GNT_BOX(hbox), combo); | |
493 field->ui_data = combo; | |
494 | |
15823 | 495 all = purple_request_field_account_get_show_all(field); |
496 def = purple_request_field_account_get_default_value(field); | |
15818 | 497 |
498 if (all) | |
15823 | 499 list = purple_accounts_get_all(); |
15818 | 500 else |
15823 | 501 list = purple_connections_get_all(); |
15818 | 502 |
503 for (; list; list = list->next) | |
504 { | |
15823 | 505 PurpleAccount *account; |
15818 | 506 char *text; |
507 | |
508 if (all) | |
509 account = list->data; | |
510 else | |
15823 | 511 account = purple_connection_get_account(list->data); |
15818 | 512 |
513 text = g_strdup_printf("%s (%s)", | |
15823 | 514 purple_account_get_username(account), |
515 purple_account_get_protocol_name(account)); | |
15818 | 516 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), account, text); |
517 g_free(text); | |
518 if (account == def) | |
519 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), account); | |
520 } | |
521 gnt_widget_set_size(combo, 20, 3); /* ew */ | |
522 } | |
523 else | |
524 { | |
525 gnt_box_add_widget(GNT_BOX(hbox), | |
526 gnt_label_new_with_format(_("Not implemented yet."), | |
527 GNT_TEXT_FLAG_BOLD)); | |
528 } | |
529 } | |
530 if (grlist->next) | |
531 gnt_box_add_widget(GNT_BOX(box), gnt_hline_new()); | |
532 } | |
533 gnt_box_add_widget(GNT_BOX(window), box); | |
534 | |
535 box = setup_button_box(userdata, request_fields_cb, allfields, | |
536 ok, ok_cb, cancel, cancel_cb, NULL); | |
537 gnt_box_add_widget(GNT_BOX(window), box); | |
538 | |
539 gnt_widget_show(window); | |
16310
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
540 |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
541 g_object_set_data(G_OBJECT(window), "fields", allfields); |
15818 | 542 |
543 return window; | |
544 } | |
545 | |
546 static void | |
547 file_cancel_cb(GntWidget *wid, gpointer fq) | |
548 { | |
15823 | 549 PurpleGntFileRequest *data = fq; |
15818 | 550 if (data->cbs[1] != NULL) |
15823 | 551 ((PurpleRequestFileCb)data->cbs[1])(data->user_data, NULL); |
15818 | 552 |
15823 | 553 purple_request_close(PURPLE_REQUEST_FILE, data->dialog); |
15818 | 554 } |
555 | |
556 static void | |
557 file_ok_cb(GntWidget *wid, gpointer fq) | |
558 { | |
15823 | 559 PurpleGntFileRequest *data = fq; |
15930
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
560 char *file = gnt_file_sel_get_selected_file(GNT_FILE_SEL(data->dialog)); |
15818 | 561 if (data->cbs[0] != NULL) |
15930
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
562 ((PurpleRequestFileCb)data->cbs[0])(data->user_data, file); |
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
563 g_free(file); |
15818 | 564 |
15823 | 565 purple_request_close(PURPLE_REQUEST_FILE, data->dialog); |
15818 | 566 } |
567 | |
568 static void | |
15823 | 569 file_request_destroy(PurpleGntFileRequest *data) |
15818 | 570 { |
571 g_free(data->cbs); | |
572 g_free(data); | |
573 } | |
574 | |
575 static void * | |
576 finch_request_file(const char *title, const char *filename, | |
577 gboolean savedialog, | |
578 GCallback ok_cb, GCallback cancel_cb, | |
579 void *user_data) | |
580 { | |
15930
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
581 GntWidget *window = gnt_file_sel_new(); |
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
582 GntFileSel *sel = GNT_FILE_SEL(window); |
15823 | 583 PurpleGntFileRequest *data = g_new0(PurpleGntFileRequest, 1); |
15818 | 584 |
585 data->user_data = user_data; | |
586 data->cbs = g_new0(GCallback, 2); | |
587 data->cbs[0] = ok_cb; | |
588 data->cbs[1] = cancel_cb; | |
589 data->dialog = window; | |
590 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
|
591 gnt_file_sel_set_current_location(sel, purple_home_dir()); /* XXX: */ |
15939 | 592 if (savedialog) |
593 gnt_file_sel_set_suggested_filename(sel, filename); | |
15930
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
594 g_signal_connect(G_OBJECT(sel->cancel), "activate", |
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
595 G_CALLBACK(file_cancel_cb), data); |
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
596 g_signal_connect(G_OBJECT(sel->select), "activate", |
846a00760176
use file select dialog
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15926
diff
changeset
|
597 G_CALLBACK(file_ok_cb), data); |
15818 | 598 g_signal_connect_swapped(G_OBJECT(window), "destroy", |
599 G_CALLBACK(file_request_destroy), data); | |
600 | |
601 gnt_widget_show(window); | |
602 | |
603 return window; | |
604 } | |
605 | |
15823 | 606 static PurpleRequestUiOps uiops = |
15818 | 607 { |
608 .request_input = finch_request_input, | |
609 .close_request = finch_close_request, | |
610 .request_choice = finch_request_choice, | |
611 .request_action = finch_request_action, | |
612 .request_fields = finch_request_fields, | |
613 .request_file = finch_request_file, | |
614 .request_folder = NULL /* No plans for this */ | |
615 }; | |
616 | |
15823 | 617 PurpleRequestUiOps *finch_request_get_ui_ops() |
15818 | 618 { |
619 return &uiops; | |
620 } | |
621 | |
622 void finch_request_init() | |
623 { | |
624 } | |
625 | |
626 void finch_request_uninit() | |
627 { | |
628 } | |
629 | |
16310
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
630 void finch_request_save_in_prefs(gpointer null, PurpleRequestFields *allfields) |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
631 { |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
632 GList *list; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
633 for (list = purple_request_fields_get_groups(allfields); list; list = list->next) { |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
634 PurpleRequestFieldGroup *group = list->data; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
635 GList *fields = purple_request_field_group_get_fields(group); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
636 |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
637 for (; fields ; fields = fields->next) { |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
638 PurpleRequestField *field = fields->data; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
639 PurpleRequestFieldType type = purple_request_field_get_type(field); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
640 PurplePrefType pt; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
641 gpointer val = NULL; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
642 const char *id = purple_request_field_get_id(field); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
643 |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
644 switch (type) { |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
645 case PURPLE_REQUEST_FIELD_LIST: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
646 val = purple_request_field_list_get_selected(field)->data; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
647 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
648 case PURPLE_REQUEST_FIELD_BOOLEAN: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
649 val = GINT_TO_POINTER(purple_request_field_bool_get_value(field)); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
650 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
651 case PURPLE_REQUEST_FIELD_INTEGER: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
652 val = GINT_TO_POINTER(purple_request_field_int_get_value(field)); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
653 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
654 case PURPLE_REQUEST_FIELD_STRING: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
655 val = (gpointer)purple_request_field_string_get_value(field); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
656 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
657 default: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
658 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
659 } |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
660 |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
661 pt = purple_prefs_get_type(id); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
662 switch (pt) { |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
663 case PURPLE_PREF_INT: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
664 if (type == PURPLE_REQUEST_FIELD_LIST) /* Lists always return string */ |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
665 sscanf(val, "%ld", (long int *)&val); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
666 purple_prefs_set_int(id, GPOINTER_TO_INT(val)); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
667 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
668 case PURPLE_PREF_BOOLEAN: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
669 purple_prefs_set_bool(id, GPOINTER_TO_INT(val)); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
670 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
671 case PURPLE_PREF_STRING: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
672 purple_prefs_set_string(id, val); |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
673 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
674 default: |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
675 break; |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
676 } |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
677 } |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
678 } |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
679 } |
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
680 |