[gnome-software/wip/rancell/reviews-3-18] Add an ability for plugins to request authorization for posting reviews



commit 97e652b63f0cd109a4b8ae06aef387147f45cac7
Author: Robert Ancell <robert ancell canonical com>
Date:   Thu Jan 14 22:41:11 2016 +1300

    Add an ability for plugins to request authorization for posting reviews

 src/gs-plugin-loader.c                 |   23 +++++++++++++++++++++--
 src/gs-plugin-loader.h                 |    1 +
 src/gs-plugin.h                        |    1 +
 src/plugins/gs-plugin-ubuntu-reviews.c |    6 ++++++
 4 files changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 4087c3d..c696863 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -49,6 +49,8 @@ typedef struct
 
        guint                    updates_changed_id;
        gboolean                 online; 
+
+       gchar                   **review_auths;
 } GsPluginLoaderPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GsPluginLoader, gs_plugin_loader, G_TYPE_OBJECT)
@@ -2803,13 +2805,16 @@ gs_plugin_loader_updates_changed_cb (GsPlugin *plugin, gpointer user_data)
  */
 static GsPlugin *
 gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
-                             const gchar *filename)
+                             const gchar *filename,
+                             GPtrArray *review_auths)
 {
        GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
        gboolean ret;
        GModule *module;
        GsPluginGetNameFunc plugin_name = NULL;
        GsPluginGetDepsFunc plugin_deps = NULL;
+       GsPluginGetReviewAuthFunc plugin_review_auth = NULL;
+       const gchar *review_auth;
        GsPlugin *plugin = NULL;
 
        module = g_module_open (filename, 0);
@@ -2834,6 +2839,14 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
                                "gs_plugin_get_deps",
                                (gpointer *) &plugin_deps);
 
+       /* Check if this module requires any authorization for reviews */
+       (void) g_module_symbol (module,
+                               "gs_plugin_get_review_auth",
+                               (gpointer *) &plugin_review_auth);
+       review_auth = plugin_review_auth != NULL ? plugin_review_auth (plugin) : NULL;
+       if (review_auth)
+               g_ptr_array_add (review_auths, g_strdup (review_auth));
+
        /* print what we know */
        plugin = g_slice_new0 (GsPlugin);
        plugin->enabled = TRUE;
@@ -2956,6 +2969,7 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
        guint i;
        guint j;
        g_autoptr(GDir) dir = NULL;
+       GPtrArray *review_auths;
 
        g_return_val_if_fail (priv->location != NULL, FALSE);
 
@@ -2969,6 +2983,7 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
 
        /* try to open each plugin */
        g_debug ("searching for plugins in %s", priv->location);
+       review_auths = g_ptr_array_new ();
        do {
                g_autofree gchar *filename_plugin = NULL;
                filename_tmp = g_dir_read_name (dir);
@@ -2979,9 +2994,12 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
                filename_plugin = g_build_filename (priv->location,
                                                    filename_tmp,
                                                    NULL);
-               gs_plugin_loader_open_plugin (plugin_loader, filename_plugin);
+               gs_plugin_loader_open_plugin (plugin_loader, filename_plugin, review_auths);
        } while (TRUE);
 
+       g_ptr_array_add (review_auths, NULL);
+       priv->review_auths = (char **) g_ptr_array_free (review_auths, FALSE);
+
        /* order by deps */
        do {
                changes = FALSE;
@@ -3113,6 +3131,7 @@ gs_plugin_loader_finalize (GObject *object)
 
        g_strfreev (priv->compatible_projects);
        g_free (priv->location);
+       g_strfreev (priv->review_auths);
 
        g_mutex_clear (&priv->pending_apps_mutex);
        g_mutex_clear (&priv->app_cache_mutex);
diff --git a/src/gs-plugin-loader.h b/src/gs-plugin-loader.h
index 3d90649..4086e55 100644
--- a/src/gs-plugin-loader.h
+++ b/src/gs-plugin-loader.h
@@ -213,6 +213,7 @@ GsApp               *gs_plugin_loader_dedupe                (GsPluginLoader 
*plugin_loader,
                                                         GsApp          *app);
 void            gs_plugin_loader_set_network_status    (GsPluginLoader *plugin_loader,
                                                         gboolean        online);
+void            gs_plugin_loader_get_review_auths      (GsPluginLoader *plugin_loader);
 
 G_END_DECLS
 
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 0122baf..f9b6fb9 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -117,6 +117,7 @@ typedef enum {
 
 typedef const gchar    *(*GsPluginGetNameFunc)         (void);
 typedef const gchar    **(*GsPluginGetDepsFunc)        (GsPlugin       *plugin);
+typedef const gchar    *(*GsPluginGetReviewAuthFunc)   (GsPlugin       *plugin);
 typedef void            (*GsPluginFunc)                (GsPlugin       *plugin);
 typedef gboolean        (*GsPluginSearchFunc)          (GsPlugin       *plugin,
                                                         gchar          **value,
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index 424c67d..cd3c5ce 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -299,6 +299,12 @@ set_request (SoupMessage *message, JsonBuilder *builder)
        g_object_unref (generator);
 }
 
+const gchar *
+gs_plugin_get_review_auth (GsPlugin *plugin)
+{
+       return "ubuntuone";
+}
+
 static gboolean
 set_package_review (GsPlugin *plugin,
                     GsAppReview *review,


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