network-manager-applet r733 - in trunk: . src



Author: dcbw
Date: Wed May 28 21:35:31 2008
New Revision: 733
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=733&view=rev

Log:
2008-05-28  Dan Williams  <dcbw redhat com>

	* src/wireless-dialog.c
	  src/wireless-dialog.h
	  src/applet.glade
		- Convert the wireless dialog into a subclass of GtkDialog
		- Add a "Connection" combo box and populate it with existing connections
			that apply to the operation being performed; it's populated with
			adhoc-create=True connections for "Create new...", populated with
			adhoc-create=False connections for "Connect to other...", and hidden
			when the applet is just asking for secrets.

	* src/applet-device-wireless.c
		- Handle new wireless dialog API



Modified:
   trunk/ChangeLog
   trunk/src/applet-device-wireless.c
   trunk/src/applet.glade
   trunk/src/wireless-dialog.c
   trunk/src/wireless-dialog.h

Modified: trunk/src/applet-device-wireless.c
==============================================================================
--- trunk/src/applet-device-wireless.c	(original)
+++ trunk/src/applet-device-wireless.c	Wed May 28 21:35:31 2008
@@ -59,12 +59,7 @@
 {
 	GtkWidget *dialog;
 
-	dialog = nma_wireless_dialog_new (applet->glade_file,
-	                                  applet->nm_client,
-	                                  NULL,
-	                                  NULL,
-	                                  NULL,
-	                                  FALSE);
+	dialog = nma_wireless_dialog_new_for_other (applet);
 	if (!dialog)
 		return;
 
@@ -72,7 +67,6 @@
 	                  G_CALLBACK (wireless_dialog_response_cb),
 	                  applet);
 
-	gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ALWAYS);
 	gtk_widget_realize (dialog);
 	gtk_window_present_with_time (GTK_WINDOW (dialog), gdk_x11_get_server_time (dialog->window));
 }
@@ -97,12 +91,7 @@
 {
 	GtkWidget *dialog;
 
-	dialog = nma_wireless_dialog_new (applet->glade_file,
-	                                  applet->nm_client,
-	                                  NULL,
-	                                  NULL,
-	                                  NULL,
-	                                  TRUE);
+	dialog = nma_wireless_dialog_new_for_create (applet);
 	if (!dialog)
 		return;
 
@@ -110,7 +99,6 @@
 	                  G_CALLBACK (wireless_dialog_response_cb),
 	                  applet);
 
-	gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ALWAYS);
 	gtk_widget_realize (dialog);
 	gtk_window_present_with_time (GTK_WINDOW (dialog), gdk_x11_get_server_time (dialog->window));
 }
@@ -1074,46 +1062,41 @@
 	return FALSE;
 }
 
-#define NAG_IGNORED_TAG "nag-ignored"
-
 static void
 nag_dialog_response_cb (GtkDialog *nag_dialog,
                         gint response,
                         gpointer user_data)
 {
-	GtkWidget *wireless_dialog = GTK_WIDGET (user_data);
+	NMAWirelessDialog *wireless_dialog = NMA_WIRELESS_DIALOG (user_data);
 
 	if (response == GTK_RESPONSE_NO) {  /* user opted not to correct the warning */
-		g_object_set_data (G_OBJECT (wireless_dialog),
-		                   NAG_IGNORED_TAG,
-		                   GUINT_TO_POINTER (TRUE));
+		nma_wireless_dialog_set_nag_ignored (wireless_dialog, TRUE);
 		g_idle_add (wireless_dialog_close, wireless_dialog);
 	}
 }
 
 static void
-wireless_dialog_response_cb (GtkDialog *dialog,
+wireless_dialog_response_cb (GtkDialog *foo,
                              gint response,
                              gpointer user_data)
 {
+	NMAWirelessDialog *dialog = NMA_WIRELESS_DIALOG (foo);
 	NMApplet *applet = NM_APPLET (user_data);
 	NMConnection *connection = NULL, *fuzzy_match = NULL;
 	NMDevice *device = NULL;
 	NMAccessPoint *ap = NULL;
 	NMAGConfConnection *gconf_connection;
-	gboolean ignored = FALSE;
 
 	if (response != GTK_RESPONSE_OK)
 		goto done;
 
-	ignored = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (dialog), NAG_IGNORED_TAG));
-	if (!ignored) {
+	if (!nma_wireless_dialog_get_nag_ignored (dialog)) {
 		GtkWidget *nag_dialog;
 
 		/* Nag the user about certificates or whatever.  Only destroy the dialog
 		 * if no nagging was done.
 		 */
-		nag_dialog = nma_wireless_dialog_nag_user (GTK_WIDGET (dialog));
+		nag_dialog = nma_wireless_dialog_nag_user (dialog);
 		if (nag_dialog) {
 			gtk_window_set_transient_for (GTK_WINDOW (nag_dialog), GTK_WINDOW (dialog));
 			g_signal_connect (nag_dialog, "response",
@@ -1123,7 +1106,7 @@
 		}
 	}
 
-	connection = nma_wireless_dialog_get_connection (GTK_WIDGET (dialog), &device, &ap);
+	connection = nma_wireless_dialog_get_connection (dialog, &device, &ap);
 	g_assert (connection);
 	g_assert (device);
 
@@ -1222,19 +1205,13 @@
 	WirelessMenuItemInfo *info = (WirelessMenuItemInfo *) user_data;
 	GtkWidget *dialog;
 
-	dialog = nma_wireless_dialog_new (applet->glade_file,
-	                                  applet->nm_client,
-	                                  g_object_ref (connection),
-	                                  device,
-	                                  info->ap,
-	                                  FALSE);
+	dialog = nma_wireless_dialog_new (applet, connection, device, info->ap);
 	g_return_if_fail (dialog != NULL);
 
 	g_signal_connect (dialog, "response",
 	                  G_CALLBACK (wireless_dialog_response_cb),
 	                  applet);
 
-	gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ALWAYS);
 	gtk_widget_realize (dialog);
 	gtk_window_present (GTK_WINDOW (dialog));
 }
@@ -1269,10 +1246,11 @@
 }
 
 static void
