[Xfce4-commits] <midori:master> Queue and save search engine icons, prefer saved icons

Christian Dywan noreply at xfce.org
Thu Jan 31 11:10:02 CET 2013


Updating branch refs/heads/master
         to 132967566fb48538a9ef5ae89918b749a659ce16 (commit)
       from 70a32229d8f6687330ece84354379b3070b2d324 (commit)

commit 132967566fb48538a9ef5ae89918b749a659ce16
Author: Christian Dywan <christian at twotoasts.de>
Date:   Thu Jan 31 09:14:03 2013 +0100

    Queue and save search engine icons, prefer saved icons

 katze/katze-item.c                  |    4 +-
 midori/midori-browser.c             |   59 +++++++++++++++++++++++++++++++++++
 midori/midori-searchaction.c        |   55 +++++++++-----------------------
 midori/midori-searchaction.h        |    6 ---
 midori/midori-searchcompletion.vala |   12 +++---
 midori/midori-view.c                |    7 +---
 6 files changed, 85 insertions(+), 58 deletions(-)

diff --git a/katze/katze-item.c b/katze/katze-item.c
index 2e8fcdc..b7f0caa 100644
--- a/katze/katze-item.c
+++ b/katze/katze-item.c
@@ -447,10 +447,10 @@ katze_item_get_pixbuf (KatzeItem* item,
 
     if (widget && KATZE_ITEM_IS_FOLDER (item))
         return gtk_widget_render_icon (widget, GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
-    if ((pixbuf = midori_paths_get_icon (item->uri, widget)))
-        return pixbuf;
     if ((pixbuf = midori_paths_get_icon (katze_item_get_icon (item), widget)))
         return pixbuf;
+    if ((pixbuf = midori_paths_get_icon (item->uri, widget)))
+        return pixbuf;
     return NULL;
 }
 
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 1b28c39..725fc6a 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -3732,6 +3732,60 @@ _action_location_reset_uri (GtkAction*     action,
     }
 }
 
