network-manager-applet r881 - in trunk: . src/connection-editor



Author: dcbw
Date: Tue Sep  9 20:52:18 2008
New Revision: 881
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=881&view=rev

Log:
2008-09-09  Dan Williams  <dcbw redhat com>

	* src/connection-editor/nm-connection-list.c
		- (remove_connection): clean up left-over VPN secrets when removing the
			connection
		- (add_connection, update_connection): save VPN secrets for user-scope
			connections

	* src/connection-editor/nm-connection-editor.c
		- (ui_to_setting, connection_editor_validate): validate and update the
			'connection' setting just like any other setting
		- (populate_connection_ui): hook up signals for notification of when
			'connection' setting properties change; connection scope needs to be
			up-to-date before any other settings are validated
		- (nm_connection_editor_save_vpn_secrets): ask the VPN page to ask the
			plugin to save its secrets

	* src/connection-editor/page-vpn.c
		- (ce_page_vpn_save_secrets): call VPN UI plugin's hook to save secrets



Modified:
   trunk/ChangeLog
   trunk/src/connection-editor/nm-connection-editor.c
   trunk/src/connection-editor/nm-connection-editor.h
   trunk/src/connection-editor/nm-connection-list.c
   trunk/src/connection-editor/page-vpn.c
   trunk/src/connection-editor/page-vpn.h

Modified: trunk/src/connection-editor/nm-connection-editor.c
==============================================================================
--- trunk/src/connection-editor/nm-connection-editor.c	(original)
+++ trunk/src/connection-editor/nm-connection-editor.c	Tue Sep  9 20:52:18 2008
@@ -97,19 +97,46 @@
 		gtk_window_set_title (GTK_WINDOW (editor->dialog), _("Editing unamed connection"));
 }
 
-static void
-connection_editor_validate (NMConnectionEditor *editor)
+static gboolean
+ui_to_setting (NMConnectionEditor *editor)
 {
+	NMSettingConnection *s_con;
 	GtkWidget *widget;
-	gboolean valid = FALSE;
 	const char *name;
-	GSList *iter;
+	gboolean autoconnect = FALSE;
+
+	s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (editor->connection, NM_TYPE_SETTING_CONNECTION));
+	g_assert (s_con);
 
 	widget = glade_xml_get_widget (editor->xml, "connection_name");
 	name = gtk_entry_get_text (GTK_ENTRY (widget));
 
-	/* Re-validate */
+	g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_ID, name, NULL);
+	nm_connection_editor_update_title (editor);
+
 	if (!name || !strlen (name))
