[evolution-data-server/account-mgmt: 25/39] Add an ESource extension for the caldav backend.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/account-mgmt: 25/39] Add an ESource extension for the caldav backend.
- Date: Thu, 27 Oct 2011 02:50:56 +0000 (UTC)
commit 66d77cff69720d5042c233aa260df13cce64436b
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Nov 23 20:23:52 2010 -0500
Add an ESource extension for the caldav backend.
calendar/backends/caldav/Makefile.am | 4 +-
.../backends/caldav/e-cal-backend-caldav-factory.c | 2 +
calendar/backends/caldav/e-cal-backend-caldav.c | 339 ++++++++++++--------
calendar/backends/caldav/e-source-caldav.c | 201 ++++++++++++
calendar/backends/caldav/e-source-caldav.h | 71 ++++
5 files changed, 477 insertions(+), 140 deletions(-)
---
diff --git a/calendar/backends/caldav/Makefile.am b/calendar/backends/caldav/Makefile.am
index fad450b..7bd418b 100644
--- a/calendar/backends/caldav/Makefile.am
+++ b/calendar/backends/caldav/Makefile.am
@@ -12,7 +12,9 @@ libecalbackendcaldav_la_CPPFLAGS = \
libecalbackendcaldav_la_SOURCES = \
e-cal-backend-caldav-factory.c \
e-cal-backend-caldav.c \
- e-cal-backend-caldav.h
+ e-cal-backend-caldav.h \
+ e-source-caldav.c \
+ e-source-caldav.h
libecalbackendcaldav_la_LIBADD = \
$(top_builddir)/calendar/libedata-cal/libedata-cal-1.2.la \
diff --git a/calendar/backends/caldav/e-cal-backend-caldav-factory.c b/calendar/backends/caldav/e-cal-backend-caldav-factory.c
index ef6cab4..99adadb 100644
--- a/calendar/backends/caldav/e-cal-backend-caldav-factory.c
+++ b/calendar/backends/caldav/e-cal-backend-caldav-factory.c
@@ -26,6 +26,7 @@
#include <libedata-cal/e-cal-backend-factory.h>
#include "e-cal-backend-caldav.h"
+#include "e-source-caldav.h"
#define FACTORY_NAME "caldav"
@@ -119,6 +120,7 @@ e_cal_backend_caldav_todos_factory_init (ECalBackendFactory *factory)
G_MODULE_EXPORT void
e_module_load (GTypeModule *type_module)
{
+ e_source_caldav_type_register (type_module);
e_cal_backend_caldav_events_factory_register_type (type_module);
e_cal_backend_caldav_journal_factory_register_type (type_module);
e_cal_backend_caldav_todos_factory_register_type (type_module);
diff --git a/calendar/backends/caldav/e-cal-backend-caldav.c b/calendar/backends/caldav/e-cal-backend-caldav.c
index c6b071c..828e841 100644
--- a/calendar/backends/caldav/e-cal-backend-caldav.c
+++ b/calendar/backends/caldav/e-cal-backend-caldav.c
@@ -31,6 +31,10 @@
#include <libedataserver/e-data-server-util.h>
#include <libedataserver/e-xml-hash-utils.h>
#include <libedataserver/e-proxy.h>
+#include <libedataserver/e-source-authentication.h>
+#include <libedataserver/e-source-authenticator.h>
+#include <libedataserver/e-source-offline.h>
+#include <libedataserver/e-source-refresh.h>
#include <libecal/e-cal-recur.h>
#include <libecal/e-cal-util.h>
#include <libecal/e-cal-time-util.h>
@@ -49,6 +53,7 @@
#include <libsoup/soup.h>
#include "e-cal-backend-caldav.h"
+#include "e-source-caldav.h"
#define d(x)
@@ -110,7 +115,7 @@ struct _ECalBackendCalDAVPrivate {
gchar *uri;
/* Authentication info */
- ECredentials *credentials;
+ gchar *secret;
gboolean auth_required;
/* object cleanup */
@@ -915,16 +920,23 @@ soup_authenticate (SoupSession *session,
gpointer data)
{
ECalBackendCalDAVPrivate *priv;
- ECalBackendCalDAV *cbdav;
+ ECalBackendCalDAV *cbdav;
+ ESourceAuthentication *auth_extension;
+ ESource *source;
+ const gchar *extension_name;
+ const gchar *user;
cbdav = E_CAL_BACKEND_CALDAV (data);
priv = cbdav->priv;
+ source = e_backend_get_source (E_BACKEND (data));
+ extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+ auth_extension = e_source_get_extension (source, extension_name);
+ user = e_source_authentication_get_user (auth_extension);
+
/* do not send same password twice, but keep it for later use */
- if (!retrying && priv->credentials && e_credentials_has_key (priv->credentials, E_CREDENTIALS_KEY_USERNAME)) {
- soup_auth_authenticate (auth, e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_USERNAME), e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_PASSWORD));
- e_credentials_clear_peek (priv->credentials);
- }
+ if (!retrying && priv->secret != NULL)
+ soup_auth_authenticate (auth, user, priv->secret);
}
/* ************************************************************************* */
@@ -2256,29 +2268,34 @@ maybe_append_email_domain (const gchar *username,
static gchar *
get_usermail (ECalBackend *backend)
{
- ECalBackendCalDAV *cbdav;
- ECalBackendCalDAVPrivate *priv;
+ ECalBackendCalDAV *cbdav;
ESource *source;
+ ESourceAuthentication *auth_extension;
+ ESourceCaldav *caldav_extension;
+ const gchar *extension_name;
+ const gchar *usermail;
+ const gchar *user;
gchar *res = NULL;
g_return_val_if_fail (backend != NULL, NULL);
source = e_backend_get_source (E_BACKEND (backend));
- if (source) {
- res = e_source_get_duped_property (source, "usermail");
- if (res && *res)
- return res;
- g_free (res);
- res = NULL;
- }
+ extension_name = E_SOURCE_EXTENSION_CALDAV_BACKEND;
+ caldav_extension = e_source_get_extension (source, extension_name);
+
+ usermail = e_source_caldav_get_email (caldav_extension);
+ if (usermail != NULL && *usermail != '\0')
+ return g_strdup (usermail);
cbdav = E_CAL_BACKEND_CALDAV (backend);
- priv = cbdav->priv;
- if (priv && priv->is_google && priv->credentials) {
- res = maybe_append_email_domain (e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_USERNAME), "@gmail.com");
- }
+ extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+ auth_extension = e_source_get_extension (source, extension_name);
+ user = e_source_authentication_get_user (auth_extension);
+
+ if (cbdav->priv && cbdav->priv->is_google)
+ res = maybe_append_email_domain (user, "@gmail.com");
return res;
}
@@ -2300,9 +2317,11 @@ caldav_get_backend_property (ECalBackendSync *backend,
g_return_val_if_fail (prop_value != NULL, FALSE);
if (g_str_equal (prop_name, CLIENT_BACKEND_PROPERTY_CAPABILITIES)) {
+ ESourceCaldav *extension;
ESource *source;
GString *caps;
gchar *usermail;
+ const gchar *extension_name;
caps = g_string_new (CAL_STATIC_CAPABILITY_NO_THISANDFUTURE ","
CAL_STATIC_CAPABILITY_NO_THISANDPRIOR ","
@@ -2314,12 +2333,13 @@ caldav_get_backend_property (ECalBackendSync *backend,
g_free (usermail);
source = e_backend_get_source (E_BACKEND (backend));
- if (source) {
- const gchar *prop = e_source_get_property (source, "autoschedule");
- if (prop && g_str_equal (prop, "1"))
- g_string_append (caps, "," CAL_STATIC_CAPABILITY_CREATE_MESSAGES
- "," CAL_STATIC_CAPABILITY_SAVE_SCHEDULES);
+ extension_name = E_SOURCE_EXTENSION_CALDAV_BACKEND;
+ extension = e_source_get_extension (source, extension_name);
+
+ if (e_source_caldav_get_autoschedule (extension)) {
+ g_string_append (caps, "," CAL_STATIC_CAPABILITY_CREATE_MESSAGES
+ "," CAL_STATIC_CAPABILITY_SAVE_SCHEDULES);
}
*prop_value = g_string_free (caps, FALSE);
@@ -2361,90 +2381,84 @@ initialize_backend (ECalBackendCalDAV *cbdav,
GError **perror)
{
ECalBackendCalDAVPrivate *priv;
+ ESourceAuthentication *auth_extension;
+ ESourceCaldav *caldav_extension;
+ ESourceOffline *offline_extension;
+ ESourceRefresh *refresh_extension;
ECalBackend *backend;
+ SoupURI *soup_uri;
ESource *source;
- const gchar *os_val;
- const gchar *uri;
gsize len;
- const gchar *refresh;
const gchar *cache_dir;
+ const gchar *extension_name;
+ guint interval_in_minutes;
priv = cbdav->priv;
backend = E_CAL_BACKEND (cbdav);
cache_dir = e_cal_backend_get_cache_dir (backend);
source = e_backend_get_source (E_BACKEND (backend));
- uri = e_source_get_uri (source);
- if (!g_signal_handler_find (G_OBJECT (source), G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, 0, 0, NULL, caldav_source_changed_cb, cbdav))
- g_signal_connect (G_OBJECT (source), "changed", G_CALLBACK (caldav_source_changed_cb), cbdav);
+ extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+ auth_extension = e_source_get_extension (source, extension_name);
- os_val = e_source_get_property (source, "offline_sync");
-
- if (!os_val || !g_str_equal (os_val, "1")) {
- priv->do_offline = FALSE;
- }
+ extension_name = E_SOURCE_EXTENSION_CALDAV_BACKEND;
+ caldav_extension = e_source_get_extension (source, extension_name);
- os_val = e_source_get_property (source, "auth");
- priv->auth_required = os_val != NULL;
+ extension_name = E_SOURCE_EXTENSION_OFFLINE;
+ offline_extension = e_source_get_extension (source, extension_name);
- os_val = e_source_get_property(source, "ssl");
+ extension_name = E_SOURCE_EXTENSION_REFRESH;
+ refresh_extension = e_source_get_extension (source, extension_name);
- g_free (priv->uri);
- priv->uri = NULL;
- if (g_str_has_prefix (uri, "caldav://")) {
- const gchar *proto;
+ if (!g_signal_handler_find (G_OBJECT (source), G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, 0, 0, NULL, caldav_source_changed_cb, cbdav))
+ g_signal_connect (G_OBJECT (source), "changed", G_CALLBACK (caldav_source_changed_cb), cbdav);
- if (os_val && os_val[0] == '1') {
- proto = "https://";
- } else {
- proto = "http://";
- }
+ priv->do_offline = e_source_offline_get_stay_synchronized (offline_extension);
- priv->uri = g_strconcat (proto, uri + 9, NULL);
- } else {
- priv->uri = g_strdup (uri);
- }
+ priv->auth_required = e_source_authentication_required (auth_extension);
- if (priv->uri) {
- SoupURI *suri = soup_uri_new (priv->uri);
+ soup_uri = e_source_webdav_get_soup_uri (
+ E_SOURCE_WEBDAV (caldav_extension));
- /* properly encode uri */
- if (suri && suri->path) {
- gchar *tmp, *path;
+ /* properly encode uri */
+ if (soup_uri != NULL && soup_uri->path != NULL) {
+ gchar *tmp, *path;
- if (suri->path && strchr (suri->path, '%')) {
- /* If path contains anything already encoded, then decode it first,
- * thus it'll be managed properly. For example, the '#' in a path
- * is in URI shown as %23 and not doing this decode makes it being
- * like %2523, which is not what is wanted here. */
- tmp = soup_uri_decode (suri->path);
- soup_uri_set_path (suri, tmp);
- g_free (tmp);
- }
+ if (strchr (soup_uri->path, '%')) {
+ /* If path contains anything already encoded, then
+ * decode it first, thus it'll be managed properly.
+ * For example, the '#' in a path is in URI shown as
+ * %23 and not doing this decode makes it being like
+ * %2523, which is not what is wanted here. */
+ tmp = soup_uri_decode (soup_uri->path);
+ soup_uri_set_path (soup_uri, tmp);
+ g_free (tmp);
+ }
- tmp = soup_uri_encode (suri->path, NULL);
- path = soup_uri_normalize (tmp, "/");
+ tmp = soup_uri_encode (soup_uri->path, NULL);
+ path = soup_uri_normalize (tmp, "/");
- soup_uri_set_path (suri, path);
+ soup_uri_set_path (soup_uri, path);
- g_free (tmp);
- g_free (path);
- g_free (priv->uri);
+ g_free (tmp);
+ g_free (path);
+ }
- priv->uri = soup_uri_to_string (suri, FALSE);
- }
+ g_free (priv->uri);
+ priv->uri = soup_uri_to_string (soup_uri, FALSE);
- soup_uri_free (suri);
- }
+ soup_uri_free (soup_uri);
/* remove trailing slashes... */
- len = strlen (priv->uri);
- while (len--) {
- if (priv->uri[len] == '/') {
- priv->uri[len] = '\0';
- } else {
- break;
+ if (priv->uri != NULL) {
+ len = strlen (priv->uri);
+ while (len--) {
+ if (priv->uri[len] == '/') {
+ priv->uri[len] = '\0';
+ } else {
+ break;
+ }
}
}
@@ -2476,8 +2490,13 @@ initialize_backend (ECalBackendCalDAV *cbdav,
return FALSE;
}
- refresh = e_source_get_property (source, "refresh");
- priv->refresh_time.tv_sec = (refresh && atoi (refresh) > 0) ? (60 * atoi (refresh)) : (DEFAULT_REFRESH_TIME);
+ interval_in_minutes =
+ e_source_refresh_get_interval_minutes (refresh_extension);
+
+ if (interval_in_minutes == 0)
+ priv->refresh_time.tv_sec = DEFAULT_REFRESH_TIME;
+ else
+ priv->refresh_time.tv_sec = interval_in_minutes * 60;
if (!priv->synch_slave) {
GThread *slave;
@@ -2513,22 +2532,26 @@ proxy_settings_changed (EProxy *proxy,
g_object_set (priv->session, SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
}
-static void
+static gboolean
open_calendar (ECalBackendCalDAV *cbdav,
GError **error)
{
gboolean server_unreachable = FALSE;
ECalBackendCalDAVPrivate *priv;
+ gboolean success;
GError *local_error = NULL;
- g_return_if_fail (cbdav != NULL);
+ g_return_val_if_fail (cbdav != NULL, FALSE);
priv = cbdav->priv;
/* set forward proxy */
proxy_settings_changed (priv->proxy, priv);
- if (caldav_server_open_calendar (cbdav, &server_unreachable, &local_error)) {
+ success = caldav_server_open_calendar (
+ cbdav, &server_unreachable, &local_error);
+
+ if (success) {
priv->slave_cmd = SLAVE_SHOULD_WORK;
g_cond_signal (priv->cond);
@@ -2541,10 +2564,14 @@ open_calendar (ECalBackendCalDAV *cbdav,
e_cal_backend_notify_error (E_CAL_BACKEND (cbdav), msg);
g_free (msg);
g_clear_error (&local_error);
+ success = TRUE;
}
- } else if (local_error) {
- g_propagate_error (error, local_error);
}
+
+ if (local_error != NULL)
+ g_propagate_error (error, local_error);
+
+ return success;
}
static void
@@ -2556,6 +2583,7 @@ caldav_do_open (ECalBackendSync *backend,
{
ECalBackendCalDAV *cbdav;
ECalBackendCalDAVPrivate *priv;
+ gboolean opened = TRUE;
gboolean online;
cbdav = E_CAL_BACKEND_CALDAV (backend);
@@ -2586,22 +2614,30 @@ caldav_do_open (ECalBackendSync *backend,
if (online) {
GError *local_error = NULL;
- open_calendar (cbdav, &local_error);
+ opened = open_calendar (cbdav, &local_error);
if (g_error_matches (local_error, E_DATA_CAL_ERROR, AuthenticationRequired) || g_error_matches (local_error, E_DATA_CAL_ERROR, AuthenticationFailed)) {
+ ESource *source;
+
g_clear_error (&local_error);
- e_cal_backend_notify_auth_required (E_CAL_BACKEND (cbdav), TRUE, priv->credentials);
- } else {
- e_cal_backend_notify_opened (E_CAL_BACKEND (backend), NULL);
+
+ source = e_backend_get_source (E_BACKEND (cbdav));
+
+ opened = e_source_authenticate_sync (
+ source, E_SOURCE_AUTHENTICATOR (cbdav),
+ cancellable, perror);
}
- if (local_error)
+ if (local_error != NULL)
g_propagate_error (perror, local_error);
+
} else {
priv->read_only = TRUE;
- e_cal_backend_notify_opened (E_CAL_BACKEND (backend), NULL);
}
+ if (opened)
+ e_cal_backend_notify_opened (E_CAL_BACKEND (backend), NULL);
+
e_cal_backend_notify_readonly (E_CAL_BACKEND (backend), priv->read_only);
e_cal_backend_notify_online (E_CAL_BACKEND (backend), online);
@@ -2609,36 +2645,6 @@ caldav_do_open (ECalBackendSync *backend,
}
static void
-caldav_authenticate_user (ECalBackendSync *backend,
- GCancellable *cancellable,
- ECredentials *credentials,
- GError **error)
-{
- ECalBackendCalDAV *cbdav;
- ECalBackendCalDAVPrivate *priv;
-
- cbdav = E_CAL_BACKEND_CALDAV (backend);
- priv = cbdav->priv;
-
- g_mutex_lock (priv->busy_lock);
-
- e_credentials_free (priv->credentials);
- priv->credentials = NULL;
-
- if (!credentials || !e_credentials_has_key (credentials, E_CREDENTIALS_KEY_USERNAME)) {
- g_mutex_unlock (priv->busy_lock);
- g_propagate_error (error, EDC_ERROR (AuthenticationRequired));
- return;
- }
-
- priv->credentials = e_credentials_new_clone (credentials);
-
- open_calendar (cbdav, error);
-
- g_mutex_unlock (priv->busy_lock);
-}
-
-static void
caldav_refresh (ECalBackendSync *backend,
EDataCal *cal,
GCancellable *cancellable,
@@ -3987,6 +3993,7 @@ process_object (ECalBackendCalDAV *cbdav,
icalproperty_method method,
GError **error)
{
+ ESourceRegistry *registry;
ECalBackend *backend;
struct icaltimetype now;
gchar *new_obj_str;
@@ -3999,6 +4006,8 @@ process_object (ECalBackendCalDAV *cbdav,
e_return_data_cal_error_if_fail (id != NULL, InvalidObject);
+ registry = e_backend_get_registry (E_BACKEND (cbdav));
+
/* ctime, mtime */
now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
e_cal_component_set_created (ecomp, &now);
@@ -4014,7 +4023,8 @@ process_object (ECalBackendCalDAV *cbdav,
case ICAL_METHOD_PUBLISH:
case ICAL_METHOD_REQUEST:
case ICAL_METHOD_REPLY:
- is_declined = e_cal_backend_user_declined (e_cal_component_get_icalcomponent (ecomp));
+ is_declined = e_cal_backend_user_declined (
+ registry, e_cal_component_get_icalcomponent (ecomp));
if (is_in_cache) {
if (!is_declined) {
icalcomponent *new_component = NULL, *old_component = NULL;
@@ -4474,11 +4484,16 @@ caldav_get_free_busy (ECalBackendSync *backend,
icalcomponent *icalcomp;
ECalComponent *comp;
ECalComponentDateTime dt;
+ ECalComponentOrganizer organizer = {NULL};
+ ESourceAuthentication *auth_extension;
+ ESource *source;
struct icaltimetype dtvalue;
icaltimezone *utc;
gchar *str, *usermail;
const GSList *u;
GSList *attendees = NULL, *to_free = NULL;
+ const gchar *extension_name;
+ const gchar *user;
GError *err = NULL;
cbdav = E_CAL_BACKEND_CALDAV (backend);
@@ -4529,16 +4544,17 @@ caldav_get_free_busy (ECalBackendSync *backend,
usermail = NULL;
}
- if ((priv->credentials && e_credentials_has_key (priv->credentials, E_CREDENTIALS_KEY_USERNAME)) || usermail) {
- ECalComponentOrganizer organizer = {NULL};
-
- organizer.value = usermail ? usermail : e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_USERNAME);
- organizer.value = g_strconcat ("mailto:", organizer.value, NULL);
-
- e_cal_component_set_organizer (comp, &organizer);
+ source = e_backend_get_source (E_BACKEND (backend));
+ extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+ auth_extension = e_source_get_extension (source, extension_name);
+ user = e_source_authentication_get_user (auth_extension);
- g_free ((gchar *) organizer.value);
- }
+ if (usermail != NULL)
+ organizer.value = g_strconcat ("mailto:", usermail, NULL);
+ else
+ organizer.value = g_strconcat ("mailto:", user, NULL);
+ e_cal_component_set_organizer (comp, &organizer);
+ g_free ((gchar *) organizer.value);
g_free (usermail);
@@ -4738,10 +4754,54 @@ caldav_source_changed_cb (ESource *source,
}
}
+static ESourceAuthenticatorResult
+caldav_try_secret_sync (ESourceAuthenticator *authenticator,
+ const gchar *secret,
+ GCancellable *cancellable,
+ GError **error)
+{
+ ECalBackendCalDAV *cbdav;
+ ESourceAuthenticatorResult result;
+ GError *local_error = NULL;
+
+ cbdav = E_CAL_BACKEND_CALDAV (authenticator);
+
+ /* Busy lock is already acquired by caldav_do_open(). */
+
+ g_free (cbdav->priv->secret);
+ cbdav->priv->secret = g_strdup (secret);
+
+ open_calendar (cbdav, &local_error);
+
+ if (local_error == NULL) {
+ result = E_SOURCE_AUTHENTICATOR_SECRET_ACCEPTED;
+ } else if (g_error_matches (local_error, E_DATA_CAL_ERROR, AuthenticationFailed)) {
+ result = E_SOURCE_AUTHENTICATOR_SECRET_REJECTED;
+ g_clear_error (&local_error);
+ } else {
+ result = E_SOURCE_AUTHENTICATOR_ERROR;
+ g_propagate_error (error, local_error);
+ }
+
+ return result;
+}
+
+static void
+caldav_source_authenticator_init (ESourceAuthenticatorInterface *interface)
+{
+ interface->try_secret_sync = caldav_try_secret_sync;
+}
+
/* ************************************************************************* */
/* ***************************** GObject Foo ******************************* */
-G_DEFINE_TYPE (ECalBackendCalDAV, e_cal_backend_caldav, E_TYPE_CAL_BACKEND_SYNC)
+G_DEFINE_TYPE_WITH_CODE (
+ ECalBackendCalDAV,
+ e_cal_backend_caldav,
+ E_TYPE_CAL_BACKEND_SYNC,
+ G_IMPLEMENT_INTERFACE (
+ E_TYPE_SOURCE_AUTHENTICATOR,
+ caldav_source_authenticator_init))
static void
e_cal_backend_caldav_dispose (GObject *object)
@@ -4779,9 +4839,6 @@ e_cal_backend_caldav_dispose (GObject *object)
g_object_unref (priv->session);
g_object_unref (priv->proxy);
- e_credentials_free (priv->credentials);
- priv->credentials = NULL;
-
g_free (priv->uri);
g_free (priv->schedule_outbox_url);
@@ -4809,6 +4866,8 @@ e_cal_backend_caldav_finalize (GObject *object)
g_cond_free (priv->cond);
g_cond_free (priv->slave_gone_cond);
+ g_free (priv->secret);
+
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -4883,7 +4942,6 @@ e_cal_backend_caldav_class_init (ECalBackendCalDAVClass *class)
sync_class->get_backend_property_sync = caldav_get_backend_property;
sync_class->open_sync = caldav_do_open;
- sync_class->authenticate_user_sync = caldav_authenticate_user;
sync_class->refresh_sync = caldav_refresh;
sync_class->remove_sync = caldav_remove;
@@ -4901,4 +4959,7 @@ e_cal_backend_caldav_class_init (ECalBackendCalDAVClass *class)
backend_class->start_view = caldav_start_view;
backend_class->internal_get_timezone = caldav_internal_get_timezone;
+
+ /* Register our ESource extension. */
+ E_TYPE_SOURCE_CALDAV;
}
diff --git a/calendar/backends/caldav/e-source-caldav.c b/calendar/backends/caldav/e-source-caldav.c
new file mode 100644
index 0000000..d6e1462
--- /dev/null
+++ b/calendar/backends/caldav/e-source-caldav.c
@@ -0,0 +1,201 @@
+/*
+ * e-source-caldav.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <webcal://www.gnu.org/licenses/>
+ *
+ */
+
+#include "e-source-caldav.h"
+
+#define E_SOURCE_CALDAV_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_SOURCE_CALDAV, ESourceCaldavPrivate))
+
+struct _ESourceCaldavPrivate {
+ gboolean autoschedule;
+ gchar *email;
+};
+
+enum {
+ PROP_0,
+ PROP_AUTOSCHEDULE,
+ PROP_EMAIL
+};
+
+G_DEFINE_DYNAMIC_TYPE (
+ ESourceCaldav,
+ e_source_caldav,
+ E_TYPE_SOURCE_WEBDAV)
+
+static void
+source_caldav_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_AUTOSCHEDULE:
+ e_source_caldav_set_autoschedule (
+ E_SOURCE_CALDAV (object),
+ g_value_get_boolean (value));
+ return;
+
+ case PROP_EMAIL:
+ e_source_caldav_set_email (
+ E_SOURCE_CALDAV (object),
+ g_value_get_string (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_caldav_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_AUTOSCHEDULE:
+ g_value_set_boolean (
+ value,
+ e_source_caldav_get_autoschedule (
+ E_SOURCE_CALDAV (object)));
+ return;
+
+ case PROP_EMAIL:
+ g_value_set_string (
+ value,
+ e_source_caldav_get_email (
+ E_SOURCE_CALDAV (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_caldav_finalize (GObject *object)
+{
+ ESourceCaldavPrivate *priv;
+
+ priv = E_SOURCE_CALDAV_GET_PRIVATE (object);
+
+ g_free (priv->email);
+
+ /* Chain up to parent's finalize() method. */
+ G_OBJECT_CLASS (e_source_caldav_parent_class)->finalize (object);
+}
+
+static void
+e_source_caldav_class_init (ESourceCaldavClass *class)
+{
+ GObjectClass *object_class;
+ ESourceExtensionClass *extension_class;
+
+ g_type_class_add_private (class, sizeof (ESourceCaldavPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = source_caldav_set_property;
+ object_class->get_property = source_caldav_get_property;
+ object_class->finalize = source_caldav_finalize;
+
+ extension_class = E_SOURCE_EXTENSION_CLASS (class);
+ extension_class->name = E_SOURCE_EXTENSION_CALDAV_BACKEND;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_AUTOSCHEDULE,
+ g_param_spec_boolean (
+ "autoschedule",
+ "Auto-Schedule",
+ "Server handles meeting invitations",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ E_SOURCE_PARAM_SETTING));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_EMAIL,
+ g_param_spec_string (
+ "email",
+ "Email",
+ "User's email address",
+ "",
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ E_SOURCE_PARAM_SETTING));
+}
+
+static void
+e_source_caldav_class_finalize (ESourceCaldavClass *class)
+{
+}
+
+static void
+e_source_caldav_init (ESourceCaldav *extension)
+{
+ extension->priv = E_SOURCE_CALDAV_GET_PRIVATE (extension);
+}
+
+void
+e_source_caldav_type_register (GTypeModule *type_module)
+{
+ /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
+ * function, so we have to wrap it with a public function in
+ * order to register types from a separate compilation unit. */
+ e_source_caldav_register_type (type_module);
+}
+
+gboolean
+e_source_caldav_get_autoschedule (ESourceCaldav *extension)
+{
+ g_return_val_if_fail (E_IS_SOURCE_CALDAV (extension), FALSE);
+
+ return extension->priv->autoschedule;
+}
+
+void
+e_source_caldav_set_autoschedule (ESourceCaldav *extension,
+ gboolean autoschedule)
+{
+ g_return_if_fail (E_IS_SOURCE_CALDAV (extension));
+
+ extension->priv->autoschedule = autoschedule;
+
+ g_object_notify (G_OBJECT (extension), "autoschedule");
+}
+
+const gchar *
+e_source_caldav_get_email (ESourceCaldav *extension)
+{
+ g_return_val_if_fail (E_IS_SOURCE_CALDAV (extension), NULL);
+
+ return extension->priv->email;
+}
+
+void
+e_source_caldav_set_email (ESourceCaldav *extension,
+ const gchar *email)
+{
+ g_return_if_fail (E_IS_SOURCE_CALDAV (extension));
+
+ g_free (extension->priv->email);
+ extension->priv->email = g_strdup (email);
+
+ g_object_notify (G_OBJECT (extension), "email");
+}
+
diff --git a/calendar/backends/caldav/e-source-caldav.h b/calendar/backends/caldav/e-source-caldav.h
new file mode 100644
index 0000000..7e46d52
--- /dev/null
+++ b/calendar/backends/caldav/e-source-caldav.h
@@ -0,0 +1,71 @@
+/*
+ * e-source-caldav.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <webcal://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef E_SOURCE_CALDAV_H
+#define E_SOURCE_CALDAV_H
+
+#include <libedataserver/e-source-webdav.h>
+
+/* Standard GObject macros */
+#define E_TYPE_SOURCE_CALDAV \
+ (e_source_caldav_get_type ())
+#define E_SOURCE_CALDAV(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_SOURCE_CALDAV, ESourceCaldav))
+#define E_SOURCE_CALDAV_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_SOURCE_CALDAV, ESourceCaldavClass))
+#define E_IS_SOURCE_CALDAV(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_SOURCE_CALDAV))
+#define E_IS_SOURCE_CALDAV_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_SOURCE_CALDAV))
+#define E_SOURCE_CALDAV_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_SOURCE_CALDAV, ESourceCaldavClass))
+
+#define E_SOURCE_EXTENSION_CALDAV_BACKEND "CalDAV Backend"
+
+G_BEGIN_DECLS
+
+typedef struct _ESourceCaldav ESourceCaldav;
+typedef struct _ESourceCaldavClass ESourceCaldavClass;
+typedef struct _ESourceCaldavPrivate ESourceCaldavPrivate;
+
+struct _ESourceCaldav {
+ ESourceWebdav parent;
+ ESourceCaldavPrivate *priv;
+};
+
+struct _ESourceCaldavClass {
+ ESourceWebdavClass parent_class;
+};
+
+GType e_source_caldav_get_type (void);
+void e_source_caldav_type_register (GTypeModule *type_module);
+gboolean e_source_caldav_get_autoschedule
+ (ESourceCaldav *extension);
+void e_source_caldav_set_autoschedule
+ (ESourceCaldav *extension,
+ gboolean autoschedule);
+const gchar * e_source_caldav_get_email (ESourceCaldav *extension);
+void e_source_caldav_set_email (ESourceCaldav *extension,
+ const gchar *email);
+
+#endif /* E_SOURCE_CALDAV_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]