network-manager-applet r727 - in trunk: . src/gconf-helpers



Author: tambeti
Date: Mon May 19 11:19:11 2008
New Revision: 727
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=727&view=rev

Log:
    2008-05-15  Tambet Ingo  <tambet gmail com>

    	Update GConf connections after all the changes are done to avoid
    	invalid connection states while in between changes.

    	* src/gconf-helpers/nma-gconf-settings.c (connections_changed_cb):
    	Collect all pending changes and handle them after all GConf changes
    	are done. Also fixes a bunch of ugly warnings when connections get
    	deleted.

    	* src/gconf-helpers/nma-gconf-connection.c
    	(nma_gconf_connection_changed): Remove the GConfEntry, we collect all
    	changes before calling this, the connection is in invalid state while
    	some setting values are update and others aren't.
    	(delete): Suggest a sync after recursive unset.


Modified:
   trunk/ChangeLog
   trunk/src/gconf-helpers/nma-gconf-connection.c
   trunk/src/gconf-helpers/nma-gconf-connection.h
   trunk/src/gconf-helpers/nma-gconf-settings.c

Modified: trunk/src/gconf-helpers/nma-gconf-connection.c
==============================================================================
--- trunk/src/gconf-helpers/nma-gconf-connection.c	(original)
+++ trunk/src/gconf-helpers/nma-gconf-connection.c	Mon May 19 11:19:11 2008
@@ -120,8 +120,7 @@
 }
 
 gboolean
-nma_gconf_connection_changed (NMAGConfConnection *self,
-						GConfEntry *entry)
+nma_gconf_connection_changed (NMAGConfConnection *self)
 {
 	NMAGConfConnectionPrivate *priv;
 	GHashTable *settings;
@@ -130,12 +129,10 @@
 	GHashTable *new_settings;
 
 	g_return_val_if_fail (NMA_IS_GCONF_CONNECTION (self), FALSE);
-	g_return_val_if_fail (entry != NULL, FALSE);
 
 	priv = NMA_GCONF_CONNECTION_GET_PRIVATE (self);
 	wrapped_connection = nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (self));
 
-	/* FIXME: just update the modified field, no need to re-read all */
 	gconf_connection = nm_gconf_read_connection (priv->client, priv->dir);
 	if (!gconf_connection) {
 		g_warning ("No connection read from GConf at %s.", priv->dir);
@@ -313,8 +310,12 @@
 delete (NMExportedConnection *exported, GError **err)
 {
 	NMAGConfConnectionPrivate *priv = NMA_GCONF_CONNECTION_GET_PRIVATE (exported);
+	gboolean success;
 
-	return gconf_client_recursive_unset (priv->client, priv->dir, 0, err);
+	success = gconf_client_recursive_unset (priv->client, priv->dir, 0, err);
+	gconf_client_suggest_sync (priv->client, NULL);
+
+	return success;
 }
 
 /* GObject */

Modified: trunk/src/gconf-helpers/nma-gconf-connection.h
==============================================================================
--- trunk/src/gconf-helpers/nma-gconf-connection.h	(original)
+++ trunk/src/gconf-helpers/nma-gconf-connection.h	Mon May 19 11:19:11 2008
@@ -47,8 +47,7 @@
 
 void                nma_gconf_connection_save (NMAGConfConnection *self);
 
-gboolean            nma_gconf_connection_changed (NMAGConfConnection *self,
-										GConfEntry *entry);
+gboolean            nma_gconf_connection_changed (NMAGConfConnection *self);
 
 G_END_DECLS
 

Modified: trunk/src/gconf-helpers/nma-gconf-settings.c
==============================================================================
--- trunk/src/gconf-helpers/nma-gconf-settings.c	(original)
+++ trunk/src/gconf-helpers/nma-gconf-settings.c	Mon May 19 11:19:11 2008
@@ -16,6 +16,7 @@
 	guint conf_notify_id;
 	GSList *connections;
 	guint read_connections_id;
+	GHashTable *pending_changes;
 
 	gboolean disposed;
 } NMAGConfSettingsPrivate;
@@ -237,6 +238,52 @@
 	return g_slist_copy (priv->connections);
 }
 
