[Xfce4-commits] <midori:master> Merge katze_load_cached_icon into Midori.Paths.get_icon

Christian Dywan noreply at xfce.org
Sun Dec 9 14:16:02 CET 2012


Updating branch refs/heads/master
         to bd2b69c5025d4afc3f6dcdab6146858dae71c070 (commit)
       from 94b733b5dedcb64f759e7d449f06a518a534aac0 (commit)

commit bd2b69c5025d4afc3f6dcdab6146858dae71c070
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Dec 9 14:07:30 2012 +0100

    Merge katze_load_cached_icon into Midori.Paths.get_icon
    
    The code paths are functionally exclusive.

 katze/katze-utils.c     |   62 -----------------------------------------------
 katze/katze-utils.h     |    4 ---
 katze/midori-paths.vala |   32 ++++++++++++++++-------
 3 files changed, 22 insertions(+), 76 deletions(-)

diff --git a/katze/katze-utils.c b/katze/katze-utils.c
index 88ab310..adfdf48 100644
--- a/katze/katze-utils.c
+++ b/katze/katze-utils.c
@@ -1402,68 +1402,6 @@ katze_widget_has_touchscreen_mode (GtkWidget* widget)
     }
 }
 
-/**
- * katze_load_cached_icon:
- * @uri: an URI string
- * @widget: a #GtkWidget, or %NULL
- *
- * Loads a cached icon for the specified @uri. If there is no
- * icon and @widget is specified, a default will be returned.
- *
- * Returns: a #GdkPixbuf, or %NULL
- *
- * Since: 0.2.2
- * Deprecated: 0.4.8
- */
-GdkPixbuf*
-katze_load_cached_icon (const gchar* uri,
-                        GtkWidget*   widget)
-{
-    GdkPixbuf* icon = NULL;
-
-    g_return_val_if_fail (uri != NULL, NULL);
-
-    if (midori_uri_is_http (uri))
-    {
-        guint i;
-        gchar* icon_uri;
-        gchar* checksum;
-        gchar* ext;
-        gchar* filename;
-        gchar* path;
-
-        i = 8;
-        while (uri[i] != '\0' && uri[i] != '/')
-            i++;
-        if (uri[i] == '/')
-        {
-            gchar* ticon_uri = g_strdup (uri);
-            ticon_uri[i] = '\0';
-            icon_uri = g_strdup_printf ("%s/favicon.ico", ticon_uri);
-            g_free (ticon_uri);
-        }
-        else
-            icon_uri = g_strdup_printf ("%s/favicon.ico", uri);
-
-        checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, icon_uri, -1);
-        ext = g_strrstr (icon_uri, ".");
-        filename = g_strdup_printf ("%s%s", checksum, ext ? ext : "");
-        g_free (icon_uri);
-        g_free (checksum);
-        path = g_build_filename (midori_paths_get_cache_dir_for_reading (), "icons", filename, NULL);
-        g_free (filename);
-        if ((icon = gdk_pixbuf_new_from_file_at_size (path, 16, 16, NULL)))
-        {
-            g_free (path);
-            return icon;
-        }
-        g_free (path);
-    }
-
-    return icon || !widget ? icon : gtk_widget_render_icon (widget,
-        GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
-}
-
 static void
 katze_uri_entry_changed_cb (GtkWidget* entry,
                             GtkWidget* other_widget)
diff --git a/katze/katze-utils.h b/katze/katze-utils.h
index bf97cbf..b80ed0d 100644
--- a/katze/katze-utils.h
+++ b/katze/katze-utils.h
@@ -153,10 +153,6 @@ katze_mkdir_with_parents             (const gchar* pathname,
 gboolean
 katze_widget_has_touchscreen_mode    (GtkWidget*      widget);
 
-GdkPixbuf*
-katze_load_cached_icon               (const gchar*    uri,
-                                      GtkWidget*      widget);
-
 GtkWidget*
 katze_uri_entry_new                  (GtkWidget*      other_widget);
 
diff --git a/katze/midori-paths.vala b/katze/midori-paths.vala
index cc475e8..9ff7460 100644
--- a/katze/midori-paths.vala
+++ b/katze/midori-paths.vala
@@ -15,10 +15,6 @@ 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;
@@ -387,25 +383,41 @@ namespace Midori {
         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
             int icon_width = 16, icon_height = 16;
             if (widget != null)
                 Gtk.icon_size_lookup_for_settings (widget.get_settings (),
                     Gtk.IconSize.MENU, out icon_width, out icon_height);
+#if HAVE_WEBKIT_1_8_0
             Gdk.Pixbuf? pixbuf = WebKit.get_favicon_database ()
                 .try_get_favicon_pixbuf (uri, icon_width, icon_height);
             if (pixbuf != null)
                 return pixbuf;
 #elif HAVE_WEBKIT_1_3_13
-            int icon_width = 16, icon_height = 16;
-            if (widget != null)
-                Gtk.icon_size_lookup_for_settings (widget.get_settings (),
-                    Gtk.IconSize.MENU, out icon_width, out icon_height);
             Gdk.Pixbuf? pixbuf = WebKit.get_icon_database ().get_icon_pixbuf (uri);
             if (pixbuf != null)
                 return pixbuf.scale_simple (icon_width, icon_height, Gdk.InterpType.BILINEAR);
+#else
+            if (Midori.URI.is_http (uri)) {
+                try {
+                    uint i = 8;
+                    while (uri[i] != '\0' && uri[i] != '/')
+                        i++;
+                    string icon_uri = (uri[i] == '/')
+                        ? uri.substring (0, i) + "/favicon.ico"
+                        : uri + "/favicon.ico";
+                    string checksum = Checksum.compute_for_string (ChecksumType.MD5, icon_uri, -1);
+                    string filename = checksum + Midori.Download.get_extension_for_uri (icon_uri) ?? "";
+                    string path = Path.build_filename (get_cache_dir_for_reading (), "icons", filename);
+                    Gdk.Pixbuf? pixbuf = new Gdk.Pixbuf.from_file_at_size (path, icon_width, icon_height);
+                    if (pixbuf != null)
+                        return pixbuf;
+                }
+                catch (GLib.Error error) { }
+            }
 #endif
-            return Katze.load_cached_icon (uri, widget);
+            if (widget != null)
+                return widget.render_icon (Gtk.STOCK_FILE, Gtk.IconSize.MENU, null);
+            return null;
         }
     }
 }


More information about the Xfce4-commits mailing list