2013-05-27 21:54:50 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Lang = imports.lang;
|
2014-01-29 21:24:50 +00:00
|
|
|
const Signals = imports.signals;
|
2013-05-27 21:54:50 +00:00
|
|
|
|
2014-04-29 21:24:27 +00:00
|
|
|
const Main = imports.ui.main;
|
2013-05-27 21:54:50 +00: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 21:51:58 +00:00
|
|
|
const RfkillManagerInterface = '<node> \
|
|
|
|
<interface name="org.gnome.SettingsDaemon.Rfkill"> \
|
|
|
|
<property name="AirplaneMode" type="b" access="readwrite" /> \
|
2013-10-08 21:34:33 +00:00
|
|
|
<property name="HardwareAirplaneMode" type="b" access="read" /> \
|
2014-09-08 22:17:24 +00:00
|
|
|
<property name="ShouldShowAirplaneMode" type="b" access="read" /> \
|
2013-10-24 21:51:58 +00:00
|
|
|
</interface> \
|
|
|
|
</node>';
|
2013-05-27 21:54:50 +00:00
|
|
|
|
|
|
|
const RfkillManagerProxy = Gio.DBusProxy.makeProxyWrapper(RfkillManagerInterface);
|
|
|
|
|
2014-01-29 21:24:50 +00:00
|
|
|
const RfkillManager = new Lang.Class({
|
|
|
|
Name: 'RfkillManager',
|
2013-05-27 21:54:50 +00: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 21:24:50 +00:00
|
|
|
Lang.bind(this, this._changed));
|
|
|
|
this._changed();
|
2013-05-27 21:54:50 +00:00
|
|
|
}));
|
2014-01-29 21:24:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get airplaneMode() {
|
|
|
|
return this._proxy.AirplaneMode;
|
|
|
|
},
|
|
|
|
|
|
|
|
set airplaneMode(v) {
|
|
|
|
this._proxy.AirplaneMode = v;
|
|
|
|
},
|
|
|
|
|
|
|
|
get hwAirplaneMode() {
|
|
|
|
return this._proxy.HardwareAirplaneMode;
|
|
|
|
},
|
|
|
|
|
2014-09-08 22:17:24 +00:00
|
|
|
get shouldShowAirplaneMode() {
|
|
|
|
return this._proxy.ShouldShowAirplaneMode;
|
|
|
|
},
|
|
|
|
|
2014-01-29 21:24:50 +00:00
|
|
|
_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 21:54:50 +00: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 21:34:33 +00:00
|
|
|
this._offItem = this._item.menu.addAction(_("Turn Off"), Lang.bind(this, function() {
|
2014-04-21 16:58:56 +00:00
|
|
|
this._manager.airplaneMode = false;
|
2013-05-27 21:54:50 +00:00
|
|
|
}));
|
|
|
|
this._item.menu.addSettingsAction(_("Network Settings"), 'gnome-network-panel.desktop');
|
|
|
|
this.menu.addMenuItem(this._item);
|
2014-04-29 21:24:27 +00:00
|
|
|
|
|
|
|
Main.sessionMode.connect('updated', Lang.bind(this, this._sessionUpdated));
|
|
|
|
this._sessionUpdated();
|
|
|
|
},
|
|
|
|
|
|
|
|
_sessionUpdated: function() {
|
|
|
|
let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
|
|
|
this.menu.setSensitive(sensitive);
|
2013-05-27 21:54:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_sync: function() {
|
2014-01-29 21:24:50 +00:00
|
|
|
let airplaneMode = this._manager.airplaneMode;
|
|
|
|
let hwAirplaneMode = this._manager.hwAirplaneMode;
|
2014-09-08 22:17:24 +00:00
|
|
|
let showAirplaneMode = this._manager.shouldShowAirplaneMode;
|
2013-10-08 21:34:33 +00:00
|
|
|
|
2014-09-08 22:17:24 +00:00
|
|
|
this._indicator.visible = (airplaneMode && showAirplaneMode);
|
|
|
|
this._item.actor.visible = (airplaneMode && showAirplaneMode);
|
2013-10-08 21:34:33 +00: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 21:54:50 +00:00
|
|
|
},
|
|
|
|
});
|