diff options
Diffstat (limited to 'src/plugins/platforms/xcb/qxcbsessionmanager.cpp')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbsessionmanager.cpp | 92 |
1 files changed, 29 insertions, 63 deletions
diff --git a/src/plugins/platforms/xcb/qxcbsessionmanager.cpp b/src/plugins/platforms/xcb/qxcbsessionmanager.cpp index f880d4d722..b4e28ab831 100644 --- a/src/plugins/platforms/xcb/qxcbsessionmanager.cpp +++ b/src/plugins/platforms/xcb/qxcbsessionmanager.cpp @@ -1,47 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Teo Mrnjavac <teo@kde.org> -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2013 Teo Mrnjavac <teo@kde.org> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qxcbsessionmanager.h" #ifndef QT_NO_SESSIONMANAGER +#include <QtCore/qvarlengtharray.h> #include <qpa/qwindowsysteminterface.h> #include <qguiapplication.h> @@ -54,6 +19,8 @@ #include <cerrno> // ERANGE +using namespace Qt::StringLiterals; + class QSmSocketReceiver : public QObject { Q_OBJECT @@ -61,15 +28,15 @@ public: QSmSocketReceiver(int socket) { QSocketNotifier* sn = new QSocketNotifier(socket, QSocketNotifier::Read, this); - connect(sn, SIGNAL(activated(int)), this, SLOT(socketActivated(int))); + connect(sn, SIGNAL(activated(QSocketDescriptor)), this, SLOT(socketActivated())); } public Q_SLOTS: - void socketActivated(int); + void socketActivated(); }; -static SmcConn smcConnection = 0; +static SmcConn smcConnection = nullptr; static bool sm_interactionActive; static bool sm_smActive; static int sm_interactStyle; @@ -81,7 +48,7 @@ static bool sm_phase2; static bool sm_in_phase2; bool qt_sm_blockUserInput = false; -static QSmSocketReceiver* sm_receiver = 0; +static QSmSocketReceiver* sm_receiver = nullptr; static void resetSmState(); static void sm_setProperty(const char *name, const char *type, @@ -134,19 +101,19 @@ static void sm_setProperty(const QString &name, const QString &value) { QByteArray v = value.toUtf8(); SmPropValue prop; - prop.length = v.length(); + prop.length = v.size(); prop.value = (SmPointer) const_cast<char *>(v.constData()); sm_setProperty(name.toLatin1().data(), SmARRAY8, 1, &prop); } static void sm_setProperty(const QString &name, const QStringList &value) { - SmPropValue *prop = new SmPropValue[value.count()]; + SmPropValue *prop = new SmPropValue[value.size()]; int count = 0; QList<QByteArray> vl; vl.reserve(value.size()); for (QStringList::ConstIterator it = value.begin(); it != value.end(); ++it) { - prop[count].length = (*it).length(); + prop[count].length = (*it).size(); vl.append((*it).toUtf8()); prop[count].value = (char*)vl.constLast().data(); ++count; @@ -191,9 +158,9 @@ static void sm_performSaveYourself(QXcbSessionManager *sm) // generate a new session key timeval tv; - gettimeofday(&tv, 0); + gettimeofday(&tv, nullptr); sm->setSessionKey(QString::number(qulonglong(tv.tv_sec)) + - QLatin1Char('_') + + u'_' + QString::number(qulonglong(tv.tv_usec))); QStringList arguments = QCoreApplication::arguments(); @@ -203,7 +170,7 @@ static void sm_performSaveYourself(QXcbSessionManager *sm) // tell the session manager about our program in best POSIX style sm_setProperty(QString::fromLatin1(SmProgram), argument0); // tell the session manager about our user as well. - struct passwd *entryPtr = 0; + struct passwd *entryPtr = nullptr; #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS - 0 > 0) QVarLengthArray<char, 1024> buf(qMax<long>(sysconf(_SC_GETPW_R_SIZE_MAX), 1024L)); struct passwd entry; @@ -227,12 +194,11 @@ static void sm_performSaveYourself(QXcbSessionManager *sm) // generate a restart and discard command that makes sense QStringList restart; - restart << argument0 << QLatin1String("-session") - << sm->sessionId() + QLatin1Char('_') + sm->sessionKey(); + restart << argument0 << "-session"_L1 << sm->sessionId() + u'_' + sm->sessionKey(); - QFileInfo fi = QCoreApplication::applicationFilePath(); + QFileInfo fi(QCoreApplication::applicationFilePath()); if (qAppName().compare(fi.fileName(), Qt::CaseInsensitive) != 0) - restart << QLatin1String("-name") << qAppName(); + restart << "-name"_L1 << qAppName(); sm->setRestartCommand(restart); QStringList discard; sm->setDiscardCommand(discard); @@ -242,7 +208,7 @@ static void sm_performSaveYourself(QXcbSessionManager *sm) sm->appCommitData(); if (sm_isshutdown && sm_cancel) break; // we cancelled the shutdown, no need to save state - // fall through + Q_FALLTHROUGH(); case SmSaveLocal: sm->appSaveState(); break; @@ -327,9 +293,9 @@ static void sm_saveYourselfPhase2Callback(SmcConn smcConn, SmPointer clientData) } -void QSmSocketReceiver::socketActivated(int) +void QSmSocketReceiver::socketActivated() { - IceProcessMessages(SmcGetIceConnection(smcConnection), 0, 0); + IceProcessMessages(SmcGetIceConnection(smcConnection), nullptr, nullptr); } @@ -337,11 +303,11 @@ void QSmSocketReceiver::socketActivated(int) QXcbSessionManager::QXcbSessionManager(const QString &id, const QString &key) : QPlatformSessionManager(id, key) - , m_eventLoop(0) + , m_eventLoop(nullptr) { resetSmState(); char cerror[256]; - char* myId = 0; + char* myId = nullptr; QByteArray b_id = id.toLatin1(); char* prevId = b_id.data(); @@ -359,7 +325,7 @@ QXcbSessionManager::QXcbSessionManager(const QString &id, const QString &key) if (!qEnvironmentVariableIsSet("SESSION_MANAGER")) return; - smcConnection = SmcOpenConnection(0, 0, 1, 0, + smcConnection = SmcOpenConnection(nullptr, nullptr, 1, 0, SmcSaveYourselfProcMask | SmcDieProcMask | SmcSaveCompleteProcMask | @@ -382,8 +348,8 @@ QXcbSessionManager::QXcbSessionManager(const QString &id, const QString &key) QXcbSessionManager::~QXcbSessionManager() { if (smcConnection) - SmcCloseConnection(smcConnection, 0, 0); - smcConnection = 0; + SmcCloseConnection(smcConnection, 0, nullptr); + smcConnection = nullptr; delete sm_receiver; } @@ -411,7 +377,7 @@ bool QXcbSessionManager::allowsInteraction() QEventLoop eventLoop; m_eventLoop = &eventLoop; eventLoop.exec(); - m_eventLoop = 0; + m_eventLoop = nullptr; sm_waitingForInteraction = false; if (sm_smActive) { // not cancelled @@ -441,7 +407,7 @@ bool QXcbSessionManager::allowsErrorInteraction() QEventLoop eventLoop; m_eventLoop = &eventLoop; eventLoop.exec(); - m_eventLoop = 0; + m_eventLoop = nullptr; sm_waitingForInteraction = false; if (sm_smActive) { // not cancelled |