[evolution-couchdb] Use desktopcouch-glib instead of getting the port and OAuth credentials manually
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-couchdb] Use desktopcouch-glib instead of getting the port and OAuth credentials manually
- Date: Mon, 11 Jan 2010 17:12:02 +0000 (UTC)
commit 89567849569df873cee771f2921b9c7a026123f7
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Mon Jan 11 18:11:45 2010 +0100
Use desktopcouch-glib instead of getting the port and OAuth credentials manually
addressbook/e-book-backend-couchdb.c | 102 ++++------------------------------
addressbook/e-book-backend-couchdb.h | 1 +
configure.ac | 2 +-
3 files changed, 13 insertions(+), 92 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index ca3b1f1..d1531d2 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -896,8 +896,6 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
const gchar *property;
CouchdbDatabaseInfo *db_info;
GError *error = NULL;
- gboolean enable_oauth = FALSE;
- char *oauth_c_key = NULL, *oauth_c_secret = NULL, *oauth_t_key = NULL, *oauth_t_secret = NULL;
EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
g_return_val_if_fail (E_IS_BOOK_BACKEND_COUCHDB (couchdb_backend), GNOME_Evolution_Addressbook_OtherError);
@@ -913,104 +911,26 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
property = e_source_get_property (source, "couchdb_instance");
if (g_strcmp0 (property, "user") == 0) {
- DBusGConnection *bus;
- DBusGProxy *proxy;
- gint port;
- gboolean success;
-
- /* Get the port via the org.desktopcouch.CouchDB interface */
- error = NULL;
- bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (error) {
- g_warning ("Couldn't get session bus: %s", error->message);
- g_error_free (error);
-
- return GNOME_Evolution_Addressbook_NoSuchBook;
- }
-
- proxy = dbus_g_proxy_new_for_name (bus,
- "org.desktopcouch.CouchDB",
- "/",
- "org.desktopcouch.CouchDB");
-
- error = NULL;
- success = dbus_g_proxy_call (proxy, "getPort", &error, G_TYPE_INVALID,
- G_TYPE_INT, &port, G_TYPE_INVALID);
-
- /* Free memory */
- g_object_unref (G_OBJECT (proxy));
- dbus_g_connection_unref (bus);
-
- if (success) {
- GnomeKeyringAttributeList *attrs;
- GnomeKeyringResult result;
- GList *items_found;
-
- uri = g_strdup_printf ("http://127.0.0.1:%d", port);
-
- /* Get OAuth tokens from GnomeKeyring */
- attrs = gnome_keyring_attribute_list_new ();
- gnome_keyring_attribute_list_append_string (attrs, "desktopcouch", "oauth");
-
- result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
- attrs, &items_found);
- if (result == GNOME_KEYRING_RESULT_OK && items_found != NULL) {
- gchar **items;
- GnomeKeyringFound *first_item = (GnomeKeyringFound *) items_found->data;
-
- items = g_strsplit (first_item->secret, ":", 4);
- if (items) {
- oauth_c_key = g_strdup (items[0]);
- oauth_c_secret = g_strdup (items[1]);
- oauth_t_key = g_strdup (items[2]);
- oauth_t_secret = g_strdup (items[3]);
- g_strfreev (items);
-
- enable_oauth = TRUE;
- }
-
- gnome_keyring_found_list_free (items_found);
- } else {
- g_warning ("Could not get OAuth tokens from keyring: %s",
- gnome_keyring_result_to_message (result));
- }
-
- /* Free memory */
- gnome_keyring_attribute_list_free (attrs);
- } else {
- g_warning ("Couldn't get port for desktopcouch: %s", error->message);
- g_error_free (error);
-
+ if (! (couchdb_backend->couchdb = COUCHDB_SESSION (desktopcouch_session_new ()))) {
+ g_warning ("Could not create DesktopcouchSession object");
return GNOME_Evolution_Addressbook_NoSuchBook;
}
couchdb_backend->using_desktopcouch = TRUE;
+ } else {
+ if (g_strcmp0 (property, "remote") == 0)
+ uri = g_strdup_printf ("http://%s", e_source_get_property (source, "couchdb_remote_server"));
+ else
+ uri = g_strdup ("http://127.0.0.1:5984");
- } else if (g_strcmp0 (property, "remote") == 0)
- uri = g_strdup_printf ("http://%s", e_source_get_property (source, "couchdb_remote_server"));
- else
- uri = g_strdup ("http://127.0.0.1:5984");
+ if (! (couchdb_backend->couchdb = couchdb_session_new (uri))) {
+ g_free (uri);
+ return GNOME_Evolution_Addressbook_OtherError;
+ }
- if (! (couchdb_backend->couchdb = couchdb_session_new (uri))) {
g_free (uri);
- return GNOME_Evolution_Addressbook_OtherError;
}
- if (enable_oauth) {
- couchdb_session_enable_oauth (couchdb_backend->couchdb,
- oauth_c_key,
- oauth_c_secret,
- oauth_t_key,
- oauth_t_secret);
-
- g_free (oauth_c_key);
- g_free (oauth_c_secret);
- g_free (oauth_t_key);
- g_free (oauth_t_secret);
- }
-
- g_free (uri);
-
/* check if only_if_exists */
error = NULL;
db_info = couchdb_session_get_database_info (couchdb_backend->couchdb,
diff --git a/addressbook/e-book-backend-couchdb.h b/addressbook/e-book-backend-couchdb.h
index 78296ac..a69db3d 100644
--- a/addressbook/e-book-backend-couchdb.h
+++ b/addressbook/e-book-backend-couchdb.h
@@ -25,6 +25,7 @@
#include <couchdb-glib.h>
#include <couchdb-document-contact.h>
+#include <desktopcouch-glib.h>
#include <libedata-book/e-book-backend.h>
#define E_TYPE_BOOK_BACKEND_COUCHDB (e_book_backend_couchdb_get_type ())
diff --git a/configure.ac b/configure.ac
index 6851b63..0e4ad06 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,7 +34,7 @@ localedir='$(prefix)/$(DATADIRNAME)/locale'
AC_SUBST(localedir)
dnl Check for dependencies
-PKG_CHECK_MODULES(EVOLUTION, glib-2.0 couchdb-glib-1.0 >= 0.5.99 libebook-1.2 libedata-book-1.2 dbus-glib-1 gnome-keyring-1)
+PKG_CHECK_MODULES(EVOLUTION, glib-2.0 couchdb-glib-1.0 >= 0.5.99 desktopcouch-glib-1.0 >= 0.5.99 libebook-1.2 libedata-book-1.2 dbus-glib-1 gnome-keyring-1)
AC_SUBST(EVOLUTION_CFLAGS)
AC_SUBST(EVOLUTION_LIBS)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]