[evolution-couchdb] Add #ifdef'ed code for e-d-s/evo 3.3.x API



commit 38ad0cc8e14fecd6c63cd4f3456266be43191613
Author: Milan Crha <mcrha redhat com>
Date:   Tue Oct 11 11:37:36 2011 +0200

    Add #ifdef'ed code for e-d-s/evo 3.3.x API

 addressbook/e-book-backend-couchdb-factory.c |   56 ++++++++++++++++++-
 addressbook/e-book-backend-couchdb.c         |   78 +++++++++++++++++++++++---
 calendar/e-cal-backend-couchdb-factory.c     |   56 ++++++++++++++++++-
 calendar/e-cal-backend-couchdb-factory.h     |    3 +
 calendar/e-cal-backend-couchdb.c             |    9 +++-
 plugins/couchdb-sources.c                    |   16 +++++
 6 files changed, 205 insertions(+), 13 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb-factory.c b/addressbook/e-book-backend-couchdb-factory.c
index f13a87a..071f776 100644
--- a/addressbook/e-book-backend-couchdb-factory.c
+++ b/addressbook/e-book-backend-couchdb-factory.c
@@ -20,11 +20,62 @@
  * Authors: Rodrigo Moya <rodrigo moya canonical com>
  */
 
-#include <libebackend/e-data-server-module.h>
+#include <libedataserver/eds-version.h>
 #include <libedata-book/e-book-backend-factory.h>
-#include <dbus/dbus.h>
 #include "e-book-backend-couchdb.h"
 
+#if EDS_CHECK_VERSION (3,3,1)
+
+typedef EBookBackendFactory EBookBackendCouchDBFactory;
+typedef EBookBackendFactoryClass EBookBackendCouchDBFactoryClass;
+
+/* Module Entry Points */
+void e_module_load (GTypeModule *type_module);
+void e_module_unload (GTypeModule *type_module);
+
+/* Forward Declarations */
+GType e_book_backend_couchdb_factory_get_type (void);
+
+G_DEFINE_DYNAMIC_TYPE (
+	EBookBackendCouchDBFactory,
+	e_book_backend_couchdb_factory,
+	E_TYPE_BOOK_BACKEND_FACTORY)
+
+static void
+e_book_backend_couchdb_factory_class_init (EBookBackendFactoryClass *klass)
+{
+	klass->factory_name = "couchdb";
+	klass->backend_type = E_TYPE_BOOK_BACKEND_COUCHDB;
+}
+
+static void
+e_book_backend_couchdb_factory_class_finalize (EBookBackendFactoryClass *klass)
+{
+}
+
+static void
+e_book_backend_couchdb_factory_init (EBookBackendFactory *factory)
+{
+}
+
+G_MODULE_EXPORT void
+e_module_load (GTypeModule *type_module)
+{
+	/* FIXME: this is a hack to avoid crashes when calling gnome-keyring
+	   from desktopcouch_session_new */
+	dbus_threads_init_default ();
+
+	e_book_backend_couchdb_factory_register_type (type_module);
+}
+
+G_MODULE_EXPORT void
+e_module_unload (GTypeModule *type_module)
+{
+}
+
+#else /* EDS_CHECK_VERSION */
+#include <libebackend/e-data-server-module.h>
+
 E_BOOK_BACKEND_FACTORY_SIMPLE (couchdb, CouchDB, e_book_backend_couchdb_new)
 
 static GType couchdb_type;
@@ -49,3 +100,4 @@ eds_module_list_types (const GType **types, int *num_types)
 	*types = &couchdb_type;
 	*num_types = 1;
 }
+#endif /* EDS_CHECK_VERSION */
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index 3cd5797..798a50a 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -25,6 +25,7 @@
 #include <glib/gi18n-lib.h>
 #include "e-book-backend-couchdb.h"
 #include <libedataserver/eds-version.h>
+#include <libedataserver/e-data-server-util.h>
 #include <libedata-book/e-book-backend-sexp.h>
 #include <libedata-book/e-data-book.h>
 #include <libedata-book/e-data-book-view.h>
@@ -1067,7 +1068,9 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
 	GSList *doc_list, *sl;
 	const gchar *db_name;
 	EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
-#if EDS_CHECK_VERSION(3, 1, 2)
+#if EDS_CHECK_VERSION(3, 3, 1)
+	ESource *source = e_backend_get_source (E_BACKEND (backend));
+#elif EDS_CHECK_VERSION(3, 1, 2)
 	ESource *source = e_book_backend_get_source (backend);
 #endif
 
