comparison 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
comparison
equal deleted inserted replaced
16302:03532b86c20f 16310:8c89913276b3
137 137
138 static void 138 static void
139 finch_close_request(PurpleRequestType type, gpointer ui_handle) 139 finch_close_request(PurpleRequestType type, gpointer ui_handle)
140 { 140 {
141 GntWidget *widget = GNT_WIDGET(ui_handle); 141 GntWidget *widget = GNT_WIDGET(ui_handle);
142 if (type == PURPLE_REQUEST_FIELDS) {
143 PurpleRequestFields *fields = g_object_get_data(G_OBJECT(widget), "fields");
144 purple_request_fields_destroy(fields);
145 }
146
142 while (widget->parent) 147 while (widget->parent)
143 widget = widget->parent; 148 widget = widget->parent;
144 gnt_widget_destroy(widget); 149 gnt_widget_destroy(widget);
145 } 150 }
146 151
241 { 246 {
242 PurpleRequestFieldsCb callback = g_object_get_data(G_OBJECT(button), "activate-callback"); 247 PurpleRequestFieldsCb callback = g_object_get_data(G_OBJECT(button), "activate-callback");
243 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata"); 248 gpointer data = g_object_get_data(G_OBJECT(button), "activate-userdata");
244 GList *list; 249 GList *list;
245 250
246 /* Update the data of the fields. GtkPurple does this differently. Instead of 251 /* Update the data of the fields. Pidgin does this differently. Instead of
247 * updating the fields at the end like here, it updates the appropriate field 252 * 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 253 * 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 254 * '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 255 * here, althought it can be done. I am not honouring the 'required' fields
251 * for the moment. */ 256 * for the moment. */
530 box = setup_button_box(userdata, request_fields_cb, allfields, 535 box = setup_button_box(userdata, request_fields_cb, allfields,
531 ok, ok_cb, cancel, cancel_cb, NULL); 536 ok, ok_cb, cancel, cancel_cb, NULL);
532 gnt_box_add_widget(GNT_BOX(window), box); 537 gnt_box_add_widget(GNT_BOX(window), box);
533 538
534 gnt_widget_show(window); 539 gnt_widget_show(window);
540
541 g_object_set_data(G_OBJECT(window), "fields", allfields);
535 542
536 return window; 543 return window;
537 } 544 }
538 545
539 static void 546 static void
618 625
619 void finch_request_uninit() 626 void finch_request_uninit()
620 { 627 {
621 } 628 }
622 629
630 void finch_request_save_in_prefs(gpointer null, PurpleRequestFields *allfields)
631 {
632 GList *list;
633 for (list = purple_request_fields_get_groups(allfields); list; list = list->next) {
634 PurpleRequestFieldGroup *group = list->data;
635 GList *fields = purple_request_field_group_get_fields(group);
636
637 for (; fields ; fields = fields->next) {
638 PurpleRequestField *field = fields->data;
639 PurpleRequestFieldType type = purple_request_field_get_type(field);
640 PurplePrefType pt;
641 gpointer val = NULL;
642 const char *id = purple_request_field_get_id(field);
643
644 switch (type) {
645 case PURPLE_REQUEST_FIELD_LIST:
646 val = purple_request_field_list_get_selected(field)->data;
647 break;
648 case PURPLE_REQUEST_FIELD_BOOLEAN:
649 val = GINT_TO_POINTER(purple_request_field_bool_get_value(field));
650 break;
651 case PURPLE_REQUEST_FIELD_INTEGER:
652 val = GINT_TO_POINTER(purple_request_field_int_get_value(field));
653 break;
654 case PURPLE_REQUEST_FIELD_STRING:
655 val = (gpointer)purple_request_field_string_get_value(field);
656 break;
657 default:
658 break;
659 }
660
661 pt = purple_prefs_get_type(id);
662 switch (pt) {
663 case PURPLE_PREF_INT:
664 if (type == PURPLE_REQUEST_FIELD_LIST) /* Lists always return string */
665 sscanf(val, "%ld", (long int *)&val);
666 purple_prefs_set_int(id, GPOINTER_TO_INT(val));
667 break;
668 case PURPLE_PREF_BOOLEAN:
669 purple_prefs_set_bool(id, GPOINTER_TO_INT(val));
670 break;
671 case PURPLE_PREF_STRING:
672 purple_prefs_set_string(id, val);
673 break;
674 default:
675 break;
676 }
677 }
678 }
679 }
680