[gnome-software/wip/attente/reviews] Show login dialog in GDK thread



commit 8f4a90d556e0931d4e95d23ce1c95737b1e50de1
Author: William Hua <william hua canonical com>
Date:   Tue Feb 9 10:49:00 2016 -0500

    Show login dialog in GDK thread

 src/plugins/gs-plugin-ubuntu-reviews.c |   94 +++++++++++++++++++++++---------
 1 files changed, 67 insertions(+), 27 deletions(-)
---
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index 51590d2..607b777 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -803,55 +803,95 @@ set_package_review (GsPlugin *plugin,
        return TRUE;
 }
 
-static gboolean
-sign_into_ubuntu (GsPlugin  *plugin,
-                  GError   **error)
+typedef struct
 {
-       GsPluginPrivate *priv = plugin->priv;
-       GtkWidget *dialog;
-       gboolean remember;
-       gboolean success;
-
-       if (priv->consumer_key != NULL &&
-           priv->consumer_secret != NULL &&
-           priv->token_key != NULL &&
-           priv->token_secret != NULL)
-               return TRUE;
+       GsPlugin *plugin;
+       GError **error;
 
-       g_clear_pointer (&priv->token_secret, g_free);
-       g_clear_pointer (&priv->token_key, g_free);
-       g_clear_pointer (&priv->consumer_secret, g_free);
-       g_clear_pointer (&priv->consumer_key, g_free);
+       GCond cond;
+       GMutex mutex;
+       gboolean done;
+       gboolean success;
+       gboolean remember;
+} LoginContext;
 
-       dialog = ubuntu_login_dialog_new ();
+static gboolean
+show_login_dialog (gpointer user_data)
+{
+       LoginContext *context = user_data;
+       GsPluginPrivate *priv = context->plugin->priv;
+       GtkWidget *dialog = ubuntu_login_dialog_new ();
 
-       g_object_set (dialog, "session", plugin->priv->session, NULL);
+       g_object_set (dialog, "session", priv->session, NULL);
 
        switch (gtk_dialog_run (GTK_DIALOG (dialog))) {
        case GTK_RESPONSE_DELETE_EVENT:
        case GTK_RESPONSE_CANCEL:
-               success = FALSE;
+               g_set_error (context->error,
+                            GS_PLUGIN_ERROR,
+                            GS_PLUGIN_ERROR_FAILED,
+                            "Unable to sign into Ubuntu One");
+
+               context->success = FALSE;
                break;
 
        case GTK_RESPONSE_OK:
                g_object_get (dialog,
-                             "remember", &remember,
+                             "remember", &context->remember,
                              "consumer-key", &priv->consumer_key,
                              "consumer-secret", &priv->consumer_secret,
                              "token-key", &priv->token_key,
                              "token-secret", &priv->token_secret,
                              NULL);
 
-               if (remember) {
-                       /* FIXME: store credentials somewhere... */
-               }
-
-               success = TRUE;
+               context->success = TRUE;
                break;
        }
 
        gtk_widget_destroy (dialog);
-       return success;
+
+       g_mutex_lock (&context->mutex);
+       context->done = TRUE;
+       g_cond_signal (&context->cond);
+       g_mutex_unlock (&context->mutex);
+
+       return G_SOURCE_REMOVE;
+}
+
+static gboolean
+sign_into_ubuntu (GsPlugin  *plugin,
+                  GError   **error)
+{
+       GsPluginPrivate *priv = plugin->priv;
+       LoginContext context = { 0 };
+
+       if (priv->consumer_key != NULL &&
+           priv->consumer_secret != NULL &&
+           priv->token_key != NULL &&
+           priv->token_secret != NULL)
+               return TRUE;
+
+       g_clear_pointer (&priv->token_secret, g_free);
+       g_clear_pointer (&priv->token_key, g_free);
+       g_clear_pointer (&priv->consumer_secret, g_free);
+       g_clear_pointer (&priv->consumer_key, g_free);
+
+       context.plugin = plugin;
+       context.error = error;
+       g_cond_init (&context.cond);
+       g_mutex_init (&context.mutex);
+       g_mutex_lock (&context.mutex);
+
+       gdk_threads_add_idle (show_login_dialog, &context);
+
+       while (!context.done)
+               g_cond_wait (&context.cond, &context.mutex);
+
+       g_mutex_unlock (&context.mutex);
+       g_mutex_clear (&context.mutex);
+       g_cond_clear (&context.cond);
+
+       return context.success;
 }
 
 gboolean


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