| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/plugins/platforms/xcb/qxcbsessionmanager.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2013 Teo Mrnjavac <teo@kde.org> | - | ||||||||||||
| 4 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
| 5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 6 | ** | - | ||||||||||||
| 7 | ** This file is part of the plugins of the Qt Toolkit. | - | ||||||||||||
| 8 | ** | - | ||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 10 | ** Commercial License Usage | - | ||||||||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
| 17 | ** | - | ||||||||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 20 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 22 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 25 | ** | - | ||||||||||||
| 26 | ** GNU General Public License Usage | - | ||||||||||||
| 27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 36 | ** | - | ||||||||||||
| 37 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 38 | ** | - | ||||||||||||
| 39 | ****************************************************************************/ | - | ||||||||||||
| 40 | - | |||||||||||||
| 41 | #include "qxcbsessionmanager.h" | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | #include <qguiapplication.h> | - | ||||||||||||
| 44 | #include <qdatetime.h> | - | ||||||||||||
| 45 | #include <qfileinfo.h> | - | ||||||||||||
| 46 | #include <qplatformdefs.h> | - | ||||||||||||
| 47 | #include <qsocketnotifier.h> | - | ||||||||||||
| 48 | #include <X11/SM/SMlib.h> | - | ||||||||||||
| 49 | #include <errno.h> // ERANGE | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | #include <cerrno> // ERANGE | - | ||||||||||||
| 52 | - | |||||||||||||
| 53 | class QSmSocketReceiver : public QObject | - | ||||||||||||
| 54 | { | - | ||||||||||||
| 55 | Q_OBJECT | - | ||||||||||||
| 56 | public: | - | ||||||||||||
| 57 | QSmSocketReceiver(int socket) | - | ||||||||||||
| 58 | { | - | ||||||||||||
| 59 | QSocketNotifier* sn = new QSocketNotifier(socket, QSocketNotifier::Read, this); | - | ||||||||||||
| 60 | connect(sn, SIGNAL(activated(int)), this, SLOT(socketActivated(int))); | - | ||||||||||||
| 61 | } never executed: end of block | 0 | ||||||||||||
| 62 | - | |||||||||||||
| 63 | public Q_SLOTS: | - | ||||||||||||
| 64 | void socketActivated(int); | - | ||||||||||||
| 65 | }; | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | - | |||||||||||||
| 68 | static SmcConn smcConnection = 0; | - | ||||||||||||
| 69 | static bool sm_interactionActive; | - | ||||||||||||
| 70 | static bool sm_smActive; | - | ||||||||||||
| 71 | static int sm_interactStyle; | - | ||||||||||||
| 72 | static int sm_saveType; | - | ||||||||||||
| 73 | static bool sm_cancel; | - | ||||||||||||
| 74 | static bool sm_waitingForInteraction; | - | ||||||||||||
| 75 | static bool sm_isshutdown; | - | ||||||||||||
| 76 | static bool sm_phase2; | - | ||||||||||||
| 77 | static bool sm_in_phase2; | - | ||||||||||||
| 78 | bool qt_sm_blockUserInput = false; | - | ||||||||||||
| 79 | - | |||||||||||||
| 80 | static QSmSocketReceiver* sm_receiver = 0; | - | ||||||||||||
| 81 | - | |||||||||||||
| 82 | static void resetSmState(); | - | ||||||||||||
| 83 | static void sm_setProperty(const char *name, const char *type, | - | ||||||||||||
| 84 | int num_vals, SmPropValue *vals); | - | ||||||||||||
| 85 | static void sm_saveYourselfCallback(SmcConn smcConn, SmPointer clientData, | - | ||||||||||||
| 86 | int saveType, Bool shutdown , int interactStyle, Bool fast); | - | ||||||||||||
| 87 | static void sm_saveYourselfPhase2Callback(SmcConn smcConn, SmPointer clientData) ; | - | ||||||||||||
| 88 | static void sm_dieCallback(SmcConn smcConn, SmPointer clientData) ; | - | ||||||||||||
| 89 | static void sm_shutdownCancelledCallback(SmcConn smcConn, SmPointer clientData); | - | ||||||||||||
| 90 | static void sm_saveCompleteCallback(SmcConn smcConn, SmPointer clientData); | - | ||||||||||||
| 91 | static void sm_interactCallback(SmcConn smcConn, SmPointer clientData); | - | ||||||||||||
| 92 | static void sm_performSaveYourself(QXcbSessionManager*); | - | ||||||||||||
| 93 | - | |||||||||||||
| 94 | static void resetSmState() | - | ||||||||||||
| 95 | { | - | ||||||||||||
| 96 | sm_waitingForInteraction = false; | - | ||||||||||||
| 97 | sm_interactionActive = false; | - | ||||||||||||
| 98 | sm_interactStyle = SmInteractStyleNone; | - | ||||||||||||
| 99 | sm_smActive = false; | - | ||||||||||||
| 100 | qt_sm_blockUserInput = false; | - | ||||||||||||
| 101 | sm_isshutdown = false; | - | ||||||||||||
| 102 | sm_phase2 = false; | - | ||||||||||||
| 103 | sm_in_phase2 = false; | - | ||||||||||||
| 104 | } executed 135 times by 5 tests: end of blockExecuted by:
| 135 | ||||||||||||
| 105 | - | |||||||||||||
| 106 | - | |||||||||||||
| 107 | // theoretically it's possible to set several properties at once. For | - | ||||||||||||
| 108 | // simplicity, however, we do just one property at a time | - | ||||||||||||
| 109 | static void sm_setProperty(const char *name, const char *type, | - | ||||||||||||
| 110 | int num_vals, SmPropValue *vals) | - | ||||||||||||
| 111 | { | - | ||||||||||||
| 112 | if (num_vals) {
| 0 | ||||||||||||
| 113 | SmProp prop; | - | ||||||||||||
| 114 | prop.name = const_cast<char*>(name); | - | ||||||||||||
| 115 | prop.type = const_cast<char*>(type); | - | ||||||||||||
| 116 | prop.num_vals = num_vals; | - | ||||||||||||
| 117 | prop.vals = vals; | - | ||||||||||||
| 118 | - | |||||||||||||
| 119 | SmProp* props[1]; | - | ||||||||||||
| 120 | props[0] = ∝ | - | ||||||||||||
| 121 | SmcSetProperties(smcConnection, 1, props); | - | ||||||||||||
| 122 | } else { never executed: end of block | 0 | ||||||||||||
| 123 | char* names[1]; | - | ||||||||||||
| 124 | names[0] = const_cast<char*>(name); | - | ||||||||||||
| 125 | SmcDeleteProperties(smcConnection, 1, names); | - | ||||||||||||
| 126 | } never executed: end of block | 0 | ||||||||||||
| 127 | } | - | ||||||||||||
| 128 | - | |||||||||||||
| 129 | static void sm_setProperty(const QString &name, const QString &value) | - | ||||||||||||
| 130 | { | - | ||||||||||||
| 131 | QByteArray v = value.toUtf8(); | - | ||||||||||||
| 132 | SmPropValue prop; | - | ||||||||||||
| 133 | prop.length = v.length(); | - | ||||||||||||
| 134 | prop.value = (SmPointer) const_cast<char *>(v.constData()); | - | ||||||||||||
| 135 | sm_setProperty(name.toLatin1().data(), SmARRAY8, 1, &prop); | - | ||||||||||||
| 136 | } never executed: end of block | 0 | ||||||||||||
| 137 | - | |||||||||||||
| 138 | static void sm_setProperty(const QString &name, const QStringList &value) | - | ||||||||||||
| 139 | { | - | ||||||||||||
| 140 | SmPropValue *prop = new SmPropValue[value.count()]; | - | ||||||||||||
| 141 | int count = 0; | - | ||||||||||||
| 142 | QList<QByteArray> vl; | - | ||||||||||||
| 143 | vl.reserve(value.size()); | - | ||||||||||||
| 144 | for (QStringList::ConstIterator it = value.begin(); it != value.end(); ++it) {
| 0 | ||||||||||||
| 145 | prop[count].length = (*it).length(); | - | ||||||||||||
| 146 | vl.append((*it).toUtf8()); | - | ||||||||||||
| 147 | prop[count].value = (char*)vl.last().data(); | - | ||||||||||||
| 148 | ++count; | - | ||||||||||||
| 149 | } never executed: end of block | 0 | ||||||||||||
| 150 | sm_setProperty(name.toLatin1().data(), SmLISTofARRAY8, count, prop); | - | ||||||||||||
| 151 | delete [] prop; | - | ||||||||||||
| 152 | } never executed: end of block | 0 | ||||||||||||
| 153 | - | |||||||||||||
| 154 | - | |||||||||||||
| 155 | // workaround for broken libsm, see below | - | ||||||||||||
| 156 | struct QT_smcConn { | - | ||||||||||||
| 157 | unsigned int save_yourself_in_progress : 1; | - | ||||||||||||
| 158 | unsigned int shutdown_in_progress : 1; | - | ||||||||||||
| 159 | }; | - | ||||||||||||
| 160 | - | |||||||||||||
| 161 | static void sm_saveYourselfCallback(SmcConn smcConn, SmPointer clientData, | - | ||||||||||||
| 162 | int saveType, Bool shutdown , int interactStyle, Bool /*fast*/) | - | ||||||||||||
| 163 | { | - | ||||||||||||
| 164 | if (smcConn != smcConnection)
| 0 | ||||||||||||
| 165 | return; never executed: return; | 0 | ||||||||||||
| 166 | sm_cancel = false; | - | ||||||||||||
| 167 | sm_smActive = true; | - | ||||||||||||
| 168 | sm_isshutdown = shutdown; | - | ||||||||||||
| 169 | sm_saveType = saveType; | - | ||||||||||||
| 170 | sm_interactStyle = interactStyle; | - | ||||||||||||
| 171 | - | |||||||||||||
| 172 | // ugly workaround for broken libSM. libSM should do that _before_ | - | ||||||||||||
| 173 | // actually invoking the callback in sm_process.c | - | ||||||||||||
| 174 | ((QT_smcConn*)smcConn)->save_yourself_in_progress = true; | - | ||||||||||||
| 175 | if (sm_isshutdown)
| 0 | ||||||||||||
| 176 | ((QT_smcConn*)smcConn)->shutdown_in_progress = true; never executed: ((QT_smcConn*)smcConn)->shutdown_in_progress = true; | 0 | ||||||||||||
| 177 | - | |||||||||||||
| 178 | sm_performSaveYourself((QXcbSessionManager*) clientData); | - | ||||||||||||
| 179 | if (!sm_isshutdown) // we cannot expect a confirmation message in that case
| 0 | ||||||||||||
| 180 | resetSmState(); never executed: resetSmState(); | 0 | ||||||||||||
| 181 | } never executed: end of block | 0 | ||||||||||||
| 182 | - | |||||||||||||
| 183 | static void sm_performSaveYourself(QXcbSessionManager *sm) | - | ||||||||||||
| 184 | { | - | ||||||||||||
| 185 | if (sm_isshutdown)
| 0 | ||||||||||||
| 186 | qt_sm_blockUserInput = true; never executed: qt_sm_blockUserInput = true; | 0 | ||||||||||||
| 187 | - | |||||||||||||
| 188 | // generate a new session key | - | ||||||||||||
| 189 | timeval tv; | - | ||||||||||||
| 190 | gettimeofday(&tv, 0); | - | ||||||||||||
| 191 | sm->setSessionKey(QString::number(qulonglong(tv.tv_sec)) + | - | ||||||||||||
| 192 | QLatin1Char('_') + | - | ||||||||||||
| 193 | QString::number(qulonglong(tv.tv_usec))); | - | ||||||||||||
| 194 | - | |||||||||||||
| 195 | QStringList arguments = QCoreApplication::arguments(); | - | ||||||||||||
| 196 | QString argument0 = arguments.isEmpty() ? QCoreApplication::applicationFilePath()
| 0 | ||||||||||||
| 197 | : arguments.at(0); | - | ||||||||||||
| 198 | - | |||||||||||||
| 199 | // tell the session manager about our program in best POSIX style | - | ||||||||||||
| 200 | sm_setProperty(QString::fromLatin1(SmProgram), argument0); | - | ||||||||||||
| 201 | // tell the session manager about our user as well. | - | ||||||||||||
| 202 | struct passwd *entryPtr = 0; | - | ||||||||||||
| 203 | #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS - 0 > 0) | - | ||||||||||||
| 204 | QVarLengthArray<char, 1024> buf(qMax<long>(sysconf(_SC_GETPW_R_SIZE_MAX), 1024L)); | - | ||||||||||||
| 205 | struct passwd entry; | - | ||||||||||||
| 206 | while (getpwuid_r(geteuid(), &entry, buf.data(), buf.size(), &entryPtr) == ERANGE) {
| 0 | ||||||||||||
| 207 | if (buf.size() >= 32768) {
| 0 | ||||||||||||
| 208 | // too big already, fail | - | ||||||||||||
| 209 | static char badusername[] = ""; | - | ||||||||||||
| 210 | entryPtr = &entry; | - | ||||||||||||
| 211 | entry.pw_name = badusername; | - | ||||||||||||
| 212 | break; never executed: break; | 0 | ||||||||||||
| 213 | } | - | ||||||||||||
| 214 | - | |||||||||||||
| 215 | // retry with a bigger buffer | - | ||||||||||||
| 216 | buf.resize(buf.size() * 2); | - | ||||||||||||
| 217 | } never executed: end of block | 0 | ||||||||||||
| 218 | #else | - | ||||||||||||
| 219 | entryPtr = getpwuid(geteuid()); | - | ||||||||||||
| 220 | #endif | - | ||||||||||||
| 221 | if (entryPtr)
| 0 | ||||||||||||
| 222 | sm_setProperty(QString::fromLatin1(SmUserID), QString::fromLocal8Bit(entryPtr->pw_name)); never executed: sm_setProperty(QString::fromLatin1("UserID"), QString::fromLocal8Bit(entryPtr->pw_name)); | 0 | ||||||||||||
| 223 | - | |||||||||||||
| 224 | // generate a restart and discard command that makes sense | - | ||||||||||||
| 225 | QStringList restart; | - | ||||||||||||
| 226 | restart << argument0 << QLatin1String("-session") | - | ||||||||||||
| 227 | << sm->sessionId() + QLatin1Char('_') + sm->sessionKey(); | - | ||||||||||||
| 228 | - | |||||||||||||
| 229 | QFileInfo fi = QCoreApplication::applicationFilePath(); | - | ||||||||||||
| 230 | if (qAppName().compare(fi.fileName(), Qt::CaseInsensitive) != 0)
| 0 | ||||||||||||
| 231 | restart << QLatin1String("-name") << qAppName(); never executed: restart << QLatin1String("-name") << qAppName(); | 0 | ||||||||||||
| 232 | sm->setRestartCommand(restart); | - | ||||||||||||
| 233 | QStringList discard; | - | ||||||||||||
| 234 | sm->setDiscardCommand(discard); | - | ||||||||||||
| 235 | - | |||||||||||||
| 236 | switch (sm_saveType) { | - | ||||||||||||
| 237 | case SmSaveBoth: never executed: case 2: | 0 | ||||||||||||
| 238 | sm->appCommitData(); | - | ||||||||||||
| 239 | if (sm_isshutdown && sm_cancel)
| 0 | ||||||||||||
| 240 | break; // we cancelled the shutdown, no need to save state never executed: break; | 0 | ||||||||||||
| 241 | // fall through | - | ||||||||||||
| 242 | case SmSaveLocal: code before this statement never executed: case 1:never executed: case 1: | 0 | ||||||||||||
| 243 | sm->appSaveState(); | - | ||||||||||||
| 244 | break; never executed: break; | 0 | ||||||||||||
| 245 | case SmSaveGlobal: never executed: case 0: | 0 | ||||||||||||
| 246 | sm->appCommitData(); | - | ||||||||||||
| 247 | break; never executed: break; | 0 | ||||||||||||
| 248 | default: never executed: default: | 0 | ||||||||||||
| 249 | break; never executed: break; | 0 | ||||||||||||
| 250 | } | - | ||||||||||||
| 251 | - | |||||||||||||
| 252 | if (sm_phase2 && !sm_in_phase2) {
| 0 | ||||||||||||
| 253 | SmcRequestSaveYourselfPhase2(smcConnection, sm_saveYourselfPhase2Callback, (SmPointer*) sm); | - | ||||||||||||
| 254 | qt_sm_blockUserInput = false; | - | ||||||||||||
| 255 | } else { never executed: end of block | 0 | ||||||||||||
| 256 | // close eventual interaction monitors and cancel the | - | ||||||||||||
| 257 | // shutdown, if required. Note that we can only cancel when | - | ||||||||||||
| 258 | // performing a shutdown, it does not work for checkpoints | - | ||||||||||||
| 259 | if (sm_interactionActive) {
| 0 | ||||||||||||
| 260 | SmcInteractDone(smcConnection, sm_isshutdown && sm_cancel); | - | ||||||||||||
| 261 | sm_interactionActive = false; | - | ||||||||||||
| 262 | } else if (sm_cancel && sm_isshutdown) { never executed: end of block
| 0 | ||||||||||||
| 263 | if (sm->allowsErrorInteraction()) {
| 0 | ||||||||||||
| 264 | SmcInteractDone(smcConnection, True); | - | ||||||||||||
| 265 | sm_interactionActive = false; | - | ||||||||||||
| 266 | } never executed: end of block | 0 | ||||||||||||
| 267 | } never executed: end of block | 0 | ||||||||||||
| 268 | - | |||||||||||||
| 269 | // set restart and discard command in session manager | - | ||||||||||||
| 270 | sm_setProperty(QString::fromLatin1(SmRestartCommand), sm->restartCommand()); | - | ||||||||||||
| 271 | sm_setProperty(QString::fromLatin1(SmDiscardCommand), sm->discardCommand()); | - | ||||||||||||
| 272 | - | |||||||||||||
| 273 | // set the restart hint | - | ||||||||||||
| 274 | SmPropValue prop; | - | ||||||||||||
| 275 | prop.length = sizeof(int); | - | ||||||||||||
| 276 | int value = sm->restartHint(); | - | ||||||||||||
| 277 | prop.value = (SmPointer) &value; | - | ||||||||||||
| 278 | sm_setProperty(SmRestartStyleHint, SmCARD8, 1, &prop); | - | ||||||||||||
| 279 | - | |||||||||||||
| 280 | // we are done | - | ||||||||||||
| 281 | SmcSaveYourselfDone(smcConnection, !sm_cancel); | - | ||||||||||||
| 282 | } never executed: end of block | 0 | ||||||||||||
| 283 | } | - | ||||||||||||
| 284 | - | |||||||||||||
| 285 | static void sm_dieCallback(SmcConn smcConn, SmPointer /* clientData */) | - | ||||||||||||
| 286 | { | - | ||||||||||||
| 287 | if (smcConn != smcConnection)
| 0 | ||||||||||||
| 288 | return; never executed: return; | 0 | ||||||||||||
| 289 | resetSmState(); | - | ||||||||||||
| 290 | QEvent quitEvent(QEvent::Quit); | - | ||||||||||||
| 291 | QGuiApplication::sendEvent(qApp, &quitEvent); | - | ||||||||||||
| 292 | } never executed: end of block | 0 | ||||||||||||
| 293 | - | |||||||||||||
| 294 | static void sm_shutdownCancelledCallback(SmcConn smcConn, SmPointer clientData) | - | ||||||||||||
| 295 | { | - | ||||||||||||
| 296 | if (smcConn != smcConnection)
| 0 | ||||||||||||
| 297 | return; never executed: return; | 0 | ||||||||||||
| 298 | if (sm_waitingForInteraction)
| 0 | ||||||||||||
| 299 | ((QXcbSessionManager *) clientData)->exitEventLoop(); never executed: ((QXcbSessionManager *) clientData)->exitEventLoop(); | 0 | ||||||||||||
| 300 | resetSmState(); | - | ||||||||||||
| 301 | } never executed: end of block | 0 | ||||||||||||
| 302 | - | |||||||||||||
| 303 | static void sm_saveCompleteCallback(SmcConn smcConn, SmPointer /*clientData */) | - | ||||||||||||
| 304 | { | - | ||||||||||||
| 305 | if (smcConn != smcConnection)
| 0 | ||||||||||||
| 306 | return; never executed: return; | 0 | ||||||||||||
| 307 | resetSmState(); | - | ||||||||||||
| 308 | } never executed: end of block | 0 | ||||||||||||
| 309 | - | |||||||||||||
| 310 | static void sm_interactCallback(SmcConn smcConn, SmPointer clientData) | - | ||||||||||||
| 311 | { | - | ||||||||||||
| 312 | if (smcConn != smcConnection)
| 0 | ||||||||||||
| 313 | return; never executed: return; | 0 | ||||||||||||
| 314 | if (sm_waitingForInteraction)
| 0 | ||||||||||||
| 315 | ((QXcbSessionManager *) clientData)->exitEventLoop(); never executed: ((QXcbSessionManager *) clientData)->exitEventLoop(); | 0 | ||||||||||||
| 316 | } never executed: end of block | 0 | ||||||||||||
| 317 | - | |||||||||||||
| 318 | static void sm_saveYourselfPhase2Callback(SmcConn smcConn, SmPointer clientData) | - | ||||||||||||
| 319 | { | - | ||||||||||||
| 320 | if (smcConn != smcConnection)
| 0 | ||||||||||||
| 321 | return; never executed: return; | 0 | ||||||||||||
| 322 | sm_in_phase2 = true; | - | ||||||||||||
| 323 | sm_performSaveYourself((QXcbSessionManager *) clientData); | - | ||||||||||||
| 324 | } never executed: end of block | 0 | ||||||||||||
| 325 | - | |||||||||||||
| 326 | - | |||||||||||||
| 327 | void QSmSocketReceiver::socketActivated(int) | - | ||||||||||||
| 328 | { | - | ||||||||||||
| 329 | IceProcessMessages(SmcGetIceConnection(smcConnection), 0, 0); | - | ||||||||||||
| 330 | } never executed: end of block | 0 | ||||||||||||
| 331 | - | |||||||||||||
| 332 | - | |||||||||||||
| 333 | // QXcbSessionManager starts here | - | ||||||||||||
| 334 | - | |||||||||||||
| 335 | QXcbSessionManager::QXcbSessionManager(const QString &id, const QString &key) | - | ||||||||||||
| 336 | : QPlatformSessionManager(id, key) | - | ||||||||||||
| 337 | , m_eventLoop(0) | - | ||||||||||||
| 338 | { | - | ||||||||||||
| 339 | resetSmState(); | - | ||||||||||||
| 340 | char cerror[256]; | - | ||||||||||||
| 341 | char* myId = 0; | - | ||||||||||||
| 342 | QByteArray b_id = id.toLatin1(); | - | ||||||||||||
| 343 | char* prevId = b_id.data(); | - | ||||||||||||
| 344 | - | |||||||||||||
| 345 | SmcCallbacks cb; | - | ||||||||||||
| 346 | cb.save_yourself.callback = sm_saveYourselfCallback; | - | ||||||||||||
| 347 | cb.save_yourself.client_data = (SmPointer) this; | - | ||||||||||||
| 348 | cb.die.callback = sm_dieCallback; | - | ||||||||||||
| 349 | cb.die.client_data = (SmPointer) this; | - | ||||||||||||
| 350 | cb.save_complete.callback = sm_saveCompleteCallback; | - | ||||||||||||
| 351 | cb.save_complete.client_data = (SmPointer) this; | - | ||||||||||||
| 352 | cb.shutdown_cancelled.callback = sm_shutdownCancelledCallback; | - | ||||||||||||
| 353 | cb.shutdown_cancelled.client_data = (SmPointer) this; | - | ||||||||||||
| 354 | - | |||||||||||||
| 355 | // avoid showing a warning message below | - | ||||||||||||
| 356 | if (!qEnvironmentVariableIsSet("SESSION_MANAGER"))
| 0-135 | ||||||||||||
| 357 | return; executed 135 times by 5 tests: return;Executed by:
| 135 | ||||||||||||
| 358 | - | |||||||||||||
| 359 | smcConnection = SmcOpenConnection(0, 0, 1, 0, | - | ||||||||||||
| 360 | SmcSaveYourselfProcMask | | - | ||||||||||||
| 361 | SmcDieProcMask | | - | ||||||||||||
| 362 | SmcSaveCompleteProcMask | | - | ||||||||||||
| 363 | SmcShutdownCancelledProcMask, | - | ||||||||||||
| 364 | &cb, | - | ||||||||||||
| 365 | prevId, | - | ||||||||||||
| 366 | &myId, | - | ||||||||||||
| 367 | 256, cerror); | - | ||||||||||||
| 368 | - | |||||||||||||
| 369 | setSessionId(QString::fromLatin1(myId)); | - | ||||||||||||
| 370 | ::free(myId); // it was allocated by C | - | ||||||||||||
| 371 | - | |||||||||||||
| 372 | QString error = QString::fromLocal8Bit(cerror); | - | ||||||||||||
| 373 | if (!smcConnection)
| 0 | ||||||||||||
| 374 | qWarning("Qt: Session management error: %s", qPrintable(error)); never executed: QMessageLogger(__FILE__, 374, __PRETTY_FUNCTION__).warning("Qt: Session management error: %s", QString(error).toLocal8Bit().constData()); | 0 | ||||||||||||
| 375 | else | - | ||||||||||||
| 376 | sm_receiver = new QSmSocketReceiver(IceConnectionNumber(SmcGetIceConnection(smcConnection))); never executed: sm_receiver = new QSmSocketReceiver(IceConnectionNumber(SmcGetIceConnection(smcConnection))); | 0 | ||||||||||||
| 377 | } | - | ||||||||||||
| 378 | - | |||||||||||||
| 379 | QXcbSessionManager::~QXcbSessionManager() | - | ||||||||||||
| 380 | { | - | ||||||||||||
| 381 | if (smcConnection)
| 0-347 | ||||||||||||
| 382 | SmcCloseConnection(smcConnection, 0, 0); never executed: SmcCloseConnection(smcConnection, 0, 0); | 0 | ||||||||||||
| 383 | smcConnection = 0; | - | ||||||||||||
| 384 | delete sm_receiver; | - | ||||||||||||
| 385 | } executed 347 times by 219 tests: end of blockExecuted by:
| 347 | ||||||||||||
| 386 | - | |||||||||||||
| 387 | - | |||||||||||||
| 388 | void* QXcbSessionManager::handle() const | - | ||||||||||||
| 389 | { | - | ||||||||||||
| 390 | return (void*) smcConnection; never executed: return (void*) smcConnection; | 0 | ||||||||||||
| 391 | } | - | ||||||||||||
| 392 | - | |||||||||||||
| 393 | bool QXcbSessionManager::allowsInteraction() | - | ||||||||||||
| 394 | { | - | ||||||||||||
| 395 | if (sm_interactionActive)
| 0 | ||||||||||||
| 396 | return true; never executed: return true; | 0 | ||||||||||||
| 397 | - | |||||||||||||
| 398 | if (sm_waitingForInteraction)
| 0 | ||||||||||||
| 399 | return false; never executed: return false; | 0 | ||||||||||||
| 400 | - | |||||||||||||
| 401 | if (sm_interactStyle == SmInteractStyleAny) {
| 0 | ||||||||||||
| 402 | sm_waitingForInteraction = SmcInteractRequest(smcConnection, | - | ||||||||||||
| 403 | SmDialogNormal, | - | ||||||||||||
| 404 | sm_interactCallback, | - | ||||||||||||
| 405 | (SmPointer*) this); | - | ||||||||||||
| 406 | } never executed: end of block | 0 | ||||||||||||
| 407 | if (sm_waitingForInteraction) {
| 0 | ||||||||||||
| 408 | QEventLoop eventLoop; | - | ||||||||||||
| 409 | m_eventLoop = &eventLoop; | - | ||||||||||||
| 410 | eventLoop.exec(); | - | ||||||||||||
| 411 | m_eventLoop = 0; | - | ||||||||||||
| 412 | - | |||||||||||||
| 413 | sm_waitingForInteraction = false; | - | ||||||||||||
| 414 | if (sm_smActive) { // not cancelled
| 0 | ||||||||||||
| 415 | sm_interactionActive = true; | - | ||||||||||||
| 416 | qt_sm_blockUserInput = false; | - | ||||||||||||
| 417 | return true; never executed: return true; | 0 | ||||||||||||
| 418 | } | - | ||||||||||||
| 419 | } never executed: end of block | 0 | ||||||||||||
| 420 | return false; never executed: return false; | 0 | ||||||||||||
| 421 | } | - | ||||||||||||
| 422 | - | |||||||||||||
| 423 | bool QXcbSessionManager::allowsErrorInteraction() | - | ||||||||||||
| 424 | { | - | ||||||||||||
| 425 | if (sm_interactionActive)
| 0 | ||||||||||||
| 426 | return true; never executed: return true; | 0 | ||||||||||||
| 427 | - | |||||||||||||
| 428 | if (sm_waitingForInteraction)
| 0 | ||||||||||||
| 429 | return false; never executed: return false; | 0 | ||||||||||||
| 430 | - | |||||||||||||
| 431 | if (sm_interactStyle == SmInteractStyleAny || sm_interactStyle == SmInteractStyleErrors) {
| 0 | ||||||||||||
| 432 | sm_waitingForInteraction = SmcInteractRequest(smcConnection, | - | ||||||||||||
| 433 | SmDialogError, | - | ||||||||||||
| 434 | sm_interactCallback, | - | ||||||||||||
| 435 | (SmPointer*) this); | - | ||||||||||||
| 436 | } never executed: end of block | 0 | ||||||||||||
| 437 | if (sm_waitingForInteraction) {
| 0 | ||||||||||||
| 438 | QEventLoop eventLoop; | - | ||||||||||||
| 439 | m_eventLoop = &eventLoop; | - | ||||||||||||
| 440 | eventLoop.exec(); | - | ||||||||||||
| 441 | m_eventLoop = 0; | - | ||||||||||||
| 442 | - | |||||||||||||
| 443 | sm_waitingForInteraction = false; | - | ||||||||||||
| 444 | if (sm_smActive) { // not cancelled
| 0 | ||||||||||||
| 445 | sm_interactionActive = true; | - | ||||||||||||
| 446 | qt_sm_blockUserInput = false; | - | ||||||||||||
| 447 | return true; never executed: return true; | 0 | ||||||||||||
| 448 | } | - | ||||||||||||
| 449 | } never executed: end of block | 0 | ||||||||||||
| 450 | return false; never executed: return false; | 0 | ||||||||||||
| 451 | } | - | ||||||||||||
| 452 | - | |||||||||||||
| 453 | void QXcbSessionManager::release() | - | ||||||||||||
| 454 | { | - | ||||||||||||
| 455 | if (sm_interactionActive) {
| 0 | ||||||||||||
| 456 | SmcInteractDone(smcConnection, False); | - | ||||||||||||
| 457 | sm_interactionActive = false; | - | ||||||||||||
| 458 | if (sm_smActive && sm_isshutdown)
| 0 | ||||||||||||
| 459 | qt_sm_blockUserInput = true; never executed: qt_sm_blockUserInput = true; | 0 | ||||||||||||
| 460 | } never executed: end of block | 0 | ||||||||||||
| 461 | } never executed: end of block | 0 | ||||||||||||
| 462 | - | |||||||||||||
| 463 | void QXcbSessionManager::cancel() | - | ||||||||||||
| 464 | { | - | ||||||||||||
| 465 | sm_cancel = true; | - | ||||||||||||
| 466 | } never executed: end of block | 0 | ||||||||||||
| 467 | - | |||||||||||||
| 468 | void QXcbSessionManager::setManagerProperty(const QString &name, const QString &value) | - | ||||||||||||
| 469 | { | - | ||||||||||||
| 470 | sm_setProperty(name, value); | - | ||||||||||||
| 471 | } never executed: end of block | 0 | ||||||||||||
| 472 | - | |||||||||||||
| 473 | void QXcbSessionManager::setManagerProperty(const QString &name, const QStringList &value) | - | ||||||||||||
| 474 | { | - | ||||||||||||
| 475 | sm_setProperty(name, value); | - | ||||||||||||
| 476 | } never executed: end of block | 0 | ||||||||||||
| 477 | - | |||||||||||||
| 478 | bool QXcbSessionManager::isPhase2() const | - | ||||||||||||
| 479 | { | - | ||||||||||||
| 480 | return sm_in_phase2; never executed: return sm_in_phase2; | 0 | ||||||||||||
| 481 | } | - | ||||||||||||
| 482 | - | |||||||||||||
| 483 | void QXcbSessionManager::requestPhase2() | - | ||||||||||||
| 484 | { | - | ||||||||||||
| 485 | sm_phase2 = true; | - | ||||||||||||
| 486 | } never executed: end of block | 0 | ||||||||||||
| 487 | - | |||||||||||||
| 488 | void QXcbSessionManager::exitEventLoop() | - | ||||||||||||
| 489 | { | - | ||||||||||||
| 490 | m_eventLoop->exit(); | - | ||||||||||||
| 491 | } never executed: end of block | 0 | ||||||||||||
| 492 | - | |||||||||||||
| 493 | #include "qxcbsessionmanager.moc" | - | ||||||||||||
| Source code | Switch to Preprocessed file |