@@ -1309,26 +1312,49 @@ e_book_backend_couchdb_create_contact (EBookBackend *backend,
 #if EDS_CHECK_VERSION(3, 1, 2)
 				       GCancellable *cancellable,
 #endif
-				       const char *vcard)
+#if EDS_CHECK_VERSION(3, 3, 1)
+				       const GSList *vcards
+#else
+				       const gchar *vcard
+#endif
+	)
 {
 	EContact *contact, *new_contact;
 	CouchdbDocument *document;
 	GError *error = NULL;
 	EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
+#if EDS_CHECK_VERSION(3, 3, 1)
+	const gchar *vcard = vcards->data;
+
+	if (vcards->next) {
+		e_data_book_respond_create_contacts (book, opid,
+		                                     e_data_book_create_error (E_DATA_BOOK_STATUS_NOT_SUPPORTED, _("The backend does not support bulk additions")),
+		                                     NULL);
+		return;
+	}
+#endif
 
 	contact = e_contact_new_from_vcard (vcard);
 	document = couch_document_from_contact (couchdb_backend, contact);
 
 	/* save the contact into the DB */
 	if ((new_contact = put_document (couchdb_backend, document, &error)) != NULL) {
-#if EDS_CHECK_VERSION(2, 31, 0)
+#if EDS_CHECK_VERSION(3, 3, 1)
+		GSList *added_contacts;
+
+		added_contacts = g_slist_append (NULL, new_contact);
+		e_data_book_respond_create_contacts (book, opid, NULL, added_contacts);
+		e_util_free_object_slist (added_contacts);
+#elif 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 {
-#if EDS_CHECK_VERSION(2, 31, 0)
+#if EDS_CHECK_VERSION(3, 3, 1)
+		e_data_book_respond_create_contacts (book, opid, error, NULL);
+#elif 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);
@@ -1468,26 +1494,49 @@ e_book_backend_couchdb_modify_contact (EBookBackend *backend,
 #if EDS_CHECK_VERSION(3, 1, 2)
 				       GCancellable *cancellable,
 #endif
-				       const char *vcard)
+#if EDS_CHECK_VERSION(3, 3, 1)
+				       const GSList *vcards
+#else
+				       const gchar *vcard
+#endif
+	)
 {
 	EContact *contact, *new_contact;
 	CouchdbDocument *document;
 	GError *error = NULL;
 	EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
+#if EDS_CHECK_VERSION(3, 3, 1)
+	const gchar *vcard = vcards->data;
+
+	if (vcards->next != NULL) {
+		e_data_book_respond_modify_contacts (book, opid,
+		                                     e_data_book_create_error (E_DATA_BOOK_STATUS_NOT_SUPPORTED, _("The backend does not support bulk modifications")),
+		                                     NULL);
+		return;
+	}
+#endif
 
 	contact = e_contact_new_from_vcard (vcard);
 	document = couch_document_from_contact (couchdb_backend, contact);
 
 	/* save the contact into the DB */
 	if ((new_contact = put_document (couchdb_backend, document, &error)) != NULL) {
-#if EDS_CHECK_VERSION(2, 31, 0)
+#if EDS_CHECK_VERSION(3, 3, 1)
+		GSList *modified_contacts;
+
+		modified_contacts = g_slist_append (NULL, new_contact);
+		e_data_book_respond_modify_contacts (book, opid, NULL, modified_contacts);
+		e_util_free_object_slist (modified_contacts);
+#elif 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 {
-#if EDS_CHECK_VERSION(2, 31, 0)
+#if EDS_CHECK_VERSION(3, 3, 1)
+		e_data_book_respond_modify_contacts (book, opid, error, NULL);
+#elif 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);
@@ -1610,7 +1659,11 @@ e_book_backend_couchdb_start_book_view (EBookBackend *backend,
 		if (!vcard)
 			continue;
 
+#if EDS_CHECK_VERSION(3, 3, 1)
+		e_data_book_view_notify_update_vcard (book_view, e_contact_get_const (contact, E_CONTACT_UID), vcard);
+#else
 		e_data_book_view_notify_update_vcard (book_view, vcard);
+#endif
 
 		doc_list = g_list_remove (doc_list, contact);
 		g_object_unref (G_OBJECT (contact));
@@ -1674,10 +1727,12 @@ e_book_backend_couchdb_get_backend_property (EBookBackend *backend,
 	}
 }
 
+#if !EDS_CHECK_VERSION(3, 3, 1)
 static void
 e_book_backend_couchdb_set_online (EBookBackend *backend, gboolean is_online)
 {
 }
+#endif
 
 #else /* EDS_CHECK_VERSION(3, 1, 2) */
 static char *
@@ -1839,7 +1894,9 @@ e_book_backend_couchdb_class_init (EBookBackendCouchDBClass *klass)
 #if EDS_CHECK_VERSION(3, 1, 2)
 	parent_class->open                    = e_book_backend_couchdb_open;
 	parent_class->get_backend_property    = e_book_backend_couchdb_get_backend_property;
+#if !EDS_CHECK_VERSION(3, 3, 1)
 	parent_class->set_online              = e_book_backend_couchdb_set_online;
+#endif
 #else
 	parent_class->load_source             = e_book_backend_couchdb_load_source;
 	parent_class->get_static_capabilities = e_book_backend_couchdb_get_static_capabilities;
@@ -1850,9 +1907,14 @@ e_book_backend_couchdb_class_init (EBookBackendCouchDBClass *klass)
 	parent_class->cancel_operation        = e_book_backend_couchdb_cancel_operation;
 	parent_class->set_mode                = e_book_backend_couchdb_set_mode;
 #endif
+#if EDS_CHECK_VERSION(3, 3, 1)
+	parent_class->create_contacts         = e_book_backend_couchdb_create_contact;
+	parent_class->modify_contacts         = e_book_backend_couchdb_modify_contact;
+#else
 	parent_class->create_contact          = e_book_backend_couchdb_create_contact;
-	parent_class->remove_contacts         = e_book_backend_couchdb_remove_contacts;
 	parent_class->modify_contact          = e_book_backend_couchdb_modify_contact;
+#endif
+	parent_class->remove_contacts         = e_book_backend_couchdb_remove_contacts;
 	parent_class->get_contact             = e_book_backend_couchdb_get_contact;
 	parent_class->get_contact_list        = e_book_backend_couchdb_get_contact_list;
 	parent_class->start_book_view         = e_book_backend_couchdb_start_book_view;
diff --git a/calendar/e-cal-backend-couchdb-factory.c b/calendar/e-cal-backend-couchdb-factory.c
index 605f306..c89b64e 100644
--- a/calendar/e-cal-backend-couchdb-factory.c
+++ b/calendar/e-cal-backend-couchdb-factory.c
@@ -26,11 +26,61 @@
 
 #include <string.h>
 
-#include <libebackend/e-data-server-module.h>
+#include <libedataserver/eds-version.h>
 #include <libedata-cal/e-cal-backend-factory.h>
-#include "e-cal-backend-couchdb-factory.h"
+
 #include "e-cal-backend-couchdb.h"
 
+#if EDS_CHECK_VERSION (3,3,1)
+
+typedef ECalBackendFactory ECalBackendCouchDBTodosFactory;
+typedef ECalBackendFactoryClass ECalBackendCouchDBTodosFactoryClass;
+
+/* Module Entry Points */
+void e_module_load (GTypeModule *type_module);
+void e_module_unload (GTypeModule *type_module);
+
+/* Forward Declarations */
+GType e_cal_backend_couchdb_todos_factory_get_type (void);
+
+G_DEFINE_DYNAMIC_TYPE (
+	ECalBackendCouchDBTodosFactory,
+	e_cal_backend_couchdb_todos_factory,
+	E_TYPE_CAL_BACKEND_FACTORY)
+
+static void
+e_cal_backend_couchdb_todos_factory_class_init (ECalBackendFactoryClass *klass)
+{
+	klass->factory_name = "couchdb";
+	klass->component_kind = ICAL_VTODO_COMPONENT;
+	klass->backend_type = E_TYPE_CAL_BACKEND_COUCHDB;
+}
+
+static void
+e_cal_backend_couchdb_todos_factory_class_finalize (ECalBackendFactoryClass *klass)
+{
+}
+
+static void
+e_cal_backend_couchdb_todos_factory_init (ECalBackendFactory *factory)
+{
+}
+
+G_MODULE_EXPORT void
+e_module_load (GTypeModule *type_module)
+{
+	e_cal_backend_couchdb_todos_factory_register_type (type_module);
+}
+
+G_MODULE_EXPORT void
+e_module_unload (GTypeModule *type_module)
+{
+}
+
+#else /* EDS_CHECK_VERSION */
+#include <libebackend/e-data-server-module.h>
+#include "e-cal-backend-couchdb-factory.h"
+
 typedef ECalBackendFactory      ECalBackendCouchDBTodosFactory;
 typedef ECalBackendFactoryClass ECalBackendCouchDBTodosFactoryClass;
 
@@ -102,3 +152,5 @@ eds_module_list_types (const GType **types, gint *num_types)
 	*types = couchdb_types;
 	*num_types = G_N_ELEMENTS (couchdb_types);
 }
+
+#endif /* EDS_CHECK_VERSION */
diff --git a/calendar/e-cal-backend-couchdb-factory.h b/calendar/e-cal-backend-couchdb-factory.h
index f0cbda8..005e5de 100644
--- a/calendar/e-cal-backend-couchdb-factory.h
+++ b/calendar/e-cal-backend-couchdb-factory.h
@@ -22,6 +22,7 @@
 #ifndef _E_CAL_BACKEND_COUCHDB_FACTORY_H
 #define _E_CAL_BACKEND_COUCHDB_FACTORY_H
 
+#if !EDS_CHECK_VERSION (3,3,1)
 #include <glib.h>
 #include <libedata-cal/e-cal-backend-factory.h>
 
@@ -33,5 +34,7 @@ void eds_module_list_types (const GType **types, gint *num_types);
 
 G_END_DECLS
 
+#endif /* EDS_CHECK_VERSION */
+
 #endif
 
diff --git a/calendar/e-cal-backend-couchdb.c b/calendar/e-cal-backend-couchdb.c
index 2c92323..66c8393 100644
--- a/calendar/e-cal-backend-couchdb.c
+++ b/calendar/e-cal-backend-couchdb.c
@@ -196,8 +196,11 @@ e_cal_backend_couchdb_open (ECalBackend *backend, EDataCal *cal, EServerMethodCo
 	ECalBackendCouchDB *couchdb_backend = E_CAL_BACKEND_COUCHDB (backend);
 	ESource *source;
 
-
+#if EDS_CHECK_VERSION(3, 3, 1)
+	source = e_backend_get_source (E_BACKEND (backend));
+#else
 	source = e_cal_backend_get_source (backend);
+#endif
 	if (!(E_IS_CAL_BACKEND_COUCHDB (couchdb_backend))) {
 #if EDS_CHECK_VERSION(3, 1, 0)
 		e_data_cal_respond_open (cal, opid, e_data_cal_create_error (ObjectNotFound, "Invalid CouchDB backend"));
@@ -806,7 +809,11 @@ e_cal_backend_couchdb_start_view (ECalBackend *backend, EDataCalView *query)
 	ECalBackendCouchDB *couchdb_backend = E_CAL_BACKEND_COUCHDB (backend);
 	ECalBackendSExp *sexp;
 
+#if EDS_CHECK_VERSION(3, 3, 1)
+	e_cal_backend_add_view (backend, query);
+#else
 	e_cal_backend_add_query (backend, query);
+#endif
 	sexp = e_data_cal_view_get_object_sexp (query);
 
 	// Get the list of documents from cache
diff --git a/plugins/couchdb-sources.c b/plugins/couchdb-sources.c
index d153f46..45c3d77 100644
--- a/plugins/couchdb-sources.c
+++ b/plugins/couchdb-sources.c
@@ -28,7 +28,15 @@
 #include <libedataserver/eds-version.h>
 #include <libedataserver/e-source.h>
 #include <libedataserver/e-source-list.h>
+
+#if EDS_CHECK_VERSION(3, 2, 0)
+#include <libecal/e-cal-client.h>
+#include <libebook/e-book-client.h>
+#else
 #include <libecal/e-cal.h>
+#include <libebook/e-book.h>
+#endif
+
 #include "couchdb-sources.h"
 
 typedef struct {
@@ -233,13 +241,21 @@ e_plugin_lib_enable (EPluginLib *ep, gint enable)
 {
 	ESourceList *book_sources, *task_sources;
 
+#if EDS_CHECK_VERSION(3, 2, 0)
+	e_book_client_get_sources (&book_sources, NULL);
+	e_cal_client_get_sources (&task_sources, E_CAL_CLIENT_SOURCE_TYPE_TASKS, NULL);
+#else
 	e_book_get_addressbooks (&book_sources, NULL);
 	e_cal_get_sources (&task_sources, E_CAL_SOURCE_TYPE_TODO, NULL);
+#endif
 
 	if (enable)
 		ensure_source_group (book_sources);
 	else
 		remove_source_group (book_sources);
 
+	g_object_unref (book_sources);
+	g_object_unref (task_sources);
+
 	return 0;
 }



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