[gnome-software] Add gs_plugin_refine_app() to the loader and port the plugins



commit 0cb82535f5edfb58f59dd0dbbd1c378b38eb872b
Author: Richard Hughes <richard hughsie com>
Date:   Fri Mar 4 10:18:39 2016 +0000

    Add gs_plugin_refine_app() to the loader and port the plugins
    
    A lot of the plugins were just traversing the list, which lead to duplicated
    code. Leave the old function in place for plugins like PackageKit that have to
    batch up all the requests into one transaction for efficiency.

 src/gs-plugin-loader.c                      |   49 ++++++++---
 src/gs-plugin.h                             |   10 +++
 src/plugins/gs-plugin-appstream.c           |   28 +++----
 src/plugins/gs-plugin-dummy.c               |  117 ++++++++++++---------------
 src/plugins/gs-plugin-epiphany.c            |   43 +++-------
 src/plugins/gs-plugin-hardcoded-blacklist.c |   34 ++------
 src/plugins/gs-plugin-icons.c               |   44 +++-------
 src/plugins/gs-plugin-limba.c               |   46 +++-------
 src/plugins/gs-plugin-menu-spec-refine.c    |   46 ++++-------
 src/plugins/gs-plugin-packagekit-origin.c   |   47 +++--------
 src/plugins/gs-plugin-provenance.c          |   50 ++++--------
 src/plugins/gs-plugin-self-test.c           |   24 ++----
 src/plugins/gs-plugin-shell-extensions.c    |   33 ++------
 src/plugins/gs-plugin-steam.c               |   36 ++-------
 src/plugins/gs-plugin-ubuntu-reviews.c      |   33 +++-----
 src/plugins/gs-plugin-xdg-app-reviews.c     |   61 +++++---------
 src/plugins/gs-plugin-xdg-app.c             |   37 +++-----
 17 files changed, 272 insertions(+), 466 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 676767c..90bb10d 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -185,9 +185,8 @@ gs_plugin_loader_run_refine (GsPluginLoader *plugin_loader,
        GPtrArray *related;
        GsApp *app;
        GsPlugin *plugin;
-       GsPluginRefineFunc plugin_func = NULL;
+       const gchar *function_name_app = "gs_plugin_refine_app";
        const gchar *function_name = "gs_plugin_refine";
-       gboolean exists;
        gboolean ret = TRUE;
        guint i;
        g_autoptr(GsAppList) addons_list = NULL;
@@ -201,18 +200,20 @@ gs_plugin_loader_run_refine (GsPluginLoader *plugin_loader,
 
        /* run each plugin */
        for (i = 0; i < priv->plugins->len; i++) {
+               GsPluginRefineAppFunc plugin_app_func = NULL;
+               GsPluginRefineFunc plugin_func = NULL;
                g_autoptr(AsProfileTask) ptask = NULL;
-               g_autoptr(GError) error_local = NULL;
 
                plugin = g_ptr_array_index (priv->plugins, i);
                if (!plugin->enabled)
                        continue;
 
-               /* load the symbol */
-               exists = g_module_symbol (plugin->module,
-                                         function_name,
-                                         (gpointer *) &plugin_func);
-               if (!exists)
+               /* load the possible symbols */
+               g_module_symbol (plugin->module, function_name,
+                                (gpointer *) &plugin_func);
+               g_module_symbol (plugin->module, function_name_app,
+                                (gpointer *) &plugin_app_func);
+               if (plugin_func == NULL && plugin_app_func == NULL)
                        continue;
 
                /* profile the plugin runtime */
@@ -228,12 +229,32 @@ gs_plugin_loader_run_refine (GsPluginLoader *plugin_loader,
                                                  function_name_parent,
                                                  function_name);
                }
-               ret = plugin_func (plugin, list, flags, cancellable, &error_local);
-               if (!ret) {
-                       g_warning ("failed to call %s on %s: %s",
-                                  function_name, plugin->name,
-                                  error_local->message);
-                       continue;
+
+               /* run the batched plugin symbol then the per-app plugin */
+               if (plugin_func != NULL) {
+                       g_autoptr(GError) error_local = NULL;
+                       ret = plugin_func (plugin, list, flags,
+                                          cancellable, &error_local);
+                       if (!ret) {
+                               g_warning ("failed to call %s on %s: %s",
+                                          function_name, plugin->name,
+                                          error_local->message);
+                               continue;
+                       }
+               }
+               if (plugin_app_func != NULL) {
+                       for (l = *list; l != NULL; l = l->next) {
+                               g_autoptr(GError) error_local = NULL;
+                               app = GS_APP (l->data);
+                               ret = plugin_app_func (plugin, app, flags,
+                                                   cancellable, &error_local);
+                               if (!ret) {
+                                       g_warning ("failed to call %s on %s: %s",
+                                                  function_name_app, plugin->name,
+                                                  error_local->message);
+                                       continue;
+                               }
+                       }
                }
                gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_FINISHED);
        }
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index efbb5bd..6955bf5 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -156,6 +156,11 @@ typedef gboolean    (*GsPluginRefineFunc)          (GsPlugin       *plugin,
                                                         GsPluginRefineFlags flags,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
+typedef gboolean        (*GsPluginRefineAppFunc)       (GsPlugin       *plugin,
+                                                        GsApp          *app,
+                                                        GsPluginRefineFlags flags,
+                                                        GCancellable   *cancellable,
+                                                        GError         **error);
 typedef gboolean        (*GsPluginRefreshFunc  )       (GsPlugin       *plugin,
                                                         guint           cache_age,
                                                         GsPluginRefreshFlags flags,
@@ -261,6 +266,11 @@ gboolean    gs_plugin_refine                       (GsPlugin       *plugin,
                                                         GsPluginRefineFlags flags,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
+gboolean        gs_plugin_refine_app                   (GsPlugin       *plugin,
+                                                        GsApp          *app,
+                                                        GsPluginRefineFlags flags,
+                                                        GCancellable   *cancellable,
+                                                        GError         **error);
 gboolean        gs_plugin_launch                       (GsPlugin       *plugin,
                                                         GsApp          *app,
                                                         GCancellable   *cancellable,
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 1dc61c0..27a00ef 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -349,34 +349,28 @@ gs_plugin_add_distro_upgrades (GsPlugin *plugin,
 }
 
 /**
- * gs_plugin_refine:
+ * gs_plugin_refine_app:
  */
 gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
        gboolean found = FALSE;
-       GList *l;
-       GsApp *app;
-       g_autoptr(AsProfileTask) ptask = NULL;
        g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&plugin->priv->store_mutex);
 
        /* load XML files */
        if (!gs_plugin_appstream_startup (plugin, error))
                return FALSE;
 
-       ptask = as_profile_start_literal (plugin->profile, "appstream::refine");
-       for (l = *list; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-               if (!gs_plugin_refine_from_id (plugin, app, &found, error))
+       /* find by ID then package name */
+       if (!gs_plugin_refine_from_id (plugin, app, &found, error))
+               return FALSE;
+       if (!found) {
+               if (!gs_plugin_refine_from_pkgname (plugin, app, error))
                        return FALSE;
-               if (!found) {
-                       if (!gs_plugin_refine_from_pkgname (plugin, app, error))
-                               return FALSE;
-               }
        }
 
        /* sucess */
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index be10d98..60ea8bb 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -140,87 +140,74 @@ gs_plugin_add_popular (GsPlugin *plugin,
 }
 
 /**
- * gs_plugin_refine:
+ * gs_plugin_refine_app:
  */
 gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
-       GsApp *app;
-       GList *l;
-
-       for (l = *list; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-               if (gs_app_get_name (app) == NULL) {
-                       if (g_strcmp0 (gs_app_get_id (app), "gnome-boxes") == 0) {
-                               gs_app_set_license (app, GS_APP_QUALITY_NORMAL,
-                                                   "GPL-2.0+");
-                               gs_app_set_name (app, GS_APP_QUALITY_NORMAL,
-                                                "Boxes");
-                               gs_app_set_url (app, AS_URL_KIND_HOMEPAGE,
-                                               "http://www.gimp.org/";);
-                               gs_app_set_summary (app, GS_APP_QUALITY_NORMAL,
-                                                   "A simple GNOME 3 application "
-                                                   "to access remote or virtual systems");
-                               gs_app_set_description (app, GS_APP_QUALITY_NORMAL,
-                                                       "<p>long description!</p>");
-                       }
+       /* pkgname */
+       if (gs_app_get_name (app) == NULL) {
+               if (g_strcmp0 (gs_app_get_id (app), "gnome-boxes") == 0) {
+                       gs_app_set_license (app, GS_APP_QUALITY_NORMAL,
+                                           "GPL-2.0+");
+                       gs_app_set_name (app, GS_APP_QUALITY_NORMAL,
+                                        "Boxes");
+                       gs_app_set_url (app, AS_URL_KIND_HOMEPAGE,
+                                       "http://www.gimp.org/";);
+                       gs_app_set_summary (app, GS_APP_QUALITY_NORMAL,
+                                           "A simple GNOME 3 application "
+                                           "to access remote or virtual systems");
+                       gs_app_set_description (app, GS_APP_QUALITY_NORMAL,
+                                               "<p>long description!</p>");
                }
        }
 
        /* add fake review */
        if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS) {
-               for (l = *list; l != NULL; l = l->next) {
-                       g_autoptr(GsReview) review1 = NULL;
-                       g_autoptr(GsReview) review2 = NULL;
-                       g_autoptr(GDateTime) dt = NULL;
-                       app = GS_APP (l->data);
-                       dt = g_date_time_new_now_utc ();
+               g_autoptr(GsReview) review1 = NULL;
+               g_autoptr(GsReview) review2 = NULL;
+               g_autoptr(GDateTime) dt = NULL;
 
-                       /* set first review */
-                       review1 = gs_review_new ();
-                       gs_review_set_rating (review1, 50);
-                       gs_review_set_reviewer (review1, "Angela Avery");
-                       gs_review_set_summary (review1, "Steep learning curve, but worth it");
-                       gs_review_set_text (review1, "Best overall 3D application I've ever used overall 3D 
application I've ever used. Best overall 3D application I've ever used overall 3D application I've ever used. 
Best overall 3D application I've ever used overall 3D application I've ever used. Best overall 3D application 
I've ever used overall 3D application I've ever used.");
-                       gs_review_set_version (review1, "3.16.4");
-                       gs_review_set_date (review1, dt);
-                       gs_app_add_review (app, review1);
+               dt = g_date_time_new_now_utc ();
 
-                       /* set self review */
-                       review2 = gs_review_new ();
-                       gs_review_set_rating (review2, 100);
-                       gs_review_set_reviewer (review2, "Just Myself");
-                       gs_review_set_summary (review2, "I like this application");
-                       gs_review_set_text (review2, "I'm not very wordy myself.");
-                       gs_review_set_version (review2, "3.16.3");
-                       gs_review_set_date (review2, dt);
-                       gs_review_set_flags (review2, GS_REVIEW_FLAG_SELF);
-                       gs_app_add_review (app, review2);
-               }
+               /* set first review */
+               review1 = gs_review_new ();
+               gs_review_set_rating (review1, 50);
+               gs_review_set_reviewer (review1, "Angela Avery");
+               gs_review_set_summary (review1, "Steep learning curve, but worth it");
+               gs_review_set_text (review1, "Best overall 3D application I've ever used overall 3D 
application I've ever used. Best overall 3D application I've ever used overall 3D application I've ever used. 
Best overall 3D application I've ever used overall 3D application I've ever used. Best overall 3D application 
I've ever used overall 3D application I've ever used.");
+               gs_review_set_version (review1, "3.16.4");
+               gs_review_set_date (review1, dt);
+               gs_app_add_review (app, review1);
+
+               /* set self review */
+               review2 = gs_review_new ();
+               gs_review_set_rating (review2, 100);
+               gs_review_set_reviewer (review2, "Just Myself");
+               gs_review_set_summary (review2, "I like this application");
+               gs_review_set_text (review2, "I'm not very wordy myself.");
+               gs_review_set_version (review2, "3.16.3");
+               gs_review_set_date (review2, dt);
+               gs_review_set_flags (review2, GS_REVIEW_FLAG_SELF);
+               gs_app_add_review (app, review2);
        }
 
        /* add fake ratings */
        if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS) {
-               for (l = *list; l != NULL; l = l->next) {
-                       g_autoptr(GArray) ratings = NULL;
-                       const gint data[] = { 0, 10, 20, 30, 15, 2 };
-                       ratings = g_array_sized_new (FALSE, FALSE, sizeof (gint), 6);
-                       g_array_append_vals (ratings, data, 6);
-                       app = GS_APP (l->data);
-                       gs_app_set_review_ratings (app, ratings);
-               }
+               g_autoptr(GArray) ratings = NULL;
+               const gint data[] = { 0, 10, 20, 30, 15, 2 };
+               ratings = g_array_sized_new (FALSE, FALSE, sizeof (gint), 6);
+               g_array_append_vals (ratings, data, 6);
+               gs_app_set_review_ratings (app, ratings);
        }
 
        /* add a rating */
        if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING) {
-               for (l = *list; l != NULL; l = l->next) {
-                       app = GS_APP (l->data);
-                       gs_app_set_rating (app, 66);
-               }
+               gs_app_set_rating (app, 66);
        }
 
        return TRUE;
diff --git a/src/plugins/gs-plugin-epiphany.c b/src/plugins/gs-plugin-epiphany.c
index 2e7ca6b..cda1a62 100644
--- a/src/plugins/gs-plugin-epiphany.c
+++ b/src/plugins/gs-plugin-epiphany.c
@@ -262,13 +262,24 @@ gs_plugin_app_remove (GsPlugin *plugin, GsApp *app,
 /**
  * gs_plugin_refine_app:
  */
-static gboolean
-gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
        g_autofree gchar *fn = NULL;
        g_autofree gchar *hash = NULL;
        g_autofree gchar *id_nonfull = NULL;
 
+       if (gs_app_get_kind (app) != AS_APP_KIND_WEB_APP)
+               return TRUE;
+       if (gs_app_get_source_id_default (app) != NULL)
+               return TRUE;
+
+       gs_app_set_size (app, 4096);
+
        id_nonfull = _gs_app_get_id_nonfull (app);
        hash = g_compute_checksum_for_string (G_CHECKSUM_SHA1, gs_app_get_name (app), -1);
        fn = g_strdup_printf ("%s/epiphany/app-%s-%s/%s-%s.desktop",
@@ -288,34 +299,6 @@ gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
 }
 
 /**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
-{
-       GList *l;
-       GsApp *app;
-       const gchar *tmp;
-
-       for (l = *list; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-               if (gs_app_get_kind (app) != AS_APP_KIND_WEB_APP)
-                       continue;
-               gs_app_set_size (app, 4096);
-               tmp = gs_app_get_source_id_default (app);
-               if (tmp != NULL)
-                       continue;
-               if (!gs_plugin_refine_app (plugin, app, error))
-                       return FALSE;
-       }
-       return TRUE;
-}
-
-/**
  * gs_plugin_launch:
  */
 gboolean
diff --git a/src/plugins/gs-plugin-hardcoded-blacklist.c b/src/plugins/gs-plugin-hardcoded-blacklist.c
index 2a27de4..c871733 100644
--- a/src/plugins/gs-plugin-hardcoded-blacklist.c
+++ b/src/plugins/gs-plugin-hardcoded-blacklist.c
@@ -52,8 +52,12 @@ gs_plugin_get_deps (GsPlugin *plugin)
 /**
  * gs_plugin_refine_app:
  */
-static gboolean
-gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
        guint i;
        const gchar *app_globs[] = {
@@ -69,12 +73,14 @@ gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
                "tracker-preferences.desktop",
                "Uninstall*.desktop",
                NULL };
+       g_autoptr(AsProfileTask) ptask = NULL;
 
        /* not set yet */
        if (gs_app_get_id (app) == NULL)
                return TRUE;
 
        /* search */
+       ptask = as_profile_start_literal (plugin->profile, "hardcoded-blacklist");
        for (i = 0; app_globs[i] != NULL; i++) {
                if (fnmatch (app_globs[i], gs_app_get_id (app), 0) == 0) {
                        gs_app_add_category (app, "Blacklisted");
@@ -84,27 +90,3 @@ gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
 
        return TRUE;
 }
-
-/**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
-{
-       GList *l;
-       GsApp *app;
-       g_autoptr(AsProfileTask) ptask = NULL;
-
-       /* are any of the packages on the blacklist? */
-       ptask = as_profile_start_literal (plugin->profile, "hardcoded-blacklist");
-       for (l = *list; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-               if (!gs_plugin_refine_app (plugin, app, error))
-                       return FALSE;
-       }
-       return TRUE;
-}
diff --git a/src/plugins/gs-plugin-icons.c b/src/plugins/gs-plugin-icons.c
index 40e3563..218f24b 100644
--- a/src/plugins/gs-plugin-icons.c
+++ b/src/plugins/gs-plugin-icons.c
@@ -112,15 +112,25 @@ gs_plugin_icons_download (GsPlugin *plugin, const gchar *uri, const gchar *filen
 }
 
 /**
- * gs_plugin_refine:
+ * gs_plugin_refine_app:
  */
-static gboolean
-gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
        AsIcon *ic;
        const gchar *fn;
        gchar *found;
 
+       /* invalid */
+       if (gs_app_get_pixbuf (app) != NULL)
+               return TRUE;
+       if (gs_app_get_icon (app) == NULL)
+               return TRUE;
+
        /* not applicable */
        ic = gs_app_get_icon (app);
        if (as_icon_get_url (ic) == NULL)
@@ -142,31 +152,3 @@ gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
        as_icon_set_kind (ic, AS_ICON_KIND_LOCAL);
        return gs_app_load_icon (app, plugin->scale, error);
 }
-
-/**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
-{
-       GError *error_local = NULL;
-       GList *l;
-       GsApp *app;
-
-       for (l = *list; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-               if (gs_app_get_pixbuf (app) != NULL)
-                       continue;
-               if (gs_app_get_icon (app) == NULL)
-                       continue;
-               if (!gs_plugin_refine_app (plugin, app, &error_local)) {
-                       g_warning ("ignoring: %s", error_local->message);
-                       g_clear_error (&error_local);
-               }
-       }
-       return TRUE;
-}
diff --git a/src/plugins/gs-plugin-limba.c b/src/plugins/gs-plugin-limba.c
index e9f7af5..8cc4994 100644
--- a/src/plugins/gs-plugin-limba.c
+++ b/src/plugins/gs-plugin-limba.c
@@ -67,12 +67,24 @@ gs_plugin_destroy (GsPlugin *plugin)
 /**
  * gs_plugin_refine_app:
  */
-static gboolean
-gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
        LiPkgInfo *pki;
        g_autoptr(GError) error_local = NULL;
 
+       /* not us */
+       if (g_strcmp0 (gs_app_get_management_plugin (app), "Limba") != 0)
+               return TRUE;
+
+       ptask = as_profile_start_literal (plugin->profile, "limba::refine");
+       if (!gs_plugin_refine_app (plugin, app, error))
+               return FALSE;
+
        /* sanity check */
        if (gs_app_get_source_default (app) == NULL)
                return TRUE;
@@ -103,36 +115,6 @@ gs_plugin_refine_app (GsPlugin *plugin, GsApp *app, GError **error)
 }
 
 /**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
-               GList **list,
-               GsPluginRefineFlags flags,
-               GCancellable *cancellable,
-               GError **error)
-{
-       GList *l;
-       GsApp *app;
-       g_autoptr(AsProfileTask) ptask = NULL;
-
-       ptask = as_profile_start_literal (plugin->profile, "limba::refine");
-       for (l = *list; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-
-               /* not us */
-               if (g_strcmp0 (gs_app_get_management_plugin (app), "Limba") != 0)
-                       continue;
-
-               if (!gs_plugin_refine_app (plugin, app, error))
-                       return FALSE;
-       }
-
-       /* sucess */
-       return TRUE;
-}
-
-/**
  * GsPluginHelper:
  * Helper structure for Limba callbacks.
  */
diff --git a/src/plugins/gs-plugin-menu-spec-refine.c b/src/plugins/gs-plugin-menu-spec-refine.c
index 4c0197f..7ddaa96 100644
--- a/src/plugins/gs-plugin-menu-spec-refine.c
+++ b/src/plugins/gs-plugin-menu-spec-refine.c
@@ -93,13 +93,24 @@ gs_plugin_refine_app_category (GsPlugin *plugin,
 /**
  * gs_plugin_refine_app:
  */
-static gboolean
-gs_plugin_refine_app (GsPlugin *plugin, GsApp *app)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
        const MenuSpecData *msdata;
        gboolean ret = FALSE;
        gchar *tmp;
        guint i;
+       const gchar *EMPTY[] = { "", NULL };
+
+       /* nothing to do here */
+       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_MENU_PATH) == 0)
+               return TRUE;
+       if (gs_app_get_menu_path (app) != NULL)
+               return TRUE;
 
        /* find a top level category the app has */
        msdata = menu_spec_get_data ();
@@ -114,35 +125,10 @@ gs_plugin_refine_app (GsPlugin *plugin, GsApp *app)
                        break;
                }
        }
