[gthumb] facebook: use the common oauth account manager, instead of a custom one
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] facebook: use the common oauth account manager, instead of a custom one
- Date: Sat, 22 Dec 2012 16:08:14 +0000 (UTC)
commit 2b3a0492267d5b5bc4e0533ada01578f931e7cd7
Author: Paolo Bacchilega <paobac src gnome org>
Date: Wed Dec 12 13:20:24 2012 +0100
facebook: use the common oauth account manager, instead of a custom one
extensions/facebook/Makefile.am | 6 -
extensions/facebook/data/ui/Makefile.am | 2 -
.../facebook/data/ui/facebook-account-chooser.ui | 61 -----
.../facebook/data/ui/facebook-account-manager.ui | 113 ----------
extensions/facebook/dlg-export-to-facebook.c | 25 +-
.../facebook/facebook-account-chooser-dialog.c | 236 --------------------
.../facebook/facebook-account-chooser-dialog.h | 60 -----
.../facebook/facebook-account-manager-dialog.c | 219 ------------------
.../facebook/facebook-account-manager-dialog.h | 58 -----
extensions/facebook/facebook-account.c | 176 ---------------
extensions/facebook/facebook-account.h | 68 ------
extensions/facebook/facebook-authentication.c | 57 +++---
extensions/facebook/facebook-authentication.h | 6 +-
extensions/facebook/facebook-service.c | 105 +---------
extensions/facebook/facebook-service.h | 8 -
extensions/oauth/Makefile.am | 1 +
extensions/oauth/data/ui/oauth-account-manager.ui | 6 +-
extensions/oauth/oauth-account-manager-dialog.c | 14 +-
extensions/oauth/oauth-account.c | 169 +++++++++++++-
extensions/oauth/oauth-account.h | 6 +-
extensions/oauth/oauth-authentication.c | 13 +-
extensions/oauth/oauth.h | 32 +++
extensions/oauth/oauth2-ask-authorization-dialog.c | 4 +-
extensions/photobucket/photobucket-account.c | 4 +-
extensions/photobucket/photobucket-consumer.c | 9 +-
25 files changed, 273 insertions(+), 1185 deletions(-)
---
diff --git a/extensions/facebook/Makefile.am b/extensions/facebook/Makefile.am
index 5456eec..3795a91 100644
--- a/extensions/facebook/Makefile.am
+++ b/extensions/facebook/Makefile.am
@@ -12,12 +12,6 @@ libfacebook_la_SOURCES = \
callbacks.h \
dlg-export-to-facebook.c \
dlg-export-to-facebook.h \
- facebook-account.c \
- facebook-account.h \
- facebook-account-chooser-dialog.c \
- facebook-account-chooser-dialog.h \
- facebook-account-manager-dialog.c \
- facebook-account-manager-dialog.h \
facebook-album.c \
facebook-album.h \
facebook-album-properties-dialog.c \
diff --git a/extensions/facebook/data/ui/Makefile.am b/extensions/facebook/data/ui/Makefile.am
index 2007a37..c288b4b 100644
--- a/extensions/facebook/data/ui/Makefile.am
+++ b/extensions/facebook/data/ui/Makefile.am
@@ -1,8 +1,6 @@
uidir = $(pkgdatadir)/ui
ui_DATA = \
export-to-facebook.ui \
- facebook-account-chooser.ui \
- facebook-account-manager.ui \
facebook-album-properties.ui \
facebook-export-completed.ui
diff --git a/extensions/facebook/dlg-export-to-facebook.c b/extensions/facebook/dlg-export-to-facebook.c
index 96bd704..855689d 100644
--- a/extensions/facebook/dlg-export-to-facebook.c
+++ b/extensions/facebook/dlg-export-to-facebook.c
@@ -22,6 +22,7 @@
#include <config.h>
#include <gtk/gtk.h>
#include <gthumb.h>
+#include <extensions/oauth/oauth.h>
#include "dlg-export-to-facebook.h"
#include "facebook-authentication.h"
#include "facebook-album.h"
@@ -67,7 +68,7 @@ typedef struct {
FacebookConnection *conn;
FacebookAuthentication *auth;
FacebookService *service;
- FacebookAccount *account;
+ OAuthAccount *account;
GList *albums;
FacebookAlbum *album;
GList *photos_ids;
@@ -254,18 +255,18 @@ export_dialog_response_cb (GtkDialog *dialog,
static void
update_account_list (DialogData *data)
{
- int current_account_idx;
- FacebookAccount *current_account;
- int idx;
- GList *scan;
- GtkTreeIter iter;
+ int current_account_idx;
+ OAuthAccount *current_account;
+ int idx;
+ GList *scan;
+ GtkTreeIter iter;
gtk_list_store_clear (GTK_LIST_STORE (GET_WIDGET ("account_liststore")));
current_account_idx = 0;
current_account = facebook_authentication_get_account (data->auth);
for (scan = facebook_authentication_get_accounts (data->auth), idx = 0; scan; scan = scan->next, idx++) {
- FacebookAccount *account = scan->data;
+ OAuthAccount *account = scan->data;
if ((current_account != NULL) && (g_strcmp0 (current_account->username, account->username) == 0))
current_account_idx = idx;
@@ -273,7 +274,7 @@ update_account_list (DialogData *data)
gtk_list_store_append (GTK_LIST_STORE (GET_WIDGET ("account_liststore")), &iter);
gtk_list_store_set (GTK_LIST_STORE (GET_WIDGET ("account_liststore")), &iter,
ACCOUNT_DATA_COLUMN, account,
- ACCOUNT_NAME_COLUMN, account->username,
+ ACCOUNT_NAME_COLUMN, account->name,
-1);
}
gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("account_combobox")), current_account_idx);
@@ -373,9 +374,9 @@ static void
account_combobox_changed_cb (GtkComboBox *widget,
gpointer user_data)
{
- DialogData *data = user_data;
- GtkTreeIter iter;
- FacebookAccount *account;
+ DialogData *data = user_data;
+ GtkTreeIter iter;
+ OAuthAccount *account;
if (! gtk_combo_box_get_active_iter (widget, &iter))
return;
@@ -385,7 +386,7 @@ account_combobox_changed_cb (GtkComboBox *widget,
ACCOUNT_DATA_COLUMN, &account,
-1);
- if (facebook_account_cmp (account, facebook_authentication_get_account (data->auth)) != 0)
+ if (oauth_account_cmp (account, facebook_authentication_get_account (data->auth)) != 0)
facebook_authentication_connect (data->auth, account);
g_object_unref (account);
diff --git a/extensions/facebook/facebook-authentication.c b/extensions/facebook/facebook-authentication.c
index 217000b..ea36bd4 100644
--- a/extensions/facebook/facebook-authentication.c
+++ b/extensions/facebook/facebook-authentication.c
@@ -24,9 +24,7 @@
#ifdef HAVE_LIBSECRET
#include <libsecret/secret.h>
#endif /* HAVE_LIBSECRET */
-#include <extensions/oauth/oauth2-ask-authorization-dialog.h>
-#include "facebook-account-chooser-dialog.h"
-#include "facebook-account-manager-dialog.h"
+#include <extensions/oauth/oauth.h>
#include "facebook-authentication.h"
#include "facebook-user.h"
#include "facebook-service.h"
@@ -48,7 +46,7 @@ struct _FacebookAuthenticationPrivate
FacebookService *service;
GCancellable *cancellable;
GList *accounts;
- FacebookAccount *account;
+ OAuthAccount *account;
GtkWidget *browser;
GtkWidget *dialog;
};
@@ -134,8 +132,8 @@ facebook_authentication_new (FacebookConnection *conn,
self->priv->conn = g_object_ref (conn);
self->priv->service = g_object_ref (service);
self->priv->cancellable = _g_object_ref (cancellable);
- self->priv->accounts = facebook_accounts_load_from_file ();
- self->priv->account = facebook_accounts_find_default (self->priv->accounts);
+ self->priv->accounts = oauth_accounts_load_from_file ("facebook", 0);
+ self->priv->account = oauth_accounts_find_default (self->priv->accounts);
self->priv->browser = browser;
self->priv->dialog = dialog;
@@ -212,11 +210,11 @@ show_authentication_error_dialog (FacebookAuthentication *self,
static void
set_current_account (FacebookAuthentication *self,
- FacebookAccount *account)
+ OAuthAccount *account)
{
GList *link;
- link = g_list_find_custom (self->priv->accounts, self->priv->account, (GCompareFunc) facebook_account_cmp);
+ link = g_list_find_custom (self->priv->accounts, self->priv->account, (GCompareFunc) oauth_account_cmp);
if (link != NULL) {
self->priv->accounts = g_list_remove_link (self->priv->accounts, link);
_g_object_list_unref (link);
@@ -264,7 +262,7 @@ get_user_ready_cb (GObject *source_object,
FacebookAuthentication *self = user_data;
GError *error = NULL;
FacebookUser *user;
- FacebookAccount *account;
+ OAuthAccount *account;
user = facebook_service_get_user_finish (self->priv->service, res, &error);
if (user == NULL) {
@@ -272,12 +270,14 @@ get_user_ready_cb (GObject *source_object,
return;
}
- account = facebook_account_new ();
- facebook_account_set_username (account, user->name);
- facebook_account_set_user_id (account, user->id);
- facebook_account_set_token (account, facebook_connection_get_access_token (self->priv->conn));
+ account = g_object_new (OAUTH_TYPE_ACCOUNT,
+ "id", user->id,
+ "username", user->username,
+ "name", user->name,
+ "token", facebook_connection_get_access_token (self->priv->conn),
+ NULL);
set_current_account (self, account);
- facebook_accounts_save_to_file (self->priv->accounts, self->priv->account);
+ oauth_accounts_save_to_file ("facebook", self->priv->accounts, self->priv->account);
#ifdef HAVE_LIBSECRET
{
@@ -288,7 +288,7 @@ get_user_ready_cb (GObject *source_object,
self->priv->cancellable,
password_store_ready_cb,
self,
- "user", account->user_id,
+ "user", account->id,
"server", FACEBOOK_HTTP_SERVER,
"protocol", "https",
NULL);
@@ -328,7 +328,7 @@ password_lookup_ready_cb (GObject *source_object,
secret = secret_password_lookup_finish (result, NULL);
if (secret != NULL) {
- facebook_account_set_token (self->priv->account, secret);
+ g_object_set (G_OBJECT (self->priv->account), "token", secret, NULL);
g_free (secret);
}
@@ -341,7 +341,7 @@ static void
connect_to_server (FacebookAuthentication *self)
{
g_return_if_fail (self->priv->account != NULL);
- g_return_if_fail (self->priv->account->user_id != NULL);
+ g_return_if_fail (self->priv->account->id != NULL);
#ifdef HAVE_LIBSECRET
if (self->priv->account->token == NULL) {
@@ -349,7 +349,7 @@ connect_to_server (FacebookAuthentication *self)
self->priv->cancellable,
password_lookup_ready_cb,
self,
- "user", self->priv->account->user_id,
+ "user", self->priv->account->id,
"server", FACEBOOK_HTTP_SERVER,
"protocol", "https",
NULL);
@@ -434,6 +434,7 @@ start_authorization_process (FacebookAuthentication *self)
else
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self->priv->browser));
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+ gtk_window_set_default_size (GTK_WINDOW (dialog), 800, 600);
g_signal_connect (dialog,
"delete-event",
@@ -468,14 +469,14 @@ account_chooser_dialog_response_cb (GtkDialog *dialog,
case GTK_RESPONSE_OK:
_g_object_unref (self->priv->account);
- self->priv->account = facebook_account_chooser_dialog_get_active (FACEBOOK_ACCOUNT_CHOOSER_DIALOG (dialog));
+ self->priv->account = oauth_account_chooser_dialog_get_active (OAUTH_ACCOUNT_CHOOSER_DIALOG (dialog));
if (self->priv->account != NULL) {
gtk_widget_destroy (GTK_WIDGET (dialog));
connect_to_server (self);
}
break;
- case FACEBOOK_ACCOUNT_CHOOSER_RESPONSE_NEW:
+ case OAUTH_ACCOUNT_CHOOSER_RESPONSE_NEW:
gtk_widget_destroy (GTK_WIDGET (dialog));
start_authorization_process (self);
break;
@@ -492,7 +493,7 @@ show_choose_account_dialog (FacebookAuthentication *self)
GtkWidget *dialog;
gth_task_dialog (GTH_TASK (self->priv->conn), TRUE, NULL);
- dialog = facebook_account_chooser_dialog_new (self->priv->accounts, self->priv->account);
+ dialog = oauth_account_chooser_dialog_new (self->priv->accounts, self->priv->account);
g_signal_connect (dialog,
"delete-event",
G_CALLBACK (gtk_true),
@@ -533,14 +534,14 @@ facebook_authentication_auto_connect (FacebookAuthentication *self)
void
facebook_authentication_connect (FacebookAuthentication *self,
- FacebookAccount *account)
+ OAuthAccount *account)
{
set_current_account (self, account);
facebook_authentication_auto_connect (self);
}
-FacebookAccount *
+OAuthAccount *
facebook_authentication_get_account (FacebookAuthentication *self)
{
return self->priv->account;
@@ -572,19 +573,19 @@ account_manager_dialog_response_cb (GtkDialog *dialog,
case GTK_RESPONSE_OK:
_g_object_list_unref (self->priv->accounts);
- self->priv->accounts = facebook_account_manager_dialog_get_accounts (FACEBOOK_ACCOUNT_MANAGER_DIALOG (dialog));
- if (! g_list_find_custom (self->priv->accounts, self->priv->account, (GCompareFunc) facebook_account_cmp)) {
+ self->priv->accounts = oauth_account_manager_dialog_get_accounts (OAUTH_ACCOUNT_MANAGER_DIALOG (dialog));
+ if (! g_list_find_custom (self->priv->accounts, self->priv->account, (GCompareFunc) oauth_account_cmp)) {
_g_object_unref (self->priv->account);
self->priv->account = NULL;
facebook_authentication_auto_connect (self);
}
else
g_signal_emit (self, facebook_authentication_signals[ACCOUNTS_CHANGED], 0);
- facebook_accounts_save_to_file (self->priv->accounts, self->priv->account);
+ oauth_accounts_save_to_file ("facebook", self->priv->accounts, self->priv->account);
gtk_widget_destroy (GTK_WIDGET (dialog));
break;
- case FACEBOOK_ACCOUNT_MANAGER_RESPONSE_NEW:
+ case OAUTH_ACCOUNT_CHOOSER_RESPONSE_NEW:
gtk_widget_destroy (GTK_WIDGET (dialog));
start_authorization_process (self);
break;
@@ -601,7 +602,7 @@ facebook_authentication_edit_accounts (FacebookAuthentication *self,
{
GtkWidget *dialog;
- dialog = facebook_account_manager_dialog_new (self->priv->accounts);
+ dialog = oauth_account_manager_dialog_new (self->priv->accounts);
g_signal_connect (dialog,
"delete-event",
G_CALLBACK (gtk_true),
diff --git a/extensions/facebook/facebook-authentication.h b/extensions/facebook/facebook-authentication.h
index 997515e..a1428b9 100644
--- a/extensions/facebook/facebook-authentication.h
+++ b/extensions/facebook/facebook-authentication.h
@@ -24,7 +24,7 @@
#include <glib.h>
#include <glib-object.h>
-#include "facebook-account.h"
+#include <extensions/oauth/oauth.h>
#include "facebook-connection.h"
#include "facebook-service.h"
#include "facebook-user.h"
@@ -67,8 +67,8 @@ FacebookAuthentication * facebook_authentication_new (FacebookConnec
GtkWidget *dialog);
void facebook_authentication_auto_connect (FacebookAuthentication *auth);
void facebook_authentication_connect (FacebookAuthentication *auth,
- FacebookAccount *account);
-FacebookAccount * facebook_authentication_get_account (FacebookAuthentication *auth);
+ OAuthAccount *account);
+OAuthAccount * facebook_authentication_get_account (FacebookAuthentication *auth);
GList * facebook_authentication_get_accounts (FacebookAuthentication *auth);
void facebook_authentication_edit_accounts (FacebookAuthentication *auth,
GtkWindow *parent);
diff --git a/extensions/facebook/facebook-service.c b/extensions/facebook/facebook-service.c
index f211180..2b4c4bb 100644
--- a/extensions/facebook/facebook-service.c
+++ b/extensions/facebook/facebook-service.c
@@ -24,7 +24,7 @@
#include <glib/gi18n.h>
#include <json-glib/json-glib.h>
#include <gthumb.h>
-#include "facebook-account.h"
+#include <extensions/oauth/oauth.h>
#include "facebook-album.h"
#include "facebook-connection.h"
#include "facebook-photo.h"
@@ -873,106 +873,3 @@ facebook_service_list_photos_finish (FacebookService *self,
#endif
-
-/* utilities */
-
-
-GList *
-facebook_accounts_load_from_file (void)
-{
- GList *accounts = NULL;
- GFile *file;
- char *buffer;
- gsize len;
- DomDocument *doc;
-
- file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "facebook.xml", NULL);
- if (! _g_file_load_in_buffer (file, (void **) &buffer, &len, NULL, NULL)) {
- g_object_unref (file);
- return NULL;
- }
-
- doc = dom_document_new ();
- if (dom_document_load (doc, buffer, len, NULL)) {
- DomElement *node;
-
- node = DOM_ELEMENT (doc)->first_child;
- if ((node != NULL) && (g_strcmp0 (node->tag_name, "accounts") == 0)) {
- DomElement *child;
-
- for (child = node->first_child;
- child != NULL;
- child = child->next_sibling)
- {
- if (strcmp (child->tag_name, "account") == 0) {
- FacebookAccount *account;
-
- account = facebook_account_new ();
- dom_domizable_load_from_element (DOM_DOMIZABLE (account), child);
-
- accounts = g_list_prepend (accounts, account);
- }
- }
-
- accounts = g_list_reverse (accounts);
- }
- }
-
- g_object_unref (doc);
- g_free (buffer);
- g_object_unref (file);
-
- return accounts;
-}
-
-
-FacebookAccount *
-facebook_accounts_find_default (GList *accounts)
-{
- GList *scan;
-
- for (scan = accounts; scan; scan = scan->next) {
- FacebookAccount *account = scan->data;
-
- if (account->is_default)
- return g_object_ref (account);
- }
-
- return NULL;
-}
-
-
-void
-facebook_accounts_save_to_file (GList *accounts,
- FacebookAccount *default_account)
-{
- DomDocument *doc;
- DomElement *root;
- GList *scan;
- char *buffer;
- gsize len;
- GFile *file;
-
- doc = dom_document_new ();
- root = dom_document_create_element (doc, "accounts", NULL);
- dom_element_append_child (DOM_ELEMENT (doc), root);
- for (scan = accounts; scan; scan = scan->next) {
- FacebookAccount *account = scan->data;
- DomElement *node;
-
- if ((default_account != NULL) && g_strcmp0 (account->username, default_account->username) == 0)
- account->is_default = TRUE;
- else
- account->is_default = FALSE;
- node = dom_domizable_create_element (DOM_DOMIZABLE (account), doc);
- dom_element_append_child (root, node);
- }
-
- file = gth_user_dir_get_file_for_write (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", "facebook.xml", NULL);
- buffer = dom_document_dump (doc, &len);
- _g_file_write (file, FALSE, G_FILE_CREATE_PRIVATE | G_FILE_CREATE_REPLACE_DESTINATION, buffer, len, NULL, NULL);
-
- g_free (buffer);
- g_object_unref (file);
- g_object_unref (doc);
-}
diff --git a/extensions/facebook/facebook-service.h b/extensions/facebook/facebook-service.h
index 8396dca..8f065d2 100644
--- a/extensions/facebook/facebook-service.h
+++ b/extensions/facebook/facebook-service.h
@@ -23,7 +23,6 @@
#define FACEBOOK_SERVICE_H
#include <glib-object.h>
-#include "facebook-account.h"
#include "facebook-connection.h"
#include "facebook-album.h"
#include "facebook-types.h"
@@ -95,11 +94,4 @@ GList * facebook_service_list_photos_finish (FacebookService
GError **error);
#endif
-/* utilities */
-
-GList * facebook_accounts_load_from_file (void);
-FacebookAccount * facebook_accounts_find_default (GList *accounts);
-void facebook_accounts_save_to_file (GList *accounts,
- FacebookAccount *default_account);
-
#endif /* FACEBOOK_SERVICE_H */
diff --git a/extensions/oauth/Makefile.am b/extensions/oauth/Makefile.am
index 009e29c..f22c444 100644
--- a/extensions/oauth/Makefile.am
+++ b/extensions/oauth/Makefile.am
@@ -7,6 +7,7 @@ extension_LTLIBRARIES = liboauth.la
liboauth_la_SOURCES = \
main.c \
+ oauth.h \
oauth2-ask-authorization-dialog.c \
oauth2-ask-authorization-dialog.h \
oauth-account.c \
diff --git a/extensions/oauth/data/ui/oauth-account-manager.ui b/extensions/oauth/data/ui/oauth-account-manager.ui
index b63c358..29cf12b 100644
--- a/extensions/oauth/data/ui/oauth-account-manager.ui
+++ b/extensions/oauth/data/ui/oauth-account-manager.ui
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <requires lib="gtk+" version="2.16"/>
+ <!-- interface-requires gtk+ 3.0 -->
<object class="GtkListStore" id="accounts_liststore">
<columns>
<!-- column-name data -->
@@ -78,16 +78,14 @@
<property name="spacing">6</property>
<child>
<object class="GtkButton" id="delete_button">
- <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
- <property name="use_action_appearance">False</property>
<child>
<object class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="stock">gtk-delete</property>
+ <property name="icon_name">list-remove-symbolic</property>
</object>
</child>
</object>
diff --git a/extensions/oauth/oauth-account-manager-dialog.c b/extensions/oauth/oauth-account-manager-dialog.c
index a65c21f..6a2e9d5 100644
--- a/extensions/oauth/oauth-account-manager-dialog.c
+++ b/extensions/oauth/oauth-account-manager-dialog.c
@@ -72,8 +72,8 @@ delete_button_clicked_cb (GtkWidget *button,
gpointer user_data)
{
OAuthAccountManagerDialog *self = user_data;
- GtkTreeModel *tree_model;
- GtkTreeIter iter;
+ GtkTreeModel *tree_model;
+ GtkTreeIter iter;
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (GET_WIDGET ("account_treeview"))),
&tree_model,
@@ -91,8 +91,8 @@ text_renderer_edited_cb (GtkCellRendererText *renderer,
gpointer user_data)
{
OAuthAccountManagerDialog *self = user_data;
- GtkTreePath *tree_path;
- GtkTreeIter iter;
+ GtkTreePath *tree_path;
+ GtkTreeIter iter;
OAuthAccount *account;
tree_path = gtk_tree_path_new_from_string (path);
@@ -109,7 +109,7 @@ text_renderer_edited_cb (GtkCellRendererText *renderer,
gtk_tree_model_get (GTK_TREE_MODEL (GET_WIDGET ("accounts_liststore")), &iter,
ACCOUNT_DATA_COLUMN, &account,
-1);
- oauth_account_set_username (account, new_text);
+ g_object_set (account, "name", new_text, NULL);
gtk_list_store_set (GTK_LIST_STORE (GET_WIDGET ("accounts_liststore")), &iter,
ACCOUNT_DATA_COLUMN, account,
@@ -161,7 +161,7 @@ oauth_account_manager_dialog_init (OAuthAccountManagerDialog *self)
static void
oauth_account_manager_dialog_construct (OAuthAccountManagerDialog *self,
- GList *accounts)
+ GList *accounts)
{
GtkListStore *list_store;
GtkTreeIter iter;
@@ -175,7 +175,7 @@ oauth_account_manager_dialog_construct (OAuthAccountManagerDialog *self,
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
ACCOUNT_DATA_COLUMN, account,
- ACCOUNT_NAME_COLUMN, account->username,
+ ACCOUNT_NAME_COLUMN, account->name,
-1);
}
}
diff --git a/extensions/oauth/oauth-account.c b/extensions/oauth/oauth-account.c
index 2a59e9a..39b3a5a 100644
--- a/extensions/oauth/oauth-account.c
+++ b/extensions/oauth/oauth-account.c
@@ -29,6 +29,17 @@
#include "oauth-account.h"
+enum {
+ PROP_0,
+ PROP_ID,
+ PROP_USERNAME,
+ PROP_NAME,
+ PROP_TOKEN,
+ PROP_TOKEN_SECRET,
+ PROP_IS_DEFAULT
+};
+
+
static void oauth_account_dom_domizable_interface_init (DomDomizableInterface *iface);
@@ -46,7 +57,9 @@ oauth_account_finalize (GObject *obj)
self = OAUTH_ACCOUNT (obj);
+ g_free (self->id);
g_free (self->username);
+ g_free (self->name);
g_free (self->token);
g_free (self->token_secret);
@@ -55,13 +68,136 @@ oauth_account_finalize (GObject *obj)
static void
+oauth_account_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ OAuthAccount *self;
+
+ self = OAUTH_ACCOUNT (object);
+
+ switch (property_id) {
+ case PROP_ID:
+ _g_strset (&self->id, g_value_get_string (value));
+ break;
+ case PROP_USERNAME:
+ _g_strset (&self->username, g_value_get_string (value));
+ if (self->name == NULL)
+ _g_strset (&self->name, g_value_get_string (value));
+ break;
+ case PROP_NAME:
+ _g_strset (&self->name, g_value_get_string (value));
+ break;
+ case PROP_TOKEN:
+ _g_strset (&self->token, g_value_get_string (value));
+ break;
+ case PROP_TOKEN_SECRET:
+ _g_strset (&self->token_secret, g_value_get_string (value));
+ break;
+ case PROP_IS_DEFAULT:
+ self->is_default = g_value_get_boolean (value);
+ break;
+ default:
+ break;
+ }
+}
+
+
+static void
+oauth_account_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ OAuthAccount *self;
+
+ self = OAUTH_ACCOUNT (object);
+
+ switch (property_id) {
+ case PROP_ID:
+ g_value_set_string (value, self->id);
+ break;
+ case PROP_USERNAME:
+ g_value_set_string (value, self->username);
+ break;
+ case PROP_NAME:
+ g_value_set_string (value, self->name);
+ break;
+ case PROP_TOKEN:
+ g_value_set_string (value, self->token);
+ break;
+ case PROP_TOKEN_SECRET:
+ g_value_set_string (value, self->token_secret);
+ break;
+ case PROP_IS_DEFAULT:
+ g_value_set_boolean (value, self->is_default);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
+static void
oauth_account_class_init (OAuthAccountClass *klass)
{
- G_OBJECT_CLASS (klass)->finalize = oauth_account_finalize;
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = oauth_account_finalize;
+ object_class->set_property = oauth_account_set_property;
+ object_class->get_property = oauth_account_get_property;
+
+ /* properties */
+
+ g_object_class_install_property (object_class,
+ PROP_ID,
+ g_param_spec_string ("id",
+ "ID",
+ "",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_USERNAME,
+ g_param_spec_string ("username",
+ "Username",
+ "",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_NAME,
+ g_param_spec_string ("name",
+ "Name",
+ "",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_TOKEN,
+ g_param_spec_string ("token",
+ "Token",
+ "",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_TOKEN_SECRET,
+ g_param_spec_string ("token-secret",
+ "Token secret",
+ "",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_IS_DEFAULT,
+ g_param_spec_boolean ("is-default",
+ "Is default",
+ "",
+ FALSE,
+ G_PARAM_READWRITE));
}
-DomElement*
+static DomElement *
oauth_account_create_element (DomDomizable *base,
DomDocument *doc)
{
@@ -72,8 +208,12 @@ oauth_account_create_element (DomDomizable *base,
self = OAUTH_ACCOUNT (base);
element = dom_document_create_element (doc, "account", NULL);
+ if (self->id != NULL)
+ dom_element_set_attribute (element, "id", self->id);
if (self->username != NULL)
dom_element_set_attribute (element, "username", self->username);
+ if (self->name != NULL)
+ dom_element_set_attribute (element, "name", self->name);
/* Don't save the token in the configuration file if the keyring is
* available. */
@@ -94,7 +234,7 @@ oauth_account_create_element (DomDomizable *base,
}
-void
+static void
oauth_account_load_from_element (DomDomizable *base,
DomElement *element)
{
@@ -102,9 +242,13 @@ oauth_account_load_from_element (DomDomizable *base,
self = OAUTH_ACCOUNT (base);
- oauth_account_set_username (self, dom_element_get_attribute (element, "username"));
- oauth_account_set_token (self, dom_element_get_attribute (element, "token"));
- self->is_default = (g_strcmp0 (dom_element_get_attribute (element, "default"), "1") == 0);
+ g_object_set (self,
+ "id", dom_element_get_attribute (element, "id"),
+ "username", dom_element_get_attribute (element, "username"),
+ "name", dom_element_get_attribute (element, "name"),
+ "token", dom_element_get_attribute (element, "token"),
+ "is-default", (g_strcmp0 (dom_element_get_attribute (element, "default"), "1") == 0),
+ NULL);
}
@@ -119,7 +263,12 @@ oauth_account_dom_domizable_interface_init (DomDomizableInterface *iface)
static void
oauth_account_init (OAuthAccount *self)
{
- /* void */
+ self->id = NULL;
+ self->username = NULL;
+ self->name = NULL;
+ self->token = NULL;
+ self->token_secret = NULL;
+ self->is_default = FALSE;
}
@@ -164,6 +313,10 @@ oauth_account_cmp (OAuthAccount *a,
return 1;
else if (b == NULL)
return -1;
- else
+ else if ((a->id != NULL) || (b->id != NULL))
+ return g_strcmp0 (a->id, b->id);
+ else if ((a->username != NULL) || (b->username != NULL))
return g_strcmp0 (a->username, b->username);
+ else
+ return g_strcmp0 (a->name, b->name);
}
diff --git a/extensions/oauth/oauth-account.h b/extensions/oauth/oauth-account.h
index ce6e57d..b3f04d8 100644
--- a/extensions/oauth/oauth-account.h
+++ b/extensions/oauth/oauth-account.h
@@ -43,7 +43,9 @@ struct _OAuthAccount {
GObject parent_instance;
OAuthAccountPrivate *priv;
+ char *id;
char *username;
+ char *name;
char *token;
char *token_secret;
gboolean is_default;
@@ -63,10 +65,6 @@ void oauth_account_set_token_secret (OAuthAccount *self,
const char *value);
int oauth_account_cmp (OAuthAccount *a,
OAuthAccount *b);
-DomElement * oauth_account_create_element (DomDomizable *base,
- DomDocument *doc);
-void oauth_account_load_from_element (DomDomizable *base,
- DomElement *element);
G_END_DECLS
diff --git a/extensions/oauth/oauth-authentication.c b/extensions/oauth/oauth-authentication.c
index 6315603..e3c52eb 100644
--- a/extensions/oauth/oauth-authentication.c
+++ b/extensions/oauth/oauth-authentication.c
@@ -30,6 +30,7 @@
#include "oauth-authentication.h"
+#define ACCOUNTS_FORMAT_VERSION "2.0"
#define TOKEN_SECRET_SEPARATOR ("::")
#define OAUTH_AUTHENTICATION_RESPONSE_CHOOSE_ACCOUNT 1
@@ -739,6 +740,9 @@ oauth_accounts_load_from_file (const char *service_name,
GError *error = NULL;
DomDocument *doc;
+ if (account_type == 0)
+ account_type = OAUTH_TYPE_ACCOUNT;
+
filename = g_strconcat (service_name, ".xml", NULL);
file = gth_user_dir_get_file_for_read (GTH_DIR_CONFIG, GTHUMB_DIR, "accounts", filename, NULL);
if (! _g_file_load_in_buffer (file, (void **) &buffer, &len, NULL, &error)) {
@@ -754,7 +758,10 @@ oauth_accounts_load_from_file (const char *service_name,
DomElement *node;
node = DOM_ELEMENT (doc)->first_child;
- if ((node != NULL) && (g_strcmp0 (node->tag_name, "accounts") == 0)) {
+ if ((node != NULL)
+ && (g_strcmp0 (node->tag_name, "accounts") == 0)
+ && (g_strcmp0 (dom_element_get_attribute (node, "version"), ACCOUNTS_FORMAT_VERSION) == 0))
+ {
DomElement *child;
for (child = node->first_child;
@@ -814,7 +821,9 @@ oauth_accounts_save_to_file (const char *service_name,
GFile *file;
doc = dom_document_new ();
- root = dom_document_create_element (doc, "accounts", NULL);
+ root = dom_document_create_element (doc, "accounts",
+ "version", ACCOUNTS_FORMAT_VERSION,
+ NULL);
dom_element_append_child (DOM_ELEMENT (doc), root);
for (scan = accounts; scan; scan = scan->next) {
OAuthAccount *account = scan->data;
diff --git a/extensions/oauth/oauth.h b/extensions/oauth/oauth.h
new file mode 100644
index 0000000..7db1151
--- /dev/null
+++ b/extensions/oauth/oauth.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2012 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef OAUTH_H
+#define OAUTH_H
+
+#include <extensions/oauth/oauth2-ask-authorization-dialog.h>
+#include <extensions/oauth/oauth-account.h>
+#include <extensions/oauth/oauth-account-chooser-dialog.h>
+#include <extensions/oauth/oauth-account-manager-dialog.h>
+#include <extensions/oauth/oauth-authentication.h>
+#include <extensions/oauth/oauth-connection.h>
+
+#endif /* OAUTH_H */
diff --git a/extensions/oauth/oauth2-ask-authorization-dialog.c b/extensions/oauth/oauth2-ask-authorization-dialog.c
index 0b2bfc8..e3fef64 100644
--- a/extensions/oauth/oauth2-ask-authorization-dialog.c
+++ b/extensions/oauth/oauth2-ask-authorization-dialog.c
@@ -113,7 +113,9 @@ oauth2_ask_authorization_dialog_new (const char *title,
{
OAuth2AskAuthorizationDialog *self;
- self = g_object_new (OAUTH2_TYPE_ASK_AUTHORIZATION_DIALOG, "title", title, NULL);
+ self = g_object_new (OAUTH2_TYPE_ASK_AUTHORIZATION_DIALOG,
+ "title", title,
+ NULL);
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (self->priv->view), uri);
return (GtkWidget *) self;
diff --git a/extensions/photobucket/photobucket-account.c b/extensions/photobucket/photobucket-account.c
index 7180f9e..db7bf75 100644
--- a/extensions/photobucket/photobucket-account.c
+++ b/extensions/photobucket/photobucket-account.c
@@ -66,7 +66,7 @@ photobucket_account_create_element (DomDomizable *base,
DomElement *element;
self = PHOTOBUCKET_ACCOUNT (base);
- element = oauth_account_create_element (DOM_DOMIZABLE (self), doc);
+ element = dom_domizable_create_element (DOM_DOMIZABLE (self), doc);
if (self->subdomain != NULL)
dom_element_set_attribute (element, "subdomain", self->subdomain);
@@ -104,7 +104,7 @@ photobucket_account_load_from_element (DomDomizable *base,
}
}
else if (g_str_equal (element->tag_name, "account")) {
- oauth_account_load_from_element (DOM_DOMIZABLE (self), element);
+ dom_domizable_load_from_element (DOM_DOMIZABLE (self), element);
photobucket_account_set_subdomain (self, dom_element_get_attribute (element, "subdomain"));
}
}
diff --git a/extensions/photobucket/photobucket-consumer.c b/extensions/photobucket/photobucket-consumer.c
index 9c8b97c..41cda6f 100644
--- a/extensions/photobucket/photobucket-consumer.c
+++ b/extensions/photobucket/photobucket-consumer.c
@@ -157,9 +157,12 @@ photobucket_get_access_token_response (OAuthConnection *self,
oauth_connection_set_token (self, token, token_secret);
account = photobucket_account_new ();
- oauth_account_set_username (account, username);
- oauth_account_set_token (account, token);
- oauth_account_set_token_secret (account, token_secret);
+ g_object_set (account,
+ "name", username,
+ "username", username,
+ "token", token,
+ "token-secret", token_secret,
+ 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]