[network-manager-applet/rm-userset] applet: add applet secret agent skeleton



commit 6e8ab19ac6c85a06db8620ad5f37dad4a82484ad
Author: Dan Williams <dcbw redhat com>
Date:   Thu Jan 13 21:52:20 2011 -0600

    applet: add applet secret agent skeleton

 src/Makefile.am         |   14 +++--
 src/applet-agent.c      |  123 +++++++++++++++++++++++++++++++++++++++++++++++
 src/applet-agent.h      |   48 ++++++++++++++++++
 src/applet-device-gsm.c |    2 +-
 src/applet.c            |   15 ++++--
 src/applet.h            |    4 +-
 6 files changed, 191 insertions(+), 15 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2c5e7e8..5c8e043 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,12 +21,14 @@ nm_applet_CPPFLAGS = \
 	-I${top_srcdir}/src/gconf-helpers  \
 	-I${top_srcdir}/src/wireless-security
 
-nm_applet_SOURCES =			\
-	main.c				\
-	applet.c				\
-	applet.h				\
-	vpn-password-dialog.c	\
-	vpn-password-dialog.h	\
+nm_applet_SOURCES = \
+	main.c \
+	applet.c \
+	applet.h \
+	applet-agent.c \
+	applet-agent.h \
+	vpn-password-dialog.c \
+	vpn-password-dialog.h \
 	wired-dialog.h \
 	wired-dialog.c \
 	wireless-dialog.h \
diff --git a/src/applet-agent.c b/src/applet-agent.c
new file mode 100644
index 0000000..c95d220
--- /dev/null
+++ b/src/applet-agent.c
@@ -0,0 +1,123 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * Dan Williams <dcbw redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2011 Red Hat, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n.h>
+#include <string.h>
+
+#include "applet-agent.h"
+
+G_DEFINE_TYPE (AppletAgent, applet_agent, NM_TYPE_SECRET_AGENT);
+
+#define APPLET_AGENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), APPLET_TYPE_AGENT, AppletAgentPrivate))
+
+typedef struct {
+
+
+	gboolean disposed;
+} AppletAgentPrivate;
+
+/*******************************************************/
+
+static void
+get_secrets (NMSecretAgent *agent,
+             NMConnection *connection,
+             const char *connection_path,
+             const char *setting_name,
+             const char **hints,
+             gboolean request_new,
+             NMSecretAgentGetSecretsFunc callback,
+             gpointer callback_data)
+{
+}
+
+static void
+cancel_get_secrets (NMSecretAgent *agent,
+                    const char *connection_path,
+                    const char *setting_name)
+{
+}
+
+static void
+save_secrets (NMSecretAgent *agent,
+              NMConnection *connection,
+              const char *connection_path,
+              NMSecretAgentSaveSecretsFunc callback,
+              gpointer callback_data)
+{
+}
+
+static void
+delete_secrets (NMSecretAgent *agent,
+                NMConnection *connection,
+                const char *connection_path,
+                NMSecretAgentDeleteSecretsFunc callback,
+                gpointer callback_data)
+{
+}
+
+/*******************************************************/
+
+AppletAgent *
+applet_agent_new (void)
+{
+	return (AppletAgent *) g_object_new (APPLET_TYPE_AGENT,
+	                                     NM_SECRET_AGENT_IDENTIFIER, "org.freedesktop.nm-applet",
+	                                     NULL);
+}
+
+static void
+applet_agent_init (AppletAgent *self)
+{
+}
+
+static void
+dispose (GObject *object)
+{
+	AppletAgent *self = APPLET_AGENT (object);
+	AppletAgentPrivate *priv = APPLET_AGENT_GET_PRIVATE (self);
+
+	if (!priv->disposed) {
+		priv->disposed = TRUE;
+	}
+
+	G_OBJECT_CLASS (applet_agent_parent_class)->dispose (object);
+}
+
+static void
+applet_agent_class_init (AppletAgentClass *agent_class)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (agent_class);
+	NMSecretAgentClass *parent_class = NM_SECRET_AGENT_CLASS (agent_class);
+
+	g_type_class_add_private (agent_class, sizeof (AppletAgentPrivate));
+
+	/* virtual methods */
+	object_class->dispose = dispose;
+	parent_class->get_secrets = get_secrets;
+	parent_class->cancel_get_secrets = cancel_get_secrets;
+	parent_class->save_secrets = save_secrets;
+	parent_class->delete_secrets = delete_secrets;
+}
+
diff --git a/src/applet-agent.h b/src/applet-agent.h
new file mode 100644
index 0000000..5b29417
--- /dev/null
+++ b/src/applet-agent.h
@@ -0,0 +1,48 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * Dan Williams <dcbw redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2011 Red Hat, Inc.
+ */
+
+#ifndef _APPLET_AGENT_H_
+#define _APPLET_AGENT_H_
+
+#include <nm-secret-agent.h>
+
+#define APPLET_TYPE_AGENT            (applet_agent_get_type ())
+#define APPLET_AGENT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), APPLET_TYPE_AGENT, AppletAgent))
+#define APPLET_AGENT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), APPLET_TYPE_AGENT, AppletAgentClass))
+#define APPLET_IS_AGENT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), APPLET_TYPE_AGENT))
+#define APPLET_IS_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APPLET_TYPE_AGENT))
+#define APPLET_AGENT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), APPLET_TYPE_AGENT, AppletAgentClass))
+
+typedef struct {
+	NMSecretAgent parent;
+} AppletAgent;
+
+typedef struct {
+	NMSecretAgentClass parent_class;
+} AppletAgentClass;
+
+
+GType applet_agent_get_type (void) G_GNUC_CONST;
+
+AppletAgent *applet_agent_new (void);
+
+#endif /* _APPLET_AGENT_H_ */
+
diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index f1ecd95..33b4746 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -642,7 +642,7 @@ get_gsm_secrets_cb (GtkDialog *dialog,
 	}
 
 	/* Get existing connection secrets since NM will want those too */