-       return ret;
-}
 
-/**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
-{
-       GList *l;
-       GsApp *app;
-       const gchar *EMPTY[] = { "", NULL };
+       /* don't keep searching for this */
+       if (!ret)
+               gs_app_set_menu_path (app, (gchar **) EMPTY);
 
-       /* nothing to do here */
-       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_MENU_PATH) == 0)
-               return TRUE;
-
-       for (l = *list; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-               if (gs_app_get_menu_path (app) == NULL) {
-                       if (!gs_plugin_refine_app (plugin, app)) {
-                               /* don't keep searching for this */
-                               gs_app_set_menu_path (app, (gchar **) EMPTY);
-                       }
-               }
-       }
        return TRUE;
 }
diff --git a/src/plugins/gs-plugin-packagekit-origin.c b/src/plugins/gs-plugin-packagekit-origin.c
index 72c73cd..56c601f 100644
--- a/src/plugins/gs-plugin-packagekit-origin.c
+++ b/src/plugins/gs-plugin-packagekit-origin.c
@@ -127,17 +127,22 @@ gs_plugin_packagekit_origin_ensure_sources (GsPlugin *plugin,
 }
 
 /**
- * gs_plugin_packagekit_origin_refine_app:
- **/
-static gboolean
-gs_plugin_packagekit_origin_refine_app (GsPlugin *plugin,
-                                       GsApp *app,
-                                       GCancellable *cancellable,
-                                       GError **error)
+ * gs_plugin_refine_app:
+ */
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
        const gchar *origin_id;
        const gchar *origin_ui;
 
