[gnome-software/wip/kalev/gnome-3-22-prep: 5/52] trivial: Move out some shared functionality for searching a store
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/kalev/gnome-3-22-prep: 5/52] trivial: Move out some shared functionality for searching a store
- Date: Mon, 7 Nov 2016 09:45:12 +0000 (UTC)
commit 0ee32e78edd86f121e13103025c1e822d935cd90
Author: Richard Hughes <richard hughsie com>
Date: Tue Sep 13 16:40:37 2016 +0100
trivial: Move out some shared functionality for searching a store
(cherry picked from commit a0a3d06a5d80bba8b3cab4bbb85ed6449f30b682)
src/plugins/gs-appstream.c | 68 +++++++++++++++++++++++++++++++++++++
src/plugins/gs-appstream.h | 6 +++
src/plugins/gs-plugin-appstream.c | 62 +++------------------------------
3 files changed, 80 insertions(+), 56 deletions(-)
---
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index 76a53a4..e9984d9 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -728,3 +728,71 @@ gs_appstream_refine_app (GsPlugin *plugin,
return TRUE;
}
+
+static gboolean
+gs_appstream_store_search_item (GsPlugin *plugin,
+ AsApp *item,
+ gchar **values,
+ GsAppList *list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ AsApp *item_tmp;
+ GPtrArray *addons;
+ guint i;
+ guint match_value;
+ g_autoptr(GsApp) app = NULL;
+
+ /* match against the app or any of the addons */
+ match_value = as_app_search_matches_all (item, values);
+ addons = as_app_get_addons (item);
+ for (i = 0; i < addons->len; i++) {
+ item_tmp = g_ptr_array_index (addons, i);
+ match_value |= as_app_search_matches_all (item_tmp, values);
+ }
+
+ /* no match */
+ if (match_value == 0)
+ return TRUE;
+
+ /* create app */
+ app = gs_appstream_create_app (plugin, item);
+ if (!gs_appstream_refine_app (plugin, app, item, error))
+ return FALSE;
+ gs_app_set_match_value (app, match_value);
+ gs_app_list_add (list, app);
+ return TRUE;
+}
+
+gboolean
+gs_appstream_store_search (GsPlugin *plugin,
+ AsStore *store,
+ gchar **values,
+ GsAppList *list,
+ GCancellable *cancellable,
+ GError **error)
+{
+ AsApp *item;
+ GPtrArray *array;
+ gboolean ret = TRUE;
+ guint i;
+ g_autoptr(AsProfileTask) ptask = NULL;
+
+ /* search categories for the search term */
+ ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+ "appstream::search");
+ g_assert (ptask != NULL);
+ array = as_store_get_apps (store);
+ for (i = 0; i < array->len; i++) {
+ if (g_cancellable_set_error_if_cancelled (cancellable, error))
+ return FALSE;
+
+ item = g_ptr_array_index (array, i);
+ ret = gs_appstream_store_search_item (plugin, item,
+ values, list,
+ cancellable, error);
+ if (!ret)
+ return FALSE;
+ }
+ return TRUE;
+}
diff --git a/src/plugins/gs-appstream.h b/src/plugins/gs-appstream.h
index f17370d..7a7440d 100644
--- a/src/plugins/gs-appstream.h
+++ b/src/plugins/gs-appstream.h
@@ -35,6 +35,12 @@ gboolean gs_appstream_refine_app (GsPlugin *plugin,
GsApp *gs_appstream_create_runtime (GsPlugin *plugin,
GsApp *parent,
const gchar *runtime);
+gboolean gs_appstream_store_search (GsPlugin *plugin,
+ AsStore *store,
+ gchar **values,
+ GsAppList *list,
+ GCancellable *cancellable,
+ GError **error);
G_END_DECLS
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index cc1b0e6..c947cce 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -592,41 +592,6 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
return TRUE;
}
-static gboolean
-gs_plugin_add_search_item (GsPlugin *plugin,
- GsAppList *list,
- AsApp *item,
- gchar **values,
- GCancellable *cancellable,
- GError **error)
-{
- AsApp *item_tmp;
- GPtrArray *addons;
- guint i;
- guint match_value;
- g_autoptr(GsApp) app = NULL;
-
- /* match against the app or any of the addons */
- match_value = as_app_search_matches_all (item, values);
- addons = as_app_get_addons (item);
- for (i = 0; i < addons->len; i++) {
- item_tmp = g_ptr_array_index (addons, i);
- match_value |= as_app_search_matches_all (item_tmp, values);
- }
-
- /* no match */
- if (match_value == 0)
- return TRUE;
-
- /* create app */
- app = gs_plugin_appstream_create_app (plugin, item);
- if (!gs_appstream_refine_app (plugin, app, item, error))
- return FALSE;
- gs_app_set_match_value (app, match_value);
- gs_app_list_add (list, app);
- return TRUE;
-}
-
gboolean
gs_plugin_add_search (GsPlugin *plugin,
gchar **values,
@@ -635,27 +600,12 @@ gs_plugin_add_search (GsPlugin *plugin,
GError **error)
{
GsPluginData *priv = gs_plugin_get_data (plugin);
- AsApp *item;
- GPtrArray *array;
- gboolean ret = TRUE;
- guint i;
- g_autoptr(AsProfileTask) ptask = NULL;
-
- /* search categories for the search term */
- ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
- "appstream::search");
- g_assert (ptask != NULL);
- array = as_store_get_apps (priv->store);
- for (i = 0; i < array->len; i++) {
- if (g_cancellable_set_error_if_cancelled (cancellable, error))
- return FALSE;
-
- item = g_ptr_array_index (array, i);
- ret = gs_plugin_add_search_item (plugin, list, item, values, cancellable, error);
- if (!ret)
- return FALSE;
- }
- return TRUE;
+ return gs_appstream_store_search (plugin,
+ priv->store,
+ values,
+ list,
+ cancellable,
+ error);
}
gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]