pidgin/gtkrequest.c

branch
soc.2013.gobjectification.plugins
changeset 36712
84a411b5b569
parent 36706
de22c6f89190
parent 34944
0d5d42e2c0d6
child 36761
a84a6709c72a
equal deleted inserted replaced
36711:549a5e92c546 36712:84a411b5b569
122 { 122 {
123 g_return_if_fail(data != NULL); 123 g_return_if_fail(data != NULL);
124 124
125 /* Tell the user we're doing something. */ 125 /* Tell the user we're doing something. */
126 pidgin_set_cursor(GTK_WIDGET(data->dialog), GDK_WATCH); 126 pidgin_set_cursor(GTK_WIDGET(data->dialog), GDK_WATCH);
127
128 g_object_set_data(G_OBJECT(data->dialog),
129 "pidgin-window-is-closing", GINT_TO_POINTER(TRUE));
127 } 130 }
128 131
129 static void 132 static void
130 input_response_cb(GtkDialog *dialog, gint id, PidginRequestData *data) 133 input_response_cb(GtkDialog *dialog, gint id, PidginRequestData *data)
131 { 134 {
432 return gtk_image_new_from_stock(PIDGIN_STOCK_DIALOG_QUESTION, 435 return gtk_image_new_from_stock(PIDGIN_STOCK_DIALOG_QUESTION,
433 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE)); 436 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE));
434 } 437 }
435 438
436 static void 439 static void
440 pidgin_request_help_clicked(GtkButton *button, gpointer _unused)
441 {
442 PurpleRequestHelpCb cb;
443 gpointer data;
444
445 cb = g_object_get_data(G_OBJECT(button), "pidgin-help-cb");
446 data = g_object_get_data(G_OBJECT(button), "pidgin-help-data");
447
448 g_return_if_fail(cb != NULL);
449 cb(data);
450 }
451
452 static void
437 pidgin_request_add_help(GtkDialog *dialog, PurpleRequestCommonParameters *cpar) 453 pidgin_request_add_help(GtkDialog *dialog, PurpleRequestCommonParameters *cpar)
438 { 454 {
439 GtkWidget *button; 455 GtkWidget *button;
440 PurpleRequestHelpCb help_cb; 456 PurpleRequestHelpCb help_cb;
441 gpointer help_data; 457 gpointer help_data;
444 if (help_cb == NULL) 460 if (help_cb == NULL)
445 return; 461 return;
446 462
447 button = gtk_dialog_add_button(dialog, GTK_STOCK_HELP, 463 button = gtk_dialog_add_button(dialog, GTK_STOCK_HELP,
448 GTK_RESPONSE_HELP); 464 GTK_RESPONSE_HELP);
449 g_signal_connect(G_OBJECT(button), "clicked", (GCallback)help_cb, 465
450 help_data); 466 g_object_set_data(G_OBJECT(button), "pidgin-help-cb", help_cb);
467 g_object_set_data(G_OBJECT(button), "pidgin-help-data", help_data);
468
469 g_signal_connect(G_OBJECT(button), "clicked",
470 G_CALLBACK(pidgin_request_help_clicked), NULL);
451 } 471 }
452 472
453 static void * 473 static void *
454 pidgin_request_input(const char *title, const char *primary, 474 pidgin_request_input(const char *title, const char *primary,
455 const char *secondary, const char *default_value, 475 const char *secondary, const char *default_value,
1059 GList *elements = purple_request_field_choice_get_elements(field); 1079 GList *elements = purple_request_field_choice_get_elements(field);
1060 int num_labels = g_list_length(elements) / 2; 1080 int num_labels = g_list_length(elements) / 2;
1061 GList *l; 1081 GList *l;
1062 gpointer *values = g_new(gpointer, num_labels); 1082 gpointer *values = g_new(gpointer, num_labels);
1063 gpointer default_value; 1083 gpointer default_value;
1084 gboolean default_found = FALSE;
1064 int i; 1085 int i;
1065 1086
1066 default_value = purple_request_field_choice_get_default_value(field); 1087 default_value = purple_request_field_choice_get_value(field);
1067 if (num_labels > 5 || purple_request_cpar_is_compact(cpar)) 1088 if (num_labels > 5 || purple_request_cpar_is_compact(cpar))
1068 { 1089 {
1069 int default_index = 0; 1090 int default_index = 0;
1070 widget = gtk_combo_box_text_new(); 1091 widget = gtk_combo_box_text_new();
1071 1092
1080 l = g_list_next(l); 1101 l = g_list_next(l);
1081 value = l->data; 1102 value = l->data;
1082 l = g_list_next(l); 1103 l = g_list_next(l);
1083 1104
1084 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widget), text); 1105 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widget), text);
1085 if (value == default_value) 1106 if (value == default_value) {
1086 default_index = i; 1107 default_index = i;
1108 default_found = TRUE;
1109 }
1087 values[i++] = value; 1110 values[i++] = value;
1088 } 1111 }
1089 1112
1090 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), default_index); 1113 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), default_index);
1091 1114
1126 g_object_set_data(G_OBJECT(radio), "box", box); 1149 g_object_set_data(G_OBJECT(radio), "box", box);
1127 1150
1128 if (first_radio == NULL) 1151 if (first_radio == NULL)
1129 first_radio = radio; 1152 first_radio = radio;
1130 1153
1131 if (value == default_value) 1154 if (value == default_value) {
1132 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE); 1155 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE);
1156 default_found = TRUE;
1157 }
1133 values[i++] = value; 1158 values[i++] = value;
1134 1159
1135 gtk_box_pack_start(GTK_BOX(box), radio, TRUE, TRUE, 0); 1160 gtk_box_pack_start(GTK_BOX(box), radio, TRUE, TRUE, 0);
1136 gtk_widget_show(radio); 1161 gtk_widget_show(radio);
1137 1162
1138 g_signal_connect(G_OBJECT(radio), "toggled", 1163 g_signal_connect(G_OBJECT(radio), "toggled",
1139 G_CALLBACK(field_choice_option_cb), field); 1164 G_CALLBACK(field_choice_option_cb), field);
1140 } 1165 }
1141 } 1166 }
1167
1168 if (!default_found && i > 0)
1169 purple_request_field_choice_set_value(field, values[0]);
1142 1170
1143 g_object_set_data_full(G_OBJECT(widget), "values", values, g_free); 1171 g_object_set_data_full(G_OBJECT(widget), "values", values, g_free);
1144 1172
1145 return widget; 1173 return widget;
1146 } 1174 }
1888 gtk_widget_show(dirsel); 1916 gtk_widget_show(dirsel);
1889 1917
1890 return (void *)data; 1918 return (void *)data;
1891 } 1919 }
1892 1920
1893 #ifdef _WIN32 1921 /* if request callback issues another request, it should be attached to the
1894 1922 * primary request parent */
1895 /* Not needed (yet) for non-win32, but should work everywhere. */ 1923 static void
1896 static void 1924 pidgin_window_detach_children(GtkWindow* win)
1897 pidgin_window_detach_children(GtkWindow* parent)
1898 { 1925 {
1899 GList *it; 1926 GList *it;
1900 1927 GtkWindow *par;
1901 g_return_if_fail(parent != NULL); 1928
1902 1929 g_return_if_fail(win != NULL);
1930
1931 par = gtk_window_get_transient_for(win);
1903 it = gtk_window_list_toplevels(); 1932 it = gtk_window_list_toplevels();
1904 for (it = g_list_first(it); it != NULL; it = g_list_next(it)) { 1933 for (it = g_list_first(it); it != NULL; it = g_list_next(it)) {
1905 GtkWindow *win = GTK_WINDOW(it->data); 1934 GtkWindow *child = GTK_WINDOW(it->data);
1906 if (gtk_window_get_transient_for(win) == parent) 1935 if (gtk_window_get_transient_for(child) != win)
1907 gtk_window_set_transient_for(win, NULL); 1936 continue;
1908 } 1937 if (gtk_window_get_destroy_with_parent(child)) {
1909 } 1938 #ifdef _WIN32
1910 1939 /* XXX test/verify it: Win32 gtk ignores
1940 * gtk_window_set_destroy_with_parent(..., FALSE). */
1941 gtk_window_set_transient_for(child, NULL);
1911 #endif 1942 #endif
1943 continue;
1944 }
1945 gtk_window_set_transient_for(child, par);
1946 }
1947 }
1912 1948
1913 static void 1949 static void
1914 pidgin_close_request(PurpleRequestType type, void *ui_handle) 1950 pidgin_close_request(PurpleRequestType type, void *ui_handle)
1915 { 1951 {
1916 PidginRequestData *data = (PidginRequestData *)ui_handle; 1952 PidginRequestData *data = (PidginRequestData *)ui_handle;
1917 1953
1918 g_free(data->cbs); 1954 g_free(data->cbs);
1919 1955
1920 #ifdef _WIN32
1921 /* Win32 gtk ignores gtk_window_set_destroy_with_parent(..., FALSE). */
1922 pidgin_window_detach_children(GTK_WINDOW(data->dialog)); 1956 pidgin_window_detach_children(GTK_WINDOW(data->dialog));
1923 #endif
1924 1957
1925 gtk_widget_destroy(data->dialog); 1958 gtk_widget_destroy(data->dialog);
1926 1959
1927 if (type == PURPLE_REQUEST_FIELDS) 1960 if (type == PURPLE_REQUEST_FIELDS)
1928 purple_request_fields_destroy(data->u.multifield.fields); 1961 purple_request_fields_destroy(data->u.multifield.fields);

mercurial