2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-07-24 07:57:53 -04:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const GnomeBluetoothApplet = imports.gi.GnomeBluetoothApplet;
|
2012-07-30 13:09:42 -04:00
|
|
|
const GnomeBluetooth = imports.gi.GnomeBluetooth;
|
2010-07-24 07:57:53 -04:00
|
|
|
const Lang = imports.lang;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
2011-11-20 09:38:48 -05:00
|
|
|
const Indicator = new Lang.Class({
|
|
|
|
Name: 'BTIndicator',
|
2013-06-06 17:27:25 -04:00
|
|
|
Extends: PanelMenu.SystemIndicator,
|
2010-07-24 07:57:53 -04:00
|
|
|
|
|
|
|
_init: function() {
|
2013-06-06 17:27:25 -04:00
|
|
|
this.parent();
|
|
|
|
|
2013-07-19 06:05:47 -04:00
|
|
|
this._indicator = this._addIndicator();
|
|
|
|
this._indicator.icon_name = 'bluetooth-active-symbolic';
|
2010-07-24 07:57:53 -04:00
|
|
|
|
2013-07-15 13:51:42 -04: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() {
|
|
|
|
this._applet.killswitch_state = GnomeBluetooth.KillswitchState.SOFT_BLOCKED;
|
2010-07-24 07:57:53 -04:00
|
|
|
}));
|
2013-07-15 13:51:42 -04:00
|
|
|
this._item.menu.addSettingsAction(_("Bluetooth Settings"), 'gnome-bluetooth-panel.desktop');
|
2013-09-21 12:57:41 -04:00
|
|
|
this.menu.addMenuItem(this._item);
|
2010-07-24 07:57:53 -04:00
|
|
|
|
2013-07-15 13:51:42 -04:00
|
|
|
this._applet = new GnomeBluetoothApplet.Applet();
|
|
|
|
this._applet.connect('devices-changed', Lang.bind(this, this._sync));
|
|
|
|
this._sync();
|
2010-07-24 07:57:53 -04:00
|
|
|
},
|
|
|
|
|
2013-07-15 13:51:42 -04:00
|
|
|
_sync: function() {
|
|
|
|
let connectedDevices = this._applet.get_devices().filter(function(device) {
|
|
|
|
return device.connected;
|
|
|
|
});
|
|
|
|
let nDevices = connectedDevices.length;
|
2010-07-24 07:57:53 -04:00
|
|
|
|
2013-07-15 13:51:42 -04:00
|
|
|
let on = nDevices > 0;
|
2013-06-06 17:27:25 -04:00
|
|
|
this._indicator.visible = on;
|
|
|
|
this._item.actor.visible = on;
|
2010-07-24 07:57:53 -04:00
|
|
|
|
2013-07-15 13:51:42 -04:00
|
|
|
if (on)
|
2013-10-03 08:26:12 -04:00
|
|
|
this._item.status.text = ngettext("%d Connected Device", "%d Connected Devices", nDevices).format(nDevices);
|
2010-07-24 07:57:53 -04:00
|
|
|
},
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|