[network-manager-applet/NETWORKMANAGER_APPLET_0_7] wifi: fix passphrase/key dialog default widget focus (bgo #587315)



commit 46d302969a6ad62dc224e49759c6c06d40aedd88
Author: Dries Harnie <dharnie infogroep be>
Date:   Wed Aug 5 09:13:28 2009 -0400

    wifi: fix passphrase/key dialog default widget focus (bgo #587315)

 src/applet.glade                          |    2 +-
 src/wireless-dialog.c                     |   50 ++++++++++++++++++++++++-----
 src/wireless-security/eap-method-leap.c   |    3 +-
 src/wireless-security/eap-method-peap.c   |    3 +-
 src/wireless-security/eap-method-simple.c |    3 +-
 src/wireless-security/eap-method-tls.c    |    3 +-
 src/wireless-security/eap-method-ttls.c   |    3 +-
 src/wireless-security/eap-method.c        |    4 ++-
 src/wireless-security/eap-method.h        |    4 ++-
 src/wireless-security/wireless-security.c |   12 ++++++-
 src/wireless-security/wireless-security.h |    4 ++-
 src/wireless-security/ws-dynamic-wep.c    |    3 +-
 src/wireless-security/ws-leap.c           |    3 +-
 src/wireless-security/ws-wep-key.c        |    3 +-
 src/wireless-security/ws-wpa-eap.c        |    3 +-
 src/wireless-security/ws-wpa-psk.c        |    3 +-
 16 files changed, 83 insertions(+), 23 deletions(-)
---
diff --git a/src/applet.glade b/src/applet.glade
index c758b6b..2bde5f4 100644
--- a/src/applet.glade
+++ b/src/applet.glade
@@ -697,7 +697,7 @@
 	      <property name="max_length">0</property>
 	      <property name="text" translatable="yes"></property>
 	      <property name="has_frame">True</property>
-	      <property name="activates_default">False</property>
+	      <property name="activates_default">True</property>
 	    </widget>
 	    <packing>
 	      <property name="left_attach">1</property>
diff --git a/src/wireless-dialog.c b/src/wireless-dialog.c
index 664791f..75e6233 100644
--- a/src/wireless-dialog.c
+++ b/src/wireless-dialog.c
@@ -67,6 +67,7 @@ typedef struct {
 	GtkWidget *sec_combo;
 
 	gboolean nag_ignored;
+	gboolean network_name_focus;
 
 	gboolean disposed;
 } NMAWirelessDialogPrivate;
@@ -82,7 +83,6 @@ typedef struct {
 #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 (NMAWirelessDialog *self);
 
 void
@@ -158,12 +158,11 @@ security_combo_changed (GtkWidget *combo,
 {
 	NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
 	NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
-	GtkWidget *vbox;
+	GtkWidget *vbox, *sec_widget, *def_widget;
 	GList *elt, *children;
 	GtkTreeIter iter;
 	GtkTreeModel *model;
 	WirelessSecurity *sec = NULL;
-	GtkWidget *sec_widget;
 
 	vbox = glade_xml_get_widget (priv->xml, "security_vbox");
 	g_assert (vbox);
@@ -192,10 +191,34 @@ security_combo_changed (GtkWidget *combo,
 	wireless_security_add_to_size_group (sec, priv->group);
 
 	gtk_container_add (GTK_CONTAINER (vbox), sec_widget);
-	wireless_security_unref (sec);
 
 	/* Re-validate */
 	wireless_security_changed_cb (NULL, sec);
+
+	/* Set focus to the security method's default widget, but only if the
+	 * network name entry should not be focused.
+	 */
+	if (!priv->network_name_focus) {
+		def_widget = glade_xml_get_widget (sec->xml, sec->default_field);
+		if (def_widget)
+			gtk_widget_grab_focus (def_widget);
+	}
+
+	wireless_security_unref (sec);
+}
+
+static void
+security_combo_changed_manually (GtkWidget *combo,
+                                 gpointer user_data)
+{
+	NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
+	NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+
+	/* Flag that the combo was changed manually to allow focus to move
+	 * to the security method's default widget instead of the network name.
+	 */
+	priv->network_name_focus = FALSE;
+	security_combo_changed (combo, user_data);
 }
 
 static GByteArray *
@@ -260,6 +283,11 @@ ssid_entry_changed (GtkWidget *entry, gpointer user_data)
 	gboolean valid = FALSE;
 	GByteArray *ssid;
 
+	/* If the network name entry was touched at all, allow focus to go to
+	 * the default widget of the security method now.
+	 */
+	priv->network_name_focus = FALSE;
+
 	ssid = validate_dialog_ssid (self);
 	if (!ssid)
 		goto out;
@@ -949,10 +977,11 @@ internal_init (NMAWirelessDialog *self,
 		gtk_widget_hide (widget);
 
 		security_combo_focus = TRUE;
+		priv->network_name_focus = FALSE;
 	} else {
 		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);
+		priv->network_name_focus = TRUE;
 	}
 
 	gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, FALSE);
@@ -972,11 +1001,16 @@ internal_init (NMAWirelessDialog *self,
 		return FALSE;
 	}
 
+	security_combo_changed (priv->sec_combo, self);
+	g_signal_connect (G_OBJECT (priv->sec_combo), "changed",
+	                  G_CALLBACK (security_combo_changed_manually), self);
+
 	if (security_combo_focus)
 		gtk_widget_grab_focus (priv->sec_combo);
-
-	security_combo_changed (priv->sec_combo, self);
-	g_signal_connect (G_OBJECT (priv->sec_combo), "changed", G_CALLBACK (security_combo_changed), self);
+	else if (priv->network_name_focus) {
+		widget = glade_xml_get_widget (priv->xml, "network_name_entry");
+		gtk_widget_grab_focus (widget);
+	}
 
 	if (priv->connection) {
 		char *tmp;
diff --git a/src/wireless-security/eap-method-leap.c b/src/wireless-security/eap-method-leap.c
index f11053d..e766488 100644
--- a/src/wireless-security/eap-method-leap.c
+++ b/src/wireless-security/eap-method-leap.c
@@ -139,7 +139,8 @@ eap_method_leap_new (const char *glade_file,
 	                 fill_connection,
 	                 destroy,
 	                 xml,
-	                 widget);
+	                 widget,
+	                 "eap_leap_username_entry");
 
 	widget = glade_xml_get_widget (xml, "eap_leap_username_entry");
 	g_assert (widget);
diff --git a/src/wireless-security/eap-method-peap.c b/src/wireless-security/eap-method-peap.c
index 8eee286..e8e5f6e 100644
--- a/src/wireless-security/eap-method-peap.c
+++ b/src/wireless-security/eap-method-peap.c
@@ -326,7 +326,8 @@ eap_method_peap_new (const char *glade_file,
 	                 fill_connection,
 	                 destroy,
 	                 xml,
-	                 widget);
+	                 widget,
+	                 "eap_peap_anon_identity_entry");
 
 	eap_method_nag_init (EAP_METHOD (method),
 	                     glade_file,
diff --git a/src/wireless-security/eap-method-simple.c b/src/wireless-security/eap-method-simple.c
index 169d487..dfae3c6 100644
--- a/src/wireless-security/eap-method-simple.c
+++ b/src/wireless-security/eap-method-simple.c
@@ -163,7 +163,8 @@ eap_method_simple_new (const char *glade_file,
 	                 fill_connection,
 	                 destroy,
 	                 xml,
-	                 widget);
+	                 widget,
+	                 "eap_simple_username_entry");
 
 	method->type = type;
 
diff --git a/src/wireless-security/eap-method-tls.c b/src/wireless-security/eap-method-tls.c
index 6912427..db0d7c4 100644
--- a/src/wireless-security/eap-method-tls.c
+++ b/src/wireless-security/eap-method-tls.c
@@ -370,7 +370,8 @@ eap_method_tls_new (const char *glade_file,
 	                 fill_connection,
 	                 destroy,
 	                 xml,
-	                 widget);
+	                 widget,
+	                 "eap_tls_identity_entry");
 
 	eap_method_nag_init (EAP_METHOD (method),
 	                     glade_file,
diff --git a/src/wireless-security/eap-method-ttls.c b/src/wireless-security/eap-method-ttls.c
index 043a0e8..6117592 100644
--- a/src/wireless-security/eap-method-ttls.c
+++ b/src/wireless-security/eap-method-ttls.c
@@ -324,7 +324,8 @@ eap_method_ttls_new (const char *glade_file,
 	                 fill_connection,
 	                 destroy,
 	                 xml,
-	                 widget);
+	                 widget,
+	                 "eap_ttls_anon_identity_entry");
 
 	eap_method_nag_init (EAP_METHOD (method),
 	                     glade_file,
diff --git a/src/wireless-security/eap-method.c b/src/wireless-security/eap-method.c
index 60f776e..f382bf7 100644
--- a/src/wireless-security/eap-method.c
+++ b/src/wireless-security/eap-method.c
@@ -198,7 +198,8 @@ eap_method_init (EAPMethod *method,
                  EMFillConnectionFunc fill_connection,
                  EMDestroyFunc destroy,
                  GladeXML *xml,
-                 GtkWidget *ui_widget)
+                 GtkWidget *ui_widget,
+                 const char *default_field)
 {                 
 	method->refcount = 1;
 
@@ -209,6 +210,7 @@ eap_method_init (EAPMethod *method,
 
 	method->xml = xml;
 	method->ui_widget = ui_widget;
+	method->default_field = default_field;
 }
 
 
diff --git a/src/wireless-security/eap-method.h b/src/wireless-security/eap-method.h
index fecae8c..2d517b0 100644
--- a/src/wireless-security/eap-method.h
+++ b/src/wireless-security/eap-method.h
@@ -43,6 +43,7 @@ struct _EAPMethod {
 
 	GladeXML *nag_dialog_xml;
 	char *ca_cert_chooser;
+	const char *default_field;
 	GtkWidget *nag_dialog;
 
 	gboolean ignore_ca_cert;
@@ -86,7 +87,8 @@ void eap_method_init (EAPMethod *method,
                       EMFillConnectionFunc fill_connection,
                       EMDestroyFunc destroy,
                       GladeXML *xml,
-                      GtkWidget *ui_widget);
+                      GtkWidget *ui_widget,
+                      const char *default_field);
 
 GtkFileFilter * eap_method_default_file_chooser_filter_new (gboolean privkey);
 
diff --git a/src/wireless-security/wireless-security.c b/src/wireless-security/wireless-security.c
index a3a60a7..a14b182 100644
--- a/src/wireless-security/wireless-security.c
+++ b/src/wireless-security/wireless-security.c
@@ -139,7 +139,8 @@ wireless_security_init (WirelessSecurity *sec,
                         WSFillConnectionFunc fill_connection,
                         WSDestroyFunc destroy,
                         GladeXML *xml,
-                        GtkWidget *ui_widget)
+                        GtkWidget *ui_widget,
+                        const char *default_field)
 {
 	sec->refcount = 1;
 
@@ -150,6 +151,7 @@ wireless_security_init (WirelessSecurity *sec,
 
 	sec->xml = xml;
 	sec->ui_widget = ui_widget;
+	sec->default_field = default_field;
 }
 
 GtkWidget *
@@ -237,6 +239,7 @@ ws_802_1x_auth_combo_changed (GtkWidget *combo,
 	GtkTreeModel *model;
 	GtkTreeIter iter;
 	GtkWidget *eap_widget;
+	GtkWidget *eap_default_widget = NULL;
 
 	vbox = glade_xml_get_widget (sec->xml, vbox_name);
 	g_assert (vbox);
@@ -258,6 +261,13 @@ ws_802_1x_auth_combo_changed (GtkWidget *combo,
 		eap_method_add_to_size_group (eap, size_group);
 	gtk_container_add (GTK_CONTAINER (vbox), eap_widget);
 
+	/* Refocus the EAP method's default widget */
+	if (eap->default_field) {
+		eap_default_widget = glade_xml_get_widget (eap->xml, eap->default_field);
+		if (eap_default_widget)
+			gtk_widget_grab_focus (eap_default_widget);
+	}
+
 	eap_method_unref (eap);
 
 	wireless_security_changed_cb (combo, WIRELESS_SECURITY (sec));
diff --git a/src/wireless-security/wireless-security.h b/src/wireless-security/wireless-security.h
index c0a0302..99d86ad 100644
--- a/src/wireless-security/wireless-security.h
+++ b/src/wireless-security/wireless-security.h
@@ -44,6 +44,7 @@ struct _WirelessSecurity {
 	GtkWidget *ui_widget;
 	WSChangedFunc changed_notify;
 	gpointer changed_notify_data;
+	const char *default_field;
 
 	WSAddToSizeGroupFunc add_to_size_group;
 	WSFillConnectionFunc fill_connection;
@@ -91,7 +92,8 @@ void wireless_security_init (WirelessSecurity *sec,
                              WSFillConnectionFunc fill_connection,
                              WSDestroyFunc destroy,
                              GladeXML *xml,
-                             GtkWidget *ui_widget);
+                             GtkWidget *ui_widget,
+                             const char *default_field);
 
 void wireless_security_changed_cb (GtkWidget *entry, gpointer user_data);
 
diff --git a/src/wireless-security/ws-dynamic-wep.c b/src/wireless-security/ws-dynamic-wep.c
index a547501..9112fa4 100644
--- a/src/wireless-security/ws-dynamic-wep.c
+++ b/src/wireless-security/ws-dynamic-wep.c
@@ -129,7 +129,8 @@ ws_dynamic_wep_new (const char *glade_file,
 	                        fill_connection,
 	                        destroy,
 	                        xml,
-	                        widget);
+	                        widget,
+	                        NULL);
 
 	WIRELESS_SECURITY (sec)->nag_user = nag_user;
 
diff --git a/src/wireless-security/ws-leap.c b/src/wireless-security/ws-leap.c
index f237a84..00de8cc 100644
--- a/src/wireless-security/ws-leap.c
+++ b/src/wireless-security/ws-leap.c
@@ -147,7 +147,8 @@ ws_leap_new (const char *glade_file, NMConnection *connection)
 	                        fill_connection,
 	                        destroy,
 	                        xml,
-	                        widget);
+	                        widget,
+	                        "leap_username_entry");
 
 	if (connection) {
 		wsec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY));
