[gnome-shell] network/status: Split out NMMenuItem base class
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] network/status: Split out NMMenuItem base class
- Date: Wed, 10 Aug 2022 13:56:30 +0000 (UTC)
commit b4da69d4747ab5850a4dce49eb920e3aed1e7fc9
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Aug 2 13:41:13 2022 +0200
network/status: Split out NMMenuItem base class
The class only provides the GObject properties that are currently
defined by NMConnectionItem, plus a way to set the active connection
that should be used for the item's :is-active state.
Its sole purpose is to provide a shared base for both device- and
connection items, and to have that base be a GObject so we can
start linking properties via bindings rather than manual fiddling.
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2407>
js/ui/status/network.js | 74 ++++++++++++++++++++++++++++++-------------------
1 file changed, 45 insertions(+), 29 deletions(-)
---
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index a4ed4a4e6e..394fd074e7 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -148,7 +148,7 @@ class ItemSorter {
}
}
-const NMConnectionItem = GObject.registerClass({
+const NMMenuItem = GObject.registerClass({
Properties: {
'radio-mode': GObject.ParamSpec.boolean('radio-mode', '', '',
GObject.ParamFlags.READWRITE,
@@ -163,7 +163,45 @@ const NMConnectionItem = GObject.registerClass({
GObject.ParamFlags.READWRITE,
''),
},
-}, class NMConnectionItem extends PopupMenu.PopupBaseMenuItem {
+}, class NMMenuItem extends PopupMenu.PopupBaseMenuItem {
+ get state() {
+ return this._activeConnection?.state ??
+ NM.ActiveConnectionState.DEACTIVATED;
+ }
+
+ get is_active() {
+ return this.state <= NM.ActiveConnectionState.ACTIVATED;
+ }
+
+ activate() {
+ super.activate(Clutter.get_current_event());
+ }
+
+ _activeConnectionStateChanged() {
+ this.notify('is-active');
+ this.notify('icon-name');
+
+ this._sync();
+ }
+
+ _setActiveConnection(activeConnection) {
+ this._activeConnection?.disconnectObject(this);
+
+ this._activeConnection = activeConnection;
+
+ this._activeConnection?.connectObject(
+ 'notify::state', () => this._activeConnectionStateChanged(),
+ this);
+ this._activeConnectionStateChanged();
+ }
+
+ _sync() {
+ // Overridden by subclasses
+ }
+});
+
+const NMConnectionItem = GObject.registerClass(
+class NMConnectionItem extends NMMenuItem {
constructor(section, connection) {
super();
@@ -203,15 +241,6 @@ const NMConnectionItem = GObject.registerClass({
return this._connection.get_id();
}
- get state() {
- return this._activeConnection?.state ??
- NM.ActiveConnectionState.DEACTIVATED;
- }
-
- get is_active() {
- return this.state <= NM.ActiveConnectionState.ACTIVATED;
- }
-
updateForConnection(connection) {
// connection should always be the same object
// (and object path) as this._connection, but
@@ -249,7 +278,7 @@ const NMConnectionItem = GObject.registerClass({
}
activate() {
- super.activate(Clutter.get_current_event());
+ super.activate();
if (this.radio_mode && this._activeConnection != null)
return; // only activate in radio mode
@@ -262,20 +291,8 @@ const NMConnectionItem = GObject.registerClass({
this._sync();
}
- _connectionStateChanged(_ac, _newstate, _reason) {
- this.notify('is-active');
- this._sync();
- }
-
- setActiveConnection(activeConnection) {
- this._activeConnection?.disconnectObject(this);
-
- this._activeConnection = activeConnection;
-
- this._activeConnection?.connectObject('notify::state',
- this._connectionStateChanged.bind(this), this);
-
- this._sync();
+ setActiveConnection(connection) {
+ this._setActiveConnection(connection);
}
});
@@ -1498,7 +1515,7 @@ const NMVpnConnectionItem = GObject.registerClass({
this.remove_accessible_state(Atk.StateType.CHECKED);
}
- _connectionStateChanged() {
+ _activeConnectionStateChanged() {
const state = this._activeConnection?.get_state();
const reason = this._activeConnection?.get_state_reason();
@@ -1507,8 +1524,7 @@ const NMVpnConnectionItem = GObject.registerClass({
reason !== NM.ActiveConnectionStateReason.USER_DISCONNECTED)
this.emit('activation-failed');
- this.notify('icon-name');
- super._connectionStateChanged();
+ super._activeConnectionStateChanged();
}
get icon_name() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]