[gnome-software] trivial: Move out some shared functionality for searching a store



commit a0a3d06a5d80bba8b3cab4bbb85ed6449f30b682
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

 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 53c5572..4e175e1 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -741,3 +741,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 c1c0e87..8b87c8f 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -594,41 +594,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,
@@ -637,27 +602,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]