[evolution-couchdb] Added e_book_backend_couchdb_remove_contacts method



commit 257778ad26299ee789a821fd76bdc29fe7a2a841
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Wed Jun 24 17:24:52 2009 +0200

    Added e_book_backend_couchdb_remove_contacts method

 addressbook/e-book-backend-couchdb.c |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index 4b79713..be77c29 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -167,6 +167,10 @@ couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *con
 	/* create the CouchDBDocument to put on the database */
 	document = couchdb_document_new (couchdb_backend->couchdb);
 
+	str = e_contact_get_const (contact, E_CONTACT_UID);
+	if (str)
+		couchdb_document_set_id (document, str);
+
 	couchdb_document_contact_set_first_name (document, (const char *) e_contact_get_const (contact, E_CONTACT_GIVEN_NAME));
 	couchdb_document_contact_set_last_name (document, (const char *) e_contact_get_const (contact, E_CONTACT_FAMILY_NAME));
 
@@ -345,8 +349,28 @@ e_book_backend_couchdb_remove_contacts (EBookBackend *backend,
 					guint32 opid,
 					GList *id_list)
 {
-	/* FIXME */
-	e_data_book_respond_remove_contacts (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
+	GList *l, *deleted_ids = NULL;
+	EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
+
+	for (l = id_list; l != NULL; l = l->next) {
+		CouchDBDocument *document;
+		GError *error = NULL;
+		const gchar *uid = (const gchar *) id_list->data;
+
+		document = couchdb_document_get (couchdb_backend->couchdb, couchdb_backend->dbname, uid, &error);
+		if (document) {
+			if (couchdb_document_delete (document, &error))
+				deleted_ids = g_list_append (deleted_ids, (gpointer) uid);
+		}
+	}
+
+	if (deleted_ids) {
+		e_data_book_respond_remove_contacts (book, opid,
+						     GNOME_Evolution_Addressbook_Success, deleted_ids);
+		g_list_free (deleted_ids);
+	} else
+		e_data_book_respond_remove_contacts (book, opid,
+						     GNOME_Evolution_Addressbook_OtherError, NULL);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]