[gnome-software] Show icons in the overview category list



commit 3454b1a238508ffeb5cf76d29587439e8336d559
Author: Richard Hughes <richard hughsie com>
Date:   Tue May 31 12:39:52 2016 +0100

    Show icons in the overview category list

 src/gs-category-tile.c                       |    5 +++
 src/gs-category-tile.ui                      |   29 ++++++++++++---
 src/gs-category.c                            |   49 ++++++++++++++++++++++++++
 src/gs-category.h                            |    3 ++
 src/plugins/gs-plugin-menu-spec-categories.c |    1 +
 5 files changed, 82 insertions(+), 5 deletions(-)
---
diff --git a/src/gs-category-tile.c b/src/gs-category-tile.c
index 10aa9db..9a916e2 100644
--- a/src/gs-category-tile.c
+++ b/src/gs-category-tile.c
@@ -32,6 +32,7 @@ struct _GsCategoryTile
 
        GsCategory      *cat;
        GtkWidget       *label;
+       GtkWidget       *image;
 };
 
 G_DEFINE_TYPE (GsCategoryTile, gs_category_tile, GTK_TYPE_BUTTON)
@@ -54,6 +55,9 @@ gs_category_tile_set_category (GsCategoryTile *tile, GsCategory *cat)
        tile->cat = g_object_ref (cat);
 
        gtk_label_set_label (GTK_LABEL (tile->label), gs_category_get_name (cat));
+       gtk_image_set_from_icon_name (GTK_IMAGE (tile->image),
+                                     gs_category_get_icon (cat),
+                                     GTK_ICON_SIZE_MENU);
 }
 
 static void
@@ -83,6 +87,7 @@ gs_category_tile_class_init (GsCategoryTileClass *klass)
        gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-category-tile.ui");
 
        gtk_widget_class_bind_template_child (widget_class, GsCategoryTile, label);
+       gtk_widget_class_bind_template_child (widget_class, GsCategoryTile, image);
 }
 
 GtkWidget *
diff --git a/src/gs-category-tile.ui b/src/gs-category-tile.ui
index eaba017..f696f21 100644
--- a/src/gs-category-tile.ui
+++ b/src/gs-category-tile.ui
@@ -8,13 +8,32 @@
       <class name="tile"/>
     </style>
     <child>
-      <object class="GtkLabel" id="label">
+      <object class="GtkBox" id="box">
         <property name="visible">True</property>
-        <property name="margin_top">11</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">horizontal</property>
+        <property name="spacing">12</property>
+        <property name="margin_top">12</property>
         <property name="margin_bottom">12</property>
-        <property name="margin_start">18</property>
-        <property name="margin_end">18</property>
-        <property name="xalign">0</property>
+        <property name="margin_start">12</property>
+        <property name="margin_end">12</property>
+        <child>
+          <object class="GtkImage" id="image">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="icon_name">folder-music-symbolic</property>
+            <property name="icon_size">1</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label">
+            <property name="visible">True</property>
+            <property name="xalign">0</property>
+          </object>
+        </child>
       </object>
     </child>
   </template>
diff --git a/src/gs-category.c b/src/gs-category.c
index 5934038..c761ceb 100644
--- a/src/gs-category.c
+++ b/src/gs-category.c
@@ -40,6 +40,7 @@ struct _GsCategory
 
        gchar           *id;
        gchar           *name;
+       gchar           *icon;
        GsCategory      *parent;
        guint            size;
        GPtrArray       *children;
@@ -156,6 +157,53 @@ gs_category_set_name (GsCategory *category, const gchar *name)
 }
 
 /**
+ * gs_category_get_icon:
+ * @category: a #GsCategory
+ *
+ * Gets the category icon.
+ *
+ * Returns: the string, or %NULL
+ **/
+const gchar *
+gs_category_get_icon (GsCategory *category)
+{
+       g_return_val_if_fail (GS_IS_CATEGORY (category), NULL);
+
+       /* special case, we don't want translations in the plugins */
+       if (g_strcmp0 (category->id, "other") == 0) {
+               /* TRANSLATORS: this is where all applications that don't
+                * fit in other groups are put */
+               return _("Other");
+       }
+       if (g_strcmp0 (category->id, "all") == 0) {
+               /* TRANSLATORS: this is a subcategory matching all the
+                * different apps in the parent category, e.g. "Games" */
+               return _("All");
+       }
+       if (g_strcmp0 (category->id, "featured") == 0) {
+               /* TRANSLATORS: this is a subcategory of featured apps */
+               return _("Featured");
+       }
+
+       return category->icon;
+}
+
+/**
+ * gs_category_set_icon:
+ * @category: a #GsCategory
+ * @icon: a category icon, or %NULL
+ *
+ * Sets the category icon.
+ **/
+void
+gs_category_set_icon (GsCategory *category, const gchar *icon)
+{
+       g_return_if_fail (GS_IS_CATEGORY (category));
+       g_free (category->icon);
+       category->icon = g_strdup (icon);
+}
+
+/**
  * gs_category_find_child:
  * @category: a #GsCategory
  * @id: a category ID, e.g. "other"
@@ -286,6 +334,7 @@ gs_category_finalize (GObject *object)
        g_ptr_array_unref (category->children);
        g_free (category->id);
        g_free (category->name);
+       g_free (category->icon);
 
        G_OBJECT_CLASS (gs_category_parent_class)->finalize (object);
 }
diff --git a/src/gs-category.h b/src/gs-category.h
index f597162..95ef917 100644
--- a/src/gs-category.h
+++ b/src/gs-category.h
@@ -38,6 +38,9 @@ GsCategory    *gs_category_get_parent         (GsCategory     *category);
 const gchar    *gs_category_get_name           (GsCategory     *category);
 void            gs_category_set_name           (GsCategory     *category,
                                                 const gchar    *name);
+const gchar    *gs_category_get_icon           (GsCategory     *category);
+void            gs_category_set_icon           (GsCategory     *category,
+                                                const gchar    *icon);
 
 GsCategory     *gs_category_find_child         (GsCategory     *category,
                                                 const gchar    *id);
diff --git a/src/plugins/gs-plugin-menu-spec-categories.c b/src/plugins/gs-plugin-menu-spec-categories.c
index 6937210..133eaf8 100644
--- a/src/plugins/gs-plugin-menu-spec-categories.c
+++ b/src/plugins/gs-plugin-menu-spec-categories.c
@@ -49,6 +49,7 @@ gs_plugin_add_categories (GsPlugin *plugin,
                tmp = g_strstr_len (msdata[i].path, -1, "::");
                if (tmp == NULL) {
                        category = gs_category_new (msdata[i].path);
+                       gs_category_set_icon (category, msdata[i].icon);
                        gs_category_set_name (category, gettext (msdata[i].text));
                        g_ptr_array_add (list, category);
                        g_snprintf (msgctxt, 100, "Menu subcategory of %s", msdata[i].text);


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