[gnome-software] Search the appstream data for name, summary, description and keywords
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Search the appstream data for name, summary, description and keywords
- Date: Fri, 13 Sep 2013 08:32:23 +0000 (UTC)
commit 58593ac5a437ed12af88d5a43a4aac0c5de0130f
Author: Richard Hughes <richard hughsie com>
Date: Fri Sep 13 09:31:42 2013 +0100
Search the appstream data for name, summary, description and keywords
Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=707841
src/plugins/appstream-app.c | 26 ++++++++++++++++++++++++
src/plugins/appstream-app.h | 2 +
src/plugins/gs-plugin-appstream.c | 40 +++++++++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/appstream-app.c b/src/plugins/appstream-app.c
index a60a79e..a4cf15e 100644
--- a/src/plugins/appstream-app.c
+++ b/src/plugins/appstream-app.c
@@ -21,6 +21,7 @@
#include "config.h"
+#define _GNU_SOURCE
#include <string.h>
#include "appstream-app.h"
@@ -350,3 +351,28 @@ appstream_app_set_icon_kind (AppstreamApp *app,
{
app->icon_kind = icon_kind;
}
+
+/**
+ * appstream_app_search_matches:
+ */
+gboolean
+appstream_app_search_matches (AppstreamApp *app, const gchar *search)
+{
+ const gchar *tmp;
+ guint i;
+
+ if (search == NULL)
+ return FALSE;
+ if (app->name != NULL && strcasestr (app->name, search) != NULL)
+ return TRUE;
+ if (app->summary != NULL && strcasestr (app->summary, search) != NULL)
+ return TRUE;
+ if (app->description != NULL && strcasestr (app->description, search) != NULL)
+ return TRUE;
+ for (i = 0; i < app->keywords->len; i++) {
+ tmp = g_ptr_array_index (app->keywords, i);
+ if (strcasestr (tmp, search) != NULL)
+ return TRUE;
+ }
+ return FALSE;
+}
diff --git a/src/plugins/appstream-app.h b/src/plugins/appstream-app.h
index df8dcaf..03c0569 100644
--- a/src/plugins/appstream-app.h
+++ b/src/plugins/appstream-app.h
@@ -86,6 +86,8 @@ gpointer appstream_app_get_userdata (AppstreamApp *app);
void appstream_app_set_userdata (AppstreamApp *app,
gpointer userdata,
GDestroyNotify userdata_destroy_func);
+gboolean appstream_app_search_matches (AppstreamApp *app,
+ const gchar *search);
G_END_DECLS
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 78d7d6b..c7a058d 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -438,3 +438,43 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
out:
return ret;
}
+
+/**
+ * gs_plugin_add_search:
+ */
+gboolean
+gs_plugin_add_search (GsPlugin *plugin,
+ const gchar *value,
+ GList **list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ AppstreamApp *item;
+ gboolean ret = TRUE;
+ GPtrArray *array;
+ GsApp *app;
+ guint i;
+
+ /* load XML files */
+ if (g_once_init_enter (&plugin->priv->done_init)) {
+ ret = gs_plugin_startup (plugin, error);
+ g_once_init_leave (&plugin->priv->done_init, TRUE);
+ if (!ret)
+ goto out;
+ }
+
+ /* search categories for the search term */
+ array = appstream_cache_get_items (plugin->priv->cache);
+ for (i = 0; i < array->len; i++) {
+ item = g_ptr_array_index (array, i);
+ if (appstream_app_search_matches (item, value)) {
+ app = gs_app_new (appstream_app_get_id (item));
+ ret = gs_plugin_refine_item (plugin, app, item, error);
+ if (!ret)
+ goto out;
+ gs_plugin_add_app (list, app);
+ }
+ }
+out:
+ return ret;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]