[gthumb] photobucket-account: added some properties to simplify the code



commit 2f10ed46e7a4009aaf7f552702a8329d5e0c8e86
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Dec 20 16:48:29 2012 +0100

    photobucket-account: added some properties to simplify the code

 extensions/photobucket/photobucket-account.c  |   78 ++++++++++++++++++++++++-
 extensions/photobucket/photobucket-consumer.c |   13 ++--
 2 files changed, 83 insertions(+), 8 deletions(-)
---
diff --git a/extensions/photobucket/photobucket-account.c b/extensions/photobucket/photobucket-account.c
index 98049bf..77c3d10 100644
--- a/extensions/photobucket/photobucket-account.c
+++ b/extensions/photobucket/photobucket-account.c
@@ -26,6 +26,13 @@
 #include "photobucket-account.h"
 
 
+enum {
+        PROP_0,
+        PROP_SUBDOMAIN,
+        PROP_HOME_URL
+};
+
+
 static void photobucket_account_dom_domizable_interface_init (DomDomizableInterface *iface);
 
 
@@ -52,9 +59,78 @@ photobucket_account_finalize (GObject *obj)
 
 
 static void
+photobucket_account_set_property (GObject      *object,
+				  guint         property_id,
+				  const GValue *value,
+				  GParamSpec   *pspec)
+{
+	PhotobucketAccount *self;
+
+	self = PHOTOBUCKET_ACCOUNT (object);
+
+	switch (property_id) {
+	case PROP_SUBDOMAIN:
+		_g_strset (&self->subdomain, g_value_get_string (value));
+		break;
+	case PROP_HOME_URL:
+		_g_strset (&self->home_url, g_value_get_string (value));
+		break;
+	default:
+		break;
+	}
+}
+
+
+static void
+photobucket_account_get_property (GObject    *object,
+				  guint       property_id,
+				  GValue     *value,
+				  GParamSpec *pspec)
+{
+	PhotobucketAccount *self;
+
+	self = PHOTOBUCKET_ACCOUNT (object);
+
+	switch (property_id) {
+	case PROP_SUBDOMAIN:
+		g_value_set_string (value, self->subdomain);
+		break;
+	case PROP_HOME_URL:
+		g_value_set_string (value, self->home_url);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+		break;
+	}
+}
+
+
+static void
 photobucket_account_class_init (PhotobucketAccountClass *klass)
 {
-	G_OBJECT_CLASS (klass)->finalize = photobucket_account_finalize;
+	GObjectClass *object_class;
+
+	object_class = G_OBJECT_CLASS (klass);
+	object_class->finalize = photobucket_account_finalize;
+	object_class->set_property = photobucket_account_set_property;
+	object_class->get_property = photobucket_account_get_property;
+
+	/* properties */
+
+	g_object_class_install_property (object_class,
+					 PROP_SUBDOMAIN,
+					 g_param_spec_string ("subdomain",
+                                                              "Subdomain",
+                                                              "",
+                                                              NULL,
+                                                              G_PARAM_READWRITE));
+	g_object_class_install_property (object_class,
+					 PROP_HOME_URL,
+					 g_param_spec_string ("home-url",
+                                                              "Home URL",
+                                                              "",
+                                                              NULL,
+                                                              G_PARAM_READWRITE));
 }
 
 
diff --git a/extensions/photobucket/photobucket-consumer.c b/extensions/photobucket/photobucket-consumer.c
index a365cfa..7ac2082 100644
--- a/extensions/photobucket/photobucket-consumer.c
+++ b/extensions/photobucket/photobucket-consumer.c
@@ -116,29 +116,28 @@ photobucket_access_token_response (OAuthService       *self,
 				   GSimpleAsyncResult *result)
 {
 	GHashTable *values;
-	char       *username;
 	char       *token;
 	char       *token_secret;
 
 	values = soup_form_decode (body->data);
 
-	username = g_hash_table_lookup (values, "username");
 	token = g_hash_table_lookup (values, "oauth_token");
 	token_secret = g_hash_table_lookup (values, "oauth_token_secret");
-	if ((username != NULL) && (token != NULL) && (token_secret != NULL)) {
+	if ((token != NULL) && (token_secret != NULL)) {
 		OAuthAccount *account;
 
 		oauth_service_set_token (self, token);
 		oauth_service_set_token_secret (self, token_secret);
 
 		account = g_object_new (PHOTOBUCKET_TYPE_ACCOUNT,
-					"name", username,
-					"username", username,
+					"id", g_hash_table_lookup (values, "username"),
+					"name", g_hash_table_lookup (values, "username"),
+					"username", g_hash_table_lookup (values, "username"),
 					"token", token,
 					"token-secret", token_secret,
+					"subdomain", g_hash_table_lookup (values, "subdomain"),
+					"home-url", g_hash_table_lookup (values, "homeurl"),
 					NULL);
-		photobucket_account_set_subdomain (PHOTOBUCKET_ACCOUNT (account), g_hash_table_lookup (values, "subdomain"));
-		photobucket_account_set_home_url (PHOTOBUCKET_ACCOUNT (account), g_hash_table_lookup (values, "homeurl"));
 		g_simple_async_result_set_op_res_gpointer (result, account, g_object_unref);
 	}
 	else {



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