status/bluetooth: Port to new GListModel API

The GtkTreeView API was removed, and replaced with a GListModel API.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4748
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2055>
This commit is contained in:
Bastien Nocera 2021-12-02 11:44:47 +01:00 committed by Marge Bot
parent 170f3ee089
commit 4a480a78af
3 changed files with 33 additions and 40 deletions

View File

@ -6,7 +6,7 @@ const Config = imports.misc.config;
imports.gi.versions.Clutter = Config.LIBMUTTER_API_VERSION; imports.gi.versions.Clutter = Config.LIBMUTTER_API_VERSION;
imports.gi.versions.Gio = '2.0'; imports.gi.versions.Gio = '2.0';
imports.gi.versions.GdkPixbuf = '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.GnomeDesktop = '3.0';
imports.gi.versions.Gtk = '3.0'; imports.gi.versions.Gtk = '3.0';
imports.gi.versions.GWeather = '4.0'; imports.gi.versions.GWeather = '4.0';

View File

@ -53,10 +53,16 @@ class Indicator extends PanelMenu.SystemIndicator {
this._adapter = null; this._adapter = null;
this._client = new GnomeBluetooth.Client(); this._client = new GnomeBluetooth.Client();
this._model = this._client.get_model(); this._store = this._client.get_devices();
this._model.connect('row-deleted', this._queueSync.bind(this)); this._deviceNotifyConnected = [];
this._model.connect('row-changed', this._queueSync.bind(this)); this._client.connect('device-removed', (c, path) => {
this._model.connect('row-inserted', this._sync.bind(this)); 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)); Main.sessionMode.connect('updated', this._sync.bind(this));
this._sync(); this._sync();
} }
@ -70,42 +76,30 @@ class Indicator extends PanelMenu.SystemIndicator {
HAD_BLUETOOTH_DEVICES_SETUP, this._hadSetupDevices); HAD_BLUETOOTH_DEVICES_SETUP, this._hadSetupDevices);
} }
_getDefaultAdapter() { _connectDeviceNotify(device) {
let [ret, iter] = this._model.get_iter_first(); if (this._deviceNotifyConnected[device.get_object_path()] !== true)
while (ret) { return;
let isDefault = this._model.get_value(iter, device.connect('notify::alias', this._queueSync.bind(this));
GnomeBluetooth.Column.DEFAULT); device.connect('notify::paired', this._queueSync.bind(this));
let isPowered = this._model.get_value(iter, device.connect('notify::trusted', this._queueSync.bind(this));
GnomeBluetooth.Column.POWERED); device.connect('notify::connected', this._queueSync.bind(this));
if (isDefault && isPowered) this._deviceNotifyConnected.push([device.get_object_path(), true]);
return iter;
ret = this._model.iter_next(iter);
}
return null;
} }
_getDeviceInfos(adapter) { _getDeviceInfos() {
if (!adapter)
return [];
let deviceInfos = []; let deviceInfos = [];
let [ret, iter] = this._model.iter_children(adapter); const numDevices = this._store.get_n_items();
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) { for (let i = 0; i < numDevices; i++) {
const device = this._store.get_item(i);
if (device.paired || device.trusted) {
deviceInfos.push({ deviceInfos.push({
connected: this._model.get_value(iter, connected: device.connected,
GnomeBluetooth.Column.CONNECTED), name: device.alias,
name: this._model.get_value(iter,
GnomeBluetooth.Column.ALIAS),
}); });
} }
this._connectDeviceNotify(device);
ret = this._model.iter_next(iter);
} }
return deviceInfos; return deviceInfos;
@ -122,14 +116,13 @@ class Indicator extends PanelMenu.SystemIndicator {
} }
_sync() { _sync() {
let adapter = this._getDefaultAdapter(); let devices = this._getDeviceInfos();
let devices = this._getDeviceInfos(adapter);
const connectedDevices = devices.filter(dev => dev.connected); const connectedDevices = devices.filter(dev => dev.connected);
const nConnectedDevices = connectedDevices.length; const nConnectedDevices = connectedDevices.length;
if (adapter && this._adapter) if (this._client.default_adapter && this._adapter)
this._setHadSetupDevices(devices.length > 0); this._setHadSetupDevices(devices.length > 0);
this._adapter = adapter; this._adapter = this._client.default_adapter ?? null;
let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter; 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); this._item.label.text = ngettext('%d Connected', '%d Connected', nConnectedDevices).format(nConnectedDevices);
else if (nConnectedDevices === 1) else if (nConnectedDevices === 1)
this._item.label.text = connectedDevices[0].name; this._item.label.text = connectedDevices[0].name;
else if (adapter === null) else if (this._adapter === null)
this._item.label.text = _('Bluetooth Off'); this._item.label.text = _('Bluetooth Off');
else else
this._item.label.text = _('Bluetooth On'); this._item.label.text = _('Bluetooth On');

View File

@ -93,7 +93,7 @@ x11_dep = dependency('x11')
schemas_dep = dependency('gsettings-desktop-schemas', version: schemas_req) schemas_dep = dependency('gsettings-desktop-schemas', version: schemas_req)
gnome_desktop_dep = dependency('gnome-desktop-3.0', version: gnome_desktop_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_dep = dependency('gstreamer-1.0', version: gst_req, required: false)
gst_base_dep = dependency('gstreamer-base-1.0', required: false) gst_base_dep = dependency('gstreamer-base-1.0', required: false)
pipewire_dep = dependency('libpipewire-0.3', required: false) pipewire_dep = dependency('libpipewire-0.3', required: false)