[gnome-software/wip/rancell/reviews-3-18] Only show reviews widgets if a plugin supports it



commit ab5d84e17b1b73c3a8dca818adc11561ef6948c9
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Jan 15 13:42:59 2016 +1300

    Only show reviews widgets if a plugin supports it

 src/gs-plugin-loader.c                 |   21 ++++++++++++++++++++-
 src/gs-plugin-loader.h                 |    1 +
 src/gs-plugin.h                        |    3 +++
 src/gs-shell-details.c                 |   10 ++++++++++
 src/gs-shell-details.ui                |    1 -
 src/plugins/gs-plugin-ubuntu-reviews.c |    6 ++++++
 6 files changed, 40 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 8a0c509..66c1303 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -50,6 +50,7 @@ typedef struct
        guint                    updates_changed_id;
        gboolean                 online; 
 
+       gboolean                 supports_reviews;
        gchar                   **review_auths;
 } GsPluginLoaderPrivate;
 
@@ -2813,6 +2814,7 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        GModule *module;
        GsPluginGetNameFunc plugin_name = NULL;
        GsPluginGetDepsFunc plugin_deps = NULL;
+       GsPluginGetSupportsReviewsFunc plugin_supports_reviews = NULL;
        GsPluginGetReviewAuthFunc plugin_review_auth = NULL;
        const gchar *review_auth;
        GsPlugin *plugin = NULL;
@@ -2839,7 +2841,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 */
+       /* Check if this plugin can do reviews */
+       (void) g_module_symbol (module,
+                               "gs_plugin_get_supports_reviews",
+                               (gpointer *) &plugin_supports_reviews);
+       if (plugin_supports_reviews && plugin_supports_reviews (plugin))
+               priv->supports_reviews = TRUE;
+
+       /* Check if this plugin requires any authorization for reviews */
        (void) g_module_symbol (module,
                                "gs_plugin_get_review_auth",
                                (gpointer *) &plugin_review_auth);
@@ -3709,6 +3718,16 @@ gs_plugin_loader_offline_update_finish (GsPluginLoader *plugin_loader,
 }
 
 /**
+ * gs_plugin_loader_get_supports_reviews:
+ */
+gboolean
+gs_plugin_loader_get_supports_reviews (GsPluginLoader *plugin_loader)
+{
+       GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+       return priv->supports_reviews;
+}
+
+/**
  * gs_plugin_loader_get_review_auths:
  */
 gchar **
diff --git a/src/gs-plugin-loader.h b/src/gs-plugin-loader.h
index bbdbb5b..6edc759 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);
+gboolean        gs_plugin_loader_get_supports_reviews  (GsPluginLoader *plugin_loader);
 gchar          **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 f9b6fb9..e5341e9 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 gboolean       *(*GsPluginGetSupportsReviewsFunc)      (GsPlugin       *plugin);
 typedef const gchar    *(*GsPluginGetReviewAuthFunc)   (GsPlugin       *plugin);
 typedef void            (*GsPluginFunc)                (GsPlugin       *plugin);
 typedef gboolean        (*GsPluginSearchFunc)          (GsPlugin       *plugin,
@@ -248,6 +249,8 @@ gboolean     gs_plugin_app_set_rating               (GsPlugin       *plugin,
                                                         GsApp          *app,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
+gboolean        gs_plugin_get_supports_review          (GsPlugin       *plugin);
+const gchar    *gs_plugin_get_review_auth              (GsPlugin       *plugin);
 gboolean        gs_plugin_app_set_review               (GsPlugin       *plugin,
                                                         GsApp          *app,
                                                         GCancellable   *cancellable,
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index b905355..0fd0877 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -87,6 +87,7 @@ struct _GsShellDetails
        GtkWidget               *label_details_version_value;
        GtkWidget               *label_pending;
        GtkWidget               *list_box_addons;
+       GtkWidget               *box_reviews;
        GtkWidget               *list_box_reviews;
        GtkWidget               *scrolledwindow_details;
        GtkWidget               *spinner_details;
@@ -872,6 +873,9 @@ gs_shell_details_refresh_reviews (GsShellDetails *self)
        GPtrArray *reviews;
        guint i;
 
+       if (!gs_plugin_loader_get_supports_reviews (self->plugin_loader))
+               return;
+
        gs_container_remove_all (GTK_CONTAINER (self->list_box_reviews));
 
        reviews = gs_app_get_reviews (self->app);
@@ -1249,6 +1253,7 @@ gs_shell_details_rating_changed_cb (GsStarWidget *star,
        gs_app_review_dialog_set_rating (GS_APP_REVIEW_DIALOG (dialog), rating);
 
        review_auths = gs_plugin_loader_get_review_auths (self->plugin_loader);
+       // FIXME: Use these
 
        gtk_window_set_transient_for (GTK_WINDOW (dialog), gs_shell_get_window (self->shell));
        response = gtk_dialog_run (GTK_DIALOG (dialog));
@@ -1325,6 +1330,10 @@ gs_shell_details_setup (GsShellDetails *self,
        self->builder = g_object_ref (builder);
        self->cancellable = g_object_ref (cancellable);
 
+       /* Show review widgets if we have plugins that provide them */
+       if (gs_plugin_loader_get_supports_reviews (plugin_loader))
+               gtk_widget_set_visible (self->box_reviews, TRUE);
+
        /* set up star ratings */
        self->star = gs_star_widget_new ();
        g_signal_connect (self->star, "rating-changed",
@@ -1430,6 +1439,7 @@ gs_shell_details_class_init (GsShellDetailsClass *klass)
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, label_details_version_value);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, label_pending);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, list_box_addons);
+       gtk_widget_class_bind_template_child (widget_class, GsShellDetails, box_reviews);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, list_box_reviews);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, scrolledwindow_details);
        gtk_widget_class_bind_template_child (widget_class, GsShellDetails, spinner_details);
diff --git a/src/gs-shell-details.ui b/src/gs-shell-details.ui
index d1eaf39..c4c1571 100644
--- a/src/gs-shell-details.ui
+++ b/src/gs-shell-details.ui
@@ -1024,7 +1024,6 @@
                     </child>
                     <child>
                       <object class="GtkBox" id="box_reviews">
-                        <property name="visible">True</property>
                         <property name="orientation">vertical</property>
                         <property name="margin_top">28</property>
                         <child>
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index cd3c5ce..4554201 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);
 }
 
+gboolean
+gs_plugin_get_supports_reviews (GsPlugin *plugin)
+{
+       return TRUE;
+}
+
 const gchar *
 gs_plugin_get_review_auth (GsPlugin *plugin)
 {


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