2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
/*
|
2011-01-06 15:30:15 +00:00
|
|
|
* Copyright 2010 Red Hat, Inc
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const Lang = imports.lang;
|
2013-01-26 08:01:41 +00:00
|
|
|
const Mainloop = imports.mainloop;
|
2011-01-06 15:30:15 +00:00
|
|
|
|
2011-05-10 14:13:05 +00:00
|
|
|
const AccountsService = imports.gi.AccountsService;
|
2011-01-06 15:30:15 +00:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2011-08-16 12:24:39 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
2011-01-06 15:30:15 +00:00
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
|
|
|
const Pango = imports.gi.Pango;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
|
2011-08-16 12:24:39 +00:00
|
|
|
const GnomeSession = imports.misc.gnomeSession;
|
2013-08-22 18:35:28 +00:00
|
|
|
const LoginManager = imports.misc.loginManager;
|
2011-01-06 15:30:15 +00:00
|
|
|
const ModalDialog = imports.ui.modalDialog;
|
|
|
|
const Tweener = imports.ui.tweener;
|
2013-04-24 02:31:08 +00:00
|
|
|
const UserWidget = imports.ui.userWidget;
|
2011-01-06 15:30:15 +00:00
|
|
|
|
|
|
|
let _endSessionDialog = null;
|
|
|
|
|
|
|
|
const _ITEM_ICON_SIZE = 48;
|
|
|
|
const _DIALOG_ICON_SIZE = 32;
|
|
|
|
|
|
|
|
const GSM_SESSION_MANAGER_LOGOUT_FORCE = 2;
|
|
|
|
|
2013-10-24 21:51:58 +00:00
|
|
|
const EndSessionDialogIface = '<node> \
|
|
|
|
<interface name="org.gnome.SessionManager.EndSessionDialog"> \
|
|
|
|
<method name="Open"> \
|
|
|
|
<arg type="u" direction="in" /> \
|
|
|
|
<arg type="u" direction="in" /> \
|
|
|
|
<arg type="u" direction="in" /> \
|
|
|
|
<arg type="ao" direction="in" /> \
|
|
|
|
</method> \
|
|
|
|
<method name="Close" /> \
|
|
|
|
<signal name="ConfirmedLogout" /> \
|
|
|
|
<signal name="ConfirmedReboot" /> \
|
|
|
|
<signal name="ConfirmedShutdown" /> \
|
|
|
|
<signal name="Canceled" /> \
|
|
|
|
<signal name="Closed" /> \
|
|
|
|
</interface> \
|
|
|
|
</node>';
|
2011-01-06 15:30:15 +00:00
|
|
|
|
|
|
|
const logoutDialogContent = {
|
2011-10-21 20:29:13 +00:00
|
|
|
subjectWithUser: C_("title", "Log Out %s"),
|
|
|
|
subject: C_("title", "Log Out"),
|
2013-08-23 16:30:30 +00:00
|
|
|
descriptionWithUser: function(user, seconds) {
|
2011-09-07 11:34:48 +00:00
|
|
|
return ngettext("%s will be logged out automatically in %d second.",
|
|
|
|
"%s will be logged out automatically in %d seconds.",
|
|
|
|
seconds).format(user, seconds);
|
|
|
|
},
|
2013-08-23 16:30:30 +00:00
|
|
|
description: function(seconds) {
|
2011-09-07 11:34:48 +00:00
|
|
|
return ngettext("You will be logged out automatically in %d second.",
|
|
|
|
"You will be logged out automatically in %d seconds.",
|
|
|
|
seconds).format(seconds);
|
|
|
|
},
|
2011-03-21 20:12:30 +00:00
|
|
|
confirmButtons: [{ signal: 'ConfirmedLogout',
|
2011-10-21 20:29:13 +00:00
|
|
|
label: C_("button", "Log Out") }],
|
2013-08-30 11:40:40 +00:00
|
|
|
iconStyleClass: 'end-session-dialog-logout-icon',
|
|
|
|
showOtherSessions: false,
|
2011-01-06 15:30:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const shutdownDialogContent = {
|
2011-10-21 20:29:13 +00:00
|
|
|
subject: C_("title", "Power Off"),
|
2013-08-23 16:30:30 +00:00
|
|
|
description: function(seconds) {
|
2011-09-07 11:34:48 +00:00
|
|
|
return ngettext("The system will power off automatically in %d second.",
|
|
|
|
"The system will power off automatically in %d seconds.",
|
|
|
|
seconds).format(seconds);
|
|
|
|
},
|
2011-03-21 20:12:30 +00:00
|
|
|
confirmButtons: [{ signal: 'ConfirmedReboot',
|
2011-10-21 20:29:13 +00:00
|
|
|
label: C_("button", "Restart") },
|
2011-03-21 20:12:30 +00:00
|
|
|
{ signal: 'ConfirmedShutdown',
|
2011-10-21 20:29:13 +00:00
|
|
|
label: C_("button", "Power Off") }],
|
2012-05-30 13:58:37 +00:00
|
|
|
iconName: 'system-shutdown-symbolic',
|
2013-08-30 11:40:40 +00:00
|
|
|
iconStyleClass: 'end-session-dialog-shutdown-icon',
|
|
|
|
showOtherSessions: true,
|
2011-01-06 15:30:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const restartDialogContent = {
|
2011-10-21 20:29:13 +00:00
|
|
|
subject: C_("title", "Restart"),
|
2013-08-23 16:30:30 +00:00
|
|
|
description: function(seconds) {
|
2011-09-07 11:34:48 +00:00
|
|
|
return ngettext("The system will restart automatically in %d second.",
|
|
|
|
"The system will restart automatically in %d seconds.",
|
|
|
|
seconds).format(seconds);
|
|
|
|
},
|
2011-03-21 20:12:30 +00:00
|
|
|
confirmButtons: [{ signal: 'ConfirmedReboot',
|
2011-10-21 20:29:13 +00:00
|
|
|
label: C_("button", "Restart") }],
|
2012-11-01 16:18:32 +00:00
|
|
|
iconName: 'view-refresh-symbolic',
|
2013-08-30 11:40:40 +00:00
|
|
|
iconStyleClass: 'end-session-dialog-shutdown-icon',
|
|
|
|
showOtherSessions: true,
|
2011-01-06 15:30:15 +00:00
|
|
|
};
|
|
|
|
|
2013-08-26 04:52:41 +00:00
|
|
|
const restartInstallDialogContent = {
|
|
|
|
|
|
|
|
subject: C_("title", "Restart & Install Updates"),
|
|
|
|
description: function(seconds) {
|
|
|
|
return ngettext("The system will automatically restart and install updates in %d second.",
|
|
|
|
"The system will automatically restart and install updates in %d seconds.",
|
|
|
|
seconds).format(seconds);
|
|
|
|
},
|
|
|
|
confirmButtons: [{ signal: 'ConfirmedReboot',
|
|
|
|
label: C_("button", "Restart & Install") }],
|
|
|
|
iconName: 'view-refresh-symbolic',
|
2013-08-30 11:40:40 +00:00
|
|
|
iconStyleClass: 'end-session-dialog-shutdown-icon',
|
|
|
|
showOtherSessions: true,
|
2013-08-26 04:52:41 +00:00
|
|
|
};
|
|
|
|
|
2011-01-06 15:30:15 +00:00
|
|
|
const DialogContent = {
|
|
|
|
0 /* GSM_SHELL_END_SESSION_DIALOG_TYPE_LOGOUT */: logoutDialogContent,
|
|
|
|
1 /* GSM_SHELL_END_SESSION_DIALOG_TYPE_SHUTDOWN */: shutdownDialogContent,
|
2013-08-26 04:52:41 +00:00
|
|
|
2 /* GSM_SHELL_END_SESSION_DIALOG_TYPE_RESTART */: restartDialogContent,
|
|
|
|
3: restartInstallDialogContent
|
2011-01-06 15:30:15 +00:00
|
|
|
};
|
|
|
|
|
2013-08-22 18:35:28 +00:00
|
|
|
const MAX_USERS_IN_SESSION_DIALOG = 5;
|
|
|
|
|
2013-10-24 21:51:58 +00:00
|
|
|
const LogindSessionIface = '<node> \
|
|
|
|
<interface name="org.freedesktop.login1.Session"> \
|
|
|
|
<property name="Id" type="s" access="read"/> \
|
|
|
|
<property name="Remote" type="b" access="read"/> \
|
|
|
|
<property name="Class" type="s" access="read"/> \
|
|
|
|
<property name="Type" type="s" access="read"/> \
|
|
|
|
<property name="State" type="s" access="read"/> \
|
|
|
|
</interface> \
|
|
|
|
</node>';
|
2013-08-22 18:35:28 +00:00
|
|
|
|
|
|
|
const LogindSession = Gio.DBusProxy.makeProxyWrapper(LogindSessionIface);
|
|
|
|
|
2011-01-06 15:30:15 +00:00
|
|
|
function findAppFromInhibitor(inhibitor) {
|
2013-08-22 20:14:14 +00:00
|
|
|
let desktopFile;
|
|
|
|
try {
|
|
|
|
[desktopFile] = inhibitor.GetAppIdSync();
|
|
|
|
} catch(e) {
|
|
|
|
// XXX -- sometimes JIT inhibitors generated by gnome-session
|
|
|
|
// get removed too soon. Don't fail in this case.
|
2013-08-22 21:27:43 +00:00
|
|
|
log('gnome-session gave us a dead inhibitor: %s'.format(inhibitor.get_object_path()));
|
2013-08-22 20:14:14 +00:00
|
|
|
return null;
|
|
|
|
}
|
2011-01-06 15:30:15 +00:00
|
|
|
|
|
|
|
if (!GLib.str_has_suffix(desktopFile, '.desktop'))
|
2012-03-17 02:13:37 +00:00
|
|
|
desktopFile += '.desktop';
|
2011-01-06 15:30:15 +00:00
|
|
|
|
2012-03-17 02:16:30 +00:00
|
|
|
return Shell.AppSystem.get_default().lookup_heuristic_basename(desktopFile);
|
2011-01-06 15:30:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The logout timer only shows updates every 10 seconds
|
|
|
|
// until the last 10 seconds, then it shows updates every
|
|
|
|
// second. This function takes a given time and returns
|
|
|
|
// what we should show to the user for that time.
|
|
|
|
function _roundSecondsToInterval(totalSeconds, secondsLeft, interval) {
|
|
|
|
let time;
|
|
|
|
|
|
|
|
time = Math.ceil(secondsLeft);
|
|
|
|
|
|
|
|
// Final count down is in decrements of 1
|
|
|
|
if (time <= interval)
|
|
|
|
return time;
|
|
|
|
|
|
|
|
// Round up higher than last displayable time interval
|
|
|
|
time += interval - 1;
|
|
|
|
|
|
|
|
// Then round down to that time interval
|
|
|
|
if (time > totalSeconds)
|
|
|
|
time = Math.ceil(totalSeconds);
|
|
|
|
else
|
|
|
|
time -= time % interval;
|
|
|
|
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _setLabelText(label, text) {
|
|
|
|
if (text) {
|
|
|
|
label.set_text(text);
|
|
|
|
label.show();
|
|
|
|
} else {
|
|
|
|
label.set_text('');
|
|
|
|
label.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
// This always returns the same singleton object
|
|
|
|
// By instantiating it initially, we register the
|
|
|
|
// bus object, etc.
|
2011-11-20 15:32:59 +00:00
|
|
|
_endSessionDialog = new EndSessionDialog();
|
2011-01-06 15:30:15 +00:00
|
|
|
}
|
|
|
|
|
2011-11-20 15:32:59 +00:00
|
|
|
const EndSessionDialog = new Lang.Class({
|
|
|
|
Name: 'EndSessionDialog',
|
|
|
|
Extends: ModalDialog.ModalDialog,
|
2011-01-06 15:30:15 +00:00
|
|
|
|
|
|
|
_init: function() {
|
2013-04-06 14:53:11 +00:00
|
|
|
this.parent({ styleClass: 'end-session-dialog',
|
|
|
|
destroyOnClose: false });
|
2011-01-06 15:30:15 +00:00
|
|
|
|
2013-08-22 18:35:28 +00:00
|
|
|
this._loginManager = LoginManager.getLoginManager();
|
|
|
|
this._userManager = AccountsService.UserManager.get_default();
|
|
|
|
this._user = this._userManager.get_user(GLib.get_user_name());
|
2013-08-26 04:52:41 +00:00
|
|
|
this._updatesFile = Gio.File.new_for_path('/system-update');
|
2011-01-06 15:30:15 +00:00
|
|
|
|
|
|
|
this._secondsLeft = 0;
|
|
|
|
this._totalSecondsToStayOpen = 0;
|
2013-08-23 16:13:35 +00:00
|
|
|
this._applications = [];
|
2013-08-22 18:35:28 +00:00
|
|
|
this._sessions = [];
|
2011-01-06 15:30:15 +00:00
|
|
|
|
|
|
|
this.connect('destroy',
|
|
|
|
Lang.bind(this, this._onDestroy));
|
|
|
|
this.connect('opened',
|
|
|
|
Lang.bind(this, this._onOpened));
|
|
|
|
|
2013-08-22 18:48:28 +00:00
|
|
|
this._userLoadedId = this._user.connect('notify::is_loaded', Lang.bind(this, this._sync));
|
|
|
|
this._userChangedId = this._user.connect('changed', Lang.bind(this, this._sync));
|
2011-01-06 15:30:15 +00:00
|
|
|
|
|
|
|
let mainContentLayout = new St.BoxLayout({ vertical: false });
|
|
|
|
this.contentLayout.add(mainContentLayout,
|
|
|
|
{ x_fill: true,
|
|
|
|
y_fill: false });
|
|
|
|
|
|
|
|
this._iconBin = new St.Bin();
|
|
|
|
mainContentLayout.add(this._iconBin,
|
|
|
|
{ x_fill: true,
|
|
|
|
y_fill: false,
|
|
|
|
x_align: St.Align.END,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
|
|
|
|
let messageLayout = new St.BoxLayout({ vertical: true });
|
|
|
|
mainContentLayout.add(messageLayout,
|
|
|
|
{ y_align: St.Align.START });
|
|
|
|
|
|
|
|
this._subjectLabel = new St.Label({ style_class: 'end-session-dialog-subject' });
|
|
|
|
|
|
|
|
messageLayout.add(this._subjectLabel,
|
|
|
|
{ y_fill: false,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
|
|
|
|
this._descriptionLabel = new St.Label({ style_class: 'end-session-dialog-description' });
|
|
|
|
this._descriptionLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
|
|
|
this._descriptionLabel.clutter_text.line_wrap = true;
|
|
|
|
|
|
|
|
messageLayout.add(this._descriptionLabel,
|
|
|
|
{ y_fill: true,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
|
2013-08-23 16:13:35 +00:00
|
|
|
this._scrollView = new St.ScrollView({ style_class: 'end-session-dialog-list' });
|
|
|
|
this._scrollView.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
|
|
|
|
this.contentLayout.add(this._scrollView,
|
2011-01-06 15:30:15 +00:00
|
|
|
{ x_fill: true,
|
|
|
|
y_fill: true });
|
2013-08-23 16:13:35 +00:00
|
|
|
this._scrollView.hide();
|
2011-03-21 20:11:15 +00:00
|
|
|
|
2013-08-23 16:13:35 +00:00
|
|
|
this._inhibitorSection = new St.BoxLayout({ vertical: true,
|
|
|
|
style_class: 'end-session-dialog-inhibitor-layout' });
|
|
|
|
this._scrollView.add_actor(this._inhibitorSection);
|
2011-03-21 20:11:15 +00:00
|
|
|
|
2013-08-23 16:13:35 +00:00
|
|
|
this._applicationHeader = new St.Label({ style_class: 'end-session-dialog-list-header',
|
|
|
|
text: _("Some applications are busy or have unsaved work.") });
|
|
|
|
this._applicationList = new St.BoxLayout({ vertical: true });
|
|
|
|
this._inhibitorSection.add_actor(this._applicationHeader);
|
|
|
|
this._inhibitorSection.add_actor(this._applicationList);
|
2011-03-21 20:11:15 +00:00
|
|
|
|
2013-08-23 16:13:35 +00:00
|
|
|
this._sessionHeader = new St.Label({ style_class: 'end-session-dialog-list-header',
|
|
|
|
text: _("Other users are logged in.") });
|
|
|
|
this._sessionList = new St.BoxLayout({ vertical: true });
|
|
|
|
this._inhibitorSection.add_actor(this._sessionHeader);
|
|
|
|
this._inhibitorSection.add_actor(this._sessionList);
|
2011-08-16 12:24:39 +00:00
|
|
|
|
|
|
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(EndSessionDialogIface, this);
|
|
|
|
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/SessionManager/EndSessionDialog');
|
2011-01-06 15:30:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onDestroy: function() {
|
|
|
|
this._user.disconnect(this._userLoadedId);
|
|
|
|
this._user.disconnect(this._userChangedId);
|
|
|
|
},
|
|
|
|
|
2013-08-22 18:48:28 +00:00
|
|
|
_sync: function() {
|
|
|
|
let open = (this.state == ModalDialog.State.OPENING || this.state == ModalDialog.State.OPENED);
|
|
|
|
if (!open)
|
2011-01-06 15:30:15 +00:00
|
|
|
return;
|
|
|
|
|
2013-08-26 04:52:41 +00:00
|
|
|
if (this._type == 2 && this._updatesFile.query_exists(null))
|
|
|
|
this._type = 3;
|
|
|
|
|
2011-01-06 15:30:15 +00:00
|
|
|
let dialogContent = DialogContent[this._type];
|
|
|
|
|
|
|
|
let subject = dialogContent.subject;
|
|
|
|
|
2013-08-22 18:48:28 +00:00
|
|
|
let description;
|
2013-08-23 16:30:30 +00:00
|
|
|
let displayTime = _roundSecondsToInterval(this._totalSecondsToStayOpen,
|
|
|
|
this._secondsLeft,
|
|
|
|
10);
|
2011-01-06 15:30:15 +00:00
|
|
|
|
2013-08-23 16:30:30 +00:00
|
|
|
if (this._user.is_loaded) {
|
|
|
|
let realName = this._user.get_real_name();
|
|
|
|
|
|
|
|
if (realName != null) {
|
|
|
|
if (dialogContent.subjectWithUser)
|
|
|
|
subject = dialogContent.subjectWithUser.format(realName);
|
|
|
|
|
|
|
|
if (dialogContent.descriptionWithUser)
|
|
|
|
description = dialogContent.descriptionWithUser(realName, displayTime);
|
|
|
|
else
|
|
|
|
description = dialogContent.description(displayTime);
|
|
|
|
}
|
2011-01-06 15:30:15 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 16:30:30 +00:00
|
|
|
if (!description)
|
|
|
|
description = dialogContent.description(displayTime);
|
|
|
|
|
2011-01-06 15:30:15 +00:00
|
|
|
_setLabelText(this._descriptionLabel, description);
|
2013-08-22 18:48:28 +00:00
|
|
|
_setLabelText(this._subjectLabel, subject);
|
2012-06-05 09:51:36 +00:00
|
|
|
|
|
|
|
let dialogContent = DialogContent[this._type];
|
2012-08-31 21:18:26 +00:00
|
|
|
if (dialogContent.iconName) {
|
|
|
|
this._iconBin.child = new St.Icon({ icon_name: dialogContent.iconName,
|
|
|
|
icon_size: _DIALOG_ICON_SIZE,
|
|
|
|
style_class: dialogContent.iconStyleClass });
|
|
|
|
} else {
|
2013-04-24 02:31:08 +00:00
|
|
|
let avatarWidget = new UserWidget.Avatar(this._user,
|
|
|
|
{ iconSize: _DIALOG_ICON_SIZE,
|
|
|
|
styleClass: dialogContent.iconStyleClass });
|
2012-08-31 21:18:26 +00:00
|
|
|
this._iconBin.child = avatarWidget.actor;
|
|
|
|
avatarWidget.update();
|
2012-06-05 09:51:36 +00:00
|
|
|
}
|
2013-08-23 16:13:35 +00:00
|
|
|
|
|
|
|
let hasApplications = this._applications.length > 0;
|
|
|
|
let hasSessions = this._sessions.length > 0;
|
|
|
|
this._scrollView.visible = hasApplications || hasSessions;
|
|
|
|
this._applicationHeader.visible = hasApplications;
|
|
|
|
this._sessionHeader.visible = hasSessions;
|
2012-06-05 09:51:36 +00:00
|
|
|
},
|
|
|
|
|
2011-01-06 15:30:15 +00:00
|
|
|
_updateButtons: function() {
|
|
|
|
let dialogContent = DialogContent[this._type];
|
2011-03-21 20:12:30 +00:00
|
|
|
let buttons = [{ action: Lang.bind(this, this.cancel),
|
|
|
|
label: _("Cancel"),
|
|
|
|
key: Clutter.Escape }];
|
|
|
|
|
|
|
|
for (let i = 0; i < dialogContent.confirmButtons.length; i++) {
|
|
|
|
let signal = dialogContent.confirmButtons[i].signal;
|
|
|
|
let label = dialogContent.confirmButtons[i].label;
|
|
|
|
buttons.push({ action: Lang.bind(this, function() {
|
2013-02-20 18:30:26 +00:00
|
|
|
this.close(true);
|
|
|
|
let signalId = this.connect('closed',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this.disconnect(signalId);
|
|
|
|
this._confirm(signal);
|
|
|
|
}));
|
2011-03-21 20:12:30 +00:00
|
|
|
}),
|
|
|
|
label: label });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setButtons(buttons);
|
2011-01-06 15:30:15 +00:00
|
|
|
},
|
|
|
|
|
2013-02-20 18:30:26 +00:00
|
|
|
close: function(skipSignal) {
|
2011-11-20 15:32:59 +00:00
|
|
|
this.parent();
|
2013-02-20 18:30:26 +00:00
|
|
|
|
|
|
|
if (!skipSignal)
|
|
|
|
this._dbusImpl.emit_signal('Closed', null);
|
2011-03-22 16:50:56 +00:00
|
|
|
},
|
|
|
|
|
2011-01-06 15:30:15 +00:00
|
|
|
cancel: function() {
|
|
|
|
this._stopTimer();
|
2011-08-16 12:24:39 +00:00
|
|
|
this._dbusImpl.emit_signal('Canceled', null);
|
2013-02-20 18:12:42 +00:00
|
|
|
this.close();
|
2011-01-06 15:30:15 +00:00
|
|
|
},
|
|
|
|
|
2011-03-21 20:12:30 +00:00
|
|
|
_confirm: function(signal) {
|
2011-01-06 15:30:15 +00:00
|
|
|
this._fadeOutDialog();
|
|
|
|
this._stopTimer();
|
2011-08-16 12:24:39 +00:00
|
|
|
this._dbusImpl.emit_signal(signal, null);
|
2011-01-06 15:30:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onOpened: function() {
|
2013-08-22 18:48:28 +00:00
|
|
|
this._sync();
|
2011-01-06 15:30:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_startTimer: function() {
|
2013-01-26 08:01:41 +00:00
|
|
|
let startTime = GLib.get_monotonic_time();
|
2011-01-06 15:30:15 +00:00
|
|
|
this._secondsLeft = this._totalSecondsToStayOpen;
|
2013-01-26 08:01:41 +00:00
|
|
|
|
|
|
|
this._timerId = Mainloop.timeout_add_seconds(1, Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
let currentTime = GLib.get_monotonic_time();
|
|
|
|
let secondsElapsed = ((currentTime - startTime) / 1000000);
|
|
|
|
|
|
|
|
this._secondsLeft = this._totalSecondsToStayOpen - secondsElapsed;
|
|
|
|
if (this._secondsLeft > 0) {
|
2013-08-22 18:48:28 +00:00
|
|
|
this._sync();
|
2013-01-26 08:01:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let dialogContent = DialogContent[this._type];
|
|
|
|
let button = dialogContent.confirmButtons[dialogContent.confirmButtons.length - 1];
|
|
|
|
this._confirm(button.signal);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}));
|
2011-01-06 15:30:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_stopTimer: function() {
|
2013-08-22 20:17:52 +00:00
|
|
|
if (this._timerId > 0) {
|
2013-01-26 08:01:41 +00:00
|
|
|
Mainloop.source_remove(this._timerId);
|
|
|
|
this._timerId = 0;
|
|
|
|
}
|
|
|
|
|
2011-01-06 15:30:15 +00:00
|
|
|
this._secondsLeft = 0;
|
|
|
|
},
|
|
|
|
|
2013-08-23 16:13:35 +00:00
|
|
|
_constructListItemForApp: function(inhibitor, app) {
|
|
|
|
let actor = new St.BoxLayout({ style_class: 'end-session-dialog-app-list-item',
|
|
|
|
can_focus: true });
|
|
|
|
actor.add(app.create_icon_texture(_ITEM_ICON_SIZE));
|
|
|
|
|
|
|
|
let textLayout = new St.BoxLayout({ vertical: true,
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
|
|
|
actor.add(textLayout);
|
|
|
|
|
|
|
|
let nameLabel = new St.Label({ text: app.get_name(),
|
|
|
|
style_class: 'end-session-dialog-app-list-item-name' });
|
|
|
|
textLayout.add(nameLabel);
|
|
|
|
actor.label_actor = nameLabel;
|
|
|
|
|
|
|
|
let [reason] = inhibitor.GetReasonSync();
|
|
|
|
if (reason) {
|
|
|
|
let reasonLabel = new St.Label({ text: reason,
|
|
|
|
style_class: 'end-session-dialog-app-list-item-description' });
|
|
|
|
textLayout.add(reasonLabel);
|
|
|
|
}
|
|
|
|
|
|
|
|
return actor;
|
|
|
|
},
|
|
|
|
|
2011-01-06 15:30:15 +00:00
|
|
|
_onInhibitorLoaded: function(inhibitor) {
|
2013-08-23 16:13:35 +00:00
|
|
|
if (this._applications.indexOf(inhibitor) < 0) {
|
2011-01-06 15:30:15 +00:00
|
|
|
// Stale inhibitor
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let app = findAppFromInhibitor(inhibitor);
|
|
|
|
|
|
|
|
if (app) {
|
2013-08-23 16:13:35 +00:00
|
|
|
let actor = this._constructListItemForApp(inhibitor, app);
|
|
|
|
this._applicationList.add(actor);
|
2011-01-06 15:30:15 +00:00
|
|
|
} else {
|
|
|
|
// inhibiting app is a service, not an application
|
2013-08-23 16:13:35 +00:00
|
|
|
this._applications.splice(this._applications.indexOf(inhibitor), 1);
|
2011-01-06 15:30:15 +00:00
|
|
|
}
|
|
|
|
|
2013-08-22 18:48:28 +00:00
|
|
|
this._sync();
|
2011-01-06 15:30:15 +00:00
|
|
|
},
|
|
|
|
|
2013-08-23 16:13:35 +00:00
|
|
|
_constructListItemForSession: function(session) {
|
|
|
|
let avatar = new UserWidget.Avatar(session.user, { iconSize: _ITEM_ICON_SIZE });
|
|
|
|
avatar.update();
|
|
|
|
|
|
|
|
let userName = session.user.get_real_name() ? session.user.get_real_name() : session.username;
|
|
|
|
let userLabelText;
|
|
|
|
|
|
|
|
if (session.remote)
|
|
|
|
/* Translators: Remote here refers to a remote session, like a ssh login */
|
|
|
|
userLabelText = _("%s (remote)").format(userName);
|
|
|
|
else if (session.type == "tty")
|
|
|
|
/* Translators: Console here refers to a tty like a VT console */
|
|
|
|
userLabelText = _("%s (console)").format(userName);
|
|
|
|
else
|
|
|
|
userLabelText = userName;
|
|
|
|
|
|
|
|
let actor = new St.BoxLayout({ style_class: 'end-session-dialog-session-list-item',
|
|
|
|
can_focus: true });
|
|
|
|
actor.add(avatar.actor);
|
|
|
|
|
|
|
|
let nameLabel = new St.Label({ text: userLabelText,
|
|
|
|
style_class: 'end-session-dialog-session-list-item-name',
|
|
|
|
y_expand: true,
|
|
|
|
y_align: Clutter.ActorAlign.CENTER });
|
|
|
|
actor.add(nameLabel);
|
|
|
|
actor.label_actor = nameLabel;
|
|
|
|
|
|
|
|
return actor;
|
|
|
|
},
|
|
|
|
|
2013-08-22 18:35:28 +00:00
|
|
|
_loadSessions: function() {
|
|
|
|
this._loginManager.listSessions(Lang.bind(this, function(result) {
|
|
|
|
let n = 0;
|
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
let[id, uid, userName, seat, sessionPath] = result[i];
|
|
|
|
let proxy = new LogindSession(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;
|
|
|
|
|
|
|
|
let session = { user: this._userManager.get_user(userName),
|
|
|
|
username: userName,
|
|
|
|
type: proxy.Type,
|
|
|
|
remote: proxy.Remote };
|
|
|
|
this._sessions.push(session);
|
|
|
|
|
2013-08-23 16:13:35 +00:00
|
|
|
let actor = this._constructListItemForSession(session);
|
|
|
|
this._sessionList.add(actor);
|
2013-08-22 18:35:28 +00:00
|
|
|
|
|
|
|
// limit the number of entries
|
|
|
|
n++;
|
|
|
|
if (n == MAX_USERS_IN_SESSION_DIALOG)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-22 18:48:28 +00:00
|
|
|
this._sync();
|
2013-08-22 18:35:28 +00:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2011-08-16 12:24:39 +00:00
|
|
|
OpenAsync: function(parameters, invocation) {
|
|
|
|
let [type, timestamp, totalSecondsToStayOpen, inhibitorObjectPaths] = parameters;
|
2011-01-06 15:30:15 +00:00
|
|
|
this._totalSecondsToStayOpen = totalSecondsToStayOpen;
|
|
|
|
this._type = type;
|
|
|
|
|
2013-08-23 16:13:35 +00:00
|
|
|
this._applications = [];
|
|
|
|
this._applicationList.destroy_all_children();
|
|
|
|
|
|
|
|
this._sessions = [];
|
|
|
|
this._sessionList.destroy_all_children();
|
|
|
|
|
2011-08-16 12:24:39 +00:00
|
|
|
if (!(this._type in DialogContent)) {
|
2012-02-28 23:45:33 +00:00
|
|
|
invocation.return_dbus_error('org.gnome.Shell.ModalDialog.TypeError',
|
2011-08-16 12:24:39 +00:00
|
|
|
"Unknown dialog type requested");
|
|
|
|
return;
|
|
|
|
}
|
2011-01-06 15:30:15 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < inhibitorObjectPaths.length; i++) {
|
2011-08-16 12:24:39 +00:00
|
|
|
let inhibitor = new GnomeSession.Inhibitor(inhibitorObjectPaths[i], Lang.bind(this, function(proxy, error) {
|
|
|
|
this._onInhibitorLoaded(proxy);
|
|
|
|
}));
|
2011-01-06 15:30:15 +00:00
|
|
|
|
2013-08-23 16:13:35 +00:00
|
|
|
this._applications.push(inhibitor);
|
2011-01-06 15:30:15 +00:00
|
|
|
}
|
|
|
|
|
2013-08-30 11:40:40 +00:00
|
|
|
if (DialogContent[type].showOtherSessions)
|
|
|
|
this._loadSessions();
|
2013-08-22 18:35:28 +00:00
|
|
|
|
2011-04-06 16:54:47 +00:00
|
|
|
this._updateButtons();
|
|
|
|
|
2011-08-16 12:24:39 +00:00
|
|
|
if (!this.open(timestamp)) {
|
2012-02-28 23:45:33 +00:00
|
|
|
invocation.return_dbus_error('org.gnome.Shell.ModalDialog.GrabError',
|
2011-08-16 12:24:39 +00:00
|
|
|
"Cannot grab pointer and keyboard");
|
|
|
|
return;
|
|
|
|
}
|
2011-01-06 15:30:15 +00:00
|
|
|
|
2013-08-23 16:30:30 +00:00
|
|
|
this._startTimer();
|
2013-08-22 18:48:28 +00:00
|
|
|
this._sync();
|
2011-01-06 15:30:15 +00:00
|
|
|
|
|
|
|
let signalId = this.connect('opened',
|
|
|
|
Lang.bind(this, function() {
|
2011-08-16 12:24:39 +00:00
|
|
|
invocation.return_value(null);
|
2011-01-06 15:30:15 +00:00
|
|
|
this.disconnect(signalId);
|
|
|
|
}));
|
2012-12-04 23:32:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Close: function(parameters, invocation) {
|
|
|
|
this.close();
|
2011-01-06 15:30:15 +00:00
|
|
|
}
|
2011-11-20 15:32:59 +00:00
|
|
|
});
|