[network-manager-netbook] Implement support for hidden APs.
- From: Tambet Ingo <tambeti src gnome org>
- To: svn-commits-list gnome org
- Subject: [network-manager-netbook] Implement support for hidden APs.
- Date: Thu, 11 Jun 2009 08:52:01 -0400 (EDT)
commit c24a619195bb27784a216ba130c23ac965fdd34c
Author: Tambet Ingo <tambet gmail com>
Date: Thu Jun 11 15:50:31 2009 +0300
Implement support for hidden APs.
Lots of random bug fixes concerning wireless dialog.
---
TODO | 2 +-
src/network-manager-netbook.glade | 36 +-
src/nmn-new-connection.c | 83 ++-
src/nmn-wifi-item.c | 125 ++--
src/wireless-dialog.c | 1810 ++++++++++++++++++-------------------
src/wireless-dialog.h | 27 +-
6 files changed, 1061 insertions(+), 1022 deletions(-)
diff --git a/TODO b/TODO
index 51662ac..8b13789 100644
--- a/TODO
+++ b/TODO
@@ -1 +1 @@
-* Hidden APs are not supported at all.
+
diff --git a/src/network-manager-netbook.glade b/src/network-manager-netbook.glade
index 87e865e..f1e4d18 100644
--- a/src/network-manager-netbook.glade
+++ b/src/network-manager-netbook.glade
@@ -46,48 +46,22 @@
</packing>
</child>
<child>
- <object class="GtkHBox" id="hbox3">
+ <object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkLabel" id="label9">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Hidden network name:</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="new_wifi_entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="position">1</property>
- </packing>
- </child>
+ <property name="xalign">0</property>
+ <property name="xscale">0</property>
<child>
- <object class="GtkButton" id="new_wifi_find">
- <property name="label" translatable="yes">Find</property>
+ <object class="GtkButton" id="new_wifi_hidden">
+ <property name="label" translatable="yes">Hidden network</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">2</property>
- </packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
diff --git a/src/nmn-new-connection.c b/src/nmn-new-connection.c
index 2b9d03f..6402be5 100644
--- a/src/nmn-new-connection.c
+++ b/src/nmn-new-connection.c
@@ -16,6 +16,7 @@
#include "nma-gconf-settings.h"
#include "nmn-wifi-list.h"
#include "nmn-mobile-providers.h"
+#include "wireless-dialog.h"
G_DEFINE_TYPE (NmnNewConnection, nmn_new_connection, GTK_TYPE_EVENT_BOX)
@@ -35,8 +36,7 @@ typedef struct {
/* WiFi widgets */
GtkWidget *wifi_list;
- GtkWidget *wifi_search_entry;
- GtkWidget *wifi_search_button;
+ GtkWidget *wifi_hidden_network;
/* 3G widgets */
GtkWidget *mobile_label;
@@ -64,14 +64,84 @@ nmn_new_connection_create (GtkBuilder *builder,
}
static void
-connect_requested (NmnWifiList *wifi_list, gpointer user_data)
+connect_requested (gpointer instance, gpointer user_data)
{
gtk_widget_hide (GTK_WIDGET (user_data));
}
static void
+connect_cb (gpointer user_data,
+ const char *object_path,
+ GError *error)
+{
+ /* FIXME: Report the error somewhere */
+ g_debug ("connect_cb: %s %s", object_path,
+ error ? error->message : "success");
+}
+
+static gboolean
+save_connection (NmnNMData *data, NMConnection *connection)
+{
+ NMAGConfConnection *exported;
+ NMAGConfSettings *settings;
+
+ settings = NMA_GCONF_SETTINGS (nmn_nm_data_get_user_settings (data));
+
+ exported = nma_gconf_settings_get_by_connection (settings, connection);
+ if (exported) {
+ /* Not a new or system connection, save the updated settings to GConf */
+ nma_gconf_connection_save (exported);
+ return TRUE;
+ }
+
+ /* FIXME: Try fuzzy match */
+
+ exported = nma_gconf_settings_add_connection (settings, connection);
+
+ if (exported) {
+ g_object_unref (exported);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+wifi_dialog_done (NMAWirelessDialog *dialog,
+ gint response,
+ gpointer user_data)
+{
+ NmnNewConnectionPrivate *priv = GET_PRIVATE (user_data);
+ NMConnection *connection;
+
+ if (response != GTK_RESPONSE_OK)
+ goto done;
+
+ connection = nma_wireless_dialog_get_connection (dialog);
+ save_connection (priv->nm_data, connection);
+
+ nm_client_activate_connection (NM_CLIENT (priv->nm_data),
+ NM_DBUS_SERVICE_USER_SETTINGS,
+ nm_connection_get_path (connection),
+ nma_wireless_dialog_get_device (dialog),
+ "/",
+ connect_cb,
+ NULL);
+
+ done:
+ gtk_widget_hide (GTK_WIDGET (dialog));
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+static void
wifi_search (GtkButton *button, gpointer user_data)
{
+ NmnNewConnectionPrivate *priv = GET_PRIVATE (user_data);
+ GtkWidget *dialog;
+
+ dialog = nma_wireless_dialog_hidden_new (NM_CLIENT (priv->nm_data));
+ g_signal_connect (dialog, "done", G_CALLBACK (wifi_dialog_done), user_data);
+ nma_wireless_dialog_show (NMA_WIRELESS_DIALOG (dialog));
}
static void
@@ -86,10 +156,9 @@ wifi_page_init (NmnNewConnection *connection)
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (container), priv->wifi_list);
gtk_widget_show_all (priv->wifi_list);
- priv->wifi_search_entry = GTK_WIDGET (gtk_builder_get_object (priv->builder, "new_wifi_entry"));
-
- priv->wifi_search_button = GTK_WIDGET (gtk_builder_get_object (priv->builder, "new_wifi_find"));
- g_signal_connect (priv->wifi_search_button, "clicked", G_CALLBACK (wifi_search), connection);
+ priv->wifi_hidden_network = GTK_WIDGET (gtk_builder_get_object (priv->builder, "new_wifi_hidden"));
+ g_signal_connect (priv->wifi_hidden_network, "clicked", G_CALLBACK (wifi_search), connection);
+ g_signal_connect (priv->wifi_hidden_network, "clicked", G_CALLBACK (connect_requested), connection);
}
/* Mobile */
diff --git a/src/nmn-wifi-item.c b/src/nmn-wifi-item.c
index 8283b41..798967e 100644
--- a/src/nmn-wifi-item.c
+++ b/src/nmn-wifi-item.c
@@ -374,29 +374,35 @@ create_new_connection (NMDeviceWifi *device, NMAccessPoint *ap)
}
static void
+wifi_item_created (NmnNetworkItem *item, NMConnection *connection)
+{
+ NmnNMData *nm_data;
+ NMExportedConnection *exported;
+
+ nm_data = nmn_network_item_get_nm_data (item);
+
+ /* FIXME: Maybe it already exists, try harder */
+ exported = NM_EXPORTED_CONNECTION
+ (nma_gconf_settings_add_connection (NMA_GCONF_SETTINGS (nmn_nm_data_get_user_settings (nm_data)),
+ connection));
+
+ if (!exported)
+ return;
+
+ nmn_network_item_set_connection (item, exported);
+ g_object_unref (exported);
+
+ connect (NMN_ITEM (item));
+ nmn_network_item_set_connection (item, NULL);
+}
+
+static void
wireless_dialog_response_cb (NMAWirelessDialog *dialog,
gint response,
gpointer user_data)
{
if (response == GTK_RESPONSE_OK) {
- NmnNetworkItem *item = NMN_NETWORK_ITEM (user_data);
- NmnNMData *nm_data;
- NMConnection *connection;
- NMExportedConnection *exported;
-
- nm_data = nmn_network_item_get_nm_data (item);
- connection = nma_wireless_dialog_get_connection (dialog);
- exported = NM_EXPORTED_CONNECTION
- (nma_gconf_settings_add_connection (NMA_GCONF_SETTINGS (nmn_nm_data_get_user_settings (nm_data)),
- connection));
-
- g_object_unref (connection);
- if (exported) {
- nmn_network_item_set_connection (item, exported);
- g_object_unref (exported);
-
- connect (NMN_ITEM (item));
- }
+ wifi_item_created (NMN_NETWORK_ITEM (user_data), nma_wireless_dialog_get_connection (dialog));
}
gtk_widget_hide (GTK_WIDGET (dialog));
@@ -431,53 +437,33 @@ static void
connect (NmnItem *item)
{
NmnNetworkItem *network_item = NMN_NETWORK_ITEM (item);
- NmnNMData *nm_data;
- NMDeviceWifi *device;
- NMAccessPoint *ap;
- NMConnection *connection;
- NMExportedConnection *exported;
- gboolean connection_constructed;
if (!nmn_network_item_get_connection (network_item)) {
- nm_data = nmn_network_item_get_nm_data (network_item);
- device = NM_DEVICE_WIFI (nmn_network_item_get_device (network_item));
- ap = nmn_wifi_item_get_ap (NMN_WIFI_ITEM (item));
+ NMDevice *device;
+ NMAccessPoint *ap;
+ NMConnection *connection;
- connection = create_new_connection (device, ap);
+ device = nmn_network_item_get_device (network_item);
+ ap = nmn_wifi_item_get_ap (NMN_WIFI_ITEM (item));
+ connection = create_new_connection (NM_DEVICE_WIFI (device), ap);
if (!connection)
return;
if (nm_connection_need_secrets (connection, NULL)) {
+ NmnNMData *nm_data;
GtkWidget *dialog;
- dialog = nma_wireless_dialog_new (NMN_WIFI_ITEM (item), connection);
- g_object_unref (connection);
+ nm_data = nmn_network_item_get_nm_data (network_item);
+ dialog = nma_wireless_dialog_new (NM_CLIENT (nm_data), connection, device, ap);
g_signal_connect (dialog, "done", G_CALLBACK (wireless_dialog_response_cb), item);
nma_wireless_dialog_show (NMA_WIRELESS_DIALOG (dialog));
- return;
- }
-
- exported = NM_EXPORTED_CONNECTION
- (nma_gconf_settings_add_connection (NMA_GCONF_SETTINGS (nmn_nm_data_get_user_settings (nm_data)),
- connection));
+ } else
+ wifi_item_created (network_item, connection);
g_object_unref (connection);
- if (!exported)
- return;
-
- nmn_network_item_set_connection (network_item, exported);
- g_object_unref (exported);
- connection_constructed = TRUE;
} else {
- update_autoconnect (NMN_NETWORK_ITEM (item), TRUE);
- connection_constructed = FALSE;
- }
-
- NMN_ITEM_CLASS (nmn_wifi_item_parent_class)->connect (item);
-
- if (connection_constructed) {
- /* Clear the exported connection again - the main networks list will handle password requests and so on. */
- nmn_network_item_set_connection (network_item, NULL);
+ update_autoconnect (network_item, TRUE);
+ NMN_ITEM_CLASS (nmn_wifi_item_parent_class)->connect (item);
}
}
@@ -532,14 +518,17 @@ add_one_setting (GHashTable *settings,
return secrets ? TRUE : FALSE;
}
+typedef struct {
+ NMExportedConnection *exported;
+ DBusGMethodInvocation *context;
+} SecretsRequestInfo;
+
static void
secrets_requested_response_cb (NMAWirelessDialog *dialog,
gint response,
gpointer user_data)
{
- DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
- NmnWifiItem *item;
- NMExportedConnection *connection;
+ SecretsRequestInfo *info = (SecretsRequestInfo *) user_data;
NMSettingWirelessSecurity *s_wireless_sec;
const char *key_mgmt;
NMConnection *wrapped = NULL;
@@ -552,9 +541,7 @@ secrets_requested_response_cb (NMAWirelessDialog *dialog,
goto done;
}
- item = nma_wireless_dialog_get_item (dialog);
- connection = nmn_network_item_get_connection (NMN_NETWORK_ITEM (item));
- wrapped = nm_exported_connection_get_connection (connection);
+ wrapped = nm_exported_connection_get_connection (info->exported);
/* Second-guess which setting NM wants secrets for. */
s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (wrapped, NM_TYPE_SETTING_WIRELESS_SECURITY));
@@ -604,13 +591,13 @@ secrets_requested_response_cb (NMAWirelessDialog *dialog,
if (!add_one_setting (settings, wrapped, NM_SETTING (s_wireless_sec), &error))
goto done;
- dbus_g_method_return (context, settings);
+ dbus_g_method_return (info->context, settings);
/* Save the connection back to GConf _after_ hashing it, because
* saving to GConf might trigger the GConf change notifiers, resulting
* in the connection being read back in from GConf which clears secrets.
*/
- nma_gconf_connection_save (NMA_GCONF_CONNECTION (connection));
+ nma_gconf_connection_save (NMA_GCONF_CONNECTION (info->exported));
done:
if (settings)
@@ -618,7 +605,7 @@ secrets_requested_response_cb (NMAWirelessDialog *dialog,
if (error) {
g_warning ("%s", error->message);
- dbus_g_method_return_error (context, error);
+ dbus_g_method_return_error (info->context, error);
g_error_free (error);
}
@@ -637,9 +624,23 @@ secrets_requested (NmnNetworkItem *network_item,
DBusGMethodInvocation *context)
{
GtkWidget *dialog;
+ NMExportedConnection *exported;
+ SecretsRequestInfo *info;
+
+ exported = nmn_network_item_get_connection (network_item);
+ dialog = nma_wireless_dialog_new (NM_CLIENT (nmn_network_item_get_nm_data (network_item)),
+ nm_exported_connection_get_connection (exported),
+ nmn_network_item_get_device (network_item),
+ nmn_wifi_item_get_ap (NMN_WIFI_ITEM (network_item)));
+
+ info = g_new (SecretsRequestInfo, 1);
+ info->exported = exported;
+ info->context = context;
+
+ g_signal_connect_data (dialog, "done",
+ G_CALLBACK (secrets_requested_response_cb),
+ info, (GClosureNotify) g_free, 0);
- dialog = nma_wireless_dialog_new (NMN_WIFI_ITEM (network_item), NULL);
- g_signal_connect (dialog, "done", G_CALLBACK (secrets_requested_response_cb), context);
nma_wireless_dialog_show (NMA_WIRELESS_DIALOG (dialog));
}
diff --git a/src/wireless-dialog.c b/src/wireless-dialog.c
index d6a390a..7627913 100644
--- a/src/wireless-dialog.c
+++ b/src/wireless-dialog.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
*
* Dan Williams <dcbw redhat com>
@@ -46,46 +47,45 @@
G_DEFINE_TYPE (NMAWirelessDialog, nma_wireless_dialog, GTK_TYPE_DIALOG)
enum {
- DONE,
- LAST_SIGNAL
+ DONE,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
#define NMA_WIRELESS_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
- NMA_TYPE_WIRELESS_DIALOG, \
- NMAWirelessDialogPrivate))
+ NMA_TYPE_WIRELESS_DIALOG, \
+ NMAWirelessDialogPrivate))
typedef struct {
- NMClient *client;
- NmnWifiItem *item;
- GtkBuilder *builder;
+ NMClient *client;
+ GtkBuilder *builder;
- NMConnection *connection;
- NMDevice *device;
- NMAccessPoint *ap;
- gboolean adhoc_create;
+ NMConnection *connection;
+ NMDevice *device;
+ NMAccessPoint *ap;
+ gboolean adhoc_create;
- GtkTreeModel *device_model;
- GtkTreeModel *connection_model;
- GtkSizeGroup *group;
- GtkWidget *sec_combo;
+ GtkTreeModel *device_model;
+ GtkTreeModel *connection_model;
+ GtkSizeGroup *group;
+ GtkWidget *sec_combo;
- gboolean nag_ignored;
+ gboolean nag_ignored;
- gboolean disposed;
+ gboolean disposed;
} NMAWirelessDialogPrivate;
-#define D_NAME_COLUMN 0
-#define D_DEV_COLUMN 1
+#define D_NAME_COLUMN 0
+#define D_DEV_COLUMN 1
-#define S_NAME_COLUMN 0
-#define S_SEC_COLUMN 1
+#define S_NAME_COLUMN 0
+#define S_SEC_COLUMN 1
-#define C_NAME_COLUMN 0
-#define C_CON_COLUMN 1
-#define C_SEP_COLUMN 2
-#define C_NEW_COLUMN 3
+#define C_NAME_COLUMN 0
+#define C_CON_COLUMN 1
+#define C_SEP_COLUMN 2
+#define C_NEW_COLUMN 3
static void security_combo_changed (GtkWidget *combo, gpointer user_data);
static gboolean security_combo_init (NMAWirelessDialog *self);
@@ -93,527 +93,431 @@ static gboolean security_combo_init (NMAWirelessDialog *self);
static void
nma_wireless_dialog_set_nag_ignored (NMAWirelessDialog *self, gboolean ignored)
{
- g_return_if_fail (self != NULL);
+ g_return_if_fail (self != NULL);
- NMA_WIRELESS_DIALOG_GET_PRIVATE (self)->nag_ignored = ignored;
+ NMA_WIRELESS_DIALOG_GET_PRIVATE (self)->nag_ignored = ignored;
}
static void
model_free (GtkTreeModel *model, guint col)
{
- GtkTreeIter iter;
+ GtkTreeIter iter;
- if (!model)
- return;
+ if (!model)
+ return;
- if (gtk_tree_model_get_iter_first (model, &iter)) {
- do {
- char *str;
+ if (gtk_tree_model_get_iter_first (model, &iter)) {
+ do {
+ char *str;
- gtk_tree_model_get (model, &iter, col, &str, -1);
- g_free (str);
- } while (gtk_tree_model_iter_next (model, &iter));
- }
- g_object_unref (model);
+ gtk_tree_model_get (model, &iter, col, &str, -1);
+ g_free (str);
+ } while (gtk_tree_model_iter_next (model, &iter));
+ }
+ g_object_unref (model);
}
static void
size_group_clear (GtkSizeGroup *group)
{
- GSList *children;
- GSList *iter;
+ GSList *children;
+ GSList *iter;
- g_return_if_fail (group != NULL);
+ g_return_if_fail (group != NULL);
- children = gtk_size_group_get_widgets (group);
- for (iter = children; iter; iter = g_slist_next (iter))
- gtk_size_group_remove_widget (group, GTK_WIDGET (iter->data));
+ children = gtk_size_group_get_widgets (group);
+ for (iter = children; iter; iter = g_slist_next (iter))
+ gtk_size_group_remove_widget (group, GTK_WIDGET (iter->data));
}
static void
size_group_add_permanent (GtkSizeGroup *group,
GtkBuilder *builder)
{
- GtkWidget *widget;
+ GtkWidget *widget;
- widget = GTK_WIDGET (gtk_builder_get_object (builder, "network_name_label"));
- gtk_size_group_add_widget (group, widget);
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "network_name_label"));
+ gtk_size_group_add_widget (group, widget);
- widget = GTK_WIDGET (gtk_builder_get_object (builder, "security_combo_label"));
- gtk_size_group_add_widget (group, widget);
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "security_combo_label"));
+ gtk_size_group_add_widget (group, widget);
- widget = GTK_WIDGET (gtk_builder_get_object (builder, "device_label"));
- gtk_size_group_add_widget (group, widget);
+ widget = GTK_WIDGET (gtk_builder_get_object (builder, "device_label"));
+ gtk_size_group_add_widget (group, widget);
}
static void
security_combo_changed (GtkWidget *combo,
gpointer user_data)
{
- NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
- NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- GtkWidget *vbox;
- GList *elt, *children;
- GtkTreeIter iter;
- GtkTreeModel *model;
- WirelessSecurity *sec = NULL;
- GtkWidget *sec_widget;
-
- vbox = GTK_WIDGET (gtk_builder_get_object (priv->builder, "security_vbox"));
- g_assert (vbox);
-
- size_group_clear (priv->group);
-
- /* Remove any previous wireless security widgets */
- children = gtk_container_get_children (GTK_CONTAINER (vbox));
- for (elt = children; elt; elt = g_list_next (elt))
- gtk_container_remove (GTK_CONTAINER (vbox), GTK_WIDGET (elt->data));
-
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) {
- g_warning ("%s: no active security combo box item.", __func__);
- return;
- }
-
- gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
- if (!sec)
- return;
-
- sec_widget = wireless_security_get_widget (sec);
- g_assert (sec_widget);
-
- size_group_add_permanent (priv->group, priv->builder);
- wireless_security_add_to_size_group (sec, priv->group);
-
- if (gtk_widget_get_parent (sec_widget))
- gtk_widget_reparent (sec_widget, vbox);
- else
- gtk_container_add (GTK_CONTAINER (vbox), sec_widget);
-
- wireless_security_unref (sec);
-
- /* Re-validate */
- wireless_security_changed_cb (NULL, sec);
+ NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
+ NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ GtkWidget *vbox;
+ GList *elt, *children;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ WirelessSecurity *sec = NULL;
+ GtkWidget *sec_widget;
+
+ vbox = GTK_WIDGET (gtk_builder_get_object (priv->builder, "security_vbox"));
+ g_assert (vbox);
+
+ size_group_clear (priv->group);
+
+ /* Remove any previous wireless security widgets */
+ children = gtk_container_get_children (GTK_CONTAINER (vbox));
+ for (elt = children; elt; elt = g_list_next (elt))
+ gtk_container_remove (GTK_CONTAINER (vbox), GTK_WIDGET (elt->data));
+
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) {
+ g_warning ("%s: no active security combo box item.", __func__);
+ return;
+ }
+
+ gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
+ if (!sec)
+ return;
+
+ sec_widget = wireless_security_get_widget (sec);
+ g_assert (sec_widget);
+
+ size_group_add_permanent (priv->group, priv->builder);
+ wireless_security_add_to_size_group (sec, priv->group);
+
+ if (gtk_widget_get_parent (sec_widget))
+ gtk_widget_reparent (sec_widget, vbox);
+ else
+ gtk_container_add (GTK_CONTAINER (vbox), sec_widget);
+
+ wireless_security_unref (sec);
+
+ /* Re-validate */
+ wireless_security_changed_cb (NULL, sec);
}
static GByteArray *
validate_dialog_ssid (NMAWirelessDialog *self)
{
- NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- GtkWidget *widget;
- const char *ssid;
- guint32 ssid_len;
- GByteArray *ssid_ba;
-
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_entry"));
-
- ssid = gtk_entry_get_text (GTK_ENTRY (widget));
- ssid_len = strlen (ssid);
-
- if (!ssid || !ssid_len || (ssid_len > 32))
- return NULL;
-
- ssid_len = strlen (ssid);
- ssid_ba = g_byte_array_sized_new (ssid_len);
- g_byte_array_append (ssid_ba, (unsigned char *) ssid, ssid_len);
- return ssid_ba;
+ NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ GtkWidget *widget;
+ const char *ssid;
+ guint32 ssid_len;
+ GByteArray *ssid_ba;
+
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_entry"));
+
+ ssid = gtk_entry_get_text (GTK_ENTRY (widget));
+ ssid_len = strlen (ssid);
+
+ if (!ssid || !ssid_len || (ssid_len > 32))
+ return NULL;
+
+ ssid_len = strlen (ssid);
+ ssid_ba = g_byte_array_sized_new (ssid_len);
+ g_byte_array_append (ssid_ba, (unsigned char *) ssid, ssid_len);
+ return ssid_ba;
}
static void
stuff_changed_cb (WirelessSecurity *sec, gpointer user_data)
{
- NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
- NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- GByteArray *ssid = NULL;
- gboolean free_ssid = TRUE;
- gboolean valid = FALSE;
-
- if (priv->connection) {
- NMSettingWireless *s_wireless;
- s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS));
- g_assert (s_wireless);
- ssid = (GByteArray *) nm_setting_wireless_get_ssid (s_wireless);
- free_ssid = FALSE;
- } else {
- ssid = validate_dialog_ssid (self);
- }
-
- if (ssid) {
- valid = wireless_security_validate (sec, ssid);
- if (free_ssid)
- g_byte_array_free (ssid, TRUE);
- }
-
- gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, valid);
+ NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
+ NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ GByteArray *ssid = NULL;
+ gboolean free_ssid = TRUE;
+ gboolean valid = FALSE;
+
+ if (priv->connection) {
+ NMSettingWireless *s_wireless;
+ s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS));
+ g_assert (s_wireless);
+ ssid = (GByteArray *) nm_setting_wireless_get_ssid (s_wireless);
+ free_ssid = FALSE;
+ } else {
+ ssid = validate_dialog_ssid (self);
+ }
+
+ if (ssid) {
+ valid = wireless_security_validate (sec, ssid);
+ if (free_ssid)
+ g_byte_array_free (ssid, TRUE);
+ }
+
+ gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, valid);
}
static void
ssid_entry_changed (GtkWidget *entry, gpointer user_data)
{
- NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
- NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- GtkTreeIter iter;
- WirelessSecurity *sec = NULL;
- GtkTreeModel *model;
- gboolean valid = FALSE;
- GByteArray *ssid;
-
- ssid = validate_dialog_ssid (self);
- if (!ssid)
- goto out;
-
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->sec_combo));
- if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->sec_combo), &iter))
- gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
-
- if (sec) {
- valid = wireless_security_validate (sec, ssid);
- wireless_security_unref (sec);
- } else {
- valid = TRUE;
- }
-
-out:
- gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, valid);
+ NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
+ NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ GtkTreeIter iter;
+ WirelessSecurity *sec = NULL;
+ GtkTreeModel *model;
+ gboolean valid = FALSE;
+ GByteArray *ssid;
+
+ ssid = validate_dialog_ssid (self);
+ if (!ssid)
+ goto out;
+
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->sec_combo));
+ if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->sec_combo), &iter))
+ gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
+
+ if (sec) {
+ valid = wireless_security_validate (sec, ssid);
+ wireless_security_unref (sec);
+ } else {
+ valid = TRUE;
+ }
+
+ out:
+ gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, valid);
}
static void
connection_combo_changed (GtkWidget *combo,
gpointer user_data)
{
- NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
- NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- GtkTreeIter iter;
- GtkTreeModel *model;
- gboolean is_new = FALSE;
- NMSettingWireless *s_wireless;
- char *utf8_ssid;
- GtkWidget *widget;
-
- gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
-
- if (priv->connection)
- g_object_unref (priv->connection);
-
- gtk_tree_model_get (model, &iter,
- C_CON_COLUMN, &priv->connection,
- C_NEW_COLUMN, &is_new, -1);
-
- if (!security_combo_init (self)) {
- g_warning ("Couldn't change wireless security combo box.");
- return;
- }
- security_combo_changed (priv->sec_combo, self);
-
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_entry"));
- if (priv->connection) {
- const GByteArray *ssid;
-
- s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS));
- ssid = nm_setting_wireless_get_ssid (s_wireless);
- utf8_ssid = nm_utils_ssid_to_utf8 ((const char *) ssid->data, ssid->len);
- gtk_entry_set_text (GTK_ENTRY (widget), utf8_ssid);
- g_free (utf8_ssid);
- } else {
- gtk_entry_set_text (GTK_ENTRY (widget), "");
- }
-
- gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_entry")), is_new);
- gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_label")), is_new);
- gtk_widget_set_sensitive (priv->sec_combo, is_new);
- gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->builder, "security_combo_label")), is_new);
- gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->builder, "security_vbox")), is_new);
+ NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
+ NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ gboolean is_new = FALSE;
+ NMSettingWireless *s_wireless;
+ char *utf8_ssid;
+ GtkWidget *widget;
+
+ gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
+
+ if (priv->connection)
+ g_object_unref (priv->connection);
+
+ gtk_tree_model_get (model, &iter,
+ C_CON_COLUMN, &priv->connection,
+ C_NEW_COLUMN, &is_new, -1);
+
+ if (!security_combo_init (self)) {
+ g_warning ("Couldn't change wireless security combo box.");
+ return;
+ }
+ security_combo_changed (priv->sec_combo, self);
+
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_entry"));
+ if (priv->connection) {
+ const GByteArray *ssid;
+
+ s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS));
+ ssid = nm_setting_wireless_get_ssid (s_wireless);
+ utf8_ssid = nm_utils_ssid_to_utf8 ((const char *) ssid->data, ssid->len);
+ gtk_entry_set_text (GTK_ENTRY (widget), utf8_ssid);
+ g_free (utf8_ssid);
+ } else {
+ gtk_entry_set_text (GTK_ENTRY (widget), "");
+ }
+
+ gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_entry")), is_new);
+ gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_label")), is_new);
+ gtk_widget_set_sensitive (priv->sec_combo, is_new);
+ gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->builder, "security_combo_label")), is_new);
+ gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->builder, "security_vbox")), is_new);
}
static gboolean
connection_combo_separator_cb (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
{
- gboolean is_separator = FALSE;
+ gboolean is_separator = FALSE;
- gtk_tree_model_get (model, iter, C_SEP_COLUMN, &is_separator, -1);
- return is_separator;
+ gtk_tree_model_get (model, iter, C_SEP_COLUMN, &is_separator, -1);
+ return is_separator;
}
-static gint
-alphabetize_connections (NMConnection *a, NMConnection *b)
+static gboolean
+connection_combo_init (NMAWirelessDialog *self, NMConnection *connection)
{
- NMSettingConnection *asc, *bsc;
+ NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ GtkListStore *store;
+ GtkTreeIter tree_iter;
+ GtkWidget *widget;
+ GtkCellRenderer *renderer;
- asc = NM_SETTING_CONNECTION (nm_connection_get_setting (a, NM_TYPE_SETTING_CONNECTION));
- bsc = NM_SETTING_CONNECTION (nm_connection_get_setting (b, NM_TYPE_SETTING_CONNECTION));
+ g_return_val_if_fail (priv->connection == NULL, FALSE);
- return strcmp (nm_setting_connection_get_id (asc),
- nm_setting_connection_get_id (bsc));
-}
+ /* Clear any old model */
+ model_free (priv->connection_model, C_NAME_COLUMN);
-static gboolean
-connection_combo_init (NMAWirelessDialog *self, NMConnection *connection)
-{
- NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- GtkListStore *store;
- int num_added = 0;
- GtkTreeIter tree_iter;
- GtkWidget *widget;
- NMSettingConnection *s_con;
- GtkCellRenderer *renderer;
- const char *id;
-
- g_return_val_if_fail (priv->connection == NULL, FALSE);
-
- /* Clear any old model */
- model_free (priv->connection_model, C_NAME_COLUMN);
-
- /* New model */
- store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_OBJECT, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
- priv->connection_model = GTK_TREE_MODEL (store);
-
- if (connection) {
- s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
- g_assert (s_con);
-
- id = nm_setting_connection_get_id (s_con);
- g_assert (id);
-
- gtk_list_store_append (store, &tree_iter);
- gtk_list_store_set (store, &tree_iter,
- C_NAME_COLUMN, id,
- C_CON_COLUMN, connection, -1);
- } else {
- GSList *connections, *iter, *to_add = NULL;
-
- gtk_list_store_append (store, &tree_iter);
- gtk_list_store_set (store, &tree_iter,
- C_NAME_COLUMN, _("New..."),
- C_NEW_COLUMN, TRUE, -1);
-
- gtk_list_store_append (store, &tree_iter);
- gtk_list_store_set (store, &tree_iter, C_SEP_COLUMN, TRUE, -1);
-
- /* FIXME: (added when imported to nmn */
- /* connections = get_all_connections (priv->applet); */
- connections = NULL;
- for (iter = connections; iter; iter = g_slist_next (iter)) {
- NMConnection *candidate = NM_CONNECTION (iter->data);
- NMSettingWireless *s_wireless;
- const char *connection_type;
- const char *mode;
- const GByteArray *setting_mac;
-
- s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (candidate, NM_TYPE_SETTING_CONNECTION));
- connection_type = s_con ? nm_setting_connection_get_connection_type (s_con) : NULL;
- if (!connection_type)
- continue;
-
- if (strcmp (connection_type, NM_SETTING_WIRELESS_SETTING_NAME))
- continue;
-
- s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (candidate, NM_TYPE_SETTING_WIRELESS));
- if (!s_wireless)
- continue;
-
- /* If creating a new Ad-Hoc network, only show shared network connections */
- if (priv->adhoc_create) {
- NMSettingIP4Config *s_ip4;
- const char *method = NULL;
-
- s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (candidate, NM_TYPE_SETTING_IP4_CONFIG);
- if (s_ip4)
- method = nm_setting_ip4_config_get_method (s_ip4);
-
- if (!s_ip4 || strcmp (method, "shared"))
- continue;
-
- /* Ignore non-Ad-Hoc connections too */
- mode = nm_setting_wireless_get_mode (s_wireless);
- if (!mode || strcmp (mode, "adhoc"))
- continue;
- }
-
- /* Ignore connections that don't apply to the selected device */
- setting_mac = nm_setting_wireless_get_mac_address (s_wireless);
- if (setting_mac) {
- const char *hw_addr;
-
- hw_addr = nm_device_wifi_get_hw_address (NM_DEVICE_WIFI (priv->device));
- if (hw_addr) {
- struct ether_addr *ether;
-
- ether = ether_aton (hw_addr);
- if (ether && memcmp (setting_mac->data, ether->ether_addr_octet, ETH_ALEN))
- continue;
- }
- }
-
- to_add = g_slist_append (to_add, candidate);
- }
- g_slist_free (connections);
-
- /* Alphabetize the list then add the connections */
- to_add = g_slist_sort (to_add, (GCompareFunc) alphabetize_connections);
- for (iter = to_add; iter; iter = g_slist_next (iter)) {
- NMConnection *candidate = NM_CONNECTION (iter->data);
-
- s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (candidate, NM_TYPE_SETTING_CONNECTION));
- gtk_list_store_append (store, &tree_iter);
- gtk_list_store_set (store, &tree_iter,
- C_NAME_COLUMN, nm_setting_connection_get_id (s_con),
- C_CON_COLUMN, candidate, -1);
- num_added++;
- }
- g_slist_free (to_add);
- }
-
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "connection_combo"));
-
- gtk_cell_layout_clear (GTK_CELL_LAYOUT (widget));
- renderer = gtk_cell_renderer_text_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget), renderer, TRUE);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (widget), renderer,
- "text", C_NAME_COLUMN);
- gtk_combo_box_set_wrap_width (GTK_COMBO_BOX (widget), 1);
-
- gtk_combo_box_set_model (GTK_COMBO_BOX (widget), priv->connection_model);
-
- gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (widget),
- connection_combo_separator_cb,
- NULL,
- NULL);
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
- g_signal_connect (G_OBJECT (widget), "changed",
- G_CALLBACK (connection_combo_changed), self);
- if (connection || !num_added) {
- gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "connection_label")));
- gtk_widget_hide (widget);
- }
- gtk_tree_model_get_iter_first (priv->connection_model, &tree_iter);
- gtk_tree_model_get (priv->connection_model, &tree_iter, C_CON_COLUMN, &priv->connection, -1);
-
- return TRUE;
+ /* New model */
+ store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_OBJECT, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
+ priv->connection_model = GTK_TREE_MODEL (store);
+
+ if (connection) {
+ NMSettingConnection *s_con;
+ const char *id;
+
+ s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+ g_assert (s_con);
+
+ id = nm_setting_connection_get_id (s_con);
+ g_assert (id);
+
+ gtk_list_store_append (store, &tree_iter);
+ gtk_list_store_set (store, &tree_iter,
+ C_NAME_COLUMN, id,
+ C_CON_COLUMN, connection, -1);
+
+ priv->connection = g_object_ref (connection);
+ }
+
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "connection_combo"));
+
+ gtk_cell_layout_clear (GTK_CELL_LAYOUT (widget));
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget), renderer, TRUE);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (widget), renderer,
+ "text", C_NAME_COLUMN);
+ gtk_combo_box_set_wrap_width (GTK_COMBO_BOX (widget), 1);
+
+ gtk_combo_box_set_model (GTK_COMBO_BOX (widget), priv->connection_model);
+
+ gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (widget),
+ connection_combo_separator_cb,
+ NULL,
+ NULL);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
+ g_signal_connect (G_OBJECT (widget), "changed",
+ G_CALLBACK (connection_combo_changed), self);
+
+ gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "connection_label")));
+ gtk_widget_hide (widget);
+
+ return TRUE;
}
static void
device_combo_changed (GtkWidget *combo,
gpointer user_data)
{
- NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
- NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- GtkTreeIter iter;
- GtkTreeModel *model;
+ NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
+ NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ GtkTreeIter iter;
+ GtkTreeModel *model;
- gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
+ gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
- g_object_unref (priv->device);
- gtk_tree_model_get (model, &iter, D_DEV_COLUMN, &priv->device, -1);
+ g_object_unref (priv->device);
+ gtk_tree_model_get (model, &iter, D_DEV_COLUMN, &priv->device, -1);
- if (!connection_combo_init (self, NULL)) {
- g_warning ("Couldn't change connection combo box.");
- return;
- }
+ if (!connection_combo_init (self, NULL)) {
+ g_warning ("Couldn't change connection combo box.");
+ return;
+ }
- if (!security_combo_init (self)) {
- g_warning ("Couldn't change wireless security combo box.");
- return;
- }
+ if (!security_combo_init (self)) {
+ g_warning ("Couldn't change wireless security combo box.");
+ return;
+ }
- security_combo_changed (priv->sec_combo, self);
+ security_combo_changed (priv->sec_combo, self);
}
static void
add_device_to_model (GtkListStore *model, NMDevice *device)
{
- GtkTreeIter iter;
- char *desc;
+ GtkTreeIter iter;
+ char *desc;
- desc = (char *) utils_get_device_description (device);
- if (!desc)
- desc = (char *) nm_device_get_iface (device);
- g_assert (desc);
+ desc = (char *) utils_get_device_description (device);
+ if (!desc)
+ desc = (char *) nm_device_get_iface (device);
+ g_assert (desc);
- gtk_list_store_append (model, &iter);
- gtk_list_store_set (model, &iter, D_NAME_COLUMN, desc, D_DEV_COLUMN, device, -1);
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter, D_NAME_COLUMN, desc, D_DEV_COLUMN, device, -1);
}
static gboolean
can_use_device (NMDevice *device)
{
- /* Ignore unsupported devices */
- if (!(nm_device_get_capabilities (device) & NM_DEVICE_CAP_NM_SUPPORTED))
- return FALSE;
+ /* Ignore unsupported devices */
+ if (!(nm_device_get_capabilities (device) & NM_DEVICE_CAP_NM_SUPPORTED))
+ return FALSE;
- if (!NM_IS_DEVICE_WIFI (device))
- return FALSE;
+ if (!NM_IS_DEVICE_WIFI (device))
+ return FALSE;
- if (nm_device_get_state (device) < NM_DEVICE_STATE_DISCONNECTED)
- return FALSE;
+ if (nm_device_get_state (device) < NM_DEVICE_STATE_DISCONNECTED)
+ return FALSE;
- return TRUE;
+ return TRUE;
}
static gboolean
device_combo_init (NMAWirelessDialog *self, NMDevice *device)
{
- NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- const GPtrArray *devices;
- GtkListStore *store;
- int i, num_added = 0;
-
- g_return_val_if_fail (priv->device == NULL, FALSE);
-
- store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_OBJECT);
- priv->device_model = GTK_TREE_MODEL (store);
-
- if (device) {
- if (!can_use_device (device))
- return FALSE;
- add_device_to_model (store, device);
- num_added++;
- } else {
- devices = nm_client_get_devices (priv->client);
- if (devices->len == 0)
- return FALSE;
-
- for (i = 0; devices && (i < devices->len); i++) {
- device = NM_DEVICE (g_ptr_array_index (devices, i));
- if (can_use_device (device)) {
- add_device_to_model (store, device);
- num_added++;
- }
- }
- }
-
- if (num_added > 0) {
- GtkWidget *widget;
- GtkTreeIter iter;
-
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "device_combo"));
- gtk_combo_box_set_model (GTK_COMBO_BOX (widget), priv->device_model);
- gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
- g_signal_connect (G_OBJECT (widget), "changed",
- G_CALLBACK (device_combo_changed), self);
- if (num_added == 1) {
- gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "device_label")));
- gtk_widget_hide (widget);
- }
- gtk_tree_model_get_iter_first (priv->device_model, &iter);
- gtk_tree_model_get (priv->device_model, &iter, D_DEV_COLUMN, &priv->device, -1);
- }
-
- return num_added > 0 ? TRUE : FALSE;
+ NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ const GPtrArray *devices;
+ GtkListStore *store;
+ int i, num_added = 0;
+
+ g_return_val_if_fail (priv->device == NULL, FALSE);
+
+ store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_OBJECT);
+ priv->device_model = GTK_TREE_MODEL (store);
+
+ if (device) {
+ if (!can_use_device (device))
+ return FALSE;
+ add_device_to_model (store, device);
+ num_added++;
+ } else {
+ devices = nm_client_get_devices (priv->client);
+ if (devices->len == 0)
+ return FALSE;
+
+ for (i = 0; devices && (i < devices->len); i++) {
+ device = NM_DEVICE (g_ptr_array_index (devices, i));
+ if (can_use_device (device)) {
+ add_device_to_model (store, device);
+ num_added++;
+ }
+ }
+ }
+
+ if (num_added > 0) {
+ GtkWidget *widget;
+ GtkTreeIter iter;
+
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "device_combo"));
+ gtk_combo_box_set_model (GTK_COMBO_BOX (widget), priv->device_model);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
+ g_signal_connect (G_OBJECT (widget), "changed",
+ G_CALLBACK (device_combo_changed), self);
+ if (num_added == 1) {
+ gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "device_label")));
+ gtk_widget_hide (widget);
+ }
+ gtk_tree_model_get_iter_first (priv->device_model, &iter);
+ gtk_tree_model_get (priv->device_model, &iter, D_DEV_COLUMN, &priv->device, -1);
+ }
+
+ return num_added > 0 ? TRUE : FALSE;
}
static gboolean
find_proto (NMSettingWirelessSecurity *sec, const char *item)
{
- guint32 i;
+ guint32 i;
- for (i = 0; i < nm_setting_wireless_security_get_num_protos (sec); i++) {
- if (!strcmp (item, nm_setting_wireless_security_get_proto (sec, i)))
- return TRUE;
- }
- return FALSE;
+ for (i = 0; i < nm_setting_wireless_security_get_num_protos (sec); i++) {
+ if (!strcmp (item, nm_setting_wireless_security_get_proto (sec, i)))
+ return TRUE;
+ }
+ return FALSE;
}
static NMUtilsSecurityType
@@ -622,47 +526,47 @@ get_default_type_for_security (NMSettingWirelessSecurity *sec,
guint32 ap_flags,
guint32 dev_caps)
{
- const char *key_mgmt, *auth_alg;
-
- g_return_val_if_fail (sec != NULL, NMU_SEC_NONE);
-
- key_mgmt = nm_setting_wireless_security_get_key_mgmt (sec);
- auth_alg = nm_setting_wireless_security_get_auth_alg (sec);
-
- /* No IEEE 802.1x */
- if (!strcmp (key_mgmt, "none"))
- return NMU_SEC_STATIC_WEP;
-
- if ( !strcmp (key_mgmt, "ieee8021x")
- && (!have_ap || (ap_flags & NM_802_11_AP_FLAGS_PRIVACY))) {
- if (auth_alg && !strcmp (auth_alg, "leap"))
- return NMU_SEC_LEAP;
- return NMU_SEC_DYNAMIC_WEP;
- }
-
- if ( !strcmp (key_mgmt, "wpa-none")
- || !strcmp (key_mgmt, "wpa-psk")) {
- if (!have_ap || (ap_flags & NM_802_11_AP_FLAGS_PRIVACY)) {
- if (find_proto (sec, "rsn"))
- return NMU_SEC_WPA2_PSK;
- else if (find_proto (sec, "wpa"))
- return NMU_SEC_WPA_PSK;
- else
- return NMU_SEC_WPA_PSK;
- }
- }
-
- if ( !strcmp (key_mgmt, "wpa-eap")
- && (!have_ap || (ap_flags & NM_802_11_AP_FLAGS_PRIVACY))) {
- if (find_proto (sec, "rsn"))
- return NMU_SEC_WPA2_ENTERPRISE;
- else if (find_proto (sec, "wpa"))
- return NMU_SEC_WPA_ENTERPRISE;
- else
- return NMU_SEC_WPA_ENTERPRISE;
- }
-
- return NMU_SEC_INVALID;
+ const char *key_mgmt, *auth_alg;
+
+ g_return_val_if_fail (sec != NULL, NMU_SEC_NONE);
+
+ key_mgmt = nm_setting_wireless_security_get_key_mgmt (sec);
+ auth_alg = nm_setting_wireless_security_get_auth_alg (sec);
+
+ /* No IEEE 802.1x */
+ if (!strcmp (key_mgmt, "none"))
+ return NMU_SEC_STATIC_WEP;
+
+ if ( !strcmp (key_mgmt, "ieee8021x")
+ && (!have_ap || (ap_flags & NM_802_11_AP_FLAGS_PRIVACY))) {
+ if (auth_alg && !strcmp (auth_alg, "leap"))
+ return NMU_SEC_LEAP;
+ return NMU_SEC_DYNAMIC_WEP;
+ }
+
+ if ( !strcmp (key_mgmt, "wpa-none")
+ || !strcmp (key_mgmt, "wpa-psk")) {
+ if (!have_ap || (ap_flags & NM_802_11_AP_FLAGS_PRIVACY)) {
+ if (find_proto (sec, "rsn"))
+ return NMU_SEC_WPA2_PSK;
+ else if (find_proto (sec, "wpa"))
+ return NMU_SEC_WPA_PSK;
+ else
+ return NMU_SEC_WPA_PSK;
+ }
+ }
+
+ if ( !strcmp (key_mgmt, "wpa-eap")
+ && (!have_ap || (ap_flags & NM_802_11_AP_FLAGS_PRIVACY))) {
+ if (find_proto (sec, "rsn"))
+ return NMU_SEC_WPA2_ENTERPRISE;
+ else if (find_proto (sec, "wpa"))
+ return NMU_SEC_WPA_ENTERPRISE;
+ else
+ return NMU_SEC_WPA_ENTERPRISE;
+ }
+
+ return NMU_SEC_INVALID;
}
static void
@@ -672,186 +576,186 @@ add_security_item (NMAWirelessDialog *self,
GtkTreeIter *iter,
const char *text)
{
- wireless_security_set_changed_notify (sec, stuff_changed_cb, self);
- gtk_list_store_append (model, iter);
- gtk_list_store_set (model, iter, S_NAME_COLUMN, text, S_SEC_COLUMN, sec, -1);
- wireless_security_unref (sec);
+ wireless_security_set_changed_notify (sec, stuff_changed_cb, self);
+ gtk_list_store_append (model, iter);
+ gtk_list_store_set (model, iter, S_NAME_COLUMN, text, S_SEC_COLUMN, sec, -1);
+ wireless_security_unref (sec);
}
static gboolean
security_combo_init (NMAWirelessDialog *self)
{
- NMAWirelessDialogPrivate *priv;
- GtkListStore *sec_model;
- GtkTreeIter iter;
- guint32 ap_flags = 0;
- guint32 ap_wpa = 0;
- guint32 ap_rsn = 0;
- guint32 dev_caps;
- NMSettingWirelessSecurity *wsec = NULL;
- NMUtilsSecurityType default_type = NMU_SEC_NONE;
- WEPKeyType default_wep_type = WEP_KEY_TYPE_KEY;
- int active = -1;
- int item = 0;
- NMSettingWireless *s_wireless = NULL;
- gboolean is_adhoc;
-
- g_return_val_if_fail (self != NULL, FALSE);
-
- priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- g_return_val_if_fail (priv->device != NULL, FALSE);
- g_return_val_if_fail (priv->sec_combo != NULL, FALSE);
-
- is_adhoc = priv->adhoc_create;
-
- /* The security options displayed are filtered based on device
- * capabilities, and if provided, additionally by access point capabilities.
- * If a connection is given, that connection's options should be selected
- * by default.
- */
- dev_caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (priv->device));
- if (priv->ap != NULL) {
- ap_flags = nm_access_point_get_flags (priv->ap);
- ap_wpa = nm_access_point_get_wpa_flags (priv->ap);
- ap_rsn = nm_access_point_get_rsn_flags (priv->ap);
- }
-
- if (priv->connection) {
- const char *mode;
- const char *security;
-
- s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS));
-
- mode = nm_setting_wireless_get_mode (s_wireless);
- if (mode && !strcmp (mode, "adhoc"))
- is_adhoc = TRUE;
-
- wsec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (priv->connection,
- NM_TYPE_SETTING_WIRELESS_SECURITY));
-
- security = nm_setting_wireless_get_security (s_wireless);
- if (!security || strcmp (security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME))
- wsec = NULL;
- if (wsec) {
- default_type = get_default_type_for_security (wsec, !!priv->ap, ap_flags, dev_caps);
- if (default_type == NMU_SEC_STATIC_WEP)
- default_wep_type = ws_wep_guess_key_type (priv->connection);
- }
- } else if (is_adhoc) {
- default_type = NMU_SEC_STATIC_WEP;
- default_wep_type = WEP_KEY_TYPE_PASSPHRASE;
- }
-
- sec_model = gtk_list_store_new (2, G_TYPE_STRING, wireless_security_get_g_type ());
-
- if (nm_utils_security_valid (NMU_SEC_NONE, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
- gtk_list_store_append (sec_model, &iter);
- gtk_list_store_set (sec_model, &iter,
- S_NAME_COLUMN, _("None"),
- -1);
- if (default_type == NMU_SEC_NONE)
- active = item;
- item++;
- }
-
- /* Don't show Static WEP if both the AP and the device are capable of WPA,
- * even though technically it's possible to have this configuration.
- */
- if ( nm_utils_security_valid (NMU_SEC_STATIC_WEP, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
- && ((!ap_wpa && !ap_rsn) || !(dev_caps & (NM_WIFI_DEVICE_CAP_WPA | NM_WIFI_DEVICE_CAP_RSN)))) {
- WirelessSecurityWEPKey *ws_wep;
-
- ws_wep = ws_wep_key_new (priv->builder, priv->connection, WEP_KEY_TYPE_KEY, priv->adhoc_create);
- if (ws_wep) {
- add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
- &iter, _("WEP 40/128-bit Key"));
- if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (default_wep_type == WEP_KEY_TYPE_KEY))
- active = item;
- item++;
- }
-
- ws_wep = ws_wep_key_new (priv->builder, priv->connection, WEP_KEY_TYPE_PASSPHRASE, priv->adhoc_create);
- if (ws_wep) {
- add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
- &iter, _("WEP 128-bit Passphrase"));
- if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (default_wep_type == WEP_KEY_TYPE_PASSPHRASE))
- active = item;
- item++;
- }
- }
-
- /* Don't show LEAP if both the AP and the device are capable of WPA,
- * even though technically it's possible to have this configuration.
- */
- if ( nm_utils_security_valid (NMU_SEC_LEAP, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
- && ((!ap_wpa && !ap_rsn) || !(dev_caps & (NM_WIFI_DEVICE_CAP_WPA | NM_WIFI_DEVICE_CAP_RSN)))) {
- WirelessSecurityLEAP *ws_leap;
-
- ws_leap = ws_leap_new (priv->builder, priv->connection);
- if (ws_leap) {
- add_security_item (self, WIRELESS_SECURITY (ws_leap), sec_model,
- &iter, _("LEAP"));
- if ((active < 0) && (default_type == NMU_SEC_LEAP))
- active = item;
- item++;
- }
- }
-
- if (nm_utils_security_valid (NMU_SEC_DYNAMIC_WEP, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
- WirelessSecurityDynamicWEP *ws_dynamic_wep;
-
- ws_dynamic_wep = ws_dynamic_wep_new (priv->builder, priv->connection);
- if (ws_dynamic_wep) {
- add_security_item (self, WIRELESS_SECURITY (ws_dynamic_wep), sec_model,
- &iter, _("Dynamic WEP (802.1x)"));
- if ((active < 0) && (default_type == NMU_SEC_DYNAMIC_WEP))
- active = item;
- item++;
- }
- }
-
- if ( nm_utils_security_valid (NMU_SEC_WPA_PSK, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
- || nm_utils_security_valid (NMU_SEC_WPA2_PSK, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
- WirelessSecurityWPAPSK *ws_wpa_psk;
-
- ws_wpa_psk = ws_wpa_psk_new (priv->builder, priv->connection);
- if (ws_wpa_psk) {
- add_security_item (self, WIRELESS_SECURITY (ws_wpa_psk), sec_model,
- &iter, _("WPA & WPA2 Personal"));
- if ((active < 0) && ((default_type == NMU_SEC_WPA_PSK) || (default_type == NMU_SEC_WPA2_PSK)))
- active = item;
- item++;
- }
- }
-
- if ( nm_utils_security_valid (NMU_SEC_WPA_ENTERPRISE, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
- || nm_utils_security_valid (NMU_SEC_WPA2_ENTERPRISE, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
- WirelessSecurityWPAEAP *ws_wpa_eap;
-
- ws_wpa_eap = ws_wpa_eap_new (priv->builder, priv->connection);
- if (ws_wpa_eap) {
- add_security_item (self, WIRELESS_SECURITY (ws_wpa_eap), sec_model,
- &iter, _("WPA & WPA2 Enterprise"));
- if ((active < 0) && ((default_type == NMU_SEC_WPA_ENTERPRISE) || (default_type == NMU_SEC_WPA2_ENTERPRISE)))
- active = item;
- item++;
- }
- }
-
- gtk_combo_box_set_model (GTK_COMBO_BOX (priv->sec_combo), GTK_TREE_MODEL (sec_model));
- gtk_combo_box_set_active (GTK_COMBO_BOX (priv->sec_combo), active < 0 ? 0 : (guint32) active);
- g_object_unref (G_OBJECT (sec_model));
- return TRUE;
+ NMAWirelessDialogPrivate *priv;
+ GtkListStore *sec_model;
+ GtkTreeIter iter;
+ guint32 ap_flags = 0;
+ guint32 ap_wpa = 0;
+ guint32 ap_rsn = 0;
+ guint32 dev_caps;
+ NMSettingWirelessSecurity *wsec = NULL;
+ NMUtilsSecurityType default_type = NMU_SEC_NONE;
+ WEPKeyType default_wep_type = WEP_KEY_TYPE_KEY;
+ int active = -1;
+ int item = 0;
+ NMSettingWireless *s_wireless = NULL;
+ gboolean is_adhoc;
+
+ g_return_val_if_fail (self != NULL, FALSE);
+
+ priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ g_return_val_if_fail (priv->device != NULL, FALSE);
+ g_return_val_if_fail (priv->sec_combo != NULL, FALSE);
+
+ is_adhoc = priv->adhoc_create;
+
+ /* The security options displayed are filtered based on device
+ * capabilities, and if provided, additionally by access point capabilities.
+ * If a connection is given, that connection's options should be selected
+ * by default.
+ */
+ dev_caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (priv->device));
+ if (priv->ap != NULL) {
+ ap_flags = nm_access_point_get_flags (priv->ap);
+ ap_wpa = nm_access_point_get_wpa_flags (priv->ap);
+ ap_rsn = nm_access_point_get_rsn_flags (priv->ap);
+ }
+
+ if (priv->connection) {
+ const char *mode;
+ const char *security;
+
+ s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS));
+
+ mode = nm_setting_wireless_get_mode (s_wireless);
+ if (mode && !strcmp (mode, "adhoc"))
+ is_adhoc = TRUE;
+
+ wsec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (priv->connection,
+ NM_TYPE_SETTING_WIRELESS_SECURITY));
+
+ security = nm_setting_wireless_get_security (s_wireless);
+ if (!security || strcmp (security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME))
+ wsec = NULL;
+ if (wsec) {
+ default_type = get_default_type_for_security (wsec, !!priv->ap, ap_flags, dev_caps);
+ if (default_type == NMU_SEC_STATIC_WEP)
+ default_wep_type = ws_wep_guess_key_type (priv->connection);
+ }
+ } else if (is_adhoc) {
+ default_type = NMU_SEC_STATIC_WEP;
+ default_wep_type = WEP_KEY_TYPE_PASSPHRASE;
+ }
+
+ sec_model = gtk_list_store_new (2, G_TYPE_STRING, wireless_security_get_g_type ());
+
+ if (nm_utils_security_valid (NMU_SEC_NONE, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
+ gtk_list_store_append (sec_model, &iter);
+ gtk_list_store_set (sec_model, &iter,
+ S_NAME_COLUMN, _("None"),
+ -1);
+ if (default_type == NMU_SEC_NONE)
+ active = item;
+ item++;
+ }
+
+ /* Don't show Static WEP if both the AP and the device are capable of WPA,
+ * even though technically it's possible to have this configuration.
+ */
+ if ( nm_utils_security_valid (NMU_SEC_STATIC_WEP, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
+ && ((!ap_wpa && !ap_rsn) || !(dev_caps & (NM_WIFI_DEVICE_CAP_WPA | NM_WIFI_DEVICE_CAP_RSN)))) {
+ WirelessSecurityWEPKey *ws_wep;
+
+ ws_wep = ws_wep_key_new (priv->builder, priv->connection, WEP_KEY_TYPE_KEY, priv->adhoc_create);
+ if (ws_wep) {
+ add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
+ &iter, _("WEP 40/128-bit Key"));
+ if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (default_wep_type == WEP_KEY_TYPE_KEY))
+ active = item;
+ item++;
+ }
+
+ ws_wep = ws_wep_key_new (priv->builder, priv->connection, WEP_KEY_TYPE_PASSPHRASE, priv->adhoc_create);
+ if (ws_wep) {
+ add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
+ &iter, _("WEP 128-bit Passphrase"));
+ if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (default_wep_type == WEP_KEY_TYPE_PASSPHRASE))
+ active = item;
+ item++;
+ }
+ }
+
+ /* Don't show LEAP if both the AP and the device are capable of WPA,
+ * even though technically it's possible to have this configuration.
+ */
+ if ( nm_utils_security_valid (NMU_SEC_LEAP, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
+ && ((!ap_wpa && !ap_rsn) || !(dev_caps & (NM_WIFI_DEVICE_CAP_WPA | NM_WIFI_DEVICE_CAP_RSN)))) {
+ WirelessSecurityLEAP *ws_leap;
+
+ ws_leap = ws_leap_new (priv->builder, priv->connection);
+ if (ws_leap) {
+ add_security_item (self, WIRELESS_SECURITY (ws_leap), sec_model,
+ &iter, _("LEAP"));
+ if ((active < 0) && (default_type == NMU_SEC_LEAP))
+ active = item;
+ item++;
+ }
+ }
+
+ if (nm_utils_security_valid (NMU_SEC_DYNAMIC_WEP, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
+ WirelessSecurityDynamicWEP *ws_dynamic_wep;
+
+ ws_dynamic_wep = ws_dynamic_wep_new (priv->builder, priv->connection);
+ if (ws_dynamic_wep) {
+ add_security_item (self, WIRELESS_SECURITY (ws_dynamic_wep), sec_model,
+ &iter, _("Dynamic WEP (802.1x)"));
+ if ((active < 0) && (default_type == NMU_SEC_DYNAMIC_WEP))
+ active = item;
+ item++;
+ }
+ }
+
+ if ( nm_utils_security_valid (NMU_SEC_WPA_PSK, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
+ || nm_utils_security_valid (NMU_SEC_WPA2_PSK, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
+ WirelessSecurityWPAPSK *ws_wpa_psk;
+
+ ws_wpa_psk = ws_wpa_psk_new (priv->builder, priv->connection);
+ if (ws_wpa_psk) {
+ add_security_item (self, WIRELESS_SECURITY (ws_wpa_psk), sec_model,
+ &iter, _("WPA & WPA2 Personal"));
+ if ((active < 0) && ((default_type == NMU_SEC_WPA_PSK) || (default_type == NMU_SEC_WPA2_PSK)))
+ active = item;
+ item++;
+ }
+ }
+
+ if ( nm_utils_security_valid (NMU_SEC_WPA_ENTERPRISE, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)
+ || nm_utils_security_valid (NMU_SEC_WPA2_ENTERPRISE, dev_caps, !!priv->ap, is_adhoc, ap_flags, ap_wpa, ap_rsn)) {
+ WirelessSecurityWPAEAP *ws_wpa_eap;
+
+ ws_wpa_eap = ws_wpa_eap_new (priv->builder, priv->connection);
+ if (ws_wpa_eap) {
+ add_security_item (self, WIRELESS_SECURITY (ws_wpa_eap), sec_model,
+ &iter, _("WPA & WPA2 Enterprise"));
+ if ((active < 0) && ((default_type == NMU_SEC_WPA_ENTERPRISE) || (default_type == NMU_SEC_WPA2_ENTERPRISE)))
+ active = item;
+ item++;
+ }
+ }
+
+ gtk_combo_box_set_model (GTK_COMBO_BOX (priv->sec_combo), GTK_TREE_MODEL (sec_model));
+ gtk_combo_box_set_active (GTK_COMBO_BOX (priv->sec_combo), active < 0 ? 0 : (guint32) active);
+ g_object_unref (G_OBJECT (sec_model));
+ return TRUE;
}
static gboolean
revalidate (gpointer user_data)
{
- NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
- NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
+ NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- security_combo_changed (priv->sec_combo, self);
- return FALSE;
+ security_combo_changed (priv->sec_combo, self);
+ return FALSE;
}
static gboolean
@@ -861,222 +765,254 @@ internal_init (NMAWirelessDialog *self,
gboolean auth_only,
gboolean create)
{
- NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- GtkWidget *widget;
- char *label, *icon_name = "network-wireless";
- gboolean security_combo_focus = FALSE;
-
- gtk_window_set_position (GTK_WINDOW (self), GTK_WIN_POS_CENTER_ALWAYS);
- gtk_container_set_border_width (GTK_CONTAINER (self), 6);
- gtk_window_set_default_size (GTK_WINDOW (self), 488, -1);
- gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
- gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE);
-
- if (auth_only)
- icon_name = "dialog-password";
- else
- icon_name = "network-wireless";
-
- gtk_window_set_icon_name (GTK_WINDOW (self), icon_name);
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "image1"));
- gtk_image_set_from_icon_name (GTK_IMAGE (widget), icon_name, GTK_ICON_SIZE_DIALOG);
-
- gtk_box_set_spacing (GTK_BOX (gtk_bin_get_child (GTK_BIN (self))), 2);
-
- widget = gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
- gtk_box_set_child_packing (GTK_BOX (GTK_DIALOG (self)->action_area), widget,
- FALSE, TRUE, 0, GTK_PACK_END);
-
- /* Connect/Create button */
- if (create) {
- GtkWidget *image;
-
- widget = gtk_button_new_with_mnemonic (_("C_reate"));
- image = gtk_image_new_from_stock (GTK_STOCK_CONNECT, GTK_ICON_SIZE_BUTTON);
- gtk_button_set_image (GTK_BUTTON (widget), image);
-
- gtk_widget_show (widget);
- gtk_dialog_add_action_widget (GTK_DIALOG (self), widget, GTK_RESPONSE_OK);
- } else
- widget = gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CONNECT, GTK_RESPONSE_OK);
-
- gtk_box_set_child_packing (GTK_BOX (GTK_DIALOG (self)->action_area), widget,
- FALSE, TRUE, 0, GTK_PACK_END);
- g_object_set (G_OBJECT (widget), "can-default", TRUE, NULL);
- gtk_widget_grab_default (widget);
-
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "hbox1"));
- if (!widget) {
- nm_warning ("Couldn't find glade wireless_dialog widget.");
- return FALSE;
- }
-
- gtk_widget_reparent (widget, gtk_bin_get_child (GTK_BIN (self)));
-
- /* If given a valid connection, hide the SSID bits and connection combo */
- if (specific_connection) {
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_label"));
- gtk_widget_hide (widget);
-
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_entry"));
- gtk_widget_hide (widget);
-
- security_combo_focus = TRUE;
- } else {
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_entry"));
- g_signal_connect (G_OBJECT (widget), "changed", (GCallback) ssid_entry_changed, self);
- gtk_widget_grab_focus (widget);
- }
-
- gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, FALSE);
-
- if (!device_combo_init (self, specific_device)) {
- g_warning ("No wireless devices available.");
- return FALSE;
- }
-
- if (!connection_combo_init (self, specific_connection)) {
- g_warning ("Couldn't set up connection combo box.");
- return FALSE;
- }
-
- if (!security_combo_init (self)) {
- g_warning ("Couldn't set up wireless security combo box.");
- return FALSE;
- }
-
- if (security_combo_focus)
- gtk_widget_grab_focus (priv->sec_combo);
-
- security_combo_changed (priv->sec_combo, self);
- g_signal_connect (G_OBJECT (priv->sec_combo), "changed", G_CALLBACK (security_combo_changed), self);
-
- if (priv->connection) {
- char *tmp;
- char *esc_ssid = NULL;
- NMSettingWireless *s_wireless;
- const GByteArray *ssid;
-
- s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS));
- ssid = s_wireless ? nm_setting_wireless_get_ssid (s_wireless) : NULL;
- if (ssid)
- esc_ssid = nm_utils_ssid_to_utf8 ((const char *) ssid->data, ssid->len);
-
- tmp = g_strdup_printf (_("Passwords or encryption keys are required to access the wireless network '%s'."),
- esc_ssid ? esc_ssid : "<unknown>");
- gtk_window_set_title (GTK_WINDOW (self), _("Wireless Network Authentication Required"));
- label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
- _("Authentication required by wireless network"),
- tmp);
- g_free (esc_ssid);
- g_free (tmp);
- } else if (priv->adhoc_create) {
- gtk_window_set_title (GTK_WINDOW (self), _("Create New Wireless Network"));
- label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
- _("New wireless network"),
- _("Enter a name for the wireless network you wish to create."));
- } else {
- gtk_window_set_title (GTK_WINDOW (self), _("Connect to Hidden Wireless Network"));
- label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
- _("Hidden wireless network"),
- _("Enter the name and security details of the hidden wireless network you wish to connect to."));
- }
-
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "caption_label"));
- gtk_label_set_markup (GTK_LABEL (widget), label);
- g_free (label);
-
- /* Re-validate from an idle handler so that widgets like file choosers
- * have had time to find their files.
- */
- g_idle_add (revalidate, self);
-
- return TRUE;
-}
+ NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ GtkWidget *widget;
+ char *label, *icon_name = "network-wireless";
+ gboolean security_combo_focus = FALSE;
+
+ gtk_window_set_position (GTK_WINDOW (self), GTK_WIN_POS_CENTER_ALWAYS);
+ gtk_container_set_border_width (GTK_CONTAINER (self), 6);
+ gtk_window_set_default_size (GTK_WINDOW (self), 488, -1);
+ gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
+ gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE);
+
+ if (auth_only)
+ icon_name = "dialog-password";
+ else
+ icon_name = "network-wireless";
+
+ gtk_window_set_icon_name (GTK_WINDOW (self), icon_name);
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "image1"));
+ gtk_image_set_from_icon_name (GTK_IMAGE (widget), icon_name, GTK_ICON_SIZE_DIALOG);
+
+ gtk_box_set_spacing (GTK_BOX (gtk_bin_get_child (GTK_BIN (self))), 2);
+
+ widget = gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+ gtk_box_set_child_packing (GTK_BOX (GTK_DIALOG (self)->action_area), widget,
+ FALSE, TRUE, 0, GTK_PACK_END);
+
+ /* Connect/Create button */
+ if (create) {
+ GtkWidget *image;
+
+ widget = gtk_button_new_with_mnemonic (_("C_reate"));
+ image = gtk_image_new_from_stock (GTK_STOCK_CONNECT, GTK_ICON_SIZE_BUTTON);
+ gtk_button_set_image (GTK_BUTTON (widget), image);
+
+ gtk_widget_show (widget);
+ gtk_dialog_add_action_widget (GTK_DIALOG (self), widget, GTK_RESPONSE_OK);
+ } else
+ widget = gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CONNECT, GTK_RESPONSE_OK);
+
+ gtk_box_set_child_packing (GTK_BOX (GTK_DIALOG (self)->action_area), widget,
+ FALSE, TRUE, 0, GTK_PACK_END);
+ g_object_set (G_OBJECT (widget), "can-default", TRUE, NULL);
+ gtk_widget_grab_default (widget);
+
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "hbox1"));
+ if (!widget) {
+ nm_warning ("Couldn't find glade wireless_dialog widget.");
+ return FALSE;
+ }
-NmnWifiItem *
-nma_wireless_dialog_get_item (NMAWirelessDialog *self)
-{
- g_return_val_if_fail (NMA_IS_WIRELESS_DIALOG (self), NULL);
+ gtk_widget_reparent (widget, gtk_bin_get_child (GTK_BIN (self)));
+
+ /* If given a valid connection, hide the SSID bits and connection combo */
+ if (specific_connection) {
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_label"));
+ gtk_widget_hide (widget);
+
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_entry"));
+ gtk_widget_hide (widget);
- return NMA_WIRELESS_DIALOG_GET_PRIVATE (self)->item;
+ security_combo_focus = TRUE;
+ } else {
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_entry"));
+ g_signal_connect (G_OBJECT (widget), "changed", (GCallback) ssid_entry_changed, self);
+ gtk_widget_grab_focus (widget);
+ }
+
+ gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, FALSE);
+
+ if (!device_combo_init (self, specific_device)) {
+ g_warning ("No wireless devices available.");
+ return FALSE;
+ }
+
+ if (!connection_combo_init (self, specific_connection)) {
+ g_warning ("Couldn't set up connection combo box.");
+ return FALSE;
+ }
+
+ if (!security_combo_init (self)) {
+ g_warning ("Couldn't set up wireless security combo box.");
+ return FALSE;
+ }
+
+ if (security_combo_focus)
+ gtk_widget_grab_focus (priv->sec_combo);
+
+ security_combo_changed (priv->sec_combo, self);
+ g_signal_connect (G_OBJECT (priv->sec_combo), "changed", G_CALLBACK (security_combo_changed), self);
+
+ if (priv->connection) {
+ char *tmp;
+ char *esc_ssid = NULL;
+ NMSettingWireless *s_wireless;
+ const GByteArray *ssid;
+
+ s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS));
+ ssid = s_wireless ? nm_setting_wireless_get_ssid (s_wireless) : NULL;
+ if (ssid)
+ esc_ssid = nm_utils_ssid_to_utf8 ((const char *) ssid->data, ssid->len);
+
+ tmp = g_strdup_printf (_("Passwords or encryption keys are required to access the wireless network '%s'."),
+ esc_ssid ? esc_ssid : "<unknown>");
+ gtk_window_set_title (GTK_WINDOW (self), _("Wireless Network Authentication Required"));
+ label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
+ _("Authentication required by wireless network"),
+ tmp);
+ g_free (esc_ssid);
+ g_free (tmp);
+ } else if (priv->adhoc_create) {
+ gtk_window_set_title (GTK_WINDOW (self), _("Create New Wireless Network"));
+ label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
+ _("New wireless network"),
+ _("Enter a name for the wireless network you wish to create."));
+ } else {
+ gtk_window_set_title (GTK_WINDOW (self), _("Connect to Hidden Wireless Network"));
+ label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s",
+ _("Hidden wireless network"),
+ _("Enter the name and security details of the hidden wireless network you wish to connect to."));
+ }
+
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "caption_label"));
+ gtk_label_set_markup (GTK_LABEL (widget), label);
+ g_free (label);
+
+ /* Re-validate from an idle handler so that widgets like file choosers
+ * have had time to find their files.
+ */
+ g_idle_add (revalidate, self);
+
+ return TRUE;
}
NMConnection *
nma_wireless_dialog_get_connection (NMAWirelessDialog *self)
{
- g_return_val_if_fail (NMA_IS_WIRELESS_DIALOG (self), NULL);
+ g_return_val_if_fail (NMA_IS_WIRELESS_DIALOG (self), NULL);
+
+ return NMA_WIRELESS_DIALOG_GET_PRIVATE (self)->connection;
+}
+
+NMDevice *
+nma_wireless_dialog_get_device (NMAWirelessDialog *self)
+{
+ NMAWirelessDialogPrivate *priv;
+ GObject *combo;
+ NMDevice *device = NULL;
+ GtkTreeIter iter;
+
+ g_return_val_if_fail (NMA_IS_WIRELESS_DIALOG (self), NULL);
+
+ priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ combo = gtk_builder_get_object (priv->builder, "device_combo");
+ gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
+ gtk_tree_model_get (priv->device_model, &iter, D_DEV_COLUMN, &device, -1);
+
+ if (device)
+ g_object_unref (device);
- return NMA_WIRELESS_DIALOG_GET_PRIVATE (self)->connection;
+ return device;
+}
+
+NMAccessPoint *
+nma_wireless_dialog_get_ap (NMAWirelessDialog *self)
+{
+ g_return_val_if_fail (NMA_IS_WIRELESS_DIALOG (self), NULL);
+
+ return NMA_WIRELESS_DIALOG_GET_PRIVATE (self)->ap;
}
GtkWidget *
-nma_wireless_dialog_new (NmnWifiItem *item,
- NMConnection *connection)
+nma_wireless_dialog_new (NMClient *client,
+ NMConnection *connection,
+ NMDevice *device,
+ NMAccessPoint *ap)
{
- NMAWirelessDialog *self;
- NMAWirelessDialogPrivate *priv;
- NMClient *nm_data;
- NMDevice *device;
- NMAccessPoint *ap;
- guint32 dev_caps;
+ NMAWirelessDialog *self;
+ NMAWirelessDialogPrivate *priv;
+ guint32 dev_caps;
+
+ g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
+ g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
+ g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
+ g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
- g_return_val_if_fail (NMN_IS_WIFI_ITEM (item), NULL);
+ /* Ensure device validity */
+ dev_caps = nm_device_get_capabilities (device);
+ g_return_val_if_fail (dev_caps & NM_DEVICE_CAP_NM_SUPPORTED, NULL);
+ g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL);
- nm_data = NM_CLIENT (nmn_network_item_get_nm_data (NMN_NETWORK_ITEM (item)));
- device = nmn_network_item_get_device (NMN_NETWORK_ITEM (item));
- ap = nmn_wifi_item_get_ap (item);
+ self = NMA_WIRELESS_DIALOG (g_object_new (NMA_TYPE_WIRELESS_DIALOG, NULL));
+ if (!self)
+ return NULL;
- /* Ensure device validity */
- dev_caps = nm_device_get_capabilities (device);
- g_return_val_if_fail (dev_caps & NM_DEVICE_CAP_NM_SUPPORTED, NULL);
- g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL);
+ priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- self = NMA_WIRELESS_DIALOG (g_object_new (NMA_TYPE_WIRELESS_DIALOG, NULL));
- if (!self)
- return NULL;
+ priv->client = g_object_ref (client);
+ priv->ap = g_object_ref (ap);
- priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ if (!internal_init (self, connection, device, TRUE, FALSE)) {
+ nm_warning ("Couldn't create wireless security dialog.");
+ g_object_unref (self);
+ return NULL;
+ }
+
+ return GTK_WIDGET (self);
+}
+
+GtkWidget *
+nma_wireless_dialog_hidden_new (NMClient *client)
+{
+ NMAWirelessDialog *self;
+ NMAWirelessDialogPrivate *priv;
- priv->item = item;
- priv->client = g_object_ref (nm_data);
- priv->ap = g_object_ref (ap);
+ g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
- priv->sec_combo = GTK_WIDGET (gtk_builder_get_object (priv->builder, "security_combo"));
- priv->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+ self = NMA_WIRELESS_DIALOG (g_object_new (NMA_TYPE_WIRELESS_DIALOG, NULL));
+ if (!self)
+ return NULL;
- /* Try a bit harder */
- if (!connection) {
- NMExportedConnection *exported;
+ priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- exported = nmn_network_item_get_connection (NMN_NETWORK_ITEM (item));
- connection = nm_exported_connection_get_connection (exported);
- }
+ priv->client = g_object_ref (client);
- if (!internal_init (self, connection, device, TRUE, FALSE)) {
- nm_warning ("Couldn't create wireless security dialog.");
- g_object_unref (self);
- return NULL;
- }
+ if (!internal_init (self, NULL, NULL, FALSE, FALSE)) {
+ nm_warning ("Couldn't create wireless security dialog.");
+ g_object_unref (self);
+ return NULL;
+ }
- return GTK_WIDGET (self);
+ return GTK_WIDGET (self);
}
void
nma_wireless_dialog_show (NMAWirelessDialog *dialog)
{
- GtkWidget *widget;
+ GtkWidget *widget;
- g_return_if_fail (NMA_IS_WIRELESS_DIALOG (dialog));
+ g_return_if_fail (NMA_IS_WIRELESS_DIALOG (dialog));
- utils_hide_main_widget ();
+ utils_hide_main_widget ();
- widget = GTK_WIDGET (dialog);
+ widget = GTK_WIDGET (dialog);
- /* Prevent focus stealing */
- gtk_widget_realize (widget);
- gtk_widget_show (widget);
- gtk_window_present_with_time (GTK_WINDOW (widget), gdk_x11_get_server_time (widget->window));
+ /* Prevent focus stealing */
+ gtk_widget_realize (widget);
+ gtk_widget_show (widget);
+ gtk_window_present_with_time (GTK_WINDOW (widget), gdk_x11_get_server_time (widget->window));
}
static gboolean
@@ -1103,119 +1039,175 @@ nag_dialog_response_cb (GtkDialog *nag_dialog,
static void
dialog_response (GtkDialog *dialog,
- gint response,
- gpointer user_data)
+ gint response,
+ gpointer user_data)
{
- NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
-
- if (response == GTK_RESPONSE_OK) {
+ NMAWirelessDialog *self = NMA_WIRELESS_DIALOG (user_data);
NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ NMSetting *setting;
GtkTreeModel *model;
GtkTreeIter iter;
WirelessSecurity *sec = NULL;
- NMSettingWireless *s_wireless;
+
+ if (response != GTK_RESPONSE_OK)
+ goto out;
+
+ if (!priv->connection) {
+ /* Create new connection */
+ char *id;
+ char *uuid;
+ GByteArray *ssid;
+
+ priv->connection = nm_connection_new ();
+
+ /* Wireless setting */
+ setting = nm_setting_wireless_new ();
+ ssid = validate_dialog_ssid (self);
+ g_object_set (setting, NM_SETTING_WIRELESS_SSID, ssid, NULL);
+ nm_connection_add_setting (priv->connection, setting);
+
+ if (ssid) {
+ id = nm_utils_ssid_to_utf8 ((char *) ssid->data, ssid->len);
+ g_byte_array_free (ssid, TRUE);
+ } else
+ id = NULL;
+
+ /* Connection setting */
+ setting = nm_setting_connection_new ();
+ uuid = nm_utils_uuid_generate ();
+
+ /* FIXME: don't autoconnect until the connection is successful at least once */
+ /* Don't autoconnect adhoc networks by default for now */
+ g_object_set (setting,
+ NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
+ NM_SETTING_CONNECTION_UUID, uuid,
+ NM_SETTING_CONNECTION_ID, id,
+ NM_SETTING_CONNECTION_AUTOCONNECT, !priv->adhoc_create,
+ NULL);
+
+ g_free (uuid);
+ g_free (id);
+ nm_connection_add_setting (priv->connection, setting);
+
+ /* IPv4 setting */
+ if (priv->adhoc_create) {
+ g_object_set (setting, NM_SETTING_WIRELESS_MODE, "adhoc", NULL);
+
+ setting = nm_setting_ip4_config_new ();
+ g_object_set (setting,
+ NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED,
+ NULL);
+
+ nm_connection_add_setting (priv->connection, setting);
+ }
+ }
model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->sec_combo));
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->sec_combo), &iter);
gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
if (sec && !priv->nag_ignored) {
- GtkWidget *nag_dialog;
-
- /* Nag the user about certificates or whatever. Only destroy the dialog
- * if no nagging was done.
- */
- nag_dialog = wireless_security_nag_user (sec);
- if (nag_dialog) {
- gtk_window_set_transient_for (GTK_WINDOW (nag_dialog), GTK_WINDOW (dialog));
- g_signal_connect (nag_dialog, "response",
- G_CALLBACK (nag_dialog_response_cb),
- dialog);
- return;
- }
+ GtkWidget *nag_dialog;
+
+ /* Nag the user about certificates or whatever. Only destroy the dialog
+ * if no nagging was done.
+ */
+ nag_dialog = wireless_security_nag_user (sec);
+ if (nag_dialog) {
+ gtk_window_set_transient_for (GTK_WINDOW (nag_dialog), GTK_WINDOW (dialog));
+ g_signal_connect (nag_dialog, "response",
+ G_CALLBACK (nag_dialog_response_cb),
+ dialog);
+ return;
+ }
}
/* Fill security */
if (sec) {
- wireless_security_fill_connection (sec, priv->connection);
- wireless_security_unref (sec);
+ wireless_security_fill_connection (sec, priv->connection);
+ wireless_security_unref (sec);
} else {
- /* Unencrypted */
- s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS));
- g_object_set (s_wireless, NM_SETTING_WIRELESS_SEC, NULL, NULL);
+ /* Unencrypted */
+ setting = nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS);
+ g_object_set (setting, NM_SETTING_WIRELESS_SEC, NULL, NULL);
}
- }
- g_signal_emit (self, signals[DONE], 0, response);
+ out:
+ g_signal_emit (self, signals[DONE], 0, response);
+
+ /* FIXME: clear security? */
}
static void
nma_wireless_dialog_init (NMAWirelessDialog *self)
{
- NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
- GError *error = NULL;
+ NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self);
+ GError *error = NULL;
+
+ priv->builder = gtk_builder_new ();
+ gtk_builder_add_from_file (priv->builder, GLADEDIR "/wireless-security.glade", &error);
+ if (error) {
+ g_error ("Could not load wireless security glade file: %s", error->message);
+ g_error_free (error);
+ }
- priv->builder = gtk_builder_new ();
- gtk_builder_add_from_file (priv->builder, GLADEDIR "/wireless-security.glade", &error);
- if (error) {
- g_error ("Could not load wireless security glade file: %s", error->message);
- g_error_free (error);
- }
+ g_signal_connect (self, "response", G_CALLBACK (dialog_response), self);
- g_signal_connect (self, "response", G_CALLBACK (dialog_response), self);
+ priv->sec_combo = GTK_WIDGET (gtk_builder_get_object (priv->builder, "security_combo"));
+ priv->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
}
static void
dispose (GObject *object)
{
- NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (object);
+ NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (object);
- if (!priv->disposed)
- return;
+ if (!priv->disposed)
+ return;
- priv->disposed = TRUE;
+ priv->disposed = TRUE;
- model_free (priv->device_model, D_NAME_COLUMN);
- model_free (priv->connection_model, C_NAME_COLUMN);
- gtk_combo_box_set_model (GTK_COMBO_BOX (priv->sec_combo), NULL);
+ model_free (priv->device_model, D_NAME_COLUMN);
+ model_free (priv->connection_model, C_NAME_COLUMN);
+ gtk_combo_box_set_model (GTK_COMBO_BOX (priv->sec_combo), NULL);
- if (priv->group)
- g_object_unref (priv->group);
+ if (priv->group)
+ g_object_unref (priv->group);
- if (priv->connection)
- g_object_unref (priv->connection);
+ if (priv->connection)
+ g_object_unref (priv->connection);
- if (priv->device)
- g_object_unref (priv->device);
+ if (priv->device)
+ g_object_unref (priv->device);
- if (priv->ap)
- g_object_unref (priv->ap);
+ if (priv->ap)
+ g_object_unref (priv->ap);
- g_object_unref (priv->builder);
+ g_object_unref (priv->builder);
- if (priv->client)
- g_object_unref (priv->client);
+ if (priv->client)
+ g_object_unref (priv->client);
- G_OBJECT_CLASS (nma_wireless_dialog_parent_class)->dispose (object);
+ G_OBJECT_CLASS (nma_wireless_dialog_parent_class)->dispose (object);
}
static void
nma_wireless_dialog_class_init (NMAWirelessDialogClass *class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
-
- g_type_class_add_private (object_class, sizeof (NMAWirelessDialogPrivate));
-
- /* virtual methods */
- object_class->dispose = dispose;
-
- /* Signals */
- signals[DONE] = g_signal_new ("done",
- G_OBJECT_CLASS_TYPE (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NMAWirelessDialogClass, done),
- NULL, NULL,
- g_cclosure_marshal_VOID__INT,
- G_TYPE_NONE, 1,
- G_TYPE_INT);
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ g_type_class_add_private (object_class, sizeof (NMAWirelessDialogPrivate));
+
+ /* virtual methods */
+ object_class->dispose = dispose;
+
+ /* Signals */
+ signals[DONE] = g_signal_new ("done",
+ G_OBJECT_CLASS_TYPE (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NMAWirelessDialogClass, done),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__INT,
+ G_TYPE_NONE, 1,
+ G_TYPE_INT);
}
diff --git a/src/wireless-dialog.h b/src/wireless-dialog.h
index 65dedc8..a5d4724 100644
--- a/src/wireless-dialog.h
+++ b/src/wireless-dialog.h
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
*
* Dan Williams <dcbw redhat com>
@@ -30,7 +31,6 @@
#include <nm-connection.h>
#include <nm-device.h>
#include <nm-access-point.h>
-#include "nmn-wifi-item.h"
#define NMA_TYPE_WIRELESS_DIALOG (nma_wireless_dialog_get_type ())
#define NMA_WIRELESS_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMA_TYPE_WIRELESS_DIALOG, NMAWirelessDialog))
@@ -40,24 +40,27 @@
#define NMA_WIRELESS_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMA_TYPE_WIRELESS_DIALOG, NMAWirelessDialogClass))
typedef struct {
- GtkDialog parent;
+ GtkDialog parent;
} NMAWirelessDialog;
typedef struct {
- GtkDialogClass parent;
+ GtkDialogClass parent;
- /* Signals */
- void (*done) (NMAWirelessDialog *dialog, gint response_id);
+ /* Signals */
+ void (*done) (NMAWirelessDialog *dialog, gint response_id);
} NMAWirelessDialogClass;
GType nma_wireless_dialog_get_type (void);
-GtkWidget *nma_wireless_dialog_new (NmnWifiItem *item,
- NMConnection *connection);
+GtkWidget *nma_wireless_dialog_new (NMClient *client,
+ NMConnection *connection,
+ NMDevice *device,
+ NMAccessPoint *ap);
-void nma_wireless_dialog_show (NMAWirelessDialog *self);
-NmnWifiItem *nma_wireless_dialog_get_item (NMAWirelessDialog *self);
-NMConnection *nma_wireless_dialog_get_connection (NMAWirelessDialog *self);
-
-#endif /* WIRELESS_DIALOG_H */
+GtkWidget *nma_wireless_dialog_hidden_new (NMClient *client);
+void nma_wireless_dialog_show (NMAWirelessDialog *self);
+NMConnection *nma_wireless_dialog_get_connection (NMAWirelessDialog *self);
+NMDevice *nma_wireless_dialog_get_device (NMAWirelessDialog *self);
+NMAccessPoint *nma_wireless_dialog_get_ap (NMAWirelessDialog *self);
+#endif /* WIRELESS_DIALOG_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]