[evolution-data-server] Adapt ECalBackendHttp to libedata-cal changes.



commit b40e72dfa893c76d2122d20b1e72d95380de5c54
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Sep 9 13:26:23 2011 -0400

    Adapt ECalBackendHttp to libedata-cal changes.

 calendar/backends/http/Makefile.am                 |    1 -
 .../backends/http/e-cal-backend-http-factory.c     |  105 ++++----------------
 .../backends/http/e-cal-backend-http-factory.h     |   36 -------
 calendar/backends/http/e-cal-backend-http.c        |   59 ++++++-----
 calendar/backends/http/e-cal-backend-http.h        |   37 ++++---
 5 files changed, 71 insertions(+), 167 deletions(-)
---
diff --git a/calendar/backends/http/Makefile.am b/calendar/backends/http/Makefile.am
index 3f0be8a..a7a367a 100644
--- a/calendar/backends/http/Makefile.am
+++ b/calendar/backends/http/Makefile.am
@@ -12,7 +12,6 @@ libecalbackendhttp_la_CPPFLAGS = \
 
 libecalbackendhttp_la_SOURCES =		\
 	e-cal-backend-http-factory.c	\
-	e-cal-backend-http-factory.h	\
 	e-cal-backend-http.c		\
 	e-cal-backend-http.h
 
diff --git a/calendar/backends/http/e-cal-backend-http-factory.c b/calendar/backends/http/e-cal-backend-http-factory.c
index 006af78..5cd1108 100644
--- a/calendar/backends/http/e-cal-backend-http-factory.c
+++ b/calendar/backends/http/e-cal-backend-http-factory.c
@@ -7,15 +7,13 @@
  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
  */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
-#include <string.h>
-
-#include "e-cal-backend-http-factory.h"
+#include <libedata-cal/e-cal-backend-factory.h>
 #include "e-cal-backend-http.h"
 
+#define FACTORY_NAME "webcal"
+
 typedef ECalBackendFactory ECalBackendHttpEventsFactory;
 typedef ECalBackendFactoryClass ECalBackendHttpEventsFactoryClass;
 
@@ -25,6 +23,10 @@ typedef ECalBackendFactoryClass ECalBackendHttpJournalFactoryClass;
 typedef ECalBackendFactory ECalBackendHttpTodosFactory;
 typedef ECalBackendFactoryClass ECalBackendHttpTodosFactoryClass;
 
+/* Module Entry Points */
+void e_module_load (GTypeModule *type_module);
+void e_module_unload (GTypeModule *type_module);
+
 /* Forward Declarations */
 GType e_cal_backend_http_events_factory_get_type (void);
 GType e_cal_backend_http_journal_factory_get_type (void);
@@ -45,66 +47,12 @@ G_DEFINE_DYNAMIC_TYPE (
 	e_cal_backend_http_todos_factory,
 	E_TYPE_CAL_BACKEND_FACTORY)
 
-static const gchar *
-_get_protocol (ECalBackendFactory *factory)
-{
-	return "webcal";
-}
-
-static icalcomponent_kind
-_events_get_kind (ECalBackendFactory *factory)
-{
-	return ICAL_VEVENT_COMPONENT;
-}
-
-static ECalBackend *
-_events_new_backend (ECalBackendFactory *factory,
-                     ESource *source)
-{
-	return g_object_new (
-		e_cal_backend_http_get_type (),
-		"kind", ICAL_VEVENT_COMPONENT,
-		"source", source, NULL);
-}
-
-static icalcomponent_kind
-_journal_get_kind (ECalBackendFactory *factory)
-{
-	return ICAL_VJOURNAL_COMPONENT;
-}
-
-static ECalBackend *
-_journal_new_backend (ECalBackendFactory *factory,
-                      ESource *source)
-{
-	return g_object_new (
-		e_cal_backend_http_get_type (),
-		"kind", ICAL_VJOURNAL_COMPONENT,
-		"source", source, NULL);
-}
-
-static icalcomponent_kind
-_todos_get_kind (ECalBackendFactory *factory)
-{
-	return ICAL_VTODO_COMPONENT;
-}
-
-static ECalBackend *
-_todos_new_backend (ECalBackendFactory *factory,
-                    ESource *source)
-{
-	return g_object_new (
-		e_cal_backend_http_get_type (),
-		"kind", ICAL_VTODO_COMPONENT,
-		"source", source, NULL);
-}
-
 static void
 e_cal_backend_http_events_factory_class_init (ECalBackendFactoryClass *class)
 {
-	class->get_protocol = _get_protocol;
-	class->get_kind     = _events_get_kind;
-	class->new_backend  = _events_new_backend;
+	class->factory_name = FACTORY_NAME;
+	class->component_kind = ICAL_VEVENT_COMPONENT;
+	class->backend_type = E_TYPE_CAL_BACKEND_HTTP;
 }
 
 static void