-get_secrets_dialog_response_cb (GtkDialog *dialog,
+get_secrets_dialog_response_cb (GtkDialog *foo,
                                 gint response,
                                 gpointer user_data)
 {
+	NMAWirelessDialog *dialog = NMA_WIRELESS_DIALOG (foo);
 	NMApplet *applet = NM_APPLET (user_data);
 	DBusGMethodInvocation *context;
 	NMAGConfConnection *gconf_connection;
@@ -1282,7 +1260,6 @@
 	GHashTable *settings = NULL;
 	const char *setting_name;
 	GError *error = NULL;
-	gboolean ignored;
 
 	context = g_object_get_data (G_OBJECT (dialog), "dbus-context");
 	setting_name = g_object_get_data (G_OBJECT (dialog), "setting-name");
@@ -1300,14 +1277,13 @@
 		goto done;
 	}
 
-	ignored = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (dialog), NAG_IGNORED_TAG));
-	if (!ignored) {
+	if (!nma_wireless_dialog_get_nag_ignored (dialog)) {
 		GtkWidget *widget;
 
 		/* Nag the user about certificates or whatever.  Only destroy the dialog
 		 * if no nagging was done.
 		 */
-		widget = nma_wireless_dialog_nag_user (GTK_WIDGET (dialog));
+		widget = nma_wireless_dialog_nag_user (dialog);
 		if (widget) {
 			gtk_window_set_transient_for (GTK_WINDOW (widget), GTK_WINDOW (dialog));
 			g_signal_connect (widget, "response",
@@ -1317,7 +1293,7 @@
 		}
 	}
 
-	connection = nma_wireless_dialog_get_connection (GTK_WIDGET (dialog), &device, NULL);
+	connection = nma_wireless_dialog_get_connection (dialog, &device, NULL);
 	if (!connection) {
 		g_set_error (&error, NM_SETTINGS_ERROR, 1,
 		             "%s.%d (%s): couldn't get connection from wireless dialog.",
@@ -1421,12 +1397,7 @@
 	ap = nm_device_802_11_wireless_get_access_point_by_path (NM_DEVICE_802_11_WIRELESS (device),
 	                                                         specific_object);
 
-	dialog = nma_wireless_dialog_new (applet->glade_file,
-	                                  applet->nm_client,
-	                                  g_object_ref (connection),
-	                                  device,
-	                                  ap,
-	                                  FALSE);
+	dialog = nma_wireless_dialog_new (applet, connection, device, ap);
 	if (!dialog) {
 		g_set_error (error, NM_SETTINGS_ERROR, 1,
 		             "%s.%d (%s): couldn't display secrets UI",
@@ -1443,7 +1414,6 @@
 	                  G_CALLBACK (get_secrets_dialog_response_cb),
 	                  applet);
 
-	gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ALWAYS);
 	gtk_widget_realize (dialog);
 	gtk_window_present (GTK_WINDOW (dialog));
 

Modified: trunk/src/applet.glade
==============================================================================
--- trunk/src/applet.glade	(original)
+++ trunk/src/applet.glade	Wed May 28 21:35:31 2008
@@ -52,11 +52,73 @@
 	      <property name="can_default">True</property>
 	      <property name="has_default">True</property>
 	      <property name="can_focus">True</property>
-	      <property name="label" translatable="yes">C_onnect</property>
-	      <property name="use_underline">True</property>
 	      <property name="relief">GTK_RELIEF_NORMAL</property>
 	      <property name="focus_on_click">True</property>
 	      <property name="response_id">-5</property>
+
+	      <child>
+		<widget class="GtkAlignment" id="alignment4">
+		  <property name="visible">True</property>
+		  <property name="xalign">0.5</property>
+		  <property name="yalign">0.5</property>
+		  <property name="xscale">0</property>
+		  <property name="yscale">0</property>
+		  <property name="top_padding">0</property>
+		  <property name="bottom_padding">0</property>
+		  <property name="left_padding">0</property>
+		  <property name="right_padding">0</property>
+
+		  <child>
+		    <widget class="GtkHBox" id="hbox6">
+		      <property name="visible">True</property>
+		      <property name="homogeneous">False</property>
+		      <property name="spacing">2</property>
+
+		      <child>
+			<widget class="GtkImage" id="image5">
+			  <property name="visible">True</property>
+			  <property name="stock">gtk-connect</property>
+			  <property name="icon_size">4</property>
+			  <property name="xalign">0.5</property>
+			  <property name="yalign">0.5</property>
+			  <property name="xpad">0</property>
+			  <property name="ypad">0</property>
+			</widget>
+			<packing>
+			  <property name="padding">0</property>
+			  <property name="expand">False</property>
+			  <property name="fill">False</property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkLabel" id="label67">
+			  <property name="visible">True</property>
+			  <property name="label" translatable="yes">C_onnect</property>
+			  <property name="use_underline">True</property>
+			  <property name="use_markup">False</property>
+			  <property name="justify">GTK_JUSTIFY_LEFT</property>
+			  <property name="wrap">False</property>
+			  <property name="selectable">False</property>
+			  <property name="xalign">0.5</property>
+			  <property name="yalign">0.5</property>
+			  <property name="xpad">0</property>
+			  <property name="ypad">0</property>
+			  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+			  <property name="width_chars">-1</property>
+			  <property name="single_line_mode">False</property>
+			  <property name="angle">0</property>
+			</widget>
+			<packing>
+			  <property name="padding">0</property>
+			  <property name="expand">False</property>
+			  <property name="fill">False</property>
+			</packing>
+		      </child>
+		    </widget>
+		  </child>
+		</widget>
+	      </child>
 	    </widget>
 	  </child>
 	</widget>
@@ -126,16 +188,35 @@
 	      <child>
 		<widget class="GtkTable" id="table1">
 		  <property name="visible">True</property>
-		  <property name="n_rows">4</property>
+		  <property name="n_rows">5</property>
 		  <property name="n_columns">2</property>
 		  <property name="homogeneous">False</property>
 		  <property name="row_spacing">6</property>
 		  <property name="column_spacing">12</property>
 
 		  <child>
-		    <widget class="GtkLabel" id="device_label">
+		    <widget class="GtkVBox" id="security_vbox">
 		      <property name="visible">True</property>
-		      <property name="label" translatable="yes">Wireless _adapter:</property>
+		      <property name="homogeneous">False</property>
+		      <property name="spacing">0</property>
+
+		      <child>
+			<placeholder/>
+		      </child>
+		    </widget>
+		    <packing>
+		      <property name="left_attach">0</property>
+		      <property name="right_attach">2</property>
+		      <property name="top_attach">4</property>
+		      <property name="bottom_attach">5</property>
+		      <property name="x_options">fill</property>
+		    </packing>
+		  </child>
+
+		  <child>
+		    <widget class="GtkLabel" id="security_combo_label">
+		      <property name="visible">True</property>
+		      <property name="label" translatable="yes">_Wireless Security:</property>
 		      <property name="use_underline">True</property>
 		      <property name="use_markup">False</property>
 		      <property name="justify">GTK_JUSTIFY_LEFT</property>
@@ -145,7 +226,6 @@
 		      <property name="yalign">0.5</property>
 		      <property name="xpad">0</property>
 		      <property name="ypad">0</property>
-		      <property name="mnemonic_widget">device_combo</property>
 		      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
 		      <property name="width_chars">-1</property>
 		      <property name="single_line_mode">False</property>
@@ -154,14 +234,31 @@
 		    <packing>
 		      <property name="left_attach">0</property>
 		      <property name="right_attach">1</property>
-		      <property name="top_attach">0</property>
-		      <property name="bottom_attach">1</property>
+		      <property name="top_attach">3</property>
+		      <property name="bottom_attach">4</property>
 		      <property name="x_options">fill</property>
 		      <property name="y_options"></property>
 		    </packing>
 		  </child>
 
 		  <child>
+		    <widget class="GtkComboBox" id="security_combo">
+		      <property name="visible">True</property>
+		      <property name="items" translatable="yes"> </property>
+		      <property name="add_tearoffs">False</property>
+		      <property name="focus_on_click">True</property>
+		    </widget>
+		    <packing>
+		      <property name="left_attach">1</property>
+		      <property name="right_attach">2</property>
+		      <property name="top_attach">3</property>
+		      <property name="bottom_attach">4</property>
+		      <property name="x_options">fill</property>
+		      <property name="y_options">fill</property>
+		    </packing>
+		  </child>
+
+		  <child>
 		    <widget class="GtkLabel" id="network_name_label">
 		      <property name="visible">True</property>
 		      <property name="label" translatable="yes">_Network Name:</property>
@@ -183,8 +280,8 @@
 		    <packing>
 		      <property name="left_attach">0</property>
 		      <property name="right_attach">1</property>
-		      <property name="top_attach">1</property>
-		      <property name="bottom_attach">2</property>
+		      <property name="top_attach">2</property>
+		      <property name="bottom_attach">3</property>
 		      <property name="x_options">fill</property>
 		      <property name="y_options"></property>
 		    </packing>
@@ -204,14 +301,42 @@
 		    <packing>
 		      <property name="left_attach">1</property>
 		      <property name="right_attach">2</property>
+		      <property name="top_attach">2</property>
+		      <property name="bottom_attach">3</property>
+		      <property name="y_options"></property>
+		    </packing>
+		  </child>
+
+		  <child>
+		    <widget class="GtkLabel" id="connection_label">
+		      <property name="visible">True</property>
+		      <property name="label" translatable="yes">Connection:</property>
+		      <property name="use_underline">False</property>
+		      <property name="use_markup">False</property>
+		      <property name="justify">GTK_JUSTIFY_LEFT</property>
+		      <property name="wrap">False</property>
+		      <property name="selectable">False</property>
+		      <property name="xalign">0</property>
+		      <property name="yalign">0.5</property>
+		      <property name="xpad">0</property>
+		      <property name="ypad">0</property>
+		      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+		      <property name="width_chars">-1</property>
+		      <property name="single_line_mode">False</property>
+		      <property name="angle">0</property>
+		    </widget>
+		    <packing>
+		      <property name="left_attach">0</property>
+		      <property name="right_attach">1</property>
 		      <property name="top_attach">1</property>
 		      <property name="bottom_attach">2</property>
+		      <property name="x_options">fill</property>
 		      <property name="y_options"></property>
 		    </packing>
 		  </child>
 
 		  <child>
-		    <widget class="GtkComboBox" id="device_combo">
+		    <widget class="GtkComboBox" id="connection_combo">
 		      <property name="visible">True</property>
 		      <property name="items" translatable="yes"></property>
 		      <property name="add_tearoffs">False</property>
@@ -220,16 +345,17 @@
 		    <packing>
 		      <property name="left_attach">1</property>
 		      <property name="right_attach">2</property>
-		      <property name="top_attach">0</property>
-		      <property name="bottom_attach">1</property>
+		      <property name="top_attach">1</property>
+		      <property name="bottom_attach">2</property>
+		      <property name="x_options">fill</property>
 		      <property name="y_options">fill</property>
 		    </packing>
 		  </child>
 
 		  <child>
-		    <widget class="GtkLabel" id="security_combo_label">
+		    <widget class="GtkLabel" id="device_label">
 		      <property name="visible">True</property>
-		      <property name="label" translatable="yes">_Wireless Security:</property>
+		      <property name="label" translatable="yes">Wireless _adapter:</property>
 		      <property name="use_underline">True</property>
 		      <property name="use_markup">False</property>
 		      <property name="justify">GTK_JUSTIFY_LEFT</property>
@@ -239,6 +365,7 @@
 		      <property name="yalign">0.5</property>
 		      <property name="xpad">0</property>
 		      <property name="ypad">0</property>
+		      <property name="mnemonic_widget">device_combo</property>
 		      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
 		      <property name="width_chars">-1</property>
 		      <property name="single_line_mode">False</property>
@@ -247,15 +374,15 @@
 		    <packing>
 		      <property name="left_attach">0</property>
 		      <property name="right_attach">1</property>
-		      <property name="top_attach">2</property>
-		      <property name="bottom_attach">3</property>
+		      <property name="top_attach">0</property>
+		      <property name="bottom_attach">1</property>
 		      <property name="x_options">fill</property>
 		      <property name="y_options"></property>
 		    </packing>
 		  </child>
 
 		  <child>
-		    <widget class="GtkComboBox" id="security_combo">
+		    <widget class="GtkComboBox" id="device_combo">
 		      <property name="visible">True</property>
 		      <property name="items" translatable="yes"> </property>
 		      <property name="add_tearoffs">False</property>
@@ -264,31 +391,12 @@
 		    <packing>
 		      <property name="left_attach">1</property>
 		      <property name="right_attach">2</property>
-		      <property name="top_attach">2</property>
-		      <property name="bottom_attach">3</property>
+		      <property name="top_attach">0</property>
+		      <property name="bottom_attach">1</property>
 		      <property name="x_options">fill</property>
 		      <property name="y_options">fill</property>
 		    </packing>
 		  </child>
-
-		  <child>
-		    <widget class="GtkVBox" id="security_vbox">
-		      <property name="visible">True</property>
-		      <property name="homogeneous">False</property>
-		      <property name="spacing">0</property>
-
-		      <child>
-			<placeholder/>
-		      </child>
-		    </widget>
-		    <packing>
-		      <property name="left_attach">0</property>
-		      <property name="right_attach">2</property>
-		      <property name="top_attach">3</property>
-		      <property name="bottom_attach">4</property>
-		      <property name="x_options">fill</property>
-		    </packing>
-		  </child>
 		</widget>
 		<packing>
 		  <property name="padding">0</property>

Modified: trunk/src/wireless-dialog.c
==============================================================================
--- trunk/src/wireless-dialog.c	(original)
+++ trunk/src/wireless-dialog.c	Wed May 28 21:35:31 2008
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * (C) Copyright 2007 Red Hat, Inc.
+ * (C) Copyright 2007 - 2008 Red Hat, Inc.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -29,6 +29,7 @@
 #include <gtk/gtk.h>
 #include <gtk/gtkcontainer.h>
 #include <glade/glade.h>
+#include <netinet/ether.h>
 
 #include <nm-client.h>
 #include <nm-utils.h>
@@ -43,7 +44,32 @@
 #include "utils.h"
 #include "gconf-helpers.h"
 
-#define NEW_ADHOC_TAG "user-created-adhoc"
+G_DEFINE_TYPE (NMAWirelessDialog, nma_wireless_dialog, GTK_TYPE_DIALOG)
+
+#define NMA_WIRELESS_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+                                            NMA_TYPE_WIRELESS_DIALOG, \
+                                            NMAWirelessDialogPrivate))
+
+typedef struct {
+	NMApplet *applet;
+
+	char *glade_file;
+	GladeXML *xml;
+
+	NMConnection *connection;
+	NMDevice *device;
+	NMAccessPoint *ap;
+	gboolean adhoc_create;
+
+	GtkTreeModel *device_model;
+	GtkTreeModel *connection_model;
+	GtkSizeGroup *group;
+	GtkWidget *sec_combo;
+
+	gboolean nag_ignored;
+
+	gboolean disposed;
+} NMAWirelessDialogPrivate;
 
 #define D_NAME_COLUMN		0
 #define D_DEV_COLUMN		1
@@ -51,50 +77,47 @@
 #define S_NAME_COLUMN		0
 #define S_SEC_COLUMN		1
 
+#define C_NAME_COLUMN		0
+#define C_CON_COLUMN		1
+#define C_SEP_COLUMN		2
+#define C_NEW_COLUMN		3
+
 static void security_combo_changed (GtkWidget *combo, gpointer user_data);
-static gboolean security_combo_init (const char *glade_file,
-                                     GtkWidget *combo,
-                                     NMDevice *device,
-                                     GtkWidget *dialog,
-                                     NMConnection *connection,
-                                     gboolean user_created_adhoc);
+static gboolean security_combo_init (NMAWirelessDialog *self);
 
-static void
-device_combo_changed (GtkWidget *combo,
-                      gpointer user_data)
+void
+nma_wireless_dialog_set_nag_ignored (NMAWirelessDialog *self, gboolean ignored)
 {
-	GtkWidget *dialog = GTK_WIDGET (user_data);
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	NMDevice *device = NULL;
-	const char *glade_file;
-	GtkWidget *security_combo;
-	GladeXML *xml;
-	NMConnection *connection;
-	gboolean user_created_adhoc = FALSE;
+	g_return_if_fail (self != NULL);
 
-	model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
-	gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
-	gtk_tree_model_get (model, &iter, D_DEV_COLUMN, &device, -1);
-
-	glade_file = g_object_get_data (G_OBJECT (dialog), "glade-file");
-	g_assert (glade_file);
+	NMA_WIRELESS_DIALOG_GET_PRIVATE (self)->nag_ignored = ignored;
+}
 
-	xml = g_object_get_data (G_OBJECT (dialog), "glade-xml");
-	g_assert (xml);
+gboolean
+nma_wireless_dialog_get_nag_ignored (NMAWirelessDialog *self)
+{
+	g_return_val_if_fail (self != NULL, FALSE);
 
-	connection = g_object_get_data (G_OBJECT (dialog), "connection");
+	return NMA_WIRELESS_DIALOG_GET_PRIVATE (self)->nag_ignored;
+}
 
-	user_created_adhoc = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (dialog), NEW_ADHOC_TAG));
+static void
+model_free (GtkTreeModel *model, guint col)
+{
+	GtkTreeIter	iter;
 
-	security_combo = glade_xml_get_widget (xml, "security_combo");
-	g_assert (security_combo);
-	if (!security_combo_init (glade_file, security_combo, device, dialog, connection, user_created_adhoc)) {
-		g_message ("Couldn't change wireless security combo box.");
+	if (!model)
 		return;
-	}
 
-	security_combo_changed (security_combo, dialog);
+	if (gtk_tree_model_get_iter_first (model, &iter)) {
+		do {
+			char *str;
+
+			gtk_tree_model_get (model, &iter, col, &str, -1);
+			g_free (str);
+		} while (gtk_tree_model_iter_next (model, &iter));
+	}
+	g_object_unref (model);
 }
 
 static void
