[evolution-exchange] Adapt to libebackend changes.



commit b83491c1f6add5dbb476f9d98090309a3200ac4c
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Sep 11 09:07:50 2011 -0400

    Adapt to libebackend changes.
    
    Address book and calendar backends now use the EModule / EExtension
    framework promoted from Evolution, instead of e-data-server-module.c.

 addressbook/e-book-backend-exchange-factory.c |   81 ++++++++++----
 addressbook/e-book-backend-exchange.c         |   39 ++++---
 addressbook/e-book-backend-gal.c              |   66 ++++++++----
 calendar/Makefile.am                          |    1 -
 calendar/e-cal-backend-exchange-calendar.c    |   16 ++--
 calendar/e-cal-backend-exchange-factory.c     |  147 +++++++------------------
 calendar/e-cal-backend-exchange-factory.h     |   90 ---------------
 calendar/e-cal-backend-exchange-tasks.c       |   10 +-
 calendar/e-cal-backend-exchange.c             |   39 ++++---
 9 files changed, 205 insertions(+), 284 deletions(-)
---
diff --git a/addressbook/e-book-backend-exchange-factory.c b/addressbook/e-book-backend-exchange-factory.c
index 886bb76..396db21 100644
--- a/addressbook/e-book-backend-exchange-factory.c
+++ b/addressbook/e-book-backend-exchange-factory.c
@@ -17,40 +17,79 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
-#include <string.h>
-
-#include <camel/camel.h>
-#include <libebackend/e-data-server-module.h>
 #include <libedata-book/e-book-backend-factory.h>
-
 #include "e-book-backend-exchange.h"
 #include "e-book-backend-gal.h"
 
-E_BOOK_BACKEND_FACTORY_SIMPLE (exchange, Exchange, e_book_backend_exchange_new)
-E_BOOK_BACKEND_FACTORY_SIMPLE (gal, Gal, e_book_backend_gal_new)
+typedef EBookBackendFactory EBookBackendExchangeFactory;
+typedef EBookBackendFactoryClass EBookBackendExchangeFactoryClass;
+
+typedef EBookBackendFactory EBookBackendGalFactory;
+typedef EBookBackendFactoryClass EBookBackendGalFactoryClass;
+
+/* Module Entry Points */
+void e_module_load (GTypeModule *type_module);
+void e_module_unload (GTypeModule *type_module);
+
+/* Forward Declarations */
+GType e_book_backend_exchange_factory_get_type (void);
+GType e_book_backend_gal_factory_get_type (void);
+
+G_DEFINE_DYNAMIC_TYPE (
+	EBookBackendExchangeFactory,
+	e_book_backend_exchange_factory,
+	E_TYPE_BOOK_BACKEND_FACTORY)
+
+G_DEFINE_DYNAMIC_TYPE (
+	EBookBackendGalFactory,
+	e_book_backend_gal_factory,
+	E_TYPE_BOOK_BACKEND_FACTORY)
+
+static void
+e_book_backend_exchange_factory_class_init (EBookBackendFactoryClass *class)
+{
+	class->factory_name = "exchange";
+	class->backend_type = E_TYPE_BOOK_BACKEND_EXCHANGE;
+}
+
+static void
+e_book_backend_exchange_factory_class_finalize (EBookBackendFactoryClass *class)
+{
+}
 
-static GType exchange_types[2];
+static void
+e_book_backend_exchange_factory_init (EBookBackendFactory *factory)
+{
+}
 
-void
-eds_module_initialize (GTypeModule *type_module)
+static void
+e_book_backend_gal_factory_class_init (EBookBackendFactoryClass *class)
 {
-	exchange_types[0] = _exchange_factory_get_type (type_module);
-	exchange_types[1] = _gal_factory_get_type (type_module);
+	class->factory_name = "gal";
+	class->backend_type = E_TYPE_BOOK_BACKEND_GAL;
 }
 
-void
-eds_module_shutdown (void)
+static void
+e_book_backend_gal_factory_class_finalize (EBookBackendFactoryClass *class)
 {
 }
 
-void
-eds_module_list_types (const GType **types,
-                       gint *num_types)
+static void
+e_book_backend_gal_factory_init (EBookBackendFactory *factory)
 {
-	*types = exchange_types;
-	*num_types = G_N_ELEMENTS (exchange_types);
 }
