[gnome-software/wip/rancell/reviews: 17/33] Add an ability for plugins to request authorization for posting reviews



commit 28e299c0e8470b482784ea1da8604900dea4332d
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 817c753..de7b9a2 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -50,6 +50,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)
@@ -2828,13 +2830,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);
@@ -2859,6 +2864,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;
@@ -2982,6 +2995,7 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader, GError **error)
        guint j;
        g_autoptr(GDir) dir = NULL;
        g_autoptr(AsProfileTask) ptask = NULL;
+       GPtrArray *review_auths;
 
        g_return_val_if_fail (priv->location != NULL, FALSE);
 
@@ -2993,6 +3007,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);
@@ -3003,9 +3018,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;
@@ -3130,6 +3148,7 @@ gs_plugin_loader_finalize (GObject *object)
        g_strfreev (priv->compatible_projects);
        g_free (priv->location);
        g_free (priv->locale);
+       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 ede9b14..dfdd080 100644
--- a/src/gs-plugin-loader.h
+++ b/src/gs-plugin-loader.h
@@ -224,6 +224,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 5e67565..cb4decd 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -123,6 +123,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]