[gnome-shell/3.7.2.1-branch: 1/2] Revert "NetworkMenu: rework multiple NIC support"



commit 4233ca29836991f35d08b8cfb144f2b155f42b29
Author: Florian MÃllner <fmuellner gnome org>
Date:   Fri Nov 23 17:49:11 2012 +0100

    Revert "NetworkMenu: rework multiple NIC support"
    
    This reverts commit 490206b5b23649017859b9cb6d534cce1855d6dd.

 configure.ac            |    6 +--
 js/misc/util.js         |   80 ++++++++++++++++++++++++++++
 js/ui/status/network.js |  132 +++++++++++++++++++++++++++++-----------------
 3 files changed, 165 insertions(+), 53 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9d3bb3f..e0604b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -78,7 +78,6 @@ STARTUP_NOTIFICATION_MIN_VERSION=0.11
 GCR_MIN_VERSION=3.3.90
 GNOME_DESKTOP_REQUIRED_VERSION=3.7.1
 GNOME_MENUS_REQUIRED_VERSION=3.5.3
-NETWORKMANAGER_MIN_VERSION=0.9.7
 
 # Collect more than 20 libraries for a prize!
 PKG_CHECK_MODULES(GNOME_SHELL, gio-unix-2.0 >= $GIO_MIN_VERSION
@@ -99,9 +98,8 @@ PKG_CHECK_MODULES(GNOME_SHELL, gio-unix-2.0 >= $GIO_MIN_VERSION
                                telepathy-glib >= $TELEPATHY_GLIB_MIN_VERSION
                                telepathy-logger-0.2 >= $TELEPATHY_LOGGER_MIN_VERSION
                                polkit-agent-1 >= $POLKIT_MIN_VERSION xfixes
-                               libnm-glib libnm-util >= $NETWORKMANAGER_MIN_VERSION
-                               libnm-gtk >= $NETWORKMANAGER_MIN_VERSION
-                               gnome-keyring-1 gcr-3 >= $GCR_MIN_VERSION)
+                               libnm-glib libnm-util gnome-keyring-1
+                               gcr-3 >= $GCR_MIN_VERSION)
 
 PKG_CHECK_MODULES(SHELL_PERF_HELPER, gtk+-3.0 gio-2.0)
 
diff --git a/js/misc/util.js b/js/misc/util.js
index 98c2310..fb936c9 100644
--- a/js/misc/util.js
+++ b/js/misc/util.js
@@ -159,6 +159,86 @@ function killall(processName) {
     }
 }
 
+// This was ported from network-manager-applet
+// Copyright 2007 - 2011 Red Hat, Inc.
+// Author: Dan Williams <dcbw redhat com>
+
+const _IGNORED_WORDS = [
+        'Semiconductor',
+        'Components',
+        'Corporation',
+        'Communications',
+        'Company',
+        'Corp.',
+        'Corp',
+        'Co.',
+        'Inc.',
+        'Inc',
+        'Incorporated',
+        'Ltd.',
+        'Limited.',
+        'Intel',
+        'chipset',
+        'adapter',
+        '[hex]',
+        'NDIS',
+        'Module'
+];
+
+const _IGNORED_PHRASES = [
+        'Multiprotocol MAC/baseband processor',
+        'Wireless LAN Controller',
+        'Wireless LAN Adapter',
+        'Wireless Adapter',
+        'Network Connection',
+        'Wireless Cardbus Adapter',
+        'Wireless CardBus Adapter',
+        '54 Mbps Wireless PC Card',
+        'Wireless PC Card',
+        'Wireless PC',
+        'PC Card with XJACK(r) Antenna',
+        'Wireless cardbus',
+        'Wireless LAN PC Card',
+        'Technology Group Ltd.',
+        'Communication S.p.A.',
+        'Business Mobile Networks BV',
+        'Mobile Broadband Minicard Composite Device',
+        'Mobile Communications AB',
+        '(PC-Suite Mode)'
+];
+
+function fixupPCIDescription(desc) {
+    desc = desc.replace(/[_,]/, ' ');
+
+    /* Attempt to shorten ID by ignoring certain phrases */
+    for (let i = 0; i < _IGNORED_PHRASES.length; i++) {
+        let item = _IGNORED_PHRASES[i];
+        let pos = desc.indexOf(item);
+        if (pos != -1) {
+            let before = desc.substring(0, pos);
+            let after = desc.substring(pos + item.length, desc.length);
+            desc = before + after;
+        }
+    }
+
+    /* Attmept to shorten ID by ignoring certain individual words */
+    let words = desc.split(' ');
+    let out = [ ];
+    for (let i = 0; i < words.length; i++) {
+        let item = words[i];
+
+        // skip empty items (that come out from consecutive spaces)
+        if (item.length == 0)
+            continue;
+
+        if (_IGNORED_WORDS.indexOf(item) == -1) {
+            out.push(item);
+        }
+    }
+
+    return out.join(' ');
+}
+
 // lowerBound:
 // @array: an array or array-like object, already sorted
 //         according to @cmp
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 9da066d..5e4c472 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -5,7 +5,6 @@ const Gio = imports.gi.Gio;
 const Lang = imports.lang;
 const NetworkManager = imports.gi.NetworkManager;
 const NMClient = imports.gi.NMClient;
