2013-05-27 17:54:50 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Lang = imports.lang;
|
2014-01-29 16:24:50 -05:00
|
|
|
const Signals = imports.signals;
|
2013-05-27 17:54:50 -04:00
|
|
|
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
|
|
|
const BUS_NAME = 'org.gnome.SettingsDaemon.Rfkill';
|
|
|
|
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Rfkill';
|
|
|
|
|
2013-10-24 17:51:58 -04:00
|
|
|
const RfkillManagerInterface = '<node> \
|
|
|
|
<interface name="org.gnome.SettingsDaemon.Rfkill"> \
|
|
|
|
<property name="AirplaneMode" type="b" access="readwrite" /> \
|
2013-10-08 17:34:33 -04:00
|
|
|
<property name="HardwareAirplaneMode" type="b" access="read" /> \
|
2013-10-24 17:51:58 -04:00
|
|
|
</interface> \
|
|
|
|
</node>';
|
2013-05-27 17:54:50 -04:00
|
|
|
|
|
|
|
const RfkillManagerProxy = Gio.DBusProxy.makeProxyWrapper(RfkillManagerInterface);
|
|
|
|
|
2014-01-29 16:24:50 -05:00
|
|
|
const RfkillManager = new Lang.Class({
|
|
|
|
Name: 'RfkillManager',
|
2013-05-27 17:54:50 -04:00
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this._proxy = new RfkillManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
|
|
|
|
Lang.bind(this, function(proxy, error) {
|
|
|
|
if (error) {
|
|
|
|
log(error.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._proxy.connect('g-properties-changed',
|
2014-01-29 16:24:50 -05:00
|
|
|
Lang.bind(this, this._changed));
|
|
|
|
this._changed();
|
2013-05-27 17:54:50 -04:00
|
|
|
}));
|
2014-01-29 16:24:50 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
get airplaneMode() {
|
|
|
|
return this._proxy.AirplaneMode;
|
|
|
|
},
|
|
|
|
|
|
|
|
set airplaneMode(v) {
|
|
|
|
this._proxy.AirplaneMode = v;
|
|
|
|
},
|
|
|
|
|
|
|
|
get hwAirplaneMode() {
|
|
|
|
return this._proxy.HardwareAirplaneMode;
|
|
|
|
},
|
|
|
|
|
|
|
|
_changed: function() {
|
|
|
|
this.emit('airplane-mode-changed');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Signals.addSignalMethods(RfkillManager.prototype);
|
|
|
|
|
|
|
|
var _manager;
|
|
|
|
function getRfkillManager() {
|
|
|
|
if (_manager != null)
|
|
|
|
return _manager;
|
|
|
|
|
|
|
|
_manager = new RfkillManager();
|
|
|
|
return _manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Indicator = new Lang.Class({
|
|
|
|
Name: 'RfkillIndicator',
|
|
|
|
Extends: PanelMenu.SystemIndicator,
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this.parent();
|
|
|
|
|
|
|
|
this._manager = getRfkillManager();
|
|
|
|
this._manager.connect('airplane-mode-changed', Lang.bind(this, this._sync));
|
2013-05-27 17:54:50 -04:00
|
|
|
|
|
|
|
this._indicator = this._addIndicator();
|
|
|
|
this._indicator.icon_name = 'airplane-mode-symbolic';
|
|
|
|
this._indicator.hide();
|
|
|
|
|
|
|
|
// The menu only appears when airplane mode is on, so just
|
|
|
|
// statically build it as if it was on, rather than dynamically
|
|
|
|
// changing the menu contents.
|
|
|
|
this._item = new PopupMenu.PopupSubMenuMenuItem(_("Airplane Mode"), true);
|
|
|
|
this._item.icon.icon_name = 'airplane-mode-symbolic';
|
|
|
|
this._item.status.text = _("On");
|
2013-10-08 17:34:33 -04:00
|
|
|
this._offItem = this._item.menu.addAction(_("Turn Off"), Lang.bind(this, function() {
|
2013-05-27 17:54:50 -04:00
|
|
|
this._proxy.AirplaneMode = false;
|
|
|
|
}));
|
|
|
|
this._item.menu.addSettingsAction(_("Network Settings"), 'gnome-network-panel.desktop');
|
|
|
|
this.menu.addMenuItem(this._item);
|
|
|
|
},
|
|
|
|
|
|
|
|
_sync: function() {
|
2014-01-29 16:24:50 -05:00
|
|
|
let airplaneMode = this._manager.airplaneMode;
|
|
|
|
let hwAirplaneMode = this._manager.hwAirplaneMode;
|
|
|
|
let changed = (airplaneMode != this._indicator.visible) ||
|
|
|
|
(hwAirplaneMode != this._offItem.actor.visible);
|
2013-10-08 17:34:33 -04:00
|
|
|
|
2013-05-27 17:54:50 -04:00
|
|
|
this._indicator.visible = airplaneMode;
|
|
|
|
this._item.actor.visible = airplaneMode;
|
2013-10-08 17:34:33 -04:00
|
|
|
this._offItem.setSensitive(!hwAirplaneMode);
|
|
|
|
|
|
|
|
if (hwAirplaneMode)
|
|
|
|
this._offItem.label.text = _("Use hardware switch to turn off");
|
|
|
|
else
|
|
|
|
this._offItem.label.text = _("Turn Off");
|
2013-05-27 17:54:50 -04:00
|
|
|
},
|
|
|
|
});
|