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



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

    Adapt ECalBackendWeather to libedata-cal changes.

 calendar/backends/weather/Makefile.am              |    1 -
 .../weather/e-cal-backend-weather-factory.c        |   59 +++++---------------
 .../weather/e-cal-backend-weather-factory.h        |   34 -----------
 calendar/backends/weather/e-cal-backend-weather.c  |   53 +++++++++++-------
 calendar/backends/weather/e-cal-backend-weather.h  |   32 +++++++----
 5 files changed, 67 insertions(+), 112 deletions(-)
---
diff --git a/calendar/backends/weather/Makefile.am b/calendar/backends/weather/Makefile.am
index cd57049..fd20e3d 100644
--- a/calendar/backends/weather/Makefile.am
+++ b/calendar/backends/weather/Makefile.am
@@ -17,7 +17,6 @@ libecalbackendweather_la_CPPFLAGS = \
 
 libecalbackendweather_la_SOURCES =	\
 	e-cal-backend-weather-factory.c	\
-	e-cal-backend-weather-factory.h	\
 	e-cal-backend-weather.c		\
 	e-cal-backend-weather.h		\
 	e-weather-source.c		\
diff --git a/calendar/backends/weather/e-cal-backend-weather-factory.c b/calendar/backends/weather/e-cal-backend-weather-factory.c
index 94d6cd9..f68113d 100644
--- a/calendar/backends/weather/e-cal-backend-weather-factory.c
+++ b/calendar/backends/weather/e-cal-backend-weather-factory.c
@@ -18,18 +18,20 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
-#include <string.h>
-
-#include "e-cal-backend-weather-factory.h"
+#include <libedata-cal/e-cal-backend-factory.h>
 #include "e-cal-backend-weather.h"
 
+#define FACTORY_NAME "weather"
+
 typedef ECalBackendFactory ECalBackendWeatherEventsFactory;
 typedef ECalBackendFactoryClass ECalBackendWeatherEventsFactoryClass;
 
+/* Module Entry Points */
+void e_module_load (GTypeModule *type_module);
+void e_module_unload (GTypeModule *type_module);
+
 /* Forward Declarations */
 GType e_cal_backend_weather_events_factory_get_type (void);
 
@@ -38,34 +40,12 @@ G_DEFINE_DYNAMIC_TYPE (
 	e_cal_backend_weather_events_factory,
 	E_TYPE_CAL_BACKEND_FACTORY)
 
-static const gchar *
-_get_protocol (ECalBackendFactory *factory)
-{
-	return "weather";
-}
-
-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_weather_get_type (),
-		"kind", ICAL_VEVENT_COMPONENT,
-		"source", source, NULL);
-}
-
 static void
 e_cal_backend_weather_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_WEATHER;
 }
 
 static void
@@ -78,25 +58,14 @@ e_cal_backend_weather_events_factory_init (ECalBackendFactory *factory)
 {
 }
 
