[gnome-shell/wip/hadess/new-gnome-bluetooth: 1/2] status/bluetooth: Port to new GListModel API
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/hadess/new-gnome-bluetooth: 1/2] status/bluetooth: Port to new GListModel API
- Date: Wed, 19 Jan 2022 12:56:40 +0000 (UTC)
commit d56d17b1620d4370070602dd69c9b3a88864a2de
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.
https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4748
js/ui/environment.js | 2 +-
js/ui/status/bluetooth.js | 71 +++++++++++++++++++++--------------------------
meson.build | 2 +-
3 files changed, 34 insertions(+), 41 deletions(-)
---
diff --git a/js/ui/environment.js b/js/ui/environment.js
index 67571152a6..dc9c5c9433 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 = '3.0';
imports.gi.versions.GnomeDesktop = '3.0';
imports.gi.versions.Gtk = '3.0';
imports.gi.versions.GWeather = '4.0';
diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js
index 98ccc3d314..3e49a5591d 100644
--- a/js/ui/status/bluetooth.js
+++ b/js/ui/status/bluetooth.js
@@ -53,10 +53,16 @@ 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._deviceNotifyConnected = [];
+ this._client.connect('device-removed', (c, path) => {
+ this._deviceNotifyConnected[path] = false;
+ this._queueSync.bind(this);
+ });
+ this._client.connect('device-added', (c, device) => {
+ this._connectDeviceNotify(device);
+ this._sync();
+ });
Main.sessionMode.connect('updated', this._sync.bind(this));
this._sync();
}
@@ -70,42 +76,30 @@ 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;
+ _connectDeviceNotify(device) {
+ if (this._deviceNotifyConnected[device.get_object_path()] !== true)
+ return;
+ device.connect('notify::alias', this._queueSync.bind(this));
+ device.connect('notify::paired', this._queueSync.bind(this));
+ device.connect('notify::trusted', this._queueSync.bind(this));
+ device.connect('notify::connected', this._queueSync.bind(this));
+ this._deviceNotifyConnected.push([device.get_object_path(), true]);
}
- _getDeviceInfos(adapter) {
- if (!adapter)
- return [];
-
+ _getDeviceInfos() {
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) {
+ const numDevices = this._store.get_n_items();
+
+ for (let i = 0; i < numDevices; i++) {
+ const device = this._store.get_item(i);
+
+ 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);
+ this._connectDeviceNotify(device);
}
return deviceInfos;
@@ -122,14 +116,13 @@ 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 ?? null;
let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
@@ -148,7 +141,7 @@ class Indicator extends PanelMenu.SystemIndicator {
this._item.label.text = ngettext('%d Connected', '%d Connected',
nConnectedDevices).format(nConnectedDevices);
else if (nConnectedDevices === 1)
this._item.label.text = connectedDevices[0].name;
- else if (adapter === null)
+ else if (this._adapter === null)
this._item.label.text = _('Bluetooth Off');
else
this._item.label.text = _('Bluetooth On');
diff --git a/meson.build b/meson.build
index efdd7def15..9ae4ddef7e 100644
--- a/meson.build
+++ b/meson.build
@@ -93,7 +93,7 @@ x11_dep = dependency('x11')
schemas_dep = dependency('gsettings-desktop-schemas', version: schemas_req)
gnome_desktop_dep = dependency('gnome-desktop-3.0', version: gnome_desktop_req)
-bt_dep = dependency('gnome-bluetooth-1.0', version: bt_req, required: false)
+bt_dep = dependency('gnome-bluetooth-3.0', version: bt_req, required: false)
gst_dep = dependency('gstreamer-1.0', version: gst_req, required: false)
gst_base_dep = dependency('gstreamer-base-1.0', required: false)
pipewire_dep = dependency('libpipewire-0.3', required: false)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]