[gnome-shell] status/network: Move settings item into toplevel section



commit c84d63854f52d3344d19a4b290329799fff1d437
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Aug 3 05:35:25 2022 +0200

    status/network: Move settings item into toplevel section
    
    Eventually each section will turn into its own menu, which should
    include a single settings item.
    
    This also removes the odd duplication of items, now that we avoid
    using submenus where possible.
    
    In general this is straight-forward, except for modems: Some
    models are now supported by a dedicated wwan panel, while others
    still use the generic network one.
    
    Address this by adding items for either panel, but only show one
    at a time. The new panel is used if *any* modem is supported,
    only when all modems require it, the legacy panel is used.
    
    Hopefully that shouldn't be an issue for many users, as using many
    different modems with different capabilities should be fairly rare
    (except for Aleksander Morgado, but I think he can handle it)
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2407>

 js/ui/status/network.js | 47 ++++++++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 21 deletions(-)
---
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 5405c7aa07..7370af9858 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -541,13 +541,6 @@ const NMDeviceItem = GObject.registerClass({
 
 const NMWiredDeviceItem = GObject.registerClass(
 class NMWiredDeviceItem extends NMDeviceItem {
-    constructor(client, device) {
-        super(client, device);
-
-        this.section.addSettingsAction(_('Wired Settings'),
-            'gnome-network-panel.desktop');
-    }
-
     get icon_name() {
         switch (this.state) {
         case NM.ActiveConnectionState.ACTIVATING:
@@ -583,12 +576,6 @@ class NMModemDeviceItem extends NMDeviceItem {
     constructor(client, device) {
         super(client, device);
 
-        const settingsPanel = this._useWwanPanel()
-            ? 'gnome-wwan-panel.desktop'
-            : 'gnome-network-panel.desktop';
-
-        this.section.addSettingsAction(_('Mobile Broadband Settings'), settingsPanel);
-
         this._mobileDevice = null;
 
         let capabilities = device.current_capabilities;
@@ -629,7 +616,7 @@ class NMModemDeviceItem extends NMDeviceItem {
         return this._mobileDevice?.operator_name || this._deviceName;
     }
 
-    _useWwanPanel() {
+    get wwanPanelSupported() {
         // Currently, wwan panel doesn't support CDMA_EVDO modems
         const supportedCaps =
             NM.DeviceModemCapabilities.GSM_UMTS |
@@ -638,7 +625,7 @@ class NMModemDeviceItem extends NMDeviceItem {
     }
 
     _autoConnect() {
-        if (this._useWwanPanel())
+        if (this.wwanPanelSupported)
             launchSettingsPanel('wwan', 'show-device', this._device.udi);
         else
             launchSettingsPanel('network', 'connect-3g', this._device.get_path());
@@ -657,9 +644,6 @@ class NMBluetoothDeviceItem extends NMDeviceItem {
         this._device.bind_property('name',
             this, 'name',
             GObject.BindingFlags.SYNC_CREATE);
-
-        this.section.addSettingsAction(_('Bluetooth Settings'),
-            'gnome-network-panel.desktop');
     }
 
     get icon_name() {
@@ -987,9 +971,6 @@ const NMWirelessDeviceItem = GObject.registerClass({
             sortFunc: (one, two) => one.network.compare(two.network),
         });
 
-        this.section.addSettingsAction(_('Wi-Fi Settings'),
-            'gnome-wifi-panel.desktop');
-
         this._client.connectObject(
             'notify::wireless-enabled', () => this.notify('icon-name'),
             'notify::connectivity', () => this.notify('icon-name'),
@@ -1574,6 +1555,9 @@ class NMDeviceSection extends NMSection {
 class NMWirelessSection extends NMDeviceSection {
     constructor() {
         super(NM.DeviceType.WIFI);
+
+        this.addSettingsAction(_('All Networks'),
+            'gnome-wifi-panel.desktop');
     }
 
     _createDeviceMenuItem(device) {
@@ -1595,6 +1579,9 @@ class NMWirelessSection extends NMDeviceSection {
 class NMWiredSection extends NMDeviceSection {
     constructor() {
         super(NM.DeviceType.ETHERNET);
+
+        this.addSettingsAction(_('Wired Settings'),
+            'gnome-network-panel.desktop');
     }
 
     _createDeviceMenuItem(device) {
@@ -1616,6 +1603,9 @@ class NMWiredSection extends NMDeviceSection {
 class NMBluetoothSection extends NMDeviceSection {
     constructor() {
         super(NM.DeviceType.BT);
+
+        this.addSettingsAction(_('Bluetooth Settings'),
+            'gnome-network-panel.desktop');
     }
 
     _createDeviceMenuItem(device) {
@@ -1637,6 +1627,12 @@ class NMBluetoothSection extends NMDeviceSection {
 class NMModemSection extends NMDeviceSection {
     constructor() {
         super(NM.DeviceType.MODEM);
+
+        const settingsLabel = _('Mobile Broadband Settings');
+        this._wwanSettings = this.addSettingsAction(settingsLabel,
+            'gnome-wwan-panel.desktop');
+        this._legacySettings = this.addSettingsAction(settingsLabel,
+            'gnome-network-panel.desktop');
     }
 
     _createDeviceMenuItem(device) {
@@ -1653,6 +1649,15 @@ class NMModemSection extends NMDeviceSection {
             '%s Modem Connections',
             nDevices).format(nDevices);
     }
+
+    _sync() {
+        super._sync();
+
+        const useWwanPanel =
+            [...this._items.values()].some(i => i.wwanPanelSupported);
+        this._wwanSettings.visible = useWwanPanel;
+        this._legacySettings.visible = !useWwanPanel;
+    }
 }
 
 var NMApplet = GObject.registerClass(


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