[gnome-shell/wip/hadess/new-gnome-bluetooth] status/bluetooth: Port to new GListModel API




commit 2c6cfc50a7aa54ddfbe88b8a74675e97066c1513
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Dec 2 11:44:47 2021 +0100

    status/bluetooth: Port to new GListModel API
    
    The GtkTreeView API was removed, and replaced with a GListModel API.

 js/ui/environment.js      |  2 +-
 js/ui/status/bluetooth.js | 58 ++++++++++++++++-------------------------------
 2 files changed, 20 insertions(+), 40 deletions(-)
---
diff --git a/js/ui/environment.js b/js/ui/environment.js
index cb254e3195..b8867e1e3d 100644
--- a/js/ui/environment.js
+++ b/js/ui/environment.js
@@ -6,7 +6,7 @@ const Config = imports.misc.config;
 imports.gi.versions.Clutter = Config.LIBMUTTER_API_VERSION;
 imports.gi.versions.Gio = '2.0';
 imports.gi.versions.GdkPixbuf = '2.0';
-imports.gi.versions.GnomeBluetooth = '1.0';
+imports.gi.versions.GnomeBluetooth = '2.0';
 imports.gi.versions.GnomeDesktop = '3.0';
 imports.gi.versions.Gtk = '3.0';
 imports.gi.versions.Soup = '3.0';
diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js
index 98ccc3d314..33c700047f 100644
--- a/js/ui/status/bluetooth.js
+++ b/js/ui/status/bluetooth.js
@@ -53,10 +53,9 @@ class Indicator extends PanelMenu.SystemIndicator {
         this._adapter = null;
 
         this._client = new GnomeBluetooth.Client();
-        this._model = this._client.get_model();
-        this._model.connect('row-deleted', this._queueSync.bind(this));
-        this._model.connect('row-changed', this._queueSync.bind(this));
-        this._model.connect('row-inserted', this._sync.bind(this));
+        this._store = this._client.get_devices();
+        this._client.connect('device-removed', this._queueSync.bind(this));
+        this._client.connect('device-added', this._sync.bind(this));
         Main.sessionMode.connect('updated', this._sync.bind(this));
         this._sync();
     }
@@ -70,42 +69,23 @@ class Indicator extends PanelMenu.SystemIndicator {
             HAD_BLUETOOTH_DEVICES_SETUP, this._hadSetupDevices);
     }
 
-    _getDefaultAdapter() {
-        let [ret, iter] = this._model.get_iter_first();
-        while (ret) {
-            let isDefault = this._model.get_value(iter,
-                                                  GnomeBluetooth.Column.DEFAULT);
-            let isPowered = this._model.get_value(iter,
-                                                  GnomeBluetooth.Column.POWERED);
-            if (isDefault && isPowered)
-                return iter;
-            ret = this._model.iter_next(iter);
-        }
-        return null;
-    }
+    _getDeviceInfos() {
+        let deviceInfos = [];
+        let numDevices = this._store.get_n_items();
 
-    _getDeviceInfos(adapter) {
-        if (!adapter)
-            return [];
+        for (let i = 0; i < numDevices; i++) {
+            const device = this._store.get_item(i);
 
-        let deviceInfos = [];
-        let [ret, iter] = this._model.iter_children(adapter);
-        while (ret) {
-            const isPaired = this._model.get_value(iter,
-                GnomeBluetooth.Column.PAIRED);
-            const isTrusted = this._model.get_value(iter,
-                GnomeBluetooth.Column.TRUSTED);
-
-            if (isPaired || isTrusted) {
+            if (device.paired || device.trusted) {
                 deviceInfos.push({
-                    connected: this._model.get_value(iter,
-                        GnomeBluetooth.Column.CONNECTED),
-                    name: this._model.get_value(iter,
-                        GnomeBluetooth.Column.ALIAS),
+                    connected: device.connected,
+                    name: device.alias,
                 });
             }
-
-            ret = this._model.iter_next(iter);
+            //FIXME shouldn't connect multiple times
+            device.connect('notify::paired', this._queueSync.bind(this));
+            device.connect('notify::trusted', this._queueSync.bind(this));
+            device.connect('notify::connected', this._queueSync.bind(this));
         }
 
         return deviceInfos;
@@ -122,14 +102,14 @@ class Indicator extends PanelMenu.SystemIndicator {
     }
 
     _sync() {
-        let adapter = this._getDefaultAdapter();
-        let devices = this._getDeviceInfos(adapter);
+        let devices = this._getDeviceInfos();
         const connectedDevices = devices.filter(dev => dev.connected);
         const nConnectedDevices = connectedDevices.length;
 
-        if (adapter && this._adapter)
+        if (this._client.default_adapter && this._adapter)
             this._setHadSetupDevices(devices.length > 0);
-        this._adapter = adapter;
+        this._adapter = this._client.default_adapter ?
+                        this._client.default_adapter.get_object_path() : null;
 
         let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
 


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