NetworkMenu patches (part one)



Given that bugzilla is down, attaching fixes for two bugs to the Network
Menu, as discussed in IRC.

Giovanni
From 181470314e5c696aef5c14407d9ef4b5f2bb2c54 Mon Sep 17 00:00:00 2001
From: Giovanni Campagna <gcampagna src gnome org>
Date: Fri, 25 Mar 2011 17:10:38 +0100
Subject: [PATCH 1/2] NetworkStatus: show "firmware missing" when firmware is not available

Since device state Unavailable is generic and has substates, instead
of using an hack for carrier, introduce some code that checks both
for carrier and firmware-missing when in that device state, and updates
the UI accordingly.
---
 js/ui/status/network.js |   46 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index e57349a..eefbd12 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -478,15 +478,27 @@ NMDevice.prototype = {
             /* Translators: this is for network connections that require some kind of key or password */
             return _("authentication required");
         case NetworkManager.DeviceState.UNAVAILABLE:
-            // we don't check if the carrier property is actually false, as that causes race
-            // conditions if state is changed before the new carrier value is picked by libnm-glib
-            if (this.device.capabilities & NetworkManager.DeviceCapabilities.CARRIER_DETECT)
-                /* Translators: this is for wired network devices that are physically disconnected */
-                return _("cable unplugged");
-            else
-                /* Translators: this is for a network device that cannot be activated (for example it
-                   is disabled by rfkill, or it has no coverage */
-                return _("unavailable");
+            // This state is actually a compound of various states (generically unavailable,
+            // firmware missing, carrier not available), that are exposed by different properties
+            // (whose state may or may not updated when we receive state-changed).
+            if (!this._firmwareMissingId)
+                this._firmwareMissingId = this.device.connect('notify::firmware-missing', Lang.bind(this, this._substateChanged));
+            if (this.device.firmware_missing) {
+                /* Translators: this is for devices that require some kind of firmware or kernel
+                   module, which is missing */
+                return _("firmware missing");
+            }
+            if (this.device.capabilities & NetworkManager.DeviceCapabilities.CARRIER_DETECT) {
+                if (!this._carrierChangedId)
+                    this._carrierChangedId = this.device.connect('notify::carrier', Lang.bind(this, this._substateChanged));
+                if (!this.carrier) {
+                    /* Translators: this is for wired network devices that are physically disconnected */
+                    return _("cable unplugged");
+                }
+            }
+            /* Translators: this is for a network device that cannot be activated (for example it
+               is disabled by rfkill, or it has no coverage */
+            return _("unavailable");
         case NetworkManager.DeviceState.FAILED:
             return _("connection failed");
         default:
@@ -595,6 +607,16 @@ NMDevice.prototype = {
             break;
         }
 
+        if (this._carrierChangedId) {
+            // see above for why this is needed
+            GObject.prototype.disconnect.call(this.device, this._carrierChangedId);
+            this._carrierChangedId = 0;
+        }
+        if (this._firmwareChangedId) {
+            GObject.prototype.disconnect.call(this.device, this._firmwareChangedId);
+            this._firmwareChangedId = 0;
+        }
+
         this.statusItem.setStatus(this.getStatusLabel());
         this.statusItem.setToggleState(this.connected);
 
@@ -603,6 +625,12 @@ NMDevice.prototype = {
         this.emit('state-changed');
     },
 
+    _substateChanged: function() {
+        this.statusItem.setStatus(this.getStatusLabel());
+
+        this.emit('state-changed');
+    },
+
     _getDescription: function() {
         let dev_product = this.device.get_product();
         let dev_vendor = this.device.get_vendor();
-- 
1.7.4.1

From cc7c08444005eb00e215b81f7789c7727552a891 Mon Sep 17 00:00:00 2001
From: Giovanni Campagna <gcampagna src gnome org>
Date: Fri, 25 Mar 2011 17:12:38 +0100
Subject: [PATCH 2/2] NetworkStatus: hide the only connection for wired devices

For wired devices (actually, ethernet devices), hide the connection
list when there is only one connection (either automatic or stored).
The device can be operated with the associated switch.
---
 js/ui/status/network.js |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index eefbd12..da24cc2 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -449,8 +449,10 @@ NMDevice.prototype = {
             obj.item.destroy();
         this._connections.splice(pos, 1);
 
-        if (this._connections.length == 0) {
+        if (this._connections.length <= 1) {
             // We need to show the automatic connection again
+            // (or in the case of NMDeviceWired, we want to hide
+            // the only explicit connection)
             this._clearSection();
             this._createSection();
         }
@@ -678,6 +680,20 @@ NMDeviceWired.prototype = {
         return true;
     },
 
+    _createSection: function() {
+        NMDevice.prototype._createSection.call(this);
+
+        // if we have only one connection (normal or automatic)
+        // we hide the connection list, and use the switch to control
+        // the device
+        // we can do it here because addConnection and removeConnection
+        // both call _createSection at some point
+        if (this._connections.length <= 1)
+            this.section.actor.hide();
+        else
+            this.section.actor.show();
+    },
+
     _createAutomaticConnection: function() {
         let connection = new NetworkManager.Connection();
         connection._uuid = NetworkManager.utils_uuid_generate();
-- 
1.7.4.1

Attachment: signature.asc
Description: This is a digitally signed message part



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