@@ -133,24 +156,19 @@
 security_combo_changed (GtkWidget *combo,
                         gpointer user_data)
 {
-	GtkWidget *dialog = GTK_WIDGET (user_data);
-	GladeXML *xml;
+	NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
+	NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
 	GtkWidget *vbox;
 	GList *elt, *children;
 	GtkTreeIter iter;
 	GtkTreeModel *model;
 	WirelessSecurity *sec = NULL;
-	GtkSizeGroup *group;
+	GtkWidget *sec_widget;
 
-	xml = g_object_get_data (G_OBJECT (dialog), "glade-xml");
-	g_assert (xml);
-
-	vbox = glade_xml_get_widget (xml, "security_vbox");
+	vbox = glade_xml_get_widget (priv->xml, "security_vbox");
 	g_assert (vbox);
 
-	group = g_object_get_data (G_OBJECT (dialog), "size-group");
-	g_assert (group);
-	size_group_clear (group);
+	size_group_clear (priv->group);
 
 	/* Remove any previous wireless security widgets */
 	children = gtk_container_get_children (GTK_CONTAINER (vbox));
@@ -158,39 +176,38 @@
 		gtk_container_remove (GTK_CONTAINER (vbox), GTK_WIDGET (elt->data));
 
 	model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
-	if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) {
-		gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
-		if (sec) {
-			GtkWidget *sec_widget;
+	if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) {
+		g_warning ("%s: no active security combo box item.", __func__);
+		return;
+	}
+
+	gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
+	if (!sec)
+		return;
 
-			sec_widget = wireless_security_get_widget (sec);
-			g_assert (sec_widget);
+	sec_widget = wireless_security_get_widget (sec);
+	g_assert (sec_widget);
 
-			size_group_add_permanent (group, xml);
-			wireless_security_add_to_size_group (sec, group);
+	size_group_add_permanent (priv->group, priv->xml);
+	wireless_security_add_to_size_group (sec, priv->group);
 
-			gtk_container_add (GTK_CONTAINER (vbox), sec_widget);
-			wireless_security_unref (sec);
+	gtk_container_add (GTK_CONTAINER (vbox), sec_widget);
+	wireless_security_unref (sec);
 
-			/* Re-validate */
-			wireless_security_changed_cb (NULL, sec);
-		}
-	} else {
-		g_warning ("%s: no active security combo box item.", __func__);
-	}
+	/* Re-validate */
+	wireless_security_changed_cb (NULL, sec);
 }
 
 static GByteArray *
-validate_dialog_ssid (GtkWidget *dialog)
+validate_dialog_ssid (NMAWirelessDialog *self)
 {
-	GladeXML *xml;
+	NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
 	GtkWidget *widget;
 	const char *ssid;
 	guint32 ssid_len;
 	GByteArray *ssid_ba;
 
-	xml = g_object_get_data (G_OBJECT (dialog), "glade-xml");
-	widget = glade_xml_get_widget (xml, "network_name_entry");
+	widget = glade_xml_get_widget (priv->xml, "network_name_entry");
 
 	ssid = gtk_entry_get_text (GTK_ENTRY (widget));
 	ssid_len = strlen (ssid);
@@ -207,26 +224,20 @@
 static void
 stuff_changed_cb (WirelessSecurity *sec, gpointer user_data)
 {
-	GtkWidget *dialog = GTK_WIDGET (user_data);
-	GladeXML *xml;
-	GtkWidget *widget;
+	NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
+	NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
 	GByteArray *ssid = NULL;
 	gboolean free_ssid = TRUE;
 	gboolean valid = FALSE;
-	NMConnection *connection;
 	
-	xml = g_object_get_data (G_OBJECT (dialog), "glade-xml");
-	g_assert (xml);
-
-	connection = g_object_get_data (G_OBJECT (dialog), "connection");
-	if (connection) {
+	if (priv->connection) {
 		NMSettingWireless *s_wireless;
-		s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
+		s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS));
 		g_assert (s_wireless);
 		ssid = s_wireless->ssid;
 		free_ssid = FALSE;
 	} else {
-		ssid = validate_dialog_ssid (dialog);
+		ssid = validate_dialog_ssid (self);
 	}
 
 	if (ssid) {
@@ -235,33 +246,26 @@
 			g_byte_array_free (ssid, TRUE);
 	}
 
-	widget = glade_xml_get_widget (xml, "ok_button");
-	gtk_widget_set_sensitive (widget, valid);
+	gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, valid);
 }
 
 static void
 ssid_entry_changed (GtkWidget *entry, gpointer user_data)
 {
-	GtkWidget *dialog = GTK_WIDGET (user_data);
+	NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
+	NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
 	GtkTreeIter iter;
 	WirelessSecurity *sec = NULL;
-	GladeXML *xml;
-	GtkWidget *combo;
 	GtkTreeModel *model;
 	gboolean valid = FALSE;
 	GByteArray *ssid;
-	GtkWidget *widget;
 
-	xml = g_object_get_data (G_OBJECT (dialog), "glade-xml");
-	g_assert (xml);
-
-	ssid = validate_dialog_ssid (dialog);
+	ssid = validate_dialog_ssid (self);
 	if (!ssid)
 		goto out;
 
-	combo = glade_xml_get_widget (xml, "security_combo");
-	model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
-	if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
+	model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->sec_combo));
+	if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->sec_combo), &iter))
 		gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
 
 	if (sec) {
@@ -272,83 +276,335 @@
 	}
 
 out:
-	widget = glade_xml_get_widget (xml, "ok_button");
-	gtk_widget_set_sensitive (widget, valid);
+	gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, valid);
 }
 
 static void
