[network-manager-netbook] Implement device specific connection creator
- From: Tambet Ingo <tambeti src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [network-manager-netbook] Implement device specific connection creator
- Date: Thu, 28 Jan 2010 20:36:44 +0000 (UTC)
commit 168cc92cab1ff773c5cac2ed1903006ef95c0582
Author: Tambet Ingo <tambet gmail com>
Date: Thu Jan 28 13:40:41 2010 -0400
Implement device specific connection creator
Use it when using static IP to connect to a wireless AP for which there's
no connection yet.
libnm-gtk/nm-connection-item.c | 33 ++++++++++++++++++++++
libnm-gtk/nm-connection-item.h | 5 +++
libnm-gtk/nm-wifi-item.c | 60 ++++++++++++++++++++++-----------------
src/nmn-item-renderer.c | 35 +++++++++++++++--------
4 files changed, 95 insertions(+), 38 deletions(-)
---
diff --git a/libnm-gtk/nm-connection-item.c b/libnm-gtk/nm-connection-item.c
index 46f8898..9c99b68 100644
--- a/libnm-gtk/nm-connection-item.c
+++ b/libnm-gtk/nm-connection-item.c
@@ -21,6 +21,7 @@
#include <nm-setting-connection.h>
#include <nm-settings-connection-interface.h>
#include <nm-active-connection.h>
+#include <nm-utils.h>
#include "nm-connection-item.h"
#include "gconf-helpers.h"
@@ -265,6 +266,17 @@ nm_connection_item_new_connection (NMConnectionItem *self,
nm_gconf_write_connection (connection, NULL, NULL);
}
+NMConnection *
+nm_connection_item_create_connection (NMConnectionItem *self)
+{
+ g_return_val_if_fail (NM_IS_CONNECTION_ITEM (self), NULL);
+
+ if (NM_CONNECTION_ITEM_GET_CLASS (self)->create_connection)
+ return NM_CONNECTION_ITEM_GET_CLASS (self)->create_connection (self);
+
+ return NULL;
+}
+
static void
delete_cb (NMSettingsConnectionInterface *connection,
GError *error,
@@ -304,6 +316,25 @@ priority (NMListItem *item)
return priority;
}
+static NMConnection *
+create_connection (NMConnectionItem *self)
+{
+ NMConnection *connection;
+ NMSetting *setting;
+ char *id;
+
+ connection = nm_connection_new ();
+
+ setting = nm_setting_connection_new ();
+ id = nm_utils_uuid_generate ();
+ g_object_set (setting, NM_SETTING_CONNECTION_UUID, id, NULL);
+ g_free (id);
+
+ nm_connection_add_setting (connection, setting);
+
+ return connection;
+}
+
/*****************************************************************************/
static void
@@ -389,6 +420,8 @@ nm_connection_item_class_init (NMConnectionItemClass *klass)
list_class->delete = do_delete;
list_class->priority = priority;
+ klass->create_connection = create_connection;
+
/* Properties */
g_object_class_install_property
(object_class, PROP_CLIENT,
diff --git a/libnm-gtk/nm-connection-item.h b/libnm-gtk/nm-connection-item.h
index 4693915..d2b1279 100644
--- a/libnm-gtk/nm-connection-item.h
+++ b/libnm-gtk/nm-connection-item.h
@@ -44,6 +44,8 @@ typedef struct {
typedef struct {
NMListItemClass parent_class;
+
+ NMConnection *(*create_connection) (NMConnectionItem *self);
} NMConnectionItemClass;
GType nm_connection_item_get_type (void);
@@ -57,6 +59,9 @@ void nm_connection_item_new_connection (NMConnectionIt
NMConnection *connection,
gboolean connect);
+
+NMConnection *nm_connection_item_create_connection (NMConnectionItem *self);
+
G_END_DECLS
#endif /* NM_CONNECTION_ITEM_H */
diff --git a/libnm-gtk/nm-wifi-item.c b/libnm-gtk/nm-wifi-item.c
index 9d05e1a..c8f9005 100644
--- a/libnm-gtk/nm-wifi-item.c
+++ b/libnm-gtk/nm-wifi-item.c
@@ -360,11 +360,13 @@ get_security_for_ap (NMAccessPoint *ap,
}
static NMConnection *
-create_new_connection (NMDeviceWifi *device, NMAccessPoint *ap)
+create_connection (NMConnectionItem *item)
{
NMConnection *connection;
- NMSettingConnection *s_con;
- NMSettingWireless *s_wireless;
+ NMDeviceWifi *device;
+ NMAccessPoint *ap;
+ NMSetting *s_con;
+ NMSetting *s_wireless;
NMSettingWirelessSecurity *s_wireless_sec;
NMSetting8021x *s_8021x = NULL;
const GByteArray *ap_ssid;
@@ -375,12 +377,21 @@ create_new_connection (NMDeviceWifi *device, NMAccessPoint *ap)
guint32 dev_caps;
gboolean supported = TRUE;
+ device = NM_DEVICE_WIFI (nm_device_item_get_device (NM_DEVICE_ITEM (item)));
+ ap = nm_wifi_item_get_ap (NM_WIFI_ITEM (item));
+
dev_caps = nm_device_wifi_get_capabilities (device);
s_wireless_sec = get_security_for_ap (ap, dev_caps, &supported, &s_8021x);
if (!supported)
return NULL;
- s_wireless = NM_SETTING_WIRELESS (nm_setting_wireless_new ());
+ if (NM_CONNECTION_ITEM_CLASS (nm_wifi_item_parent_class)->create_connection)
+ connection = NM_CONNECTION_ITEM_CLASS (nm_wifi_item_parent_class)->create_connection (item);
+
+ if (!connection)
+ return NULL;
+
+ s_wireless = nm_setting_wireless_new ();
ap_ssid = nm_access_point_get_ssid (ap);
g_object_set (s_wireless, NM_SETTING_WIRELESS_SSID, ap_ssid, NULL);
@@ -392,8 +403,8 @@ create_new_connection (NMDeviceWifi *device, NMAccessPoint *ap)
else
g_assert_not_reached ();
- connection = nm_connection_new ();
- nm_connection_add_setting (connection, NM_SETTING (s_wireless));
+ nm_connection_add_setting (connection, s_wireless);
+
if (s_wireless_sec) {
g_object_set (s_wireless, NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, NULL);
nm_connection_add_setting (connection, NM_SETTING (s_wireless_sec));
@@ -401,9 +412,9 @@ create_new_connection (NMDeviceWifi *device, NMAccessPoint *ap)
if (s_8021x)
nm_connection_add_setting (connection, NM_SETTING (s_8021x));
- s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
+ s_con = nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
g_object_set (s_con,
- NM_SETTING_CONNECTION_TYPE, nm_setting_get_name (NM_SETTING (s_wireless)),
+ NM_SETTING_CONNECTION_TYPE, nm_setting_get_name (s_wireless),
NM_SETTING_CONNECTION_AUTOCONNECT, !is_manufacturer_default_ssid (ap_ssid),
NULL);
@@ -414,12 +425,6 @@ create_new_connection (NMDeviceWifi *device, NMAccessPoint *ap)
g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, NULL);
g_free (id);
- id = nm_utils_uuid_generate ();
- g_object_set (s_con, NM_SETTING_CONNECTION_UUID, id, NULL);
- g_free (id);
-
- nm_connection_add_setting (connection, NM_SETTING (s_con));
-
return connection;
}
@@ -441,34 +446,34 @@ wireless_dialog_response_cb (NMAWirelessDialog *dialog,
static void
connect (NMListItem *item)
{
+ NMConnectionItem *connection_item = NM_CONNECTION_ITEM (item);
NMConnection *connection;
- NMDeviceWifi *device;
- NMAccessPoint *ap;
- connection = (NMConnection *) nm_connection_item_get_connection (NM_CONNECTION_ITEM (item));
+ connection = (NMConnection *) nm_connection_item_get_connection (connection_item);
if (connection) {
NM_LIST_ITEM_CLASS (nm_wifi_item_parent_class)->connect (item);
return;
}
/* We don't have a connection yet, so create one */
-
- device = NM_DEVICE_WIFI (nm_device_item_get_device (NM_DEVICE_ITEM (item)));
- ap = nm_wifi_item_get_ap (NM_WIFI_ITEM (item));
-
- connection = create_new_connection (device, ap);
- if (!connection)
+ connection = nm_connection_item_create_connection (connection_item);
+ if (!connection) {
+ g_warning ("Could not create a new WiFi connection");
return;
+ }
if (nm_connection_need_secrets (connection, NULL)) {
GtkWidget *dialog;
- dialog = nma_wireless_dialog_new (nm_connection_item_get_client (NM_CONNECTION_ITEM (item)),
- connection, NM_DEVICE (device), ap);
+ dialog = nma_wireless_dialog_new (nm_connection_item_get_client (connection_item),
+ connection,
+ nm_device_item_get_device (NM_DEVICE_ITEM (item)),
+ nm_wifi_item_get_ap (NM_WIFI_ITEM (item)));
+
g_signal_connect (dialog, "done", G_CALLBACK (wireless_dialog_response_cb), item);
nma_wireless_dialog_show (NMA_WIRELESS_DIALOG (dialog));
} else
- nm_connection_item_new_connection (NM_CONNECTION_ITEM (item), connection, TRUE);
+ nm_connection_item_new_connection (connection_item, connection, TRUE);
g_object_unref (connection);
}
@@ -577,6 +582,7 @@ nm_wifi_item_class_init (NMWifiItemClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMListItemClass *list_class = NM_LIST_ITEM_CLASS (klass);
+ NMConnectionItemClass *connection_class = NM_CONNECTION_ITEM_CLASS (klass);
NMDeviceItemClass *device_class = NM_DEVICE_ITEM_CLASS (klass);
g_type_class_add_private (object_class, sizeof (NMWifiItemPrivate));
@@ -589,6 +595,8 @@ nm_wifi_item_class_init (NMWifiItemClass *klass)
list_class->priority = priority;
list_class->connect = connect;
+ connection_class->create_connection = create_connection;
+
device_class->get_specific_object = wifi_get_specific_object;
device_class->get_hw_address = wifi_get_hw_address;
diff --git a/src/nmn-item-renderer.c b/src/nmn-item-renderer.c
index af4d5b5..b679a2c 100644
--- a/src/nmn-item-renderer.c
+++ b/src/nmn-item-renderer.c
@@ -212,29 +212,40 @@ update_connection_cb (NMSettingsConnectionInterface *connection,
static gboolean
details_need_updating (NmnItemRenderer *self)
{
- NmnItemRendererPrivate *priv = GET_PRIVATE (self);
+ NMConnectionItem *connection_item;
NmnConnectionDetails *details;
- NMSettingsConnectionInterface *connection;
+ NMConnection *connection;
NMSetting *current_config;
NMSetting *new_config;
+ gboolean new_connection = FALSE;
- connection = nm_connection_item_get_connection (NM_CONNECTION_ITEM (priv->item));
- if (!connection)
- /* FIXME: Now this is wrong - need to use the IP configuration still */
- return FALSE;
+ connection_item = NM_CONNECTION_ITEM (nmn_item_renderer_get_item (self));
+ connection = (NMConnection *) nm_connection_item_get_connection (connection_item);
+ if (!connection) {
+ connection = nm_connection_item_create_connection (connection_item);
+ new_connection = TRUE;
+
+ if (!connection) {
+ g_warning ("Could not create a new connection");
+ return;
+ }
+ }
- current_config = nm_connection_get_setting (NM_CONNECTION (connection), NM_TYPE_SETTING_IP4_CONFIG);
+ current_config = nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
details = get_details (self);
new_config = NM_SETTING (nmn_connection_details_get_data (NMN_CONNECTION_DETAILS (details)));
g_assert (new_config);
if (current_config == NULL || nm_setting_compare (current_config, new_config, 0) == FALSE) {
- nm_connection_add_setting (NM_CONNECTION (connection), new_config);
- nm_connection_dump (NM_CONNECTION (connection));
- nm_settings_connection_interface_update (connection,
- update_connection_cb,
- self);
+ nm_connection_add_setting (connection, new_config);
+
+ if (new_connection) {
+ nm_connection_item_new_connection (connection_item, connection, TRUE);
+ g_object_unref (connection);
+ } else
+ nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (connection),
+ update_connection_cb, self);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]