+		return FALSE;
+
+	widget = glade_xml_get_widget (editor->xml, "connection_autoconnect");
+	autoconnect = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+	g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_AUTOCONNECT, autoconnect, NULL);
+
+	widget = glade_xml_get_widget (editor->xml, "connection_system");
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
+		nm_connection_set_scope (editor->connection, NM_CONNECTION_SCOPE_SYSTEM);
+	else
+		nm_connection_set_scope (editor->connection, NM_CONNECTION_SCOPE_USER);
+
+	return TRUE;
+}
+
+static void
+connection_editor_validate (NMConnectionEditor *editor)
+{
+	gboolean valid = FALSE;
+	GSList *iter;
+
+	if (!ui_to_setting (editor))
 		goto done;
 
 	for (iter = editor->pages; iter; iter = g_slist_next (iter)) {
@@ -133,26 +160,8 @@
 }
 
 static void
-connection_name_changed (GtkEditable *editable, gpointer user_data)
-{
-	NMSettingConnection *s_con;
-	NMConnectionEditor *editor = NM_CONNECTION_EDITOR (user_data);
-	const char *name;
-
-	s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (editor->connection, NM_TYPE_SETTING_CONNECTION));
-	g_assert (s_con);
-
-	name = gtk_entry_get_text (GTK_ENTRY (editable));
-	g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_ID, name, NULL);
-	nm_connection_editor_update_title (editor);
-
-	connection_editor_validate (editor);
-}
-
-static void
 nm_connection_editor_init (NMConnectionEditor *editor)
 {
-	GtkWidget *widget;
 	GtkWidget *dialog;
 
 	/* Yes, we mean applet.glade, not nm-connection-editor.glade. The wireless security bits
@@ -187,10 +196,6 @@
 
 	editor->ok_button = glade_xml_get_widget (editor->xml, "ok_button");
 
-	widget = glade_xml_get_widget (editor->xml, "connection_name");
-	g_signal_connect (G_OBJECT (widget), "changed",
-	                  G_CALLBACK (connection_name_changed), editor);
-
 	editor->pages = NULL;
 }
 
@@ -275,6 +280,13 @@
 		gtk_entry_set_text (GTK_ENTRY (name), NULL);
 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (autoconnect), FALSE);
 	}
+
+	g_signal_connect (G_OBJECT (name), "changed",
+	                  G_CALLBACK (connection_editor_validate), editor);
+	g_signal_connect (G_OBJECT (autoconnect), "toggled",
+	                  G_CALLBACK (connection_editor_validate), editor);
+	g_signal_connect (G_OBJECT (autoconnect), "toggled",
+	                  G_CALLBACK (connection_editor_validate), editor);
 }
 
 static void
@@ -361,40 +373,10 @@
 }
 
 static void
-connection_editor_update_connection (NMConnectionEditor *editor)
-{
-	NMSettingConnection *s_con;
-	GtkWidget *widget;
-	const char *name;
-	gboolean autoconnect = FALSE;
-
-	s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (editor->connection, NM_TYPE_SETTING_CONNECTION));
-	g_assert (s_con);
-
-	widget = glade_xml_get_widget (editor->xml, "connection_name");
-	name = gtk_entry_get_text (GTK_ENTRY (widget));
-	widget = glade_xml_get_widget (editor->xml, "connection_autoconnect");
-	autoconnect = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
-	g_object_set (G_OBJECT (s_con),
-	              NM_SETTING_CONNECTION_ID, name,
-	              NM_SETTING_CONNECTION_AUTOCONNECT, autoconnect,
-	              NULL);
-
-	widget = glade_xml_get_widget (editor->xml, "connection_system");
-	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
-		nm_connection_set_scope (editor->connection, NM_CONNECTION_SCOPE_SYSTEM);
-	else
-		nm_connection_set_scope (editor->connection, NM_CONNECTION_SCOPE_USER);
-}
-
-static void
 editor_response_cb (GtkDialog *dialog, gint response, gpointer user_data)
 {
 	NMConnectionEditor *editor = NM_CONNECTION_EDITOR (user_data);
 
-	if (response == GTK_RESPONSE_OK)
-		connection_editor_update_connection (editor);
-
 	g_signal_emit (editor, editor_signals[EDITOR_DONE], 0, response);
 }
 
@@ -417,3 +399,21 @@
 	nm_connection_editor_present (editor);
 }
 
+void
+nm_connection_editor_save_vpn_secrets (NMConnectionEditor *editor)
+{
+	GSList *iter;
+
+	g_return_if_fail (NM_IS_CONNECTION_EDITOR (editor));
+	g_return_if_fail (nm_connection_get_scope (editor->connection) == NM_CONNECTION_SCOPE_USER);
+
+	for (iter = editor->pages; iter; iter = g_slist_next (iter)) {
+		CEPage *page = CE_PAGE (iter->data);
+
+		if (CE_IS_PAGE_VPN (page)) {
+			ce_page_vpn_save_secrets (page, editor->connection);
+			break;
+		}
+	}
+}
+

Modified: trunk/src/connection-editor/nm-connection-editor.h
==============================================================================
--- trunk/src/connection-editor/nm-connection-editor.h	(original)
+++ trunk/src/connection-editor/nm-connection-editor.h	Tue Sep  9 20:52:18 2008
@@ -55,6 +55,7 @@
 
 void                nm_connection_editor_present (NMConnectionEditor *editor);
 void                nm_connection_editor_run (NMConnectionEditor *editor);
+void                nm_connection_editor_save_vpn_secrets (NMConnectionEditor *editor);
 NMConnection *nm_connection_editor_get_connection (NMConnectionEditor *editor);
 
 #endif

Modified: trunk/src/connection-editor/nm-connection-list.c
==============================================================================
--- trunk/src/connection-editor/nm-connection-list.c	(original)
+++ trunk/src/connection-editor/nm-connection-list.c	Tue Sep  9 20:52:18 2008
@@ -369,14 +369,13 @@
 
 static void
 remove_connection (NMExportedConnection *exported,
-			    ConnectionRemovedFn callback,
-			    gpointer user_data)
+                   ConnectionRemovedFn callback,
+                   gpointer user_data)
 {
 	GError *error = NULL;
 	gboolean success;
 
 	success = nm_exported_connection_delete (exported, &error);
-
 	if (!success) {
 		gboolean auth_pending = FALSE;
 
@@ -401,6 +400,33 @@
 
 		if (auth_pending)
 			return;
+	} else {
+		NMConnection *connection;
+		NMSettingConnection *s_con;
+		NMSettingVPN *s_vpn;
+		NMVpnPluginUiInterface *plugin;
+
+		connection = nm_exported_connection_get_connection (exported);
+		s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+		g_assert (s_con);
+		g_assert (s_con->type);
+
+		/* FIXME: clean up any left-over connection secrets here */
+
+		/* Clean up VPN secrets and any plugin-specific data */
+		if (!strcmp (s_con->type, NM_SETTING_VPN_SETTING_NAME)) {
+			s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
+			if (s_vpn) {
+				plugin = vpn_get_plugin_by_service (s_vpn->service_type);
+				if (plugin)
+					if (!nm_vpn_plugin_ui_interface_delete_connection (plugin, connection, &error)) {
+						g_warning ("%s: couldn't clean up VPN connection on delete: (%d) %s",
+						           __func__, error ? error->code : -1, error ? error->message : "unknown");
+						if (error)
+							g_error_free (error);
+					}
+			}
+		}
 	}
 
 	if (callback)