+       /* only run when required */
+       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN) == 0)
+               return TRUE;
+
        if (g_strcmp0 (gs_app_get_management_plugin (app), "PackageKit") != 0)
                return TRUE;
        if (gs_app_get_origin (app) == NULL)
@@ -168,31 +173,3 @@ gs_plugin_packagekit_origin_refine_app (GsPlugin *plugin,
                gs_app_set_origin_ui (app, origin_ui);
        return TRUE;
 }
-
-/**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
-{
-       GList *l;
-       GsApp *app;
-
-       /* only run when required */
-       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN) == 0)
-               return TRUE;
-
-       /* for each app */
-       for (l = *list; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-               if (!gs_plugin_packagekit_origin_refine_app (plugin, app,
-                                                            cancellable,
-                                                            error))
-                       return FALSE;
-       }
-       return TRUE;
-}
diff --git a/src/plugins/gs-plugin-provenance.c b/src/plugins/gs-plugin-provenance.c
index 666f2ee..0ecad6d 100644
--- a/src/plugins/gs-plugin-provenance.c
+++ b/src/plugins/gs-plugin-provenance.c
@@ -95,36 +95,46 @@ gs_plugin_destroy (GsPlugin *plugin)
 }
 
 /**
- * gs_plugin_provenance_refine_app:
+ * gs_plugin_refine_app:
  */
