comparison pidgin/gtknotify.c @ 32112:1ca2df744414

propagate from branch 'im.pidgin.pidgin' (head 32c5c2d4cfb2bede5ffb66792760a368ba8b9f0a) to branch 'im.pidgin.soc.2009.webkitmessageview' (head 92ef7ff2d3d0706e73113ff78aded4c9ce5559e4)
author tdrhq@soc.pidgin.im
date Tue, 25 Aug 2009 17:01:49 +0000
parents 9affcab62522 fe75cd926073
children e1cc8d07fe07
comparison
equal deleted inserted replaced
28096:b357216b7b79 32112:1ca2df744414
34 #include "prefs.h" 34 #include "prefs.h"
35 #include "pidginstock.h" 35 #include "pidginstock.h"
36 #include "util.h" 36 #include "util.h"
37 37
38 #include "gtkblist.h" 38 #include "gtkblist.h"
39 #include "gtkimhtml.h"
40 #include "gtknotify.h" 39 #include "gtknotify.h"
41 #include "gtkpounce.h" 40 #include "gtkpounce.h"
42 #include "gtkutils.h" 41 #include "gtkutils.h"
42 #include "gtkwebview.h"
43 43
44 typedef struct 44 typedef struct
45 { 45 {
46 GtkWidget *window; 46 GtkWidget *window;
47 int count; 47 int count;
813 } 813 }
814 814
815 return FALSE; 815 return FALSE;
816 } 816 }
817 817
818 static GtkIMHtmlOptions
819 notify_imhtml_options(void)
820 {
821 GtkIMHtmlOptions options = 0;
822
823 if (!purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/show_incoming_formatting"))
824 options |= GTK_IMHTML_NO_COLOURS | GTK_IMHTML_NO_FONTS | GTK_IMHTML_NO_SIZES;
825
826 options |= GTK_IMHTML_NO_COMMENTS;
827 options |= GTK_IMHTML_NO_TITLE;
828 options |= GTK_IMHTML_NO_NEWLINE;
829 options |= GTK_IMHTML_NO_SCROLL;
830 return options;
831 }
832
833 static void * 818 static void *
834 pidgin_notify_formatted(const char *title, const char *primary, 819 pidgin_notify_formatted(const char *title, const char *primary,
835 const char *secondary, const char *text) 820 const char *secondary, const char *text)
836 { 821 {
837 GtkWidget *window; 822 GtkWidget *window;
838 GtkWidget *vbox; 823 GtkWidget *vbox;
839 GtkWidget *label; 824 GtkWidget *label;
840 GtkWidget *button; 825 GtkWidget *button;
841 GtkWidget *imhtml; 826 GtkWidget *web_view;
842 GtkWidget *frame; 827 GtkWidget *scrolled_window;
843 char label_text[2048]; 828 char label_text[2048];
844 char *linked_text, *primary_esc, *secondary_esc; 829 char *linked_text, *primary_esc, *secondary_esc;
845 830
846 window = gtk_dialog_new(); 831 window = gtk_dialog_new();
847 gtk_window_set_title(GTK_WINDOW(window), title); 832 gtk_window_set_title(GTK_WINDOW(window), title);
872 gtk_label_set_selectable(GTK_LABEL(label), TRUE); 857 gtk_label_set_selectable(GTK_LABEL(label), TRUE);
873 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); 858 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
874 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); 859 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
875 gtk_widget_show(label); 860 gtk_widget_show(label);
876 861
877 /* Add the imhtml */ 862 /* Add the webview */
878 frame = pidgin_create_imhtml(FALSE, &imhtml, NULL, NULL); 863 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
879 gtk_widget_set_name(imhtml, "pidgin_notify_imhtml"); 864 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN);
880 gtk_imhtml_set_format_functions(GTK_IMHTML(imhtml), 865 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
881 gtk_imhtml_get_format_functions(GTK_IMHTML(imhtml)) | GTK_IMHTML_IMAGE); 866
882 gtk_widget_set_size_request(imhtml, 300, 250); 867 web_view = gtk_webview_new ();
883 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); 868 gtk_container_add (GTK_CONTAINER (scrolled_window), web_view);
884 gtk_widget_show(frame); 869
870 gtk_widget_set_name(web_view, "pidgin_notify_webview");
871 gtk_widget_set_size_request(web_view, 300, 250);
872 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
873 gtk_widget_show_all(scrolled_window);
885 874
886 /* Add the Close button. */ 875 /* Add the Close button. */
887 button = gtk_dialog_add_button(GTK_DIALOG(window), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); 876 button = gtk_dialog_add_button(GTK_DIALOG(window), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
888 gtk_widget_grab_focus(button); 877 gtk_widget_grab_focus(button);
889 878
892 g_signal_connect(G_OBJECT(window), "key_press_event", 881 g_signal_connect(G_OBJECT(window), "key_press_event",
893 G_CALLBACK(formatted_input_cb), NULL); 882 G_CALLBACK(formatted_input_cb), NULL);
894 883
895 /* Make sure URLs are clickable */ 884 /* Make sure URLs are clickable */
896 linked_text = purple_markup_linkify(text); 885 linked_text = purple_markup_linkify(text);
897 gtk_imhtml_append_text(GTK_IMHTML(imhtml), linked_text, notify_imhtml_options()); 886 webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (web_view), linked_text, "");
898 g_free(linked_text); 887 g_free(linked_text);
899 888
900 g_object_set_data(G_OBJECT(window), "info-widget", imhtml); 889 g_object_set_data(G_OBJECT(window), "webview-widget", web_view);
901 890
902 /* Show the window */ 891 /* Show the window */
903 pidgin_auto_parent_window(window); 892 pidgin_auto_parent_window(window);
904 893
905 gtk_widget_show(window); 894 gtk_widget_show(window);
1154 } 1143 }
1155 1144
1156 info = purple_notify_user_info_get_text_with_newline(user_info, "<br />"); 1145 info = purple_notify_user_info_get_text_with_newline(user_info, "<br />");
1157 pinfo = g_hash_table_lookup(userinfo, key); 1146 pinfo = g_hash_table_lookup(userinfo, key);
1158 if (pinfo != NULL) { 1147 if (pinfo != NULL) {
1159 GtkIMHtml *imhtml = g_object_get_data(G_OBJECT(pinfo->window), "info-widget"); 1148 GtkWidget *webview = g_object_get_data(G_OBJECT(pinfo->window), "webview-widget");
1160 char *linked_text = purple_markup_linkify(info); 1149 char *linked_text = purple_markup_linkify(info);
1161 gtk_imhtml_clear(imhtml); 1150 g_assert (webview);
1162 gtk_imhtml_append_text(imhtml, linked_text, notify_imhtml_options()); 1151 printf ("%s\n", linked_text);
1152 gtk_webview_load_html_string_with_imgstore (GTK_WEBVIEW (webview), linked_text);
1163 g_free(linked_text); 1153 g_free(linked_text);
1164 g_free(key); 1154 g_free(key);
1165 ui_handle = pinfo->window; 1155 ui_handle = pinfo->window;
1166 pinfo->count++; 1156 pinfo->count++;
1167 } else { 1157 } else {