[gnome-software] Use GsCategory for categories
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Use GsCategory for categories
- Date: Thu, 29 Aug 2013 18:28:22 +0000 (UTC)
commit 05e13a632468fa84dd954f6e9888522f1845343d
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Aug 29 14:26:40 2013 -0400
Use GsCategory for categories
Use GsCategory throughout instead of hardcoded strings.
The actual categories are still hardcoded, in gs-shell-overview.c.
The next step will be to move generation of the category list
to the plugins.
src/gs-shell-category.c | 84 ++++++++++++++++++----------------------
src/gs-shell-category.h | 4 +-
src/gs-shell-overview.c | 97 ++++++++++++++++++++++++++++++++++------------
src/gs-shell.c | 6 +-
src/gs-shell.h | 4 +-
5 files changed, 117 insertions(+), 78 deletions(-)
---
diff --git a/src/gs-shell-category.c b/src/gs-shell-category.c
index b51d19d..a85f764 100644
--- a/src/gs-shell-category.c
+++ b/src/gs-shell-category.c
@@ -34,7 +34,7 @@ struct GsShellCategoryPrivate
{
GtkBuilder *builder;
GsShell *shell;
- gchar *category;
+ GsCategory *category;
};
G_DEFINE_TYPE (GsShellCategory, gs_shell_category, G_TYPE_OBJECT)
@@ -49,7 +49,7 @@ gs_shell_category_refresh (GsShellCategory *shell)
gtk_widget_show (widget);
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "application_details_header"));
gtk_widget_show (widget);
- gtk_label_set_label (GTK_LABEL (widget), priv->category);
+ gtk_label_set_label (GTK_LABEL (widget), gs_category_get_name (priv->category));
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_bar"));
gtk_widget_hide (widget);
@@ -119,7 +119,7 @@ create_app_tile (GsShellCategory *shell, GsApp *app)
}
static void
-gs_shell_category_populate_filtered (GsShellCategory *shell, const gchar *category, const gchar *filter)
+gs_shell_category_populate_filtered (GsShellCategory *shell, GsCategory *subcategory)
{
GsShellCategoryPrivate *priv = shell->priv;
gint i;
@@ -130,9 +130,8 @@ gs_shell_category_populate_filtered (GsShellCategory *shell, const gchar *catego
grid = GTK_WIDGET (gtk_builder_get_object (priv->builder, "category_detail_grid"));
gtk_grid_remove_column (GTK_GRID (grid), 2);
gtk_grid_remove_column (GTK_GRID (grid), 1);
- if (filter == NULL) {
+ if (!subcategory)
gtk_grid_remove_column (GTK_GRID (grid), 0);
- }
/* FIXME load apps for this category and filter */
app = gs_app_new ("gnome-boxes");
@@ -145,7 +144,7 @@ gs_shell_category_populate_filtered (GsShellCategory *shell, const gchar *catego
for (i = 0; i < 30; i++) {
tile = create_app_tile (shell, app);
- if (filter) {
+ if (subcategory) {
gtk_grid_attach (GTK_GRID (grid), tile, 1 + (i % 2), i / 2, 1, 1);
}
else {
@@ -170,19 +169,17 @@ static void
filter_selected (GtkListBox *filters, GtkListBoxRow *row, gpointer data)
{
GsShellCategory *shell = GS_SHELL_CATEGORY (data);
- const gchar *filter;
- const gchar *category;
+ GsCategory *subcategory;
if (row == NULL)
return;
- filter = gtk_label_get_label (GTK_LABEL (gtk_bin_get_child (GTK_BIN (row))));
- category = (const gchar*)g_object_get_data (G_OBJECT (filters), "category");
- gs_shell_category_populate_filtered (shell, category, filter);
+ subcategory = g_object_get_data (G_OBJECT (gtk_bin_get_child (GTK_BIN (row))), "subcategory");
+ gs_shell_category_populate_filtered (shell, subcategory);
}
-static void
-create_filter_list (GsShellCategory *shell, const gchar *category, const gchar *filters[])
+static GsCategory *
+create_filter_list (GsShellCategory *shell, GsCategory *category)
{
GsShellCategoryPrivate *priv = shell->priv;
GtkWidget *grid;
@@ -190,18 +187,28 @@ create_filter_list (GsShellCategory *shell, const gchar *category, const gchar *
GtkWidget *row;
GtkWidget *frame;
guint i;
+ GList *subcategories, *l;
+ GsCategory *subcategory;
+
+ subcategories = gs_category_get_subcategories (category);
+
+ if (!subcategories)
+ return NULL;
grid = GTK_WIDGET (gtk_builder_get_object (priv->builder, "category_detail_grid"));
list = gtk_list_box_new ();
- g_object_set_data (G_OBJECT (list), "category", (gpointer)category);
gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_BROWSE);
g_signal_connect (list, "row-selected", G_CALLBACK (filter_selected), shell);
gtk_list_box_set_header_func (GTK_LIST_BOX (list), add_separator, NULL, NULL);
- for (i = 0; filters[i]; i++) {
- row = gtk_label_new (filters[i]);
+ for (l = subcategories, i = 0; l; l = l->next, i++) {
+ subcategory = l->data;
+ row = gtk_label_new (gs_category_get_name (subcategory));
+ g_object_set_data_full (G_OBJECT (row), "subcategory", g_object_ref (subcategory),
g_object_unref);
g_object_set (row, "xalign", 0.0, "margin", 6, NULL);
gtk_list_box_insert (GTK_LIST_BOX (list), row, i);
}
+ g_list_free (subcategories);
+
frame = gtk_frame_new (NULL);
g_object_set (frame, "margin", 6, NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
@@ -210,43 +217,31 @@ create_filter_list (GsShellCategory *shell, const gchar *category, const gchar *
gtk_widget_show_all (frame);
gtk_widget_set_valign (frame, GTK_ALIGN_START);
gtk_grid_attach (GTK_GRID (grid), frame, 0, 0, 1, 5);
- gtk_list_box_select_row (GTK_LIST_BOX (list),
- gtk_list_box_get_row_at_index (GTK_LIST_BOX (list), 0));
+
+ row = GTK_WIDGET (gtk_list_box_get_row_at_index (GTK_LIST_BOX (list), 0));
+ gtk_list_box_select_row (GTK_LIST_BOX (list), GTK_LIST_BOX_ROW (row));
+
+ return GS_CATEGORY (g_object_get_data (G_OBJECT (gtk_bin_get_child (GTK_BIN (row))), "subcategory"));
}
void
-gs_shell_category_set_category (GsShellCategory *shell, const gchar *category)
+gs_shell_category_set_category (GsShellCategory *shell, GsCategory *category)
{
GsShellCategoryPrivate *priv = shell->priv;
GtkWidget *grid;
+ GsCategory *subcategory;
- g_free (priv->category);
- priv->category = g_strdup (category);
+ if (priv->category)
+ g_object_unref (priv->category);
+ priv->category = category;
+ if (priv->category)
+ g_object_ref (priv->category);
grid = GTK_WIDGET (gtk_builder_get_object (priv->builder, "category_detail_grid"));
container_remove_all (GTK_CONTAINER (grid));
- /* FIXME: get actual filters */
- if (g_str_equal (category, "Games")) {
- const gchar *filters[] = {
- "Popular", "Action", "Arcade", "Board",
- "Blocks", "Card", "Kids", "Logic", "Role Playing",
- "Shooter", "Simulation", "Sports", "Strategy",
- NULL
- };
- create_filter_list (shell, category, filters);
- }
- else if (g_str_equal (category, "Add-ons")) {
- const gchar *filters[] = {
- "Popular", "Codecs", "Fonts",
- "Input Sources", "Language Packs",
- NULL
- };
- create_filter_list (shell, category, filters);
- }
- else {
- gs_shell_category_populate_filtered (shell, category, NULL);
- }
+ subcategory = create_filter_list (shell, category);
+ gs_shell_category_populate_filtered (shell, subcategory);
}
static void
@@ -271,7 +266,7 @@ gs_shell_category_finalize (GObject *object)
GsShellCategoryPrivate *priv = shell->priv;
g_object_unref (priv->builder);
- g_free (priv->category);
+ g_object_unref (priv->category);
G_OBJECT_CLASS (gs_shell_category_parent_class)->finalize (object);
}
@@ -285,9 +280,6 @@ gs_shell_category_setup (GsShellCategory *shell_category, GsShell *shell, GtkBui
priv->shell = shell;
}
-/**
- * gs_shell_category_new:
- **/
GsShellCategory *
gs_shell_category_new (void)
{
diff --git a/src/gs-shell-category.h b/src/gs-shell-category.h
index e2ef8b7..63416f4 100644
--- a/src/gs-shell-category.h
+++ b/src/gs-shell-category.h
@@ -25,7 +25,7 @@
#include <glib-object.h>
#include <gtk/gtk.h>
-#include "gs-app.h"
+#include "gs-category.h"
#include "gs-shell.h"
#include "gs-plugin-loader.h"
@@ -55,7 +55,7 @@ GType gs_shell_category_get_type (void);
GsShellCategory *gs_shell_category_new (void);
void gs_shell_category_set_category (GsShellCategory *shell_category,
- const gchar *category);
+ GsCategory *category);
void gs_shell_category_refresh (GsShellCategory *shell_category);
void gs_shell_category_setup (GsShellCategory *shell_category,
GsShell *shell,
diff --git a/src/gs-shell-overview.c b/src/gs-shell-overview.c
index 1b0acad..fcf9d8e 100644
--- a/src/gs-shell-overview.c
+++ b/src/gs-shell-overview.c
@@ -21,9 +21,12 @@
#include "config.h"
+#include <glib/gi18n.h>
+
#include "gs-shell.h"
#include "gs-shell-overview.h"
#include "gs-app.h"
+#include "gs-category.h"
#include "gs-app-widget.h"
static void gs_shell_overview_finalize (GObject *object);
@@ -151,14 +154,14 @@ static void
category_tile_clicked (GtkButton *button, gpointer data)
{
GsShellOverview *shell_overview = GS_SHELL_OVERVIEW (data);
- const gchar *category;
+ GsCategory *category;
- category = g_object_get_data (G_OBJECT (button), "category");
+ category = GS_CATEGORY (g_object_get_data (G_OBJECT (button), "category"));
gs_shell_show_category (shell_overview->priv->shell, category);
}
static GtkWidget *
-create_category_tile (GsShellOverview *shell_overview, const gchar *category)
+create_category_tile (GsShellOverview *shell_overview, GsCategory *category)
{
GtkWidget *button, *frame, *label;
@@ -168,11 +171,11 @@ create_category_tile (GsShellOverview *shell_overview, const gchar *category)
gtk_container_add (GTK_CONTAINER (button), frame);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_style_context_add_class (gtk_widget_get_style_context (frame), "view");
- label = gtk_label_new (category);
+ label = gtk_label_new (gs_category_get_name (category));
g_object_set (label, "margin", 12, "xalign", 0, NULL);
gtk_container_add (GTK_CONTAINER (frame), label);
gtk_widget_show_all (button);
- g_object_set_data (G_OBJECT (button), "category", (gpointer)category);
+ g_object_set_data_full (G_OBJECT (button), "category", g_object_ref (category), g_object_unref);
g_signal_connect (button, "clicked",
G_CALLBACK (category_tile_clicked), shell_overview);
@@ -225,28 +228,60 @@ out:
return;
}
-static void
+static GList *
gs_shell_overview_get_categories (GsShellOverview *shell_overview)
{
- GsShellOverviewPrivate *priv = shell_overview->priv;
- GtkWidget *grid;
- /* FIXME get real categories */
- const gchar *categories[] = {
- "Add-ons", "Books", "Business & Finance",
- "Entertainment", "Education", "Games",
- "Lifestyle", "Music", "Navigation",
- "Overviews", "Photo & Video", "Productivity",
- "Social Networking", "Utility", "Weather",
- };
- guint i;
- GtkWidget *tile;
-
- grid = GTK_WIDGET (gtk_builder_get_object (priv->builder, "grid_categories"));
-
- for (i = 0; i < G_N_ELEMENTS (categories); i++) {
- tile = create_category_tile (shell_overview, categories[i]);
- gtk_grid_attach (GTK_GRID (grid), tile, i % 3, i / 3, 1, 1);
- }
+ GsCategory *category;
+ GList *list = NULL;
+
+ category = gs_category_new (NULL, "add-ons", _("Add-ons"));
+ list = g_list_append (list, category);
+ gs_category_add_subcategory (category, gs_category_new (category, "codecs", _("Codecs")));
+ gs_category_add_subcategory (category, gs_category_new (category, "fonts", _("Fonts")));
+ gs_category_add_subcategory (category, gs_category_new (category, "inputs", _("Input Sources")));
+ gs_category_add_subcategory (category, gs_category_new (category, "languages", _("Language Packs")));
+ category = gs_category_new (NULL, "books", _("Books"));
+ list = g_list_append (list, category);
+ category = gs_category_new (NULL, "business", _("Business & Finance"));
+ list = g_list_append (list, category);
+ category = gs_category_new (NULL, "entertainment", _("Entertainment"));
+ list = g_list_append (list, category);
+ category = gs_category_new (NULL, "education", _("Education"));
+ list = g_list_append (list, category);
+ category = gs_category_new (NULL, "games", _("Games"));
+ list = g_list_append (list, category);
+ gs_category_add_subcategory (category, gs_category_new (category, "action", _("Action")));
+ gs_category_add_subcategory (category, gs_category_new (category, "arcade", _("Arcade")));
+ gs_category_add_subcategory (category, gs_category_new (category, "board", _("Board")));
+ gs_category_add_subcategory (category, gs_category_new (category, "blocks", _("Blocks")));
+ gs_category_add_subcategory (category, gs_category_new (category, "card", _("Card")));
+ gs_category_add_subcategory (category, gs_category_new (category, "kids", _("Kids")));
+ gs_category_add_subcategory (category, gs_category_new (category, "logic", _("Logic")));
+ gs_category_add_subcategory (category, gs_category_new (category, "role", _("Role Playing")));
+ gs_category_add_subcategory (category, gs_category_new (category, "shooter", _("Shooter")));
+ gs_category_add_subcategory (category, gs_category_new (category, "simulation", _("Simulation")));
+ gs_category_add_subcategory (category, gs_category_new (category, "sports", _("Sports")));
+ gs_category_add_subcategory (category, gs_category_new (category, "strategy", _("Strategy")));
+ category = gs_category_new (NULL, "lifestyle", _("Lifestyle"));
+ list = g_list_append (list, category);
+ category = gs_category_new (NULL, "music", _("Music"));
+ list = g_list_append (list, category);
+ category = gs_category_new (NULL, "navigation", _("Navigation"));
+ list = g_list_append (list, category);
+ category = gs_category_new (NULL, "overviews", _("Overviews"));
+ list = g_list_append (list, category);
+ category = gs_category_new (NULL, "photos", _("Photo & Video"));
+ list = g_list_append (list, category);
+ category = gs_category_new (NULL, "productivity", _("Productivity"));
+ list = g_list_append (list, category);
+ category = gs_category_new (NULL, "social", _("Social Networking"));
+ list = g_list_append (list, category);
+ category = gs_category_new (NULL, "utility", _("Utility"));
+ list = g_list_append (list, category);
+ category = gs_category_new (NULL, "weather", _("Weather"));
+ list = g_list_append (list, category);
+
+ return list;
}
/**
@@ -258,6 +293,10 @@ gs_shell_overview_refresh (GsShellOverview *shell_overview)
GsShellOverviewPrivate *priv = shell_overview->priv;
GtkWidget *widget;
GtkWidget *grid;
+ GList *list, *l;
+ gint i;
+ GtkWidget *tile;
+ GsCategory *category;
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "buttonbox_main"));
gtk_widget_show (widget);
@@ -293,7 +332,13 @@ gs_shell_overview_refresh (GsShellOverview *shell_overview)
grid = GTK_WIDGET (gtk_builder_get_object (priv->builder, "grid_categories"));
container_remove_all (GTK_CONTAINER (grid));
- gs_shell_overview_get_categories (shell_overview);
+ list = gs_shell_overview_get_categories (shell_overview);
+ for (l = list, i = 0; l; l = l->next, i++) {
+ category = l->data;
+ tile = create_category_tile (shell_overview, category);
+ gtk_grid_attach (GTK_GRID (grid), tile, i % 3, i / 3, 1, 1);
+ }
+ g_list_free_full (list, g_object_unref);
priv->cache_valid = TRUE;
}
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 331f190..7e7da08 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -54,7 +54,7 @@ struct GsShellPrivate
G_DEFINE_TYPE (GsShell, gs_shell, G_TYPE_OBJECT)
-static void gs_shell_set_overview_mode (GsShell *shell, GsShellMode mode, GsApp *app, const gchar *category);
+static void gs_shell_set_overview_mode (GsShell *shell, GsShellMode mode, GsApp *app, GsCategory *category);
/**
* gs_shell_activate:
@@ -71,7 +71,7 @@ gs_shell_activate (GsShell *shell)
* gs_shell_set_overview_mode:
**/
static void
-gs_shell_set_overview_mode (GsShell *shell, GsShellMode mode, GsApp *app, const gchar *category)
+gs_shell_set_overview_mode (GsShell *shell, GsShellMode mode, GsApp *app, GsCategory *category)
{
GsShellPrivate *priv = shell->priv;
GtkWidget *widget;
@@ -275,7 +275,7 @@ gs_shell_show_details (GsShell *shell, GsApp *app)
}
void
-gs_shell_show_category (GsShell *shell, const gchar *category)
+gs_shell_show_category (GsShell *shell, GsCategory *category)
{
gs_shell_set_overview_mode (shell, GS_SHELL_MODE_CATEGORY, NULL, category);
}
diff --git a/src/gs-shell.h b/src/gs-shell.h
index 4a22915..c2e9f54 100644
--- a/src/gs-shell.h
+++ b/src/gs-shell.h
@@ -26,6 +26,8 @@
#include <gtk/gtk.h>
#include "gs-plugin-loader.h"
+#include "gs-category.h"
+#include "gs-app.h"
G_BEGIN_DECLS
@@ -70,7 +72,7 @@ GsShellMode gs_shell_get_mode (GsShell *shell);
void gs_shell_show_details (GsShell *shell,
GsApp *app);
void gs_shell_show_category (GsShell *shell,
- const gchar *category);
+ GsCategory *category);
GtkWindow *gs_shell_setup (GsShell *shell,
GsPluginLoader *plugin_loader,
GCancellable *cancellable);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]