@@ -120,9 +68,9 @@ e_cal_backend_http_events_factory_init (ECalBackendFactory *factory)
 static void
 e_cal_backend_http_journal_factory_class_init (ECalBackendFactoryClass *class)
 {
-	class->get_protocol = _get_protocol;
-	class->get_kind     = _journal_get_kind;
-	class->new_backend  = _journal_new_backend;
+	class->factory_name = FACTORY_NAME;
+	class->component_kind = ICAL_VJOURNAL_COMPONENT;
+	class->backend_type = E_TYPE_CAL_BACKEND_HTTP;
 }
 
 static void
@@ -138,9 +86,9 @@ e_cal_backend_http_journal_factory_init (ECalBackendFactory *factory)
 static void
 e_cal_backend_http_todos_factory_class_init (ECalBackendFactoryClass *class)
 {
-	class->get_protocol = _get_protocol;
-	class->get_kind     = _todos_get_kind;
-	class->new_backend  = _todos_new_backend;
+	class->factory_name = FACTORY_NAME;
+	class->component_kind = ICAL_VTODO_COMPONENT;
+	class->backend_type = E_TYPE_CAL_BACKEND_HTTP;
 }
 
 static void
@@ -153,29 +101,16 @@ e_cal_backend_http_todos_factory_init (ECalBackendFactory *factory)
 {
 }
 
-void
-eds_module_initialize (GTypeModule *type_module)
+G_MODULE_EXPORT void
+e_module_load (GTypeModule *type_module)
 {
 	e_cal_backend_http_events_factory_register_type (type_module);
 	e_cal_backend_http_journal_factory_register_type (type_module);
 	e_cal_backend_http_todos_factory_register_type (type_module);
 }
 
-void
-eds_module_shutdown (void)
+G_MODULE_EXPORT void
+e_module_unload (GTypeModule *type_module)
 {
 }
 
