3 * Pidgin is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 #include "tls-certificate-info.h"
29 #include "gtkwebview.h"
30 #include "gtkrequest.h"
32 #include "pidginstock.h"
34 #include "gtkinternal.h"
36 #include <gdk/gdkkeysyms.h>
39 #define GCR_API_SUBJECT_TO_CHANGE
43 #include "gtk3compat.h"
47 PurpleRequestType type
;
61 GtkProgressBar
*progress_bar
;
75 PurpleRequestFields
*fields
;
90 static GHashTable
*datasheet_stock
= NULL
;
92 static GtkWidget
* create_account_field(PurpleRequestField
*field
);
95 pidgin_widget_decorate_account(GtkWidget
*cont
, PurpleAccount
*account
)
103 pixbuf
= pidgin_create_protocol_icon(account
, PIDGIN_PROTOCOL_ICON_SMALL
);
104 image
= gtk_image_new_from_pixbuf(pixbuf
);
105 g_object_unref(G_OBJECT(pixbuf
));
107 gtk_widget_set_tooltip_text(image
, purple_account_get_username(account
));
109 if (GTK_IS_DIALOG(cont
)) {
110 gtk_box_pack_start(GTK_BOX(gtk_dialog_get_action_area(GTK_DIALOG(cont
))),
111 image
, FALSE
, TRUE
, 0);
112 gtk_box_reorder_child(GTK_BOX(gtk_dialog_get_action_area(GTK_DIALOG(cont
))),
114 } else if (GTK_IS_BOX(cont
)) {
115 gtk_widget_set_halign(image
, GTK_ALIGN_START
);
116 gtk_widget_set_valign(image
, GTK_ALIGN_START
);
117 gtk_box_pack_end(GTK_BOX(cont
), image
, FALSE
, TRUE
, 0);
119 gtk_widget_show(image
);
123 generic_response_start(PidginRequestData
*data
)
125 g_return_if_fail(data
!= NULL
);
127 /* Tell the user we're doing something. */
128 pidgin_set_cursor(GTK_WIDGET(data
->dialog
), GDK_WATCH
);
130 g_object_set_data(G_OBJECT(data
->dialog
),
131 "pidgin-window-is-closing", GINT_TO_POINTER(TRUE
));
132 gtk_widget_set_visible(GTK_WIDGET(data
->dialog
), FALSE
);
136 input_response_cb(GtkDialog
*dialog
, gint id
, PidginRequestData
*data
)
139 char *multiline_value
= NULL
;
141 generic_response_start(data
);
143 if (data
->u
.input
.multiline
) {
144 GtkTextIter start_iter
, end_iter
;
145 GtkTextBuffer
*buffer
=
146 gtk_text_view_get_buffer(GTK_TEXT_VIEW(data
->u
.input
.entry
));
148 gtk_text_buffer_get_start_iter(buffer
, &start_iter
);
149 gtk_text_buffer_get_end_iter(buffer
, &end_iter
);
151 if ((data
->u
.input
.hint
!= NULL
) && (!strcmp(data
->u
.input
.hint
, "html")))
152 multiline_value
= pidgin_webview_get_body_html(PIDGIN_WEBVIEW(data
->u
.input
.entry
));
154 multiline_value
= gtk_text_buffer_get_text(buffer
, &start_iter
, &end_iter
,
157 value
= multiline_value
;
160 value
= gtk_entry_get_text(GTK_ENTRY(data
->u
.input
.entry
));
162 if (id
>= 0 && (gsize
)id
< data
->cb_count
&& data
->cbs
[id
] != NULL
)
163 ((PurpleRequestInputCb
)data
->cbs
[id
])(data
->user_data
, value
);
164 else if (data
->cbs
[1] != NULL
)
165 ((PurpleRequestInputCb
)data
->cbs
[1])(data
->user_data
, value
);
167 if (data
->u
.input
.multiline
)
168 g_free(multiline_value
);
170 purple_request_close(PURPLE_REQUEST_INPUT
, data
);
174 action_response_cb(GtkDialog
*dialog
, gint id
, PidginRequestData
*data
)
176 generic_response_start(data
);
178 if (id
>= 0 && (gsize
)id
< data
->cb_count
&& data
->cbs
[id
] != NULL
)
179 ((PurpleRequestActionCb
)data
->cbs
[id
])(data
->user_data
, id
);
181 purple_request_close(PURPLE_REQUEST_INPUT
, data
);
186 choice_response_cb(GtkDialog
*dialog
, gint id
, PidginRequestData
*data
)
188 GtkWidget
*radio
= g_object_get_data(G_OBJECT(dialog
), "radio");
189 GSList
*group
= gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio
));
191 generic_response_start(data
);
193 if (id
>= 0 && (gsize
)id
< data
->cb_count
&& data
->cbs
[id
] != NULL
)
195 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(group
->data
))) {
196 ((PurpleRequestChoiceCb
)data
->cbs
[id
])(data
->user_data
, g_object_get_data(G_OBJECT(group
->data
), "choice_value"));
201 purple_request_close(PURPLE_REQUEST_INPUT
, data
);
205 field_string_focus_out_cb(GtkWidget
*entry
, GdkEventFocus
*event
,
206 PurpleRequestField
*field
)
210 if (purple_request_field_string_is_multiline(field
))
212 GtkTextBuffer
*buffer
;
213 GtkTextIter start_iter
, end_iter
;
215 buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry
));
217 gtk_text_buffer_get_start_iter(buffer
, &start_iter
);
218 gtk_text_buffer_get_end_iter(buffer
, &end_iter
);
220 value
= gtk_text_buffer_get_text(buffer
, &start_iter
, &end_iter
, FALSE
);
223 value
= gtk_entry_get_text(GTK_ENTRY(entry
));
225 purple_request_field_string_set_value(field
,
226 (*value
== '\0' ? NULL
: value
));
232 field_bool_cb(GtkToggleButton
*button
, PurpleRequestField
*field
)
234 purple_request_field_bool_set_value(field
,
235 gtk_toggle_button_get_active(button
));
239 field_choice_menu_cb(GtkComboBox
*menu
, PurpleRequestField
*field
)
241 int active
= gtk_combo_box_get_active(menu
);
242 gpointer
*values
= g_object_get_data(G_OBJECT(menu
), "values");
244 g_return_if_fail(values
!= NULL
);
245 g_return_if_fail(active
>= 0);
247 purple_request_field_choice_set_value(field
, values
[active
]);
251 field_choice_option_cb(GtkRadioButton
*button
, PurpleRequestField
*field
)
254 gpointer
*values
= g_object_get_data(G_OBJECT(g_object_get_data(
255 G_OBJECT(button
), "box")), "values");
257 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button
)))
260 active
= (g_slist_length(gtk_radio_button_get_group(button
)) -
261 g_slist_index(gtk_radio_button_get_group(button
), button
)) - 1;
263 g_return_if_fail(values
!= NULL
);
264 g_return_if_fail(active
>= 0);
266 purple_request_field_choice_set_value(field
, values
[active
]);
270 field_account_cb(GObject
*w
, PurpleAccount
*account
, PurpleRequestField
*field
)
272 purple_request_field_account_set_value(field
, account
);
276 multifield_ok_cb(GtkWidget
*button
, PidginRequestData
*data
)
278 generic_response_start(data
);
280 if (!gtk_widget_has_focus(button
))
281 gtk_widget_grab_focus(button
);
283 if (data
->cbs
[0] != NULL
)
284 ((PurpleRequestFieldsCb
)data
->cbs
[0])(data
->user_data
,
285 data
->u
.multifield
.fields
);
287 purple_request_close(PURPLE_REQUEST_FIELDS
, data
);
291 multifield_cancel_cb(GtkWidget
*button
, PidginRequestData
*data
)
293 generic_response_start(data
);
295 if (data
->cbs
[1] != NULL
)
296 ((PurpleRequestFieldsCb
)data
->cbs
[1])(data
->user_data
,
297 data
->u
.multifield
.fields
);
299 purple_request_close(PURPLE_REQUEST_FIELDS
, data
);
303 multifield_extra_cb(GtkWidget
*button
, PidginRequestData
*data
)
305 PurpleRequestFieldsCb cb
;
307 generic_response_start(data
);
309 cb
= g_object_get_data(G_OBJECT(button
), "extra-cb");
312 cb(data
->user_data
, data
->u
.multifield
.fields
);
314 purple_request_close(PURPLE_REQUEST_FIELDS
, data
);
318 destroy_multifield_cb(GtkWidget
*dialog
, GdkEvent
*event
,
319 PidginRequestData
*data
)
321 multifield_cancel_cb(NULL
, data
);
326 #define STOCK_ITEMIZE(r, l) \
327 if (!strcmp((r), text) || !strcmp(_(r), text)) \
331 text_to_stock(const char *text
)
333 STOCK_ITEMIZE(N_("Yes"), GTK_STOCK_YES
);
334 STOCK_ITEMIZE(N_("_Yes"), GTK_STOCK_YES
);
335 STOCK_ITEMIZE(N_("No"), GTK_STOCK_NO
);
336 STOCK_ITEMIZE(N_("_No"), GTK_STOCK_NO
);
337 STOCK_ITEMIZE(N_("OK"), GTK_STOCK_OK
);
338 STOCK_ITEMIZE(N_("_OK"), GTK_STOCK_OK
);
339 STOCK_ITEMIZE(N_("Cancel"), GTK_STOCK_CANCEL
);
340 STOCK_ITEMIZE(N_("_Cancel"), GTK_STOCK_CANCEL
);
341 STOCK_ITEMIZE(N_("Apply"), GTK_STOCK_APPLY
);
342 STOCK_ITEMIZE(N_("Close"), GTK_STOCK_CLOSE
);
343 STOCK_ITEMIZE(N_("Delete"), GTK_STOCK_DELETE
);
344 STOCK_ITEMIZE(N_("Add"), GTK_STOCK_ADD
);
345 STOCK_ITEMIZE(N_("Remove"), GTK_STOCK_REMOVE
);
346 STOCK_ITEMIZE(N_("Save"), GTK_STOCK_SAVE
);
347 STOCK_ITEMIZE(N_("Next"), PIDGIN_STOCK_NEXT
);
348 STOCK_ITEMIZE(N_("_Next"), PIDGIN_STOCK_NEXT
);
349 STOCK_ITEMIZE(N_("Back"), GTK_STOCK_GO_BACK
);
350 STOCK_ITEMIZE(N_("_Back"), GTK_STOCK_GO_BACK
);
351 STOCK_ITEMIZE(N_("Alias"), PIDGIN_STOCK_ALIAS
);
359 pidgin_request_escape(PurpleRequestCommonParameters
*cpar
, const gchar
*text
)
364 if (purple_request_cpar_is_html(cpar
)) {
367 valid
= pango_parse_markup(text
, -1, 0, NULL
, NULL
, NULL
, NULL
);
370 return g_strdup(text
);
372 purple_debug_error("pidgin", "Passed label text is not "
373 "a valid markup. Falling back to plain text.");
377 return g_markup_escape_text(text
, -1);
381 pidgin_request_dialog_icon(PurpleRequestType dialog_type
,
382 PurpleRequestCommonParameters
*cpar
)
384 GtkWidget
*img
= NULL
;
385 PurpleRequestIconType icon_type
;
386 gconstpointer icon_data
;
388 const gchar
*icon_stock
= PIDGIN_STOCK_DIALOG_QUESTION
;
391 icon_data
= purple_request_cpar_get_custom_icon(cpar
, &icon_size
);
395 pixbuf
= pidgin_pixbuf_from_data(icon_data
, icon_size
);
397 /* scale the image if it is too large */
398 int width
= gdk_pixbuf_get_width(pixbuf
);
399 int height
= gdk_pixbuf_get_height(pixbuf
);
400 if (width
> 128 || height
> 128) {
401 int scaled_width
= width
> height
?
402 128 : (128 * width
) / height
;
403 int scaled_height
= height
> width
?
404 128 : (128 * height
) / width
;
407 purple_debug_info("pidgin", "dialog icon was "
408 "too large, scaling it down");
410 scaled
= gdk_pixbuf_scale_simple(pixbuf
,
411 scaled_width
, scaled_height
,
412 GDK_INTERP_BILINEAR
);
414 g_object_unref(pixbuf
);
418 img
= gtk_image_new_from_pixbuf(pixbuf
);
419 g_object_unref(pixbuf
);
421 purple_debug_info("pidgin",
422 "failed to parse dialog icon");
429 icon_type
= purple_request_cpar_get_icon(cpar
);
432 case PURPLE_REQUEST_ICON_DEFAULT
:
435 case PURPLE_REQUEST_ICON_REQUEST
:
436 icon_stock
= PIDGIN_STOCK_DIALOG_QUESTION
;
438 case PURPLE_REQUEST_ICON_DIALOG
:
439 case PURPLE_REQUEST_ICON_INFO
:
440 case PURPLE_REQUEST_ICON_WAIT
: /* TODO: we need another icon */
441 icon_stock
= PIDGIN_STOCK_DIALOG_INFO
;
443 case PURPLE_REQUEST_ICON_WARNING
:
444 icon_stock
= PIDGIN_STOCK_DIALOG_WARNING
;
446 case PURPLE_REQUEST_ICON_ERROR
:
447 icon_stock
= PIDGIN_STOCK_DIALOG_ERROR
;
449 /* intentionally no default value */
452 if (icon_stock
== NULL
) {
453 switch (dialog_type
) {
454 case PURPLE_REQUEST_INPUT
:
455 case PURPLE_REQUEST_CHOICE
:
456 case PURPLE_REQUEST_ACTION
:
457 case PURPLE_REQUEST_FIELDS
:
458 case PURPLE_REQUEST_FILE
:
459 case PURPLE_REQUEST_FOLDER
:
460 icon_stock
= PIDGIN_STOCK_DIALOG_QUESTION
;
462 case PURPLE_REQUEST_WAIT
:
463 icon_stock
= PIDGIN_STOCK_DIALOG_INFO
;
465 /* intentionally no default value */
469 img
= gtk_image_new_from_stock(icon_stock
,
470 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE
));
472 if (img
|| icon_type
== PURPLE_REQUEST_ICON_REQUEST
)
475 return gtk_image_new_from_stock(PIDGIN_STOCK_DIALOG_QUESTION
,
476 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE
));
480 pidgin_request_help_clicked(GtkButton
*button
, gpointer _unused
)
482 PurpleRequestHelpCb cb
;
485 cb
= g_object_get_data(G_OBJECT(button
), "pidgin-help-cb");
486 data
= g_object_get_data(G_OBJECT(button
), "pidgin-help-data");
488 g_return_if_fail(cb
!= NULL
);
493 pidgin_request_add_help(GtkDialog
*dialog
, PurpleRequestCommonParameters
*cpar
)
496 PurpleRequestHelpCb help_cb
;
499 help_cb
= purple_request_cpar_get_help_cb(cpar
, &help_data
);
503 button
= gtk_dialog_add_button(dialog
, GTK_STOCK_HELP
,
506 g_object_set_data(G_OBJECT(button
), "pidgin-help-cb", help_cb
);
507 g_object_set_data(G_OBJECT(button
), "pidgin-help-data", help_data
);
509 g_signal_connect(G_OBJECT(button
), "clicked",
510 G_CALLBACK(pidgin_request_help_clicked
), NULL
);
514 pidgin_request_input(const char *title
, const char *primary
,
515 const char *secondary
, const char *default_value
,
516 gboolean multiline
, gboolean masked
, gchar
*hint
,
517 const char *ok_text
, GCallback ok_cb
,
518 const char *cancel_text
, GCallback cancel_cb
,
519 PurpleRequestCommonParameters
*cpar
,
522 PidginRequestData
*data
;
530 char *primary_esc
, *secondary_esc
;
532 data
= g_new0(PidginRequestData
, 1);
533 data
->type
= PURPLE_REQUEST_INPUT
;
534 data
->user_data
= user_data
;
537 data
->cbs
= g_new0(GCallback
, 2);
539 data
->cbs
[0] = ok_cb
;
540 data
->cbs
[1] = cancel_cb
;
542 /* Create the dialog. */
543 dialog
= gtk_dialog_new_with_buttons(title
? title
: PIDGIN_ALERT_TITLE
,
545 text_to_stock(cancel_text
), 1,
546 text_to_stock(ok_text
), 0,
548 data
->dialog
= dialog
;
550 g_signal_connect(G_OBJECT(dialog
), "response",
551 G_CALLBACK(input_response_cb
), data
);
553 /* Setup the dialog */
554 gtk_container_set_border_width(GTK_CONTAINER(dialog
), PIDGIN_HIG_BORDER
/2);
555 gtk_container_set_border_width(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog
))),
556 PIDGIN_HIG_BORDER
/ 2);
558 gtk_window_set_resizable(GTK_WINDOW(dialog
), FALSE
);
559 gtk_dialog_set_default_response(GTK_DIALOG(dialog
), 0);
560 gtk_box_set_spacing(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog
))),
563 /* Setup the main horizontal box */
564 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, PIDGIN_HIG_BORDER
);
565 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog
))),
569 img
= pidgin_request_dialog_icon(PURPLE_REQUEST_INPUT
, cpar
);
570 gtk_widget_set_halign(img
, GTK_ALIGN_START
);
571 gtk_widget_set_valign(img
, GTK_ALIGN_START
);
572 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 0);
574 pidgin_request_add_help(GTK_DIALOG(dialog
), cpar
);
577 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BORDER
);
579 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, TRUE
, TRUE
, 0);
581 pidgin_widget_decorate_account(hbox
, purple_request_cpar_get_account(cpar
));
583 /* Descriptive label */
584 primary_esc
= pidgin_request_escape(cpar
, primary
);
585 secondary_esc
= pidgin_request_escape(cpar
, secondary
);
586 label_text
= g_strdup_printf((primary
? "<span weight=\"bold\" size=\"larger\">"
587 "%s</span>%s%s" : "%s%s%s"),
588 (primary
? primary_esc
: ""),
589 ((primary
&& secondary
) ? "\n\n" : ""),
590 (secondary
? secondary_esc
: ""));
592 g_free(secondary_esc
);
594 label
= GTK_LABEL(gtk_label_new(NULL
));
596 gtk_label_set_markup(label
, label_text
);
597 gtk_label_set_line_wrap(label
, TRUE
);
598 gtk_label_set_xalign(label
, 0);
599 gtk_label_set_yalign(label
, 0);
600 gtk_box_pack_start(GTK_BOX(vbox
), GTK_WIDGET(label
), FALSE
, FALSE
, 0);
605 data
->u
.input
.multiline
= multiline
;
606 data
->u
.input
.hint
= g_strdup(hint
);
608 gtk_widget_show_all(hbox
);
610 if ((data
->u
.input
.hint
!= NULL
) && (!strcmp(data
->u
.input
.hint
, "html"))) {
614 frame
= pidgin_create_webview(TRUE
, &entry
, NULL
);
615 gtk_widget_set_size_request(entry
, 320, 130);
616 gtk_widget_set_name(entry
, "pidgin_request_webview");
617 if (default_value
!= NULL
)
618 pidgin_webview_append_html(PIDGIN_WEBVIEW(entry
), default_value
);
619 gtk_box_pack_start(GTK_BOX(vbox
), frame
, TRUE
, TRUE
, 0);
620 gtk_widget_show(frame
);
625 entry
= gtk_text_view_new();
626 gtk_text_view_set_editable(GTK_TEXT_VIEW(entry
), TRUE
);
628 if (default_value
!= NULL
) {
629 GtkTextBuffer
*buffer
;
631 buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry
));
632 gtk_text_buffer_set_text(buffer
, default_value
, -1);
635 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(entry
), GTK_WRAP_WORD_CHAR
);
637 gtk_box_pack_start(GTK_BOX(vbox
),
638 pidgin_make_scrollable(entry
, GTK_POLICY_NEVER
, GTK_POLICY_ALWAYS
, GTK_SHADOW_IN
, 320, 130),
642 entry
= gtk_entry_new();
644 gtk_entry_set_activates_default(GTK_ENTRY(entry
), TRUE
);
646 gtk_box_pack_start(GTK_BOX(vbox
), entry
, FALSE
, FALSE
, 0);
648 if (default_value
!= NULL
)
649 gtk_entry_set_text(GTK_ENTRY(entry
), default_value
);
653 gtk_entry_set_visibility(GTK_ENTRY(entry
), FALSE
);
656 gtk_widget_show_all(vbox
);
659 pidgin_set_accessible_label(entry
, label
);
660 data
->u
.input
.entry
= entry
;
662 pidgin_auto_parent_window(dialog
);
664 /* Show everything. */
665 gtk_widget_show(dialog
);
671 pidgin_request_choice(const char *title
, const char *primary
,
672 const char *secondary
, gpointer default_value
, const char *ok_text
,
673 GCallback ok_cb
, const char *cancel_text
, GCallback cancel_cb
,
674 PurpleRequestCommonParameters
*cpar
, void *user_data
, va_list args
)
676 PidginRequestData
*data
;
678 GtkWidget
*vbox
, *vbox2
;
682 GtkWidget
*radio
= NULL
;
685 char *primary_esc
, *secondary_esc
;
687 data
= g_new0(PidginRequestData
, 1);
688 data
->type
= PURPLE_REQUEST_ACTION
;
689 data
->user_data
= user_data
;
692 data
->cbs
= g_new0(GCallback
, 2);
693 data
->cbs
[0] = cancel_cb
;
694 data
->cbs
[1] = ok_cb
;
696 /* Create the dialog. */
697 data
->dialog
= dialog
= gtk_dialog_new();
700 gtk_window_set_title(GTK_WINDOW(dialog
), title
);
702 gtk_window_set_title(GTK_WINDOW(dialog
), PIDGIN_ALERT_TITLE
);
705 gtk_dialog_add_button(GTK_DIALOG(dialog
),
706 text_to_stock(cancel_text
), 0);
708 gtk_dialog_add_button(GTK_DIALOG(dialog
),
709 text_to_stock(ok_text
), 1);
711 g_signal_connect(G_OBJECT(dialog
), "response",
712 G_CALLBACK(choice_response_cb
), data
);
714 /* Setup the dialog */
715 gtk_container_set_border_width(GTK_CONTAINER(dialog
), PIDGIN_HIG_BORDER
/2);
716 gtk_container_set_border_width(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog
))),
717 PIDGIN_HIG_BORDER
/ 2);
718 gtk_window_set_resizable(GTK_WINDOW(dialog
), FALSE
);
719 gtk_box_set_spacing(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog
))),
722 /* Setup the main horizontal box */
723 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, PIDGIN_HIG_BORDER
);
724 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog
))),
728 img
= pidgin_request_dialog_icon(PURPLE_REQUEST_CHOICE
, cpar
);
729 gtk_widget_set_halign(img
, GTK_ALIGN_START
);
730 gtk_widget_set_valign(img
, GTK_ALIGN_START
);
731 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 0);
733 pidgin_widget_decorate_account(hbox
, purple_request_cpar_get_account(cpar
));
735 pidgin_request_add_help(GTK_DIALOG(dialog
), cpar
);
738 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BORDER
);
739 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, FALSE
, FALSE
, 0);
741 /* Descriptive label */
742 primary_esc
= pidgin_request_escape(cpar
, primary
);
743 secondary_esc
= pidgin_request_escape(cpar
, secondary
);
744 label_text
= g_strdup_printf((primary
? "<span weight=\"bold\" size=\"larger\">"
745 "%s</span>%s%s" : "%s%s%s"),
746 (primary
? primary_esc
: ""),
747 ((primary
&& secondary
) ? "\n\n" : ""),
748 (secondary
? secondary_esc
: ""));
750 g_free(secondary_esc
);
752 label
= gtk_label_new(NULL
);
754 gtk_label_set_markup(GTK_LABEL(label
), label_text
);
755 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
756 gtk_label_set_xalign(GTK_LABEL(label
), 0);
757 gtk_label_set_yalign(GTK_LABEL(label
), 0);
758 gtk_box_pack_start(GTK_BOX(vbox
), label
, TRUE
, TRUE
, 0);
762 vbox2
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BOX_SPACE
);
763 gtk_box_pack_start(GTK_BOX(vbox
), vbox2
, FALSE
, FALSE
, 0);
764 while ((radio_text
= va_arg(args
, char*))) {
765 gpointer resp
= va_arg(args
, gpointer
);
766 radio
= gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio
), radio_text
);
767 gtk_box_pack_start(GTK_BOX(vbox2
), radio
, FALSE
, FALSE
, 0);
768 g_object_set_data(G_OBJECT(radio
), "choice_value", resp
);
769 if (resp
== default_value
)
770 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio
), TRUE
);
773 g_object_set_data(G_OBJECT(dialog
), "radio", radio
);
775 /* Show everything. */
776 pidgin_auto_parent_window(dialog
);
778 gtk_widget_show_all(dialog
);
784 pidgin_request_action(const char *title
, const char *primary
,
785 const char *secondary
, int default_action
,
786 PurpleRequestCommonParameters
*cpar
, void *user_data
,
787 size_t action_count
, va_list actions
)
789 PidginRequestData
*data
;
794 GtkWidget
*img
= NULL
;
797 char *primary_esc
, *secondary_esc
;
800 data
= g_new0(PidginRequestData
, 1);
801 data
->type
= PURPLE_REQUEST_ACTION
;
802 data
->user_data
= user_data
;
804 data
->cb_count
= action_count
;
805 data
->cbs
= g_new0(GCallback
, action_count
);
807 /* Reverse the buttons */
808 buttons
= g_new0(void *, action_count
* 2);
810 for (i
= 0; i
< action_count
* 2; i
+= 2) {
811 buttons
[(action_count
* 2) - i
- 2] = va_arg(actions
, char *);
812 buttons
[(action_count
* 2) - i
- 1] = va_arg(actions
, GCallback
);
815 /* Create the dialog. */
816 data
->dialog
= dialog
= gtk_dialog_new();
818 gtk_window_set_deletable(GTK_WINDOW(data
->dialog
), FALSE
);
821 gtk_window_set_title(GTK_WINDOW(dialog
), title
);
824 gtk_window_set_title(GTK_WINDOW(dialog
), PIDGIN_ALERT_TITLE
);
827 for (i
= 0; i
< action_count
; i
++) {
828 gtk_dialog_add_button(GTK_DIALOG(dialog
),
829 text_to_stock(buttons
[2 * i
]), i
);
831 data
->cbs
[i
] = buttons
[2 * i
+ 1];
836 g_signal_connect(G_OBJECT(dialog
), "response",
837 G_CALLBACK(action_response_cb
), data
);
839 /* Setup the dialog */
840 gtk_container_set_border_width(GTK_CONTAINER(dialog
), PIDGIN_HIG_BORDER
/2);
841 gtk_container_set_border_width(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog
))),
842 PIDGIN_HIG_BORDER
/ 2);
843 gtk_window_set_resizable(GTK_WINDOW(dialog
), FALSE
);
844 gtk_box_set_spacing(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog
))),
847 /* Setup the main horizontal box */
848 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, PIDGIN_HIG_BORDER
);
849 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog
))),
852 img
= pidgin_request_dialog_icon(PURPLE_REQUEST_ACTION
, cpar
);
853 gtk_widget_set_halign(img
, GTK_ALIGN_START
);
854 gtk_widget_set_valign(img
, GTK_ALIGN_START
);
855 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 0);
858 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BORDER
);
859 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, FALSE
, FALSE
, 0);
861 pidgin_widget_decorate_account(hbox
,
862 purple_request_cpar_get_account(cpar
));
864 pidgin_request_add_help(GTK_DIALOG(dialog
), cpar
);
866 /* Descriptive label */
867 primary_esc
= pidgin_request_escape(cpar
, primary
);
868 secondary_esc
= pidgin_request_escape(cpar
, secondary
);
869 label_text
= g_strdup_printf((primary
? "<span weight=\"bold\" size=\"larger\">"
870 "%s</span>%s%s" : "%s%s%s"),
871 (primary
? primary_esc
: ""),
872 ((primary
&& secondary
) ? "\n\n" : ""),
873 (secondary
? secondary_esc
: ""));
875 g_free(secondary_esc
);
877 label
= gtk_label_new(NULL
);
879 gtk_label_set_markup(GTK_LABEL(label
), label_text
);
880 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
881 gtk_label_set_xalign(GTK_LABEL(label
), 0);
882 gtk_label_set_yalign(GTK_LABEL(label
), 0);
883 gtk_label_set_selectable(GTK_LABEL(label
), TRUE
);
884 gtk_box_pack_start(GTK_BOX(vbox
), label
, TRUE
, TRUE
, 0);
889 if (default_action
== PURPLE_DEFAULT_ACTION_NONE
) {
890 gtk_widget_set_can_default(img
, TRUE
);
891 gtk_widget_set_can_focus(img
, TRUE
);
892 gtk_widget_grab_focus(img
);
893 gtk_widget_grab_default(img
);
896 * Need to invert the default_action number because the
897 * buttons are added to the dialog in reverse order.
899 gtk_dialog_set_default_response(GTK_DIALOG(dialog
), action_count
- 1 - default_action
);
901 /* Show everything. */
902 pidgin_auto_parent_window(dialog
);
904 gtk_widget_show_all(dialog
);
910 wait_cancel_cb(GtkWidget
*button
, PidginRequestData
*data
)
912 generic_response_start(data
);
914 if (data
->cbs
[0] != NULL
)
915 ((PurpleRequestCancelCb
)data
->cbs
[0])(data
->user_data
);
917 purple_request_close(PURPLE_REQUEST_FIELDS
, data
);
921 pidgin_request_wait(const char *title
, const char *primary
,
922 const char *secondary
, gboolean with_progress
,
923 PurpleRequestCancelCb cancel_cb
, PurpleRequestCommonParameters
*cpar
,
926 PidginRequestData
*data
;
928 GtkWidget
*hbox
, *vbox
, *img
, *label
, *button
;
929 gchar
*primary_esc
, *secondary_esc
, *label_text
;
931 data
= g_new0(PidginRequestData
, 1);
932 data
->type
= PURPLE_REQUEST_WAIT
;
933 data
->user_data
= user_data
;
936 data
->cbs
= g_new0(GCallback
, 1);
937 data
->cbs
[0] = (GCallback
)cancel_cb
;
939 data
->dialog
= dialog
= gtk_dialog_new();
941 gtk_window_set_deletable(GTK_WINDOW(data
->dialog
), cancel_cb
!= NULL
);
944 gtk_window_set_title(GTK_WINDOW(dialog
), title
);
946 gtk_window_set_title(GTK_WINDOW(dialog
), _("Please wait"));
948 /* Setup the dialog */
949 gtk_container_set_border_width(GTK_CONTAINER(dialog
),
950 PIDGIN_HIG_BORDER
/ 2);
951 gtk_container_set_border_width(GTK_CONTAINER(
952 gtk_dialog_get_content_area(GTK_DIALOG(dialog
))),
953 PIDGIN_HIG_BORDER
/ 2);
954 gtk_window_set_resizable(GTK_WINDOW(dialog
), FALSE
);
955 gtk_box_set_spacing(GTK_BOX(gtk_dialog_get_content_area(
956 GTK_DIALOG(dialog
))), PIDGIN_HIG_BORDER
);
958 /* Setup the main horizontal box */
959 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, PIDGIN_HIG_BORDER
);
960 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(
961 GTK_DIALOG(dialog
))), hbox
);
963 img
= pidgin_request_dialog_icon(PURPLE_REQUEST_WAIT
, cpar
);
964 gtk_widget_set_halign(img
, GTK_ALIGN_START
);
965 gtk_widget_set_valign(img
, GTK_ALIGN_START
);
966 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 0);
969 button
= pidgin_dialog_add_button(GTK_DIALOG(dialog
),
970 text_to_stock(_("Cancel")), G_CALLBACK(wait_cancel_cb
), data
);
971 gtk_widget_set_can_default(button
, FALSE
);
974 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BORDER
);
975 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, FALSE
, FALSE
, 0);
977 pidgin_widget_decorate_account(hbox
,
978 purple_request_cpar_get_account(cpar
));
980 pidgin_request_add_help(GTK_DIALOG(dialog
), cpar
);
982 /* Descriptive label */
983 primary_esc
= pidgin_request_escape(cpar
, primary
);
984 secondary_esc
= pidgin_request_escape(cpar
, secondary
);
985 label_text
= g_strdup_printf((primary
? "<span weight=\"bold\" "
986 "size=\"larger\">%s</span>%s%s" : "%s%s%s"),
987 (primary
? primary_esc
: ""),
988 ((primary
&& secondary
) ? "\n\n" : ""),
989 (secondary
? secondary_esc
: ""));
991 g_free(secondary_esc
);
993 label
= gtk_label_new(NULL
);
995 gtk_label_set_markup(GTK_LABEL(label
), label_text
);
996 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
997 gtk_label_set_xalign(GTK_LABEL(label
), 0);
998 gtk_label_set_yalign(GTK_LABEL(label
), 0);
999 gtk_label_set_selectable(GTK_LABEL(label
), FALSE
);
1000 gtk_box_pack_start(GTK_BOX(vbox
), label
, TRUE
, TRUE
, 0);
1004 if (with_progress
) {
1005 GtkProgressBar
*bar
;
1007 bar
= data
->u
.wait
.progress_bar
=
1008 GTK_PROGRESS_BAR(gtk_progress_bar_new());
1009 gtk_progress_bar_set_fraction(bar
, 0);
1010 gtk_box_pack_start(GTK_BOX(vbox
), GTK_WIDGET(bar
),
1014 /* Move focus out of cancel button. */
1015 gtk_widget_set_can_default(img
, TRUE
);
1016 gtk_widget_set_can_focus(img
, TRUE
);
1017 gtk_widget_grab_focus(img
);
1018 gtk_widget_grab_default(img
);
1020 /* Show everything. */
1021 pidgin_auto_parent_window(dialog
);
1023 gtk_widget_show_all(dialog
);
1029 pidgin_request_wait_update(void *ui_handle
, gboolean pulse
, gfloat fraction
)
1031 GtkProgressBar
*bar
;
1032 PidginRequestData
*data
= ui_handle
;
1034 g_return_if_fail(data
->type
== PURPLE_REQUEST_WAIT
);
1036 bar
= data
->u
.wait
.progress_bar
;
1038 gtk_progress_bar_pulse(bar
);
1040 gtk_progress_bar_set_fraction(bar
, fraction
);
1044 req_entry_field_changed_cb(GtkWidget
*entry
, PurpleRequestField
*field
)
1046 if (purple_request_field_get_field_type(field
) == PURPLE_REQUEST_FIELD_INTEGER
) {
1047 int value
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(entry
));
1048 purple_request_field_int_set_value(field
, value
);
1052 if (purple_request_field_string_is_multiline(field
))
1055 GtkTextIter start_iter
, end_iter
;
1057 gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(entry
), &start_iter
);
1058 gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(entry
), &end_iter
);
1060 text
= gtk_text_buffer_get_text(GTK_TEXT_BUFFER(entry
), &start_iter
, &end_iter
, FALSE
);
1061 purple_request_field_string_set_value(field
, (!text
|| !*text
) ? NULL
: text
);
1066 const char *text
= NULL
;
1067 text
= gtk_entry_get_text(GTK_ENTRY(entry
));
1068 purple_request_field_string_set_value(field
, (*text
== '\0') ? NULL
: text
);
1073 req_field_changed_cb(GtkWidget
*widget
, PurpleRequestField
*field
)
1075 PurpleRequestFieldGroup
*group
;
1076 PurpleRequestFields
*fields
;
1077 PidginRequestData
*req_data
;
1080 group
= purple_request_field_get_group(field
);
1081 fields
= purple_request_field_group_get_fields_list(group
);
1082 req_data
= purple_request_fields_get_ui_data(fields
);
1084 gtk_widget_set_sensitive(req_data
->ok_button
,
1085 purple_request_fields_all_required_filled(fields
) &&
1086 purple_request_fields_all_valid(fields
));
1088 it
= purple_request_fields_get_autosensitive(fields
);
1089 for (; it
!= NULL
; it
= g_list_next(it
)) {
1090 PurpleRequestField
*field
= it
->data
;
1091 GtkWidget
*widget
= purple_request_field_get_ui_data(field
);
1094 sensitive
= purple_request_field_is_sensitive(field
);
1095 gtk_widget_set_sensitive(widget
, sensitive
);
1097 /* XXX: and what about multiline? */
1098 if (GTK_IS_EDITABLE(widget
))
1099 gtk_editable_set_editable(GTK_EDITABLE(widget
), sensitive
);
1104 setup_entry_field(GtkWidget
*entry
, PurpleRequestField
*field
)
1106 const char *type_hint
;
1108 gtk_entry_set_activates_default(GTK_ENTRY(entry
), TRUE
);
1110 g_signal_connect(G_OBJECT(entry
), "changed",
1111 G_CALLBACK(req_entry_field_changed_cb
), field
);
1112 g_signal_connect(G_OBJECT(entry
), "changed",
1113 G_CALLBACK(req_field_changed_cb
), field
);
1115 if ((type_hint
= purple_request_field_get_field_type_hint(field
)) != NULL
)
1117 if (purple_str_has_prefix(type_hint
, "screenname"))
1119 GtkWidget
*optmenu
= NULL
;
1120 PurpleRequestFieldGroup
*group
= purple_request_field_get_group(field
);
1121 GList
*fields
= purple_request_field_group_get_fields(group
);
1123 /* Ensure the account option menu is created (if the widget hasn't
1124 * been initialized already) for username auto-completion. */
1127 PurpleRequestField
*fld
= fields
->data
;
1128 fields
= fields
->next
;
1130 if (purple_request_field_get_field_type(fld
) == PURPLE_REQUEST_FIELD_ACCOUNT
&&
1131 purple_request_field_is_visible(fld
))
1133 const char *type_hint
= purple_request_field_get_field_type_hint(fld
);
1134 if (type_hint
!= NULL
&& strcmp(type_hint
, "account") == 0)
1136 optmenu
= GTK_WIDGET(purple_request_field_get_ui_data(fld
));
1137 if (optmenu
== NULL
) {
1138 optmenu
= GTK_WIDGET(create_account_field(fld
));
1139 purple_request_field_set_ui_data(fld
, optmenu
);
1145 pidgin_setup_screenname_autocomplete(entry
, optmenu
, pidgin_screenname_autocomplete_default_filter
, GINT_TO_POINTER(!strcmp(type_hint
, "screenname-all")));
1151 create_string_field(PurpleRequestField
*field
)
1155 gboolean is_editable
;
1157 value
= purple_request_field_string_get_default_value(field
);
1158 is_editable
= purple_request_field_is_sensitive(field
);
1160 if (purple_request_field_string_is_multiline(field
))
1162 GtkWidget
*textview
;
1164 textview
= gtk_text_view_new();
1165 gtk_text_view_set_editable(GTK_TEXT_VIEW(textview
),
1167 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview
),
1168 GTK_WRAP_WORD_CHAR
);
1170 gtk_widget_show(textview
);
1174 GtkTextBuffer
*buffer
;
1176 buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview
));
1178 gtk_text_buffer_set_text(buffer
, value
, -1);
1181 gtk_widget_set_tooltip_text(textview
, purple_request_field_get_tooltip(field
));
1183 gtk_text_view_set_editable(GTK_TEXT_VIEW(textview
), is_editable
);
1185 g_signal_connect(G_OBJECT(textview
), "focus-out-event",
1186 G_CALLBACK(field_string_focus_out_cb
), field
);
1188 if (purple_request_field_is_required(field
))
1190 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview
));
1191 g_signal_connect(G_OBJECT(buffer
), "changed",
1192 G_CALLBACK(req_entry_field_changed_cb
), field
);
1195 widget
= pidgin_make_scrollable(textview
, GTK_POLICY_NEVER
, GTK_POLICY_ALWAYS
, GTK_SHADOW_IN
, -1, 75);
1199 widget
= gtk_entry_new();
1201 setup_entry_field(widget
, field
);
1204 gtk_entry_set_text(GTK_ENTRY(widget
), value
);
1206 gtk_widget_set_tooltip_text(widget
, purple_request_field_get_tooltip(field
));
1208 if (purple_request_field_string_is_masked(field
))
1210 gtk_entry_set_visibility(GTK_ENTRY(widget
), FALSE
);
1213 gtk_editable_set_editable(GTK_EDITABLE(widget
), is_editable
);
1215 g_signal_connect(G_OBJECT(widget
), "focus-out-event",
1216 G_CALLBACK(field_string_focus_out_cb
), field
);
1223 create_int_field(PurpleRequestField
*field
)
1228 widget
= gtk_spin_button_new_with_range(
1229 purple_request_field_int_get_lower_bound(field
),
1230 purple_request_field_int_get_upper_bound(field
), 1);
1232 setup_entry_field(widget
, field
);
1234 value
= purple_request_field_int_get_default_value(field
);
1235 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget
), value
);
1237 gtk_widget_set_tooltip_text(widget
, purple_request_field_get_tooltip(field
));
1243 create_bool_field(PurpleRequestField
*field
,
1244 PurpleRequestCommonParameters
*cpar
)
1249 label
= pidgin_request_escape(cpar
,
1250 purple_request_field_get_label(field
));
1251 widget
= gtk_check_button_new_with_label(label
);
1254 gtk_widget_set_tooltip_text(widget
, purple_request_field_get_tooltip(field
));
1256 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
),
1257 purple_request_field_bool_get_default_value(field
));
1259 g_signal_connect(G_OBJECT(widget
), "toggled",
1260 G_CALLBACK(field_bool_cb
), field
);
1261 g_signal_connect(widget
, "toggled",
1262 G_CALLBACK(req_field_changed_cb
), field
);
1268 create_choice_field(PurpleRequestField
*field
,
1269 PurpleRequestCommonParameters
*cpar
)
1272 GList
*elements
= purple_request_field_choice_get_elements(field
);
1273 int num_labels
= g_list_length(elements
) / 2;
1275 gpointer
*values
= g_new(gpointer
, num_labels
);
1276 gpointer default_value
;
1277 gboolean default_found
= FALSE
;
1280 default_value
= purple_request_field_choice_get_value(field
);
1281 if (num_labels
> 5 || purple_request_cpar_is_compact(cpar
))
1283 int default_index
= 0;
1284 widget
= gtk_combo_box_text_new();
1298 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widget
), text
);
1299 if (value
== default_value
) {
1301 default_found
= TRUE
;
1303 values
[i
++] = value
;
1306 gtk_combo_box_set_active(GTK_COMBO_BOX(widget
), default_index
);
1308 gtk_widget_set_tooltip_text(widget
, purple_request_field_get_tooltip(field
));
1310 g_signal_connect(G_OBJECT(widget
), "changed",
1311 G_CALLBACK(field_choice_menu_cb
), field
);
1316 GtkWidget
*first_radio
= NULL
;
1319 if (num_labels
== 2)
1320 box
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, PIDGIN_HIG_BOX_SPACE
);
1322 box
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0);
1326 gtk_widget_set_tooltip_text(widget
, purple_request_field_get_tooltip(field
));
1340 radio
= gtk_radio_button_new_with_label_from_widget(
1341 GTK_RADIO_BUTTON(first_radio
), text
);
1342 g_object_set_data(G_OBJECT(radio
), "box", box
);
1344 if (first_radio
== NULL
)
1345 first_radio
= radio
;
1347 if (value
== default_value
) {
1348 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio
), TRUE
);
1349 default_found
= TRUE
;
1351 values
[i
++] = value
;
1353 gtk_box_pack_start(GTK_BOX(box
), radio
, TRUE
, TRUE
, 0);
1354 gtk_widget_show(radio
);
1356 g_signal_connect(G_OBJECT(radio
), "toggled",
1357 G_CALLBACK(field_choice_option_cb
), field
);
1361 if (!default_found
&& i
> 0)
1362 purple_request_field_choice_set_value(field
, values
[0]);
1364 g_object_set_data_full(G_OBJECT(widget
), "values", values
, g_free
);
1370 create_image_field(PurpleRequestField
*field
)
1373 GdkPixbuf
*buf
, *scale
;
1375 buf
= pidgin_pixbuf_from_data(
1376 (const guchar
*)purple_request_field_image_get_buffer(field
),
1377 purple_request_field_image_get_size(field
));
1379 scale
= gdk_pixbuf_scale_simple(buf
,
1380 purple_request_field_image_get_scale_x(field
) * gdk_pixbuf_get_width(buf
),
1381 purple_request_field_image_get_scale_y(field
) * gdk_pixbuf_get_height(buf
),
1382 GDK_INTERP_BILINEAR
);
1383 widget
= gtk_image_new_from_pixbuf(scale
);
1384 g_object_unref(G_OBJECT(buf
));
1385 g_object_unref(G_OBJECT(scale
));
1387 gtk_widget_set_tooltip_text(widget
, purple_request_field_get_tooltip(field
));
1393 create_account_field(PurpleRequestField
*field
)
1397 widget
= pidgin_account_option_menu_new(
1398 purple_request_field_account_get_default_value(field
),
1399 purple_request_field_account_get_show_all(field
),
1400 G_CALLBACK(field_account_cb
),
1401 purple_request_field_account_get_filter(field
),
1404 gtk_widget_set_tooltip_text(widget
, purple_request_field_get_tooltip(field
));
1405 g_signal_connect(widget
, "changed",
1406 G_CALLBACK(req_field_changed_cb
), field
);
1412 select_field_list_item(GtkTreeModel
*model
, GtkTreePath
*path
,
1413 GtkTreeIter
*iter
, gpointer data
)
1415 PurpleRequestField
*field
= (PurpleRequestField
*)data
;
1418 gtk_tree_model_get(model
, iter
, 1, &text
, -1);
1420 purple_request_field_list_add_selected(field
, text
);
1425 list_field_select_changed_cb(GtkTreeSelection
*sel
, PurpleRequestField
*field
)
1427 purple_request_field_list_clear_selected(field
);
1429 gtk_tree_selection_selected_foreach(sel
, select_field_list_item
, field
);
1433 create_list_field(PurpleRequestField
*field
)
1435 GtkWidget
*treeview
;
1436 GtkListStore
*store
;
1437 GtkCellRenderer
*renderer
;
1438 GtkTreeSelection
*sel
;
1439 GtkTreeViewColumn
*column
;
1442 GList
*icons
= NULL
;
1444 icons
= purple_request_field_list_get_icons(field
);
1447 /* Create the list store */
1449 store
= gtk_list_store_new(3, G_TYPE_POINTER
, G_TYPE_STRING
, GDK_TYPE_PIXBUF
);
1451 store
= gtk_list_store_new(2, G_TYPE_POINTER
, G_TYPE_STRING
);
1453 /* Create the tree view */
1454 treeview
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(store
));
1455 g_object_unref(G_OBJECT(store
));
1456 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview
), FALSE
);
1458 sel
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
1460 if (purple_request_field_list_get_multi_select(field
))
1461 gtk_tree_selection_set_mode(sel
, GTK_SELECTION_MULTIPLE
);
1463 column
= gtk_tree_view_column_new();
1464 gtk_tree_view_insert_column(GTK_TREE_VIEW(treeview
), column
, -1);
1466 renderer
= gtk_cell_renderer_text_new();
1467 gtk_tree_view_column_pack_start(column
, renderer
, TRUE
);
1468 gtk_tree_view_column_add_attribute(column
, renderer
, "text", 1);
1472 renderer
= gtk_cell_renderer_pixbuf_new();
1473 gtk_tree_view_column_pack_start(column
, renderer
, TRUE
);
1474 gtk_tree_view_column_add_attribute(column
, renderer
, "pixbuf", 2);
1476 gtk_widget_set_size_request(treeview
, 200, 400);
1479 for (l
= purple_request_field_list_get_items(field
); l
!= NULL
; l
= l
->next
)
1481 const char *text
= (const char *)l
->data
;
1483 gtk_list_store_append(store
, &iter
);
1487 const char *icon_path
= (const char *)icons
->data
;
1488 GdkPixbuf
* pixbuf
= NULL
;
1491 pixbuf
= pidgin_pixbuf_new_from_file(icon_path
);
1493 gtk_list_store_set(store
, &iter
,
1494 0, purple_request_field_list_get_data(field
, text
),
1498 icons
= icons
->next
;
1501 gtk_list_store_set(store
, &iter
,
1502 0, purple_request_field_list_get_data(field
, text
),
1506 if (purple_request_field_list_is_selected(field
, text
))
1507 gtk_tree_selection_select_iter(sel
, &iter
);
1511 * We only want to catch changes made by the user, so it's important
1512 * that we wait until after the list is created to connect this
1513 * handler. If we connect the handler before the loop above and
1514 * there are multiple items selected, then selecting the first iter
1515 * in the tree causes list_field_select_changed_cb to be triggered
1516 * which clears out the rest of the list of selected items.
1518 g_signal_connect(G_OBJECT(sel
), "changed",
1519 G_CALLBACK(list_field_select_changed_cb
), field
);
1521 gtk_widget_show(treeview
);
1523 return pidgin_make_scrollable(treeview
, GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
, GTK_SHADOW_IN
, -1, -1);
1527 create_certificate_field(PurpleRequestField
*field
)
1529 GTlsCertificate
*cert
;
1531 GByteArray
*der
= NULL
;
1532 GcrCertificateBasicsWidget
*cert_widget
;
1533 GcrCertificate
*gcrt
;
1535 PurpleTlsCertificateInfo
*info
;
1536 GtkWidget
*cert_label
;
1541 cert
= purple_request_field_certificate_get_value(field
);
1544 g_object_get(cert
, "certificate", &der
, NULL
);
1545 g_return_val_if_fail(der
, NULL
);
1547 gcrt
= gcr_simple_certificate_new(der
->data
, der
->len
);
1548 g_return_val_if_fail(gcrt
, NULL
);
1550 cert_widget
= gcr_certificate_basics_widget_new(gcrt
);
1552 g_byte_array_free(der
, TRUE
);
1553 g_object_unref(G_OBJECT(gcrt
));
1555 return GTK_WIDGET(cert_widget
);
1557 info
= purple_tls_certificate_get_info(cert
);
1558 str
= purple_tls_certificate_info_get_display_string(info
);
1559 purple_tls_certificate_info_free(info
);
1561 escaped
= g_markup_escape_text(str
, -1);
1563 cert_label
= gtk_label_new(NULL
);
1564 gtk_label_set_markup(GTK_LABEL(cert_label
), escaped
);
1565 gtk_label_set_line_wrap(GTK_LABEL(cert_label
), TRUE
);
1566 gtk_label_set_xalign(GTK_LABEL(cert_label
), 0);
1567 gtk_label_set_yalign(GTK_LABEL(cert_label
), 0);
1577 _pidgin_datasheet_stock_icon_get(const gchar
*stock_name
)
1579 GdkPixbuf
*image
= NULL
;
1582 if (stock_name
== NULL
)
1585 /* core is quitting */
1586 if (datasheet_stock
== NULL
)
1589 if (g_hash_table_lookup_extended(datasheet_stock
, stock_name
,
1590 NULL
, (gpointer
*)&image
))
1595 domain
= g_strdup(stock_name
);
1596 id
= strchr(domain
, '/');
1604 if (g_strcmp0(domain
, "protocol") == 0) {
1605 PurpleAccount
*account
;
1606 gchar
*protocol_id
, *accountname
;
1609 accountname
= strchr(id
, ':');
1616 accountname
[0] = '\0';
1619 account
= purple_accounts_find(accountname
, protocol_id
);
1621 image
= pidgin_create_protocol_icon(account
,
1622 PIDGIN_PROTOCOL_ICON_SMALL
);
1624 } else if (g_strcmp0(domain
, "e2ee") == 0) {
1625 image
= pidgin_pixbuf_from_image(
1626 _pidgin_e2ee_stock_icon_get(id
));
1628 purple_debug_error("gtkrequest", "Unknown domain: %s", domain
);
1633 g_hash_table_insert(datasheet_stock
, g_strdup(stock_name
), image
);
1637 static PurpleRequestDatasheetRecord
*
1638 datasheet_get_selected_row(GtkWidget
*sheet_widget
)
1640 PurpleRequestDatasheet
*sheet
;
1642 GtkTreeSelection
*selection
;
1643 GtkTreeModel
*model
;
1648 g_return_val_if_fail(sheet_widget
!= NULL
, NULL
);
1650 view
= GTK_TREE_VIEW(g_object_get_data(G_OBJECT(sheet_widget
), "view"));
1651 sheet
= g_object_get_data(G_OBJECT(sheet_widget
), "sheet");
1653 g_return_val_if_fail(view
!= NULL
, NULL
);
1654 g_return_val_if_fail(sheet
!= NULL
, NULL
);
1656 selection
= gtk_tree_view_get_selection(view
);
1657 if (gtk_tree_selection_count_selected_rows(selection
) != 1)
1660 sel_list
= gtk_tree_selection_get_selected_rows(selection
, &model
);
1661 gtk_tree_model_get_iter(model
, &iter
, sel_list
->data
);
1662 g_list_foreach(sel_list
, (GFunc
)gtk_tree_path_free
, NULL
);
1663 g_list_free(sel_list
);
1665 gtk_tree_model_get(model
, &iter
, 0, &key
, -1);
1667 return purple_request_datasheet_record_find(sheet
, key
);
1671 datasheet_button_check_sens(GtkWidget
*button
, gpointer _sheet_widget
)
1673 PurpleRequestDatasheetAction
*act
;
1674 GtkWidget
*sheet_widget
= GTK_WIDGET(_sheet_widget
);
1676 g_return_if_fail(sheet_widget
!= NULL
);
1678 act
= g_object_get_data(G_OBJECT(button
), "action");
1680 g_return_if_fail(act
!= NULL
);
1682 gtk_widget_set_sensitive(button
,
1683 purple_request_datasheet_action_is_sensitive(act
,
1684 datasheet_get_selected_row(sheet_widget
)));
1688 datasheet_selection_changed(GtkWidget
*sheet_widget
)
1690 gpointer buttons_box
;
1692 g_return_if_fail(sheet_widget
!= NULL
);
1694 buttons_box
= g_object_get_data(G_OBJECT(sheet_widget
), "buttons");
1695 gtk_container_foreach(GTK_CONTAINER(buttons_box
),
1696 datasheet_button_check_sens
, sheet_widget
);
1700 datasheet_update_rec(PurpleRequestDatasheetRecord
*rec
, GtkListStore
*model
,
1704 PurpleRequestDatasheet
*sheet
;
1706 g_return_if_fail(rec
!= NULL
);
1707 g_return_if_fail(model
!= NULL
);
1708 g_return_if_fail(iter
!= NULL
);
1710 sheet
= purple_request_datasheet_record_get_datasheet(rec
);
1712 g_return_if_fail(sheet
!= NULL
);
1714 col_count
= purple_request_datasheet_get_column_count(sheet
);
1716 for (i
= 0; i
< col_count
; i
++) {
1717 PurpleRequestDatasheetColumnType type
;
1719 type
= purple_request_datasheet_get_column_type(
1721 if (type
== PURPLE_REQUEST_DATASHEET_COLUMN_STRING
) {
1725 g_value_init(&val
, G_TYPE_STRING
);
1726 g_value_set_string(&val
,
1727 purple_request_datasheet_record_get_string_data(
1729 gtk_list_store_set_value(model
, iter
,
1732 PURPLE_REQUEST_DATASHEET_COLUMN_IMAGE
)
1736 pixbuf
= _pidgin_datasheet_stock_icon_get(
1737 purple_request_datasheet_record_get_image_data(
1739 gtk_list_store_set(model
, iter
, i
+ 1,
1742 g_warn_if_reached();
1747 datasheet_fill(PurpleRequestDatasheet
*sheet
, GtkListStore
*model
)
1751 gtk_list_store_clear(model
);
1753 it
= purple_request_datasheet_get_records(sheet
);
1754 for (; it
!= NULL
; it
= g_list_next(it
)) {
1755 PurpleRequestDatasheetRecord
*rec
= it
->data
;
1758 gtk_list_store_append(model
, &iter
);
1759 gtk_list_store_set(model
, &iter
, 0,
1760 purple_request_datasheet_record_get_key(rec
), -1);
1762 datasheet_update_rec(rec
, model
, &iter
);
1765 datasheet_selection_changed(GTK_WIDGET(g_object_get_data(
1766 G_OBJECT(model
), "sheet-widget")));
1770 datasheet_update(PurpleRequestDatasheet
*sheet
, gpointer key
,
1771 GtkListStore
*model
)
1773 PurpleRequestDatasheetRecord
*rec
;
1775 GtkTreeModel
*tmodel
= GTK_TREE_MODEL(model
);
1776 gboolean found
= FALSE
;
1778 g_return_if_fail(tmodel
!= NULL
);
1781 datasheet_fill(sheet
, model
);
1785 rec
= purple_request_datasheet_record_find(sheet
, key
);
1787 if (gtk_tree_model_get_iter_first(tmodel
, &iter
)) {
1791 gtk_tree_model_get(tmodel
, &iter
, 0, &ikey
, -1);
1797 } while (gtk_tree_model_iter_next(tmodel
, &iter
));
1800 if (rec
== NULL
&& !found
)
1804 gtk_list_store_remove(model
, &iter
);
1809 gtk_list_store_append(model
, &iter
);
1810 gtk_list_store_set(model
, &iter
, 0, key
, -1);
1813 datasheet_update_rec(rec
, model
, &iter
);
1815 datasheet_selection_changed(GTK_WIDGET(g_object_get_data(
1816 G_OBJECT(model
), "sheet-widget")));
1821 datasheet_selection_changed_cb(GtkTreeSelection
*sel
, gpointer sheet_widget
)
1823 datasheet_selection_changed(GTK_WIDGET(sheet_widget
));
1827 datasheet_action_clicked(GtkButton
*btn
, PurpleRequestDatasheetAction
*act
)
1829 GtkWidget
*sheet_widget
;
1831 sheet_widget
= g_object_get_data(G_OBJECT(btn
), "sheet-widget");
1833 g_return_if_fail(sheet_widget
!= NULL
);
1835 purple_request_datasheet_action_call(act
, datasheet_get_selected_row(
1840 create_datasheet_field(PurpleRequestField
*field
, GtkSizeGroup
*buttons_sg
)
1842 PurpleRequestDatasheet
*sheet
;
1845 GtkListStore
*model
;
1847 GtkTreeSelection
*sel
;
1848 GtkWidget
*scrollable
;
1849 GtkCellRenderer
*renderer_image
= NULL
, *renderer_text
= NULL
;
1850 GtkTreeViewColumn
*id_column
;
1851 GtkWidget
*main_box
;
1852 GtkWidget
*buttons_box
;
1855 sheet
= purple_request_field_datasheet_get_sheet(field
);
1856 main_box
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0);
1858 col_count
= purple_request_datasheet_get_column_count(sheet
);
1860 col_types
= g_new0(GType
, col_count
+ 1);
1861 col_types
[0] = G_TYPE_POINTER
;
1862 for (i
= 0; i
< col_count
; i
++) {
1863 PurpleRequestDatasheetColumnType type
;
1864 type
= purple_request_datasheet_get_column_type(sheet
, i
);
1865 if (type
== PURPLE_REQUEST_DATASHEET_COLUMN_STRING
)
1866 col_types
[i
+ 1] = G_TYPE_STRING
;
1867 else if (type
== PURPLE_REQUEST_DATASHEET_COLUMN_IMAGE
)
1868 col_types
[i
+ 1] = GDK_TYPE_PIXBUF
;
1870 g_warn_if_reached();
1872 model
= gtk_list_store_newv(col_count
+ 1, col_types
);
1875 view
= GTK_TREE_VIEW(gtk_tree_view_new_with_model(
1876 GTK_TREE_MODEL(model
)));
1877 g_object_set_data(G_OBJECT(model
), "sheet-widget", main_box
);
1878 g_object_unref(G_OBJECT(model
));
1880 id_column
= gtk_tree_view_column_new();
1881 gtk_tree_view_column_set_visible(id_column
, FALSE
);
1882 gtk_tree_view_append_column(view
, id_column
);
1884 for (i
= 0; i
< col_count
; i
++) {
1885 PurpleRequestDatasheetColumnType type
;
1887 GtkCellRenderer
*renderer
= NULL
;
1888 const gchar
*type_str
= "";
1890 type
= purple_request_datasheet_get_column_type(sheet
, i
);
1891 title
= purple_request_datasheet_get_column_title(sheet
, i
);
1893 if (type
== PURPLE_REQUEST_DATASHEET_COLUMN_STRING
) {
1896 renderer_text
= gtk_cell_renderer_text_new();
1897 renderer
= renderer_text
;
1899 else if (type
== PURPLE_REQUEST_DATASHEET_COLUMN_IMAGE
) {
1900 type_str
= "pixbuf";
1901 if (!renderer_image
)
1902 renderer_image
= gtk_cell_renderer_pixbuf_new();
1903 renderer
= renderer_image
;
1905 g_warn_if_reached();
1909 gtk_tree_view_insert_column_with_attributes(
1910 view
, -1, title
, renderer
, type_str
,
1914 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view
), TRUE
);
1916 gtk_widget_set_size_request(GTK_WIDGET(view
), 400, 250);
1918 scrollable
= pidgin_make_scrollable(GTK_WIDGET(view
),
1919 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
, GTK_SHADOW_IN
, -1, -1);
1920 gtk_widget_show(GTK_WIDGET(view
));
1922 buttons_box
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BORDER
);
1923 gtk_size_group_add_widget(buttons_sg
, buttons_box
);
1925 gtk_box_pack_start(GTK_BOX(main_box
), scrollable
, TRUE
, TRUE
, 0);
1926 gtk_box_pack_start(GTK_BOX(main_box
), buttons_box
,
1928 gtk_widget_show(scrollable
);
1929 gtk_widget_show(buttons_box
);
1931 it
= purple_request_datasheet_get_actions(sheet
);
1932 for (; it
!= NULL
; it
= g_list_next(it
)) {
1933 PurpleRequestDatasheetAction
*act
= it
->data
;
1937 label
= purple_request_datasheet_action_get_label(act
);
1939 btn
= GTK_BUTTON(gtk_button_new_with_label(label
? label
: ""));
1941 g_object_set_data(G_OBJECT(btn
), "action", act
);
1942 g_object_set_data(G_OBJECT(btn
), "sheet-widget", main_box
);
1943 g_signal_connect(G_OBJECT(btn
), "clicked",
1944 G_CALLBACK(datasheet_action_clicked
), act
);
1946 gtk_box_pack_start(GTK_BOX(buttons_box
), GTK_WIDGET(btn
),
1948 gtk_widget_show(GTK_WIDGET(btn
));
1951 g_object_set_data(G_OBJECT(main_box
), "view", view
);
1952 g_object_set_data(G_OBJECT(main_box
), "buttons", buttons_box
);
1953 g_object_set_data(G_OBJECT(main_box
), "sheet", sheet
);
1955 datasheet_fill(sheet
, model
);
1956 purple_signal_connect(sheet
, "record-changed",
1957 pidgin_request_get_handle(),
1958 PURPLE_CALLBACK(datasheet_update
), model
);
1960 sel
= gtk_tree_view_get_selection(view
);
1961 g_signal_connect(G_OBJECT(sel
), "changed",
1962 G_CALLBACK(datasheet_selection_changed_cb
), main_box
);
1968 pidgin_request_fields(const char *title
, const char *primary
,
1969 const char *secondary
, PurpleRequestFields
*fields
, const char *ok_text
,
1970 GCallback ok_cb
, const char *cancel_text
, GCallback cancel_cb
,
1971 PurpleRequestCommonParameters
*cpar
, void *user_data
)
1973 PidginRequestData
*data
;
1975 GtkNotebook
*notebook
;
1977 GtkWidget
*hbox
, *vbox
;
1983 GtkSizeGroup
*sg
, *datasheet_buttons_sg
;
1985 PurpleRequestFieldGroup
*group
;
1986 PurpleRequestField
*field
;
1988 char *primary_esc
, *secondary_esc
;
1989 const gboolean compact
= purple_request_cpar_is_compact(cpar
);
1990 GSList
*extra_actions
, *it
;
1991 size_t extra_actions_count
, i
;
1992 const gchar
**tab_names
;
1994 gboolean ok_btn
= (ok_text
!= NULL
);
1996 data
= g_new0(PidginRequestData
, 1);
1997 data
->type
= PURPLE_REQUEST_FIELDS
;
1998 data
->user_data
= user_data
;
1999 data
->u
.multifield
.fields
= fields
;
2001 purple_request_fields_set_ui_data(fields
, data
);
2003 extra_actions
= purple_request_cpar_get_extra_actions(cpar
);
2004 extra_actions_count
= g_slist_length(extra_actions
) / 2;
2007 data
->cbs
= g_new0(GCallback
, 2);
2009 data
->cbs
[0] = ok_cb
;
2010 data
->cbs
[1] = cancel_cb
;
2013 data
->dialog
= win
= pidgin_create_dialog(PIDGIN_ALERT_TITLE
, PIDGIN_HIG_BORDER
, "multifield", TRUE
) ;
2015 data
->dialog
= win
= pidgin_create_dialog(title
, PIDGIN_HIG_BORDER
, "multifield", TRUE
) ;
2018 g_signal_connect(G_OBJECT(win
), "delete_event",
2019 G_CALLBACK(destroy_multifield_cb
), data
);
2021 /* Setup the main horizontal box */
2022 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, PIDGIN_HIG_BORDER
);
2023 gtk_container_add(GTK_CONTAINER(pidgin_dialog_get_vbox(GTK_DIALOG(win
))), hbox
);
2024 gtk_widget_show(hbox
);
2027 img
= pidgin_request_dialog_icon(PURPLE_REQUEST_FIELDS
, cpar
);
2028 gtk_widget_set_halign(img
, GTK_ALIGN_START
);
2029 gtk_widget_set_valign(img
, GTK_ALIGN_START
);
2030 gtk_box_pack_start(GTK_BOX(hbox
), img
, FALSE
, FALSE
, 0);
2031 gtk_widget_show(img
);
2033 pidgin_request_add_help(GTK_DIALOG(win
), cpar
);
2036 for (i
= 0; i
< extra_actions_count
; i
++, it
= it
->next
->next
) {
2037 const gchar
*label
= it
->data
;
2038 PurpleRequestFieldsCb
*cb
= it
->next
->data
;
2040 button
= pidgin_dialog_add_button(GTK_DIALOG(win
),
2041 text_to_stock(label
), G_CALLBACK(multifield_extra_cb
),
2043 g_object_set_data(G_OBJECT(button
), "extra-cb", cb
);
2047 button
= pidgin_dialog_add_button(GTK_DIALOG(win
), text_to_stock(cancel_text
), G_CALLBACK(multifield_cancel_cb
), data
);
2048 gtk_widget_set_can_default(button
, TRUE
);
2052 gtk_window_set_default(GTK_WINDOW(win
), button
);
2054 button
= pidgin_dialog_add_button(GTK_DIALOG(win
), text_to_stock(ok_text
), G_CALLBACK(multifield_ok_cb
), data
);
2055 data
->ok_button
= button
;
2056 gtk_widget_set_can_default(button
, TRUE
);
2057 gtk_window_set_default(GTK_WINDOW(win
), button
);
2060 pidgin_widget_decorate_account(hbox
,
2061 purple_request_cpar_get_account(cpar
));
2063 /* Setup the vbox */
2064 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BORDER
);
2065 gtk_box_pack_start(GTK_BOX(hbox
), vbox
, TRUE
, TRUE
, 0);
2066 gtk_widget_show(vbox
);
2068 sg
= gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL
);
2069 datasheet_buttons_sg
= gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL
);
2072 primary_esc
= pidgin_request_escape(cpar
, primary
);
2073 label_text
= g_strdup_printf(
2074 "<span weight=\"bold\" size=\"larger\">%s</span>", primary_esc
);
2075 g_free(primary_esc
);
2076 label
= gtk_label_new(NULL
);
2078 gtk_label_set_markup(GTK_LABEL(label
), label_text
);
2079 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
2080 gtk_label_set_xalign(GTK_LABEL(label
), 0);
2081 gtk_label_set_yalign(GTK_LABEL(label
), 0);
2082 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 0);
2083 gtk_widget_show(label
);
2088 tab_names
= purple_request_fields_get_tab_names(fields
);
2089 if (tab_names
== NULL
) {
2093 pages
= g_new0(GtkWidget
*, 1);
2096 tab_count
= g_strv_length((gchar
**)tab_names
);
2097 notebook
= GTK_NOTEBOOK(gtk_notebook_new());
2099 pages
= g_new0(GtkWidget
*, tab_count
);
2101 for (i
= 0; i
< tab_count
; i
++) {
2102 pages
[i
] = gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BORDER
);
2103 gtk_container_set_border_width(GTK_CONTAINER(pages
[i
]), PIDGIN_HIG_BORDER
);
2104 gtk_notebook_append_page(notebook
, pages
[i
], NULL
);
2105 gtk_notebook_set_tab_label_text(notebook
, pages
[i
], tab_names
[i
]);
2106 gtk_widget_show(pages
[i
]);
2110 for (i
= 0; i
< tab_count
; i
++) {
2111 guint total_fields
= 0;
2114 it
= purple_request_fields_get_groups(fields
);
2115 for (; it
!= NULL
; it
= g_list_next(it
)) {
2117 if (purple_request_field_group_get_tab(group
) != i
)
2119 total_fields
+= g_list_length(
2120 purple_request_field_group_get_fields(group
));
2123 if(total_fields
> 9) {
2124 GtkWidget
*hbox_for_spacing
, *vbox_for_spacing
;
2126 gtk_container_set_border_width(
2127 GTK_CONTAINER(pages
[i
]), 0);
2130 gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, PIDGIN_HIG_BORDER
);
2131 gtk_box_pack_start(GTK_BOX(pages
[i
]),
2132 pidgin_make_scrollable(hbox_for_spacing
,
2133 GTK_POLICY_NEVER
, GTK_POLICY_AUTOMATIC
,
2134 GTK_SHADOW_NONE
, -1, 200),
2136 gtk_widget_show(hbox_for_spacing
);
2139 gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BORDER
);
2140 gtk_box_pack_start(GTK_BOX(hbox_for_spacing
),
2141 vbox_for_spacing
, TRUE
, TRUE
,
2142 PIDGIN_HIG_BOX_SPACE
);
2143 gtk_widget_show(vbox_for_spacing
);
2145 pages
[i
] = gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BORDER
);
2146 gtk_box_pack_start(GTK_BOX(vbox_for_spacing
),
2147 pages
[i
], TRUE
, TRUE
, PIDGIN_HIG_BOX_SPACE
);
2148 gtk_widget_show(pages
[i
]);
2151 if (notebook
== NULL
)
2156 secondary_esc
= pidgin_request_escape(cpar
, secondary
);
2157 label
= gtk_label_new(NULL
);
2159 gtk_label_set_markup(GTK_LABEL(label
), secondary_esc
);
2160 g_free(secondary_esc
);
2161 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
2162 gtk_label_set_xalign(GTK_LABEL(label
), 0);
2163 gtk_label_set_yalign(GTK_LABEL(label
), 0);
2164 gtk_box_pack_start(GTK_BOX(vbox
), label
, (notebook
== NULL
),
2165 (notebook
== NULL
), 0);
2166 gtk_widget_show(label
);
2169 if (notebook
!= NULL
) {
2170 gtk_box_pack_start(GTK_BOX(vbox
), GTK_WIDGET(notebook
), TRUE
, TRUE
, 0);
2171 gtk_widget_show(GTK_WIDGET(notebook
));
2174 for (gl
= purple_request_fields_get_groups(fields
);
2179 size_t field_count
= 0;
2187 gboolean contains_resizable
= FALSE
, frame_fill
;
2190 field_list
= purple_request_field_group_get_fields(group
);
2191 tab_no
= purple_request_field_group_get_tab(group
);
2192 if (tab_no
>= tab_count
) {
2193 purple_debug_warning("gtkrequest",
2194 "Invalid tab number: %d", tab_no
);
2198 if (purple_request_field_group_get_title(group
) != NULL
)
2200 frame
= pidgin_make_frame(pages
[tab_no
],
2201 purple_request_field_group_get_title(group
));
2204 frame
= pages
[tab_no
];
2206 field_count
= g_list_length(field_list
);
2208 if (field_count
> 9)
2210 rows
= field_count
/ 2;
2221 for (fl
= field_list
; fl
!= NULL
; fl
= fl
->next
)
2223 PurpleRequestFieldType type
;
2225 field
= (PurpleRequestField
*)fl
->data
;
2227 type
= purple_request_field_get_field_type(field
);
2229 if (type
== PURPLE_REQUEST_FIELD_DATASHEET
)
2230 contains_resizable
= TRUE
;
2232 if (type
== PURPLE_REQUEST_FIELD_LABEL
)
2241 else if ((type
== PURPLE_REQUEST_FIELD_LIST
) ||
2242 (type
== PURPLE_REQUEST_FIELD_STRING
&&
2243 purple_request_field_string_is_multiline(field
)))
2251 } else if (compact
&& type
!= PURPLE_REQUEST_FIELD_BOOLEAN
)
2257 if (col_num
>= cols
)
2262 grid
= gtk_grid_new();
2263 gtk_grid_set_row_spacing(GTK_GRID(grid
), PIDGIN_HIG_BOX_SPACE
);
2264 gtk_grid_set_column_spacing(GTK_GRID(grid
), PIDGIN_HIG_BOX_SPACE
);
2266 frame_fill
= (notebook
== NULL
|| contains_resizable
);
2267 gtk_box_pack_start(GTK_BOX(frame
), grid
, frame_fill
, frame_fill
, 0);
2268 gtk_widget_show(grid
);
2270 for (row_num
= 0, fl
= field_list
;
2271 row_num
< rows
&& fl
!= NULL
;
2276 col_num
< cols
&& fl
!= NULL
;
2277 col_num
++, fl
= fl
->next
)
2279 gboolean dummy_counter
= TRUE
;
2280 /* it's the same as loop above */
2281 for (; dummy_counter
&& fl
!= NULL
; dummy_counter
= FALSE
, fl
= fl
->next
)
2285 size_t col_offset
= col_num
* 2;
2287 size_t col_offset
= 0;
2289 PurpleRequestFieldType type
;
2290 GtkWidget
*widget
= NULL
;
2296 if (!purple_request_field_is_visible(field
)) {
2303 type
= purple_request_field_get_field_type(field
);
2304 field_label
= pidgin_request_escape(cpar
,
2305 purple_request_field_get_label(field
));
2307 if (type
!= PURPLE_REQUEST_FIELD_BOOLEAN
&& field_label
)
2311 if (field_label
[strlen(field_label
) - 1] != ':' &&
2312 field_label
[strlen(field_label
) - 1] != '?' &&
2313 type
!= PURPLE_REQUEST_FIELD_LABEL
)
2315 text
= g_strdup_printf("%s:", field_label
);
2318 label
= gtk_label_new(NULL
);
2319 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label
), text
? text
: field_label
);
2322 gtk_widget_set_hexpand(label
, TRUE
);
2323 gtk_widget_set_vexpand(label
, TRUE
);
2324 gtk_label_set_xalign(GTK_LABEL(label
), 0);
2326 gtk_size_group_add_widget(sg
, label
);
2328 if (type
== PURPLE_REQUEST_FIELD_LABEL
||
2329 type
== PURPLE_REQUEST_FIELD_LIST
||
2330 (type
== PURPLE_REQUEST_FIELD_STRING
&&
2331 purple_request_field_string_is_multiline(field
)))
2338 gtk_grid_attach(GTK_GRID(grid
), label
,
2339 0, row_num
, 2 * cols
, 1);
2348 gtk_grid_attach(GTK_GRID(grid
), label
,
2349 col_offset
, row_num
, 1, 1);
2352 gtk_widget_show(label
);
2353 g_free(field_label
);
2356 widget
= GTK_WIDGET(purple_request_field_get_ui_data(field
));
2359 if (type
== PURPLE_REQUEST_FIELD_STRING
)
2360 widget
= create_string_field(field
);
2361 else if (type
== PURPLE_REQUEST_FIELD_INTEGER
)
2362 widget
= create_int_field(field
);
2363 else if (type
== PURPLE_REQUEST_FIELD_BOOLEAN
)
2364 widget
= create_bool_field(field
, cpar
);
2365 else if (type
== PURPLE_REQUEST_FIELD_CHOICE
)
2366 widget
= create_choice_field(field
, cpar
);
2367 else if (type
== PURPLE_REQUEST_FIELD_LIST
)
2368 widget
= create_list_field(field
);
2369 else if (type
== PURPLE_REQUEST_FIELD_IMAGE
)
2370 widget
= create_image_field(field
);
2371 else if (type
== PURPLE_REQUEST_FIELD_ACCOUNT
)
2372 widget
= create_account_field(field
);
2373 else if (type
== PURPLE_REQUEST_FIELD_CERTIFICATE
)
2374 widget
= create_certificate_field(field
);
2375 else if (type
== PURPLE_REQUEST_FIELD_DATASHEET
)
2376 widget
= create_datasheet_field(field
, datasheet_buttons_sg
);
2381 gtk_widget_set_sensitive(widget
,
2382 purple_request_field_is_sensitive(field
));
2385 gtk_label_set_mnemonic_widget(GTK_LABEL(label
), widget
);
2387 gtk_widget_set_hexpand(widget
, TRUE
);
2388 gtk_widget_set_vexpand(widget
, TRUE
);
2389 #if GTK_CHECK_VERSION(3,12,0)
2390 gtk_widget_set_margin_start(widget
, 5);
2391 gtk_widget_set_margin_end(widget
, 5);
2393 gtk_widget_set_margin_left(widget
, 5);
2394 gtk_widget_set_margin_right(widget
, 5);
2397 if (type
== PURPLE_REQUEST_FIELD_STRING
&&
2398 purple_request_field_string_is_multiline(field
))
2400 gtk_grid_attach(GTK_GRID(grid
), widget
,
2401 0, row_num
, 2 * cols
, 1);
2403 else if (type
== PURPLE_REQUEST_FIELD_LIST
)
2405 gtk_grid_attach(GTK_GRID(grid
), widget
,
2406 0, row_num
, 2 * cols
, 1);
2408 else if (type
== PURPLE_REQUEST_FIELD_BOOLEAN
)
2410 gtk_grid_attach(GTK_GRID(grid
), widget
,
2411 col_offset
, row_num
, 1, 1);
2415 gtk_grid_attach(GTK_GRID(grid
), widget
,
2416 0, row_num
, 2 * cols
, 1);
2418 gtk_grid_attach(GTK_GRID(grid
), widget
,
2419 1, row_num
, 2 * cols
- 1, 1);
2422 gtk_widget_show(widget
);
2424 purple_request_field_set_ui_data(field
, widget
);
2430 g_object_unref(datasheet_buttons_sg
);
2432 if (!purple_request_fields_all_required_filled(fields
))
2433 gtk_widget_set_sensitive(data
->ok_button
, FALSE
);
2435 if (!purple_request_fields_all_valid(fields
))
2436 gtk_widget_set_sensitive(data
->ok_button
, FALSE
);
2440 pidgin_auto_parent_window(win
);
2442 gtk_widget_show(win
);
2448 file_yes_no_cb(PidginRequestData
*data
, gint id
)
2450 /* Only call the callback if yes was selected, otherwise the request
2451 * (eg. file transfer) will be cancelled, then when a new filename is chosen
2454 if (data
->cbs
[1] != NULL
)
2455 ((PurpleRequestFileCb
)data
->cbs
[1])(data
->user_data
, data
->u
.file
.name
);
2456 purple_request_close(data
->type
, data
);
2458 pidgin_clear_cursor(GTK_WIDGET(data
->dialog
));
2463 file_ok_check_if_exists_cb(GtkWidget
*widget
, gint response
, PidginRequestData
*data
)
2465 gchar
*current_folder
;
2467 generic_response_start(data
);
2469 if (response
!= GTK_RESPONSE_ACCEPT
) {
2470 if (data
->cbs
[0] != NULL
)
2471 ((PurpleRequestFileCb
)data
->cbs
[0])(data
->user_data
, NULL
);
2472 purple_request_close(data
->type
, data
);
2476 data
->u
.file
.name
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(data
->dialog
));
2477 current_folder
= gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(data
->dialog
));
2478 if (current_folder
!= NULL
) {
2479 if (data
->u
.file
.savedialog
) {
2480 purple_prefs_set_path(PIDGIN_PREFS_ROOT
"/filelocations/last_save_folder", current_folder
);
2482 purple_prefs_set_path(PIDGIN_PREFS_ROOT
"/filelocations/last_open_folder", current_folder
);
2484 g_free(current_folder
);
2486 if ((data
->u
.file
.savedialog
== TRUE
) &&
2487 (g_file_test(data
->u
.file
.name
, G_FILE_TEST_EXISTS
))) {
2488 purple_request_action(data
, NULL
, _("That file already exists"),
2489 _("Would you like to overwrite it?"), 0,
2492 _("Overwrite"), G_CALLBACK(file_yes_no_cb
),
2493 _("Choose New Name"), G_CALLBACK(file_yes_no_cb
));
2495 file_yes_no_cb(data
, 1);
2499 pidgin_request_file(const char *title
, const char *filename
,
2500 gboolean savedialog
, GCallback ok_cb
, GCallback cancel_cb
,
2501 PurpleRequestCommonParameters
*cpar
, void *user_data
)
2503 PidginRequestData
*data
;
2506 const gchar
*current_folder
;
2507 gboolean folder_set
= FALSE
;
2510 data
= g_new0(PidginRequestData
, 1);
2511 data
->type
= PURPLE_REQUEST_FILE
;
2512 data
->user_data
= user_data
;
2514 data
->cbs
= g_new0(GCallback
, 2);
2515 data
->cbs
[0] = cancel_cb
;
2516 data
->cbs
[1] = ok_cb
;
2517 data
->u
.file
.savedialog
= savedialog
;
2519 filesel
= gtk_file_chooser_dialog_new(
2520 title
? title
: (savedialog
? _("Save File...")
2521 : _("Open File...")),
2523 savedialog
? GTK_FILE_CHOOSER_ACTION_SAVE
2524 : GTK_FILE_CHOOSER_ACTION_OPEN
,
2525 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
2526 savedialog
? GTK_STOCK_SAVE
2528 GTK_RESPONSE_ACCEPT
,
2530 gtk_dialog_set_default_response(GTK_DIALOG(filesel
), GTK_RESPONSE_ACCEPT
);
2532 pidgin_request_add_help(GTK_DIALOG(filesel
), cpar
);
2534 if ((filename
!= NULL
) && (*filename
!= '\0')) {
2536 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(filesel
), filename
);
2537 else if (g_file_test(filename
, G_FILE_TEST_EXISTS
))
2538 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(filesel
), filename
);
2543 current_folder
= purple_prefs_get_path(PIDGIN_PREFS_ROOT
"/filelocations/last_save_folder");
2545 current_folder
= purple_prefs_get_path(PIDGIN_PREFS_ROOT
"/filelocations/last_open_folder");
2548 if ((filename
== NULL
|| *filename
== '\0' || !g_file_test(filename
, G_FILE_TEST_EXISTS
)) &&
2549 (current_folder
!= NULL
) && (*current_folder
!= '\0')) {
2550 folder_set
= gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(filesel
), current_folder
);
2553 if (!folder_set
&& (filename
== NULL
|| *filename
== '\0' || !g_file_test(filename
, G_FILE_TEST_EXISTS
))) {
2554 char *my_documents
= wpurple_get_special_folder(CSIDL_PERSONAL
);
2556 if (my_documents
!= NULL
) {
2557 gtk_file_chooser_set_current_folder(
2558 GTK_FILE_CHOOSER(filesel
), my_documents
);
2560 g_free(my_documents
);
2565 g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(filesel
)), "response",
2566 G_CALLBACK(file_ok_check_if_exists_cb
), data
);
2568 pidgin_auto_parent_window(filesel
);
2570 data
->dialog
= filesel
;
2571 gtk_widget_show(filesel
);
2573 return (void *)data
;
2577 pidgin_request_folder(const char *title
, const char *dirname
, GCallback ok_cb
,
2578 GCallback cancel_cb
, PurpleRequestCommonParameters
*cpar
,
2581 PidginRequestData
*data
;
2584 data
= g_new0(PidginRequestData
, 1);
2585 data
->type
= PURPLE_REQUEST_FOLDER
;
2586 data
->user_data
= user_data
;
2588 data
->cbs
= g_new0(GCallback
, 2);
2589 data
->cbs
[0] = cancel_cb
;
2590 data
->cbs
[1] = ok_cb
;
2591 data
->u
.file
.savedialog
= FALSE
;
2593 dirsel
= gtk_file_chooser_dialog_new(
2594 title
? title
: _("Select Folder..."),
2596 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
,
2597 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
2598 GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
,
2600 gtk_dialog_set_default_response(GTK_DIALOG(dirsel
), GTK_RESPONSE_ACCEPT
);
2602 pidgin_request_add_help(GTK_DIALOG(dirsel
), cpar
);
2604 if ((dirname
!= NULL
) && (*dirname
!= '\0'))
2605 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dirsel
), dirname
);
2607 g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(dirsel
)), "response",
2608 G_CALLBACK(file_ok_check_if_exists_cb
), data
);
2610 data
->dialog
= dirsel
;
2611 pidgin_auto_parent_window(dirsel
);
2613 gtk_widget_show(dirsel
);
2615 return (void *)data
;
2618 /* if request callback issues another request, it should be attached to the
2619 * primary request parent */
2621 pidgin_window_detach_children(GtkWindow
* win
)
2626 g_return_if_fail(win
!= NULL
);
2628 par
= gtk_window_get_transient_for(win
);
2629 it
= gtk_window_list_toplevels();
2630 for (it
= g_list_first(it
); it
!= NULL
; it
= g_list_next(it
)) {
2631 GtkWindow
*child
= GTK_WINDOW(it
->data
);
2632 if (gtk_window_get_transient_for(child
) != win
)
2634 if (gtk_window_get_destroy_with_parent(child
)) {
2636 /* XXX test/verify it: Win32 gtk ignores
2637 * gtk_window_set_destroy_with_parent(..., FALSE). */
2638 gtk_window_set_transient_for(child
, NULL
);
2642 gtk_window_set_transient_for(child
, par
);
2647 pidgin_close_request(PurpleRequestType type
, void *ui_handle
)
2649 PidginRequestData
*data
= (PidginRequestData
*)ui_handle
;
2653 pidgin_window_detach_children(GTK_WINDOW(data
->dialog
));
2655 gtk_widget_destroy(data
->dialog
);
2657 if (type
== PURPLE_REQUEST_FIELDS
)
2658 purple_request_fields_destroy(data
->u
.multifield
.fields
);
2659 else if (type
== PURPLE_REQUEST_FILE
)
2660 g_free(data
->u
.file
.name
);
2666 pidgin_request_get_dialog_window(void *ui_handle
)
2668 PidginRequestData
*data
= ui_handle
;
2670 g_return_val_if_fail(
2671 purple_request_is_valid_ui_handle(data
, NULL
), NULL
);
2673 return GTK_WINDOW(data
->dialog
);
2676 static PurpleRequestUiOps ops
=
2678 PURPLE_REQUEST_FEATURE_HTML
,
2679 pidgin_request_input
,
2680 pidgin_request_choice
,
2681 pidgin_request_action
,
2682 pidgin_request_wait
,
2683 pidgin_request_wait_update
,
2684 pidgin_request_fields
,
2685 pidgin_request_file
,
2686 pidgin_request_folder
,
2687 pidgin_close_request
,
2694 PurpleRequestUiOps
*
2695 pidgin_request_get_ui_ops(void)
2701 pidgin_request_get_handle(void)
2709 pidgin_request_datasheet_stock_remove(gpointer obj
)
2713 g_object_unref(obj
);
2717 pidgin_request_init(void)
2719 datasheet_stock
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
2720 g_free
, pidgin_request_datasheet_stock_remove
);
2724 pidgin_request_uninit(void)
2726 purple_signals_disconnect_by_handle(pidgin_request_get_handle());
2727 g_hash_table_destroy(datasheet_stock
);
2728 datasheet_stock
= NULL
;