[evolution-couchdb] Listen for changes on contacts database
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-couchdb] Listen for changes on contacts database
- Date: Mon, 31 Aug 2009 23:22:40 +0000 (UTC)
commit b9570409b0f4e5cae0bbcdf0e954f19cb3327c8d
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Tue Sep 1 01:22:22 2009 +0200
Listen for changes on contacts database
addressbook/e-book-backend-couchdb.c | 43 ++++++++++++++++++++++++++++++++++
1 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index 23fcce7..fbd5b9d 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -671,6 +671,40 @@ couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *con
return document;
}
+static void
+document_updated_cb (CouchDB *couchdb, const char *dbname, CouchDBDocument *document, gpointer user_data)
+{
+ char *vcard;
+ EContact *contact;
+ EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (user_data);
+
+ if (g_strcmp0 (dbname, couchdb_backend->dbname) != 0)
+ return;
+
+ vcard = vcard_from_couch_document (document);
+ if (!vcard)
+ return;
+
+ contact = e_contact_new_from_vcard (vcard);
+ if (contact != NULL) {
+ e_book_backend_notify_update (E_BOOK_BACKEND (couchdb_backend), contact);
+ g_object_unref (G_OBJECT (contact));
+ }
+
+ g_free (vcard);
+}
+
+static void
+document_deleted_cb (CouchDB *couchdb, const char *dbname, const char *docid, gpointer user_data)
+{
+ EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (user_data);
+
+ if (g_strcmp0 (dbname, couchdb_backend->dbname) != 0)
+ return;
+
+ e_book_backend_notify_remove (E_BOOK_BACKEND (couchdb_backend), docid);
+}
+
static GNOME_Evolution_Addressbook_CallStatus
e_book_backend_couchdb_load_source (EBookBackend *backend,
ESource *source,
@@ -773,6 +807,15 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
e_book_backend_set_is_loaded (backend, TRUE);
e_book_backend_set_is_writable (backend, TRUE);
+ /* Listen for changes on database */
+ g_signal_connect (G_OBJECT (couchdb_backend->couchdb), "document_created",
+ G_CALLBACK (document_updated_cb), couchdb_backend);
+ g_signal_connect (G_OBJECT (couchdb_backend->couchdb), "document_updated",
+ G_CALLBACK (document_updated_cb), couchdb_backend);
+ g_signal_connect (G_OBJECT (couchdb_backend->couchdb), "document_deleted",
+ G_CALLBACK (document_deleted_cb), couchdb_backend);
+ couchdb_listen_for_changes (couchdb_backend->couchdb, couchdb_backend->dbname);
+
return GNOME_Evolution_Addressbook_Success;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]