-static void
-gs_plugin_provenance_refine_app (GsPlugin *plugin, GsApp *app)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
        const gchar *origin;
        const gchar * const *sources;
        guint i;
 
+       /* not required */
+       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
+               return TRUE;
+       if (gs_app_has_quirk (app, AS_APP_QUIRK_PROVENANCE))
+               return TRUE;
+
        /* nothing to search */
        sources = (const gchar * const *) plugin->priv->sources;
        if (sources == NULL || sources[0] == NULL) {
                gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
-               return;
+               return TRUE;
        }
 
        /* simple case */
        origin = gs_app_get_origin (app);
        if (origin != NULL && g_strv_contains (sources, origin)) {
                gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
-               return;
+               return TRUE;
        }
 
        /* this only works for packages */
        origin = gs_app_get_source_id_default (app);
        if (origin == NULL)
-               return;
+               return TRUE;
        origin = g_strrstr (origin, ";");
        if (origin == NULL)
-               return;
+               return TRUE;
        if (g_str_has_prefix (origin + 1, "installed:"))
                origin += 10;
        for (i = 0; sources[i] != NULL; i++) {
@@ -133,31 +143,5 @@ gs_plugin_provenance_refine_app (GsPlugin *plugin, GsApp *app)
                        break;
                }
        }
