[network-manager-netbook] Set the 'autoconnect' property off when wifi connection is disconnected.



commit 275607be6545664358104de7479192de931c246b
Author: Tambet Ingo <tambet gmail com>
Date:   Wed May 27 12:08:38 2009 +0300

    Set the 'autoconnect' property off when wifi connection is disconnected.
    
    Otherwise the connection would get automatically activated again. Turn it on
    again on manual connect request.
---
 src/nmn-wifi-item.c |   44 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/src/nmn-wifi-item.c b/src/nmn-wifi-item.c
index 0a90a22..0343c46 100644
--- a/src/nmn-wifi-item.c
+++ b/src/nmn-wifi-item.c
@@ -403,6 +403,30 @@ wireless_dialog_response_cb (NMAWirelessDialog *dialog,
     gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 
+static gboolean
+update_autoconnect (NmnNetworkItem *item, gboolean connect_automatically)
+{
+    NMExportedConnection *exported;
+    NMConnection *wrapped;
+    NMSettingConnection *s_con;
+    GHashTable *new_settings;
+
+    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);
+
+    nm_exported_connection_update (exported, new_settings, NULL);
+    g_hash_table_unref (new_settings);
+
+    return TRUE;
+}
+
 static void
 connect (NmnItem *item)
 {
@@ -412,6 +436,7 @@ connect (NmnItem *item)
     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);
@@ -442,12 +467,26 @@ connect (NmnItem *item)
 
         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);
 
-    /* Clear the exported connection again - the main networks list will handle password requests and so on. */
-    nmn_network_item_set_connection (network_item, NULL);
+    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);
+    }
+}
+
+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_wifi_item_parent_class)->disconnect (item);
 }
 
 static const char *
@@ -685,6 +724,7 @@ nmn_wifi_item_class_init (NmnWifiItemClass *class)
     object_class->dispose = dispose;
 
     item_class->connect = connect;
+    item_class->disconnect = disconnect;
     network_item_class->get_specific_object = get_specific_object;
     network_item_class->secrets_requested = secrets_requested;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]