[evolution-ews/gnome-2-28: 49/49] Merge branch 'master' into gnome-2-28



commit 41fbbedfa67929b5201b7434d0556e9328197c11
Merge: c1d6105 e6a75d1
Author: Chenthill Palanisamy <pchenthill novell com>
Date:   Tue Oct 4 15:40:18 2011 +0530

    Merge branch 'master' into gnome-2-28
    
    Conflicts:
    	src/addressbook/e-book-backend-ews-gal.c
    	src/addressbook/e-book-backend-ews-utils.c
    	src/addressbook/e-book-backend-ews.c
    	src/calendar/e-cal-backend-ews.c
    	src/camel/camel-ews-folder.c

 configure.ac                                       |    6 +-
 po/POTFILES.in                                     |    3 +
 po/pl.po                                           |   87 +-
 .../exchange-ews-account-listener.c                |   13 +-
 .../exchange-ews-account-setup.c                   |   24 +-
 src/addressbook/Makefile.am                        |    4 +-
 src/addressbook/e-book-backend-ews-factory.c       |    6 +-
 src/addressbook/e-book-backend-ews-gal.c           | 1224 --------------------
 src/addressbook/e-book-backend-ews-gal.h           |   49 -
 src/addressbook/e-book-backend-ews-utils.c         |   28 +-
 src/addressbook/e-book-backend-ews.c               |  758 ++++++++++++-
 src/addressbook/e-book-backend-sqlitedb-test.c     |    4 +-
 src/addressbook/e-book-backend-sqlitedb.c          | 1100 ++++++++++++------
 src/addressbook/e-book-backend-sqlitedb.h          |   53 +-
 src/addressbook/ews-oab-decoder.c                  |   10 +-
 src/addressbook/libedata-book-compat.c             |   83 ++
 src/addressbook/libedata-book-compat.h             |   34 +
 src/calendar/Makefile.am                           |    2 +
 src/calendar/e-cal-backend-ews.c                   |  221 +++--
 src/calendar/libedata-cal-compat.c                 |  155 +++
 src/calendar/libedata-cal-compat.h                 |   51 +
 src/server/Makefile.am                             |    2 +
 src/server/e-ews-connection.c                      |    2 +-
 src/utils/ews-esource-utils.c                      |   10 +-
 24 files changed, 2096 insertions(+), 1833 deletions(-)
---
diff --cc src/addressbook/e-book-backend-ews-utils.c
index 77a7964,b3bb05f..193fc4f
--- a/src/addressbook/e-book-backend-ews-utils.c
+++ b/src/addressbook/e-book-backend-ews-utils.c
@@@ -35,13 -35,12 +35,13 @@@
  #include <glib/gstdio.h>
  #include <glib/gi18n-lib.h>
  
 -#include "e-book-backend-ews-utils.h"
 -#include "libedata-book/e-book-backend-sexp.h"
 -#include "libedata-book/e-data-book.h"
 -#include "libedata-book/e-data-book-view.h"
 +#include <libedata-book/e-book-backend-sexp.h>
 +#include <libedata-book/e-book-backend.h>
 +#include <libedata-book/e-data-book.h>
 +#include <libedata-book/e-data-book-view.h>
+ #include <libedataserver/eds-version.h>
 +#include "e-book-backend-ews-utils.h"
  
