network-manager-applet r621 - in trunk: . src src/connection-editor src/wireless-security



Author: dcbw
Date: Sun Mar 30 15:31:26 2008
New Revision: 621
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=621&view=rev

Log:
2008-03-30  Dan Williams  <dcbw redhat com>

	* src/applet.glade
		- Add combo for specifying WEP key index

	* src/wireless-security/wireless-security.c
	  src/wireless-security/wireless-security.h
		- (ws_wep_fill_connection): fold into ws-wep-key.c's fill_connection()
			which is now it's only user

	* src/wireless-security/ws-wep-key.c
	  src/wireless-security/ws-wep-key.h
		- (key_index_combo_changed_cb): new function; save current key to its
			index
		- (destroy): zero out keys
		- (fill_connection): fold in functionality of ws_wep_fill_connection(),
			handle WEP key index too
		- (ws_wep_key_new): select the WEP key index

	* src/wireless-dialog.c
		- (security_combo_init): only get default type for security if security
			is specified

	* src/connection-editor/page-wireless-security.c
		- (ce_page_wireless_security_new): only get default type for security
			if security is specified



Modified:
   trunk/ChangeLog
   trunk/src/applet.glade
   trunk/src/connection-editor/page-wireless-security.c
   trunk/src/wireless-dialog.c
   trunk/src/wireless-security/wireless-security.c
   trunk/src/wireless-security/wireless-security.h
   trunk/src/wireless-security/ws-wep-key.c
   trunk/src/wireless-security/ws-wep-key.h

Modified: trunk/src/applet.glade
==============================================================================
--- trunk/src/applet.glade	(original)
+++ trunk/src/applet.glade	Sun Mar 30 15:31:26 2008
@@ -1072,6 +1072,7 @@
 
 		      <child>
 			<widget class="GtkLabel" id="label-security-label">
+			  <property name="can_focus">True</property>
 			  <property name="label" translatable="yes">Security:</property>
 			  <property name="use_underline">False</property>
 			  <property name="use_markup">False</property>
@@ -1235,7 +1236,7 @@
       <child>
 	<widget class="GtkTable" id="table6">
 	  <property name="visible">True</property>
-	  <property name="n_rows">3</property>
+	  <property name="n_rows">4</property>
 	  <property name="n_columns">2</property>
 	  <property name="homogeneous">False</property>
 	  <property name="row_spacing">6</property>
@@ -1275,7 +1276,7 @@
 	      <property name="can_focus">True</property>
 	      <property name="editable">True</property>
 	      <property name="visibility">False</property>
-	      <property name="max_length">26</property>
+	      <property name="max_length">0</property>
 	      <property name="text" translatable="yes"></property>
 	      <property name="has_frame">True</property>
 	      <property name="activates_default">False</property>
@@ -1290,9 +1291,9 @@
 	  </child>
 
 	  <child>
-	    <widget class="GtkLabel" id="auth_method_label">
+	    <widget class="GtkLabel" id="label31">
 	      <property name="visible">True</property>
-	      <property name="label" translatable="yes">Authentication:</property>
+	      <property name="label" translatable="yes"></property>
 	      <property name="use_underline">False</property>
 	      <property name="use_markup">False</property>
 	      <property name="justify">GTK_JUSTIFY_LEFT</property>
@@ -1310,17 +1311,39 @@
 	    <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">1</property>
+	      <property name="bottom_attach">2</property>
 	      <property name="x_options">fill</property>
 	      <property name="y_options"></property>
 	    </packing>
 	  </child>
 
 	  <child>
-	    <widget class="GtkLabel" id="label31">
+	    <widget class="GtkCheckButton" id="show_checkbutton">
 	      <property name="visible">True</property>
-	      <property name="label" translatable="yes"></property>
+	      <property name="can_focus">True</property>
+	      <property name="label" translatable="yes">Show key</property>
+	      <property name="use_underline">True</property>
+	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
+	      <property name="active">False</property>
+	      <property name="inconsistent">False</property>
+	      <property name="draw_indicator">True</property>
+	    </widget>
+	    <packing>
+	      <property name="left_attach">1</property>
+	      <property name="right_attach">2</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="GtkLabel" id="auth_method_label">
+	      <property name="visible">True</property>
+	      <property name="label" translatable="yes">Authentication:</property>
 	      <property name="use_underline">False</property>
 	      <property name="use_markup">False</property>
 	      <property name="justify">GTK_JUSTIFY_LEFT</property>