@@ -422,9 +448,10 @@
 } ConnectionAddInfo;
 
 static void add_connection (NMConnectionList *self,
-					   NMConnection *connection,
-					   ConnectionAddedFn callback,
-					   gpointer user_data);
+                            NMConnectionEditor *editor,
+                            NMConnection *connection,
+                            ConnectionAddedFn callback,
+                            gpointer user_data);
 
 static void
 add_connection_cb (PolKitAction *action,
@@ -436,7 +463,7 @@
 	gboolean done = TRUE;
 
 	if (gained_privilege) {
-		add_connection (info->list, info->connection, info->callback, info->user_data);
+		add_connection (info->list, NULL, info->connection, info->callback, info->user_data);
 		done = FALSE;
 	} else if (error) {
 		show_error_dialog (_("Could not obtain required privileges: %s."), error->message);
@@ -453,14 +480,17 @@
 
 static void
 add_connection (NMConnectionList *self,
-			 NMConnection *connection,
-			 ConnectionAddedFn callback,
-			 gpointer user_data)
+                NMConnectionEditor *editor,
+                NMConnection *connection,
+                ConnectionAddedFn callback,
+                gpointer user_data)
 {
 	NMExportedConnection *exported = NULL;
-	gboolean success;
+	NMConnectionScope scope;
+	gboolean success = FALSE;
 
-	if (nm_connection_get_scope (connection) == NM_CONNECTION_SCOPE_SYSTEM) {
+	scope = nm_connection_get_scope (connection);
+	if (scope == NM_CONNECTION_SCOPE_SYSTEM) {
 		GError *error = NULL;
 
 		success = nm_dbus_settings_system_add_connection (self->system_settings, connection, &error);
@@ -491,10 +521,13 @@
 				return;
 
 		}
-	} else {
+	} else if (scope == NM_CONNECTION_SCOPE_USER) {
 		exported = (NMExportedConnection *) nma_gconf_settings_add_connection (self->gconf_settings, connection);
 		success = exported != NULL;
-	}
+		if (success && editor)
+			nm_connection_editor_save_vpn_secrets (editor);
+	} else
+		g_warning ("%s: unhandled connection scope %d!", __func__, scope);
 
 	if (callback)
 		callback (exported, success, user_data);
@@ -521,10 +554,11 @@
 } ConnectionUpdateInfo;
 
 static void update_connection (NMConnectionList *list,
-						 NMExportedConnection *original,
-						 NMConnection *modified,
-						 ConnectionUpdatedFn callback,
-						 gpointer user_data);
+                               NMConnectionEditor *editor,
+                               NMExportedConnection *original,
+                               NMConnection *modified,
+                               ConnectionUpdatedFn callback,
+                               gpointer user_data);
 
 
 static void
