[network-manager-applet/applet-shell] applet: only handle VPN secrets with GNOME Shell < 3.4



commit 43c61d4d04398244fb76bf020727919f78e4101f
Author: Dan Williams <dcbw redhat com>
Date:   Thu Aug 2 21:19:05 2012 -0500

    applet: only handle VPN secrets with GNOME Shell < 3.4
    
    GNOME Shell 3.2 and lower don't handle VPN secrets, so the applet
    still needs to do that.  But they do handle other secrets, so instead
    of having the applet and the Shell fight over who gets to handle
    secrets, defer non-VPN secrets to the Shell.

 src/applet-agent.c |   20 ++++++++++++++++++++
 src/applet-agent.h |    2 ++
 src/applet.c       |   27 ++++++++++++++++++---------
 3 files changed, 40 insertions(+), 9 deletions(-)
---
diff --git a/src/applet-agent.c b/src/applet-agent.c
index 7957f26..8952683 100644
--- a/src/applet-agent.c
+++ b/src/applet-agent.c
@@ -45,6 +45,7 @@ G_DEFINE_TYPE (AppletAgent, applet_agent, NM_TYPE_SECRET_AGENT);
 
 typedef struct {
 	GHashTable *requests;
+	gboolean vpn_only;
 
 	gboolean disposed;
 } AppletAgentPrivate;
@@ -487,6 +488,16 @@ get_secrets (NMSecretAgent *agent,
 		return;
 	}
 
+	/* Only handle non-VPN secrets if we're supposed to */
+	if (priv->vpn_only == TRUE) {
+		error = g_error_new_literal (NM_SECRET_AGENT_ERROR,
+		                             NM_SECRET_AGENT_ERROR_NO_SECRETS,
+		                             "Only handling VPN secrets at this time.");
+		callback (agent, connection, NULL, error, callback_data);
+		g_error_free (error);
+		return;
+	}
+
 	/* For everything else we scrape the keyring for secrets first, and ask
 	 * later if required.
 	 */
@@ -782,6 +793,15 @@ delete_secrets (NMSecretAgent *agent,
 	r->keyring_calls = g_slist_append (r->keyring_calls, call);
 }
 
+void
+applet_agent_handle_vpn_only (AppletAgent *agent, gboolean vpn_only)
+{
+	g_return_if_fail (agent != NULL);
+	g_return_if_fail (APPLET_IS_AGENT (agent));
+
+	APPLET_AGENT_GET_PRIVATE (agent)->vpn_only = vpn_only;
+}
+
 /*******************************************************/
 
 AppletAgent *
diff --git a/src/applet-agent.h b/src/applet-agent.h
index 6e8af97..2e1be3e 100644
--- a/src/applet-agent.h
+++ b/src/applet-agent.h
@@ -64,5 +64,7 @@ GType applet_agent_get_type (void) G_GNUC_CONST;
 
 AppletAgent *applet_agent_new (void);
 
+void applet_agent_handle_vpn_only (AppletAgent *agent, gboolean vpn_only);
+
 #endif /* _APPLET_AGENT_H_ */
 
diff --git a/src/applet.c b/src/applet.c
index 50c80bc..dc4cbad 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -3255,23 +3255,32 @@ shell_version_changed_cb (NMShellWatcher *watcher, GParamSpec *pspec, gpointer u
 {
 	NMApplet *applet = user_data;
 
-	if (nm_shell_watcher_version_at_least (watcher, 3, 4)) {
-		if (applet->agent_start_id)
-			g_source_remove (applet->agent_start_id);
+	if (applet->agent_start_id) {
+		g_source_remove (applet->agent_start_id);
+		applet->agent_start_id = 0;
+	}
 
-		if (applet->agent && nm_secret_agent_get_registered (NM_SECRET_AGENT (applet->agent))) {
+	if (!applet->agent)
+		return;
+
+	if (nm_shell_watcher_version_at_least (watcher, 3, 4)) {
+		/* GNOME Shell handles all secrets requests */
+		if (nm_secret_agent_get_registered (NM_SECRET_AGENT (applet->agent))) {
 			g_message ("Stopping applet secret agent because GNOME Shell appeared");
 			nm_secret_agent_unregister (NM_SECRET_AGENT (applet->agent));
 		}
+	} else if (nm_shell_watcher_version_at_least (watcher, 3, 2)) {
+		/* GNOME Shell handles everything except VPN secrets requests */
+		if (nm_secret_agent_get_registered (NM_SECRET_AGENT (applet->agent)))
+			g_message ("Applet secret agent handling only VPN secrets because GNOME Shell appeared");
+		applet_agent_handle_vpn_only (applet->agent, TRUE);
 	} else {
 		/* If the shell quit and our agent wasn't already registered, do it
-		 * now on a delay (just in case the shell is restarting.
+		 * now on a delay (just in case the shell is restarting).
 		 */
-		if (applet->agent_start_id)
-			g_source_remove (applet->agent_start_id);
-
-		if (nm_secret_agent_get_registered (NM_SECRET_AGENT (applet->agent)) == FALSE)
+		if (!nm_secret_agent_get_registered (NM_SECRET_AGENT (applet->agent)))
 			applet->agent_start_id = g_timeout_add_seconds (4, delayed_start_agent, applet);
+		applet_agent_handle_vpn_only (applet->agent, FALSE);
 	}
 }
 #endif



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