[gnome-software] lib: Drop the refine_app() vfunc in favour of refine()



commit 99f871758ad9f200b41c903a4bd56161de18cc5a
Author: Philip Withnall <withnall endlessm com>
Date:   Wed Apr 22 12:02:54 2020 +0100

    lib: Drop the refine_app() vfunc in favour of refine()
    
    See the previous commits for details. This is an API break in the
    libgnome-software API, but that’s allowed.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 doc/api/gnome-software-docs.xml | 28 ++++++++++++++++------------
 lib/gs-plugin-loader.c          | 14 ++++----------
 lib/gs-plugin-vfuncs.h          | 31 +------------------------------
 3 files changed, 21 insertions(+), 52 deletions(-)
---
diff --git a/doc/api/gnome-software-docs.xml b/doc/api/gnome-software-docs.xml
index 385ea5cd..fb43ff23 100644
--- a/doc/api/gnome-software-docs.xml
+++ b/doc/api/gnome-software-docs.xml
@@ -293,7 +293,7 @@ gs_plugin_add_installed (GsPlugin *plugin,
 
         <para>
           By filling in the optional details (which can also be filled in using
-          <code>gs_plugin_refine_app()</code> you can also make the details
+          <code>gs_plugin_refine()</code> you can also make the details
           page a much more exciting place.
           Adding a set of screenshots is left as an exercise to the reader.
         </para>
@@ -421,23 +421,27 @@ gs_plugin_refresh (GsPlugin *plugin,
           <title>Refine example</title>
           <programlisting>
 gboolean
-gs_plugin_refine_app (GsPlugin *plugin,
-                      GsApp *app,
-                      GsPluginRefineFlags flags,
-                      GCancellable *cancellable,
-                      GError **error)
+gs_plugin_refine (GsPlugin *plugin,
+                  GsAppList *list,
+                  GsPluginRefineFlags flags,
+                  GCancellable *cancellable,
+                  GError **error)
 {
   /* not required */
   if ((flags &amp; GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE) == 0)
     return TRUE;
 
-  /* already set */
-  if (gs_app_get_license (app) != NULL)
-    return TRUE;
+  for (guint i = 0; i &lt; gs_app_list_length (list); i++) {
+    GsApp *app = gs_app_list_index (list, i);
 
-  /* FIXME, not just hardcoded! */
-  if (g_strcmp0 (gs_app_get_id (app, "chiron.desktop") == 0))
-    gs_app_set_license (app, "GPL-2.0 and LGPL-2.0+");
+    /* already set */
+    if (gs_app_get_license (app) != NULL)
+      return TRUE;
+
+    /* FIXME, not just hardcoded! */
+    if (g_strcmp0 (gs_app_get_id (app, "chiron.desktop") == 0))
+      gs_app_set_license (app, "GPL-2.0 and LGPL-2.0+");
+  }
 
   return TRUE;
 }
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index c8136f1c..003a06a1 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -540,9 +540,6 @@ gs_plugin_loader_call_vfunc (GsPluginLoaderHelper *helper,
                if (g_strcmp0 (helper->function_name, "gs_plugin_refine_wildcard") == 0) {
                        GsPluginRefineWildcardFunc plugin_func = func;
                        ret = plugin_func (plugin, app, list, refine_flags, cancellable, &error_local);
-               } else if (g_strcmp0 (helper->function_name, "gs_plugin_refine_app") == 0) {
-                       GsPluginRefineAppFunc plugin_func = func;
-                       ret = plugin_func (plugin, app, refine_flags, cancellable, &error_local);
                } else if (g_strcmp0 (helper->function_name, "gs_plugin_refine") == 0) {
                        GsPluginRefineFunc plugin_func = func;
                        ret = plugin_func (plugin, list, refine_flags, cancellable, &error_local);
@@ -786,7 +783,7 @@ gs_plugin_loader_run_refine_filter (GsPluginLoaderHelper *helper,
                GsPlugin *plugin = g_ptr_array_index (priv->plugins, i);
                g_autoptr(GsAppList) app_list = NULL;
 
-               /* run the batched plugin symbol then the per-app plugin */
+               /* run the batched plugin symbol then refine wildcards per-app */
                helper->function_name = "gs_plugin_refine";
                if (!gs_plugin_loader_call_vfunc (helper, plugin, NULL, list,
                                                  refine_flags, cancellable, error)) {
@@ -797,15 +794,12 @@ gs_plugin_loader_run_refine_filter (GsPluginLoaderHelper *helper,
                 * on the plugin may affect the list which can lead to problems
                 * (e.g. inserting an app in the list on every call results in
                 * an infinite loop) */
+               helper->function_name = "gs_plugin_refine_wildcard";
                app_list = gs_app_list_copy (list);
                for (guint j = 0; j < gs_app_list_length (app_list); j++) {
                        GsApp *app = gs_app_list_index (app_list, j);
-                       if (!gs_app_has_quirk (app, GS_APP_QUIRK_IS_WILDCARD)) {
-                               helper->function_name = "gs_plugin_refine_app";
-                       } else {
-                               helper->function_name = "gs_plugin_refine_wildcard";
-                       }
-                       if (!gs_plugin_loader_call_vfunc (helper, plugin, app, NULL,
+                       if (gs_app_has_quirk (app, GS_APP_QUIRK_IS_WILDCARD) &&
+                           !gs_plugin_loader_call_vfunc (helper, plugin, app, NULL,
                                                          refine_flags, cancellable, error)) {
                                return FALSE;
                        }
diff --git a/lib/gs-plugin-vfuncs.h b/lib/gs-plugin-vfuncs.h
index 907bdc71..751c419a 100644
--- a/lib/gs-plugin-vfuncs.h
+++ b/lib/gs-plugin-vfuncs.h
@@ -410,8 +410,7 @@ gboolean     gs_plugin_add_unvoted_reviews          (GsPlugin       *plugin,
  * @error: a #GError, or %NULL
  *
  * Adds required information to a list of #GsApp's. It allows requests to be
- * batched up, which allows better performance than individual calls to
- * gs_plugin_refine_app(). It should be used in preference wherever possible.
+ * batched up, which allows better performance than individual calls per app.
  *
  * An example for when this is useful would be in the PackageKit plugin where
  * we want to do one transaction of GetDetails with multiple source-ids rather
@@ -425,34 +424,6 @@ gboolean    gs_plugin_refine                       (GsPlugin       *plugin,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
 
-/**
- * gs_plugin_refine_app:
- * @plugin: a #GsPlugin
- * @app: a #GsApp
- * @flags: a #GsPluginRefineFlags, e.g. %GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE
- * @cancellable: a #GCancellable, or %NULL
- * @error: a #GError, or %NULL
- *
- * Adds required information to @app.
- *
- * The general idea for @flags is that this indicates what the UI needs at the
- * moment. This doesn't mean you can't add more information if you have it,
- * for example, if we requested %GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE and had
- * to do some IO to get a blob of data, we can use gs_app_set_license() *and*
- * gs_app_set_origin() even though only the first thing was specified.
- *
- * If the plugin can't handle applications of the specific kind, or if the
- * plugin knows not of the #GsApp ID then it should just ignore the request and
- * return FALSE.
- *
- * Returns: %TRUE for success or if not relevant
- **/
-gboolean        gs_plugin_refine_app                   (GsPlugin       *plugin,
-                                                        GsApp          *app,
-                                                        GsPluginRefineFlags flags,
-                                                        GCancellable   *cancellable,
-                                                        GError         **error);
-
 /**
  * gs_plugin_refine_wildcard:
  * @plugin: a #GsPlugin


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