[network-manager-netbook/MplPanelClient] Remove autoconnect hacks, NM now supports device disconnects.



commit 32b94c093721254f12a9a0e40ce9e602637edde2
Author: Tambet Ingo <tambet gmail com>
Date:   Thu Nov 12 14:50:35 2009 +0200

    Remove autoconnect hacks, NM now supports device disconnects.

 src/nmn-ethernet-item.c |   57 ---------------------------
 src/nmn-network-item.c  |   11 +++++-
 src/nmn-wifi-item.c     |   99 +++++++++++++----------------------------------
 3 files changed, 37 insertions(+), 130 deletions(-)
---
diff --git a/src/nmn-ethernet-item.c b/src/nmn-ethernet-item.c
index 5717bac..99c80c9 100644
--- a/src/nmn-ethernet-item.c
+++ b/src/nmn-ethernet-item.c
@@ -19,8 +19,6 @@
 
 #include <glib/gi18n.h>
 #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)
@@ -67,59 +65,6 @@ nmn_ethernet_item_new (NmnNMData *nm_data,
                                      NULL));
 }
 
-static void
-update_cb (NMSettingsConnectionInterface *connection,
-	   GError *error,
-	   gpointer data)
-{
-	NMSettingConnection *s_con;
-	NmnNetworkItem *item = data;
-
-	if (error != NULL) {
-		g_warning ("Updating auto-connect for ethernet failed: %s", error->message);
-		return;
-	}
-	s_con = NM_SETTING_CONNECTION (connection);
-	if (nm_setting_connection_get_autoconnect (s_con) == TRUE) {
-		NMN_NETWORK_ITEM_CLASS (nmn_ethernet_item_parent_class)->connect (item);
-	} else {
-		NMN_NETWORK_ITEM_CLASS (nmn_ethernet_item_parent_class)->disconnect (item);
-	}
-}
-
-static gboolean
-update_autoconnect (NmnNetworkItem *item, gboolean connect_automatically)
-{
-    NMSettingsConnectionInterface *connection;
-    NMSettingConnection *s_con;
-
-    connection = nmn_network_item_get_connection (item);
-    s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (NM_CONNECTION (connection), 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);
-    nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (connection),
-                                             update_cb,
-                                             item);
-
-    return TRUE;
-}
-
-static void
-connect (NmnNetworkItem *item)
-{
-    update_autoconnect (NMN_NETWORK_ITEM (item), TRUE);
-}
-
-static void
-disconnect (NmnNetworkItem *item)
-{
-    /* Turn off autoconnect, otherwise it would reconnect right back. */
-    update_autoconnect (item, FALSE);
-}
-
 static guint
 get_priority (NmnNetworkItem *item)
 {
@@ -184,7 +129,5 @@ nmn_ethernet_item_class_init (NmnEthernetItemClass *class)
     object_class->constructor = constructor;
     object_class->dispose = dispose;
 
-    network_item_class->connect = connect;
-    network_item_class->disconnect = disconnect;
     network_item_class->get_priority = get_priority;
 }
diff --git a/src/nmn-network-item.c b/src/nmn-network-item.c
index 6ba8ea0..760c5ab 100644
--- a/src/nmn-network-item.c
+++ b/src/nmn-network-item.c
@@ -420,6 +420,15 @@ connect (NmnNetworkItem *item)
 }
 
 static void
+disconnect_cb (NMDevice *device, GError *error, gpointer user_data)
+{
+    if (error)
+        g_warning ("Device disconnect failed: (%d) %s",
+                   error ? error->code : -1,
+                   error && error->message ? error->message : "(unknown)");
+}
+
+static void
 disconnect (NmnNetworkItem *item)
 {
     NmnNetworkItemPrivate *priv = GET_PRIVATE (item);
@@ -429,7 +438,7 @@ disconnect (NmnNetworkItem *item)
         return;
     }
 
-    nm_client_deactivate_connection (NM_CLIENT (priv->nm_data), priv->ac);
+    nm_device_disconnect (priv->device, disconnect_cb, item);
 }
 
 void
diff --git a/src/nmn-wifi-item.c b/src/nmn-wifi-item.c
index df9ffb9..17aac44 100644
--- a/src/nmn-wifi-item.c
+++ b/src/nmn-wifi-item.c
@@ -429,87 +429,43 @@ wireless_dialog_response_cb (NMAWirelessDialog *dialog,
 
 static void
 update_cb (NMSettingsConnectionInterface *connection,
-	   GError *error,
-	   gpointer data)
+           GError *error,
+           gpointer data)
 {
-	NMSettingConnection *s_con;
-	NmnNetworkItem *item = data;
-
-	if (error != NULL) {
-		g_warning ("Updating auto-connect for wifi failed: %s", error->message);
-		g_error_free (error);
-		return;
-	}
-	s_con = NM_SETTING_CONNECTION (connection);
-	if (nm_setting_connection_get_autoconnect (s_con) == TRUE) {
-		NMN_NETWORK_ITEM_CLASS (nmn_wifi_item_parent_class)->connect (item);
-	} else {
-		NMN_NETWORK_ITEM_CLASS (nmn_wifi_item_parent_class)->disconnect (item);
-	}
-}
-
-static gboolean
-update_autoconnect (NmnNetworkItem *item, gboolean connect_automatically)
-{
-    NMSettingsConnectionInterface *connection;
-    NMSettingConnection *s_con;
-
-    connection = nmn_network_item_get_connection (item);
-    s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (NM_CONNECTION (connection), 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);
-
-    nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (connection),
-                                             update_cb,
-                                             item);
-
-    return TRUE;
+	if (error)
+		g_warning ("Failed to updated wifi connection: %s", error->message);
 }
 
 static void
 connect (NmnNetworkItem *item)
 {
-    if (!nmn_network_item_get_connection (item)) {
-        NMDevice *device;
-        NMAccessPoint *ap;
-        NMConnection *connection;
-
-        device = nmn_network_item_get_device (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;
-
-            nm_data = nmn_network_item_get_nm_data (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));
-        } else
-            wifi_item_created (item, connection);
-
-        g_object_unref (connection);
-    } else {
-        update_autoconnect (item, TRUE);
+    NMDevice *device;
+    NMAccessPoint *ap;
+    NMConnection *connection;
+
+    if (nmn_network_item_get_connection (item)) {
         NMN_NETWORK_ITEM_CLASS (nmn_wifi_item_parent_class)->connect (item);
+        return;
     }
-}
 
-static void
-disconnect (NmnNetworkItem *item)
-{
-    if (nmn_nm_data_wifi_get_active (nmn_network_item_get_nm_data (NMN_NETWORK_ITEM (item)))) {
-        /* Turn off autoconnect, otherwise it would reconnect right back. */
-        update_autoconnect (item, FALSE);
-    }
+    device = nmn_network_item_get_device (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;
 
-    NMN_NETWORK_ITEM_CLASS (nmn_wifi_item_parent_class)->disconnect (item);
+        nm_data = nmn_network_item_get_nm_data (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));
+    } else
+        wifi_item_created (item, connection);
+
+    g_object_unref (connection);
 }
 
 static guint
@@ -772,7 +728,6 @@ nmn_wifi_item_class_init (NmnWifiItemClass *class)
     object_class->dispose = dispose;
 
     network_item_class->connect = connect;
-    network_item_class->disconnect = disconnect;
     network_item_class->get_priority = get_priority;
     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]