@@ -1338,40 +1361,66 @@
 	    <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">3</property>
+	      <property name="bottom_attach">4</property>
 	      <property name="x_options">fill</property>
 	      <property name="y_options"></property>
 	    </packing>
 	  </child>
 
 	  <child>
-	    <widget class="GtkCheckButton" id="show_checkbutton">
+	    <widget class="GtkComboBox" id="auth_method_combo">
 	      <property name="visible">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="label" translatable="yes">Show key</property>
-	      <property name="use_underline">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="items" translatable="yes">Open System
+Shared Key</property>
+	      <property name="add_tearoffs">False</property>
 	      <property name="focus_on_click">True</property>
-	      <property name="active">False</property>
-	      <property name="inconsistent">False</property>
-	      <property name="draw_indicator">True</property>
 	    </widget>
 	    <packing>
 	      <property name="left_attach">1</property>
 	      <property name="right_attach">2</property>
-	      <property name="top_attach">1</property>
-	      <property name="bottom_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="key_index_label">
+	      <property name="visible">True</property>
+	      <property name="label" translatable="yes">WEP Index:</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">2</property>
+	      <property name="bottom_attach">3</property>
 	      <property name="x_options">fill</property>
 	      <property name="y_options"></property>
 	    </packing>
 	  </child>
 
 	  <child>
-	    <widget class="GtkComboBox" id="auth_method_combo">
+	    <widget class="GtkComboBox" id="key_index_combo">
 	      <property name="visible">True</property>
-	      <property name="items" translatable="yes">Open System
-Shared Key</property>
+	      <property name="items" translatable="yes">1 (Default)
+2
+3
+4</property>
 	      <property name="add_tearoffs">False</property>
 	      <property name="focus_on_click">True</property>
 	    </widget>
@@ -1380,6 +1429,7 @@
 	      <property name="right_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">fill</property>
 	    </packing>
 	  </child>

Modified: trunk/src/connection-editor/page-wireless-security.c
==============================================================================
--- trunk/src/connection-editor/page-wireless-security.c	(original)
+++ trunk/src/connection-editor/page-wireless-security.c	Sun Mar 30 15:31:26 2008
@@ -239,7 +239,8 @@
 
 	s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (connection, 
 	                                               NM_TYPE_SETTING_WIRELESS_SECURITY));
-	default_type = get_default_type_for_security (s_wireless_sec);
+	if (s_wireless_sec && s_wireless->security && !strcmp (s_wireless->security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME))
+		default_type = get_default_type_for_security (s_wireless_sec);
 
 	sec_model = gtk_list_store_new (2, G_TYPE_STRING, wireless_security_get_g_type ());
 

Modified: trunk/src/wireless-dialog.c
==============================================================================
--- trunk/src/wireless-dialog.c	(original)
+++ trunk/src/wireless-dialog.c	Sun Mar 30 15:31:26 2008
@@ -458,7 +458,8 @@
 
 		wsec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (connection, 
 										NM_TYPE_SETTING_WIRELESS_SECURITY));
-		default_type = get_default_type_for_security (wsec, ap_flags, dev_caps);
+		if (wsec && s_wireless->security && !strcmp (s_wireless->security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME))
+			default_type = get_default_type_for_security (wsec, ap_flags, dev_caps);
 	}
 
 	sec_model = gtk_list_store_new (2, G_TYPE_STRING, wireless_security_get_g_type ());

Modified: trunk/src/wireless-security/wireless-security.c
==============================================================================
--- trunk/src/wireless-security/wireless-security.c	(original)
+++ trunk/src/wireless-security/wireless-security.c	Sun Mar 30 15:31:26 2008
@@ -131,42 +131,6 @@
 }
 
 void
