[evolution-ews] Bug 662224 - Make it compile against 3.3.1 of eds/evo



commit 8cf26212917f036abec59af831a28732fe491e6e
Author: Milan Crha <mcrha redhat com>
Date:   Wed Oct 19 18:35:44 2011 +0100

    Bug 662224 - Make it compile against 3.3.1 of eds/evo

 configure.ac                                       |    4 +-
 .../exchange-ews-account-listener.c                |    2 +-
 .../exchange-ews-account-setup.c                   |    2 +-
 src/addressbook/e-book-backend-ews-factory.c       |   46 ++-
 src/addressbook/e-book-backend-ews.c               |  518 ++++++++++----------
 src/calendar/Makefile.am                           |    1 -
 src/calendar/e-cal-backend-ews-factory.c           |  201 +++------
 src/calendar/e-cal-backend-ews-factory.h           |   36 --
 src/calendar/e-cal-backend-ews.c                   |  473 ++-----------------
 src/camel/Makefile.am                              |    2 +
 src/camel/camel-ews-folder.c                       |   73 +++-
 src/camel/camel-ews-provider.c                     |   10 +-
 src/camel/camel-ews-store.c                        |   16 +-
 src/camel/camel-ews-summary.c                      |  191 +-------
 src/camel/camel-ews-summary.h                      |    3 -
 src/camel/camel-ews-utils.c                        |   21 +-
 16 files changed, 491 insertions(+), 1108 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3fceb11..35625e2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,7 +147,7 @@ PKG_CHECK_MODULES(LIBECAL, libecal-1.2 >= eds_minimum_version)
 PKG_CHECK_MODULES(LIBEDATACAL, libedata-cal-1.2 >= eds_minimum_version)
 PKG_CHECK_MODULES(LIBBOOK, libebook-1.2 >= eds_minimum_version)
 PKG_CHECK_MODULES(LIBEDATABOOK, libedata-book-1.2 >= eds_minimum_version)
-PKG_CHECK_MODULES(CAMEL, camel-provider-1.2 >= eds_minimum_version)
+PKG_CHECK_MODULES(CAMEL, camel-1.2 >= eds_minimum_version)
 
 dnl ****************************
 dnl Check for evolution plugins 
@@ -193,7 +193,7 @@ dnl *******************
 plugindir=`$PKG_CONFIG --variable=plugindir evolution-plugin-3.0`
 AC_SUBST(plugindir)
 
-camel_providerdir=`$PKG_CONFIG --variable=camel_providerdir camel-provider-1.2`
+camel_providerdir=`$PKG_CONFIG --variable=camel_providerdir camel-1.2`
 AC_SUBST(camel_providerdir) 
 
 privincludedir=`$PKG_CONFIG --variable=privincludedir libedataserver-1.2`
diff --git a/src/account-setup-eplugin/exchange-ews-account-listener.c b/src/account-setup-eplugin/exchange-ews-account-listener.c
index abfa23c..5bcb8d2 100644
--- a/src/account-setup-eplugin/exchange-ews-account-listener.c
+++ b/src/account-setup-eplugin/exchange-ews-account-listener.c
@@ -239,7 +239,7 @@ add_gal_esource (CamelURL *url)
 	} else
 		oal_name = _("Global Address list");
 
-	account_uri = camel_url_to_string (url, CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS);
+	account_uri = camel_url_to_string (url, CAMEL_URL_HIDE_PARAMS);
 	source_uri = g_strdup_printf ("%s;gal=1", account_uri + strlen (EWS_BASE_URI));
 	source = e_source_new (oal_name, source_uri);
 	
diff --git a/src/account-setup-eplugin/exchange-ews-account-setup.c b/src/account-setup-eplugin/exchange-ews-account-setup.c
index 8f48014..ac646fd 100644
--- a/src/account-setup-eplugin/exchange-ews-account-setup.c
+++ b/src/account-setup-eplugin/exchange-ews-account-setup.c
@@ -135,7 +135,7 @@ get_password (EMConfigTargetAccount *target_account)
 	account = get_modified_account (target_account);
 	url = camel_url_new (e_account_get_string (account, E_ACCOUNT_SOURCE_URL), NULL);
 