-}
-
-/**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
-{
-       GList *l;
-       GsApp *app;
-
-       /* not required */
-       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE) == 0)
-               return TRUE;
-
-       /* refine apps */
-       for (l = *list; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-               if (gs_app_has_quirk (app, AS_APP_QUIRK_PROVENANCE))
-                       continue;
-               gs_plugin_provenance_refine_app (plugin, app);
-       }
        return TRUE;
 }
diff --git a/src/plugins/gs-plugin-self-test.c b/src/plugins/gs-plugin-self-test.c
index 37b85d4..98f3792 100644
--- a/src/plugins/gs-plugin-self-test.c
+++ b/src/plugins/gs-plugin-self-test.c
@@ -45,24 +45,18 @@ gs_plugin_initialize (GsPlugin *plugin)
 }
 
 /**
- * gs_plugin_refine:
+ * gs_plugin_refine_app:
  */
 gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
-       GsApp *app;
-       GList *l;
-
-       for (l = *list; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-               if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN) {
-                       gs_app_set_state (app, AS_APP_STATE_INSTALLED);
-                       gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
-               }
+       if (gs_app_get_state (app) == AS_APP_STATE_UNKNOWN) {
+               gs_app_set_state (app, AS_APP_STATE_INSTALLED);
+               gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
        }
        return TRUE;
 }
