[gnome-shell] bluetooth: Use BluetoothClient to detect connected devices
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] bluetooth: Use BluetoothClient to detect connected devices
- Date: Tue, 26 Nov 2013 17:53:38 +0000 (UTC)
commit 85f2d94253fd86eee2653eacceae2cbce01fd8e9
Author: Bastien Nocera <hadess hadess net>
Date: Tue Nov 26 14:46:13 2013 +0100
bluetooth: Use BluetoothClient to detect connected devices
Instead of the GnomeBluetoothApplet helper.
https://bugzilla.gnome.org/show_bug.cgi?id=719341
js/ui/status/bluetooth.js | 41 +++++++++++++++++++++++++++++++++++------
1 files changed, 35 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js
index 7a34f99..47171c7 100644
--- a/js/ui/status/bluetooth.js
+++ b/js/ui/status/bluetooth.js
@@ -52,16 +52,45 @@ const Indicator = new Lang.Class({
this._item.menu.addSettingsAction(_("Bluetooth Settings"), 'gnome-bluetooth-panel.desktop');
this.menu.addMenuItem(this._item);
- this._applet = new GnomeBluetoothApplet.Applet();
- this._applet.connect('devices-changed', Lang.bind(this, this._sync));
+ this._client = new GnomeBluetooth.Client();
+ this._model = this._client.get_model();
+ this._model.connect('row-changed', Lang.bind(this, this._sync));
+ this._model.connect('row-deleted', Lang.bind(this, this._sync));
+ this._model.connect('row-inserted', Lang.bind(this, this._sync));
this._sync();
},
+ _getDefaultAdapter: function() {
+ let [ret, iter] = this._model.get_iter_first();
+ while (ret) {
+ let isDefault = this._model.get_value(iter,
+ GnomeBluetooth.Column.DEFAULT);
+ if (isDefault)
+ return iter;
+ ret = this._model.iter_next(iter);
+ }
+ return null;
+ },
+
+ _getNConnectedDevices: function() {
+ let adapter = this._getDefaultAdapter();
+ if (!adapter)
+ return 0;
+
+ let nDevices = 0;
+ let [ret, iter] = this._model.iter_children(adapter);
+ while (ret) {
+ let isConnected = this._model.get_value(iter,
+ GnomeBluetooth.Column.CONNECTED);
+ if (isConnected)
+ nDevices++;
+ ret = this._model.iter_next(iter);
+ }
+ return nDevices;
+ },
+
_sync: function() {
- let connectedDevices = this._applet.get_devices().filter(function(device) {
- return device.connected;
- });
- let nDevices = connectedDevices.length;
+ let nDevices = this._getNConnectedDevices();
let on = nDevices > 0;
this._indicator.visible = on;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]