Blame SOURCES/0001-network-Summarize-sections-with-too-many-devices.patch

ab48da
From cd541f612cc7340450f4c874b7bf0ef4f84b177c Mon Sep 17 00:00:00 2001
ab48da
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
ab48da
Date: Fri, 13 May 2016 19:42:04 +0200
ab48da
Subject: [PATCH] network: Summarize sections with too many devices
ab48da
ab48da
Any network devices appear as top level items in the system status
ab48da
menu, so on system with an unusually high number of devices, the
ab48da
menu can end up exceeding the available screen height. While this
ab48da
is a corner case, leaving important system actions unreachable is
ab48da
bad. The system menu does not lend itself to scrolling, so handle
ab48da
this case instead by summarizing sections ("n connections") where
ab48da
the number of devices exceeds a threshold.
ab48da
---
ab48da
 js/ui/status/network.js | 88 ++++++++++++++++++++++++++++++++++++++++++-------
ab48da
 1 file changed, 76 insertions(+), 12 deletions(-)
ab48da
ab48da
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
ab48da
index 3ce228c..b8bd375 100644
ab48da
--- a/js/ui/status/network.js
ab48da
+++ b/js/ui/status/network.js
ab48da
@@ -39,6 +39,8 @@ const NMAccessPointSecurity = {
ab48da
     WPA2_ENT: 6
ab48da
 };
ab48da
 
ab48da
+const MAX_DEVICE_ITEMS = 4;
ab48da
+
ab48da
 // small optimization, to avoid using [] all the time
ab48da
 const NM80211Mode = NetworkManager['80211Mode'];
ab48da
 const NM80211ApFlags = NetworkManager['80211ApFlags'];
ab48da
@@ -1552,6 +1554,73 @@ const NMVPNSection = new Lang.Class({
ab48da
 });
ab48da
 Signals.addSignalMethods(NMVPNSection.prototype);
ab48da
 
ab48da
+const DeviceCategory = new Lang.Class({
ab48da
+    Name: 'DeviceCategory',
ab48da
+    Extends: PopupMenu.PopupMenuSection,
ab48da
+
ab48da
+    _init: function(category) {
ab48da
+        this.parent();
ab48da
+
ab48da
+        this._category = category;
ab48da
+
ab48da
+        this.devices = [];
ab48da
+
ab48da
+        this.section = new PopupMenu.PopupMenuSection();
ab48da
+        this.section.box.connect('actor-added', Lang.bind(this, this._sync));
ab48da
+        this.section.box.connect('actor-removed', Lang.bind(this, this._sync));
ab48da
+        this.addMenuItem(this.section);
ab48da
+
ab48da
+        this._summaryItem = new PopupMenu.PopupSubMenuMenuItem('', true);
ab48da
+        this._summaryItem.icon.icon_name = this._getSummaryIcon();
ab48da
+        this.addMenuItem(this._summaryItem);
ab48da
+
ab48da
+        this._summaryItem.menu.addSettingsAction(_('Network Settings'),
ab48da
+                                                 'gnome-network-panel.desktop');
ab48da
+        this._summaryItem.actor.hide();
ab48da
+
ab48da
+    },
ab48da
+
ab48da
+    _sync: function() {
ab48da
+        let nDevices = this.section.box.get_children().reduce(
ab48da
+            function(prev, child) {
ab48da
+                return prev + (child.visible ? 1 : 0);
ab48da
+            }, 0);
ab48da
+        this._summaryItem.label.text = this._getSummaryLabel(nDevices);
ab48da
+        let shouldSummarize = nDevices > MAX_DEVICE_ITEMS;
ab48da
+        this._summaryItem.actor.visible = shouldSummarize;
ab48da
+        this.section.actor.visible = !shouldSummarize;
ab48da
+    },
ab48da
+
ab48da
+    _getSummaryIcon: function() {
ab48da
+        switch(this._category) {
ab48da
+            case NMConnectionCategory.WIRED:
ab48da
+                return 'network-wired-symbolic';
ab48da
+            case NMConnectionCategory.WIRELESS:
ab48da
+            case NMConnectionCategory.WWAN:
ab48da
+                return 'network-wireless-symbolic';
ab48da
+        }
ab48da
+        return '';
ab48da
+    },
ab48da
+
ab48da
+    _getSummaryLabel: function(nDevices) {
ab48da
+        switch(this._category) {
ab48da
+            case NMConnectionCategory.WIRED:
ab48da
+                return ngettext("%s Wired Connection",
ab48da
+                                "%s Wired Connections",
ab48da
+                                nDevices).format(nDevices);
ab48da
+            case NMConnectionCategory.WIRELESS:
ab48da
+                return ngettext("%s Wi-Fi Connection",
ab48da
+                                "%s Wi-Fi Connections",
ab48da
+                                nDevices).format(nDevices);
ab48da
+            case NMConnectionCategory.WWAN:
ab48da
+                return ngettext("%s Modem Connection",
ab48da
+                                "%s Modem Connections",
ab48da
+                                nDevices).format(nDevices);
ab48da
+        }
ab48da
+        return '';
ab48da
+    }
ab48da
+});
ab48da
+
ab48da
 const NMApplet = new Lang.Class({
ab48da
     Name: 'NMApplet',
ab48da
     Extends: PanelMenu.SystemIndicator,
ab48da
@@ -1595,15 +1664,6 @@ const NMApplet = new Lang.Class({
ab48da
         this._tryLateInit();
ab48da
     },
ab48da
 
ab48da
-    _createDeviceCategory: function() {
ab48da
-        let category = {
ab48da
-            section: new PopupMenu.PopupMenuSection(),
ab48da
-            devices: [ ],
ab48da
-        };
ab48da
-        this.menu.addMenuItem(category.section);
ab48da
-        return category;
ab48da
-    },
ab48da
-
ab48da
     _tryLateInit: function() {
ab48da
         if (!this._client || !this._settings)
ab48da
             return;
ab48da
@@ -1620,9 +1680,13 @@ const NMApplet = new Lang.Class({
ab48da
         this._nmDevices = [];
ab48da
         this._devices = { };
ab48da
 
ab48da
-        this._devices.wired = this._createDeviceCategory();
ab48da
-        this._devices.wireless = this._createDeviceCategory();
ab48da
-        this._devices.wwan = this._createDeviceCategory();
ab48da
+        let categories = [NMConnectionCategory.WIRED,
ab48da
+                          NMConnectionCategory.WIRELESS,
ab48da
+                          NMConnectionCategory.WWAN];
ab48da
+        for (let category of categories) {
ab48da
+            this._devices[category] = new DeviceCategory(category);
ab48da
+            this.menu.addMenuItem(this._devices[category]);
ab48da
+        }
ab48da
 
ab48da
         this._vpnSection = new NMVPNSection(this._client);
ab48da
         this._vpnSection.connect('activation-failed', Lang.bind(this, this._onActivationFailed));
ab48da
-- 
ab48da
2.7.4
ab48da