diff --git a/src/plugins/gs-plugin-shell-extensions.c b/src/plugins/gs-plugin-shell-extensions.c
index 8d5c8a7..609b1ab 100644
--- a/src/plugins/gs-plugin-shell-extensions.c
+++ b/src/plugins/gs-plugin-shell-extensions.c
@@ -297,12 +297,14 @@ gs_plugin_add_installed (GsPlugin *plugin,
 }
 
 /**
- * gs_plugin_refine:
+ * gs_plugin_refine_app:
  */
-static gboolean
-gs_plugin_refine_item (GsPlugin *plugin,
-                      GsApp *app,
-                      GError **error)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
        /* only process this these kinds */
        if (gs_app_get_kind (app) != AS_APP_KIND_SHELL_EXTENSION)
@@ -324,27 +326,6 @@ gs_plugin_refine_item (GsPlugin *plugin,
 }
 
 /**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
-{
-       GList *l;
-       GsApp *app;
-
-       for (l = *list; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-               if (!gs_plugin_refine_item (plugin, app, error))
-                       return FALSE;
-       }
-       return TRUE;
-}
-
-/**
  * gs_plugin_shell_extensions_parse_version:
  */
 static gboolean
diff --git a/src/plugins/gs-plugin-steam.c b/src/plugins/gs-plugin-steam.c
index f5dd58d..79964f7 100644
--- a/src/plugins/gs-plugin-steam.c
+++ b/src/plugins/gs-plugin-steam.c
@@ -928,14 +928,14 @@ typedef enum {
 } GsSteamStateFlags;
 
 /**
- * gs_plugin_steam_refine_app:
+ * gs_plugin_refine_app:
  */