+#if WEBKIT_CHECK_VERSION (1, 3, 13)
+static void
+#if WEBKIT_CHECK_VERSION (1, 8, 0)
+midori_browser_item_icon_loaded_cb (WebKitFaviconDatabase* database,
+#elif WEBKIT_CHECK_VERSION (1, 3, 13)
+midori_browser_item_icon_loaded_cb (WebKitIconDatabase*    database,
+                                    WebKitWebFrame*        web_frame,
+#endif
+                                    const gchar*           frame_uri,
+                                    KatzeItem*             item)
+{
+    gchar* uri = g_object_get_data (G_OBJECT (item), "browser-queue-icon");
+    if (strcmp (frame_uri, uri))
+        return;
+
+    #if WEBKIT_CHECK_VERSION (1, 8, 0)
+    gchar* icon_uri = webkit_favicon_database_get_favicon_uri (
+        webkit_get_favicon_database (), frame_uri);
+    #elif WEBKIT_CHECK_VERSION (1, 3, 13)
+    gchar* icon_uri = webkit_icon_database_get_icon_uri (
+        webkit_get_icon_database (), frame_uri);
+    #endif
+    if (icon_uri != NULL)
+    {
+        g_free (icon_uri);
+        katze_item_set_icon (item, frame_uri);
+        /* This signal fires extremely often (WebKit bug?)
+           we must throttle it (disconnect) once we have an icon */
+        #if WEBKIT_CHECK_VERSION (1, 8, 0)
+        g_signal_handlers_disconnect_by_func (webkit_get_favicon_database (),
+            midori_browser_item_icon_loaded_cb, item);
+        #elif WEBKIT_CHECK_VERSION (1, 3, 13)
+        g_signal_handlers_disconnect_by_func (webkit_get_icon_database (),
+            midori_browser_item_icon_loaded_cb, item);
+        #endif
+    }
+}
+#endif
+
+static void
+midori_browser_queue_item_for_icon (KatzeItem*     item,
+                                    const gchar*   uri)
+{
+    if (katze_item_get_icon (item) != NULL)
+        return;
+    g_object_set_data_full (G_OBJECT (item), "browser-queue-icon", g_strdup (uri), g_free);
+    #if WEBKIT_CHECK_VERSION (1, 8, 0)
+    g_signal_connect (webkit_get_favicon_database (), "icon-loaded",
+        G_CALLBACK (midori_browser_item_icon_loaded_cb), item);
+    #elif WEBKIT_CHECK_VERSION (1, 3, 13)
+    g_signal_connect (webkit_get_icon_database (), "icon-loaded",
+        G_CALLBACK (midori_browser_item_icon_loaded_cb), item);
+    #endif
+}
 
 static void
 _action_location_submit_uri (GtkAction*     action,
@@ -3781,6 +3835,9 @@ _action_location_submit_uri (GtkAction*     action,
         }
         new_uri = midori_uri_for_search (search_uri, keywords);
 
+        if (browser->search_engines && item != NULL)
+            midori_browser_queue_item_for_icon (item, new_uri);
+
         if (browser->history != NULL)
         {
             time_t now = time (NULL);
@@ -3926,6 +3983,8 @@ _action_search_submit (GtkAction*     action,
         url = browser->location_entry_search;
 
     search = midori_uri_for_search (url, keywords);
+    if (item != NULL)
+        midori_browser_queue_item_for_icon (item, search);
 
     if (new_tab)
     {
diff --git a/midori/midori-searchaction.c b/midori/midori-searchaction.c
index 73060c3..2381f95 100644
--- a/midori/midori-searchaction.c
+++ b/midori/midori-searchaction.c
@@ -400,36 +400,6 @@ midori_search_action_manage_activate_cb (GtkWidget*          menuitem,
         gtk_widget_show (dialog);
 }
 
-GdkPixbuf*
-midori_search_action_get_icon (KatzeItem*    item,
-                               GtkWidget*    widget,
-                               const gchar** icon_name,
-                               gboolean      in_entry)
-{
-    GdkPixbuf* pixbuf = katze_item_get_pixbuf (item, widget);
-    if (widget == NULL)
-        return pixbuf;
-
-    GdkScreen* screen = gtk_widget_get_screen (widget);
-    GtkIconTheme* icon_theme = gtk_icon_theme_get_for_screen (screen);
-    if (katze_item_get_icon (item))
-    {
-        if (gtk_icon_theme_has_icon (icon_theme, katze_item_get_icon (item)))
-        {
-            *icon_name = katze_item_get_icon (item);
-            return pixbuf;
-        }
-    }
-
-    if (in_entry && gtk_icon_theme_has_icon (icon_theme, "edit-find-option-symbolic"))
-        *icon_name = "edit-find-option-symbolic";
-    else if (gtk_icon_theme_has_icon (icon_theme, "edit-find-option"))
-        *icon_name = "edit-find-option";
-    else
-        *icon_name = STOCK_EDIT_FIND;
-    return pixbuf;
-}
-
 static void
 midori_search_action_icon_released_cb (GtkWidget*           entry,
                                        GtkIconEntryPosition icon_pos,
@@ -457,14 +427,13 @@ midori_search_action_icon_released_cb (GtkWidget*           entry,
             menuitem = gtk_image_menu_item_new_with_label (
                 katze_item_get_name (item));
             image = gtk_image_new ();
-            icon = midori_search_action_get_icon (item, entry, &icon_name, FALSE);
-            if (icon)
+            if ((icon = katze_item_get_pixbuf (item, entry)))
             {
                 gtk_image_set_from_pixbuf (GTK_IMAGE (image), icon);
                 g_object_unref (icon);
             }
             else
-                gtk_image_set_from_icon_name (GTK_IMAGE (image), icon_name,
+                gtk_image_set_from_icon_name (GTK_IMAGE (image), STOCK_EDIT_FIND,
                                               GTK_ICON_SIZE_MENU);
             gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
             gtk_image_menu_item_set_always_show_image (
@@ -519,16 +488,25 @@ midori_search_action_set_entry_icon (MidoriSearchAction* search_action,
     {
         const gchar* icon_name;
 
-        icon = midori_search_action_get_icon (search_action->current_item,
-                                              entry, &icon_name, TRUE);
-        if (icon)
+        if ((icon = katze_item_get_pixbuf (search_action->current_item, entry)))
         {
             gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, icon);
             g_object_unref (icon);
         }
         else
+        {
+            GdkScreen* screen = gtk_widget_get_screen (entry);
+            GtkIconTheme* icon_theme = gtk_icon_theme_get_for_screen (screen);
+            gchar* icon_name;
+            if (gtk_icon_theme_has_icon (icon_theme, "edit-find-option-symbolic"))
+                icon_name = "edit-find-option-symbolic";
+            else if (gtk_icon_theme_has_icon (icon_theme, "edit-find-option"))
+                icon_name = "edit-find-option";
+            else
+                icon_name = STOCK_EDIT_FIND;
             gtk_icon_entry_set_icon_from_icon_name (GTK_ICON_ENTRY (entry),
                 GTK_ICON_ENTRY_PRIMARY, icon_name);
+        }
         gtk_entry_set_placeholder_text (GTK_ENTRY (entry),
             katze_item_get_name (search_action->current_item));
     }
@@ -806,17 +784,16 @@ midori_search_action_dialog_render_icon_cb (GtkTreeViewColumn* column,
 {
     KatzeItem* item;
     GdkPixbuf* icon;
-    const gchar* icon_name;
 
     gtk_tree_model_get (model, iter, 0, &item, -1);
 
-    if ((icon = midori_search_action_get_icon (item, treeview, &icon_name, FALSE)))
+    if ((icon = katze_item_get_pixbuf (item, treeview)))
     {
         g_object_set (renderer, "pixbuf", icon, "yalign", 0.25, NULL);
         g_object_unref (icon);
     }
     else
-        g_object_set (renderer, "icon-name", icon_name, "yalign", 0.25, NULL);
+        g_object_set (renderer, "icon-name", STOCK_EDIT_FIND, "yalign", 0.25, NULL);
     g_object_unref (item);
 }
 
diff --git a/midori/midori-searchaction.h b/midori/midori-searchaction.h
index d7f20e6..6817f29 100644
--- a/midori/midori-searchaction.h
+++ b/midori/midori-searchaction.h
@@ -60,12 +60,6 @@ midori_search_action_set_current_item      (MidoriSearchAction* search_action,
 KatzeItem*
 midori_search_action_get_default_item      (MidoriSearchAction* search_action);
 
-GdkPixbuf*
-midori_search_action_get_icon              (KatzeItem*          item,
-                                            GtkWidget*          widget,
-                                            const gchar** icon_name,
-                                            gboolean      in_entry);
-
 void
 midori_search_action_set_default_item      (MidoriSearchAction* search_action,
                                             KatzeItem*          item);
diff --git a/midori/midori-searchcompletion.vala b/midori/midori-searchcompletion.vala
index 282542c..5bb9581 100644
--- a/midori/midori-searchcompletion.vala
+++ b/midori/midori-searchcompletion.vala
@@ -13,9 +13,6 @@ namespace Katze {
 }
 
 namespace Midori {
-    extern static Gdk.Pixbuf? search_action_get_icon (GLib.Object item,
-        Gtk.Widget? widget, out string[] icon_name, bool in_entry);
-
     public class SearchCompletion : Completion {
         GLib.Object search_engines;
 
@@ -42,17 +39,20 @@ namespace Midori {
             var suggestions = new List<Suggestion> ();
             uint n = 0;
             foreach (var item in items) {
-                string uri, title, desc;
+                string icon, uri, title, desc;
+                item.get ("icon", out icon);
                 item.get ("uri", out uri);
                 item.get ("name", out title);
                 item.get ("text", out desc);
                 string search_uri = URI.for_search (uri, text);
                 string search_title = _("Search with %s").printf (title);
-                var icon = Midori.search_action_get_icon (item, null, null, false);
+                Gdk.Pixbuf? pixbuf = Midori.Paths.get_icon (icon, null);
+                if (pixbuf == null)
+                    pixbuf = Midori.Paths.get_icon (uri, null);
                 string search_desc = search_title + "\n" + desc ?? uri;
                 /* FIXME: Theming? Win32? */
                 string background = "gray";
-                var suggestion = new Suggestion (search_uri, search_desc, false, background, icon);
+                var suggestion = new Suggestion (search_uri, search_desc, false, background, pixbuf);
                 suggestions.append (suggestion);
 
                 n++;
diff --git a/midori/midori-view.c b/midori/midori-view.c
index 361cc8f..1a1f986 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -2538,18 +2538,15 @@ midori_view_populate_popup (MidoriView* view,
             KATZE_ARRAY_FOREACH_ITEM (item, search_engines)
             {
                 GdkPixbuf* pixbuf;
-                const gchar* icon_name;
 
                 menuitem = gtk_image_menu_item_new_with_mnemonic (katze_item_get_name (item));
-                pixbuf = midori_search_action_get_icon (item,
-                    GTK_WIDGET (web_view), &icon_name, FALSE);
-                if (pixbuf)
+                if ((pixbuf = katze_item_get_pixbuf (item, GTK_WIDGET (web_view))))
                 {
                     icon = gtk_image_new_from_pixbuf (pixbuf);
                     g_object_unref (pixbuf);
                 }
                 else
-                    icon = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+                    icon = gtk_image_new_from_icon_name (STOCK_EDIT_FIND, GTK_ICON_SIZE_MENU);
                 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), icon);
                 gtk_image_menu_item_set_always_show_image (
                     GTK_IMAGE_MENU_ITEM (menuitem), TRUE);


More information about the Xfce4-commits mailing list