[gthumb] flicker_utils: use a FlickAccount in FlickConnection to simplify the code
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] flicker_utils: use a FlickAccount in FlickConnection to simplify the code
- Date: Sun, 25 Sep 2011 10:19:09 +0000 (UTC)
commit e1683257e37b65bc400b4a1cb4c0d5230a0bfb06
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Sep 25 12:09:01 2011 +0200
flicker_utils: use a FlickAccount in FlickConnection to simplify the code
extensions/flicker_utils/flickr-account.c | 8 +++
extensions/flicker_utils/flickr-account.h | 1 +
extensions/flicker_utils/flickr-authentication.c | 11 +--
extensions/flicker_utils/flickr-connection.c | 70 ++++++++--------------
extensions/flicker_utils/flickr-connection.h | 8 +--
extensions/flicker_utils/flickr-photo.c | 3 +-
6 files changed, 41 insertions(+), 60 deletions(-)
---
diff --git a/extensions/flicker_utils/flickr-account.c b/extensions/flicker_utils/flickr-account.c
index 31e8e12..16db1be 100644
--- a/extensions/flicker_utils/flickr-account.c
+++ b/extensions/flicker_utils/flickr-account.c
@@ -172,6 +172,14 @@ flickr_account_set_token (FlickrAccount *self,
}
+void
+flickr_account_reset (FlickrAccount *self)
+{
+ flickr_account_set_username (self, NULL);
+ flickr_account_set_token (self, NULL);
+}
+
+
int
flickr_account_cmp (FlickrAccount *a,
FlickrAccount *b)
diff --git a/extensions/flicker_utils/flickr-account.h b/extensions/flicker_utils/flickr-account.h
index 573240c..712ad5c 100644
--- a/extensions/flicker_utils/flickr-account.h
+++ b/extensions/flicker_utils/flickr-account.h
@@ -57,6 +57,7 @@ void flickr_account_set_username (FlickrAccount *self,
const char *value);
void flickr_account_set_token (FlickrAccount *self,
const char *value);
+void flickr_account_reset (FlickrAccount *self);
int flickr_account_cmp (FlickrAccount *a,
FlickrAccount *b);
diff --git a/extensions/flicker_utils/flickr-authentication.c b/extensions/flicker_utils/flickr-authentication.c
index d8e1e96..9e8f6ba 100644
--- a/extensions/flicker_utils/flickr-authentication.c
+++ b/extensions/flicker_utils/flickr-authentication.c
@@ -269,7 +269,7 @@ connect_to_server_step2 (FlickrAuthentication *self)
start_authorization_process (self);
return;
}
- flickr_connection_set_auth_token (self->priv->conn, self->priv->account->token);
+ flickr_connection_set_account (self->priv->conn, self->priv->account);
flickr_service_get_upload_status (self->priv->service,
self->priv->cancellable,
upload_status_ready_cb,
@@ -362,22 +362,19 @@ connection_token_ready_cb (GObject *source_object,
return;
}
- account = flickr_account_new ();
- flickr_account_set_username (account, flickr_connection_get_username (self->priv->conn));
- flickr_account_set_token (account, flickr_connection_get_auth_token (self->priv->conn));
+ account = flickr_connection_get_account (self->priv->conn);
set_account (self, account);
- g_object_unref (account);
#ifdef HAVE_GNOME_KEYRING
if (gnome_keyring_is_available ()) {
gnome_keyring_store_password (GNOME_KEYRING_NETWORK_PASSWORD,
NULL,
self->priv->conn->server->name,
- flickr_connection_get_auth_token (self->priv->conn),
+ account->token,
store_password_done_cb,
self,
NULL,
- "user", flickr_connection_get_username (self->priv->conn),
+ "user", account->username,
"server", self->priv->conn->server->url,
"protocol", "http",
NULL);
diff --git a/extensions/flicker_utils/flickr-connection.c b/extensions/flicker_utils/flickr-connection.c
index d2a5c63..f153fd1 100644
--- a/extensions/flicker_utils/flickr-connection.c
+++ b/extensions/flicker_utils/flickr-connection.c
@@ -23,6 +23,7 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gthumb.h>
+#include "flickr-account.h"
#include "flickr-connection.h"
#include "flickr-user.h"
@@ -50,9 +51,7 @@ struct _FlickrConnectionPrivate
SoupSession *session;
SoupMessage *msg;
char *frob;
- char *token;
- char *username;
- char *user_id;
+ FlickrAccount *account;
GCancellable *cancellable;
GSimpleAsyncResult *result;
GChecksum *checksum;
@@ -72,9 +71,7 @@ flickr_connection_finalize (GObject *object)
g_checksum_free (self->priv->checksum);
_g_object_unref (self->priv->result);
_g_object_unref (self->priv->cancellable);
- g_free (self->priv->user_id);
- g_free (self->priv->username);
- g_free (self->priv->token);
+ _g_object_unref (self->priv->account);
g_free (self->priv->frob);
_g_object_unref (self->priv->session);
@@ -125,9 +122,7 @@ flickr_connection_init (FlickrConnection *self)
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, FLICKR_TYPE_CONNECTION, FlickrConnectionPrivate);
self->priv->session = NULL;
self->priv->msg = NULL;
- self->priv->username = NULL;
- self->priv->user_id = NULL;
- self->priv->token = NULL;
+ self->priv->account = flickr_account_new ();
self->priv->frob = NULL;
self->priv->cancellable = NULL;
self->priv->result = NULL;
@@ -253,8 +248,8 @@ flickr_connection_add_api_sig (FlickrConnection *self,
GList *scan;
g_hash_table_insert (data_set, "api_key", (gpointer) self->server->api_key);
- if (self->priv->token != NULL)
- g_hash_table_insert (data_set, "auth_token", self->priv->token);
+ if (self->priv->account->token != NULL)
+ g_hash_table_insert (data_set, "auth_token", self->priv->account->token);
g_checksum_reset (self->priv->checksum);
g_checksum_update (self->priv->checksum, (guchar *) self->server->shared_secret, -1);
@@ -325,8 +320,7 @@ flickr_connection_get_frob (FlickrConnection *self,
gth_task_progress (GTH_TASK (self), _("Connecting to the server"), NULL, TRUE, 0.0);
- g_free (self->priv->token);
- self->priv->token = NULL;
+ flickr_account_set_token (self->priv->account, NULL);
data_set = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (data_set, "method", "flickr.auth.getFrob");
@@ -436,18 +430,15 @@ connection_token_ready_cb (SoupSession *session,
DomElement *node;
for (node = auth->first_child; node; node = node->next_sibling) {
- if (g_strcmp0 (node->tag_name, "token") == 0) {
- self->priv->token = g_strdup (dom_element_get_inner_text (node));
- }
- else if (g_strcmp0 (node->tag_name, "user") == 0) {
- self->priv->username = g_strdup (dom_element_get_attribute (node, "username"));
- self->priv->user_id = g_strdup (dom_element_get_attribute (node, "nsid"));
- }
+ if (g_strcmp0 (node->tag_name, "token") == 0)
+ flickr_account_set_token (self->priv->account, dom_element_get_inner_text (node));
+ else if (g_strcmp0 (node->tag_name, "user") == 0)
+ flickr_account_set_username (self->priv->account, dom_element_get_attribute (node, "username"));
}
}
}
- if (self->priv->token == NULL) {
+ if (self->priv->account->token == NULL) {
error = g_error_new_literal (FLICKR_CONNECTION_ERROR, 0, _("Unknown error"));
g_simple_async_result_set_from_error (self->priv->result, error);
}
@@ -476,8 +467,7 @@ flickr_connection_get_token (FlickrConnection *self,
gth_task_progress (GTH_TASK (self), _("Connecting to the server"), NULL, TRUE, 0.0);
- g_free (self->priv->token);
- self->priv->token = NULL;
+ flickr_account_set_token (self->priv->account, NULL);
data_set = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (data_set, "method", "flickr.auth.getToken");
@@ -510,34 +500,22 @@ flickr_connection_get_token_finish (FlickrConnection *self,
void
-flickr_connection_set_auth_token (FlickrConnection *self,
- const char *value)
-{
- g_free (self->priv->token);
- self->priv->token = NULL;
- if (value != NULL)
- self->priv->token = g_strdup (value);
-}
-
-
-const char *
-flickr_connection_get_auth_token (FlickrConnection *self)
+flickr_connection_set_account (FlickrConnection *self,
+ FlickrAccount *account)
{
- return self->priv->token;
-}
-
-
-const char *
-flickr_connection_get_username (FlickrConnection *self)
-{
- return self->priv->username;
+ if (account != NULL) {
+ _g_object_unref (self->priv->account);
+ self->priv->account = _g_object_ref (account);
+ }
+ else
+ flickr_account_reset (self->priv->account);
}
-const char *
-flickr_connection_get_user_id (FlickrConnection *self)
+FlickrAccount *
+flickr_connection_get_account (FlickrConnection *self)
{
- return self->priv->user_id;
+ return self->priv->account;
}
diff --git a/extensions/flicker_utils/flickr-connection.h b/extensions/flicker_utils/flickr-connection.h
index 15e3ff8..654fd04 100644
--- a/extensions/flicker_utils/flickr-connection.h
+++ b/extensions/flicker_utils/flickr-connection.h
@@ -94,11 +94,9 @@ void flickr_connection_get_token (FlickrConnection
gboolean flickr_connection_get_token_finish (FlickrConnection *self,
GAsyncResult *result,
GError **error);
-void flickr_connection_set_auth_token (FlickrConnection *self,
- const char *value);
-const char * flickr_connection_get_auth_token (FlickrConnection *self);
-const char * flickr_connection_get_username (FlickrConnection *self);
-const char * flickr_connection_get_user_id (FlickrConnection *self);
+void flickr_connection_set_account (FlickrConnection *self,
+ FlickrAccount *account);
+FlickrAccount * flickr_connection_get_account (FlickrConnection *self);
/* utilities */
diff --git a/extensions/flicker_utils/flickr-photo.c b/extensions/flicker_utils/flickr-photo.c
index 6fa8ffc..f85396c 100644
--- a/extensions/flicker_utils/flickr-photo.c
+++ b/extensions/flicker_utils/flickr-photo.c
@@ -256,7 +256,7 @@ flickr_photo_set_is_primary (FlickrPhoto *self,
static char *
flickr_get_static_url (FlickrPhoto *self,
- FlickrUrl size)
+ FlickrUrl size)
{
const char *ext;
@@ -286,7 +286,6 @@ flickr_get_static_url (FlickrPhoto *self,
secret,
FlickrUrlSuffix[size],
ext);
-
else
return g_strdup_printf ("http://%s/%s/%s_%s%s.%s",
self->priv->server->static_url,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]