Commit d41af0af authored by Dan Williams's avatar Dan Williams
Browse files

2004-10-29 Dan Williams <dcbw@redhat.com>

	* panel-applet/NMWirelessAppletOtherNetworksDialog.[ch]
		- New files, implement the "Other wireless network" dialog

	* panel-applet/NMWirelessApplet.c
		- Move "other wireless network" dialog to separate file

	* panel-applet/NMWirelessAppletDbus.[ch]
		- Take key and key_type paramaters for the set_device function

	* panel-applet/essid.glade
		- Add UI bits for encryption settings

	* src/NetworkManagerDbus.c
		- Retrieve key and key_type params for "setActiveDevice" method call
			and pass them on
		- unref AP returned from nm_device_get_best_ap() when needed

	* src/NetworkManagerDevice.c
		- (nm_device_get_best_ap): ref the ap before returning it
		- unref AP returned from nm_device_get_best_ap() when needed
		- (nm_device_activate_wireless): add "ap" parameter so we don't
			need to call nm_device_get_best_ap() here, it was pretty much
			redundant anyway
		- (AP_NEED_KEY): break second link check condition out into separate
			function, and fix segfault when ap->enc_key_source was NULL
		- (nm_device_find_and_use_essid): take key and key_type parameters and
			pass them along to nm_device_wireless_network_exists().  If the
			network does exist, set the passed-in key+key_type on the AP

	* src/NetworkManagerPolicy.c
		- unref AP returned from nm_device_get_best_ap() when needed


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@277 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 8200b37f
2004-10-29 Dan Williams <dcbw@redhat.com>
* panel-applet/NMWirelessAppletOtherNetworksDialog.[ch]
- New files, implement the "Other wireless network" dialog
* panel-applet/NMWirelessApplet.c
- Move "other wireless network" dialog to separate file
* panel-applet/NMWirelessAppletDbus.[ch]
- Take key and key_type paramaters for the set_device function
* panel-applet/essid.glade
- Add UI bits for encryption settings
* src/NetworkManagerDbus.c
- Retrieve key and key_type params for "setActiveDevice" method call
and pass them on
- unref AP returned from nm_device_get_best_ap() when needed
* src/NetworkManagerDevice.c
- (nm_device_get_best_ap): ref the ap before returning it
- unref AP returned from nm_device_get_best_ap() when needed
- (nm_device_activate_wireless): add "ap" parameter so we don't
need to call nm_device_get_best_ap() here, it was pretty much
redundant anyway
- (AP_NEED_KEY): break second link check condition out into separate
function, and fix segfault when ap->enc_key_source was NULL
- (nm_device_find_and_use_essid): take key and key_type parameters and
pass them along to nm_device_wireless_network_exists(). If the
network does exist, set the passed-in key+key_type on the AP
* src/NetworkManagerPolicy.c
- unref AP returned from nm_device_get_best_ap() when needed
2004-10-28 Dan Williams <dcbw@redhat.com>
* src/NetworkManagerUtils.c
......
......@@ -26,6 +26,8 @@ libnm_notification_applet_la_SOURCES = \
NMWirelessApplet.h \
NMWirelessAppletDbus.c \
NMWirelessAppletDbus.h \
NMWirelessAppletOtherNetworkDialog.c \
NMWirelessAppletOtherNetworkDialog.h \
menu-info.c \
menu-info.h \
gtkcellview.c \
......
......@@ -377,14 +377,13 @@ static void nmwa_start_redraw_timeout (NMWirelessApplet *applet)
}
/*
* show_warning_dialog
*
* pop up a warning or error dialog with certain text
*
*/
static void show_warning_dialog (gboolean error, gchar *mesg, ...)
void show_warning_dialog (gboolean error, gchar *mesg, ...)
{
GtkWidget *dialog;
char *tmp;
......@@ -555,7 +554,7 @@ static void nmwa_menu_item_activate (GtkMenuItem *item, gpointer user_data)
{
applet->applet_state = APPLET_STATE_WIRELESS_CONNECTING;
applet->forcing_device = TRUE;
nmwa_dbus_set_device (applet->connection, dev, net);
nmwa_dbus_set_device (applet->connection, dev, net, -1, NULL);
}
}
......@@ -640,173 +639,13 @@ static void nmwa_menu_add_device_item (GtkWidget *menu, NetworkDevice *device, g
gtk_widget_show (menu_item);
}
static void
update_button_cb (GtkWidget *entry,
GtkWidget *button)
{
const char *text;
text = gtk_entry_get_text (GTK_ENTRY (entry));
if (text[0] == '\000')
gtk_widget_set_sensitive (button, FALSE);
else
gtk_widget_set_sensitive (button, TRUE);
}
static GtkTreeModel *
create_wireless_adaptor_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 *network = (NetworkDevice *)(element->data);
g_assert (network);
if (network->type == DEVICE_TYPE_WIRELESS_ETHERNET)
{
GtkTreeIter iter;
const char *network_name;
network_name = network->hal_name ? network->hal_name : network->nm_name;
gtk_list_store_append (retval, &iter);
gtk_list_store_set (retval, &iter,
0, network_name,
1, network,
-1);
}
}
return GTK_TREE_MODEL (retval);
}
/* FIXME: We really should break this dialog into its own file. This function is too long.
*/
static void
custom_essid_item_selected (GtkWidget *menu_item, NMWirelessApplet *applet)
{
gchar *glade_file;
GtkWidget *dialog;
GtkWidget *entry;
GtkWidget *button;
GladeXML *xml;
gint response;
gint n_wireless_interfaces = 0;
GSList *element;
NetworkDevice *default_dev = NULL;
char *label;
glade_file = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_DATADIR,
"NetworkManagerNotification/essid.glade",
FALSE, NULL);
if (!glade_file ||
!g_file_test (glade_file, G_FILE_TEST_IS_REGULAR))
{
show_warning_dialog (TRUE, _("The NetworkManager Applet could not find some required resources (the glade file was not found)."));
return;
}
xml = glade_xml_new (glade_file, NULL, NULL);
g_free (glade_file);
if (xml == NULL)
{
/* Reuse the above string to make the translators less angry. */
show_warning_dialog (TRUE, _("The NetworkManager Applet could not find some required resources (the glade file was not found)."));
return;
}
/* Set up the dialog */
dialog = glade_xml_get_widget (xml, "custom_essid_dialog");
entry = glade_xml_get_widget (xml, "essid_entry");
button = glade_xml_get_widget (xml, "ok_button");
gtk_widget_grab_focus (entry);
gtk_entry_set_text (GTK_ENTRY (entry), "");
gtk_widget_set_sensitive (button, FALSE);
g_signal_connect (entry, "changed", G_CALLBACK (update_button_cb), button);
label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
_("Custom wireless network"),
_("Enter the ESSID of the wireless network to which you wish to connect."));
gtk_label_set_markup (GTK_LABEL (glade_xml_get_widget (xml, "essid_label")), label);
/* Do we have multiple Network cards? */
g_mutex_lock (applet->data_mutex);
for (element = applet->device_list; element; element = element->next)
{
NetworkDevice *dev = (NetworkDevice *)(element->data);
g_assert (dev);
if (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET)
{
if (!default_dev)
{
default_dev = dev;
network_device_ref (default_dev);
}
n_wireless_interfaces++;
}
}
if (n_wireless_interfaces < 1)
{
g_mutex_unlock (applet->data_mutex);
/* Run away!!! */
return;
}
else if (n_wireless_interfaces == 1)
{
gtk_widget_hide (glade_xml_get_widget (xml, "wireless_adaptor_label"));
gtk_widget_hide (glade_xml_get_widget (xml, "wireless_adaptor_combo"));
}
else
{
GtkWidget *combo;
GtkTreeModel *model;
combo = glade_xml_get_widget (xml, "wireless_adaptor_combo");
model = create_wireless_adaptor_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);
}
g_mutex_unlock (applet->data_mutex);
/* Run the dialog */
response = gtk_dialog_run (GTK_DIALOG (dialog));
if (response == GTK_RESPONSE_OK)
{
const char *essid;
essid = gtk_entry_get_text (GTK_ENTRY (entry));
if (essid[0] != '\000')
{
WirelessNetwork *net = wireless_network_new_with_essid (essid);
/* 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...
*/
if (net)
{
applet->applet_state = APPLET_STATE_WIRELESS_CONNECTING;
applet->forcing_device = TRUE;
nmwa_dbus_set_device (applet->connection, default_dev, net);
network_device_unref (default_dev);
wireless_network_unref (net);
}
}
}
gtk_widget_destroy (dialog);
g_object_unref (xml);
nmwa_other_network_dialog_run (applet);
}
static void nmwa_menu_add_custom_essid_item (GtkWidget *menu, NMWirelessApplet *applet)
......
......@@ -148,5 +148,6 @@ typedef struct
NetworkDevice *nmwa_get_device_for_nm_device (NMWirelessApplet *applet, const char *nm_dev);
NMWirelessApplet *nmwa_new (void);
void show_warning_dialog (gboolean error, gchar *mesg, ...);
#endif
......@@ -514,20 +514,27 @@ static char *nmwa_dbus_get_hal_device_info (DBusConnection *connection, const ch
* possibly a specific wireless network too.
*
*/
void nmwa_dbus_set_device (DBusConnection *connection, const NetworkDevice *dev, const WirelessNetwork *network)
void nmwa_dbus_set_device (DBusConnection *connection, const NetworkDevice *dev, const WirelessNetwork *network,
NMEncKeyType key_type, const char *passphrase)
{
DBusMessage *message;
g_return_if_fail (connection != NULL);
g_return_if_fail (dev != NULL);
if ((dev->type == DEVICE_TYPE_WIRED_ETHERNET) && !passphrase && (key_type != -1))
return;
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setActiveDevice")))
{
if ((dev->type == DEVICE_TYPE_WIRELESS_ETHERNET) && network && network->essid)
{
fprintf (stderr, "Forcing device '%s' and network '%s'\n", dev->nm_device, network->essid);
fprintf (stderr, "Forcing device '%s' and network '%s' %s passphrase\n", dev->nm_device, network->essid, passphrase ? "with" : "without");
dbus_message_append_args (message, DBUS_TYPE_STRING, dev->nm_device,
DBUS_TYPE_STRING, network->essid, DBUS_TYPE_INVALID);
DBUS_TYPE_STRING, network->essid,
DBUS_TYPE_STRING, (passphrase ? passphrase : ""),
DBUS_TYPE_INT32, key_type,
DBUS_TYPE_INVALID);
}
else
{
......
......@@ -39,7 +39,8 @@ enum
gpointer nmwa_dbus_worker (gpointer user_data);
void nmwa_dbus_set_device (DBusConnection *connection, const NetworkDevice *dev,
const WirelessNetwork *network);
const WirelessNetwork *network, NMEncKeyType key_type,
const char *passphrase);
WirelessNetwork * wireless_network_new_with_essid (const char *essid);
void wireless_network_unref (WirelessNetwork *net);
......
/* 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.
*
* 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
*/
#include <string.h>
#include <stdlib.h>
#include "config.h"
#include <gnome.h>
#include <libgnomeui/libgnomeui.h>
#include <glade/glade.h>
#include "NetworkManager.h"
#include "NMWirelessApplet.h"
#include "NMWirelessAppletDbus.h"
#include "NMWirelessAppletOtherNetworkDialog.h"
enum NMWAEncryptionKeyTypes
{
KEY_TYPE_128_BIT_PASSPHRASE = 0,
KEY_TYPE_128_BIT_HEX_KEY = 1
};
static void update_button_cb (GtkWidget *entry, GtkWidget *button)
{
const char *text;
text = gtk_entry_get_text (GTK_ENTRY (entry));
if (text[0] == '\000')
gtk_widget_set_sensitive (button, FALSE);
else
gtk_widget_set_sensitive (button, TRUE);
}
static GtkTreeModel *create_wireless_adaptor_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 *network = (NetworkDevice *)(element->data);
g_assert (network);
if (network->type == DEVICE_TYPE_WIRELESS_ETHERNET)
{
GtkTreeIter iter;
const char *network_name;
network_name = network->hal_name ? network->hal_name : network->nm_name;
gtk_list_store_append (retval, &iter);
gtk_list_store_set (retval, &iter,
0, network_name,
1, network,
-1);
}
}
return GTK_TREE_MODEL (retval);
}
/*
* nmwa_other_network_dialog_key_type_combo_changed
*
* Change the text of the passphrase entry label to match the selected
* key type.
*
*/
void nmwa_other_network_dialog_key_type_combo_changed (GtkWidget *key_type_combo, gpointer user_data)
{
GtkLabel *entry_label;
int combo_choice;
GladeXML *xml = (GladeXML *)user_data;
g_return_if_fail (xml != NULL);
entry_label = GTK_LABEL (glade_xml_get_widget (xml, "passphrase_entry_label"));
switch ((combo_choice = gtk_combo_box_get_active (GTK_COMBO_BOX (key_type_combo))))
{
case KEY_TYPE_128_BIT_PASSPHRASE:
gtk_label_set_label (entry_label, _("Passphrase:"));
break;
case KEY_TYPE_128_BIT_HEX_KEY:
gtk_label_set_label (entry_label, _("Key:"));
break;
default:
break;
}
}
/*
* nmwa_other_network_dialog_enc_check_toggled
*
* Enable/disable the encryption-related dialog items based on the
* widget's status.
*
*/
void nmwa_other_network_dialog_enc_check_toggled (GtkWidget *enc_check_button, gpointer user_data)
{
GladeXML *xml = (GladeXML *)user_data;
GtkComboBox *combo;
GtkEntry *entry;
GtkLabel *combo_label;
GtkLabel *entry_label;
gboolean active;
g_return_if_fail (xml != NULL);
combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "key_type_combo"));
combo_label = GTK_LABEL (glade_xml_get_widget (xml, "key_type_combo_label"));
entry = GTK_ENTRY (glade_xml_get_widget (xml, "passphrase_entry"));
entry_label = GTK_LABEL (glade_xml_get_widget (xml, "passphrase_entry_label"));
active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (enc_check_button));
gtk_widget_set_sensitive (GTK_WIDGET (combo), active);
gtk_widget_set_sensitive (GTK_WIDGET (combo_label), active);
gtk_widget_set_sensitive (GTK_WIDGET (entry), active);
gtk_widget_set_sensitive (GTK_WIDGET (entry_label), active);
}
static GtkDialog *nmwa_other_network_dialog_init (GladeXML *xml, NMWirelessApplet *applet, NetworkDevice **def_dev)
{
GtkDialog *dialog = NULL;
GtkWidget *entry;
GtkWidget *button;
GtkComboBox *key_type_combo;
gint n_wireless_interfaces = 0;
GSList *element;
char *label;
GtkCheckButton *enc_check_button;
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 */
dialog = GTK_DIALOG (glade_xml_get_widget (xml, "custom_essid_dialog"));
entry = glade_xml_get_widget (xml, "essid_entry");
button = glade_xml_get_widget (xml, "ok_button");
gtk_widget_grab_focus (entry);
gtk_entry_set_text (GTK_ENTRY (entry), "");
gtk_widget_set_sensitive (button, FALSE);
g_signal_connect (entry, "changed", G_CALLBACK (update_button_cb), button);
label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
_("Custom wireless network"),
_("Enter the ESSID of the wireless network to which you wish to connect."));
gtk_label_set_markup (GTK_LABEL (glade_xml_get_widget (xml, "essid_label")), label);
/* Do we have multiple Network cards? */
g_mutex_lock (applet->data_mutex);
for (element = applet->device_list; element; element = element->next)
{
NetworkDevice *dev = (NetworkDevice *)(element->data);
g_assert (dev);
if (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET)
{
if (!*def_dev)
{
*def_dev = dev;
network_device_ref (*def_dev);
}
n_wireless_interfaces++;
}
}
if (n_wireless_interfaces < 1)
{
g_mutex_unlock (applet->data_mutex);
/* Run away!!! */
return (NULL);
}
else if (n_wireless_interfaces == 1)
{
gtk_widget_hide (glade_xml_get_widget (xml, "wireless_adaptor_label"));
gtk_widget_hide (glade_xml_get_widget (xml, "wireless_adaptor_combo"));
}
else
{
GtkWidget *combo;
GtkTreeModel *model;
combo = glade_xml_get_widget (xml, "wireless_adaptor_combo");
model = create_wireless_adaptor_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);
}
g_mutex_unlock (applet->data_mutex);
/* Uncheck the "use encryption" checkbox and disable relevant encryption widgets */
enc_check_button = GTK_CHECK_BUTTON (glade_xml_get_widget (xml, "use_encryption_checkbox"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enc_check_button), 0);
g_signal_connect (G_OBJECT (enc_check_button), "toggled", GTK_SIGNAL_FUNC (nmwa_other_network_dialog_enc_check_toggled), xml);
nmwa_other_network_dialog_enc_check_toggled (GTK_WIDGET (enc_check_button), xml);
/* Set initial passphrase entry label and key type combo box item */
key_type_combo = GTK_COMBO_BOX (glade_xml_get_widget (xml, "key_type_combo"));
gtk_combo_box_set_active (key_type_combo, 0);
g_signal_connect (G_OBJECT (key_type_combo), "changed", GTK_SIGNAL_FUNC (nmwa_other_network_dialog_key_type_combo_changed), xml);
nmwa_other_network_dialog_key_type_combo_changed (GTK_WIDGET (key_type_combo), xml);
return (dialog);
}
void nmwa_other_network_dialog_run (NMWirelessApplet *applet)
{
gchar *glade_file;
GtkDialog *dialog;
GladeXML *xml;
gint response;
NetworkDevice *def_dev = NULL;
g_return_if_fail (applet != NULL);
glade_file = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_DATADIR,
"NetworkManagerNotification/essid.glade", FALSE, NULL);
if (!glade_file || !g_file_test (glade_file, G_FILE_TEST_IS_REGULAR))
{
show_warning_dialog (TRUE, _("The NetworkManager Applet could not find some required resources (the glade file was not found)."));
return;
}
xml = glade_xml_new (glade_file, NULL, NULL);
g_free (glade_file);
if (xml == NULL)
{
/* Reuse the above string to make the translators less angry. */
show_warning_dialog (TRUE, _("The NetworkManager Applet could not find some required resources (the glade file was not found)."));
return;
}
if (!(dialog = nmwa_other_network_dialog_init (xml, applet, &def_dev)))
return;
/* Run the dialog */
response = gtk_dialog_run (dialog);
if (response == GTK_RESPONSE_OK)
{
GtkEntry *essid_entry;
GtkCheckButton *enc_check_button;
GtkEntry *passphrase_entry;
GtkComboBox *key_type_combo;
const char *essid = NULL;
const char *passphrase = NULL;
int key_type = -1;
essid_entry = GTK_ENTRY (glade_xml_get_widget (xml, "essid_entry"));
essid = gtk_entry_get_text (essid_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));
}
if (essid[0] != '\000')
{
WirelessNetwork *net = wireless_network_new_with_essid (essid);
/* 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...
*/
if (net)
{