[Xfce4-commits] <midori:master> Supersede Katze.load_cached_icon by Midori.Paths.get_icon

Christian Dywan noreply at xfce.org
Thu Dec 6 02:32:05 CET 2012


Updating branch refs/heads/master
         to 1ecd4ad38fb3395d46a27c981fc9bd9e4d951381 (commit)
       from 4dcba68069f6d2873427d81b9f8e0899a7873c65 (commit)

commit 1ecd4ad38fb3395d46a27c981fc9bd9e4d951381
Author: Christian Dywan <christian at twotoasts.de>
Date:   Thu Dec 6 01:49:31 2012 +0100

    Supersede Katze.load_cached_icon by Midori.Paths.get_icon
    
    Try FaviconDatabase before cached file.
    
    Have katze_item_get_pixbuf try both URL and Katze.icon.
    Get katze_item_get_image consistent with _get_pixbuf.
    Get midori_search_action_get_icon to rely on katze_item_get_pixbuf.
    Drop icon hacks from history/ bookmarks panel.
    Use new Midori.Paths.get_icon in completions.

 extensions/feed-panel/feed-panel.c   |    2 +-
 katze/katze-item.c                   |   34 ++++++++++------------------------
 katze/katze-utils.c                  |    1 +
 katze/midori-paths.vala              |   17 +++++++++++++++++
 midori/midori-historycompletion.vala |    6 +-----
 midori/midori-searchaction.c         |   26 ++++++++++----------------
 midori/midori-viewcompletion.vala    |    2 +-
 midori/webkitgtk-3.0.vapi            |    8 ++++++++
 panels/midori-bookmarks.c            |   14 ++------------
 panels/midori-history.c              |   15 ++-------------
 wscript                              |    2 ++
 11 files changed, 55 insertions(+), 72 deletions(-)

