Merge lp:~rodrigo-moya/evolution-couchdb/use-esource-properties into lp:evolution-couchdb

Proposed by Rodrigo Moya
Status: Merged
Approved by: Elliot Murphy
Approved revision: 46
Merge reported by: Rodrigo Moya
Merged at revision: not available
Proposed branch: lp:~rodrigo-moya/evolution-couchdb/use-esource-properties
Merge into: lp:evolution-couchdb
Diff against target: None lines
To merge this branch: bzr merge lp:~rodrigo-moya/evolution-couchdb/use-esource-properties
Reviewer Review Type Date Requested Status
Elliot Murphy (community) Approve
dobey (community) Approve
Review via email: mp+9520@code.launchpad.net
To post a comment you must log in.
Revision history for this message
dobey (dobey) :
review: Approve
46. By Rodrigo Moya

Use 'error' correctly'

Revision history for this message
Elliot Murphy (statik) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addressbook/e-book-backend-couchdb.c'
2--- addressbook/e-book-backend-couchdb.c 2009-07-25 21:39:45 +0000
3+++ addressbook/e-book-backend-couchdb.c 2009-07-31 15:49:02 +0000
4@@ -24,6 +24,7 @@
5 #include "e-book-backend-couchdb.h"
6 #include <libedata-book/e-data-book.h>
7 #include <libedata-book/e-data-book-view.h>
8+#include <dbus/dbus-glib.h>
9
10 G_DEFINE_TYPE (EBookBackendCouchDB, e_book_backend_couchdb, E_TYPE_BOOK_BACKEND);
11
12@@ -164,7 +165,7 @@
13 GList *attr_list, *al;
14 const char *str;
15 CouchDBDocument *document;
16- EContactAddress *contact_address;
17+ const EContactAddress *contact_address;
18
19 /* create the CouchDBDocument to put on the database */
20 document = couchdb_document_new (couchdb_backend->couchdb);
21@@ -329,6 +330,7 @@
22 gboolean only_if_exists)
23 {
24 gchar *uri;
25+ const gchar *property;
26 CouchDBDatabaseInfo *db_info;
27 GError *error = NULL;
28 EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
29@@ -341,11 +343,52 @@
30 g_free (couchdb_backend->dbname);
31
32 /* create CouchDB main object */
33- uri = e_source_get_uri (source);
34 couchdb_backend->dbname = g_strdup ("contacts");
35
36- if (! (couchdb_backend->couchdb = couchdb_new (NULL /* FIXME: uri */)))
37+ property = e_source_get_property (source, "couchdb_instance");
38+ if (g_strcmp0 (property, "user") == 0) {
39+ DBusGConnection *bus;
40+ DBusGProxy *proxy;
41+ gint port;
42+ gboolean success;
43+
44+ /* Get the port via the org.desktopcouch.CouchDB interface */
45+ error = NULL;
46+ bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
47+ if (&error) {
48+ g_warning ("DBus error: %s", error->message);
49+ g_error_free (error);
50+ return GNOME_Evolution_Addressbook_NoSuchBook;
51+ }
52+
53+ proxy = dbus_g_proxy_new_for_name (bus,
54+ "org.desktopcouch.CouchDB",
55+ "/",
56+ "org.desktopcouch.CouchDB");
57+
58+ error = NULL;
59+ success = dbus_g_proxy_call (proxy, "getPort", &error, G_TYPE_INVALID,
60+ &port, G_TYPE_INVALID);
61+
62+ /* Free memory */
63+ g_object_unref (G_OBJECT (proxy));
64+ g_object_unref (G_OBJECT (bus));
65+
66+ if (success)
67+ uri = g_strdup_printf ("http://localhost:%d", port);
68+ else
69+ return GNOME_Evolution_Addressbook_NoSuchBook;
70+
71+ } else if (g_strcmp0 (property, "remote") == 0)
72+ uri = g_strdup_printf ("http://%s", e_source_get_property (source, "couchdb_remote_server"));
73+ else
74+ uri = g_strdup ("http://localhost:5984");
75+
76+ if (! (couchdb_backend->couchdb = couchdb_new (uri))) {
77+ g_free (uri);
78 return GNOME_Evolution_Addressbook_OtherError;
79+ }
80+
81 g_free (uri);
82
83 /* check if only_if_exists */
84
85=== modified file 'configure.ac'
86--- configure.ac 2009-07-20 14:24:39 +0000
87+++ configure.ac 2009-07-31 15:49:02 +0000
88@@ -34,7 +34,7 @@
89 AC_SUBST(localedir)
90
91 dnl Check for dependencies
92-PKG_CHECK_MODULES(EVOLUTION, glib-2.0 couchdb-glib-1.0 >= 0.2 libebook-1.2 libedata-book-1.2)
93+PKG_CHECK_MODULES(EVOLUTION, glib-2.0 couchdb-glib-1.0 >= 0.2 libebook-1.2 libedata-book-1.2 dbus-glib-1)
94 AC_SUBST(EVOLUTION_CFLAGS)
95 AC_SUBST(EVOLUTION_LIBS)
96

Subscribers

People subscribed via source and target branches