[gnome-software] Save the application categories in GsApp
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Save the application categories in GsApp
- Date: Thu, 10 Oct 2013 09:05:20 +0000 (UTC)
commit 8e02e20c7dbad40ae30a9ef6a37ad756e08b248f
Author: Richard Hughes <richard hughsie com>
Date: Wed Oct 9 22:08:24 2013 +0100
Save the application categories in GsApp
We'll need this if we want to show the menu in the details panel.
src/gs-app.c | 50 +++++++++++++++++++++++++++++++++++++
src/gs-app.h | 5 +++
src/plugins/appstream-app.c | 11 +++++++-
src/plugins/appstream-app.h | 1 +
src/plugins/gs-plugin-appstream.c | 4 +++
5 files changed, 70 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 5713f65..71eee79 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -62,6 +62,7 @@ struct GsAppPrivate
gchar *summary;
gchar *description;
GPtrArray *screenshots;
+ GPtrArray *categories;
gchar *url;
gchar *licence;
gchar *update_version;
@@ -994,6 +995,53 @@ gs_app_set_install_date (GsApp *app, guint64 install_date)
}
/**
+ * gs_app_get_categories:
+ */
+GPtrArray *
+gs_app_get_categories (GsApp *app)
+{
+ g_return_val_if_fail (GS_IS_APP (app), NULL);
+ return app->priv->categories;
+}
+
+/**
+ * gs_app_has_category:
+ */
+gboolean
+gs_app_has_category (GsApp *app, const gchar *category)
+{
+ const gchar *tmp;
+ guint i;
+
+ g_return_val_if_fail (GS_IS_APP (app), FALSE);
+
+ /* nothing set */
+ if (app->priv->categories == NULL)
+ return FALSE;
+
+ /* find the category */
+ for (i = 0; i < app->priv->categories->len; i++) {
+ tmp = g_ptr_array_index (app->priv->categories, i);
+ if (g_strcmp0 (tmp, category) == 0)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
+ * gs_app_set_categories:
+ */
+void
+gs_app_set_categories (GsApp *app, GPtrArray *categories)
+{
+ g_return_if_fail (GS_IS_APP (app));
+ g_return_if_fail (categories != NULL);
+ if (app->priv->categories != NULL)
+ g_ptr_array_unref (app->priv->categories);
+ app->priv->categories = g_ptr_array_ref (categories);
+}
+
+/**
* gs_app_get_property:
*/
static void
@@ -1231,6 +1279,8 @@ gs_app_finalize (GObject *object)
g_object_unref (priv->pixbuf);
if (priv->featured_pixbuf != NULL)
g_object_unref (priv->featured_pixbuf);
+ if (priv->categories != NULL)
+ g_ptr_array_unref (priv->categories);
G_OBJECT_CLASS (gs_app_parent_class)->finalize (object);
}
diff --git a/src/gs-app.h b/src/gs-app.h
index e28c67a..38b3eff 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -158,6 +158,11 @@ void gs_app_add_history (GsApp *app,
guint64 gs_app_get_install_date (GsApp *app);
void gs_app_set_install_date (GsApp *app,
guint64 install_date);
+GPtrArray *gs_app_get_categories (GsApp *app);
+void gs_app_set_categories (GsApp *app,
+ GPtrArray *categories);
+gboolean gs_app_has_category (GsApp *app,
+ const gchar *category);
G_END_DECLS
diff --git a/src/plugins/appstream-app.c b/src/plugins/appstream-app.c
index adf69a5..e56cd88 100644
--- a/src/plugins/appstream-app.c
+++ b/src/plugins/appstream-app.c
@@ -42,7 +42,7 @@ struct AppstreamApp
gchar *project_group;
gchar *icon;
AppstreamAppIconKind icon_kind;
- GPtrArray *appcategories;
+ GPtrArray *appcategories; /* of gchar* */
GPtrArray *keywords;
gpointer userdata;
GDestroyNotify userdata_destroy_func;
@@ -400,6 +400,15 @@ appstream_app_get_screenshots (AppstreamApp *app)
}
/**
+ * appstream_app_get_categories:
+ */
+GPtrArray *
+appstream_app_get_categories (AppstreamApp *app)
+{
+ return app->appcategories;
+}
+
+/**
* appstream_app_search_matches:
*/
gboolean
diff --git a/src/plugins/appstream-app.h b/src/plugins/appstream-app.h
index 6109a26..2c4973b 100644
--- a/src/plugins/appstream-app.h
+++ b/src/plugins/appstream-app.h
@@ -99,6 +99,7 @@ void appstream_app_set_userdata (AppstreamApp *app,
void appstream_app_add_screenshot (AppstreamApp *app,
AppstreamScreenshot *screenshot);
GPtrArray *appstream_app_get_screenshots (AppstreamApp *app);
+GPtrArray *appstream_app_get_categories (AppstreamApp *app);
gboolean appstream_app_search_matches (AppstreamApp *app,
const gchar *search);
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index c95e3d0..ede4c77 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -457,6 +457,10 @@ gs_plugin_refine_item (GsPlugin *plugin,
if (appstream_app_get_icon (item) != NULL && gs_app_get_pixbuf (app) == NULL)
gs_plugin_refine_item_pixbuf (plugin, app, item);
+ /* set categories */
+ if (appstream_app_get_categories (item) != NULL && gs_app_get_categories (app) == NULL)
+ gs_app_set_categories (app, appstream_app_get_categories (item));
+
/* set project group */
if (appstream_app_get_project_group (item) != NULL &&
gs_app_get_project_group (app) == NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]