diff --git a/extensions/feed-panel/feed-panel.c b/extensions/feed-panel/feed-panel.c
index ca4c529..ed2d292 100644
--- a/extensions/feed-panel/feed-panel.c
+++ b/extensions/feed-panel/feed-panel.c
@@ -85,7 +85,7 @@ feed_panel_treeview_render_icon_cb (GtkTreeViewColumn* column,
     uri = katze_item_get_uri (pitem);
     if (uri)
     {
-        pixbuf = katze_load_cached_icon (uri, NULL);
+        pixbuf = midori_paths_get_icon (uri, panel->treeview);
         if (!pixbuf)
             pixbuf = panel->pixbuf;
     }
diff --git a/katze/katze-item.c b/katze/katze-item.c
index 233c944..45ab4fe 100644
--- a/katze/katze-item.c
+++ b/katze/katze-item.c
@@ -10,8 +10,8 @@
 */
 
 #include "katze-item.h"
-
 #include "katze-utils.h"
+#include "midori/midori-core.h"
 
 #include <glib/gi18n.h>
 
@@ -445,18 +445,16 @@ katze_item_get_pixbuf (KatzeItem* item,
 
     g_return_val_if_fail (KATZE_IS_ITEM (item), NULL);
 
-    if (item->uri == NULL)
-        return NULL;
-
-    #if WEBKIT_CHECK_VERSION (1, 8, 0)
-    /* FIXME: Don't hard-code icon size */
-    if ((pixbuf = webkit_favicon_database_try_get_favicon_pixbuf (
-        webkit_get_favicon_database (), item->uri, 16, 16)))
+    if ((pixbuf = midori_paths_get_icon (item->uri, widget)))
         return pixbuf;
-    #else
-    if ((pixbuf = g_object_get_data (G_OBJECT (item), "pixbuf")))
+    if ((pixbuf = midori_paths_get_icon (katze_item_get_icon (item), widget)))
         return pixbuf;
-    #endif
+    if (widget != NULL)
+    {
+        if (KATZE_ITEM_IS_FOLDER (item))
+            return gtk_widget_render_icon (widget, GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
+        return gtk_widget_render_icon (widget, GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
+    }
     return NULL;
 }
 
@@ -484,20 +482,8 @@ katze_item_get_image (KatzeItem* item)
     /* FIXME: Pass widget for icon size */
     else if ((pixbuf = katze_item_get_pixbuf (item, NULL)))
         image = gtk_image_new_from_pixbuf (pixbuf);
-    else if ((icon = katze_item_get_icon (item)) && !strchr (icon, '/'))
-        image = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_MENU);
     else
-    {
-        if (!(icon && (pixbuf = katze_load_cached_icon (icon, NULL))))
-            pixbuf = katze_load_cached_icon (item->uri, NULL);
-        if (pixbuf)
-        {
-            image = gtk_image_new_from_pixbuf (pixbuf);
-            g_object_unref (pixbuf);
-        }
-        else
-            image = gtk_image_new_from_stock (GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
-    }
+        image = gtk_image_new_from_stock (GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
     return image;
 }
 
diff --git a/katze/katze-utils.c b/katze/katze-utils.c
index 8fc174f..88ab310 100644
--- a/katze/katze-utils.c
+++ b/katze/katze-utils.c
@@ -1413,6 +1413,7 @@ katze_widget_has_touchscreen_mode (GtkWidget* widget)
  * Returns: a #GdkPixbuf, or %NULL
  *
  * Since: 0.2.2
+ * Deprecated: 0.4.8
  */
 GdkPixbuf*
 katze_load_cached_icon (const gchar* uri,
diff --git a/katze/midori-paths.vala b/katze/midori-paths.vala
index fccf513..6c1ed41 100644
--- a/katze/midori-paths.vala
+++ b/katze/midori-paths.vala
@@ -15,6 +15,10 @@ namespace GLib {
     #endif
 }
 
+namespace Katze {
+    extern static Gdk.Pixbuf? load_cached_icon (string uri, Gtk.Widget? proxy);
+}
+
 extern const string LIBDIR;
 extern const string MDATADIR;
 extern const string PACKAGE_NAME;
@@ -359,5 +363,18 @@ namespace Midori {
             return Path.build_filename (SYSCONFDIR, "xdg", PACKAGE_NAME, folder ?? "", filename);
             #endif
         }
+
+        public static Gdk.Pixbuf? get_icon (string? uri, Gtk.Widget? widget) {
+            if (!Midori.URI.is_resource (uri))
+                return null;
+#if HAVE_WEBKIT_1_8_0
+            /* FIXME: Don't hard-code icon size */
+            Gdk.Pixbuf? pixbuf = WebKit.get_favicon_database ()
+                .try_get_favicon_pixbuf (uri, 16, 16);
+            if (pixbuf != null)
+                return pixbuf;
+#endif
+            return Katze.load_cached_icon (uri, widget);
+        }
     }
 }
diff --git a/midori/midori-historycompletion.vala b/midori/midori-historycompletion.vala
index d7e756f..a00c535 100644
--- a/midori/midori-historycompletion.vala
+++ b/midori/midori-historycompletion.vala
@@ -9,10 +9,6 @@
  See the file COPYING for the full license text.
 */
 
-namespace Katze {
-    extern static Gdk.Pixbuf? load_cached_icon (string uri, Gtk.Widget? proxy);
-}
-
 namespace Midori {
     public class HistoryCompletion : Completion {
         unowned Sqlite.Database db;
@@ -75,7 +71,7 @@ namespace Midori {
                 int64 type = stmt.column_int64 (0);
                 unowned string uri = stmt.column_text (1);
                 unowned string title = stmt.column_text (2);
-                Gdk.Pixbuf? icon = Katze.load_cached_icon (uri, null);
+                Gdk.Pixbuf? icon = Midori.Paths.get_icon (uri, null);
                 Suggestion suggestion;
 
                 switch (type) {
diff --git a/midori/midori-searchaction.c b/midori/midori-searchaction.c
index 5aadec4..2335113 100644
--- a/midori/midori-searchaction.c
+++ b/midori/midori-searchaction.c
@@ -406,24 +406,18 @@ midori_search_action_get_icon (KatzeItem*    item,
                                const gchar** icon_name,
                                gboolean      in_entry)
 {
-    const gchar* icon = katze_item_get_uri (item);
-    GdkScreen* screen;
-    GtkIconTheme* icon_theme;
+    GdkPixbuf* pixbuf = katze_item_get_pixbuf (item, widget);
+    if (widget == NULL)
+        return pixbuf;
 
-    if (midori_uri_is_resource (icon))
-        return katze_load_cached_icon (icon, widget);
-
-    if (icon_name == NULL)
-        return NULL;
-
-    screen = gtk_widget_get_screen (widget);
-    icon_theme = gtk_icon_theme_get_for_screen (screen);
-    if ((icon = katze_item_get_icon (item)) && *icon)
+    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, icon))
+        if (gtk_icon_theme_has_icon (icon_theme, katze_item_get_icon (item)))
         {
-            *icon_name = icon;
-            return NULL;
+            *icon_name = katze_item_get_icon (item);
+            return pixbuf;
         }
     }
 
@@ -433,7 +427,7 @@ midori_search_action_get_icon (KatzeItem*    item,
         *icon_name = "edit-find-option";
     else
         *icon_name = STOCK_EDIT_FIND;
-    return NULL;
+    return pixbuf;
 }
 
 static void
diff --git a/midori/midori-viewcompletion.vala b/midori/midori-viewcompletion.vala
index 5cb8764..b8eef6b 100644
--- a/midori/midori-viewcompletion.vala
+++ b/midori/midori-viewcompletion.vala
@@ -56,7 +56,7 @@ namespace Midori {
                     if (!(key in uri.casefold () || key in title.casefold ()))
                         continue;
 
-                    Gdk.Pixbuf? icon = Katze.load_cached_icon (uri, null);
+                    Gdk.Pixbuf? icon = Midori.Paths.get_icon (uri, null);
                     /* FIXME: Theming? Win32? */
                     string background = "gray";
                     var suggestion = new Suggestion (uri, title + "\n" + uri, false, background, icon);
diff --git a/midori/webkitgtk-3.0.vapi b/midori/webkitgtk-3.0.vapi
index 7ee599f..d856b82 100644
--- a/midori/webkitgtk-3.0.vapi
+++ b/midori/webkitgtk-3.0.vapi
@@ -3,6 +3,12 @@
 [CCode (cprefix = "WebKit", lower_case_cprefix = "webkit_")]
 namespace WebKit {
 	[CCode (cheader_filename = "webkit/webkit.h")]
+	public class FaviconDatabase : GLib.Object {
+		public Gdk.Pixbuf? try_get_favicon_pixbuf (string page_uri, uint width, uint height);
+		public void set_path (string? path);
+		public void clear ();
+	}
+	[CCode (cheader_filename = "webkit/webkit.h")]
 	public class DOMDOMTokenList : GLib.Object {
 		[CCode (has_construct_function = false)]
 		protected DOMDOMTokenList ();
@@ -796,6 +802,8 @@ namespace WebKit {
 	[CCode (cheader_filename = "webkit/webkit.h")]
 	public static uint64 get_default_web_database_quota ();
 	[CCode (cheader_filename = "webkit/webkit.h")]
+	public static unowned WebKit.FaviconDatabase get_favicon_database ();
+	[CCode (cheader_filename = "webkit/webkit.h")]
 	public static unowned string get_web_database_directory_path ();
 	[CCode (cheader_filename = "webkit/webkit.h")]
 	public static unowned WebKit.WebPluginDatabase get_web_plugin_database ();
diff --git a/panels/midori-bookmarks.c b/panels/midori-bookmarks.c
index 39b4950..eb8347a 100644
--- a/panels/midori-bookmarks.c
+++ b/panels/midori-bookmarks.c
@@ -658,22 +658,12 @@ midori_bookmarks_treeview_render_icon_cb (GtkTreeViewColumn* column,
 
     gtk_tree_model_get (model, iter, 0, &item, -1);
 
-    /* TODO: Would it be better to not do this on every redraw? */
-    pixbuf = NULL;
-    if (KATZE_ITEM_IS_FOLDER (item))
-        pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY,
-                                         GTK_ICON_SIZE_MENU, NULL);
-    else if ((pixbuf = katze_item_get_pixbuf (item, treeview)))
-        ;
-    else if (KATZE_ITEM_IS_BOOKMARK (item))
-        pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview);
+    pixbuf = katze_item_get_pixbuf (item, treeview);
     g_object_set (renderer, "pixbuf", pixbuf, NULL);
 
     if (pixbuf)
         g_object_unref (pixbuf);
-
-    if (item)
-        g_object_unref (item);
+    g_object_unref (item);
 }
 
 static void
diff --git a/panels/midori-history.c b/panels/midori-history.c
index 3248750..fa7b7ec 100644
--- a/panels/midori-history.c
+++ b/panels/midori-history.c
@@ -594,23 +594,12 @@ midori_history_treeview_render_icon_cb (GtkTreeViewColumn* column,
 
     gtk_tree_model_get (model, iter, 0, &item, -1);
 
-    if (!item)
-        pixbuf = NULL;
-    else if ((pixbuf = katze_item_get_pixbuf (item, treeview)))
-        ;
-    else if (katze_item_get_uri (item))
-        pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview);
-    else
-        pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY,
-                                         GTK_ICON_SIZE_MENU, NULL);
-
+    pixbuf = katze_item_get_pixbuf (item, treeview);
     g_object_set (renderer, "pixbuf", pixbuf, NULL);
 
     if (pixbuf)
-    {
         g_object_unref (pixbuf);
-        g_object_unref (item);
-    }
+    g_object_unref (item);
 }
 
 static void
diff --git a/wscript b/wscript
index 598ce1f..15d60df 100644
--- a/wscript
+++ b/wscript
@@ -294,6 +294,8 @@ def configure (conf):
         conf.define ('HAVE_LIBSOUP_2_37_1', 1)
     if check_version (conf.env['WEBKIT_VERSION'], 1, 3, 8):
         conf.env.append_value ('VALAFLAGS', '-D HAVE_WEBKIT_1_3_8')
+    if check_version (conf.env['WEBKIT_VERSION'], 1, 8, 0):
+        conf.env.append_value ('VALAFLAGS', '-D HAVE_WEBKIT_1_8_0')
     check_pkg ('libxml-2.0', '2.6')
     conf.undefine ('LIBXML_VERSION') # Defined in xmlversion.h
     check_pkg ('sqlite3', '3.6.19', var='SQLITE')


More information about the Xfce4-commits mailing list