pidgin/gtkrequest.c

branch
soc.2013.gobjectification.plugins
changeset 36701
5acd461707ae
parent 36577
0f30fdfb84be
parent 34941
e5530c2b896e
child 36706
de22c6f89190
equal deleted inserted replaced
36700:6e948576476e 36701:5acd461707ae
185 generic_response_start(data); 185 generic_response_start(data);
186 186
187 if (id >= 0 && (gsize)id < data->cb_count && data->cbs[id] != NULL) 187 if (id >= 0 && (gsize)id < data->cb_count && data->cbs[id] != NULL)
188 while (group) { 188 while (group) {
189 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(group->data))) { 189 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(group->data))) {
190 ((PurpleRequestChoiceCb)data->cbs[id])(data->user_data, GPOINTER_TO_INT(g_object_get_data(G_OBJECT(group->data), "choice_id"))); 190 ((PurpleRequestChoiceCb)data->cbs[id])(data->user_data, g_object_get_data(G_OBJECT(group->data), "choice_value"));
191 break; 191 break;
192 } 192 }
193 group = group->next; 193 group = group->next;
194 } 194 }
195 purple_request_close(PURPLE_REQUEST_INPUT, data); 195 purple_request_close(PURPLE_REQUEST_INPUT, data);
230 } 230 }
231 231
232 static void 232 static void
233 field_choice_menu_cb(GtkComboBox *menu, PurpleRequestField *field) 233 field_choice_menu_cb(GtkComboBox *menu, PurpleRequestField *field)
234 { 234 {
235 purple_request_field_choice_set_value(field, 235 int active = gtk_combo_box_get_active(menu);
236 gtk_combo_box_get_active(menu)); 236 gpointer *values = g_object_get_data(G_OBJECT(menu), "values");
237
238 g_return_if_fail(values != NULL);
239 g_return_if_fail(active >= 0);
240
241 purple_request_field_choice_set_value(field, values[active]);
237 } 242 }
238 243
239 static void 244 static void
240 field_choice_option_cb(GtkRadioButton *button, PurpleRequestField *field) 245 field_choice_option_cb(GtkRadioButton *button, PurpleRequestField *field)
241 { 246 {
242 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) 247 int active;
243 purple_request_field_choice_set_value(field, 248 gpointer *values = g_object_get_data(G_OBJECT(g_object_get_data(
244 (g_slist_length(gtk_radio_button_get_group(button)) - 249 G_OBJECT(button), "box")), "values");
245 g_slist_index(gtk_radio_button_get_group(button), button)) - 1); 250
251 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
252 return;
253
254 active = (g_slist_length(gtk_radio_button_get_group(button)) -
255 g_slist_index(gtk_radio_button_get_group(button), button)) - 1;
256
257 g_return_if_fail(values != NULL);
258 g_return_if_fail(active >= 0);
259
260 purple_request_field_choice_set_value(field, values[active]);
246 } 261 }
247 262
248 static void 263 static void
249 field_account_cb(GObject *w, PurpleAccount *account, PurpleRequestField *field) 264 field_account_cb(GObject *w, PurpleAccount *account, PurpleRequestField *field)
250 { 265 {
286 return FALSE; 301 return FALSE;
287 } 302 }
288 303
289 304
290 #define STOCK_ITEMIZE(r, l) \ 305 #define STOCK_ITEMIZE(r, l) \
291 if (!strcmp((r), text)) \ 306 if (!strcmp((r), text) || !strcmp(_(r), text)) \
292 return (l); 307 return (l);
293 308
294 static const char * 309 static const char *
295 text_to_stock(const char *text) 310 text_to_stock(const char *text)
296 { 311 {
297 STOCK_ITEMIZE(_("Yes"), GTK_STOCK_YES); 312 STOCK_ITEMIZE(N_("Yes"), GTK_STOCK_YES);
298 STOCK_ITEMIZE(_("No"), GTK_STOCK_NO); 313 STOCK_ITEMIZE(N_("_Yes"), GTK_STOCK_YES);
299 STOCK_ITEMIZE(_("OK"), GTK_STOCK_OK); 314 STOCK_ITEMIZE(N_("No"), GTK_STOCK_NO);
300 STOCK_ITEMIZE(_("Cancel"), GTK_STOCK_CANCEL); 315 STOCK_ITEMIZE(N_("_No"), GTK_STOCK_NO);
301 STOCK_ITEMIZE(_("Apply"), GTK_STOCK_APPLY); 316 STOCK_ITEMIZE(N_("OK"), GTK_STOCK_OK);
302 STOCK_ITEMIZE(_("Close"), GTK_STOCK_CLOSE); 317 STOCK_ITEMIZE(N_("_OK"), GTK_STOCK_OK);
303 STOCK_ITEMIZE(_("Delete"), GTK_STOCK_DELETE); 318 STOCK_ITEMIZE(N_("Cancel"), GTK_STOCK_CANCEL);
304 STOCK_ITEMIZE(_("Add"), GTK_STOCK_ADD); 319 STOCK_ITEMIZE(N_("_Cancel"), GTK_STOCK_CANCEL);
305 STOCK_ITEMIZE(_("Remove"), GTK_STOCK_REMOVE); 320 STOCK_ITEMIZE(N_("Apply"), GTK_STOCK_APPLY);
306 STOCK_ITEMIZE(_("Save"), GTK_STOCK_SAVE); 321 STOCK_ITEMIZE(N_("Close"), GTK_STOCK_CLOSE);
307 STOCK_ITEMIZE(_("Alias"), PIDGIN_STOCK_ALIAS); 322 STOCK_ITEMIZE(N_("Delete"), GTK_STOCK_DELETE);
323 STOCK_ITEMIZE(N_("Add"), GTK_STOCK_ADD);
324 STOCK_ITEMIZE(N_("Remove"), GTK_STOCK_REMOVE);
325 STOCK_ITEMIZE(N_("Save"), GTK_STOCK_SAVE);
326 STOCK_ITEMIZE(N_("Next"), GTK_STOCK_GO_FORWARD);
327 STOCK_ITEMIZE(N_("Back"), GTK_STOCK_GO_BACK);
328 STOCK_ITEMIZE(N_("Alias"), PIDGIN_STOCK_ALIAS);
308 329
309 return text; 330 return text;
331 }
332
333 #undef STOCK_ITEMIZE
334
335 static gchar *
336 pidgin_request_escape(PurpleRequestCommonParameters *cpar, const gchar *text)
337 {
338 if (text == NULL)
339 return NULL;
340
341 if (purple_request_cpar_is_html(cpar)) {
342 gboolean valid;
343
344 valid = pango_parse_markup(text, -1, 0, NULL, NULL, NULL, NULL);
345
346 if (valid)
347 return g_strdup(text);
348 else {
349 purple_debug_error("pidgin", "Passed label text is not "
350 "a valid markup. Falling back to plain text.");
351 }
352 }
353
354 return g_markup_escape_text(text, -1);
355 }
356
357 static GtkWidget *
358 pidgin_request_dialog_icon(PurpleRequestCommonParameters *cpar)
359 {
360 GtkWidget *img = NULL;
361 PurpleRequestIconType icon_type;
362 gconstpointer icon_data;
363 gsize icon_size;
364 const gchar *icon_stock = PIDGIN_STOCK_DIALOG_QUESTION;
365
366 /* Dialog icon. */
367 icon_data = purple_request_cpar_get_custom_icon(cpar, &icon_size);
368 if (icon_data) {
369 GdkPixbuf *pixbuf;
370
371 pixbuf = pidgin_pixbuf_from_data(icon_data, icon_size);
372 if (pixbuf) {
373 /* scale the image if it is too large */
374 int width = gdk_pixbuf_get_width(pixbuf);
375 int height = gdk_pixbuf_get_height(pixbuf);
376 if (width > 128 || height > 128) {
377 int scaled_width = width > height ?
378 128 : (128 * width) / height;
379 int scaled_height = height > width ?
380 128 : (128 * height) / width;
381 GdkPixbuf *scaled;
382
383 purple_debug_info("pidgin", "dialog icon was "
384 "too large, scaling it down");
385
386 scaled = gdk_pixbuf_scale_simple(pixbuf,
387 scaled_width, scaled_height,
388 GDK_INTERP_BILINEAR);
389 if (scaled) {
390 g_object_unref(pixbuf);
391 pixbuf = scaled;
392 }
393 }
394 img = gtk_image_new_from_pixbuf(pixbuf);
395 g_object_unref(pixbuf);
396 } else {
397 purple_debug_info("pidgin",
398 "failed to parse dialog icon");
399 }
400 }
401
402 if (img)
403 return img;
404
405 icon_type = purple_request_cpar_get_icon(cpar);
406 switch (icon_type)
407 {
408 case PURPLE_REQUEST_ICON_REQUEST:
409 icon_stock = PIDGIN_STOCK_DIALOG_QUESTION;
410 break;
411 case PURPLE_REQUEST_ICON_DIALOG:
412 case PURPLE_REQUEST_ICON_INFO:
413 icon_stock = PIDGIN_STOCK_DIALOG_INFO;
414 break;
415 case PURPLE_REQUEST_ICON_WARNING:
416 icon_stock = PIDGIN_STOCK_DIALOG_WARNING;
417 break;
418 case PURPLE_REQUEST_ICON_ERROR:
419 icon_stock = PIDGIN_STOCK_DIALOG_ERROR;
420 break;
421 /* intentionally no default value */
422 }
423
424 img = gtk_image_new_from_stock(icon_stock,
425 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE));
426
427 if (img || icon_type == PURPLE_REQUEST_ICON_REQUEST)
428 return img;
429
430 return gtk_image_new_from_stock(PIDGIN_STOCK_DIALOG_QUESTION,
431 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE));
310 } 432 }
311 433
312 static void * 434 static void *
313 pidgin_request_input(const char *title, const char *primary, 435 pidgin_request_input(const char *title, const char *primary,
314 const char *secondary, const char *default_value, 436 const char *secondary, const char *default_value,
315 gboolean multiline, gboolean masked, gchar *hint, 437 gboolean multiline, gboolean masked, gchar *hint,
316 const char *ok_text, GCallback ok_cb, 438 const char *ok_text, GCallback ok_cb,
317 const char *cancel_text, GCallback cancel_cb, 439 const char *cancel_text, GCallback cancel_cb,
318 PurpleAccount *account, const char *who, PurpleConversation *conv, 440 PurpleRequestCommonParameters *cpar,
319 void *user_data) 441 void *user_data)
320 { 442 {
321 PidginRequestData *data; 443 PidginRequestData *data;
322 GtkWidget *dialog; 444 GtkWidget *dialog;
323 GtkWidget *vbox; 445 GtkWidget *vbox;
363 hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER); 485 hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER);
364 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), 486 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
365 hbox); 487 hbox);
366 488
367 /* Dialog icon. */ 489 /* Dialog icon. */
368 img = gtk_image_new_from_stock(PIDGIN_STOCK_DIALOG_QUESTION, 490 img = pidgin_request_dialog_icon(cpar);
369 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE));
370 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); 491 gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
371 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); 492 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
372 493
373 /* Vertical box */ 494 /* Vertical box */
374 vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER); 495 vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER);
375 496
376 gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0); 497 gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
377 498
378 pidgin_widget_decorate_account(hbox, account); 499 pidgin_widget_decorate_account(hbox, purple_request_cpar_get_account(cpar));
379 500
380 /* Descriptive label */ 501 /* Descriptive label */
381 primary_esc = (primary != NULL) ? g_markup_escape_text(primary, -1) : NULL; 502 primary_esc = pidgin_request_escape(cpar, primary);
382 secondary_esc = (secondary != NULL) ? g_markup_escape_text(secondary, -1) : NULL; 503 secondary_esc = pidgin_request_escape(cpar, secondary);
383 label_text = g_strdup_printf((primary ? "<span weight=\"bold\" size=\"larger\">" 504 label_text = g_strdup_printf((primary ? "<span weight=\"bold\" size=\"larger\">"
384 "%s</span>%s%s" : "%s%s%s"), 505 "%s</span>%s%s" : "%s%s%s"),
385 (primary ? primary_esc : ""), 506 (primary ? primary_esc : ""),
386 ((primary && secondary) ? "\n\n" : ""), 507 ((primary && secondary) ? "\n\n" : ""),
387 (secondary ? secondary_esc : "")); 508 (secondary ? secondary_esc : ""));
466 return data; 587 return data;
467 } 588 }
468 589
469 static void * 590 static void *
470 pidgin_request_choice(const char *title, const char *primary, 591 pidgin_request_choice(const char *title, const char *primary,
471 const char *secondary, int default_value, 592 const char *secondary, gpointer default_value, const char *ok_text,
472 const char *ok_text, GCallback ok_cb, 593 GCallback ok_cb, const char *cancel_text, GCallback cancel_cb,
473 const char *cancel_text, GCallback cancel_cb, 594 PurpleRequestCommonParameters *cpar, void *user_data, va_list args)
474 PurpleAccount *account, const char *who, PurpleConversation *conv,
475 void *user_data, va_list args)
476 { 595 {
477 PidginRequestData *data; 596 PidginRequestData *data;
478 GtkWidget *dialog; 597 GtkWidget *dialog;
479 GtkWidget *vbox, *vbox2; 598 GtkWidget *vbox, *vbox2;
480 GtkWidget *hbox; 599 GtkWidget *hbox;
524 hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER); 643 hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER);
525 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), 644 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
526 hbox); 645 hbox);
527 646
528 /* Dialog icon. */ 647 /* Dialog icon. */
529 img = gtk_image_new_from_stock(PIDGIN_STOCK_DIALOG_QUESTION, 648 img = pidgin_request_dialog_icon(cpar);
530 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE));
531 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); 649 gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
532 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); 650 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
533 651
534 pidgin_widget_decorate_account(hbox, account); 652 pidgin_widget_decorate_account(hbox, purple_request_cpar_get_account(cpar));
535 653
536 /* Vertical box */ 654 /* Vertical box */
537 vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER); 655 vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER);
538 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); 656 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
539 657
540 /* Descriptive label */ 658 /* Descriptive label */
541 primary_esc = (primary != NULL) ? g_markup_escape_text(primary, -1) : NULL; 659 primary_esc = pidgin_request_escape(cpar, primary);
542 secondary_esc = (secondary != NULL) ? g_markup_escape_text(secondary, -1) : NULL; 660 secondary_esc = pidgin_request_escape(cpar, secondary);
543 label_text = g_strdup_printf((primary ? "<span weight=\"bold\" size=\"larger\">" 661 label_text = g_strdup_printf((primary ? "<span weight=\"bold\" size=\"larger\">"
544 "%s</span>%s%s" : "%s%s%s"), 662 "%s</span>%s%s" : "%s%s%s"),
545 (primary ? primary_esc : ""), 663 (primary ? primary_esc : ""),
546 ((primary && secondary) ? "\n\n" : ""), 664 ((primary && secondary) ? "\n\n" : ""),
547 (secondary ? secondary_esc : "")); 665 (secondary ? secondary_esc : ""));
558 g_free(label_text); 676 g_free(label_text);
559 677
560 vbox2 = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE); 678 vbox2 = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
561 gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, FALSE, 0); 679 gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, FALSE, 0);
562 while ((radio_text = va_arg(args, char*))) { 680 while ((radio_text = va_arg(args, char*))) {
563 int resp = va_arg(args, int); 681 gpointer resp = va_arg(args, gpointer);
564 radio = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio), radio_text); 682 radio = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio), radio_text);
565 gtk_box_pack_start(GTK_BOX(vbox2), radio, FALSE, FALSE, 0); 683 gtk_box_pack_start(GTK_BOX(vbox2), radio, FALSE, FALSE, 0);
566 g_object_set_data(G_OBJECT(radio), "choice_id", GINT_TO_POINTER(resp)); 684 g_object_set_data(G_OBJECT(radio), "choice_value", resp);
567 if (resp == default_value) 685 if (resp == default_value)
568 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE); 686 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE);
569 } 687 }
570 688
571 g_object_set_data(G_OBJECT(dialog), "radio", radio); 689 g_object_set_data(G_OBJECT(dialog), "radio", radio);
577 695
578 return data; 696 return data;
579 } 697 }
580 698
581 static void * 699 static void *
582 pidgin_request_action_with_icon(const char *title, const char *primary, 700 pidgin_request_action(const char *title, const char *primary,
583 const char *secondary, int default_action, 701 const char *secondary, int default_action,
584 PurpleAccount *account, const char *who, 702 PurpleRequestCommonParameters *cpar, void *user_data,
585 PurpleConversation *conv, gconstpointer icon_data, 703 size_t action_count, va_list actions)
586 gsize icon_size,
587 void *user_data, size_t action_count, va_list actions)
588 { 704 {
589 PidginRequestData *data; 705 PidginRequestData *data;
590 GtkWidget *dialog; 706 GtkWidget *dialog;
591 GtkWidget *vbox; 707 GtkWidget *vbox;
592 GtkWidget *hbox; 708 GtkWidget *hbox;
647 /* Setup the main horizontal box */ 763 /* Setup the main horizontal box */
648 hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER); 764 hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER);
649 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), 765 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
650 hbox); 766 hbox);
651 767
652 /* Dialog icon. */ 768 img = pidgin_request_dialog_icon(cpar);
653 if (icon_data) {
654 GdkPixbuf *pixbuf = pidgin_pixbuf_from_data(icon_data, icon_size);
655 if (pixbuf) {
656 /* scale the image if it is too large */
657 int width = gdk_pixbuf_get_width(pixbuf);
658 int height = gdk_pixbuf_get_height(pixbuf);
659 if (width > 128 || height > 128) {
660 int scaled_width = width > height ? 128 : (128 * width) / height;
661 int scaled_height = height > width ? 128 : (128 * height) / width;
662 GdkPixbuf *scaled =
663 gdk_pixbuf_scale_simple(pixbuf, scaled_width, scaled_height,
664 GDK_INTERP_BILINEAR);
665
666 purple_debug_info("pidgin",
667 "dialog icon was too large, scaled it down\n");
668 if (scaled) {
669 g_object_unref(pixbuf);
670 pixbuf = scaled;
671 }
672 }
673 img = gtk_image_new_from_pixbuf(pixbuf);
674 g_object_unref(pixbuf);
675 } else {
676 purple_debug_info("pidgin", "failed to parse dialog icon\n");
677 }
678 }
679
680 if (!img) {
681 img = gtk_image_new_from_stock(PIDGIN_STOCK_DIALOG_QUESTION,
682 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE));
683 }
684 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); 769 gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
685 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); 770 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
686 771
687 /* Vertical box */ 772 /* Vertical box */
688 vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER); 773 vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER);
689 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); 774 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
690 775
691 pidgin_widget_decorate_account(hbox, account); 776 pidgin_widget_decorate_account(hbox,
777 purple_request_cpar_get_account(cpar));
692 778
693 /* Descriptive label */ 779 /* Descriptive label */
694 primary_esc = (primary != NULL) ? g_markup_escape_text(primary, -1) : NULL; 780 primary_esc = pidgin_request_escape(cpar, primary);
695 secondary_esc = (secondary != NULL) ? g_markup_escape_text(secondary, -1) : NULL; 781 secondary_esc = pidgin_request_escape(cpar, secondary);
696 label_text = g_strdup_printf((primary ? "<span weight=\"bold\" size=\"larger\">" 782 label_text = g_strdup_printf((primary ? "<span weight=\"bold\" size=\"larger\">"
697 "%s</span>%s%s" : "%s%s%s"), 783 "%s</span>%s%s" : "%s%s%s"),
698 (primary ? primary_esc : ""), 784 (primary ? primary_esc : ""),
699 ((primary && secondary) ? "\n\n" : ""), 785 ((primary && secondary) ? "\n\n" : ""),
700 (secondary ? secondary_esc : "")); 786 (secondary ? secondary_esc : ""));
728 pidgin_auto_parent_window(dialog); 814 pidgin_auto_parent_window(dialog);
729 815
730 gtk_widget_show_all(dialog); 816 gtk_widget_show_all(dialog);
731 817
732 return data; 818 return data;
733 }
734
735 static void *
736 pidgin_request_action(const char *title, const char *primary,
737 const char *secondary, int default_action,
738 PurpleAccount *account, const char *who, PurpleConversation *conv,
739 void *user_data, size_t action_count, va_list actions)
740 {
741 return pidgin_request_action_with_icon(title, primary, secondary,
742 default_action, account, who, conv, NULL, 0, user_data, action_count,
743 actions);
744 } 819 }
745 820
746 static void 821 static void
747 req_entry_field_changed_cb(GtkWidget *entry, PurpleRequestField *field) 822 req_entry_field_changed_cb(GtkWidget *entry, PurpleRequestField *field)
748 { 823 {
950 1025
951 return widget; 1026 return widget;
952 } 1027 }
953 1028
954 static GtkWidget * 1029 static GtkWidget *
955 create_choice_field(PurpleRequestField *field) 1030 create_choice_field(PurpleRequestField *field,
1031 PurpleRequestCommonParameters *cpar)
956 { 1032 {
957 GtkWidget *widget; 1033 GtkWidget *widget;
958 GList *labels = purple_request_field_choice_get_labels(field); 1034 GList *elements = purple_request_field_choice_get_elements(field);
959 int num_labels = g_list_length(labels); 1035 int num_labels = g_list_length(elements) / 2;
960 GList *l; 1036 GList *l;
961 1037 gpointer *values = g_new(gpointer, num_labels);
962 if (num_labels > 5) 1038 gpointer default_value;
1039 int i;
1040
1041 default_value = purple_request_field_choice_get_default_value(field);
1042 if (num_labels > 5 || purple_request_cpar_is_compact(cpar))
963 { 1043 {
1044 int default_index = 0;
964 widget = gtk_combo_box_text_new(); 1045 widget = gtk_combo_box_text_new();
965 1046
966 for (l = labels; l != NULL; l = l->next) 1047 i = 0;
1048 l = elements;
1049 while (l != NULL)
967 { 1050 {
968 const char *text = l->data; 1051 const char *text;
1052 gpointer *value;
1053
1054 text = l->data;
1055 l = g_list_next(l);
1056 value = l->data;
1057 l = g_list_next(l);
1058
969 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widget), text); 1059 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widget), text);
1060 if (value == default_value)
1061 default_index = i;
1062 values[i++] = value;
970 } 1063 }
971 1064
972 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), 1065 gtk_combo_box_set_active(GTK_COMBO_BOX(widget), default_index);
973 purple_request_field_choice_get_default_value(field));
974 1066
975 gtk_widget_set_tooltip_text(widget, purple_request_field_get_tooltip(field)); 1067 gtk_widget_set_tooltip_text(widget, purple_request_field_get_tooltip(field));
976 1068
977 g_signal_connect(G_OBJECT(widget), "changed", 1069 g_signal_connect(G_OBJECT(widget), "changed",
978 G_CALLBACK(field_choice_menu_cb), field); 1070 G_CALLBACK(field_choice_menu_cb), field);
980 else 1072 else
981 { 1073 {
982 GtkWidget *box; 1074 GtkWidget *box;
983 GtkWidget *first_radio = NULL; 1075 GtkWidget *first_radio = NULL;
984 GtkWidget *radio; 1076 GtkWidget *radio;
985 gint i;
986 1077
987 if (num_labels == 2) 1078 if (num_labels == 2)
988 box = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE); 1079 box = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
989 else 1080 else
990 box = gtk_vbox_new(FALSE, 0); 1081 box = gtk_vbox_new(FALSE, 0);
991 1082
992 widget = box; 1083 widget = box;
993 1084
994 gtk_widget_set_tooltip_text(widget, purple_request_field_get_tooltip(field)); 1085 gtk_widget_set_tooltip_text(widget, purple_request_field_get_tooltip(field));
995 1086
996 for (l = labels, i = 0; l != NULL; l = l->next, i++) 1087 i = 0;
1088 l = elements;
1089 while (l != NULL)
997 { 1090 {
998 const char *text = l->data; 1091 const char *text;
1092 gpointer *value;
1093
1094 text = l->data;
1095 l = g_list_next(l);
1096 value = l->data;
1097 l = g_list_next(l);
999 1098
1000 radio = gtk_radio_button_new_with_label_from_widget( 1099 radio = gtk_radio_button_new_with_label_from_widget(
1001 GTK_RADIO_BUTTON(first_radio), text); 1100 GTK_RADIO_BUTTON(first_radio), text);
1101 g_object_set_data(G_OBJECT(radio), "box", box);
1002 1102
1003 if (first_radio == NULL) 1103 if (first_radio == NULL)
1004 first_radio = radio; 1104 first_radio = radio;
1005 1105
1006 if (i == purple_request_field_choice_get_default_value(field)) 1106 if (value == default_value)
1007 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE); 1107 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE);
1108 values[i++] = value;
1008 1109
1009 gtk_box_pack_start(GTK_BOX(box), radio, TRUE, TRUE, 0); 1110 gtk_box_pack_start(GTK_BOX(box), radio, TRUE, TRUE, 0);
1010 gtk_widget_show(radio); 1111 gtk_widget_show(radio);
1011 1112
1012 g_signal_connect(G_OBJECT(radio), "toggled", 1113 g_signal_connect(G_OBJECT(radio), "toggled",
1013 G_CALLBACK(field_choice_option_cb), field); 1114 G_CALLBACK(field_choice_option_cb), field);
1014 } 1115 }
1015 } 1116 }
1117
1118 g_object_set_data_full(G_OBJECT(widget), "values", values, g_free);
1016 1119
1017 return widget; 1120 return widget;
1018 } 1121 }
1019 1122
1020 static GtkWidget * 1123 static GtkWidget *
1219 #endif 1322 #endif
1220 } 1323 }
1221 1324
1222 static void * 1325 static void *
1223 pidgin_request_fields(const char *title, const char *primary, 1326 pidgin_request_fields(const char *title, const char *primary,
1224 const char *secondary, PurpleRequestFields *fields, 1327 const char *secondary, PurpleRequestFields *fields, const char *ok_text,
1225 const char *ok_text, GCallback ok_cb, 1328 GCallback ok_cb, const char *cancel_text, GCallback cancel_cb,
1226 const char *cancel_text, GCallback cancel_cb, 1329 PurpleRequestCommonParameters *cpar, void *user_data)
1227 PurpleAccount *account, const char *who, PurpleConversation *conv,
1228 void *user_data)
1229 { 1330 {
1230 PidginRequestData *data; 1331 PidginRequestData *data;
1231 GtkWidget *win; 1332 GtkWidget *win;
1232 GtkWidget *vbox; 1333 GtkWidget *vbox;
1233 GtkWidget *vbox2; 1334 GtkWidget *vbox2;
1242 PurpleRequestFieldGroup *group; 1343 PurpleRequestFieldGroup *group;
1243 PurpleRequestField *field; 1344 PurpleRequestField *field;
1244 char *label_text; 1345 char *label_text;
1245 char *primary_esc, *secondary_esc; 1346 char *primary_esc, *secondary_esc;
1246 int total_fields = 0; 1347 int total_fields = 0;
1348 const gboolean compact = purple_request_cpar_is_compact(cpar);
1247 1349
1248 data = g_new0(PidginRequestData, 1); 1350 data = g_new0(PidginRequestData, 1);
1249 data->type = PURPLE_REQUEST_FIELDS; 1351 data->type = PURPLE_REQUEST_FIELDS;
1250 data->user_data = user_data; 1352 data->user_data = user_data;
1251 data->u.multifield.fields = fields; 1353 data->u.multifield.fields = fields;
1272 hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER); 1374 hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER);
1273 gtk_container_add(GTK_CONTAINER(pidgin_dialog_get_vbox(GTK_DIALOG(win))), hbox); 1375 gtk_container_add(GTK_CONTAINER(pidgin_dialog_get_vbox(GTK_DIALOG(win))), hbox);
1274 gtk_widget_show(hbox); 1376 gtk_widget_show(hbox);
1275 1377
1276 /* Dialog icon. */ 1378 /* Dialog icon. */
1277 img = gtk_image_new_from_stock(PIDGIN_STOCK_DIALOG_QUESTION, 1379 img = pidgin_request_dialog_icon(cpar);
1278 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE));
1279 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); 1380 gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
1280 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); 1381 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
1281 gtk_widget_show(img); 1382 gtk_widget_show(img);
1282 1383
1283 /* Cancel button */ 1384 /* Cancel button */
1288 button = pidgin_dialog_add_button(GTK_DIALOG(win), text_to_stock(ok_text), G_CALLBACK(multifield_ok_cb), data); 1389 button = pidgin_dialog_add_button(GTK_DIALOG(win), text_to_stock(ok_text), G_CALLBACK(multifield_ok_cb), data);
1289 data->ok_button = button; 1390 data->ok_button = button;
1290 gtk_widget_set_can_default(button, TRUE); 1391 gtk_widget_set_can_default(button, TRUE);
1291 gtk_window_set_default(GTK_WINDOW(win), button); 1392 gtk_window_set_default(GTK_WINDOW(win), button);
1292 1393
1293 pidgin_widget_decorate_account(hbox, account); 1394 pidgin_widget_decorate_account(hbox,
1395 purple_request_cpar_get_account(cpar));
1294 1396
1295 /* Setup the vbox */ 1397 /* Setup the vbox */
1296 vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER); 1398 vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BORDER);
1297 gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0); 1399 gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
1298 gtk_widget_show(vbox); 1400 gtk_widget_show(vbox);
1299 1401
1300 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); 1402 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1301 1403
1302 if(primary) { 1404 if(primary) {
1303 primary_esc = g_markup_escape_text(primary, -1); 1405 primary_esc = pidgin_request_escape(cpar, primary);
1304 label_text = g_strdup_printf( 1406 label_text = g_strdup_printf(
1305 "<span weight=\"bold\" size=\"larger\">%s</span>", primary_esc); 1407 "<span weight=\"bold\" size=\"larger\">%s</span>", primary_esc);
1306 g_free(primary_esc); 1408 g_free(primary_esc);
1307 label = gtk_label_new(NULL); 1409 label = gtk_label_new(NULL);
1308 1410
1339 } else { 1441 } else {
1340 vbox2 = vbox; 1442 vbox2 = vbox;
1341 } 1443 }
1342 1444
1343 if (secondary) { 1445 if (secondary) {
1344 secondary_esc = g_markup_escape_text(secondary, -1); 1446 secondary_esc = pidgin_request_escape(cpar, secondary);
1345 label = gtk_label_new(NULL); 1447 label = gtk_label_new(NULL);
1346 1448
1347 gtk_label_set_markup(GTK_LABEL(label), secondary_esc); 1449 gtk_label_set_markup(GTK_LABEL(label), secondary_esc);
1348 g_free(secondary_esc); 1450 g_free(secondary_esc);
1349 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); 1451 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
1408 { 1510 {
1409 if (col_num > 0) 1511 if (col_num > 0)
1410 rows++; 1512 rows++;
1411 1513
1412 rows += 2; 1514 rows += 2;
1413 } 1515 } else if (compact && type != PURPLE_REQUEST_FIELD_BOOLEAN)
1516 rows++;
1414 1517
1415 col_num++; 1518 col_num++;
1416 1519
1417 if (col_num >= cols) 1520 if (col_num >= cols)
1418 col_num = 0; 1521 col_num = 0;
1419 } 1522 }
1420 1523
1421 table = gtk_table_new(rows, 2 * cols, FALSE); 1524 if (compact)
1525 table = gtk_table_new(rows, cols, FALSE);
1526 else
1527 table = gtk_table_new(rows, 2 * cols, FALSE);
1422 gtk_table_set_row_spacings(GTK_TABLE(table), PIDGIN_HIG_BOX_SPACE); 1528 gtk_table_set_row_spacings(GTK_TABLE(table), PIDGIN_HIG_BOX_SPACE);
1423 gtk_table_set_col_spacings(GTK_TABLE(table), PIDGIN_HIG_BOX_SPACE); 1529 gtk_table_set_col_spacings(GTK_TABLE(table), PIDGIN_HIG_BOX_SPACE);
1424 1530
1425 gtk_container_add(GTK_CONTAINER(frame), table); 1531 gtk_container_add(GTK_CONTAINER(frame), table);
1426 gtk_widget_show(table); 1532 gtk_widget_show(table);
1451 1557
1452 if (type != PURPLE_REQUEST_FIELD_BOOLEAN && field_label) 1558 if (type != PURPLE_REQUEST_FIELD_BOOLEAN && field_label)
1453 { 1559 {
1454 char *text = NULL; 1560 char *text = NULL;
1455 1561
1456 if (field_label[strlen(field_label) - 1] != ':') 1562 if (field_label[strlen(field_label) - 1] != ':' &&
1563 field_label[strlen(field_label) - 1] != '?')
1564 {
1457 text = g_strdup_printf("%s:", field_label); 1565 text = g_strdup_printf("%s:", field_label);
1566 }
1458 1567
1459 label = gtk_label_new(NULL); 1568 label = gtk_label_new(NULL);
1460 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), text ? text : field_label); 1569 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), text ? text : field_label);
1461 g_free(text); 1570 g_free(text);
1462 1571
1497 else if (type == PURPLE_REQUEST_FIELD_INTEGER) 1606 else if (type == PURPLE_REQUEST_FIELD_INTEGER)
1498 widget = create_int_field(field); 1607 widget = create_int_field(field);
1499 else if (type == PURPLE_REQUEST_FIELD_BOOLEAN) 1608 else if (type == PURPLE_REQUEST_FIELD_BOOLEAN)
1500 widget = create_bool_field(field); 1609 widget = create_bool_field(field);
1501 else if (type == PURPLE_REQUEST_FIELD_CHOICE) 1610 else if (type == PURPLE_REQUEST_FIELD_CHOICE)
1502 widget = create_choice_field(field); 1611 widget = create_choice_field(field, cpar);
1503 else if (type == PURPLE_REQUEST_FIELD_LIST) 1612 else if (type == PURPLE_REQUEST_FIELD_LIST)
1504 widget = create_list_field(field); 1613 widget = create_list_field(field);
1505 else if (type == PURPLE_REQUEST_FIELD_IMAGE) 1614 else if (type == PURPLE_REQUEST_FIELD_IMAGE)
1506 widget = create_image_field(field); 1615 widget = create_image_field(field);
1507 else if (type == PURPLE_REQUEST_FIELD_ACCOUNT) 1616 else if (type == PURPLE_REQUEST_FIELD_ACCOUNT)
1541 row_num, row_num + 1, 1650 row_num, row_num + 1,
1542 GTK_FILL | GTK_EXPAND, 1651 GTK_FILL | GTK_EXPAND,
1543 GTK_FILL | GTK_EXPAND, 1652 GTK_FILL | GTK_EXPAND,
1544 5, 0); 1653 5, 0);
1545 } 1654 }
1546 else 1655 else if (compact) {
1547 { 1656 row_num++;
1657 gtk_table_attach(GTK_TABLE(table), widget,
1658 0, 2 * cols,
1659 row_num, row_num + 1,
1660 GTK_FILL | GTK_EXPAND,
1661 GTK_FILL | GTK_EXPAND,
1662 5, 0);
1663 } else {
1548 gtk_table_attach(GTK_TABLE(table), widget, 1664 gtk_table_attach(GTK_TABLE(table), widget,
1549 1, 2 * cols, 1665 1, 2 * cols,
1550 row_num, row_num + 1, 1666 row_num, row_num + 1,
1551 GTK_FILL | GTK_EXPAND, 1667 GTK_FILL | GTK_EXPAND,
1552 GTK_FILL | GTK_EXPAND, 1668 GTK_FILL | GTK_EXPAND,
1616 } 1732 }
1617 if ((data->u.file.savedialog == TRUE) && 1733 if ((data->u.file.savedialog == TRUE) &&
1618 (g_file_test(data->u.file.name, G_FILE_TEST_EXISTS))) { 1734 (g_file_test(data->u.file.name, G_FILE_TEST_EXISTS))) {
1619 purple_request_action(data, NULL, _("That file already exists"), 1735 purple_request_action(data, NULL, _("That file already exists"),
1620 _("Would you like to overwrite it?"), 0, 1736 _("Would you like to overwrite it?"), 0,
1621 NULL, NULL, NULL, 1737 NULL,
1622 data, 2, 1738 data, 2,
1623 _("Overwrite"), G_CALLBACK(file_yes_no_cb), 1739 _("Overwrite"), G_CALLBACK(file_yes_no_cb),
1624 _("Choose New Name"), G_CALLBACK(file_yes_no_cb)); 1740 _("Choose New Name"), G_CALLBACK(file_yes_no_cb));
1625 } else 1741 } else
1626 file_yes_no_cb(data, 1); 1742 file_yes_no_cb(data, 1);
1627 } 1743 }
1628 1744
1629 static void * 1745 static void *
1630 pidgin_request_file(const char *title, const char *filename, 1746 pidgin_request_file(const char *title, const char *filename,
1631 gboolean savedialog, 1747 gboolean savedialog, GCallback ok_cb, GCallback cancel_cb,
1632 GCallback ok_cb, GCallback cancel_cb, 1748 PurpleRequestCommonParameters *cpar, void *user_data)
1633 PurpleAccount *account, const char *who, PurpleConversation *conv,
1634 void *user_data)
1635 { 1749 {
1636 PidginRequestData *data; 1750 PidginRequestData *data;
1637 GtkWidget *filesel; 1751 GtkWidget *filesel;
1638 #ifdef _WIN32 1752 #ifdef _WIN32
1639 const gchar *current_folder; 1753 const gchar *current_folder;
1704 1818
1705 return (void *)data; 1819 return (void *)data;
1706 } 1820 }
1707 1821
1708 static void * 1822 static void *
1709 pidgin_request_folder(const char *title, const char *dirname, 1823 pidgin_request_folder(const char *title, const char *dirname, GCallback ok_cb,
1710 GCallback ok_cb, GCallback cancel_cb, 1824 GCallback cancel_cb, PurpleRequestCommonParameters *cpar,
1711 PurpleAccount *account, const char *who, PurpleConversation *conv, 1825 void *user_data)
1712 void *user_data)
1713 { 1826 {
1714 PidginRequestData *data; 1827 PidginRequestData *data;
1715 GtkWidget *dirsel; 1828 GtkWidget *dirsel;
1716 1829
1717 data = g_new0(PidginRequestData, 1); 1830 data = g_new0(PidginRequestData, 1);
1788 g_free(data); 1901 g_free(data);
1789 } 1902 }
1790 1903
1791 static PurpleRequestUiOps ops = 1904 static PurpleRequestUiOps ops =
1792 { 1905 {
1906 PURPLE_REQUEST_FEATURE_HTML,
1793 pidgin_request_input, 1907 pidgin_request_input,
1794 pidgin_request_choice, 1908 pidgin_request_choice,
1795 pidgin_request_action, 1909 pidgin_request_action,
1796 pidgin_request_fields, 1910 pidgin_request_fields,
1797 pidgin_request_file, 1911 pidgin_request_file,
1798 pidgin_close_request, 1912 pidgin_close_request,
1799 pidgin_request_folder, 1913 pidgin_request_folder,
1800 pidgin_request_action_with_icon, 1914 NULL,
1801 NULL, 1915 NULL,
1802 NULL, 1916 NULL,
1803 NULL 1917 NULL
1804 }; 1918 };
1805 1919

mercurial