-	key = camel_url_to_string (url, CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS);
+	key = camel_url_to_string (url, CAMEL_URL_HIDE_PARAMS);
 	password = e_passwords_get_password (EXCHANGE_EWS_PASSWORD_COMPONENT, key);
 	if (!password || !*password) {
 		gboolean remember = e_account_get_bool (account, E_ACCOUNT_SOURCE_SAVE_PASSWD);
diff --git a/src/addressbook/e-book-backend-ews-factory.c b/src/addressbook/e-book-backend-ews-factory.c
index bd44c74..8f736fb 100644
--- a/src/addressbook/e-book-backend-ews-factory.c
+++ b/src/addressbook/e-book-backend-ews-factory.c
@@ -25,28 +25,48 @@
 #include <config.h>
 #endif
 
-#include "libebackend/e-data-server-module.h"
-#include "libedata-book/e-book-backend-factory.h"
+#include <libedata-book/e-book-backend-factory.h>
 #include "e-book-backend-ews.h"
 
-E_BOOK_BACKEND_FACTORY_SIMPLE (ews, Ews, e_book_backend_ews_new)
+typedef EBookBackendFactory EBookBackendEwsFactory;
+typedef EBookBackendFactoryClass EBookBackendEwsFactoryClass;
 
-static GType  ews_types [1];
+/* Module Entry Points */
+void e_module_load (GTypeModule *type_module);
+void e_module_unload (GTypeModule *type_module);
 
-void
-eds_module_initialize (GTypeModule *module)
+/* Forward Declarations */
+GType e_book_backend_ews_factory_get_type (void);
+
+G_DEFINE_DYNAMIC_TYPE (
+	EBookBackendEwsFactory,
+	e_book_backend_ews_factory,
+	E_TYPE_BOOK_BACKEND_FACTORY)
+
+static void
+e_book_backend_ews_factory_class_init (EBookBackendFactoryClass *class)
+{
+	class->factory_name = "ews";
+	class->backend_type = E_TYPE_BOOK_BACKEND_EWS;
+}
+
+static void
+e_book_backend_ews_factory_class_finalize (EBookBackendFactoryClass *class)
+{
+}
+
+static void
+e_book_backend_ews_factory_init (EBookBackendFactory *factory)
 {
-	ews_types[0] = _ews_factory_get_type (module);
 }
 
-void
-eds_module_shutdown   (void)
+G_MODULE_EXPORT void
+e_module_load (GTypeModule *type_module)
 {
+	e_book_backend_ews_factory_register_type (type_module);
 }
 
-void
-eds_module_list_types (const GType **types, gint *num_types)
+G_MODULE_EXPORT void
+e_module_unload (GTypeModule *type_module)
 {
-	*types = ews_types;
-	*num_types = G_N_ELEMENTS (ews_types);
 }
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index f45a065..111f649 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -85,7 +85,7 @@ struct _EBookBackendEwsPrivate {
 	gboolean marked_for_offline;
 	gboolean cache_ready;
 	gboolean is_gal;
-	gint mode;
+	gboolean is_online;
 
 	GHashTable *ops;
 
@@ -753,8 +753,13 @@ ews_create_contact_cb(GObject *object, GAsyncResult *res, gpointer user_data)
 		e_contact_set (create_contact->contact, E_CONTACT_REV, item_id->change_key);
 		e_book_backend_sqlitedb_add_contact (ebews->priv->ebsdb, ebews->priv->folder_id, create_contact->contact, FALSE, &error);
 
-		if (error == NULL)
-			e_data_book_respond_create (create_contact->book, create_contact->opid, EDB_ERROR (SUCCESS), create_contact->contact);
+		if (error == NULL) {
+			GSList *contacts;
+
+			contacts = g_slist_append (NULL, create_contact->contact);
+			e_data_book_respond_create_contacts (create_contact->book, create_contact->opid, EDB_ERROR (SUCCESS), contacts);
+			g_slist_free (contacts);
+		}
 
 		g_object_unref (item);
 		g_slist_free (items);
@@ -762,7 +767,7 @@ ews_create_contact_cb(GObject *object, GAsyncResult *res, gpointer user_data)
 	
 	if (error) {
 		g_warning("Error while Creating contact: %s", error->message);
-		e_data_book_respond_create (create_contact->book, create_contact->opid, EDB_ERROR_EX (OTHER_ERROR, error->message), create_contact->contact);
+		e_data_book_respond_create_contacts (create_contact->book, create_contact->opid, EDB_ERROR_EX (OTHER_ERROR, error->message), NULL);
 	}
 
 	/* free memory allocated for create_contact & unref contained objects */
@@ -773,70 +778,72 @@ ews_create_contact_cb(GObject *object, GAsyncResult *res, gpointer user_data)
 }
 
 static void
-e_book_backend_ews_create_contact	(EBookBackend *backend,
+e_book_backend_ews_create_contacts	(EBookBackend *backend,
 					 EDataBook *book,
 					 guint32 opid,
 					 GCancellable *cancellable,
-					 const gchar *vcard )
+					 const GSList *vcards)
 {
 	EContact *contact = NULL;
 	EBookBackendEws *ebews;
 	EwsCreateContact *create_contact;
 	EBookBackendEwsPrivate *priv;
  
+	if (vcards->next != NULL) {
+		e_data_book_respond_create_contacts (book, opid,
+		                                     EDB_ERROR_EX (NOT_SUPPORTED,
+		                                     _("The backend does not support bulk additions")),
+		                                     NULL);
+		return;
+	}
+
 	ebews = E_BOOK_BACKEND_EWS (backend);
 	priv = ebews->priv;
 
-	switch (ebews->priv->mode) {
-	case MODE_LOCAL :
+	if (!priv->is_online) {
 		if (!priv->is_writable) {
-			e_data_book_respond_modify (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
+			e_data_book_respond_create_contacts (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
 			return;
 		}
 
-		e_data_book_respond_create (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
+		e_data_book_respond_create_contacts (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
 		return;
+	}
 
-	case  MODE_REMOTE :
-
-		if (ebews->priv->cnc == NULL) {
-			e_data_book_respond_create (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
-			return;
-		}
-
-		if (!ebews->priv->is_writable) {
-			e_data_book_respond_create (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
-			return;
-		}
+	if (ebews->priv->cnc == NULL) {
+		e_data_book_respond_create_contacts (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
+		return;
+	}
 
-		contact = e_contact_new_from_vcard (vcard);
-		
-		if (e_contact_get (contact, E_CONTACT_IS_LIST)) {
-			g_object_unref (contact);
-			e_data_book_respond_create (book, opid, EDB_ERROR (NOT_SUPPORTED), NULL);
-			return;
-		}
+	if (!ebews->priv->is_writable) {
+		e_data_book_respond_create_contacts (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
+		return;
+	}
 
-		create_contact = g_new0(EwsCreateContact, 1);
-		create_contact->ebews = g_object_ref(ebews);
-		create_contact->book = g_object_ref(book);
-		create_contact->opid = opid;
-		create_contact->contact = g_object_ref(contact);
-
-		/* pass new contact component data to the exchange server and expect response in the callback */
-		e_ews_connection_create_items_start (priv->cnc,
-						     EWS_PRIORITY_MEDIUM, NULL,
-						     NULL,
-						     priv->folder_id,
-						     convert_contact_to_xml,
-						     contact,
-						     ews_create_contact_cb,
-						     cancellable,
-						     create_contact);
+	contact = e_contact_new_from_vcard (vcards->data);
+	
+	if (e_contact_get (contact, E_CONTACT_IS_LIST)) {
+		g_object_unref (contact);
+		e_data_book_respond_create_contacts (book, opid, EDB_ERROR (NOT_SUPPORTED), NULL);
 		return;
-	default:
-		break;
 	}
+
+	create_contact = g_new0(EwsCreateContact, 1);
+	create_contact->ebews = g_object_ref(ebews);
+	create_contact->book = g_object_ref(book);
+	create_contact->opid = opid;
+	create_contact->contact = g_object_ref(contact);
+
+	/* pass new contact component data to the exchange server and expect response in the callback */
+	e_ews_connection_create_items_start (priv->cnc,
+					     EWS_PRIORITY_MEDIUM, NULL,
+					     NULL,
+					     priv->folder_id,
+					     convert_contact_to_xml,
+					     contact,
+					     ews_create_contact_cb,
+					     cancellable,
+					     create_contact);
 }
 
 typedef struct {
@@ -892,41 +899,36 @@ e_book_backend_ews_remove_contacts	(EBookBackend *backend,
  
 	priv = ebews->priv;
 
-	switch (ebews->priv->mode) {
-	case MODE_LOCAL :
+	if (!priv->is_online) {
 		if (!priv->is_writable) {
-			e_data_book_respond_modify (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
+			e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
 			return;
 		}
 
 		e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
 		return;
+	}
 
-	case MODE_REMOTE :
-		if (ebews->priv->cnc == NULL) {
-			e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
-			return;
-		}
-
-		if (!ebews->priv->is_writable) {
-			e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
-			return;
-		}
-
-		remove_contact = g_new0(EwsRemoveContact, 1);
-		remove_contact->ebews = g_object_ref(ebews);
-		remove_contact->book = g_object_ref(book);
-		remove_contact->opid = opid;
-		remove_contact->sl_ids = (GSList *) id_list;
+	if (ebews->priv->cnc == NULL) {
+		e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
+		return;
+	}
 
-		e_ews_connection_delete_items_start (priv->cnc, EWS_PRIORITY_MEDIUM, (GSList *) id_list,
-						     EWS_HARD_DELETE, 0 , FALSE,
-						     ews_book_remove_contact_cb, cancellable,
-						     remove_contact);
+	if (!ebews->priv->is_writable) {
+		e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
 		return;
-	default :
-		break;
 	}
+
+	remove_contact = g_new0(EwsRemoveContact, 1);
+	remove_contact->ebews = g_object_ref(ebews);
+	remove_contact->book = g_object_ref(book);
+	remove_contact->opid = opid;
+	remove_contact->sl_ids = (GSList *) id_list;
+
+	e_ews_connection_delete_items_start (priv->cnc, EWS_PRIORITY_MEDIUM, (GSList *) id_list,
+					     EWS_HARD_DELETE, 0 , FALSE,
+					     ews_book_remove_contact_cb, cancellable,
+					     remove_contact);
 }
 
 typedef struct {
@@ -969,8 +971,13 @@ ews_modify_contact_cb (GObject *object, GAsyncResult *res, gpointer user_data)
 		e_book_backend_sqlitedb_remove_contact (priv->ebsdb, priv->folder_id, id, &error);
 		e_book_backend_sqlitedb_add_contact (ebews->priv->ebsdb, ebews->priv->folder_id, modify_contact->new_contact, FALSE, &error);
 
-		if (error == NULL)
-			e_data_book_respond_modify (modify_contact->book, modify_contact->opid, EDB_ERROR (SUCCESS), modify_contact->new_contact);
+		if (error == NULL) {
+			GSList *new_contacts;
+
+			new_contacts = g_slist_append (NULL, modify_contact->new_contact);
+			e_data_book_respond_modify_contacts (modify_contact->book, modify_contact->opid, EDB_ERROR (SUCCESS), new_contacts);
+			g_slist_free (new_contacts);
+		}
 
 		g_object_unref (item);
 		g_slist_free (items);
@@ -978,7 +985,8 @@ ews_modify_contact_cb (GObject *object, GAsyncResult *res, gpointer user_data)
 	
 	if (error) {
 		g_warning("Error while Modifying contact: %s", error->message);
-		e_data_book_respond_modify (modify_contact->book, modify_contact->opid, EDB_ERROR_EX (OTHER_ERROR, error->message), modify_contact->new_contact);
+
+		e_data_book_respond_modify_contacts (modify_contact->book, modify_contact->opid, EDB_ERROR_EX (OTHER_ERROR, error->message), NULL);
 	}
 
 	/* free memory allocated for create_contact & unref contained objects */
@@ -1032,11 +1040,11 @@ convert_contact_to_updatexml (ESoapMessage *msg, gpointer user_data)
 }
 
 static void
-e_book_backend_ews_modify_contact	(EBookBackend *backend,
+e_book_backend_ews_modify_contacts	(EBookBackend *backend,
 					 EDataBook    *book,
 					 guint32       opid,
 					 GCancellable *cancellable,
-					 const gchar   *vcard)
+					 const GSList *vcards)
 {
 	EContact *contact = NULL, *old_contact;
 	EwsModifyContact *modify_contact;
@@ -1045,71 +1053,72 @@ e_book_backend_ews_modify_contact	(EBookBackend *backend,
 	EBookBackendEwsPrivate *priv;
 	GError *error;
 
+	if (vcards->next != NULL) {
+		e_data_book_respond_modify_contacts (book, opid,
+		                                     EDB_ERROR_EX (NOT_SUPPORTED,
+		                                     _("The backend does not support bulk modifications")),
+		                                     NULL);
+		return;
+	}
 
 	ebews = E_BOOK_BACKEND_EWS (backend);
 	priv = ebews->priv;
 
-	switch (priv->mode) {
-
-	case MODE_LOCAL :
+	if (!priv->is_online) {
 		if (!priv->is_writable) {
-			e_data_book_respond_modify (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
+			e_data_book_respond_modify_contacts (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
 			return;
 		}
 
-		e_data_book_respond_modify (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
+		e_data_book_respond_modify_contacts (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
 		return;
-	case MODE_REMOTE :
-
-		if (priv->cnc == NULL) {
-			e_data_book_respond_modify (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
-			return;
-		}
-		
-		if (!priv->is_writable) {
-			e_data_book_respond_modify (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
-			return;
-		}
-		
-		contact = e_contact_new_from_vcard (vcard);
+	}
 
-		id = g_new0 (EwsId, 1);
-		id->id = e_contact_get (contact, E_CONTACT_UID);
-		id->change_key = e_contact_get (contact, E_CONTACT_REV);
+	if (priv->cnc == NULL) {
+		e_data_book_respond_modify_contacts (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
+		return;
+	}
+	
+	if (!priv->is_writable) {
+		e_data_book_respond_modify_contacts (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
+		return;
+	}
+	
+	contact = e_contact_new_from_vcard (vcards->data);
 
-		/*get item id and change key from contact and fetch old contact and assign.*/
+	id = g_new0 (EwsId, 1);
+	id->id = e_contact_get (contact, E_CONTACT_UID);
+	id->change_key = e_contact_get (contact, E_CONTACT_REV);
 
-		if (e_contact_get (contact, E_CONTACT_IS_LIST)) {
-			g_object_unref (contact);
-			e_data_book_respond_modify (book, opid, EDB_ERROR (NOT_SUPPORTED), NULL);
-			return;
-		}
+	/*get item id and change key from contact and fetch old contact and assign.*/
 
-		old_contact = e_book_backend_sqlitedb_get_contact ( priv->ebsdb, priv->folder_id,
-					 id->id, NULL, NULL, &error); 
-		if (!old_contact) {
-			g_object_unref (contact);
-			e_data_book_respond_modify (book, opid, EDB_ERROR (NOT_SUPPORTED), NULL);
-			return;
-		}
+	if (e_contact_get (contact, E_CONTACT_IS_LIST)) {
+		g_object_unref (contact);
+		e_data_book_respond_modify_contacts (book, opid, EDB_ERROR (NOT_SUPPORTED), NULL);
+		return;
+	}
 
-		/* TODO implement */
-		modify_contact = g_new0 (EwsModifyContact, 1);
-		modify_contact->ebews = g_object_ref(ebews);
-		modify_contact->book = g_object_ref(book);
-		modify_contact->opid = opid;
-		modify_contact->old_contact = g_object_ref(old_contact);
-		modify_contact->new_contact = g_object_ref(contact);
-		e_ews_connection_update_items_start (priv->cnc, EWS_PRIORITY_MEDIUM,
-							"AlwaysOverwrite", "SendAndSaveCopy",
-							"SendToAllAndSaveCopy", priv->folder_id,
-							convert_contact_to_updatexml, modify_contact,
-							ews_modify_contact_cb, cancellable,
-							modify_contact);
+	old_contact = e_book_backend_sqlitedb_get_contact ( priv->ebsdb, priv->folder_id,
+				 id->id, NULL, NULL, &error); 
+	if (!old_contact) {
+		g_object_unref (contact);
+		e_data_book_respond_modify_contacts (book, opid, EDB_ERROR (NOT_SUPPORTED), NULL);
 		return;
-	default :
-		break;
 	}
+
+	/* TODO implement */
+	modify_contact = g_new0 (EwsModifyContact, 1);
+	modify_contact->ebews = g_object_ref(ebews);
+	modify_contact->book = g_object_ref(book);
+	modify_contact->opid = opid;
+	modify_contact->old_contact = g_object_ref(old_contact);
+	modify_contact->new_contact = g_object_ref(contact);
+	e_ews_connection_update_items_start (priv->cnc, EWS_PRIORITY_MEDIUM,
+						"AlwaysOverwrite", "SendAndSaveCopy",
+						"SendToAllAndSaveCopy", priv->folder_id,
+						convert_contact_to_updatexml, modify_contact,
+						ews_modify_contact_cb, cancellable,
+						modify_contact);
 }
 
 static void
@@ -1123,22 +1132,16 @@ e_book_backend_ews_get_contact	(EBookBackend *backend,
 
 	gwb =  E_BOOK_BACKEND_EWS (backend);
 
-	switch (gwb->priv->mode) {
-
-	case MODE_LOCAL :
+	if (!gwb->priv->is_online) {
 		e_data_book_respond_get_contact (book, opid, EDB_ERROR (CONTACT_NOT_FOUND), "");
 		return;
+	}
 
-	case MODE_REMOTE :
-		if (gwb->priv->cnc == NULL) {
-			e_data_book_respond_get_contact (book, opid, e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR, "Not connected"), NULL);
-			return;
-		}
-		e_data_book_respond_get_contact (book, opid, EDB_ERROR (CONTACT_NOT_FOUND), "");
+	if (gwb->priv->cnc == NULL) {
+		e_data_book_respond_get_contact (book, opid, e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR, "Not connected"), NULL);
 		return;
-	default :
-		break;
 	}
+	e_data_book_respond_get_contact (book, opid, EDB_ERROR (CONTACT_NOT_FOUND), "");
 }
 
 static void
@@ -1154,26 +1157,17 @@ e_book_backend_ews_get_contact_list	(EBookBackend *backend,
 	egwb = E_BOOK_BACKEND_EWS (backend);
 	vcard_list = NULL;
 
-	switch (egwb->priv->mode) {
-
-	case MODE_LOCAL :
-
+	if (!egwb->priv->is_online) {
 		e_data_book_respond_get_contact_list (book, opid, EDB_ERROR (SUCCESS), vcard_list);
 		return;
+	}
 
-	case MODE_REMOTE:
-
-		if (egwb->priv->cnc == NULL) {
-			e_data_book_respond_get_contact_list (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
-			return;
-		}
-
-		e_data_book_respond_get_contact_list (book, opid, EDB_ERROR (SUCCESS), vcard_list);
+	if (egwb->priv->cnc == NULL) {
+		e_data_book_respond_get_contact_list (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
 		return;
-	default :
-		break;
-
 	}
+
+	e_data_book_respond_get_contact_list (book, opid, EDB_ERROR (SUCCESS), vcard_list);
 }
 
 typedef struct {
@@ -1990,9 +1984,8 @@ ebews_start_refreshing (EBookBackendEws *ebews)
 
 	PRIV_LOCK (priv);
 
-	if	(priv->mode == MODE_REMOTE &&
-		 priv->cnc && priv->marked_for_offline)
-				fetch_deltas (ebews);
+	if (priv->is_online && priv->cnc && priv->marked_for_offline)
+		fetch_deltas (ebews);
 
 	PRIV_UNLOCK (priv);
 }
@@ -2051,8 +2044,7 @@ e_book_backend_ews_start_book_view (EBookBackend  *backend,
 	e_data_book_view_ref (book_view);
 	e_data_book_view_notify_progress (book_view, -1, _("Searching..."));
 
-	switch (priv->mode) {
-	case MODE_LOCAL:
+	if (!priv->is_online) {
 		if (e_book_backend_sqlitedb_get_is_populated (priv->ebsdb, priv->folder_id, NULL)) {
 			fetch_from_offline (ebews, book_view, query, error);
 			return;
@@ -2062,84 +2054,82 @@ e_book_backend_ews_start_book_view (EBookBackend  *backend,
 		e_data_book_view_notify_complete (book_view, error);
 		g_error_free (error);
 		return;
-	case MODE_REMOTE:
-		if (!priv->cnc) {
-			error = EDB_ERROR (AUTHENTICATION_REQUIRED);
-			ews_auth_required (backend);
-			e_data_book_view_notify_complete (book_view, error);
-			e_data_book_view_unref (book_view);
-			g_error_free (error);
-			return;
-		}
+	}
 
-		ebews_start_refreshing (ebews);
+	if (!priv->cnc) {
+		error = EDB_ERROR (AUTHENTICATION_REQUIRED);
+		ews_auth_required (backend);
+		e_data_book_view_notify_complete (book_view, error);
+		e_data_book_view_unref (book_view);
+		g_error_free (error);
+		return;
+	}
 
-		if (e_book_backend_sqlitedb_get_is_populated (priv->ebsdb, priv->folder_id, NULL)) {
-			fetch_from_offline (ebews, book_view, query, error);
-			return;
-		}
+	ebews_start_refreshing (ebews);
 
-		e_book_backend_ews_build_restriction (query, &is_autocompletion, &auto_comp_str);
-		if (!is_autocompletion || !auto_comp_str) {
-			g_free (auto_comp_str);
-			e_data_book_view_notify_complete (book_view, error);
-			e_data_book_view_unref (book_view);
-			return;
-		}
+	if (e_book_backend_sqlitedb_get_is_populated (priv->ebsdb, priv->folder_id, NULL)) {
+		fetch_from_offline (ebews, book_view, query, error);
+		return;
+	}
 
-		source = e_book_backend_get_source (backend);
-		cancellable = g_cancellable_new ();
-
-		/* FIXME Need to convert the Ids from EwsLegacyId format to EwsId format using
-		   convert_id operation before using it as the schema has changed between Exchange
-		   2007 and 2007_SP1 */
-		fid = g_new0 (EwsFolderId, 1);
-		fid->id = g_strdup (priv->folder_id);
-		fid->change_key = e_source_get_duped_property (source, "change-key");
-		ids = g_slist_append (ids, fid);
-
-		/* We do not scan until we reach the last_item as it might be good enough to show first 100
-		   items during auto-completion. Change it if needed. TODO, Personal Address-book should start using
-		   find_items rather than resolve_names to support all queries */
-		g_hash_table_insert (priv->ops, book_view, cancellable);
-		e_ews_connection_resolve_names	(priv->cnc, EWS_PRIORITY_MEDIUM, auto_comp_str,
-						 EWS_SEARCH_AD, NULL, FALSE, &mailboxes, NULL,
-						 &includes_last_item, cancellable, &error);
+	e_book_backend_ews_build_restriction (query, &is_autocompletion, &auto_comp_str);
+	if (!is_autocompletion || !auto_comp_str) {
 		g_free (auto_comp_str);
-		g_hash_table_remove (priv->ops, book_view);
-		e_ews_folder_free_fid (fid);
-		if (error != NULL) {
-			e_data_book_view_notify_complete (book_view, error);
-			e_data_book_view_unref (book_view);
-			g_clear_error (&error);
-			return;
-		}
+		e_data_book_view_notify_complete (book_view, error);
+		e_data_book_view_unref (book_view);
+		return;
+	}
+
+	source = e_backend_get_source (E_BACKEND (backend));
+	cancellable = g_cancellable_new ();
 
-		for (l = mailboxes; l != NULL; l = g_slist_next (l)) {
-			EwsMailbox *mb = l->data;
-			EContact *contact;
+	/* FIXME Need to convert the Ids from EwsLegacyId format to EwsId format using
+	   convert_id operation before using it as the schema has changed between Exchange
+	   2007 and 2007_SP1 */
+	fid = g_new0 (EwsFolderId, 1);
+	fid->id = g_strdup (priv->folder_id);
+	fid->change_key = e_source_get_duped_property (source, "change-key");
+	ids = g_slist_append (ids, fid);
+
+	/* We do not scan until we reach the last_item as it might be good enough to show first 100
+	   items during auto-completion. Change it if needed. TODO, Personal Address-book should start using
+	   find_items rather than resolve_names to support all queries */
+	g_hash_table_insert (priv->ops, book_view, cancellable);
+	e_ews_connection_resolve_names	(priv->cnc, EWS_PRIORITY_MEDIUM, auto_comp_str,
+					 EWS_SEARCH_AD, NULL, FALSE, &mailboxes, NULL,
+					 &includes_last_item, cancellable, &error);
+	g_free (auto_comp_str);
+	g_hash_table_remove (priv->ops, book_view);
+	e_ews_folder_free_fid (fid);
+	if (error != NULL) {
+		e_data_book_view_notify_complete (book_view, error);
+		e_data_book_view_unref (book_view);
+		g_clear_error (&error);
+		return;
+	}
 
-			contact = e_contact_new ();
+	for (l = mailboxes; l != NULL; l = g_slist_next (l)) {
+		EwsMailbox *mb = l->data;
+		EContact *contact;
 
-			/* We do not get an id from the server, so just using email_id as uid for now */
-			e_contact_set (contact, E_CONTACT_UID, mb->email);
-			e_contact_set (contact, E_CONTACT_FULL_NAME, mb->name);
-			e_contact_set (contact, E_CONTACT_EMAIL_1, mb->email);
+		contact = e_contact_new ();
 
-			e_data_book_view_notify_update (book_view, contact);
+		/* We do not get an id from the server, so just using email_id as uid for now */
+		e_contact_set (contact, E_CONTACT_UID, mb->email);
+		e_contact_set (contact, E_CONTACT_FULL_NAME, mb->name);
+		e_contact_set (contact, E_CONTACT_EMAIL_1, mb->email);
 
-			g_free (mb->email);
-			g_free (mb->name);
-			g_free (mb);
-			g_object_unref (contact);
-		}
+		e_data_book_view_notify_update (book_view, contact);
 
-		g_slist_free (mailboxes);
-		e_data_book_view_notify_complete (book_view, error);
-		e_data_book_view_unref (book_view);
-	default:
-		break;
+		g_free (mb->email);
+		g_free (mb->name);
+		g_free (mb);
+		g_object_unref (contact);
 	}
+
+	g_slist_free (mailboxes);
+	e_data_book_view_notify_complete (book_view, error);
+	e_data_book_view_unref (book_view);
 }
 
 static void
@@ -2216,8 +2206,8 @@ e_book_backend_ews_load_source 	(EBookBackend           *backend,
 	}
 	
 	e_book_backend_notify_opened (backend, NULL);
-	if (priv->mode == MODE_REMOTE)
-		e_book_backend_set_online (backend, TRUE);
+	if (priv->is_online)
+		e_backend_set_online (E_BACKEND (backend), TRUE);
 }
 
 static void
@@ -2245,55 +2235,54 @@ e_book_backend_ews_authenticate_user (EBookBackend *backend,
 	ebgw = E_BOOK_BACKEND_EWS (backend);
 	priv = ebgw->priv;
 
-	switch (ebgw->priv->mode) {
-	case MODE_LOCAL:
+	if (!ebgw->priv->is_online) {
 		e_book_backend_notify_opened (backend, EDB_ERROR (SUCCESS));
 		return;
+	}
 
-	case MODE_REMOTE:
-		if (priv->cnc) {
-			e_book_backend_notify_opened (backend, EDB_ERROR (SUCCESS));
-			return;
-		}
+	if (priv->cnc) {
+		e_book_backend_notify_opened (backend, EDB_ERROR (SUCCESS));
+		return;
+	}
 
-		esource = e_book_backend_get_source (backend);
-		host_url = e_source_get_property (esource, "hosturl");
-		read_only = e_source_get_property (esource, "read_only");
+	esource = e_backend_get_source (E_BACKEND (backend));
+	host_url = e_source_get_property (esource, "hosturl");
+	read_only = e_source_get_property (esource, "read_only");
 
-		priv->cnc = e_ews_connection_new (host_url, e_credentials_peek (credentials, E_CREDENTIALS_KEY_USERNAME), 
-						  e_credentials_peek (credentials, E_CREDENTIALS_KEY_PASSWORD),
-						  NULL, NULL, &error);
+	priv->cnc = e_ews_connection_new (host_url, e_credentials_peek (credentials, E_CREDENTIALS_KEY_USERNAME), 
+					  e_credentials_peek (credentials, E_CREDENTIALS_KEY_PASSWORD),
+					  NULL, NULL, &error);
 
-		if ((read_only && !strcmp (read_only, "true")) || priv->is_gal) {
-			priv->is_writable = FALSE;
-		} else 
-			priv->is_writable = TRUE;
+	if ((read_only && !strcmp (read_only, "true")) || priv->is_gal) {
+		priv->is_writable = FALSE;
+	} else 
+		priv->is_writable = TRUE;
 
-		priv->username = e_source_get_duped_property (esource, "username");
-		priv->password = g_strdup (e_credentials_peek (credentials, E_CREDENTIALS_KEY_PASSWORD));
-	
-		/* FIXME: Do some dummy request to ensure that the password is actually
-		   correct; don't just blindly return success */
-		e_book_backend_notify_opened (backend, EDB_ERROR (SUCCESS));
-		e_book_backend_notify_readonly (backend, !priv->is_writable);
-		return;
-	default :
-		break;
-	}
+	priv->username = e_source_get_duped_property (esource, "username");
+	priv->password = g_strdup (e_credentials_peek (credentials, E_CREDENTIALS_KEY_PASSWORD));
+
+	/* FIXME: Do some dummy request to ensure that the password is actually
+	   correct; don't just blindly return success */
+	e_book_backend_notify_opened (backend, EDB_ERROR (SUCCESS));
+	e_book_backend_notify_readonly (backend, !priv->is_writable);
 }	
 
 static void
-e_book_backend_ews_set_online (EBookBackend *backend,
-                                     gboolean is_online)
+e_book_backend_ews_notify_online_cb (EBookBackend *backend,
+				     GParamSpec *spec)
 {
 	EBookBackendEws *ebews;
+	gboolean is_online;
 
 	ebews = E_BOOK_BACKEND_EWS (backend);
-	
-	if (is_online)
-		ebews->priv->mode = MODE_REMOTE;
-	else
-		ebews->priv->mode = MODE_LOCAL;
+
+	is_online = e_backend_get_online (E_BACKEND (backend));
+
+	if ((ebews->priv->is_online ? 1 : 0) == (is_online ? 1 : 0))
+		return;
+
+	ebews->priv->is_online = is_online;
+
 	if (e_book_backend_is_opened (backend)) {
 		if (!is_online) {
 			e_book_backend_notify_readonly (backend, TRUE);
@@ -2373,7 +2362,7 @@ e_book_backend_ews_open (EBookBackend *backend,
 	GError *error = NULL;
 	ESource *source;
 
-	source = e_book_backend_get_source (backend);
+	source = e_backend_get_source (E_BACKEND (backend));
 	e_book_backend_ews_load_source (backend, source, only_if_exists, &error);
 	e_data_book_respond_open (book, opid, error);
 }
@@ -2480,11 +2469,10 @@ e_book_backend_ews_class_init (EBookBackendEwsClass *klass)
 	/* Set the virtual methods. */
 	parent_class->open		      = e_book_backend_ews_open;
 	parent_class->get_backend_property    = e_book_backend_ews_get_backend_property;
-	parent_class->set_online	      = e_book_backend_ews_set_online;
 
-	parent_class->create_contact          = e_book_backend_ews_create_contact;
+	parent_class->create_contacts         = e_book_backend_ews_create_contacts;
 	parent_class->remove_contacts         = e_book_backend_ews_remove_contacts;
-	parent_class->modify_contact          = e_book_backend_ews_modify_contact;
+	parent_class->modify_contacts         = e_book_backend_ews_modify_contacts;
 	parent_class->get_contact             = e_book_backend_ews_get_contact;
 	parent_class->get_contact_list        = e_book_backend_ews_get_contact_list;
 	parent_class->remove                  = e_book_backend_ews_remove;
@@ -2508,4 +2496,8 @@ e_book_backend_ews_init (EBookBackendEws *backend)
 
 	bews->priv = priv;
 	g_static_rec_mutex_init (&priv->rec_mutex);
+
+	g_signal_connect (
+		bews, "notify::online",
+		G_CALLBACK (e_book_backend_ews_notify_online_cb), NULL);
 }
diff --git a/src/calendar/Makefile.am b/src/calendar/Makefile.am
index 0cef280..8ebbd24 100644
--- a/src/calendar/Makefile.am
+++ b/src/calendar/Makefile.am
@@ -21,7 +21,6 @@ libecalbackendews_la_SOURCES =				\
 	libedata-cal-compat.h				\
 	libedata-cal-compat.c				\
 	e-cal-backend-ews-factory.c			\
-	e-cal-backend-ews-factory.h			\
 	e-cal-backend-ews.c				\
 	e-cal-backend-ews.h				\
 	e-cal-backend-ews-utils.c			\
diff --git a/src/calendar/e-cal-backend-ews-factory.c b/src/calendar/e-cal-backend-ews-factory.c
index f53af45..8647402 100644
--- a/src/calendar/e-cal-backend-ews-factory.c
+++ b/src/calendar/e-cal-backend-ews-factory.c
@@ -11,190 +11,107 @@
 
 #include <string.h>
 
-#include "e-cal-backend-ews-factory.h"
+#include <libedata-cal/e-cal-backend-factory.h>
 #include "e-cal-backend-ews.h"
 
-typedef struct {
-	ECalBackendFactory            parent_object;
-} ECalBackendEwsFactory;
+#define FACTORY_NAME "ews"
 
-typedef struct {
-	ECalBackendFactoryClass parent_class;
-} ECalBackendEwsFactoryClass;
+typedef ECalBackendFactory ECalBackendEwsEventsFactory;
+typedef ECalBackendFactoryClass ECalBackendEwsEventsFactoryClass;
 
-static void
-e_cal_backend_ews_factory_instance_init (ECalBackendEwsFactory *factory)
-{
-}
+typedef ECalBackendFactory ECalBackendEwsJournalFactory;
+typedef ECalBackendFactoryClass ECalBackendEwsJournalFactoryClass;
 
-static const gchar *
-_get_protocol (ECalBackendFactory *factory)
-{
-	return "ews";
-}
+typedef ECalBackendFactory ECalBackendEwsTodosFactory;
+typedef ECalBackendFactoryClass ECalBackendEwsTodosFactoryClass;
 
-static ECalBackend*
-_todos_new_backend (ECalBackendFactory *factory, ESource *source)
-{
-	return g_object_new (e_cal_backend_ews_get_type (),
-			     "source", source,
-			     "kind", ICAL_VTODO_COMPONENT,
-			     NULL);
-}
+/* Module Entry Points */
+void e_module_load (GTypeModule *type_module);
+void e_module_unload (GTypeModule *type_module);
 
-static icalcomponent_kind
-_todos_get_kind (ECalBackendFactory *factory)
-{
-	return ICAL_VTODO_COMPONENT;
-}
+/* Forward Declarations */
+GType e_cal_backend_ews_events_factory_get_type (void);
+GType e_cal_backend_ews_journal_factory_get_type (void);
+GType e_cal_backend_ews_todos_factory_get_type (void);
 
-static ECalBackend*
-_journal_new_backend (ECalBackendFactory *factory, ESource *source)
-{
-	return g_object_new (e_cal_backend_ews_get_type (),
-			     "source", source,
-			     "kind", ICAL_VJOURNAL_COMPONENT,
-			     NULL);
-}
+G_DEFINE_DYNAMIC_TYPE (
+	ECalBackendEwsEventsFactory,
+	e_cal_backend_ews_events_factory,
+	E_TYPE_CAL_BACKEND_FACTORY)
 
-static icalcomponent_kind
-_journal_get_kind (ECalBackendFactory *factory)
-{
-	return ICAL_VJOURNAL_COMPONENT;
-}
+G_DEFINE_DYNAMIC_TYPE (
+	ECalBackendEwsJournalFactory,
+	e_cal_backend_ews_journal_factory,
+	E_TYPE_CAL_BACKEND_FACTORY)
+
+G_DEFINE_DYNAMIC_TYPE (
+	ECalBackendEwsTodosFactory,
+	e_cal_backend_ews_todos_factory,
+	E_TYPE_CAL_BACKEND_FACTORY)
 
-static ECalBackend*
-_events_new_backend (ECalBackendFactory *factory, ESource *source)
+static void
+e_cal_backend_ews_events_factory_class_init (ECalBackendFactoryClass *class)
 {
-	return g_object_new (e_cal_backend_ews_get_type (),
-			     "source", source,
-			     "kind", ICAL_VEVENT_COMPONENT,
-			     NULL);
+	class->factory_name = FACTORY_NAME;
+	class->component_kind = ICAL_VEVENT_COMPONENT;
+	class->backend_type = E_TYPE_CAL_BACKEND_EWS;
 }
 
-static icalcomponent_kind
-_events_get_kind (ECalBackendFactory *factory)
+static void
+e_cal_backend_ews_events_factory_class_finalize (ECalBackendFactoryClass *class)
 {
-	return ICAL_VEVENT_COMPONENT;
 }
 
 static void
-todos_backend_factory_class_init (ECalBackendEwsFactoryClass *klass)
+e_cal_backend_ews_events_factory_init (ECalBackendFactory *factory)
 {
-	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;
 }
 
 static void
-events_backend_factory_class_init (ECalBackendEwsFactoryClass *klass)
+e_cal_backend_ews_journal_factory_class_init (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;
+	class->factory_name = FACTORY_NAME;
+	class->component_kind = ICAL_VJOURNAL_COMPONENT;
+	class->backend_type = E_TYPE_CAL_BACKEND_EWS;
 }
 
 static void
-journal_backend_factory_class_init (ECalBackendEwsFactoryClass *klass)
+e_cal_backend_ews_journal_factory_class_finalize (ECalBackendFactoryClass *class)
 {
-	E_CAL_BACKEND_FACTORY_CLASS (klass)->get_protocol = _get_protocol;
-	E_CAL_BACKEND_FACTORY_CLASS (klass)->get_kind     = _journal_get_kind;
-	E_CAL_BACKEND_FACTORY_CLASS (klass)->new_backend  = _journal_new_backend;
 }
 
-static GType
-events_backend_factory_get_type (GTypeModule *module)
+static void
+e_cal_backend_ews_journal_factory_init (ECalBackendFactory *factory)
 {
-	GType type;
-
-	GTypeInfo info = {
-		sizeof (ECalBackendEwsFactoryClass),
-		NULL, /* base_class_init */
-		NULL, /* base_class_finalize */
-		(GClassInitFunc)  events_backend_factory_class_init,
-		NULL, /* class_finalize */
-		NULL, /* class_data */
-		sizeof (ECalBackend),
-		0,    /* n_preallocs */
-		(GInstanceInitFunc) e_cal_backend_ews_factory_instance_init
-	};
-
-	type = g_type_module_register_type (module,
-					    E_TYPE_CAL_BACKEND_FACTORY,
-					    "ECalBackendEwsEventsFactory",
-					    &info, 0);
-
-	return type;
 }
 
-static GType
-todos_backend_factory_get_type (GTypeModule *module)
+static void
+e_cal_backend_ews_todos_factory_class_init (ECalBackendFactoryClass *class)
 {
-	GType type;
-
-	GTypeInfo info = {
-		sizeof (ECalBackendEwsFactoryClass),
-		NULL, /* base_class_init */
-		NULL, /* base_class_finalize */
-		(GClassInitFunc)  todos_backend_factory_class_init,
-		NULL, /* class_finalize */
-		NULL, /* class_data */
-		sizeof (ECalBackend),
-		0,    /* n_preallocs */
-		(GInstanceInitFunc) e_cal_backend_ews_factory_instance_init
-	};
-
-	type = g_type_module_register_type (module,
-					    E_TYPE_CAL_BACKEND_FACTORY,
-					    "ECalBackendEwsTodosFactory",
-					    &info, 0);
-
-	return type;
+	class->factory_name = FACTORY_NAME;
+	class->component_kind = ICAL_VTODO_COMPONENT;
+	class->backend_type = E_TYPE_CAL_BACKEND_EWS;
 }
 
-static GType
-journal_backend_factory_get_type (GTypeModule *module)
+static void
+e_cal_backend_ews_todos_factory_class_finalize (ECalBackendFactoryClass *class)
 {
-	GType type;
-
-	GTypeInfo info = {
-		sizeof (ECalBackendEwsFactoryClass),
-		NULL, /* base_class_init */
-		NULL, /* base_class_finalize */
-		(GClassInitFunc)  journal_backend_factory_class_init,
-		NULL, /* class_finalize */
-		NULL, /* class_data */
-		sizeof (ECalBackend),
-		0,    /* n_preallocs */
-		(GInstanceInitFunc) e_cal_backend_ews_factory_instance_init
-	};
-
-	type = g_type_module_register_type (module,
-					    E_TYPE_CAL_BACKEND_FACTORY,
-					    "ECalBackendEwsJournalFactory",
-					    &info, 0);
-
-	return type;
 }
 
-static GType ews_types[3];
-
-void
-eds_module_initialize (GTypeModule *module)
+static void
+e_cal_backend_ews_todos_factory_init (ECalBackendFactory *factory)
 {
-	ews_types[0] = todos_backend_factory_get_type (module);
-	ews_types[1] = events_backend_factory_get_type (module);
-	ews_types[2] = journal_backend_factory_get_type (module);
 }
 
-void
-eds_module_shutdown   (void)
+G_MODULE_EXPORT void
+e_module_load (GTypeModule *type_module)
 {
+	e_cal_backend_ews_events_factory_register_type (type_module);
+	e_cal_backend_ews_journal_factory_register_type (type_module);
+	e_cal_backend_ews_todos_factory_register_type (type_module);
 }
 
-void
-eds_module_list_types (const GType **types, gint *num_types)
+G_MODULE_EXPORT void
+e_module_unload (GTypeModule *type_module)
 {
-	*types = ews_types;
-	*num_types = 3;
 }
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index 03d832e..dd083c3 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -79,7 +79,7 @@ struct _ECalBackendEwsPrivate {
 	EDataCal *opening_cal;
 	EServerMethodContext opening_ctx;
 
-	CalMode mode;
+	gboolean is_online;
 	ECalBackendStore *store;
 	gboolean read_only;
 
@@ -90,9 +90,7 @@ struct _ECalBackendEwsPrivate {
 	gboolean refreshing;
 	GHashTable *item_id_hash;
 
-#if EDS_CHECK_VERSION (3,1,0)
 	ECredentials *credentials;
-#endif
 };
 
 #define PRIV_LOCK(p)   (g_static_rec_mutex_lock (&(p)->rec_mutex))
@@ -147,202 +145,6 @@ switch_offline (ECalBackendEws *cbews)
 }
 
 /* Property Accessors */
-
-#if ! EDS_CHECK_VERSION (3, 1, 0)	
-static void
-e_cal_backend_ews_is_read_only (ECalBackend *backend, EDataCal *cal)
-{
-	ECalBackendEws *cbews;
-
-	cbews = E_CAL_BACKEND_EWS (backend);
-
-	e_data_cal_notify_read_only (cal, NULL, cbews->priv->read_only);
-}
-
-static void
-e_cal_backend_ews_get_cal_address (ECalBackend *backend, EDataCal *cal, EServerMethodContext context)
-{
-	ECalBackendEws *cbews;
-	ECalBackendEwsPrivate *priv;
-
-	cbews = E_CAL_BACKEND_EWS (backend);
-	priv = cbews->priv;
-
-	e_data_cal_notify_cal_address (cal, context, NULL, priv->user_email);
-}
-
-static void
-e_cal_backend_ews_get_static_capabilities (ECalBackend *backend, EDataCal *cal, EServerMethodContext context)
-{
-	const gchar *capabilities;
-
-	capabilities =	(CAL_STATIC_CAPABILITY_NO_EMAIL_ALARMS ","
-			 CAL_STATIC_CAPABILITY_ONE_ALARM_ONLY ","
-			 CAL_STATIC_CAPABILITY_REMOVE_ALARMS ","
-			 CAL_STATIC_CAPABILITY_REFRESH_SUPPORTED ","
-			 CAL_STATIC_CAPABILITY_NO_THISANDPRIOR ","
-			 CAL_STATIC_CAPABILITY_NO_THISANDFUTURE ","
-			 CAL_STATIC_CAPABILITY_NO_CONV_TO_ASSIGN_TASK ","
-		//	 CAL_STATIC_CAPABILITY_NO_CONV_TO_RECUR ","
-			 CAL_STATIC_CAPABILITY_NO_TASK_ASSIGNMENT ","
-			 CAL_STATIC_CAPABILITY_SAVE_SCHEDULES);
-
-	e_data_cal_notify_static_capabilities (cal, context, NULL, capabilities);
-}
-
-static gboolean
-e_cal_backend_ews_is_loaded (ECalBackend *backend)
-{
-	ECalBackendEws *cbews;
-	ECalBackendEwsPrivate *priv;
-
-	cbews = E_CAL_BACKEND_EWS (backend);
-	priv = cbews->priv;
-
-	return priv->store ? TRUE : FALSE;
-}
-
-static icaltimezone *
-e_cal_backend_ews_internal_get_default_timezone (ECalBackend *backend)
-{
-	ECalBackendEws *cbews = E_CAL_BACKEND_EWS (backend);
-
-	return cbews->priv->default_zone;
-}
-
-static CalMode
-e_cal_backend_ews_get_mode (ECalBackend *backend)
-{
-	ECalBackendEws *cbews;
-	ECalBackendEwsPrivate *priv;
-
-	cbews = E_CAL_BACKEND_EWS (backend);
-	priv = cbews->priv;
-
-	return priv->mode;
-}
-static void
-e_cal_backend_ews_set_mode (ECalBackend *backend, CalMode mode)
-{
-	ECalBackendEws *cbews;
-	ECalBackendEwsPrivate *priv;
-
-	cbews = E_CAL_BACKEND_EWS (backend);
-	priv = cbews->priv;
-
-	if (priv->mode == mode) {
-		e_cal_backend_notify_mode (backend, ModeSet,
-					   cal_mode_to_corba (mode));
-		return;
-	}
-
-	PRIV_LOCK (priv);
-
-	switch (mode) {
-	case CAL_MODE_REMOTE :/* go online */
-		priv->mode = CAL_MODE_REMOTE;
-		priv->read_only = FALSE;
-		e_cal_backend_notify_mode (backend, ModeSet, Remote);
-		e_cal_backend_notify_readonly (backend, priv->read_only);
-		if (e_cal_backend_ews_is_loaded (backend))
-			      e_cal_backend_notify_auth_required (backend);
-		break;
-
-	case CAL_MODE_LOCAL : /* go offline */
-		priv->mode = CAL_MODE_LOCAL;
-		switch_offline (cbews);
-		e_cal_backend_notify_readonly (backend, priv->read_only);
-		e_cal_backend_notify_mode (backend, ModeSet, Local);
-
-		break;
-	default :
-		e_cal_backend_notify_mode (backend, ModeNotSupported,
-					   cal_mode_to_corba (mode));
-	}
-
-	PRIV_UNLOCK (priv);
-}
-
-static void
-e_cal_backend_ews_set_default_zone (ECalBackend *backend, EDataCal *cal, EServerMethodContext context, const gchar *tzobj)
-{
-	icalcomponent *tz_comp;
-	ECalBackendEws *cbews;
-	ECalBackendEwsPrivate *priv;
-	icaltimezone *zone;
-	GError *error = NULL;
-
-	cbews = (ECalBackendEws *) backend;
-
-	e_data_cal_error_if_fail (E_IS_CAL_BACKEND_EWS (cbews), InvalidArg);
-	e_data_cal_error_if_fail (tzobj != NULL, InvalidArg);
-
-	priv = cbews->priv;
-
-	tz_comp = icalparser_parse_string (tzobj);
-	if (!tz_comp) {
-		g_propagate_error (&error, EDC_ERROR (InvalidObject));
-		goto exit;
-	}
-
-	zone = icaltimezone_new ();
-	icaltimezone_set_component (zone, tz_comp);
-
-	PRIV_LOCK (priv);
-
-	if (priv->default_zone && priv->default_zone != icaltimezone_get_utc_timezone ())
-		icaltimezone_free (priv->default_zone, 1);
-
-	/* Set the default timezone to it. */
-	priv->default_zone = zone;
-
-	PRIV_UNLOCK (priv);
-
-exit:
-	e_data_cal_notify_default_timezone_set (cal, context, error);
-}
-
-static void 
-e_cal_backend_ews_get_ldap_attribute (ECalBackend *backend, EDataCal *cal, EServerMethodContext context)
-{
-	e_data_cal_notify_ldap_attribute (cal, context, NULL, NULL);
-}
-
-static void
-e_cal_backend_ews_get_default_object (ECalBackend *backend, EDataCal *cal, EServerMethodContext context)
-{
-
-	ECalComponent *comp;
-	GError *error = NULL;
-	gchar *object = NULL;
-
-	comp = e_cal_component_new ();
-
-	switch (e_cal_backend_get_kind (backend)) {
-	case ICAL_VEVENT_COMPONENT:
-		e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT);
-		break;
-	case ICAL_VTODO_COMPONENT:
-		e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_TODO);
-		break;
-	default:
-		g_object_unref (comp);
-		g_propagate_error (&error, EDC_ERROR (ObjectNotFound));
-		goto exit;
-	}
-
-	object = e_cal_component_get_as_string (comp);
-	g_object_unref (comp);
-
-exit:
-	e_data_cal_notify_default_object (cal, context, error, object);
-	g_free (object);
-}
-
-
-
-#endif
-
 static icaltimezone *
 e_cal_backend_ews_internal_get_timezone (ECalBackend *backend, const gchar *tzid)
 {
@@ -679,11 +481,11 @@ connect_to_server (ECalBackendEws *cbews, const gchar *username, const gchar *pa
 	ESource *esource;
 	
 	priv = cbews->priv;
-	esource = e_cal_backend_get_source (E_CAL_BACKEND (cbews));
+	esource = e_backend_get_source (E_BACKEND (cbews));
 	
 	PRIV_LOCK (priv);
 
-	if (priv->mode != CAL_MODE_LOCAL && !priv->cnc && password) {
+	if (priv->is_online && !priv->cnc && password) {
 		const gchar *host_url;
 
 		/* If we can be called a second time while the first is still
@@ -720,7 +522,7 @@ e_cal_backend_ews_open (ECalBackend *backend, EDataCal *cal, EServerMethodContex
 	priv = cbews->priv;
 
 	cache_dir = e_cal_backend_get_cache_dir (backend);
-	esource = e_cal_backend_get_source (E_CAL_BACKEND (cbews));
+	esource = e_backend_get_source (E_BACKEND (cbews));
 
 	PRIV_LOCK (priv);
 	if (!priv->store) {
@@ -746,18 +548,6 @@ e_cal_backend_ews_open (ECalBackend *backend, EDataCal *cal, EServerMethodContex
 	return FALSE;
 }
 
-#if ! EDS_CHECK_VERSION (3,1,0)
-static void	
-e_cal_backend_ews_open_compat	(ECalBackend *backend, EDataCal *cal, EServerMethodContext context, gboolean only_if_exists, const gchar *username,
-				 const gchar *password)
-{
-	GError *error = NULL;
-	
-	if (!e_cal_backend_ews_open (backend, cal, context, NULL, only_if_exists, username, password, &error))
-		e_data_cal_respond_open (cal, context, error);
-}
-#else
-
 static void	
 e_cal_backend_ews_open_compat (ECalBackend *backend, EDataCal *cal, guint32 opid, GCancellable *cancellable, gboolean only_if_exists)
 {
@@ -815,8 +605,6 @@ e_cal_backend_ews_authenticate_user (ECalBackend *backend,
 	g_clear_error (&error);
 }
 
-#endif
-
 static void
 e_cal_backend_ews_remove (ECalBackend *backend, EDataCal *cal, EServerMethodContext context, GCancellable *cancellable)
 {
@@ -1502,7 +1290,7 @@ ews_create_object_cb(GObject *object, GAsyncResult *res, gpointer user_data)
 	guint n_attach;
 	gboolean result;
 	EEwsItem *item;
-	gchar *comp_str;
+	icalcomponent *new_icalcomp;
 
 	/* get a list of ids from server (single item) */
 	e_ews_connection_create_items_finish(cnc, res, &ids, &error);
@@ -1589,13 +1377,11 @@ ews_create_object_cb(GObject *object, GAsyncResult *res, gpointer user_data)
 	
 	e_cal_component_get_uid(create_data->comp, &comp_uid);
 
-	comp_str = e_cal_component_get_as_string(create_data->comp);
-	e_data_cal_respond_create_object (create_data->cal, create_data->context, error, comp_uid, comp_str);
+	new_icalcomp = e_cal_component_get_icalcomponent (create_data->comp);
+	e_data_cal_respond_create_object (create_data->cal, create_data->context, error, comp_uid, new_icalcomp);
 	
 	/* notify the backend and the application that a new object was created */
-	e_cal_backend_notify_object_created (E_CAL_BACKEND(create_data->cbews), comp_str);
-
-	g_free (comp_str);
+	e_cal_backend_notify_component_created (E_CAL_BACKEND(create_data->cbews), new_icalcomp);
 
 	/* place new component in our cache */
 	PRIV_LOCK (priv);
@@ -1684,7 +1470,7 @@ e_cal_backend_ews_create_object (ECalBackend *backend, EDataCal *cal, EServerMet
 	kind = e_cal_backend_get_kind(E_CAL_BACKEND(backend));
 
 	/* make sure we're not offline */
-	if (priv->mode == CAL_MODE_LOCAL) {
+	if (!priv->is_online) {
 		g_propagate_error(&error, EDC_ERROR(RepositoryOffline));
 		goto exit;
 	}
@@ -1770,13 +1556,13 @@ ews_cal_modify_object_cb (GObject *object, GAsyncResult *res, gpointer user_data
 	ECalBackendEws *cbews = modify_data->cbews;
 	ECalBackendEwsPrivate *priv = cbews->priv;
 	GError *error = NULL;
-	gchar *comp_str = NULL, *comp_str_old = NULL;
 	GSList *ids = NULL;
 	const EwsId *item_id;
 	icalproperty *icalprop = NULL;
 	icalcomponent *icalcomp;
 	ECalComponentId *id = NULL;
 	const gchar *x_name;
+	icalcomponent *old_icalcomp = NULL, *new_icalcomp = NULL;
 
 	if (!e_ews_connection_update_items_finish (cnc, res, &ids, &error)) {
 		/* The calendar UI doesn't *display* errors unless they have
@@ -1811,12 +1597,12 @@ ews_cal_modify_object_cb (GObject *object, GAsyncResult *res, gpointer user_data
 	e_cal_backend_store_remove_component (cbews->priv->store, id->uid, id->rid);
 	put_component_to_store (cbews, modify_data->comp);
 
-	comp_str = e_cal_component_get_as_string (modify_data->comp);
-	comp_str_old = e_cal_component_get_as_string (modify_data->oldcomp);
+	new_icalcomp = e_cal_component_get_icalcomponent (modify_data->comp);
+	old_icalcomp = e_cal_component_get_icalcomponent (modify_data->oldcomp);
 
 	if (modify_data->context) {
-		e_cal_backend_notify_object_modified (E_CAL_BACKEND (cbews), comp_str_old, comp_str);
-		e_data_cal_respond_modify_object (modify_data->cal, modify_data->context, error, comp_str_old, comp_str);
+		e_cal_backend_notify_component_modified (E_CAL_BACKEND (cbews), old_icalcomp, new_icalcomp);
+		e_data_cal_respond_modify_object (modify_data->cal, modify_data->context, error, old_icalcomp, new_icalcomp);
 	}
 	else if (error) {
 		g_warning ("Modify object error :  %s\n", error->message);
@@ -1831,8 +1617,6 @@ ews_cal_modify_object_cb (GObject *object, GAsyncResult *res, gpointer user_data
 
 	icalproperty_free (icalprop);
 	e_cal_component_free_id (id);
-	g_free(comp_str);
-	g_free(comp_str_old);
 
 exit:
 	g_free(modify_data->itemid);
@@ -2146,7 +1930,7 @@ e_cal_backend_ews_modify_object (ECalBackend *backend, EDataCal *cal, EServerMet
 	priv = cbews->priv;
 	kind = e_cal_backend_get_kind(E_CAL_BACKEND(backend));
 
-	if (priv->mode == CAL_MODE_LOCAL) {
+	if (!priv->is_online) {
 		g_propagate_error(&error, EDC_ERROR(RepositoryOffline));
 		goto exit;
 	}
@@ -2423,7 +2207,7 @@ e_cal_backend_ews_receive_objects (ECalBackend *backend, EDataCal *cal, EServerM
 	priv = cbews->priv;
 
 	/* make sure we're not offline */
-	if (priv->mode == CAL_MODE_LOCAL) {
+	if (!priv->is_online) {
 		g_propagate_error (&error, EDC_ERROR (RepositoryOffline));
 		goto exit;
 	}
@@ -2672,7 +2456,7 @@ e_cal_backend_ews_send_objects (ECalBackend *backend, EDataCal *cal, EServerMeth
 	priv = cbews->priv;
 
 	/* make sure we're not offline */
-	if (priv->mode == CAL_MODE_LOCAL) {
+	if (!priv->is_online) {
 		g_propagate_error (&error, EDC_ERROR (RepositoryOffline));
 		goto exit;
 	}
@@ -3342,33 +3126,8 @@ ews_cal_sync_items_ready_cb (GObject *obj, GAsyncResult *res, gpointer user_data
 							 &items_deleted, &error);
 
 	/*FIXME invoke a dummy request in authenticate user to ensure we have a valid connection to avoid this mess */
-#if ! EDS_CHECK_VERSION (3,1,0)
-	PRIV_LOCK (priv);
-	if (priv->opening_ctx) {
-		/* Report success/failure for calendar open if pending,
-		   translating an authentication failure into something that
-		   will be recognized and handled appropriately */
-		if (error && error->domain == EWS_CONNECTION_ERROR &&
-		    error->code == EWS_CONNECTION_ERROR_AUTHENTICATION_FAILED) {
-			e_data_cal_respond_open(priv->opening_cal, priv->opening_ctx,
-					       EDC_ERROR(AuthenticationFailed));
-		} else {
-			e_data_cal_respond_open(priv->opening_cal, priv->opening_ctx,
-					       error?g_error_copy (error):NULL);
-		}
-		priv->opening_ctx = 0;
-		priv->opening_cal = NULL;
-		if (error) {
-			priv->cnc = NULL;
-			g_object_unref (cnc);
-		}
-
-	}
-	PRIV_UNLOCK (priv);
-#else
 	if (!(error && error->domain == EWS_CONNECTION_ERROR && error->code == EWS_CONNECTION_ERROR_AUTHENTICATION_FAILED))
 		e_cal_backend_notify_readonly (E_CAL_BACKEND (cbews), FALSE);
-#endif	
 
 	if (error != NULL) {
 		g_warning ("Unable to Sync changes %s \n", error->message);
@@ -3511,7 +3270,7 @@ ews_cal_start_refreshing (ECalBackendEws *cbews)
 	PRIV_LOCK (priv);
 
 	if	(!priv->refresh_timeout &&
- 		 priv->mode == CAL_MODE_REMOTE &&
+ 		 priv->is_online &&
 		 priv->cnc) {
 			ews_start_sync (cbews);
 			priv->refresh_timeout = g_timeout_add_seconds
@@ -3564,7 +3323,7 @@ e_cal_backend_ews_refresh (ECalBackend *backend, EDataCal *cal, EServerMethodCon
 	priv = cbews->priv;
 
 	/* make sure we're not offline */
-	if (priv->mode == CAL_MODE_LOCAL) {
+	if (!priv->is_online) {
 		g_propagate_error(&error, EDC_ERROR(RepositoryOffline));
 		goto exit;
 	}
@@ -3636,9 +3395,6 @@ ews_cal_get_free_busy_cb (GObject *obj, GAsyncResult *res, gpointer user_data)
 	GSList *free_busy_sl = NULL, *i;
 	GSList *free_busy = NULL, *j;
 	GError *error = NULL;
-#if ! EDS_CHECK_VERSION (3,1,0)	
-	GList *fb = NULL;
-#endif	
 
 	if (!e_ews_connection_get_free_busy_finish (cnc, res, &free_busy_sl, &error)) {
 		error->code = OtherError;
@@ -3654,18 +3410,9 @@ ews_cal_get_free_busy_cb (GObject *obj, GAsyncResult *res, gpointer user_data)
 	g_slist_free (free_busy_sl);
 
 done:
-#if ! EDS_CHECK_VERSION (3,1,0)	
-	for (j = free_busy; j != NULL; j = g_slist_next (j))
-		fb = g_list_prepend (fb, j->data);
-	if (fb)
-		fb = g_list_reverse (fb);
-	e_data_cal_notify_free_busy (free_busy_data->cal, free_busy_data->context, error, fb);
-	g_list_free (fb);
-#else
 	if (free_busy)
 		e_data_cal_report_free_busy_data (free_busy_data->cal, free_busy);
 	e_data_cal_respond_get_free_busy (free_busy_data->cal, free_busy_data->context, error);
-#endif
 
 	/* FIXME free free_busy_sl ? */
 	g_slist_foreach (free_busy, (GFunc) g_free, NULL);
@@ -3689,8 +3436,7 @@ e_cal_backend_ews_get_free_busy (ECalBackend *backend, EDataCal *cal,
 	GSList *users_copy = NULL;
 
 	/* make sure we're not offline */
-	if (priv->mode == CAL_MODE_LOCAL)
-	{
+	if (!priv->is_online) {
 		g_propagate_error (&error, EDC_ERROR (RepositoryOffline));
 		goto exit;
 	}
@@ -3726,17 +3472,10 @@ e_cal_backend_ews_get_free_busy (ECalBackend *backend, EDataCal *cal,
 	return;
 
 exit:
-#if ! EDS_CHECK_VERSION (3,1,0)	
-	e_data_cal_notify_free_busy (cal, context, error, NULL);
-#else
 	e_data_cal_respond_get_free_busy (cal, context, error);
-#endif	
 
 }
 
-/* new virtual functions from 3.2 onwards */
-#if EDS_CHECK_VERSION (3,1,0)
-
 static void
 e_cal_backend_ews_get_backend_property	(ECalBackend *backend,
                                          EDataCal *cal,
@@ -3802,54 +3541,42 @@ e_cal_backend_ews_get_backend_property	(ECalBackend *backend,
 }
 
 static void
-e_cal_backend_ews_set_online (ECalBackend *backend,
-                              gboolean is_online)
+e_cal_backend_ews_notify_online_cb (ECalBackend *backend,
+				    GParamSpec *spec)
 {
 	ECalBackendEws *cbgw;
 	ECalBackendEwsPrivate *priv;
-	CalMode mode;
+	gboolean is_online;
 
 	cbgw = E_CAL_BACKEND_EWS (backend);
 	priv = cbgw->priv;
 
-	if (is_online)
-		mode = CAL_MODE_REMOTE;
-	else
-		mode = CAL_MODE_LOCAL;
+	is_online = e_backend_get_online (E_BACKEND (backend));
 
-	if (priv->mode == mode) {
-		e_cal_backend_notify_online (backend, (mode == CAL_MODE_REMOTE) ? TRUE : FALSE);
+	if ((is_online ? 1 : 0) == (priv->is_online ? 1 : 0)) {
+		e_cal_backend_notify_online (backend, is_online);
 		return;
 	}
 
 	PRIV_LOCK (priv);
 
-	switch (mode) {
-	case CAL_MODE_REMOTE :/* go online */
-		priv->mode = CAL_MODE_REMOTE;
+	priv->is_online = is_online;
+
+	if (is_online) {
 		priv->read_only = FALSE;
 		e_cal_backend_notify_online (backend, TRUE);
 		e_cal_backend_notify_readonly (backend, priv->read_only);
 		if (e_cal_backend_is_opened (backend))
 			      e_cal_backend_notify_auth_required (backend, TRUE, priv->credentials);
-		break;
-
-	case CAL_MODE_LOCAL : /* go offline */
-		priv->mode = CAL_MODE_LOCAL;
+	} else {
 		switch_offline (E_CAL_BACKEND_EWS (backend));
 		e_cal_backend_notify_readonly (backend, priv->read_only);
 		e_cal_backend_notify_online (backend, FALSE);
-
-		break;
-	default :
-		e_cal_backend_notify_online (backend, FALSE);
 	}
 
 	PRIV_UNLOCK (priv);
 }
 
-#endif
-
 static void
 e_cal_backend_ews_dispose (GObject *object)
 {
@@ -3911,10 +3638,8 @@ e_cal_backend_ews_finalize (GObject *object)
 
 	g_hash_table_destroy (priv->item_id_hash);
 
-#if EDS_CHECK_VERSION (3,1,0)
 	e_credentials_free (priv->credentials);
 	priv->credentials = NULL;
-#endif	
 	
 	g_free (priv);
 	cbews->priv = NULL;
@@ -3940,101 +3665,12 @@ e_cal_backend_ews_init (ECalBackendEws *cbews)
 	priv->default_zone = icaltimezone_get_utc_timezone ();
 
 	cbews->priv = priv;
-}
-
-#if ! EDS_CHECK_VERSION (3,1,0)
-static void
-e_cal_backend_ews_add_timezone_compat (ECalBackend *backend, EDataCal *cal, EServerMethodContext context, const gchar *tzobj)
-{
-	e_cal_backend_ews_add_timezone (backend, cal, context, NULL, tzobj);
-}
-
-static void
-e_cal_backend_ews_get_timezone_compat (ECalBackend *backend, EDataCal *cal, EServerMethodContext context, const gchar *tzid)
-{
-	e_cal_backend_ews_get_timezone (backend, cal, context, NULL, tzid);
-}
-
-static void
-e_cal_backend_ews_refresh_compat (ECalBackend *backend, EDataCal *cal, EServerMethodContext context)
-{
-	e_cal_backend_ews_refresh (backend, cal, context, NULL);
-}
-
-static void
-e_cal_backend_ews_get_object_compat	(ECalBackend *backend, EDataCal *cal, EServerMethodContext context,
-	 			 	 const gchar *uid, const gchar *rid)
-{
-	e_cal_backend_ews_get_object (backend, cal, context, NULL, uid, rid);
-}
-
-static void
-e_cal_backend_ews_get_object_list_compat (ECalBackend *backend, EDataCal *cal, EServerMethodContext context, const gchar *sexp)
-{
-	e_cal_backend_ews_get_object_list (backend, cal, context, NULL, sexp);
-}
-
-static void
-e_cal_backend_ews_remove_compat (ECalBackend *backend, EDataCal *cal, EServerMethodContext context)
-{
-	e_cal_backend_ews_remove (backend, cal, context, NULL);
-}
-
-static void
-e_cal_backend_ews_discard_alarm_compat (ECalBackend *backend, EDataCal *cal, EServerMethodContext context, const gchar *uid, const gchar *auid)
-{
-	e_cal_backend_ews_discard_alarm (backend, cal, context, NULL, uid, NULL, auid);
-}
-
-static void
-e_cal_backend_ews_create_object_compat (ECalBackend *backend, EDataCal *cal, EServerMethodContext context, const gchar *calobj)
-{
-	e_cal_backend_ews_create_object (backend, cal, context, NULL, calobj);
-}
-
-static void
-e_cal_backend_ews_modify_object_compat (ECalBackend *backend, EDataCal *cal, EServerMethodContext context, const gchar *calobj, CalObjModType mod)
-{
-	e_cal_backend_ews_modify_object (backend, cal, context, NULL, calobj, mod);
-}
 
-static void
-e_cal_backend_ews_remove_object_compat	(ECalBackend *backend, EDataCal *cal, EServerMethodContext context,
-					 const gchar *uid, const gchar *rid, CalObjModType mod)
-{
-	e_cal_backend_ews_remove_object (backend, cal, context, NULL, uid, rid, mod);
-}
-
-static void
-e_cal_backend_ews_receive_objects_compat (ECalBackend *backend, EDataCal *cal, EServerMethodContext context, const gchar *calobj)
-{
-	e_cal_backend_ews_receive_objects (backend, cal, context, NULL, calobj);
+	g_signal_connect (
+		cbews, "notify::online",
+		G_CALLBACK (e_cal_backend_ews_notify_online_cb), NULL);
 }
 
-static void
-e_cal_backend_ews_send_objects_compat (ECalBackend *backend, EDataCal *cal, EServerMethodContext context, const gchar *calobj)
-{
-	e_cal_backend_ews_send_objects (backend, cal, context, NULL, calobj);
-}
-
-static void
-e_cal_backend_ews_get_free_busy_compat (ECalBackend *backend, EDataCal *cal,
-				 EServerMethodContext context, GList *users,
-				 time_t start, time_t end)
-{
-	GSList *s_users = NULL;
-	GList *l = NULL;
-
-	for (l = users; l != NULL; l = g_list_next (users))
-		s_users = g_slist_prepend (s_users, l->data);
-	s_users = g_slist_reverse (s_users);
-
-	e_cal_backend_ews_get_free_busy (backend, cal, context, NULL, s_users, start, end);
-	g_slist_free (s_users);
-}
-
-#endif
-
 /* Class initialization function for the gw backend */
 static void
 e_cal_backend_ews_class_init (ECalBackendEwsClass *class)
@@ -4051,45 +3687,7 @@ e_cal_backend_ews_class_init (ECalBackendEwsClass *class)
 	object_class->finalize = e_cal_backend_ews_finalize;
 
 	/* Property accessors */
-#if ! EDS_CHECK_VERSION (3,1,0)	
-	backend_class->is_read_only = e_cal_backend_ews_is_read_only;
-	backend_class->get_cal_address = e_cal_backend_ews_get_cal_address;
-	backend_class->get_static_capabilities = e_cal_backend_ews_get_static_capabilities;
-	backend_class->set_default_zone = e_cal_backend_ews_set_default_zone;
-	backend_class->is_loaded = e_cal_backend_ews_is_loaded;
-	backend_class->internal_get_default_timezone = e_cal_backend_ews_internal_get_default_timezone;
-	backend_class->get_mode = e_cal_backend_ews_get_mode;
-	backend_class->set_mode = e_cal_backend_ews_set_mode;
-	backend_class->get_ldap_attribute = e_cal_backend_ews_get_ldap_attribute;
-	backend_class->get_default_object = e_cal_backend_ews_get_default_object;
-	
-	backend_class->start_query = e_cal_backend_ews_start_query;
-
-	backend_class->add_timezone = e_cal_backend_ews_add_timezone_compat;
-	backend_class->get_timezone = e_cal_backend_ews_get_timezone_compat;
-
-	backend_class->open = e_cal_backend_ews_open_compat;
-	backend_class->refresh = e_cal_backend_ews_refresh_compat;
-	backend_class->get_object = e_cal_backend_ews_get_object_compat;
-	backend_class->get_object_list = e_cal_backend_ews_get_object_list_compat;
-	backend_class->remove = e_cal_backend_ews_remove_compat;
-
-	backend_class->discard_alarm = e_cal_backend_ews_discard_alarm_compat;
-
-	backend_class->create_object = e_cal_backend_ews_create_object_compat;
-	backend_class->modify_object = e_cal_backend_ews_modify_object_compat;
-
-	backend_class->remove_object = e_cal_backend_ews_remove_object_compat;
-
-	backend_class->receive_objects = e_cal_backend_ews_receive_objects_compat;
-	backend_class->send_objects = e_cal_backend_ews_send_objects_compat;
-//	backend_class->get_attachment_list = e_cal_backend_ews_get_attachment_list;
-	backend_class->get_free_busy = e_cal_backend_ews_get_free_busy_compat;
-//	backend_class->get_changes = e_cal_backend_ews_get_changes;
-
-#else
 	backend_class->get_backend_property = e_cal_backend_ews_get_backend_property;
-	backend_class->set_online = e_cal_backend_ews_set_online;
 
 	backend_class->start_view = e_cal_backend_ews_start_query;
 	
@@ -4114,9 +3712,8 @@ e_cal_backend_ews_class_init (ECalBackendEwsClass *class)
 
 	backend_class->receive_objects = e_cal_backend_ews_receive_objects;
 	backend_class->send_objects = e_cal_backend_ews_send_objects;
-//	backend_class->get_attachment_list = e_cal_backend_ews_get_attachment_list;
+	/* backend_class->get_attachment_list = e_cal_backend_ews_get_attachment_list; */
 	backend_class->get_free_busy = e_cal_backend_ews_get_free_busy;
-//	backend_class->get_changes = e_cal_backend_ews_get_changes;
-#endif
+	/* backend_class->get_changes = e_cal_backend_ews_get_changes; */
 	backend_class->internal_get_timezone = e_cal_backend_ews_internal_get_timezone;
 }
diff --git a/src/camel/Makefile.am b/src/camel/Makefile.am
index b60251d..c8bcd04 100644
--- a/src/camel/Makefile.am
+++ b/src/camel/Makefile.am
@@ -19,6 +19,7 @@ libcamelews_la_CPPFLAGS = \
 
 libcamelews_la_SOURCES = 			\
 	camel-ews-folder.c                	\
+	camel-ews-settings.c               	\
 	camel-ews-store-summary.c              	\
 	camel-ews-store.c                 	\
 	camel-ews-summary.c               	\
@@ -29,6 +30,7 @@ libcamelews_la_SOURCES = 			\
 noinst_HEADERS =         			\
 	camel-ews-folder.h			\
 	camel-ews-private.h			\
+	camel-ews-settings.h              	\
 	camel-ews-store-summary.h              	\
 	camel-ews-store.h			\
 	camel-ews-summary.h			\
diff --git a/src/camel/camel-ews-folder.c b/src/camel/camel-ews-folder.c
index a6da13a..b1aed24 100644
--- a/src/camel/camel-ews-folder.c
+++ b/src/camel/camel-ews-folder.c
@@ -50,6 +50,7 @@ which needs to be better organized via functions */
 
 #include "camel-ews-folder.h"
 #include "camel-ews-private.h"
+#include "camel-ews-settings.h"
 #include "camel-ews-store.h"
 #include "camel-ews-summary.h"
 #include "camel-ews-utils.h"
@@ -708,7 +709,7 @@ ews_synchronize_sync (CamelFolder *folder, gboolean expunge, GCancellable *cance
 
 	for (i = 0; success && i < uids->len; i++) {
 		guint32 flags_changed;
-		CamelEwsMessageInfo *mi = (void *)camel_folder_summary_uid (folder->summary, uids->pdata[i]);
+		CamelEwsMessageInfo *mi = (void *)camel_folder_summary_get (folder->summary, uids->pdata[i]);
 		if (!mi)
 			continue;
 
@@ -745,6 +746,38 @@ ews_synchronize_sync (CamelFolder *folder, gboolean expunge, GCancellable *cance
 	return success;
 }
 
+static void
+ews_folder_count_notify_cb (CamelFolderSummary *folder_summary, GParamSpec *param, CamelFolder *folder)
+{
+	gint count;
+	CamelEwsStore *ews_store;
+	CamelEwsStoreSummary *store_summary;
+	gchar *folder_id;
+
+	g_return_if_fail (folder_summary != NULL);
+	g_return_if_fail (param != NULL);
+	g_return_if_fail (folder != NULL);
+	g_return_if_fail (folder->summary == folder_summary);
+
+	ews_store = CAMEL_EWS_STORE (camel_folder_get_parent_store (folder));
+	g_return_if_fail (ews_store != NULL);
+
+	store_summary = ews_store->summary;
+	folder_id = camel_ews_store_summary_get_folder_id_from_name (ews_store->summary, camel_folder_get_full_name (folder));
+
+	if (g_strcmp0 (g_param_spec_get_name (param), "saved-count") == 0) {
+		count = camel_folder_summary_get_saved_count (folder_summary);
+		camel_ews_store_summary_set_folder_total (store_summary, folder_id, count);
+	} else if (g_strcmp0 (g_param_spec_get_name (param), "unread-count") == 0) {
+		count = camel_folder_summary_get_unread_count (folder_summary);
+		camel_ews_store_summary_set_folder_unread (store_summary, folder_id, count);
+	} else {
+		g_warn_if_reached ();
+	}
+
+	g_free (folder_id);
+}
+
 CamelFolder *
 camel_ews_folder_new (CamelStore *store, const gchar *folder_name, const gchar *folder_dir, GCancellable *cancellable, GError **error)
 {
@@ -791,7 +824,9 @@ camel_ews_folder_new (CamelStore *store, const gchar *folder_name, const gchar *
 	}
 
 	if (!g_ascii_strcasecmp (folder_name, "Inbox")) {
-		if (camel_url_get_param (camel_service_get_camel_url ((CamelService *) store), "filter"))
+		CamelStoreSettings *settings = CAMEL_STORE_SETTINGS (camel_service_get_settings (CAMEL_SERVICE (store)));
+
+		if (camel_store_settings_get_filter_inbox (settings))
 			folder->folder_flags |= CAMEL_FOLDER_FILTER_RECENT;
 	}
 
@@ -801,6 +836,9 @@ camel_ews_folder_new (CamelStore *store, const gchar *folder_name, const gchar *
 		return NULL;
 	}
 
+	g_signal_connect (folder->summary, "notify::saved-count", G_CALLBACK (ews_folder_count_notify_cb), folder);
+	g_signal_connect (folder->summary, "notify::unread-count", G_CALLBACK (ews_folder_count_notify_cb), folder);
+
 	return folder;
 }
 
@@ -819,7 +857,7 @@ sync_updated_items (CamelEwsFolder *ews_folder, EEwsConnection *cnc, GSList *upd
 
 		/* Compare the item_type from summary as the updated items seems to
 		   arrive as generic types while its not the case */
-		mi = camel_folder_summary_uid (folder->summary, id->id);
+		mi = camel_folder_summary_get (folder->summary, id->id);
 		if (!mi) {
 			g_object_unref (item);
 			continue;
@@ -1044,7 +1082,7 @@ ews_refresh_info_sync (CamelFolder *folder, GCancellable *cancellable, GError **
 			break;
 
 		total = camel_folder_summary_count (folder->summary);
-		unread = folder->summary->unread_count;
+		unread = camel_folder_summary_get_unread_count (folder->summary);
 
 		camel_ews_store_summary_set_folder_total (ews_store->summary, id, total);
 		camel_ews_store_summary_set_folder_unread (ews_store->summary, id, unread);
@@ -1262,7 +1300,8 @@ ews_expunge_sync (CamelFolder *folder, GCancellable *cancellable, GError **error
 	CamelMessageInfo *info;
 	CamelStore *parent_store;
 	GSList *deleted_items = NULL;
-	gint i, count;
+	gint i;
+	GPtrArray *known_uids;
 
 	parent_store = camel_folder_get_parent_store (folder);
 	ews_store = CAMEL_EWS_STORE (parent_store);
@@ -1272,18 +1311,25 @@ ews_expunge_sync (CamelFolder *folder, GCancellable *cancellable, GError **error
 	
 	/* FIXME Run expunge on just trash folder once we are able to identify the exact trash */
 
-	/*Collect UIDs of deleted messages.*/
-	count = camel_folder_summary_count (folder->summary);
-	for (i = 0; i < count; i++) {
-		info = camel_folder_summary_index (folder->summary, i);
+	camel_folder_summary_prepare_fetch_all (folder->summary, NULL);
+	known_uids = camel_folder_summary_get_array (folder->summary);
+	if (!known_uids)
+		return TRUE;
+
+	/* Collect UIDs of deleted messages. */
+	for (i = 0; i < known_uids->len; i++) {
+		const gchar *uid = g_ptr_array_index (known_uids, i);
+
+		info = camel_folder_summary_get (folder->summary, uid);
 		ews_info = (CamelEwsMessageInfo *) info;
-		if (ews_info && (ews_info->info.flags & CAMEL_MESSAGE_DELETED)) {
-			const gchar *uid = camel_message_info_uid (info);
+		if (ews_info && (ews_info->info.flags & CAMEL_MESSAGE_DELETED))
 			deleted_items = g_slist_prepend (deleted_items, (gpointer) camel_pstring_strdup (uid));
-		}
+
 		camel_message_info_free (info);
 	}
 
+	camel_folder_summary_free_array (known_uids);
+
 	return ews_delete_messages (folder, deleted_items, TRUE, cancellable, error);
 }
 
@@ -1315,6 +1361,9 @@ ews_folder_dispose (GObject *object)
 	g_hash_table_destroy (ews_folder->priv->uid_eflags);
 	g_cond_free (ews_folder->priv->fetch_cond);
 
+	if (CAMEL_FOLDER (ews_folder)->summary)
+		g_signal_handlers_disconnect_by_func (CAMEL_FOLDER (ews_folder)->summary, G_CALLBACK (ews_folder_count_notify_cb), ews_folder);
+
 	/* Chain up to parent's dispose() method. */
 	G_OBJECT_CLASS (camel_ews_folder_parent_class)->dispose (object);
 }
diff --git a/src/camel/camel-ews-provider.c b/src/camel/camel-ews-provider.c
index c3f9462..1b7fc0e 100644
--- a/src/camel/camel-ews-provider.c
+++ b/src/camel/camel-ews-provider.c
@@ -46,18 +46,18 @@ static CamelProviderConfEntry ews_conf_entries[] = {
 
 	{ CAMEL_PROVIDER_CONF_SECTION_START, "mailcheck", NULL,
 	  N_("Checking for new mail") },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "check_all", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "check-all", NULL,
 	  N_("C_heck for new messages in all folders"), "1" },
 	{ CAMEL_PROVIDER_CONF_SECTION_END },
 
 	{ CAMEL_PROVIDER_CONF_SECTION_START, "general", NULL, N_("Options") },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter-inbox", NULL,
 	  N_("_Apply filters to new messages in Inbox on this server"), "0" },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter_junk", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk", NULL,
 	  N_("Check new messages for Jun_k contents"), "0" },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter_junk_inbox", "filter_junk",
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk-inbox", "filter-junk",
 	  N_("Only check for Junk messages in the IN_BOX folder"), "0" },
-	{ CAMEL_PROVIDER_CONF_CHECKBOX, "sync_offline", NULL,
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "stay-synchronized", NULL,
 	  N_("Automatically synchroni_ze remote mail locally"), "0" },
 	{ CAMEL_PROVIDER_CONF_SECTION_END },
 
diff --git a/src/camel/camel-ews-store.c b/src/camel/camel-ews-store.c
index 3bf0eaa..4287a95 100644
--- a/src/camel/camel-ews-store.c
+++ b/src/camel/camel-ews-store.c
@@ -41,6 +41,7 @@
 #include <e-ews-message.h>
 
 #include "camel-ews-folder.h"
+#include "camel-ews-settings.h"
 #include "camel-ews-store.h"
 #include "camel-ews-summary.h"
 #include "camel-ews-utils.h"
@@ -189,22 +190,23 @@ ews_store_authenticate	(EEwsConnection *cnc,
 	url = camel_service_get_camel_url (service);
 
 	if (retrying)
-		url->passwd = NULL;
+		camel_service_set_password (service, NULL);
 
-	if (!url->passwd) {
+	if (!camel_service_get_password (service)) {
 		gchar *prompt;
 
 		prompt = camel_session_build_password_prompt ("Exchange Web Services",
 				      url->user, url->host);
-		url->passwd = camel_session_get_password (session, service,
+		camel_service_set_password (service,
+					camel_session_get_password (session, service,
 						prompt, "password",
 						CAMEL_SESSION_PASSWORD_SECRET,
-						&error);
+						&error));
 		g_free (prompt);
 	}
 
 	e_ews_connection_authenticate (cnc, auth, url->user,
-				       url->passwd, error);
+				       camel_service_get_password (service), error);
 }
 
 static gboolean
@@ -799,7 +801,7 @@ ews_can_refresh_folder (CamelStore *store, CamelFolderInfo *info, GError **error
 
 	/* Delegate decision to parent class */
 	return CAMEL_STORE_CLASS(camel_ews_store_parent_class)->can_refresh_folder (store, info, error) ||
-			(camel_url_get_param (camel_service_get_camel_url ((CamelService *)store), "check_all") != NULL);
+		camel_ews_settings_get_check_all (CAMEL_EWS_SETTINGS (camel_service_get_settings (CAMEL_SERVICE (store))));
 }
 
 gboolean
@@ -871,7 +873,7 @@ camel_ews_store_class_init (CamelEwsStoreClass *class)
 	object_class->finalize = ews_store_finalize;
 
 	service_class = CAMEL_SERVICE_CLASS (class);
-
+	service_class->settings_type = CAMEL_TYPE_EWS_SETTINGS;
 	service_class->query_auth_types_sync = ews_store_query_auth_types_sync;
 	service_class->get_name = ews_get_name;
 	service_class->connect_sync = ews_connect_sync;
diff --git a/src/camel/camel-ews-summary.c b/src/camel/camel-ews-summary.c
index 501c1b4..22ab292 100644
--- a/src/camel/camel-ews-summary.c
+++ b/src/camel/camel-ews-summary.c
@@ -130,10 +130,6 @@ camel_ews_summary_class_init (CamelEwsSummaryClass *class)
 static void
 camel_ews_summary_init (CamelEwsSummary *ews_summary)
 {
-	CamelFolderSummary *summary = CAMEL_FOLDER_SUMMARY (ews_summary);
-
-	/* Meta-summary - Overriding UID len */
-	summary->meta_summary->uid_len = 2048;
 }
 
 /**
@@ -150,8 +146,7 @@ camel_ews_summary_new (struct _CamelFolder *folder, const gchar *filename)
 {
 	CamelFolderSummary *summary;
 
-	summary = g_object_new (CAMEL_TYPE_EWS_SUMMARY, NULL);
-	summary->folder = folder;
+	summary = g_object_new (CAMEL_TYPE_EWS_SUMMARY, "folder", folder, NULL);
 	camel_folder_summary_set_build_content (summary, TRUE);
 	camel_folder_summary_set_filename (summary, filename);
 
@@ -326,65 +321,7 @@ content_info_to_db (CamelFolderSummary *s, CamelMessageContentInfo *info, CamelM
 static gboolean
 ews_info_set_flags (CamelMessageInfo *info, guint32 flags, guint32 set)
 {
-		guint32 old;
-		CamelMessageInfoBase *mi = (CamelMessageInfoBase *)info;
-		gint read = 0 , deleted = 0;
-
-		gint junk_flag = 0, junk_learn_flag = 0;
-
-		/* TODO: locking? */
-
-		if (flags & CAMEL_MESSAGE_SEEN && ((set & CAMEL_MESSAGE_SEEN) != (mi->flags & CAMEL_MESSAGE_SEEN)))
-		{ read = set & CAMEL_MESSAGE_SEEN ? 1 : -1; d(printf("Setting read as %d\n", set & CAMEL_MESSAGE_SEEN ? 1 : 0));}
-
-		if (flags & CAMEL_MESSAGE_DELETED && ((set & CAMEL_MESSAGE_DELETED) != (mi->flags & CAMEL_MESSAGE_DELETED)))
-		{ deleted = set & CAMEL_MESSAGE_DELETED ? 1 : -1; d(printf("Setting deleted as %d\n", set & CAMEL_MESSAGE_DELETED ? 1 : 0));}
-
-		old = mi->flags;
-		mi->flags = (old & ~flags) | (set & flags);
-
-		if (old != mi->flags) {
-				mi->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED;
-				mi->dirty = TRUE;
-
-				if (((old & ~CAMEL_MESSAGE_SYSTEM_MASK) == (mi->flags & ~CAMEL_MESSAGE_SYSTEM_MASK)) )
-						return FALSE;
-
-				if (mi->summary) {
-						mi->summary->deleted_count += deleted;
-						mi->summary->unread_count -= read;
-						camel_folder_summary_touch(mi->summary);
-				}
-		}
-
-		junk_flag = ((flags & CAMEL_MESSAGE_JUNK) && (set & CAMEL_MESSAGE_JUNK));
-		junk_learn_flag = ((flags & CAMEL_MESSAGE_JUNK_LEARN) && (set & CAMEL_MESSAGE_JUNK_LEARN));
-
-		/* This is a hack, we are using CAMEL_MESSAGE_JUNK justo to hide the item
-		 * we make sure this doesn't have any side effects*/
-
-		if (junk_learn_flag && !junk_flag  && (old & CAMEL_GW_MESSAGE_JUNK)) {
-				/*
-				   This has ugly side-effects. Evo will never learn unjunk.
-				   We need to create one CAMEL_MESSAGE_HIDDEN flag which must be
-				   used for all hiding operations. We must also get rid of the seperate file
-				   that is maintained somewhere in evolution/mail/em-folder-browser.c for hidden messages
-				 */
-				mi->flags |= CAMEL_GW_MESSAGE_NOJUNK | CAMEL_MESSAGE_JUNK | CAMEL_MESSAGE_JUNK_LEARN;
-		} else if (junk_learn_flag && junk_flag && !(old & CAMEL_GW_MESSAGE_JUNK)) {
-				mi->flags |= CAMEL_GW_MESSAGE_JUNK | CAMEL_MESSAGE_JUNK | CAMEL_MESSAGE_JUNK_LEARN;
-		}
-
-		if (mi->summary && mi->summary->folder && mi->uid) {
-				CamelFolderChangeInfo *changes = camel_folder_change_info_new();
-
-				camel_folder_change_info_change_uid(changes, camel_message_info_uid(info));
-				camel_folder_changed (mi->summary->folder, changes);
-				camel_folder_change_info_free(changes);
-				camel_folder_summary_touch(mi->summary);
-		}
-
-		return TRUE;
+	return CAMEL_FOLDER_SUMMARY_CLASS (camel_ews_summary_parent_class)->info_set_flags (info, flags, set);
 }
 
 void
@@ -397,7 +334,7 @@ camel_ews_summary_add_message	(CamelFolderSummary *summary,
 	const CamelFlag *flag;
 	const CamelTag *tag;
 
-	info = camel_folder_summary_uid (summary, uid);
+	info = camel_folder_summary_get (summary, uid);
 
 	/* Create summary entry */
 	mi = (CamelEwsMessageInfo *)camel_folder_summary_info_new_from_message (summary, message, NULL);
@@ -430,84 +367,16 @@ camel_ews_summary_add_message_info	(CamelFolderSummary *summary,
 {
 	CamelMessageInfoBase *binfo = (CamelMessageInfoBase *) mi;
 	CamelEwsMessageInfo *einfo = (CamelEwsMessageInfo *) mi;
-	gint unread=0, junk=0;
-	guint32 flags;
 
 	binfo->flags |= server_flags;
 	einfo->server_flags = server_flags;
 
 	/* TODO update user flags */
 
-	/* update the summary count */
-	flags = binfo->flags;
-
-	if (!(flags & CAMEL_MESSAGE_SEEN))
-		unread = 1;
-
-	if (flags & CAMEL_MESSAGE_JUNK)
-		junk = 1;
-
-	if (summary) {
-		if (unread)
-			summary->unread_count += unread;
-		if (junk)
-			summary->junk_count += junk;
-		summary->visible_count++;
-		if (junk)
-			summary->visible_count -= junk;
-
-		summary->saved_count++;
-		camel_folder_summary_touch (summary);
-	}
-
 	binfo->flags &= ~CAMEL_MESSAGE_FOLDER_FLAGGED;
 	camel_folder_summary_add (summary, (CamelMessageInfo *)mi);
 }
 
-/* Caller should use camel_db_delete_uids to permanently delete the mi
-   from summary */
-void
-camel_ews_summary_delete_id	(CamelFolderSummary *summary,
-				 const gchar *uid)
-{
-	CamelMessageInfo *mi;
-
-	mi = camel_folder_summary_uid (summary, uid);
-	if (mi) {
-		CamelMessageInfoBase *dinfo = (CamelMessageInfoBase *) mi;
-		gint unread=0, deleted=0, junk=0;
-		guint32 flags;
-
-		flags = dinfo->flags;
-		if (!(flags & CAMEL_MESSAGE_SEEN))
-			unread = 1;
-
-		if (flags & CAMEL_MESSAGE_DELETED)
-			deleted = 1;
-
-		if (flags & CAMEL_MESSAGE_JUNK)
-			junk = 1;
-
-		if (unread)
-			summary->unread_count--;
-
-		if (deleted)
-			summary->deleted_count--;
-		if (junk)
-			summary->junk_count--;
-
-		if (junk && !deleted)
-			summary->junk_not_deleted_count--;
-
-		if (!junk &&  !deleted)
-			summary->visible_count--;
-
-		summary->saved_count--;
-		camel_message_info_free (mi);
-	}
-	camel_folder_summary_remove_uid_fast (summary, uid);
-}
-
 static gboolean
 ews_update_user_flags (CamelMessageInfo *info, CamelFlag *server_user_flags)
 {
@@ -536,44 +405,14 @@ camel_ews_update_message_info_flags	(CamelFolderSummary *summary,
 	CamelEwsMessageInfo *einfo = (CamelEwsMessageInfo *) info;
 	gboolean changed = FALSE;
 
-	if (server_flags != einfo->server_flags)
-	{
+	if (server_flags != einfo->server_flags) {
 		guint32 server_set, server_cleared;
-		gint read=0, deleted=0, junk=0;
 
 		server_set = server_flags & ~einfo->server_flags;
 		server_cleared = einfo->server_flags & ~server_flags;
 
-		if (server_set & CAMEL_MESSAGE_SEEN)
-			read = 1;
-		else if (server_cleared & CAMEL_MESSAGE_SEEN)
-			read = -1;
-
-		if (server_set & CAMEL_MESSAGE_DELETED)
-			deleted = 1;
-		else if (server_cleared & CAMEL_MESSAGE_DELETED)
-			deleted = -1;
-
-		if (server_set & CAMEL_MESSAGE_JUNK)
-			junk = 1;
-		else if (server_cleared & CAMEL_MESSAGE_JUNK)
-			junk = -1;
-
-		if (read) {
-			summary->unread_count -= read;
-		}
-		if (deleted)
-			summary->deleted_count += deleted;
-		if (junk)
-			summary->junk_count += junk;
-		if (junk && !deleted)
-			summary->junk_not_deleted_count += junk;
-		if (junk ||  deleted)
-			summary->visible_count -= junk ? junk : deleted;
-
-		einfo->info.flags = (einfo->info.flags | server_set) & ~server_cleared;
+		camel_message_info_set_flags (info, server_set | server_cleared, (einfo->info.flags | server_set) & ~server_cleared);
 		einfo->server_flags = server_flags;
-		einfo->info.dirty = TRUE;
 		if (info->summary)
 			camel_folder_summary_touch (info->summary);
 		changed = TRUE;
@@ -591,27 +430,27 @@ ews_summary_clear	(CamelFolderSummary *summary,
 			 gboolean uncache)
 {
 	CamelFolderChangeInfo *changes;
-	CamelMessageInfo *info;
-	gint i, count;
-	const gchar *uid;
+	GPtrArray *known_uids;
+	gint i;
 
 	changes = camel_folder_change_info_new ();
-	count = camel_folder_summary_count (summary);
-	for (i = 0; i < count; i++) {
-		if (!(info = camel_folder_summary_index (summary, i)))
+	known_uids = camel_folder_summary_get_array (summary);
+	for (i = 0; i < known_uids->len; i++) {
+		const gchar *uid = g_ptr_array_index (known_uids, i);
+
+		if (!uid)
 			continue;
 
-		uid = camel_message_info_uid (info);
 		camel_folder_change_info_remove_uid (changes, uid);
 		camel_folder_summary_remove_uid (summary, uid);
-		camel_message_info_free(info);
 	}
 
-	camel_folder_summary_clear_db (summary);
+	camel_folder_summary_clear (summary, NULL);
 	/*camel_folder_summary_save (summary);*/
 
 	if (camel_folder_change_info_changed (changes))
-		camel_folder_changed (summary->folder, changes);
+		camel_folder_changed (camel_folder_summary_get_folder (summary), changes);
 	camel_folder_change_info_free (changes);
+	camel_folder_summary_free_array (known_uids);
 }
 
diff --git a/src/camel/camel-ews-summary.h b/src/camel/camel-ews-summary.h
index fab060d..bfc2b18 100644
--- a/src/camel/camel-ews-summary.h
+++ b/src/camel/camel-ews-summary.h
@@ -97,9 +97,6 @@ void	camel_ews_summary_add_message_info
 					(CamelFolderSummary *summary,
 					 guint32 server_flags,
 					 CamelMessageInfo *info);
-void
-camel_ews_summary_delete_id		(CamelFolderSummary *summary,
-					 const gchar *id);
 void	ews_summary_clear		(CamelFolderSummary *summary,
 					 gboolean uncache);
 
diff --git a/src/camel/camel-ews-utils.c b/src/camel/camel-ews-utils.c
index 32c2656..77afcbd 100644
--- a/src/camel/camel-ews-utils.c
+++ b/src/camel/camel-ews-utils.c
@@ -296,9 +296,8 @@ camel_ews_utils_build_folder_info (CamelEwsStore *store, const gchar *fid)
 
 	curl = camel_service_get_camel_url (CAMEL_SERVICE (store));
 	url = camel_url_to_string (curl,
-			(CAMEL_URL_HIDE_PASSWORD|
 			 CAMEL_URL_HIDE_PARAMS|
-			 CAMEL_URL_HIDE_AUTH) );
+			 CAMEL_URL_HIDE_AUTH);
 
 	if ( url[strlen (url) - 1] != '/') {
 		gchar *temp_url;
@@ -575,7 +574,7 @@ sync_created_folders (CamelEwsStore *ews_store, GSList *created_folders)
 			CamelURL *url = camel_service_get_camel_url (CAMEL_SERVICE (ews_store));
 
 			add_data->folder = g_object_ref (folder);
-			add_data->account_uri = camel_url_to_string (url, CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS);
+			add_data->account_uri = camel_url_to_string (url, CAMEL_URL_HIDE_PARAMS);
 			add_data->account_name = g_strdup (camel_url_get_param (url, "email"));
 			add_data->username = g_strdup (url->user);
 			/* Duplicate... for now */
@@ -630,6 +629,7 @@ camel_ews_utils_sync_deleted_items (CamelEwsFolder *ews_folder, GSList *items_de
 	CamelFolderChangeInfo *ci;
 	CamelEwsStore *ews_store;
 	GSList *l;
+	GList *items_deleted_list = NULL;
 
 	ci = camel_folder_change_info_new ();
 	ews_store = (CamelEwsStore *) camel_folder_get_parent_store ((CamelFolder *) ews_folder);
@@ -638,12 +638,17 @@ camel_ews_utils_sync_deleted_items (CamelEwsFolder *ews_folder, GSList *items_de
 	full_name = camel_folder_get_full_name (folder);
 
 	for (l = items_deleted; l != NULL; l = g_slist_next (l)) {
-		gchar *id = (gchar *) l->data;
+		const gchar *id = l->data;
 
-		camel_ews_summary_delete_id (folder->summary, id);
+		items_deleted_list = g_list_prepend (items_deleted_list, (gpointer) id);
+
+		camel_folder_summary_remove_uid (folder->summary, id);
 		camel_folder_change_info_remove_uid (ci, id);
 	}
-	camel_db_delete_uids (((CamelStore *)ews_store)->cdb_w, full_name, items_deleted, NULL);
+
+	items_deleted_list = g_list_reverse (items_deleted_list);
+	camel_db_delete_uids (((CamelStore *)ews_store)->cdb_w, full_name, items_deleted_list, NULL);
+	g_list_free (items_deleted_list);
 
 	camel_folder_changed ((CamelFolder *) ews_folder, ci);
 	camel_folder_change_info_free (ci);
@@ -911,7 +916,7 @@ camel_ews_utils_sync_updated_items (CamelEwsFolder *ews_folder, GSList *items_up
 		CamelEwsMessageInfo *mi;
 
 		id = e_ews_item_get_id (item);
-		mi = (CamelEwsMessageInfo *) camel_folder_summary_uid (folder->summary, id->id);
+		mi = (CamelEwsMessageInfo *) camel_folder_summary_get (folder->summary, id->id);
 		if (mi) {
 			gint server_flags;
 
@@ -966,7 +971,7 @@ camel_ews_utils_sync_created_items (CamelEwsFolder *ews_folder, GSList *items_cr
 			continue;
 
 		id = e_ews_item_get_id (item);
-		mi = (CamelEwsMessageInfo *) camel_folder_summary_uid (folder->summary, id->id);
+		mi = (CamelEwsMessageInfo *) camel_folder_summary_get (folder->summary, id->id);
 		if (mi) {
 			camel_message_info_free (mi);
 			g_object_unref (item);



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