-	nm_secret_agent_get_secrets (info->applet->agent,
+	nm_secret_agent_get_secrets (NM_SECRET_AGENT (info->applet->agent),
 	                             NM_CONNECTION (info->connection),
 	                             NM_SETTING_GSM_SETTING_NAME,
 	                             (const char **) &hints,
diff --git a/src/applet.c b/src/applet.c
index eb5ee6f..20fe9f2 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -55,6 +55,7 @@
 #include <nm-setting-vpn.h>
 #include <nm-active-connection.h>
 #include <nm-setting-wireless.h>
+#include <nm-secret-agent.h>
 
 #include <gconf/gconf-client.h>
 #include <gnome-keyring.h>
@@ -2923,6 +2924,9 @@ constructor (GType type,
 
 	applet->settings = nm_remote_settings_new (applet->bus);
 
+	applet->agent = applet_agent_new ();
+	g_assert (applet->agent);
+
 	/* Initialize device classes */
 	applet->wired_class = applet_device_wired_get_class (applet);
 	g_assert (applet->wired_class);
@@ -3002,15 +3006,14 @@ static void finalize (GObject *object)
 	if (applet->fallback_icon)
 		g_object_unref (applet->fallback_icon);
 
-	if (applet->settings) {
+	if (applet->agent)
+		g_object_unref (applet->agent);
+
+	if (applet->settings)
 		g_object_unref (applet->settings);
-		applet->settings = NULL;
-	}
 
-	if (applet->bus) {
+	if (applet->bus)
 		dbus_g_connection_unref (applet->bus);
-		applet->bus = NULL;
-	}
 
 	G_OBJECT_CLASS (nma_parent_class)->finalize (object);
 }
diff --git a/src/applet.h b/src/applet.h
index 3da04ca..87c762e 100644
--- a/src/applet.h
+++ b/src/applet.h
@@ -45,7 +45,7 @@
 #include <NetworkManager.h>
 #include <nm-active-connection.h>
 #include <nm-remote-settings.h>
-#include <nm-secret-agent.h>
+#include "applet-agent.h"
 
 #define NM_TYPE_APPLET			(nma_get_type())
 #define NM_APPLET(object)		(G_TYPE_CHECK_INSTANCE_CAST((object), NM_TYPE_APPLET, NMApplet))
@@ -84,7 +84,7 @@ typedef struct
 
 	NMClient *nm_client;
 	NMRemoteSettings *settings;
-	NMSecretAgent *agent;
+	AppletAgent *agent;
 
 	GConfClient *	gconf_client;
 	char	*		ui_file;



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