[gnome-software/wip/williamhua/reviews] Use UbuntuLoginDialog to get credentials
- From: William Hua <williamhua src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/williamhua/reviews] Use UbuntuLoginDialog to get credentials
- Date: Tue, 9 Feb 2016 00:44:48 +0000 (UTC)
commit 32a71f30b8d5cfc9d48491fa5721e655b17037e7
Author: William Hua <william hua canonical com>
Date: Mon Feb 8 13:31:01 2016 -0500
Use UbuntuLoginDialog to get credentials
src/plugins/gs-plugin-ubuntu-reviews.c | 64 ++++++++++++++++++++++++++++++--
1 files changed, 60 insertions(+), 4 deletions(-)
---
diff --git a/src/plugins/gs-plugin-ubuntu-reviews.c b/src/plugins/gs-plugin-ubuntu-reviews.c
index 6a2d49e..c69a546 100644
--- a/src/plugins/gs-plugin-ubuntu-reviews.c
+++ b/src/plugins/gs-plugin-ubuntu-reviews.c
@@ -30,11 +30,17 @@
#include <gs-plugin.h>
#include <gs-utils.h>
+#include "ubuntu-login-dialog.h"
+
struct GsPluginPrivate {
gchar *db_path;
sqlite3 *db;
gsize db_loaded;
SoupSession *session;
+ gchar *consumer_key;
+ gchar *consumer_secret;
+ gchar *token_key;
+ gchar *token_secret;
};
typedef struct {
@@ -86,10 +92,14 @@ gs_plugin_get_deps (GsPlugin *plugin)
void
gs_plugin_destroy (GsPlugin *plugin)
{
- if (plugin->priv->db != NULL)
- sqlite3_close (plugin->priv->db);
- if (plugin->priv->session != NULL)
- g_object_unref (plugin->priv->session);
+ GsPluginPrivate *priv = plugin->priv;
+
+ 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);
+ g_clear_pointer (&priv->db, sqlite3_close);
+ g_clear_object (&priv->session);
}
static gboolean
@@ -806,6 +816,49 @@ set_package_review (GsPlugin *plugin,
return result;
}
+static gboolean
+sign_into_ubuntu (GsPlugin *plugin,
+ GError **error)
+{
+ GsPluginPrivate *priv = plugin->priv;
+ GtkWidget *dialog;
+ gboolean success;
+
+ 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);
+
+ dialog = ubuntu_login_dialog_new ();
+
+ switch (gtk_dialog_run (GTK_DIALOG (dialog))) {
+ case GTK_RESPONSE_DELETE_EVENT:
+ case GTK_RESPONSE_CANCEL:
+ success = FALSE;
+ break;
+
+ case GTK_RESPONSE_CLOSE:
+ g_object_get (dialog,
+ "consumer-key", &priv->consumer_key,
+ "consumer-secret", &priv->consumer_secret,
+ "token-key", &priv->token_key,
+ "token-secret", &priv->token_secret,
+ NULL);
+
+ success = TRUE;
+ break;
+ }
+
+ gtk_widget_destroy (dialog);
+ return success;
+}
+
gboolean
gs_plugin_app_set_review (GsPlugin *plugin,
GsApp *app,
@@ -840,6 +893,9 @@ gs_plugin_app_set_review (GsPlugin *plugin,
if (!setup_networking (plugin, error))
return FALSE;
+ if (!sign_into_ubuntu (plugin, error))
+ return FALSE;
+
/* set rating for each package */
for (i = 0; i < sources->len; i++) {
package_name = g_ptr_array_index (sources, i);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]