-ws_wep_fill_connection (NMConnection *connection,
-                        const char *key,
-                        int auth_alg)
-{
-	NMSettingWireless *s_wireless;
-	NMSettingWirelessSecurity *s_wireless_sec;
-
-	s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
-	g_assert (s_wireless);
-
-	if (s_wireless->security)
-		g_free (s_wireless->security);
-	s_wireless->security = g_strdup (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
-
-	/* Blow away the old security setting by adding a clear one */
-	s_wireless_sec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
-	nm_connection_add_setting (connection, (NMSetting *) s_wireless_sec);
-
-	s_wireless_sec->wep_key0 = g_strdup (key);
-	s_wireless_sec->key_mgmt = g_strdup ("none");
-	s_wireless_sec->wep_tx_keyidx = 0;
-
-	switch (auth_alg) {
-		case 0:
-			s_wireless_sec->auth_alg = g_strdup ("open");
-			break;
-		case 1:
-			s_wireless_sec->auth_alg = g_strdup ("shared");
-			break;
-		default:
-			g_assert_not_reached ();
-			break;
-	}
-}
-
-void
 wireless_security_init (WirelessSecurity *sec,
                         WSValidateFunc validate,
                         WSAddToSizeGroupFunc add_to_size_group,

Modified: trunk/src/wireless-security/wireless-security.h
==============================================================================
--- trunk/src/wireless-security/wireless-security.h	(original)
+++ trunk/src/wireless-security/wireless-security.h	Sun Mar 30 15:31:26 2008
@@ -97,10 +97,6 @@
 
 void wireless_security_changed_cb (GtkWidget *entry, gpointer user_data);
 
-void ws_wep_fill_connection (NMConnection *connection,
-                             const char *key,
-                             gint auth_alg);
-
 void ws_wpa_fill_default_ciphers (NMConnection *connection);
 
 #define AUTH_NAME_COLUMN   0

Modified: trunk/src/wireless-security/ws-wep-key.c
==============================================================================
--- trunk/src/wireless-security/ws-wep-key.c	(original)
+++ trunk/src/wireless-security/ws-wep-key.c	Sun Mar 30 15:31:26 2008
@@ -23,6 +23,9 @@
 #include <ctype.h>
 #include <string.h>
 
+#include <nm-setting-wireless.h>
+#include <nm-setting-wireless-security.h>
+
 #include "wireless-security.h"
 #include "utils.h"
 #include "gnome-keyring-md5.h"
@@ -42,9 +45,38 @@
 }
 
 static void
+key_index_combo_changed_cb (GtkWidget *combo, WirelessSecurity *parent)
+{
+	WirelessSecurityWEPKey *sec = (WirelessSecurityWEPKey *) parent;
+	GtkWidget *entry;
+	const char *key;
+	int key_index;
+
+	/* Save WEP key for old key index */
+	entry = glade_xml_get_widget (parent->xml, "wep_key_entry");
+	key = gtk_entry_get_text (GTK_ENTRY (entry));
+	if (key)
+		strcpy (sec->keys[sec->cur_index], key);
+	else
+		memset (sec->keys[sec->cur_index], 0, sizeof (sec->keys[sec->cur_index]));
+
+	key_index = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
+	g_return_if_fail (key_index < 3);
+	g_return_if_fail (key_index > 0);
+
+	/* Populate entry with key from new index */
+	gtk_entry_set_text (GTK_ENTRY (entry), sec->keys[key_index]);
+	sec->cur_index = key_index;
+}
+
+static void
 destroy (WirelessSecurity *parent)
 {
 	WirelessSecurityWEPKey *sec = (WirelessSecurityWEPKey *) parent;
+	int i;
+
+	for (i = 0; i < 4; i++)
+		memset (sec->keys[i], 0, sizeof (sec->keys[i]));
 
 	g_slice_free (WirelessSecurityWEPKey, sec);
 }
@@ -95,6 +127,9 @@
 
 	widget = glade_xml_get_widget (parent->xml, "wep_key_label");
 	gtk_size_group_add_widget (group, widget);
+
+	widget = glade_xml_get_widget (parent->xml, "key_index_label");
+	gtk_size_group_add_widget (group, widget);
 }
 
 static char *
