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
|
|
|
|
2014-04-29 17:24:27 -04:00
|
|
|
const Main = imports.ui.main;
|
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" /> \
|
2014-09-08 18:17:24 -04:00
|
|
|
<property name="ShouldShowAirplaneMode" 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);
|
|
|
|
|
2017-07-18 13:41:25 -04:00
|
|
|
var RfkillManager = new Lang.Class({
|
2014-01-29 16:24:50 -05:00
|
|
|
Name: 'RfkillManager',
|
2013-05-27 17:54:50 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2013-05-27 17:54:50 -04:00
|
|
|
this._proxy = new RfkillManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
|
2017-10-30 20:38:18 -04:00
|
|
|
(proxy, error) => {
|
2013-05-27 17:54:50 -04:00
|
|
|
if (error) {
|
|
|
|
log(error.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._proxy.connect('g-properties-changed',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._changed.bind(this));
|
2014-01-29 16:24:50 -05:00
|
|
|
this._changed();
|
2017-10-30 20:38:18 -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;
|
|
|
|
},
|
|
|
|
|
2014-09-08 18:17:24 -04:00
|
|
|
get shouldShowAirplaneMode() {
|
|
|
|
return this._proxy.ShouldShowAirplaneMode;
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_changed() {
|
2014-01-29 16:24:50 -05:00
|
|
|
this.emit('airplane-mode-changed');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Signals.addSignalMethods(RfkillManager.prototype);
|
|
|
|
|
|
|
|
var _manager;
|
|
|
|
function getRfkillManager() {
|
|
|
|
if (_manager != null)
|
|
|
|
return _manager;
|
|
|
|
|
|
|
|
_manager = new RfkillManager();
|
|
|
|
return _manager;
|
|
|
|
}
|
|
|
|
|
2017-07-18 13:41:25 -04:00
|
|
|
var Indicator = new Lang.Class({
|
2014-01-29 16:24:50 -05:00
|
|
|
Name: 'RfkillIndicator',
|
|
|
|
Extends: PanelMenu.SystemIndicator,
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2014-01-29 16:24:50 -05:00
|
|
|
this.parent();
|
|
|
|
|
|
|
|
this._manager = getRfkillManager();
|
2017-12-01 19:27:35 -05:00
|
|
|
this._manager.connect('airplane-mode-changed', this._sync.bind(this));
|
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.
|
2015-08-06 05:19:37 -04:00
|
|
|
this._item = new PopupMenu.PopupSubMenuMenuItem(_("Airplane Mode On"), true);
|
2013-05-27 17:54:50 -04:00
|
|
|
this._item.icon.icon_name = 'airplane-mode-symbolic';
|
2017-10-30 20:38:18 -04:00
|
|
|
this._offItem = this._item.menu.addAction(_("Turn Off"), () => {
|
2014-04-21 12:58:56 -04:00
|
|
|
this._manager.airplaneMode = false;
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2013-05-27 17:54:50 -04:00
|
|
|
this._item.menu.addSettingsAction(_("Network Settings"), 'gnome-network-panel.desktop');
|
|
|
|
this.menu.addMenuItem(this._item);
|
2014-04-29 17:24:27 -04:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
2014-04-29 17:24:27 -04:00
|
|
|
this._sessionUpdated();
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sessionUpdated() {
|
2014-04-29 17:24:27 -04:00
|
|
|
let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
|
|
|
this.menu.setSensitive(sensitive);
|
2013-05-27 17:54:50 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2014-01-29 16:24:50 -05:00
|
|
|
let airplaneMode = this._manager.airplaneMode;
|
|
|
|
let hwAirplaneMode = this._manager.hwAirplaneMode;
|
2014-09-08 18:17:24 -04:00
|
|
|
let showAirplaneMode = this._manager.shouldShowAirplaneMode;
|
2013-10-08 17:34:33 -04:00
|
|
|
|
2014-09-08 18:17:24 -04:00
|
|
|
this._indicator.visible = (airplaneMode && showAirplaneMode);
|
|
|
|
this._item.actor.visible = (airplaneMode && showAirplaneMode);
|
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
|
|
|
},
|
|
|
|
});
|