-const NMGtk = imports.gi.NMGtk;
 const Signals = imports.signals;
 const St = imports.gi.St;
 
@@ -140,6 +139,46 @@ const NMNetworkMenuItem = new Lang.Class({
     }
 });
 
+const NMWiredSectionTitleMenuItem = new Lang.Class({
+    Name: 'NMWiredSectionTitleMenuItem',
+    Extends: PopupMenu.PopupSwitchMenuItem,
+
+    _init: function(label, params) {
+        params = params || { };
+        params.style_class = 'popup-subtitle-menu-item';
+        this.parent(label, false, params);
+    },
+
+    updateForDevice: function(device) {
+        if (device) {
+            this._device = device;
+            this.setStatus(device.getStatusLabel());
+            this.setToggleState(device.connected);
+        } else
+            this.setStatus('');
+    },
+
+    activate: function(event) {
+        this.parent(event);
+
+        if (!this._device) {
+            log('Section title activated when there is more than one device, should be non reactive');
+            return;
+        }
+
+        let newState = this._switch.state;
+
+        let ok;
+        if (newState)
+            ok = this._device.activate();
+        else
+            ok = this._device.deactivate();
+
+        if (!ok)
+            this._switch.setToggleState(false);
+    }
+});
+
 const NMWirelessSectionTitleMenuItem = new Lang.Class({
     Name: 'NMWirelessSectionTitleMenuItem',
     Extends: PopupMenu.PopupSwitchMenuItem,
@@ -312,7 +351,7 @@ const NMDevice = new Lang.Class({
         this._autoConnectionItem = null;
         this._overflowItem = null;
 
-        this.statusItem = new PopupMenu.PopupSwitchMenuItem('', this.connected, { style_class: 'popup-subtitle-menu-item' });
+        this.statusItem = new PopupMenu.PopupSwitchMenuItem(this._getDescription(), this.connected, { style_class: 'popup-subtitle-menu-item' });
         this._statusChanged = this.statusItem.connect('toggled', Lang.bind(this, function(item, state) {
             let ok;
             if (state)
@@ -473,10 +512,6 @@ const NMDevice = new Lang.Class({
         }
     },
 
-    syncDescription: function() {
-        this.statusItem.label.text = this.device._description;
-    },
-
     // protected
     _createAutomaticConnection: function() {
         throw new TypeError('Invoking pure virtual function NMDevice.createAutomaticConnection');
@@ -604,6 +639,25 @@ const NMDevice = new Lang.Class({
         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();
+        if (!dev_product || !dev_vendor)
+	    return '';
+
+        let product = Util.fixupPCIDescription(dev_product);
+        let vendor = Util.fixupPCIDescription(dev_vendor);
+        let out = '';
+
+        // Another quick hack; if all of the fixed up vendor string
+        // is found in product, ignore the vendor.
+        if (product.indexOf(vendor) == -1)
+            out += vendor + ' ';
+        out += product;
+
+        return out;
     }
 });
 
@@ -813,6 +867,10 @@ const NMDeviceBluetooth = new Lang.Class({
         this._clearSection();
         this._queueCreateSection();
         this._updateStatusItem();
+    },
+
+    _getDescription: function() {
+        return this.device.name || _("Bluetooth");
     }
 });
 
@@ -1593,14 +1651,15 @@ const NMApplet = new Lang.Class({
         this._mobileUpdateId = 0;
         this._mobileUpdateDevice = null;
 
-        this._nmDevices = [];
         this._devices = { };
 
         this._devices.wired = {
             section: new PopupMenu.PopupMenuSection(),
             devices: [ ],
+            item: new NMWiredSectionTitleMenuItem(_("Wired"))
         };
 
+        this._devices.wired.section.addMenuItem(this._devices.wired.item);
         this._devices.wired.section.actor.hide();
         this.menu.addMenuItem(this._devices.wired.section);
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
@@ -1608,7 +1667,7 @@ const NMApplet = new Lang.Class({
         this._devices.wireless = {
             section: new PopupMenu.PopupMenuSection(),
             devices: [ ],
-            item: this._makeToggleItem('wireless', _("Wi-Fi"))
+            item: this._makeToggleItem('wireless', _("Wireless"))
         };
         this._devices.wireless.section.addMenuItem(this._devices.wireless.item);
         this._devices.wireless.section.actor.hide();
@@ -1618,7 +1677,9 @@ const NMApplet = new Lang.Class({
         this._devices.wwan = {
             section: new PopupMenu.PopupMenuSection(),
             devices: [ ],
+            item: this._makeToggleItem('wwan', _("Mobile broadband"))
         };
+        this._devices.wwan.section.addMenuItem(this._devices.wwan.item);
         this._devices.wwan.section.actor.hide();
         this.menu.addMenuItem(this._devices.wwan.section);
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
@@ -1701,23 +1762,16 @@ const NMApplet = new Lang.Class({
             section.actor.hide();
         else {
             section.actor.show();
-
-            // Sync the relation between the section title
-            // item (the one with the airplane mode switch)
-            // and the individual device switches
-            if (item) {
-                if (devices.length == 1) {
-                    let dev = devices[0];
-                    dev.statusItem.actor.hide();
-                    item.updateForDevice(dev);
-                } else {
-                    devices.forEach(function(dev) {
-                        dev.statusItem.actor.show();
-                    });
-
-                    // remove status text from the section title item
-                    item.updateForDevice(null);
-                }
+            if (devices.length == 1) {
+                let dev = devices[0];
+                dev.statusItem.actor.hide();
+                item.updateForDevice(dev);
+            } else {
+                devices.forEach(function(dev) {
+                    dev.statusItem.actor.show();
+                });
+                // remove status text from the section title item
+                item.updateForDevice(null);
             }
         }
     },
@@ -1725,9 +1779,8 @@ const NMApplet = new Lang.Class({
     _readDevices: function() {
         let devices = this._client.get_devices() || [ ];
         for (let i = 0; i < devices.length; ++i) {
-            this._deviceAdded(this._client, devices[i], true);
+            this._deviceAdded(this._client, devices[i]);
         }
-        this._syncDeviceNames();
     },
 
     _notifyForDevice: function(device, iconName, title, text, urgency) {
@@ -1775,18 +1828,7 @@ const NMApplet = new Lang.Class({
         return wrapper;
     },
 
-    _syncDeviceNames: function() {
-        let names = NMGtk.utils_disambiguate_device_names(this._nmDevices);
-        for (let i = 0; i < this._nmDevices.length; i++) {
-            let device = this._nmDevices[i];
-            if (device._description != names[i]) {
-                device._description = names[i];
-                device._delegate.syncDescription();
-            }
-        }
-    },
-
-    _deviceAdded: function(client, device, skipSyncDeviceNames) {
+    _deviceAdded: function(client, device) {
         if (device._delegate) {
             // already seen, not adding again
             return;
@@ -1797,14 +1839,10 @@ const NMApplet = new Lang.Class({
             let section = this._devices[wrapper.category].section;
             let devices = this._devices[wrapper.category].devices;
 
-            section.addMenuItem(wrapper.statusItem);
-            section.addMenuItem(wrapper.section);
+            section.addMenuItem(wrapper.section, 1);
+            section.addMenuItem(wrapper.statusItem, 1);
             devices.push(wrapper);
 
-            this._nmDevices.push(device);
-            if (!skipSyncDeviceNames)
-                this._syncDeviceNames();
-
             this._syncSectionTitle(wrapper.category);
         }
     },
@@ -1822,10 +1860,6 @@ const NMApplet = new Lang.Class({
         let pos = devices.indexOf(wrapper);
         devices.splice(pos, 1);
 
-        pos = this._nmDevices.indexOf(device);
-        this._nmDevices.splice(pos, 1);
-        this._syncDeviceNames();
-
         this._syncSectionTitle(wrapper.category)
     },
 



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