2005-12-11 Dan Williams <dcbw@redhat.com>

* Make validation of the key work correctly


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1162 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams 2005-12-11 17:23:29 +00:00
parent f7f136dad2
commit 7c39985801
6 changed files with 68 additions and 29 deletions

View file

@ -1,3 +1,7 @@
2005-12-11 Dan Williams <dcbw@redhat.com>
* Make validation of the key work correctly
2005-12-11 Dan Williams <dcbw@redhat.com>
* Hook more bits of the Other Network Dialog up to the

View file

@ -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 <eskil@eskil.dk>
* Bastien Nocera <hadess@hadess.net> (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);

View file

@ -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);
}

View file

@ -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 */

View file

@ -21,6 +21,7 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <string.h>
#include <glade/glade.h>
@ -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;
}

View file

@ -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);