From e1ae13450cf3ad12df82bd6a2111eedd6d169ef7 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 29 Jul 2011 14:23:21 +1000 Subject: Add a webview widget for displaying the log The widget is currently bolted in alongside the existing log display widget for comparison. This includes some debugging cruft like showing the secret notebook tabs. The webview is populated from the store_events treestore, allowing all of the existing node-management and ordering code to be used. Attempting to replace this logic in Javascript was demonstratably too hard. This approach keeps the Javascript code down to the 4 GtkTreeModel signals. TODO: - icons - pretty printed dates - expanders - supporting smileys, links, etc. - using the correct font, etc. - removing the debugging --- libempathy-gtk/empathy-log-window.c | 133 ++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index e5c935011..04f224290 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -83,6 +84,7 @@ struct _EmpathyLogWindowPriv GtkWidget *treeview_what; GtkWidget *treeview_when; GtkWidget *treeview_events; + GtkWidget *webview; GtkTreeStore *store_events; @@ -360,6 +362,103 @@ toolbutton_av_clicked (GtkToolButton *toolbutton, TRUE, video, gtk_get_current_event_time ()); } +static void +insert_or_change_row (EmpathyLogWindow *self, + const char *method, + GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter) +{ + char *str = gtk_tree_path_to_string (path); + char *script, *text; + + gtk_tree_model_get (model, iter, + COL_EVENTS_TEXT, &text, + -1); + + script = g_strdup_printf ("javascript:%s([%s], '%s');", + method, + g_strdelimit (str, ":", ','), + text); + + // g_print ("%s\n", script); + webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self->priv->webview), + script); + + g_free (str); + g_free (text); + g_free (script); +} + +static void +store_events_row_inserted (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + EmpathyLogWindow *self) +{ + insert_or_change_row (self, "insertRow", model, path, iter); +} + +static void +store_events_row_changed (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + EmpathyLogWindow *self) +{ + insert_or_change_row (self, "changeRow", model, path, iter); +} + +static void +store_events_row_deleted (GtkTreeModel *model, + GtkTreePath *path, + EmpathyLogWindow *self) +{ + char *str = gtk_tree_path_to_string (path); + char *script; + + script = g_strdup_printf ("javascript:deleteRow([%s]);", + g_strdelimit (str, ":", ',')); + + // g_print ("%s\n", script); + webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self->priv->webview), + script); + + g_free (str); + g_free (script); +} + +static void +store_events_rows_reordered (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + int *new_order, + EmpathyLogWindow *self) +{ + char *str = gtk_tree_path_to_string (path); + int i, children = gtk_tree_model_iter_n_children (model, iter); + char **new_order_strv, *new_order_s; + char *script; + + new_order_strv = g_new0 (char *, children + 1); + + for (i = 0; i < children; i++) + new_order_strv[i] = g_strdup_printf ("%i", new_order[i]); + + new_order_s = g_strjoinv (",", new_order_strv); + + script = g_strdup_printf ("javascript:reorderRows([%s], [%s]);", + str == NULL ? "" : g_strdelimit (str, ":", ','), + new_order_s); + + webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self->priv->webview), + script); + + g_free (str); + g_free (script); + g_free (new_order_s); + g_strfreev (new_order_strv); +} + static GObject * empathy_log_window_constructor (GType type, guint n_props, @@ -444,7 +543,9 @@ empathy_log_window_init (EmpathyLogWindow *self) EmpathyAccountChooser *account_chooser; GtkBuilder *gui; gchar *filename; + GFile *gfile; GtkWidget *vbox, *accounts, *search, *label, *quit; + GtkWidget *sw; self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_LOG_WINDOW, EmpathyLogWindowPriv); @@ -564,6 +665,38 @@ empathy_log_window_init (EmpathyLogWindow *self) log_window_who_populate (self); + /* events */ + sw = gtk_scrolled_window_new (NULL, NULL); + self->priv->webview = webkit_web_view_new (); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + gtk_container_add (GTK_CONTAINER (sw), self->priv->webview); + + filename = empathy_file_lookup ("empathy-log-window.html", "data"); + gfile = g_file_new_for_path (filename); + g_free (filename); + + webkit_web_view_load_uri (WEBKIT_WEB_VIEW (self->priv->webview), + g_file_get_uri (gfile)); + g_object_unref (gfile); + + gtk_notebook_append_page (GTK_NOTEBOOK (self->priv->notebook), + sw, gtk_label_new ("webview")); + gtk_widget_show_all (sw); + + /* listen to changes to the treemodel */ + g_signal_connect (self->priv->store_events, "row-inserted", + G_CALLBACK (store_events_row_inserted), self); + g_signal_connect (self->priv->store_events, "row-changed", + G_CALLBACK (store_events_row_changed), self); + g_signal_connect (self->priv->store_events, "row-deleted", + G_CALLBACK (store_events_row_deleted), self); + g_signal_connect (self->priv->store_events, "rows-reordered", + G_CALLBACK (store_events_rows_reordered), self); + + // debug + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (self->priv->notebook), TRUE); + gtk_widget_show (GTK_WIDGET (self)); } -- cgit v1.2.3 From e3d0a1862508fad3d16585b0210a2a9328453c2f Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 1 Aug 2011 13:04:15 +1000 Subject: Abstract WebKit string parsers into empathy-webkit-utils This file is currently optionally built, but if the logviewer is going to depend on WebKit, maybe that's a bad idea? Maybe we should just make WebKit required (this will probably happen when we require Adium themes in the future). --- libempathy-gtk/Makefile.am | 13 +++-- libempathy-gtk/empathy-theme-adium.c | 69 ++------------------------ libempathy-gtk/empathy-webkit-utils.c | 91 +++++++++++++++++++++++++++++++++++ libempathy-gtk/empathy-webkit-utils.h | 32 ++++++++++++ 4 files changed, 137 insertions(+), 68 deletions(-) create mode 100644 libempathy-gtk/empathy-webkit-utils.c create mode 100644 libempathy-gtk/empathy-webkit-utils.h (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 7023ecfe5..f12230def 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -279,16 +279,23 @@ endif if HAVE_WEBKIT libempathy_gtk_handwritten_source += \ empathy-plist.c \ - empathy-theme-adium.c + empathy-theme-adium.c \ + empathy-webkit-utils.c \ + $(NULL) libempathy_gtk_headers += \ empathy-plist.h \ - empathy-theme-adium.h + empathy-theme-adium.h \ + empathy-webkit-utils.h \ + $(NULL) else EXTRA_DIST += \ empathy-plist.c \ empathy-plist.h \ empathy-theme-adium.c \ - empathy-theme-adium.h + empathy-theme-adium.h \ + empathy-webkit-utils.c \ + empathy-webkit-utils.h \ + $(NULL) endif CLEANFILES = \ diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index 14e149e18..874f5592f 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -39,8 +39,8 @@ #include "empathy-smiley-manager.h" #include "empathy-ui-utils.h" #include "empathy-plist.h" -#include "empathy-string-parser.h" #include "empathy-images.h" +#include "empathy-webkit-utils.h" #define DEBUG_FLAG EMPATHY_DEBUG_CHAT #include @@ -293,65 +293,6 @@ theme_adium_load_template (EmpathyThemeAdium *theme) g_free (template); } -static void -theme_adium_match_newline (const gchar *text, - gssize len, - EmpathyStringReplace replace_func, - EmpathyStringParser *sub_parsers, - gpointer user_data) -{ - GString *string = user_data; - gint i; - gint prev = 0; - - if (len < 0) { - len = G_MAXSSIZE; - } - - /* Replace \n by
*/ - for (i = 0; i < len && text[i] != '\0'; i++) { - if (text[i] == '\n') { - empathy_string_parser_substr (text + prev, - i - prev, sub_parsers, - user_data); - g_string_append (string, "
"); - prev = i + 1; - } - } - empathy_string_parser_substr (text + prev, i - prev, - sub_parsers, user_data); -} - -static void -theme_adium_replace_smiley (const gchar *text, - gssize len, - gpointer match_data, - gpointer user_data) -{ - EmpathySmileyHit *hit = match_data; - GString *string = user_data; - - /* Replace smiley by a tag */ - g_string_append_printf (string, - "\"%.*s\"", - hit->path, (int)len, text, (int)len, text); -} - -static EmpathyStringParser string_parsers[] = { - {empathy_string_match_link, empathy_string_replace_link}, - {theme_adium_match_newline, NULL}, - {empathy_string_match_all, empathy_string_replace_escaped}, - {NULL, NULL} -}; - -static EmpathyStringParser string_parsers_with_smiley[] = { - {empathy_string_match_link, empathy_string_replace_link}, - {empathy_string_match_smiley, theme_adium_replace_smiley}, - {theme_adium_match_newline, NULL}, - {empathy_string_match_all, empathy_string_replace_escaped}, - {NULL, NULL} -}; - static gchar * theme_adium_parse_body (EmpathyThemeAdium *self, const gchar *text, @@ -362,11 +303,9 @@ theme_adium_parse_body (EmpathyThemeAdium *self, GString *string; /* Check if we have to parse smileys */ - if (g_settings_get_boolean (priv->gsettings_chat, - EMPATHY_PREFS_CHAT_SHOW_SMILEYS)) - parsers = string_parsers_with_smiley; - else - parsers = string_parsers; + parsers = empathy_webkit_get_string_parser ( + g_settings_get_boolean (priv->gsettings_chat, + EMPATHY_PREFS_CHAT_SHOW_SMILEYS)); /* Parse text and construct string with links and smileys replaced * by html tags. Also escape text to make sure html code is diff --git a/libempathy-gtk/empathy-webkit-utils.c b/libempathy-gtk/empathy-webkit-utils.c new file mode 100644 index 000000000..e5d163ae2 --- /dev/null +++ b/libempathy-gtk/empathy-webkit-utils.c @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2008-2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens + */ + +#include "empathy-webkit-utils.h" +#include "empathy-smiley-manager.h" + +static void +empathy_webkit_match_newline (const gchar *text, + gssize len, + EmpathyStringReplace replace_func, + EmpathyStringParser *sub_parsers, + gpointer user_data) +{ + GString *string = user_data; + gint i; + gint prev = 0; + + if (len < 0) + len = G_MAXSSIZE; + + /* Replace \n by
*/ + for (i = 0; i < len && text[i] != '\0'; i++) + { + if (text[i] == '\n') + { + empathy_string_parser_substr (text + prev, i - prev, + sub_parsers, user_data); + g_string_append (string, "
"); + prev = i + 1; + } + } + + empathy_string_parser_substr (text + prev, i - prev, + sub_parsers, user_data); +} + +static void +empathy_webkit_replace_smiley (const gchar *text, + gssize len, + gpointer match_data, + gpointer user_data) +{ + EmpathySmileyHit *hit = match_data; + GString *string = user_data; + + /* Replace smiley by a tag */ + g_string_append_printf (string, + "\"%.*s\"", + hit->path, (int)len, text, (int)len, text); +} + +static EmpathyStringParser string_parsers[] = { + { empathy_string_match_link, empathy_string_replace_link }, + { empathy_webkit_match_newline, NULL }, + { empathy_string_match_all, empathy_string_replace_escaped }, + { NULL, NULL} +}; + +static EmpathyStringParser string_parsers_with_smiley[] = { + { empathy_string_match_link, empathy_string_replace_link }, + { empathy_string_match_smiley, empathy_webkit_replace_smiley }, + { empathy_webkit_match_newline, NULL }, + { empathy_string_match_all, empathy_string_replace_escaped }, + { NULL, NULL } +}; + +EmpathyStringParser * +empathy_webkit_get_string_parser (gboolean smileys) +{ + if (smileys) + return string_parsers_with_smiley; + else + return string_parsers; +} diff --git a/libempathy-gtk/empathy-webkit-utils.h b/libempathy-gtk/empathy-webkit-utils.h new file mode 100644 index 000000000..38cbfedcb --- /dev/null +++ b/libempathy-gtk/empathy-webkit-utils.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2008-2009 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens + */ + +#ifndef _EMPATHY_WEBKIT_UTILS__H_ +#define _EMPATHY_WEBKIT_UTILS__H_ + +#include "empathy-string-parser.h" + +G_BEGIN_DECLS + +EmpathyStringParser *empathy_webkit_get_string_parser (gboolean smileys); + +G_END_DECLS + +#endif -- cgit v1.2.3 From 3b86a347cd3e859c427b7e596d949d6ce0094840 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 1 Aug 2011 13:05:30 +1000 Subject: Use webkit-utils in LogWindow webview --- libempathy-gtk/empathy-log-window.c | 101 ++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 45 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index 04f224290..9459ce26b 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -60,6 +60,8 @@ #include "empathy-images.h" #include "empathy-theme-manager.h" #include "empathy-ui-utils.h" +// FIXME: this work forces a dependency on webkit +#include "empathy-webkit-utils.h" #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include @@ -1189,8 +1191,10 @@ log_window_append_chat_message (TplEvent *event, { GtkTreeStore *store = log_window->priv->store_events; GtkTreeIter iter, parent; - gchar *pretty_date, *alias, *body, *msg; + gchar *pretty_date, *alias, *body; GDateTime *date; + EmpathyStringParser *parsers; + GString *msg; date = g_date_time_new_from_unix_utc ( tpl_event_get_timestamp (event)); @@ -1199,62 +1203,69 @@ log_window_append_chat_message (TplEvent *event, get_parent_iter_for_message (event, message, &parent); - msg = g_markup_escape_text (empathy_message_get_body (message), -1); alias = g_markup_escape_text ( tpl_entity_get_alias (tpl_event_get_sender (event)), -1); - /* If the user is searching, highlight the matched text */ - if (!EMP_STR_EMPTY (log_window->priv->last_find)) - { - gchar *str = g_regex_escape_string (log_window->priv->last_find, -1); - gchar *replacement = g_markup_printf_escaped ( - "%s", - log_window->priv->last_find); - GError *error = NULL; - GRegex *regex = g_regex_new (str, 0, 0, &error); - - if (regex == NULL) - { - DEBUG ("Could not create regex: %s", error->message); - g_error_free (error); - } - else - { - gchar *new_msg = g_regex_replace_literal (regex, - empathy_message_get_body (message), -1, 0, replacement, - 0, &error); - - if (new_msg != NULL) - { - /* We pass ownership of new_msg to msg, which is freed later */ - g_free (msg); - msg = new_msg; - } - else - { - DEBUG ("Error while performing string substitution: %s", - error->message); - g_error_free (error); - } - } - - g_free (str); - g_free (replacement); - - tp_clear_pointer (®ex, g_regex_unref); - } + // /* If the user is searching, highlight the matched text */ + // if (!EMP_STR_EMPTY (log_window->priv->last_find)) + // { + // gchar *str = g_regex_escape_string (log_window->priv->last_find, -1); + // gchar *replacement = g_markup_printf_escaped ( + // "%s", + // log_window->priv->last_find); + // GError *error = NULL; + // GRegex *regex = g_regex_new (str, 0, 0, &error); + + // if (regex == NULL) + // { + // DEBUG ("Could not create regex: %s", error->message); + // g_error_free (error); + // } + // else + // { + // gchar *new_msg = g_regex_replace_literal (regex, + // empathy_message_get_body (message), -1, 0, replacement, + // 0, &error); + + // if (new_msg != NULL) + // { + // /* We pass ownership of new_msg to msg, which is freed later */ + // g_free (msg); + // msg = new_msg; + // } + // else + // { + // DEBUG ("Error while performing string substitution: %s", + // error->message); + // g_error_free (error); + // } + // } + + // g_free (str); + // g_free (replacement); + + // tp_clear_pointer (®ex, g_regex_unref); + // } + + /* escape the text */ + // FIXME: handle smileys + parsers = empathy_webkit_get_string_parser (FALSE); + msg = g_string_new (""); + + empathy_string_parser_substr (empathy_message_get_body (message), -1, + parsers, msg); if (tpl_text_event_get_message_type (TPL_TEXT_EVENT (event)) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) { /* Translators: this is an emote: '* Danielle waves' */ - body = g_strdup_printf (_("* %s %s"), alias, msg); + body = g_strdup_printf (_("* %s %s"), alias, msg->str); } else { /* Translators: this is a message: 'Danielle: hello' * The string in bold is the sender's name */ - body = g_strdup_printf (_("%s: %s"), alias, msg); + body = g_strdup_printf (_("%s: %s"), alias, msg->str); } gtk_tree_store_append (store, &iter, &parent); @@ -1268,7 +1279,7 @@ log_window_append_chat_message (TplEvent *event, COL_EVENTS_EVENT, event, -1); - g_free (msg); + g_string_free (msg, TRUE); g_free (body); g_free (alias); g_free (pretty_date); -- cgit v1.2.3 From 7565c39bfa0f118fb513c0af86a5ba0ef7976277 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 1 Aug 2011 15:42:43 +1000 Subject: Add expander toggles --- libempathy-gtk/empathy-log-window.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index 9459ce26b..ef6450f36 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -429,6 +429,27 @@ store_events_row_deleted (GtkTreeModel *model, g_free (script); } +static void +store_events_has_child_rows (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + EmpathyLogWindow *self) +{ + char *str = gtk_tree_path_to_string (path); + char *script; + + script = g_strdup_printf ("javascript:hasChildRows([%s], %u);", + g_strdelimit (str, ":", ','), + gtk_tree_model_iter_has_child (model, iter)); + + // g_print ("%s\n", script); + webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self->priv->webview), + script); + + g_free (str); + g_free (script); +} + static void store_events_rows_reordered (GtkTreeModel *model, GtkTreePath *path, @@ -695,6 +716,8 @@ empathy_log_window_init (EmpathyLogWindow *self) G_CALLBACK (store_events_row_deleted), self); g_signal_connect (self->priv->store_events, "rows-reordered", G_CALLBACK (store_events_rows_reordered), self); + g_signal_connect (self->priv->store_events, "row-has-child-toggled", + G_CALLBACK (store_events_has_child_rows), self); // debug gtk_notebook_set_show_tabs (GTK_NOTEBOOK (self->priv->notebook), TRUE); -- cgit v1.2.3 From 0f84b8fa5a7f061cb5f82ed489e22f15ae2bc7cc Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 1 Aug 2011 15:51:23 +1000 Subject: Handle links via external browser --- libempathy-gtk/empathy-log-window.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index ef6450f36..f81ea4cfe 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -482,6 +482,21 @@ store_events_rows_reordered (GtkTreeModel *model, g_strfreev (new_order_strv); } +static gboolean +events_webview_handle_navigation (WebKitWebView *webview, + WebKitWebFrame *frame, + WebKitNetworkRequest *request, + WebKitWebNavigationAction *navigation_action, + WebKitWebPolicyDecision *policy_decision, + EmpathyLogWindow *window) +{ + empathy_url_show (GTK_WIDGET (webview), + webkit_network_request_get_uri (request)); + + webkit_web_policy_decision_ignore (policy_decision); + return TRUE; +} + static GObject * empathy_log_window_constructor (GType type, guint n_props, @@ -703,6 +718,10 @@ empathy_log_window_init (EmpathyLogWindow *self) g_file_get_uri (gfile)); g_object_unref (gfile); + /* handle all navigation externally */ + g_signal_connect (self->priv->webview, "navigation-policy-decision-requested", + G_CALLBACK (events_webview_handle_navigation), self); + gtk_notebook_append_page (GTK_NOTEBOOK (self->priv->notebook), sw, gtk_label_new ("webview")); gtk_widget_show_all (sw); -- cgit v1.2.3 From 79de445e7b21747cbc7893737a5d6756da184274 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Thu, 4 Aug 2011 12:14:11 +1000 Subject: Support smileys in log viewer --- libempathy-gtk/empathy-log-window.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index f81ea4cfe..8869d4acd 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -121,6 +122,8 @@ struct _EmpathyLogWindowPriv TpAccount *selected_account; gchar *selected_chat_id; gboolean selected_is_chatroom; + + GSettings *gsettings_chat; }; static void log_window_search_entry_changed_cb (GtkWidget *entry, @@ -546,6 +549,7 @@ empathy_log_window_dispose (GObject *object) tp_clear_object (&self->priv->selected_account); tp_clear_object (&self->priv->selected_contact); tp_clear_object (&self->priv->camera_monitor); + tp_clear_object (&self->priv->gsettings_chat); G_OBJECT_CLASS (empathy_log_window_parent_class)->dispose (object); } @@ -594,6 +598,8 @@ empathy_log_window_init (EmpathyLogWindow *self) self->priv->log_manager = tpl_log_manager_dup_singleton (); + self->priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA); + gtk_window_set_title (GTK_WINDOW (self), _("History")); gtk_widget_set_can_focus (GTK_WIDGET (self), FALSE); gtk_window_set_default_size (GTK_WINDOW (self), 800, 600); @@ -1290,8 +1296,9 @@ log_window_append_chat_message (TplEvent *event, // } /* escape the text */ - // FIXME: handle smileys - parsers = empathy_webkit_get_string_parser (FALSE); + parsers = empathy_webkit_get_string_parser ( + g_settings_get_boolean (log_window->priv->gsettings_chat, + EMPATHY_PREFS_CHAT_SHOW_SMILEYS)); msg = g_string_new (""); empathy_string_parser_substr (empathy_message_get_body (message), -1, -- cgit v1.2.3 From e15b7f70a43898e4978836fdf8efbed0bebeaea4 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 5 Aug 2011 14:43:00 +1000 Subject: Replace highlighting of search strings --- libempathy-gtk/empathy-log-window.c | 47 +++++-------------------------------- 1 file changed, 6 insertions(+), 41 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index 8869d4acd..b5c2e48cf 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -1254,47 +1254,6 @@ log_window_append_chat_message (TplEvent *event, alias = g_markup_escape_text ( tpl_entity_get_alias (tpl_event_get_sender (event)), -1); - // /* If the user is searching, highlight the matched text */ - // if (!EMP_STR_EMPTY (log_window->priv->last_find)) - // { - // gchar *str = g_regex_escape_string (log_window->priv->last_find, -1); - // gchar *replacement = g_markup_printf_escaped ( - // "%s", - // log_window->priv->last_find); - // GError *error = NULL; - // GRegex *regex = g_regex_new (str, 0, 0, &error); - - // if (regex == NULL) - // { - // DEBUG ("Could not create regex: %s", error->message); - // g_error_free (error); - // } - // else - // { - // gchar *new_msg = g_regex_replace_literal (regex, - // empathy_message_get_body (message), -1, 0, replacement, - // 0, &error); - - // if (new_msg != NULL) - // { - // /* We pass ownership of new_msg to msg, which is freed later */ - // g_free (msg); - // msg = new_msg; - // } - // else - // { - // DEBUG ("Error while performing string substitution: %s", - // error->message); - // g_error_free (error); - // } - // } - - // g_free (str); - // g_free (replacement); - - // tp_clear_pointer (®ex, g_regex_unref); - // } - /* escape the text */ parsers = empathy_webkit_get_string_parser ( g_settings_get_boolean (log_window->priv->gsettings_chat, @@ -1977,6 +1936,8 @@ log_window_find_populate (EmpathyLogWindow *self, if (EMP_STR_EMPTY (search_criteria)) { tp_clear_pointer (&self->priv->hits, tpl_log_manager_search_free); + webkit_web_view_set_highlight_text_matches ( + WEBKIT_WEB_VIEW (self->priv->webview), FALSE); log_window_who_populate (self); return; } @@ -1985,6 +1946,10 @@ log_window_find_populate (EmpathyLogWindow *self, log_window_when_changed_cb, self); + /* highlight the search text */ + webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (self->priv->webview), + search_criteria, FALSE, 0); + tpl_log_manager_search_async (self->priv->log_manager, search_criteria, TPL_EVENT_MASK_ANY, log_manager_searched_new_cb, NULL); -- cgit v1.2.3 From 7424ac01d5010aaa101c2b5841daf840b4d0e20c Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Sun, 7 Aug 2011 13:17:31 +1000 Subject: Remove treeview_events -- make the webview the only viewing component Still some commented out code to reimplement. --- libempathy-gtk/empathy-log-window.c | 166 ++++++++++++----------------------- libempathy-gtk/empathy-log-window.ui | 9 -- 2 files changed, 58 insertions(+), 117 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index b5c2e48cf..cd1daac22 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -86,7 +86,6 @@ struct _EmpathyLogWindowPriv GtkWidget *treeview_who; GtkWidget *treeview_what; GtkWidget *treeview_when; - GtkWidget *treeview_events; GtkWidget *webview; GtkTreeStore *store_events; @@ -551,6 +550,8 @@ empathy_log_window_dispose (GObject *object) tp_clear_object (&self->priv->camera_monitor); tp_clear_object (&self->priv->gsettings_chat); + tp_clear_object (&self->priv->store_events); + G_OBJECT_CLASS (empathy_log_window_parent_class)->dispose (object); } @@ -587,7 +588,7 @@ empathy_log_window_init (EmpathyLogWindow *self) gchar *filename; GFile *gfile; GtkWidget *vbox, *accounts, *search, *label, *quit; - GtkWidget *sw; + GtkWidget *scrolledwindow_events; self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_LOG_WINDOW, EmpathyLogWindowPriv); @@ -617,7 +618,7 @@ empathy_log_window_init (EmpathyLogWindow *self) "treeview_who", &self->priv->treeview_who, "treeview_what", &self->priv->treeview_what, "treeview_when", &self->priv->treeview_when, - "treeview_events", &self->priv->treeview_events, + "scrolledwindow_events", &scrolledwindow_events, "notebook", &self->priv->notebook, "spinner", &self->priv->spinner, NULL); @@ -710,11 +711,12 @@ empathy_log_window_init (EmpathyLogWindow *self) log_window_who_populate (self); /* events */ - sw = gtk_scrolled_window_new (NULL, NULL); self->priv->webview = webkit_web_view_new (); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_events), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_container_add (GTK_CONTAINER (sw), self->priv->webview); + gtk_container_add (GTK_CONTAINER (scrolledwindow_events), + self->priv->webview); + gtk_widget_show (self->priv->webview); filename = empathy_file_lookup ("empathy-log-window.html", "data"); gfile = g_file_new_for_path (filename); @@ -728,10 +730,6 @@ empathy_log_window_init (EmpathyLogWindow *self) g_signal_connect (self->priv->webview, "navigation-policy-decision-requested", G_CALLBACK (events_webview_handle_navigation), self); - gtk_notebook_append_page (GTK_NOTEBOOK (self->priv->notebook), - sw, gtk_label_new ("webview")); - gtk_widget_show_all (sw); - /* listen to changes to the treemodel */ g_signal_connect (self->priv->store_events, "row-inserted", G_CALLBACK (store_events_row_inserted), self); @@ -744,9 +742,6 @@ empathy_log_window_init (EmpathyLogWindow *self) g_signal_connect (self->priv->store_events, "row-has-child-toggled", G_CALLBACK (store_events_has_child_rows), self); - // debug - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (self->priv->notebook), TRUE); - gtk_widget_show (GTK_WIDGET (self)); } @@ -2066,15 +2061,16 @@ log_window_update_buttons_sensitivity (EmpathyLogWindow *self) /* If the Who pane doesn't contain a contact (e.g. it has many * selected, or has 'Anyone', let's try to get the contact from * the selected event. */ - view = GTK_TREE_VIEW (self->priv->treeview_events); - model = gtk_tree_view_get_model (view); - selection = gtk_tree_view_get_selection (view); + goto out; // FIXME: reimplement + // view = GTK_TREE_VIEW (self->priv->treeview_events); + // model = gtk_tree_view_get_model (view); + // selection = gtk_tree_view_get_selection (view); - if (gtk_tree_selection_count_selected_rows (selection) != 1) - goto out; + // if (gtk_tree_selection_count_selected_rows (selection) != 1) + // goto out; - if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) - goto out; + // if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) + // goto out; gtk_tree_model_get (model, &iter, COL_EVENTS_ACCOUNT, &account, @@ -2482,40 +2478,33 @@ who_row_is_separator (GtkTreeModel *model, return (type == COL_TYPE_SEPARATOR); } -static void -log_window_events_changed_cb (GtkTreeSelection *selection, - EmpathyLogWindow *self) -{ - DEBUG ("log_window_events_changed_cb"); - - log_window_update_buttons_sensitivity (self); -} - -static void -log_window_events_row_activated_cb (GtkTreeView *view, - GtkTreePath *path, - GtkTreeViewColumn *column, - EmpathyLogWindow *self) -{ - if (gtk_tree_view_row_expanded (view, path)) - gtk_tree_view_collapse_row (view, path); - else - gtk_tree_view_expand_row (view, path, FALSE); -} +// static void +// log_window_events_changed_cb (GtkTreeSelection *selection, +// EmpathyLogWindow *self) +// { +// DEBUG ("log_window_events_changed_cb"); +// +// log_window_update_buttons_sensitivity (self); +// } + +// static void +// log_window_events_row_activated_cb (GtkTreeView *view, +// GtkTreePath *path, +// GtkTreeViewColumn *column, +// EmpathyLogWindow *self) +// { +// if (gtk_tree_view_row_expanded (view, path)) +// gtk_tree_view_collapse_row (view, path); +// else +// gtk_tree_view_expand_row (view, path, FALSE); +// } static void log_window_events_setup (EmpathyLogWindow *self) { - GtkTreeView *view; GtkTreeModel *model; - GtkTreeSelection *selection; GtkTreeSortable *sortable; - GtkTreeViewColumn *column; GtkTreeStore *store; - GtkCellRenderer *cell; - - view = GTK_TREE_VIEW (self->priv->treeview_events); - selection = gtk_tree_view_get_selection (view); /* new store */ self->priv->store_events = store = gtk_tree_store_new (COL_EVENTS_COUNT, @@ -2531,49 +2520,9 @@ log_window_events_setup (EmpathyLogWindow *self) model = GTK_TREE_MODEL (store); sortable = GTK_TREE_SORTABLE (store); - gtk_tree_view_set_model (view, model); - - /* new column */ - column = gtk_tree_view_column_new (); - - cell = gtk_cell_renderer_pixbuf_new (); - gtk_tree_view_column_pack_start (column, cell, FALSE); - gtk_tree_view_column_add_attribute (column, cell, - "icon-name", COL_EVENTS_ICON); - - cell = gtk_cell_renderer_text_new (); - gtk_tree_view_column_pack_start (column, cell, TRUE); - gtk_tree_view_column_add_attribute (column, cell, - "markup", COL_EVENTS_TEXT); - - cell = gtk_cell_renderer_text_new (); - g_object_set (cell, "xalign", 1.0, NULL); - gtk_tree_view_column_pack_end (column, cell, FALSE); - gtk_tree_view_column_add_attribute (column, cell, - "text", COL_EVENTS_PRETTY_DATE); - - gtk_tree_view_append_column (view, column); - - /* set up treeview properties */ - gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); - gtk_tree_view_set_headers_visible (view, FALSE); - gtk_tree_sortable_set_sort_column_id (sortable, COL_EVENTS_TS, GTK_SORT_ASCENDING); - - gtk_tree_view_set_enable_search (view, FALSE); - - /* set up signals */ - g_signal_connect (selection, "changed", - G_CALLBACK (log_window_events_changed_cb), - self); - - g_signal_connect (view, "row-activated", - G_CALLBACK (log_window_events_row_activated_cb), - self); - - g_object_unref (store); } static void @@ -3033,15 +2982,16 @@ log_window_what_setup (EmpathyLogWindow *self) static void log_window_maybe_expand_events (void) { - GtkTreeView *view; - GtkTreeModel *model; + // GtkTreeView *view; + // GtkTreeModel *model; - view = GTK_TREE_VIEW (log_window->priv->treeview_events); - model = gtk_tree_view_get_model (view); + // FIXME: reimplement + // view = GTK_TREE_VIEW (log_window->priv->treeview_events); + // model = gtk_tree_view_get_model (view); - /* If there's only one result, expand it */ - if (gtk_tree_model_iter_n_children (model, NULL) == 1) - gtk_tree_view_expand_all (view); + // /* If there's only one result, expand it */ + // if (gtk_tree_model_iter_n_children (model, NULL) == 1) + // gtk_tree_view_expand_all (view); } static gboolean @@ -3090,13 +3040,13 @@ log_window_got_messages_for_date_cb (GObject *manager, gpointer user_data) { Ctx *ctx = user_data; - GtkTreeView *view; - GtkTreeModel *model; - GtkTreeIter iter; + // GtkTreeView *view; + // GtkTreeModel *model; + // GtkTreeIter iter; GList *events; GList *l; GError *error = NULL; - gint n; + // gint n; if (log_window == NULL) { @@ -3170,18 +3120,18 @@ log_window_got_messages_for_date_cb (GObject *manager, } g_list_free (events); - view = GTK_TREE_VIEW (log_window->priv->treeview_events); - model = gtk_tree_view_get_model (view); - n = gtk_tree_model_iter_n_children (model, NULL) - 1; + // view = GTK_TREE_VIEW (log_window->priv->treeview_events); + // model = gtk_tree_view_get_model (view); + // n = gtk_tree_model_iter_n_children (model, NULL) - 1; - if (n >= 0 && gtk_tree_model_iter_nth_child (model, &iter, NULL, n)) - { - GtkTreePath *path; + // if (n >= 0 && gtk_tree_model_iter_nth_child (model, &iter, NULL, n)) + // { + // GtkTreePath *path; - path = gtk_tree_model_get_path (model, &iter); - gtk_tree_view_scroll_to_cell (view, path, NULL, FALSE, 0, 0); - gtk_tree_path_free (path); - } + // path = gtk_tree_model_get_path (model, &iter); + // gtk_tree_view_scroll_to_cell (view, path, NULL, FALSE, 0, 0); + // gtk_tree_path_free (path); + // } out: ctx_free (ctx); diff --git a/libempathy-gtk/empathy-log-window.ui b/libempathy-gtk/empathy-log-window.ui index b07e42da5..4a3bc60ae 100644 --- a/libempathy-gtk/empathy-log-window.ui +++ b/libempathy-gtk/empathy-log-window.ui @@ -270,15 +270,6 @@ True True - - - True - True - - - - - -- cgit v1.2.3 From daae637bdf6ea311c306eefe298e5760e2af22dc Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 8 Aug 2011 11:15:06 +1000 Subject: Reimplement log_window_maybe_expand_events() --- libempathy-gtk/empathy-log-window.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index cd1daac22..bb8b1ce42 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -2982,16 +2982,13 @@ log_window_what_setup (EmpathyLogWindow *self) static void log_window_maybe_expand_events (void) { - // GtkTreeView *view; - // GtkTreeModel *model; + GtkTreeModel *model = GTK_TREE_MODEL (log_window->priv->store_events); - // FIXME: reimplement - // view = GTK_TREE_VIEW (log_window->priv->treeview_events); - // model = gtk_tree_view_get_model (view); - - // /* If there's only one result, expand it */ - // if (gtk_tree_model_iter_n_children (model, NULL) == 1) - // gtk_tree_view_expand_all (view); + /* If there's only one result, expand it */ + if (gtk_tree_model_iter_n_children (model, NULL) == 1) + webkit_web_view_execute_script ( + WEBKIT_WEB_VIEW (log_window->priv->webview), + "javascript:expandAll()"); } static gboolean -- cgit v1.2.3 From 3b97f8064e775fd770188b4f186da95706e205f8 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 9 Aug 2011 11:40:53 +1000 Subject: Utility to set the webkit default font/size from GSettings --- libempathy-gtk/empathy-webkit-utils.c | 73 +++++++++++++++++++++++++++++++++++ libempathy-gtk/empathy-webkit-utils.h | 4 ++ 2 files changed, 77 insertions(+) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-webkit-utils.c b/libempathy-gtk/empathy-webkit-utils.c index e5d163ae2..827d57e6b 100644 --- a/libempathy-gtk/empathy-webkit-utils.c +++ b/libempathy-gtk/empathy-webkit-utils.c @@ -21,6 +21,8 @@ #include "empathy-webkit-utils.h" #include "empathy-smiley-manager.h" +#define BORING_DPI_DEFAULT 96 + static void empathy_webkit_match_newline (const gchar *text, gssize len, @@ -89,3 +91,74 @@ empathy_webkit_get_string_parser (gboolean smileys) else return string_parsers; } + +static gboolean +webkit_get_font_family (GValue *value, + GVariant *variant, + gpointer user_data) +{ + PangoFontDescription *font = pango_font_description_from_string ( + g_variant_get_string (variant, NULL)); + + if (font == NULL) + return FALSE; + + g_value_set_string (value, pango_font_description_get_family (font)); + pango_font_description_free (font); + + return TRUE; +} + +static gboolean +webkit_get_font_size (GValue *value, + GVariant *variant, + gpointer user_data) +{ + PangoFontDescription *font = pango_font_description_from_string ( + g_variant_get_string (variant, NULL)); + int size; + + if (font == NULL) + return FALSE; + + size = pango_font_description_get_size (font) / PANGO_SCALE; + + if (pango_font_description_get_size_is_absolute (font)) + { + GdkScreen *screen = gdk_screen_get_default (); + double dpi; + + if (screen != NULL) + dpi = gdk_screen_get_resolution (screen); + else + dpi = BORING_DPI_DEFAULT; + + size = (gint) (size / (dpi / 72)); + } + + g_value_set_int (value, size); + pango_font_description_free (font); + + return TRUE; +} + +void +empathy_webkit_bind_font_setting (WebKitWebView *webview, + GSettings *gsettings, + const char *key) +{ + WebKitWebSettings *settings = webkit_web_view_get_settings (webview); + + g_settings_bind_with_mapping (gsettings, key, + settings, "default-font-family", + G_SETTINGS_BIND_GET, + webkit_get_font_family, + NULL, + NULL, NULL); + g_settings_bind_with_mapping (gsettings, key, + settings, "default-font-size", + G_SETTINGS_BIND_GET, + webkit_get_font_size, + NULL, + NULL, NULL); +} diff --git a/libempathy-gtk/empathy-webkit-utils.h b/libempathy-gtk/empathy-webkit-utils.h index 38cbfedcb..5ba0a840a 100644 --- a/libempathy-gtk/empathy-webkit-utils.h +++ b/libempathy-gtk/empathy-webkit-utils.h @@ -21,11 +21,15 @@ #ifndef _EMPATHY_WEBKIT_UTILS__H_ #define _EMPATHY_WEBKIT_UTILS__H_ +#include + #include "empathy-string-parser.h" G_BEGIN_DECLS EmpathyStringParser *empathy_webkit_get_string_parser (gboolean smileys); +void empathy_webkit_bind_font_setting (WebKitWebView *webview, + GSettings *gsettings, const char *key); G_END_DECLS -- cgit v1.2.3 From a23b86b6a47b06cc9b37cafd892b73229c2d97d3 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 9 Aug 2011 11:41:11 +1000 Subject: Use this utility in the log viewer It should also be used for the Adium theme, but this also supports fonts specified in the Adium theme, which we need to support. --- libempathy-gtk/empathy-log-window.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index bb8b1ce42..fdf433307 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -123,6 +123,7 @@ struct _EmpathyLogWindowPriv gboolean selected_is_chatroom; GSettings *gsettings_chat; + GSettings *gsettings_desktop; }; static void log_window_search_entry_changed_cb (GtkWidget *entry, @@ -548,7 +549,9 @@ empathy_log_window_dispose (GObject *object) tp_clear_object (&self->priv->selected_account); tp_clear_object (&self->priv->selected_contact); tp_clear_object (&self->priv->camera_monitor); + tp_clear_object (&self->priv->gsettings_chat); + tp_clear_object (&self->priv->gsettings_desktop); tp_clear_object (&self->priv->store_events); @@ -600,6 +603,8 @@ empathy_log_window_init (EmpathyLogWindow *self) self->priv->log_manager = tpl_log_manager_dup_singleton (); self->priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA); + self->priv->gsettings_desktop = g_settings_new ( + EMPATHY_PREFS_DESKTOP_INTERFACE_SCHEMA); gtk_window_set_title (GTK_WINDOW (self), _("History")); gtk_widget_set_can_focus (GTK_WIDGET (self), FALSE); @@ -718,6 +723,10 @@ empathy_log_window_init (EmpathyLogWindow *self) self->priv->webview); gtk_widget_show (self->priv->webview); + empathy_webkit_bind_font_setting (WEBKIT_WEB_VIEW (self->priv->webview), + self->priv->gsettings_desktop, + EMPATHY_PREFS_DESKTOP_INTERFACE_FONT_NAME); + filename = empathy_file_lookup ("empathy-log-window.html", "data"); gfile = g_file_new_for_path (filename); g_free (filename); -- cgit v1.2.3 From 356bb4555e3d1eacd8115cb8a8f0c91483055a52 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 9 Aug 2011 11:50:33 +1000 Subject: Use the same font-setting utility for empathy-theme-adium --- libempathy-gtk/empathy-theme-adium.c | 77 +++++++----------------------------- 1 file changed, 15 insertions(+), 62 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index 874f5592f..e5227f506 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -65,7 +65,10 @@ typedef struct { * marker for when we lose focus. */ GQueue acked_messages; GtkWidget *inspector_window; + GSettings *gsettings_chat; + GSettings *gsettings_desktop; + gboolean has_focus; gboolean has_unread_message; gboolean allow_scrolling; @@ -1463,7 +1466,9 @@ theme_adium_finalize (GObject *object) EmpathyThemeAdiumPriv *priv = GET_PRIV (object); empathy_adium_data_unref (priv->data); + g_object_unref (priv->gsettings_chat); + g_object_unref (priv->gsettings_desktop); G_OBJECT_CLASS (empathy_theme_adium_parent_class)->finalize (object); } @@ -1560,64 +1565,6 @@ theme_adium_inspect_web_view_cb (WebKitWebInspector *inspector, return NULL; } -static PangoFontDescription * -theme_adium_get_default_font (void) -{ - GSettings *gsettings; - PangoFontDescription *pango_fd; - gchar *font_family; - - gsettings = g_settings_new (EMPATHY_PREFS_DESKTOP_INTERFACE_SCHEMA); - - font_family = g_settings_get_string (gsettings, - EMPATHY_PREFS_DESKTOP_INTERFACE_DOCUMENT_FONT_NAME); - - if (font_family == NULL) - return NULL; - - pango_fd = pango_font_description_from_string (font_family); - g_free (font_family); - g_object_unref (gsettings); - return pango_fd; -} - -static void -theme_adium_set_webkit_font (WebKitWebSettings *w_settings, - const gchar *name, - gint size) -{ - g_object_set (w_settings, "default-font-family", name, NULL); - g_object_set (w_settings, "default-font-size", size, NULL); -} - -static void -theme_adium_set_default_font (WebKitWebSettings *w_settings) -{ - PangoFontDescription *default_font_desc; - GdkScreen *current_screen; - gdouble dpi = 0; - gint pango_font_size = 0; - - default_font_desc = theme_adium_get_default_font (); - if (default_font_desc == NULL) - return ; - pango_font_size = pango_font_description_get_size (default_font_desc) - / PANGO_SCALE ; - if (pango_font_description_get_size_is_absolute (default_font_desc)) { - current_screen = gdk_screen_get_default (); - if (current_screen != NULL) { - dpi = gdk_screen_get_resolution (current_screen); - } else { - dpi = BORING_DPI_DEFAULT; - } - pango_font_size = (gint) (pango_font_size / (dpi / 72)); - } - theme_adium_set_webkit_font (w_settings, - pango_font_description_get_family (default_font_desc), - pango_font_size); - pango_font_description_free (default_font_desc); -} - static void theme_adium_constructed (GObject *object) { @@ -1625,18 +1572,21 @@ theme_adium_constructed (GObject *object) const gchar *font_family = NULL; gint font_size = 0; WebKitWebView *webkit_view = WEBKIT_WEB_VIEW (object); - WebKitWebSettings *webkit_settings; WebKitWebInspector *webkit_inspector; /* Set default settings */ font_family = tp_asv_get_string (priv->data->info, "DefaultFontFamily"); font_size = tp_asv_get_int32 (priv->data->info, "DefaultFontSize", NULL); - webkit_settings = webkit_web_view_get_settings (webkit_view); if (font_family && font_size) { - theme_adium_set_webkit_font (webkit_settings, font_family, font_size); + g_object_set (webkit_web_view_get_settings (webkit_view), + "default-font-family", font_family, + "default-font-size", font_size, + NULL); } else { - theme_adium_set_default_font (webkit_settings); + empathy_webkit_bind_font_setting (webkit_view, + priv->gsettings_desktop, + EMPATHY_PREFS_DESKTOP_INTERFACE_DOCUMENT_FONT_NAME); } /* Setup webkit inspector */ @@ -1758,6 +1708,9 @@ empathy_theme_adium_init (EmpathyThemeAdium *theme) NULL); priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA); + priv->gsettings_desktop = g_settings_new ( + EMPATHY_PREFS_DESKTOP_INTERFACE_SCHEMA); + g_signal_connect (priv->gsettings_chat, "changed::" EMPATHY_PREFS_CHAT_WEBKIT_DEVELOPER_TOOLS, G_CALLBACK (theme_adium_notify_enable_webkit_developer_tools_cb), -- cgit v1.2.3 From 4133101266b116d34b04a69e9957c0502daf72e8 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 9 Aug 2011 14:05:28 +1000 Subject: Add dates to new log viewer --- libempathy-gtk/empathy-log-window.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index fdf433307..f2aafda31 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -375,16 +375,18 @@ insert_or_change_row (EmpathyLogWindow *self, GtkTreeIter *iter) { char *str = gtk_tree_path_to_string (path); - char *script, *text; + char *script, *text, *date; gtk_tree_model_get (model, iter, COL_EVENTS_TEXT, &text, + COL_EVENTS_PRETTY_DATE, &date, -1); - script = g_strdup_printf ("javascript:%s([%s], '%s');", + script = g_strdup_printf ("javascript:%s([%s], '%s', '%s');", method, g_strdelimit (str, ":", ','), - text); + text, + date); // g_print ("%s\n", script); webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self->priv->webview), @@ -392,6 +394,7 @@ insert_or_change_row (EmpathyLogWindow *self, g_free (str); g_free (text); + g_free (date); g_free (script); } -- cgit v1.2.3 From 14899f2d17dd5943b28fb83e79aa998125159fff Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 9 Aug 2011 14:21:35 +1000 Subject: Add icons to the new log viewer --- libempathy-gtk/empathy-log-window.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index f2aafda31..ba634205b 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -375,17 +375,33 @@ insert_or_change_row (EmpathyLogWindow *self, GtkTreeIter *iter) { char *str = gtk_tree_path_to_string (path); - char *script, *text, *date; + char *script, *text, *date, *stock_icon; + char *icon = NULL; gtk_tree_model_get (model, iter, COL_EVENTS_TEXT, &text, COL_EVENTS_PRETTY_DATE, &date, + COL_EVENTS_ICON, &stock_icon, -1); - script = g_strdup_printf ("javascript:%s([%s], '%s', '%s');", + if (!tp_str_empty (stock_icon)) + { + GtkIconInfo *icon_info = gtk_icon_theme_lookup_icon ( + gtk_icon_theme_get_default (), + stock_icon, + GTK_ICON_SIZE_MENU, 0); + + if (icon_info != NULL) + icon = g_strdup (gtk_icon_info_get_filename (icon_info)); + + gtk_icon_info_free (icon_info); + } + + script = g_strdup_printf ("javascript:%s([%s], '%s', '%s', '%s');", method, g_strdelimit (str, ":", ','), text, + icon != NULL ? icon: "", date); // g_print ("%s\n", script); @@ -395,6 +411,8 @@ insert_or_change_row (EmpathyLogWindow *self, g_free (str); g_free (text); g_free (date); + g_free (stock_icon); + g_free (icon); g_free (script); } -- cgit v1.2.3 From a5992fcfddf42b53ef8d6446b824780512f529b9 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 9 Aug 2011 14:37:16 +1000 Subject: Set the primary toolbar style --- libempathy-gtk/empathy-log-window.ui | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.ui b/libempathy-gtk/empathy-log-window.ui index 4a3bc60ae..08af5b65b 100644 --- a/libempathy-gtk/empathy-log-window.ui +++ b/libempathy-gtk/empathy-log-window.ui @@ -69,6 +69,9 @@ True False both + True -- cgit v1.2.3 From dccd3368d1ee4d4cf4c96628f81ba4bd184e7461 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 9 Aug 2011 14:44:04 +1000 Subject: Remove old code --- libempathy-gtk/empathy-log-window.c | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index ba634205b..b0910532d 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -404,7 +404,6 @@ insert_or_change_row (EmpathyLogWindow *self, icon != NULL ? icon: "", date); - // g_print ("%s\n", script); webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self->priv->webview), script); @@ -445,7 +444,6 @@ store_events_row_deleted (GtkTreeModel *model, script = g_strdup_printf ("javascript:deleteRow([%s]);", g_strdelimit (str, ":", ',')); - // g_print ("%s\n", script); webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self->priv->webview), script); @@ -466,7 +464,6 @@ store_events_has_child_rows (GtkTreeModel *model, g_strdelimit (str, ":", ','), gtk_tree_model_iter_has_child (model, iter)); - // g_print ("%s\n", script); webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self->priv->webview), script); @@ -2517,18 +2514,6 @@ who_row_is_separator (GtkTreeModel *model, // log_window_update_buttons_sensitivity (self); // } -// static void -// log_window_events_row_activated_cb (GtkTreeView *view, -// GtkTreePath *path, -// GtkTreeViewColumn *column, -// EmpathyLogWindow *self) -// { -// if (gtk_tree_view_row_expanded (view, path)) -// gtk_tree_view_collapse_row (view, path); -// else -// gtk_tree_view_expand_row (view, path, FALSE); -// } - static void log_window_events_setup (EmpathyLogWindow *self) { -- cgit v1.2.3 From 3dfc7d6b26f17b0b00762b3fe7b509d7be73b30f Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 12 Aug 2011 08:42:04 +1000 Subject: Remove unused variable --- libempathy-gtk/empathy-log-window.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index b0910532d..a27b238e5 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -2517,7 +2517,6 @@ who_row_is_separator (GtkTreeModel *model, static void log_window_events_setup (EmpathyLogWindow *self) { - GtkTreeModel *model; GtkTreeSortable *sortable; GtkTreeStore *store; @@ -2532,7 +2531,6 @@ log_window_events_setup (EmpathyLogWindow *self) TPL_TYPE_ENTITY, /* target */ TPL_TYPE_EVENT); /* event */ - model = GTK_TREE_MODEL (store); sortable = GTK_TREE_SORTABLE (store); gtk_tree_sortable_set_sort_column_id (sortable, -- cgit v1.2.3 From d5024011258a052ea3b88e95d0098f3901bb98cc Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 12 Aug 2011 08:47:48 +1000 Subject: Style fix --- libempathy-gtk/empathy-log-window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index a27b238e5..bbf9e0480 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -401,7 +401,7 @@ insert_or_change_row (EmpathyLogWindow *self, method, g_strdelimit (str, ":", ','), text, - icon != NULL ? icon: "", + icon != NULL ? icon : "", date); webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self->priv->webview), -- cgit v1.2.3 From 6cf57d879945059cd974a3ee6d02d81edff47438 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 16 Aug 2011 13:38:23 +1000 Subject: Make WebKit compulsory It is now required for the log viewer, furthermore it will be required once we remove non-adium themes. --- libempathy-gtk/Makefile.am | 37 ++++++++++------------------------ libempathy-gtk/empathy-log-window.c | 1 - libempathy-gtk/empathy-theme-manager.c | 21 ------------------- 3 files changed, 11 insertions(+), 48 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index f12230def..fd895d508 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -14,7 +14,6 @@ AM_CPPFLAGS = \ $(GEOCLUE_CFLAGS) \ $(GEOCODE_CFLAGS) \ $(MEEGO_CFLAGS) \ - $(WEBKIT_CFLAGS) \ $(CHEESE_CFLAGS) \ $(WARN_CFLAGS) \ $(DISABLE_DEPRECATED) @@ -88,7 +87,11 @@ libempathy_gtk_handwritten_source = \ empathy-theme-irc.c \ empathy-theme-manager.c \ empathy-tls-dialog.c \ - empathy-ui-utils.c + empathy-ui-utils.c \ + empathy-plist.c \ + empathy-theme-adium.c \ + empathy-webkit-utils.c \ + $(NULL) libempathy_gtk_headers = \ empathy-account-chooser.h \ @@ -150,7 +153,12 @@ libempathy_gtk_headers = \ empathy-theme-irc.h \ empathy-theme-manager.h \ empathy-tls-dialog.h \ - empathy-ui-utils.h + empathy-ui-utils.h \ + empathy-plist.h \ + empathy-theme-adium.h \ + empathy-webkit-utils.h \ + $(NULL) + libempathy_gtk_la_SOURCES = \ $(libempathy_gtk_handwritten_source) \ @@ -173,7 +181,6 @@ libempathy_gtk_la_LIBADD = \ $(GEOCODE_LIBS) \ $(GCR_LIBS) \ $(MEEGO_LIBS) \ - $(WEBKIT_LIBS) \ $(CHEESE_LIBS) \ $(top_builddir)/libempathy/libempathy.la @@ -276,28 +283,6 @@ EXTRA_DIST += \ empathy-location-manager.h endif -if HAVE_WEBKIT -libempathy_gtk_handwritten_source += \ - empathy-plist.c \ - empathy-theme-adium.c \ - empathy-webkit-utils.c \ - $(NULL) -libempathy_gtk_headers += \ - empathy-plist.h \ - empathy-theme-adium.h \ - empathy-webkit-utils.h \ - $(NULL) -else -EXTRA_DIST += \ - empathy-plist.c \ - empathy-plist.h \ - empathy-theme-adium.c \ - empathy-theme-adium.h \ - empathy-webkit-utils.c \ - empathy-webkit-utils.h \ - $(NULL) -endif - CLEANFILES = \ $(BUILT_SOURCES) \ stamp-empathy-gtk-enum-types.h diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index bbf9e0480..ac05740cf 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -61,7 +61,6 @@ #include "empathy-images.h" #include "empathy-theme-manager.h" #include "empathy-ui-utils.h" -// FIXME: this work forces a dependency on webkit #include "empathy-webkit-utils.h" #define DEBUG_FLAG EMPATHY_DEBUG_OTHER diff --git a/libempathy-gtk/empathy-theme-manager.c b/libempathy-gtk/empathy-theme-manager.c index 2a6c393f2..c771392b9 100644 --- a/libempathy-gtk/empathy-theme-manager.c +++ b/libempathy-gtk/empathy-theme-manager.c @@ -39,10 +39,7 @@ #include "empathy-chat-text-view.h" #include "empathy-theme-boxes.h" #include "empathy-theme-irc.h" - -#ifdef HAVE_WEBKIT #include "empathy-theme-adium.h" -#endif #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include @@ -56,12 +53,10 @@ typedef struct { guint emit_changed_idle; gboolean in_constructor; -#ifdef HAVE_WEBKIT EmpathyAdiumData *adium_data; gchar *adium_variant; /* list of weakref to EmpathyThemeAdium objects */ GList *adium_views; -#endif } EmpathyThemeManagerPriv; enum { @@ -85,7 +80,6 @@ static gboolean theme_manager_emit_changed_idle_cb (gpointer manager) { EmpathyThemeManagerPriv *priv = GET_PRIV (manager); -#ifdef HAVE_WEBKIT const gchar *adium_path = NULL; if (priv->adium_data) { @@ -94,7 +88,6 @@ theme_manager_emit_changed_idle_cb (gpointer manager) DEBUG ("Emit theme-changed with: name='%s' adium_path='%s' " "adium_variant='%s'", priv->name, adium_path, priv->adium_variant); -#endif /* HAVE_WEBKIT */ g_signal_emit (manager, signals[THEME_CHANGED], 0, NULL); priv->emit_changed_idle = 0; @@ -371,7 +364,6 @@ theme_manager_update_boxes_theme (EmpathyThemeManager *manager, } } -#ifdef HAVE_WEBKIT static EmpathyThemeAdium * theme_manager_create_adium_view (EmpathyThemeManager *manager) { @@ -451,7 +443,6 @@ theme_manager_notify_adium_variant_cb (GSettings *gsettings_chat, priv->adium_variant); } } -#endif /* HAVE_WEBKIT */ EmpathyChatView * empathy_theme_manager_create_view (EmpathyThemeManager *manager) @@ -463,11 +454,9 @@ empathy_theme_manager_create_view (EmpathyThemeManager *manager) DEBUG ("Using theme %s", priv->name); -#ifdef HAVE_WEBKIT if (strcmp (priv->name, "adium") == 0 && priv->adium_data != NULL) { return EMPATHY_CHAT_VIEW (theme_manager_create_adium_view (manager)); } -#endif if (strcmp (priv->name, "classic") == 0) { return EMPATHY_CHAT_VIEW (theme_manager_create_irc_view (manager)); @@ -583,11 +572,9 @@ theme_manager_finalize (GObject *object) clear_list_of_views (&priv->boxes_views); -#ifdef HAVE_WEBKIT clear_list_of_views (&priv->adium_views); g_free (priv->adium_variant); tp_clear_pointer (&priv->adium_data, empathy_adium_data_unref); -#endif G_OBJECT_CLASS (empathy_theme_manager_parent_class)->finalize (object); } @@ -632,7 +619,6 @@ empathy_theme_manager_init (EmpathyThemeManager *manager) EMPATHY_PREFS_CHAT_THEME, manager); -#ifdef HAVE_WEBKIT /* Take the adium path/variant and track changes */ g_signal_connect (priv->gsettings_chat, "changed::" EMPATHY_PREFS_CHAT_ADIUM_PATH, @@ -649,7 +635,6 @@ empathy_theme_manager_init (EmpathyThemeManager *manager) theme_manager_notify_adium_variant_cb (priv->gsettings_chat, EMPATHY_PREFS_CHAT_THEME_VARIANT, manager); -#endif priv->in_constructor = FALSE; } @@ -674,7 +659,6 @@ empathy_theme_manager_get_themes (void) return themes; } -#ifdef HAVE_WEBKIT static void find_themes (GList **list, const gchar *dirpath) { @@ -705,12 +689,10 @@ find_themes (GList **list, const gchar *dirpath) g_error_free (error); } } -#endif /* HAVE_WEBKIT */ GList * empathy_theme_manager_get_adium_themes (void) { -#ifdef HAVE_WEBKIT GList *themes_list = NULL; gchar *userpath = NULL; const gchar *const *paths = NULL; @@ -729,7 +711,4 @@ empathy_theme_manager_get_adium_themes (void) } return themes_list; -#else - return NULL; -#endif /* HAVE_WEBKIT */ } -- cgit v1.2.3 From 9d1f95bebe28683a23f56568539ee2c56655b80c Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 16 Aug 2011 13:55:56 +1000 Subject: Reimplement scrollToRow N.B. This has not been properly tested, because I'm not actually sure how to exhaust this codepath. --- libempathy-gtk/empathy-log-window.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index ac05740cf..b4501af57 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -3049,13 +3049,12 @@ log_window_got_messages_for_date_cb (GObject *manager, gpointer user_data) { Ctx *ctx = user_data; - // GtkTreeView *view; - // GtkTreeModel *model; - // GtkTreeIter iter; + GtkTreeModel *model; + GtkTreeIter iter; GList *events; GList *l; GError *error = NULL; - // gint n; + gint n; if (log_window == NULL) { @@ -3129,18 +3128,28 @@ log_window_got_messages_for_date_cb (GObject *manager, } g_list_free (events); - // view = GTK_TREE_VIEW (log_window->priv->treeview_events); - // model = gtk_tree_view_get_model (view); - // n = gtk_tree_model_iter_n_children (model, NULL) - 1; + model = GTK_TREE_MODEL (log_window->priv->store_events); + n = gtk_tree_model_iter_n_children (model, NULL) - 1; + + if (n >= 0 && gtk_tree_model_iter_nth_child (model, &iter, NULL, n)) + { + GtkTreePath *path; + char *str, *script; + + path = gtk_tree_model_get_path (model, &iter); + str = gtk_tree_path_to_string (path); - // if (n >= 0 && gtk_tree_model_iter_nth_child (model, &iter, NULL, n)) - // { - // GtkTreePath *path; + script = g_strdup_printf ("javascript:scrollToRow([%s]);", + g_strdelimit (str, ":", ',')); - // path = gtk_tree_model_get_path (model, &iter); - // gtk_tree_view_scroll_to_cell (view, path, NULL, FALSE, 0, 0); - // gtk_tree_path_free (path); - // } + webkit_web_view_execute_script ( + WEBKIT_WEB_VIEW (log_window->priv->webview), + script); + + gtk_tree_path_free (path); + g_free (str); + g_free (script); + } out: ctx_free (ctx); -- cgit v1.2.3 From ede83c3b09c25b9e08c0aa54d842d844b582e0d8 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Tue, 16 Aug 2011 16:15:38 +1000 Subject: Allow clicking on a row to select the contact Does not currently highlight the row. --- libempathy-gtk/empathy-log-window.c | 112 ++++++++++++++++++++++++++---------- 1 file changed, 83 insertions(+), 29 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index b4501af57..c4a260889 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -66,6 +66,8 @@ #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include +#define EMPATHY_NS "http://live.gnome.org/Empathy" + G_DEFINE_TYPE (EmpathyLogWindow, empathy_log_window, GTK_TYPE_WINDOW); struct _EmpathyLogWindowPriv @@ -105,6 +107,7 @@ struct _EmpathyLogWindowPriv TpBaseClient *observer; EmpathyContact *selected_contact; + EmpathyContact *events_contact; EmpathyCameraMonitor *camera_monitor; GBinding *button_video_binding; @@ -150,6 +153,9 @@ static void log_window_delete_menu_clicked_cb (GtkMenuItem *menuitem, static void start_spinner (void); static void log_window_create_observer (EmpathyLogWindow *window); +static gboolean log_window_events_button_press_event (GtkWidget *webview, + GdkEventButton *event, EmpathyLogWindow *self); +static void log_window_update_buttons_sensitivity (EmpathyLogWindow *self); static void empathy_account_chooser_filter_has_logs (TpAccount *account, @@ -565,6 +571,7 @@ empathy_log_window_dispose (GObject *object) tp_clear_object (&self->priv->log_manager); tp_clear_object (&self->priv->selected_account); tp_clear_object (&self->priv->selected_contact); + tp_clear_object (&self->priv->events_contact); tp_clear_object (&self->priv->camera_monitor); tp_clear_object (&self->priv->gsettings_chat); @@ -768,6 +775,11 @@ empathy_log_window_init (EmpathyLogWindow *self) g_signal_connect (self->priv->store_events, "row-has-child-toggled", G_CALLBACK (store_events_has_child_rows), self); + /* track clicked row */ + g_signal_connect (self->priv->webview, "button-press-event", + G_CALLBACK (log_window_events_button_press_event), self); + + log_window_update_buttons_sensitivity (self); gtk_widget_show (GTK_WIDGET (self)); } @@ -2039,8 +2051,10 @@ log_window_update_buttons_sensitivity (EmpathyLogWindow *self) GtkTreePath *path; gboolean profile, chat, call, video; - tp_clear_object (&self->priv->selected_contact); + profile = chat = call = video = FALSE; + tp_clear_object (&self->priv->button_video_binding); + tp_clear_object (&self->priv->selected_contact); view = GTK_TREE_VIEW (self->priv->treeview_who); model = gtk_tree_view_get_model (view); @@ -2087,27 +2101,11 @@ log_window_update_buttons_sensitivity (EmpathyLogWindow *self) /* If the Who pane doesn't contain a contact (e.g. it has many * selected, or has 'Anyone', let's try to get the contact from * the selected event. */ - goto out; // FIXME: reimplement - // view = GTK_TREE_VIEW (self->priv->treeview_events); - // model = gtk_tree_view_get_model (view); - // selection = gtk_tree_view_get_selection (view); - // if (gtk_tree_selection_count_selected_rows (selection) != 1) - // goto out; - - // if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) - // goto out; - - gtk_tree_model_get (model, &iter, - COL_EVENTS_ACCOUNT, &account, - COL_EVENTS_TARGET, &target, - -1); - - self->priv->selected_contact = empathy_contact_from_tpl_contact (account, - target); - - g_object_unref (account); - g_object_unref (target); + if (self->priv->events_contact != NULL) + self->priv->selected_contact = g_object_ref (self->priv->events_contact); + else + goto out; capabilities = empathy_contact_get_capabilities (self->priv->selected_contact); @@ -2504,14 +2502,70 @@ who_row_is_separator (GtkTreeModel *model, return (type == COL_TYPE_SEPARATOR); } -// static void -// log_window_events_changed_cb (GtkTreeSelection *selection, -// EmpathyLogWindow *self) -// { -// DEBUG ("log_window_events_changed_cb"); -// -// log_window_update_buttons_sensitivity (self); -// } +static gboolean +log_window_events_button_press_event (GtkWidget *webview, + GdkEventButton *event, + EmpathyLogWindow *self) +{ + WebKitHitTestResult *hit = webkit_web_view_get_hit_test_result ( + WEBKIT_WEB_VIEW (webview), event); + WebKitDOMNode *inner_node; + + tp_clear_object (&self->priv->events_contact); + + g_object_get (hit, + "inner-node", &inner_node, + NULL); + + if (inner_node != NULL) + { + GtkTreeModel *model = GTK_TREE_MODEL (self->priv->store_events); + WebKitDOMNode *node; + const char *path = NULL; + GtkTreeIter iter; + + /* walk back up the DOM tree looking for a node with empathy:path set */ + for (node = inner_node; node != NULL; + node = webkit_dom_node_get_parent_node (node)) + { + if (!WEBKIT_DOM_IS_ELEMENT (node)) + continue; + + path = webkit_dom_element_get_attribute_ns ( + WEBKIT_DOM_ELEMENT (node), EMPATHY_NS, "path"); + + if (!tp_str_empty (path)) + break; + } + + /* look up the contact for this path */ + if (!tp_str_empty (path) && + gtk_tree_model_get_iter_from_string (model, &iter, path)) + { + TpAccount *account; + TplEntity *target; + + gtk_tree_model_get (model, &iter, + COL_EVENTS_ACCOUNT, &account, + COL_EVENTS_TARGET, &target, + -1); + + self->priv->events_contact = empathy_contact_from_tpl_contact ( + account, target); + + g_object_unref (account); + g_object_unref (target); + } + + g_object_unref (inner_node); + } + + g_object_unref (hit); + + log_window_update_buttons_sensitivity (self); + + return FALSE; +} static void log_window_events_setup (EmpathyLogWindow *self) -- cgit v1.2.3 From 1ba7c298c282b4775c29c80214009876e943648d Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Wed, 17 Aug 2011 15:37:09 +1000 Subject: Factor out WebKit context menu as a utility --- libempathy-gtk/empathy-theme-adium.c | 121 +----------------------------- libempathy-gtk/empathy-webkit-utils.c | 136 ++++++++++++++++++++++++++++++++++ libempathy-gtk/empathy-webkit-utils.h | 6 ++ 3 files changed, 145 insertions(+), 118 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index e5227f506..4e32630d5 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -212,39 +212,6 @@ theme_adium_navigation_policy_decision_requested_cb (WebKitWebView * return TRUE; } -static void -theme_adium_copy_address_cb (GtkMenuItem *menuitem, - gpointer user_data) -{ - WebKitHitTestResult *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data); - gchar *uri; - GtkClipboard *clipboard; - - g_object_get (G_OBJECT (hit_test_result), "link-uri", &uri, NULL); - - clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); - gtk_clipboard_set_text (clipboard, uri, -1); - - clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY); - gtk_clipboard_set_text (clipboard, uri, -1); - - g_free (uri); -} - -static void -theme_adium_open_address_cb (GtkMenuItem *menuitem, - gpointer user_data) -{ - WebKitHitTestResult *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data); - gchar *uri; - - g_object_get (G_OBJECT (hit_test_result), "link-uri", &uri, NULL); - - empathy_url_show (GTK_WIDGET (menuitem), uri); - - g_free (uri); -} - /* Replace each %@ in format with string passed in args */ static gchar * string_with_format (const gchar *format, @@ -1296,90 +1263,6 @@ theme_adium_message_acknowledged (EmpathyChatView *view, theme_adium_remove_mark_from_message (self, id); } -static void -theme_adium_context_menu_selection_done_cb (GtkMenuShell *menu, gpointer user_data) -{ - WebKitHitTestResult *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data); - - g_object_unref (hit_test_result); -} - -static void -theme_adium_context_menu_for_event (EmpathyThemeAdium *theme, GdkEventButton *event) -{ - WebKitWebView *view = WEBKIT_WEB_VIEW (theme); - WebKitHitTestResult *hit_test_result; - WebKitHitTestResultContext context; - GtkWidget *menu; - GtkWidget *item; - - hit_test_result = webkit_web_view_get_hit_test_result (view, event); - g_object_get (G_OBJECT (hit_test_result), "context", &context, NULL); - - /* The menu */ - menu = empathy_context_menu_new (GTK_WIDGET (view)); - - /* Select all item */ - item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL); - gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); - - g_signal_connect_swapped (item, "activate", - G_CALLBACK (webkit_web_view_select_all), - view); - - /* Copy menu item */ - if (webkit_web_view_can_copy_clipboard (view)) { - item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL); - gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); - - g_signal_connect_swapped (item, "activate", - G_CALLBACK (webkit_web_view_copy_clipboard), - view); - } - - /* Clear menu item */ - item = gtk_separator_menu_item_new (); - gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); - - item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL); - gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); - - g_signal_connect_swapped (item, "activate", - G_CALLBACK (empathy_chat_view_clear), - view); - - /* We will only add the following menu items if we are - * right-clicking a link */ - if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) { - /* Separator */ - item = gtk_separator_menu_item_new (); - gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); - - /* Copy Link Address menu item */ - item = gtk_menu_item_new_with_mnemonic (_("_Copy Link Address")); - g_signal_connect (item, "activate", - G_CALLBACK (theme_adium_copy_address_cb), - hit_test_result); - gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); - - /* Open Link menu item */ - item = gtk_menu_item_new_with_mnemonic (_("_Open Link")); - g_signal_connect (item, "activate", - G_CALLBACK (theme_adium_open_address_cb), - hit_test_result); - gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); - } - - g_signal_connect (GTK_MENU_SHELL (menu), "selection-done", - G_CALLBACK (theme_adium_context_menu_selection_done_cb), - hit_test_result); - - /* Display the menu */ - gtk_widget_show_all (menu); - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, - event->button, event->time); -} - static gboolean theme_adium_button_press_event (GtkWidget *widget, GdkEventButton *event) { @@ -1393,7 +1276,9 @@ theme_adium_button_press_event (GtkWidget *widget, GdkEventButton *event) * item ourselves, so we disable our customized menu * if the developer extras are enabled. */ if (!developer_tools_enabled) { - theme_adium_context_menu_for_event (EMPATHY_THEME_ADIUM (widget), event); + empathy_webkit_context_menu_for_event ( + WEBKIT_WEB_VIEW (widget), event, + EMPATHY_WEBKIT_MENU_CLEAR); return TRUE; } } diff --git a/libempathy-gtk/empathy-webkit-utils.c b/libempathy-gtk/empathy-webkit-utils.c index 827d57e6b..cac9af9d8 100644 --- a/libempathy-gtk/empathy-webkit-utils.c +++ b/libempathy-gtk/empathy-webkit-utils.c @@ -18,8 +18,13 @@ * Authors: Xavier Claessens */ +#include "config.h" + +#include + #include "empathy-webkit-utils.h" #include "empathy-smiley-manager.h" +#include "empathy-ui-utils.h" #define BORING_DPI_DEFAULT 96 @@ -162,3 +167,134 @@ empathy_webkit_bind_font_setting (WebKitWebView *webview, NULL, NULL, NULL); } + +static void +empathy_webkit_copy_address_cb (GtkMenuItem *menuitem, + gpointer user_data) +{ + WebKitHitTestResult *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data); + gchar *uri; + GtkClipboard *clipboard; + + g_object_get (G_OBJECT (hit_test_result), + "link-uri", &uri, + NULL); + + clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + gtk_clipboard_set_text (clipboard, uri, -1); + + clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY); + gtk_clipboard_set_text (clipboard, uri, -1); + + g_free (uri); +} + +static void +empathy_webkit_open_address_cb (GtkMenuItem *menuitem, + gpointer user_data) +{ + WebKitHitTestResult *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data); + gchar *uri; + + g_object_get (G_OBJECT (hit_test_result), + "link-uri", &uri, + NULL); + + empathy_url_show (GTK_WIDGET (menuitem), uri); + + g_free (uri); +} + +static void +empathy_webkit_context_menu_selection_done_cb (GtkMenuShell *menu, + gpointer user_data) +{ + WebKitHitTestResult *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data); + + g_object_unref (hit_test_result); +} + +void +empathy_webkit_context_menu_for_event (WebKitWebView *view, + GdkEventButton *event, + EmpathyWebKitMenuFlags flags) +{ + WebKitHitTestResult *hit_test_result; + WebKitHitTestResultContext context; + GtkWidget *menu; + GtkWidget *item; + + hit_test_result = webkit_web_view_get_hit_test_result (view, event); + g_object_get (G_OBJECT (hit_test_result), + "context", &context, + NULL); + + /* The menu */ + menu = empathy_context_menu_new (GTK_WIDGET (view)); + + /* Select all item */ + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); + + g_signal_connect_swapped (item, "activate", + G_CALLBACK (webkit_web_view_select_all), + view); + + /* Copy menu item */ + if (webkit_web_view_can_copy_clipboard (view)) + { + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); + + g_signal_connect_swapped (item, "activate", + G_CALLBACK (webkit_web_view_copy_clipboard), + view); + } + + /* Clear menu item */ + if (flags & EMPATHY_WEBKIT_MENU_CLEAR) + { + item = gtk_separator_menu_item_new (); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); + + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); + + g_signal_connect_swapped (item, "activate", + G_CALLBACK (empathy_chat_view_clear), + view); + } + + /* We will only add the following menu items if we are + * right-clicking a link */ + if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) + { + /* Separator */ + item = gtk_separator_menu_item_new (); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); + + /* Copy Link Address menu item */ + item = gtk_menu_item_new_with_mnemonic (_("_Copy Link Address")); + g_signal_connect (item, "activate", + G_CALLBACK (empathy_webkit_copy_address_cb), + hit_test_result); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); + + /* Open Link menu item */ + item = gtk_menu_item_new_with_mnemonic (_("_Open Link")); + g_signal_connect (item, "activate", + G_CALLBACK (empathy_webkit_open_address_cb), + hit_test_result); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); + } + + g_signal_connect (GTK_MENU_SHELL (menu), "selection-done", + G_CALLBACK (empathy_webkit_context_menu_selection_done_cb), + hit_test_result); + + /* Display the menu */ + gtk_widget_show_all (menu); + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, + event->button, event->time); +} + diff --git a/libempathy-gtk/empathy-webkit-utils.h b/libempathy-gtk/empathy-webkit-utils.h index 5ba0a840a..322f94c32 100644 --- a/libempathy-gtk/empathy-webkit-utils.h +++ b/libempathy-gtk/empathy-webkit-utils.h @@ -27,9 +27,15 @@ G_BEGIN_DECLS +typedef enum { + EMPATHY_WEBKIT_MENU_CLEAR = 1 << 0, +} EmpathyWebKitMenuFlags; + EmpathyStringParser *empathy_webkit_get_string_parser (gboolean smileys); void empathy_webkit_bind_font_setting (WebKitWebView *webview, GSettings *gsettings, const char *key); +void empathy_webkit_context_menu_for_event (WebKitWebView *view, + GdkEventButton *event, EmpathyWebKitMenuFlags flags); G_END_DECLS -- cgit v1.2.3 From dc7080f5071a9130bbd9288b50f807b41a5f9864 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Wed, 17 Aug 2011 15:44:22 +1000 Subject: Use context menu utility in log viewer --- libempathy-gtk/empathy-log-window.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index c4a260889..219d0cc11 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -2502,13 +2502,12 @@ who_row_is_separator (GtkTreeModel *model, return (type == COL_TYPE_SEPARATOR); } -static gboolean -log_window_events_button_press_event (GtkWidget *webview, - GdkEventButton *event, - EmpathyLogWindow *self) +static void +log_window_find_row (EmpathyLogWindow *self, + GdkEventButton *event) { WebKitHitTestResult *hit = webkit_web_view_get_hit_test_result ( - WEBKIT_WEB_VIEW (webview), event); + WEBKIT_WEB_VIEW (self->priv->webview), event); WebKitDOMNode *inner_node; tp_clear_object (&self->priv->events_contact); @@ -2563,6 +2562,27 @@ log_window_events_button_press_event (GtkWidget *webview, g_object_unref (hit); log_window_update_buttons_sensitivity (self); +} + +static gboolean +log_window_events_button_press_event (GtkWidget *webview, + GdkEventButton *event, + EmpathyLogWindow *self) +{ + switch (event->button) + { + case 1: + log_window_find_row (self, event); + break; + + case 3: + empathy_webkit_context_menu_for_event ( + WEBKIT_WEB_VIEW (webview), event, 0); + return TRUE; + + default: + break; + } return FALSE; } -- cgit v1.2.3