[evolution-couchdb] Use the couchdb instance as specified on the ESource
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-couchdb] Use the couchdb instance as specified on the ESource
- Date: Tue, 4 Aug 2009 14:57:58 +0000 (UTC)
commit 2cbc0b6c6ff85707c6d0790d6005689682e0db22
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Tue Aug 4 16:57:50 2009 +0200
Use the couchdb instance as specified on the ESource
addressbook/e-book-backend-couchdb.c | 49 +++++++++++++++++++++++++++++++--
configure.ac | 2 +-
2 files changed, 47 insertions(+), 4 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index f24e8e0..ecdc5f1 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -24,6 +24,7 @@
#include "e-book-backend-couchdb.h"
#include <libedata-book/e-data-book.h>
#include <libedata-book/e-data-book-view.h>
+#include <dbus/dbus-glib.h>
G_DEFINE_TYPE (EBookBackendCouchDB, e_book_backend_couchdb, E_TYPE_BOOK_BACKEND);
@@ -164,7 +165,7 @@ couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *con
GList *attr_list, *al;
const char *str;
CouchDBDocument *document;
- EContactAddress *contact_address;
+ const EContactAddress *contact_address;
/* create the CouchDBDocument to put on the database */
document = couchdb_document_new (couchdb_backend->couchdb);
@@ -329,6 +330,7 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
gboolean only_if_exists)
{
gchar *uri;
+ const gchar *property;
CouchDBDatabaseInfo *db_info;
GError *error = NULL;
EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
@@ -341,11 +343,52 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
g_free (couchdb_backend->dbname);
/* create CouchDB main object */
- uri = e_source_get_uri (source);
couchdb_backend->dbname = g_strdup ("contacts");
- if (! (couchdb_backend->couchdb = couchdb_new (NULL /* FIXME: uri */)))
+ 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 ("DBus error: %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));
+ g_object_unref (G_OBJECT (bus));
+
+ if (success)
+ uri = g_strdup_printf ("http://localhost:%d", port);
+ else
+ return GNOME_Evolution_Addressbook_NoSuchBook;
+
+ } 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://localhost:5984");
+
+ if (! (couchdb_backend->couchdb = couchdb_new (uri))) {
+ g_free (uri);
return GNOME_Evolution_Addressbook_OtherError;
+ }
+
g_free (uri);
/* check if only_if_exists */
diff --git a/configure.ac b/configure.ac
index b43a600..7aed01e 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.2 libebook-1.2 libedata-book-1.2)
+PKG_CHECK_MODULES(EVOLUTION, glib-2.0 couchdb-glib-1.0 >= 0.2 libebook-1.2 libedata-book-1.2 dbus-glib-1)
AC_SUBST(EVOLUTION_CFLAGS)
AC_SUBST(EVOLUTION_LIBS)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]