@@ -587,7 +621,7 @@
 	gboolean done = TRUE;
 
 	if (gained_privilege) {
-		update_connection (info->list, info->original, info->modified, info->callback, info->user_data);
+		update_connection (info->list, NULL, info->original, info->modified, info->callback, info->user_data);
 		done = FALSE;
 	} else if (error) {
 		show_error_dialog (_("Could not obtain required privileges: %s."), error->message);
@@ -606,10 +640,11 @@
 
 static void
 update_connection (NMConnectionList *list,
-			    NMExportedConnection *original,
-			    NMConnection *modified,
-			    ConnectionUpdatedFn callback,
-			    gpointer user_data)
+                   NMConnectionEditor *editor,
+                   NMExportedConnection *original,
+                   NMConnection *modified,
+                   ConnectionUpdatedFn callback,
+                   gpointer user_data)
 {
 	NMConnectionScope original_scope;
 	ConnectionUpdateInfo *info;
@@ -640,6 +675,10 @@
 				show_error_dialog (_("Updating connection failed: %s."), error->message);
 
 			g_error_free (error);
+		} else {
+			/* Save user-connection vpn secrets */
+			if (editor && (original_scope == NM_CONNECTION_SCOPE_USER))
+				nm_connection_editor_save_vpn_secrets (editor);
 		}
 
 		if (!pending_auth)
@@ -648,7 +687,7 @@
 		/* The hard part: Connection scope changed:
 		   Add the exported connection,
 		   if it succeeds, remove the old one. */
-		add_connection (list, modified, connection_update_add_done, info);
+		add_connection (list, editor, modified, connection_update_add_done, info);
 	}
 }
 
@@ -660,7 +699,7 @@
 
 	connection = nm_connection_editor_get_connection (editor);
 	if (response == GTK_RESPONSE_OK)
-		add_connection (info->list, connection, NULL, NULL);
+		add_connection (info->list, editor, connection, NULL, NULL);
 
 	g_hash_table_remove (info->list->editors, connection);
 }
@@ -932,10 +971,8 @@
 		utils_clear_filled_connection_certs (connection);
 
 		if (success) {
-			update_connection (info->list, info->original_connection,
-						    connection,
-						    connection_updated_cb,
-						    info);
+			update_connection (info->list, editor, info->original_connection,
+			                   connection, connection_updated_cb, info);
 		} else {
 			g_warning ("%s: invalid connection after update: bug in the "
 			           "'%s' / '%s' invalid: %d",

Modified: trunk/src/connection-editor/page-vpn.c
==============================================================================
--- trunk/src/connection-editor/page-vpn.c	(original)
+++ trunk/src/connection-editor/page-vpn.c	Tue Sep  9 20:52:18 2008
@@ -102,6 +102,25 @@
 	return self;
 }
 
+gboolean
+ce_page_vpn_save_secrets (CEPage *page, NMConnection *connection)
+{
+	CEPageVpn *self = CE_PAGE_VPN (page);
+	CEPageVpnPrivate *priv = CE_PAGE_VPN_GET_PRIVATE (self);
+	GError *error = NULL;
+	gboolean success = FALSE;
+
+	success = nm_vpn_plugin_ui_widget_interface_save_secrets (priv->ui, connection, &error);
+	if (!success) {
+		g_warning ("%s: couldn't save VPN secrets: (%d) %s", __func__,
+		           error ? error->code : -1, error ? error->message : "unknown");
+		if (error)
+			g_error_free (error);
+	}
+
+	return success;
+}
+
 static gboolean
 validate (CEPage *page, NMConnection *connection, GError **error)
 {

Modified: trunk/src/connection-editor/page-vpn.h
==============================================================================
--- trunk/src/connection-editor/page-vpn.h	(original)
+++ trunk/src/connection-editor/page-vpn.h	Tue Sep  9 20:52:18 2008
@@ -49,4 +49,6 @@
 
 CEPageVpn *ce_page_vpn_new (NMConnection *connection);
 
+gboolean ce_page_vpn_save_secrets (CEPage *page, NMConnection *connection);
+
 #endif  /* __PAGE_VPN_H__ */



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