-void
-eds_module_initialize (GTypeModule *type_module)
+G_MODULE_EXPORT void
+e_module_load (GTypeModule *type_module)
 {
 	e_cal_backend_weather_events_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 weather_types[1];
-
-	weather_types[0] = e_cal_backend_weather_events_factory_get_type ();
-
-	*types = weather_types;
-	*num_types = G_N_ELEMENTS (weather_types);
-}
diff --git a/calendar/backends/weather/e-cal-backend-weather.c b/calendar/backends/weather/e-cal-backend-weather.c
index e784677..aad9618 100644
--- a/calendar/backends/weather/e-cal-backend-weather.c
+++ b/calendar/backends/weather/e-cal-backend-weather.c
@@ -49,9 +49,6 @@ struct _ECalBackendWeatherPrivate {
 	/* URI to get remote weather data from */
 	gchar *uri;
 
-	/* Local/remote mode */
-	gboolean is_online;
-
 	/* The file cache */
 	ECalBackendStore *store;
 
@@ -114,7 +111,7 @@ maybe_start_reload_timeout (ECalBackendWeather *cbw)
 	if (priv->reload_timeout_id)
 		return;
 
-	source = e_cal_backend_get_source (E_CAL_BACKEND (cbw));
+	source = e_backend_get_source (E_BACKEND (cbw));
 	if (!source) {
 		g_warning ("Could not get source for ECalBackendWeather reload.");
 		return;
@@ -253,13 +250,19 @@ begin_retrieval_cb (ECalBackendWeather *cbw)
 	ECalBackendWeatherPrivate *priv = cbw->priv;
 	GSource *source;
 
-	if (!priv->is_online)
+	if (!e_backend_get_online (E_BACKEND (cbw)))
 		return TRUE;
 
 	maybe_start_reload_timeout (cbw);
 
-	if (priv->source == NULL)
-		priv->source = e_weather_source_new (e_cal_backend_get_uri (E_CAL_BACKEND (cbw)));
+	if (priv->source == NULL) {
+		ESource *e_source;
+		const gchar *uri;
+
+		e_source = e_backend_get_source (E_BACKEND (cbw));
+		uri = e_source_get_uri (e_source);
+		priv->source = e_weather_source_new (uri);
+	}
 
 	source = g_main_current_source ();
 
@@ -340,7 +343,7 @@ create_weather (ECalBackendWeather *cbw,
 
 	priv = cbw->priv;
 
-	source = e_cal_backend_get_source (E_CAL_BACKEND (cbw));
+	source = e_backend_get_source (E_BACKEND (cbw));
 	tmp = e_source_get_property (source, "units");
 	if (tmp == NULL) {
 		tmp = e_source_get_property (source, "temperature");
@@ -503,13 +506,17 @@ e_cal_backend_weather_open (ECalBackendSync *backend,
 {
 	ECalBackendWeather *cbw;
 	ECalBackendWeatherPrivate *priv;
+	ESource *source;
 	const gchar *cache_dir;
 	const gchar *uri;
+	gboolean online;
 
 	cbw = E_CAL_BACKEND_WEATHER (backend);
 	priv = cbw->priv;
 
-	uri = e_cal_backend_get_uri (E_CAL_BACKEND (backend));
+	source = e_backend_get_source (E_BACKEND (backend));
+	uri = e_source_get_uri (source);
+
 	cache_dir = e_cal_backend_get_cache_dir (E_CAL_BACKEND (backend));
 
 	if (priv->city)
@@ -517,7 +524,9 @@ e_cal_backend_weather_open (ECalBackendSync *backend,
 	priv->city = g_strdup (strrchr (uri, '/') + 1);
 
 	e_cal_backend_notify_readonly (E_CAL_BACKEND (backend), TRUE);
-	e_cal_backend_notify_online (E_CAL_BACKEND (backend), priv->is_online);
+
+	online = e_backend_get_online (E_BACKEND (backend));
+	e_cal_backend_notify_online (E_CAL_BACKEND (backend), online);
 
 	if (!priv->store) {
 		e_cal_backend_cache_remove (cache_dir, "cache.xml");
@@ -532,7 +541,7 @@ e_cal_backend_weather_open (ECalBackendSync *backend,
 		e_cal_backend_store_load (priv->store);
 		e_cal_backend_notify_opened (E_CAL_BACKEND (backend), NULL);
 
-		if (!priv->is_online)
+		if (!e_backend_get_online (E_BACKEND (backend)))
 			return;
 
 		if (!priv->begin_retrival_id)
@@ -779,28 +788,27 @@ e_cal_backend_weather_start_view (ECalBackend *backend,
 }
 
 static void
-e_cal_backend_weather_set_online (ECalBackend *backend,
-                                  gboolean is_online)
+e_cal_backend_weather_notify_online_cb (ECalBackend *backend,
+                                        GParamSpec *pspec)
 {
 	ECalBackendWeather *cbw;
 	ECalBackendWeatherPrivate *priv;
 	gboolean loaded;
+	gboolean online;
 
 	cbw = E_CAL_BACKEND_WEATHER (backend);
 	priv = cbw->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 (loaded && priv->reload_timeout_id) {
-			g_source_remove (priv->reload_timeout_id);
-			priv->reload_timeout_id = 0;
-		}
+	if (loaded && priv->reload_timeout_id) {
+		g_source_remove (priv->reload_timeout_id);
+		priv->reload_timeout_id = 0;
 	}
 
 	if (loaded) {
-		e_cal_backend_notify_online (backend, priv->is_online);
+		e_cal_backend_notify_online (backend, online);
 		e_cal_backend_notify_readonly (backend, TRUE);
 	}
 }
@@ -899,6 +907,10 @@ e_cal_backend_weather_init (ECalBackendWeather *cbw)
 	priv->zones = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_zone);
 
 	e_cal_backend_sync_set_lock (E_CAL_BACKEND_SYNC (cbw), TRUE);
+
+	g_signal_connect (
+		cbw, "notify::online",
+		G_CALLBACK (e_cal_backend_weather_notify_online_cb), NULL);
 }
 
 /* Class initialization function for the weather backend */
@@ -928,6 +940,5 @@ e_cal_backend_weather_class_init (ECalBackendWeatherClass *class)
 	sync_class->get_free_busy_sync		= e_cal_backend_weather_get_free_busy;
 
 	backend_class->start_view		= e_cal_backend_weather_start_view;
-	backend_class->set_online		= e_cal_backend_weather_set_online;
 	backend_class->internal_get_timezone	= e_cal_backend_weather_internal_get_timezone;
 }
diff --git a/calendar/backends/weather/e-cal-backend-weather.h b/calendar/backends/weather/e-cal-backend-weather.h
index 6b3afa5..8974116 100644
--- a/calendar/backends/weather/e-cal-backend-weather.h
+++ b/calendar/backends/weather/e-cal-backend-weather.h
@@ -23,23 +23,33 @@
 
 #include <libedata-cal/e-cal-backend-sync.h>
 
-G_BEGIN_DECLS
+/* Standard GObject macros */
+#define E_TYPE_CAL_BACKEND_WEATHER \
+	(e_cal_backend_weather_get_type ())
+#define E_CAL_BACKEND_WEATHER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_CAL_BACKEND_WEATHER, ECalBackendWeather))
+#define E_CAL_BACKEND_WEATHER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), E_TYPE_CAL_BACKEND_WEATHER, ECalBackendWeatherClass))
+#define E_IS_CAL_BACKEND_WEATHER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), E_TYPE_CAL_BACKEND_WEATHER))
+#define E_IS_CAL_BACKEND_WEATHER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), E_TYPE_CAL_BACKEND_WEATHER))
+#define E_CAL_BACKEND_WEATHER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), E_TYPE_CAL_BACKEND_WEATHER, ECalBackendWeatherClass))
 
-#define E_TYPE_CAL_BACKEND_WEATHER            (e_cal_backend_weather_get_type ())
-#define E_CAL_BACKEND_WEATHER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_CAL_BACKEND_WEATHER, ECalBackendWeather))
-#define E_CAL_BACKEND_WEATHER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_CAL_BACKEND_WEATHER, ECalBackendWeatherClass))
-#define E_IS_CAL_BACKEND_WEATHER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_CAL_BACKEND_WEATHER))
-#define E_IS_CAL_BACKEND_WEATHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_CAL_BACKEND_WEATHER))
+G_BEGIN_DECLS
 
 typedef struct _ECalBackendWeather ECalBackendWeather;
 typedef struct _ECalBackendWeatherClass ECalBackendWeatherClass;
-
 typedef struct _ECalBackendWeatherPrivate ECalBackendWeatherPrivate;
 
 struct _ECalBackendWeather {
 	ECalBackendSync backend;
-
-	/* Private data */
 	ECalBackendWeatherPrivate *priv;
 };
 
@@ -47,8 +57,8 @@ struct _ECalBackendWeatherClass {
 	ECalBackendSyncClass parent_class;
 };
 
-GType	e_cal_backend_weather_get_type (void);
+GType		e_cal_backend_weather_get_type	(void);
 
 G_END_DECLS
 
-#endif
+#endif /* E_CAL_BACKEND_WEATHER_H */



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