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
23 #include "glibcompat.h"
28 # include <shellapi.h>
31 #include <gdk/gdkkeysyms.h>
35 #include "conversation.h"
45 #include "gtkaccount.h"
49 #include "gtkdialogs.h"
50 #include "pidginstock.h"
51 #include "gtkrequest.h"
53 #include "pidgin/minidialog.h"
55 #include "gtk3compat.h"
58 /******************************************************************************
60 *****************************************************************************/
76 COMPLETION_DISPLAYED_COLUMN
, /* displayed completion value */
77 COMPLETION_BUDDY_COLUMN
, /* buddy name */
78 COMPLETION_NORMALIZED_COLUMN
, /* UTF-8 normalized & casefolded buddy name */
79 COMPLETION_COMPARISON_COLUMN
, /* UTF-8 normalized & casefolded value for comparison */
80 COMPLETION_ACCOUNT_COLUMN
, /* account */
81 COMPLETION_COLUMN_COUNT
84 /******************************************************************************
86 *****************************************************************************/
95 PurpleAccount
*account
;
102 GtkWidget
*accountopt
;
104 PidginFilterBuddyCompletionEntryFunc filter_func
;
105 gpointer filter_func_user_data
;
108 } PidginCompletionData
;
110 struct _icon_chooser
{
111 GtkFileChooserNative
*icon_filesel
;
112 GtkWidget
*icon_preview
;
113 GtkWidget
*icon_text
;
115 void (*callback
)(const char*,gpointer
);
119 struct _old_button_clicked_cb_data
121 PidginUtilMiniDialogCallback cb
;
125 /******************************************************************************
127 *****************************************************************************/
129 static guint accels_save_timer
= 0;
130 static GSList
*minidialogs
= NULL
;
132 /******************************************************************************
134 *****************************************************************************/
136 void pidgin_window_init(GtkWindow
*wnd
, const char *title
, guint border_width
, const char *role
, gboolean resizable
)
139 gtk_window_set_title(wnd
, title
);
142 gtk_window_set_title(wnd
, PIDGIN_ALERT_TITLE
);
144 gtk_container_set_border_width(GTK_CONTAINER(wnd
), border_width
);
146 gtk_window_set_role(wnd
, role
);
147 gtk_window_set_resizable(wnd
, resizable
);
151 pidgin_create_window(const char *title
, guint border_width
, const char *role
, gboolean resizable
)
153 GtkWindow
*wnd
= NULL
;
155 wnd
= GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL
));
156 pidgin_window_init(wnd
, title
, border_width
, role
, resizable
);
158 return GTK_WIDGET(wnd
);
162 pidgin_create_small_button(GtkWidget
*image
)
166 button
= gtk_button_new();
167 gtk_button_set_relief(GTK_BUTTON(button
), GTK_RELIEF_NONE
);
169 /* don't allow focus on the close button */
170 gtk_widget_set_focus_on_click(button
, FALSE
);
172 gtk_widget_show(image
);
174 gtk_container_add(GTK_CONTAINER(button
), image
);
180 pidgin_create_dialog(const char *title
, guint border_width
, const char *role
, gboolean resizable
)
182 GtkWindow
*wnd
= NULL
;
184 wnd
= GTK_WINDOW(gtk_dialog_new());
185 pidgin_window_init(wnd
, title
, border_width
, role
, resizable
);
187 return GTK_WIDGET(wnd
);
191 pidgin_create_video_widget(void)
193 GtkWidget
*video
= NULL
;
194 GdkRGBA color
= {0.0, 0.0, 0.0, 1.0};
196 video
= gtk_drawing_area_new();
197 gtk_widget_override_background_color(video
, GTK_STATE_FLAG_NORMAL
, &color
);
199 /* In order to enable client shadow decorations, GtkDialog from GTK+ 3.0
200 * uses ARGB visual which by default gets inherited by its child widgets.
201 * XVideo adaptors on the other hand often support just depth 24 and
202 * rendering video through xvimagesink onto a widget inside a GtkDialog
203 * then results in no visible output.
205 * This ensures the default system visual of the drawing area doesn't get
206 * overridden by the widget's parent.
208 gtk_widget_set_visual(video
,
209 gdk_screen_get_system_visual(gtk_widget_get_screen(video
)));
215 pidgin_dialog_get_vbox_with_properties(GtkDialog
*dialog
, gboolean homogeneous
, gint spacing
)
217 GtkBox
*vbox
= GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog
)));
218 gtk_box_set_homogeneous(vbox
, homogeneous
);
219 gtk_box_set_spacing(vbox
, spacing
);
220 return GTK_WIDGET(vbox
);
223 GtkWidget
*pidgin_dialog_get_vbox(GtkDialog
*dialog
)
225 return gtk_dialog_get_content_area(GTK_DIALOG(dialog
));
228 GtkWidget
*pidgin_dialog_get_action_area(GtkDialog
*dialog
)
230 return gtk_dialog_get_action_area(GTK_DIALOG(dialog
));
233 GtkWidget
*pidgin_dialog_add_button(GtkDialog
*dialog
, const char *label
,
234 GCallback callback
, gpointer callbackdata
)
236 GtkWidget
*button
= gtk_button_new_with_mnemonic(label
);
237 GtkWidget
*bbox
= pidgin_dialog_get_action_area(dialog
);
239 /* Handle stock labels if passed in until nothing calls this
240 * expecting a GtkStock button */
243 if (gtk_stock_lookup(label
, &item
)) {
244 g_object_set(button
, "use-stock", TRUE
, NULL
);
248 gtk_box_pack_start(GTK_BOX(bbox
), button
, FALSE
, FALSE
, 0);
250 g_signal_connect(G_OBJECT(button
), "clicked", callback
, callbackdata
);
251 gtk_widget_show(button
);
256 pidgin_set_sensitive_if_input(GtkWidget
*entry
, GtkWidget
*dialog
)
258 const char *text
= gtk_entry_get_text(GTK_ENTRY(entry
));
259 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog
), GTK_RESPONSE_OK
,
263 GtkWidget
*pidgin_separator(GtkWidget
*menu
)
267 menuitem
= gtk_separator_menu_item_new();
268 gtk_widget_show(menuitem
);
269 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menuitem
);
273 GtkWidget
*pidgin_new_check_item(GtkWidget
*menu
, const char *str
,
274 GCallback cb
, gpointer data
, gboolean checked
)
277 menuitem
= gtk_check_menu_item_new_with_mnemonic(str
);
280 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menuitem
);
282 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem
), checked
);
285 g_signal_connect(G_OBJECT(menuitem
), "activate", cb
, data
);
287 gtk_widget_show_all(menuitem
);
293 pidgin_pixbuf_toolbar_button_from_stock(const char *icon
)
295 GtkWidget
*button
, *image
, *bbox
;
297 button
= gtk_toggle_button_new();
298 gtk_button_set_relief(GTK_BUTTON(button
), GTK_RELIEF_NONE
);
300 bbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0);
302 gtk_container_add (GTK_CONTAINER(button
), bbox
);
304 image
= gtk_image_new_from_stock(icon
, gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL
));
305 gtk_box_pack_start(GTK_BOX(bbox
), image
, FALSE
, FALSE
, 0);
307 gtk_widget_show_all(bbox
);
313 pidgin_pixbuf_button_from_stock(const char *text
, const char *icon
,
314 PidginButtonOrientation style
)
316 GtkWidget
*button
, *image
, *bbox
, *ibox
, *lbox
= NULL
;
318 button
= gtk_button_new();
320 if (style
== PIDGIN_BUTTON_HORIZONTAL
) {
321 bbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0);
322 ibox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0);
324 lbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0);
326 bbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0);
327 ibox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0);
329 lbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0);
332 gtk_container_add(GTK_CONTAINER(button
), bbox
);
335 gtk_box_pack_start(GTK_BOX(bbox
), ibox
, TRUE
, TRUE
, 0);
336 image
= gtk_image_new_from_stock(icon
, GTK_ICON_SIZE_BUTTON
);
337 gtk_box_pack_end(GTK_BOX(ibox
), image
, FALSE
, TRUE
, 0);
343 gtk_box_pack_start(GTK_BOX(bbox
), lbox
, TRUE
, TRUE
, 0);
344 label
= GTK_LABEL(gtk_label_new(NULL
));
345 gtk_label_set_text_with_mnemonic(label
, text
);
346 gtk_label_set_mnemonic_widget(label
, button
);
347 gtk_box_pack_start(GTK_BOX(lbox
), GTK_WIDGET(label
),
349 pidgin_set_accessible_label(button
, label
);
352 gtk_widget_show_all(bbox
);
358 GtkWidget
*pidgin_new_menu_item(GtkWidget
*menu
, const char *mnemonic
,
359 const char *icon
, GCallback cb
, gpointer data
)
365 box
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, PIDGIN_HIG_BOX_SPACE
);
367 menuitem
= gtk_menu_item_new();
370 g_signal_connect(G_OBJECT(menuitem
), "activate", cb
, data
);
374 image
= gtk_image_new_from_stock(icon
, GTK_ICON_SIZE_MENU
);
375 gtk_container_add(GTK_CONTAINER(box
), image
);
378 label
= gtk_label_new_with_mnemonic(mnemonic
);
379 gtk_container_add(GTK_CONTAINER(box
), label
);
381 gtk_container_add(GTK_CONTAINER(menuitem
), box
);
384 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menuitem
);
386 gtk_widget_show_all(menuitem
);
392 pidgin_make_frame(GtkWidget
*parent
, const char *title
)
394 GtkWidget
*vbox
, *vbox2
, *hbox
;
398 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BOX_SPACE
);
399 gtk_box_pack_start(GTK_BOX(parent
), vbox
, FALSE
, FALSE
, 0);
400 gtk_widget_show(vbox
);
402 label
= GTK_LABEL(gtk_label_new(NULL
));
404 labeltitle
= g_strdup_printf("<span weight=\"bold\">%s</span>", title
);
405 gtk_label_set_markup(label
, labeltitle
);
408 gtk_label_set_xalign(GTK_LABEL(label
), 0);
409 gtk_label_set_yalign(GTK_LABEL(label
), 0);
410 gtk_box_pack_start(GTK_BOX(vbox
), GTK_WIDGET(label
), FALSE
, FALSE
, 0);
411 gtk_widget_show(GTK_WIDGET(label
));
412 pidgin_set_accessible_label(vbox
, label
);
414 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, PIDGIN_HIG_BOX_SPACE
);
415 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
416 gtk_widget_show(hbox
);
418 label
= GTK_LABEL(gtk_label_new(" "));
419 gtk_box_pack_start(GTK_BOX(hbox
), GTK_WIDGET(label
), FALSE
, FALSE
, 0);
420 gtk_widget_show(GTK_WIDGET(label
));
422 vbox2
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BOX_SPACE
);
423 gtk_box_pack_start(GTK_BOX(hbox
), vbox2
, FALSE
, FALSE
, 0);
424 gtk_widget_show(vbox2
);
426 g_object_set_data(G_OBJECT(vbox2
), "main-vbox", vbox
);
432 aop_option_menu_get_selected(GtkWidget
*optmenu
)
434 gpointer data
= NULL
;
437 g_return_val_if_fail(optmenu
!= NULL
, NULL
);
439 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(optmenu
), &iter
))
440 gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu
)),
441 &iter
, AOP_DATA_COLUMN
, &data
, -1);
447 aop_menu_cb(GtkWidget
*optmenu
, GCallback cb
)
450 ((void (*)(GtkWidget
*, gpointer
, gpointer
))cb
)(optmenu
,
451 aop_option_menu_get_selected(optmenu
),
452 g_object_get_data(G_OBJECT(optmenu
), "user_data"));
457 aop_option_menu_replace_menu(GtkWidget
*optmenu
, AopMenu
*new_aop_menu
)
459 gtk_combo_box_set_model(GTK_COMBO_BOX(optmenu
), new_aop_menu
->model
);
460 gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu
), new_aop_menu
->default_item
);
461 g_free(new_aop_menu
);
465 pidgin_create_icon_from_protocol(PurpleProtocol
*protocol
, PidginProtocolIconSize size
, PurpleAccount
*account
)
467 const char *protoname
= NULL
;
469 char *filename
= NULL
;
472 protoname
= purple_protocol_class_list_icon(protocol
, account
, NULL
);
473 if (protoname
== NULL
)
477 * Status icons will be themeable too, and then it will look up
478 * protoname from the theme
480 tmp
= g_strconcat("im-", protoname
, ".png", NULL
);
482 filename
= g_build_filename(PURPLE_DATADIR
,
483 "pidgin", "icons", "hicolor",
484 (size
== PIDGIN_PROTOCOL_ICON_SMALL
) ? "16x16" :
485 ((size
== PIDGIN_PROTOCOL_ICON_MEDIUM
) ? "22x22" :
490 pixbuf
= pidgin_pixbuf_new_from_file(filename
);
497 aop_option_menu_new(AopMenu
*aop_menu
, GCallback cb
, gpointer user_data
)
499 GtkWidget
*optmenu
= NULL
;
500 GtkCellRenderer
*cr
= NULL
;
502 optmenu
= gtk_combo_box_new();
503 gtk_widget_show(optmenu
);
504 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(optmenu
), cr
= gtk_cell_renderer_pixbuf_new(), FALSE
);
505 gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(optmenu
), cr
, "pixbuf", AOP_ICON_COLUMN
);
506 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(optmenu
), cr
= gtk_cell_renderer_text_new(), TRUE
);
507 gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(optmenu
), cr
, "text", AOP_NAME_COLUMN
);
509 aop_option_menu_replace_menu(optmenu
, aop_menu
);
510 g_object_set_data(G_OBJECT(optmenu
), "user_data", user_data
);
512 g_signal_connect(G_OBJECT(optmenu
), "changed", G_CALLBACK(aop_menu_cb
), cb
);
518 aop_option_menu_select_by_data(GtkWidget
*optmenu
, gpointer data
)
523 model
= gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu
));
524 if (gtk_tree_model_get_iter_first(model
, &iter
)) {
526 gtk_tree_model_get(model
, &iter
, AOP_DATA_COLUMN
, &iter_data
, -1);
527 if (iter_data
== data
) {
528 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(optmenu
), &iter
);
531 } while (gtk_tree_model_iter_next(model
, &iter
));
536 create_protocols_menu(const char *default_proto_id
)
538 AopMenu
*aop_menu
= NULL
;
539 PurpleProtocol
*protocol
;
540 GdkPixbuf
*pixbuf
= NULL
;
546 ls
= gtk_list_store_new(AOP_COLUMN_COUNT
, GDK_TYPE_PIXBUF
, G_TYPE_STRING
, G_TYPE_POINTER
);
548 aop_menu
= g_malloc0(sizeof(AopMenu
));
549 aop_menu
->default_item
= 0;
550 aop_menu
->model
= GTK_TREE_MODEL(ls
);
552 list
= purple_protocols_get_all();
554 for (p
= list
, i
= 0;
558 protocol
= PURPLE_PROTOCOL(p
->data
);
560 pixbuf
= pidgin_create_icon_from_protocol(protocol
, PIDGIN_PROTOCOL_ICON_SMALL
, NULL
);
562 gtk_list_store_append(ls
, &iter
);
563 gtk_list_store_set(ls
, &iter
,
564 AOP_ICON_COLUMN
, pixbuf
,
565 AOP_NAME_COLUMN
, purple_protocol_get_name(protocol
),
566 AOP_DATA_COLUMN
, purple_protocol_get_id(protocol
),
570 g_object_unref(pixbuf
);
572 if (default_proto_id
!= NULL
&& purple_strequal(purple_protocol_get_id(protocol
), default_proto_id
))
573 aop_menu
->default_item
= i
;
581 pidgin_protocol_option_menu_new(const char *id
, GCallback cb
,
584 return aop_option_menu_new(create_protocols_menu(id
), cb
, user_data
);
588 pidgin_protocol_option_menu_get_selected(GtkWidget
*optmenu
)
590 return (const char *)aop_option_menu_get_selected(optmenu
);
594 pidgin_save_accels_cb(GtkAccelGroup
*accel_group
, guint arg1
,
595 GdkModifierType arg2
, GClosure
*arg3
,
598 purple_debug(PURPLE_DEBUG_MISC
, "accels",
599 "accel changed, scheduling save.\n");
601 if (!accels_save_timer
)
602 accels_save_timer
= g_timeout_add_seconds(5, pidgin_save_accels
,
607 pidgin_save_accels(gpointer data
)
609 char *filename
= NULL
;
611 filename
= g_build_filename(purple_config_dir(), "accels", NULL
);
612 purple_debug(PURPLE_DEBUG_MISC
, "accels", "saving accels to %s\n", filename
);
613 gtk_accel_map_save(filename
);
616 accels_save_timer
= 0;
623 char *filename
= NULL
;
625 filename
= g_build_filename(purple_config_dir(), "accels", NULL
);
626 gtk_accel_map_load(filename
);
631 show_retrieveing_info(PurpleConnection
*conn
, const char *name
)
633 PurpleNotifyUserInfo
*info
= purple_notify_user_info_new();
634 purple_notify_user_info_add_pair_plaintext(info
, _("Information"), _("Retrieving..."));
635 purple_notify_userinfo(conn
, name
, info
, NULL
, NULL
);
636 purple_notify_user_info_destroy(info
);
639 void pidgin_retrieve_user_info(PurpleConnection
*conn
, const char *name
)
641 show_retrieveing_info(conn
, name
);
642 purple_serv_get_info(conn
, name
);
645 void pidgin_retrieve_user_info_in_chat(PurpleConnection
*conn
, const char *name
, int chat
)
648 PurpleProtocol
*protocol
= NULL
;
651 pidgin_retrieve_user_info(conn
, name
);
655 protocol
= purple_connection_get_protocol(conn
);
656 if (protocol
!= NULL
)
657 who
= purple_protocol_chat_iface_get_user_real_name(protocol
, conn
, chat
, name
);
659 pidgin_retrieve_user_info(conn
, who
? who
: name
);
664 pidgin_parse_x_im_contact(const char *msg
, gboolean all_accounts
,
665 PurpleAccount
**ret_account
, char **ret_protocol
,
666 char **ret_username
, char **ret_alias
)
668 char *protocol
= NULL
;
669 char *username
= NULL
;
675 g_return_val_if_fail(msg
!= NULL
, FALSE
);
676 g_return_val_if_fail(ret_protocol
!= NULL
, FALSE
);
677 g_return_val_if_fail(ret_username
!= NULL
, FALSE
);
679 s
= str
= g_strdup(msg
);
681 while (*s
!= '\r' && *s
!= '\n' && *s
!= '\0')
688 while (*s
!= '\r' && *s
!= '\n' && *s
!= '\0' && *s
!= ' ')
699 if (*s
!= '\0') *s
++ = '\0';
701 /* Clear past any whitespace */
702 while (*s
!= '\0' && *s
== ' ')
705 /* Now let's grab until the end of the line. */
708 while (*s
!= '\r' && *s
!= '\n' && *s
!= '\0')
711 if (*s
== '\r') *s
++ = '\0';
712 if (*s
== '\n') *s
++ = '\0';
714 if (strchr(key
, ':') != NULL
)
716 if (!g_ascii_strcasecmp(key
, "X-IM-Username:"))
717 username
= g_strdup(value
);
718 else if (!g_ascii_strcasecmp(key
, "X-IM-Protocol:"))
719 protocol
= g_strdup(value
);
720 else if (!g_ascii_strcasecmp(key
, "X-IM-Alias:"))
721 alias
= g_strdup(value
);
725 if (username
!= NULL
&& protocol
!= NULL
)
729 *ret_username
= username
;
730 *ret_protocol
= protocol
;
732 if (ret_alias
!= NULL
)
735 /* Check for a compatible account. */
736 if (ret_account
!= NULL
)
739 PurpleAccount
*account
= NULL
;
741 const char *protoname
;
744 list
= purple_accounts_get_all();
746 list
= purple_connections_get_all();
748 for (l
= list
; l
!= NULL
; l
= l
->next
)
750 PurpleConnection
*gc
;
751 PurpleProtocol
*proto
= NULL
;
755 account
= (PurpleAccount
*)l
->data
;
757 proto
= purple_protocols_find(
758 purple_account_get_protocol_id(account
));
769 gc
= (PurpleConnection
*)l
->data
;
770 account
= purple_connection_get_account(gc
);
772 proto
= purple_connection_get_protocol(gc
);
775 protoname
= purple_protocol_class_list_icon(proto
, account
, NULL
);
777 if (purple_strequal(protoname
, protocol
))
783 /* Special case for AIM and ICQ */
784 if (account
== NULL
&& (purple_strequal(protocol
, "aim") ||
785 purple_strequal(protocol
, "icq")))
787 for (l
= list
; l
!= NULL
; l
= l
->next
)
789 PurpleConnection
*gc
;
790 PurpleProtocol
*proto
= NULL
;
794 account
= (PurpleAccount
*)l
->data
;
796 proto
= purple_protocols_find(
797 purple_account_get_protocol_id(account
));
808 gc
= (PurpleConnection
*)l
->data
;
809 account
= purple_connection_get_account(gc
);
811 proto
= purple_connection_get_protocol(gc
);
814 protoname
= purple_protocol_class_list_icon(proto
, account
, NULL
);
816 if (purple_strequal(protoname
, "aim") || purple_strequal(protoname
, "icq"))
823 *ret_account
= account
;
841 pidgin_set_accessible_label(GtkWidget
*w
, GtkLabel
*l
)
844 const gchar
*label_text
;
845 const gchar
*existing_name
;
847 acc
= gtk_widget_get_accessible (w
);
849 /* If this object has no name, set it's name with the label text */
850 existing_name
= atk_object_get_name (acc
);
851 if (!existing_name
) {
852 label_text
= gtk_label_get_text(l
);
854 atk_object_set_name (acc
, label_text
);
857 pidgin_set_accessible_relations(w
, l
);
861 pidgin_set_accessible_relations (GtkWidget
*w
, GtkLabel
*l
)
863 AtkObject
*acc
, *label
;
864 AtkObject
*rel_obj
[1];
866 AtkRelation
*relation
;
868 acc
= gtk_widget_get_accessible (w
);
869 label
= gtk_widget_get_accessible(GTK_WIDGET(l
));
871 /* Make sure mnemonics work */
872 gtk_label_set_mnemonic_widget(l
, w
);
874 /* Create the labeled-by relation */
875 set
= atk_object_ref_relation_set (acc
);
877 relation
= atk_relation_new (rel_obj
, 1, ATK_RELATION_LABELLED_BY
);
878 atk_relation_set_add (set
, relation
);
879 g_object_unref (relation
);
882 /* Create the label-for relation */
883 set
= atk_object_ref_relation_set (label
);
885 relation
= atk_relation_new (rel_obj
, 1, ATK_RELATION_LABEL_FOR
);
886 atk_relation_set_add (set
, relation
);
887 g_object_unref (relation
);
892 pidgin_menu_position_func_helper(GtkMenu
*menu
,
899 GtkRequisition requisition
;
901 GdkRectangle monitor
;
903 gint space_left
, space_right
, space_above
, space_below
;
906 g_return_if_fail(GTK_IS_MENU(menu
));
908 widget
= GTK_WIDGET(menu
);
909 screen
= gtk_widget_get_screen(widget
);
910 rtl
= (gtk_widget_get_direction(widget
) == GTK_TEXT_DIR_RTL
);
913 * We need the requisition to figure out the right place to
914 * popup the menu. In fact, we always need to ask here, since
915 * if a size_request was queued while we weren't popped up,
916 * the requisition won't have been recomputed yet.
918 gtk_widget_get_preferred_size(widget
, NULL
, &requisition
);
920 monitor_num
= gdk_screen_get_monitor_at_point (screen
, *x
, *y
);
925 * The placement of popup menus horizontally works like this (with
926 * RTL in parentheses)
928 * - If there is enough room to the right (left) of the mouse cursor,
929 * position the menu there.
931 * - Otherwise, if if there is enough room to the left (right) of the
932 * mouse cursor, position the menu there.
934 * - Otherwise if the menu is smaller than the monitor, position it
935 * on the side of the mouse cursor that has the most space available
937 * - Otherwise (if there is simply not enough room for the menu on the
938 * monitor), position it as far left (right) as possible.
940 * Positioning in the vertical direction is similar: first try below
941 * mouse cursor, then above.
943 gdk_screen_get_monitor_geometry (screen
, monitor_num
, &monitor
);
945 space_left
= *x
- monitor
.x
;
946 space_right
= monitor
.x
+ monitor
.width
- *x
- 1;
947 space_above
= *y
- monitor
.y
;
948 space_below
= monitor
.y
+ monitor
.height
- *y
- 1;
950 /* position horizontally */
952 if (requisition
.width
<= space_left
||
953 requisition
.width
<= space_right
)
955 if ((rtl
&& requisition
.width
<= space_left
) ||
956 (!rtl
&& requisition
.width
> space_right
))
959 *x
= *x
- requisition
.width
+ 1;
962 /* x is clamped on-screen further down */
964 else if (requisition
.width
<= monitor
.width
)
966 /* the menu is too big to fit on either side of the mouse
967 * cursor, but smaller than the monitor. Position it on
968 * the side that has the most space
970 if (space_left
> space_right
)
978 *x
= monitor
.x
+ monitor
.width
- requisition
.width
;
981 else /* menu is simply too big for the monitor */
986 *x
= monitor
.x
+ monitor
.width
- requisition
.width
;
995 /* Position vertically. The algorithm is the same as above, but
996 * simpler because we don't have to take RTL into account.
999 if (requisition
.height
<= space_above
||
1000 requisition
.height
<= space_below
)
1002 if (requisition
.height
> space_below
) {
1003 *y
= *y
- requisition
.height
+ 1;
1006 *y
= CLAMP (*y
, monitor
.y
,
1007 monitor
.y
+ monitor
.height
- requisition
.height
);
1009 if (space_below
>= space_above
)
1010 *y
= monitor
.y
+ monitor
.height
- requisition
.height
;
1017 #if !GTK_CHECK_VERSION(3,22,0)
1019 pidgin_treeview_popup_menu_position_func(GtkMenu
*menu
,
1025 GtkWidget
*widget
= GTK_WIDGET(data
);
1026 GtkTreeView
*tv
= GTK_TREE_VIEW(data
);
1028 GtkTreeViewColumn
*col
;
1031 gdk_window_get_origin (gtk_widget_get_window(widget
), x
, y
);
1032 gtk_tree_view_get_cursor (tv
, &path
, &col
);
1033 gtk_tree_view_get_cell_area (tv
, path
, col
, &rect
);
1035 *x
+= rect
.x
+rect
.width
;
1036 *y
+= rect
.y
+ rect
.height
;
1037 pidgin_menu_position_func_helper(menu
, x
, y
, push_in
, data
);
1043 pidgin_menu_popup_at_treeview_selection(GtkWidget
*menu
, GtkWidget
*treeview
)
1045 #if GTK_CHECK_VERSION(3,22,0)
1047 GtkTreeViewColumn
*column
;
1048 GdkWindow
*bin_window
;
1051 gtk_tree_view_get_cursor(GTK_TREE_VIEW(treeview
), &path
, &column
);
1052 g_return_if_fail(path
!= NULL
);
1054 column
= gtk_tree_view_get_column(GTK_TREE_VIEW(treeview
), 0);
1055 bin_window
= gtk_tree_view_get_bin_window(GTK_TREE_VIEW(treeview
));
1056 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(treeview
), path
, column
, &rect
);
1057 gtk_menu_popup_at_rect(GTK_MENU(menu
), bin_window
, &rect
,
1058 GDK_GRAVITY_SOUTH_WEST
, GDK_GRAVITY_NORTH_WEST
,
1061 gtk_tree_path_free(path
);
1063 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
,
1064 pidgin_treeview_popup_menu_position_func
, treeview
,
1065 0, GDK_CURRENT_TIME
);
1070 static void dnd_image_ok_callback(_DndData
*data
, int choice
)
1072 const gchar
*shortname
;
1077 PurpleConversation
*conv
;
1079 PurpleContact
*contact
;
1083 case DND_BUDDY_ICON
:
1084 if (g_stat(data
->filename
, &st
)) {
1087 str
= g_strdup_printf(_("The following error has occurred loading %s: %s"),
1088 data
->filename
, g_strerror(errno
));
1089 purple_notify_error(NULL
, NULL
,
1090 _("Failed to load image"), str
, NULL
);
1096 buddy
= purple_blist_find_buddy(data
->account
, data
->who
);
1098 purple_debug_info("custom-icon", "You can only set custom icons for people on your buddylist.\n");
1101 contact
= purple_buddy_get_contact(buddy
);
1102 purple_buddy_icons_node_set_custom_icon_from_file((PurpleBlistNode
*)contact
, data
->filename
);
1104 case DND_FILE_TRANSFER
:
1105 purple_serv_send_file(purple_account_get_connection(data
->account
), data
->who
, data
->filename
);
1108 conv
= PURPLE_CONVERSATION(purple_im_conversation_new(data
->account
, data
->who
));
1110 if (!g_file_get_contents(data
->filename
, &filedata
, &size
,
1114 str
= g_strdup_printf(_("The following error has occurred loading %s: %s"), data
->filename
, err
->message
);
1115 purple_notify_error(NULL
, NULL
,
1116 _("Failed to load image"), str
, NULL
);
1123 shortname
= strrchr(data
->filename
, G_DIR_SEPARATOR
);
1124 shortname
= shortname
? shortname
+ 1 : data
->filename
;
1125 img
= purple_image_new_from_data((guint8
*)filedata
, size
);
1126 purple_image_set_friendly_filename(img
, shortname
);
1128 # warning fix this when talkatu has a way to programmatically insert an image
1129 // pidgin_webview_insert_image(PIDGIN_WEBVIEW(gtkconv->entry), img);
1130 g_object_unref(img
);
1134 g_free(data
->filename
);
1139 static void dnd_image_cancel_callback(_DndData
*data
, int choice
)
1141 g_free(data
->filename
);
1146 static void dnd_set_icon_ok_cb(_DndData
*data
)
1148 dnd_image_ok_callback(data
, DND_BUDDY_ICON
);
1151 static void dnd_set_icon_cancel_cb(_DndData
*data
)
1153 g_free(data
->filename
);
1159 pidgin_dnd_file_send_image(PurpleAccount
*account
, const gchar
*who
,
1160 const gchar
*filename
)
1162 PurpleConnection
*gc
= purple_account_get_connection(account
);
1163 PurpleProtocol
*protocol
= NULL
;
1164 _DndData
*data
= g_new0(_DndData
, 1);
1165 gboolean ft
= FALSE
, im
= FALSE
;
1167 data
->who
= g_strdup(who
);
1168 data
->filename
= g_strdup(filename
);
1169 data
->account
= account
;
1172 protocol
= purple_connection_get_protocol(gc
);
1174 if (!(purple_connection_get_flags(gc
) & PURPLE_CONNECTION_FLAG_NO_IMAGES
))
1177 if (protocol
&& PURPLE_IS_PROTOCOL_XFER(protocol
)) {
1178 PurpleProtocolXferInterface
*iface
=
1179 PURPLE_PROTOCOL_XFER_GET_IFACE(protocol
);
1181 if(iface
->can_receive
) {
1182 ft
= purple_protocol_xfer_can_receive(
1183 PURPLE_PROTOCOL_XFER(protocol
),
1186 ft
= (iface
->send_file
) ? TRUE
: FALSE
;
1191 purple_request_choice(NULL
, NULL
,
1192 _("You have dragged an image"),
1193 _("You can send this image as a file "
1194 "transfer, embed it into this message, "
1195 "or use it as the buddy icon for this user."),
1196 (gpointer
)DND_FILE_TRANSFER
, _("OK"),
1197 (GCallback
)dnd_image_ok_callback
, _("Cancel"),
1198 (GCallback
)dnd_image_cancel_callback
,
1199 purple_request_cpar_from_account(account
), data
,
1200 _("Set as buddy icon"), DND_BUDDY_ICON
,
1201 _("Send image file"), DND_FILE_TRANSFER
,
1202 _("Insert in message"), DND_IM_IMAGE
,
1204 } else if (!(im
|| ft
)) {
1205 purple_request_yes_no(NULL
, NULL
, _("You have dragged an image"),
1206 _("Would you like to set it as the buddy icon for this user?"),
1207 PURPLE_DEFAULT_ACTION_NONE
,
1208 purple_request_cpar_from_account(account
),
1209 data
, (GCallback
)dnd_set_icon_ok_cb
, (GCallback
)dnd_set_icon_cancel_cb
);
1211 purple_request_choice(NULL
, NULL
,
1212 _("You have dragged an image"),
1213 (ft
? _("You can send this image as a file transfer, or use it as the buddy icon for this user.") :
1214 _("You can insert this image into this message, or use it as the buddy icon for this user")),
1215 GINT_TO_POINTER(ft
? DND_FILE_TRANSFER
: DND_IM_IMAGE
),
1216 _("OK"), (GCallback
)dnd_image_ok_callback
,
1217 _("Cancel"), (GCallback
)dnd_image_cancel_callback
,
1218 purple_request_cpar_from_account(account
),
1220 _("Set as buddy icon"), DND_BUDDY_ICON
,
1221 (ft
? _("Send image file") : _("Insert in message")), (ft
? DND_FILE_TRANSFER
: DND_IM_IMAGE
),
1229 pidgin_dnd_file_send_desktop(PurpleAccount
*account
, const gchar
*who
,
1230 const gchar
*filename
)
1235 GKeyFile
*desktop_file
;
1236 PurpleConversation
*conv
;
1237 PidginConversation
*gtkconv
;
1238 GError
*error
= NULL
;
1240 desktop_file
= g_key_file_new();
1242 if (!g_key_file_load_from_file(desktop_file
, filename
, G_KEY_FILE_NONE
, &error
)) {
1244 purple_debug_warning("D&D", "Failed to load %s: %s\n",
1245 filename
, error
->message
);
1246 g_error_free(error
);
1251 name
= g_key_file_get_string(desktop_file
, G_KEY_FILE_DESKTOP_GROUP
,
1252 G_KEY_FILE_DESKTOP_KEY_NAME
, &error
);
1254 purple_debug_warning("D&D", "Failed to read the Name from a desktop file: %s\n",
1256 g_error_free(error
);
1260 type
= g_key_file_get_string(desktop_file
, G_KEY_FILE_DESKTOP_GROUP
,
1261 G_KEY_FILE_DESKTOP_KEY_TYPE
, &error
);
1263 purple_debug_warning("D&D", "Failed to read the Type from a desktop file: %s\n",
1265 g_error_free(error
);
1269 url
= g_key_file_get_string(desktop_file
, G_KEY_FILE_DESKTOP_GROUP
,
1270 G_KEY_FILE_DESKTOP_KEY_URL
, &error
);
1272 purple_debug_warning("D&D", "Failed to read the Type from a desktop file: %s\n",
1274 g_error_free(error
);
1279 /* If any of this is null, do nothing. */
1280 if (!name
|| !type
|| !url
) {
1288 /* I don't know if we really want to do anything here. Most of
1289 * the desktop item types are crap like "MIME Type" (I have no
1290 * clue how that would be a desktop item) and "Comment"...
1291 * nothing we can really send. The only logical one is
1292 * "Application," but do we really want to send a binary and
1293 * nothing else? Probably not. I'll just give an error and
1295 /* The original patch sent the icon used by the launcher. That's probably wrong */
1296 if (purple_strequal(type
, "Link")) {
1297 purple_notify_error(NULL
, NULL
, _("Cannot send launcher"),
1298 _("You dragged a desktop launcher. Most "
1299 "likely you wanted to send the target "
1300 "of this launcher instead of this "
1301 "launcher itself."), NULL
);
1304 GtkTextBuffer
*buffer
= NULL
;
1305 GtkTextMark
*mark
= NULL
;
1308 conv
= PURPLE_CONVERSATION(purple_im_conversation_new(account
, who
));
1309 gtkconv
= PIDGIN_CONVERSATION(conv
);
1311 buffer
= talkatu_editor_get_buffer(TALKATU_EDITOR(gtkconv
->editor
));
1312 mark
= gtk_text_buffer_get_insert(buffer
);
1314 gtk_text_buffer_get_iter_at_mark(buffer
, &iter
, mark
);
1316 talkatu_buffer_insert_link(TALKATU_BUFFER(buffer
), &iter
, name
, url
);
1326 pidgin_dnd_file_manage(GtkSelectionData
*sd
, PurpleAccount
*account
, const char *who
)
1329 GList
*files
= purple_uri_list_extract_filenames((const gchar
*) gtk_selection_data_get_data(sd
));
1330 PurpleConnection
*gc
= purple_account_get_connection(account
);
1331 gchar
*filename
= NULL
;
1332 gchar
*basename
= NULL
;
1334 g_return_if_fail(account
!= NULL
);
1335 g_return_if_fail(who
!= NULL
);
1337 for ( ; files
; files
= g_list_delete_link(files
, files
)) {
1341 filename
= files
->data
;
1342 basename
= g_path_get_basename(filename
);
1344 /* XXX - Make ft API support creating a transfer with more than one file */
1345 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
)) {
1349 /* XXX - make ft api suupport sending a directory */
1350 /* Are we dealing with a directory? */
1351 if (g_file_test(filename
, G_FILE_TEST_IS_DIR
)) {
1354 str
= g_strdup_printf(_("Cannot send folder %s."), basename
);
1355 str2
= g_strdup_printf(_("%s cannot transfer a folder. You will need to send the files within individually."), PIDGIN_NAME
);
1357 purple_notify_error(NULL
, NULL
, str
, str2
,
1358 purple_request_cpar_from_connection(gc
));
1365 /* Are we dealing with an image? */
1366 pb
= pidgin_pixbuf_new_from_file(filename
);
1368 pidgin_dnd_file_send_image(account
, who
, filename
);
1370 g_object_unref(G_OBJECT(pb
));
1376 /* Are we trying to send a .desktop file? */
1377 else if (purple_str_has_suffix(basename
, ".desktop")) {
1378 pidgin_dnd_file_send_desktop(account
, who
, filename
);
1384 /* Everything is fine, let's send */
1385 purple_serv_send_file(gc
, who
, filename
);
1392 void pidgin_buddy_icon_get_scale_size(GdkPixbuf
*buf
, PurpleBuddyIconSpec
*spec
, PurpleBuddyIconScaleFlags rules
, int *width
, int *height
)
1394 *width
= gdk_pixbuf_get_width(buf
);
1395 *height
= gdk_pixbuf_get_height(buf
);
1397 if ((spec
== NULL
) || !(spec
->scale_rules
& rules
))
1400 purple_buddy_icon_spec_get_scaled_size(spec
, width
, height
);
1402 /* and now for some arbitrary sanity checks */
1409 GdkPixbuf
* pidgin_create_status_icon(PurpleStatusPrimitive prim
, GtkWidget
*w
, const char *size
)
1411 GtkIconSize icon_size
= gtk_icon_size_from_name(size
);
1412 GdkPixbuf
*pixbuf
= NULL
;
1413 const char *stock
= pidgin_stock_id_from_status_primitive(prim
);
1415 pixbuf
= gtk_widget_render_icon (w
, stock
? stock
: PIDGIN_STOCK_STATUS_AVAILABLE
,
1416 icon_size
, "GtkWidget");
1421 stock_id_from_status_primitive_idle(PurpleStatusPrimitive prim
, gboolean idle
)
1423 const char *stock
= NULL
;
1425 case PURPLE_STATUS_UNSET
:
1428 case PURPLE_STATUS_UNAVAILABLE
:
1429 stock
= idle
? PIDGIN_STOCK_STATUS_BUSY_I
: PIDGIN_STOCK_STATUS_BUSY
;
1431 case PURPLE_STATUS_AWAY
:
1432 stock
= idle
? PIDGIN_STOCK_STATUS_AWAY_I
: PIDGIN_STOCK_STATUS_AWAY
;
1434 case PURPLE_STATUS_EXTENDED_AWAY
:
1435 stock
= idle
? PIDGIN_STOCK_STATUS_XA_I
: PIDGIN_STOCK_STATUS_XA
;
1437 case PURPLE_STATUS_INVISIBLE
:
1438 stock
= PIDGIN_STOCK_STATUS_INVISIBLE
;
1440 case PURPLE_STATUS_OFFLINE
:
1441 stock
= idle
? PIDGIN_STOCK_STATUS_OFFLINE_I
: PIDGIN_STOCK_STATUS_OFFLINE
;
1444 stock
= idle
? PIDGIN_STOCK_STATUS_AVAILABLE_I
: PIDGIN_STOCK_STATUS_AVAILABLE
;
1451 pidgin_stock_id_from_status_primitive(PurpleStatusPrimitive prim
)
1453 return stock_id_from_status_primitive_idle(prim
, FALSE
);
1457 pidgin_stock_id_from_presence(PurplePresence
*presence
)
1459 PurpleStatus
*status
;
1460 PurpleStatusType
*type
;
1461 PurpleStatusPrimitive prim
;
1464 g_return_val_if_fail(presence
, NULL
);
1466 status
= purple_presence_get_active_status(presence
);
1467 type
= purple_status_get_status_type(status
);
1468 prim
= purple_status_type_get_primitive(type
);
1470 idle
= purple_presence_is_idle(presence
);
1472 return stock_id_from_status_primitive_idle(prim
, idle
);
1476 pidgin_create_protocol_icon(PurpleAccount
*account
, PidginProtocolIconSize size
)
1478 PurpleProtocol
*protocol
;
1480 g_return_val_if_fail(account
!= NULL
, NULL
);
1482 protocol
= purple_protocols_find(purple_account_get_protocol_id(account
));
1483 if (protocol
== NULL
)
1485 return pidgin_create_icon_from_protocol(protocol
, size
, account
);
1489 menu_action_cb(GtkMenuItem
*item
, gpointer object
)
1492 void (*callback
)(gpointer
, gpointer
);
1494 callback
= g_object_get_data(G_OBJECT(item
), "purplecallback");
1495 data
= g_object_get_data(G_OBJECT(item
), "purplecallbackdata");
1498 callback(object
, data
);
1502 pidgin_append_menu_action(GtkWidget
*menu
, PurpleActionMenu
*act
,
1505 GtkWidget
*menuitem
;
1509 return pidgin_separator(menu
);
1512 menuitem
= gtk_menu_item_new_with_mnemonic(
1513 purple_action_menu_get_label(act
));
1515 list
= purple_action_menu_get_children(act
);
1518 PurpleCallback callback
;
1520 callback
= purple_action_menu_get_callback(act
);
1522 if (callback
!= NULL
) {
1523 g_object_set_data(G_OBJECT(menuitem
),
1526 g_object_set_data(G_OBJECT(menuitem
),
1527 "purplecallbackdata",
1528 purple_action_menu_get_data(act
));
1529 g_signal_connect(G_OBJECT(menuitem
), "activate",
1530 G_CALLBACK(menu_action_cb
),
1533 gtk_widget_set_sensitive(menuitem
, FALSE
);
1536 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menuitem
);
1539 GtkWidget
*submenu
= NULL
;
1540 GtkAccelGroup
*group
;
1542 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menuitem
);
1544 submenu
= gtk_menu_new();
1545 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem
), submenu
);
1547 group
= gtk_menu_get_accel_group(GTK_MENU(menu
));
1549 char *path
= g_strdup_printf("%s/%s",
1550 gtk_menu_item_get_accel_path(GTK_MENU_ITEM(menuitem
)),
1551 purple_action_menu_get_label(act
));
1552 gtk_menu_set_accel_path(GTK_MENU(submenu
), path
);
1554 gtk_menu_set_accel_group(GTK_MENU(submenu
), group
);
1557 for (l
= list
; l
; l
= l
->next
) {
1558 PurpleActionMenu
*act
= (PurpleActionMenu
*)l
->data
;
1560 pidgin_append_menu_action(submenu
, act
, object
);
1563 purple_action_menu_set_children(act
, NULL
);
1565 purple_action_menu_free(act
);
1569 static gboolean
buddyname_completion_match_func(GtkEntryCompletion
*completion
,
1570 const gchar
*key
, GtkTreeIter
*iter
, gpointer user_data
)
1572 GtkTreeModel
*model
;
1577 model
= gtk_entry_completion_get_model(completion
);
1580 gtk_tree_model_get_value(model
, iter
, COMPLETION_NORMALIZED_COLUMN
, &val1
);
1581 tmp
= g_value_get_string(&val1
);
1582 if (tmp
!= NULL
&& purple_str_has_prefix(tmp
, key
))
1584 g_value_unset(&val1
);
1587 g_value_unset(&val1
);
1590 gtk_tree_model_get_value(model
, iter
, COMPLETION_COMPARISON_COLUMN
, &val2
);
1591 tmp
= g_value_get_string(&val2
);
1592 if (tmp
!= NULL
&& purple_str_has_prefix(tmp
, key
))
1594 g_value_unset(&val2
);
1597 g_value_unset(&val2
);
1602 static gboolean
buddyname_completion_match_selected_cb(GtkEntryCompletion
*completion
,
1603 GtkTreeModel
*model
, GtkTreeIter
*iter
, PidginCompletionData
*data
)
1606 GtkWidget
*optmenu
= data
->accountopt
;
1607 PurpleAccount
*account
;
1610 gtk_tree_model_get_value(model
, iter
, COMPLETION_BUDDY_COLUMN
, &val
);
1611 gtk_entry_set_text(GTK_ENTRY(data
->entry
), g_value_get_string(&val
));
1612 g_value_unset(&val
);
1614 gtk_tree_model_get_value(model
, iter
, COMPLETION_ACCOUNT_COLUMN
, &val
);
1615 account
= g_value_get_pointer(&val
);
1616 g_value_unset(&val
);
1618 if (account
== NULL
)
1621 if (optmenu
!= NULL
)
1622 aop_option_menu_select_by_data(optmenu
, account
);
1628 add_buddyname_autocomplete_entry(GtkListStore
*store
, const char *buddy_alias
, const char *contact_alias
,
1629 const PurpleAccount
*account
, const char *buddyname
)
1632 gboolean completion_added
= FALSE
;
1633 gchar
*normalized_buddyname
;
1636 tmp
= g_utf8_normalize(buddyname
, -1, G_NORMALIZE_DEFAULT
);
1637 normalized_buddyname
= g_utf8_casefold(tmp
, -1);
1640 /* There's no sense listing things like: 'xxx "xxx"'
1641 when the name and buddy alias match. */
1642 if (buddy_alias
&& !purple_strequal(buddy_alias
, buddyname
)) {
1643 char *completion_entry
= g_strdup_printf("%s \"%s\"", buddyname
, buddy_alias
);
1644 char *tmp2
= g_utf8_normalize(buddy_alias
, -1, G_NORMALIZE_DEFAULT
);
1646 tmp
= g_utf8_casefold(tmp2
, -1);
1649 gtk_list_store_append(store
, &iter
);
1650 gtk_list_store_set(store
, &iter
,
1651 COMPLETION_DISPLAYED_COLUMN
, completion_entry
,
1652 COMPLETION_BUDDY_COLUMN
, buddyname
,
1653 COMPLETION_NORMALIZED_COLUMN
, normalized_buddyname
,
1654 COMPLETION_COMPARISON_COLUMN
, tmp
,
1655 COMPLETION_ACCOUNT_COLUMN
, account
,
1657 g_free(completion_entry
);
1659 completion_added
= TRUE
;
1662 /* There's no sense listing things like: 'xxx "xxx"'
1663 when the name and contact alias match. */
1664 if (contact_alias
&& !purple_strequal(contact_alias
, buddyname
)) {
1665 /* We don't want duplicates when the contact and buddy alias match. */
1666 if (!purple_strequal(contact_alias
, buddy_alias
)) {
1667 char *completion_entry
= g_strdup_printf("%s \"%s\"",
1668 buddyname
, contact_alias
);
1669 char *tmp2
= g_utf8_normalize(contact_alias
, -1, G_NORMALIZE_DEFAULT
);
1671 tmp
= g_utf8_casefold(tmp2
, -1);
1674 gtk_list_store_append(store
, &iter
);
1675 gtk_list_store_set(store
, &iter
,
1676 COMPLETION_DISPLAYED_COLUMN
, completion_entry
,
1677 COMPLETION_BUDDY_COLUMN
, buddyname
,
1678 COMPLETION_NORMALIZED_COLUMN
, normalized_buddyname
,
1679 COMPLETION_COMPARISON_COLUMN
, tmp
,
1680 COMPLETION_ACCOUNT_COLUMN
, account
,
1682 g_free(completion_entry
);
1684 completion_added
= TRUE
;
1688 if (completion_added
== FALSE
) {
1689 /* Add the buddy's name. */
1690 gtk_list_store_append(store
, &iter
);
1691 gtk_list_store_set(store
, &iter
,
1692 COMPLETION_DISPLAYED_COLUMN
, buddyname
,
1693 COMPLETION_BUDDY_COLUMN
, buddyname
,
1694 COMPLETION_NORMALIZED_COLUMN
, normalized_buddyname
,
1695 COMPLETION_COMPARISON_COLUMN
, NULL
,
1696 COMPLETION_ACCOUNT_COLUMN
, account
,
1700 g_free(normalized_buddyname
);
1703 static void get_log_set_name(PurpleLogSet
*set
, gpointer value
, PidginCompletionData
*data
)
1705 PidginFilterBuddyCompletionEntryFunc filter_func
= data
->filter_func
;
1706 gpointer user_data
= data
->filter_func_user_data
;
1708 /* 1. Don't show buddies because we will have gotten them already.
1709 * 2. The boxes that use this autocomplete code handle only IMs. */
1710 if (!set
->buddy
&& set
->type
== PURPLE_LOG_IM
) {
1711 PidginBuddyCompletionEntry entry
;
1712 entry
.is_buddy
= FALSE
;
1713 entry
.entry
.logged_buddy
= set
;
1715 if (filter_func(&entry
, user_data
)) {
1716 add_buddyname_autocomplete_entry(data
->store
,
1717 NULL
, NULL
, set
->account
, set
->name
);
1723 add_completion_list(PidginCompletionData
*data
)
1725 PurpleBlistNode
*gnode
, *cnode
, *bnode
;
1726 PidginFilterBuddyCompletionEntryFunc filter_func
= data
->filter_func
;
1727 gpointer user_data
= data
->filter_func_user_data
;
1731 gtk_list_store_clear(data
->store
);
1733 for (gnode
= purple_blist_get_default_root(); gnode
!= NULL
;
1734 gnode
= gnode
->next
) {
1735 if (!PURPLE_IS_GROUP(gnode
))
1738 for (cnode
= gnode
->child
; cnode
!= NULL
; cnode
= cnode
->next
)
1740 if (!PURPLE_IS_CONTACT(cnode
))
1743 g_object_get(cnode
, "alias", &alias
, NULL
);
1745 for (bnode
= cnode
->child
; bnode
!= NULL
; bnode
= bnode
->next
)
1747 PidginBuddyCompletionEntry entry
;
1748 entry
.is_buddy
= TRUE
;
1749 entry
.entry
.buddy
= (PurpleBuddy
*) bnode
;
1751 if (filter_func(&entry
, user_data
)) {
1752 add_buddyname_autocomplete_entry(data
->store
,
1754 purple_buddy_get_contact_alias(entry
.entry
.buddy
),
1755 purple_buddy_get_account(entry
.entry
.buddy
),
1756 purple_buddy_get_name(entry
.entry
.buddy
)
1765 sets
= purple_log_get_log_sets();
1766 g_hash_table_foreach(sets
, (GHFunc
)get_log_set_name
, data
);
1767 g_hash_table_destroy(sets
);
1772 buddyname_autocomplete_destroyed_cb(GtkWidget
*widget
, gpointer data
)
1775 purple_signals_disconnect_by_handle(widget
);
1779 repopulate_autocomplete(gpointer something
, gpointer data
)
1781 add_completion_list(data
);
1785 pidgin_setup_screenname_autocomplete(
1786 GtkWidget
*entry
, GtkWidget
*chooser
,
1787 PidginFilterBuddyCompletionEntryFunc filter_func
, gpointer user_data
)
1789 PidginCompletionData
*data
;
1792 * Store the displayed completion value, the buddy name, the UTF-8
1793 * normalized & casefolded buddy name, the UTF-8 normalized &
1794 * casefolded value for comparison, and the account.
1796 GtkListStore
*store
;
1798 GtkEntryCompletion
*completion
;
1800 data
= g_new0(PidginCompletionData
, 1);
1801 store
= gtk_list_store_new(COMPLETION_COLUMN_COUNT
, G_TYPE_STRING
,
1802 G_TYPE_STRING
, G_TYPE_STRING
, G_TYPE_STRING
,
1805 data
->entry
= entry
;
1806 data
->accountopt
= chooser
;
1807 if (filter_func
== NULL
) {
1808 data
->filter_func
= pidgin_screenname_autocomplete_default_filter
;
1809 data
->filter_func_user_data
= NULL
;
1811 data
->filter_func
= filter_func
;
1812 data
->filter_func_user_data
= user_data
;
1814 data
->store
= store
;
1816 add_completion_list(data
);
1818 /* Sort the completion list by buddy name */
1819 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store
),
1820 COMPLETION_BUDDY_COLUMN
,
1821 GTK_SORT_ASCENDING
);
1823 completion
= gtk_entry_completion_new();
1824 gtk_entry_completion_set_match_func(completion
, buddyname_completion_match_func
, NULL
, NULL
);
1826 g_signal_connect(G_OBJECT(completion
), "match-selected",
1827 G_CALLBACK(buddyname_completion_match_selected_cb
), data
);
1829 gtk_entry_set_completion(GTK_ENTRY(entry
), completion
);
1830 g_object_unref(completion
);
1832 gtk_entry_completion_set_model(completion
, GTK_TREE_MODEL(store
));
1833 g_object_unref(store
);
1835 gtk_entry_completion_set_text_column(completion
, COMPLETION_DISPLAYED_COLUMN
);
1837 purple_signal_connect(purple_connections_get_handle(), "signed-on", entry
,
1838 PURPLE_CALLBACK(repopulate_autocomplete
), data
);
1839 purple_signal_connect(purple_connections_get_handle(), "signed-off", entry
,
1840 PURPLE_CALLBACK(repopulate_autocomplete
), data
);
1842 purple_signal_connect(purple_accounts_get_handle(), "account-added", entry
,
1843 PURPLE_CALLBACK(repopulate_autocomplete
), data
);
1844 purple_signal_connect(purple_accounts_get_handle(), "account-removed", entry
,
1845 PURPLE_CALLBACK(repopulate_autocomplete
), data
);
1847 g_signal_connect(G_OBJECT(entry
), "destroy", G_CALLBACK(buddyname_autocomplete_destroyed_cb
), data
);
1851 pidgin_screenname_autocomplete_default_filter(const PidginBuddyCompletionEntry
*completion_entry
, gpointer all_accounts
) {
1852 gboolean all
= GPOINTER_TO_INT(all_accounts
);
1854 if (completion_entry
->is_buddy
) {
1855 return all
|| purple_account_is_connected(purple_buddy_get_account(completion_entry
->entry
.buddy
));
1857 return all
|| (completion_entry
->entry
.logged_buddy
->account
!= NULL
&& purple_account_is_connected(completion_entry
->entry
.logged_buddy
->account
));
1861 void pidgin_set_cursor(GtkWidget
*widget
, GdkCursorType cursor_type
)
1863 GdkDisplay
*display
;
1866 g_return_if_fail(widget
!= NULL
);
1867 if (gtk_widget_get_window(widget
) == NULL
)
1870 display
= gtk_widget_get_display(widget
);
1871 cursor
= gdk_cursor_new_for_display(display
, cursor_type
);
1872 gdk_window_set_cursor(gtk_widget_get_window(widget
), cursor
);
1874 g_object_unref(cursor
);
1876 gdk_display_flush(gdk_window_get_display(gtk_widget_get_window(widget
)));
1879 void pidgin_clear_cursor(GtkWidget
*widget
)
1881 g_return_if_fail(widget
!= NULL
);
1882 if (gtk_widget_get_window(widget
) == NULL
)
1885 gdk_window_set_cursor(gtk_widget_get_window(widget
), NULL
);
1889 icon_filesel_choose_cb(GtkWidget
*widget
, gint response
, struct _icon_chooser
*dialog
)
1891 char *filename
, *current_folder
;
1893 if (response
!= GTK_RESPONSE_ACCEPT
) {
1894 if (dialog
->callback
)
1895 dialog
->callback(NULL
, dialog
->data
);
1900 filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog
->icon_filesel
));
1901 current_folder
= gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog
->icon_filesel
));
1902 if (current_folder
!= NULL
) {
1903 purple_prefs_set_path(PIDGIN_PREFS_ROOT
"/filelocations/last_icon_folder", current_folder
);
1904 g_free(current_folder
);
1908 if (dialog
->callback
)
1909 dialog
->callback(filename
, dialog
->data
);
1916 icon_preview_change_cb(GtkFileChooser
*widget
, struct _icon_chooser
*dialog
)
1920 char *basename
, *markup
, *size
;
1924 filename
= gtk_file_chooser_get_preview_filename(
1925 GTK_FILE_CHOOSER(dialog
->icon_filesel
));
1927 if (!filename
|| g_stat(filename
, &st
) || !(pixbuf
= pidgin_pixbuf_new_from_file_at_size(filename
, 128, 128)))
1929 gtk_image_set_from_pixbuf(GTK_IMAGE(dialog
->icon_preview
), NULL
);
1930 gtk_label_set_markup(GTK_LABEL(dialog
->icon_text
), "");
1935 gdk_pixbuf_get_file_info(filename
, &width
, &height
);
1936 basename
= g_path_get_basename(filename
);
1937 size
= g_format_size(st
.st_size
);
1938 markup
= g_strdup_printf(_("<b>File:</b> %s\n"
1939 "<b>File size:</b> %s\n"
1940 "<b>Image size:</b> %dx%d"),
1941 basename
, size
, width
, height
);
1943 gtk_image_set_from_pixbuf(GTK_IMAGE(dialog
->icon_preview
), pixbuf
);
1944 gtk_label_set_markup(GTK_LABEL(dialog
->icon_text
), markup
);
1946 g_object_unref(G_OBJECT(pixbuf
));
1953 GtkFileChooserNative
*
1954 pidgin_buddy_icon_chooser_new(GtkWindow
*parent
,
1955 void (*callback
)(const char *, gpointer
),
1958 struct _icon_chooser
*dialog
= g_new0(struct _icon_chooser
, 1);
1961 const char *current_folder
;
1963 dialog
->callback
= callback
;
1964 dialog
->data
= data
;
1966 current_folder
= purple_prefs_get_path(PIDGIN_PREFS_ROOT
"/filelocations/last_icon_folder");
1968 dialog
->icon_filesel
= gtk_file_chooser_native_new(
1969 _("Buddy Icon"), parent
, GTK_FILE_CHOOSER_ACTION_OPEN
, _("_Open"),
1971 if ((current_folder
!= NULL
) && (*current_folder
!= '\0'))
1972 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog
->icon_filesel
),
1975 dialog
->icon_preview
= gtk_image_new();
1976 dialog
->icon_text
= gtk_label_new(NULL
);
1978 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, PIDGIN_HIG_BOX_SPACE
);
1979 gtk_widget_set_size_request(GTK_WIDGET(vbox
), -1, 50);
1980 gtk_box_pack_start(GTK_BOX(vbox
), GTK_WIDGET(dialog
->icon_preview
), TRUE
, FALSE
, 0);
1981 gtk_box_pack_end(GTK_BOX(vbox
), GTK_WIDGET(dialog
->icon_text
), FALSE
, FALSE
, 0);
1982 gtk_widget_show_all(vbox
);
1984 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog
->icon_filesel
), vbox
);
1985 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(dialog
->icon_filesel
), TRUE
);
1986 gtk_file_chooser_set_use_preview_label(GTK_FILE_CHOOSER(dialog
->icon_filesel
), FALSE
);
1988 g_signal_connect(G_OBJECT(dialog
->icon_filesel
), "update-preview",
1989 G_CALLBACK(icon_preview_change_cb
), dialog
);
1990 g_signal_connect(G_OBJECT(dialog
->icon_filesel
), "response",
1991 G_CALLBACK(icon_filesel_choose_cb
), dialog
);
1992 icon_preview_change_cb(NULL
, dialog
);
1994 return dialog
->icon_filesel
;
2000 * Returns: %TRUE if any string from array @a exists in array @b.
2003 str_array_match(char **a
, char **b
)
2009 for (i
= 0; a
[i
] != NULL
; i
++)
2010 for (j
= 0; b
[j
] != NULL
; j
++)
2011 if (!g_ascii_strcasecmp(a
[i
], b
[j
]))
2017 pidgin_convert_buddy_icon(PurpleProtocol
*protocol
, const char *path
, size_t *len
)
2019 PurpleBuddyIconSpec
*spec
;
2020 int orig_width
, orig_height
, new_width
, new_height
;
2021 GdkPixbufFormat
*format
;
2022 char **pixbuf_formats
;
2023 char **protocol_formats
;
2024 GError
*error
= NULL
;
2027 GdkPixbuf
*pixbuf
, *original
;
2032 spec
= purple_protocol_get_icon_spec(protocol
);
2033 g_return_val_if_fail(spec
->format
!= NULL
, NULL
);
2035 format
= gdk_pixbuf_get_file_info(path
, &orig_width
, &orig_height
);
2036 if (format
== NULL
) {
2037 purple_debug_warning("buddyicon", "Could not get file info of %s\n", path
);
2041 pixbuf_formats
= gdk_pixbuf_format_get_extensions(format
);
2042 protocol_formats
= g_strsplit(spec
->format
, ",", 0);
2044 if (str_array_match(pixbuf_formats
, protocol_formats
) && /* This is an acceptable format AND */
2045 (!(spec
->scale_rules
& PURPLE_ICON_SCALE_SEND
) || /* The protocol doesn't scale before it sends OR */
2046 (spec
->min_width
<= orig_width
&& spec
->max_width
>= orig_width
&&
2047 spec
->min_height
<= orig_height
&& spec
->max_height
>= orig_height
))) /* The icon is the correct size */
2049 g_strfreev(pixbuf_formats
);
2051 if (!g_file_get_contents(path
, &contents
, &length
, &error
)) {
2052 purple_debug_warning("buddyicon", "Could not get file contents "
2053 "of %s: %s\n", path
, error
->message
);
2054 g_strfreev(protocol_formats
);
2058 if (spec
->max_filesize
== 0 || length
< spec
->max_filesize
) {
2059 /* The supplied image fits the file size, dimensions and type
2060 constraints. Great! Return it without making any changes. */
2063 g_strfreev(protocol_formats
);
2067 /* The image was too big. Fall-through and try scaling it down. */
2070 g_strfreev(pixbuf_formats
);
2073 /* The original image wasn't compatible. Scale it or convert file type. */
2074 pixbuf
= gdk_pixbuf_new_from_file(path
, &error
);
2076 purple_debug_warning("buddyicon", "Could not open icon '%s' for "
2077 "conversion: %s\n", path
, error
->message
);
2078 g_error_free(error
);
2079 g_strfreev(protocol_formats
);
2082 original
= g_object_ref(pixbuf
);
2084 new_width
= orig_width
;
2085 new_height
= orig_height
;
2087 /* Make sure the image is the correct dimensions */
2088 if (spec
->scale_rules
& PURPLE_ICON_SCALE_SEND
&&
2089 (orig_width
< spec
->min_width
|| orig_width
> spec
->max_width
||
2090 orig_height
< spec
->min_height
|| orig_height
> spec
->max_height
))
2092 purple_buddy_icon_spec_get_scaled_size(spec
, &new_width
, &new_height
);
2094 g_object_unref(G_OBJECT(pixbuf
));
2095 pixbuf
= gdk_pixbuf_scale_simple(original
, new_width
, new_height
, GDK_INTERP_HYPER
);
2100 for (i
= 0; protocol_formats
[i
]; i
++) {
2103 const char *key
= NULL
;
2104 const char *value
= NULL
;
2107 purple_debug_info("buddyicon", "Converting buddy icon to %s\n", protocol_formats
[i
]);
2109 if (purple_strequal(protocol_formats
[i
], "png")) {
2110 key
= "compression";
2112 } else if (purple_strequal(protocol_formats
[i
], "jpeg")) {
2113 sprintf(tmp_buf
, "%u", quality
);
2118 if (!gdk_pixbuf_save_to_buffer(pixbuf
, &contents
, &length
,
2119 protocol_formats
[i
], &error
, key
, value
, NULL
))
2121 /* The NULL checking of error is necessary due to this bug:
2122 * http://bugzilla.gnome.org/show_bug.cgi?id=405539 */
2123 purple_debug_warning("buddyicon",
2124 "Could not convert to %s: %s\n", protocol_formats
[i
],
2125 (error
&& error
->message
) ? error
->message
: "Unknown error");
2126 g_error_free(error
);
2129 /* We couldn't convert to this image type. Try the next
2134 if (spec
->max_filesize
== 0 || length
<= spec
->max_filesize
) {
2135 /* We were able to save the image as this image type and
2136 have it be within the size constraints. Great! Return
2138 purple_debug_info("buddyicon", "Converted image from "
2139 "%dx%d to %dx%d, format=%s, quality=%u, "
2140 "filesize=%" G_GSIZE_FORMAT
"\n",
2141 orig_width
, orig_height
, new_width
, new_height
,
2142 protocol_formats
[i
], quality
, length
);
2145 g_strfreev(protocol_formats
);
2146 g_object_unref(G_OBJECT(pixbuf
));
2147 g_object_unref(G_OBJECT(original
));
2153 if (!purple_strequal(protocol_formats
[i
], "jpeg")) {
2154 /* File size was too big and we can't lower the quality,
2155 so skip to the next image type. */
2159 /* File size was too big, but we're dealing with jpeg so try
2160 lowering the quality. */
2162 } while (quality
>= 70);
2165 /* We couldn't save the image in any format that was below the max
2166 file size. Maybe we can reduce the image dimensions? */
2167 scale_factor
*= 0.8;
2168 new_width
= orig_width
* scale_factor
;
2169 new_height
= orig_height
* scale_factor
;
2170 g_object_unref(G_OBJECT(pixbuf
));
2171 pixbuf
= gdk_pixbuf_scale_simple(original
, new_width
, new_height
, GDK_INTERP_HYPER
);
2172 } while ((new_width
> 10 || new_height
> 10) && new_width
> spec
->min_width
&& new_height
> spec
->min_height
);
2173 g_strfreev(protocol_formats
);
2174 g_object_unref(G_OBJECT(pixbuf
));
2175 g_object_unref(G_OBJECT(original
));
2177 tmp
= g_strdup_printf(_("The file '%s' is too large for %s. Please try a smaller image.\n"),
2178 path
, purple_protocol_get_name(protocol
));
2179 purple_notify_error(NULL
, _("Icon Error"), _("Could not set icon"), tmp
, NULL
);
2185 void pidgin_set_urgent(GtkWindow
*window
, gboolean urgent
)
2188 winpidgin_window_flash(window
, urgent
);
2190 gtk_window_set_urgency_hint(window
, urgent
);
2195 pidgin_utils_get_handle(void)
2202 static void connection_signed_off_cb(PurpleConnection
*gc
)
2204 GSList
*list
, *l_next
;
2205 for (list
= minidialogs
; list
; list
= l_next
) {
2206 l_next
= list
->next
;
2207 if (g_object_get_data(G_OBJECT(list
->data
), "gc") == gc
) {
2208 gtk_widget_destroy(GTK_WIDGET(list
->data
));
2213 static void alert_killed_cb(GtkWidget
*widget
)
2215 minidialogs
= g_slist_remove(minidialogs
, widget
);
2219 old_mini_dialog_button_clicked_cb(PidginMiniDialog
*mini_dialog
,
2223 struct _old_button_clicked_cb_data
*data
= user_data
;
2224 data
->cb(data
->data
, button
);
2228 old_mini_dialog_destroy_cb(GtkWidget
*dialog
,
2231 while (cb_datas
!= NULL
)
2233 g_free(cb_datas
->data
);
2234 cb_datas
= g_list_delete_link(cb_datas
, cb_datas
);
2239 mini_dialog_init(PidginMiniDialog
*mini_dialog
, PurpleConnection
*gc
, void *user_data
, va_list args
)
2241 const char *button_text
;
2242 GList
*cb_datas
= NULL
;
2243 static gboolean first_call
= TRUE
;
2247 purple_signal_connect(purple_connections_get_handle(), "signed-off",
2248 pidgin_utils_get_handle(),
2249 PURPLE_CALLBACK(connection_signed_off_cb
), NULL
);
2252 g_object_set_data(G_OBJECT(mini_dialog
), "gc" ,gc
);
2253 g_signal_connect(G_OBJECT(mini_dialog
), "destroy",
2254 G_CALLBACK(alert_killed_cb
), NULL
);
2256 while ((button_text
= va_arg(args
, char*))) {
2257 struct _old_button_clicked_cb_data
*data
= NULL
;
2258 PidginMiniDialogCallback wrapper_cb
= NULL
;
2259 PidginUtilMiniDialogCallback callback
=
2260 va_arg(args
, PidginUtilMiniDialogCallback
);
2262 if (callback
!= NULL
) {
2263 data
= g_new0(struct _old_button_clicked_cb_data
, 1);
2264 data
->cb
= callback
;
2265 data
->data
= user_data
;
2266 wrapper_cb
= old_mini_dialog_button_clicked_cb
;
2268 pidgin_mini_dialog_add_button(mini_dialog
, button_text
,
2270 cb_datas
= g_list_append(cb_datas
, data
);
2273 g_signal_connect(G_OBJECT(mini_dialog
), "destroy",
2274 G_CALLBACK(old_mini_dialog_destroy_cb
), cb_datas
);
2277 #define INIT_AND_RETURN_MINI_DIALOG(mini_dialog) \
2279 va_start(args, user_data); \
2280 mini_dialog_init(mini_dialog, gc, user_data, args); \
2282 return GTK_WIDGET(mini_dialog);
2285 pidgin_make_mini_dialog(PurpleConnection
*gc
,
2286 const char *icon_name
,
2287 const char *primary
,
2288 const char *secondary
,
2292 PidginMiniDialog
*mini_dialog
= pidgin_mini_dialog_new(primary
, secondary
, icon_name
);
2293 INIT_AND_RETURN_MINI_DIALOG(mini_dialog
);
2297 pidgin_make_mini_dialog_with_custom_icon(PurpleConnection
*gc
,
2298 GdkPixbuf
*custom_icon
,
2299 const char *primary
,
2300 const char *secondary
,
2304 PidginMiniDialog
*mini_dialog
= pidgin_mini_dialog_new_with_custom_icon(primary
, secondary
, custom_icon
);
2305 INIT_AND_RETURN_MINI_DIALOG(mini_dialog
);
2309 * "This is so dead sexy."
2311 * "Best movie of the year."
2313 * This is the function that handles CTRL+F searching in the buddy list.
2314 * It finds the top-most buddy/group/chat/whatever containing the
2317 * It's somewhat ineffecient, because we strip all the HTML from the
2318 * "name" column of the buddy list (because the GtkTreeModel does not
2319 * contain the screen name in a non-markedup format). But the alternative
2320 * is to add an extra column to the GtkTreeModel. And this function is
2321 * used rarely, so it shouldn't matter TOO much.
2323 gboolean
pidgin_tree_view_search_equal_func(GtkTreeModel
*model
, gint column
,
2324 const gchar
*key
, GtkTreeIter
*iter
, gpointer data
)
2326 gchar
*enteredstring
;
2334 PangoLogAttr
*log_attrs
;
2337 if (g_ascii_strcasecmp(key
, "Global Thermonuclear War") == 0)
2339 purple_notify_info(NULL
, "WOPR", "Wouldn't you prefer a nice "
2340 "game of chess?", NULL
, NULL
);
2344 gtk_tree_model_get(model
, iter
, column
, &withmarkup
, -1);
2345 if (withmarkup
== NULL
) /* This is probably a separator */
2348 tmp
= g_utf8_normalize(key
, -1, G_NORMALIZE_DEFAULT
);
2349 enteredstring
= g_utf8_casefold(tmp
, -1);
2352 nomarkup
= purple_markup_strip_html(withmarkup
);
2353 tmp
= g_utf8_normalize(nomarkup
, -1, G_NORMALIZE_DEFAULT
);
2355 normalized
= g_utf8_casefold(tmp
, -1);
2358 if (purple_str_has_prefix(normalized
, enteredstring
))
2361 g_free(enteredstring
);
2367 /* Use Pango to separate by words. */
2368 len
= g_utf8_strlen(normalized
, -1);
2369 log_attrs
= g_new(PangoLogAttr
, len
+ 1);
2371 pango_get_log_attrs(normalized
, strlen(normalized
), -1, NULL
, log_attrs
, len
+ 1);
2375 for (i
= 0; i
< (len
- 1) ; i
++)
2377 if (log_attrs
[i
].is_word_start
&&
2378 purple_str_has_prefix(word
, enteredstring
))
2383 word
= g_utf8_next_char(word
);
2387 /* The non-Pango version. */
2391 while (word
[0] != '\0')
2393 gunichar c
= g_utf8_get_char(word
);
2394 if (!g_unichar_isalnum(c
))
2396 word
= g_utf8_find_next_char(word
, NULL
);
2397 if (purple_str_has_prefix(word
, enteredstring
))
2404 word
= g_utf8_find_next_char(word
, NULL
);
2409 g_free(enteredstring
);
2415 const char *pidgin_get_dim_grey_string(GtkWidget
*widget
) {
2416 static char dim_grey_string
[8] = "";
2417 GtkStyleContext
*context
;
2423 context
= gtk_widget_get_style_context(widget
);
2427 gtk_style_context_get_color(context
, gtk_style_context_get_state(context
),
2429 gtk_style_context_get_background_color(context
,
2430 gtk_style_context_get_state(context
),
2432 snprintf(dim_grey_string
, sizeof(dim_grey_string
), "#%02x%02x%02x",
2433 (unsigned int)((fg
.red
+ bg
.red
) * 0.5 * 255),
2434 (unsigned int)((fg
.green
+ bg
.green
) * 0.5 * 255),
2435 (unsigned int)((fg
.blue
+ bg
.blue
) * 0.5 * 255));
2436 return dim_grey_string
;
2440 combo_box_changed_cb(GtkComboBoxText
*combo_box
, GtkEntry
*entry
)
2442 char *text
= gtk_combo_box_text_get_active_text(combo_box
);
2443 gtk_entry_set_text(entry
, text
? text
: "");
2448 entry_key_pressed_cb(GtkWidget
*entry
, GdkEventKey
*key
, GtkComboBoxText
*combo
)
2450 if (key
->keyval
== GDK_KEY_Down
|| key
->keyval
== GDK_KEY_Up
) {
2451 gtk_combo_box_popup(GTK_COMBO_BOX(combo
));
2458 pidgin_text_combo_box_entry_new(const char *default_item
, GList
*items
)
2460 GtkComboBoxText
*ret
= NULL
;
2461 GtkWidget
*the_entry
= NULL
;
2463 ret
= GTK_COMBO_BOX_TEXT(gtk_combo_box_text_new_with_entry());
2464 the_entry
= gtk_bin_get_child(GTK_BIN(ret
));
2467 gtk_entry_set_text(GTK_ENTRY(the_entry
), default_item
);
2469 for (; items
!= NULL
; items
= items
->next
) {
2470 char *text
= items
->data
;
2472 gtk_combo_box_text_append_text(ret
, text
);
2475 g_signal_connect(G_OBJECT(ret
), "changed", (GCallback
)combo_box_changed_cb
, the_entry
);
2476 g_signal_connect_after(G_OBJECT(the_entry
), "key-press-event", G_CALLBACK(entry_key_pressed_cb
), ret
);
2478 return GTK_WIDGET(ret
);
2481 const char *pidgin_text_combo_box_entry_get_text(GtkWidget
*widget
)
2483 return gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((widget
)))));
2486 void pidgin_text_combo_box_entry_set_text(GtkWidget
*widget
, const char *text
)
2488 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((widget
)))), (text
));
2492 pidgin_add_widget_to_vbox(GtkBox
*vbox
, const char *widget_label
, GtkSizeGroup
*sg
, GtkWidget
*widget
, gboolean expand
, GtkWidget
**p_label
)
2495 GtkWidget
*label
= NULL
;
2498 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 5);
2499 gtk_widget_show(hbox
);
2500 gtk_box_pack_start(vbox
, hbox
, FALSE
, FALSE
, 0);
2502 label
= gtk_label_new_with_mnemonic(widget_label
);
2503 gtk_widget_show(label
);
2505 gtk_label_set_xalign(GTK_LABEL(label
), 0);
2506 gtk_size_group_add_widget(sg
, label
);
2508 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
2510 hbox
= GTK_WIDGET(vbox
);
2513 gtk_widget_show(widget
);
2514 gtk_box_pack_start(GTK_BOX(hbox
), widget
, expand
, TRUE
, 0);
2516 gtk_label_set_mnemonic_widget(GTK_LABEL(label
), widget
);
2517 pidgin_set_accessible_label(widget
, GTK_LABEL(label
));
2525 gboolean
pidgin_auto_parent_window(GtkWidget
*widget
)
2528 /* This looks at the most recent window that received focus, and makes
2529 * that the parent window. */
2531 static GdkAtom _WindowTime
= GDK_NONE
;
2532 static GdkAtom _Cardinal
= GDK_NONE
;
2533 GList
*windows
= NULL
;
2534 GtkWidget
*parent
= NULL
;
2535 time_t window_time
= 0;
2537 windows
= gtk_window_list_toplevels();
2539 if (_WindowTime
== GDK_NONE
) {
2540 _WindowTime
= gdk_x11_xatom_to_atom(gdk_x11_get_xatom_by_name("_NET_WM_USER_TIME"));
2542 if (_Cardinal
== GDK_NONE
) {
2543 _Cardinal
= gdk_atom_intern("CARDINAL", FALSE
);
2547 GtkWidget
*window
= windows
->data
;
2548 guchar
*data
= NULL
;
2552 windows
= g_list_delete_link(windows
, windows
);
2554 if (window
== widget
||
2555 !gtk_widget_get_visible(window
))
2558 if (!gdk_property_get(window
->window
, _WindowTime
, _Cardinal
, 0, sizeof(time_t), FALSE
,
2559 NULL
, NULL
, &al
, &data
))
2561 value
= *(time_t *)data
;
2562 if (window_time
< value
) {
2563 window_time
= value
;
2569 g_list_free(windows
);
2571 if (!gtk_get_current_event() && gtk_window_has_toplevel_focus(GTK_WINDOW(parent
))) {
2572 /* The window is in focus, and the new window was not triggered by a keypress/click
2573 * event. So do not set it transient, to avoid focus stealing and all that.
2577 gtk_window_set_transient_for(GTK_WINDOW(widget
), GTK_WINDOW(parent
));
2583 /* This finds the currently active window and makes that the parent window. */
2584 GList
*windows
= NULL
;
2585 GtkWindow
*parent
= NULL
;
2586 GdkEvent
*event
= gtk_get_current_event();
2587 GdkWindow
*menu
= NULL
;
2588 gpointer parent_from
;
2589 PurpleNotifyType notify_type
;
2591 parent_from
= g_object_get_data(G_OBJECT(widget
), "pidgin-parent-from");
2592 if (purple_request_is_valid_ui_handle(parent_from
, NULL
)) {
2594 gtk_window_set_transient_for(GTK_WINDOW(widget
),
2595 gtk_window_get_transient_for(
2596 pidgin_request_get_dialog_window(parent_from
)));
2599 if (purple_notify_is_valid_ui_handle(parent_from
, ¬ify_type
) &&
2600 notify_type
== PURPLE_NOTIFY_MESSAGE
)
2602 gtk_window_set_transient_for(GTK_WINDOW(widget
),
2603 gtk_window_get_transient_for(GTK_WINDOW(parent_from
)));
2608 /* The window was not triggered by a user action. */
2611 /* We need to special case events from a popup menu. */
2612 if (event
->type
== GDK_BUTTON_RELEASE
) {
2613 /* XXX: Neither of the following works:
2614 menu = event->button.window;
2615 menu = gdk_window_get_parent(event->button.window);
2616 menu = gdk_window_get_toplevel(event->button.window);
2618 } else if (event
->type
== GDK_KEY_PRESS
)
2619 menu
= event
->key
.window
;
2621 windows
= gtk_window_list_toplevels();
2623 GtkWindow
*window
= GTK_WINDOW(windows
->data
);
2624 windows
= g_list_delete_link(windows
, windows
);
2626 if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window
),
2627 "pidgin-window-is-closing")))
2629 parent
= gtk_window_get_transient_for(window
);
2633 if (GTK_WIDGET(window
) == widget
||
2634 !gtk_widget_get_visible(GTK_WIDGET(window
))) {
2638 if (gtk_window_has_toplevel_focus(window
) ||
2639 (menu
&& menu
== gtk_widget_get_window(GTK_WIDGET(window
)))) {
2645 g_list_free(windows
);
2647 gtk_window_set_transient_for(GTK_WINDOW(widget
), parent
);
2654 static GObject
*pidgin_pixbuf_from_data_helper(const guchar
*buf
, gsize count
, gboolean animated
)
2657 GdkPixbufLoader
*loader
;
2658 GError
*error
= NULL
;
2660 loader
= gdk_pixbuf_loader_new();
2662 if (!gdk_pixbuf_loader_write(loader
, buf
, count
, &error
) || error
) {
2663 purple_debug_warning("gtkutils", "gdk_pixbuf_loader_write() "
2664 "failed with size=%" G_GSIZE_FORMAT
": %s\n", count
,
2665 error
? error
->message
: "(no error message)");
2667 g_error_free(error
);
2668 g_object_unref(G_OBJECT(loader
));
2672 if (!gdk_pixbuf_loader_close(loader
, &error
) || error
) {
2673 purple_debug_warning("gtkutils", "gdk_pixbuf_loader_close() "
2674 "failed for image of size %" G_GSIZE_FORMAT
": %s\n", count
,
2675 error
? error
->message
: "(no error message)");
2677 g_error_free(error
);
2678 g_object_unref(G_OBJECT(loader
));
2683 pixbuf
= G_OBJECT(gdk_pixbuf_loader_get_animation(loader
));
2685 pixbuf
= G_OBJECT(gdk_pixbuf_loader_get_pixbuf(loader
));
2687 purple_debug_warning("gtkutils", "%s() returned NULL for image "
2688 "of size %" G_GSIZE_FORMAT
"\n",
2689 animated
? "gdk_pixbuf_loader_get_animation"
2690 : "gdk_pixbuf_loader_get_pixbuf", count
);
2691 g_object_unref(G_OBJECT(loader
));
2695 g_object_ref(pixbuf
);
2696 g_object_unref(G_OBJECT(loader
));
2701 GdkPixbuf
*pidgin_pixbuf_from_data(const guchar
*buf
, gsize count
)
2703 return GDK_PIXBUF(pidgin_pixbuf_from_data_helper(buf
, count
, FALSE
));
2706 GdkPixbufAnimation
*pidgin_pixbuf_anim_from_data(const guchar
*buf
, gsize count
)
2708 return GDK_PIXBUF_ANIMATION(pidgin_pixbuf_from_data_helper(buf
, count
, TRUE
));
2712 pidgin_pixbuf_from_image(PurpleImage
*image
)
2714 return pidgin_pixbuf_from_data(purple_image_get_data(image
),
2715 purple_image_get_data_size(image
));
2718 GdkPixbuf
*pidgin_pixbuf_new_from_file(const gchar
*filename
)
2721 GError
*error
= NULL
;
2723 g_return_val_if_fail(filename
!= NULL
, NULL
);
2724 g_return_val_if_fail(filename
[0] != '\0', NULL
);
2726 pixbuf
= gdk_pixbuf_new_from_file(filename
, &error
);
2727 if (!pixbuf
|| error
) {
2728 purple_debug_warning("gtkutils", "gdk_pixbuf_new_from_file() "
2729 "returned %s for file %s: %s\n",
2730 pixbuf
? "something" : "nothing",
2732 error
? error
->message
: "(no error message)");
2734 g_error_free(error
);
2736 g_object_unref(G_OBJECT(pixbuf
));
2743 GdkPixbuf
*pidgin_pixbuf_new_from_file_at_size(const char *filename
, int width
, int height
)
2746 GError
*error
= NULL
;
2748 g_return_val_if_fail(filename
!= NULL
, NULL
);
2749 g_return_val_if_fail(filename
[0] != '\0', NULL
);
2751 pixbuf
= gdk_pixbuf_new_from_file_at_size(filename
,
2752 width
, height
, &error
);
2753 if (!pixbuf
|| error
) {
2754 purple_debug_warning("gtkutils", "gdk_pixbuf_new_from_file_at_size() "
2755 "returned %s for file %s: %s\n",
2756 pixbuf
? "something" : "nothing",
2758 error
? error
->message
: "(no error message)");
2760 g_error_free(error
);
2762 g_object_unref(G_OBJECT(pixbuf
));
2769 GdkPixbuf
*pidgin_pixbuf_new_from_file_at_scale(const char *filename
, int width
, int height
, gboolean preserve_aspect_ratio
)
2772 GError
*error
= NULL
;
2774 g_return_val_if_fail(filename
!= NULL
, NULL
);
2775 g_return_val_if_fail(filename
[0] != '\0', NULL
);
2777 pixbuf
= gdk_pixbuf_new_from_file_at_scale(filename
,
2778 width
, height
, preserve_aspect_ratio
, &error
);
2779 if (!pixbuf
|| error
) {
2780 purple_debug_warning("gtkutils", "gdk_pixbuf_new_from_file_at_scale() "
2781 "returned %s for file %s: %s\n",
2782 pixbuf
? "something" : "nothing",
2784 error
? error
->message
: "(no error message)");
2786 g_error_free(error
);
2788 g_object_unref(G_OBJECT(pixbuf
));
2796 pidgin_pixbuf_scale_down(GdkPixbuf
*src
, guint max_width
, guint max_height
,
2797 GdkInterpType interp_type
, gboolean preserve_ratio
)
2802 g_return_val_if_fail(src
!= NULL
, NULL
);
2804 if (max_width
== 0 || max_height
== 0) {
2805 g_object_unref(src
);
2806 g_return_val_if_reached(NULL
);
2809 cur_w
= gdk_pixbuf_get_width(src
);
2810 cur_h
= gdk_pixbuf_get_height(src
);
2812 if (cur_w
<= max_width
&& cur_h
<= max_height
)
2815 /* cur_ratio = cur_w / cur_h
2816 * max_ratio = max_w / max_h
2819 if (!preserve_ratio
) {
2820 cur_w
= MIN(cur_w
, max_width
);
2821 cur_h
= MIN(cur_h
, max_height
);
2822 } else if ((guint64
)cur_w
* max_height
> (guint64
)max_width
* cur_h
) {
2823 /* cur_w / cur_h > max_width / max_height */
2824 cur_h
= (guint64
)max_width
* cur_h
/ cur_w
;
2827 cur_w
= (guint64
)max_height
* cur_w
/ cur_h
;
2836 dst
= gdk_pixbuf_scale_simple(src
, cur_w
, cur_h
, interp_type
);
2837 g_object_unref(src
);
2843 pidgin_make_scrollable(GtkWidget
*child
, GtkPolicyType hscrollbar_policy
, GtkPolicyType vscrollbar_policy
, GtkShadowType shadow_type
, int width
, int height
)
2845 GtkWidget
*sw
= gtk_scrolled_window_new(NULL
, NULL
);
2848 gtk_widget_show(sw
);
2849 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw
), hscrollbar_policy
, vscrollbar_policy
);
2850 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw
), shadow_type
);
2851 if (width
!= -1 || height
!= -1)
2852 gtk_widget_set_size_request(sw
, width
, height
);
2854 gtk_container_add(GTK_CONTAINER(sw
), child
);