Mercurial > pidgin.yaz
comparison src/gtkrequest.c @ 8286:89d9d004e3f3
[gaim-migrate @ 9010]
Improved the field request API, adding required fields and account fields,
as well as some new utility API functions and bug fixes. These changes
allowed me to migrate the New IM dialog over to the field request API,
removing a lot of code and improving consistency.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 18 Feb 2004 07:22:53 +0000 |
parents | 4971193f761d |
children | e39ea2b4f6cd |
comparison
equal
deleted
inserted
replaced
8285:d335cc7bca54 | 8286:89d9d004e3f3 |
---|---|
36 GaimRequestType type; | 36 GaimRequestType type; |
37 | 37 |
38 void *user_data; | 38 void *user_data; |
39 GtkWidget *dialog; | 39 GtkWidget *dialog; |
40 | 40 |
41 GtkWidget *ok_button; | |
42 | |
41 size_t cb_count; | 43 size_t cb_count; |
42 GCallback *cbs; | 44 GCallback *cbs; |
43 | 45 |
44 union | 46 union |
45 { | 47 { |
106 field_string_focus_out_cb(GtkWidget *entry, GdkEventFocus *event, | 108 field_string_focus_out_cb(GtkWidget *entry, GdkEventFocus *event, |
107 GaimRequestField *field) | 109 GaimRequestField *field) |
108 { | 110 { |
109 const char *value; | 111 const char *value; |
110 | 112 |
111 if (gaim_request_field_string_is_multiline(field)) { | 113 if (gaim_request_field_string_is_multiline(field)) |
114 { | |
112 GtkTextBuffer *buffer; | 115 GtkTextBuffer *buffer; |
113 GtkTextIter start_iter, end_iter; | 116 GtkTextIter start_iter, end_iter; |
114 | 117 |
115 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)); | 118 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry)); |
116 | 119 |
156 field_choice_option_cb(GtkRadioButton *button, GaimRequestField *field) | 159 field_choice_option_cb(GtkRadioButton *button, GaimRequestField *field) |
157 { | 160 { |
158 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) | 161 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) |
159 gaim_request_field_choice_set_value(field, | 162 gaim_request_field_choice_set_value(field, |
160 g_slist_index(gtk_radio_button_get_group(button), button)); | 163 g_slist_index(gtk_radio_button_get_group(button), button)); |
164 } | |
165 | |
166 static void | |
167 field_account_cb(GObject *w, GaimAccount *account, GaimRequestField *field) | |
168 { | |
169 gaim_request_field_account_set_value(field, account); | |
161 } | 170 } |
162 | 171 |
163 static void | 172 static void |
164 multifield_ok_cb(GtkWidget *button, GaimGtkRequestData *data) | 173 multifield_ok_cb(GtkWidget *button, GaimGtkRequestData *data) |
165 { | 174 { |
265 /* Descriptive label */ | 274 /* Descriptive label */ |
266 label_text = g_strdup_printf((primary ? "<span weight=\"bold\" size=\"larger\">" | 275 label_text = g_strdup_printf((primary ? "<span weight=\"bold\" size=\"larger\">" |
267 "%s</span>%s%s" : "%s%s%s"), | 276 "%s</span>%s%s" : "%s%s%s"), |
268 (primary ? primary : ""), | 277 (primary ? primary : ""), |
269 ((primary && secondary) ? "\n\n" : ""), | 278 ((primary && secondary) ? "\n\n" : ""), |
270 (secondary ? secondary : "")); | 279 (secondary ? secondary : "")); |
271 | 280 |
272 label = gtk_label_new(NULL); | 281 label = gtk_label_new(NULL); |
273 | 282 |
274 gtk_label_set_markup(GTK_LABEL(label), label_text); | 283 gtk_label_set_markup(GTK_LABEL(label), label_text); |
275 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | 284 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
435 gtk_widget_show_all(dialog); | 444 gtk_widget_show_all(dialog); |
436 | 445 |
437 return data; | 446 return data; |
438 } | 447 } |
439 | 448 |
449 static void | |
450 req_entry_field_changed_cb(GtkWidget *entry, GaimRequestField *field) | |
451 { | |
452 GaimGtkRequestData *req_data; | |
453 const char *text = gtk_entry_get_text(GTK_ENTRY(entry)); | |
454 | |
455 gaim_request_field_string_set_value(field, (*text == '\0' ? NULL : text)); | |
456 | |
457 req_data = (GaimGtkRequestData *)field->group->fields_list->ui_data; | |
458 | |
459 gtk_widget_set_sensitive(req_data->ok_button, | |
460 gaim_request_fields_all_required_filled(field->group->fields_list)); | |
461 } | |
462 | |
463 static void | |
464 setup_entry_field(GtkWidget *entry, GaimRequestField *field) | |
465 { | |
466 gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE); | |
467 | |
468 if (gaim_request_field_is_required(field)) | |
469 { | |
470 g_signal_connect(G_OBJECT(entry), "changed", | |
471 G_CALLBACK(req_entry_field_changed_cb), field); | |
472 } | |
473 } | |
474 | |
440 static GtkWidget * | 475 static GtkWidget * |
441 create_string_field(GaimRequestField *field) | 476 create_string_field(GaimRequestField *field) |
442 { | 477 { |
443 const char *value; | 478 const char *value; |
444 GtkWidget *widget; | 479 GtkWidget *widget; |
486 } | 521 } |
487 else | 522 else |
488 { | 523 { |
489 widget = gtk_entry_new(); | 524 widget = gtk_entry_new(); |
490 | 525 |
526 setup_entry_field(widget, field); | |
527 | |
491 if (value != NULL) | 528 if (value != NULL) |
492 gtk_entry_set_text(GTK_ENTRY(widget), value); | 529 gtk_entry_set_text(GTK_ENTRY(widget), value); |
493 | 530 |
494 gtk_entry_set_visibility(GTK_ENTRY(widget), | 531 gtk_entry_set_visibility(GTK_ENTRY(widget), |
495 !gaim_request_field_string_is_masked(field)); | 532 !gaim_request_field_string_is_masked(field)); |
509 { | 546 { |
510 int value; | 547 int value; |
511 GtkWidget *widget; | 548 GtkWidget *widget; |
512 | 549 |
513 widget = gtk_entry_new(); | 550 widget = gtk_entry_new(); |
551 | |
552 setup_entry_field(widget, field); | |
514 | 553 |
515 value = gaim_request_field_int_get_default_value(field); | 554 value = gaim_request_field_int_get_default_value(field); |
516 | 555 |
517 if (value != 0) | 556 if (value != 0) |
518 { | 557 { |
606 | 645 |
607 g_signal_connect(G_OBJECT(radio), "toggled", | 646 g_signal_connect(G_OBJECT(radio), "toggled", |
608 G_CALLBACK(field_choice_option_cb), field); | 647 G_CALLBACK(field_choice_option_cb), field); |
609 } | 648 } |
610 } | 649 } |
650 | |
651 return widget; | |
652 } | |
653 | |
654 static GtkWidget * | |
655 create_account_field(GaimRequestField *field) | |
656 { | |
657 GtkWidget *widget; | |
658 | |
659 widget = gaim_gtk_account_option_menu_new( | |
660 gaim_request_field_account_get_default_value(field), | |
661 gaim_request_field_account_get_show_all(field), | |
662 G_CALLBACK(field_account_cb), NULL, field); | |
611 | 663 |
612 return widget; | 664 return widget; |
613 } | 665 } |
614 | 666 |
615 static void | 667 static void |
723 data = g_new0(GaimGtkRequestData, 1); | 775 data = g_new0(GaimGtkRequestData, 1); |
724 data->type = GAIM_REQUEST_FIELDS; | 776 data->type = GAIM_REQUEST_FIELDS; |
725 data->user_data = user_data; | 777 data->user_data = user_data; |
726 data->u.multifield.fields = fields; | 778 data->u.multifield.fields = fields; |
727 | 779 |
780 fields->ui_data = data; | |
781 | |
728 data->cb_count = 2; | 782 data->cb_count = 2; |
729 data->cbs = g_new0(GCallback, 2); | 783 data->cbs = g_new0(GCallback, 2); |
730 | 784 |
731 data->cbs[0] = ok_cb; | 785 data->cbs[0] = ok_cb; |
732 data->cbs[1] = cancel_cb; | 786 data->cbs[1] = cancel_cb; |
811 cols++; | 865 cols++; |
812 } | 866 } |
813 else | 867 else |
814 rows = field_count; | 868 rows = field_count; |
815 | 869 |
816 col_num=0; | 870 col_num = 0; |
871 | |
817 for (fl = field_list; fl != NULL; fl = fl->next) | 872 for (fl = field_list; fl != NULL; fl = fl->next) |
818 { | 873 { |
819 GaimRequestFieldType type; | 874 GaimRequestFieldType type; |
820 | 875 |
821 field = (GaimRequestField *)fl->data; | 876 field = (GaimRequestField *)fl->data; |
822 | 877 |
823 type = gaim_request_field_get_type(field); | 878 type = gaim_request_field_get_type(field); |
824 | 879 |
825 if (type == GAIM_REQUEST_FIELD_LABEL) { | 880 if (type == GAIM_REQUEST_FIELD_LABEL) |
826 if(col_num > 0) | 881 { |
882 if (col_num > 0) | |
827 rows++; | 883 rows++; |
884 | |
828 rows++; | 885 rows++; |
829 } else if(type == GAIM_REQUEST_FIELD_STRING && gaim_request_field_string_is_multiline(field)){ | 886 } |
830 if(col_num > 0) | 887 else if (type == GAIM_REQUEST_FIELD_STRING && |
888 gaim_request_field_string_is_multiline(field)) | |
889 { | |
890 if (col_num > 0) | |
831 rows++; | 891 rows++; |
892 | |
832 rows += 2; | 893 rows += 2; |
833 } | 894 } |
834 | 895 |
835 col_num++; | 896 col_num++; |
897 | |
836 if(col_num >= cols) | 898 if(col_num >= cols) |
837 col_num=0; | 899 col_num = 0; |
838 } | 900 } |
839 | 901 |
840 table = gtk_table_new(rows, 2 * cols, FALSE); | 902 table = gtk_table_new(rows, 2 * cols, FALSE); |
841 gtk_table_set_row_spacings(GTK_TABLE(table), 6); | 903 gtk_table_set_row_spacings(GTK_TABLE(table), 6); |
842 gtk_table_set_col_spacings(GTK_TABLE(table), 6); | 904 gtk_table_set_col_spacings(GTK_TABLE(table), 6); |
912 widget = create_bool_field(field); | 974 widget = create_bool_field(field); |
913 else if (type == GAIM_REQUEST_FIELD_CHOICE) | 975 else if (type == GAIM_REQUEST_FIELD_CHOICE) |
914 widget = create_choice_field(field); | 976 widget = create_choice_field(field); |
915 else if (type == GAIM_REQUEST_FIELD_LIST) | 977 else if (type == GAIM_REQUEST_FIELD_LIST) |
916 widget = create_list_field(field); | 978 widget = create_list_field(field); |
979 else if (type == GAIM_REQUEST_FIELD_ACCOUNT) | |
980 widget = create_account_field(field); | |
917 else | 981 else |
918 continue; | 982 continue; |
919 | 983 |
920 if (type == GAIM_REQUEST_FIELD_STRING && | 984 if (type == GAIM_REQUEST_FIELD_STRING && |
921 gaim_request_field_string_is_multiline(field)) | 985 gaim_request_field_string_is_multiline(field)) |
968 gtk_widget_show(button); | 1032 gtk_widget_show(button); |
969 | 1033 |
970 g_signal_connect(G_OBJECT(button), "clicked", | 1034 g_signal_connect(G_OBJECT(button), "clicked", |
971 G_CALLBACK(multifield_cancel_cb), data); | 1035 G_CALLBACK(multifield_cancel_cb), data); |
972 | 1036 |
1037 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
1038 | |
973 /* OK button */ | 1039 /* OK button */ |
974 button = gtk_button_new_from_stock(text_to_stock(ok_text)); | 1040 button = gtk_button_new_from_stock(text_to_stock(ok_text)); |
975 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | 1041 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); |
976 gtk_widget_show(button); | 1042 gtk_widget_show(button); |
977 | 1043 |
1044 data->ok_button = button; | |
1045 | |
1046 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
1047 gtk_window_set_default(GTK_WINDOW(win), button); | |
1048 | |
978 g_signal_connect(G_OBJECT(button), "clicked", | 1049 g_signal_connect(G_OBJECT(button), "clicked", |
979 G_CALLBACK(multifield_ok_cb), data); | 1050 G_CALLBACK(multifield_ok_cb), data); |
980 | 1051 |
1052 if (!gaim_request_fields_all_required_filled(fields)) | |
1053 gtk_widget_set_sensitive(button, FALSE); | |
1054 | |
981 gtk_widget_show(win); | 1055 gtk_widget_show(win); |
982 | 1056 |
983 return data; | 1057 return data; |
984 } | 1058 } |
985 | 1059 |
989 GaimGtkRequestData *data = (GaimGtkRequestData *)ui_handle; | 1063 GaimGtkRequestData *data = (GaimGtkRequestData *)ui_handle; |
990 | 1064 |
991 if (data->cbs != NULL) | 1065 if (data->cbs != NULL) |
992 g_free(data->cbs); | 1066 g_free(data->cbs); |
993 | 1067 |
1068 gtk_widget_destroy(data->dialog); | |
1069 | |
994 if (type == GAIM_REQUEST_FIELDS) | 1070 if (type == GAIM_REQUEST_FIELDS) |
995 gaim_request_fields_destroy(data->u.multifield.fields); | 1071 gaim_request_fields_destroy(data->u.multifield.fields); |
996 | |
997 gtk_widget_destroy(data->dialog); | |
998 | 1072 |
999 g_free(data); | 1073 g_free(data); |
1000 } | 1074 } |
1001 | 1075 |
1002 static GaimRequestUiOps ops = | 1076 static GaimRequestUiOps ops = |