| 646 |
645 |
| 647 static gboolean |
646 static gboolean |
| 648 close_smiley_dialog(GtkWebViewToolbar *toolbar) |
647 close_smiley_dialog(GtkWebViewToolbar *toolbar) |
| 649 { |
648 { |
| 650 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
649 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
| 651 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->smiley), FALSE); |
650 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(priv->smiley), FALSE); |
| 652 return FALSE; |
651 return FALSE; |
| 653 } |
652 } |
| 654 |
653 |
| 655 |
|
| 656 static void |
654 static void |
| 657 insert_smiley_text(GtkWidget *widget, GtkWebViewToolbar *toolbar) |
655 insert_smiley_text(GtkWidget *widget, GtkWebViewToolbar *toolbar) |
| 658 { |
656 { |
| 659 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
|
| 660 char *smiley_text, *escaped_smiley; |
657 char *smiley_text, *escaped_smiley; |
| 661 |
658 |
| 662 smiley_text = g_object_get_data(G_OBJECT(widget), "smiley_text"); |
659 smiley_text = g_object_get_data(G_OBJECT(widget), "smiley_text"); |
| 663 escaped_smiley = g_markup_escape_text(smiley_text, -1); |
660 escaped_smiley = g_markup_escape_text(smiley_text, -1); |
| 664 |
661 |
| 665 gtk_webview_insert_smiley(GTK_WEBVIEW(toolbar->webview), |
662 gtk_webview_insert_smiley(GTK_WEBVIEW(toolbar->webview), |
| 666 GTK_WEBVIEW(toolbar->webview)->protocol_name, |
663 gtk_webview_get_protocol_name(GTK_WEBVIEW(toolbar->webview)), |
| 667 escaped_smiley); |
664 escaped_smiley); |
| 668 |
665 |
| 669 g_free(escaped_smiley); |
666 g_free(escaped_smiley); |
| 670 |
667 |
| 671 close_smiley_dialog(toolbar); |
668 close_smiley_dialog(toolbar); |
| 672 } |
669 } |
| 673 |
670 |
| 674 /* smiley buttons list */ |
671 /* smiley buttons list */ |
| 675 struct smiley_button_list { |
672 struct smiley_button_list { |
| 676 int width, height; |
673 int width, height; |
| 677 GtkWidget *button; |
674 GtkWidget *button; |
| 678 const GtkIMHtmlSmiley *smiley; |
675 const GtkWebViewSmiley *smiley; |
| 679 struct smiley_button_list *next; |
676 struct smiley_button_list *next; |
| 680 }; |
677 }; |
| 681 |
678 |
| 682 static struct smiley_button_list * |
679 static struct smiley_button_list * |
| 683 sort_smileys(struct smiley_button_list *ls, GtkWebViewToolbar *toolbar, |
680 sort_smileys(struct smiley_button_list *ls, GtkWebViewToolbar *toolbar, |
| 684 int *width, const GtkIMHtmlSmiley *smiley) |
681 int *width, const GtkWebViewSmiley *smiley) |
| 685 { |
682 { |
| 686 GtkWebViewToolbarPriv *priv = GTK_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar); |
|
| 687 GtkWidget *image; |
683 GtkWidget *image; |
| 688 GtkWidget *button; |
684 GtkWidget *button; |
| 689 GtkRequisition size; |
685 GtkRequisition size; |
| 690 struct smiley_button_list *cur; |
686 struct smiley_button_list *cur; |
| 691 struct smiley_button_list *it, *it_last; |
687 struct smiley_button_list *it, *it_last; |
| 692 const gchar *filename = smiley->file; |
688 const gchar *filename = gtk_webview_smiley_get_file(smiley); |
| 693 gchar *face = smiley->smile; |
689 const gchar *face = gtk_webview_smiley_get_smile(smiley); |
| 694 PurpleSmiley *psmiley = NULL; |
690 PurpleSmiley *psmiley = NULL; |
| 695 gboolean supports_custom = (gtk_webview_get_format_functions(GTK_WEBVIEW(toolbar->webview)) & GTK_WEBVIEW_CUSTOM_SMILEY); |
691 gboolean supports_custom = (gtk_webview_get_format_functions(GTK_WEBVIEW(toolbar->webview)) & GTK_WEBVIEW_CUSTOM_SMILEY); |
| 696 |
692 |
| 697 cur = g_new0(struct smiley_button_list, 1); |
693 cur = g_new0(struct smiley_button_list, 1); |
| 698 it = ls; |
694 it = ls; |
| 699 it_last = ls; /* list iterators*/ |
695 it_last = ls; /* list iterators */ |
| 700 image = gtk_image_new_from_file(filename); |
696 image = gtk_image_new_from_file(filename); |
| 701 |
697 |
| 702 gtk_widget_size_request(image, &size); |
698 gtk_widget_size_request(image, &size); |
| 703 |
699 |
| 704 if (size.width > 24 && |
700 if ((size.width > 24) |
| 705 smiley->flags & GTK_WEBVIEW_SMILEY_CUSTOM) { /* This is a custom smiley, let's scale it */ |
701 && (gtk_webview_smiley_get_flags(smiley) & GTK_WEBVIEW_SMILEY_CUSTOM)) { |
| |
702 /* This is a custom smiley, let's scale it */ |
| 706 GdkPixbuf *pixbuf = NULL; |
703 GdkPixbuf *pixbuf = NULL; |
| 707 GtkImageType type; |
704 GtkImageType type; |
| 708 |
705 |
| 709 type = gtk_image_get_storage_type(GTK_IMAGE(image)); |
706 type = gtk_image_get_storage_type(GTK_IMAGE(image)); |
| 710 |
707 |
| 732 (*width) += size.width; |
729 (*width) += size.width; |
| 733 |
730 |
| 734 button = gtk_button_new(); |
731 button = gtk_button_new(); |
| 735 gtk_container_add(GTK_CONTAINER(button), image); |
732 gtk_container_add(GTK_CONTAINER(button), image); |
| 736 |
733 |
| 737 g_object_set_data(G_OBJECT(button), "smiley_text", face); |
734 g_object_set_data_full(G_OBJECT(button), "smiley_text", g_strdup(face), g_free); |
| 738 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(insert_smiley_text), toolbar); |
735 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(insert_smiley_text), toolbar); |
| 739 |
736 |
| 740 gtk_widget_set_tooltip_text(button, face); |
737 gtk_widget_set_tooltip_text(button, face); |
| 741 |
738 |
| 742 /* these look really weird with borders */ |
739 /* these look really weird with borders */ |
| 743 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); |
740 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); |
| 744 |
741 |
| 745 psmiley = purple_smileys_find_by_shortcut(smiley->smile); |
742 psmiley = purple_smileys_find_by_shortcut(face); |
| 746 /* If this is a "non-custom" smiley, check to see if its shortcut is |
743 /* If this is a "non-custom" smiley, check to see if its shortcut is |
| 747 "shadowed" by any custom smiley. This can only happen if the connection |
744 "shadowed" by any custom smiley. This can only happen if the connection |
| 748 is custom smiley-enabled */ |
745 is custom smiley-enabled */ |
| 749 if (supports_custom && psmiley && !(smiley->flags & GTK_WEBVIEW_SMILEY_CUSTOM)) { |
746 if (supports_custom && psmiley |
| |
747 && !(gtk_webview_smiley_get_flags(smiley) & GTK_WEBVIEW_SMILEY_CUSTOM)) { |
| 750 gchar tip[128]; |
748 gchar tip[128]; |
| 751 g_snprintf(tip, sizeof(tip), |
749 g_snprintf(tip, sizeof(tip), |
| 752 _("This smiley is disabled because a custom smiley exists for this shortcut:\n %s"), |
750 _("This smiley is disabled because a custom smiley exists for this shortcut:\n %s"), |
| 753 face); |
751 face); |
| 754 gtk_widget_set_tooltip_text(button, tip); |
752 gtk_widget_set_tooltip_text(button, tip); |
| 816 return; |
814 return; |
| 817 |
815 |
| 818 line = gtk_hbox_new(FALSE, 0); |
816 line = gtk_hbox_new(FALSE, 0); |
| 819 gtk_box_pack_start(GTK_BOX(container), line, FALSE, FALSE, 0); |
817 gtk_box_pack_start(GTK_BOX(container), line, FALSE, FALSE, 0); |
| 820 for (; list; list = list->next) { |
818 for (; list; list = list->next) { |
| 821 if (custom != !!(list->smiley->flags & GTK_WEBVIEW_SMILEY_CUSTOM)) |
819 if (custom != !!(gtk_webview_smiley_get_flags(list->smiley) & GTK_WEBVIEW_SMILEY_CUSTOM)) |
| 822 continue; |
820 continue; |
| 823 gtk_box_pack_start(GTK_BOX(line), list->button, FALSE, FALSE, 0); |
821 gtk_box_pack_start(GTK_BOX(line), list->button, FALSE, FALSE, 0); |
| 824 gtk_widget_show(list->button); |
822 gtk_widget_show(list->button); |
| 825 line_width += list->width; |
823 line_width += list->width; |
| 826 if (line_width >= max_width) { |
824 if (line_width >= max_width) { |
| 856 if (priv->sml) |
852 if (priv->sml) |
| 857 smileys = pidgin_themes_get_proto_smileys(priv->sml); |
853 smileys = pidgin_themes_get_proto_smileys(priv->sml); |
| 858 else |
854 else |
| 859 smileys = pidgin_themes_get_proto_smileys(NULL); |
855 smileys = pidgin_themes_get_proto_smileys(NULL); |
| 860 |
856 |
| 861 /* Note: prepend smileys to list to avoid O(n^2) overhead when there is |
857 /* Note: prepend smileys to list to avoid O(n^2) overhead when there is a |
| 862 a large number of smileys... need to revers the list after for the dialog |
858 large number of smileys... need to reverse the list after for the dialog |
| 863 work... */ |
859 to work... */ |
| 864 while(smileys) { |
860 while (smileys) { |
| 865 GtkIMHtmlSmiley *smiley = (GtkIMHtmlSmiley *) smileys->data; |
861 GtkWebViewSmiley *smiley = (GtkWebViewSmiley *)smileys->data; |
| 866 if(!smiley->hidden) { |
862 if (!gtk_webview_smiley_get_hidden(smiley)) { |
| 867 if(smiley_is_unique(unique_smileys, smiley)) { |
863 if (smiley_is_unique(unique_smileys, smiley)) { |
| 868 unique_smileys = g_slist_prepend(unique_smileys, smiley); |
864 unique_smileys = g_slist_prepend(unique_smileys, smiley); |
| 869 } |
865 } |
| 870 } |
866 } |
| 871 smileys = smileys->next; |
867 smileys = smileys->next; |
| 872 } |
868 } |
| 911 button_width = req.width; |
907 button_width = req.width; |
| 912 } |
908 } |
| 913 |
909 |
| 914 /* create list of smileys sorted by height */ |
910 /* create list of smileys sorted by height */ |
| 915 while (unique_smileys) { |
911 while (unique_smileys) { |
| 916 GtkIMHtmlSmiley *smiley = (GtkIMHtmlSmiley *) unique_smileys->data; |
912 GtkWebViewSmiley *smiley = (GtkWebViewSmiley *)unique_smileys->data; |
| 917 if (!smiley->hidden) { |
913 if (!gtk_webview_smiley_get_hidden(smiley)) { |
| 918 ls = sort_smileys(ls, toolbar, &max_line_width, smiley); |
914 ls = sort_smileys(ls, toolbar, &max_line_width, smiley); |
| 919 } |
915 } |
| 920 unique_smileys = g_slist_delete_link(unique_smileys, unique_smileys); |
916 unique_smileys = g_slist_delete_link(unique_smileys, unique_smileys); |
| 921 } |
917 } |
| 922 /* The window will be at least as wide as the 'Manage ..' button */ |
918 /* The window will be at least as wide as the 'Manage ..' button */ |
| 940 smiley_table = gtk_label_new(_("This theme has no available smileys.")); |
936 smiley_table = gtk_label_new(_("This theme has no available smileys.")); |
| 941 gtk_widget_add_events(dialog, GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK); |
937 gtk_widget_add_events(dialog, GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK); |
| 942 g_signal_connect(G_OBJECT(dialog), "button-press-event", (GCallback)smiley_dialog_input_cb, toolbar); |
938 g_signal_connect(G_OBJECT(dialog), "button-press-event", (GCallback)smiley_dialog_input_cb, toolbar); |
| 943 } |
939 } |
| 944 |
940 |
| 945 |
|
| 946 scrolled = pidgin_make_scrollable(smiley_table, GTK_POLICY_NEVER, GTK_POLICY_NEVER, GTK_SHADOW_NONE, -1, -1); |
941 scrolled = pidgin_make_scrollable(smiley_table, GTK_POLICY_NEVER, GTK_POLICY_NEVER, GTK_SHADOW_NONE, -1, -1); |
| 947 gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); |
942 gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); |
| 948 gtk_widget_show(smiley_table); |
943 gtk_widget_show(smiley_table); |
| 949 |
944 |
| 950 viewport = gtk_widget_get_parent(smiley_table); |
945 viewport = gtk_widget_get_parent(smiley_table); |
| 1345 {&priv->bgcolor, "ToggleBG", PIDGIN_STOCK_TOOLBAR_BGCOLOR, N_("Bac_kground color"), N_("Background Color"), toggle_bg_color, TRUE}, |
1339 {&priv->bgcolor, "ToggleBG", PIDGIN_STOCK_TOOLBAR_BGCOLOR, N_("Bac_kground color"), N_("Background Color"), toggle_bg_color, TRUE}, |
| 1346 {&priv->clear, "ResetFormat", PIDGIN_STOCK_CLEAR, N_("_Reset formatting"), N_("Reset Formatting"), clear_formatting_cb, FALSE}, |
1340 {&priv->clear, "ResetFormat", PIDGIN_STOCK_CLEAR, N_("_Reset formatting"), N_("Reset Formatting"), clear_formatting_cb, FALSE}, |
| 1347 {&priv->image, "InsertImage", PIDGIN_STOCK_TOOLBAR_INSERT_IMAGE, N_("_Image"), N_("Insert IM Image"), insert_image_cb, FALSE}, |
1341 {&priv->image, "InsertImage", PIDGIN_STOCK_TOOLBAR_INSERT_IMAGE, N_("_Image"), N_("Insert IM Image"), insert_image_cb, FALSE}, |
| 1348 {&priv->link, "InsertLink", PIDGIN_STOCK_TOOLBAR_INSERT_LINK, N_("_Link"), N_("Insert Link"), insert_link_cb, TRUE}, |
1342 {&priv->link, "InsertLink", PIDGIN_STOCK_TOOLBAR_INSERT_LINK, N_("_Link"), N_("Insert Link"), insert_link_cb, TRUE}, |
| 1349 {&priv->hr, "InsertHR", NULL, N_("_Horizontal rule"), N_("Insert Horizontal rule"), insert_hr_cb, FALSE}, |
1343 {&priv->hr, "InsertHR", NULL, N_("_Horizontal rule"), N_("Insert Horizontal rule"), insert_hr_cb, FALSE}, |
| 1350 {&priv->smiley, "InsertSmiley", PIDGIN_STOCK_TOOLBAR_SMILEY, N_("_Smile!"), N_("Insert Smiley"), insert_smiley_cb, FALSE}, |
1344 {&priv->smiley, "InsertSmiley", PIDGIN_STOCK_TOOLBAR_SMILEY, N_("_Smile!"), N_("Insert Smiley"), insert_smiley_cb, TRUE}, |
| 1351 {&priv->attention, "SendAttention", PIDGIN_STOCK_TOOLBAR_SEND_ATTENTION, N_("_Attention!"), N_("Send Attention"), send_attention_cb, FALSE}, |
1345 {&priv->attention, "SendAttention", PIDGIN_STOCK_TOOLBAR_SEND_ATTENTION, N_("_Attention!"), N_("Send Attention"), send_attention_cb, FALSE}, |
| 1352 }; |
1346 }; |
| 1353 |
1347 |
| 1354 action_group = gtk_action_group_new("GtkWebViewToolbar"); |
1348 action_group = gtk_action_group_new("GtkWebViewToolbar"); |
| 1355 #ifdef ENABLE_NLS |
1349 #ifdef ENABLE_NLS |