2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2009-11-10 12:13:58 -05:00
|
|
|
|
2011-05-10 10:13:05 -04:00
|
|
|
const AccountsService = imports.gi.AccountsService;
|
2012-05-19 19:19:25 -04:00
|
|
|
const Gdm = imports.gi.Gdm;
|
2011-03-21 08:51:46 -04:00
|
|
|
const Gio = imports.gi.Gio;
|
2009-11-10 12:13:58 -05:00
|
|
|
const GLib = imports.gi.GLib;
|
2013-02-11 11:39:29 -05:00
|
|
|
const Gtk = imports.gi.Gtk;
|
2009-11-10 12:13:58 -05:00
|
|
|
const Lang = imports.lang;
|
2013-06-11 17:17:09 -04:00
|
|
|
const Shell = imports.gi.Shell;
|
2009-11-10 12:13:58 -05:00
|
|
|
const St = imports.gi.St;
|
2013-02-11 11:39:29 -05:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2009-11-10 12:13:58 -05:00
|
|
|
|
2012-09-18 23:02:15 -04:00
|
|
|
const BoxPointer = imports.ui.boxpointer;
|
2010-04-29 13:13:20 -04:00
|
|
|
const GnomeSession = imports.misc.gnomeSession;
|
2012-10-19 11:41:10 -04:00
|
|
|
const LoginManager = imports.misc.loginManager;
|
2010-06-03 19:21:08 -04:00
|
|
|
const Main = imports.ui.main;
|
2013-02-11 11:39:29 -05:00
|
|
|
const ModalDialog = imports.ui.modalDialog;
|
2010-06-22 17:02:26 -04:00
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
2010-05-20 11:18:46 -04:00
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2010-11-17 11:43:08 -05:00
|
|
|
const Util = imports.misc.util;
|
2013-04-23 22:31:08 -04:00
|
|
|
const UserWidget = imports.ui.userWidget;
|
2009-11-10 12:13:58 -05:00
|
|
|
|
2011-03-21 08:51:46 -04:00
|
|
|
const LOCKDOWN_SCHEMA = 'org.gnome.desktop.lockdown';
|
2012-08-13 19:51:51 -04:00
|
|
|
const SCREENSAVER_SCHEMA = 'org.gnome.desktop.screensaver';
|
2013-01-15 03:30:43 -05:00
|
|
|
const PRIVACY_SCHEMA = 'org.gnome.desktop.privacy'
|
2011-03-21 08:51:46 -04:00
|
|
|
const DISABLE_USER_SWITCH_KEY = 'disable-user-switching';
|
|
|
|
const DISABLE_LOCK_SCREEN_KEY = 'disable-lock-screen';
|
|
|
|
const DISABLE_LOG_OUT_KEY = 'disable-log-out';
|
2012-10-29 00:27:18 -04:00
|
|
|
const ALWAYS_SHOW_LOG_OUT_KEY = 'always-show-log-out';
|
2011-03-21 08:51:46 -04:00
|
|
|
|
2013-02-11 11:39:29 -05:00
|
|
|
const MAX_USERS_IN_SESSION_DIALOG = 5;
|
|
|
|
|
|
|
|
const SystemdLoginSessionIface = <interface name='org.freedesktop.login1.Session'>
|
2013-02-18 12:03:13 -05:00
|
|
|
<property name="Id" type="s" access="read"/>
|
2013-02-11 11:39:29 -05:00
|
|
|
<property name="Remote" type="b" access="read"/>
|
|
|
|
<property name="Class" type="s" access="read"/>
|
|
|
|
<property name="Type" type="s" access="read"/>
|
2013-03-02 10:53:50 -05:00
|
|
|
<property name="State" type="s" access="read"/>
|
2013-02-11 11:39:29 -05:00
|
|
|
</interface>;
|
|
|
|
|
|
|
|
const SystemdLoginSession = Gio.DBusProxy.makeProxyWrapper(SystemdLoginSessionIface);
|
|
|
|
|
2013-05-22 14:46:47 -04:00
|
|
|
const Indicator = new Lang.Class({
|
|
|
|
Name: 'SystemIndicator',
|
2013-06-06 17:27:25 -04:00
|
|
|
Extends: PanelMenu.SystemIndicator,
|
2010-05-10 09:46:54 -04:00
|
|
|
|
2009-11-10 12:13:58 -05:00
|
|
|
_init: function() {
|
2013-06-06 17:27:25 -04:00
|
|
|
this.parent();
|
|
|
|
|
|
|
|
this._indicator = this.addIndicator(new Gio.ThemedIcon({ name: 'system-shutdown-symbolic' }));
|
2010-05-10 09:46:54 -04:00
|
|
|
|
2012-08-13 19:51:51 -04:00
|
|
|
this._screenSaverSettings = new Gio.Settings({ schema: SCREENSAVER_SCHEMA });
|
2011-03-21 08:51:46 -04:00
|
|
|
this._lockdownSettings = new Gio.Settings({ schema: LOCKDOWN_SCHEMA });
|
2013-01-15 03:30:43 -05:00
|
|
|
this._privacySettings = new Gio.Settings({ schema: PRIVACY_SCHEMA });
|
2013-07-17 02:33:09 -04:00
|
|
|
this._orientationSettings = new Gio.Settings({ schema: 'org.gnome.settings-daemon.peripherals.touchscreen' });
|
2011-03-21 08:51:46 -04:00
|
|
|
|
2011-03-12 15:34:01 -05:00
|
|
|
this._session = new GnomeSession.SessionManager();
|
2011-06-03 18:10:55 -04:00
|
|
|
this._haveShutdown = true;
|
2009-11-10 12:13:58 -05:00
|
|
|
|
2013-04-23 17:33:54 -04:00
|
|
|
this._loginManager = LoginManager.getLoginManager();
|
|
|
|
this._userManager = AccountsService.UserManager.get_default();
|
|
|
|
this._user = this._userManager.get_user(GLib.get_user_name());
|
2013-06-11 15:25:32 -04:00
|
|
|
|
|
|
|
this._createSubMenu();
|
|
|
|
|
2011-05-10 10:13:05 -04:00
|
|
|
this._userManager.connect('notify::is-loaded',
|
2012-05-10 07:16:15 -04:00
|
|
|
Lang.bind(this, this._updateMultiUser));
|
2011-10-18 14:57:24 -04:00
|
|
|
this._userManager.connect('notify::has-multiple-users',
|
2012-05-10 07:16:15 -04:00
|
|
|
Lang.bind(this, this._updateMultiUser));
|
2011-05-10 10:13:05 -04:00
|
|
|
this._userManager.connect('user-added',
|
2012-05-10 07:16:15 -04:00
|
|
|
Lang.bind(this, this._updateMultiUser));
|
2011-05-10 10:13:05 -04:00
|
|
|
this._userManager.connect('user-removed',
|
2012-05-10 07:16:15 -04:00
|
|
|
Lang.bind(this, this._updateMultiUser));
|
2011-03-21 08:51:46 -04:00
|
|
|
this._lockdownSettings.connect('changed::' + DISABLE_USER_SWITCH_KEY,
|
2013-06-11 15:25:32 -04:00
|
|
|
Lang.bind(this, this._updateMultiUser));
|
2011-03-21 08:51:46 -04:00
|
|
|
this._lockdownSettings.connect('changed::' + DISABLE_LOG_OUT_KEY,
|
2013-06-11 15:25:32 -04:00
|
|
|
Lang.bind(this, this._updateMultiUser));
|
2011-03-21 08:51:46 -04:00
|
|
|
this._lockdownSettings.connect('changed::' + DISABLE_LOCK_SCREEN_KEY,
|
|
|
|
Lang.bind(this, this._updateLockScreen));
|
2013-01-30 09:19:54 -05:00
|
|
|
global.settings.connect('changed::' + ALWAYS_SHOW_LOG_OUT_KEY,
|
2013-06-11 15:25:32 -04:00
|
|
|
Lang.bind(this, this._updateMultiUser));
|
2011-03-21 08:51:46 -04:00
|
|
|
this._updateSwitchUser();
|
2013-06-11 15:25:32 -04:00
|
|
|
this._updateMultiUser();
|
2011-02-04 18:37:54 -05:00
|
|
|
|
2011-06-03 18:10:55 -04: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.
|
|
|
|
this.menu.connect('open-state-changed', Lang.bind(this,
|
|
|
|
function(menu, open) {
|
2012-10-19 11:41:10 -04:00
|
|
|
if (!open)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._updateHaveShutdown();
|
2011-06-03 18:10:55 -04:00
|
|
|
}));
|
|
|
|
this._lockdownSettings.connect('changed::' + DISABLE_LOG_OUT_KEY,
|
|
|
|
Lang.bind(this, this._updateHaveShutdown));
|
|
|
|
|
2013-07-17 02:33:09 -04:00
|
|
|
this._orientationSettings.connect('changed::orientation-lock',
|
|
|
|
Lang.bind(this, this._updateOrientationLock));
|
|
|
|
this._orientationExists = false;
|
|
|
|
Gio.DBus.session.watch_name('org.gnome.SettingsDaemon.Orientation',
|
|
|
|
Gio.BusNameWatcherFlags.NONE,
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this._orentationExists = true;
|
|
|
|
this._updateOrientationLock();
|
|
|
|
}),
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this._orentationExists = false;
|
|
|
|
this._updateOrientationLock();
|
|
|
|
}));
|
|
|
|
this._updateOrientationLock();
|
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
Main.sessionMode.connect('updated', Lang.bind(this, this._sessionUpdated));
|
|
|
|
this._sessionUpdated();
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
2013-08-12 13:08:53 -04:00
|
|
|
_updateActionsVisibility: function() {
|
|
|
|
let visible = (this._settingsAction.visible ||
|
|
|
|
this._orientationLockAction.visible ||
|
|
|
|
this._lockScreenAction.visible ||
|
|
|
|
this._powerOffAction.visible);
|
|
|
|
|
|
|
|
this._actionsItem.actor.visible = visible;
|
|
|
|
},
|
|
|
|
|
2012-09-01 08:42:53 -04:00
|
|
|
_sessionUpdated: function() {
|
2013-06-11 17:17:09 -04:00
|
|
|
this._updateLockScreen();
|
|
|
|
this._updatePowerOff();
|
2013-08-12 13:15:13 -04:00
|
|
|
this._updateMultiUser();
|
2013-06-11 17:17:09 -04:00
|
|
|
this._settingsAction.visible = Main.sessionMode.allowSettings;
|
2013-08-12 13:08:53 -04:00
|
|
|
this._updateActionsVisibility();
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
2012-05-10 07:16:15 -04:00
|
|
|
_updateMultiUser: function() {
|
2013-06-11 17:17:09 -04:00
|
|
|
let shouldShowInMode = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
2013-06-11 15:25:32 -04:00
|
|
|
let hasSwitchUser = this._updateSwitchUser();
|
|
|
|
let hasLogout = this._updateLogout();
|
|
|
|
|
2013-06-11 17:17:09 -04:00
|
|
|
this._switchUserSubMenu.actor.visible = shouldShowInMode && (hasSwitchUser || hasLogout);
|
2012-05-10 07:16:15 -04:00
|
|
|
},
|
|
|
|
|
2009-11-10 12:13:58 -05:00
|
|
|
_updateSwitchUser: function() {
|
2011-03-21 08:51:46 -04:00
|
|
|
let allowSwitch = !this._lockdownSettings.get_boolean(DISABLE_USER_SWITCH_KEY);
|
2012-05-13 11:11:06 -04:00
|
|
|
let multiUser = this._userManager.can_switch() && this._userManager.has_multiple_users;
|
|
|
|
|
2013-06-11 15:25:32 -04:00
|
|
|
let visible = allowSwitch && multiUser;
|
|
|
|
this._loginScreenItem.actor.visible = visible;
|
|
|
|
return visible;
|
2011-03-21 08:51:46 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateLogout: function() {
|
|
|
|
let allowLogout = !this._lockdownSettings.get_boolean(DISABLE_LOG_OUT_KEY);
|
2012-10-29 00:27:18 -04:00
|
|
|
let alwaysShow = global.settings.get_boolean(ALWAYS_SHOW_LOG_OUT_KEY);
|
2012-10-28 23:55:43 -04:00
|
|
|
let systemAccount = this._user.system_account;
|
|
|
|
let localAccount = this._user.local_account;
|
2012-05-13 11:11:06 -04:00
|
|
|
let multiUser = this._userManager.has_multiple_users;
|
2012-05-19 19:19:25 -04:00
|
|
|
let multiSession = Gdm.get_session_ids().length > 1;
|
2012-05-13 11:11:06 -04:00
|
|
|
|
2013-06-11 15:25:32 -04:00
|
|
|
let visible = allowLogout && (alwaysShow || multiUser || multiSession || systemAccount || !localAccount);
|
|
|
|
this._logoutItem.actor.visible = visible;
|
|
|
|
return visible;
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateSwitchUserSubMenu: function() {
|
|
|
|
this._switchUserSubMenu.label.text = this._user.get_real_name();
|
2013-08-12 06:56:51 -04:00
|
|
|
let clutterText = this._switchUserSubMenu.label.clutter_text;
|
|
|
|
|
|
|
|
// XXX -- for some reason, the ClutterText's width changes
|
|
|
|
// rapidly unless we force a relayout of the actor. Probably
|
|
|
|
// a size cache issue or something. Moving this to be a layout
|
|
|
|
// manager would be a much better idea.
|
|
|
|
clutterText.get_allocation_box();
|
|
|
|
|
|
|
|
let layout = clutterText.get_layout();
|
|
|
|
if (layout.is_ellipsized())
|
|
|
|
this._switchUserSubMenu.label.text = this._user.get_user_name();
|
2013-06-11 15:25:32 -04:00
|
|
|
|
|
|
|
let iconFile = this._user.get_icon_file();
|
|
|
|
if (iconFile && !GLib.file_test(iconFile, GLib.FileTest.EXISTS))
|
|
|
|
iconFile = null;
|
|
|
|
|
|
|
|
if (iconFile) {
|
|
|
|
let file = Gio.File.new_for_path(iconFile);
|
|
|
|
let gicon = new Gio.FileIcon({ file: file });
|
|
|
|
this._switchUserSubMenu.icon.gicon = gicon;
|
|
|
|
} else {
|
2013-08-12 13:10:18 -04:00
|
|
|
this._switchUserSubMenu.icon.icon_name = 'avatar-default-symbolic';
|
2013-06-11 15:25:32 -04:00
|
|
|
}
|
2011-03-21 08:51:46 -04:00
|
|
|
},
|
|
|
|
|
2013-07-17 02:33:09 -04:00
|
|
|
_updateOrientationLock: function() {
|
|
|
|
this._orientationLockAction.visible = this._orientationExists;
|
|
|
|
|
|
|
|
let locked = this._orientationSettings.get_boolean('orientation-lock');
|
|
|
|
let icon = this._orientationLockAction.child;
|
|
|
|
icon.icon_name = locked ? 'rotation-locked-symbolic' : 'rotation-allowed-symbolic';
|
2013-08-12 13:08:53 -04:00
|
|
|
|
|
|
|
this._updateActionsVisibility();
|
2013-07-17 02:33:09 -04:00
|
|
|
},
|
|
|
|
|
2011-03-21 08:51:46 -04:00
|
|
|
_updateLockScreen: function() {
|
2013-06-11 17:17:09 -04:00
|
|
|
let showLock = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
2011-03-21 08:51:46 -04:00
|
|
|
let allowLockScreen = !this._lockdownSettings.get_boolean(DISABLE_LOCK_SCREEN_KEY);
|
2013-06-11 17:17:09 -04:00
|
|
|
this._lockScreenAction.visible = showLock && allowLockScreen && LoginManager.canLock();
|
2013-08-12 13:08:53 -04:00
|
|
|
this._updateActionsVisibility();
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
2011-06-03 18:10:55 -04:00
|
|
|
_updateHaveShutdown: function() {
|
|
|
|
this._session.CanShutdownRemote(Lang.bind(this,
|
|
|
|
function(result, error) {
|
|
|
|
if (!error) {
|
2012-06-26 11:44:24 -04:00
|
|
|
this._haveShutdown = result[0];
|
2013-06-11 14:33:59 -04:00
|
|
|
this._updatePowerOff();
|
2011-06-03 18:10:55 -04:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2013-06-11 14:33:59 -04:00
|
|
|
_updatePowerOff: function() {
|
2013-06-11 17:17:09 -04:00
|
|
|
this._powerOffAction.visible = this._haveShutdown && !Main.sessionMode.isLocked;
|
2013-08-12 13:08:53 -04:00
|
|
|
this._updateActionsVisibility();
|
2013-06-11 17:17:09 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_createActionButton: function(iconName, accessibleName) {
|
|
|
|
let icon = new St.Button({ reactive: true,
|
|
|
|
can_focus: true,
|
|
|
|
track_hover: true,
|
|
|
|
accessible_name: accessibleName,
|
|
|
|
style_class: 'system-menu-action' });
|
|
|
|
icon.child = new St.Icon({ icon_name: iconName });
|
|
|
|
return icon;
|
2011-02-04 18:37:54 -05:00
|
|
|
},
|
|
|
|
|
2009-11-10 12:13:58 -05:00
|
|
|
_createSubMenu: function() {
|
|
|
|
let item;
|
|
|
|
|
2013-06-11 15:25:32 -04:00
|
|
|
this._switchUserSubMenu = new PopupMenu.PopupSubMenuMenuItem('', true);
|
|
|
|
this._switchUserSubMenu.icon.style_class = 'system-switch-user-submenu-icon';
|
2009-11-10 12:13:58 -05:00
|
|
|
|
2013-08-12 06:56:51 -04:00
|
|
|
// Since the label of the switch user submenu depends on the width of
|
|
|
|
// the popup menu, and we can't easily connect on allocation-changed
|
|
|
|
// or notify::width without creating layout cycles, simply update the
|
|
|
|
// label whenever the menu is opened.
|
|
|
|
this.menu.connect('open-state-changed', Lang.bind(this, function(menu, isOpen) {
|
|
|
|
if (isOpen)
|
|
|
|
this._updateSwitchUserSubMenu();
|
|
|
|
}));
|
|
|
|
|
2010-10-19 11:59:23 -04:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("Switch User"));
|
2009-11-10 12:13:58 -05:00
|
|
|
item.connect('activate', Lang.bind(this, this._onLoginScreenActivate));
|
2013-06-11 15:25:32 -04:00
|
|
|
this._switchUserSubMenu.menu.addMenuItem(item);
|
2009-11-10 12:13:58 -05:00
|
|
|
this._loginScreenItem = item;
|
|
|
|
|
2012-05-10 07:24:12 -04:00
|
|
|
item = new PopupMenu.PopupMenuItem(_("Log Out"));
|
2009-11-10 12:13:58 -05:00
|
|
|
item.connect('activate', Lang.bind(this, this._onQuitSessionActivate));
|
2013-06-11 15:25:32 -04:00
|
|
|
this._switchUserSubMenu.menu.addMenuItem(item);
|
2011-03-21 08:51:46 -04:00
|
|
|
this._logoutItem = item;
|
2009-11-10 12:13:58 -05:00
|
|
|
|
2013-06-11 15:25:32 -04:00
|
|
|
this._user.connect('notify::is-loaded', Lang.bind(this, this._updateSwitchUserSubMenu));
|
|
|
|
this._user.connect('changed', Lang.bind(this, this._updateSwitchUserSubMenu));
|
|
|
|
|
2013-06-11 17:17:09 -04:00
|
|
|
this.menu.addMenuItem(this._switchUserSubMenu);
|
2013-06-11 15:25:32 -04:00
|
|
|
|
2013-06-11 17:17:09 -04:00
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
|
|
|
|
|
|
|
let hbox = new St.BoxLayout({ style_class: 'system-menu-actions-box' });
|
|
|
|
|
|
|
|
this._settingsAction = this._createActionButton('preferences-system-symbolic', _("Settings"));
|
|
|
|
this._settingsAction.connect('clicked', Lang.bind(this, this._onSettingsClicked));
|
|
|
|
hbox.add(this._settingsAction, { expand: true, x_fill: false });
|
|
|
|
|
2013-07-17 02:33:09 -04:00
|
|
|
this._orientationLockAction = this._createActionButton('', _("Orientation Lock"));
|
|
|
|
this._orientationLockAction.connect('clicked', Lang.bind(this, this._onOrientationLockClicked));
|
|
|
|
item.actor.add(this._orientationLockAction, { expand: true, x_fill: false });
|
|
|
|
|
2013-06-11 17:17:09 -04:00
|
|
|
this._lockScreenAction = this._createActionButton('changes-prevent-symbolic', _("Lock"));
|
|
|
|
this._lockScreenAction.connect('clicked', Lang.bind(this, this._onLockScreenClicked));
|
|
|
|
hbox.add(this._lockScreenAction, { expand: true, x_fill: false });
|
|
|
|
|
|
|
|
this._powerOffAction = this._createActionButton('system-shutdown-symbolic', _("Power Off"));
|
|
|
|
this._powerOffAction.connect('clicked', Lang.bind(this, this._onPowerOffClicked));
|
|
|
|
hbox.add(this._powerOffAction, { expand: true, x_fill: false });
|
|
|
|
|
|
|
|
item = new PopupMenu.PopupBaseMenuItem({ reactive: false,
|
|
|
|
can_focus: false });
|
|
|
|
item.addActor(hbox, { expand: true });
|
2012-06-28 06:22:17 -04:00
|
|
|
|
2013-08-12 13:08:53 -04:00
|
|
|
this._actionsItem = item;
|
2012-06-28 06:22:17 -04:00
|
|
|
this.menu.addMenuItem(item);
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
2013-06-11 17:17:09 -04:00
|
|
|
_onSettingsClicked: function() {
|
|
|
|
this.menu.itemActivated();
|
|
|
|
let app = Shell.AppSystem.get_default().lookup_app('gnome-control-center.desktop');
|
|
|
|
Main.overview.hide();
|
|
|
|
app.activate();
|
|
|
|
},
|
|
|
|
|
2013-07-17 02:33:09 -04:00
|
|
|
_onOrientationLockClicked: function() {
|
|
|
|
this.menu.itemActivated();
|
|
|
|
let locked = this._orientationSettings.get_boolean('orientation-lock');
|
|
|
|
this._orientationSettings.set_boolean('orientation-lock', !locked);
|
|
|
|
this._updateOrientationLock();
|
|
|
|
},
|
|
|
|
|
2013-06-11 17:17:09 -04:00
|
|
|
_onLockScreenClicked: function() {
|
2013-06-18 04:46:44 -04:00
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
2010-06-03 19:21:08 -04:00
|
|
|
Main.overview.hide();
|
2012-06-02 18:10:23 -04:00
|
|
|
Main.screenShield.lock(true);
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onLoginScreenActivate: function() {
|
2013-06-18 04:46:44 -04:00
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
2010-06-03 19:21:08 -04:00
|
|
|
Main.overview.hide();
|
2013-03-04 13:33:36 -05:00
|
|
|
if (Main.screenShield)
|
|
|
|
Main.screenShield.lock(false);
|
2012-08-14 11:49:46 -04:00
|
|
|
Gdm.goto_login_session_sync(null);
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_onQuitSessionActivate: function() {
|
2010-06-03 19:21:08 -04:00
|
|
|
Main.overview.hide();
|
2011-03-12 15:34:01 -05:00
|
|
|
this._session.LogoutRemote(0);
|
2009-11-10 12:13:58 -05:00
|
|
|
},
|
|
|
|
|
2013-02-11 11:39:29 -05:00
|
|
|
_openSessionWarnDialog: function(sessions) {
|
|
|
|
let dialog = new ModalDialog.ModalDialog();
|
|
|
|
let subjectLabel = new St.Label({ style_class: 'end-session-dialog-subject',
|
|
|
|
text: _("Other users are logged in.") });
|
|
|
|
dialog.contentLayout.add(subjectLabel, { y_fill: true,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
|
|
|
|
let descriptionLabel = new St.Label({ style_class: 'end-session-dialog-description'});
|
|
|
|
descriptionLabel.set_text(_("Shutting down might cause them to lose unsaved work."));
|
2013-03-02 10:55:13 -05:00
|
|
|
descriptionLabel.clutter_text.line_wrap = true;
|
2013-02-11 11:39:29 -05:00
|
|
|
dialog.contentLayout.add(descriptionLabel, { x_fill: true,
|
|
|
|
y_fill: true,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
|
|
|
|
let scrollView = new St.ScrollView({ style_class: 'end-session-dialog-app-list' });
|
|
|
|
scrollView.add_style_class_name('vfade');
|
|
|
|
scrollView.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
|
|
|
|
dialog.contentLayout.add(scrollView, { x_fill: true, y_fill: true });
|
|
|
|
|
|
|
|
let userList = new St.BoxLayout({ vertical: true });
|
|
|
|
scrollView.add_actor(userList);
|
|
|
|
|
|
|
|
for (let i = 0; i < sessions.length; i++) {
|
|
|
|
let session = sessions[i];
|
|
|
|
let userEntry = new St.BoxLayout({ style_class: 'login-dialog-user-list-item',
|
|
|
|
vertical: false });
|
2013-04-23 22:31:08 -04:00
|
|
|
let avatar = new UserWidget.Avatar(session.user);
|
2013-02-11 11:39:29 -05:00
|
|
|
avatar.update();
|
|
|
|
userEntry.add(avatar.actor);
|
|
|
|
|
|
|
|
let userLabelText = "";;
|
|
|
|
let userName = session.user.get_real_name() ?
|
|
|
|
session.user.get_real_name() : session.username;
|
|
|
|
|
|
|
|
if (session.info.remote)
|
2013-03-10 19:37:52 -04:00
|
|
|
/* Translators: Remote here refers to a remote session, like a ssh login */
|
2013-02-11 11:39:29 -05:00
|
|
|
userLabelText = _("%s (remote)").format(userName);
|
|
|
|
else if (session.info.type == "tty")
|
2013-03-10 19:37:52 -04:00
|
|
|
/* Translators: Console here refers to a tty like a VT console */
|
2013-02-11 11:39:29 -05:00
|
|
|
userLabelText = _("%s (console)").format(userName);
|
|
|
|
else
|
|
|
|
userLabelText = userName;
|
|
|
|
|
|
|
|
let textLayout = new St.BoxLayout({ style_class: 'login-dialog-user-list-item-text-box',
|
|
|
|
vertical: true });
|
|
|
|
textLayout.add(new St.Label({ text: userLabelText }),
|
|
|
|
{ y_fill: false,
|
|
|
|
y_align: St.Align.MIDDLE,
|
|
|
|
expand: true });
|
|
|
|
userEntry.add(textLayout, { expand: true });
|
|
|
|
userList.add(userEntry, { x_fill: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
let cancelButton = { label: _("Cancel"),
|
|
|
|
action: function() { dialog.close(); },
|
|
|
|
key: Clutter.Escape };
|
|
|
|
|
|
|
|
let powerOffButton = { label: _("Power Off"), action: Lang.bind(this, function() {
|
|
|
|
dialog.close();
|
|
|
|
this._session.ShutdownRemote();
|
|
|
|
}), default: true };
|
|
|
|
|
|
|
|
dialog.setButtons([cancelButton, powerOffButton]);
|
|
|
|
|
|
|
|
dialog.open();
|
|
|
|
},
|
|
|
|
|
2013-06-11 17:17:09 -04:00
|
|
|
_onPowerOffClicked: function() {
|
|
|
|
this.menu.itemActivated();
|
2010-06-03 19:21:08 -04:00
|
|
|
Main.overview.hide();
|
2013-06-11 14:33:59 -04:00
|
|
|
this._loginManager.listSessions(Lang.bind(this, function(result) {
|
|
|
|
let sessions = [];
|
|
|
|
let n = 0;
|
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
let[id, uid, userName, seat, sessionPath] = result[i];
|
|
|
|
let proxy = new SystemdLoginSession(Gio.DBus.system,
|
|
|
|
'org.freedesktop.login1',
|
|
|
|
sessionPath);
|
|
|
|
|
|
|
|
if (proxy.Class != 'user')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (proxy.State == 'closing')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (proxy.Id == GLib.getenv('XDG_SESSION_ID'))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sessions.push({ user: this._userManager.get_user(userName),
|
|
|
|
username: userName,
|
|
|
|
info: { type: proxy.Type,
|
|
|
|
remote: proxy.Remote }
|
|
|
|
});
|
|
|
|
|
|
|
|
// limit the number of entries
|
|
|
|
n++;
|
|
|
|
if (n == MAX_USERS_IN_SESSION_DIALOG)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n != 0)
|
|
|
|
this._openSessionWarnDialog(sessions);
|
|
|
|
else
|
|
|
|
this._session.ShutdownRemote();
|
|
|
|
}));
|
2009-11-10 12:13:58 -05:00
|
|
|
}
|
2011-11-20 09:38:48 -05:00
|
|
|
});
|