@@ -125,28 +160,64 @@
 fill_connection (WirelessSecurity *parent, NMConnection *connection)
 {
 	WirelessSecurityWEPKey *sec = (WirelessSecurityWEPKey *) parent;
+	NMSettingWireless *s_wireless;
+	NMSettingWirelessSecurity *s_wireless_sec;
 	GtkWidget *widget;
 	gint auth_alg;
 	const char *key;
-	char *hashed;
+	char *hashed = NULL;
+	int i;
 
 	widget = glade_xml_get_widget (parent->xml, "auth_method_combo");
 	auth_alg = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
 
 	widget = glade_xml_get_widget (parent->xml, "wep_key_entry");
 	key = gtk_entry_get_text (GTK_ENTRY (widget));
+	strcpy (sec->keys[sec->cur_index], key);
 
-	if (sec->type == WEP_KEY_TYPE_HEX) {
-		ws_wep_fill_connection (connection, key, auth_alg);
-	} else if (sec->type == WEP_KEY_TYPE_ASCII) {
-		hashed = utils_bin2hexstr (key, strlen (key), strlen (key) * 2);
-		ws_wep_fill_connection (connection, hashed, auth_alg);
-		g_free (hashed);
-	} else if (sec->type == WEP_KEY_TYPE_PASSPHRASE) {
-		hashed = wep128_passphrase_hash (key);
-		ws_wep_fill_connection (connection, hashed, auth_alg);
-		g_free (hashed);
+	s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
+	g_assert (s_wireless);
+
+	if (s_wireless->security)
+		g_free (s_wireless->security);
+	s_wireless->security = g_strdup (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
+
+	/* Blow away the old security setting by adding a clear one */
+	s_wireless_sec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
+	nm_connection_add_setting (connection, (NMSetting *) s_wireless_sec);
+
+	s_wireless_sec->key_mgmt = g_strdup ("none");
+	s_wireless_sec->wep_tx_keyidx = sec->cur_index;
+
+	for (i = 0; i < 4; i++) {
+		int key_len = strlen (sec->keys[i]);
+
+		if (!key_len)
+			continue;
+
+		if (sec->type == WEP_KEY_TYPE_HEX)
+			hashed = g_strdup (sec->keys[i]);
+		else if (sec->type == WEP_KEY_TYPE_ASCII)
+			hashed = utils_bin2hexstr (sec->keys[i], key_len, key_len * 2);
+		else if (sec->type == WEP_KEY_TYPE_PASSPHRASE)
+			hashed = wep128_passphrase_hash (sec->keys[i]);
+
+		if (i == 0)
+			s_wireless_sec->wep_key0 = hashed;
+		else if (i == 1)
+			s_wireless_sec->wep_key1 = hashed;
+		else if (i == 2)
+			s_wireless_sec->wep_key2 = hashed;
+		else if (i == 3)
+			s_wireless_sec->wep_key3 = hashed;
 	}
+
+	if (auth_alg == 0)
+		s_wireless_sec->auth_alg = g_strdup ("open");
+	else if (auth_alg == 1)
+		s_wireless_sec->auth_alg = g_strdup ("shared");
+	else
+		g_assert_not_reached ();
 }
 
 static void
@@ -200,6 +271,8 @@
 	WirelessSecurityWEPKey *sec;
 	GtkWidget *widget;
 	GladeXML *xml;
+	NMSettingWirelessSecurity *s_wsec;
+	guint8 default_key_idx = 0;
 
 	g_return_val_if_fail (glade_file != NULL, NULL);
 
@@ -244,6 +317,18 @@
 	else if (sec->type == WEP_KEY_TYPE_PASSPHRASE)
 		gtk_entry_set_max_length (GTK_ENTRY (widget), 64);
 
+	widget = glade_xml_get_widget (xml, "key_index_combo");
+	if (connection) {
+		s_wsec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY));
+		if (s_wsec)
+			default_key_idx = s_wsec->wep_tx_keyidx;
+	}
+	gtk_combo_box_set_active (GTK_COMBO_BOX (widget), default_key_idx);
+	sec->cur_index = default_key_idx;
+	g_signal_connect (G_OBJECT (widget), "changed",
+	                  (GCallback) key_index_combo_changed_cb,
+	                  sec);
+
 	widget = glade_xml_get_widget (xml, "show_checkbutton");
 	g_assert (widget);
 	g_signal_connect (G_OBJECT (widget), "toggled",

Modified: trunk/src/wireless-security/ws-wep-key.h
==============================================================================
--- trunk/src/wireless-security/ws-wep-key.h	(original)
+++ trunk/src/wireless-security/ws-wep-key.h	Sun Mar 30 15:31:26 2008
@@ -32,6 +32,8 @@
 	struct _WirelessSecurity parent;
 
 	WEPKeyType type;
+	char keys[4][65];
+	guint8 cur_index;
 } WirelessSecurityWEPKey;
 
 WirelessSecurityWEPKey * ws_wep_key_new (const char *glade_file,



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