[gnome-software] Use a 96x96 icon if available on the details panel



commit 9fa031120e29dc6d2c131a2b6d0f68f2b075e61e
Author: Richard Hughes <richard hughsie com>
Date:   Sun Oct 20 21:00:01 2013 +0100

    Use a 96x96 icon if available on the details panel
    
    You can only get the larger icon if the application is installed.
    
    Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=708342

 src/gs-app.c                             |   27 +++++-------------------
 src/gs-cmd.c                             |    7 +++++-
 src/gs-shell-details.c                   |    9 ++++++-
 src/gs-utils.c                           |   24 +++++++++++++++++++++
 src/gs-utils.h                           |    3 ++
 src/plugins/gs-plugin-datadir-apps.c     |   33 ++++++++++++-----------------
 src/plugins/gs-plugin-datadir-filename.c |    2 +-
 7 files changed, 61 insertions(+), 44 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index ae5a774..da45a39 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -47,6 +47,7 @@
 #include <gtk/gtk.h>
 
 #include "gs-app.h"
+#include "gs-utils.h"
 
 static void    gs_app_finalize (GObject        *object);
 
@@ -602,28 +603,12 @@ gs_app_set_icon (GsApp *app, const gchar *icon, GError **error)
        app->priv->icon = g_strdup (icon);
 
        /* either load from the theme or from a file */
-       if (icon[0] == '/') {
-               pixbuf = gdk_pixbuf_new_from_file_at_size (icon,
-                                                          64, 64,
-                                                          error);
-               if (pixbuf == NULL) {
-                       ret = FALSE;
-                       goto out;
-               }
-               gs_app_set_pixbuf (app, pixbuf);
-       } else if (g_strstr_len (icon, -1, ".") == NULL) {
-               pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
-                                                  icon,
-                                                  64,
-                                                  GTK_ICON_LOOKUP_USE_BUILTIN |
-                                                  GTK_ICON_LOOKUP_FORCE_SIZE,
-                                                  error);
-               if (pixbuf == NULL) {
-                       ret = FALSE;
-                       goto out;
-               }
-               gs_app_set_pixbuf (app, pixbuf);
+       pixbuf = gs_pixbuf_load (icon, 64, error);
+       if (pixbuf == NULL) {
+               ret = FALSE;
+               goto out;
        }
+       gs_app_set_pixbuf (app, pixbuf);
 out:
        if (pixbuf != NULL)
                g_object_unref (pixbuf);
diff --git a/src/gs-cmd.c b/src/gs-cmd.c
index f6480fd..34f03dd 100644
--- a/src/gs-cmd.c
+++ b/src/gs-cmd.c
@@ -109,9 +109,14 @@ main (int argc, char **argv)
                                                     GS_PLUGIN_REFINE_FLAGS_DEFAULT,
                                                     NULL,
                                                     &error);
+       } else if (argc == 2 && g_strcmp0 (argv[1], "popular") == 0) {
+               list = gs_plugin_loader_get_popular (plugin_loader,
+                                                    GS_PLUGIN_REFINE_FLAGS_DEFAULT,
+                                                    NULL,
+                                                    &error);
        } else {
                g_warning ("Did not recognise option, use 'installed', "
-                          "'updates', or 'search'");
+                          "'updates', 'popular', or 'search'");
        }
 
        if (show_results)
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 8720885..9ad128d 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -384,7 +384,7 @@ static void
 gs_shell_details_refresh_all (GsShellDetails *shell_details)
 {
        GPtrArray *history;
-       GdkPixbuf *pixbuf;
+       GdkPixbuf *pixbuf = NULL;
        GsShellDetailsPrivate *priv = shell_details->priv;
        GtkWidget *widget2;
        GtkWidget *widget;
@@ -419,7 +419,12 @@ gs_shell_details_refresh_all (GsShellDetails *shell_details)
                                                     "application_details_description_header"));
        gtk_widget_set_visible (widget, tmp != NULL);
 
-       pixbuf = gs_app_get_pixbuf (priv->app);
+       /* set the icon */
+       tmp = gs_app_get_metadata_item (priv->app, "DataDir::desktop-icon");
+       if (tmp != NULL)
+               pixbuf = gs_pixbuf_load (tmp, 96, NULL);
+       if (pixbuf == NULL)
+               pixbuf = gs_app_get_pixbuf (priv->app);
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "application_details_icon"));
        if (pixbuf != NULL) {
                gtk_image_set_from_pixbuf (GTK_IMAGE (widget), pixbuf);
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 2fefaca..ced2160 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -291,4 +291,28 @@ gs_mkdir_parent (const gchar *path, GError **error)
        return ret;
 }
 
