diff options
author | Richard Hughes <richard@hughsie.com> | 2014-05-06 11:54:13 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2014-05-06 11:54:13 +0100 |
commit | 5f7911825eed969c0b918ac6d9d248a4a670d9b8 (patch) | |
tree | 6580eef51d8ff9ea962a523c0588151bf1f30bd5 | |
parent | cbb8ad8378861eb8f8fe574ef394f52ad642fc8c (diff) | |
download | appstream-glib-5f7911825eed969c0b918ac6d9d248a4a670d9b8.tar.gz |
Add as_app_has_category()
It's used in GNOME Software and now createrepo_as, so move it here.
-rw-r--r-- | libappstream-glib/as-app.c | 27 | ||||
-rw-r--r-- | libappstream-glib/as-app.h | 2 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 2 |
3 files changed, 31 insertions, 0 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index 477249d..011ef37 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -241,6 +241,33 @@ as_app_get_categories (AsApp *app) } /** + * as_app_has_category: + * @app: a #AsApp instance. + * @category: a category string, e.g. "DesktopSettings" + * + * Searches the category list for a specific item. + * + * Returns: %TRUE if the application has got the specified category + * + * Since: 0.1.5 + */ +gboolean +as_app_has_category (AsApp *app, const gchar *category) +{ + GPtrArray *categories; + const gchar *tmp; + guint i; + + categories = as_app_get_categories (app); + for (i = 0; i < categories->len; i++) { + tmp = g_ptr_array_index (categories, i); + if (g_strcmp0 (tmp, category) == 0) + return TRUE; + } + return FALSE; +} + +/** * as_app_get_compulsory_for_desktops: * @app: a #AsApp instance. * diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h index dcbb2a3..a0bcabd 100644 --- a/libappstream-glib/as-app.h +++ b/libappstream-glib/as-app.h @@ -183,6 +183,8 @@ const gchar *as_app_get_metadata_item (AsApp *app, const gchar *key); const gchar *as_app_get_url_item (AsApp *app, AsUrlKind url_kind); +gboolean as_app_has_category (AsApp *app, + const gchar *category); /* setters */ void as_app_set_id_full (AsApp *app, diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index de22618..5c60088 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -579,6 +579,8 @@ ch_test_app_parse_file_func (void) g_assert_cmpstr (as_app_get_metadata_item (app, "NoDisplay"), ==, ""); g_assert_cmpstr (as_app_get_project_group (app), ==, NULL); g_assert_cmpint (as_app_get_categories(app)->len, ==, 1); + g_assert (as_app_has_category (app, "System")); + g_assert (!as_app_has_category (app, "NotGoingToExist")); /* reparse with heuristics */ ret = as_app_parse_file (app, |