-static gboolean
-gs_plugin_steam_refine_app (GsPlugin *plugin,
-                           GsApp *app,
-                           GsPluginRefineFlags flags,
-                           GCancellable *cancellable,
-                           GError **error)
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
        const gchar *gameid;
        const gchar *tmp;
@@ -1019,28 +1019,6 @@ gs_plugin_steam_refine_app (GsPlugin *plugin,
 }
 
 /**
- * gs_plugin_refine:
- */
-gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
-{
-       GList *l;
-       GsApp *app;
-
-       for (l = *list; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-               if (!gs_plugin_steam_refine_app (plugin, app, flags,
-                                                cancellable, error))
-                       return FALSE;
-       }
-       return TRUE;
-}
-
-/**
  * gs_plugin_app_install:
  */
 gboolean
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index d40683a..79f0239 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -652,28 +652,21 @@ refine_reviews (GsPlugin *plugin, GsApp *app, GError **error)
 }
 
 gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
-       GList *l;
-       gboolean ret = TRUE;
-
-       for (l = *list; l != NULL; l = l->next) {
-               GsApp *app = GS_APP (l->data);
-
-               if ((flags & (GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING | 
GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS)) != 0) {
-                       if (!refine_rating (plugin, app, error))
-                               return FALSE;
-               }
-               if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS) != 0) {
-                       if (!refine_reviews (plugin, app, error))
-                               return FALSE;
-               }
+       if ((flags & (GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING | GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS)) 
!= 0) {
+               if (!refine_rating (plugin, app, error))
+                       return FALSE;
+       }
+       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS) != 0) {
+               if (!refine_reviews (plugin, app, error))
+                       return FALSE;
        }
 
-       return ret;
+       return TRUE;
 }
 
diff --git a/src/plugins/gs-plugin-xdg-app-reviews.c b/src/plugins/gs-plugin-xdg-app-reviews.c
index 395b110..2fac117 100644
--- a/src/plugins/gs-plugin-xdg-app-reviews.c
+++ b/src/plugins/gs-plugin-xdg-app-reviews.c
@@ -656,56 +656,37 @@ gs_plugin_refine_reviews (GsPlugin *plugin,
 }
 
 /**
- * gs_plugin_refine:
+ * gs_plugin_refine_app:
  */
 gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
