Mercurial > pidgin.yaz
comparison console/gntrequest.c @ 14047:c5bfede33622
[gaim-migrate @ 16660]
A couple of minor adjustments, memory leak fixes.
And request-ui is almost complete now.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Mon, 07 Aug 2006 02:15:58 +0000 |
parents | 19a1812e6c46 |
children | 9c4bec886220 |
comparison
equal
deleted
inserted
replaced
14046:eb1a7d176149 | 14047:c5bfede33622 |
---|---|
1 #include <gnt.h> | 1 #include <gnt.h> |
2 #include <gntbox.h> | 2 #include <gntbox.h> |
3 #include <gntbutton.h> | 3 #include <gntbutton.h> |
4 #include <gntcheckbox.h> | |
4 #include <gntcombobox.h> | 5 #include <gntcombobox.h> |
5 #include <gntentry.h> | 6 #include <gntentry.h> |
6 #include <gntlabel.h> | 7 #include <gntlabel.h> |
7 | 8 #include <gntline.h> |
9 #include <gnttree.h> | |
10 | |
11 #include "gntgaim.h" | |
8 #include "gntrequest.h" | 12 #include "gntrequest.h" |
9 | 13 |
10 static GntWidget * | 14 static GntWidget * |
11 setup_request_window(const char *title, const char *primary, | 15 setup_request_window(const char *title, const char *primary, |
12 const char *secondary) | 16 const char *secondary, GaimRequestType type) |
13 { | 17 { |
14 GntWidget *window; | 18 GntWidget *window; |
15 | 19 |
16 window = gnt_vbox_new(FALSE); | 20 window = gnt_vbox_new(FALSE); |
17 gnt_box_set_toplevel(GNT_BOX(window), TRUE); | 21 gnt_box_set_toplevel(GNT_BOX(window), TRUE); |
22 gnt_box_add_widget(GNT_BOX(window), | 26 gnt_box_add_widget(GNT_BOX(window), |
23 gnt_label_new_with_format(primary, GNT_TEXT_FLAG_BOLD)); | 27 gnt_label_new_with_format(primary, GNT_TEXT_FLAG_BOLD)); |
24 if (secondary) | 28 if (secondary) |
25 gnt_box_add_widget(GNT_BOX(window), gnt_label_new(secondary)); | 29 gnt_box_add_widget(GNT_BOX(window), gnt_label_new(secondary)); |
26 | 30 |
31 g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gaim_request_close), | |
32 GINT_TO_POINTER(type)); | |
33 | |
27 return window; | 34 return window; |
28 } | 35 } |
29 | 36 |
30 static GntWidget * | 37 static GntWidget * |
31 setup_button_box(gpointer userdata, gpointer cb, gpointer data, ...) | 38 setup_button_box(gpointer userdata, gpointer cb, gpointer data, ...) |
33 GntWidget *box, *button; | 40 GntWidget *box, *button; |
34 va_list list; | 41 va_list list; |
35 const char *text; | 42 const char *text; |
36 gpointer callback; | 43 gpointer callback; |
37 | 44 |
38 box = gnt_hbox_new(TRUE); | 45 box = gnt_hbox_new(FALSE); |
39 | 46 |
40 va_start(list, data); | 47 va_start(list, data); |
41 | 48 |
42 while ((text = va_arg(list, const char *))) | 49 while ((text = va_arg(list, const char *))) |
43 { | 50 { |
77 const char *cancel_text, GCallback cancel_cb, | 84 const char *cancel_text, GCallback cancel_cb, |
78 void *user_data) | 85 void *user_data) |
79 { | 86 { |
80 GntWidget *window, *box, *entry; | 87 GntWidget *window, *box, *entry; |
81 | 88 |
82 window = setup_request_window(title, primary, secondary); | 89 window = setup_request_window(title, primary, secondary, GAIM_REQUEST_INPUT); |
83 | 90 |
84 entry = gnt_entry_new(default_value); | 91 entry = gnt_entry_new(default_value); |
85 if (masked) | 92 if (masked) |
86 gnt_entry_set_masked(GNT_ENTRY(entry), TRUE); | 93 gnt_entry_set_masked(GNT_ENTRY(entry), TRUE); |
87 gnt_box_add_widget(GNT_BOX(window), entry); | 94 gnt_box_add_widget(GNT_BOX(window), entry); |
129 { | 136 { |
130 GntWidget *window, *combo, *box; | 137 GntWidget *window, *combo, *box; |
131 const char *text; | 138 const char *text; |
132 int val; | 139 int val; |
133 | 140 |
134 window = setup_request_window(title, primary, secondary); | 141 window = setup_request_window(title, primary, secondary, GAIM_REQUEST_CHOICE); |
135 | 142 |
136 combo = gnt_combo_box_new(); | 143 combo = gnt_combo_box_new(); |
137 gnt_box_add_widget(GNT_BOX(window), combo); | 144 gnt_box_add_widget(GNT_BOX(window), combo); |
138 while ((text = va_arg(choices, const char *))) | 145 while ((text = va_arg(choices, const char *))) |
139 { | 146 { |
171 va_list actions) | 178 va_list actions) |
172 { | 179 { |
173 GntWidget *window, *box, *button; | 180 GntWidget *window, *box, *button; |
174 int i; | 181 int i; |
175 | 182 |
176 window = setup_request_window(title, primary, secondary); | 183 window = setup_request_window(title, primary, secondary, GAIM_REQUEST_ACTION); |
177 | 184 |
178 box = gnt_hbox_new(TRUE); | 185 box = gnt_hbox_new(TRUE); |
179 gnt_box_add_widget(GNT_BOX(window), box); | 186 gnt_box_add_widget(GNT_BOX(window), box); |
180 for (i = 0; i < actioncount; i++) | 187 for (i = 0; i < actioncount; i++) |
181 { | 188 { |
194 gnt_widget_show(window); | 201 gnt_widget_show(window); |
195 | 202 |
196 return window; | 203 return window; |
197 } | 204 } |
198 | 205 |
206 static void | |
207 request_fields_cb(GntWidget *button, GaimRequestFields *fields) | |
208 { | |
209 GaimRequestFieldsCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); | |
210 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); | |
211 GList *list; | |
212 | |
213 /* Update the data of the fields. GtkGaim does this differently. Instead of | |
214 * updating the fields at the end like here, it updates the appropriate field | |
215 * instantly whenever a change is made. That allows it to make sure the | |
216 * 'required' fields are entered before the user can hit OK. It's not the case | |
217 * here, althought it can be done. I am not honouring the 'required' fields | |
218 * for the moment. */ | |
219 for (list = gaim_request_fields_get_groups(fields); list; list = list->next) | |
220 { | |
221 GaimRequestFieldGroup *group = list->data; | |
222 GList *fields = gaim_request_field_group_get_fields(group); | |
223 | |
224 for (; fields ; fields = fields->next) | |
225 { | |
226 GaimRequestField *field = fields->data; | |
227 GaimRequestFieldType type = gaim_request_field_get_type(field); | |
228 if (type == GAIM_REQUEST_FIELD_BOOLEAN) | |
229 { | |
230 GntWidget *check = field->ui_data; | |
231 gboolean value = gnt_check_box_get_checked(GNT_CHECK_BOX(check)); | |
232 gaim_request_field_bool_set_value(field, value); | |
233 } | |
234 else if (type == GAIM_REQUEST_FIELD_STRING) | |
235 { | |
236 GntWidget *entry = field->ui_data; | |
237 gaim_request_field_string_set_value(field, gnt_entry_get_text(GNT_ENTRY(entry))); | |
238 } | |
239 else if (type == GAIM_REQUEST_FIELD_INTEGER) | |
240 { | |
241 GntWidget *entry = field->ui_data; | |
242 const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); | |
243 int value = (text && *text) ? atoi(text) : 0; | |
244 gaim_request_field_int_set_value(field, value); | |
245 } | |
246 else if (type == GAIM_REQUEST_FIELD_CHOICE) | |
247 { | |
248 GntWidget *combo = field->ui_data;; | |
249 int id = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo))); | |
250 gaim_request_field_choice_set_value(field, id); | |
251 } | |
252 else if (type == GAIM_REQUEST_FIELD_LIST) | |
253 { | |
254 GntWidget *tree = field->ui_data; | |
255 gpointer data = gnt_tree_get_selection_data(GNT_TREE(tree)); | |
256 GList *list = g_list_append(NULL, data); /* XXX: Update when multi-select is allowed */ | |
257 gaim_request_field_list_set_selected(field, list); | |
258 g_list_free(list); | |
259 } | |
260 else if (type == GAIM_REQUEST_FIELD_ACCOUNT) | |
261 { | |
262 } | |
263 } | |
264 } | |
265 | |
266 if (callback) | |
267 callback(data, fields); | |
268 | |
269 while (button->parent) | |
270 button = button->parent; | |
271 | |
272 gaim_request_close(GAIM_REQUEST_FIELDS, button); | |
273 } | |
274 | |
275 static void * | |
276 gg_request_fields(const char *title, const char *primary, | |
277 const char *secondary, GaimRequestFields *fields, | |
278 const char *ok, GCallback ok_cb, | |
279 const char *cancel, GCallback cancel_cb, | |
280 void *userdata) | |
281 { | |
282 GntWidget *window, *box; | |
283 GList *list; | |
284 | |
285 window = setup_request_window(title, primary, secondary, GAIM_REQUEST_FIELDS); | |
286 | |
287 /* This is how it's going to work: the request-groups are going to be | |
288 * stacked vertically one after the other. A GntLine will be separating | |
289 * the groups. */ | |
290 box = gnt_vbox_new(FALSE); | |
291 gnt_box_set_pad(GNT_BOX(box), 0); | |
292 gnt_box_set_fill(GNT_BOX(box), TRUE); | |
293 for (list = gaim_request_fields_get_groups(fields); list; list = list->next) | |
294 { | |
295 GaimRequestFieldGroup *group = list->data; | |
296 GList *fields = gaim_request_field_group_get_fields(group); | |
297 GntWidget *hbox; | |
298 | |
299 /* XXX: Do something with the title, perhaps add a bold label */ | |
300 | |
301 for (; fields ; fields = fields->next) | |
302 { | |
303 GaimRequestField *field = fields->data; | |
304 GaimRequestFieldType type = gaim_request_field_get_type(field); | |
305 const char *label = gaim_request_field_get_label(field); | |
306 | |
307 hbox = gnt_hbox_new(FALSE); | |
308 gnt_box_set_pad(GNT_BOX(hbox), 0); | |
309 gnt_box_add_widget(GNT_BOX(box), hbox); | |
310 | |
311 if (type != GAIM_REQUEST_FIELD_BOOLEAN) | |
312 gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(label)); | |
313 | |
314 if (type == GAIM_REQUEST_FIELD_BOOLEAN) | |
315 { | |
316 GntWidget *check = gnt_check_box_new(label); | |
317 gnt_check_box_set_checked(GNT_CHECK_BOX(check), | |
318 gaim_request_field_bool_get_default_value(field)); | |
319 gnt_box_add_widget(GNT_BOX(hbox), check); | |
320 field->ui_data = check; | |
321 } | |
322 else if (type == GAIM_REQUEST_FIELD_STRING) | |
323 { | |
324 GntWidget *entry = gnt_entry_new( | |
325 gaim_request_field_string_get_default_value(field)); | |
326 gnt_entry_set_masked(GNT_ENTRY(entry), | |
327 gaim_request_field_string_is_masked(field)); | |
328 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
329 field->ui_data = entry; | |
330 } | |
331 else if (type == GAIM_REQUEST_FIELD_INTEGER) | |
332 { | |
333 GntWidget *entry = gnt_entry_new( | |
334 gaim_request_field_string_get_default_value(field)); | |
335 gnt_entry_set_flag(GNT_ENTRY(entry), GNT_ENTRY_FLAG_INT); | |
336 gnt_box_add_widget(GNT_BOX(hbox), entry); | |
337 field->ui_data = entry; | |
338 } | |
339 else if (type == GAIM_REQUEST_FIELD_CHOICE) | |
340 { | |
341 int id; | |
342 const GList *list; | |
343 GntWidget *combo = gnt_combo_box_new(); | |
344 gnt_box_add_widget(GNT_BOX(hbox), combo); | |
345 field->ui_data = combo; | |
346 | |
347 list = gaim_request_field_choice_get_labels(field); | |
348 for (id = 1; list; list = list->next, id++) | |
349 { | |
350 gnt_combo_box_add_data(GNT_COMBO_BOX(combo), | |
351 GINT_TO_POINTER(id), list->data); | |
352 } | |
353 gnt_combo_box_set_selected(GNT_COMBO_BOX(combo), | |
354 GINT_TO_POINTER(gaim_request_field_choice_get_default_value(field))); | |
355 } | |
356 else if (type == GAIM_REQUEST_FIELD_LIST) | |
357 { | |
358 /* XXX: Yet to allow multi-select, because the feature is absent in GntTree */ | |
359 const GList *list; | |
360 GntWidget *tree = gnt_tree_new(); | |
361 gnt_box_add_widget(GNT_BOX(hbox), tree); | |
362 field->ui_data = tree; | |
363 | |
364 list = gaim_request_field_list_get_items(field); | |
365 for (; list; list = list->next) | |
366 { | |
367 const char *text = list->data; | |
368 gpointer key = gaim_request_field_list_get_data(field, text); | |
369 gnt_tree_add_row_after(GNT_TREE(tree), key, | |
370 gnt_tree_create_row(GNT_TREE(tree), text), NULL, NULL); | |
371 if (gaim_request_field_list_is_selected(field, text)) | |
372 gnt_tree_set_selected(GNT_TREE(tree), key); | |
373 } | |
374 } | |
375 #if 0 | |
376 else if (type == GAIM_REQUEST_FIELD_ACCOUNT) | |
377 { | |
378 /* XXX: remember to set the field->ui_data */ | |
379 } | |
380 #endif | |
381 else | |
382 { | |
383 gnt_box_add_widget(GNT_BOX(hbox), | |
384 gnt_label_new_with_format(_("Not implemented yet."), | |
385 GNT_TEXT_FLAG_BOLD)); | |
386 } | |
387 if (fields->next) | |
388 gnt_box_add_widget(GNT_BOX(box), gnt_hline_new()); | |
389 } | |
390 } | |
391 gnt_box_add_widget(GNT_BOX(window), box); | |
392 | |
393 box = setup_button_box(userdata, request_fields_cb, fields, | |
394 ok, ok_cb, cancel, cancel_cb, NULL); | |
395 gnt_box_add_widget(GNT_BOX(window), box); | |
396 | |
397 gnt_widget_show(window); | |
398 | |
399 | |
400 return window; | |
401 } | |
402 | |
199 static GaimRequestUiOps uiops = | 403 static GaimRequestUiOps uiops = |
200 { | 404 { |
201 .request_input = gg_request_input, | 405 .request_input = gg_request_input, |
202 .close_request = gg_close_request, | 406 .close_request = gg_close_request, |
203 .request_choice = gg_request_choice, | 407 .request_choice = gg_request_choice, |
204 .request_action = gg_request_action, | 408 .request_action = gg_request_action, |
409 .request_fields = gg_request_fields, | |
410 .request_file = NULL, /* No plans for these */ | |
411 .request_folder = NULL | |
205 }; | 412 }; |
206 | 413 |
207 GaimRequestUiOps *gg_request_get_ui_ops() | 414 GaimRequestUiOps *gg_request_get_ui_ops() |
208 { | 415 { |
209 return &uiops; | 416 return &uiops; |