[gthumb] moved some common code to oauth-service.c



commit b21c2e6f8900eb5484e708305b7aa6c351e1ee5b
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Dec 20 16:47:13 2012 +0100

    moved some common code to oauth-service.c

 extensions/flicker_utils/flickr-consumer.c    |   32 -------------------------
 extensions/oauth/oauth-consumer.c             |    1 -
 extensions/oauth/oauth-consumer.h             |   13 ++++-----
 extensions/oauth/oauth-service.c              |   31 +++++++++++++++++++++---
 extensions/photobucket/photobucket-consumer.c |   30 -----------------------
 5 files changed, 33 insertions(+), 74 deletions(-)
---
diff --git a/extensions/flicker_utils/flickr-consumer.c b/extensions/flicker_utils/flickr-consumer.c
index 5273f86..7e9aa3b 100644
--- a/extensions/flicker_utils/flickr-consumer.c
+++ b/extensions/flicker_utils/flickr-consumer.c
@@ -68,35 +68,6 @@ flickr_utils_parse_response (SoupBuffer   *body,
 }
 
 
-static void
-flickr_request_token_response (OAuthService       *self,
-			       SoupMessage        *msg,
-			       SoupBuffer         *body,
-			       GSimpleAsyncResult *result)
-{
-	GHashTable *values;
-	char       *token;
-	char       *token_secret;
-
-	values = soup_form_decode (body->data);
-	token = g_hash_table_lookup (values, "oauth_token");
-	token_secret = g_hash_table_lookup (values, "oauth_token_secret");
-	if ((token != NULL) && (token_secret != NULL)) {
-		oauth_service_set_token (self, token);
-		oauth_service_set_token_secret (self, token_secret);
-		g_simple_async_result_set_op_res_gboolean (result, TRUE);
-	}
-	else {
-		GError *error;
-
-		error = g_error_new_literal (WEB_SERVICE_ERROR, WEB_SERVICE_ERROR_GENERIC, _("Unknown error"));
-		g_simple_async_result_set_from_error (result, error);
-	}
-
-	g_hash_table_destroy (values);
-}
-
-
 static char *
 flickr_get_authorization_url (OAuthService *self)
 {
@@ -145,8 +116,6 @@ flickr_access_token_response (OAuthService       *self,
 					"token", token,
 					"token-secret", token_secret,
 					NULL);
-		web_service_set_current_account (WEB_SERVICE (self), OAUTH_ACCOUNT (account));
-
 		g_simple_async_result_set_op_res_gpointer (result, account, g_object_unref);
 	}
 	else {
@@ -164,7 +133,6 @@ OAuthConsumer flickr_consumer = {
 	NULL,
 	NULL,
 	NULL,
-	flickr_request_token_response,
 	flickr_get_authorization_url,
 	NULL,
 	flickr_access_token_response
diff --git a/extensions/oauth/oauth-consumer.c b/extensions/oauth/oauth-consumer.c
index 5cc740f..3729ee3 100644
--- a/extensions/oauth/oauth-consumer.c
+++ b/extensions/oauth/oauth-consumer.c
@@ -34,7 +34,6 @@ oauth_consumer_copy (OAuthConsumer *consumer)
 	consumer_2->consumer_key = consumer->consumer_key;
 	consumer_2->consumer_secret = consumer->consumer_secret;
 	consumer_2->request_token_url = consumer->request_token_url;
-	consumer_2->request_token_response = consumer->request_token_response;
 	consumer_2->get_authorization_url = consumer->get_authorization_url;
 	consumer_2->access_token_url = consumer->access_token_url;
 	consumer_2->access_token_response = consumer->access_token_response;
diff --git a/extensions/oauth/oauth-consumer.h b/extensions/oauth/oauth-consumer.h
index 9dccf33..1ecb0de 100644
--- a/extensions/oauth/oauth-consumer.h
+++ b/extensions/oauth/oauth-consumer.h
@@ -41,13 +41,12 @@ typedef char * (*OAuthStringFunc)      (OAuthService        *self);
 
 
 typedef struct {
-	const char               *consumer_key;
-	const char               *consumer_secret;
-	const char               *request_token_url;
-	OAuthResponseFunc         request_token_response;
-	OAuthStringFunc           get_authorization_url;
-	const char               *access_token_url;
-	OAuthResponseFunc         access_token_response;
+	const char		*consumer_key;
+	const char		*consumer_secret;
+	const char		*request_token_url;
+	OAuthStringFunc		 get_authorization_url;
+	const char		*access_token_url;
+	OAuthResponseFunc	 access_token_response;
 } OAuthConsumer;
 
 
diff --git a/extensions/oauth/oauth-service.c b/extensions/oauth/oauth-service.c
index 3c29e19..39e10a8 100644
--- a/extensions/oauth/oauth-service.c
+++ b/extensions/oauth/oauth-service.c
@@ -123,6 +123,9 @@ _oauth_service_get_request_token_ready_cb (SoupSession *session,
 	OAuthService       *self = user_data;
 	GSimpleAsyncResult *result;
 	SoupBuffer         *body;
+	GHashTable         *values;
+	char               *token;
+	char               *token_secret;
 
 	result = _web_service_get_result (WEB_SERVICE (self));
 
@@ -137,9 +140,24 @@ _oauth_service_get_request_token_ready_cb (SoupSession *session,
 	}
 
 	body = soup_message_body_flatten (msg->response_body);
-	self->priv->consumer->request_token_response (self, msg, body, result);
+	values = soup_form_decode (body->data);
+	token = g_hash_table_lookup (values, "oauth_token");
+	token_secret = g_hash_table_lookup (values, "oauth_token_secret");
+	if ((token != NULL) && (token_secret != NULL)) {
+		oauth_service_set_token (self, token);
+		oauth_service_set_token_secret (self, token_secret);
+		g_simple_async_result_set_op_res_gboolean (result, TRUE);
+	}
+	else {
+		GError *error;
+
+		error = g_error_new_literal (WEB_SERVICE_ERROR, WEB_SERVICE_ERROR_GENERIC, _("Unknown error"));
+		g_simple_async_result_set_from_error (result, error);
+	}
+
 	g_simple_async_result_complete_in_idle (result);
 
+	g_hash_table_destroy (values);
 	soup_buffer_free (body);
 }
 
@@ -264,15 +282,20 @@ get_access_token_ready_cb (GObject      *source_object,
 	OAuthService *self = user_data;
 	GError       *error = NULL;
 	GtkWidget    *dialog;
+	OAuthAccount *account;
 
 	dialog = _web_service_get_auth_dialog (WEB_SERVICE (self));
-
-	if (! _oauth_service_get_access_token_finish (self, result, &error)) {
+	account = _oauth_service_get_access_token_finish (self, result, &error);
+	if (account == NULL) {
+		gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
 		gth_task_completed (GTH_TASK (self), error);
 		return;
 	}
 
+	web_service_set_current_account (WEB_SERVICE (self), account);
 	gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+	g_object_unref (account);
 }
 
 
@@ -336,7 +359,7 @@ get_request_token_ready_cb (GObject      *source_object,
 
 	url = self->priv->consumer->get_authorization_url (self);
 	dialog = oauth_ask_authorization_dialog_new (url);
-	_gtk_window_resize_to_fit_screen_height (dialog, 800);
+	_gtk_window_resize_to_fit_screen_height (dialog, 1024);
 	_web_service_set_auth_dialog (WEB_SERVICE (self), GTK_DIALOG (dialog));
 	g_signal_connect (OAUTH_ASK_AUTHORIZATION_DIALOG (dialog),
 			  "load-request",
diff --git a/extensions/photobucket/photobucket-consumer.c b/extensions/photobucket/photobucket-consumer.c
index 8788adb..a365cfa 100644
--- a/extensions/photobucket/photobucket-consumer.c
+++ b/extensions/photobucket/photobucket-consumer.c
@@ -92,35 +92,6 @@ photobucket_utils_parse_response (SoupMessage         *msg,
 }
 
 
-static void
-photobucket_request_token_response (OAuthService       *self,
-				    SoupMessage        *msg,
-				    SoupBuffer         *body,
-				    GSimpleAsyncResult *result)
-{
-	GHashTable *values;
-	char       *token;
-	char       *token_secret;
-
-	values = soup_form_decode (body->data);
-	token = g_hash_table_lookup (values, "oauth_token");
-	token_secret = g_hash_table_lookup (values, "oauth_token_secret");
-	if ((token != NULL) && (token_secret != NULL)) {
-		oauth_service_set_token (self, token);
-		oauth_service_set_token_secret (self, token_secret);
-		g_simple_async_result_set_op_res_gboolean (result, TRUE);
-	}
-	else {
-		GError *error;
-
-		error = g_error_new_literal (WEB_SERVICE_ERROR, WEB_SERVICE_ERROR_GENERIC, _("Unknown error"));
-		g_simple_async_result_set_from_error (result, error);
-	}
-
-	g_hash_table_destroy (values);
-}
-
-
 static char *
 photobucket_get_authorization_url (OAuthService *self)
 {
@@ -185,7 +156,6 @@ OAuthConsumer photobucket_consumer = {
 	"149829931",
 	"b4e542229836cc59b66489c6d2d8ca04",
 	"http://api.photobucket.com/login/request";,
-	photobucket_request_token_response,
 	photobucket_get_authorization_url,
 	"http://api.photobucket.com/login/access";,
 	photobucket_access_token_response



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