2011-09-28 13:16:26 +00:00
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/ *
2016-03-15 17:46:40 +00:00
* Copyright 2010 - 2016 Red Hat , Inc
2011-01-06 15:30:15 +00:00
*
* 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
2014-01-07 21:32:37 +00:00
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2011-01-06 15:30:15 +00:00
* /
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 ;
2014-02-19 18:58:50 +00:00
const Polkit = imports . gi . Polkit ;
2011-01-06 15:30:15 +00:00
const St = imports . gi . St ;
const Shell = imports . gi . Shell ;
2014-02-19 18:58:50 +00:00
const CheckBox = imports . ui . checkBox ;
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 ;
2014-02-18 20:41:30 +00:00
const _DIALOG _ICON _SIZE = 48 ;
2011-01-06 15:30:15 +00:00
2017-07-18 17:47:27 +00:00
var GSM _SESSION _MANAGER _LOGOUT _FORCE = 2 ;
2011-01-06 15:30:15 +00:00
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" / > \
< / m e t h o d > \
< method name = "Close" / > \
< signal name = "ConfirmedLogout" / > \
< signal name = "ConfirmedReboot" / > \
< signal name = "ConfirmedShutdown" / > \
< signal name = "Canceled" / > \
< signal name = "Closed" / > \
< / i n t e r f a c e > \
< / n o d e > ' ;
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" ) ,
2017-10-31 00:03:21 +00:00
descriptionWithUser ( 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 ) ;
} ,
2017-10-31 00:03:21 +00:00
description ( 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 ) ;
} ,
2014-02-19 18:59:47 +00:00
showBatteryWarning : false ,
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" ) ,
2014-02-19 18:58:50 +00:00
subjectWithUpdates : C _ ( "title" , "Install Updates & Power Off" ) ,
2017-10-31 00:03:21 +00:00
description ( 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 ) ;
} ,
2014-02-19 18:58:50 +00:00
checkBoxText : C _ ( "checkbox" , "Install pending software updates" ) ,
2014-02-19 18:59:47 +00:00
showBatteryWarning : true ,
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" ) ,
2017-10-31 00:03:21 +00:00
description ( 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 ) ;
} ,
2014-02-19 18:59:47 +00:00
showBatteryWarning : false ,
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
} ;
2016-03-14 22:52:14 +00:00
const restartUpdateDialogContent = {
2013-08-26 04:52:41 +00:00
subject : C _ ( "title" , "Restart & Install Updates" ) ,
2017-10-31 00:03:21 +00:00
description ( seconds ) {
2013-08-26 04:52:41 +00:00
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 ) ;
} ,
2014-02-19 18:59:47 +00:00
showBatteryWarning : true ,
2013-08-26 04:52:41 +00:00
confirmButtons : [ { signal : 'ConfirmedReboot' ,
2014-02-18 21:17:58 +00:00
label : C _ ( "button" , "Restart & Install" ) } ] ,
2014-02-19 22:53:00 +00:00
unusedFutureButtonForTranslation : C _ ( "button" , "Install & Power Off" ) ,
unusedFutureCheckBoxForTranslation : C _ ( "checkbox" , "Power off after updates are installed" ) ,
2013-08-26 04:52:41 +00:00
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
} ;
2016-03-15 17:46:40 +00:00
const restartUpgradeDialogContent = {
subject : C _ ( "title" , "Restart & Install Upgrade" ) ,
2017-10-31 00:03:21 +00:00
upgradeDescription ( distroName , distroVersion ) {
2016-03-15 17:46:40 +00:00
/ * T r a n s l a t o r s : T h i s i s t h e t e x t d i s p l a y e d f o r s y s t e m u p g r a d e s i n t h e
shut down dialog . First % s gets replaced with the distro name and
second % s with the distro version to upgrade to * /
return _ ( "%s %s will be installed after restart. Upgrade installation can take a long time: ensure that you have backed up and that the computer is plugged in." ) . format ( distroName , distroVersion ) ;
} ,
disableTimer : true ,
showBatteryWarning : false ,
confirmButtons : [ { signal : 'ConfirmedReboot' ,
label : C _ ( "button" , "Restart & Install" ) } ] ,
iconName : 'view-refresh-symbolic' ,
iconStyleClass : 'end-session-dialog-shutdown-icon' ,
showOtherSessions : true ,
} ;
2014-09-11 13:55:07 +00:00
const DialogType = {
LOGOUT : 0 /* GSM_SHELL_END_SESSION_DIALOG_TYPE_LOGOUT */ ,
SHUTDOWN : 1 /* GSM_SHELL_END_SESSION_DIALOG_TYPE_SHUTDOWN */ ,
RESTART : 2 /* GSM_SHELL_END_SESSION_DIALOG_TYPE_RESTART */ ,
2016-03-15 17:46:40 +00:00
UPDATE _RESTART : 3 ,
UPGRADE _RESTART : 4
2014-09-11 13:55:07 +00:00
} ;
2011-01-06 15:30:15 +00:00
const DialogContent = {
2014-09-11 16:04:36 +00:00
0 /* DialogType.LOGOUT */ : logoutDialogContent ,
1 /* DialogType.SHUTDOWN */ : shutdownDialogContent ,
2 /* DialogType.RESTART */ : restartDialogContent ,
2016-03-15 17:46:40 +00:00
3 /* DialogType.UPDATE_RESTART */ : restartUpdateDialogContent ,
4 /* DialogType.UPGRADE_RESTART */ : restartUpgradeDialogContent
2011-01-06 15:30:15 +00:00
} ;
2017-07-18 17:47:27 +00:00
var MAX _USERS _IN _SESSION _DIALOG = 5 ;
2013-08-22 18:35:28 +00:00
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" / > \
< / i n t e r f a c e > \
< / n o d e > ' ;
2013-08-22 18:35:28 +00:00
const LogindSession = Gio . DBusProxy . makeProxyWrapper ( LogindSessionIface ) ;
2014-09-09 11:16:25 +00:00
const PkOfflineIface = ' < node > \
< interface name = "org.freedesktop.PackageKit.Offline" > \
< property name = "UpdatePrepared" type = "b" access = "read" / > \
2016-03-14 22:55:03 +00:00
< property name = "UpdateTriggered" type = "b" access = "read" / > \
2016-03-15 17:46:40 +00:00
< property name = "UpgradePrepared" type = "b" access = "read" / > \
< property name = "UpgradeTriggered" type = "b" access = "read" / > \
< property name = "PreparedUpgrade" type = "a{sv}" access = "read" / > \
2014-09-09 11:16:25 +00:00
< method name = "Trigger" > \
< arg type = "s" name = "action" direction = "in" / > \
< / m e t h o d > \
< method name = "Cancel" / > \
< / i n t e r f a c e > \
< / n o d e > ' ;
const PkOfflineProxy = Gio . DBusProxy . makeProxyWrapper ( PkOfflineIface ) ;
2014-02-19 18:59:47 +00:00
const UPowerIface = ' < node > \
< interface name = "org.freedesktop.UPower" > \
< property name = "OnBattery" type = "b" access = "read" / > \
< / i n t e r f a c e > \
< / n o d e > ' ;
const UPowerProxy = Gio . DBusProxy . makeProxyWrapper ( UPowerIface ) ;
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 ( ) ;
}
}
2014-02-19 18:58:50 +00:00
function _setCheckBoxLabel ( checkBox , text ) {
let label = checkBox . getLabelActor ( ) ;
if ( text ) {
label . set _text ( text ) ;
checkBox . actor . show ( ) ;
} else {
label . set _text ( '' ) ;
checkBox . actor . hide ( ) ;
}
}
2011-01-06 15:30:15 +00:00
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
}
2017-07-18 17:41:25 +00:00
var EndSessionDialog = new Lang . Class ( {
2011-11-20 15:32:59 +00:00
Name : 'EndSessionDialog' ,
Extends : ModalDialog . ModalDialog ,
2011-01-06 15:30:15 +00:00
2017-10-31 00:03:21 +00:00
_init ( ) {
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 ( ) ) ;
2011-01-06 15:30:15 +00:00
2014-09-09 11:16:25 +00:00
this . _pkOfflineProxy = new PkOfflineProxy ( Gio . DBus . system ,
'org.freedesktop.PackageKit' ,
'/org/freedesktop/PackageKit' ,
2017-10-31 00:38:18 +00:00
( proxy , error ) => {
2014-09-09 11:16:25 +00:00
if ( error )
log ( error . message ) ;
2017-10-31 00:38:18 +00:00
} ) ;
2014-02-19 18:59:47 +00:00
this . _powerProxy = new UPowerProxy ( Gio . DBus . system ,
'org.freedesktop.UPower' ,
'/org/freedesktop/UPower' ,
2017-10-31 00:38:18 +00:00
( proxy , error ) => {
2014-02-19 18:59:47 +00:00
if ( error ) {
log ( error . message ) ;
return ;
}
this . _powerProxy . connect ( 'g-properties-changed' ,
2017-12-02 00:27:35 +00:00
this . _sync . bind ( this ) ) ;
2014-02-19 18:59:47 +00:00
this . _sync ( ) ;
2017-10-31 00:38:18 +00:00
} ) ;
2014-02-19 18:59:47 +00:00
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' ,
2017-12-02 00:27:35 +00:00
this . _onDestroy . bind ( this ) ) ;
2011-01-06 15:30:15 +00:00
this . connect ( 'opened' ,
2017-12-02 00:27:35 +00:00
this . _onOpened . bind ( this ) ) ;
2011-01-06 15:30:15 +00:00
2017-12-02 00:27:35 +00:00
this . _userLoadedId = this . _user . connect ( 'notify::is_loaded' , this . _sync . bind ( this ) ) ;
this . _userChangedId = this . _user . connect ( 'changed' , this . _sync . bind ( this ) ) ;
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 } ) ;
2014-02-18 20:49:33 +00:00
let messageLayout = new St . BoxLayout ( { vertical : true ,
style _class : 'end-session-dialog-layout' } ) ;
2011-01-06 15:30:15 +00:00
mainContentLayout . add ( messageLayout ,
{ y _align : St . Align . START } ) ;
this . _subjectLabel = new St . Label ( { style _class : 'end-session-dialog-subject' } ) ;
messageLayout . add ( this . _subjectLabel ,
2013-12-11 20:42:01 +00:00
{ x _fill : false ,
y _fill : false ,
x _align : St . Align . START ,
2011-01-06 15:30:15 +00:00
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 } ) ;
2014-02-19 18:58:50 +00:00
this . _checkBox = new CheckBox . CheckBox ( ) ;
2017-12-02 00:27:35 +00:00
this . _checkBox . actor . connect ( 'clicked' , this . _sync . bind ( this ) ) ;
2014-02-19 18:58:50 +00:00
messageLayout . add ( this . _checkBox . actor ) ;
2014-02-19 18:59:47 +00:00
this . _batteryWarning = new St . Label ( { style _class : 'end-session-dialog-warning' ,
text : _ ( "Running on battery power: please plug in before installing updates." ) } ) ;
this . _batteryWarning . clutter _text . ellipsize = Pango . EllipsizeMode . NONE ;
this . _batteryWarning . clutter _text . line _wrap = true ;
messageLayout . add ( this . _batteryWarning ) ;
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." ) } ) ;
2013-10-20 13:03:18 +00:00
this . _applicationList = new St . BoxLayout ( { style _class : 'end-session-dialog-app-list' ,
vertical : true } ) ;
2013-08-23 16:13:35 +00:00
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." ) } ) ;
2013-10-20 13:03:18 +00:00
this . _sessionList = new St . BoxLayout ( { style _class : 'end-session-dialog-session-list' ,
vertical : true } ) ;
2013-08-23 16:13:35 +00:00
this . _inhibitorSection . add _actor ( this . _sessionHeader ) ;
this . _inhibitorSection . add _actor ( this . _sessionList ) ;
2011-08-16 12:24:39 +00:00
2014-02-19 18:58:50 +00:00
try {
this . _updatesPermission = Polkit . Permission . new _sync ( "org.freedesktop.packagekit.trigger-offline-update" , null , null ) ;
} catch ( e ) {
log ( 'No permission to trigger offline updates: %s' . format ( e . toString ( ) ) ) ;
}
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
} ,
2017-10-31 00:03:21 +00:00
_onDestroy ( ) {
2011-01-06 15:30:15 +00:00
this . _user . disconnect ( this . _userLoadedId ) ;
this . _user . disconnect ( this . _userChangedId ) ;
} ,
2017-10-31 00:03:21 +00:00
_sync ( ) {
2013-08-22 18:48:28 +00:00
let open = ( this . state == ModalDialog . State . OPENING || this . state == ModalDialog . State . OPENED ) ;
if ( ! open )
2011-01-06 15:30:15 +00:00
return ;
let dialogContent = DialogContent [ this . _type ] ;
let subject = dialogContent . subject ;
2014-02-19 18:58:50 +00:00
// Use different title when we are installing updates
if ( dialogContent . subjectWithUpdates && this . _checkBox . actor . checked )
subject = dialogContent . subjectWithUpdates ;
2014-02-19 18:59:47 +00:00
if ( dialogContent . showBatteryWarning ) {
// Warn when running on battery power
if ( this . _powerProxy . OnBattery && this . _checkBox . actor . checked )
this . _batteryWarning . opacity = 255 ;
else
this . _batteryWarning . opacity = 0 ;
}
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 ) ;
}
2011-01-06 15:30:15 +00:00
}
2016-03-15 17:46:40 +00:00
// Use a different description when we are installing a system upgrade
if ( dialogContent . upgradeDescription ) {
let name = this . _pkOfflineProxy . PreparedUpgrade [ 'name' ] . deep _unpack ( ) ;
let version = this . _pkOfflineProxy . PreparedUpgrade [ 'version' ] . deep _unpack ( ) ;
if ( name != null && version != null )
description = dialogContent . upgradeDescription ( name , version ) ;
}
// Fall back to regular description
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
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
} ,
2017-10-31 00:03:21 +00:00
_updateButtons ( ) {
2011-01-06 15:30:15 +00:00
let dialogContent = DialogContent [ this . _type ] ;
2017-12-02 00:27:35 +00:00
let buttons = [ { action : this . cancel . bind ( this ) ,
2011-03-21 20:12:30 +00:00
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 ;
2017-10-31 00:38:18 +00:00
buttons . push ( { action : ( ) => {
this . close ( true ) ;
let signalId = this . connect ( 'closed' , ( ) => {
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
} ,
2017-10-31 00:03:21 +00:00
close ( 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
} ,
2017-10-31 00:03:21 +00:00
cancel ( ) {
2011-01-06 15:30:15 +00:00
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
} ,
2017-10-31 00:03:21 +00:00
_confirm ( signal ) {
2017-10-31 00:38:18 +00:00
let callback = ( ) => {
2014-02-19 18:58:50 +00:00
this . _fadeOutDialog ( ) ;
this . _stopTimer ( ) ;
this . _dbusImpl . emit _signal ( signal , null ) ;
2017-10-31 00:38:18 +00:00
} ;
2014-02-19 18:58:50 +00:00
// Offline update not available; just emit the signal
if ( ! this . _checkBox . actor . visible ) {
callback ( ) ;
return ;
}
// Trigger the offline update as requested
if ( this . _checkBox . actor . checked ) {
switch ( signal ) {
case "ConfirmedReboot" :
this . _triggerOfflineUpdateReboot ( callback ) ;
break ;
case "ConfirmedShutdown" :
// To actually trigger the offline update, we need to
// reboot to do the upgrade. When the upgrade is complete,
// the computer will shut down automatically.
signal = "ConfirmedReboot" ;
this . _triggerOfflineUpdateShutdown ( callback ) ;
break ;
default :
callback ( ) ;
break ;
}
} else {
this . _triggerOfflineUpdateCancel ( callback ) ;
}
2011-01-06 15:30:15 +00:00
} ,
2017-10-31 00:03:21 +00:00
_onOpened ( ) {
2013-08-22 18:48:28 +00:00
this . _sync ( ) ;
2011-01-06 15:30:15 +00:00
} ,
2017-10-31 00:03:21 +00:00
_triggerOfflineUpdateReboot ( callback ) {
2017-10-31 00:38:18 +00:00
this . _pkOfflineProxy . TriggerRemote ( 'reboot' , ( result , error ) => {
2014-09-09 11:16:25 +00:00
if ( error )
log ( error . message ) ;
2014-02-19 18:58:50 +00:00
2014-09-09 11:16:25 +00:00
callback ( ) ;
} ) ;
2014-02-19 18:58:50 +00:00
} ,
2017-10-31 00:03:21 +00:00
_triggerOfflineUpdateShutdown ( callback ) {
2017-10-31 00:38:18 +00:00
this . _pkOfflineProxy . TriggerRemote ( 'power-off' , ( result , error ) => {
2014-09-09 11:16:25 +00:00
if ( error )
log ( error . message ) ;
2014-02-19 18:58:50 +00:00
callback ( ) ;
2014-09-09 11:16:25 +00:00
} ) ;
} ,
2014-02-19 18:58:50 +00:00
2017-10-31 00:03:21 +00:00
_triggerOfflineUpdateCancel ( callback ) {
2017-10-31 00:38:18 +00:00
this . _pkOfflineProxy . CancelRemote ( ( result , error ) => {
2014-09-09 11:16:25 +00:00
if ( error )
log ( error . message ) ;
2014-02-19 18:58:50 +00:00
callback ( ) ;
} ) ;
} ,
2017-10-31 00:03:21 +00:00
_startTimer ( ) {
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
2017-10-31 00:38:18 +00:00
this . _timerId = Mainloop . timeout _add _seconds ( 1 , ( ) => {
let currentTime = GLib . get _monotonic _time ( ) ;
let secondsElapsed = ( ( currentTime - startTime ) / 1000000 ) ;
2013-01-26 08:01:41 +00:00
2017-10-31 00:38:18 +00:00
this . _secondsLeft = this . _totalSecondsToStayOpen - secondsElapsed ;
if ( this . _secondsLeft > 0 ) {
this . _sync ( ) ;
return GLib . SOURCE _CONTINUE ;
}
2013-01-26 08:01:41 +00:00
2017-10-31 00:38:18 +00:00
let dialogContent = DialogContent [ this . _type ] ;
let button = dialogContent . confirmButtons [ dialogContent . confirmButtons . length - 1 ] ;
this . _confirm ( button . signal ) ;
this . _timerId = 0 ;
2013-01-26 08:01:41 +00:00
2017-10-31 00:38:18 +00:00
return GLib . SOURCE _REMOVE ;
} ) ;
2014-04-10 17:26:52 +00:00
GLib . Source . set _name _by _id ( this . _timerId , '[gnome-shell] this._confirm' ) ;
2011-01-06 15:30:15 +00:00
} ,
2017-10-31 00:03:21 +00:00
_stopTimer ( ) {
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 ;
} ,
2017-10-31 00:03:21 +00:00
_constructListItemForApp ( inhibitor , app ) {
2013-08-23 16:13:35 +00:00
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 ;
} ,
2017-10-31 00:03:21 +00:00
_onInhibitorLoaded ( 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
} ,
2017-10-31 00:03:21 +00:00
_constructListItemForSession ( session ) {
2013-08-23 16:13:35 +00:00
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 ;
} ,
2017-10-31 00:03:21 +00:00
_loadSessions ( ) {
2017-10-31 00:38:18 +00:00
this . _loginManager . listSessions ( result => {
2013-08-22 18:35:28 +00:00
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 ;
2018-01-08 14:23:52 +00:00
let sessionId = GLib . getenv ( 'XDG_SESSION_ID' ) ;
if ( ! sessionId )
this . _loginManager . getCurrentSessionProxy ( currentSessionProxy => {
sessionId = currentSessionProxy . Id ;
log ( ` endSessionDialog: No XDG_SESSION_ID, fetched from logind: ${ sessionId } ` ) ;
} ) ;
if ( proxy . Id == sessionId )
2013-08-22 18:35:28 +00:00
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 ( ) ;
2017-10-31 00:38:18 +00:00
} ) ;
2013-08-22 18:35:28 +00:00
} ,
2017-10-31 00:03:21 +00:00
OpenAsync ( parameters , invocation ) {
2011-08-16 12:24:39 +00:00
let [ type , timestamp , totalSecondsToStayOpen , inhibitorObjectPaths ] = parameters ;
2011-01-06 15:30:15 +00:00
this . _totalSecondsToStayOpen = totalSecondsToStayOpen ;
this . _type = type ;
2016-03-15 17:46:40 +00:00
if ( this . _type == DialogType . RESTART ) {
if ( this . _pkOfflineProxy . UpdateTriggered )
this . _type = DialogType . UPDATE _RESTART ;
else if ( this . _pkOfflineProxy . UpgradeTriggered )
this . _type = DialogType . UPGRADE _RESTART ;
}
2014-02-18 21:17:58 +00:00
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
2014-02-19 18:58:50 +00:00
let dialogContent = DialogContent [ this . _type ] ;
2011-01-06 15:30:15 +00:00
for ( let i = 0 ; i < inhibitorObjectPaths . length ; i ++ ) {
2017-10-31 00:38:18 +00:00
let inhibitor = new GnomeSession . Inhibitor ( inhibitorObjectPaths [ i ] , ( proxy , error ) => {
2011-08-16 12:24:39 +00:00
this . _onInhibitorLoaded ( proxy ) ;
2017-10-31 00:38:18 +00:00
} ) ;
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
}
2014-02-19 18:58:50 +00:00
if ( dialogContent . showOtherSessions )
2013-08-30 11:40:40 +00:00
this . _loadSessions ( ) ;
2013-08-22 18:35:28 +00:00
2016-03-14 22:55:03 +00:00
let updateTriggered = this . _pkOfflineProxy . UpdateTriggered ;
2014-09-09 11:16:25 +00:00
let updatePrepared = this . _pkOfflineProxy . UpdatePrepared ;
2014-02-19 18:58:50 +00:00
let updatesAllowed = this . _updatesPermission && this . _updatesPermission . allowed ;
_setCheckBoxLabel ( this . _checkBox , dialogContent . checkBoxText ) ;
2014-09-09 11:16:25 +00:00
this . _checkBox . actor . visible = ( dialogContent . checkBoxText && updatePrepared && updatesAllowed ) ;
2016-03-14 22:55:03 +00:00
this . _checkBox . actor . checked = ( updatePrepared && updateTriggered ) ;
2014-02-19 18:58:50 +00:00
2014-02-19 18:59:47 +00:00
// We show the warning either together with the checkbox, or when
// updates have already been triggered, but the user doesn't have
// enough permissions to cancel them.
this . _batteryWarning . visible = ( dialogContent . showBatteryWarning &&
2016-03-14 22:55:03 +00:00
( this . _checkBox . actor . visible || updatePrepared && updateTriggered && ! updatesAllowed ) ) ;
2014-02-19 18:59:47 +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
2016-03-15 17:46:40 +00:00
if ( ! dialogContent . disableTimer )
this . _startTimer ( ) ;
2013-08-22 18:48:28 +00:00
this . _sync ( ) ;
2011-01-06 15:30:15 +00:00
2017-10-31 00:38:18 +00:00
let signalId = this . connect ( 'opened' , ( ) => {
invocation . return _value ( null ) ;
this . disconnect ( signalId ) ;
} ) ;
2012-12-04 23:32:59 +00:00
} ,
2017-10-31 00:03:21 +00:00
Close ( parameters , invocation ) {
2012-12-04 23:32:59 +00:00
this . close ( ) ;
2011-01-06 15:30:15 +00:00
}
2011-11-20 15:32:59 +00:00
} ) ;