-void
-eds_module_list_types (const GType **types,
-                       gint *num_types)
-{
-	static GType http_types[3];
-
-	http_types[0] = e_cal_backend_http_events_factory_get_type ();
-	http_types[1] = e_cal_backend_http_journal_factory_get_type ();
-	http_types[2] = e_cal_backend_http_todos_factory_get_type ();
-
-	*types = http_types;
-	*num_types = G_N_ELEMENTS (http_types);
-}
diff --git a/calendar/backends/http/e-cal-backend-http.c b/calendar/backends/http/e-cal-backend-http.c
index d40bdd3..e564eb9 100644
--- a/calendar/backends/http/e-cal-backend-http.c
+++ b/calendar/backends/http/e-cal-backend-http.c
@@ -53,9 +53,6 @@ struct _ECalBackendHttpPrivate {
 	/* URI to get remote calendar data from */
 	gchar *uri;
 
-	/* Local/remote mode */
-	gboolean is_online;
-
 	/* The file cache */
 	ECalBackendStore *store;
 
@@ -100,7 +97,7 @@ e_cal_backend_http_dispose (GObject *object)
 	priv->credentials = NULL;
 
 	if (priv->source_changed_id) {
-		g_signal_handler_disconnect (e_cal_backend_get_source (E_CAL_BACKEND (cbhttp)), priv->source_changed_id);
+		g_signal_handler_disconnect (e_backend_get_source (E_BACKEND (cbhttp)), priv->source_changed_id);
 		priv->source_changed_id = 0;
 	}
 
@@ -579,7 +576,7 @@ begin_retrieval_cb (ECalBackendHttp *cbhttp)
 
 	priv = cbhttp->priv;
 
-	if (!priv->is_online)
+	if (!e_backend_get_online (E_BACKEND (cbhttp)))
 		return FALSE;
 
 	maybe_start_reload_timeout (cbhttp);
@@ -592,11 +589,12 @@ begin_retrieval_cb (ECalBackendHttp *cbhttp)
 	priv->is_loading = TRUE;
 
 	if (priv->uri == NULL) {
-		ESource *source = e_cal_backend_get_source (E_CAL_BACKEND (cbhttp));
+		ESource *source = e_backend_get_source (E_BACKEND (cbhttp));
 		const gchar *secure_prop = e_source_get_property (source, "use_ssl");
 
-		priv->uri = webcal_to_http_method (e_cal_backend_get_uri (E_CAL_BACKEND (cbhttp)),
-						   (secure_prop && g_str_equal(secure_prop, "1")));
+		priv->uri = webcal_to_http_method (
+			e_source_get_uri (source),
+			(secure_prop && g_str_equal(secure_prop, "1")));
 	}
 
 	/* create the Soup session if not already created */
@@ -685,7 +683,7 @@ maybe_start_reload_timeout (ECalBackendHttp *cbhttp)
 	if (priv->reload_timeout_id)
 		return;
 
-	source = e_cal_backend_get_source (E_CAL_BACKEND (cbhttp));
+	source = e_backend_get_source (E_BACKEND (cbhttp));
 	if (!source) {
 		g_warning ("Could not get source for ECalBackendHttp reload.");
 		return;
@@ -713,11 +711,11 @@ source_changed_cb (ESource *source,
 		const gchar *secure_prop;
 		gchar *new_uri;
 
-		source = e_cal_backend_get_source (E_CAL_BACKEND (cbhttp));
+		source = e_backend_get_source (E_BACKEND (cbhttp));
 		secure_prop = e_source_get_property (source, "use_ssl");
 
 		new_uri = webcal_to_http_method (
-			e_cal_backend_get_uri (E_CAL_BACKEND (cbhttp)),
+			e_source_get_uri (source),
 			(secure_prop && g_str_equal(secure_prop, "1")));
 
 		if (new_uri && !g_str_equal (priv->uri, new_uri)) {
@@ -744,6 +742,7 @@ e_cal_backend_http_open (ECalBackendSync *backend,
 	ECalBackendHttp *cbhttp;
 	ECalBackendHttpPrivate *priv;
 	ESource *source;
+	gboolean online;
 	gchar *tmp;
 
 	cbhttp = E_CAL_BACKEND_HTTP (backend);
@@ -755,7 +754,7 @@ e_cal_backend_http_open (ECalBackendSync *backend,
 		return;
 	}
 
-	source = e_cal_backend_get_source (E_CAL_BACKEND (backend));
+	source = e_backend_get_source (E_BACKEND (backend));
 
 	if (priv->source_changed_id == 0) {
 		priv->source_changed_id = g_signal_connect (source, "changed", G_CALLBACK (source_changed_cb), cbhttp);
@@ -784,9 +783,11 @@ e_cal_backend_http_open (ECalBackendSync *backend,
 	}
 
 	e_cal_backend_notify_readonly (E_CAL_BACKEND (backend), TRUE);
-	e_cal_backend_notify_online (E_CAL_BACKEND (backend), priv->is_online);
 
-	if (priv->is_online) {
+	online = e_backend_get_online (E_BACKEND (backend));
+	e_cal_backend_notify_online (E_CAL_BACKEND (backend), online);
+
+	if (online) {
 		if (e_source_get_property (source, "auth")) {
 			e_cal_backend_notify_auth_required (E_CAL_BACKEND (cbhttp), TRUE, priv->credentials);
 		} else if (priv->requires_auth && perror && !*perror) {
@@ -875,33 +876,32 @@ e_cal_backend_http_remove (ECalBackendSync *backend,
 
 /* Set_mode handler for the http backend */
 static void
-e_cal_backend_http_set_online (ECalBackend *backend,
-                               gboolean is_online)
+e_cal_backend_http_notify_online_cb (ECalBackend *backend,
+                                     GParamSpec *pspec)
 {
 	ECalBackendHttp *cbhttp;
 	ECalBackendHttpPrivate *priv;
 	gboolean loaded;
+	gboolean online;
 
 	cbhttp = E_CAL_BACKEND_HTTP (backend);
 	priv = cbhttp->priv;
 
+	online = e_backend_get_online (E_BACKEND (backend));
 	loaded = e_cal_backend_is_opened (backend);
 
-	if ((priv->is_online ? 1 : 0) != (is_online ? 1 : 0)) {
-		priv->is_online = is_online;
-		if (!priv->is_online) {
-			if (loaded && priv->reload_timeout_id) {
-				g_source_remove (priv->reload_timeout_id);
-				priv->reload_timeout_id = 0;
-			}
-		} else {
-			if (loaded)
-				g_idle_add ((GSourceFunc) begin_retrieval_cb, backend);
+	if (!online) {
+		if (loaded && priv->reload_timeout_id) {
+			g_source_remove (priv->reload_timeout_id);
+			priv->reload_timeout_id = 0;
 		}
+	} else {
+		if (loaded)
+			g_idle_add ((GSourceFunc) begin_retrieval_cb, backend);
 	}
 
 	if (loaded)
-		e_cal_backend_notify_online (backend, priv->is_online);
+		e_cal_backend_notify_online (backend, online);
 }
 
 /* Get_object_component handler for the http backend */
@@ -1369,6 +1369,10 @@ e_cal_backend_http_init (ECalBackendHttp *cbhttp)
 	priv->opened = FALSE;
 
 	e_cal_backend_sync_set_lock (E_CAL_BACKEND_SYNC (cbhttp), TRUE);
+
+	g_signal_connect (
+		cbhttp, "notify::online",
+		G_CALLBACK (e_cal_backend_http_notify_online_cb), NULL);
 }
 
 /* Class initialization function for the file backend */
@@ -1404,6 +1408,5 @@ e_cal_backend_http_class_init (ECalBackendHttpClass *class)
 	sync_class->get_free_busy_sync		= e_cal_backend_http_get_free_busy;
 
 	backend_class->start_view		= e_cal_backend_http_start_view;
-	backend_class->set_online		= e_cal_backend_http_set_online;
 	backend_class->internal_get_timezone	= e_cal_backend_http_internal_get_timezone;
 }
diff --git a/calendar/backends/http/e-cal-backend-http.h b/calendar/backends/http/e-cal-backend-http.h
index 6c23351..a28eb73 100644
--- a/calendar/backends/http/e-cal-backend-http.h
+++ b/calendar/backends/http/e-cal-backend-http.h
@@ -23,27 +23,32 @@
 
 #include <libedata-cal/e-cal-backend-sync.h>
 
-G_BEGIN_DECLS
-
-
+#define E_TYPE_CAL_BACKEND_HTTP \
+	(e_cal_backend_http_get_type ())
+#define E_CAL_BACKEND_HTTP(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_CAL_BACKEND_HTTP, ECalBackendHttp))
+#define E_CAL_BACKEND_HTTP_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), E_TYPE_CAL_BACKEND_HTTP, ECalBackendHttpClass))
+#define E_IS_CAL_BACKEND_HTTP(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), E_TYPE_CAL_BACKEND_HTTP))
+#define E_IS_CAL_BACKEND_HTTP_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), E_TYPE_CAL_BACKEND_HTTP))
+#define E_CAL_BACKEND_HTTP_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), E_TYPE_CAL_BACKEND_HTTP, ECalBackendHttpClass))
 
-#define E_TYPE_CAL_BACKEND_HTTP            (e_cal_backend_http_get_type ())
-#define E_CAL_BACKEND_HTTP(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_CAL_BACKEND_HTTP,		\
-					  ECalBackendHttp))
-#define E_CAL_BACKEND_HTTP_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_CAL_BACKEND_HTTP,	\
-					  ECalBackendHttpClass))
-#define E_IS_CAL_BACKEND_HTTP(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_CAL_BACKEND_HTTP))
-#define E_IS_CAL_BACKEND_HTTP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_CAL_BACKEND_HTTP))
+G_BEGIN_DECLS
 
 typedef struct _ECalBackendHttp ECalBackendHttp;
 typedef struct _ECalBackendHttpClass ECalBackendHttpClass;
-
 typedef struct _ECalBackendHttpPrivate ECalBackendHttpPrivate;
 
 struct _ECalBackendHttp {
 	ECalBackendSync backend;
-
-	/* Private data */
 	ECalBackendHttpPrivate *priv;
 };
 
@@ -51,10 +56,8 @@ struct _ECalBackendHttpClass {
 	ECalBackendSyncClass parent_class;
 };
 
-GType       e_cal_backend_http_get_type      (void);
-
-
+GType		e_cal_backend_http_get_type	(void);
 
 G_END_DECLS
 
-#endif
+#endif /* E_CAL_BACKEND_HTTP_H */



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