diff --git a/ChangeLog b/ChangeLog index f9c0bc387c..9fe139c3d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2005-12-11 Dan Williams + + * Make validation of the key work correctly + 2005-12-11 Dan Williams * Hook more bits of the Other Network Dialog up to the diff --git a/gnome/applet/other-network-dialog.c b/gnome/applet/other-network-dialog.c index a3591d4d59..2246a2ba3b 100644 --- a/gnome/applet/other-network-dialog.c +++ b/gnome/applet/other-network-dialog.c @@ -16,14 +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. * - * This applet used the GNOME Wireless Applet as a skeleton to build from. - * - * GNOME Wireless Applet Authors: - * Eskil Heyn Olsen - * Bastien Nocera (Gnome2 port) - * - * (C) Copyright 2004 Red Hat, Inc. - * (C) Copyright 2001, 2002 Free Software Foundation + * (C) Copyright 2005 Red Hat, Inc. */ #ifdef HAVE_CONFIG_H @@ -53,7 +46,7 @@ static void update_button_cb (GtkWidget *unused, GtkDialog *dialog) { gboolean enable = FALSE; - const char * text; + const char * ssid; GtkButton * ok_button; GtkEntry * network_name_entry; GladeXML * xml; @@ -66,12 +59,10 @@ static void update_button_cb (GtkWidget *unused, GtkDialog *dialog) wsm = (WirelessSecurityManager *) g_object_get_data (G_OBJECT (dialog), "wireless-security-manager"); g_return_if_fail (wsm != NULL); - network_name_entry = GTK_ENTRY (glade_xml_get_widget (xml, "network_name_entry")); - ok_button = GTK_BUTTON (glade_xml_get_widget (xml, "ok_button")); - - /* An ESSID is required */ - text = gtk_entry_get_text (network_name_entry); - if (text && strlen (text) > 0) + /* An SSID is required */ + network_name_entry = GTK_ENTRY (glade_xml_get_widget (xml, "network_name_entry")); + ssid = gtk_entry_get_text (network_name_entry); + if (ssid && strlen (ssid) > 0) enable = TRUE; /* Validate the wireless security choices */ @@ -80,9 +71,10 @@ static void update_button_cb (GtkWidget *unused, GtkDialog *dialog) GtkComboBox * security_combo; security_combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "security_combo")); - enable = wsm_validate_active (wsm, security_combo); + enable = wsm_validate_active (wsm, security_combo, ssid); } + ok_button = GTK_BUTTON (glade_xml_get_widget (xml, "ok_button")); gtk_widget_set_sensitive (GTK_WIDGET (ok_button), enable); } @@ -122,7 +114,8 @@ static void nmwa_other_network_dialog_security_combo_changed (GtkWidget *securit } /* Determine and add the correct wireless security widget to the dialog */ - if ((wso_widget = wsm_get_widget_for_active (wsm, GTK_COMBO_BOX (security_combo)))) + wso_widget = wsm_get_widget_for_active (wsm, GTK_COMBO_BOX (security_combo), GTK_SIGNAL_FUNC (update_button_cb), dialog); + if (wso_widget) gtk_container_add (GTK_CONTAINER (vbox), wso_widget); update_button_cb (NULL, dialog); diff --git a/gnome/applet/wireless-security-manager.c b/gnome/applet/wireless-security-manager.c index 3fd54b49ed..61f4d5ee14 100644 --- a/gnome/applet/wireless-security-manager.c +++ b/gnome/applet/wireless-security-manager.c @@ -93,7 +93,8 @@ void wsm_populate_combo (WirelessSecurityManager *wsm, GtkComboBox *combo) } -GtkWidget * wsm_get_widget_for_active (WirelessSecurityManager *wsm, GtkComboBox *combo) +GtkWidget * wsm_get_widget_for_active (WirelessSecurityManager *wsm, GtkComboBox *combo, + GtkSignalFunc validate_cb, gpointer user_data) { WirelessSecurityOption * opt = NULL; GtkTreeIter iter; @@ -109,10 +110,10 @@ GtkWidget * wsm_get_widget_for_active (WirelessSecurityManager *wsm, GtkComboBox gtk_tree_model_get (model, &iter, NAME_COLUMN, &str, OPT_COLUMN, &opt, -1); g_return_val_if_fail (opt != NULL, NULL); - return wso_get_widget (opt); + return wso_get_widget (opt, validate_cb, user_data); } -gboolean wsm_validate_active (WirelessSecurityManager *wsm, GtkComboBox *combo) +gboolean wsm_validate_active (WirelessSecurityManager *wsm, GtkComboBox *combo, const char *ssid) { WirelessSecurityOption * opt = NULL; GtkTreeIter iter; @@ -128,7 +129,7 @@ gboolean wsm_validate_active (WirelessSecurityManager *wsm, GtkComboBox *combo) gtk_tree_model_get (model, &iter, NAME_COLUMN, &str, OPT_COLUMN, &opt, -1); g_return_val_if_fail (opt != NULL, FALSE); - return wso_validate_input (opt); + return wso_validate_input (opt, ssid); } diff --git a/gnome/applet/wireless-security-manager.h b/gnome/applet/wireless-security-manager.h index 00188e42ea..17cdc5bfaf 100644 --- a/gnome/applet/wireless-security-manager.h +++ b/gnome/applet/wireless-security-manager.h @@ -30,7 +30,8 @@ typedef struct WirelessSecurityManager WirelessSecurityManager; WirelessSecurityManager * wsm_new (const char * glade_file); void wsm_free (WirelessSecurityManager *wsm); void wsm_populate_combo (WirelessSecurityManager *wsm, GtkComboBox *combo); -GtkWidget * wsm_get_widget_for_active (WirelessSecurityManager *wsm, GtkComboBox *combo); -gboolean wsm_validate_active (WirelessSecurityManager *wsm, GtkComboBox *combo); +GtkWidget * wsm_get_widget_for_active (WirelessSecurityManager *wsm, GtkComboBox *combo, + GtkSignalFunc validate_cb, gpointer user_data); +gboolean wsm_validate_active (WirelessSecurityManager *wsm, GtkComboBox *combo, const char *ssid); #endif /* WIRELESS_SECURITY_MANAGER_H */ diff --git a/gnome/applet/wireless-security-option.c b/gnome/applet/wireless-security-option.c index ccb7153b09..743c861c93 100644 --- a/gnome/applet/wireless-security-option.c +++ b/gnome/applet/wireless-security-option.c @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -179,27 +180,66 @@ const char * wso_get_name (WirelessSecurityOption * opt) } -GtkWidget * wso_get_widget (WirelessSecurityOption * opt) +GtkWidget * wso_get_widget (WirelessSecurityOption * opt, GtkSignalFunc validate_cb, gpointer user_data) { g_return_val_if_fail (opt != NULL, NULL); /* Some options may not have any UI */ if (!opt->widget && opt->uixml) { + GSList * elt; + + /* Grab our UI widget and tag it as a WSO widget */ opt->widget = glade_xml_get_widget (opt->uixml, opt->widget_name); g_object_ref (G_OBJECT (opt->widget)); g_object_set_data (G_OBJECT (opt->widget), WS_TAG_NAME, GINT_TO_POINTER (WS_TAG_MAGIC)); + + /* Set the caller's validate callback on any sub-widgets we care about */ + for (elt = opt->subwidget_names; elt; elt = g_slist_next (elt)) + { + const char * widget_name = (const char *) (elt->data); + GtkWidget * widget; + + if ((widget = glade_xml_get_widget (opt->uixml, widget_name))) + g_signal_connect (G_OBJECT (widget), "changed", validate_cb, user_data); + } } return opt->widget; } -gboolean wso_validate_input (WirelessSecurityOption * opt) +gboolean wso_validate_input (WirelessSecurityOption * opt, const char *ssid) { - g_return_val_if_fail (opt != NULL, FALSE); + GSList * elt; - return TRUE; + g_return_val_if_fail (opt != NULL, FALSE); + g_return_val_if_fail (ssid != NULL, FALSE); + + if (!opt->subwidget_names) + return TRUE; + + for (elt = opt->subwidget_names; elt; elt = g_slist_next (elt)) + { + const char * widget_name = (const char *) (elt->data); + GtkWidget * widget; + + if ((widget = glade_xml_get_widget (opt->uixml, widget_name))) + { + const char * input = gtk_entry_get_text (GTK_ENTRY (widget)); + GSList * cipher_elt; + + /* Try each of our ciphers in turn, if one validates that's enough */ + for (cipher_elt = opt->ciphers; cipher_elt; cipher_elt = g_slist_next (cipher_elt)) + { + IEEE_802_11_Cipher * cipher = (IEEE_802_11_Cipher *) (cipher_elt->data); + if (ieee_802_11_cipher_validate (cipher, ssid, input) == 0) + return TRUE; + } + } + } + + return FALSE; } diff --git a/gnome/applet/wireless-security-option.h b/gnome/applet/wireless-security-option.h index 9160975f87..3ee3c06303 100644 --- a/gnome/applet/wireless-security-option.h +++ b/gnome/applet/wireless-security-option.h @@ -31,9 +31,9 @@ WirelessSecurityOption * wso_wep_ascii_new (const char *glade_file); WirelessSecurityOption * wso_wpa_psk_passphrase_new (const char *glade_file); const char * wso_get_name (WirelessSecurityOption * opt); -GtkWidget * wso_get_widget (WirelessSecurityOption * opt); +GtkWidget * wso_get_widget (WirelessSecurityOption * opt, GtkSignalFunc validate_cb, gpointer user_data); gboolean wso_is_wso_widget (GtkWidget * widget); -gboolean wso_validate_input (WirelessSecurityOption * opt); +gboolean wso_validate_input (WirelessSecurityOption * opt, const char * ssid); void wso_free (WirelessSecurityOption * opt);