- 
  /**
   * e_book_backend_ews_utils_get_book_view:
   * @backend: an #EBookBackend
diff --cc src/addressbook/e-book-backend-ews.c
index 2da3478,5977dbd..d442bcd
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@@ -53,7 -57,11 +57,8 @@@
  #include "e-ews-connection.h"
  #include "e-ews-item.h"
  
+ #define d(x) x
 -
 -#define EDB_ERROR(_code) e_data_book_create_error (E_DATA_BOOK_STATUS_ ## _code, NULL)
 -#define EDB_ERROR_EX(_code,_msg) e_data_book_create_error (E_DATA_BOOK_STATUS_ ## _code, _msg)
 -#define EDB_ERROR_FAILED_STATUS(_code, _status) e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_ ## _code, "Failed with status 0x%x", _status)
 +#define EDB_ERROR(_code) GNOME_Evolution_Addressbook_##_code
  
  G_DEFINE_TYPE (EBookBackendEws, e_book_backend_ews, E_TYPE_BOOK_BACKEND)
  
@@@ -630,14 -761,19 +758,19 @@@ e_book_backend_ews_create_contact	(EBoo
  	priv = ebews->priv;
  
  	switch (ebews->priv->mode) {
 -	case MODE_LOCAL :
 -		if (!priv->is_writable) {
 -			e_data_book_respond_modify (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
 +	case GNOME_Evolution_Addressbook_MODE_LOCAL :
++		if (!ebews->priv->is_writable) {
++			e_data_book_respond_create (book, opid, EDB_ERROR (PermissionDenied), NULL);
+ 			return;
+ 		}
+ 
 -		e_data_book_respond_create (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
 +		e_data_book_respond_create (book, opid, EDB_ERROR (RepositoryOffline), NULL);
  		return;
  
 -	case  MODE_REMOTE :
 +	case  GNOME_Evolution_Addressbook_MODE_REMOTE :
  
  		if (ebews->priv->cnc == NULL) {
 -			e_data_book_respond_create (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
 +			e_data_book_respond_create (book, opid, EDB_ERROR (AuthenticationRequired), NULL);
  			return;
  		}
  
@@@ -698,19 -834,11 +831,18 @@@ ews_book_remove_contact_cb (GObject *ob
  	if (!g_simple_async_result_propagate_error(simple, &error))
  		deleted = e_book_backend_sqlitedb_remove_contacts (priv->ebsdb, priv->folder_id, remove_contact->sl_ids, &error);
  
 -	if (deleted)
 -		e_data_book_respond_remove_contacts_compat (remove_contact->book, remove_contact->opid, EDB_ERROR (SUCCESS),  remove_contact->sl_ids);
 -	else {
 -		e_data_book_respond_remove_contacts_compat (remove_contact->book, remove_contact->opid, EDB_ERROR_EX (OTHER_ERROR, error->message), NULL);
 -		
 +	if (deleted) {
 +		GList *dl_ids = NULL;
 +		GSList *l;
 +
 +		/* This is pretty ugly, but cant help */
 +		for (l = remove_contact->sl_ids; l != NULL; l = g_slist_next (l))
 +			dl_ids = g_list_prepend (dl_ids, l->data);
 +
 +		e_data_book_respond_remove_contacts (remove_contact->book, remove_contact->opid, EDB_ERROR (Success),  dl_ids);
 +		g_list_free (dl_ids);
 +	} else {
 +		e_data_book_respond_remove_contacts (remove_contact->book, remove_contact->opid, EDB_ERROR (OtherError), NULL);
- 		
  		g_warning ("\nError removing contact %s \n", error->message);
  	}
  
