[evolution-couchdb] Port to e-d-s 2.31.0 API
- From: Rodrigo Moya <rodrigo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-couchdb] Port to e-d-s 2.31.0 API
- Date: Fri, 15 Oct 2010 10:24:10 +0000 (UTC)
commit 2361d590b3fb60e6ba4f6af449e43b7158c9fee5
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Fri Oct 15 12:23:51 2010 +0200
Port to e-d-s 2.31.0 API
addressbook/e-book-backend-couchdb.c | 203 ++++++++++++++++++++++++++-------
1 files changed, 160 insertions(+), 43 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index 3d2be8a..87fd4f8 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -20,8 +20,11 @@
* Authors: Rodrigo Moya <rodrigo moya canonical com>
*/
+#include <config.h>
#include <string.h>
+#include <glib/gi18n-lib.h>
#include "e-book-backend-couchdb.h"
+#include <libedataserver/eds-version.h>
#include <libedata-book/e-book-backend-sexp.h>
#include <libedata-book/e-data-book.h>
#include <libedata-book/e-data-book-view.h>
@@ -33,6 +36,21 @@
G_DEFINE_TYPE (EBookBackendCouchDB, e_book_backend_couchdb, E_TYPE_BOOK_BACKEND);
+#if EDS_CHECK_VERSION(2, 31, 0)
+#define ERROR_QUARK e_book_backend_couchdb_error_quark ()
+
+static GQuark
+e_book_backend_couchdb_error_quark (void)
+{
+ static GQuark error;
+
+ if (!error)
+ error = g_quark_from_static_string ("evolution_couchdb");
+
+ return error;
+}
+#endif
+
static void
get_current_time (gchar time_string[100])
{
@@ -956,10 +974,18 @@ document_deleted_cb (CouchdbDatabase *database, const char *docid, gpointer user
e_book_backend_notify_remove (E_BOOK_BACKEND (couchdb_backend), docid);
}
+#if EDS_CHECK_VERSION(2, 31, 0)
+static void
+e_book_backend_couchdb_load_source (EBookBackend *backend,
+ ESource *source,
+ gboolean only_if_exists,
+ GError **ret_error)
+#else
static GNOME_Evolution_Addressbook_CallStatus
e_book_backend_couchdb_load_source (EBookBackend *backend,
ESource *source,
gboolean only_if_exists)
+#endif
{
gchar *uri;
const gchar *property;
@@ -967,7 +993,11 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
GSList *doc_list, *sl;
EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
+#if EDS_CHECK_VERSION(2, 31, 0)
+ g_return_if_fail (E_IS_BOOK_BACKEND_COUCHDB (couchdb_backend));
+#else
g_return_val_if_fail (E_IS_BOOK_BACKEND_COUCHDB (couchdb_backend), GNOME_Evolution_Addressbook_OtherError);
+#endif
if (couchdb_backend->couchdb != NULL)
g_object_unref (G_OBJECT (couchdb_backend->couchdb));
@@ -986,8 +1016,13 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
property = e_source_get_property (source, "couchdb_instance");
if (g_strcmp0 (property, "user") == 0) {
if (! (couchdb_backend->couchdb = COUCHDB_SESSION (desktopcouch_session_new ()))) {
+#if EDS_CHECK_VERSION(2, 31, 0)
+ g_set_error (ret_error, ERROR_QUARK, 100, _("Could not create DesktopcouchSession object"));
+ return;
+#else
g_warning ("Could not create DesktopcouchSession object");
return GNOME_Evolution_Addressbook_NoSuchBook;
+#endif
}
couchdb_backend->using_desktopcouch = TRUE;
@@ -999,7 +1034,12 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
if (! (couchdb_backend->couchdb = couchdb_session_new (uri))) {
g_free (uri);
+#if EDS_CHECK_VERSION(2, 31, 0)
+ g_set_error (ret_error, ERROR_QUARK, 100, _("Could not create CouchdbSession object"));
+ return;
+#else
return GNOME_Evolution_Addressbook_NoSuchBook;
+#endif
}
g_free (uri);
@@ -1016,18 +1056,33 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
g_error_free (error);
}
- if (only_if_exists)
+ if (only_if_exists) {
+#if EDS_CHECK_VERSION(2, 31, 0)
+ g_set_error (ret_error, ERROR_QUARK, error->code, "%s: %s",
+ _("Could not get CouchDB database info"), error->message);
+ return;
+#else
return GNOME_Evolution_Addressbook_NoSuchBook;
+#endif
+ }
/* if it does not exist, create it */
error = NULL;
if (!couchdb_session_create_database (couchdb_backend->couchdb,
"contacts",
&error)) {
+#if EDS_CHECK_VERSION(2, 31, 0)
+ g_set_error (ret_error, ERROR_QUARK, error->code, "%s: %s",
+ _("Could not create 'contacts' database"), error->message);
+#endif
g_warning ("Could not create 'contacts' database: %s", error->message);
g_error_free (error);
+#if EDS_CHECK_VERSION(2, 31, 0)
+ return;
+#else
return GNOME_Evolution_Addressbook_PermissionDenied;
+#endif
}
couchdb_backend->database = couchdb_session_get_database (couchdb_backend->couchdb,
@@ -1049,7 +1104,7 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
EContact *contact;
CouchdbDocument *document = COUCHDB_DOCUMENT (sl->data);
- contact = contact_from_couch_document (document);
+ contact = contact_from_couch_document (couchdb_backend, document);
if (contact != NULL) {
e_book_backend_cache_add_contact (couchdb_backend->cache, contact);
g_object_unref (G_OBJECT (contact));
@@ -1070,7 +1125,9 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
e_book_backend_set_is_loaded (backend, TRUE);
e_book_backend_set_is_writable (backend, TRUE);
+#if !EDS_CHECK_VERSION(2, 31, 0)
return GNOME_Evolution_Addressbook_Success;
+#endif
}
static void
@@ -1088,7 +1145,11 @@ e_book_backend_couchdb_remove (EBookBackend *backend, EDataBook *book, guint32 o
/* We don't remove data from CouchDB, since it would affect other apps,
so just report success */
+#if EDS_CHECK_VERSION(2, 31, 0)
+ e_data_book_respond_remove (book, opid, NULL);
+#else
e_data_book_respond_remove (book, opid, GNOME_Evolution_Addressbook_Success);
+#endif
}
static char *
@@ -1098,11 +1159,11 @@ e_book_backend_couchdb_get_static_capabilities (EBookBackend *backend)
}
static EContact *
-put_document (EBookBackendCouchDB *couchdb_backend, CouchdbDocument *document)
+put_document (EBookBackendCouchDB *couchdb_backend, CouchdbDocument *document, GError **error)
{
- GError *error = NULL;
+ *error = NULL;
- if (couchdb_database_put_document (couchdb_backend->database, document, &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 */
@@ -1114,8 +1175,7 @@ put_document (EBookBackendCouchDB *couchdb_backend, CouchdbDocument *document)
return new_contact;
} else {
if (error != NULL) {
- g_warning ("Could not PUT document: %s\n", error->message);
- g_error_free (error);
+ g_warning ("Could not PUT document: %s\n", ((GError *) error)->message);
}
}
@@ -1130,27 +1190,27 @@ e_book_backend_couchdb_create_contact (EBookBackend *backend,
{
EContact *contact, *new_contact;
CouchdbDocument *document;
+ GError *error = NULL;
EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
contact = e_contact_new_from_vcard (vcard);
- if (!contact) {
- e_data_book_respond_create (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
- return;
- }
-
document = couch_document_from_contact (couchdb_backend, contact);
- if (!document) {
- e_data_book_respond_create (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
- g_object_unref (G_OBJECT (contact));
- return;
- }
/* save the contact into the DB */
- if ((new_contact = put_document (couchdb_backend, document)) != NULL) {
+ if ((new_contact = put_document (couchdb_backend, document, &error)) != NULL) {
+#if EDS_CHECK_VERSION(2, 31, 0)
+ e_data_book_respond_create (book, opid, NULL, new_contact);
+#else
e_data_book_respond_create (book, opid, GNOME_Evolution_Addressbook_Success, new_contact);
+#endif
g_object_unref (new_contact);
- } else
+ } else {
+#if EDS_CHECK_VERSION(2, 31, 0)
+ e_data_book_respond_create (book, opid, error, NULL);
+#else
e_data_book_respond_create (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
+#endif
+ }
/* free memory */
g_object_unref (G_OBJECT (contact));
@@ -1164,6 +1224,7 @@ e_book_backend_couchdb_remove_contacts (EBookBackend *backend,
GList *id_list)
{
GList *l, *deleted_ids = NULL;
+ GError *error = NULL;
EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
for (l = id_list; l != NULL; l = l->next) {
@@ -1200,11 +1261,12 @@ e_book_backend_couchdb_remove_contacts (EBookBackend *backend,
deleted_ids = g_list_append (deleted_ids, (gpointer) uid);
e_book_backend_cache_remove_contact (couchdb_backend->cache, uid);
} else {
- if (error != NULL) {
+ if (error != NULL)
g_debug ("Error deleting document: %s", error->message);
- g_error_free (error);
- } else
+ else
g_debug ("Error deleting document");
+
+ break;
}
/* Free memory */
@@ -1217,29 +1279,42 @@ e_book_backend_couchdb_remove_contacts (EBookBackend *backend,
e_book_backend_cache_remove_contact (couchdb_backend->cache, uid);
g_hash_table_remove (couchdb_backend->revisions, uid);
} else {
- if (error != NULL) {
+ if (error != NULL)
g_debug ("Error deleting document: %s", error->message);
- g_error_free (error);
- } else
+ else
g_debug ("Error deleting document");
+
+ break;
}
}
} else {
- if (error != NULL) {
+ if (error != NULL)
g_debug ("Error getting document: %s", error->message);
- g_error_free (error);
- } else
+ else
g_debug ("Error getting document");
+
+ break;
}
}
if (deleted_ids) {
+#if EDS_CHECK_VERSION(2, 31, 0)
+ e_data_book_respond_remove_contacts (book, opid, NULL, deleted_ids);
+#else
e_data_book_respond_remove_contacts (book, opid,
GNOME_Evolution_Addressbook_Success, deleted_ids);
+#endif
g_list_free (deleted_ids);
- } else
+ } else {
+#if EDS_CHECK_VERSION(2, 31, 0)
+ if (error == NULL)
+ error = g_error_new_literal (ERROR_QUARK, 100, _("Could not remove contacts from CouchDB"));
+ e_data_book_respond_remove_contacts (book, opid, error, NULL);
+#else
e_data_book_respond_remove_contacts (book, opid,
GNOME_Evolution_Addressbook_OtherError, NULL);
+#endif
+ }
}
static void
@@ -1250,27 +1325,27 @@ e_book_backend_couchdb_modify_contact (EBookBackend *backend,
{
EContact *contact, *new_contact;
CouchdbDocument *document;
+ GError *error = NULL;
EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
contact = e_contact_new_from_vcard (vcard);
- if (!contact) {
- e_data_book_respond_modify (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
- return;
- }
-
document = couch_document_from_contact (couchdb_backend, contact);
- if (!document) {
- e_data_book_respond_modify (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
- g_object_unref (G_OBJECT (document));
- return;
- }
/* save the contact into the DB */
- if ((new_contact = put_document (couchdb_backend, document)) != NULL) {
+ if ((new_contact = put_document (couchdb_backend, document, &error)) != NULL) {
+#if EDS_CHECK_VERSION(2, 31, 0)
+ e_data_book_respond_modify (book, opid, NULL, new_contact);
+#else
e_data_book_respond_modify (book, opid, GNOME_Evolution_Addressbook_Success, new_contact);
+#endif
g_object_unref (new_contact);
- } else
+ } else {
+#if EDS_CHECK_VERSION(2, 31, 0)
+ e_data_book_respond_modify (book, opid, error, NULL);
+#else
e_data_book_respond_modify (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
+#endif
+ }
/* free memory */
g_object_unref (G_OBJECT (contact));
@@ -1292,16 +1367,27 @@ e_book_backend_couchdb_get_contact (EBookBackend *backend,
g_object_unref (G_OBJECT (contact));
if (vcard != NULL) {
+#if EDS_CHECK_VERSION(2, 31, 0)
+ e_data_book_respond_get_contact (book, opid, NULL, vcard);
+#else
e_data_book_respond_get_contact (book,
opid,
GNOME_Evolution_Addressbook_Success,
vcard);
+#endif
g_free (vcard);
return;
}
+ } else {
+#if EDS_CHECK_VERSION(2, 31, 0)
+ GError *error;
+
+ error = g_error_new (ERROR_QUARK, 100, _("Contact %s could not be found in CouchDB contacts database"), id);
+ e_data_book_respond_get_contact (book, opid, error, NULL);
+#else
+ e_data_book_respond_get_contact (book, opid, GNOME_Evolution_Addressbook_ContactNotFound, NULL);
+#endif
}
-
- e_data_book_respond_get_contact (book, opid, GNOME_Evolution_Addressbook_ContactNotFound, "");
}
static void
@@ -1326,7 +1412,11 @@ e_book_backend_couchdb_get_contact_list (EBookBackend *backend,
g_object_unref (G_OBJECT (contact));
}
+#if EDS_CHECK_VERSION(2, 31, 0)
+ e_data_book_respond_get_contact_list (book, opid, NULL, contacts);
+#else
e_data_book_respond_get_contact_list (book, opid, GNOME_Evolution_Addressbook_Success, contacts);
+#endif
}
static void
@@ -1355,7 +1445,11 @@ e_book_backend_couchdb_start_book_view (EBookBackend *backend,
g_object_unref (G_OBJECT (contact));
}
+#if EDS_CHECK_VERSION(2, 31, 0)
+ e_data_book_view_notify_complete (book_view, NULL);
+#else
e_data_book_view_notify_complete (book_view, GNOME_Evolution_Addressbook_Success);
+#endif
}
static void
@@ -1394,8 +1488,12 @@ e_book_backend_couchdb_get_required_fields (EBookBackend *backend,
field_name = e_contact_field_name (E_CONTACT_GIVEN_NAME);
fields = g_list_append (fields, g_strdup (field_name));
+#if EDS_CHECK_VERSION(2, 31, 0)
+ e_data_book_respond_get_required_fields(book, opid, NULL, fields);
+#else
e_data_book_respond_get_required_fields(book, opid,
GNOME_Evolution_Addressbook_Success, fields);
+#endif
g_list_foreach (fields, (GFunc) g_free, NULL);
g_list_free (fields);
@@ -1472,8 +1570,12 @@ e_book_backend_couchdb_get_supported_fields (EBookBackend *backend,
fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_SKYPE)));
fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_YAHOO)));
+#if EDS_CHECK_VERSION(2, 31, 0)
+ e_data_book_respond_get_supported_fields (book, opid, NULL, fields);
+#else
e_data_book_respond_get_supported_fields (book, opid,
GNOME_Evolution_Addressbook_Success, fields);
+#endif
g_list_foreach (fields, (GFunc) g_free, NULL);
g_list_free (fields);
@@ -1486,21 +1588,36 @@ e_book_backend_couchdb_get_supported_auth_methods (EBookBackend *backend, EDataB
auth_methods = g_list_append (auth_methods, g_strdup ("plain/password"));
+#if EDS_CHECK_VERSION(2, 31, 0)
+ e_data_book_respond_get_supported_auth_methods (book, opid, NULL, auth_methods);
+#else
e_data_book_respond_get_supported_auth_methods (book, opid,
GNOME_Evolution_Addressbook_Success, auth_methods);
+#endif
g_list_foreach (auth_methods, (GFunc) g_free, NULL);
g_list_free (auth_methods);
}
+#if EDS_CHECK_VERSION(2, 31, 0)
+static void
+e_book_backend_couchdb_cancel_operation (EBookBackend *backend, EDataBook *book, GError **ret_error)
+{
+}
+#else
static GNOME_Evolution_Addressbook_CallStatus
e_book_backend_couchdb_cancel_operation (EBookBackend *backend, EDataBook *book)
{
return GNOME_Evolution_Addressbook_CouldNotCancel;
}
+#endif
static void
+#if EDS_CHECK_VERSION(2, 31, 0)
+e_book_backend_couchdb_set_mode (EBookBackend *backend, EDataBookMode mode)
+#else
e_book_backend_couchdb_set_mode (EBookBackend *backend, GNOME_Evolution_Addressbook_BookMode mode)
+#endif
{
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]