2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported Indicator */
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2019-10-15 18:51:33 +00:00
|
|
|
const { GObject, Shell, St } = imports.gi;
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2012-09-19 03:02:15 +00:00
|
|
|
const BoxPointer = imports.ui.boxpointer;
|
2017-08-02 20:57:54 +00:00
|
|
|
const SystemActions = imports.misc.systemActions;
|
2010-06-03 23:21:08 +00:00
|
|
|
const Main = imports.ui.main;
|
2010-06-22 21:02:26 +00:00
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
2010-05-20 15:18:46 +00:00
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2015-03-05 14:46:57 +00:00
|
|
|
|
2019-10-28 18:35:33 +00:00
|
|
|
var Indicator = GObject.registerClass(
|
|
|
|
class Indicator extends PanelMenu.SystemIndicator {
|
2019-07-16 09:24:13 +00:00
|
|
|
_init() {
|
|
|
|
super._init();
|
2013-06-06 21:27:25 +00:00
|
|
|
|
2017-08-02 20:57:54 +00:00
|
|
|
this._systemActions = new SystemActions.getDefault();
|
2013-06-11 19:25:32 +00:00
|
|
|
|
|
|
|
this._createSubMenu();
|
|
|
|
|
2019-04-12 21:00:49 +00:00
|
|
|
this._loginScreenItem.connect('notify::visible',
|
2019-01-28 00:42:00 +00:00
|
|
|
() => this._updateMultiUser());
|
2019-04-12 21:00:49 +00:00
|
|
|
this._logoutItem.connect('notify::visible',
|
2019-01-28 00:42:00 +00:00
|
|
|
() => this._updateMultiUser());
|
2011-06-03 22:10:55 +00:00
|
|
|
// Whether shutdown is available or not depends on both lockdown
|
|
|
|
// settings (disable-log-out) and Polkit policy - the latter doesn't
|
|
|
|
// notify, so we update the menu item each time the menu opens or
|
|
|
|
// the lockdown setting changes, which should be close enough.
|
2017-10-31 00:38:18 +00:00
|
|
|
this.menu.connect('open-state-changed', (menu, open) => {
|
|
|
|
if (!open)
|
|
|
|
return;
|
2012-10-19 15:41:10 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
this._systemActions.forceUpdate();
|
|
|
|
});
|
2017-08-02 20:57:54 +00:00
|
|
|
this._updateMultiUser();
|
2013-07-17 06:33:09 +00:00
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
2012-09-01 12:42:53 +00:00
|
|
|
this._sessionUpdated();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sessionUpdated() {
|
2019-10-15 18:51:33 +00:00
|
|
|
this._settingsItem.visible = Main.sessionMode.allowSettings;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_updateMultiUser() {
|
2019-04-12 21:00:49 +00:00
|
|
|
let hasSwitchUser = this._loginScreenItem.visible;
|
|
|
|
let hasLogout = this._logoutItem.visible;
|
2013-06-11 19:25:32 +00:00
|
|
|
|
2019-10-15 18:51:33 +00:00
|
|
|
this._sessionSubMenu.visible = hasSwitchUser || hasLogout;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-02-04 23:37:54 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_createSubMenu() {
|
2017-08-02 20:57:54 +00:00
|
|
|
let bindFlags = GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE;
|
2009-11-10 17:13:58 +00:00
|
|
|
let item;
|
|
|
|
|
2019-12-09 18:16:41 +00:00
|
|
|
item = new PopupMenu.PopupImageMenuItem(
|
|
|
|
this._systemActions.getName('lock-orientation'),
|
2019-10-15 18:51:33 +00:00
|
|
|
this._systemActions.orientation_lock_icon);
|
2019-12-09 18:16:41 +00:00
|
|
|
|
2017-08-02 20:57:54 +00:00
|
|
|
item.connect('activate', () => {
|
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
2019-10-15 18:51:33 +00:00
|
|
|
this._systemActions.activateLockOrientation();
|
2017-08-02 20:57:54 +00:00
|
|
|
});
|
2019-10-15 18:51:33 +00:00
|
|
|
this.menu.addMenuItem(item);
|
|
|
|
this._orientationLockItem = item;
|
|
|
|
this._systemActions.bind_property('can-lock-orientation',
|
|
|
|
this._orientationLockItem,
|
2017-08-02 20:57:54 +00:00
|
|
|
'visible',
|
|
|
|
bindFlags);
|
2019-10-15 18:51:33 +00:00
|
|
|
this._systemActions.connect('notify::orientation-lock-icon', () => {
|
|
|
|
let iconName = this._systemActions.orientation_lock_icon;
|
2019-12-09 18:16:41 +00:00
|
|
|
let labelText = this._systemActions.getName("lock-orientation");
|
|
|
|
|
2019-10-15 18:51:33 +00:00
|
|
|
this._orientationLockItem.setIcon(iconName);
|
2019-12-09 18:16:41 +00:00
|
|
|
this._orientationLockItem.label.text = labelText;
|
2017-08-02 20:57:54 +00:00
|
|
|
});
|
2013-06-11 21:17:09 +00:00
|
|
|
|
2018-07-24 14:40:03 +00:00
|
|
|
let app = this._settingsApp = Shell.AppSystem.get_default().lookup_app(
|
|
|
|
'gnome-control-center.desktop'
|
|
|
|
);
|
|
|
|
if (app) {
|
|
|
|
let [icon, name] = [app.app_info.get_icon().names[0],
|
|
|
|
app.get_name()];
|
2019-10-15 18:51:33 +00:00
|
|
|
item = new PopupMenu.PopupImageMenuItem(name, icon);
|
|
|
|
item.connect('activate', () => {
|
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
|
|
|
Main.overview.hide();
|
|
|
|
this._settingsApp.activate();
|
|
|
|
});
|
|
|
|
this.menu.addMenuItem(item);
|
|
|
|
this._settingsItem = item;
|
2018-07-24 14:40:03 +00:00
|
|
|
} else {
|
|
|
|
log('Missing required core component Settings, expect trouble…');
|
2019-10-15 18:51:33 +00:00
|
|
|
this._settingsItem = new St.Widget();
|
2018-07-24 14:40:03 +00:00
|
|
|
}
|
2013-06-11 21:17:09 +00:00
|
|
|
|
2019-10-15 18:51:33 +00:00
|
|
|
item = new PopupMenu.PopupImageMenuItem(_('Lock'), 'changes-prevent-symbolic');
|
|
|
|
item.connect('activate', () => {
|
2019-08-19 18:56:36 +00:00
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
2019-10-15 18:51:33 +00:00
|
|
|
this._systemActions.activateLockScreen();
|
2017-08-02 20:57:54 +00:00
|
|
|
});
|
2019-10-15 18:51:33 +00:00
|
|
|
this.menu.addMenuItem(item);
|
|
|
|
this._lockScreenItem = item;
|
|
|
|
this._systemActions.bind_property('can-lock-screen',
|
|
|
|
this._lockScreenItem,
|
2017-08-02 20:57:54 +00:00
|
|
|
'visible',
|
|
|
|
bindFlags);
|
2019-10-15 18:51:33 +00:00
|
|
|
|
|
|
|
this._sessionSubMenu = new PopupMenu.PopupSubMenuMenuItem(
|
|
|
|
_('Power Off / Log Out'), true);
|
|
|
|
this._sessionSubMenu.icon.icon_name = 'system-shutdown-symbolic';
|
|
|
|
|
|
|
|
item = new PopupMenu.PopupMenuItem(_("Log Out"));
|
|
|
|
item.connect('activate', () => {
|
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
|
|
|
this._systemActions.activateLogout();
|
|
|
|
});
|
|
|
|
this._sessionSubMenu.menu.addMenuItem(item);
|
|
|
|
this._logoutItem = item;
|
|
|
|
this._systemActions.bind_property('can-logout',
|
|
|
|
this._logoutItem,
|
|
|
|
'visible',
|
2017-08-02 20:57:54 +00:00
|
|
|
bindFlags);
|
2013-07-17 06:33:09 +00:00
|
|
|
|
2019-10-15 18:51:33 +00:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("Switch User…"));
|
|
|
|
item.connect('activate', () => {
|
2017-08-02 20:57:54 +00:00
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
2019-10-15 18:51:33 +00:00
|
|
|
this._systemActions.activateSwitchUser();
|
2017-08-02 20:57:54 +00:00
|
|
|
});
|
2019-10-15 18:51:33 +00:00
|
|
|
this._sessionSubMenu.menu.addMenuItem(item);
|
|
|
|
this._loginScreenItem = item;
|
|
|
|
this._systemActions.bind_property('can-switch-user',
|
|
|
|
this._loginScreenItem,
|
2017-08-02 20:57:54 +00:00
|
|
|
'visible',
|
|
|
|
bindFlags);
|
2013-06-11 21:17:09 +00:00
|
|
|
|
2019-10-15 18:51:33 +00:00
|
|
|
this._sessionSubMenu.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
|
|
|
|
|
|
|
item = new PopupMenu.PopupMenuItem(_("Suspend"));
|
|
|
|
item.connect('activate', () => {
|
2017-08-02 20:57:54 +00:00
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
|
|
|
this._systemActions.activateSuspend();
|
|
|
|
});
|
2019-10-15 18:51:33 +00:00
|
|
|
this._sessionSubMenu.menu.addMenuItem(item);
|
|
|
|
this._suspendItem = item;
|
2017-08-02 20:57:54 +00:00
|
|
|
this._systemActions.bind_property('can-suspend',
|
2019-10-15 18:51:33 +00:00
|
|
|
this._suspendItem,
|
2017-08-02 20:57:54 +00:00
|
|
|
'visible',
|
|
|
|
bindFlags);
|
2013-08-23 15:09:51 +00:00
|
|
|
|
2019-10-15 18:51:33 +00:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("Power Off…"));
|
|
|
|
item.connect('activate', () => {
|
2017-08-02 20:57:54 +00:00
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
|
|
|
this._systemActions.activatePowerOff();
|
|
|
|
});
|
2019-10-15 18:51:33 +00:00
|
|
|
this._sessionSubMenu.menu.addMenuItem(item);
|
|
|
|
this._powerOffItem = item;
|
2017-08-02 20:57:54 +00:00
|
|
|
this._systemActions.bind_property('can-power-off',
|
2019-10-15 18:51:33 +00:00
|
|
|
this._powerOffItem,
|
2017-08-02 20:57:54 +00:00
|
|
|
'visible',
|
|
|
|
bindFlags);
|
2013-08-23 15:09:51 +00:00
|
|
|
|
2019-10-15 18:51:33 +00:00
|
|
|
this.menu.addMenuItem(this._sessionSubMenu);
|
2017-08-02 20:57:54 +00:00
|
|
|
}
|
2019-07-16 09:24:13 +00:00
|
|
|
});
|