pidgin/gtknotify.c

changeset 17728
323b1481c2bc
parent 17027
cad1dc392f1a
child 18178
d461ccafa1fb
equal deleted inserted replaced
17726:106ce8d3fa09 17728:323b1481c2bc
35 35
36 #include "gtkblist.h" 36 #include "gtkblist.h"
37 #include "gtkimhtml.h" 37 #include "gtkimhtml.h"
38 #include "gtknotify.h" 38 #include "gtknotify.h"
39 #include "gtkutils.h" 39 #include "gtkutils.h"
40
41 typedef struct
42 {
43 GtkWidget *window;
44 int count;
45 } PidginUserInfo;
40 46
41 typedef struct 47 typedef struct
42 { 48 {
43 PurpleAccount *account; 49 PurpleAccount *account;
44 char *url; 50 char *url;
622 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); 628 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
623 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); 629 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
624 gtk_widget_show(button); 630 gtk_widget_show(button);
625 631
626 g_signal_connect_swapped(G_OBJECT(button), "clicked", 632 g_signal_connect_swapped(G_OBJECT(button), "clicked",
627 G_CALLBACK(formatted_close_cb), window); 633 G_CALLBACK(gtk_widget_destroy), window);
628 g_signal_connect(G_OBJECT(window), "key_press_event", 634 g_signal_connect(G_OBJECT(window), "key_press_event",
629 G_CALLBACK(formatted_input_cb), NULL); 635 G_CALLBACK(formatted_input_cb), NULL);
630 636
631 /* Make sure URLs are clickable */ 637 /* Make sure URLs are clickable */
632 linked_text = purple_markup_linkify(text); 638 linked_text = purple_markup_linkify(text);
876 } 882 }
877 883
878 static void 884 static void
879 remove_userinfo(GtkWidget *widget, gpointer key) 885 remove_userinfo(GtkWidget *widget, gpointer key)
880 { 886 {
887 PidginUserInfo *pinfo = g_hash_table_lookup(userinfo, key);
888
889 while (pinfo->count--)
890 purple_notify_close(PURPLE_NOTIFY_USERINFO, widget);
891
881 g_hash_table_remove(userinfo, key); 892 g_hash_table_remove(userinfo, key);
882 } 893 }
883 894
884 static void * 895 static void *
885 pidgin_notify_userinfo(PurpleConnection *gc, const char *who, 896 pidgin_notify_userinfo(PurpleConnection *gc, const char *who,
886 PurpleNotifyUserInfo *user_info) 897 PurpleNotifyUserInfo *user_info)
887 { 898 {
888 char *info; 899 char *info;
889 void *ui_handle; 900 void *ui_handle;
890 char *key = userinfo_hash(purple_connection_get_account(gc), who); 901 char *key = userinfo_hash(purple_connection_get_account(gc), who);
902 PidginUserInfo *pinfo = NULL;
891 903
892 if (!userinfo) { 904 if (!userinfo) {
893 userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); 905 userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
894 } 906 }
895 907
896 info = purple_notify_user_info_get_text_with_newline(user_info, "<br />"); 908 info = purple_notify_user_info_get_text_with_newline(user_info, "<br />");
897 ui_handle = g_hash_table_lookup(userinfo, key); 909 pinfo = g_hash_table_lookup(userinfo, key);
898 if (ui_handle != NULL) { 910 if (pinfo != NULL) {
899 GtkIMHtml *imhtml = g_object_get_data(G_OBJECT(ui_handle), "info-widget"); 911 GtkIMHtml *imhtml = g_object_get_data(G_OBJECT(pinfo->window), "info-widget");
900 char *linked_text = purple_markup_linkify(info); 912 char *linked_text = purple_markup_linkify(info);
901 gtk_imhtml_clear(imhtml); 913 gtk_imhtml_clear(imhtml);
902 gtk_imhtml_append_text(imhtml, linked_text, notify_imhtml_options()); 914 gtk_imhtml_append_text(imhtml, linked_text, notify_imhtml_options());
903 g_free(linked_text); 915 g_free(linked_text);
904 g_free(key); 916 g_free(key);
917 ui_handle = pinfo->window;
918 pinfo->count++;
905 } else { 919 } else {
906 char *primary = g_strdup_printf(_("Info for %s"), who); 920 char *primary = g_strdup_printf(_("Info for %s"), who);
907 ui_handle = pidgin_notify_formatted(_("Buddy Information"), primary, NULL, info); 921 ui_handle = pidgin_notify_formatted(_("Buddy Information"), primary, NULL, info);
908 g_hash_table_insert(userinfo, key, ui_handle); 922 g_signal_handlers_disconnect_by_func(G_OBJECT(ui_handle), G_CALLBACK(formatted_close_cb), NULL);
909 g_signal_connect(G_OBJECT(ui_handle), "destroy", G_CALLBACK(remove_userinfo), key); 923 g_signal_connect(G_OBJECT(ui_handle), "destroy", G_CALLBACK(remove_userinfo), key);
910 g_free(primary); 924 g_free(primary);
925 pinfo = g_new0(PidginUserInfo, 1);
926 pinfo->window = ui_handle;
927 pinfo->count = 1;
928 g_hash_table_insert(userinfo, key, pinfo);
911 } 929 }
912 g_free(info); 930 g_free(info);
913 return ui_handle; 931 return ui_handle;
914 } 932 }
915 933

mercurial