[evolution-data-server] EDataFactory: Use GNetworkMonitor always.



commit f8e615bf8bbd75b38144b75dbea337626c7b604a
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Mar 31 10:37:06 2012 -0400

    EDataFactory: Use GNetworkMonitor always.

 libebackend/e-data-factory.c |   99 ++++-------------------------------------
 1 files changed, 10 insertions(+), 89 deletions(-)
---
diff --git a/libebackend/e-data-factory.c b/libebackend/e-data-factory.c
index 8694e5a..93ee067 100644
--- a/libebackend/e-data-factory.c
+++ b/libebackend/e-data-factory.c
@@ -26,10 +26,6 @@
 
 #include <config.h>
 
-#if GLIB_CHECK_VERSION(2,31,0)
-#define USE_NETWORK_MONITOR
-#endif
-
 #include <libebackend/e-extensible.h>
 #include <libebackend/e-backend-factory.h>
 
@@ -50,10 +46,6 @@ struct _EDataFactoryPrivate {
 	/* Hash Key -> EBackendFactory */
 	GHashTable *backend_factories;
 
-#ifndef USE_NETWORK_MONITOR
-	GSettings *settings;
-#endif
-
 	gboolean online;
 };
 
@@ -70,73 +62,6 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (
 	G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, e_data_factory_initable_init)
 	G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE, NULL))
 
-#ifdef USE_NETWORK_MONITOR
-
-static void
-network_changed (GNetworkMonitor *monitor,
-                 gboolean available,
-                 EDataFactory *factory)
-{
-	e_data_factory_set_online (factory, available);
-}
-
-static void
-data_factory_init_online_monitoring (EDataFactory *factory)
-{
-	GNetworkMonitor *monitor;
-	gboolean network_available;
-
-	monitor = g_network_monitor_get_default ();
-	g_signal_connect (
-		monitor, "network-changed",
-		G_CALLBACK (network_changed), factory);
-
-	network_available = g_network_monitor_get_network_available (monitor);
-	e_data_factory_set_online (factory, network_available);
-}
-
-#else
-
-static void
-data_factory_online_changed (GSettings *settings,
-                             const gchar *key,
-                             EDataFactory *factory)
-{
-	gboolean start_offline;
-
-	start_offline = g_settings_get_boolean (
-		factory->priv->settings, "start-offline");
-
-	e_data_factory_set_online (factory, !start_offline);
-}
-
-static void
-data_factory_init_online_monitoring (EDataFactory *factory)
-{
-	const gchar *schema;
-	gboolean start_offline;
-
-	/* XXX For the record, we're doing this completely wrong.
-	 *     EDataFactory should monitor network availability itself
-	 *     instead of relying on one particular client application
-	 *     to tell us when we're offline.  But I'll deal with this
-	 *     at some later date. */
-
-	schema = "org.gnome.evolution.eds-shell";
-	factory->priv->settings = g_settings_new (schema);
-
-	g_signal_connect (
-		factory->priv->settings, "changed::start-offline",
-		G_CALLBACK (data_factory_online_changed), factory);
-
-	start_offline = g_settings_get_boolean (
-		factory->priv->settings, "start-offline");
-
-	e_data_factory_set_online (factory, !start_offline);
-}
-
-#endif
-
 static void
 data_factory_last_client_gone_cb (EBackend *backend,
                                   EDataFactory *factory)
@@ -197,17 +122,6 @@ data_factory_dispose (GObject *object)
 	g_hash_table_remove_all (priv->backends);
 	g_hash_table_remove_all (priv->backend_factories);
 
-#ifdef USE_NETWORK_MONITOR
-	g_signal_handlers_disconnect_by_func (
-		g_network_monitor_get_default (),
-		G_CALLBACK (network_changed), object);
-#else
-	if (priv->settings != NULL) {
-		g_object_unref (priv->settings);
-		priv->settings = NULL;
-	}
-#endif
-
 	/* Chain up to parent's dispose() method. */
 	G_OBJECT_CLASS (e_data_factory_parent_class)->dispose (object);
 }
@@ -234,10 +148,20 @@ data_factory_initable_init (GInitable *initable,
                             GError **error)
 {
 	EDataFactoryPrivate *priv;
+	GNetworkMonitor *monitor;
 	GList *list, *link;
 
 	priv = E_DATA_FACTORY_GET_PRIVATE (initable);
 
+	/* Synchronize network monitoring. */
+
+	monitor = g_network_monitor_get_default ();
+
+	g_object_bind_property (
+		monitor, "network-available",
+		initable, "online",
+		G_BINDING_SYNC_CREATE);
+
 	/* Load all module libraries containing extensions. */
 
 	e_dbus_server_load_modules (E_DBUS_SERVER (initable));
@@ -293,7 +217,6 @@ e_data_factory_class_init (EDataFactoryClass *class)
 			"Whether the server is online",
 			TRUE,
 			G_PARAM_READWRITE |
-			G_PARAM_CONSTRUCT |
 			G_PARAM_STATIC_STRINGS));
 }
 
@@ -321,8 +244,6 @@ e_data_factory_init (EDataFactory *factory)
 		(GEqualFunc) g_str_equal,
 		(GDestroyNotify) g_free,
 		(GDestroyNotify) g_object_unref);
-
-	data_factory_init_online_monitoring (factory);
 }
 
 EBackend *



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