[gnome-session] [capplet] Make GspApp use GIcon and get rid of the pixbuf/icon-name



commit 4829dafee3f3a76564b4ac4f4d23d81ff43e05a2
Author: Vincent Untz <vuntz gnome org>
Date:   Tue Jun 23 18:05:37 2009 +0200

    [capplet] Make GspApp use GIcon and get rid of the pixbuf/icon-name
    
    Instead of having GspApp provide an icon name or a pixbuf, and handling
    this different cases in the UI, make GspApp only provide a GIcon which
    hides this detail.

 capplet/gsm-properties-dialog.c |   58 ++++++++++++++-----------------
 capplet/gsp-app.c               |   72 +++++++++++++++-----------------------
 capplet/gsp-app.h               |    5 +--
 3 files changed, 57 insertions(+), 78 deletions(-)
---
diff --git a/capplet/gsm-properties-dialog.c b/capplet/gsm-properties-dialog.c
index b0db1af..47c0f36 100644
--- a/capplet/gsm-properties-dialog.c
+++ b/capplet/gsm-properties-dialog.c
@@ -76,9 +76,7 @@ struct GsmPropertiesDialogPrivate
 enum {
         STORE_COL_VISIBLE = 0,
         STORE_COL_ENABLED,
-        STORE_COL_ICON_NAME,
         STORE_COL_GICON,
-        STORE_COL_PIXBUF,
         STORE_COL_DESCRIPTION,
         STORE_COL_APP,
         NUMBER_OF_COLUMNS
@@ -120,49 +118,49 @@ _fill_iter_from_app (GtkListStore *list_store,
                      GtkTreeIter  *iter,
                      GspApp       *app)
 {
-        gboolean      hidden;
-        gboolean      enabled;
-        GIcon        *icon;
-        const char   *icon_name;
-        GdkPixbuf    *pixbuf;
-        const char   *description;
+        gboolean    hidden;
+        gboolean    enabled;
+        GIcon      *icon;
+        const char *description;
 
         hidden      = gsp_app_get_hidden (app);
         enabled     = gsp_app_get_enabled (app);
-        icon_name   = gsp_app_get_icon_name (app);
-        pixbuf      = gsp_app_get_pixbuf (app);
+        icon        = gsp_app_get_icon (app);
         description = gsp_app_get_description (app);
 
-        icon = NULL;
-        if (!pixbuf) {
-#if 1
-                GtkIconTheme *theme;
+        if (G_IS_THEMED_ICON (icon)) {
+                GtkIconTheme       *theme;
+                const char * const *icon_names;
+
                 theme = gtk_icon_theme_get_default ();
-                if (icon_name == NULL ||
-                    !gtk_icon_theme_has_icon (theme, icon_name)) {
-                        icon_name = STARTUP_APP_ICON;
+                icon_names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+                if (icon_names[0] == NULL ||
+                    !gtk_icon_theme_has_icon (theme, icon_names[0])) {
+                        g_object_unref (icon);
+                        icon = NULL;
                 }
-#else
-                /* the issue with this approach is that icons that live in
-                 * hicolor are ignored and STARTUP_APP_ICON is nearly always
-                 * used if it's in the main theme */
-                icon = g_themed_icon_new (STARTUP_APP_ICON);
-                if (icon_name != NULL) {
-                        g_themed_icon_prepend_name (G_THEMED_ICON (icon),
-                                                    icon_name);
+        } else if (G_IS_FILE_ICON (icon)) {
+                GFile *iconfile;
+
+                iconfile = g_file_icon_get_file (G_FILE_ICON (icon));
+                if (!g_file_query_exists (iconfile, NULL)) {
+                        g_object_unref (icon);
+                        icon = NULL;
                 }
-#endif
+        }
+
+        if (icon == NULL) {
+                icon = g_themed_icon_new (STARTUP_APP_ICON);
         }
 
         gtk_list_store_set (list_store, iter,
                             STORE_COL_VISIBLE, !hidden,
                             STORE_COL_ENABLED, enabled,
-                            STORE_COL_ICON_NAME, icon_name,
                             STORE_COL_GICON, icon,
-                            STORE_COL_PIXBUF, pixbuf,
                             STORE_COL_DESCRIPTION, description,
                             STORE_COL_APP, app,
                             -1);
+        g_object_unref (icon);
 }
 
 static void
@@ -468,9 +466,7 @@ setup_dialog (GsmPropertiesDialog *dialog)
         dialog->priv->list_store = gtk_list_store_new (NUMBER_OF_COLUMNS,
                                                        G_TYPE_BOOLEAN,
                                                        G_TYPE_BOOLEAN,
-                                                       G_TYPE_STRING,
                                                        G_TYPE_ICON,
-                                                       GDK_TYPE_PIXBUF,
                                                        G_TYPE_STRING,
                                                        G_TYPE_OBJECT);
         tree_filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (dialog->priv->list_store),
@@ -517,9 +513,7 @@ setup_dialog (GsmPropertiesDialog *dialog)
         renderer = gtk_cell_renderer_pixbuf_new ();
         column = gtk_tree_view_column_new_with_attributes (_("Icon"),
                                                            renderer,
-                                                           "icon_name", STORE_COL_ICON_NAME,
                                                            "gicon", STORE_COL_GICON,
-                                                           "pixbuf", STORE_COL_PIXBUF,
                                                            NULL);
         g_object_set (renderer,
                       "stock-size", GSM_PROPERTIES_ICON_SIZE,
diff --git a/capplet/gsp-app.c b/capplet/gsp-app.c
index dd4beef..b9c8be6 100644
--- a/capplet/gsp-app.c
+++ b/capplet/gsp-app.c
@@ -54,9 +54,9 @@ struct _GspAppPrivate {
         char         *name;
         char         *exec;
         char         *comment;
-        char         *icon_name;
+        char         *icon;
 
-        GdkPixbuf    *pixbuf;
+        GIcon        *gicon;
         char         *description;
 
         /* position of the directory in the XDG environment variable */
@@ -178,14 +178,14 @@ _gsp_app_free_reusable_data (GspApp *app)
                 app->priv->comment = NULL;
         }
 
-        if (app->priv->icon_name) {
-                g_free (app->priv->icon_name);
-                app->priv->icon_name = NULL;
+        if (app->priv->icon) {
+                g_free (app->priv->icon);
+                app->priv->icon = NULL;
         }
 
-        if (app->priv->pixbuf) {
-                g_object_unref (app->priv->pixbuf);
-                app->priv->pixbuf = NULL;
+        if (app->priv->gicon) {
+                g_object_unref (app->priv->gicon);
+                app->priv->gicon = NULL;
         }
 
         if (app->priv->description) {
@@ -552,20 +552,16 @@ gsp_app_get_comment (GspApp *app)
         return app->priv->comment;
 }
 
-const char *
-gsp_app_get_icon_name (GspApp *app)
+GIcon *
+gsp_app_get_icon (GspApp *app)
 {
         g_return_val_if_fail (GSP_IS_APP (app), NULL);
 
-        return app->priv->icon_name;
-}
-
-GdkPixbuf *
-gsp_app_get_pixbuf (GspApp *app)
-{
-        g_return_val_if_fail (GSP_IS_APP (app), NULL);
-
-        return app->priv->pixbuf;
+        if (app->priv->gicon) {
+                return g_object_ref (app->priv->gicon);
+        } else {
+                return NULL;
+        }
 }
 
 unsigned int
@@ -696,20 +692,6 @@ gsp_app_reload_at (GspApp       *app,
         gsp_app_new (path, xdg_position);
 }
 
-static GdkPixbuf *
-_gsp_app_load_pixbuf (const char *path)
-{
-        int width, height;
-
-        if (gtk_icon_size_lookup (GSM_PROPERTIES_ICON_SIZE,
-                                  &width, &height)) {
-                return gdk_pixbuf_new_from_file_at_size (path,
-                                                         width, height, NULL);
-        }
-
-        return NULL;
-}
-
 GspApp *
 gsp_app_new (const char   *path,
              unsigned int  xdg_position)
@@ -719,7 +701,6 @@ gsp_app_new (const char   *path,
         GKeyFile      *keyfile;
         char          *basename;
         gboolean       new;
-        char          *icon;
 
         basename = g_path_get_basename (path);
 
@@ -788,17 +769,22 @@ gsp_app_new (const char   *path,
                 app->priv->name = g_strdup (app->priv->exec);
         }
 
-        icon = gsp_key_file_get_locale_string (keyfile,
-                                               G_KEY_FILE_DESKTOP_KEY_ICON);
+        app->priv->icon = gsp_key_file_get_locale_string (keyfile,
+                                                          G_KEY_FILE_DESKTOP_KEY_ICON);
 
-        if (icon) {
+        if (app->priv->icon) {
                 /* look at icon and see if it's a themed icon or not */
-                if (g_path_is_absolute (icon)) {
-                        app->priv->pixbuf = _gsp_app_load_pixbuf (icon);
-                        g_free (icon);
+                if (g_path_is_absolute (app->priv->icon)) {
+                        GFile *iconfile;
+
+                        iconfile = g_file_new_for_path (app->priv->icon);
+                        app->priv->gicon = g_file_icon_new (iconfile);
+                        g_object_unref (iconfile);
                 } else {
-                        app->priv->icon_name = icon;
+                        app->priv->gicon = g_themed_icon_new (app->priv->icon);
                 }
+        } else {
+                app->priv->gicon = NULL;
         }
 
         g_key_file_free (keyfile);
@@ -921,9 +907,9 @@ gsp_app_create (const char *name,
         }
         app->priv->exec = g_strdup (exec);
         app->priv->comment = g_strdup (comment);
-        app->priv->icon_name = NULL;
+        app->priv->icon = NULL;
 
-        app->priv->pixbuf = NULL;
+        app->priv->gicon = NULL;
         _gsp_app_update_description (app);
 
         /* by definition */
diff --git a/capplet/gsp-app.h b/capplet/gsp-app.h
index 77716f7..1a29058 100644
--- a/capplet/gsp-app.h
+++ b/capplet/gsp-app.h
@@ -25,7 +25,7 @@
 #define __GSP_APP_H
 
 #include <glib-object.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gio/gio.h>
 
 G_BEGIN_DECLS
 
@@ -83,8 +83,7 @@ const char      *gsp_app_get_exec          (GspApp       *app);
 const char      *gsp_app_get_comment       (GspApp       *app);
 
 const char      *gsp_app_get_description   (GspApp       *app);
-const char      *gsp_app_get_icon_name     (GspApp       *app);
-GdkPixbuf       *gsp_app_get_pixbuf        (GspApp       *app);
+GIcon           *gsp_app_get_icon          (GspApp       *app);
 
 /* private interface for GspAppManager only */
 



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