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:
parent
170f3ee089
commit
4a480a78af
@ -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';
|
||||
|
@ -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);
|
||||
const numDevices = this._store.get_n_items();
|
||||
|
||||
if (isPaired || isTrusted) {
|
||||
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');
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user