[evolution-data-server/account-mgmt: 19/40] Adapt libedata-cal to the new ESource API.



commit d91ca6151884a98315bb54ac9cdf63c5b034a309
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Nov 13 15:02:02 2010 -0500

    Adapt libedata-cal to the new ESource API.

 calendar/libedata-cal/e-cal-backend-factory.c      |    2 +
 calendar/libedata-cal/e-cal-backend-sync.c         |   36 ----
 calendar/libedata-cal/e-cal-backend-sync.h         |    4 -
 calendar/libedata-cal/e-cal-backend-util.c         |  177 ++++++++++++++------
 calendar/libedata-cal/e-cal-backend-util.h         |   17 ++-
 calendar/libedata-cal/e-cal-backend.c              |   96 +----------
 calendar/libedata-cal/e-cal-backend.h              |    4 -
 calendar/libedata-cal/e-data-cal-factory.c         |  141 ++++++++--------
 calendar/libedata-cal/e-data-cal.c                 |   82 ---------
 calendar/libedata-cal/e-data-cal.h                 |    1 -
 calendar/libedata-cal/e-data-cal.xml               |    8 -
 .../libedata-cal/libedata-cal-sections.txt         |    4 -
 12 files changed, 214 insertions(+), 358 deletions(-)
---
diff --git a/calendar/libedata-cal/e-cal-backend-factory.c b/calendar/libedata-cal/e-cal-backend-factory.c
index 45238b3..2b69a89 100644
--- a/calendar/libedata-cal/e-cal-backend-factory.c
+++ b/calendar/libedata-cal/e-cal-backend-factory.c
@@ -55,6 +55,7 @@ cal_backend_factory_get_hash_key (EBackendFactory *factory)
 
 static EBackend *
 cal_backend_factory_new_backend (EBackendFactory *factory,
+                                 ESourceRegistry *registry,
                                  ESource *source)
 {
 	ECalBackendFactoryClass *class;
@@ -66,6 +67,7 @@ cal_backend_factory_new_backend (EBackendFactory *factory,
 	return g_object_new (
 		class->backend_type,
 		"kind", class->component_kind,
+		"registry", registry,
 		"source", source, NULL);
 }
 
diff --git a/calendar/libedata-cal/e-cal-backend-sync.c b/calendar/libedata-cal/e-cal-backend-sync.c
index f6226e5..963073b 100644
--- a/calendar/libedata-cal/e-cal-backend-sync.c
+++ b/calendar/libedata-cal/e-cal-backend-sync.c
@@ -89,29 +89,6 @@ e_cal_backend_sync_open (ECalBackendSync *backend,
 }
 
 /**
- * e_cal_backend_sync_authenticate_user:
- * @backend: an #ECalBackendSync
- * @cancellable: a #GCancellable for the operation
- * @credentials: an #ECredentials to authenticate with
- * @error: #GError to set, when something fails
- *
- * Authenticates @backend with given @credentials.
- *
- * Since: 3.2
- **/
-void
-e_cal_backend_sync_authenticate_user (ECalBackendSync *backend,
-                                      GCancellable *cancellable,
-                                      ECredentials *credentials,
-                                      GError **error)
-{
-	e_return_data_cal_error_if_fail (E_IS_CAL_BACKEND_SYNC (backend), InvalidArg);
-	e_return_data_cal_error_if_fail (credentials, InvalidArg);
-
-	LOCK_WRAPPER (authenticate_user_sync, (backend, cancellable, credentials, error));
-}
-
-/**
  * e_cal_backend_sync_remove:
  * @backend: An ECalBackendSync object.
  * @cal: An EDataCal object.
@@ -597,18 +574,6 @@ cal_backend_open (ECalBackend *backend,
 }
 
 static void
-cal_backend_authenticate_user (ECalBackend *backend,
-                               GCancellable *cancellable,
-                               ECredentials *credentials)
-{
-	GError *error = NULL;
-
-	e_cal_backend_sync_authenticate_user (E_CAL_BACKEND_SYNC (backend), cancellable, credentials, &error);
-
-	e_cal_backend_notify_opened (backend, error);
-}
-
-static void
 cal_backend_remove (ECalBackend *backend,
                     EDataCal *cal,
                     guint32 opid,
@@ -1040,7 +1005,6 @@ e_cal_backend_sync_class_init (ECalBackendSyncClass *class)
 
 	backend_class = E_CAL_BACKEND_CLASS (class);
 	backend_class->open			= cal_backend_open;
-	backend_class->authenticate_user	= cal_backend_authenticate_user;
 	backend_class->remove			= cal_backend_remove;
 	backend_class->refresh			= cal_backend_refresh;
 	backend_class->get_backend_property	= cal_backend_get_backend_property;
diff --git a/calendar/libedata-cal/e-cal-backend-sync.h b/calendar/libedata-cal/e-cal-backend-sync.h
index 6b7d180..826e648 100644
--- a/calendar/libedata-cal/e-cal-backend-sync.h
+++ b/calendar/libedata-cal/e-cal-backend-sync.h
@@ -48,8 +48,6 @@ struct _ECalBackendSyncClass {
 	void	(* discard_alarm_sync)		(ECalBackendSync *backend, EDataCal *cal, GCancellable *cancellable, const gchar *uid, const gchar *rid, const gchar *auid, GError **error);
 	void	(* get_timezone_sync)		(ECalBackendSync *backend, EDataCal *cal, GCancellable *cancellable, const gchar *tzid, gchar **tzobject, GError **error);
 	void	(* add_timezone_sync)		(ECalBackendSync *backend, EDataCal *cal, GCancellable *cancellable, const gchar *tzobject, GError **error);
-
-	void	(* authenticate_user_sync)	(ECalBackendSync *backend, GCancellable *cancellable, ECredentials *credentials, GError **error);
 };
 
 GType	e_cal_backend_sync_get_type		(void);
@@ -74,8 +72,6 @@ void	e_cal_backend_sync_discard_alarm	(ECalBackendSync *backend, EDataCal *cal,
 void	e_cal_backend_sync_get_timezone		(ECalBackendSync *backend, EDataCal *cal, GCancellable *cancellable, const gchar *tzid, gchar **tzobject, GError **error);
 void	e_cal_backend_sync_add_timezone		(ECalBackendSync *backend, EDataCal *cal, GCancellable *cancellable, const gchar *tzobject, GError **error);
 
-void	e_cal_backend_sync_authenticate_user	(ECalBackendSync *backend, GCancellable *cancellable, ECredentials *credentials, GError **error);
-
 G_END_DECLS
 
 #endif /* __E_CAL_BACKEND_SYNC_H__ */
diff --git a/calendar/libedata-cal/e-cal-backend-util.c b/calendar/libedata-cal/e-cal-backend-util.c
index 4adf829..65302ee 100644
--- a/calendar/libedata-cal/e-cal-backend-util.c
+++ b/calendar/libedata-cal/e-cal-backend-util.c
@@ -26,70 +26,139 @@
 #include <string.h>
 #include <glib/gi18n-lib.h>
 #include "e-cal-backend-util.h"
-#include "libedataserver/e-account-list.h"
-
-static EAccountList *accounts;
+#include <libedataserver/e-source-mail-account.h>
+#include <libedataserver/e-source-mail-identity.h>
 
 /**
  * e_cal_backend_mail_account_get_default:
- * @address: Placeholder for default address.
- * @name: Placeholder for name.
+ * @registry: an #ESourceRegistry
+ * @address: placeholder for default address
+ * @name: placeholder for name
  *
  * Retrieve the default mail account as stored in Evolution configuration.
  *
  * Returns: TRUE if there is a default account, FALSE otherwise.
  */
 gboolean
-e_cal_backend_mail_account_get_default (gchar **address,
+e_cal_backend_mail_account_get_default (ESourceRegistry *registry,
+                                        gchar **address,
                                         gchar **name)
 {
-	const EAccount *account;
+	ESource *source;
+	ESourceMailAccount *mail_account;
+	ESourceMailIdentity *mail_identity;
+	const gchar *extension_name;
+	const gchar *identity_uid;
+	const gchar *value;
 
-	if (accounts == NULL) {
-		GConfClient *gconf = gconf_client_get_default ();
+	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
 
-		accounts = e_account_list_new (gconf);
+	source = e_source_registry_get_default_mail_account (registry);
 
-		g_object_unref (gconf);
-	}
+	if (source == NULL)
+		return FALSE;
 
-	account = e_account_list_get_default (accounts);
-	if (account) {
-		*address = g_strdup(account->id->address);
-		*name = g_strdup(account->id->name);
-	}
+	extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
+	if (!e_source_has_extension (source, extension_name))
+		return FALSE;
+
+	mail_account = e_source_get_extension (source, extension_name);
+	identity_uid = e_source_mail_account_get_identity_uid (mail_account);
+	source = e_source_registry_lookup_by_uid (registry, identity_uid);
+
+	if (source == NULL)
+		return FALSE;
+
+	extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
+	if (!e_source_has_extension (source, extension_name))
+		return FALSE;
 
-	return account != NULL;
+	mail_identity = e_source_get_extension (source, extension_name);
+
+	value = e_source_mail_identity_get_address (mail_identity);
+	if (address != NULL)
+		*address = g_strdup (value);
+
+	value = e_source_mail_identity_get_name (mail_identity);
+	if (name != NULL)
+		*name = g_strdup (value);
+
+	return TRUE;
 }
 
 /**
  * e_cal_backend_mail_account_is_valid:
- * @user: User name for the account to check.
- * @name: Placeholder for the account name.
+ * @registry: an #ESourceRegistry
+ * @user: user name for the account to check
+ * @name: placeholder for the account name
  *
  * Checks that a mail account is valid, and returns its name.
  *
  * Returns: TRUE if the account is valid, FALSE if not.
  */
 gboolean
-e_cal_backend_mail_account_is_valid (gchar *user,
+e_cal_backend_mail_account_is_valid (ESourceRegistry *registry,
+                                     gchar *user,
                                      gchar **name)
 {
-	const EAccount *account;
+	GList *list, *iter;
+	const gchar *extension_name;
+	gboolean valid = FALSE;
+
+	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
+	g_return_val_if_fail (user != NULL, FALSE);
+
+	extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
+
+	list = e_source_registry_list_sources (registry, extension_name);
+
+	for (iter = list; iter != NULL; iter = g_list_next (iter)) {
+		ESource *source = E_SOURCE (iter->data);
+		ESourceMailAccount *mail_account;
+		ESourceMailIdentity *mail_identity;
+		const gchar *address;
+		const gchar *display_name;
+		const gchar *uid;
+
+		display_name = e_source_get_display_name (source);
+
+		if (!e_source_get_enabled (source))
+			continue;
+
+		extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
+		mail_account = e_source_get_extension (source, extension_name);
+		uid = e_source_mail_account_get_identity_uid (mail_account);
+
+		if (uid == NULL)
+			continue;
+
+		source = e_source_registry_lookup_by_uid (registry, uid);
 
-	if (accounts == NULL) {
-		GConfClient *gconf = gconf_client_get_default ();
+		if (source == NULL)
+			continue;
+
+		extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
 
-		accounts = e_account_list_new (gconf);
+		if (!e_source_has_extension (source, extension_name))
+			continue;
 
-		g_object_unref (gconf);
+		mail_identity = e_source_get_extension (source, extension_name);
+		address = e_source_mail_identity_get_address (mail_identity);
+
+		if (address == NULL)
+			continue;
+
+		if (g_ascii_strcasecmp (address, user) == 0) {
+			if (name != NULL)
+				*name = g_strdup (display_name);
+			valid = TRUE;
+			break;
+		}
 	}
 
-	account = e_account_list_find (accounts, E_ACCOUNT_FIND_ID_ADDRESS, user);
-	if (account)
-		*name = g_strdup(account->id->name);
+	g_list_free_full (list, (GDestroyNotify) g_object_unref);
 
-	return account != NULL;
+	return valid;
 }
 
 /**
@@ -143,7 +212,8 @@ is_attendee_declined (icalcomponent *icalcomp,
 
 /**
  * e_cal_backend_user_declined:
- * @icalcomp: Component where to check.
+ * @registry: an #ESourceRegistry
+ * @icalcomp: component where to check
  *
  * Returns: Whether icalcomp contains attendee with a mail same as any of
  *          configured enabled mail account and whether this user declined.
@@ -151,37 +221,42 @@ is_attendee_declined (icalcomponent *icalcomp,
  * Since: 2.26
  **/
 gboolean
-e_cal_backend_user_declined (icalcomponent *icalcomp)
+e_cal_backend_user_declined (ESourceRegistry *registry,
+                             icalcomponent *icalcomp)
 {
-	gboolean res = FALSE;
-	EAccountList *accounts;
-	GConfClient *gconf;
+	GList *list, *iter;
+	const gchar *extension_name;
+	gboolean declined = FALSE;
 
+	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
 	g_return_val_if_fail (icalcomp != NULL, FALSE);
 
-	gconf = gconf_client_get_default ();
-	accounts = e_account_list_new (gconf);
+	extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
 
-	if (accounts) {
-		EIterator *it;
+	list = e_source_registry_list_sources (registry, extension_name);
 
-		for (it = e_list_get_iterator (E_LIST (accounts)); e_iterator_is_valid (it); e_iterator_next (it)) {
-			EAccount *account = (EAccount *) e_iterator_get (it);
+	for (iter = list; iter != NULL; iter = g_list_next (iter)) {
+		ESource *source = E_SOURCE (iter->data);
+		ESourceMailIdentity *extension;
+		const gchar *address;
 
-			if (account && account->enabled && e_account_get_string (account, E_ACCOUNT_ID_ADDRESS)) {
-				res = is_attendee_declined (icalcomp, e_account_get_string (account, E_ACCOUNT_ID_ADDRESS));
+		if (!e_source_get_enabled (source))
+			continue;
 
-				if (res)
-					break;
-			}
-		}
+		extension = e_source_get_extension (source, extension_name);
+		address = e_source_mail_identity_get_address (extension);
 
-		g_object_unref (it);
-		g_object_unref (accounts);
+		if (address == NULL)
+			continue;
+
+		if (is_attendee_declined (icalcomp, address)) {
+			declined = TRUE;
+			break;
+		}
 	}
 
-	g_object_unref (gconf);
+	g_list_free_full (list, (GDestroyNotify) g_object_unref);
 
-	return res;
+	return declined;
 }
 
diff --git a/calendar/libedata-cal/e-cal-backend-util.h b/calendar/libedata-cal/e-cal-backend-util.h
index 55cc712..7842158 100644
--- a/calendar/libedata-cal/e-cal-backend-util.h
+++ b/calendar/libedata-cal/e-cal-backend-util.h
@@ -23,6 +23,7 @@
 #define E_CAL_BACKEND_UTIL_H
 
 #include <libedata-cal/e-cal-backend.h>
+#include <libedataserver/e-source-registry.h>
 
 G_BEGIN_DECLS
 
@@ -30,11 +31,17 @@ G_BEGIN_DECLS
  * Functions for accessing mail configuration
  */
 
-gboolean e_cal_backend_mail_account_get_default (gchar **address, gchar **name);
-gboolean e_cal_backend_mail_account_is_valid (gchar *user, gchar **name);
-
-gboolean e_cal_backend_user_declined (icalcomponent *icalcomp);
+gboolean	e_cal_backend_mail_account_get_default
+						(ESourceRegistry *registry,
+						 gchar **address,
+						 gchar **name);
+gboolean	e_cal_backend_mail_account_is_valid
+						(ESourceRegistry *registry,
+						 gchar *user,
+						 gchar **name);
+gboolean	e_cal_backend_user_declined	(ESourceRegistry *registry,
+                                                 icalcomponent *icalcomp);
 
 G_END_DECLS
 
-#endif
+#endif /* E_CAL_BACKEND_UTIL_H */
diff --git a/calendar/libedata-cal/e-cal-backend.c b/calendar/libedata-cal/e-cal-backend.c
index d956ae3..f289dcc 100644
--- a/calendar/libedata-cal/e-cal-backend.c
+++ b/calendar/libedata-cal/e-cal-backend.c
@@ -45,9 +45,6 @@ struct _ECalBackendPrivate {
 
 	gboolean opening, opened, readonly, removed;
 
-	/* URI, from source. This is cached, since we return const. */
-	gchar *uri;
-
 	gchar *cache_dir;
 
 	/* List of Cal objects */
@@ -80,7 +77,7 @@ cal_backend_set_default_cache_dir (ECalBackend *backend)
 	icalcomponent_kind kind;
 	const gchar *component_type;
 	const gchar *user_cache_dir;
-	gchar *mangled_uri;
+	const gchar *uid;
 	gchar *filename;
 
 	user_cache_dir = e_get_user_cache_dir ();
@@ -88,6 +85,9 @@ cal_backend_set_default_cache_dir (ECalBackend *backend)
 	kind = e_cal_backend_get_kind (backend);
 	source = e_backend_get_source (E_BACKEND (backend));
 
+	uid = e_source_get_uid (source);
+	g_return_if_fail (uid != NULL);
+
 	switch (kind) {
 		case ICAL_VEVENT_COMPONENT:
 			component_type = "calendar";
@@ -102,15 +102,10 @@ cal_backend_set_default_cache_dir (ECalBackend *backend)
 			g_return_if_reached ();
 	}
 
-	/* Mangle the URI to not contain invalid characters. */
-	mangled_uri = g_strdelimit (e_source_get_uri (source), ":/", '_');
-
 	filename = g_build_filename (
-		user_cache_dir, component_type, mangled_uri, NULL);
+		user_cache_dir, component_type, uid, NULL);
 	e_cal_backend_set_cache_dir (backend, filename);
 	g_free (filename);
-
-	g_free (mangled_uri);
 }
 
 static void
@@ -819,39 +814,6 @@ e_cal_backend_open (ECalBackend *backend,
 }
 
 /**
- * e_cal_backend_authenticate_user:
- * @backend: an #ECalBackend
- * @cancellable: a #GCancellable for the operation
- * @credentials: #ECredentials to use for authentication
- *
- * Notifies @backend about @credentials provided by user to use
- * for authentication. This notification is usually called during
- * opening phase as a response to e_cal_backend_notify_auth_required()
- * on the client side and it results in setting property 'opening' to %TRUE
- * unless the backend is already opened. This function finishes opening
- * phase, thus it should be finished with e_cal_backend_notify_opened().
- *
- * See information at e_cal_backend_open() for more details
- * how the opening phase works.
- *
- * Since: 3.2
- **/
-void
-e_cal_backend_authenticate_user (ECalBackend *backend,
-                                 GCancellable *cancellable,
-                                 ECredentials *credentials)
-{
-	g_return_if_fail (E_IS_CAL_BACKEND (backend));
-	g_return_if_fail (credentials != NULL);
-	g_return_if_fail (E_CAL_BACKEND_GET_CLASS (backend)->authenticate_user);
-
-	if (!e_cal_backend_is_opened (backend))
-		backend->priv->opening = TRUE;
-
-	(* E_CAL_BACKEND_GET_CLASS (backend)->authenticate_user) (backend, cancellable, credentials);
-}
-
-/**
  * e_cal_backend_remove:
  * @backend: an #ECalBackend
  * @cal: an #EDataCal
@@ -1878,54 +1840,6 @@ e_cal_backend_notify_online (ECalBackend *backend,
 }
 
 /**
- * e_cal_backend_notify_auth_required:
- * @backend: an #ECalBackend
- * @is_self: Use %TRUE to indicate the authentication is required
- *    for the @backend, otheriwse the authentication is for any
- *    other source. Having @credentials %NULL means @is_self
- *    automatically.
- * @credentials: an #ECredentials that contains extra information for
- *    a source for which authentication is requested.
- *    This parameter can be NULL to indicate "for this calendar".
- *
- * Notifies clients that @backend requires authentication in order to
- * connect. This function call does not influence 'opening', but 
- * influences 'opened' property, which is set to %FALSE when @is_self
- * is %TRUE or @credentials is %NULL. Opening phase is finished
- * by e_cal_backend_notify_opened() if this is requested for @backend.
- *
- * See e_cal_backend_open() for a description how the whole opening
- * phase works.
- *
- * Meant to be used by backend implementations.
- **/
-void
-e_cal_backend_notify_auth_required (ECalBackend *backend,
-                                    gboolean is_self,
-                                    const ECredentials *credentials)
-{
-	ECalBackendPrivate *priv;
-	GSList *clients;
-
-	priv = backend->priv;
-
-	if (priv->notification_proxy) {
-		e_cal_backend_notify_auth_required (priv->notification_proxy, is_self, credentials);
-		return;
-	}
-
-	g_mutex_lock (priv->clients_mutex);
-
-	if (is_self || !credentials)
-		priv->opened = FALSE;
-
-	for (clients = priv->clients; clients != NULL; clients = g_slist_next (clients))
-		e_data_cal_report_auth_required (E_DATA_CAL (clients->data), credentials);
-
-	g_mutex_unlock (priv->clients_mutex);
-}
-
-/**
  * e_cal_backend_notify_opened:
  * @backend: an #ECalBackend
  * @error: a #GError corresponding to the error encountered during
diff --git a/calendar/libedata-cal/e-cal-backend.h b/calendar/libedata-cal/e-cal-backend.h
index 20e99d0..4af7d84 100644
--- a/calendar/libedata-cal/e-cal-backend.h
+++ b/calendar/libedata-cal/e-cal-backend.h
@@ -154,7 +154,6 @@ struct _ECalBackendClass {
 
 	void	(* open)			(ECalBackend *backend, EDataCal *cal, guint32 opid, GCancellable *cancellable, gboolean only_if_exists);
 	void	(* remove)			(ECalBackend *backend, EDataCal *cal, guint32 opid, GCancellable *cancellable);
-	void	(* authenticate_user)		(ECalBackend *backend, GCancellable *cancellable, ECredentials *credentials);
 
 	void	(* refresh)			(ECalBackend *backend, EDataCal *cal, guint32 opid, GCancellable *cancellable);
 	void	(* get_object)			(ECalBackend *backend, EDataCal *cal, guint32 opid, GCancellable *cancellable, const gchar *uid, const gchar *rid);
@@ -204,8 +203,6 @@ void		e_cal_backend_set_notification_proxy	(ECalBackend *backend, ECalBackend *p
 void		e_cal_backend_get_backend_property	(ECalBackend *backend, EDataCal *cal, guint32 opid, GCancellable *cancellable, const gchar *prop_name);
 void		e_cal_backend_set_backend_property	(ECalBackend *backend, EDataCal *cal, guint32 opid, GCancellable *cancellable, const gchar *prop_name, const gchar *prop_value);
 
-void		e_cal_backend_authenticate_user		(ECalBackend *backend, GCancellable *cancellable, ECredentials *credentials);
-
 void		e_cal_backend_open			(ECalBackend *backend, EDataCal *cal, guint32 opid, GCancellable *cancellable, gboolean only_if_exists);
 void		e_cal_backend_remove			(ECalBackend *backend, EDataCal *cal, guint32 opid, GCancellable *cancellable);
 void		e_cal_backend_refresh			(ECalBackend *backend, EDataCal *cal, guint32 opid, GCancellable *cancellable);
@@ -247,7 +244,6 @@ void		e_cal_backend_notify_objects_removed	(ECalBackend *backend, EDataCalView *
 void		e_cal_backend_notify_error		(ECalBackend *backend, const gchar *message);
 void		e_cal_backend_notify_readonly		(ECalBackend *backend, gboolean is_readonly);
 void		e_cal_backend_notify_online		(ECalBackend *backend, gboolean is_online);
-void		e_cal_backend_notify_auth_required	(ECalBackend *backend, gboolean is_self, const ECredentials *credentials);
 void		e_cal_backend_notify_opened		(ECalBackend *backend, GError *error);
 void		e_cal_backend_notify_property_changed	(ECalBackend *backend, const gchar *prop_name, const gchar *prop_value);
 
diff --git a/calendar/libedata-cal/e-data-cal-factory.c b/calendar/libedata-cal/e-data-cal-factory.c
index 484c97c..3cd200d 100644
--- a/calendar/libedata-cal/e-data-cal-factory.c
+++ b/calendar/libedata-cal/e-data-cal-factory.c
@@ -30,6 +30,8 @@
 #include <unistd.h>
 #include <glib/gi18n.h>
 
+#include <libedataserver/e-source-calendar.h>
+
 #include "e-cal-backend.h"
 #include "e-cal-backend-factory.h"
 #include "e-data-cal.h"
@@ -59,62 +61,59 @@ struct _EDataCalFactoryPrivate {
 
 G_DEFINE_TYPE (EDataCalFactory, e_data_cal_factory, E_TYPE_DATA_FACTORY);
 
-static const gchar *
-calobjtype_to_string (const EDataCalObjType type)
-{
-	switch (type) {
-	case Event:
-		return "VEVENT";
-	case Todo:
-		return "VTODO";
-	case Journal:
-		return "VJOURNAL";
-	case AnyType:
-		break;
-	}
-
-	g_return_val_if_reached (NULL);
-}
-
-static gchar *
-e_data_cal_factory_extract_proto_from_uri (const gchar *uri)
-{
-	gchar *proto, *cp;
-
-	cp = strchr (uri, ':');
-	if (cp == NULL)
-		return NULL;
-
-	proto = g_malloc0 (cp - uri + 1);
-	strncpy (proto, uri, cp - uri);
-
-	return proto;
-}
-
 static EBackend *
-e_data_cal_factory_get_backend (EDataCalFactory *factory,
+e_data_cal_factory_get_backend (EDataFactory *factory,
                                 ESource *source,
-                                const gchar *uri,
-                                EDataCalObjType type)
+                                EDataCalObjType type,
+                                GError **error)
 {
 	EBackend *backend;
-	gchar *protocol;
+	ESourceBackend *extension;
+	const gchar *extension_name;
+	const gchar *type_string;
+	gchar *backend_name;
 	gchar *hash_key;
 
-	protocol = e_data_cal_factory_extract_proto_from_uri (uri);
-	if (protocol == NULL) {
-		g_warning ("Cannot extract protocol from URI %s", uri);
-		return NULL;
+	switch (type) {
+		case Event:
+			extension_name = E_SOURCE_EXTENSION_CALENDAR;
+			type_string = "VEVENT";
+			break;
+		case Todo:
+			extension_name = E_SOURCE_EXTENSION_TASK_LIST;
+			type_string = "VTODO";
+			break;
+		case Journal:
+			extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
+			type_string = "VJOURNAL";
+			break;
+		default:
+			g_return_val_if_reached (NULL);
 	}
 
-	hash_key = g_strdup_printf (
-		"%s:%s", protocol, calobjtype_to_string (type));
+	extension = e_source_get_extension (source, extension_name);
+	backend_name = e_source_backend_dup_backend_name (extension);
 
-	backend = e_data_factory_get_backend (
-		E_DATA_FACTORY (factory), hash_key, source);
+	if (backend_name == NULL || *backend_name == '\0') {
+		g_set_error (
+			error, E_DATA_CAL_ERROR, NoSuchCal,
+			_("No backend name in source '%s'"),
+			e_source_get_display_name (source));
+		g_free (backend_name);
+		return NULL;
+	}
 
+	hash_key = g_strdup_printf ("%s:%s", backend_name, type_string);
+	backend = e_data_factory_get_backend (factory, hash_key, source);
 	g_free (hash_key);
-	g_free (protocol);
+
+	if (backend == NULL)
+		g_set_error (
+			error, E_DATA_CAL_ERROR, NoSuchCal,
+			_("Invalid backend name '%s' in source '%s'"),
+			backend_name, e_source_get_display_name (source));
+
+	g_free (backend_name);
 
 	return backend;
 }
@@ -182,19 +181,19 @@ impl_CalFactory_get_cal (EGdbusCalFactory *object,
 	EBackend *backend;
 	EDataCalFactoryPrivate *priv = factory->priv;
 	GDBusConnection *connection;
+	ESourceRegistry *registry;
 	ESource *source;
-	gchar *uri;
 	gchar *path = NULL;
 	const gchar *sender;
 	GList *list;
 	GError *error = NULL;
-	gchar *source_xml = NULL;
+	gchar *uid = NULL;
 	guint type = 0;
 
 	sender = g_dbus_method_invocation_get_sender (invocation);
 	connection = g_dbus_method_invocation_get_connection (invocation);
 
-	if (!e_gdbus_cal_factory_decode_get_cal (in_source_type, &source_xml, &type)) {
+	if (!e_gdbus_cal_factory_decode_get_cal (in_source_type, &uid, &type)) {
 		error = g_error_new (
 			E_DATA_CAL_ERROR, NoSuchCal, _("Invalid call"));
 		g_dbus_method_invocation_return_gerror (invocation, error);
@@ -203,49 +202,43 @@ impl_CalFactory_get_cal (EGdbusCalFactory *object,
 		return TRUE;
 	}
 
-	source = e_source_new_from_standalone_xml (source_xml);
-	g_free (source_xml);
-
-	if (!source) {
-		error = g_error_new (
-			E_DATA_CAL_ERROR,
-			NoSuchCal,
-			_("Invalid source"));
+	if (uid == NULL || *uid == '\0') {
+		error = g_error_new_literal (
+			E_DATA_CAL_ERROR, NoSuchCal,
+			_("Missing source UID"));
 		g_dbus_method_invocation_return_gerror (invocation, error);
 		g_error_free (error);
+		g_free (uid);
 
 		return TRUE;
 	}
 
-	uri = e_source_get_uri (source);
-
-	if (uri == NULL || *uri == '\0') {
-		g_object_unref (source);
-		g_free (uri);
+	registry = e_data_factory_get_registry (E_DATA_FACTORY (factory));
+	source = e_source_registry_lookup_by_uid (registry, uid);
 
+	if (source == NULL) {
 		error = g_error_new (
-			E_DATA_CAL_ERROR,
-			NoSuchCal,
-			_("Empty URI"));
+			E_DATA_CAL_ERROR, NoSuchCal,
+			_("No such source for UID '%s'"), uid);
 		g_dbus_method_invocation_return_gerror (invocation, error);
 		g_error_free (error);
+		g_free (uid);
 
 		return TRUE;
 	}
 
-	backend = e_data_cal_factory_get_backend (factory, source, uri, type);
+	backend = e_data_cal_factory_get_backend (
+		E_DATA_FACTORY (factory), source, type, &error);
 
-	if (backend == NULL) {
-		error = g_error_new (
-			E_DATA_CAL_ERROR,
-			NoSuchCal,
-			_("Invalid source"));
+	if (error != NULL) {
 		g_dbus_method_invocation_return_gerror (invocation, error);
 		g_error_free (error);
 
 		return TRUE;
 	}
 
+	g_return_val_if_fail (E_IS_BACKEND (backend), FALSE);
+
 	g_mutex_lock (priv->calendars_lock);
 
 	e_dbus_server_hold (E_DBUS_SERVER (factory));
@@ -268,8 +261,7 @@ impl_CalFactory_get_cal (EGdbusCalFactory *object,
 
 	g_mutex_unlock (priv->calendars_lock);
 
-	g_object_unref (source);
-	g_free (uri);
+	g_free (uid);
 
 	e_gdbus_cal_factory_complete_get_cal (
 		object, invocation, path, error);
@@ -409,6 +401,11 @@ e_data_cal_factory_class_init (EDataCalFactoryClass *class)
 	dbus_server_class->module_directory = BACKENDDIR;
 	dbus_server_class->bus_acquired = data_cal_factory_bus_acquired;
 	dbus_server_class->bus_name_lost = data_cal_factory_bus_name_lost;
+
+	/* Register ESource extensions we'll need. */
+	E_TYPE_SOURCE_CALENDAR;
+	E_TYPE_SOURCE_MEMO_LIST;
+	E_TYPE_SOURCE_TASK_LIST;
 }
 
 static void
diff --git a/calendar/libedata-cal/e-data-cal.c b/calendar/libedata-cal/e-data-cal.c
index 680baf4..15e745d 100644
--- a/calendar/libedata-cal/e-data-cal.c
+++ b/calendar/libedata-cal/e-data-cal.c
@@ -63,7 +63,6 @@ static EOperationPool *ops_pool = NULL;
 
 typedef enum {
 	OP_OPEN,
-	OP_AUTHENTICATE,
 	OP_REMOVE,
 	OP_REFRESH,
 	OP_GET_BACKEND_PROPERTY,
@@ -95,8 +94,6 @@ typedef struct {
 	union {
 		/* OP_OPEN */
 		gboolean only_if_exists;
-		/* OP_AUTHENTICATE */
-		ECredentials *credentials;
 		/* OP_GET_OBJECT */
 		/* OP_GET_ATTACHMENT_URIS */
 		struct _ur {
@@ -302,10 +299,6 @@ operation_thread (gpointer data,
 		e_cal_backend_add_timezone (backend, op->cal, op->id, op->cancellable, op->d.tzobject);
 		g_free (op->d.tzobject);
 		break;
-	case OP_AUTHENTICATE:
-		e_cal_backend_authenticate_user (backend, op->cancellable, op->d.credentials);
-		e_credentials_free (op->d.credentials);
-		break;
 	case OP_CANCEL_OPERATION:
 		g_static_rec_mutex_lock (&op->cal->priv->pending_ops_lock);
 
@@ -503,22 +496,6 @@ e_data_cal_create_error_fmt (EDataCalCallStatus status,
 	return error;
 }
 
-static void
-data_cal_return_error (GDBusMethodInvocation *invocation,
-                       const GError *perror,
-                       const gchar *error_fmt)
-{
-	GError *error;
-
-	g_return_if_fail (perror != NULL);
-
-	error = g_error_new (E_DATA_CAL_ERROR, perror->code, error_fmt, perror->message);
-
-	g_dbus_method_invocation_return_gerror (invocation, error);
-
-	g_error_free (error);
-}
-
 /**
  * e_data_cal_register_gdbus_object:
  *
@@ -851,31 +828,6 @@ impl_Cal_add_timezone (EGdbusCal *object,
 }
 
 static gboolean
-impl_Cal_authenticate_user (EGdbusCal *object,
-                            GDBusMethodInvocation *invocation,
-                            const gchar * const *in_credentials,
-                            EDataCal *cal)
-{
-	OperationData *op;
-
-	if (in_credentials == NULL) {
-		GError *error = e_data_cal_create_error (InvalidArg, NULL);
-		/* Translators: This is prefix to a detailed error message */
-		data_cal_return_error (invocation, error, _("Cannot authenticate user: "));
-		g_error_free (error);
-		return TRUE;
-	}
-
-	op = op_new (OP_AUTHENTICATE, cal);
-	op->d.credentials = e_credentials_new_strv (in_credentials);
-
-	e_gdbus_cal_complete_authenticate_user (cal->priv->gdbus_object, invocation, NULL);
-	e_operation_pool_push (ops_pool, op);
-
-	return TRUE;
-}
-
-static gboolean
 impl_Cal_cancel_operation (EGdbusCal *object,
                            GDBusMethodInvocation *invocation,
                            guint in_opid,
@@ -1533,37 +1485,6 @@ e_data_cal_report_online (EDataCal *cal,
 }
 
 /**
- * e_data_cal_report_auth_required:
- *
- * FIXME: Document me.
- *
- * Since: 3.2
- **/
-void
-e_data_cal_report_auth_required (EDataCal *cal,
-                                 const ECredentials *credentials)
-{
-	gchar *empty_strv[2];
-	gchar **strv = NULL;
-
-	/* credentilas contains extra information for a source for which
-	 * authentication is requested.  This parameter can be NULL to
-	 * indicate "for this calendar". */
-
-	g_return_if_fail (cal != NULL);
-
-	empty_strv[0] = NULL;
-	empty_strv[1] = NULL;
-
-	if (credentials)
-		strv = e_credentials_to_strv (credentials);
-
-	e_gdbus_cal_emit_auth_required (cal->priv->gdbus_object, (const gchar * const *) (strv ? strv : empty_strv));
-
-	g_strfreev (strv);
-}
-
-/**
  * e_data_cal_report_opened:
  *
  * Reports to associated client that opening phase of the cal is finished.
@@ -1765,9 +1686,6 @@ e_data_cal_init (EDataCal *ecal)
 		gdbus_object, "handle-open",
 		G_CALLBACK (impl_Cal_open), ecal);
 	g_signal_connect (
-		gdbus_object, "handle-authenticate-user",
-		G_CALLBACK (impl_Cal_authenticate_user), ecal);
-	g_signal_connect (
 		gdbus_object, "handle-remove",
 		G_CALLBACK (impl_Cal_remove), ecal);
 	g_signal_connect (
diff --git a/calendar/libedata-cal/e-data-cal.h b/calendar/libedata-cal/e-data-cal.h
index 15daa43..c5e679e 100644
--- a/calendar/libedata-cal/e-data-cal.h
+++ b/calendar/libedata-cal/e-data-cal.h
@@ -150,7 +150,6 @@ void		e_data_cal_respond_add_timezone			(EDataCal *cal, guint32 opid, GError *er
 void		e_data_cal_report_error				(EDataCal *cal, const gchar *message);
 void		e_data_cal_report_readonly			(EDataCal *cal, gboolean is_readonly);
 void		e_data_cal_report_online			(EDataCal *cal, gboolean is_online);
-void		e_data_cal_report_auth_required			(EDataCal *cal, const ECredentials *credentials);
 void		e_data_cal_report_opened			(EDataCal *cal, const GError *error);
 void		e_data_cal_report_free_busy_data		(EDataCal *cal, const GSList *freebusy);
 void		e_data_cal_report_backend_property_changed	(EDataCal *cal, const gchar *prop_name, const gchar *prop_value);
diff --git a/calendar/libedata-cal/e-data-cal.xml b/calendar/libedata-cal/e-data-cal.xml
index 95717d9..fe93e40 100644
--- a/calendar/libedata-cal/e-data-cal.xml
+++ b/calendar/libedata-cal/e-data-cal.xml
@@ -4,8 +4,6 @@
 	<interface name="org.gnome.evolution.dataserver.Calendar">
 		<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="EDataCal"/>
 		
-		<signal name="auth_required"/>
-
 		<signal name="backend_error">
                   <arg name="error" type="s"/>
                 </signal>
@@ -18,12 +16,6 @@
                   <arg name="mode" type="i"/>
                 </signal>
 		
-		<method name="getUri">
-			<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_Cal_get_uri"/>
-			<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
-			<arg name="str_uri_copy" type="s" direction="out"/>
-		</method>
-
 		<method name="getCacheDir">
 			<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_Cal_getCacheDir"/>
 			<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
diff --git a/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt b/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
index 12d3238..25b2b82 100644
--- a/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
+++ b/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
@@ -28,7 +28,6 @@ e_cal_backend_foreach_view
 e_cal_backend_set_notification_proxy
 e_cal_backend_get_backend_property
 e_cal_backend_set_backend_property
-e_cal_backend_authenticate_user
 e_cal_backend_open
 e_cal_backend_remove
 e_cal_backend_refresh
@@ -59,7 +58,6 @@ e_cal_backend_notify_objects_removed
 e_cal_backend_notify_error
 e_cal_backend_notify_readonly
 e_cal_backend_notify_online
-e_cal_backend_notify_auth_required
 e_cal_backend_notify_opened
 e_cal_backend_notify_property_changed
 e_cal_backend_empty_cache
@@ -237,7 +235,6 @@ e_cal_backend_sync_get_attachment_uris
 e_cal_backend_sync_discard_alarm
 e_cal_backend_sync_get_timezone
 e_cal_backend_sync_add_timezone
-e_cal_backend_sync_authenticate_user
 <SUBSECTION Standard>
 E_CAL_BACKEND_SYNC
 E_IS_CAL_BACKEND_SYNC
@@ -292,7 +289,6 @@ e_data_cal_respond_add_timezone
 e_data_cal_report_error
 e_data_cal_report_readonly
 e_data_cal_report_online
-e_data_cal_report_auth_required
 e_data_cal_report_opened
 e_data_cal_report_free_busy_data
 e_data_cal_report_backend_property_changed



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