2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-07-24 11:57:53 +00:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const GLib = imports.gi.GLib;
|
2013-11-26 13:06:41 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
2012-07-30 17:09:42 +00:00
|
|
|
const GnomeBluetooth = imports.gi.GnomeBluetooth;
|
2010-07-24 11:57:53 +00:00
|
|
|
const Lang = imports.lang;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
2013-11-26 13:06:41 +00:00
|
|
|
const BUS_NAME = 'org.gnome.SettingsDaemon.Rfkill';
|
|
|
|
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Rfkill';
|
|
|
|
|
|
|
|
const RfkillManagerInterface = '<node> \
|
|
|
|
<interface name="org.gnome.SettingsDaemon.Rfkill"> \
|
|
|
|
<property name="BluetoothAirplaneMode" type="b" access="readwrite" /> \
|
|
|
|
</interface> \
|
|
|
|
</node>';
|
|
|
|
|
|
|
|
const RfkillManagerProxy = Gio.DBusProxy.makeProxyWrapper(RfkillManagerInterface);
|
|
|
|
|
2011-11-20 14:38:48 +00:00
|
|
|
const Indicator = new Lang.Class({
|
|
|
|
Name: 'BTIndicator',
|
2013-06-06 21:27:25 +00:00
|
|
|
Extends: PanelMenu.SystemIndicator,
|
2010-07-24 11:57:53 +00:00
|
|
|
|
|
|
|
_init: function() {
|
2013-06-06 21:27:25 +00:00
|
|
|
this.parent();
|
|
|
|
|
2013-07-19 10:05:47 +00:00
|
|
|
this._indicator = this._addIndicator();
|
|
|
|
this._indicator.icon_name = 'bluetooth-active-symbolic';
|
2010-07-24 11:57:53 +00:00
|
|
|
|
2013-11-26 13:06:41 +00:00
|
|
|
this._proxy = new RfkillManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
|
|
|
|
Lang.bind(this, function(proxy, error) {
|
|
|
|
if (error) {
|
|
|
|
log(error.message);
|
|
|
|
return;
|
|
|
|
}
|
2014-01-28 20:47:37 +00:00
|
|
|
|
|
|
|
this._sync();
|
2013-11-26 13:06:41 +00:00
|
|
|
}));
|
2014-01-28 20:47:37 +00:00
|
|
|
this._proxy.connect('g-properties-changed', Lang.bind(this, this._sync));
|
2013-11-26 13:06:41 +00:00
|
|
|
|
2013-07-15 17:51:42 +00:00
|
|
|
// The Bluetooth menu only appears when Bluetooth is in use,
|
|
|
|
// so just statically build it with a "Turn Off" menu item.
|
|
|
|
this._item = new PopupMenu.PopupSubMenuMenuItem(_("Bluetooth"), true);
|
|
|
|
this._item.icon.icon_name = 'bluetooth-active-symbolic';
|
|
|
|
this._item.menu.addAction(_("Turn Off"), Lang.bind(this, function() {
|
2013-11-26 13:06:41 +00:00
|
|
|
this._proxy.BluetoothAirplaneMode = true;
|
2010-07-24 11:57:53 +00:00
|
|
|
}));
|
2013-07-15 17:51:42 +00:00
|
|
|
this._item.menu.addSettingsAction(_("Bluetooth Settings"), 'gnome-bluetooth-panel.desktop');
|
2013-09-21 16:57:41 +00:00
|
|
|
this.menu.addMenuItem(this._item);
|
2010-07-24 11:57:53 +00:00
|
|
|
|
2013-11-26 13:46:13 +00:00
|
|
|
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));
|
2014-03-15 07:53:54 +00:00
|
|
|
Main.sessionMode.connect('updated', Lang.bind(this, this._sync));
|
2013-07-15 17:51:42 +00:00
|
|
|
this._sync();
|
2010-07-24 11:57:53 +00:00
|
|
|
},
|
|
|
|
|
2013-11-26 13:46:13 +00:00
|
|
|
_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;
|
|
|
|
},
|
|
|
|
|
2013-07-15 17:51:42 +00:00
|
|
|
_sync: function() {
|
2013-11-26 13:46:13 +00:00
|
|
|
let nDevices = this._getNConnectedDevices();
|
2014-03-15 07:53:54 +00:00
|
|
|
let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
2010-07-24 11:57:53 +00:00
|
|
|
|
2014-03-15 07:53:54 +00:00
|
|
|
this.menu.setSensitive(sensitive);
|
2014-01-28 20:47:37 +00:00
|
|
|
this._indicator.visible = nDevices > 0;
|
|
|
|
this._item.actor.visible = !this._proxy.BluetoothAirplaneMode;
|
2010-07-24 11:57:53 +00:00
|
|
|
|
2014-01-28 20:47:37 +00:00
|
|
|
if (nDevices > 0)
|
2013-10-03 12:26:12 +00:00
|
|
|
this._item.status.text = ngettext("%d Connected Device", "%d Connected Devices", nDevices).format(nDevices);
|
2014-01-28 20:47:37 +00:00
|
|
|
else
|
|
|
|
this._item.status.text = _("Not Connected");
|
2010-07-24 11:57:53 +00:00
|
|
|
},
|
2011-11-20 15:12:02 +00:00
|
|
|
});
|