comparison finch/gntrequest.c @ 32819:2c6510167895 default tip

propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24) to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 02 Jun 2012 02:30:49 +0000
parents 03dcb0185c82
children
comparison
equal deleted inserted replaced
32818:01ff09d4a463 32819:2c6510167895
39 #include "finch.h" 39 #include "finch.h"
40 #include "gntrequest.h" 40 #include "gntrequest.h"
41 #include "debug.h" 41 #include "debug.h"
42 #include "util.h" 42 #include "util.h"
43 43
44 /* XXX: Until gobjectification ... */
45 #undef FINCH_GET_DATA
46 #undef FINCH_SET_DATA
47 #define FINCH_GET_DATA(obj) purple_request_field_get_ui_data(obj)
48 #define FINCH_SET_DATA(obj, data) purple_request_field_set_ui_data(obj, data)
49
50 typedef struct 44 typedef struct
51 { 45 {
52 void *user_data; 46 void *user_data;
53 GntWidget *dialog; 47 GntWidget *dialog;
54 GCallback *cbs; 48 GCallback *cbs;
321 PurpleRequestFieldType type = purple_request_field_get_type(field); 315 PurpleRequestFieldType type = purple_request_field_get_type(field);
322 if (!purple_request_field_is_visible(field)) 316 if (!purple_request_field_is_visible(field))
323 continue; 317 continue;
324 if (type == PURPLE_REQUEST_FIELD_BOOLEAN) 318 if (type == PURPLE_REQUEST_FIELD_BOOLEAN)
325 { 319 {
326 GntWidget *check = FINCH_GET_DATA(field); 320 GntWidget *check = purple_request_field_get_ui_data(field);
327 gboolean value = gnt_check_box_get_checked(GNT_CHECK_BOX(check)); 321 gboolean value = gnt_check_box_get_checked(GNT_CHECK_BOX(check));
328 purple_request_field_bool_set_value(field, value); 322 purple_request_field_bool_set_value(field, value);
329 } 323 }
330 else if (type == PURPLE_REQUEST_FIELD_STRING) 324 else if (type == PURPLE_REQUEST_FIELD_STRING)
331 { 325 {
332 GntWidget *entry = FINCH_GET_DATA(field); 326 GntWidget *entry = purple_request_field_get_ui_data(field);
333 const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); 327 const char *text = gnt_entry_get_text(GNT_ENTRY(entry));
334 purple_request_field_string_set_value(field, (text && *text) ? text : NULL); 328 purple_request_field_string_set_value(field, (text && *text) ? text : NULL);
335 } 329 }
336 else if (type == PURPLE_REQUEST_FIELD_INTEGER) 330 else if (type == PURPLE_REQUEST_FIELD_INTEGER)
337 { 331 {
338 GntWidget *entry = FINCH_GET_DATA(field); 332 GntWidget *entry = purple_request_field_get_ui_data(field);
339 const char *text = gnt_entry_get_text(GNT_ENTRY(entry)); 333 const char *text = gnt_entry_get_text(GNT_ENTRY(entry));
340 int value = (text && *text) ? atoi(text) : 0; 334 int value = (text && *text) ? atoi(text) : 0;
341 purple_request_field_int_set_value(field, value); 335 purple_request_field_int_set_value(field, value);
342 } 336 }
343 else if (type == PURPLE_REQUEST_FIELD_CHOICE) 337 else if (type == PURPLE_REQUEST_FIELD_CHOICE)
344 { 338 {
345 GntWidget *combo = FINCH_GET_DATA(field); 339 GntWidget *combo = purple_request_field_get_ui_data(field);
346 int id; 340 int id;
347 id = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo))); 341 id = GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)));
348 purple_request_field_choice_set_value(field, id); 342 purple_request_field_choice_set_value(field, id);
349 } 343 }
350 else if (type == PURPLE_REQUEST_FIELD_LIST) 344 else if (type == PURPLE_REQUEST_FIELD_LIST)
351 { 345 {
352 GList *list = NULL, *iter; 346 GList *list = NULL, *iter;
353 if (purple_request_field_list_get_multi_select(field)) 347 if (purple_request_field_list_get_multi_select(field))
354 { 348 {
355 GntWidget *tree = FINCH_GET_DATA(field); 349 GntWidget *tree = purple_request_field_get_ui_data(field);
356 350
357 iter = purple_request_field_list_get_items(field); 351 iter = purple_request_field_list_get_items(field);
358 for (; iter; iter = iter->next) 352 for (; iter; iter = iter->next)
359 { 353 {
360 const char *text = iter->data; 354 const char *text = iter->data;
363 list = g_list_prepend(list, (gpointer)text); 357 list = g_list_prepend(list, (gpointer)text);
364 } 358 }
365 } 359 }
366 else 360 else
367 { 361 {
368 GntWidget *combo = FINCH_GET_DATA(field); 362 GntWidget *combo = purple_request_field_get_ui_data(field);
369 gpointer data = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)); 363 gpointer data = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo));
370 364
371 iter = purple_request_field_list_get_items(field); 365 iter = purple_request_field_list_get_items(field);
372 for (; iter; iter = iter->next) { 366 for (; iter; iter = iter->next) {
373 const char *text = iter->data; 367 const char *text = iter->data;
382 purple_request_field_list_set_selected(field, list); 376 purple_request_field_list_set_selected(field, list);
383 g_list_free(list); 377 g_list_free(list);
384 } 378 }
385 else if (type == PURPLE_REQUEST_FIELD_ACCOUNT) 379 else if (type == PURPLE_REQUEST_FIELD_ACCOUNT)
386 { 380 {
387 GntWidget *combo = FINCH_GET_DATA(field); 381 GntWidget *combo = purple_request_field_get_ui_data(field);
388 PurpleAccount *acc = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo)); 382 PurpleAccount *acc = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(combo));
389 purple_request_field_account_set_value(field, acc); 383 purple_request_field_account_set_value(field, acc);
390 } 384 }
391 } 385 }
392 } 386 }
575 } 569 }
576 gnt_widget_set_size(combo, 20, 3); /* ew */ 570 gnt_widget_set_size(combo, 20, 3); /* ew */
577 return combo; 571 return combo;
578 } 572 }
579 573
574 static GntWidget*
575 create_certificate_field(PurpleRequestField *field)
576 {
577 GntWidget *w;
578 PurpleCertificate *cert;
579 char *str;
580
581 cert = purple_request_field_certificate_get_value(field);
582 str = purple_certificate_get_display_string(cert);
583 w = gnt_label_new(str);
584
585 g_free(str);
586
587 return w;
588 }
589
580 static void * 590 static void *
581 finch_request_fields(const char *title, const char *primary, 591 finch_request_fields(const char *title, const char *primary,
582 const char *secondary, PurpleRequestFields *allfields, 592 const char *secondary, PurpleRequestFields *allfields,
583 const char *ok, GCallback ok_cb, 593 const char *ok, GCallback ok_cb,
584 const char *cancel, GCallback cancel_cb, 594 const char *cancel, GCallback cancel_cb,
631 gnt_box_add_widget(GNT_BOX(hbox), l); 641 gnt_box_add_widget(GNT_BOX(hbox), l);
632 } 642 }
633 643
634 if (type == PURPLE_REQUEST_FIELD_BOOLEAN) 644 if (type == PURPLE_REQUEST_FIELD_BOOLEAN)
635 { 645 {
636 FINCH_SET_DATA(field, create_boolean_field(field)); 646 purple_request_field_set_ui_data(field, create_boolean_field(field));
637 } 647 }
638 else if (type == PURPLE_REQUEST_FIELD_STRING) 648 else if (type == PURPLE_REQUEST_FIELD_STRING)
639 { 649 {
640 FINCH_SET_DATA(field, create_string_field(field, &username)); 650 purple_request_field_set_ui_data(field, create_string_field(field, &username));
641 } 651 }
642 else if (type == PURPLE_REQUEST_FIELD_INTEGER) 652 else if (type == PURPLE_REQUEST_FIELD_INTEGER)
643 { 653 {
644 FINCH_SET_DATA(field, create_integer_field(field)); 654 purple_request_field_set_ui_data(field, create_integer_field(field));
645 } 655 }
646 else if (type == PURPLE_REQUEST_FIELD_CHOICE) 656 else if (type == PURPLE_REQUEST_FIELD_CHOICE)
647 { 657 {
648 FINCH_SET_DATA(field, create_choice_field(field)); 658 purple_request_field_set_ui_data(field, create_choice_field(field));
649 } 659 }
650 else if (type == PURPLE_REQUEST_FIELD_LIST) 660 else if (type == PURPLE_REQUEST_FIELD_LIST)
651 { 661 {
652 FINCH_SET_DATA(field, create_list_field(field)); 662 purple_request_field_set_ui_data(field, create_list_field(field));
653 } 663 }
654 else if (type == PURPLE_REQUEST_FIELD_ACCOUNT) 664 else if (type == PURPLE_REQUEST_FIELD_ACCOUNT)
655 { 665 {
656 accountlist = create_account_field(field); 666 accountlist = create_account_field(field);
657 FINCH_SET_DATA(field, accountlist); 667 purple_request_field_set_ui_data(field, accountlist);
668 }
669 else if (type == PURPLE_REQUEST_FIELD_CERTIFICATE)
670 {
671 purple_request_field_set_ui_data(field, create_certificate_field(field));
658 } 672 }
659 else 673 else
660 { 674 {
661 FINCH_SET_DATA(field, gnt_label_new_with_format(_("Not implemented yet."), 675 purple_request_field_set_ui_data(field, gnt_label_new_with_format(_("Not implemented yet."),
662 GNT_TEXT_FLAG_BOLD)); 676 GNT_TEXT_FLAG_BOLD));
663 } 677 }
664 gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID); 678 gnt_box_set_alignment(GNT_BOX(hbox), GNT_ALIGN_MID);
665 gnt_box_add_widget(GNT_BOX(hbox), GNT_WIDGET(FINCH_GET_DATA(field))); 679 gnt_box_add_widget(GNT_BOX(hbox), GNT_WIDGET(purple_request_field_get_ui_data(field)));
666 } 680 }
667 if (grlist->next) 681 if (grlist->next)
668 gnt_box_add_widget(GNT_BOX(box), gnt_hline_new()); 682 gnt_box_add_widget(GNT_BOX(box), gnt_hline_new());
669 } 683 }
670 gnt_box_add_widget(GNT_BOX(window), box); 684 gnt_box_add_widget(GNT_BOX(window), box);