+
+G_MODULE_EXPORT void
+e_module_load (GTypeModule *type_module)
+{
+	e_book_backend_exchange_factory_register_type (type_module);
+	e_book_backend_gal_factory_register_type (type_module);
+}
+
+G_MODULE_EXPORT void
+e_module_unload (GTypeModule *type_module)
+{
+}
+
diff --git a/addressbook/e-book-backend-exchange.c b/addressbook/e-book-backend-exchange.c
index 6203f17..626881f 100644
--- a/addressbook/e-book-backend-exchange.c
+++ b/addressbook/e-book-backend-exchange.c
@@ -1721,7 +1721,7 @@ e_book_backend_exchange_create_contact (EBookBackendSync *backend,
 
 	LOCK (bepriv);
 
-	if (!e_book_backend_is_online (E_BOOK_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		*contact = NULL;
 		UNLOCK (bepriv);
 		g_propagate_error (perror, EDB_ERROR (REPOSITORY_OFFLINE));
@@ -1812,7 +1812,7 @@ e_book_backend_exchange_modify_contact (EBookBackendSync *backend,
 
 	d(printf("ebbe_modify_contact(%p, %p, %s)\n", backend, book, vcard));
 
-	if (!e_book_backend_is_online (E_BOOK_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		*contact = NULL;
 		g_propagate_error (perror, EDB_ERROR (REPOSITORY_OFFLINE));
 	} else {
@@ -1938,7 +1938,7 @@ e_book_backend_exchange_remove_contacts (EBookBackendSync *backend,
 	 /* Remove one or more contacts */
 	d(printf("ebbe_remove_contact(%p, %p, %s)\n", backend, book, (gchar *)id_list->data));
 
-	if (!e_book_backend_is_online (E_BOOK_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		*removed_ids = NULL;
 		g_propagate_error (perror, EDB_ERROR (REPOSITORY_OFFLINE));
 	} else {
@@ -2260,7 +2260,7 @@ e_book_backend_exchange_get_contact_list (EBookBackendSync *backend,
 
 	d(printf("ebbe_get_contact_list(%p, %p, %s)\n", backend, book, query));
 
-	if (!e_book_backend_is_online (E_BOOK_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		/* FIXME */
 		offline_contacts = e_book_backend_cache_get_contacts (bepriv->cache,
 							      query);
@@ -2349,7 +2349,7 @@ e_book_backend_exchange_start_book_view (EBookBackend *backend,
 	e_data_book_view_ref (book_view);
 	e_data_book_view_notify_progress (book_view, -1, _("Searching..."));
 
-	if (!e_book_backend_is_online (E_BOOK_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		if (!bepriv->marked_for_offline) {
 			err = EDB_ERROR (OFFLINE_UNAVAILABLE);
 			e_data_book_view_notify_complete (book_view, err);
@@ -2455,7 +2455,7 @@ e_book_backend_exchange_get_contact (EBookBackendSync *backend,
 
 	be = E_BOOK_BACKEND_EXCHANGE (e_data_book_get_backend (book));
 
-	if (!e_book_backend_is_online (E_BOOK_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		contact = e_book_backend_cache_get_contact (bepriv->cache,
 							    id);
 		if (contact) {
@@ -2535,7 +2535,7 @@ e_book_backend_exchange_authenticate_user (EBookBackend *backend,
 
 	d(printf("ebbe_authenticate_user(%p, %p, %s, %s, %s)\n", backend, book, user, password, auth_method));
 
-	if (!e_book_backend_is_online (backend)) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		e_book_backend_notify_readonly (backend, TRUE);
 		e_book_backend_notify_opened (backend, NULL);
 	} else {
@@ -2575,11 +2575,13 @@ e_book_backend_exchange_open (EBookBackend *backend,
 {
 	EBookBackendExchange *be = E_BOOK_BACKEND_EXCHANGE (backend);
 	EBookBackendExchangePrivate *bepriv = be->priv;
-	ESource *source = e_book_backend_get_source (backend);
+	ESource *source;
 	const gchar *cache_dir;
 	const gchar *offline;
 	gchar *filename;
 
+	source = e_backend_get_source (E_BACKEND (backend));
+
 	if (bepriv->connected) {
 		e_book_backend_respond_opened (backend, book, opid, EDB_ERROR (OTHER_ERROR));
 		return;
@@ -2593,7 +2595,7 @@ e_book_backend_exchange_open (EBookBackend *backend,
 	if (offline  && g_str_equal (offline, "1"))
 		bepriv->marked_for_offline = TRUE;
 
-	if (!e_book_backend_is_online (E_BOOK_BACKEND (backend)) &&
+	if (!e_backend_get_online (E_BACKEND (backend)) &&
 	    !bepriv->marked_for_offline ) {
 		e_book_backend_respond_opened (backend, book, opid, EDB_ERROR (OFFLINE_UNAVAILABLE));
 		return;
@@ -2608,7 +2610,7 @@ e_book_backend_exchange_open (EBookBackend *backend,
 
 	filename = g_build_filename (cache_dir, "cache.xml", NULL);
 
-	if (!e_book_backend_is_online (E_BOOK_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		e_book_backend_notify_readonly (backend, TRUE);
 		if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
 			e_book_backend_respond_opened (backend, book, opid, EDB_ERROR (OFFLINE_UNAVAILABLE));
@@ -2622,7 +2624,7 @@ e_book_backend_exchange_open (EBookBackend *backend,
 	g_free (filename);
 
 	/* Once aunthentication in address book works this can be removed */
-	if (!e_book_backend_is_online (backend)) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		e_book_backend_respond_opened (backend, book, opid, NULL);
 		return;
 	}
@@ -2713,17 +2715,19 @@ e_book_backend_exchange_get_backend_property (EBookBackendSync *backend,
 }
 
 static void
-e_book_backend_exchange_set_online (EBookBackend *backend,
-                                    gboolean is_online)
+e_book_backend_exchange_notify_online_cb (EBookBackend *backend,
+                                          GParamSpec *pspec)
 {
 	EBookBackendExchange *be = E_BOOK_BACKEND_EXCHANGE (backend);
 	EBookBackendExchangePrivate *bepriv = be->priv;
 	ExchangeAccount *account = NULL;
+	gboolean online;
 
-	e_book_backend_notify_online (E_BOOK_BACKEND (backend), is_online);
+	online = e_backend_get_online (E_BACKEND (backend));
+	e_book_backend_notify_online (E_BOOK_BACKEND (backend), online);
 
 	if (e_book_backend_is_opened (backend)) {
-		if (!is_online) {
+		if (!online) {
 			e_book_backend_notify_readonly (backend, TRUE);
 			/* FIXME : free context ? */
 		} else {
@@ -2813,7 +2817,6 @@ e_book_backend_exchange_class_init (EBookBackendExchangeClass *klass)
 	backend_class->open			= e_book_backend_exchange_open;
 	backend_class->start_book_view		= e_book_backend_exchange_start_book_view;
 	backend_class->stop_book_view		= e_book_backend_exchange_stop_book_view;
-	backend_class->set_online		= e_book_backend_exchange_set_online;
 	backend_class->authenticate_user	= e_book_backend_exchange_authenticate_user;
 
 	sync_class->remove_sync			= e_book_backend_exchange_remove;
@@ -2841,5 +2844,9 @@ e_book_backend_exchange_init (EBookBackendExchange *backend)
 	priv->cache_lock      = g_mutex_new ();
 
 	backend->priv		= priv;
+
+	g_signal_connect (
+		backend, "notify::online",
+		G_CALLBACK (e_book_backend_exchange_notify_online_cb), NULL);
 }
 
diff --git a/addressbook/e-book-backend-gal.c b/addressbook/e-book-backend-gal.c
index b3aa907..d8e71ca 100644
--- a/addressbook/e-book-backend-gal.c
+++ b/addressbook/e-book-backend-gal.c
@@ -228,19 +228,35 @@ G_DEFINE_TYPE (
 static gboolean
 can_browse (EBookBackend *backend)
 {
-	return backend &&
-		e_book_backend_get_source (backend) &&
-		e_source_get_property (e_book_backend_get_source (backend), "can-browse") &&
-		strcmp (e_source_get_property (e_book_backend_get_source (backend), "can-browse"), "1") == 0;
+	ESource *source;
+	const gchar *can_browse;
+
+	if (backend == NULL)
+		return FALSE;
+
+	source = e_backend_get_source (E_BACKEND (backend));
+	g_return_val_if_fail (source != NULL, FALSE);
+
+	can_browse = e_source_get_property (source, "can-browse");
+
+	return (g_strcmp0 (can_browse, "1") == 0);
 }
 
 static gboolean
 can_expand_groups (EBookBackend *backend)
 {
-	return backend &&
-		e_book_backend_get_source (backend) &&
-		e_source_get_property (e_book_backend_get_source (backend), "expand-groups") &&
-		strcmp (e_source_get_property (e_book_backend_get_source (backend), "expand-groups"), "1") == 0;
+	ESource *source;
+	const gchar *expand_groups;
+
+	if (backend == NULL)
+		return FALSE;
+
+	source = e_backend_get_source (E_BACKEND (backend));
+	g_return_val_if_fail (source != NULL, FALSE);
+
+	expand_groups = e_source_get_property (source, "expand-groups");
+
+	return (g_strcmp0 (expand_groups, "1") == 0);
 }
 
 static void
@@ -656,7 +672,7 @@ get_contact (EBookBackend *backend,
 	gint ldap_error;
 
 	d(printf("get contact\n"));
-	if (!e_book_backend_is_online (backend)) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 #if defined(ENABLE_CACHE) && ENABLE_CACHE
 		if (bl->priv->marked_for_offline && bl->priv->file_db) {
 			EContact *contact = e_book_backend_db_cache_get_contact (bl->priv->file_db, id);
@@ -862,7 +878,7 @@ get_contact_list (EBookBackend *backend,
 	GError *error = NULL;
 
 	d(printf("get contact list\n"));
-	if (!e_book_backend_is_online (backend)) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 #if defined(ENABLE_CACHE) && ENABLE_CACHE
 		if (bl->priv->marked_for_offline && bl->priv->file_db) {
 			GList *contacts;
@@ -1891,7 +1907,7 @@ start_book_view (EBookBackend *backend,
 	GError *err = NULL;
 
 	d(printf("start book view\n"));
-	if (!e_book_backend_is_online (backend)) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 #if defined(ENABLE_CACHE) && ENABLE_CACHE
 		if (!(bl->priv->marked_for_offline && bl->priv->file_db)) {
 			err = EDB_ERROR (REPOSITORY_OFFLINE);
@@ -2492,7 +2508,7 @@ authenticate_user (EBookBackend *backend,
 
 	d(printf("authenticate_user(%p, %p, %s, %s, %s)\n", backend, book, user, password, auth_method));
 
-	if (!e_book_backend_is_online (backend)) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		e_book_backend_notify_readonly (backend, TRUE);
 		e_book_backend_notify_opened (backend, NULL /* Success */);
 	} else {
@@ -2590,22 +2606,25 @@ cancel_operations (EBookBackend *backend)
 }
 
 static void
-set_online (EBookBackend *backend,
-            gboolean is_online)
+notify_online_cb (EBookBackend *backend,
+                  GParamSpec *pspec)
 {
 	EBookBackendGAL *be = E_BOOK_BACKEND_GAL (backend);
 	EBookBackendGALPrivate *bepriv;
+	gboolean online;
 
 	bepriv = be->priv;
 
+	online = e_backend_get_online (E_BACKEND (backend));
+
 	/* Cancel all running operations */
 	cancel_operations (backend);
 
-	e_book_backend_notify_online (backend, is_online);
+	e_book_backend_notify_online (backend, online);
 
 	if (e_book_backend_is_opened (backend)) {
 		e_book_backend_notify_readonly (backend, TRUE);
-		if (is_online) {
+		if (online) {
 			gal_connect (be, NULL);
 			e_book_backend_notify_auth_required (backend, TRUE, NULL);
 #if defined(ENABLE_CACHE) && ENABLE_CACHE
@@ -2628,7 +2647,7 @@ gal_open (EBookBackend *backend,
           gboolean only_if_exists)
 {
 	EBookBackendGAL *bl = E_BOOK_BACKEND_GAL (backend);
-	ESource *source = e_book_backend_get_source (backend);
+	ESource *source;
 	const gchar *host;
 	gchar **tokens;
 	const gchar *offline;
@@ -2642,16 +2661,18 @@ gal_open (EBookBackend *backend,
 	DB *db;
 	DB_ENV *env;
 #endif
+
 	if (bl->priv->connected) {
 		e_book_backend_respond_opened (backend, book, opid, EDB_ERROR (OTHER_ERROR));
 		return;
 	}
 
+	source = e_backend_get_source (E_BACKEND (backend));
 	offline = e_source_get_property (source, "offline_sync");
 	if (offline && g_str_equal (offline, "1"))
 		bl->priv->marked_for_offline = TRUE;
 
-	if (!e_book_backend_is_online (backend) &&
+	if (!e_backend_get_online (E_BACKEND (backend)) &&
 	    !bl->priv->marked_for_offline) {
 		e_book_backend_respond_opened (backend, book, opid, EDB_ERROR (OFFLINE_UNAVAILABLE));
 		return;
@@ -2683,7 +2704,7 @@ gal_open (EBookBackend *backend,
 #if defined(ENABLE_CACHE) && ENABLE_CACHE
 	bl->priv->file_db = NULL;
 #endif
-	if (!e_book_backend_is_online (backend) && !bl->priv->marked_for_offline) {
+	if (!e_backend_get_online (E_BACKEND (backend)) && !bl->priv->marked_for_offline) {
 		/* Offline */
 		e_book_backend_notify_readonly (backend, TRUE);
 
@@ -2824,7 +2845,7 @@ gal_open (EBookBackend *backend,
 	/* Online */
 	e_book_backend_notify_readonly (backend, TRUE);
 
-	if (!e_book_backend_is_online (backend)) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		e_book_backend_respond_opened (backend, book, opid, NULL);
 	} else {
 		e_book_backend_notify_auth_required (E_BOOK_BACKEND (backend), TRUE, NULL);
@@ -2992,7 +3013,6 @@ e_book_backend_gal_class_init (EBookBackendGALClass *class)
 	backend_class->start_book_view		= start_book_view;
 	backend_class->stop_book_view		= stop_book_view;
 	backend_class->authenticate_user	= authenticate_user;
-	backend_class->set_online		= set_online;
 
 	/* Set up static data */
 	search_attrs = g_new (const gchar *, G_N_ELEMENTS (prop_info) + 1);
@@ -3019,5 +3039,9 @@ e_book_backend_gal_init (EBookBackendGAL *backend)
 	priv->last_best_time = 0;
 	priv->cache_time = 0;
 #endif
+
+	g_signal_connect (
+		backend, "notify::online",
+		G_CALLBACK (notify_online_cb), NULL);
 }
 
diff --git a/calendar/Makefile.am b/calendar/Makefile.am
index 313ed4c..937eb6e 100644
--- a/calendar/Makefile.am
+++ b/calendar/Makefile.am
@@ -19,7 +19,6 @@ libecalbackendexchange_la_SOURCES = \
 	e-cal-backend-exchange-tasks.c \
 	e-cal-backend-exchange-tasks.h \
 	e-cal-backend-exchange-factory.c \
-	e-cal-backend-exchange-factory.h \
 	e2k-cal-query.c \
 	e2k-cal-query.h \
 	e2k-cal-utils.c \
diff --git a/calendar/e-cal-backend-exchange-calendar.c b/calendar/e-cal-backend-exchange-calendar.c
index c6dd264..5cbc560 100644
--- a/calendar/e-cal-backend-exchange-calendar.c
+++ b/calendar/e-cal-backend-exchange-calendar.c
@@ -603,7 +603,7 @@ authenticate_user (ECalBackendSync *backend,
 		return;
 	}
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		return; /* Success */
 	}
 
@@ -805,7 +805,7 @@ create_object (ECalBackendSync *backend,
 	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_EXCHANGE_CALENDAR (cbexc), InvalidArg);
 	e_return_data_cal_error_if_fail (calobj != NULL, InvalidArg);
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		g_propagate_error (error, EDC_ERROR (RepositoryOffline));
 		return;
 	}
@@ -1196,7 +1196,7 @@ modify_object_with_href (ECalBackendSync *backend,
 	e_return_data_cal_error_and_val_if_fail (E_IS_CAL_BACKEND_EXCHANGE_CALENDAR (cbexc), InvalidArg, FALSE);
 	e_return_data_cal_error_and_val_if_fail (calobj != NULL, InvalidArg, FALSE);
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		g_propagate_error (error, EDC_ERROR (RepositoryOffline));
 		return FALSE;
 	}
@@ -1602,7 +1602,7 @@ remove_object (ECalBackendSync *backend,
 
 	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_EXCHANGE_CALENDAR (cbexc), InvalidArg);
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		g_propagate_error (error, EDC_ERROR (RepositoryOffline));
 		return;
 	}
@@ -1692,7 +1692,7 @@ receive_objects (ECalBackendSync *backend,
 	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_EXCHANGE_CALENDAR (cbexc), InvalidArg);
 	e_return_data_cal_error_if_fail (calobj != NULL, InvalidArg);
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		g_propagate_error (error, EDC_ERROR (RepositoryOffline));
 		return;
 	}
@@ -2147,7 +2147,7 @@ send_objects (ECalBackendSync *backend,
 
 	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_EXCHANGE (cbex), InvalidArg);
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (cbex))) {
+	if (!e_backend_get_online (E_BACKEND (cbex))) {
 		g_propagate_error (error, EDC_ERROR (RepositoryOffline));
 		return;
 	}
@@ -2333,7 +2333,7 @@ discard_alarm (ECalBackendSync *backend,
 
 	d(printf("ecbe_discard_alarm(%p, %p, uid=%s, auid=%s)\n", backend, cal, uid, auid));
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		g_propagate_error (error, EDC_ERROR (RepositoryOffline));
 		return;
 	}
@@ -2387,7 +2387,7 @@ get_free_busy (ECalBackendSync *backend,
 	xmlNode *recipients, *item;
 	xmlDoc *doc;
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		g_propagate_error (perror, EDC_ERROR (RepositoryOffline));
 		return;
 	}
diff --git a/calendar/e-cal-backend-exchange-factory.c b/calendar/e-cal-backend-exchange-factory.c
index 633d405..080d0b8 100644
--- a/calendar/e-cal-backend-exchange-factory.c
+++ b/calendar/e-cal-backend-exchange-factory.c
@@ -17,148 +17,83 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
-#include <string.h>
-
-#include <camel/camel.h>
-#include <libebackend/e-data-server-module.h>
-#include "e-cal-backend-exchange-factory.h"
+#include <libedata-cal/e-cal-backend-factory.h>
 #include "e-cal-backend-exchange-calendar.h"
 #include "e-cal-backend-exchange-tasks.h"
 
-static GType exchange_events_type;
-static GType exchange_todos_type;
+#define FACTORY_NAME "exchange"
 
-static const gchar *
-_get_protocol (ECalBackendFactory *factory)
-{
-	return "exchange";
-}
+typedef ECalBackendFactory ECalBackendExchangeEventsFactory;
+typedef ECalBackendFactoryClass ECalBackendExchangeEventsFactoryClass;
 
-static ECalBackend *
-_todos_new_backend (ECalBackendFactory *factory,
-                    ESource *source)
-{
-	return g_object_new (E_TYPE_CAL_BACKEND_EXCHANGE_TASKS,
-			     "source", source,
-			     "kind", ICAL_VTODO_COMPONENT, NULL);
-}
+typedef ECalBackendFactory ECalBackendExchangeTodosFactory;
+typedef ECalBackendFactoryClass ECalBackendExchangeTodosFactoryClass;
 
-static icalcomponent_kind
-_todos_get_kind (ECalBackendFactory *factory)
-{
-	return ICAL_VTODO_COMPONENT;
-}
+/* Module Entry Points */
+void e_module_load (GTypeModule *type_module);
+void e_module_unload (GTypeModule *type_module);
 
-static ECalBackend *
-_events_new_backend (ECalBackendFactory *factory,
-                     ESource *source)
-{
-	return g_object_new (E_TYPE_CAL_BACKEND_EXCHANGE_CALENDAR,
-			     "source", source,
-			     "kind", ICAL_VEVENT_COMPONENT, NULL);
-}
+/* Forward Declarations */
+GType e_cal_backend_exchange_events_factory_get_type (void);
+GType e_cal_backend_exchange_todos_factory_get_type (void);
 
-static icalcomponent_kind
-_events_get_kind (ECalBackendFactory *factory)
-{
-	return ICAL_VEVENT_COMPONENT;
-}
+G_DEFINE_DYNAMIC_TYPE (
+	ECalBackendExchangeEventsFactory,
+	e_cal_backend_exchange_events_factory,
+	E_TYPE_CAL_BACKEND_FACTORY)
+
+G_DEFINE_DYNAMIC_TYPE (
+	ECalBackendExchangeTodosFactory,
+	e_cal_backend_exchange_todos_factory,
+	E_TYPE_CAL_BACKEND_FACTORY)
 
 static void
-todos_backend_exchange_factory_class_init (ECalBackendExchangeFactoryClass *klass)
+e_cal_backend_exchange_events_factory_class_init (ECalBackendFactoryClass *class)
 {
-	E_CAL_BACKEND_FACTORY_CLASS (klass)->get_protocol = _get_protocol;
-	E_CAL_BACKEND_FACTORY_CLASS (klass)->get_kind     = _todos_get_kind;
-	E_CAL_BACKEND_FACTORY_CLASS (klass)->new_backend = _todos_new_backend;
+	class->factory_name = FACTORY_NAME;
+	class->component_kind = ICAL_VEVENT_COMPONENT;
+	class->backend_type = E_TYPE_CAL_BACKEND_EXCHANGE_CALENDAR;
 }
 
 static void
-events_backend_exchange_factory_class_init (ECalBackendExchangeFactoryClass *klass)
+e_cal_backend_exchange_events_factory_class_finalize (ECalBackendFactoryClass *class)
 {
-	E_CAL_BACKEND_FACTORY_CLASS (klass)->get_protocol = _get_protocol;
-	E_CAL_BACKEND_FACTORY_CLASS (klass)->get_kind     = _events_get_kind;
-	E_CAL_BACKEND_FACTORY_CLASS (klass)->new_backend = _events_new_backend;
 }
 
-GType
-e_cal_backend_exchange_events_factory_get_type (void)
+static void
+e_cal_backend_exchange_events_factory_init (ECalBackendFactory *factory)
 {
-	return exchange_events_type;
 }
 
-void
-e_cal_backend_exchange_events_factory_register_type (GTypeModule *type_module)
+static void
+e_cal_backend_exchange_todos_factory_class_init (ECalBackendFactoryClass *class)
 {
-	static const GTypeInfo type_info = {
-		sizeof (ECalBackendExchangeFactoryClass),
-		(GBaseInitFunc) NULL,
-		(GBaseFinalizeFunc) NULL,
-		(GClassInitFunc) events_backend_exchange_factory_class_init,
-		(GClassFinalizeFunc) NULL,
-		NULL,  /* class_data */
-		sizeof (ECalBackend),
-		0,     /* n_preallocs */
-		(GInstanceInitFunc) NULL,
-		NULL   /* value_table */
-	};
-
-	exchange_events_type = g_type_module_register_type (
-		type_module, E_TYPE_CAL_BACKEND_FACTORY,
-		"ECalBackendExchangeEventsFactory", &type_info, 0);
+	class->factory_name = FACTORY_NAME;
+	class->component_kind = ICAL_VTODO_COMPONENT;
+	class->backend_type = E_TYPE_CAL_BACKEND_EXCHANGE_TASKS;
 }
 
-GType
-e_cal_backend_exchange_todos_factory_get_type (void)
+static void
+e_cal_backend_exchange_todos_factory_class_finalize (ECalBackendFactoryClass *class)
 {
-	return exchange_todos_type;
 }
 
-void
-e_cal_backend_exchange_todos_factory_register_type (GTypeModule *type_module)
+static void
+e_cal_backend_exchange_todos_factory_init (ECalBackendFactory *factory)
 {
-	static const GTypeInfo type_info = {
-		sizeof (ECalBackendExchangeFactoryClass),
-		(GBaseInitFunc) NULL,
-		(GBaseFinalizeFunc) NULL,
-		(GClassInitFunc)  todos_backend_exchange_factory_class_init,
-		(GClassFinalizeFunc) NULL,
-		NULL,  /* class_data */
-		sizeof (ECalBackend),
-		0,     /* n_preallocs */
-		(GInstanceInitFunc) NULL,
-		NULL   /* value_table */
-	};
-
-	exchange_todos_type = g_type_module_register_type (
-		type_module, E_TYPE_CAL_BACKEND_FACTORY,
-		"ECalBackendExchangeTodosFactory", &type_info, 0);
 }
 
-void
-eds_module_initialize (GTypeModule *type_module)
+G_MODULE_EXPORT void
+e_module_load (GTypeModule *type_module)
 {
 	e_cal_backend_exchange_events_factory_register_type (type_module);
 	e_cal_backend_exchange_todos_factory_register_type (type_module);
 }
 
-void
-eds_module_shutdown (void)
+G_MODULE_EXPORT void
+e_module_unload (GTypeModule *type_module)
 {
 }
 
-void
-eds_module_list_types (const GType **types,
-                       gint *num_types)
-{
-	static GType module_types[2];
-
-	module_types[0] = E_TYPE_CAL_BACKEND_EXCHANGE_EVENTS_FACTORY;
-	module_types[1] = E_TYPE_CAL_BACKEND_EXCHANGE_TODOS_FACTORY;
-
-	*types = module_types;
-	*num_types = G_N_ELEMENTS (module_types);
-}
diff --git a/calendar/e-cal-backend-exchange-tasks.c b/calendar/e-cal-backend-exchange-tasks.c
index 278ce7f..b343412 100644
--- a/calendar/e-cal-backend-exchange-tasks.c
+++ b/calendar/e-cal-backend-exchange-tasks.c
@@ -1032,7 +1032,7 @@ authenticate_user_task (ECalBackendSync *backend,
 		return;
 	}
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		d(printf ("ECBEC : calendar is offline\n"));
 		return;
 	}
@@ -1107,7 +1107,7 @@ create_task_object (ECalBackendSync *backend,
 
 	e_return_data_cal_error_if_fail (calobj != NULL, InvalidArg);
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		d(printf ("tasks are offline\n"));
 		g_propagate_error (error, EDC_ERROR (RepositoryOffline));
 		return;
@@ -1282,7 +1282,7 @@ modify_task_object (ECalBackendSync *backend,
 	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_EXCHANGE_TASKS (ecalbextask), InvalidArg);
 	e_return_data_cal_error_if_fail (calobj != NULL, InvalidArg);
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		d(printf ("tasks are offline\n"));
 		g_propagate_error (error, EDC_ERROR (RepositoryOffline));
 		return;
@@ -1405,7 +1405,7 @@ receive_task_objects (ECalBackendSync *backend,
 	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_EXCHANGE_TASKS (ecalbextask), InvalidArg);
 	e_return_data_cal_error_if_fail (calobj != NULL, InvalidArg);
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		d(printf ("tasks are offline\n"));
 		g_propagate_error (error, EDC_ERROR (RepositoryOffline));
 		return;
@@ -1490,7 +1490,7 @@ remove_task_object (ECalBackendSync *backend,
 
 	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_EXCHANGE (ecalbex), InvalidArg);
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (backend))) {
+	if (!e_backend_get_online (E_BACKEND (backend))) {
 		d(printf ("tasks are offline\n"));
 		g_propagate_error (error, EDC_ERROR (RepositoryOffline));
 		return;
diff --git a/calendar/e-cal-backend-exchange.c b/calendar/e-cal-backend-exchange.c
index ad00043..052d16e 100644
--- a/calendar/e-cal-backend-exchange.c
+++ b/calendar/e-cal-backend-exchange.c
@@ -160,6 +160,7 @@ load_cache (ECalBackendExchange *cbex,
             E2kUri *e2kuri,
             GError **perror)
 {
+	ESource *source;
 	icalcomponent *vcalcomp, *comp, *tmp_comp;
 	struct icaltimetype comp_last_mod, folder_last_mod;
 	icalcomponent_kind kind;
@@ -170,7 +171,8 @@ load_cache (ECalBackendExchange *cbex,
 	gint i;
 	struct stat buf;
 
-	uristr = e_cal_backend_get_uri (E_CAL_BACKEND (cbex));
+	source = e_backend_get_source (E_BACKEND (cbex));
+	uristr = e_source_get_uri (source);
 	cbex->priv->object_cache_file =
 		e_folder_exchange_get_storage_file (cbex->folder, "cache.ics");
 	if (!cbex->priv->object_cache_file) {
@@ -376,21 +378,23 @@ open_calendar (ECalBackendSync *backend,
 	ExchangeAccountResult acresult;
 	gboolean load_result;
 	E2kUri *euri = NULL;
+	ESource *source;
 
 	d(printf("ecbe_open_calendar(%p, %p, %sonly if exists, user=%s, pass=%s)\n", backend, cal, only_if_exists?"":"not ", username?username:"(null)", password?password:"(null)"));
 
-	uristr = e_cal_backend_get_uri (E_CAL_BACKEND (backend));
+	source = e_backend_get_source (E_BACKEND (backend));
+	uristr = e_source_get_uri (source);
 
 	g_mutex_lock (cbex->priv->open_lock);
 
-	if (!e_cal_backend_is_online (E_CAL_BACKEND (cbex))) {
+	if (!e_backend_get_online (E_BACKEND (cbex))) {
 		ESource *source;
 		const gchar *display_contents = NULL;
 
 		d(printf ("ECBE : cal is offline .. load cache\n"));
 
 		cbex->priv->read_only = TRUE;
-		source = e_cal_backend_get_source (E_CAL_BACKEND (cbex));
+		source = e_backend_get_source (E_BACKEND (cbex));
 		display_contents = e_source_get_property (source, "offline_sync");
 
 		if (!display_contents || !g_str_equal (display_contents, "1")) {
@@ -467,10 +471,12 @@ authenticate_user (ECalBackendSync *backend,
 	E2kHTTPStatus status;
 	E2kResult *results;
 	E2kUri *euri = NULL;
+	ESource *source;
 	gint nresults = 0;
 	guint access = 0;
 
-	uristr = e_cal_backend_get_uri (E_CAL_BACKEND (backend));
+	source = e_backend_get_source (E_BACKEND (backend));
+	uristr = e_source_get_uri (source);
 
 	exchange_account_connect (cbex->account, e_credentials_peek (credentials, E_CREDENTIALS_KEY_PASSWORD), &acresult);
 	if (acresult != EXCHANGE_ACCOUNT_CONNECT_SUCCESS) {
@@ -487,7 +493,7 @@ authenticate_user (ECalBackendSync *backend,
 		 * only_if_exists is FALSE.
 		 */
 
-		source = e_cal_backend_get_source (E_CAL_BACKEND (cbex));
+		source = e_backend_get_source (E_BACKEND (cbex));
 		foreign = e_source_get_property (source, "foreign");
 		favorite = g_strrstr (uristr, ";favorites");
 
@@ -1419,27 +1425,25 @@ start_view (ECalBackend *backend,
 }
 
 static void
-set_online (ECalBackend *backend,
-            gboolean is_online)
+notify_online_cb (ECalBackend *backend,
+                  GParamSpec *pspec)
 {
 	ECalBackendExchange *cbex;
 	ECalBackendExchangePrivate *priv;
-	gboolean re_open = FALSE;
+	gboolean online;
 
 	cbex = E_CAL_BACKEND_EXCHANGE (backend);
 	priv = cbex->priv;
 
-	d(printf("ecbe_set_online(%p) : online : %d\n", backend, is_online ? 1 :0));
-
-	re_open = is_online && !e_cal_backend_is_online (backend);
-	e_cal_backend_notify_online (backend, is_online);
+	online = e_backend_get_online (E_BACKEND (backend));
+	e_cal_backend_notify_online (backend, online);
 
 	g_mutex_lock (priv->set_lock);
 
-	if (is_online) {
+	if (online) {
 		priv->read_only = FALSE;
 
-		if (e_cal_backend_is_opened (backend) && re_open)
+		if (e_cal_backend_is_opened (backend))
 			e_cal_backend_notify_auth_required (backend, TRUE, NULL);
 	} else {
 		priv->read_only = TRUE;
@@ -2151,7 +2155,6 @@ e_cal_backend_exchange_class_init (ECalBackendExchangeClass *class)
 
 	backend_class = E_CAL_BACKEND_CLASS (class);
 	backend_class->start_view = start_view;
-	backend_class->set_online = set_online;
 	backend_class->internal_get_timezone = internal_get_timezone;
 
 	sync_class = E_CAL_BACKEND_SYNC_CLASS (class);
@@ -2188,5 +2191,9 @@ e_cal_backend_exchange_init (ECalBackendExchange *cbex)
 	cbex->priv->cache_unseen = NULL;
 
 	e_cal_backend_sync_set_lock (E_CAL_BACKEND_SYNC (cbex), TRUE);
+
+	g_signal_connect (
+		cbex, "notify::online",
+		G_CALLBACK (notify_online_cb), NULL);
 }
 



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