mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-21 12:20:43 +02:00
2005-12-11 Dan Williams <dcbw@redhat.com>
* Hook more bits of the Other Network Dialog up to the wireless security manager stuff, and restructure bits of the dialog so there's less code. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1161 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
efc3db77ca
commit
f7f136dad2
9 changed files with 730 additions and 533 deletions
|
|
@ -1,3 +1,9 @@
|
|||
2005-12-11 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* Hook more bits of the Other Network Dialog up to the
|
||||
wireless security manager stuff, and restructure
|
||||
bits of the dialog so there's less code.
|
||||
|
||||
2005-12-10 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* gnome/applet/Makefile.am
|
||||
|
|
|
|||
|
|
@ -58,8 +58,10 @@ nm_applet_SOURCES = \
|
|||
vpn-password-dialog.h \
|
||||
vpn-connection.c \
|
||||
vpn-connection.h \
|
||||
wireless-security-common.c \
|
||||
wireless-security-common.h \
|
||||
wireless-security-manager.c \
|
||||
wireless-security-manager.h \
|
||||
wireless-security-option.c \
|
||||
wireless-security-option.h \
|
||||
$(NULL)
|
||||
|
||||
nm_applet_LDADD = \
|
||||
|
|
|
|||
|
|
@ -46,91 +46,46 @@
|
|||
#include "applet-dbus.h"
|
||||
#include "applet-dbus-devices.h"
|
||||
#include "other-network-dialog.h"
|
||||
#include "wireless-security-common.h"
|
||||
#include "wireless-security-manager.h"
|
||||
#include "wireless-security-option.h"
|
||||
|
||||
|
||||
static void update_button_cb (GtkWidget *widget, GladeXML *xml)
|
||||
static void update_button_cb (GtkWidget *unused, GtkDialog *dialog)
|
||||
{
|
||||
gboolean enable = FALSE;
|
||||
const char * text;
|
||||
GtkButton * button;
|
||||
GtkEntry * network_name_entry;
|
||||
GtkCheckButton * enc_check_button;
|
||||
gboolean enable = FALSE;
|
||||
const char * text;
|
||||
GtkButton * ok_button;
|
||||
GtkEntry * network_name_entry;
|
||||
GladeXML * xml;
|
||||
WirelessSecurityManager * wsm;
|
||||
|
||||
g_return_if_fail (dialog != NULL);
|
||||
|
||||
xml = (GladeXML *) g_object_get_data (G_OBJECT (dialog), "glade-xml");
|
||||
g_return_if_fail (xml != NULL);
|
||||
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"));
|
||||
button = GTK_BUTTON (glade_xml_get_widget (xml, "ok_button"));
|
||||
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)
|
||||
enable = TRUE;
|
||||
|
||||
/* If we're using encryption, validate the settings */
|
||||
/*
|
||||
if (enable && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (enc_check_button)))
|
||||
/* Validate the wireless security choices */
|
||||
if (enable)
|
||||
{
|
||||
GtkComboBox * combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "security_combo"));
|
||||
GtkEntry * passphrase_entry = GTK_ENTRY (glade_xml_get_widget (xml, "passphrase_entry"));
|
||||
const char * passphrase_text = gtk_entry_get_text (passphrase_entry);
|
||||
GtkComboBox * security_combo;
|
||||
|
||||
enable = FALSE;
|
||||
switch (gtk_combo_box_get_active (combo))
|
||||
{
|
||||
case KEY_TYPE_128_BIT_PASSPHRASE:
|
||||
if (strlen (passphrase_text) > 0)
|
||||
enable = TRUE;
|
||||
break;
|
||||
case KEY_TYPE_ASCII_KEY:
|
||||
if ((strlen (passphrase_text) == 5) || (strlen (passphrase_text) == 13))
|
||||
enable = TRUE;
|
||||
break;
|
||||
case KEY_TYPE_HEX_KEY:
|
||||
if ((strlen (passphrase_text) == 10) || (strlen (passphrase_text) == 26))
|
||||
enable = TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
security_combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "security_combo"));
|
||||
enable = wsm_validate_active (wsm, security_combo);
|
||||
}
|
||||
*/
|
||||
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (button), enable);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (ok_button), enable);
|
||||
}
|
||||
|
||||
static GtkTreeModel *create_wireless_adapter_model (NMWirelessApplet *applet)
|
||||
{
|
||||
GtkListStore *retval;
|
||||
GSList *element;
|
||||
|
||||
retval = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
|
||||
|
||||
for (element = applet->device_list; element; element = element->next)
|
||||
{
|
||||
NetworkDevice *dev = (NetworkDevice *)(element->data);
|
||||
|
||||
g_assert (dev);
|
||||
|
||||
/* Ignore unsupported devices */
|
||||
if (!(network_device_get_capabilities (dev) & NM_DEVICE_CAP_NM_SUPPORTED))
|
||||
continue;
|
||||
|
||||
if (network_device_is_wireless (dev))
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
const char *dev_name;
|
||||
|
||||
dev_name = network_device_get_desc (dev) ? network_device_get_desc (dev) : network_device_get_iface (dev);
|
||||
|
||||
gtk_list_store_append (retval, &iter);
|
||||
gtk_list_store_set (retval, &iter, 0, dev_name, 1, dev, -1);
|
||||
}
|
||||
}
|
||||
return GTK_TREE_MODEL (retval);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmwa_other_network_dialog_security_combo_changed
|
||||
*
|
||||
|
|
@ -143,10 +98,9 @@ static void nmwa_other_network_dialog_security_combo_changed (GtkWidget *securit
|
|||
int choice;
|
||||
GtkDialog * dialog = (GtkDialog *) user_data;
|
||||
WirelessSecurityManager * wsm;
|
||||
GtkWidget * ws_notebook;
|
||||
GtkWidget * wso_widget;
|
||||
GladeXML * xml;
|
||||
GtkWidget * vbox;
|
||||
GList * children;
|
||||
GList * elt;
|
||||
|
||||
g_return_if_fail (dialog != NULL);
|
||||
|
|
@ -157,28 +111,101 @@ static void nmwa_other_network_dialog_security_combo_changed (GtkWidget *securit
|
|||
g_return_if_fail (wsm != NULL);
|
||||
|
||||
vbox = GTK_WIDGET (glade_xml_get_widget (xml, "wireless_security_vbox"));
|
||||
children = gtk_container_get_children (GTK_CONTAINER (vbox));
|
||||
for (elt = children; elt; elt = elt->next)
|
||||
{
|
||||
GtkWidget * child = GTK_WIDGET (elt->data);
|
||||
|
||||
if (wsm_is_ws_widget (wsm, child))
|
||||
{
|
||||
/* Remove any previous wireless security widgets */
|
||||
for (elt = gtk_container_get_children (GTK_CONTAINER (vbox)); elt; elt = g_list_next (elt))
|
||||
{
|
||||
GtkWidget * child = GTK_WIDGET (elt->data);
|
||||
|
||||
if (wso_is_wso_widget (child))
|
||||
gtk_container_remove (GTK_CONTAINER (vbox), child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
choice = gtk_combo_box_get_active (GTK_COMBO_BOX (security_combo));
|
||||
ws_notebook = wsm_get_widget_for_index (wsm, choice);
|
||||
if (ws_notebook)
|
||||
gtk_container_add (GTK_CONTAINER (vbox), ws_notebook);
|
||||
/* 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))))
|
||||
gtk_container_add (GTK_CONTAINER (vbox), wso_widget);
|
||||
|
||||
update_button_cb (security_combo, xml);
|
||||
update_button_cb (NULL, dialog);
|
||||
}
|
||||
|
||||
|
||||
static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApplet *applet, NetworkDevice **def_dev, gboolean create_network)
|
||||
#define NAME_COLUMN 0
|
||||
#define DEV_COLUMN 1
|
||||
static GtkTreeModel * create_wireless_adapter_model (NMWirelessApplet *applet)
|
||||
{
|
||||
GtkListStore * model;
|
||||
GSList * elt;
|
||||
|
||||
model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
|
||||
|
||||
for (elt = applet->device_list; elt; elt = g_slist_next (elt))
|
||||
{
|
||||
NetworkDevice *dev = (NetworkDevice *)(elt->data);
|
||||
|
||||
g_assert (dev);
|
||||
|
||||
/* Ignore unsupported devices */
|
||||
if (!(network_device_get_capabilities (dev) & NM_DEVICE_CAP_NM_SUPPORTED))
|
||||
continue;
|
||||
|
||||
if (network_device_is_wireless (dev))
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
const char *name;
|
||||
|
||||
network_device_ref (dev);
|
||||
if (!(name = network_device_get_desc (dev)))
|
||||
name = network_device_get_iface (dev);
|
||||
|
||||
gtk_list_store_append (model, &iter);
|
||||
gtk_list_store_set (model, &iter, NAME_COLUMN, name, DEV_COLUMN, dev, -1);
|
||||
}
|
||||
}
|
||||
|
||||
g_object_ref (G_OBJECT (model));
|
||||
return GTK_TREE_MODEL (model);
|
||||
}
|
||||
|
||||
static void destroy_wireless_adapter_model (GtkTreeModel *model)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
gboolean valid;
|
||||
|
||||
g_return_if_fail (model != NULL);
|
||||
|
||||
valid = gtk_tree_model_get_iter_first (model, &iter);
|
||||
while (valid)
|
||||
{
|
||||
char *str;
|
||||
NetworkDevice *dev;
|
||||
|
||||
gtk_tree_model_get (model, &iter, NAME_COLUMN, &str, DEV_COLUMN, &dev, -1);
|
||||
if (dev)
|
||||
network_device_unref (dev);
|
||||
valid = gtk_tree_model_iter_next (model, &iter);
|
||||
}
|
||||
|
||||
g_object_unref (G_OBJECT (model));
|
||||
}
|
||||
|
||||
|
||||
static const char * get_host_name (void)
|
||||
{
|
||||
#if GLIB_CHECK_VERSION(2,8,0)
|
||||
const char *hostname = g_get_host_name ();
|
||||
#else
|
||||
char hostname[HOST_NAME_MAX] = "hostname";
|
||||
|
||||
gethostname (hostname, HOST_NAME_MAX);
|
||||
hostname[HOST_NAME_MAX-1] = '\n'; /* unspecified whether a truncated hostname is terminated */
|
||||
#endif
|
||||
|
||||
return hostname;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApplet *applet, gboolean create_network)
|
||||
{
|
||||
GtkDialog * dialog = NULL;
|
||||
GtkWidget * network_name_entry;
|
||||
|
|
@ -186,19 +213,22 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple
|
|||
WirelessSecurityManager * wsm;
|
||||
GtkComboBox * security_combo;
|
||||
gint n_wireless_interfaces = 0;
|
||||
GSList * element;
|
||||
char * label;
|
||||
GtkTreeModel * model;
|
||||
gboolean valid;
|
||||
GtkWidget * combo;
|
||||
GtkTreeIter iter;
|
||||
|
||||
g_return_val_if_fail (xml != NULL, NULL);
|
||||
g_return_val_if_fail (applet != NULL, NULL);
|
||||
g_return_val_if_fail (def_dev != NULL, NULL);
|
||||
g_return_val_if_fail (*def_dev == NULL, NULL);
|
||||
|
||||
/* Set up the dialog */
|
||||
if (!(dialog = GTK_DIALOG (glade_xml_get_widget (xml, "other_network_dialog"))))
|
||||
return NULL;
|
||||
|
||||
g_object_set_data (G_OBJECT (dialog), "glade-xml", xml);
|
||||
g_object_set_data (G_OBJECT (dialog), "applet", applet);
|
||||
g_object_set_data (G_OBJECT (dialog), "create-network", GINT_TO_POINTER (create_network));
|
||||
|
||||
network_name_entry = glade_xml_get_widget (xml, "network_name_entry");
|
||||
button = glade_xml_get_widget (xml, "ok_button");
|
||||
|
|
@ -212,20 +242,12 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple
|
|||
|
||||
gtk_widget_grab_focus (network_name_entry);
|
||||
gtk_widget_set_sensitive (button, FALSE);
|
||||
g_signal_connect (network_name_entry, "changed", G_CALLBACK (update_button_cb), xml);
|
||||
g_signal_connect (network_name_entry, "changed", G_CALLBACK (update_button_cb), dialog);
|
||||
|
||||
if (create_network)
|
||||
{
|
||||
gchar *default_essid_text;
|
||||
|
||||
#if GLIB_CHECK_VERSION(2,8,0)
|
||||
const char *hostname = g_get_host_name ();
|
||||
#else
|
||||
char hostname[HOST_NAME_MAX] = "hostname";
|
||||
|
||||
gethostname (hostname, HOST_NAME_MAX);
|
||||
hostname[HOST_NAME_MAX-1] = '\n'; /* unspecified whether a truncated hostname is terminated */
|
||||
#endif
|
||||
gchar * default_essid_text;
|
||||
const char * hostname = get_host_name ();
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (network_name_entry), hostname);
|
||||
gtk_editable_set_position (GTK_EDITABLE (network_name_entry), -1);
|
||||
|
|
@ -253,52 +275,30 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple
|
|||
gtk_label_set_markup (GTK_LABEL (glade_xml_get_widget (xml, "caption_label")), label);
|
||||
g_free (label);
|
||||
|
||||
/* Do we have multiple Network cards? */
|
||||
for (element = applet->device_list; element; element = element->next)
|
||||
model = create_wireless_adapter_model (applet);
|
||||
|
||||
valid = gtk_tree_model_get_iter_first (model, &iter);
|
||||
while (valid)
|
||||
{
|
||||
NetworkDevice *dev = (NetworkDevice *)(element->data);
|
||||
|
||||
g_assert (dev);
|
||||
|
||||
/* Ignore unsupported devices */
|
||||
if (!(network_device_get_capabilities (dev) & NM_DEVICE_CAP_NM_SUPPORTED))
|
||||
continue;
|
||||
|
||||
if (network_device_is_wireless (dev))
|
||||
{
|
||||
if (!*def_dev)
|
||||
{
|
||||
*def_dev = dev;
|
||||
network_device_ref (*def_dev);
|
||||
}
|
||||
n_wireless_interfaces++;
|
||||
}
|
||||
n_wireless_interfaces++;
|
||||
valid = gtk_tree_model_iter_next (model, &iter);
|
||||
}
|
||||
|
||||
/* Can connect to a wireless network if there aren't any wireless devices */
|
||||
if (n_wireless_interfaces < 1)
|
||||
{
|
||||
/* Run away!!! */
|
||||
return NULL;
|
||||
}
|
||||
else if (n_wireless_interfaces == 1)
|
||||
|
||||
combo = glade_xml_get_widget (xml, "wireless_adapter_combo");
|
||||
gtk_combo_box_set_model (GTK_COMBO_BOX (combo), model);
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
|
||||
|
||||
if (n_wireless_interfaces == 1)
|
||||
{
|
||||
gtk_widget_hide (glade_xml_get_widget (xml, "wireless_adapter_label"));
|
||||
gtk_widget_hide (glade_xml_get_widget (xml, "wireless_adapter_combo"));
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkWidget *combo;
|
||||
GtkTreeModel *model;
|
||||
|
||||
combo = glade_xml_get_widget (xml, "wireless_adapter_combo");
|
||||
model = create_wireless_adapter_model (applet);
|
||||
gtk_combo_box_set_model (GTK_COMBO_BOX (combo), model);
|
||||
|
||||
/* Select the first one randomly */
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
|
||||
gtk_widget_hide (combo);
|
||||
}
|
||||
|
||||
wsm = wsm_new (applet);
|
||||
wsm = wsm_new (applet->glade_file);
|
||||
g_object_set_data (G_OBJECT (dialog), "wireless-security-manager", (gpointer) wsm);
|
||||
|
||||
security_combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "security_combo"));
|
||||
|
|
@ -306,101 +306,77 @@ static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApple
|
|||
g_signal_connect (G_OBJECT (security_combo), "changed", GTK_SIGNAL_FUNC (nmwa_other_network_dialog_security_combo_changed), dialog);
|
||||
nmwa_other_network_dialog_security_combo_changed (GTK_WIDGET (security_combo), dialog);
|
||||
|
||||
|
||||
/*
|
||||
passphrase_entry = GTK_ENTRY (glade_xml_get_widget (xml, "passphrase_entry"));
|
||||
g_signal_connect (passphrase_entry, "changed", G_CALLBACK (update_button_cb), xml);
|
||||
*/
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
typedef struct OtherNetworkDialogCBData
|
||||
{
|
||||
NMWirelessApplet *applet;
|
||||
NetworkDevice *dev;
|
||||
GladeXML *xml;
|
||||
gboolean create;
|
||||
} OtherNetworkDialogCBData;
|
||||
|
||||
|
||||
static void nmwa_other_network_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
|
||||
{
|
||||
OtherNetworkDialogCBData *cb_data = (OtherNetworkDialogCBData*) data;
|
||||
GladeXML *xml = cb_data->xml;
|
||||
NetworkDevice *def_dev = cb_data->dev;
|
||||
NMWirelessApplet *applet = cb_data->applet;
|
||||
gboolean create_network = cb_data->create;
|
||||
GladeXML * xml;
|
||||
NMWirelessApplet * applet;
|
||||
gboolean create_network;
|
||||
GtkTreeModel * model;
|
||||
GtkComboBox * combo;
|
||||
WirelessSecurityManager *wsm;
|
||||
|
||||
xml = (GladeXML *) g_object_get_data (G_OBJECT (dialog), "glade-xml");
|
||||
applet = (NMWirelessApplet *) g_object_get_data (G_OBJECT (dialog), "applet");
|
||||
create_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog), "create-network"));
|
||||
|
||||
combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "wireless_adapter_combo"));
|
||||
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
|
||||
|
||||
wsm = g_object_get_data (G_OBJECT (dialog), "wireless-security-manager");
|
||||
g_assert (wsm);
|
||||
|
||||
if (response == GTK_RESPONSE_OK)
|
||||
{
|
||||
GtkEntry *network_name_entry;
|
||||
GtkCheckButton *enc_check_button;
|
||||
GtkEntry *passphrase_entry;
|
||||
GtkComboBox *key_type_combo;
|
||||
const char *essid = NULL;
|
||||
const char *passphrase = NULL;
|
||||
int key_type = -1;
|
||||
GtkEntry * network_name_entry;
|
||||
GtkComboBox * security_combo;
|
||||
const char * essid = NULL;
|
||||
const char * key = NULL;
|
||||
int key_type = -1;
|
||||
|
||||
network_name_entry = GTK_ENTRY (glade_xml_get_widget (xml, "network_name_entry"));
|
||||
essid = gtk_entry_get_text (network_name_entry);
|
||||
|
||||
enc_check_button = GTK_CHECK_BUTTON (glade_xml_get_widget (xml, "use_encryption_checkbox"));
|
||||
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (enc_check_button)))
|
||||
{
|
||||
passphrase_entry = GTK_ENTRY (glade_xml_get_widget (xml, "passphrase_entry"));
|
||||
passphrase = gtk_entry_get_text (passphrase_entry);
|
||||
|
||||
key_type_combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "key_type_combo"));
|
||||
key_type = gtk_combo_box_get_active (GTK_COMBO_BOX (key_type_combo));
|
||||
}
|
||||
security_combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "security_combo"));
|
||||
|
||||
if (essid[0] != '\000')
|
||||
{
|
||||
NMEncKeyType nm_key_type;
|
||||
NMEncKeyType nm_key_type = -1;
|
||||
GtkTreeIter iter;
|
||||
char * str;
|
||||
NetworkDevice *dev;
|
||||
char * passphrase = NULL;
|
||||
|
||||
/* FIXME: allow picking of the wireless device, we currently just
|
||||
* use the first one found in our device list.
|
||||
*
|
||||
* FIXME: default_dev might have gone away by the time the dialog
|
||||
* gets dismissed and we get here...
|
||||
*/
|
||||
switch (key_type)
|
||||
{
|
||||
case KEY_TYPE_128_BIT_PASSPHRASE:
|
||||
nm_key_type = NM_ENC_TYPE_128_BIT_PASSPHRASE;
|
||||
break;
|
||||
case KEY_TYPE_ASCII_KEY:
|
||||
nm_key_type = NM_ENC_TYPE_ASCII_KEY;
|
||||
break;
|
||||
case KEY_TYPE_HEX_KEY:
|
||||
nm_key_type = NM_ENC_TYPE_HEX_KEY;
|
||||
break;
|
||||
default:
|
||||
nm_key_type = NM_ENC_TYPE_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
|
||||
gtk_tree_model_get (model, &iter, NAME_COLUMN, &str, DEV_COLUMN, &dev, -1);
|
||||
|
||||
if (create_network)
|
||||
nmwa_dbus_create_network (applet->connection, def_dev, essid, nm_key_type, passphrase);
|
||||
nmwa_dbus_create_network (applet->connection, dev, essid, nm_key_type, passphrase);
|
||||
else
|
||||
nmwa_dbus_set_device (applet->connection, def_dev, essid, nm_key_type, passphrase);
|
||||
|
||||
network_device_unref (def_dev);
|
||||
nmwa_dbus_set_device (applet->connection, dev, essid, nm_key_type, passphrase);
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_destroy (GTK_WIDGET (dialog));
|
||||
g_object_set_data (G_OBJECT (dialog), "glade-xml", NULL);
|
||||
g_object_unref (xml);
|
||||
g_free (data);
|
||||
|
||||
g_object_set_data (G_OBJECT (dialog), "applet", NULL);
|
||||
g_object_set_data (G_OBJECT (dialog), "create-network", NULL);
|
||||
|
||||
g_object_set_data (G_OBJECT (dialog), "wireless-security-manager", NULL);
|
||||
wsm_free (wsm);
|
||||
|
||||
gtk_widget_destroy (GTK_WIDGET (dialog));
|
||||
destroy_wireless_adapter_model (model);
|
||||
}
|
||||
|
||||
void nmwa_other_network_dialog_run (NMWirelessApplet *applet, gboolean create_network)
|
||||
{
|
||||
GtkDialog * dialog;
|
||||
NetworkDevice * def_dev = NULL;
|
||||
GladeXML * xml;
|
||||
OtherNetworkDialogCBData *cb_data;
|
||||
|
||||
g_return_if_fail (applet != NULL);
|
||||
g_return_if_fail (applet->glade_file != NULL);
|
||||
|
|
@ -411,16 +387,9 @@ void nmwa_other_network_dialog_run (NMWirelessApplet *applet, gboolean create_ne
|
|||
return;
|
||||
}
|
||||
|
||||
if (!(dialog = nmwa_other_network_dialog_init (xml, applet, &def_dev, create_network)))
|
||||
if (!(dialog = nmwa_other_network_dialog_init (xml, applet, create_network)))
|
||||
return;
|
||||
|
||||
cb_data = g_malloc0 (sizeof (OtherNetworkDialogCBData));
|
||||
network_device_ref (def_dev);
|
||||
cb_data->dev = def_dev;
|
||||
cb_data->applet = applet;
|
||||
cb_data->xml = xml;
|
||||
cb_data->create = create_network;
|
||||
|
||||
gtk_window_present (GTK_WINDOW (dialog));
|
||||
g_signal_connect (dialog, "response", G_CALLBACK (nmwa_other_network_dialog_response_cb), (gpointer) cb_data);
|
||||
g_signal_connect (dialog, "response", G_CALLBACK (nmwa_other_network_dialog_response_cb), NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -490,6 +490,7 @@ You have chosen to log in to the wireless network '%s'. If you are sure that th
|
|||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
<property name="mnemonic_widget">network_name_entry</property>
|
||||
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
|
||||
<property name="width_chars">-1</property>
|
||||
<property name="single_line_mode">False</property>
|
||||
|
|
@ -2060,4 +2061,139 @@ WEP 40/128-bit ASCII
|
|||
</child>
|
||||
</widget>
|
||||
|
||||
<widget class="GtkWindow" id="wep_passphrase_subwindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="title" translatable="yes">wep_passphrase_subwindow</property>
|
||||
<property name="type">GTK_WINDOW_TOPLEVEL</property>
|
||||
<property name="window_position">GTK_WIN_POS_NONE</property>
|
||||
<property name="modal">False</property>
|
||||
<property name="resizable">True</property>
|
||||
<property name="destroy_with_parent">False</property>
|
||||
<property name="decorated">True</property>
|
||||
<property name="skip_taskbar_hint">False</property>
|
||||
<property name="skip_pager_hint">False</property>
|
||||
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
|
||||
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
|
||||
<property name="focus_on_map">True</property>
|
||||
<property name="urgency_hint">False</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkNotebook" id="wep_passphrase_notebook">
|
||||
<property name="visible">True</property>
|
||||
<property name="show_tabs">False</property>
|
||||
<property name="show_border">False</property>
|
||||
<property name="tab_pos">GTK_POS_TOP</property>
|
||||
<property name="scrollable">False</property>
|
||||
<property name="enable_popup">False</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hbox8">
|
||||
<property name="border_width">8</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="wep_passphrase_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Key:</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.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">6</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkEntry" id="wep_passphrase_entry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="editable">True</property>
|
||||
<property name="visibility">True</property>
|
||||
<property name="max_length">0</property>
|
||||
<property name="text" translatable="yes"></property>
|
||||
<property name="has_frame">True</property>
|
||||
<property name="invisible_char">*</property>
|
||||
<property name="activates_default">False</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="tab_expand">False</property>
|
||||
<property name="tab_fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label26">
|
||||
<property name="visible">True</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>
|
||||
<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="type">tab</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label27">
|
||||
<property name="visible">True</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>
|
||||
<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="type">tab</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
</glade-interface>
|
||||
|
|
|
|||
|
|
@ -1,316 +0,0 @@
|
|||
/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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 2005 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <string.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#include "wireless-security-common.h"
|
||||
#include "cipher.h"
|
||||
#include "applet.h"
|
||||
#include "cipher-wep-passphrase.h"
|
||||
#include "cipher-wep-hex.h"
|
||||
#include "cipher-wep-ascii.h"
|
||||
#include "cipher-wpa-psk-passphrase.h"
|
||||
|
||||
static const char * wsm_get_glade_file (WirelessSecurityManager *wsm);
|
||||
static NMWirelessApplet * wsm_get_applet (WirelessSecurityManager *wsm);
|
||||
|
||||
|
||||
/* Encapsulates and controls a single wireless security option */
|
||||
struct WirelessSecurityOption
|
||||
{
|
||||
/* Human readable name for the option */
|
||||
char * name;
|
||||
|
||||
/* Corresponding IEEE_802_11_Cipher objects */
|
||||
GSList * ciphers;
|
||||
|
||||
/* Name of the widget for this item */
|
||||
const char * widget_name;
|
||||
|
||||
/* The Glade UI for this option */
|
||||
GladeXML * uixml;
|
||||
};
|
||||
|
||||
struct WirelessSecurityManager
|
||||
{
|
||||
NMWirelessApplet * applet;
|
||||
GSList * options;
|
||||
};
|
||||
|
||||
|
||||
static const char * wso_get_name (WirelessSecurityOption * opt)
|
||||
{
|
||||
g_return_val_if_fail (opt != NULL, NULL);
|
||||
|
||||
return opt->name;
|
||||
}
|
||||
|
||||
#define WS_TAG_MAGIC 0xa7f4
|
||||
#define WS_TAG_NAME "ws-tag"
|
||||
static GtkWidget * wso_get_widget (WirelessSecurityOption *opt)
|
||||
{
|
||||
GtkWidget * widget = NULL;
|
||||
|
||||
g_return_val_if_fail (opt != NULL, NULL);
|
||||
|
||||
/* Some options may not have any UI */
|
||||
if (opt->uixml)
|
||||
{
|
||||
widget = glade_xml_get_widget (opt->uixml, opt->widget_name);
|
||||
g_object_set_data (G_OBJECT (widget), WS_TAG_NAME, GINT_TO_POINTER (WS_TAG_MAGIC));
|
||||
}
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
||||
static void wso_free (WirelessSecurityOption * opt)
|
||||
{
|
||||
g_free (opt->name);
|
||||
if (opt->uixml)
|
||||
g_object_unref (opt->uixml);
|
||||
g_slist_foreach (opt->ciphers, (GFunc) ieee_802_11_cipher_unref, NULL);
|
||||
g_slist_free (opt->ciphers);
|
||||
memset (opt, 0, sizeof (WirelessSecurityOption));
|
||||
g_free (opt);
|
||||
}
|
||||
|
||||
|
||||
static WirelessSecurityOption * wsm_opt_none_init (WirelessSecurityManager *wsm)
|
||||
{
|
||||
WirelessSecurityOption * opt = NULL;
|
||||
|
||||
g_return_val_if_fail (wsm != NULL, NULL);
|
||||
|
||||
opt = g_malloc0 (sizeof (WirelessSecurityOption));
|
||||
opt->name = g_strdup (_("None"));
|
||||
return opt;
|
||||
}
|
||||
|
||||
|
||||
static WirelessSecurityOption * wsm_opt_wep_passphrase_init (WirelessSecurityManager *wsm)
|
||||
{
|
||||
WirelessSecurityOption * opt = NULL;
|
||||
GladeXML * xml = NULL;
|
||||
|
||||
g_return_val_if_fail (wsm != NULL, NULL);
|
||||
|
||||
opt = g_malloc0 (sizeof (WirelessSecurityOption));
|
||||
opt->name = g_strdup (_("WEP Passphrase"));
|
||||
opt->widget_name = "wep_key_notebook";
|
||||
|
||||
if (!(opt->uixml = glade_xml_new (wsm_get_glade_file (wsm), "wep_key_notebook", NULL)))
|
||||
{
|
||||
nmwa_schedule_warning_dialog (wsm_get_applet (wsm),
|
||||
_("The NetworkManager Applet could not find some required resources (the glade file was not found)."));
|
||||
wso_free (opt);
|
||||
return NULL;
|
||||
}
|
||||
opt->ciphers = g_slist_append (opt->ciphers, cipher_wep128_passphrase_new ());
|
||||
return opt;
|
||||
}
|
||||
|
||||
|
||||
static WirelessSecurityOption * wsm_opt_wep_hex_init (WirelessSecurityManager *wsm)
|
||||
{
|
||||
WirelessSecurityOption * opt = NULL;
|
||||
GladeXML * xml = NULL;
|
||||
|
||||
g_return_val_if_fail (wsm != NULL, NULL);
|
||||
|
||||
opt = g_malloc0 (sizeof (WirelessSecurityOption));
|
||||
opt->name = g_strdup (_("WEP 40/128-bit hex"));
|
||||
opt->widget_name = "wep_key_notebook";
|
||||
|
||||
if (!(opt->uixml = glade_xml_new (wsm_get_glade_file (wsm), "wep_key_notebook", NULL)))
|
||||
{
|
||||
nmwa_schedule_warning_dialog (wsm_get_applet (wsm),
|
||||
_("The NetworkManager Applet could not find some required resources (the glade file was not found)."));
|
||||
wso_free (opt);
|
||||
return NULL;
|
||||
}
|
||||
opt->ciphers = g_slist_append (opt->ciphers, cipher_wep128_hex_new ());
|
||||
opt->ciphers = g_slist_append (opt->ciphers, cipher_wep64_hex_new ());
|
||||
return opt;
|
||||
}
|
||||
|
||||
|
||||
static WirelessSecurityOption * wsm_opt_wep_ascii_init (WirelessSecurityManager *wsm)
|
||||
{
|
||||
WirelessSecurityOption * opt = NULL;
|
||||
GladeXML * xml = NULL;
|
||||
|
||||
g_return_val_if_fail (wsm != NULL, NULL);
|
||||
|
||||
opt = g_malloc0 (sizeof (WirelessSecurityOption));
|
||||
opt->name = g_strdup (_("WEP 40/128-bit ASCII"));
|
||||
opt->widget_name = "wep_key_notebook";
|
||||
|
||||
if (!(opt->uixml = glade_xml_new (wsm_get_glade_file (wsm), "wep_key_notebook", NULL)))
|
||||
{
|
||||
nmwa_schedule_warning_dialog (wsm_get_applet (wsm),
|
||||
_("The NetworkManager Applet could not find some required resources (the glade file was not found)."));
|
||||
wso_free (opt);
|
||||
return NULL;
|
||||
}
|
||||
opt->ciphers = g_slist_append (opt->ciphers, cipher_wep128_ascii_new ());
|
||||
opt->ciphers = g_slist_append (opt->ciphers, cipher_wep64_ascii_new ());
|
||||
return opt;
|
||||
}
|
||||
|
||||
|
||||
static WirelessSecurityOption * wsm_opt_wpa_psk_passphrase_init (WirelessSecurityManager *wsm)
|
||||
{
|
||||
WirelessSecurityOption * opt = NULL;
|
||||
GladeXML * xml = NULL;
|
||||
|
||||
g_return_val_if_fail (wsm != NULL, NULL);
|
||||
|
||||
opt = g_malloc0 (sizeof (WirelessSecurityOption));
|
||||
opt->name = g_strdup (_("WPA Personal Passphrase"));
|
||||
opt->widget_name = "wpa_psk_notebook";
|
||||
|
||||
if (!(opt->uixml = glade_xml_new (wsm_get_glade_file (wsm), "wpa_psk_notebook", NULL)))
|
||||
{
|
||||
nmwa_schedule_warning_dialog (wsm_get_applet (wsm),
|
||||
_("The NetworkManager Applet could not find some required resources (the glade file was not found)."));
|
||||
wso_free (opt);
|
||||
return NULL;
|
||||
}
|
||||
opt->ciphers = g_slist_append (opt->ciphers, cipher_wpa_psk_passphrase_new ());
|
||||
return opt;
|
||||
}
|
||||
|
||||
|
||||
WirelessSecurityManager * wsm_new (NMWirelessApplet *applet)
|
||||
{
|
||||
WirelessSecurityManager * wsm = NULL;
|
||||
WirelessSecurityOption * opt;
|
||||
|
||||
g_return_val_if_fail (applet, NULL);
|
||||
|
||||
wsm = g_malloc0 (sizeof (WirelessSecurityManager));
|
||||
wsm->applet = applet;
|
||||
|
||||
/* Add the items */
|
||||
if ((opt = wsm_opt_none_init (wsm)))
|
||||
wsm->options = g_slist_append (wsm->options, opt);
|
||||
|
||||
if ((opt = wsm_opt_wep_passphrase_init (wsm)))
|
||||
wsm->options = g_slist_append (wsm->options, opt);
|
||||
|
||||
if ((opt = wsm_opt_wep_hex_init (wsm)))
|
||||
wsm->options = g_slist_append (wsm->options, opt);
|
||||
|
||||
if ((opt = wsm_opt_wep_ascii_init (wsm)))
|
||||
wsm->options = g_slist_append (wsm->options, opt);
|
||||
|
||||
/*
|
||||
if ((opt = wsm_opt_wpa_psk_passphrase_init (wsm)))
|
||||
wsm->options = g_slist_append (wsm->options, opt);
|
||||
*/
|
||||
|
||||
return wsm;
|
||||
}
|
||||
|
||||
|
||||
void wsm_populate_combo (WirelessSecurityManager *wsm, GtkComboBox *combo)
|
||||
{
|
||||
GtkListStore * model;
|
||||
GSList * elt;
|
||||
|
||||
g_return_if_fail (wsm != NULL);
|
||||
g_return_if_fail (combo != NULL);
|
||||
|
||||
model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
|
||||
|
||||
for (elt = wsm->options; elt; elt = elt->next)
|
||||
{
|
||||
WirelessSecurityOption * opt = (WirelessSecurityOption *) (elt->data);
|
||||
GtkTreeIter iter;
|
||||
|
||||
g_assert (opt);
|
||||
|
||||
gtk_list_store_append (model, &iter);
|
||||
gtk_list_store_set (model, &iter, 0, wso_get_name (opt), 1, opt, -1);
|
||||
}
|
||||
|
||||
gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (model));
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
|
||||
}
|
||||
|
||||
|
||||
GtkWidget * wsm_get_widget_for_index (WirelessSecurityManager *wsm, guint index)
|
||||
{
|
||||
GtkWidget * widget = NULL;
|
||||
WirelessSecurityOption * opt;
|
||||
|
||||
g_return_val_if_fail (wsm != NULL, NULL);
|
||||
g_return_val_if_fail (index >= 0, NULL);
|
||||
g_return_val_if_fail (index < g_slist_length (wsm->options), NULL);
|
||||
|
||||
if ((opt = g_slist_nth_data (wsm->options, index)))
|
||||
widget = wso_get_widget (opt);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
||||
gboolean wsm_is_ws_widget (WirelessSecurityManager *wsm, GtkWidget * widget)
|
||||
{
|
||||
gpointer tag;
|
||||
|
||||
g_return_val_if_fail (wsm != NULL, FALSE);
|
||||
g_return_val_if_fail (widget != NULL, FALSE);
|
||||
|
||||
tag = g_object_get_data (G_OBJECT (widget), WS_TAG_NAME);
|
||||
if (tag && (GPOINTER_TO_INT (tag) == WS_TAG_MAGIC))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static const char * wsm_get_glade_file (WirelessSecurityManager *wsm)
|
||||
{
|
||||
g_return_val_if_fail (wsm != NULL, NULL);
|
||||
g_return_val_if_fail (wsm->applet != NULL, NULL);
|
||||
|
||||
return wsm->applet->glade_file;
|
||||
}
|
||||
|
||||
static NMWirelessApplet * wsm_get_applet (WirelessSecurityManager *wsm)
|
||||
{
|
||||
g_return_val_if_fail (wsm != NULL, NULL);
|
||||
|
||||
return wsm->applet;
|
||||
}
|
||||
|
||||
void wsm_free (WirelessSecurityManager *wsm)
|
||||
{
|
||||
g_return_if_fail (wsm != NULL);
|
||||
|
||||
g_slist_foreach (wsm->options, (GFunc) wso_free, NULL);
|
||||
g_slist_free (wsm->options);
|
||||
memset (wsm, 0, sizeof (WirelessSecurityManager));
|
||||
g_free (wsm);
|
||||
}
|
||||
143
gnome/applet/wireless-security-manager.c
Normal file
143
gnome/applet/wireless-security-manager.c
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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 2005 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <string.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#include "wireless-security-manager.h"
|
||||
#include "wireless-security-option.h"
|
||||
|
||||
|
||||
struct WirelessSecurityManager
|
||||
{
|
||||
char * glade_file;
|
||||
GSList * options;
|
||||
};
|
||||
|
||||
WirelessSecurityManager * wsm_new (const char * glade_file)
|
||||
{
|
||||
WirelessSecurityManager * wsm = NULL;
|
||||
WirelessSecurityOption * opt;
|
||||
|
||||
g_return_val_if_fail (glade_file, NULL);
|
||||
|
||||
wsm = g_malloc0 (sizeof (WirelessSecurityManager));
|
||||
wsm->glade_file = g_strdup (glade_file);
|
||||
|
||||
/* Add the items */
|
||||
if ((opt = wso_none_new (glade_file)))
|
||||
wsm->options = g_slist_append (wsm->options, opt);
|
||||
|
||||
if ((opt = wso_wep_passphrase_new (glade_file)))
|
||||
wsm->options = g_slist_append (wsm->options, opt);
|
||||
|
||||
if ((opt = wso_wep_hex_new (glade_file)))
|
||||
wsm->options = g_slist_append (wsm->options, opt);
|
||||
|
||||
if ((opt = wso_wep_ascii_new (glade_file)))
|
||||
wsm->options = g_slist_append (wsm->options, opt);
|
||||
|
||||
/*
|
||||
if ((opt = wso_wpa_psk_passphrase_new (glade_file)))
|
||||
wsm->options = g_slist_append (wsm->options, opt);
|
||||
*/
|
||||
|
||||
return wsm;
|
||||
}
|
||||
|
||||
#define NAME_COLUMN 0
|
||||
#define OPT_COLUMN 1
|
||||
void wsm_populate_combo (WirelessSecurityManager *wsm, GtkComboBox *combo)
|
||||
{
|
||||
GtkListStore * model;
|
||||
GSList * elt;
|
||||
|
||||
g_return_if_fail (wsm != NULL);
|
||||
g_return_if_fail (combo != NULL);
|
||||
|
||||
model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
|
||||
|
||||
for (elt = wsm->options; elt; elt = elt->next)
|
||||
{
|
||||
WirelessSecurityOption * opt = (WirelessSecurityOption *) (elt->data);
|
||||
GtkTreeIter iter;
|
||||
|
||||
g_assert (opt);
|
||||
|
||||
gtk_list_store_append (model, &iter);
|
||||
gtk_list_store_set (model, &iter, NAME_COLUMN, wso_get_name (opt), OPT_COLUMN, opt, -1);
|
||||
}
|
||||
|
||||
gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (model));
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
|
||||
}
|
||||
|
||||
|
||||
GtkWidget * wsm_get_widget_for_active (WirelessSecurityManager *wsm, GtkComboBox *combo)
|
||||
{
|
||||
WirelessSecurityOption * opt = NULL;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel * model;
|
||||
char * str;
|
||||
|
||||
g_return_val_if_fail (wsm != NULL, NULL);
|
||||
g_return_val_if_fail (combo != NULL, NULL);
|
||||
|
||||
model = gtk_combo_box_get_model (combo);
|
||||
g_assert (model);
|
||||
gtk_combo_box_get_active_iter (combo, &iter);
|
||||
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);
|
||||
}
|
||||
|
||||
gboolean wsm_validate_active (WirelessSecurityManager *wsm, GtkComboBox *combo)
|
||||
{
|
||||
WirelessSecurityOption * opt = NULL;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel * model;
|
||||
char * str;
|
||||
|
||||
g_return_val_if_fail (wsm != NULL, FALSE);
|
||||
g_return_val_if_fail (combo != NULL, FALSE);
|
||||
|
||||
model = gtk_combo_box_get_model (combo);
|
||||
g_assert (model);
|
||||
gtk_combo_box_get_active_iter (combo, &iter);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
void wsm_free (WirelessSecurityManager *wsm)
|
||||
{
|
||||
g_return_if_fail (wsm != NULL);
|
||||
|
||||
g_slist_foreach (wsm->options, (GFunc) wso_free, NULL);
|
||||
g_slist_free (wsm->options);
|
||||
memset (wsm, 0, sizeof (WirelessSecurityManager));
|
||||
g_free (wsm);
|
||||
}
|
||||
|
|
@ -19,20 +19,18 @@
|
|||
* (C) Copyright 2005 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef WIRELESS_SECURITY_COMMON_H
|
||||
#define WIRELESS_SECURITY_COMMON_H
|
||||
#ifndef WIRELESS_SECURITY_MANAGER_H
|
||||
#define WIRELESS_SECURITY_MANAGER_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "applet.h"
|
||||
|
||||
typedef struct WirelessSecurityManager WirelessSecurityManager;
|
||||
typedef struct WirelessSecurityOption WirelessSecurityOption;
|
||||
|
||||
|
||||
WirelessSecurityManager * wsm_new (NMWirelessApplet *applet);
|
||||
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_index (WirelessSecurityManager *wsm, guint index);
|
||||
gboolean wsm_is_ws_widget (WirelessSecurityManager *wsm, GtkWidget * widget);
|
||||
GtkWidget * wsm_get_widget_for_active (WirelessSecurityManager *wsm, GtkComboBox *combo);
|
||||
gboolean wsm_validate_active (WirelessSecurityManager *wsm, GtkComboBox *combo);
|
||||
|
||||
#endif /* WIRELESS_SECURITY_COMMON_H */
|
||||
#endif /* WIRELESS_SECURITY_MANAGER_H */
|
||||
218
gnome/applet/wireless-security-option.c
Normal file
218
gnome/applet/wireless-security-option.c
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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 2005 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <string.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#include "wireless-security-option.h"
|
||||
|
||||
#include "cipher.h"
|
||||
#include "cipher-wep-passphrase.h"
|
||||
#include "cipher-wep-hex.h"
|
||||
#include "cipher-wep-ascii.h"
|
||||
#include "cipher-wpa-psk-passphrase.h"
|
||||
|
||||
#define WS_TAG_MAGIC 0xa7f4
|
||||
#define WS_TAG_NAME "ws-tag"
|
||||
|
||||
struct WirelessSecurityOption
|
||||
{
|
||||
/* Human readable name for the option */
|
||||
char * name;
|
||||
|
||||
/* Corresponding IEEE_802_11_Cipher objects */
|
||||
GSList * ciphers;
|
||||
|
||||
/* Name of the widget for this item */
|
||||
const char * widget_name;
|
||||
|
||||
/* Notebook widget (once created) for this option */
|
||||
GtkWidget * widget;
|
||||
|
||||
/* The Glade UI for this option */
|
||||
GladeXML * uixml;
|
||||
|
||||
/* Glade object names for sub-widgets */
|
||||
GSList * subwidget_names;
|
||||
};
|
||||
|
||||
gboolean wso_is_wso_widget (GtkWidget * widget)
|
||||
{
|
||||
gpointer tag;
|
||||
|
||||
g_return_val_if_fail (widget != NULL, FALSE);
|
||||
|
||||
tag = g_object_get_data (G_OBJECT (widget), WS_TAG_NAME);
|
||||
if (tag && (GPOINTER_TO_INT (tag) == WS_TAG_MAGIC))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
WirelessSecurityOption * wso_none_new (const char *glade_file)
|
||||
{
|
||||
WirelessSecurityOption * opt = NULL;
|
||||
|
||||
g_return_val_if_fail (glade_file != NULL, NULL);
|
||||
|
||||
opt = g_malloc0 (sizeof (WirelessSecurityOption));
|
||||
opt->name = g_strdup (_("None"));
|
||||
return opt;
|
||||
}
|
||||
|
||||
|
||||
WirelessSecurityOption * wso_wep_passphrase_new (const char *glade_file)
|
||||
{
|
||||
WirelessSecurityOption * opt = NULL;
|
||||
GladeXML * xml = NULL;
|
||||
|
||||
g_return_val_if_fail (glade_file != NULL, NULL);
|
||||
|
||||
opt = g_malloc0 (sizeof (WirelessSecurityOption));
|
||||
opt->name = g_strdup (_("WEP Passphrase"));
|
||||
opt->widget_name = "wep_passphrase_notebook";
|
||||
opt->subwidget_names = g_slist_append (opt->subwidget_names, "wep_passphrase_entry");
|
||||
|
||||
if (!(opt->uixml = glade_xml_new (glade_file, opt->widget_name, NULL)))
|
||||
{
|
||||
wso_free (opt);
|
||||
return NULL;
|
||||
}
|
||||
opt->ciphers = g_slist_append (opt->ciphers, cipher_wep128_passphrase_new ());
|
||||
return opt;
|
||||
}
|
||||
|
||||
|
||||
WirelessSecurityOption * wso_wep_hex_new (const char *glade_file)
|
||||
{
|
||||
WirelessSecurityOption * opt = NULL;
|
||||
GladeXML * xml = NULL;
|
||||
|
||||
g_return_val_if_fail (glade_file != NULL, NULL);
|
||||
|
||||
opt = g_malloc0 (sizeof (WirelessSecurityOption));
|
||||
opt->name = g_strdup (_("WEP 40/128-bit hex"));
|
||||
opt->widget_name = "wep_key_notebook";
|
||||
opt->subwidget_names = g_slist_append (opt->subwidget_names, "wep_key_entry");
|
||||
|
||||
if (!(opt->uixml = glade_xml_new (glade_file, opt->widget_name, NULL)))
|
||||
{
|
||||
wso_free (opt);
|
||||
return NULL;
|
||||
}
|
||||
opt->ciphers = g_slist_append (opt->ciphers, cipher_wep128_hex_new ());
|
||||
opt->ciphers = g_slist_append (opt->ciphers, cipher_wep64_hex_new ());
|
||||
return opt;
|
||||
}
|
||||
|
||||
|
||||
WirelessSecurityOption * wso_wep_ascii_new (const char *glade_file)
|
||||
{
|
||||
WirelessSecurityOption * opt = NULL;
|
||||
GladeXML * xml = NULL;
|
||||
|
||||
g_return_val_if_fail (glade_file != NULL, NULL);
|
||||
|
||||
opt = g_malloc0 (sizeof (WirelessSecurityOption));
|
||||
opt->name = g_strdup (_("WEP 40/128-bit ASCII"));
|
||||
opt->widget_name = "wep_key_notebook";
|
||||
opt->subwidget_names = g_slist_append (opt->subwidget_names, "wep_key_entry");
|
||||
|
||||
if (!(opt->uixml = glade_xml_new (glade_file, opt->widget_name, NULL)))
|
||||
{
|
||||
wso_free (opt);
|
||||
return NULL;
|
||||
}
|
||||
opt->ciphers = g_slist_append (opt->ciphers, cipher_wep128_ascii_new ());
|
||||
opt->ciphers = g_slist_append (opt->ciphers, cipher_wep64_ascii_new ());
|
||||
return opt;
|
||||
}
|
||||
|
||||
|
||||
WirelessSecurityOption * wso_wpa_psk_passphrase_new (const char *glade_file)
|
||||
{
|
||||
WirelessSecurityOption * opt = NULL;
|
||||
GladeXML * xml = NULL;
|
||||
|
||||
g_return_val_if_fail (glade_file != NULL, NULL);
|
||||
|
||||
opt = g_malloc0 (sizeof (WirelessSecurityOption));
|
||||
opt->name = g_strdup (_("WPA Personal Passphrase"));
|
||||
opt->widget_name = "wpa_psk_notebook";
|
||||
opt->subwidget_names = g_slist_append (opt->subwidget_names, "wpa_psk_entry");
|
||||
|
||||
if (!(opt->uixml = glade_xml_new (glade_file, opt->widget_name, NULL)))
|
||||
{
|
||||
wso_free (opt);
|
||||
return NULL;
|
||||
}
|
||||
opt->ciphers = g_slist_append (opt->ciphers, cipher_wpa_psk_passphrase_new ());
|
||||
return opt;
|
||||
}
|
||||
|
||||
|
||||
const char * wso_get_name (WirelessSecurityOption * opt)
|
||||
{
|
||||
g_return_val_if_fail (opt != NULL, NULL);
|
||||
|
||||
return opt->name;
|
||||
}
|
||||
|
||||
|
||||
GtkWidget * wso_get_widget (WirelessSecurityOption * opt)
|
||||
{
|
||||
g_return_val_if_fail (opt != NULL, NULL);
|
||||
|
||||
/* Some options may not have any UI */
|
||||
if (!opt->widget && opt->uixml)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
return opt->widget;
|
||||
}
|
||||
|
||||
|
||||
gboolean wso_validate_input (WirelessSecurityOption * opt)
|
||||
{
|
||||
g_return_val_if_fail (opt != NULL, FALSE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void wso_free (WirelessSecurityOption * opt)
|
||||
{
|
||||
g_free (opt->name);
|
||||
if (opt->uixml)
|
||||
g_object_unref (opt->uixml);
|
||||
if (opt->widget)
|
||||
g_object_unref (opt->widget);
|
||||
g_slist_foreach (opt->ciphers, (GFunc) ieee_802_11_cipher_unref, NULL);
|
||||
g_slist_free (opt->ciphers);
|
||||
memset (opt, 0, sizeof (WirelessSecurityOption));
|
||||
g_free (opt);
|
||||
}
|
||||
|
||||
41
gnome/applet/wireless-security-option.h
Normal file
41
gnome/applet/wireless-security-option.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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 2005 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef WIRELESS_SECURITY_OPTION_H
|
||||
#define WIRELESS_SECURITY_OPTION_H
|
||||
|
||||
typedef struct WirelessSecurityOption WirelessSecurityOption;
|
||||
|
||||
WirelessSecurityOption * wso_none_new (const char *glade_file);
|
||||
WirelessSecurityOption * wso_wep_passphrase_new (const char *glade_file);
|
||||
WirelessSecurityOption * wso_wep_hex_new (const char *glade_file);
|
||||
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);
|
||||
gboolean wso_is_wso_widget (GtkWidget * widget);
|
||||
gboolean wso_validate_input (WirelessSecurityOption * opt);
|
||||
void wso_free (WirelessSecurityOption * opt);
|
||||
|
||||
|
||||
|
||||
#endif /* WIRELESS_SECURITY_OPTION_H */
|
||||
Loading…
Add table
Reference in a new issue