[network-manager-netbook] Set the 'autoconnect' property off when ethernet connection is disconnected.
- From: Tambet Ingo <tambeti src gnome org>
- To: svn-commits-list gnome org
- Subject: [network-manager-netbook] Set the 'autoconnect' property off when ethernet connection is disconnected.
- Date: Wed, 27 May 2009 07:44:49 -0400 (EDT)
commit e8679a89611fd07e99e09b125dfafdfd1822ef60
Author: Tambet Ingo <tambet gmail com>
Date: Wed May 27 12:06:42 2009 +0300
Set the 'autoconnect' property off when ethernet connection is disconnected.
Otherwise the connection would get automatically activated again. Turn it on
again on manual connect request.
---
src/nmn-ethernet-item.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/src/nmn-ethernet-item.c b/src/nmn-ethernet-item.c
index 9cac9f7..ff8158f 100644
--- a/src/nmn-ethernet-item.c
+++ b/src/nmn-ethernet-item.c
@@ -1,6 +1,8 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include <NetworkManager.h>
+#include <nm-connection.h>
+#include <nm-setting-connection.h>
#include "nmn-ethernet-item.h"
G_DEFINE_TYPE (NmnEthernetItem, nmn_ethernet_item, NMN_TYPE_NETWORK_ITEM)
@@ -46,6 +48,53 @@ nmn_ethernet_item_new (NmnNMData *nm_data,
NULL));
}
+static gboolean
+update_autoconnect (NmnNetworkItem *item, gboolean connect_automatically)
+{
+ NMExportedConnection *exported;
+ NMConnection *wrapped;
+ NMSettingConnection *s_con;
+ GHashTable *new_settings;
+ GError *error = NULL;
+
+ exported = nmn_network_item_get_connection (item);
+ wrapped = nm_exported_connection_get_connection (exported);
+ s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (wrapped, NM_TYPE_SETTING_CONNECTION));
+
+ if (nm_setting_connection_get_autoconnect (s_con) == connect_automatically)
+ return FALSE;
+
+ g_object_set (s_con, NM_SETTING_CONNECTION_AUTOCONNECT, connect_automatically, NULL);
+ new_settings = nm_connection_to_hash (wrapped);
+
+ if (!nm_exported_connection_update (exported, new_settings, &error)) {
+ if (error) {
+ g_warning ("Couldn't update ethernet connection: %s", error->message);
+ g_error_free (error);
+ } else
+ g_warning ("Couldn't update ethernet connection: no details");
+ }
+
+ g_hash_table_unref (new_settings);
+
+ return TRUE;
+}
+
+static void
+connect (NmnItem *item)
+{
+ update_autoconnect (NMN_NETWORK_ITEM (item), TRUE);
+ NMN_ITEM_CLASS (nmn_ethernet_item_parent_class)->connect (item);
+}
+
+static void
+disconnect (NmnItem *item)
+{
+ /* Turn off autoconnect, otherwise it would reconnect right back. */
+ update_autoconnect (NMN_NETWORK_ITEM (item), FALSE);
+ NMN_ITEM_CLASS (nmn_ethernet_item_parent_class)->disconnect (item);
+}
+
static void
nmn_ethernet_item_init (NmnEthernetItem *item)
{
@@ -97,9 +146,13 @@ static void
nmn_ethernet_item_class_init (NmnEthernetItemClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
+ NmnItemClass *item_class = NMN_ITEM_CLASS (class);
g_type_class_add_private (object_class, sizeof (NmnEthernetItemPrivate));
object_class->constructor = constructor;
object_class->dispose = dispose;
+
+ item_class->connect = connect;
+ item_class->disconnect = disconnect;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]