[gnome-shell] status/network: Expose WirelessDeviceItem:is-hotspot



commit 1cc07716fa27ef9db5804e45d4e820cda5446d11
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Aug 5 12:30:12 2022 +0200

    status/network: Expose WirelessDeviceItem:is-hotspot
    
    Whether the device is used as a hotspot is currently only
    used internally for the name and icon-name properties.
    
    But hotspots need special treatment in the toggle as well,
    so turn the method into a GObject property.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2408>

 js/ui/status/network.js | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)
---
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 994c35c134..431ca5ad68 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -1009,6 +1009,9 @@ class NMWirelessNetworkItem extends PopupMenu.PopupBaseMenuItem {
 
 const NMWirelessDeviceItem = GObject.registerClass({
     Properties: {
+        'is-hotspot': GObject.ParamSpec.boolean('is-hotspot', '', '',
+            GObject.ParamFlags.READABLE,
+            false),
         'single-device-mode': GObject.ParamSpec.boolean('single-device-mode', '', '',
             GObject.ParamFlags.READWRITE,
             false),
@@ -1037,6 +1040,7 @@ const NMWirelessDeviceItem = GObject.registerClass({
             'notify::active-access-point', this._activeApChanged.bind(this),
             'notify::active-connection', () => this._activeConnectionChanged(),
             'notify::available-connections', () => this._availableConnectionsChanged(),
+            'state-changed', () => this.notify('is-hotspot'),
             'access-point-added', (d, ap) => {
                 this._addAccessPoint(ap);
                 this._updateItemsVisibility();
@@ -1072,7 +1076,7 @@ const NMWirelessDeviceItem = GObject.registerClass({
             return 'network-wireless-acquiring-symbolic';
 
         case NM.ActiveConnectionState.ACTIVATED: {
-            if (this._isHotSpotMaster())
+            if (this.is_hotspot)
                 return 'network-wireless-hotspot-symbolic';
 
             if (!this._canReachInternet())
@@ -1094,7 +1098,7 @@ const NMWirelessDeviceItem = GObject.registerClass({
     }
 
     get name() {
-        if (this._isHotSpotMaster())
+        if (this.is_hotspot)
             /* Translators: %s is a network identifier */
             return _('%s Hotspot').format(this._deviceName);
 
@@ -1105,6 +1109,21 @@ const NMWirelessDeviceItem = GObject.registerClass({
         return this._deviceName;
     }
 
+    get is_hotspot() {
+        if (!this._device.active_connection)
+            return false;
+
+        const {connection} = this._device.active_connection;
+        if (!connection)
+            return false;
+
+        let ip4config = connection.get_setting_ip4_config();
+        if (!ip4config)
+            return false;
+
+        return ip4config.get_method() === NM.SETTING_IP4_CONFIG_METHOD_SHARED;
+    }
+
     _activeApChanged() {
         this._activeAccessPoint?.disconnectObject(this);
         this._activeAccessPoint = this._device.active_access_point;
@@ -1207,21 +1226,6 @@ const NMWirelessDeviceItem = GObject.registerClass({
 
         return this._client.connectivity === NM.ConnectivityState.FULL;
     }
-
-    _isHotSpotMaster() {
-        if (!this._device.active_connection)
-            return false;
-
-        let connection = this._device.active_connection.connection;
-        if (!connection)
-            return false;
-
-        let ip4config = connection.get_setting_ip4_config();
-        if (!ip4config)
-            return false;
-
-        return ip4config.get_method() === NM.SETTING_IP4_CONFIG_METHOD_SHARED;
-    }
 });
 
 const NMVpnConnectionItem = GObject.registerClass({


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