+/**
+ * gs_pixbuf_load:
+ **/
+GdkPixbuf *
+gs_pixbuf_load (const gchar *icon_name, guint icon_size, GError **error)
+{
+       GdkPixbuf *pixbuf = NULL;
+
+       if (icon_name[0] == '/') {
+               pixbuf = gdk_pixbuf_new_from_file_at_size (icon_name,
+                                                          icon_size,
+                                                          icon_size,
+                                                          error);
+       } else if (g_strstr_len (icon_name, -1, ".") == NULL) {
+               pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+                                                  icon_name,
+                                                  icon_size,
+                                                  GTK_ICON_LOOKUP_USE_BUILTIN |
+                                                  GTK_ICON_LOOKUP_FORCE_SIZE,
+                                                  error);
+       }
+       return pixbuf;
+}
+
 /* vim: set noexpandtab: */
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 39e68ff..07b0c0e 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -45,6 +45,9 @@ guint  gs_string_replace              (GString        *string,
                                         const gchar    *replace);
 gboolean gs_mkdir_parent               (const gchar    *path,
                                         GError         **error);
+GdkPixbuf *gs_pixbuf_load              (const gchar    *icon_name,
+                                        guint           icon_size,
+                                        GError         **error);
 
 G_END_DECLS
 
diff --git a/src/plugins/gs-plugin-datadir-apps.c b/src/plugins/gs-plugin-datadir-apps.c
index a3203a7..e7e48a1 100644
--- a/src/plugins/gs-plugin-datadir-apps.c
+++ b/src/plugins/gs-plugin-datadir-apps.c
@@ -23,6 +23,7 @@
 
 #include <string.h>
 #include <gs-plugin.h>
+#include <gs-utils.h>
 
 struct GsPluginPrivate {
        GMutex           plugin_mutex;
@@ -34,6 +35,7 @@ typedef struct {
        gchar           *pkgname;
        gchar           *name;
        gchar           *summary;
+       gchar           *icon_name;
        GdkPixbuf       *pixbuf;
 } GsPluginDataDirAppsCacheItem;
 
@@ -55,6 +57,7 @@ gs_plugin_datadir_apps_cache_item_free (GsPluginDataDirAppsCacheItem *cache_item
        g_free (cache_item->id);
        g_free (cache_item->name);
        g_free (cache_item->summary);
+       g_free (cache_item->icon_name);
        if (cache_item->pixbuf != NULL)
                g_object_unref (cache_item->pixbuf);
        g_slice_free (GsPluginDataDirAppsCacheItem, cache_item);
@@ -102,6 +105,7 @@ gs_plugin_datadir_apps_set_from_cache_item (GsApp *app,
                                            GsPluginDataDirAppsCacheItem *cache_item)
 {
        gs_app_set_id (app, cache_item->id);
+       gs_app_set_metadata (app, "DataDir::desktop-icon", cache_item->icon_name);
        if (cache_item->name != NULL)
                gs_app_set_name (app, cache_item->name);
        if (cache_item->pkgname != NULL)
@@ -190,30 +194,20 @@ gs_plugin_datadir_apps_extract_desktop_data (GsPlugin *plugin,
        if (comment == NULL || comment[0] == '\0')
                goto out;
 
+       /* get desktop icon */
+       icon = g_key_file_get_string (key_file,
+                                     G_KEY_FILE_DESKTOP_GROUP,
+                                     G_KEY_FILE_DESKTOP_KEY_ICON,
+                                     NULL);
+       if (icon == NULL)
+               goto out;
+
        /* do we have an icon in the cache? */
        icon_tmp = g_hash_table_lookup (plugin->icon_cache, basename_tmp);
        if (icon_tmp != NULL) {
                pixbuf = gdk_pixbuf_new_from_file (icon_tmp, NULL);
        } else {
-               icon = g_key_file_get_string (key_file,
-                                             G_KEY_FILE_DESKTOP_GROUP,
-                                             G_KEY_FILE_DESKTOP_KEY_ICON,
-                                             NULL);
-               if (icon == NULL)
-                       goto out;
-               if (icon[0] == '/') {
-                       pixbuf = gdk_pixbuf_new_from_file_at_size (icon,
-                                                                  plugin->pixbuf_size,
-                                                                  plugin->pixbuf_size,
-                                                                  NULL);
-               } else {
-                       pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
-                                                          icon,
-                                                          plugin->pixbuf_size,
-                                                          GTK_ICON_LOOKUP_USE_BUILTIN |
-                                                          GTK_ICON_LOOKUP_FORCE_SIZE,
-                                                          NULL);
-               }
+               pixbuf = gs_pixbuf_load (icon, plugin->pixbuf_size, NULL);
                if (pixbuf == NULL)
                        goto out;
        }
@@ -223,6 +217,7 @@ gs_plugin_datadir_apps_extract_desktop_data (GsPlugin *plugin,
        cache_item->id = g_strdup (basename_tmp);
        cache_item->name = g_strdup (name);
        cache_item->summary = g_strdup (comment);
+       cache_item->icon_name = g_strdup (icon);
        cache_item->pixbuf = g_object_ref (pixbuf);
 
        /* set pkgname if set (only Ubuntu) */
diff --git a/src/plugins/gs-plugin-datadir-filename.c b/src/plugins/gs-plugin-datadir-filename.c
index 346e568..895103e 100644
--- a/src/plugins/gs-plugin-datadir-filename.c
+++ b/src/plugins/gs-plugin-datadir-filename.c
@@ -58,7 +58,7 @@ gs_plugin_initialize (GsPlugin *plugin)
 gdouble
 gs_plugin_get_priority (GsPlugin *plugin)
 {
-       return 1.1f;
+       return 0.9f;
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]