From c157ac3a330abe4831c4c93e52126a054934b9f6 Mon Sep 17 00:00:00 2001 From: Gustavo Noronha Silva Date: Mon, 29 Jun 2009 17:25:56 -0300 Subject: Fix Bug 585882: Can't easily copy URL's when using Adium themes Track the last hovered link, and use it to copy/open addresses using the context menu. --- libempathy-gtk/empathy-theme-adium.c | 94 ++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 4 deletions(-) (limited to 'libempathy-gtk/empathy-theme-adium.c') diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index b16a3e7c9..d5ea2ed52 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -54,6 +54,7 @@ typedef struct { time_t last_timestamp; gboolean page_loaded; GList *message_queue; + gchar *hovered_uri; } EmpathyThemeAdiumPriv; struct _EmpathyAdiumData { @@ -103,12 +104,72 @@ theme_adium_navigation_requested_cb (WebKitWebView *view, return WEBKIT_NAVIGATION_RESPONSE_IGNORE; } +static void +theme_adium_hovering_over_link_cb (EmpathyThemeAdium *theme, + gchar *title, + gchar *uri, + gpointer user_data) +{ + EmpathyThemeAdiumPriv *priv = GET_PRIV (theme); + + if (tp_strdiff (uri, priv->hovered_uri)) { + g_free (priv->hovered_uri); + priv->hovered_uri = g_strdup (uri); + } +} + +static void +theme_adium_copy_address_cb (GtkMenuItem *menuitem, + gpointer user_data) +{ + EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (user_data); + EmpathyThemeAdiumPriv *priv = GET_PRIV (theme); + GtkClipboard *clipboard; + + clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); + gtk_clipboard_set_text (clipboard, priv->hovered_uri, -1); + + clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY); + gtk_clipboard_set_text (clipboard, priv->hovered_uri, -1); +} + +static void +theme_adium_open_address_cb (GtkMenuItem *menuitem, + gpointer user_data) +{ + EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (user_data); + EmpathyThemeAdiumPriv *priv = GET_PRIV (theme); + + empathy_url_show (GTK_WIDGET (menuitem), priv->hovered_uri); +} + static void theme_adium_populate_popup_cb (WebKitWebView *view, GtkMenu *menu, gpointer user_data) { GtkWidget *item; + GList *items; + GtkWidget *icon; + gchar *stock_id; + gboolean is_link = FALSE; + + /* FIXME: WebKitGTK+'s context menu API clearly needs an + * overhaul. There is currently no way to know what is being + * clicked, to decide what features to provide. You either + * take what it gives you as a menu, or use hacks to figure + * out what to display. */ + items = gtk_container_get_children (GTK_CONTAINER (menu)); + item = GTK_WIDGET (g_list_nth_data (items, 0)); + g_list_free (items); + + if (GTK_IS_IMAGE_MENU_ITEM (item)) { + icon = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (item)); + gtk_image_get_stock (GTK_IMAGE (icon), &stock_id, NULL); + + if (!strcmp (stock_id, GTK_STOCK_OPEN)) + is_link = TRUE; + } /* Remove default menu items */ gtk_container_foreach (GTK_CONTAINER (menu), @@ -147,10 +208,31 @@ theme_adium_populate_popup_cb (WebKitWebView *view, G_CALLBACK (empathy_chat_view_clear), view); - /* FIXME: Add open_link and copy_link when those bugs are fixed: - * https://bugs.webkit.org/show_bug.cgi?id=16092 - * https://bugs.webkit.org/show_bug.cgi?id=16562 - */ + /* We will only add the following menu items if we are + * right-clicking a link */ + if (!is_link) + return; + + /* Separator */ + item = gtk_separator_menu_item_new (); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); + gtk_widget_show (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), + view); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); + gtk_widget_show (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), + view); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); + gtk_widget_show (item); } static gchar * @@ -661,6 +743,7 @@ theme_adium_finalize (GObject *object) EmpathyThemeAdiumPriv *priv = GET_PRIV (object); empathy_adium_data_unref (priv->data); + g_free (priv->hovered_uri); G_OBJECT_CLASS (empathy_theme_adium_parent_class)->finalize (object); } @@ -795,6 +878,9 @@ empathy_theme_adium_init (EmpathyThemeAdium *theme) g_signal_connect (theme, "populate-popup", G_CALLBACK (theme_adium_populate_popup_cb), NULL); + g_signal_connect (theme, "hovering-over-link", + G_CALLBACK (theme_adium_hovering_over_link_cb), + NULL); } EmpathyThemeAdium * -- cgit v1.2.3 From f923e5ed0d36621b580061dbaff834ec7e7ee0bc Mon Sep 17 00:00:00 2001 From: Gustavo Noronha Silva Date: Wed, 1 Jul 2009 10:08:48 -0300 Subject: Fix Bug 585601: Adium theme is not reloaded on /clear or Ctrl+L or clear menu item The theme was deciding that new messages should be 'joined' to an already existing message bubble, because not enough time had passed, even after clearing the chat area. We now clear last_contact to make sure this never happens. --- libempathy-gtk/empathy-theme-adium.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libempathy-gtk/empathy-theme-adium.c') diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index b16a3e7c9..40ae291bf 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -564,6 +564,13 @@ theme_adium_clear (EmpathyChatView *view) priv->data->template_html, basedir_uri); g_free (basedir_uri); + + /* Clear last contact to avoid trying to add a 'joined' + * message when we don't have an insertion point. */ + if (priv->last_contact) { + g_object_unref (priv->last_contact); + priv->last_contact = NULL; + } } static gboolean -- cgit v1.2.3 From 9f148e53e8086daff05f7ce9801a405c61182864 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Beaudoin Date: Mon, 29 Jun 2009 20:07:33 -0400 Subject: List installed adium themes --- libempathy-gtk/empathy-theme-adium.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'libempathy-gtk/empathy-theme-adium.c') diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index aab1f6f3d..0464a6193 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -820,6 +820,15 @@ empathy_adium_path_is_valid (const gchar *path) gboolean ret; gchar *file; + /* The theme is not valid if there is no Info.plist */ + file = g_build_filename (path, "Contents", "Info.plist", + NULL); + ret = g_file_test (file, G_FILE_TEST_EXISTS); + g_free (file); + + if (ret == FALSE) + return ret; + /* We ship a default Template.html as fallback if there is any problem * with the one inside the theme. The only other required file is * Content.html for incoming messages (outgoing fallback to use @@ -845,10 +854,15 @@ empathy_adium_info_new (const gchar *path) value = empathy_plist_parse_from_file (file); g_free (file); - if (value) { - info = g_value_dup_boxed (value); - tp_g_value_slice_free (value); - } + if (value == NULL) + return NULL; + + info = g_value_dup_boxed (value); + tp_g_value_slice_free (value); + + /* Insert the theme's path into the hash table, + * keys have to be dupped */ + tp_asv_set_string (info, g_strdup ("path"), path); return info; } -- cgit v1.2.3 From aff75bcc97abac0173dfd4cc6f9a959fbd493ae6 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 8 Jul 2009 16:36:57 +0100 Subject: Use atomic operations to manage EmpathyAdiumData refcount --- libempathy-gtk/empathy-theme-adium.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'libempathy-gtk/empathy-theme-adium.c') diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index 0464a6193..f37c98841 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -1026,7 +1026,7 @@ empathy_adium_data_ref (EmpathyAdiumData *data) { g_return_val_if_fail (data != NULL, NULL); - data->ref_count++; + g_atomic_int_inc (&data->ref_count); return data; } @@ -1036,8 +1036,7 @@ empathy_adium_data_unref (EmpathyAdiumData *data) { g_return_if_fail (data != NULL); - data->ref_count--; - if (data->ref_count == 0) { + if (g_atomic_int_dec_and_test (&data->ref_count)) { g_free (data->path); g_free (data->basedir); g_free (data->template_html); -- cgit v1.2.3 From ee5227403193fe7b5dae7d5c15e33d8a9c385c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Chieffo?= <84yelo3@gmail.com> Date: Wed, 8 Jul 2009 16:39:17 +0100 Subject: Support for history message in Adium themes. Use context HTMLs. --- libempathy-gtk/empathy-theme-adium.c | 131 +++++++++++++++++++++++++++++------ 1 file changed, 110 insertions(+), 21 deletions(-) (limited to 'libempathy-gtk/empathy-theme-adium.c') diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index f37c98841..d513c91ae 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -52,6 +52,7 @@ typedef struct { EmpathySmileyManager *smiley_manager; EmpathyContact *last_contact; time_t last_timestamp; + gboolean last_is_backlog; gboolean page_loaded; GList *message_queue; } EmpathyThemeAdiumPriv; @@ -66,12 +67,20 @@ struct _EmpathyAdiumData { gchar *template_html; gchar *in_content_html; gsize in_content_len; + gchar *in_context_html; + gsize in_context_len; gchar *in_nextcontent_html; gsize in_nextcontent_len; + gchar *in_nextcontext_html; + gsize in_nextcontext_len; gchar *out_content_html; gsize out_content_len; + gchar *out_context_html; + gsize out_context_len; gchar *out_nextcontent_html; gsize out_nextcontent_len; + gchar *out_nextcontext_html; + gsize out_nextcontext_len; gchar *status_html; gsize status_len; GHashTable *info; @@ -405,7 +414,8 @@ theme_adium_append_message (EmpathyChatView *view, gsize len = 0; const gchar *func; const gchar *service_name; - const gchar *message_classes = NULL; + GString *message_classes = NULL; + gboolean is_backlog; if (!priv->page_loaded) { priv->message_queue = g_list_prepend (priv->message_queue, @@ -458,46 +468,103 @@ theme_adium_append_message (EmpathyChatView *view, avatar_filename = priv->data->default_avatar_filename; } } + + is_backlog = empathy_message_is_backlog (msg); /* Get the right html/func to add the message */ func = "appendMessage"; + + message_classes = g_string_new ("message"); + + /* eventually append the "history" class */ + if (is_backlog) { + g_string_append (message_classes, " history"); + } + + /* check the sender of the message and append the appropriate class */ + if (empathy_contact_is_user (sender)) { + g_string_append (message_classes, " outgoing"); + } + else { + g_string_append (message_classes, " incoming"); + } + /* * To mimick Adium's behavior, we only want to join messages - * sent within a 5 minute time frame. + * sent by the same contact within a 5 minute time frame. */ if (empathy_contact_equal (priv->last_contact, sender) && - (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD)) { + (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD) && + (is_backlog == priv->last_is_backlog)) { + /* the messages can be appended */ func = "appendNextMessage"; + g_string_append (message_classes, " consecutive"); + + /* check who is the sender of the message to use the correct html file */ if (empathy_contact_is_user (sender)) { - message_classes = "consecutive incoming message"; - html = priv->data->out_nextcontent_html; - len = priv->data->out_nextcontent_len; + /* check if this is a backlog message and use NextContext.html */ + if (is_backlog) { + html = priv->data->out_nextcontext_html; + len = priv->data->out_nextcontext_len; + } + + /* + * html is null if this is not a backlog message or + * if we have to fallback (NextContext.html missing). + * use NextContent.html + */ + if (html == NULL) { + html = priv->data->out_nextcontent_html; + len = priv->data->out_nextcontent_len; + } } - if (!html) { - message_classes = "consecutive message outgoing"; - html = priv->data->in_nextcontent_html; - len = priv->data->in_nextcontent_len; + else { + if (is_backlog) { + html = priv->data->in_nextcontext_html; + len = priv->data->in_nextcontext_len; + } + + if (html == NULL) { + html = priv->data->in_nextcontent_html; + len = priv->data->in_nextcontent_len; + } } } - if (!html) { + + /* + * we have html == NULL here if: + * 1. the message didn't have to be appended because + * the sender was different or the timestamp was too far + * 2. NextContent.html file does not exist, so we must + * not forget to fallback to the correct Content.html + */ + if (html == NULL) { if (empathy_contact_is_user (sender)) { - if (!message_classes) { - message_classes = "incoming message"; + if (is_backlog) { + html = priv->data->out_context_html; + len = priv->data->out_context_len; + } + + if (html == NULL) { + html = priv->data->out_content_html; + len = priv->data->out_content_len; } - html = priv->data->out_content_html; - len = priv->data->out_content_len; } - if (!html) { - if (!message_classes) { - message_classes = "message outgoing"; + else { + if (is_backlog) { + html = priv->data->in_context_html; + len = priv->data->in_context_len; + } + + if (html == NULL) { + html = priv->data->in_content_html; + len = priv->data->in_content_len; } - html = priv->data->in_content_html; - len = priv->data->in_content_len; } } theme_adium_append_html (theme, func, html, len, body, avatar_filename, - name, contact_id, service_name, message_classes, + name, contact_id, service_name, message_classes->str, timestamp); /* Keep the sender of the last displayed message */ @@ -506,8 +573,10 @@ theme_adium_append_message (EmpathyChatView *view, } priv->last_contact = g_object_ref (sender); priv->last_timestamp = timestamp; + priv->last_is_backlog = is_backlog; g_free (dup_body); + g_string_free (message_classes, TRUE); } static void @@ -914,6 +983,14 @@ empathy_adium_data_new_with_info (const gchar *path, GHashTable *info) file = g_build_filename (data->basedir, "Incoming", "NextContent.html", NULL); g_file_get_contents (file, &data->in_nextcontent_html, &data->in_nextcontent_len, NULL); g_free (file); + + file = g_build_filename (data->basedir, "Incoming", "Context.html", NULL); + g_file_get_contents (file, &data->in_context_html, &data->in_context_len, NULL); + g_free (file); + + file = g_build_filename (data->basedir, "Incoming", "NextContext.html", NULL); + g_file_get_contents (file, &data->in_nextcontext_html, &data->in_nextcontext_len, NULL); + g_free (file); file = g_build_filename (data->basedir, "Outgoing", "Content.html", NULL); g_file_get_contents (file, &data->out_content_html, &data->out_content_len, NULL); @@ -923,6 +1000,14 @@ empathy_adium_data_new_with_info (const gchar *path, GHashTable *info) g_file_get_contents (file, &data->out_nextcontent_html, &data->out_nextcontent_len, NULL); g_free (file); + file = g_build_filename (data->basedir, "Outgoing", "Context.html", NULL); + g_file_get_contents (file, &data->out_context_html, &data->out_context_len, NULL); + g_free (file); + + file = g_build_filename (data->basedir, "Outgoing", "NextContext.html", NULL); + g_file_get_contents (file, &data->out_nextcontext_html, &data->out_nextcontext_len, NULL); + g_free (file); + file = g_build_filename (data->basedir, "Status.html", NULL); g_file_get_contents (file, &data->status_html, &data->status_len, NULL); g_free (file); @@ -1042,8 +1127,12 @@ empathy_adium_data_unref (EmpathyAdiumData *data) g_free (data->template_html); g_free (data->in_content_html); g_free (data->in_nextcontent_html); + g_free (data->in_context_html); + g_free (data->in_nextcontext_html); g_free (data->out_content_html); g_free (data->out_nextcontent_html); + g_free (data->out_context_html); + g_free (data->out_nextcontext_html); g_free (data->default_avatar_filename); g_free (data->default_incoming_avatar_filename); g_free (data->default_outgoing_avatar_filename); -- cgit v1.2.3 From ecdfee8677647e73662dd86e512c9c36772a282f Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 13 Jul 2009 18:04:37 +0100 Subject: empathy-theme-adium.c: remove trailing spaces --- libempathy-gtk/empathy-theme-adium.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'libempathy-gtk/empathy-theme-adium.c') diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index d513c91ae..37c9f1a56 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -468,19 +468,19 @@ theme_adium_append_message (EmpathyChatView *view, avatar_filename = priv->data->default_avatar_filename; } } - + is_backlog = empathy_message_is_backlog (msg); /* Get the right html/func to add the message */ func = "appendMessage"; - + message_classes = g_string_new ("message"); - + /* eventually append the "history" class */ if (is_backlog) { g_string_append (message_classes, " history"); } - + /* check the sender of the message and append the appropriate class */ if (empathy_contact_is_user (sender)) { g_string_append (message_classes, " outgoing"); @@ -488,18 +488,18 @@ theme_adium_append_message (EmpathyChatView *view, else { g_string_append (message_classes, " incoming"); } - + /* * To mimick Adium's behavior, we only want to join messages * sent by the same contact within a 5 minute time frame. */ if (empathy_contact_equal (priv->last_contact, sender) && - (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD) && + (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD) && (is_backlog == priv->last_is_backlog)) { /* the messages can be appended */ func = "appendNextMessage"; g_string_append (message_classes, " consecutive"); - + /* check who is the sender of the message to use the correct html file */ if (empathy_contact_is_user (sender)) { /* check if this is a backlog message and use NextContext.html */ @@ -507,7 +507,7 @@ theme_adium_append_message (EmpathyChatView *view, html = priv->data->out_nextcontext_html; len = priv->data->out_nextcontext_len; } - + /* * html is null if this is not a backlog message or * if we have to fallback (NextContext.html missing). @@ -523,14 +523,14 @@ theme_adium_append_message (EmpathyChatView *view, html = priv->data->in_nextcontext_html; len = priv->data->in_nextcontext_len; } - + if (html == NULL) { html = priv->data->in_nextcontent_html; len = priv->data->in_nextcontent_len; } } } - + /* * we have html == NULL here if: * 1. the message didn't have to be appended because @@ -544,7 +544,7 @@ theme_adium_append_message (EmpathyChatView *view, html = priv->data->out_context_html; len = priv->data->out_context_len; } - + if (html == NULL) { html = priv->data->out_content_html; len = priv->data->out_content_len; @@ -555,7 +555,7 @@ theme_adium_append_message (EmpathyChatView *view, html = priv->data->in_context_html; len = priv->data->in_context_len; } - + if (html == NULL) { html = priv->data->in_content_html; len = priv->data->in_content_len; @@ -983,7 +983,7 @@ empathy_adium_data_new_with_info (const gchar *path, GHashTable *info) file = g_build_filename (data->basedir, "Incoming", "NextContent.html", NULL); g_file_get_contents (file, &data->in_nextcontent_html, &data->in_nextcontent_len, NULL); g_free (file); - + file = g_build_filename (data->basedir, "Incoming", "Context.html", NULL); g_file_get_contents (file, &data->in_context_html, &data->in_context_len, NULL); g_free (file); -- cgit v1.2.3 From 133a7e7512781f4b1ad84ac97918547894b68f81 Mon Sep 17 00:00:00 2001 From: Gustavo Noronha Silva Date: Wed, 1 Jul 2009 10:07:24 -0300 Subject: Make WebKit web inspector available, when using Adium themes. --- libempathy-gtk/empathy-theme-adium.c | 125 +++++++++++++++++++++++++++++++++-- 1 file changed, 121 insertions(+), 4 deletions(-) (limited to 'libempathy-gtk/empathy-theme-adium.c') diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index 3b4a895e4..6d270a6cd 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -56,6 +56,8 @@ typedef struct { gboolean page_loaded; GList *message_queue; gchar *hovered_uri; + guint notify_enable_webkit_developer_tools_id; + GtkWidget *inspector_window; } EmpathyThemeAdiumPriv; struct _EmpathyAdiumData { @@ -99,6 +101,31 @@ G_DEFINE_TYPE_WITH_CODE (EmpathyThemeAdium, empathy_theme_adium, G_IMPLEMENT_INTERFACE (EMPATHY_TYPE_CHAT_VIEW, theme_adium_iface_init)); +static void +theme_adium_update_enable_webkit_developer_tools (EmpathyThemeAdium *theme) +{ + WebKitWebView *web_view = WEBKIT_WEB_VIEW (theme); + gboolean enable_webkit_developer_tools; + + if (empathy_conf_get_bool (empathy_conf_get (), "/apps/empathy/conversation/enable_webkit_developer_tools", &enable_webkit_developer_tools) == FALSE) + return; + + g_object_set (G_OBJECT (webkit_web_view_get_settings (web_view)), + "enable-developer-extras", + enable_webkit_developer_tools, + NULL); +} + +static void +theme_adium_notify_enable_webkit_developer_tools_cb (EmpathyConf *conf, + const gchar *key, + gpointer user_data) +{ + EmpathyThemeAdium *theme = user_data; + + theme_adium_update_enable_webkit_developer_tools (theme); +} + static WebKitNavigationResponse theme_adium_navigation_requested_cb (WebKitWebView *view, WebKitWebFrame *frame, @@ -162,6 +189,7 @@ theme_adium_populate_popup_cb (WebKitWebView *view, GtkWidget *icon; gchar *stock_id; gboolean is_link = FALSE; + gboolean developer_tools_enabled; /* FIXME: WebKitGTK+'s context menu API clearly needs an * overhaul. There is currently no way to know what is being @@ -181,8 +209,11 @@ theme_adium_populate_popup_cb (WebKitWebView *view, } /* Remove default menu items */ - gtk_container_foreach (GTK_CONTAINER (menu), - (GtkCallback) gtk_widget_destroy, NULL); + g_object_get (G_OBJECT (webkit_web_view_get_settings (view)), + "enable-developer-extras", &developer_tools_enabled, NULL); + if (!developer_tools_enabled) + gtk_container_foreach (GTK_CONTAINER (menu), + (GtkCallback) gtk_widget_destroy, NULL); /* Select all item */ item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL); @@ -821,6 +852,9 @@ theme_adium_finalize (GObject *object) empathy_adium_data_unref (priv->data); g_free (priv->hovered_uri); + empathy_conf_notify_remove (empathy_conf_get (), + priv->notify_enable_webkit_developer_tools_id); + G_OBJECT_CLASS (empathy_theme_adium_parent_class)->finalize (object); } @@ -839,9 +873,77 @@ theme_adium_dispose (GObject *object) priv->last_contact = NULL; } + if (priv->inspector_window) { + gtk_widget_destroy (priv->inspector_window); + priv->inspector_window = NULL; + } + G_OBJECT_CLASS (empathy_theme_adium_parent_class)->dispose (object); } +static gboolean +theme_adium_inspector_show_window_cb (WebKitWebInspector *inspector, + gpointer user_data) +{ + EmpathyThemeAdium *theme = user_data; + EmpathyThemeAdiumPriv *priv = GET_PRIV (theme); + + gtk_widget_show_all (priv->inspector_window); + + return TRUE; +} + +static gboolean +theme_adium_inspector_close_window_cb (WebKitWebInspector *inspector, + gpointer user_data) +{ + EmpathyThemeAdium *theme = user_data; + EmpathyThemeAdiumPriv *priv; + + /* We may be called too late - when the theme has already been + * destroyed */ + if (!theme) + return FALSE; + + priv = GET_PRIV (theme); + + if (priv->inspector_window) { + gtk_widget_hide (priv->inspector_window); + } + + return TRUE; +} + +static WebKitWebView * +theme_adium_inspect_web_view_cb (WebKitWebInspector *inspector, + WebKitWebView *web_view, + gpointer data) +{ + EmpathyThemeAdiumPriv *priv = GET_PRIV (EMPATHY_THEME_ADIUM (web_view)); + GtkWidget *scrolled_window; + GtkWidget *inspector_web_view; + + if (!priv->inspector_window) { + priv->inspector_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_default_size (GTK_WINDOW (priv->inspector_window), + 800, 600); + + g_signal_connect (priv->inspector_window, "delete-event", + G_CALLBACK (gtk_widget_hide_on_delete), NULL); + + scrolled_window = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_container_add (GTK_CONTAINER (priv->inspector_window), scrolled_window); + + inspector_web_view = webkit_web_view_new (); + gtk_container_add (GTK_CONTAINER (scrolled_window), inspector_web_view); + + return WEBKIT_WEB_VIEW (inspector_web_view); + } + + return NULL; +} + static void theme_adium_constructed (GObject *object) { @@ -861,7 +963,15 @@ theme_adium_constructed (GObject *object) if (font_size) { g_object_set (G_OBJECT (webkit_settings), "default-font-size", font_size, NULL); } - webkit_web_view_set_settings (WEBKIT_WEB_VIEW (object), webkit_settings); + + g_signal_connect (webkit_web_view_get_inspector (WEBKIT_WEB_VIEW (object)), "inspect-web-view", + G_CALLBACK (theme_adium_inspect_web_view_cb), NULL); + + g_signal_connect (webkit_web_view_get_inspector (WEBKIT_WEB_VIEW (object)), "show-window", + G_CALLBACK (theme_adium_inspector_show_window_cb), object); + + g_signal_connect (webkit_web_view_get_inspector (WEBKIT_WEB_VIEW (object)), "close-window", + G_CALLBACK (theme_adium_inspector_close_window_cb), NULL); /* Load template */ basedir_uri = g_strconcat ("file://", priv->data->basedir, NULL); @@ -931,7 +1041,6 @@ empathy_theme_adium_class_init (EmpathyThemeAdiumClass *klass) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - g_type_class_add_private (object_class, sizeof (EmpathyThemeAdiumPriv)); } @@ -957,6 +1066,14 @@ empathy_theme_adium_init (EmpathyThemeAdium *theme) g_signal_connect (theme, "hovering-over-link", G_CALLBACK (theme_adium_hovering_over_link_cb), NULL); + + priv->notify_enable_webkit_developer_tools_id = + empathy_conf_notify_add (empathy_conf_get (), + "/apps/empathy/conversation/enable_webkit_developer_tools", + theme_adium_notify_enable_webkit_developer_tools_cb, + theme); + + theme_adium_update_enable_webkit_developer_tools (theme); } EmpathyThemeAdium * -- cgit v1.2.3 From 9a3e0650a445d9eff8006a577558503944292938 Mon Sep 17 00:00:00 2001 From: Gustavo Noronha Silva Date: Fri, 17 Jul 2009 17:07:38 +0100 Subject: Only consider what's clicked a link when priv->hovered_uri is non-NULL (Fixes: #588886) --- libempathy-gtk/empathy-theme-adium.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'libempathy-gtk/empathy-theme-adium.c') diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index 6d270a6cd..3fd4932a7 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -184,12 +184,14 @@ theme_adium_populate_popup_cb (WebKitWebView *view, GtkMenu *menu, gpointer user_data) { - GtkWidget *item; - GList *items; - GtkWidget *icon; - gchar *stock_id; - gboolean is_link = FALSE; - gboolean developer_tools_enabled; + EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view); + EmpathyThemeAdiumPriv *priv = GET_PRIV (theme); + GtkWidget *item; + GList *items; + GtkWidget *icon; + gchar *stock_id; + gboolean is_link = FALSE; + gboolean developer_tools_enabled; /* FIXME: WebKitGTK+'s context menu API clearly needs an * overhaul. There is currently no way to know what is being @@ -204,7 +206,7 @@ theme_adium_populate_popup_cb (WebKitWebView *view, icon = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (item)); gtk_image_get_stock (GTK_IMAGE (icon), &stock_id, NULL); - if (!strcmp (stock_id, GTK_STOCK_OPEN)) + if ((!strcmp (stock_id, GTK_STOCK_OPEN)) && priv->hovered_uri) is_link = TRUE; } -- cgit v1.2.3