[evolution-data-server/account-mgmt: 20/42] Adapt libedata-cal to the new ESource API.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/account-mgmt: 20/42] Adapt libedata-cal to the new ESource API.
- Date: Mon, 28 May 2012 20:56:59 +0000 (UTC)
commit bcef4f2cb566e6d4e031779a2ec7df4b5495abb5
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 | 16 ++
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 | 155 +++++++++++-----
calendar/libedata-cal/e-cal-backend-util.h | 10 +-
calendar/libedata-cal/e-cal-backend.c | 170 ++++++++---------
calendar/libedata-cal/e-cal-backend.h | 9 +-
calendar/libedata-cal/e-data-cal-factory.c | 196 ++++++++++++--------
calendar/libedata-cal/e-data-cal-factory.h | 3 +
calendar/libedata-cal/e-data-cal.c | 83 --------
calendar/libedata-cal/e-data-cal.h | 1 -
calendar/libedata-cal/e-data-cal.xml | 8 -
.../libedata-cal/libedata-cal-sections.txt | 6 +-
13 files changed, 340 insertions(+), 357 deletions(-)
---
diff --git a/calendar/libedata-cal/e-cal-backend-factory.c b/calendar/libedata-cal/e-cal-backend-factory.c
index 74c95e2..3a5981c 100644
--- a/calendar/libedata-cal/e-cal-backend-factory.c
+++ b/calendar/libedata-cal/e-cal-backend-factory.c
@@ -19,6 +19,16 @@ G_DEFINE_ABSTRACT_TYPE (
e_cal_backend_factory,
E_TYPE_BACKEND_FACTORY)
+static EDataCalFactory *
+cal_backend_factory_get_data_factory (EBackendFactory *factory)
+{
+ EExtensible *extensible;
+
+ extensible = e_extension_get_extensible (E_EXTENSION (factory));
+
+ return E_DATA_CAL_FACTORY (extensible);
+}
+
static const gchar *
cal_backend_factory_get_hash_key (EBackendFactory *factory)
{
@@ -59,14 +69,20 @@ cal_backend_factory_new_backend (EBackendFactory *factory,
ESource *source)
{
ECalBackendFactoryClass *class;
+ EDataCalFactory *data_factory;
+ ESourceRegistry *registry;
class = E_CAL_BACKEND_FACTORY_GET_CLASS (factory);
g_return_val_if_fail (g_type_is_a (
class->backend_type, E_TYPE_CAL_BACKEND), NULL);
+ data_factory = cal_backend_factory_get_data_factory (factory);
+ registry = e_data_cal_factory_get_registry (data_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 6343aab..2e6d498 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 43d11e1..766e47b 100644
--- a/calendar/libedata-cal/e-cal-backend-util.c
+++ b/calendar/libedata-cal/e-cal-backend-util.c
@@ -26,12 +26,12 @@
#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:
+ * @registry: an #ESourceRegistry
* @address: placeholder for default address
* @name: placeholder for name
*
@@ -40,30 +40,38 @@ static EAccountList *accounts;
* 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;
+ ESourceMailIdentity *extension;
+ const gchar *extension_name;
- 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_ref_default_mail_identity (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_IDENTITY;
+ extension = e_source_get_extension (source, extension_name);
+
+ if (address != NULL)
+ *address = e_source_mail_identity_dup_address (extension);
- return account != NULL;
+ if (name != NULL)
+ *name = e_source_mail_identity_dup_name (extension);
+
+ g_object_unref (source);
+
+ return TRUE;
}
/**
* e_cal_backend_mail_account_is_valid:
+ * @registry: an #ESourceRegistry
* @user: user name for the account to check
* @name: placeholder for the account name
*
@@ -72,24 +80,73 @@ e_cal_backend_mail_account_get_default (gchar **address,
* 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 *uid;
+ gboolean match = FALSE;
+ gchar *address;
+
+ 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_ref_source (registry, uid);
- if (accounts == NULL) {
- GConfClient *gconf = gconf_client_get_default ();
+ if (source == NULL)
+ continue;
+
+ extension_name = E_SOURCE_EXTENSION_MAIL_IDENTITY;
+
+ if (!e_source_has_extension (source, extension_name)) {
+ g_object_unref (source);
+ continue;
+ }
+
+ mail_identity = e_source_get_extension (source, extension_name);
+ address = e_source_mail_identity_dup_address (mail_identity);
+
+ if (address != NULL) {
+ match = (g_ascii_strcasecmp (address, user) == 0);
+ g_free (address);
+ }
+
+ if (match && name != NULL)
+ *name = e_source_dup_display_name (source);
- accounts = e_account_list_new (gconf);
+ g_object_unref (source);
- g_object_unref (gconf);
+ if (match) {
+ 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,6 +200,7 @@ is_attendee_declined (icalcomponent *icalcomp,
/**
* e_cal_backend_user_declined:
+ * @registry: an #ESourceRegistry
* @icalcomp: component where to check
*
* Returns: Whether icalcomp contains attendee with a mail same as any of
@@ -151,37 +209,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 aad52be..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
@@ -31,12 +32,15 @@ G_BEGIN_DECLS
*/
gboolean e_cal_backend_mail_account_get_default
- (gchar **address,
+ (ESourceRegistry *registry,
+ gchar **address,
gchar **name);
gboolean e_cal_backend_mail_account_is_valid
- (gchar *user,
+ (ESourceRegistry *registry,
+ gchar *user,
gchar **name);
-gboolean e_cal_backend_user_declined (icalcomponent *icalcomp);
+gboolean e_cal_backend_user_declined (ESourceRegistry *registry,
+ icalcomponent *icalcomp);
G_END_DECLS
diff --git a/calendar/libedata-cal/e-cal-backend.c b/calendar/libedata-cal/e-cal-backend.c
index 661cb83..bbe6063 100644
--- a/calendar/libedata-cal/e-cal-backend.c
+++ b/calendar/libedata-cal/e-cal-backend.c
@@ -40,14 +40,13 @@
/* Private part of the CalBackend structure */
struct _ECalBackendPrivate {
+ ESourceRegistry *registry;
+
/* The kind of components for this backend */
icalcomponent_kind kind;
gboolean opening, opened, readonly, removed;
- /* URI, from source. This is cached, since we return const. */
- gchar *uri;
-
gchar *cache_dir;
/* List of Cal objects */
@@ -66,7 +65,8 @@ struct _ECalBackendPrivate {
enum {
PROP_0,
PROP_CACHE_DIR,
- PROP_KIND
+ PROP_KIND,
+ PROP_REGISTRY
};
static void e_cal_backend_remove_client_private (ECalBackend *backend, EDataCal *cal, gboolean weak_unref);
@@ -80,7 +80,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 +88,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 +105,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
@@ -164,6 +162,16 @@ cal_backend_set_kind (ECalBackend *backend,
}
static void
+cal_backend_set_registry (ECalBackend *backend,
+ ESourceRegistry *registry)
+{
+ g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+ g_return_if_fail (backend->priv->registry == NULL);
+
+ backend->priv->registry = g_object_ref (registry);
+}
+
+static void
cal_backend_set_property (GObject *object,
guint property_id,
const GValue *value,
@@ -181,6 +189,12 @@ cal_backend_set_property (GObject *object,
E_CAL_BACKEND (object),
g_value_get_ulong (value));
return;
+
+ case PROP_REGISTRY:
+ cal_backend_set_registry (
+ E_CAL_BACKEND (object),
+ g_value_get_object (value));
+ return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -204,12 +218,34 @@ cal_backend_get_property (GObject *object,
value, e_cal_backend_get_kind (
E_CAL_BACKEND (object)));
return;
+
+ case PROP_REGISTRY:
+ g_value_set_object (
+ value, e_cal_backend_get_registry (
+ E_CAL_BACKEND (object)));
+ return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
+cal_backend_dispose (GObject *object)
+{
+ ECalBackendPrivate *priv;
+
+ priv = E_CAL_BACKEND_GET_PRIVATE (object);
+
+ if (priv->registry != NULL) {
+ g_object_unref (priv->registry);
+ priv->registry = NULL;
+ }
+
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (e_cal_backend_parent_class)->dispose (object);
+}
+
+static void
cal_backend_finalize (GObject *object)
{
ECalBackendPrivate *priv;
@@ -249,6 +285,7 @@ e_cal_backend_class_init (ECalBackendClass *class)
object_class = G_OBJECT_CLASS (class);
object_class->set_property = cal_backend_set_property;
object_class->get_property = cal_backend_get_property;
+ object_class->dispose = cal_backend_dispose;
object_class->finalize = cal_backend_finalize;
object_class->constructed = cal_backend_constructed;
@@ -280,6 +317,18 @@ e_cal_backend_class_init (ECalBackendClass *class)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_REGISTRY,
+ g_param_spec_object (
+ "registry",
+ "Registry",
+ "Data source registry",
+ E_TYPE_SOURCE_REGISTRY,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
}
static void
@@ -313,6 +362,24 @@ e_cal_backend_get_kind (ECalBackend *backend)
}
/**
+ * e_cal_backend_get_registry:
+ * @backend: an #ECalBackend
+ *
+ * Returns the data source registry to which #EBackend:source belongs.
+ *
+ * Returns: an #ESourceRegistry
+ *
+ * Since: 3.6
+ **/
+ESourceRegistry *
+e_cal_backend_get_registry (ECalBackend *backend)
+{
+ g_return_val_if_fail (E_IS_CAL_BACKEND (backend), NULL);
+
+ return backend->priv->registry;
+}
+
+/**
* e_cal_backend_is_opened:
* @backend: an #ECalBackend
*
@@ -816,39 +883,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
@@ -1875,54 +1909,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 8787115..9cdf35d 100644
--- a/calendar/libedata-cal/e-cal-backend.h
+++ b/calendar/libedata-cal/e-cal-backend.h
@@ -24,8 +24,7 @@
#define E_CAL_BACKEND_H
#include <libebackend/e-backend.h>
-#include <libedataserver/e-credentials.h>
-#include <libedataserver/e-source.h>
+#include <libedataserver/e-source-registry.h>
#include <libecal/e-cal-util.h>
#include <libecal/e-cal-component.h>
#include "e-data-cal-common.h"
@@ -154,7 +153,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);
@@ -181,6 +179,8 @@ GType e_cal_backend_get_type (void);
icalcomponent_kind
e_cal_backend_get_kind (ECalBackend *backend);
+ESourceRegistry *
+ e_cal_backend_get_registry (ECalBackend *backend);
gboolean e_cal_backend_is_opened (ECalBackend *backend);
gboolean e_cal_backend_is_opening (ECalBackend *backend);
gboolean e_cal_backend_is_readonly (ECalBackend *backend);
@@ -202,8 +202,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);
@@ -245,7 +243,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 a425556..d7675a9 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"
@@ -46,6 +48,7 @@
((obj), E_TYPE_DATA_CAL_FACTORY, EDataCalFactoryPrivate))
struct _EDataCalFactoryPrivate {
+ ESourceRegistry *registry;
EGdbusCalFactory *gdbus_object;
GMutex *calendars_lock;
@@ -57,6 +60,11 @@ struct _EDataCalFactoryPrivate {
GHashTable *connections;
};
+enum {
+ PROP_0,
+ PROP_REGISTRY
+};
+
/* Forward Declarations */
static void e_data_cal_factory_initable_init
(GInitableIface *interface);
@@ -69,62 +77,59 @@ G_DEFINE_TYPE_WITH_CODE (
G_TYPE_INITABLE,
e_data_cal_factory_initable_init))
-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 *
-data_cal_factory_ref_backend (EDataCalFactory *factory,
+data_cal_factory_ref_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_ref_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_ref_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;
}
@@ -198,19 +203,21 @@ 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)) {
+ registry = e_data_cal_factory_get_registry (factory);
+
+ 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);
@@ -219,49 +226,44 @@ 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);
+ source = e_source_registry_ref_source (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 = data_cal_factory_ref_backend (factory, source, uri, type);
+ backend = data_cal_factory_ref_backend (
+ E_DATA_FACTORY (factory), source, type, &error);
- if (backend == NULL) {
- error = g_error_new (
- E_DATA_CAL_ERROR,
- NoSuchCal,
- _("Invalid source"));
+ g_object_unref (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));
@@ -286,8 +288,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);
@@ -314,12 +315,35 @@ remove_data_cal_cb (EDataCal *data_cal)
}
static void
+data_cal_factory_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_REGISTRY:
+ g_value_set_object (
+ value,
+ e_data_cal_factory_get_registry (
+ E_DATA_CAL_FACTORY (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
data_cal_factory_dispose (GObject *object)
{
EDataCalFactoryPrivate *priv;
priv = E_DATA_CAL_FACTORY_GET_PRIVATE (object);
+ if (priv->registry != NULL) {
+ g_object_unref (priv->registry);
+ priv->registry = NULL;
+ }
+
if (priv->gdbus_object != NULL) {
g_object_unref (priv->gdbus_object);
priv->gdbus_object = NULL;
@@ -431,9 +455,13 @@ data_cal_factory_initable_init (GInitable *initable,
GCancellable *cancellable,
GError **error)
{
- /* XXX Nothing to do here just yet. More to come soon. */
+ EDataCalFactoryPrivate *priv;
- return TRUE;
+ priv = E_DATA_CAL_FACTORY_GET_PRIVATE (initable);
+
+ priv->registry = e_source_registry_new_sync (cancellable, error);
+
+ return (priv->registry != NULL);
}
static void
@@ -446,6 +474,7 @@ e_data_cal_factory_class_init (EDataCalFactoryClass *class)
g_type_class_add_private (class, sizeof (EDataCalFactoryPrivate));
object_class = G_OBJECT_CLASS (class);
+ object_class->get_property = data_cal_factory_get_property;
object_class->dispose = data_cal_factory_dispose;
object_class->finalize = data_cal_factory_finalize;
@@ -458,6 +487,17 @@ e_data_cal_factory_class_init (EDataCalFactoryClass *class)
data_factory_class = E_DATA_FACTORY_CLASS (class);
data_factory_class->backend_factory_type = E_TYPE_CAL_BACKEND_FACTORY;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_REGISTRY,
+ g_param_spec_object (
+ "registry",
+ "Registry",
+ "Data source registry",
+ E_TYPE_SOURCE_REGISTRY,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
}
static void
@@ -527,3 +567,11 @@ e_data_cal_factory_new (GCancellable *cancellable,
E_TYPE_DATA_CAL_FACTORY,
cancellable, error, NULL);
}
+
+ESourceRegistry *
+e_data_cal_factory_get_registry (EDataCalFactory *factory)
+{
+ g_return_val_if_fail (E_IS_DATA_CAL_FACTORY (factory), NULL);
+
+ return factory->priv->registry;
+}
diff --git a/calendar/libedata-cal/e-data-cal-factory.h b/calendar/libedata-cal/e-data-cal-factory.h
index bf21f41..1a95687 100644
--- a/calendar/libedata-cal/e-data-cal-factory.h
+++ b/calendar/libedata-cal/e-data-cal-factory.h
@@ -23,6 +23,7 @@
#define E_DATA_CAL_FACTORY_H
#include <libebackend/e-data-factory.h>
+#include <libedataserver/e-source-registry.h>
/* Standard GObject macros */
#define E_TYPE_DATA_CAL_FACTORY \
@@ -61,6 +62,8 @@ struct _EDataCalFactoryClass {
GType e_data_cal_factory_get_type (void);
EDBusServer * e_data_cal_factory_new (GCancellable *cancellable,
GError **error);
+ESourceRegistry *
+ e_data_cal_factory_get_registry (EDataCalFactory *factory);
G_END_DECLS
diff --git a/calendar/libedata-cal/e-data-cal.c b/calendar/libedata-cal/e-data-cal.c
index e01de5a..69275ed 100644
--- a/calendar/libedata-cal/e-data-cal.c
+++ b/calendar/libedata-cal/e-data-cal.c
@@ -30,7 +30,6 @@
#include <glib/gi18n-lib.h>
#include <unistd.h>
-#include <libedataserver/e-credentials.h>
#include <libedataserver/e-data-server-util.h>
#include <libedataserver/e-operation-pool.h>
@@ -63,7 +62,6 @@ static EOperationPool *ops_pool = NULL;
typedef enum {
OP_OPEN,
- OP_AUTHENTICATE,
OP_REMOVE,
OP_REFRESH,
OP_GET_BACKEND_PROPERTY,
@@ -95,8 +93,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 +298,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 +495,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 +827,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,
@@ -1536,37 +1487,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.
@@ -1768,9 +1688,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 1956af5..fb149b8 100644
--- a/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
+++ b/docs/reference/calendar/libedata-cal/libedata-cal-sections.txt
@@ -13,6 +13,7 @@ CAL_BACKEND_PROPERTY_ALARM_EMAIL_ADDRESS
CAL_BACKEND_PROPERTY_DEFAULT_OBJECT
CAL_BACKEND_PROPERTY_REVISION
e_cal_backend_get_kind
+e_cal_backend_get_registry
e_cal_backend_is_opened
e_cal_backend_is_opening
e_cal_backend_is_readonly
@@ -28,7 +29,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 +59,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 +236,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 +290,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
@@ -330,6 +327,7 @@ ECalBackendSExpClass
<TITLE>EDataCalFactory</TITLE>
EDataCalFactory
e_data_cal_factory_new
+e_data_cal_factory_get_registry
<SUBSECTION Standard>
E_DATA_CAL_FACTORY
E_IS_DATA_CAL_FACTORY
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]