[gnome-software] Break out the category tile as a separate widget
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Break out the category tile as a separate widget
- Date: Sat, 7 Sep 2013 05:18:07 +0000 (UTC)
commit 0d5fc4b8850592efd8678ce83d770e36cccc8a38
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Sep 7 01:17:30 2013 -0400
Break out the category tile as a separate widget
Also, move to a separate template.
src/Makefile.am | 2 +
src/category-tile.ui | 23 +++++++
src/gnome-software.gresource.xml | 1 +
src/gs-category-tile.c | 134 ++++++++++++++++++++++++++++++++++++++
src/gs-category-tile.h | 64 ++++++++++++++++++
src/gs-shell-overview.c | 44 ++++---------
6 files changed, 238 insertions(+), 30 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0158216..e510bb6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -43,6 +43,8 @@ gnome_software_SOURCES = \
gs-popular-tile.h \
gs-feature-tile.c \
gs-feature-tile.h \
+ gs-category-tile.c \
+ gs-category-tile.h \
gs-box.h \
gs-box.c \
gs-plugin.c \
diff --git a/src/category-tile.ui b/src/category-tile.ui
new file mode 100644
index 0000000..98f160e
--- /dev/null
+++ b/src/category-tile.ui
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.10 -->
+ <template class="GsCategoryTile" parent="GtkBin">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkButton" id="button">
+ <property name="visible">True</property>
+ <style>
+ <class name="view"/>
+ <class name="tile"/>
+ </style>
+ <child>
+ <object class="GtkLabel" id="label">
+ <property name="visible">True</property>
+ <property name="margin">12</property>
+ <property name="xalign">0</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/gnome-software.gresource.xml b/src/gnome-software.gresource.xml
index c792bd7..e5166ac 100644
--- a/src/gnome-software.gresource.xml
+++ b/src/gnome-software.gresource.xml
@@ -5,6 +5,7 @@
<file preprocess="xml-stripblanks">app-menu.ui</file>
<file preprocess="xml-stripblanks">popular-tile.ui</file>
<file preprocess="xml-stripblanks">feature-tile.ui</file>
+ <file preprocess="xml-stripblanks">category-tile.ui</file>
<file>gtk-style.css</file>
<file>shadow.png</file>
<file>shadow-active.png</file>
diff --git a/src/gs-category-tile.c b/src/gs-category-tile.c
new file mode 100644
index 0000000..9095c0c
--- /dev/null
+++ b/src/gs-category-tile.c
@@ -0,0 +1,134 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "gs-category-tile.h"
+
+struct _GsCategoryTilePrivate
+{
+ GsCategory *cat;
+ GtkWidget *button;
+ GtkWidget *label;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GsCategoryTile, gs_category_tile, GTK_TYPE_BIN)
+
+enum {
+ SIGNAL_CLICKED,
+ SIGNAL_LAST
+};
+
+static guint signals [SIGNAL_LAST] = { 0 };
+
+GsCategory *
+gs_category_tile_get_category (GsCategoryTile *tile)
+{
+ GsCategoryTilePrivate *priv;
+
+ g_return_val_if_fail (GS_IS_CATEGORY_TILE (tile), NULL);
+
+ priv = gs_category_tile_get_instance_private (tile);
+ return priv->cat;
+}
+
+void
+gs_category_tile_set_category (GsCategoryTile *tile, GsCategory *cat)
+{
+ GsCategoryTilePrivate *priv;
+
+ g_return_if_fail (GS_IS_CATEGORY_TILE (tile));
+ g_return_if_fail (GS_IS_CATEGORY (cat));
+
+ priv = gs_category_tile_get_instance_private (tile);
+
+ g_clear_object (&priv->cat);
+ priv->cat = g_object_ref (cat);
+
+ gtk_label_set_label (GTK_LABEL (priv->label), gs_category_get_name (cat));
+}
+
+static void
+gs_category_tile_destroy (GtkWidget *widget)
+{
+ GsCategoryTile *tile = GS_CATEGORY_TILE (widget);
+ GsCategoryTilePrivate *priv;
+
+ priv = gs_category_tile_get_instance_private (tile);
+
+ g_clear_object (&priv->cat);
+
+ GTK_WIDGET_CLASS (gs_category_tile_parent_class)->destroy (widget);
+}
+
+static void
+button_clicked (GsCategoryTile *tile)
+{
+ g_signal_emit (tile, signals[SIGNAL_CLICKED], 0);
+}
+
+static void
+gs_category_tile_init (GsCategoryTile *tile)
+{
+ GsCategoryTilePrivate *priv;
+
+ gtk_widget_set_has_window (GTK_WIDGET (tile), FALSE);
+ gtk_widget_init_template (GTK_WIDGET (tile));
+ priv = gs_category_tile_get_instance_private (tile);
+ g_signal_connect_swapped (priv->button, "clicked",
+ G_CALLBACK (button_clicked), tile);
+}
+
+static void
+gs_category_tile_class_init (GsCategoryTileClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ widget_class->destroy = gs_category_tile_destroy;
+
+ signals [SIGNAL_CLICKED] =
+ g_signal_new ("clicked",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GsCategoryTileClass, clicked),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/software/category-tile.ui");
+
+ gtk_widget_class_bind_template_child_private (widget_class, GsCategoryTile, button);
+ gtk_widget_class_bind_template_child_private (widget_class, GsCategoryTile, label);
+}
+
+GtkWidget *
+gs_category_tile_new (GsCategory *cat)
+{
+ GsCategoryTile *tile;
+
+ tile = g_object_new (GS_TYPE_CATEGORY_TILE, NULL);
+ gs_category_tile_set_category (tile, cat);
+
+ return GTK_WIDGET (tile);
+}
+
diff --git a/src/gs-category-tile.h b/src/gs-category-tile.h
new file mode 100644
index 0000000..e536a80
--- /dev/null
+++ b/src/gs-category-tile.h
@@ -0,0 +1,64 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2013 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef GS_CATEGORY_TILE_H
+#define GS_CATEGORY_TILE_H
+
+#include <gtk/gtk.h>
+
+#include "gs-category.h"
+
+#define GS_TYPE_CATEGORY_TILE (gs_category_tile_get_type())
+#define GS_CATEGORY_TILE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GS_TYPE_CATEGORY_TILE,
GsCategoryTile))
+#define GS_CATEGORY_TILE_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls), GS_TYPE_CATEGORY_TILE,
GsCategoryTileClass))
+#define GS_IS_CATEGORY_TILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GS_TYPE_CATEGORY_TILE))
+#define GS_IS_CATEGORY_TILE_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls), GS_TYPE_CATEGORY_TILE))
+#define GS_CATEGORY_TILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GS_TYPE_CATEGORY_TILE,
GsCategoryTileClass))
+
+G_BEGIN_DECLS
+
+typedef struct _GsCategoryTile GsCategoryTile;
+typedef struct _GsCategoryTileClass GsCategoryTileClass;
+typedef struct _GsCategoryTilePrivate GsCategoryTilePrivate;
+
+struct _GsCategoryTile
+{
+ GtkBin parent;
+ GsCategoryTilePrivate *priv;
+};
+
+struct _GsCategoryTileClass
+{
+ GtkBinClass parent_class;
+
+ void (*clicked) (GsCategoryTile *tile);
+};
+
+GType gs_category_tile_get_type (void);
+GtkWidget *gs_category_tile_new (GsCategory *cat);
+GsCategory *gs_category_tile_get_category (GsCategoryTile *tile);
+void gs_category_tile_set_category (GsCategoryTile *tile,
+ GsCategory *cat);
+
+G_END_DECLS
+
+#endif /* GS_CATEGORY_TILE_H */
+
diff --git a/src/gs-shell-overview.c b/src/gs-shell-overview.c
index b48d8af..ae5cd10 100644
--- a/src/gs-shell-overview.c
+++ b/src/gs-shell-overview.c
@@ -29,6 +29,7 @@
#include "gs-category.h"
#include "gs-popular-tile.h"
#include "gs-feature-tile.h"
+#include "gs-category-tile.h"
#include "gs-utils.h"
struct GsShellOverviewPrivate
@@ -111,35 +112,6 @@ out:
}
static void
-category_tile_clicked (GtkButton *button, gpointer data)
-{
- GsShellOverview *shell = GS_SHELL_OVERVIEW (data);
- GsCategory *category;
-
- category = GS_CATEGORY (g_object_get_data (G_OBJECT (button), "category"));
- gs_shell_show_category (shell->priv->shell, category);
-}
-
-static GtkWidget *
-create_category_tile (GsShellOverview *shell, GsCategory *category)
-{
- GtkWidget *button, *label;
-
- button = gtk_button_new ();
- gtk_style_context_add_class (gtk_widget_get_style_context (button), "view");
- gtk_style_context_add_class (gtk_widget_get_style_context (button), "tile");
- label = gtk_label_new (gs_category_get_name (category));
- g_object_set (label, "margin", 12, "xalign", 0, NULL);
- gtk_container_add (GTK_CONTAINER (button), label);
- gtk_widget_show_all (button);
- 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);
-
- return button;
-}
-
-static void
feature_tile_clicked (GsFeatureTile *tile, gpointer data)
{
GsShellOverview *shell = GS_SHELL_OVERVIEW (data);
@@ -188,6 +160,16 @@ out:
g_signal_emit (shell, signals[SIGNAL_REFRESHED], 0);
}
+static void
+category_tile_clicked (GsCategoryTile *tile, gpointer data)
+{
+ GsShellOverview *shell = GS_SHELL_OVERVIEW (data);
+ GsCategory *category;
+
+ category = gs_category_tile_get_category (tile);
+ gs_shell_show_category (shell->priv->shell, category);
+}
+
/**
* gs_shell_overview_get_categories_cb:
**/
@@ -216,7 +198,9 @@ gs_shell_overview_get_categories_cb (GObject *source_object,
grid = GTK_WIDGET (gtk_builder_get_object (priv->builder, "grid_categories"));
for (l = list, i = 0; l; l = l->next, i++) {
cat = GS_CATEGORY (l->data);
- tile = create_category_tile (shell, cat);
+ tile = gs_category_tile_new (cat);
+ g_signal_connect (tile, "clicked",
+ G_CALLBACK (category_tile_clicked), shell);
gtk_grid_attach (GTK_GRID (grid), tile, i % 3, i / 3, 1, 1);
}
g_list_free_full (list, g_object_unref);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]