+typedef struct {
+	NMAGConfSettings *settings;
+	char *path;
+} ConnectionChangedInfo;
+
+static void
+connection_changed_info_destroy (gpointer data)
+{
+	ConnectionChangedInfo *info = (ConnectionChangedInfo *) data;
+
+	g_free (info->path);
+	g_free (info);
+}
+
+static gboolean
+connection_changes_done (gpointer data)
+{
+	ConnectionChangedInfo *info = (ConnectionChangedInfo *) data;
+	NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (info->settings);
+	NMAGConfConnection *connection;
+
+	connection = nma_gconf_settings_get_by_path (info->settings, info->path);
+	if (!connection) {
+		/* New connection */
+		connection = nma_gconf_connection_new (priv->client, info->path);
+		if (connection) {
+			g_signal_connect (connection, "new-secrets-requested",
+						   G_CALLBACK (connection_new_secrets_requested_cb),
+						   info->settings);
+			priv->connections = g_slist_append (priv->connections, connection);
+			nm_settings_signal_new_connection (NM_SETTINGS (info->settings),
+										NM_EXPORTED_CONNECTION (connection));
+		}
+	} else {
+		if (gconf_client_dir_exists (priv->client, info->path, NULL)) {
+			/* Updated connection */
+			if (!nma_gconf_connection_changed (connection))
+				priv->connections = g_slist_remove (priv->connections, connection);
+		}
+	}
+
+	g_hash_table_remove (priv->pending_changes, info->path);
+
+	return FALSE;
+}
+
 static void
 connections_changed_cb (GConfClient *conf_client,
                         guint cnxn_id,
@@ -248,8 +295,6 @@
 	char **dirs = NULL;
 	guint len;
 	char *path = NULL;
-	NMAGConfConnection *connection;
-	gboolean valid = FALSE;
 
 	dirs = g_strsplit (gconf_entry_get_key (entry), "/", -1);
 	len = g_strv_length (dirs);
@@ -263,23 +308,19 @@
 		goto out;
 
 	path = g_strconcat ("/", dirs[1], "/", dirs[2], "/", dirs[3], "/", dirs[4], NULL);
-	connection = nma_gconf_settings_get_by_path (self, path);
-	if (!connection) {
-		/* New connection */
-		connection = nma_gconf_connection_new (priv->client, path);
-		if (connection) {
-			g_signal_connect (connection, "new-secrets-requested",
-						   G_CALLBACK (connection_new_secrets_requested_cb),
-						   self);
-			priv->connections = g_slist_append (priv->connections, connection);
-			nm_settings_signal_new_connection (NM_SETTINGS (self),
-										NM_EXPORTED_CONNECTION (connection));
-		}
-	} else {
-		/* Updated or removed connection */
-		valid = nma_gconf_connection_changed (connection, entry);
-		if (!valid)
-			priv->connections = g_slist_remove (priv->connections, connection);
+
+	if (!g_hash_table_lookup (priv->pending_changes, path)) {
+		ConnectionChangedInfo *info;
+		guint id;
+
+		info = g_new (ConnectionChangedInfo, 1);
+		info->settings = self;
+		info->path = path;
+		path = NULL;
+
+		id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, connection_changes_done, 
+						  info, connection_changed_info_destroy);
+		g_hash_table_insert (priv->pending_changes, info->path, GUINT_TO_POINTER (id));
 	}
 
 out:
@@ -287,6 +328,12 @@
 	g_strfreev (dirs);
 }
 
+static void
+remove_pending_change (gpointer data)
+{
+	g_source_remove (GPOINTER_TO_UINT (data));
+}
+
 /* GObject */
 
 static void
@@ -295,6 +342,7 @@
 	NMAGConfSettingsPrivate *priv = NMA_GCONF_SETTINGS_GET_PRIVATE (settings);
 
 	priv->client = gconf_client_get_default ();
+	priv->pending_changes = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, remove_pending_change);
 
 	gconf_client_add_dir (priv->client,
 	                      GCONF_PATH_CONNECTIONS,
@@ -338,6 +386,8 @@
 
 	priv->disposed = TRUE;
 
+	g_hash_table_destroy (priv->pending_changes);
+
 	if (priv->read_connections_id) {
 		g_source_remove (priv->read_connections_id);
 		priv->read_connections_id = 0;



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