-add_device_to_model (GtkListStore *model,
-                     GtkTreeIter *iter,
-                     NMDevice *device)
+connection_combo_changed (GtkWidget *combo,
+                          gpointer user_data)
 {
-	char *desc;
+	NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
+	NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+	GtkTreeIter iter;
+	GtkTreeModel *model;
+	gboolean is_new = FALSE;
+	NMSettingWireless *s_wireless;
+	char *utf8_ssid;
+	GtkWidget *widget;
 
-	desc = (char *) utils_get_device_description (device);
-	if (!desc)
-		desc = (char *) nm_device_get_iface (device);
-	g_assert (desc);
+	gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
+	model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
 
-	gtk_list_store_append (model, iter);
-	gtk_list_store_set (model, iter, D_NAME_COLUMN, g_strdup (desc), D_DEV_COLUMN, device, -1);
+	if (priv->connection)
+		g_object_unref (priv->connection);
+
+	gtk_tree_model_get (model, &iter,
+	                    C_CON_COLUMN, &priv->connection,
+	                    C_NEW_COLUMN, &is_new, -1);
+
+	if (!security_combo_init (self)) {
+		g_warning ("Couldn't change wireless security combo box.");
+		return;
+	}
+	security_combo_changed (priv->sec_combo, self);
+
+	widget = glade_xml_get_widget (priv->xml, "network_name_entry");
+	if (priv->connection) {
+		s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS));
+		utf8_ssid = nm_utils_ssid_to_utf8 ((const char *) s_wireless->ssid->data, s_wireless->ssid->len);
+		gtk_entry_set_text (GTK_ENTRY (widget), utf8_ssid);
+		g_free (utf8_ssid);
+	} else {
+		gtk_entry_set_text (GTK_ENTRY (widget), "");
+	}
+
+	gtk_widget_set_sensitive (glade_xml_get_widget (priv->xml, "network_name_entry"), is_new);
+	gtk_widget_set_sensitive (glade_xml_get_widget (priv->xml, "network_name_label"), is_new);
+	gtk_widget_set_sensitive (glade_xml_get_widget (priv->xml, "security_combo"), is_new);
+	gtk_widget_set_sensitive (glade_xml_get_widget (priv->xml, "security_combo_label"), is_new);
+	gtk_widget_set_sensitive (glade_xml_get_widget (priv->xml, "security_vbox"), is_new);
 }
 
-static GtkTreeModel *
-create_device_model (NMClient *client, NMDevice *use_this_device, guint32 *num)
+static void
+exported_connection_to_connection (gpointer data, gpointer user_data)
 {
-	GtkListStore *model;
-	const GPtrArray *devices;
+	GSList **list = (GSList **) user_data;
+
+	*list = g_slist_prepend (*list, nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (data)));
+}
+
+static GSList *
+get_all_connections (NMApplet *applet)
+{
+	GSList *list;
+	GSList *connections = NULL;
+
+	list = nm_settings_list_connections (NM_SETTINGS (applet->dbus_settings));
+	g_slist_foreach (list, exported_connection_to_connection, &connections);
+	g_slist_free (list);
+
+	list = nm_settings_list_connections (NM_SETTINGS (applet->gconf_settings));
+	g_slist_foreach (list, exported_connection_to_connection, &connections);
+	g_slist_free (list);
+
+	return connections;
+}
+
+static gboolean
+connection_combo_separator_cb (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
+{
+	gboolean is_separator = FALSE;
+
+	gtk_tree_model_get (model, iter, C_SEP_COLUMN, &is_separator, -1);
+	return is_separator;
+}
+
+static gint
+alphabetize_connections (NMConnection *a, NMConnection *b)
+{
+	NMSettingConnection *asc, *bsc;
+
+	asc = NM_SETTING_CONNECTION (nm_connection_get_setting (a, NM_TYPE_SETTING_CONNECTION));
+	bsc = NM_SETTING_CONNECTION (nm_connection_get_setting (b, NM_TYPE_SETTING_CONNECTION));
+
+	return strcmp (asc->id, bsc->id);
+}
+
+static gboolean
+connection_combo_init (NMAWirelessDialog *self, NMConnection *connection)
+{
+	NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+	GtkListStore *store;
+	int num_added = 0;
 	GtkTreeIter tree_iter;
-	int i;
+	GtkWidget *widget;
+	NMSettingConnection *s_con;
+	GtkCellRenderer *renderer;
+
+	g_return_val_if_fail (priv->connection == NULL, FALSE);
 
-	g_return_val_if_fail (client != NULL, NULL);
-	g_return_val_if_fail (num != NULL, NULL);
+	/* Clear any old model */
+	model_free (priv->connection_model, C_NAME_COLUMN);
 
-	model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_OBJECT);
-	*num = 0;
+	/* New model */
+	store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_OBJECT, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
+	priv->connection_model = GTK_TREE_MODEL (store);
 
-	if (use_this_device) {
-		add_device_to_model (model, &tree_iter, use_this_device);
-		*num = 1;
+	if (connection) {
+		s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+		g_assert (s_con);
+		g_assert (s_con->id);
+
+		gtk_list_store_append (store, &tree_iter);
+		gtk_list_store_set (store, &tree_iter,
+		                    C_NAME_COLUMN, g_strdup (s_con->id),
+		                    C_CON_COLUMN, connection, -1);
 	} else {
-		devices = nm_client_get_devices (client);
-		for (i = 0; devices && (i < devices->len); i++) {
-			NMDevice *dev = NM_DEVICE (g_ptr_array_index (devices, i));
+		GSList *connections, *iter, *to_add = NULL;
 
-			/* Ignore unsupported devices */
-			if (!(nm_device_get_capabilities (dev) & NM_DEVICE_CAP_NM_SUPPORTED))
+		gtk_list_store_append (store, &tree_iter);
+		gtk_list_store_set (store, &tree_iter,
+		                    C_NAME_COLUMN, g_strdup (_("New...")),
+		                    C_NEW_COLUMN, TRUE, -1);
+
+		gtk_list_store_append (store, &tree_iter);
+		gtk_list_store_set (store, &tree_iter, C_SEP_COLUMN, TRUE, -1);
+
+		connections = get_all_connections (priv->applet);
+		for (iter = connections; iter; iter = g_slist_next (iter)) {
+			NMConnection *candidate = NM_CONNECTION (iter->data);
+			NMSettingWireless *s_wireless;
+
+			s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (candidate, NM_TYPE_SETTING_CONNECTION));
+			if (!s_con || !s_con->type)
+				continue;
+
+			if (strcmp (s_con->type, NM_SETTING_WIRELESS_SETTING_NAME))
 				continue;
 
-			if (!NM_IS_DEVICE_802_11_WIRELESS (dev))
+			/* If creating a new Ad-Hoc network, only show adhoc networks
+			 * with adhoc-create = TRUE.
+			 */
+			s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (candidate, NM_TYPE_SETTING_WIRELESS));
+			if (!s_wireless || (priv->adhoc_create != s_wireless->adhoc_create))
 				continue;
 
-			add_device_to_model (model, &tree_iter, dev);
-			*num += 1;
+			/* Ignore connections that don't apply to the selected device */
+			if (s_wireless->mac_address) {
+				const char *hw_addr;
+
+				hw_addr = nm_device_802_11_wireless_get_hw_address (NM_DEVICE_802_11_WIRELESS (priv->device));
+				if (hw_addr) {
+					struct ether_addr *ether;
+
+					ether = ether_aton (hw_addr);
+					if (ether && memcmp (s_wireless->mac_address->data, ether->ether_addr_octet, ETH_ALEN))
+						continue;
+				}
+			}
+
+			to_add = g_slist_append (to_add, candidate);
 		}
+		g_slist_free (connections);
+
+		/* Alphabetize the list then add the connections */
+		to_add = g_slist_sort (to_add, (GCompareFunc) alphabetize_connections);
+		for (iter = to_add; iter; iter = g_slist_next (iter)) {
+			NMConnection *candidate = NM_CONNECTION (iter->data);
+
+			s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (candidate, NM_TYPE_SETTING_CONNECTION));
+			gtk_list_store_append (store, &tree_iter);
+			gtk_list_store_set (store, &tree_iter,
+			                    C_NAME_COLUMN, g_strdup (s_con->id),
+			                    C_CON_COLUMN, candidate, -1);
+			num_added++;
+		}
+		g_slist_free (to_add);
+	}
+
+	widget = glade_xml_get_widget (priv->xml, "connection_combo");
+
+	gtk_cell_layout_clear (GTK_CELL_LAYOUT (widget));
+	renderer = gtk_cell_renderer_text_new ();
+	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget), renderer, TRUE);
+	gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (widget), renderer,
+	                               "text", C_NAME_COLUMN);
+	gtk_combo_box_set_wrap_width (GTK_COMBO_BOX (widget), 1);
+
+	gtk_combo_box_set_model (GTK_COMBO_BOX (widget), priv->connection_model);
+
+	gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (widget),
+	                                      connection_combo_separator_cb,
+	                                      NULL,
+	                                      NULL);
+
+	gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
+	g_signal_connect (G_OBJECT (widget), "changed",
+	                  GTK_SIGNAL_FUNC (connection_combo_changed), self);
+	if (connection || !num_added) {
+		gtk_widget_hide (glade_xml_get_widget (priv->xml, "connection_label"));
+		gtk_widget_hide (widget);
 	}
+	gtk_tree_model_get_iter_first (priv->connection_model, &tree_iter);
+	gtk_tree_model_get (priv->connection_model, &tree_iter, C_CON_COLUMN, &priv->connection, -1);
 
-	return GTK_TREE_MODEL (model);
+	return TRUE;
 }
 
 static void