@@@ -740,13 -867,18 +871,18 @@@ e_book_backend_ews_remove_contacts	(EBo
  	priv = ebews->priv;
  
  	switch (ebews->priv->mode) {
 -	case MODE_LOCAL :
 -		if (!priv->is_writable) {
 -			e_data_book_respond_modify (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
 +	case GNOME_Evolution_Addressbook_MODE_LOCAL :
++		if (!ebews->priv->is_writable) {
++			e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (PermissionDenied), NULL);
+ 			return;
+ 		}
 -
 -		e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
++	
 +		e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (RepositoryOffline), NULL);
  		return;
  
 -	case MODE_REMOTE :
 +	case GNOME_Evolution_Addressbook_MODE_REMOTE :
  		if (ebews->priv->cnc == NULL) {
 -			e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
 +			e_data_book_respond_remove_contacts (book, opid, EDB_ERROR (AuthenticationRequired), NULL);
  			return;
  		}
  
@@@ -896,13 -1025,18 +1029,18 @@@ e_book_backend_ews_modify_contact	(EBoo
  
  	switch (priv->mode) {
  
 -	case MODE_LOCAL :
 -		if (!priv->is_writable) {
 -			e_data_book_respond_modify (book, opid, EDB_ERROR (PERMISSION_DENIED), NULL);
 +	case GNOME_Evolution_Addressbook_MODE_LOCAL :
++		if (!ebews->priv->is_writable) {
++			e_data_book_respond_modify (book, opid, EDB_ERROR (PermissionDenied), NULL);
+ 			return;
+ 		}
+ 
 -		e_data_book_respond_modify (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
 +		e_data_book_respond_modify (book, opid, EDB_ERROR (RepositoryOffline), NULL);
  		return;
 -	case MODE_REMOTE :
 +	case GNOME_Evolution_Addressbook_MODE_REMOTE :
  
 -		if (priv->cnc == NULL) {
 -			e_data_book_respond_modify (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
 +		if (ebews->priv->cnc == NULL) {
 +			e_data_book_respond_modify (book, opid, EDB_ERROR (AuthenticationRequired), NULL);
  			return;
  		}
  		
@@@ -926,10 -1060,10 +1064,10 @@@
  		}
  
  		old_contact = e_book_backend_sqlitedb_get_contact ( priv->ebsdb, priv->folder_id,
- 					 id->id, &error); 
+ 					 id->id, NULL, NULL, &error); 
  		if (!old_contact) {
  			g_object_unref (contact);
 -			e_data_book_respond_modify (book, opid, EDB_ERROR (NOT_SUPPORTED), NULL);
 +			e_data_book_respond_modify (book, opid, EDB_ERROR (OtherError), NULL);
  			return;
  		}
  
@@@ -1625,10 -2023,10 +2027,10 @@@ e_book_backend_ews_start_book_view (EBo
  	query = e_data_book_view_get_card_query (book_view);
  
  	e_data_book_view_ref (book_view);
- 	e_data_book_view_notify_status_message (book_view, _("Searching..."));
+ 	e_data_book_view_notify_progress (book_view, -1, _("Searching..."));
  
  	switch (priv->mode) {
 -	case MODE_LOCAL:
 +	case GNOME_Evolution_Addressbook_MODE_LOCAL:
  		if (e_book_backend_sqlitedb_get_is_populated (priv->ebsdb, priv->folder_id, NULL)) {
  			fetch_from_offline (ebews, book_view, query, error);
  			return;
@@@ -1731,13 -2131,79 +2133,7 @@@ e_book_backend_ews_stop_book_view (EBoo
  	}
  }
  
--static void
- e_book_backend_ews_get_changes (EBookBackend *backend,
- 				      EDataBook    *book,
- 				      guint32       opid,
- 				      const gchar *change_id)
- {
- }
 -e_book_backend_ews_load_source 	(EBookBackend           *backend,
 -				 ESource                *source,
 -				 gboolean                only_if_exists,
 -				 GError                **perror)
 -{
 -	EBookBackendEws *cbews;
 -	EBookBackendEwsPrivate *priv;
 -	const gchar *cache_dir, *email;
 -	const gchar *folder_name;
 -	const gchar *offline, *is_gal;
 -	GError *err = NULL;
 -
 -	cbews = E_BOOK_BACKEND_EWS (backend);
 -	priv = cbews->priv;
 -
 -	cache_dir = e_book_backend_get_cache_dir (backend);
 -	email = e_source_get_property (source, "email");
 -	is_gal = e_source_get_property (source, "gal");
 -	
 -	if (is_gal && !strcmp (is_gal, "1"))
 -		priv->is_gal = TRUE;
 -
 -	if (!priv->is_gal) {
 -		priv->folder_id = e_source_get_duped_property (source, "folder-id");
 -		folder_name = e_source_peek_name (source);
 -
 -		priv->ebsdb = e_book_backend_sqlitedb_new (cache_dir, email, priv->folder_id, folder_name, TRUE, &err);
 -		if (err) {
 -			g_propagate_error (perror, err);
 -			return;
 -		}
 -
 -		offline = e_source_get_property (source, "offline_sync");
 -		if (offline  && g_str_equal (offline, "1"))
 -			priv->marked_for_offline = TRUE;
 -	} else {
 -		priv->folder_id = e_source_get_duped_property (source, "oal_id");
 -	
 -		/* If folder_id is present it means the GAL is marked for offline usage, we do not check for offline_sync property */
 -		if (priv->folder_id) {
 -			priv->folder_name = g_strdup (e_source_peek_name (source));
 -			priv->oab_url = e_source_get_duped_property (source, "oab_url");
 -
 -			/* setup stagging dir, remove any old files from there */
 -			priv->attachment_dir = g_build_filename (cache_dir, "attachments", NULL);
 -			g_mkdir_with_parents (priv->attachment_dir, 0777);
 -
 -			priv->ebsdb = e_book_backend_sqlitedb_new (cache_dir, email, priv->folder_id, priv->folder_name, TRUE, &err);
 -			if (err) {
 -				g_propagate_error (perror, err);
 -				return;
 -			}
 -			priv->marked_for_offline = TRUE;
 -			priv->is_writable = FALSE;
 -		}
 -	}
 -	
 -	e_book_backend_notify_opened (backend, NULL);
 -	if (priv->mode == MODE_REMOTE)
 -		e_book_backend_set_online (backend, TRUE);
 -}
 -
 -static void
 -e_book_backend_ews_remove	(EBookBackend *backend,
 -				 EDataBook        *book,
 -				 guint32           opid,
 -				 GCancellable *cancellable)
 -{
 -	e_data_book_respond_remove (book,  opid, EDB_ERROR (SUCCESS));
 -}
 -
+ #if ! EDS_CHECK_VERSION (3,1,0)
  
  static void
  e_book_backend_ews_authenticate_user (EBookBackend *backend,
@@@ -1780,9 -2246,12 +2176,12 @@@
  		} else 
  			priv->is_writable = TRUE;
  
+ 		priv->username = e_source_get_duped_property (esource, "username");
+ 		priv->password = g_strdup (passwd);
+ 	
  		/* FIXME: Do some dummy request to ensure that the password is actually
  		   correct; don't just blindly return success */
 -		e_data_book_respond_authenticate_user (book, opid, EDB_ERROR (SUCCESS));
 +		e_data_book_respond_authenticate_user (book, opid, EDB_ERROR (Success));
  		e_book_backend_notify_writable (backend, priv->is_writable);
  		return;
  	default :
diff --cc src/calendar/e-cal-backend-ews.c
index 0daeba7,b7b3399..ea3cd39
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@@ -75,9 -74,10 +77,9 @@@ struct _ECalBackendEwsPrivate 
  	EEwsConnection *cnc;
  	gchar *folder_id;
  	gchar *user_email;
- 	gchar *cache_dir;
+ 	gchar *storage_path;
  
  	EDataCal *opening_cal;
 -	EServerMethodContext opening_ctx;
  
  	CalMode mode;
  	ECalBackendStore *store;
@@@ -89,44 -89,12 +91,48 @@@
  	guint refresh_timeout;
  	gboolean refreshing;
  	GHashTable *item_id_hash;
+ 
+ #if EDS_CHECK_VERSION (3,1,0)
+ 	ECredentials *credentials;
+ #endif
  };
  
 +static GQuark
 +ews_cal_error_quark (void)
 +{
 +	static GQuark quark = 0;
 +
 +	if (G_UNLIKELY (quark == 0)) {
 +		const gchar *string = "ews-cal-error-quark";
 +		quark = g_quark_from_static_string (string);
 +	}
 +
 +	return quark;
 +}
 +
 +static GError *
 +ews_cal_create_error (GNOME_Evolution_Calendar_CallStatus status, const gchar *custom_msg)
 +{
 +	if (status == GNOME_Evolution_Calendar_Success)
 +		return NULL;
 +
 +	return g_error_new_literal (ews_cal_error_quark(), status, custom_msg ? custom_msg : e_cal_backend_status_to_string (status));
 +}
 +
 +static GNOME_Evolution_Calendar_CallStatus
 +get_error_code (GError *error)
 +{
 +	guint code;
 +	
 +	if (!error)
 +		return 0;
 +
 +	code =	error->code;
 +	g_clear_error (&error);
 +
 +	return code;
 +}
 +
  #define PRIV_LOCK(p)   (g_static_rec_mutex_lock (&(p)->rec_mutex))
  #define PRIV_UNLOCK(p) (g_static_rec_mutex_unlock (&(p)->rec_mutex))
  
@@@ -333,9 -299,50 +341,50 @@@ e_cal_backend_ews_set_default_zone (ECa
  	PRIV_UNLOCK (priv);
  
  exit:
 -	e_data_cal_notify_default_timezone_set (cal, context, error);
 +	e_data_cal_notify_default_timezone_set (cal, EDC_ER_CODE(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)
  {
@@@ -566,42 -572,11 +615,10 @@@ e_cal_backend_ews_get_timezone (ECalBac
  		}
  	}
  
 -	e_data_cal_respond_get_timezone (cal, context, error, object);
 +	e_data_cal_notify_timezone_requested (cal, EDC_ER_CODE(error), object);
  	g_free (object);
 -
  }
  
- 
- static void
- e_cal_backend_ews_get_default_object (ECalBackend *backend, EDataCal *cal)
- {
- 
- 	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, EDC_ER_CODE(error), object);
- 	g_free (object);
- }
- 
  /* changekey can be NULL if you don't want it. itemid cannot. */
  static void
  ews_cal_component_get_item_id (ECalComponent *comp, gchar **itemid, gchar **changekey)
@@@ -697,31 -672,44 +714,66 @@@ add_comps_to_item_id_hash (ECalBackendE
  	g_slist_free (comps);
  }
  
 +static ECalSourceType
 +source_type_from_kind (icalcomponent_kind kind)
 +{
 +	ECalSourceType source_type;
 +
 +	switch (kind) {
 +		case ICAL_VEVENT_COMPONENT:
 +			source_type = E_CAL_SOURCE_TYPE_EVENT;
 +			break;
 +		case ICAL_VTODO_COMPONENT:
 +			source_type = E_CAL_SOURCE_TYPE_TODO;
 +			break;
 +		case ICAL_VJOURNAL_COMPONENT:
 +			source_type = E_CAL_SOURCE_TYPE_JOURNAL;
 +			break;
 +		default:
 +			source_type = E_CAL_SOURCE_TYPE_EVENT;
 +	}
 +	
 +	return source_type;
 +}
 +
+ static gboolean
+ connect_to_server (ECalBackendEws *cbews, const gchar *username, const gchar *password, GError **error)
+ {
+ 	ECalBackendEwsPrivate *priv;
+ 	ESource *esource;
+ 	
+ 	priv = cbews->priv;
+ 	esource = e_cal_backend_get_source (E_CAL_BACKEND (cbews));
+ 	
+ 	PRIV_LOCK (priv);
+ 
 -	if (priv->mode != CAL_MODE_LOCAL && !priv->cnc && password) {
++	if (priv->mode != GNOME_Evolution_Calendar_MODE_LOCAL && !priv->cnc && password) {
+ 		const gchar *host_url;
+ 
+ 		/* If we can be called a second time while the first is still
+ 		   "outstanding", we need a bit of a rethink... */
+ 		g_assert (!priv->opening_ctx && !priv->opening_cal);
+ 
+ 		priv->user_email = e_source_get_duped_property (esource, "email");
+ 
+ 		host_url = e_source_get_property (esource, "hosturl");
+ 		priv->cnc = e_ews_connection_new (host_url, username, password,
+ 						  NULL, NULL, error);
+ 		/* Trigger an update request, which will test our authentication */
+ 		if (priv->cnc) {
+ 			ews_start_sync (cbews);
+ 			PRIV_UNLOCK (priv);
+ 			return TRUE;
+ 		}
+ 	}
+ 
+ 	PRIV_UNLOCK (priv);
+ 	return FALSE;
+ }
+ 
 -static gboolean
 -e_cal_backend_ews_open (ECalBackend *backend, EDataCal *cal, EServerMethodContext context, GCancellable *cancellable,
 -			gboolean only_if_exists, const gchar *username, const gchar *password, GError **error)
 +static void
 +e_cal_backend_ews_open (ECalBackend *backend, EDataCal *cal, 
 +			gboolean only_if_exists, const gchar *username, const gchar *password)
  {
  	ECalBackendEws *cbews;
  	ECalBackendEwsPrivate *priv;
@@@ -729,60 -718,107 +782,50 @@@
  
  	cbews = (ECalBackendEws *) backend;
  	priv = cbews->priv;
--
 -	cache_dir = e_cal_backend_get_cache_dir (backend);
+ 	esource = e_cal_backend_get_source (E_CAL_BACKEND (cbews));
  
  	PRIV_LOCK (priv);
  	if (!priv->store) {
- 		const gchar *uri;
++		const gchar *uri, *full_uri;
 +		icalcomponent_kind kind;
 +		ECalSourceType source_type;
 +
 +		kind = e_cal_backend_get_kind (backend);
 +		source_type = source_type_from_kind (kind);
 +		uri = e_cal_backend_get_uri (backend);
 +		
- 		priv->store = (ECalBackendStore *) e_cal_backend_file_store_new (uri, source_type);
- 		priv->cache_dir = g_strdup (e_cal_backend_store_get_path (priv->store));
+ 		priv->folder_id = e_source_get_duped_property (esource, "folder-id");
 -		priv->storage_path = g_build_filename (cache_dir, priv->folder_id, NULL);
++		path = g_strconcat (uri, ";", priv->folder_id, NULL);
+ 		
 -		priv->store = e_cal_backend_file_store_new (priv->storage_path);
++		priv->store = (ECalBackendStore *) e_cal_backend_file_store_new (path, source_type);
++		priv->storage_path = g_strdup (e_cal_backend_store_get_path (priv->store));
 +
  		e_cal_backend_store_load (priv->store);
  		add_comps_to_item_id_hash (cbews);
- 		e_cal_backend_store_set_default_timezone (priv->store, priv->default_zone);
+ 		
+ 		if (priv->default_zone)
+ 			e_cal_backend_store_set_default_timezone (priv->store, priv->default_zone);
++		g_free (path);
  	}
+ 	PRIV_UNLOCK (priv);
  
- 	if (priv->mode != CAL_MODE_LOCAL && !priv->cnc) {
- 		ESource *esource;
- 		const gchar *host_url;
+ 	if (connect_to_server (cbews, username, password, error)) {
+ 		priv->opening_cal = cal;
+ 		priv->opening_ctx = context;
  
 -		return TRUE;
 -	}
 -	
 -	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)
 -{
 -	GError *error = NULL;
 -	ECalBackendEws *cbews = E_CAL_BACKEND_EWS (backend);
 -	ECalBackendEwsPrivate *priv = cbews->priv;
 -	const gchar *user_name = NULL, *password = NULL;
 -	gboolean ret;
 -
 -	if (priv->credentials)	{
 -		user_name = e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_USERNAME); 
 -		password = e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_PASSWORD);
 -	}
 -
 -	ret = e_cal_backend_ews_open (backend, cal, opid, cancellable, only_if_exists, user_name, 
 -				password, &error);
 -
 -	if (!priv->credentials)
 -		e_cal_backend_notify_auth_required (backend, TRUE, priv->credentials);
 -	
 -	e_cal_backend_notify_opened (backend, NULL);
 -	e_data_cal_respond_open (cal, opid, error);
 -}
 -
 -static void
 -e_cal_backend_ews_authenticate_user (ECalBackend *backend,
 -                                     GCancellable *cancellable,
 -                                     ECredentials *credentials)
 -{
 -	ECalBackendEws        *cbews;
 -	ECalBackendEwsPrivate *priv;
 -	GError *error = NULL;
 -
 -	cbews = E_CAL_BACKEND_EWS (backend);
 -	priv  = cbews->priv;
 -
 -	PRIV_LOCK (priv);
 -
 -	e_credentials_free (priv->credentials);
 -	priv->credentials = NULL;
 -
 -	if (!credentials || !e_credentials_has_key (credentials, E_CREDENTIALS_KEY_USERNAME)) {
 -		PRIV_UNLOCK (priv);
 -		g_propagate_error (&error, EDC_ERROR (AuthenticationFailed));
 +		/* If we can be called a second time while the first is still
 +		   "outstanding", we need a bit of a rethink... */
 +		g_assert (!priv->opening_cal);
- 
- 		esource = e_cal_backend_get_source (E_CAL_BACKEND (cbews));
- 
- 		priv->folder_id = e_source_get_duped_property (esource, "folder-id");
- 		priv->user_email = e_source_get_duped_property (esource, "email");
- 
- 		host_url = e_source_get_property (esource, "hosturl");
- 
- 		priv->opening_cal = cal;
- 
- 		priv->cnc = e_ews_connection_new (host_url, username, password,
- 						  NULL, NULL, &error);
- 		if (priv->cnc) {
- 			/* Trigger an update request, which will test our authentication */
- 			ews_start_sync (cbews);
- 
- 			PRIV_UNLOCK (priv);
- 			return;
- 		}
+ 		return;
  	}
--
- 	PRIV_UNLOCK (priv);
 -	priv->credentials = e_credentials_new_clone (credentials);
+ 	
 -	connect_to_server (cbews, e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_USERNAME),
 -			   e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_PASSWORD), &error);
 -
 -	PRIV_UNLOCK (priv);
 -
 -	g_clear_error (&error);
 +	e_data_cal_notify_open (cal, EDC_ER_CODE(error));
++	
++	return;
  }
  
 -#endif
 -
  static void
 -e_cal_backend_ews_remove (ECalBackend *backend, EDataCal *cal, EServerMethodContext context, GCancellable *cancellable)
 +e_cal_backend_ews_remove (ECalBackend *backend, EDataCal *cal)
  {
  	ECalBackendEws *cbews;
  	ECalBackendEwsPrivate *priv;
@@@ -892,11 -937,11 +935,11 @@@ e_cal_backend_ews_get_object_list (ECal
  
  	cal_backend_ews_get_object_list (backend, sexp, &objects, &error);
  
 -	e_data_cal_respond_get_object_list (cal, context, error, objects);
 +	e_data_cal_notify_object_list (cal, EDC_ER_CODE(error), objects);
  	if (objects) {
- 		for (l = objects; l != NULL; l = l->next)
 -		for (l = objects; l != NULL; l = g_slist_next (l))
++		for (l = objects; l != NULL; l = g_list_next (l))
  			g_free (l->data);
 -		g_slist_free (objects);
 +		g_list_free (objects);
  	}
  }
  
@@@ -1538,7 -1587,11 +1581,10 @@@ ews_create_object_cb(GObject *object, G
  	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);
 +	e_data_cal_notify_object_created (create_data->cal, EDC_ER_CODE(error), comp_uid, comp_str);
+ 	
+ 	/* 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);
  
  	/* place new component in our cache */
@@@ -3286,9 -3338,10 +3329,10 @@@ ews_cal_sync_items_ready_cb (GObject *o
  							 &items_created, &items_updated,
  							 &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) {
 +
 +	if (priv->opening_cal) {
  		/* Report success/failure for calendar open if pending,
  		   translating an authentication failure into something that
  		   will be recognized and handled appropriately */
@@@ -3477,18 -3540,18 +3521,18 @@@ e_cal_backend_ews_start_query (ECalBack
  
  	/* notify listeners of all objects */
  	if (objects) {
- 		e_data_cal_view_notify_objects_added (query, (const GList *) objects);
 -		e_data_cal_view_notify_objects_added_compat (query, objects);
++		e_data_cal_view_notify_objects_added (query, objects);
  
  		/* free memory */
 -		g_slist_foreach (objects, (GFunc) g_free, NULL);
 -		g_slist_free (objects);
 +		g_list_foreach (objects, (GFunc) g_free, NULL);
 +		g_list_free (objects);
  	}
  
 -	e_data_cal_view_notify_complete (query, NULL);
 +	e_data_cal_view_notify_done (query, 0);
  }
  
 -static void
 -e_cal_backend_ews_refresh (ECalBackend *backend, EDataCal *cal, EServerMethodContext context, GCancellable *cancellable) 
 +/*static void
 +e_cal_backend_ews_refresh(ECalBackend *backend, EDataCal *cal) 
  {
  	ECalBackendEws *cbews;
  	ECalBackendEwsPrivate *priv;
@@@ -3567,11 -3631,14 +3611,12 @@@ ews_cal_get_free_busy_cb (GObject *obj
  	EEwsConnection *cnc = (EEwsConnection *)obj;
  	EwsFreeBusyData *free_busy_data = user_data;
  	GSList *free_busy_sl = NULL, *i;
 -	GSList *free_busy = NULL, *j;
 +	GList *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;
 +		error->code = EDC_CODE (OtherError);
  		goto done;
  	}
  	
@@@ -3584,10 -3651,24 +3629,13 @@@
  	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
 +	e_data_cal_notify_free_busy (free_busy_data->cal, EDC_ER_CODE(error), free_busy);
  
+ 	/* FIXME free free_busy_sl ? */
 -	g_slist_foreach (free_busy, (GFunc) g_free, NULL);
 -	g_slist_free (free_busy);
 -	g_slist_foreach (free_busy_data->users, (GFunc)free, NULL);
 -	g_slist_free (free_busy_data->users);
++	g_list_foreach (free_busy, (GFunc) g_free, NULL);
++	g_list_free (free_busy);
 +	g_list_foreach (free_busy_data->users, (GFunc)free, NULL);
 +	g_list_free (free_busy_data->users);
  	g_object_unref (free_busy_data->cal);
  	g_object_unref (free_busy_data->cbews);
  	g_free (free_busy_data);
@@@ -3602,8 -3683,7 +3650,7 @@@ e_cal_backend_ews_get_free_busy (ECalBa
  	ECalBackendEwsPrivate *priv = cbews->priv;
  	GError *error = NULL;
  	EwsFreeBusyData *free_busy_data;
- 	GCancellable *cancellable = NULL;
 -	GSList *users_copy = NULL;
 +	GList *users_copy = NULL;
  
  	/* make sure we're not offline */
  	if (priv->mode == CAL_MODE_LOCAL)
@@@ -3614,7 -3694,7 +3661,7 @@@
  
  	/* EWS can support only 100 identities, which is the maximum number of identities that the Web service method can request
  	 see http://msdn.microsoft.com/en-us/library/aa564001%28v=EXCHG.140%29.aspx*/
- 	if (g_list_length (users) > 100)
 -	if (g_slist_length ((GSList *) users) > 100)
++	if (g_list_length ((GSList *) users) > 100)
  	{
  		g_propagate_error (&error, EDC_ERROR (SearchSizeLimitExceeded));
  		goto exit;
@@@ -3756,21 -4058,50 +3809,19 @@@ e_cal_backend_ews_class_init (ECalBacke
  	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;
  
- 	/* Many of these can be moved to Base class */
 -	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;
 -	
 -	/* Many of these can be moved to Base class */
  	backend_class->add_timezone = e_cal_backend_ews_add_timezone;
- 	backend_class->get_default_object = e_cal_backend_ews_get_default_object;
  	backend_class->get_timezone = e_cal_backend_ews_get_timezone;
  
- 	backend_class->internal_get_timezone = e_cal_backend_ews_internal_get_timezone;
- 
 -	backend_class->open = e_cal_backend_ews_open_compat;
 -	backend_class->authenticate_user = e_cal_backend_ews_authenticate_user;
 +	backend_class->open = e_cal_backend_ews_open;
+ 	backend_class->refresh = e_cal_backend_ews_refresh;
  	backend_class->get_object = e_cal_backend_ews_get_object;
  	backend_class->get_object_list = e_cal_backend_ews_get_object_list;
  	backend_class->remove = e_cal_backend_ews_remove;
  
- 	backend_class->start_query = e_cal_backend_ews_start_query;
--
  	backend_class->discard_alarm = e_cal_backend_ews_discard_alarm;
  
  	backend_class->create_object = e_cal_backend_ews_create_object;



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