[gnome-software] Add a skeleton for GsCategory



commit 234d91890e9cebe8f48022ce050da32352e49bea
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Aug 29 13:11:59 2013 -0400

    Add a skeleton for GsCategory
    
    This will be an object to replace the use of hardcoded
    strings for categories.

 src/Makefile.am   |    2 +
 src/gs-category.c |  118 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gs-category.h |   65 +++++++++++++++++++++++++++++
 3 files changed, 185 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 403e0e5..ec4b0bd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,6 +34,8 @@ gnome_software_SOURCES =                              \
        gs-utils.h                                      \
        gs-app.c                                        \
        gs-app.h                                        \
+       gs-category.c                                   \
+       gs-category.h                                   \
        gs-app-widget.c                                 \
        gs-app-widget.h                                 \
        gs-plugin.c                                     \
diff --git a/src/gs-category.c b/src/gs-category.c
new file mode 100644
index 0000000..1e7b021
--- /dev/null
+++ b/src/gs-category.c
@@ -0,0 +1,118 @@
+/* -*- 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 "gs-category.h"
+
+static void    gs_category_finalize    (GObject        *object);
+
+#define GS_CATEGORY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GS_TYPE_CATEGORY, GsCategoryPrivate))
+
+struct GsCategoryPrivate
+{
+       gchar           *id;
+       gchar           *name;
+        GsCategory      *parent;
+        GList           *subcategories;
+};
+
+G_DEFINE_TYPE (GsCategory, gs_category, G_TYPE_OBJECT)
+
+const gchar *
+gs_category_get_id (GsCategory *category)
+{
+       g_return_val_if_fail (GS_IS_CATEGORY (category), NULL);
+       return category->priv->id;
+}
+
+const gchar *
+gs_category_get_name (GsCategory *category)
+{
+       g_return_val_if_fail (GS_IS_CATEGORY (category), NULL);
+       return category->priv->name;
+}
+
+void
+gs_category_set_name (GsCategory *category, const gchar *name)
+{
+       g_return_if_fail (GS_IS_CATEGORY (category));
+       g_free (category->priv->name);
+       category->priv->name = g_strdup (name);
+}
+
+GsCategory *
+gs_category_get_parent (GsCategory *category)
+{
+       g_return_val_if_fail (GS_IS_CATEGORY (category), NULL);
+        return category->priv->parent;
+}
+
+GList *
+gs_category_get_subcategories (GsCategory *category)
+{
+       g_return_val_if_fail (GS_IS_CATEGORY (category), NULL);
+        return g_list_copy (category->priv->subcategories);
+}
+
+void
+gs_category_add_subcategory (GsCategory *category, GsCategory *subcategory)
+{
+       g_return_if_fail (GS_IS_CATEGORY (category));
+        category->priv->subcategories = g_list_prepend (category->priv->subcategories, g_object_ref 
(subcategory));
+}
+
+static void
+gs_category_class_init (GsCategoryClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       object_class->finalize = gs_category_finalize;
+       g_type_class_add_private (klass, sizeof (GsCategoryPrivate));
+}
+
+static void
+gs_category_init (GsCategory *category)
+{
+       category->priv = GS_CATEGORY_GET_PRIVATE (category);
+}
+
+static void
+gs_category_finalize (GObject *object)
+{
+       GsCategory *category = GS_CATEGORY (object);
+       GsCategoryPrivate *priv = category->priv;
+
+       g_free (priv->id);
+       g_free (priv->name);
+        g_list_free_full (priv->subcategories, g_object_unref);
+
+       G_OBJECT_CLASS (gs_category_parent_class)->finalize (object);
+}
+
+GsCategory *
+gs_category_new (GsCategory *parent, const gchar *id)
+{
+       GsCategory *category;
+       category = g_object_new (GS_TYPE_CATEGORY, NULL);
+        category->priv->parent = parent;
+        category->priv->id = g_strdup (id);
+       return GS_CATEGORY (category);
+}
diff --git a/src/gs-category.h b/src/gs-category.h
new file mode 100644
index 0000000..b12f711
--- /dev/null
+++ b/src/gs-category.h
@@ -0,0 +1,65 @@
+/* -*- 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_H
+#define __GS_CATEGORY_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GS_TYPE_CATEGORY               (gs_category_get_type ())
+#define GS_CATEGORY(o)         (G_TYPE_CHECK_INSTANCE_CAST ((o), GS_TYPE_CATEGORY, GsCategory))
+#define GS_CATEGORY_CLASS(k)           (G_TYPE_CHECK_CLASS_CAST((k), GS_TYPE_CATEGORY, GsCategoryClass))
+#define GS_IS_CATEGORY(o)              (G_TYPE_CHECK_INSTANCE_TYPE ((o), GS_TYPE_CATEGORY))
+#define GS_IS_CATEGORY_CLASS(k)        (G_TYPE_CHECK_CLASS_TYPE ((k), GS_TYPE_CATEGORY))
+#define GS_CATEGORY_GET_CLASS(o)       (G_TYPE_INSTANCE_GET_CLASS ((o), GS_TYPE_CATEGORY, GsCategoryClass))
+
+typedef struct GsCategoryPrivate GsCategoryPrivate;
+
+typedef struct
+{
+        GObject                 parent;
+        GsCategoryPrivate      *priv;
+} GsCategory;
+
+typedef struct
+{
+       GObjectClass             parent_class;
+} GsCategoryClass;
+
+GType           gs_category_get_type           (void);
+
+GsCategory     *gs_category_new                (GsCategory             *parent,
+                                                 const gchar           *id);
+const gchar    *gs_category_get_id             (GsCategory             *category);
+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);
+GList           *gs_category_get_subcategories  (GsCategory             *category);
+void             gs_category_add_subcategory    (GsCategory             *category,
+                                                 GsCategory             *subcategory);
+
+
+G_END_DECLS
+
+#endif /* __GS_CATEGORY_H */


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