-destroy_device_model (GtkTreeModel *model)
+device_combo_changed (GtkWidget *combo,
+                      gpointer user_data)
 {
-	GtkTreeIter	iter;
+	NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
+	NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+	GtkTreeIter iter;
+	GtkTreeModel *model;
 
-	g_return_if_fail (model != NULL);
+	gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
+	model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
 
-	if (gtk_tree_model_get_iter_first (model, &iter)) {
-		do {
-			char *str;
+	g_object_unref (priv->device);
+	gtk_tree_model_get (model, &iter, D_DEV_COLUMN, &priv->device, -1);
 
-			gtk_tree_model_get (model, &iter, D_NAME_COLUMN, &str, -1);
-			g_free (str);
-		} while (gtk_tree_model_iter_next (model, &iter));
+	if (!connection_combo_init (self, NULL)) {
+		g_warning ("Couldn't change connection combo box.");
+		return;
 	}
-	g_object_unref (model);
+
+	if (!security_combo_init (self)) {
+		g_warning ("Couldn't change wireless security combo box.");
+		return;
+	}
+
+	security_combo_changed (priv->sec_combo, self);
+}
+
+static void
+add_device_to_model (GtkListStore *model, NMDevice *device)
+{
+	GtkTreeIter iter;
+	char *desc;
+
+	desc = (char *) utils_get_device_description (device);
+	if (!desc)
+		desc = (char *) nm_device_get_iface (device);
+	g_assert (desc);
+
+	gtk_list_store_append (model, &iter);
+	gtk_list_store_set (model, &iter, D_NAME_COLUMN, g_strdup (desc), D_DEV_COLUMN, device, -1);
+}
+
+static gboolean
+can_use_device (NMDevice *device)
+{
+	/* Ignore unsupported devices */
+	if (!(nm_device_get_capabilities (device) & NM_DEVICE_CAP_NM_SUPPORTED))
+		return FALSE;
+
+	if (!NM_IS_DEVICE_802_11_WIRELESS (device))
+		return FALSE;
+
+	if (nm_device_get_state (device) < NM_DEVICE_STATE_DISCONNECTED)
+		return FALSE;
+
+	return TRUE;
+}
+
+static gboolean
+device_combo_init (NMAWirelessDialog *self, NMDevice *device)
+{
+	NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+	const GPtrArray *devices;
+	GtkListStore *store;
+	int i, num_added = 0;
+
+	g_return_val_if_fail (priv->device == NULL, FALSE);
+
+	store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_OBJECT);
+	priv->device_model = GTK_TREE_MODEL (store);
+
+	if (device) {
+		if (!can_use_device (device))
+			return FALSE;
+		add_device_to_model (store, device);
+		num_added++;
+	} else {
+		devices = nm_client_get_devices (priv->applet->nm_client);
+		if (devices->len == 0)
+			return FALSE;
+
+		for (i = 0; devices && (i < devices->len); i++) {
+			device = NM_DEVICE (g_ptr_array_index (devices, i));
+			if (can_use_device (device)) {
+				add_device_to_model (store, device);
+				num_added++;
+			}
+		}
+	}
+
+	if (num_added > 0) {
+		GtkWidget *widget;
+		GtkTreeIter iter;
+
+		widget = glade_xml_get_widget (priv->xml, "device_combo");
+		gtk_combo_box_set_model (GTK_COMBO_BOX (widget), priv->device_model);
+		gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
+		g_signal_connect (G_OBJECT (widget), "changed",
+		                  GTK_SIGNAL_FUNC (device_combo_changed), self);
+		if (num_added == 1) {
+			gtk_widget_hide (glade_xml_get_widget (priv->xml, "device_label"));
+			gtk_widget_hide (widget);
+		}
+		gtk_tree_model_get_iter_first (priv->device_model, &iter);
+		gtk_tree_model_get (priv->device_model, &iter, D_DEV_COLUMN, &priv->device, -1);
+	}
+
+	return num_added > 0 ? TRUE : FALSE;
 }
 
 static NMUtilsSecurityType
 get_default_type_for_security (NMSettingWirelessSecurity *sec,
+                               gboolean have_ap,
                                guint32 ap_flags,
                                guint32 dev_caps)
 {
@@ -359,7 +615,7 @@
 		return NMU_SEC_STATIC_WEP;
 
 	if (   !strcmp (sec->key_mgmt, "ieee8021x")
-	    && (ap_flags & NM_802_11_AP_FLAGS_PRIVACY)) {
+	    && (!have_ap || (ap_flags & NM_802_11_AP_FLAGS_PRIVACY))) {
 		if (sec->auth_alg && !strcmp (sec->auth_alg, "leap"))
 			return NMU_SEC_LEAP;
 		return NMU_SEC_DYNAMIC_WEP;
@@ -367,7 +623,7 @@
 
 	if (   !strcmp (sec->key_mgmt, "wpa-none")
 	    || !strcmp (sec->key_mgmt, "wpa-psk")) {
-		if (ap_flags & NM_802_11_AP_FLAGS_PRIVACY) {
+		if (!have_ap || (ap_flags & NM_802_11_AP_FLAGS_PRIVACY)) {
 			if (sec->proto && !strcmp (sec->proto->data, "rsn"))
 				return NMU_SEC_WPA2_PSK;
 			else if (sec->proto && !strcmp (sec->proto->data, "wpa"))
@@ -378,7 +634,7 @@
 	}
 
 	if (   !strcmp (sec->key_mgmt, "wpa-eap")
-	    && (ap_flags & NM_802_11_AP_FLAGS_PRIVACY)) {
+	    && (!have_ap || (ap_flags & NM_802_11_AP_FLAGS_PRIVACY))) {
 			if (sec->proto && !strcmp (sec->proto->data, "rsn"))
 				return NMU_SEC_WPA2_ENTERPRISE;
 			else if (sec->proto && !strcmp (sec->proto->data, "wpa"))
@@ -391,29 +647,24 @@
 }
 
 static void
-add_security_item (GtkWidget *dialog,
+add_security_item (NMAWirelessDialog *self,
                    WirelessSecurity *sec,
                    GtkListStore *model,
                    GtkTreeIter *iter,
                    const char *text)
 {
-	wireless_security_set_changed_notify (sec, stuff_changed_cb, dialog);
+	wireless_security_set_changed_notify (sec, stuff_changed_cb, self);
 	gtk_list_store_append (model, iter);
 	gtk_list_store_set (model, iter, S_NAME_COLUMN, text, S_SEC_COLUMN, sec, -1);
 	wireless_security_unref (sec);
 }
 
 static gboolean
-security_combo_init (const char *glade_file,
-                     GtkWidget *combo,
-                     NMDevice *device,
-                     GtkWidget *dialog,
-                     NMConnection *connection,
-                     gboolean user_created_adhoc)
+security_combo_init (NMAWirelessDialog *self)
 {
+	NMAWirelessDialogPrivate *priv;
 	GtkListStore *sec_model;
 	GtkTreeIter iter;
-	NMAccessPoint *cur_ap;
 	guint32 ap_flags = 0;
 	guint32 ap_wpa = 0;
 	guint32 ap_rsn = 0;
@@ -423,45 +674,47 @@
 	int active = -1;
 	int item = 0;
 	NMSettingWireless *s_wireless = NULL;
-	gboolean is_adhoc = user_created_adhoc;
+	gboolean is_adhoc;
 	char *connection_id = NULL;
 
-	g_return_val_if_fail (combo != NULL, FALSE);
-	g_return_val_if_fail (glade_file != NULL, FALSE);
-	g_return_val_if_fail (device != NULL, FALSE);
-	g_return_val_if_fail (dialog != NULL, FALSE);
+	g_return_val_if_fail (self != NULL, FALSE);
+
+	priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+	g_return_val_if_fail (priv->device != NULL, FALSE);
+	g_return_val_if_fail (priv->sec_combo != NULL, FALSE);
+
+	is_adhoc = priv->adhoc_create;
 
 	/* The security options displayed are filtered based on device
 	 * capabilities, and if provided, additionally by access point capabilities.
 	 * If a connection is given, that connection's options should be selected
 	 * by default.
 	 */
-	dev_caps = nm_device_802_11_wireless_get_capabilities (NM_DEVICE_802_11_WIRELESS (device));
-	cur_ap = g_object_get_data (G_OBJECT (dialog), "ap");
-	if (cur_ap != NULL) {
-		ap_flags = nm_access_point_get_flags (cur_ap);
-		ap_wpa = nm_access_point_get_wpa_flags (cur_ap);
-		ap_rsn = nm_access_point_get_rsn_flags (cur_ap);
+	dev_caps = nm_device_802_11_wireless_get_capabilities (NM_DEVICE_802_11_WIRELESS (priv->device));
+	if (priv->ap != NULL) {
+		ap_flags = nm_access_point_get_flags (priv->ap);
+		ap_wpa = nm_access_point_get_wpa_flags (priv->ap);
+		ap_rsn = nm_access_point_get_rsn_flags (priv->ap);
 	}
 
-	if (connection) {
-		s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
+	if (priv->connection) {
+		s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS));
 		if (s_wireless && s_wireless->mode && !strcmp (s_wireless->mode, "adhoc"))
 			is_adhoc = TRUE;
 
-		wsec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (connection, 
+		wsec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (priv->connection, 
 										NM_TYPE_SETTING_WIRELESS_SECURITY));
 		if (!s_wireless->security || strcmp (s_wireless->security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME))
 			wsec = NULL;
 		if (wsec)
-			default_type = get_default_type_for_security (wsec, ap_flags, dev_caps);
+			default_type = get_default_type_for_security (wsec, !!priv->ap, ap_flags, dev_caps);
 
-		connection_id = g_object_get_data (G_OBJECT (connection), NMA_CONNECTION_ID_TAG);
+		connection_id = g_object_get_data (G_OBJECT (priv->connection), NMA_CONNECTION_ID_TAG);
 	}
 
 	sec_model = gtk_list_store_new (2, G_TYPE_STRING, wireless_security_get_g_type ());
 
-	if (nm_utils_security_valid (NMU_SEC_NONE, dev_caps, !!cur_ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
+	if (nm_utils_security_valid (NMU_SEC_NONE, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
 		gtk_list_store_append (sec_model, &iter);
 		gtk_list_store_set (sec_model, &iter,
 		                    S_NAME_COLUMN, _("None"),
@@ -474,35 +727,35 @@
 	/* Don't show Static WEP if both the AP and the device are capable of WPA,
 	 * even though technically it's possible to have this configuration.
 	 */
-	if (   nm_utils_security_valid (NMU_SEC_STATIC_WEP, dev_caps, !!cur_ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
+	if (   nm_utils_security_valid (NMU_SEC_STATIC_WEP, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
 	    && ((!ap_wpa && !ap_rsn) || !(dev_caps & (NM_802_11_DEVICE_CAP_WPA | NM_802_11_DEVICE_CAP_RSN)))) {
 		WirelessSecurityWEPKey *ws_wep;
 		WEPKeyType default_wep_type = WEP_KEY_TYPE_PASSPHRASE;
 
 		if (default_type == NMU_SEC_STATIC_WEP)
-			default_wep_type = ws_wep_guess_key_type (connection, connection_id);
+			default_wep_type = ws_wep_guess_key_type (priv->connection, connection_id);
 
-		ws_wep = ws_wep_key_new (glade_file, connection, connection_id, WEP_KEY_TYPE_PASSPHRASE);
+		ws_wep = ws_wep_key_new (priv->glade_file, priv->connection, connection_id, WEP_KEY_TYPE_PASSPHRASE);
 		if (ws_wep) {
-			add_security_item (dialog, WIRELESS_SECURITY (ws_wep), sec_model,
+			add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
 			                   &iter, _("WEP 128-bit Passphrase"));
 			if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (default_wep_type == WEP_KEY_TYPE_PASSPHRASE))
 				active = item;
 			item++;
 		}
 
-		ws_wep = ws_wep_key_new (glade_file, connection, connection_id, WEP_KEY_TYPE_HEX);
+		ws_wep = ws_wep_key_new (priv->glade_file, priv->connection, connection_id, WEP_KEY_TYPE_HEX);
 		if (ws_wep) {
-			add_security_item (dialog, WIRELESS_SECURITY (ws_wep), sec_model,
+			add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
 			                   &iter, _("WEP 40/128-bit Hexadecimal"));
 			if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (default_wep_type == WEP_KEY_TYPE_HEX))
 				active = item;
 			item++;
 		}
 
-		ws_wep = ws_wep_key_new (glade_file, connection, connection_id, WEP_KEY_TYPE_ASCII);
+		ws_wep = ws_wep_key_new (priv->glade_file, priv->connection, connection_id, WEP_KEY_TYPE_ASCII);
 		if (ws_wep) {
-			add_security_item (dialog, WIRELESS_SECURITY (ws_wep), sec_model,
+			add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
 			                   &iter, _("WEP 40/128-bit ASCII"));
 			if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (default_wep_type == WEP_KEY_TYPE_ASCII))
 				active = item;
@@ -513,13 +766,13 @@
 	/* Don't show LEAP if both the AP and the device are capable of WPA,
 	 * even though technically it's possible to have this configuration.
 	 */
-	if (   nm_utils_security_valid (NMU_SEC_LEAP, dev_caps, !!cur_ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
+	if (   nm_utils_security_valid (NMU_SEC_LEAP, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
 	    && ((!ap_wpa && !ap_rsn) || !(dev_caps & (NM_802_11_DEVICE_CAP_WPA | NM_802_11_DEVICE_CAP_RSN)))) {
 		WirelessSecurityLEAP *ws_leap;
 
-		ws_leap = ws_leap_new (glade_file, connection, connection_id);
+		ws_leap = ws_leap_new (priv->glade_file, priv->connection, connection_id);
 		if (ws_leap) {
-			add_security_item (dialog, WIRELESS_SECURITY (ws_leap), sec_model,
+			add_security_item (self, WIRELESS_SECURITY (ws_leap), sec_model,
 			                   &iter, _("LEAP"));
 			if ((active < 0) && (default_type == NMU_SEC_LEAP))
 				active = item;
@@ -527,12 +780,12 @@
 		}
 	}
 
-	if (nm_utils_security_valid (NMU_SEC_DYNAMIC_WEP, dev_caps, !!cur_ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
+	if (nm_utils_security_valid (NMU_SEC_DYNAMIC_WEP, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
 		WirelessSecurityDynamicWEP *ws_dynamic_wep;
 
-		ws_dynamic_wep = ws_dynamic_wep_new (glade_file, connection, connection_id);
+		ws_dynamic_wep = ws_dynamic_wep_new (priv->glade_file, priv->connection, connection_id);
 		if (ws_dynamic_wep) {
-			add_security_item (dialog, WIRELESS_SECURITY (ws_dynamic_wep), sec_model,
+			add_security_item (self, WIRELESS_SECURITY (ws_dynamic_wep), sec_model,
 			                   &iter, _("Dynamic WEP (802.1x)"));
 			if ((active < 0) && (default_type == NMU_SEC_DYNAMIC_WEP))
 				active = item;
@@ -540,13 +793,13 @@
 		}
 	}
 
-	if (   nm_utils_security_valid (NMU_SEC_WPA_PSK, dev_caps, !!cur_ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
-	    || nm_utils_security_valid (NMU_SEC_WPA2_PSK, dev_caps, !!cur_ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
+	if (   nm_utils_security_valid (NMU_SEC_WPA_PSK, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
+	    || nm_utils_security_valid (NMU_SEC_WPA2_PSK, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
 		WirelessSecurityWPAPSK *ws_wpa_psk;
 
-		ws_wpa_psk = ws_wpa_psk_new (glade_file, connection, connection_id);
+		ws_wpa_psk = ws_wpa_psk_new (priv->glade_file, priv->connection, connection_id);
 		if (ws_wpa_psk) {
-			add_security_item (dialog, WIRELESS_SECURITY (ws_wpa_psk), sec_model,
+			add_security_item (self, WIRELESS_SECURITY (ws_wpa_psk), sec_model,
 			                   &iter, _("WPA & WPA2 Personal"));
 			if ((active < 0) && ((default_type == NMU_SEC_WPA_PSK) || (default_type == NMU_SEC_WPA2_PSK)))
 				active = item;
@@ -554,13 +807,13 @@
 		}
 	}
 
-	if (   nm_utils_security_valid (NMU_SEC_WPA_ENTERPRISE, dev_caps, !!cur_ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
-	    || nm_utils_security_valid (NMU_SEC_WPA2_ENTERPRISE, dev_caps, !!cur_ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
+	if (   nm_utils_security_valid (NMU_SEC_WPA_ENTERPRISE, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
+	    || nm_utils_security_valid (NMU_SEC_WPA2_ENTERPRISE, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
 		WirelessSecurityWPAEAP *ws_wpa_eap;
 
-		ws_wpa_eap = ws_wpa_eap_new (glade_file, connection, connection_id);
+		ws_wpa_eap = ws_wpa_eap_new (priv->glade_file, priv->connection, connection_id);
 		if (ws_wpa_eap) {
-			add_security_item (dialog, WIRELESS_SECURITY (ws_wpa_eap), sec_model,
+			add_security_item (self, WIRELESS_SECURITY (ws_wpa_eap), sec_model,
 			                   &iter, _("WPA & WPA2 Enterprise"));
 			if ((active < 0) && ((default_type == NMU_SEC_WPA_ENTERPRISE) || (default_type == NMU_SEC_WPA2_ENTERPRISE)))
 				active = item;
@@ -568,157 +821,141 @@
 		}
 	}
 
-	gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (sec_model));
-	gtk_combo_box_set_active (GTK_COMBO_BOX (combo), active < 0 ? 0 : (guint32) active);
+	gtk_combo_box_set_model (GTK_COMBO_BOX (priv->sec_combo), GTK_TREE_MODEL (sec_model));
+	gtk_combo_box_set_active (GTK_COMBO_BOX (priv->sec_combo), active < 0 ? 0 : (guint32) active);
 	g_object_unref (G_OBJECT (sec_model));
 	return TRUE;
 }
 
 static gboolean
-dialog_init (GtkWidget *dialog,
-             GladeXML *xml,
-             NMClient *nm_client,
-             const char *glade_file,
-             NMConnection *connection,
-             gboolean user_created_adhoc)
+internal_init (NMAWirelessDialog *self,
+               NMConnection *specific_connection,
+               NMDevice *specific_device)
 {
+	NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
 	GtkWidget *widget;
-	GtkSizeGroup *group;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	guint32 num_devs = 0;
 	char *label;
-	NMDevice *dev;
-	gboolean success = FALSE;
 	gboolean security_combo_focus = FALSE;
-	GtkWidget *image;
 
-	/* If given a valid connection, hide the SSID bits */
-	if (connection) {
-		widget = glade_xml_get_widget (xml, "network_name_label");
-		g_assert (widget);
+	gtk_window_set_position (GTK_WINDOW (self), GTK_WIN_POS_CENTER_ALWAYS);
+	gtk_container_set_border_width (GTK_CONTAINER (self), 6);
+	gtk_window_set_default_size (GTK_WINDOW (self), 488, -1);
+	gtk_window_set_icon_name (GTK_WINDOW (self), "gtk-dialog-authentication");
+	gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
+	gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE);
+
+	gtk_box_set_spacing (GTK_BOX (gtk_bin_get_child (GTK_BIN (self))), 2);
+
+	widget = gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+	gtk_box_set_child_packing (GTK_BOX (GTK_DIALOG (self)->action_area), widget,
+	                           FALSE, TRUE, 0, GTK_PACK_END);
+
+	widget = gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CONNECT, GTK_RESPONSE_OK);
+	gtk_box_set_child_packing (GTK_BOX (GTK_DIALOG (self)->action_area), widget,
+	                           FALSE, TRUE, 0, GTK_PACK_END);
+
+	widget = glade_xml_get_widget (priv->xml, "hbox1");
+	if (!widget) {
+		nm_warning ("Couldn't find glade wireless_dialog widget.");
+		return FALSE;
+	}
+
+	gtk_container_add (GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (self))), widget);
+
+	/* If given a valid connection, hide the SSID bits and connection combo */
+	if (specific_connection) {
+		widget = glade_xml_get_widget (priv->xml, "network_name_label");
 		gtk_widget_hide (widget);
 
-		widget = glade_xml_get_widget (xml, "network_name_entry");
-		g_assert (widget);
+		widget = glade_xml_get_widget (priv->xml, "network_name_entry");
 		gtk_widget_hide (widget);
 
 		security_combo_focus = TRUE;
 	} else {
-		widget = glade_xml_get_widget (xml, "network_name_entry");
-		g_signal_connect (G_OBJECT (widget), "changed", (GCallback) ssid_entry_changed, dialog);
+		widget = glade_xml_get_widget (priv->xml, "network_name_entry");
+		g_signal_connect (G_OBJECT (widget), "changed", (GCallback) ssid_entry_changed, self);
 		gtk_widget_grab_focus (widget);
 	}
 
-	widget = glade_xml_get_widget (xml, "ok_button");
-	gtk_widget_grab_default (widget);
-	gtk_widget_set_sensitive (widget, FALSE);
-	image = gtk_image_new_from_stock (GTK_STOCK_CONNECT, GTK_ICON_SIZE_BUTTON);
-	gtk_button_set_image (GTK_BUTTON (widget), image);
-
-	group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
-	g_object_set_data_full (G_OBJECT (dialog),
-	                        "size-group", group,
-	                        (GDestroyNotify) g_object_unref);
+	gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, FALSE);
 
-	/* If passed a device, don't show all devices, let create_device_model
-	 * create a model with just the one we want.
-	 */
-	dev = g_object_get_data (G_OBJECT (dialog), "device");
-	model = create_device_model (nm_client, dev, &num_devs);
-	if (!model || (num_devs < 1)) {
+	if (!device_combo_init (self, specific_device)) {
 		g_warning ("No wireless devices available.");
-		destroy_device_model (model);
 		return FALSE;
 	}
-	g_object_set_data_full (G_OBJECT (dialog),
-	                        "device-model", model,
-	                        (GDestroyNotify) destroy_device_model);
 
-	widget = glade_xml_get_widget (xml, "device_combo");
-	gtk_combo_box_set_model (GTK_COMBO_BOX (widget), model);
-	gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
-	g_signal_connect (G_OBJECT (widget), "changed",
-	                  GTK_SIGNAL_FUNC (device_combo_changed), dialog);
-	if (num_devs == 1) {
-		gtk_widget_hide (glade_xml_get_widget (xml, "device_label"));
-		gtk_widget_hide (widget);
+	if (!connection_combo_init (self, specific_connection)) {
+		g_warning ("Couldn't set up connection combo box.");
+		return FALSE;
 	}
-	gtk_tree_model_get_iter_first (model, &iter);
-	gtk_tree_model_get (model, &iter, D_DEV_COLUMN, &dev, -1);
 
-	widget = glade_xml_get_widget (xml, "security_combo");
-	g_assert (widget);
-	if (!security_combo_init (glade_file, widget, dev, dialog, connection, user_created_adhoc)) {
-		g_message ("Couldn't set up wireless security combo box.");
-		goto out;
+	if (!security_combo_init (self)) {
+		g_warning ("Couldn't set up wireless security combo box.");
+		return FALSE;
 	}
+
 	if (security_combo_focus)
-		gtk_widget_grab_focus (widget);
+		gtk_widget_grab_focus (priv->sec_combo);
 
-	security_combo_changed (widget, dialog);
-	g_signal_connect (G_OBJECT (widget), "changed", GTK_SIGNAL_FUNC (security_combo_changed), dialog);
+	security_combo_changed (priv->sec_combo, self);
+	g_signal_connect (G_OBJECT (priv->sec_combo), "changed", GTK_SIGNAL_FUNC (security_combo_changed), self);
 
-	if (connection) {
+	if (priv->connection) {
 		char *tmp;
 		char *esc_ssid = NULL;
 		NMSettingWireless *s_wireless;
 
-		s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
+		s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS));
 		if (s_wireless && s_wireless->ssid)
 			esc_ssid = nm_utils_ssid_to_utf8 ((const char *) s_wireless->ssid->data, s_wireless->ssid->len);
 
 		tmp = g_strdup_printf (_("Passwords or encryption keys are required to access the wireless network '%s'."),
 		                       esc_ssid ? esc_ssid : "<unknown>");
-		gtk_window_set_title (GTK_WINDOW (dialog), _("Wireless Network Secrets Required"));
+		gtk_window_set_title (GTK_WINDOW (self), _("Wireless Network Secrets Required"));
 		label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
 		                         _("Secrets required by wireless network"),
 		                         tmp);
 		g_free (esc_ssid);
 		g_free (tmp);
-	} else if (user_created_adhoc) {
-		gtk_window_set_title (GTK_WINDOW (dialog), _("Create New Wireless Network"));
+	} else if (priv->adhoc_create) {
+		gtk_window_set_title (GTK_WINDOW (self), _("Create New Wireless Network"));
 		label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
 		                         _("New wireless network"),
 		                         _("Enter a name for the wireless network you wish to create."));
 	} else {
-		gtk_window_set_title (GTK_WINDOW (dialog), _("Connect to Other Wireless Network"));
+		gtk_window_set_title (GTK_WINDOW (self), _("Connect to Other Wireless Network"));
 		label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
 		                         _("Existing wireless network"),
 		                         _("Enter the name of the wireless network to which you wish to connect."));
 	}
 
-	widget = glade_xml_get_widget (xml, "caption_label");
+	widget = glade_xml_get_widget (priv->xml, "caption_label");
 	gtk_label_set_markup (GTK_LABEL (widget), label);
 	g_free (label);
 
-	success = TRUE;
-
-out:
-	g_object_unref (dev);
-	return success;
+	return TRUE;
 }
 
 NMConnection *
-nma_wireless_dialog_get_connection (GtkWidget *dialog,
+nma_wireless_dialog_get_connection (NMAWirelessDialog *self,
                                     NMDevice **device,
                                     NMAccessPoint **ap)
 {
-	GladeXML *xml;
+	NMAWirelessDialogPrivate *priv;
 	GtkWidget *combo;
 	GtkTreeModel *model;
 	WirelessSecurity *sec = NULL;
 	GtkTreeIter iter;
 	NMConnection *connection;
 	NMSettingWireless *s_wireless;
-	NMAccessPoint *tmp_ap;
 
-	g_return_val_if_fail (dialog != NULL, NULL);
+	g_return_val_if_fail (self != NULL, NULL);
 	g_return_val_if_fail (device != NULL, NULL);
 	g_return_val_if_fail (*device == NULL, NULL);
 
-	connection = g_object_get_data (G_OBJECT (dialog), "connection");
-	if (!connection) {
+	priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+
+	if (!priv->connection) {
 		NMSettingConnection *s_con;
 
 		connection = nm_connection_new ();
@@ -728,24 +965,21 @@
 		nm_connection_add_setting (connection, (NMSetting *) s_con);
 
 		s_wireless = (NMSettingWireless *) nm_setting_wireless_new ();
-		s_wireless->ssid = validate_dialog_ssid (dialog);
+		s_wireless->ssid = validate_dialog_ssid (self);
 		g_assert (s_wireless->ssid);
 
-		if (g_object_get_data (G_OBJECT (dialog), NEW_ADHOC_TAG))
+		if (priv->adhoc_create) {
 			s_wireless->mode = g_strdup ("adhoc");
+			s_wireless->adhoc_create = TRUE;
+		}
 
 		nm_connection_add_setting (connection, (NMSetting *) s_wireless);
-	}
-
-	xml = g_object_get_data (G_OBJECT (dialog), "glade-xml");
-	g_assert (xml);
-
-	combo = glade_xml_get_widget (xml, "security_combo");
-	g_assert (combo);
+	} else
+		connection = g_object_ref (priv->connection);
 
 	/* Fill security */
-	model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
-	gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
+	model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->sec_combo));
+	gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->sec_combo), &iter);
 	gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
 	if (sec) {
 		wireless_security_fill_connection (sec, connection);
@@ -762,121 +996,174 @@
 	}
 
 	/* Fill device */
-	combo = glade_xml_get_widget (xml, "device_combo");
-	model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
+	combo = glade_xml_get_widget (priv->xml, "device_combo");
 	gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
-	gtk_tree_model_get (model, &iter, D_DEV_COLUMN, device, -1);
+	gtk_tree_model_get (priv->device_model, &iter, D_DEV_COLUMN, device, -1);
 	g_object_unref (*device);
 
-	tmp_ap = g_object_get_data (G_OBJECT (dialog), "ap");
-	if (tmp_ap && ap)
-		*ap = tmp_ap;
+	if (ap)
+		*ap = priv->ap;
 
 	return connection;
 }
 
 GtkWidget *
-nma_wireless_dialog_new (const char *glade_file,
-                         NMClient *nm_client,
+nma_wireless_dialog_new (NMApplet *applet,
                          NMConnection *connection,
-                         NMDevice *cur_device,
-                         NMAccessPoint *cur_ap,
-                         gboolean user_created_adhoc)
-{
-	GtkWidget *	dialog;
-	GladeXML *	xml;
-	gboolean success;
+                         NMDevice *device,
+                         NMAccessPoint *ap)
+{
+	NMAWirelessDialog *self;
+	NMAWirelessDialogPrivate *priv;
+	guint32 dev_caps;
 
-	g_return_val_if_fail (glade_file != NULL, NULL);
+	g_return_val_if_fail (applet != NULL, NULL);
+	g_return_val_if_fail (connection != NULL, NULL);
+	g_return_val_if_fail (device != NULL, NULL);
+	g_return_val_if_fail (ap != NULL, NULL);
 
 	/* Ensure device validity */
-	if (cur_device) {
-		guint32 dev_caps = nm_device_get_capabilities (cur_device);
-
-		g_return_val_if_fail (dev_caps & NM_DEVICE_CAP_NM_SUPPORTED, NULL);
-		g_return_val_if_fail (NM_IS_DEVICE_802_11_WIRELESS (cur_device), NULL);
-	}
+	dev_caps = nm_device_get_capabilities (device);
+	g_return_val_if_fail (dev_caps & NM_DEVICE_CAP_NM_SUPPORTED, NULL);
+	g_return_val_if_fail (NM_IS_DEVICE_802_11_WIRELESS (device), NULL);
 
-	xml = glade_xml_new (glade_file, "wireless_dialog", NULL);
-	if (xml == NULL) {
-		applet_warning_dialog_show (_("The NetworkManager Applet could not find some required resources (the glade file was not found)."));
+	self = NMA_WIRELESS_DIALOG (g_object_new (NMA_TYPE_WIRELESS_DIALOG, NULL));
+	if (!self)
 		return NULL;
-	}
 
-	dialog = glade_xml_get_widget (xml, "wireless_dialog");
-	if (!dialog) {
-		nm_warning ("Couldn't find glade wireless_dialog widget.");
-		g_object_unref (xml);
+	priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+
+	priv->applet = applet;
+	priv->ap = g_object_ref (ap);
+
+	priv->sec_combo = glade_xml_get_widget (priv->xml, "security_combo");
+	priv->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+
+	if (!internal_init (self, connection, device)) {
+		nm_warning ("Couldn't create wireless security dialog.");
+		g_object_unref (self);
 		return NULL;
 	}
 
-	g_object_set_data_full (G_OBJECT (dialog),
-	                        "glade-file", g_strdup (glade_file),
-	                        (GDestroyNotify) g_free);
-
-	g_object_set_data_full (G_OBJECT (dialog),
-	                        "glade-xml", xml,
-	                        (GDestroyNotify) g_object_unref);
-
-	g_object_set_data_full (G_OBJECT (dialog),
-	                        "nm-client", g_object_ref (nm_client),
-	                        (GDestroyNotify) g_object_unref);
+	return GTK_WIDGET (self);
+}
 
-	if (connection) {
-		g_object_set_data_full (G_OBJECT (dialog),
-		                        "connection", g_object_ref (connection),
-		                        (GDestroyNotify) g_object_unref);
-	}
+static GtkWidget *
+internal_new_other (NMApplet *applet, gboolean create)
+{
+	NMAWirelessDialog *self;
+	NMAWirelessDialogPrivate *priv;
 
-	if (cur_device) {
-		g_object_set_data_full (G_OBJECT (dialog),
-		                        "device", g_object_ref (cur_device),
-		                        (GDestroyNotify) g_object_unref);
-	}
+	g_return_val_if_fail (applet != NULL, NULL);
 
-	if (cur_ap) {
-		g_object_set_data_full (G_OBJECT (dialog),
-		                        "ap", g_object_ref (cur_ap),
-		                        (GDestroyNotify) g_object_unref);
-	}
+	self = NMA_WIRELESS_DIALOG (g_object_new (NMA_TYPE_WIRELESS_DIALOG, NULL));
+	if (!self)
+		return NULL;
 
-	g_object_set_data (G_OBJECT (dialog),
-	                   NEW_ADHOC_TAG, GUINT_TO_POINTER (user_created_adhoc));
+	priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
 
-	success = dialog_init (dialog, xml, nm_client, glade_file, connection, user_created_adhoc);
-	if (!success) {
+	priv->applet = applet;
+	priv->sec_combo = glade_xml_get_widget (priv->xml, "security_combo");
+	priv->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+	priv->adhoc_create = create;
+
+	if (!internal_init (self, NULL, NULL)) {
 		nm_warning ("Couldn't create wireless security dialog.");
-		gtk_widget_destroy (dialog);
+		g_object_unref (self);
 		return NULL;
 	}
 
-	return dialog;
+	return GTK_WIDGET (self);
 }
 
 GtkWidget *
-nma_wireless_dialog_nag_user (GtkWidget *dialog)
+nma_wireless_dialog_new_for_other (NMApplet *applet)
 {
-	GladeXML *xml;
+	return internal_new_other (applet, FALSE);
+}
+
+GtkWidget *
+nma_wireless_dialog_new_for_create (NMApplet *applet)
+{
+	return internal_new_other (applet, TRUE);
+}
+
+GtkWidget *
+nma_wireless_dialog_nag_user (NMAWirelessDialog *self)
+{
+	NMAWirelessDialogPrivate *priv;
 	GtkWidget *combo;
 	GtkTreeModel *model;
 	GtkTreeIter iter;
 	WirelessSecurity *sec = NULL;
 
-	g_return_val_if_fail (dialog != NULL, NULL);
+	g_return_val_if_fail (self != NULL, NULL);
 
-	xml = g_object_get_data (G_OBJECT (dialog), "glade-xml");
-	g_return_val_if_fail (xml != NULL, NULL);
+	priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
 
-	combo = glade_xml_get_widget (xml, "security_combo");
+	combo = glade_xml_get_widget (priv->xml, "security_combo");
 	g_return_val_if_fail (combo != NULL, NULL);
 
 	/* Ask the security method if it wants to nag the user. */
 	model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
 	gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
 	gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
-	if (!sec)
-		return NULL;
+	if (sec)
+		return wireless_security_nag_user (sec);
+
+	return NULL;
+}
+
+static void
+nma_wireless_dialog_init (NMAWirelessDialog *self)
+{
+	NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+
+	priv->glade_file = g_build_filename (GLADEDIR, "applet.glade", NULL);
+	priv->xml = glade_xml_new (priv->glade_file, "hbox1", NULL);
+}
+
+static void
+dispose (GObject *object)
+{
+	NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (object);
+
+	if (priv->disposed) {
+		G_OBJECT_CLASS (nma_wireless_dialog_parent_class)->dispose (object);
+		return;
+	}
+
+	priv->disposed = TRUE;
+
+	g_free (priv->glade_file);
+
+	g_object_unref (priv->xml);
+
+	model_free (priv->device_model, D_NAME_COLUMN);
+	model_free (priv->connection_model, C_NAME_COLUMN);
+
+	if (priv->group)
+		g_object_unref (priv->group);
 
-	return wireless_security_nag_user (sec);
+	if (priv->connection)
+		g_object_unref (priv->connection);
+
+	if (priv->device)
+		g_object_unref (priv->device);
+
+	if (priv->ap)
+		g_object_unref (priv->ap);
+
+	G_OBJECT_CLASS (nma_wireless_dialog_parent_class)->dispose (object);
 }
 
+static void
+nma_wireless_dialog_class_init (NMAWirelessDialogClass *nmad_class)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (nmad_class);
+
+	g_type_class_add_private (object_class, sizeof (NMAWirelessDialogPrivate));
+
+	/* virtual methods */
+	object_class->dispose = dispose;
+}

Modified: trunk/src/wireless-dialog.h
==============================================================================
--- trunk/src/wireless-dialog.h	(original)
+++ trunk/src/wireless-dialog.h	Wed May 28 21:35:31 2008
@@ -23,28 +23,49 @@
 #define WIRELESS_DIALOG_H
 
 #include <gtk/gtk.h>
+#include <gtk/gtkdialog.h>
+#include <glib/gtypes.h>
+#include <glib-object.h>
+
 #include <nm-connection.h>
+#include <nm-device.h>
+#include <nm-access-point.h>
+
+#define NMA_TYPE_WIRELESS_DIALOG            (nma_wireless_dialog_get_type ())
+#define NMA_WIRELESS_DIALOG(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMA_TYPE_WIRELESS_DIALOG, NMAWirelessDialog))
+#define NMA_WIRELESS_DIALOG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NMA_TYPE_WIRELESS_DIALOG, NMAWirelessDialogClass))
+#define NMA_IS_WIRELESS_DIALOG(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMA_TYPE_WIRELESS_DIALOG))
+#define NMA_IS_WIRELESS_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NMA_TYPE_WIRELESS_DIALOG))
+#define NMA_WIRELESS_DIALOG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NMA_TYPE_WIRELESS_DIALOG, NMAWirelessDialogClass))
+
+typedef struct {
+	GtkDialog parent;
+} NMAWirelessDialog;
+
+typedef struct {
+	GtkDialogClass parent;
+} NMAWirelessDialogClass;
+
+GType nma_wireless_dialog_get_type (void);
 
-/* The wireless dialog is used in a few situations:
- * 1) Connecting to an unseen network, in which case 'cur_device' and 'cur_ap'
- *      can be NULL because the user gets to choose
- * 2) As the password/passphrase/key dialog, in which case 'cur_device' and
- *      'cur_ap' are given and shouldn't change (and the dialog should filter
- *      options based on the capability of the device and the AP
- * 3) Creating an adhoc network, which is much like (1)
- */
-GtkWidget *	nma_wireless_dialog_new (const char *glade_file,
-                                     NMClient *nm_client,
-                                     NMConnection *connection,
-                                     NMDevice *cur_device,
-                                     NMAccessPoint *cur_ap,
-                                     gboolean user_created_adhoc);
+GtkWidget *nma_wireless_dialog_new (NMApplet *applet,
+                                    NMConnection *connection,
+                                    NMDevice *device,
+                                    NMAccessPoint *ap);
 
-NMConnection * nma_wireless_dialog_get_connection (GtkWidget *dialog,
+GtkWidget *nma_wireless_dialog_new_for_other (NMApplet *applet);
+
+GtkWidget *nma_wireless_dialog_new_for_create (NMApplet *applet);
+
+NMConnection * nma_wireless_dialog_get_connection (NMAWirelessDialog *dialog,
                                                    NMDevice **device,
                                                    NMAccessPoint **ap);
 
-GtkWidget * nma_wireless_dialog_nag_user (GtkWidget *dialog);
+GtkWidget * nma_wireless_dialog_nag_user (NMAWirelessDialog *dialog);
+
+void nma_wireless_dialog_set_nag_ignored (NMAWirelessDialog *dialog, gboolean ignored);
+
+gboolean nma_wireless_dialog_get_nag_ignored (NMAWirelessDialog *dialog);
 
 #endif	/* WIRELESS_DIALOG_H */
 



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