Mercurial > pidgin
comparison pidgin/gtknotify.c @ 32819:2c6510167895 default tip
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24)
to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 02 Jun 2012 02:30:49 +0000 |
parents | b8cbd52e26b1 |
children |
comparison
equal
deleted
inserted
replaced
32818:01ff09d4a463 | 32819:2c6510167895 |
---|---|
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; |
532 g_signal_connect(G_OBJECT(dialog), "response", | 532 g_signal_connect(G_OBJECT(dialog), "response", |
533 G_CALLBACK(message_response_cb), dialog); | 533 G_CALLBACK(message_response_cb), dialog); |
534 | 534 |
535 gtk_container_set_border_width(GTK_CONTAINER(dialog), PIDGIN_HIG_BORDER); | 535 gtk_container_set_border_width(GTK_CONTAINER(dialog), PIDGIN_HIG_BORDER); |
536 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); | 536 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); |
537 #if !GTK_CHECK_VERSION(2,22,0) | |
537 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); | 538 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); |
539 #endif | |
538 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), PIDGIN_HIG_BORDER); | 540 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), PIDGIN_HIG_BORDER); |
539 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), PIDGIN_HIG_BOX_SPACE); | 541 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), PIDGIN_HIG_BOX_SPACE); |
540 | 542 |
541 hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER); | 543 hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BORDER); |
542 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); | 544 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); |
687 { | 689 { |
688 char *notification; | 690 char *notification; |
689 PurpleAccount *account; | 691 PurpleAccount *account; |
690 PidginNotifyMailData *data = NULL, *data2; | 692 PidginNotifyMailData *data = NULL, *data2; |
691 gboolean new_data = FALSE; | 693 gboolean new_data = FALSE; |
694 GtkTreeSelection *sel; | |
695 GtkTreeIter iter; | |
692 | 696 |
693 /* Don't bother updating if there aren't new emails and we don't have any displayed currently */ | 697 /* Don't bother updating if there aren't new emails and we don't have any displayed currently */ |
694 if (count == 0 && mail_dialog == NULL) | 698 if (count == 0 && mail_dialog == NULL) |
695 return NULL; | 699 return NULL; |
696 | 700 |
773 return NULL; | 777 return NULL; |
774 } | 778 } |
775 } | 779 } |
776 } | 780 } |
777 | 781 |
782 /* Select first item if nothing selected */ | |
783 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(mail_dialog->treeview)); | |
784 if ((gtk_tree_selection_count_selected_rows(sel) < 1) | |
785 && gtk_tree_model_get_iter_first(GTK_TREE_MODEL(mail_dialog->treemodel), &iter)) { | |
786 gtk_tree_selection_select_iter(sel, &iter); | |
787 } | |
788 | |
789 #if GTK_CHECK_VERSION(2,18,0) | |
790 if (!gtk_widget_get_visible(mail_dialog->dialog)) { | |
791 #else | |
778 if (!GTK_WIDGET_VISIBLE(mail_dialog->dialog)) { | 792 if (!GTK_WIDGET_VISIBLE(mail_dialog->dialog)) { |
793 #endif | |
779 GdkPixbuf *pixbuf = gtk_widget_render_icon(mail_dialog->dialog, PIDGIN_STOCK_DIALOG_MAIL, | 794 GdkPixbuf *pixbuf = gtk_widget_render_icon(mail_dialog->dialog, PIDGIN_STOCK_DIALOG_MAIL, |
780 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL), NULL); | 795 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL), NULL); |
781 char *label_text = g_strdup_printf(ngettext("<b>%d new email.</b>", | 796 char *label_text = g_strdup_printf(ngettext("<b>%d new email.</b>", |
782 "<b>%d new emails.</b>", | 797 "<b>%d new emails.</b>", |
783 mail_dialog->total_count), mail_dialog->total_count); | 798 mail_dialog->total_count), mail_dialog->total_count); |
789 (GDestroyNotify)reset_mail_dialog); | 804 (GDestroyNotify)reset_mail_dialog); |
790 mail_dialog->in_use = FALSE; | 805 mail_dialog->in_use = FALSE; |
791 g_free(label_text); | 806 g_free(label_text); |
792 if (pixbuf) | 807 if (pixbuf) |
793 g_object_unref(pixbuf); | 808 g_object_unref(pixbuf); |
809 #if GTK_CHECK_VERSION(2,18,0) | |
810 } else if (!gtk_widget_has_focus(mail_dialog->dialog)) | |
811 #else | |
794 } else if (!GTK_WIDGET_HAS_FOCUS(mail_dialog->dialog)) | 812 } else if (!GTK_WIDGET_HAS_FOCUS(mail_dialog->dialog)) |
813 #endif | |
795 pidgin_set_urgent(GTK_WINDOW(mail_dialog->dialog), TRUE); | 814 pidgin_set_urgent(GTK_WINDOW(mail_dialog->dialog), TRUE); |
796 | 815 |
797 return data; | 816 return data; |
798 } | 817 } |
799 | 818 |
806 | 825 |
807 return TRUE; | 826 return TRUE; |
808 } | 827 } |
809 | 828 |
810 return FALSE; | 829 return FALSE; |
811 } | |
812 | |
813 static GtkIMHtmlOptions | |
814 notify_imhtml_options(void) | |
815 { | |
816 GtkIMHtmlOptions options = 0; | |
817 | |
818 if (!purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/show_incoming_formatting")) | |
819 options |= GTK_IMHTML_NO_COLOURS | GTK_IMHTML_NO_FONTS | GTK_IMHTML_NO_SIZES; | |
820 | |
821 options |= GTK_IMHTML_NO_COMMENTS; | |
822 options |= GTK_IMHTML_NO_TITLE; | |
823 options |= GTK_IMHTML_NO_NEWLINE; | |
824 options |= GTK_IMHTML_NO_SCROLL; | |
825 return options; | |
826 } | 830 } |
827 | 831 |
828 static void * | 832 static void * |
829 pidgin_notify_formatted(const char *title, const char *primary, | 833 pidgin_notify_formatted(const char *title, const char *primary, |
830 const char *secondary, const char *text) | 834 const char *secondary, const char *text) |
831 { | 835 { |
832 GtkWidget *window; | 836 GtkWidget *window; |
833 GtkWidget *vbox; | 837 GtkWidget *vbox; |
834 GtkWidget *label; | 838 GtkWidget *label; |
835 GtkWidget *button; | 839 GtkWidget *button; |
836 GtkWidget *imhtml; | 840 GtkWidget *web_view; |
837 GtkWidget *frame; | 841 GtkWidget *frame; |
838 char label_text[2048]; | 842 char label_text[2048]; |
839 char *linked_text, *primary_esc, *secondary_esc; | 843 char *linked_text, *primary_esc, *secondary_esc; |
840 | 844 |
841 window = gtk_dialog_new(); | 845 window = gtk_dialog_new(); |
867 gtk_label_set_selectable(GTK_LABEL(label), TRUE); | 871 gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
868 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | 872 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); |
869 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | 873 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
870 gtk_widget_show(label); | 874 gtk_widget_show(label); |
871 | 875 |
872 /* Add the imhtml */ | 876 /* Add the webview */ |
873 frame = pidgin_create_imhtml(FALSE, &imhtml, NULL, NULL); | 877 frame = pidgin_create_webview(FALSE, &web_view, NULL, NULL); |
874 gtk_widget_set_name(imhtml, "pidgin_notify_imhtml"); | 878 gtk_widget_set_name(web_view, "pidgin_notify_webview"); |
875 gtk_imhtml_set_format_functions(GTK_IMHTML(imhtml), | 879 gtk_widget_set_size_request(web_view, 300, 250); |
876 gtk_imhtml_get_format_functions(GTK_IMHTML(imhtml)) | GTK_IMHTML_IMAGE); | |
877 gtk_widget_set_size_request(imhtml, 300, 250); | |
878 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); | 880 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); |
879 gtk_widget_show(frame); | 881 gtk_widget_show(frame); |
880 | 882 |
881 /* Add the Close button. */ | 883 /* Add the Close button. */ |
882 button = gtk_dialog_add_button(GTK_DIALOG(window), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); | 884 button = gtk_dialog_add_button(GTK_DIALOG(window), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); |
887 g_signal_connect(G_OBJECT(window), "key_press_event", | 889 g_signal_connect(G_OBJECT(window), "key_press_event", |
888 G_CALLBACK(formatted_input_cb), NULL); | 890 G_CALLBACK(formatted_input_cb), NULL); |
889 | 891 |
890 /* Make sure URLs are clickable */ | 892 /* Make sure URLs are clickable */ |
891 linked_text = purple_markup_linkify(text); | 893 linked_text = purple_markup_linkify(text); |
892 gtk_imhtml_append_text(GTK_IMHTML(imhtml), linked_text, notify_imhtml_options()); | 894 gtk_webview_load_html_string(GTK_WEBVIEW(web_view), linked_text); |
893 g_free(linked_text); | 895 g_free(linked_text); |
894 | 896 |
895 g_object_set_data(G_OBJECT(window), "info-widget", imhtml); | 897 g_object_set_data(G_OBJECT(window), "webview-widget", web_view); |
896 | 898 |
897 /* Show the window */ | 899 /* Show the window */ |
898 pidgin_auto_parent_window(window); | 900 pidgin_auto_parent_window(window); |
899 | 901 |
900 gtk_widget_show(window); | 902 gtk_widget_show(window); |
1032 for (columniter = results->columns; columniter != NULL; columniter = columniter->next) { | 1034 for (columniter = results->columns; columniter != NULL; columniter = columniter->next) { |
1033 PurpleNotifySearchColumn *column = columniter->data; | 1035 PurpleNotifySearchColumn *column = columniter->data; |
1034 renderer = gtk_cell_renderer_text_new(); | 1036 renderer = gtk_cell_renderer_text_new(); |
1035 | 1037 |
1036 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, | 1038 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, |
1037 column->title, renderer, "text", i, NULL); | 1039 purple_notify_searchresult_column_get_title(column), renderer, "text", i, NULL); |
1040 | |
1041 if (!purple_notify_searchresult_column_is_visible(column)) | |
1042 gtk_tree_view_column_set_visible(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), i), FALSE); | |
1043 | |
1038 i++; | 1044 i++; |
1039 } | 1045 } |
1040 | 1046 |
1041 for (l = results->buttons; l; l = l->next) { | 1047 for (l = results->buttons; l; l = l->next) { |
1042 PurpleNotifySearchButton *b = l->data; | 1048 PurpleNotifySearchButton *b = l->data; |
1043 GtkWidget *button = NULL; | 1049 GtkWidget *button = NULL; |
1044 switch (b->type) { | 1050 switch (b->type) { |
1045 case PURPLE_NOTIFY_BUTTON_LABELED: | 1051 case PURPLE_NOTIFY_BUTTON_LABELED: |
1046 if(b->label) { | 1052 if(b->label) { |
1047 button = gtk_button_new_with_label(b->label); | 1053 button = gtk_dialog_add_button(GTK_DIALOG(window), b->label, GTK_RESPONSE_NONE); |
1048 } else { | 1054 } else { |
1049 purple_debug_warning("gtknotify", "Missing button label\n"); | 1055 purple_debug_warning("gtknotify", "Missing button label\n"); |
1050 } | 1056 } |
1051 break; | 1057 break; |
1052 case PURPLE_NOTIFY_BUTTON_CONTINUE: | 1058 case PURPLE_NOTIFY_BUTTON_CONTINUE: |
1087 close_button = gtk_dialog_add_button(GTK_DIALOG(window), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); | 1093 close_button = gtk_dialog_add_button(GTK_DIALOG(window), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); |
1088 | 1094 |
1089 g_signal_connect_swapped(G_OBJECT(close_button), "clicked", | 1095 g_signal_connect_swapped(G_OBJECT(close_button), "clicked", |
1090 G_CALLBACK(searchresults_close_cb), data); | 1096 G_CALLBACK(searchresults_close_cb), data); |
1091 | 1097 |
1092 data->account = gc->account; | 1098 data->account = purple_connection_get_account(gc); |
1093 data->model = model; | 1099 data->model = model; |
1094 data->treeview = treeview; | 1100 data->treeview = treeview; |
1095 data->window = window; | 1101 data->window = window; |
1096 | 1102 |
1097 /* Insert rows. */ | 1103 /* Insert rows. */ |
1141 } | 1147 } |
1142 | 1148 |
1143 info = purple_notify_user_info_get_text_with_newline(user_info, "<br />"); | 1149 info = purple_notify_user_info_get_text_with_newline(user_info, "<br />"); |
1144 pinfo = g_hash_table_lookup(userinfo, key); | 1150 pinfo = g_hash_table_lookup(userinfo, key); |
1145 if (pinfo != NULL) { | 1151 if (pinfo != NULL) { |
1146 GtkIMHtml *imhtml = g_object_get_data(G_OBJECT(pinfo->window), "info-widget"); | 1152 GtkWidget *webview = g_object_get_data(G_OBJECT(pinfo->window), "webview-widget"); |
1147 char *linked_text = purple_markup_linkify(info); | 1153 char *linked_text = purple_markup_linkify(info); |
1148 gtk_imhtml_clear(imhtml); | 1154 gtk_webview_load_html_string(GTK_WEBVIEW(webview), linked_text); |
1149 gtk_imhtml_append_text(imhtml, linked_text, notify_imhtml_options()); | |
1150 g_free(linked_text); | 1155 g_free(linked_text); |
1151 g_free(key); | 1156 g_free(key); |
1152 ui_handle = pinfo->window; | 1157 ui_handle = pinfo->window; |
1153 pinfo->count++; | 1158 pinfo->count++; |
1154 } else { | 1159 } else { |
1506 dialog = gtk_dialog_new(); | 1511 dialog = gtk_dialog_new(); |
1507 | 1512 |
1508 /* Setup the dialog */ | 1513 /* Setup the dialog */ |
1509 gtk_container_set_border_width(GTK_CONTAINER(dialog), PIDGIN_HIG_BOX_SPACE); | 1514 gtk_container_set_border_width(GTK_CONTAINER(dialog), PIDGIN_HIG_BOX_SPACE); |
1510 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), PIDGIN_HIG_BOX_SPACE); | 1515 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), PIDGIN_HIG_BOX_SPACE); |
1516 #if !GTK_CHECK_VERSION(2,22,0) | |
1511 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); | 1517 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); |
1518 #endif | |
1512 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), PIDGIN_HIG_BORDER); | 1519 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), PIDGIN_HIG_BORDER); |
1513 | 1520 |
1514 /* Vertical box */ | 1521 /* Vertical box */ |
1515 vbox = GTK_DIALOG(dialog)->vbox; | 1522 vbox = GTK_DIALOG(dialog)->vbox; |
1516 | 1523 |
1542 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(spec_dialog->treeview), FALSE); | 1549 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(spec_dialog->treeview), FALSE); |
1543 | 1550 |
1544 gtk_tree_view_set_search_column(GTK_TREE_VIEW(spec_dialog->treeview), PIDGIN_MAIL_TEXT); | 1551 gtk_tree_view_set_search_column(GTK_TREE_VIEW(spec_dialog->treeview), PIDGIN_MAIL_TEXT); |
1545 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(spec_dialog->treeview), | 1552 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(spec_dialog->treeview), |
1546 pidgin_tree_view_search_equal_func, NULL, NULL); | 1553 pidgin_tree_view_search_equal_func, NULL, NULL); |
1554 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(spec_dialog->treeview)); | |
1555 gtk_tree_selection_set_mode(sel, GTK_SELECTION_BROWSE); | |
1547 | 1556 |
1548 g_signal_connect(G_OBJECT(dialog), "response", | 1557 g_signal_connect(G_OBJECT(dialog), "response", |
1549 G_CALLBACK(email_response_cb), spec_dialog); | 1558 G_CALLBACK(email_response_cb), spec_dialog); |
1550 g_signal_connect(G_OBJECT(gtk_tree_view_get_selection(GTK_TREE_VIEW(spec_dialog->treeview))), | 1559 g_signal_connect(G_OBJECT(sel), "changed", |
1551 "changed", G_CALLBACK(selection_changed_cb), spec_dialog); | 1560 G_CALLBACK(selection_changed_cb), spec_dialog); |
1552 g_signal_connect(G_OBJECT(spec_dialog->treeview), "row-activated", G_CALLBACK(email_row_activated_cb), NULL); | 1561 g_signal_connect(G_OBJECT(spec_dialog->treeview), "row-activated", G_CALLBACK(email_row_activated_cb), NULL); |
1553 | 1562 |
1554 column = gtk_tree_view_column_new(); | 1563 column = gtk_tree_view_column_new(); |
1555 gtk_tree_view_column_set_resizable(column, TRUE); | 1564 gtk_tree_view_column_set_resizable(column, TRUE); |
1556 rend = gtk_cell_renderer_pixbuf_new(); | 1565 rend = gtk_cell_renderer_pixbuf_new(); |
1644 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); | 1653 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); |
1645 | 1654 |
1646 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | 1655 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
1647 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | 1656 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); |
1648 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | 1657 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
1649 gtk_box_pack_start(GTK_BOX(vbox), | 1658 gtk_box_pack_start(GTK_BOX(vbox), |
1650 pidgin_make_scrollable(spec_dialog->treeview, GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS, GTK_SHADOW_IN, -1, -1), | 1659 pidgin_make_scrollable(spec_dialog->treeview, GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS, GTK_SHADOW_IN, -1, -1), |
1651 TRUE, TRUE, 2); | 1660 TRUE, TRUE, 2); |
1652 | 1661 |
1653 return spec_dialog; | 1662 return spec_dialog; |
1654 } | 1663 } |