Changeset View
Changeset View
Standalone View
Standalone View
ksmserver/logout.cpp
- This file was copied from ksmserver/shutdown.cpp.
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | |||||
72 | #include <KUserTimestamp> | 72 | #include <KUserTimestamp> | ||
73 | #include <KNotification> | 73 | #include <KNotification> | ||
74 | #include <kdisplaymanager.h> | 74 | #include <kdisplaymanager.h> | ||
75 | #include "server.h" | 75 | #include "server.h" | ||
76 | #include "global.h" | 76 | #include "global.h" | ||
77 | #include "client.h" | 77 | #include "client.h" | ||
78 | 78 | | |||
79 | #include <solid/powermanagement.h> | 79 | #include <solid/powermanagement.h> | ||
80 | | ||||
80 | #include "logoutprompt_interface.h" | 81 | #include "logoutprompt_interface.h" | ||
82 | #include "shutdown_interface.h" | ||||
81 | 83 | | |||
82 | #include <QDesktopWidget> | 84 | #include <QDesktopWidget> | ||
83 | #include <QX11Info> | 85 | #include <QX11Info> | ||
84 | #include <X11/Xutil.h> | 86 | #include <X11/Xutil.h> | ||
85 | #include <X11/Xatom.h> | 87 | #include <X11/Xatom.h> | ||
86 | 88 | | |||
87 | void KSMServer::logout( int confirm, int sdtype, int sdmode ) | 89 | void KSMServer::logout( int confirm, int sdtype, int sdmode ) | ||
88 | { | 90 | { | ||
Show All 15 Lines | 101 | { | |||
104 | return cg.readEntry( "offerShutdown", true ) && KDisplayManager().canShutdown(); | 106 | return cg.readEntry( "offerShutdown", true ) && KDisplayManager().canShutdown(); | ||
105 | } | 107 | } | ||
106 | 108 | | |||
107 | bool KSMServer::isShuttingDown() const | 109 | bool KSMServer::isShuttingDown() const | ||
108 | { | 110 | { | ||
109 | return state >= Shutdown; | 111 | return state >= Shutdown; | ||
110 | } | 112 | } | ||
111 | 113 | | |||
114 | //this method exists purely for compatibility | ||||
112 | void KSMServer::shutdown( KWorkSpace::ShutdownConfirm confirm, | 115 | void KSMServer::shutdown( KWorkSpace::ShutdownConfirm confirm, | ||
113 | KWorkSpace::ShutdownType sdtype, KWorkSpace::ShutdownMode sdmode ) | 116 | KWorkSpace::ShutdownType sdtype, KWorkSpace::ShutdownMode sdmode ) | ||
114 | { | 117 | { | ||
115 | qCDebug(KSMSERVER) << "Shutdown called with confirm " << confirm | 118 | qCDebug(KSMSERVER) << "Shutdown called with confirm " << confirm | ||
116 | << " type " << sdtype << " and mode " << sdmode; | 119 | << " type " << sdtype << " and mode " << sdmode; | ||
117 | pendingShutdown.stop(); | | |||
118 | if( state >= Shutdown ) // already performing shutdown | 120 | if( state >= Shutdown ) // already performing shutdown | ||
119 | return; | 121 | return; | ||
120 | if( state != Idle ) // performing startup | 122 | if( state != Idle ) // performing startup | ||
121 | { | 123 | { | ||
122 | // perform shutdown as soon as startup is finished, in order to avoid saving partial session | | |||
123 | if( !pendingShutdown.isActive()) | | |||
124 | { | | |||
125 | pendingShutdown.start( 1000 ); | | |||
126 | pendingShutdown_confirm = confirm; | | |||
127 | pendingShutdown_sdtype = sdtype; | | |||
128 | pendingShutdown_sdmode = sdmode; | | |||
129 | } | | |||
130 | return; | 124 | return; | ||
131 | } | 125 | } | ||
132 | 126 | | |||
133 | KSharedConfig::Ptr config = KSharedConfig::openConfig(); | 127 | KSharedConfig::Ptr config = KSharedConfig::openConfig(); | ||
134 | config->reparseConfiguration(); // config may have changed in the KControl module | 128 | config->reparseConfiguration(); // config may have changed in the KControl module | ||
135 | 129 | | |||
136 | KConfigGroup cg( config, "General"); | 130 | KConfigGroup cg( config, "General"); | ||
137 | 131 | | |||
Show All 15 Lines | 145 | case KWorkSpace::ShutdownTypeReboot: | |||
153 | break; | 147 | break; | ||
154 | case KWorkSpace::ShutdownTypeNone: | 148 | case KWorkSpace::ShutdownTypeNone: | ||
155 | Q_FALLTHROUGH(); | 149 | Q_FALLTHROUGH(); | ||
156 | default: | 150 | default: | ||
157 | logoutPrompt.promptLogout(); | 151 | logoutPrompt.promptLogout(); | ||
158 | break; | 152 | break; | ||
159 | } | 153 | } | ||
160 | } else { | 154 | } else { | ||
161 | shutdownType = sdtype; | 155 | OrgKdeShutdownInterface shutdownIface(QStringLiteral("org.kde.Shutdown"), | ||
162 | shutdownMode = sdmode; | 156 | QStringLiteral("/Shutdown"), | ||
163 | performLogout(); | 157 | QDBusConnection::sessionBus()); | ||
158 | switch (sdtype) { | ||||
159 | case KWorkSpace::ShutdownTypeHalt: | ||||
160 | shutdownIface.logoutAndShutdown(); | ||||
161 | break; | ||||
162 | case KWorkSpace::ShutdownTypeReboot: | ||||
163 | shutdownIface.logoutAndReboot(); | ||||
164 | break; | ||||
165 | case KWorkSpace::ShutdownTypeNone: | ||||
166 | Q_FALLTHROUGH(); | ||||
167 | default: | ||||
168 | shutdownIface.logout(); | ||||
169 | break; | ||||
170 | } | ||||
164 | } | 171 | } | ||
165 | } | 172 | } | ||
166 | 173 | | |||
167 | void KSMServer::performLogout() | 174 | void KSMServer::performLogout() | ||
168 | { | 175 | { | ||
176 | if( state >= Shutdown ) { // already performing shutdown | ||||
177 | return; | ||||
178 | } | ||||
179 | if (state != Idle) { | ||||
180 | QTimer::singleShot(1000, this, &KSMServer::performLogout); | ||||
181 | } | ||||
182 | state = Shutdown; | ||||
183 | | ||||
169 | // If the logout was confirmed, let's start a powermanagement inhibition. | 184 | // If the logout was confirmed, let's start a powermanagement inhibition. | ||
170 | // We store the cookie so we can interrupt it if the logout will be canceled | 185 | // We store the cookie so we can interrupt it if the logout will be canceled | ||
171 | inhibitCookie = Solid::PowerManagement::beginSuppressingSleep(QStringLiteral("Shutting down system")); | 186 | inhibitCookie = Solid::PowerManagement::beginSuppressingSleep(QStringLiteral("Shutting down system")); | ||
172 | 187 | | |||
173 | // shall we save the session on logout? | 188 | // shall we save the session on logout? | ||
174 | KConfigGroup cg(KSharedConfig::openConfig(), "General"); | 189 | KConfigGroup cg(KSharedConfig::openConfig(), "General"); | ||
175 | saveSession = ( cg.readEntry( "loginMode", | 190 | saveSession = ( cg.readEntry( "loginMode", | ||
176 | QStringLiteral( "restorePreviousLogout" ) ) | 191 | QStringLiteral( "restorePreviousLogout" ) ) | ||
177 | == QStringLiteral( "restorePreviousLogout" ) ); | 192 | == QStringLiteral( "restorePreviousLogout" ) ); | ||
178 | 193 | | |||
179 | qCDebug(KSMSERVER) << "saveSession is " << saveSession; | 194 | qCDebug(KSMSERVER) << "saveSession is " << saveSession; | ||
180 | 195 | | |||
181 | if ( saveSession ) | 196 | if ( saveSession ) | ||
182 | sessionGroup = QStringLiteral( "Session: " ) + QString::fromLocal8Bit( SESSION_PREVIOUS_LOGOUT ); | 197 | sessionGroup = QStringLiteral( "Session: " ) + QString::fromLocal8Bit( SESSION_PREVIOUS_LOGOUT ); | ||
183 | 198 | | |||
184 | // Set the real desktop background to black so that exit looks | 199 | // Set the real desktop background to black so that exit looks | ||
185 | // clean regardless of what was on "our" desktop. | 200 | // clean regardless of what was on "our" desktop. | ||
186 | QPalette palette; | 201 | QPalette palette; | ||
187 | palette.setColor( QApplication::desktop()->backgroundRole(), Qt::black ); | 202 | palette.setColor( QApplication::desktop()->backgroundRole(), Qt::black ); | ||
188 | QApplication::setPalette(palette); | 203 | QApplication::setPalette(palette); | ||
189 | state = Shutdown; | | |||
190 | wmPhase1WaitingCount = 0; | 204 | wmPhase1WaitingCount = 0; | ||
191 | saveType = saveSession?SmSaveBoth:SmSaveGlobal; | 205 | saveType = saveSession?SmSaveBoth:SmSaveGlobal; | ||
192 | #ifndef NO_LEGACY_SESSION_MANAGEMENT | 206 | #ifndef NO_LEGACY_SESSION_MANAGEMENT | ||
193 | performLegacySessionSave(); | 207 | performLegacySessionSave(); | ||
194 | #endif | 208 | #endif | ||
195 | startProtection(); | 209 | startProtection(); | ||
196 | foreach( KSMClient* c, clients ) { | 210 | foreach( KSMClient* c, clients ) { | ||
197 | c->resetState(); | 211 | c->resetState(); | ||
Show All 25 Lines | 236 | foreach( KSMClient* c, clients ) | |||
223 | SmsSaveYourself( c->connection(), saveType, | 237 | SmsSaveYourself( c->connection(), saveType, | ||
224 | true, SmInteractStyleAny, false ); | 238 | true, SmInteractStyleAny, false ); | ||
225 | } | 239 | } | ||
226 | qCDebug(KSMSERVER) << "clients should be empty, " << clients.isEmpty(); | 240 | qCDebug(KSMSERVER) << "clients should be empty, " << clients.isEmpty(); | ||
227 | if ( clients.isEmpty() ) | 241 | if ( clients.isEmpty() ) | ||
228 | completeShutdownOrCheckpoint(); | 242 | completeShutdownOrCheckpoint(); | ||
229 | } | 243 | } | ||
230 | 244 | | |||
231 | void KSMServer::pendingShutdownTimeout() | | |||
232 | { | | |||
233 | shutdown( pendingShutdown_confirm, pendingShutdown_sdtype, pendingShutdown_sdmode ); | | |||
234 | } | | |||
235 | | ||||
236 | void KSMServer::saveCurrentSession() | 245 | void KSMServer::saveCurrentSession() | ||
237 | { | 246 | { | ||
238 | if ( state != Idle ) | 247 | if ( state != Idle ) | ||
239 | return; | 248 | return; | ||
240 | 249 | | |||
241 | if ( currentSession().isEmpty() || currentSession() == QString::fromLocal8Bit( SESSION_PREVIOUS_LOGOUT ) ) | 250 | if ( currentSession().isEmpty() || currentSession() == QString::fromLocal8Bit( SESSION_PREVIOUS_LOGOUT ) ) | ||
242 | sessionGroup = QStringLiteral("Session: ") + QString::fromLocal8Bit( SESSION_BY_USER ); | 251 | sessionGroup = QStringLiteral("Session: ") + QString::fromLocal8Bit( SESSION_BY_USER ); | ||
243 | 252 | | |||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Line(s) | 400 | if( c->saveYourselfDone ) { | |||
392 | // Discard also saved state. | 401 | // Discard also saved state. | ||
393 | QStringList discard = c->discardCommand(); | 402 | QStringList discard = c->discardCommand(); | ||
394 | if( !discard.isEmpty()) | 403 | if( !discard.isEmpty()) | ||
395 | executeCommand( discard ); | 404 | executeCommand( discard ); | ||
396 | } | 405 | } | ||
397 | } | 406 | } | ||
398 | } | 407 | } | ||
399 | state = Idle; | 408 | state = Idle; | ||
409 | emit logoutCancelled(); | ||||
400 | } | 410 | } | ||
401 | 411 | | |||
402 | void KSMServer::startProtection() | 412 | void KSMServer::startProtection() | ||
403 | { | 413 | { | ||
404 | KSharedConfig::Ptr config = KSharedConfig::openConfig(); | 414 | KSharedConfig::Ptr config = KSharedConfig::openConfig(); | ||
405 | config->reparseConfiguration(); // config may have changed in the KControl module | 415 | config->reparseConfiguration(); // config may have changed in the KControl module | ||
406 | KConfigGroup cg( config, "General" ); | 416 | KConfigGroup cg( config, "General" ); | ||
407 | 417 | | |||
▲ Show 20 Lines • Show All 286 Lines • Show Last 20 Lines |