[gnome-shell/gnome-3-0] network: simplify connection sorting by using libnm-glib functions



commit 8dd45bea1c620d3553913eedd04569c69bfc49c0
Author: Dan Williams <dcbw redhat com>
Date:   Mon Apr 25 17:13:12 2011 -0500

    network: simplify connection sorting by using libnm-glib functions
    
    Instead of rolling our own code, use new libnm-glib functions to do
    the same thing.  Requires libnm-glib as of
    779215c742bbe29a2c66202ec7e2e6d43edeb8ff (which will be part of 0.9).
    
    Fixes https://bugzilla.gnome.org/show_bug.cgi?id=648648

 configure.ac            |    2 +-
 js/ui/status/network.js |  104 +++--------------------------------------------
 2 files changed, 7 insertions(+), 99 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 7f82ccc..dfb7b2a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -100,7 +100,7 @@ AC_SUBST([GJS_VERSION], ["$GJS_VERSION"])
 GOBJECT_INTROSPECTION_CHECK([$GOBJECT_INTROSPECTION_MIN_VERSION])
 JHBUILD_TYPELIBDIR="$INTROSPECTION_TYPELIBDIR"
 # NM is the only typelib we use that we don't jhbuild
-PKG_CHECK_EXISTS([libnm-glib >= 0.8.995],
+PKG_CHECK_EXISTS([libnm-glib >= 0.8.999],
         [NM_TYPELIBDIR=`$PKG_CONFIG --variable=libdir libnm-glib`/girepository-1.0
 	 if test "$INTROSPECTION_TYPELIBDIR" != "$NM_TYPELIBDIR"; then
 	     JHBUILD_TYPELIBDIR="$JHBUILD_TYPELIBDIR:$NM_TYPELIBDIR"
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 6fa5642..0c467e6 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -501,7 +501,7 @@ NMDevice.prototype = {
     },
 
     connectionValid: function(connection) {
-        throw new TypeError('Invoking pure virtual function NMDevice.connectionValid');
+        return this.device.connection_valid(connection);
     },
 
     setEnabled: function(enabled) {
@@ -719,17 +719,6 @@ NMDeviceWired.prototype = {
         NMDevice.prototype._init.call(this, client, device, connections);
     },
 
-    connectionValid: function(connection) {
-        if (connection._type != NetworkManager.SETTING_WIRED_SETTING_NAME)
-            return false;
-
-        let ethernetSettings = connection.get_setting_by_name(NetworkManager.SETTING_WIRED_SETTING_NAME);
-        let fixedMac = ethernetSettings.get_mac_address();
-        if (fixedMac)
-            return macCompare(fixedMac, macToArray(this.device.perm_hw_address));
-        return true;
-    },
-
     _createSection: function() {
         NMDevice.prototype._createSection.call(this);
 
@@ -872,10 +861,6 @@ NMDeviceModem.prototype = {
         NMDevice.prototype._clearSection.call(this);
     },
 
-    connectionValid: function(connection) {
-        return connection._type == this._connectionType;
-    },
-
     _createAutomaticConnection: function() {
         // FIXME: we need to summon the mobile wizard here
         // or NM will not have the necessary parameters to complete the connection
@@ -909,18 +894,6 @@ NMDeviceBluetooth.prototype = {
         NMDevice.prototype._init.call(this, client, device, connections);
     },
 
-    connectionValid: function(connection) {
-        if (connection._type != NetworkManager.SETTING_BLUETOOTH_SETTING_NAME)
-            return false;
-
-        let bluetoothSettings = connection.get_setting_by_name(NetworkManager.SETTING_BLUETOOTH_SETTING_NAME);
-        let fixedBdaddr = bluetoothSettings.get_bdaddr();
-        if (fixedBdaddr)
-            return macCompare(fixedBdaddr, macToArray(this.device.hw_address));
-
-        return true;
-    },
-
     _createAutomaticConnection: function() {
         let connection = new NetworkManager.Connection;
         connection._uuid = NetworkManager.utils_uuid_generate();
@@ -1042,7 +1015,7 @@ NMDeviceWireless.prototype = {
             // Check if some connection is valid for this AP
             for (let j = 0; j < validConnections.length; j++) {
                 let connection = validConnections[j];
-                if (this._connectionValidForAP(connection, ap) &&
+                if (ap.connection_valid(connection) &&
                     obj.connections.indexOf(connection) == -1) {
                     obj.connections.push(connection);
                 }
@@ -1103,7 +1076,7 @@ NMDeviceWireless.prototype = {
         if (best) {
             for (let i = 0; i < bestApObj.accessPoints.length; i++) {
                 let ap = bestApObj.accessPoints[i];
-                if (this._connectionValidForAP(best, ap)) {
+                if (ap.connection_valid(best)) {
                     this._client.activate_connection(best, this.device, ap.dbus_path, null);
                     break;
                 }
@@ -1195,7 +1168,7 @@ NMDeviceWireless.prototype = {
         // check if this enables new connections for this group
         for (let i = 0; i < this._connections.length; i++) {
             let connection = this._connections[i].connection;
-            if (this._connectionValidForAP(connection, accessPoint) &&
+            if (accessPoint.connection_valid(connection) &&
                 apObj.connections.indexOf(connection) == -1) {
                 apObj.connections.push(connection);
             }
@@ -1243,7 +1216,7 @@ NMDeviceWireless.prototype = {
         item.connect('activate', Lang.bind(this, function() {
             let accessPoints = sortAccessPoints(accessPointObj.accessPoints);
             for (let i = 0; i < accessPoints.length; i++) {
-                if (this._connectionValidForAP(connection, accessPoints[i])) {
+                if (accessPoints[i].connection_valid(connection)) {
                     this._client.activate_connection(connection, this.device, accessPoints[i].dbus_path, null);
                     break;
                 }
@@ -1252,40 +1225,6 @@ NMDeviceWireless.prototype = {
         return item;
     },
 
-    connectionValid: function(connection) {
-        if (connection._type != NetworkManager.SETTING_WIRELESS_SETTING_NAME)
-            return false;
-
-        let wirelessSettings = connection.get_setting_by_name(NetworkManager.SETTING_WIRELESS_SETTING_NAME);
-        let wirelessSecuritySettings = connection.get_setting_by_name(NetworkManager.SETTING_WIRELESS_SECURITY_SETTING_NAME);
-
-        let fixedMac = wirelessSettings.get_mac_address();
-        if (fixedMac && !macCompare(fixedMac, macToArray(this.device.perm_hw_address)))
-            return false;
-
-        if (wirelessSecuritySettings &&
-            wirelessSecuritySettings.key_mgmt != 'none' &&
-            wirelessSecuritySettings.key_mgmt != 'ieee8021x') {
-            let capabilities = this.device.wireless_capabilities;
-            if (!(capabilities & NetworkManager.DeviceWifiCapabilities.WPA) ||
-                !(capabilities & NetworkManager.DeviceWifiCapabilities.CIPHER_TKIP))
-                return false;
-            if (wirelessSecuritySettings.get_num_protos() == 1 &&
-                wirelessSecuritySettings.get_proto(0) == 'rsn' &&
-                !(capabilities & NetworkManager.DeviceWifiCapabilities.RSN))
-                return false;
-            if (wirelessSecuritySettings.get_num_pairwise() == 1 &&
-                wirelessSecuritySettings.get_pairwise(0) == 'ccmp' &&
-                !(capabilities & NetworkManager.DeviceWifiCapabilities.CIPHER_CCMP))
-                return false;
-            if (wirelessSecuritySettings.get_num_groups() == 1 &&
-                wirelessSecuritySettings.get_group(0) == 'ccmp' &&
-                !(capabilities & NetworkManager.DeviceWifiCapabilities.CIPHER_CCMP))
-                return false;
-        }
-        return true;
-    },
-
     _clearSection: function() {
         NMDevice.prototype._clearSection.call(this);
 
@@ -1363,7 +1302,7 @@ NMDeviceWireless.prototype = {
             let any = false;
             for (let k = 0; k < apObj.accessPoints.length; k++) {
                 let ap = apObj.accessPoints[k];
-                if (this._connectionValidForAP(connection, ap)) {
+                if (ap.connection_valid(connection)) {
                     apObj.connections.push(connection);
                     any = true;
                     break;
@@ -1396,37 +1335,6 @@ NMDeviceWireless.prototype = {
         }
     },
 
-    _connectionValidForAP: function(connection, ap) {
-        // copied and adapted from nm-applet
-        let wirelessSettings = connection.get_setting_by_name(NetworkManager.SETTING_WIRELESS_SETTING_NAME);
-        if (!ssidCompare(wirelessSettings.get_ssid(), ap.get_ssid()))
-            return false;
-
-        let wirelessSecuritySettings = connection.get_setting_by_name(NetworkManager.SETTING_WIRELESS_SECURITY_SETTING_NAME);
-
-        let fixedBssid = wirelessSettings.get_bssid();
-        if (fixedBssid && !macCompare(fixedBssid, macToArray(ap.hw_address)))
-            return false;
-
-        let fixedBand = wirelessSettings.band;
-        if (fixedBand) {
-            let freq = ap.frequency;
-            if (fixedBand == 'a' && (freq < 4915 || freq > 5825))
-                return false;
-            if (fixedBand == 'bg' && (freq < 2412 || freq > 2484))
-                return false;
-        }
-
-        let fixedChannel = wirelessSettings.channel;
-        if (fixedChannel && fixedChannel != NetworkManager.utils_wifi_freq_to_channel(ap.frequency))
-            return false;
-
-        if (!wirelessSecuritySettings)
-            return true;
-
-        return wirelessSettings.ap_security_compatible(wirelessSecuritySettings, ap.flags, ap.wpa_flags, ap.rsn_flags, ap.mode);
-    },
-
     _createActiveConnectionItem: function() {
         let activeAp = this.device.active_access_point;
         let icon, title;



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