diff --git a/src/wireless-security/ws-wep-key.c b/src/wireless-security/ws-wep-key.c
index e927796..01bfcfb 100644
--- a/src/wireless-security/ws-wep-key.c
+++ b/src/wireless-security/ws-wep-key.c
@@ -304,7 +304,8 @@ ws_wep_key_new (const char *glade_file,
 	                        fill_connection,
 	                        destroy,
 	                        xml,
-	                        widget);
+	                        widget,
+	                        "wep_key_entry");
 	sec->type = type;
 
 	widget = glade_xml_get_widget (xml, "wep_key_entry");
diff --git a/src/wireless-security/ws-wpa-eap.c b/src/wireless-security/ws-wpa-eap.c
index 2babc2e..f445982 100644
--- a/src/wireless-security/ws-wpa-eap.c
+++ b/src/wireless-security/ws-wpa-eap.c
@@ -124,7 +124,8 @@ ws_wpa_eap_new (const char *glade_file,
 	                        fill_connection,
 	                        destroy,
 	                        xml,
-	                        widget);
+	                        widget,
+	                        NULL);
 
 	WIRELESS_SECURITY (sec)->nag_user = nag_user;
 
diff --git a/src/wireless-security/ws-wpa-psk.c b/src/wireless-security/ws-wpa-psk.c
index a539165..223b16a 100644
--- a/src/wireless-security/ws-wpa-psk.c
+++ b/src/wireless-security/ws-wpa-psk.c
@@ -172,7 +172,8 @@ ws_wpa_psk_new (const char *glade_file, NMConnection *connection)
 	                        fill_connection,
 	                        destroy,
 	                        xml,
-	                        widget);
+	                        widget,
+	                        "wpa_psk_entry");
 
 	widget = glade_xml_get_widget (xml, "wpa_psk_entry");
 	g_assert (widget);



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