[evolution-couchdb] Adapt to CouchdbDatabase API in couchdb-glib
- From: Rodrigo Moya <rodrigo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-couchdb] Adapt to CouchdbDatabase API in couchdb-glib
- Date: Mon, 17 May 2010 15:39:06 +0000 (UTC)
commit 76eb752a6df1a294db3b833bbe44b1b9a15dd2cc
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Mon May 17 17:39:02 2010 +0200
Adapt to CouchdbDatabase API in couchdb-glib
addressbook/e-book-backend-couchdb.c | 128 ++++++++++++++++------------------
addressbook/e-book-backend-couchdb.h | 2 +-
2 files changed, 62 insertions(+), 68 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index 0d994cb..aecabd8 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -56,11 +56,11 @@ contact_from_couch_document (CouchdbDocument *document)
CouchdbStructField *app_annotations;
EContactName contact_name;
- if (!desktopcouch_document_is_contact (document))
+ if (!desktopcouch_document_is_contact (DESKTOPCOUCH_DOCUMENT (document)))
return NULL;
/* Check if the contact is marked for deletion */
- if ((app_annotations = desktopcouch_document_get_application_annotations (document))) {
+ if ((app_annotations = desktopcouch_document_get_application_annotations (DESKTOPCOUCH_DOCUMENT (document)))) {
CouchdbStructField *u1_annotations;
u1_annotations = couchdb_struct_field_get_struct_field (
@@ -87,11 +87,11 @@ contact_from_couch_document (CouchdbDocument *document)
e_contact_set (contact, E_CONTACT_UID, (const gpointer) couchdb_document_get_id (document));
- contact_name.family = desktopcouch_document_contact_get_last_name (document);
- contact_name.given = desktopcouch_document_contact_get_first_name (document);
- contact_name.additional = desktopcouch_document_contact_get_middle_name (document);
- contact_name.prefixes = desktopcouch_document_contact_get_title (document);
- contact_name.suffixes = desktopcouch_document_contact_get_suffix (document);
+ contact_name.family = desktopcouch_document_contact_get_last_name (DESKTOPCOUCH_DOCUMENT_CONTACT (document));
+ contact_name.given = desktopcouch_document_contact_get_first_name (DESKTOPCOUCH_DOCUMENT_CONTACT (document));
+ contact_name.additional = desktopcouch_document_contact_get_middle_name (DESKTOPCOUCH_DOCUMENT_CONTACT (document));
+ contact_name.prefixes = desktopcouch_document_contact_get_title (DESKTOPCOUCH_DOCUMENT_CONTACT (document));
+ contact_name.suffixes = desktopcouch_document_contact_get_suffix (DESKTOPCOUCH_DOCUMENT_CONTACT (document));
e_contact_set (contact, E_CONTACT_NAME, (const gpointer) &contact_name);
str = e_contact_name_to_string (&contact_name);
@@ -99,31 +99,31 @@ contact_from_couch_document (CouchdbDocument *document)
g_free (str);
e_contact_set (contact, E_CONTACT_NICKNAME,
- (const gpointer) desktopcouch_document_contact_get_nick_name (document));
+ (const gpointer) desktopcouch_document_contact_get_nick_name (DESKTOPCOUCH_DOCUMENT_CONTACT (document)));
e_contact_set (contact, E_CONTACT_SPOUSE,
- (const gpointer) desktopcouch_document_contact_get_spouse_name (document));
+ (const gpointer) desktopcouch_document_contact_get_spouse_name (DESKTOPCOUCH_DOCUMENT_CONTACT (document)));
e_contact_set (contact, E_CONTACT_ORG,
- (const gpointer) desktopcouch_document_contact_get_company (document));
+ (const gpointer) desktopcouch_document_contact_get_company (DESKTOPCOUCH_DOCUMENT_CONTACT (document)));
e_contact_set (contact, E_CONTACT_ORG_UNIT,
- (const gpointer) desktopcouch_document_contact_get_department (document));
+ (const gpointer) desktopcouch_document_contact_get_department (DESKTOPCOUCH_DOCUMENT_CONTACT (document)));
e_contact_set (contact, E_CONTACT_TITLE,
- (const gpointer) desktopcouch_document_contact_get_job_title (document));
+ (const gpointer) desktopcouch_document_contact_get_job_title (DESKTOPCOUCH_DOCUMENT_CONTACT (document)));
e_contact_set (contact, E_CONTACT_MANAGER,
- (const gpointer) desktopcouch_document_contact_get_manager_name (document));
+ (const gpointer) desktopcouch_document_contact_get_manager_name (DESKTOPCOUCH_DOCUMENT_CONTACT (document)));
e_contact_set (contact, E_CONTACT_ASSISTANT,
- (const gpointer) desktopcouch_document_contact_get_assistant_name (document));
+ (const gpointer) desktopcouch_document_contact_get_assistant_name (DESKTOPCOUCH_DOCUMENT_CONTACT (document)));
e_contact_set (contact, E_CONTACT_OFFICE,
- (const gpointer) desktopcouch_document_contact_get_office (document));
+ (const gpointer) desktopcouch_document_contact_get_office (DESKTOPCOUCH_DOCUMENT_CONTACT (document)));
e_contact_set (contact, E_CONTACT_CATEGORIES,
- (const gpointer) desktopcouch_document_contact_get_categories (document));
+ (const gpointer) desktopcouch_document_contact_get_categories (DESKTOPCOUCH_DOCUMENT_CONTACT (document)));
e_contact_set (contact, E_CONTACT_NOTE,
- (const gpointer) desktopcouch_document_contact_get_notes (document));
+ (const gpointer) desktopcouch_document_contact_get_notes (DESKTOPCOUCH_DOCUMENT_CONTACT (document)));
/* parse email addresses */
attr_list = NULL;
- list = desktopcouch_document_contact_get_email_addresses (document);
+ list = desktopcouch_document_contact_get_email_addresses (DESKTOPCOUCH_DOCUMENT_CONTACT (document));
while (list != NULL) {
const char *email_str, *description_str, *uuid_str;
EVCardAttribute *attr;
@@ -169,7 +169,7 @@ contact_from_couch_document (CouchdbDocument *document)
}
/* parse phone numbers */
- list = desktopcouch_document_contact_get_phone_numbers (document);
+ list = desktopcouch_document_contact_get_phone_numbers (DESKTOPCOUCH_DOCUMENT_CONTACT (document));
while (list != NULL) {
const char *phone_str, *description_str, *uuid_str;
EVCardAttribute *attr;
@@ -281,7 +281,7 @@ contact_from_couch_document (CouchdbDocument *document)
}
/* parse postal addresses */
- list = desktopcouch_document_contact_get_addresses (document);
+ list = desktopcouch_document_contact_get_addresses (DESKTOPCOUCH_DOCUMENT_CONTACT (document));
while (list != NULL) {
const char *description_str;
EContactAddress *contact_address;
@@ -314,7 +314,7 @@ contact_from_couch_document (CouchdbDocument *document)
}
/* parse URLs */
- list = desktopcouch_document_contact_get_urls (document);
+ list = desktopcouch_document_contact_get_urls (DESKTOPCOUCH_DOCUMENT_CONTACT (document));
while (list != NULL) {
const char *description_str, *address_str, *uuid_str;
EVCardAttribute *attr;
@@ -348,7 +348,7 @@ contact_from_couch_document (CouchdbDocument *document)
}
/* parse IM addresses */
- list = desktopcouch_document_contact_get_im_addresses (document);
+ list = desktopcouch_document_contact_get_im_addresses (DESKTOPCOUCH_DOCUMENT_CONTACT (document));
while (list != NULL) {
const char *address_str, *description_str, *protocol_str, *uuid_str;
EVCardAttribute *attr = NULL;
@@ -413,7 +413,7 @@ contact_from_couch_document (CouchdbDocument *document)
}
/* birth date */
- str = (char *) desktopcouch_document_contact_get_birth_date (document);
+ str = (char *) desktopcouch_document_contact_get_birth_date (DESKTOPCOUCH_DOCUMENT_CONTACT (document));
if (str && strlen (str) > 0) {
EContactDate *dt;
@@ -425,7 +425,7 @@ contact_from_couch_document (CouchdbDocument *document)
}
/* wedding date */
- str = (char *) desktopcouch_document_contact_get_wedding_date (document);
+ str = (char *) desktopcouch_document_contact_get_wedding_date (DESKTOPCOUCH_DOCUMENT_CONTACT (document));
if (str && strlen (str)) {
EContactDate *dt;
@@ -708,21 +708,21 @@ couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *con
GSList *list;
GList *attr_list, *al;
const char *str;
- CouchdbDocument *document;
+ DesktopcouchDocumentContact *document;
gint i;
CouchdbStructField *postal_address, *app_annotations;
EContactName *contact_name;
/* create the CouchDBDocument to put on the database */
- document = desktopcouch_document_contact_new (couchdb_backend->couchdb);
+ document = desktopcouch_document_contact_new ();
str = e_contact_get_const (contact, E_CONTACT_UID);
if (str)
- couchdb_document_set_id (document, str);
+ couchdb_document_set_id (COUCHDB_DOCUMENT (document), str);
str = e_vcard_attribute_get_value (e_vcard_get_attribute (E_VCARD (contact), COUCHDB_REVISION_PROP));
if (str)
- couchdb_document_set_revision (document, str);
+ couchdb_document_set_revision (COUCHDB_DOCUMENT (document), str);
contact_name = (EContactName *) e_contact_get (contact, E_CONTACT_NAME);
if (contact_name != NULL) {
@@ -916,21 +916,18 @@ couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *con
app_annotations = couchdb_struct_field_new ();
set_vcard_revision (app_annotations, contact);
- desktopcouch_document_set_application_annotations (document, app_annotations);
+ desktopcouch_document_set_application_annotations (DESKTOPCOUCH_DOCUMENT (document), app_annotations);
couchdb_struct_field_unref (app_annotations);
- return document;
+ return COUCHDB_DOCUMENT (document);
}
static void
-document_updated_cb (CouchdbSession *couchdb, const char *dbname, CouchdbDocument *document, gpointer user_data)
+document_updated_cb (CouchdbDatabase *database, CouchdbDocument *document, gpointer user_data)
{
EContact *contact;
EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (user_data);
- if (g_strcmp0 (dbname, couchdb_backend->dbname) != 0)
- return;
-
contact = contact_from_couch_document (document);
if (!contact)
return;
@@ -944,13 +941,10 @@ document_updated_cb (CouchdbSession *couchdb, const char *dbname, CouchdbDocumen
}
static void
-document_deleted_cb (CouchdbSession *couchdb, const char *dbname, const char *docid, gpointer user_data)
+document_deleted_cb (CouchdbDatabase *database, 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);
/* Remove the contact from the cache */
@@ -964,7 +958,6 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
{
gchar *uri;
const gchar *property;
- CouchdbDatabaseInfo *db_info;
GError *error = NULL;
GSList *doc_list, *sl;
EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
@@ -973,13 +966,12 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
if (couchdb_backend->couchdb != NULL)
g_object_unref (G_OBJECT (couchdb_backend->couchdb));
- if (couchdb_backend->dbname != NULL)
- g_free (couchdb_backend->dbname);
+ if (couchdb_backend->database != NULL)
+ g_object_unref (G_OBJECT (couchdb_backend->database));
if (couchdb_backend->cache != NULL)
g_object_unref (G_OBJECT (couchdb_backend->cache));
/* create CouchDB main object */
- couchdb_backend->dbname = g_strdup ("contacts");
couchdb_backend->using_desktopcouch = FALSE;
property = e_source_get_property (source, "couchdb_instance");
@@ -1006,10 +998,10 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
/* check if only_if_exists */
error = NULL;
- db_info = couchdb_session_get_database_info (couchdb_backend->couchdb,
- couchdb_backend->dbname,
- &error);
- if (!db_info) {
+ couchdb_backend->database = couchdb_session_get_database (couchdb_backend->couchdb,
+ "contacts",
+ &error);
+ if (couchdb_backend->database != NULL) {
if (error) {
g_warning ("Could not get CouchDB database info: %s", error->message);
g_error_free (error);
@@ -1021,15 +1013,18 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
/* if it does not exist, create it */
error = NULL;
if (!couchdb_session_create_database (couchdb_backend->couchdb,
- couchdb_backend->dbname,
+ "contacts",
&error)) {
g_warning ("Could not create 'contacts' database: %s", error->message);
g_error_free (error);
return GNOME_Evolution_Addressbook_PermissionDenied;
}
- } else
- couchdb_database_info_unref (db_info);
+
+ couchdb_backend->database = couchdb_session_get_database (couchdb_backend->couchdb,
+ "contacts",
+ &error);
+ }
/* Create cache */
uri = e_source_get_uri (source);
@@ -1039,9 +1034,8 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
/* Populate the cache */
e_file_cache_clean (E_FILE_CACHE (couchdb_backend->cache));
error = NULL;
- doc_list = couchdb_session_get_all_documents (couchdb_backend->couchdb,
- couchdb_backend->dbname,
- &error);
+ doc_list = couchdb_database_get_all_documents (couchdb_backend->database,
+ &error);
for (sl = doc_list; sl != NULL; sl = sl->next) {
EContact *contact;
CouchdbDocument *document = COUCHDB_DOCUMENT (sl->data);
@@ -1053,16 +1047,16 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
}
}
- couchdb_session_free_document_list (doc_list);
+ couchdb_database_free_document_list (doc_list);
/* Listen for changes on database */
- g_signal_connect (G_OBJECT (couchdb_backend->couchdb), "document_created",
+ g_signal_connect (G_OBJECT (couchdb_backend->database), "document_created",
G_CALLBACK (document_updated_cb), couchdb_backend);
- g_signal_connect (G_OBJECT (couchdb_backend->couchdb), "document_updated",
+ g_signal_connect (G_OBJECT (couchdb_backend->database), "document_updated",
G_CALLBACK (document_updated_cb), couchdb_backend);
- g_signal_connect (G_OBJECT (couchdb_backend->couchdb), "document_deleted",
+ g_signal_connect (G_OBJECT (couchdb_backend->database), "document_deleted",
G_CALLBACK (document_deleted_cb), couchdb_backend);
- couchdb_session_listen_for_changes (couchdb_backend->couchdb, couchdb_backend->dbname);
+ couchdb_database_listen_for_changes (couchdb_backend->database);
e_book_backend_set_is_loaded (backend, TRUE);
e_book_backend_set_is_writable (backend, TRUE);
@@ -1097,7 +1091,7 @@ put_document (EBookBackendCouchDB *couchdb_backend, CouchdbDocument *document)
{
GError *error = NULL;
- if (couchdb_document_put (document, couchdb_backend->dbname, &error)) {
+ if (couchdb_database_put_document (couchdb_backend->database, document, &error)) {
EContact *new_contact;
/* couchdb_document_put sets the ID for new documents, so need to send that back */
@@ -1166,14 +1160,14 @@ e_book_backend_couchdb_remove_contacts (EBookBackend *backend,
GError *error = NULL;
const gchar *uid = (const gchar *) l->data;
- document = couchdb_document_get (couchdb_backend->couchdb, couchdb_backend->dbname, uid, &error);
+ document = couchdb_database_get_document (couchdb_backend->database, uid, &error);
if (document) {
if (couchdb_backend->using_desktopcouch) {
CouchdbStructField *app_annotations, *u1_annotations, *private_annotations;
/* For desktopcouch, we don't remove contacts, we just
* mark them as deleted */
- app_annotations = desktopcouch_document_get_application_annotations (document);
+ app_annotations = desktopcouch_document_get_application_annotations (DESKTOPCOUCH_DOCUMENT (document));
if (app_annotations == NULL)
app_annotations = couchdb_struct_field_new ();
@@ -1188,10 +1182,10 @@ e_book_backend_couchdb_remove_contacts (EBookBackend *backend,
couchdb_struct_field_set_boolean_field (private_annotations, "deleted", TRUE);
couchdb_struct_field_set_struct_field (u1_annotations, "private_application_annotations", private_annotations);
couchdb_struct_field_set_struct_field (app_annotations, "Ubuntu One", u1_annotations);
- desktopcouch_document_set_application_annotations (document, app_annotations);
+ desktopcouch_document_set_application_annotations (DESKTOPCOUCH_DOCUMENT (document), app_annotations);
/* Now put the new revision of the document */
- if (couchdb_document_put (document, couchdb_backend->dbname, &error)) {
+ if (couchdb_database_put_document (couchdb_backend->database, document, &error)) {
deleted_ids = g_list_append (deleted_ids, (gpointer) uid);
e_book_backend_cache_remove_contact (couchdb_backend->cache, uid);
} else {
@@ -1207,7 +1201,7 @@ e_book_backend_couchdb_remove_contacts (EBookBackend *backend,
couchdb_struct_field_unref (u1_annotations);
couchdb_struct_field_unref (private_annotations);
} else {
- if (couchdb_document_delete (document, &error)) {
+ if (couchdb_database_delete_document (couchdb_backend->database, document, &error)) {
deleted_ids = g_list_append (deleted_ids, (gpointer) uid);
e_book_backend_cache_remove_contact (couchdb_backend->cache, uid);
} else {
@@ -1528,9 +1522,9 @@ e_book_backend_couchdb_dispose (GObject *object)
couchdb_backend->cache = NULL;
}
- if (couchdb_backend->dbname) {
- g_free (couchdb_backend->dbname);
- couchdb_backend->dbname = NULL;
+ if (couchdb_backend->database) {
+ g_object_unref (G_OBJECT (couchdb_backend->database));
+ couchdb_backend->database = NULL;
}
}
@@ -1568,6 +1562,6 @@ static void
e_book_backend_couchdb_init (EBookBackendCouchDB *backend)
{
backend->couchdb = NULL;
- backend->dbname = NULL;
+ backend->database = NULL;
backend->cache = NULL;
}
diff --git a/addressbook/e-book-backend-couchdb.h b/addressbook/e-book-backend-couchdb.h
index 4e1966b..54e4589 100644
--- a/addressbook/e-book-backend-couchdb.h
+++ b/addressbook/e-book-backend-couchdb.h
@@ -39,8 +39,8 @@ typedef struct {
EBookBackend parent_object;
CouchdbSession *couchdb;
+ CouchdbDatabase *database;
EBookBackendCache *cache;
- char *dbname;
gboolean using_desktopcouch;
} EBookBackendCouchDB;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]