-       GsApp *app;
-       GList *l;
+       /* not valid */
+       if (gs_app_get_kind (app) == AS_APP_KIND_ADDON)
+               return TRUE;
+       if (gs_app_get_id_no_prefix (app) == NULL)
+               return TRUE;
 
        /* add reviews if possible */
        if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS) {
-               for (l = *list; l != NULL; l = l->next) {
-                       g_autoptr(GError) error_local = NULL;
-                       app = GS_APP (l->data);
-                       if (gs_app_get_reviews(app)->len > 0)
-                               continue;
-                       if (gs_app_get_id_no_prefix (app) == NULL)
-                               continue;
-                       if (gs_app_get_kind (app) == AS_APP_KIND_ADDON)
-                               continue;
-                       if (!gs_plugin_refine_reviews (plugin, app,
-                                                      cancellable,
-                                                      &error_local)) {
-                               g_warning ("Failed to get reviews: %s",
-                                          error_local->message);
-                       }
-               }
+               if (gs_app_get_reviews(app)->len > 0)
+                       return TRUE;
+               if (!gs_plugin_refine_reviews (plugin, app,
+                                              cancellable, error))
+                       return FALSE;
        }
 
        /* add ratings if possible */
        if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS) {
-               for (l = *list; l != NULL; l = l->next) {
-                       g_autoptr(GError) error_local = NULL;
-                       app = GS_APP (l->data);
-                       if (gs_app_get_review_ratings(app) != NULL)
-                               continue;
-                       if (gs_app_get_id_no_prefix (app) == NULL)
-                               continue;
-                       if (gs_app_get_kind (app) == AS_APP_KIND_ADDON)
-                               continue;
-                       if (!gs_plugin_refine_ratings (plugin, app,
-                                                      cancellable,
-                                                      &error_local)) {
-                               g_warning ("Failed to get ratings: %s",
-                                          error_local->message);
-                       }
-               }
+               if (gs_app_get_review_ratings(app) != NULL)
+                       return TRUE;
+               if (!gs_plugin_refine_ratings (plugin, app,
+                                              cancellable, error))
+                       return FALSE;
        }
 
        return TRUE;
diff --git a/src/plugins/gs-plugin-xdg-app.c b/src/plugins/gs-plugin-xdg-app.c
index 613060b..cee2006 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -1120,14 +1120,14 @@ gs_plugin_refine_item_size (GsPlugin *plugin,
 }
 
 /**
- * gs_plugin_refine_item:
+ * gs_plugin_xdg_app_refine_app:
  */
 static gboolean
-gs_plugin_refine_item (GsPlugin *plugin,
-                      GsApp *app,
-                      GsPluginRefineFlags flags,
-                      GCancellable *cancellable,
-                      GError **error)
+gs_plugin_xdg_app_refine_app (GsPlugin *plugin,
+                             GsApp *app,
+                             GsPluginRefineFlags flags,
+                             GCancellable *cancellable,
+                             GError **error)
 {
        g_autoptr(AsProfileTask) ptask = NULL;
 
@@ -1173,28 +1173,19 @@ gs_plugin_refine_item (GsPlugin *plugin,
 }
 
 /**
- * gs_plugin_refine:
+ * gs_plugin_refine_app:
  */
 gboolean
-gs_plugin_refine (GsPlugin *plugin,
-                 GList **list,
-                 GsPluginRefineFlags flags,
-                 GCancellable *cancellable,
-                 GError **error)
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
 {
-       GList *l;
-       GsApp *app;
-
        /* ensure we can set up the repo */
        if (!gs_plugin_ensure_installation (plugin, cancellable, error))
                return FALSE;
-
-       for (l = *list; l != NULL; l = l->next) {
-               app = GS_APP (l->data);
-               if (!gs_plugin_refine_item (plugin, app, flags, cancellable, error))
-                       return FALSE;
-       }
-       return TRUE;
+       return gs_plugin_xdg_app_refine_app (plugin, app, flags, cancellable, error);
 }
 
 /**
@@ -1283,7 +1274,7 @@ gs_plugin_app_install (GsPlugin *plugin,
                return FALSE;
 
        /* ensure we have metadata and state */
-       if (!gs_plugin_refine_item (plugin, app, 0, cancellable, error))
+       if (!gs_plugin_xdg_app_refine_app (plugin, app, 0, cancellable, error))
                return FALSE;
 
        /* use helper: FIXME: new()&ref? */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]