From 85fc95f346a33173cea107f799cbcff2b92f6dfb Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Tue, 20 Aug 2013 18:14:48 +0200 Subject: Add QPA session manager The QSessionManager doesn't allow customization in platform independent way. The new QPlatformSessionManager aims to change that. Now the QSessionManagerPrivate has a new QPlatformSessionManager member to forward all the calls to QSessionManager's functions. If no platform manager is present, the current behavior is used. QPlatformSessionManager mimics the current QSessionManager behavior. A new factory function has been added to QPlatformIntegration to return a QPlatformSessionManager Task-number: QTBUG-28228 Change-Id: Ida7ac16a8f5303df5014fcb67878170ebdb37203 Reviewed-by: Friedemann Kleint Reviewed-by: Kevin Ottens Reviewed-by: David Faure (KDE) --- src/gui/kernel/kernel.pri | 7 +- src/gui/kernel/qguiapplication.cpp | 21 +++-- src/gui/kernel/qguiapplication_p.h | 6 +- src/gui/kernel/qplatformintegration.cpp | 17 ++++ src/gui/kernel/qplatformintegration.h | 4 + src/gui/kernel/qplatformsessionmanager.cpp | 131 +++++++++++++++++++++++++++++ src/gui/kernel/qplatformsessionmanager.h | 102 ++++++++++++++++++++++ src/gui/kernel/qsessionmanager.cpp | 74 ++++++++-------- src/gui/kernel/qsessionmanager_p.h | 82 ++++++++++++++++++ 9 files changed, 394 insertions(+), 50 deletions(-) create mode 100644 src/gui/kernel/qplatformsessionmanager.cpp create mode 100644 src/gui/kernel/qplatformsessionmanager.h create mode 100644 src/gui/kernel/qsessionmanager_p.h (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index 3c019fc5b5..d9bcbf316f 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -56,6 +56,7 @@ HEADERS += \ kernel/qpalette.h \ kernel/qshortcutmap_p.h \ kernel/qsessionmanager.h \ + kernel/qsessionmanager_p.h \ kernel/qwindowdefs.h \ kernel/qscreen.h \ kernel/qscreen_p.h \ @@ -66,7 +67,8 @@ HEADERS += \ kernel/qplatformdialoghelper.h \ kernel/qplatformservices.h \ kernel/qplatformscreenpageflipper.h \ - kernel/qplatformsystemtrayicon.h + kernel/qplatformsystemtrayicon.h \ + kernel/qplatformsessionmanager.h SOURCES += \ kernel/qclipboard_qpa.cpp \ @@ -118,7 +120,8 @@ SOURCES += \ kernel/qplatformdialoghelper.cpp \ kernel/qplatformservices.cpp \ kernel/qplatformscreenpageflipper.cpp \ - kernel/qplatformsystemtrayicon_qpa.cpp + kernel/qplatformsystemtrayicon_qpa.cpp \ + kernel/qplatformsessionmanager.cpp contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles2) { HEADERS += \ diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 4c2adef6de..1186cc2905 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1068,7 +1068,10 @@ void QGuiApplicationPrivate::init() bool doGrabUnderDebugger = false; QList pluginList; // Get command line params - +#ifndef QT_NO_SESSIONMANAGER + QString session_id; + QString session_key; +#endif int j = argc ? 1 : 0; for (int i=1; isession_id; + return d->session_manager->sessionId(); } QString QGuiApplication::sessionKey() const { Q_D(const QGuiApplication); - return d->session_key; + return d->session_manager->sessionKey(); } bool QGuiApplication::isSavingSession() const @@ -2782,12 +2785,12 @@ bool QGuiApplication::isSavingSession() const return d->is_saving_session; } -void QGuiApplicationPrivate::commitData(QSessionManager& manager) +void QGuiApplicationPrivate::commitData() { Q_Q(QGuiApplication); is_saving_session = true; - emit q->commitDataRequest(manager); - if (manager.allowsInteraction()) { + emit q->commitDataRequest(*session_manager); + if (session_manager->allowsInteraction()) { QWindowList done; QWindowList list = QGuiApplication::topLevelWindows(); bool cancelled = false; @@ -2802,17 +2805,17 @@ void QGuiApplicationPrivate::commitData(QSessionManager& manager) } } if (cancelled) - manager.cancel(); + session_manager->cancel(); } is_saving_session = false; } -void QGuiApplicationPrivate::saveState(QSessionManager &manager) +void QGuiApplicationPrivate::saveState() { Q_Q(QGuiApplication); is_saving_session = true; - emit q->saveStateRequest(manager); + emit q->saveStateRequest(*session_manager); is_saving_session = false; } #endif //QT_NO_SESSIONMANAGER diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 79e826f330..7a4a161476 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -234,12 +234,10 @@ public: #ifndef QT_NO_SESSIONMANAGER QSessionManager *session_manager; - QString session_id; - QString session_key; bool is_session_restored; bool is_saving_session; - void commitData(QSessionManager& sm); - void saveState(QSessionManager& sm); + void commitData(); + void saveState(); #endif struct ActiveTouchPointsKey { diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp index 434344df08..06d2aa4fca 100644 --- a/src/gui/kernel/qplatformintegration.cpp +++ b/src/gui/kernel/qplatformintegration.cpp @@ -51,6 +51,10 @@ #include #include +#ifndef QT_NO_SESSIONMANAGER +# include +#endif + QT_BEGIN_NAMESPACE /*! @@ -395,4 +399,17 @@ QPlatformOffscreenSurface *QPlatformIntegration::createPlatformOffscreenSurface( return 0; } +#ifndef QT_NO_SESSIONMANAGER +/*! + \since 5.2 + + Factory function for QPlatformSessionManager. The default QPlatformSessionManager provides the same + functionality as the QSessionManager. +*/ +QPlatformSessionManager *QPlatformIntegration::createPlatformSessionManager(const QString &id, const QString &key) const +{ + return new QPlatformSessionManager(id, key); +} +#endif + QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h index 9350553efd..a98d332356 100644 --- a/src/gui/kernel/qplatformintegration.h +++ b/src/gui/kernel/qplatformintegration.h @@ -74,6 +74,7 @@ class QPlatformTheme; class QPlatformDialogHelper; class QPlatformSharedGraphicsCache; class QPlatformServices; +class QPlatformSessionManager; class QKeyEvent; class QPlatformOffscreenSurface; class QOffscreenSurface; @@ -156,6 +157,9 @@ public: virtual QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const; +#ifndef QT_NO_SESSIONMANAGER + virtual QPlatformSessionManager *createPlatformSessionManager(const QString &id, const QString &key) const; +#endif protected: void screenAdded(QPlatformScreen *screen); }; diff --git a/src/gui/kernel/qplatformsessionmanager.cpp b/src/gui/kernel/qplatformsessionmanager.cpp new file mode 100644 index 0000000000..6eb88a9450 --- /dev/null +++ b/src/gui/kernel/qplatformsessionmanager.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Samuel Gaist +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtGui module 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qplatformsessionmanager.h" + +QT_BEGIN_NAMESPACE + +QPlatformSessionManager::QPlatformSessionManager(const QString &id, const QString &key) + : m_sessionId(id), + m_sessionKey(key), + m_restartHint(QSessionManager::RestartIfRunning) +{ +} + +QPlatformSessionManager::~QPlatformSessionManager() +{ +} + +QString QPlatformSessionManager::sessionId() const +{ + return m_sessionId; +} + +QString QPlatformSessionManager::sessionKey() const +{ + return m_sessionKey; +} + +bool QPlatformSessionManager::allowsInteraction() +{ + return false; +} + +bool QPlatformSessionManager::allowsErrorInteraction() +{ + return false; +} + +void QPlatformSessionManager::release() +{ +} + +void QPlatformSessionManager::cancel() +{ +} + +void QPlatformSessionManager::setRestartHint(QSessionManager::RestartHint restartHint) +{ + m_restartHint = restartHint; +} + +QSessionManager::RestartHint QPlatformSessionManager::restartHint() const +{ + return m_restartHint; +} + +void QPlatformSessionManager::setRestartCommand(const QStringList &command) +{ + m_restartCommand = command; +} + +QStringList QPlatformSessionManager::restartCommand() const +{ + return m_restartCommand; +} + +void QPlatformSessionManager::setDiscardCommand(const QStringList &command) +{ + m_discardCommand = command; +} + +QStringList QPlatformSessionManager::discardCommand() const +{ + return m_discardCommand; +} + +void QPlatformSessionManager::setManagerProperty(const QString &name, const QStringList &value) +{ + Q_UNUSED(name) + Q_UNUSED(value) +} + +bool QPlatformSessionManager::isPhase2() const +{ + return false; +} + +void QPlatformSessionManager::requestPhase2() +{ +} + +QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformsessionmanager.h b/src/gui/kernel/qplatformsessionmanager.h new file mode 100644 index 0000000000..0389a7b076 --- /dev/null +++ b/src/gui/kernel/qplatformsessionmanager.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Samuel Gaist +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtGui module 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPLATFORMSESSIONMANAGER_H +#define QPLATFORMSESSIONMANAGER_H + +// +// W A R N I N G +// ------------- +// +// This file is part of the QPA API and is not meant to be used +// in applications. Usage of this API may make your code +// source and binary incompatible with future versions of Qt. +// + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +class Q_GUI_EXPORT QPlatformSessionManager +{ +public: + explicit QPlatformSessionManager(const QString &id, const QString &key); + virtual ~QPlatformSessionManager(); + + virtual QString sessionId() const; + virtual QString sessionKey() const; + + virtual bool allowsInteraction(); + virtual bool allowsErrorInteraction(); + virtual void release(); + + virtual void cancel(); + + virtual void setRestartHint(QSessionManager::RestartHint restartHint); + virtual QSessionManager::RestartHint restartHint() const; + + virtual void setRestartCommand(const QStringList &command); + virtual QStringList restartCommand() const; + virtual void setDiscardCommand(const QStringList &command); + virtual QStringList discardCommand() const; + + virtual void setManagerProperty(const QString &name, const QStringList &value); + + virtual bool isPhase2() const; + virtual void requestPhase2(); + +private: + QStringList m_restartCommand; + QStringList m_discardCommand; + const QString m_sessionId; + const QString m_sessionKey; + QSessionManager::RestartHint m_restartHint; + + Q_DISABLE_COPY(QPlatformSessionManager) +}; + +QT_END_NAMESPACE + +#endif // QPLATFORMSESSIONMANAGER_H diff --git a/src/gui/kernel/qsessionmanager.cpp b/src/gui/kernel/qsessionmanager.cpp index 4ac9ab4db5..8ac3c24a8f 100644 --- a/src/gui/kernel/qsessionmanager.cpp +++ b/src/gui/kernel/qsessionmanager.cpp @@ -41,8 +41,12 @@ #include #include +#include +#include #include +#include +#include #ifndef QT_NO_SESSIONMANAGER @@ -117,32 +121,24 @@ QT_BEGIN_NAMESPACE The default hint is \c RestartIfRunning. */ - -class QSessionManagerPrivate : public QObjectPrivate -{ -public: - QSessionManagerPrivate(QSessionManager *m, const QString &id, - const QString &key); - - QStringList restartCommand; - QStringList discardCommand; - const QString sessionId; - const QString sessionKey; - QSessionManager::RestartHint restartHint; -}; - -QSessionManagerPrivate::QSessionManagerPrivate(QSessionManager*, - const QString &id, +QSessionManagerPrivate::QSessionManagerPrivate(const QString &id, const QString &key) - : QObjectPrivate(), sessionId(id), sessionKey(key) + : QObjectPrivate() { + platformSessionManager = QGuiApplicationPrivate::platformIntegration()->createPlatformSessionManager(id, key); + Q_ASSERT_X(platformSessionManager, "Platform session management", + "No platform session management, should use the default implementation"); +} + +QSessionManagerPrivate::~QSessionManagerPrivate() +{ + delete platformSessionManager; + platformSessionManager = 0; } QSessionManager::QSessionManager(QGuiApplication *app, QString &id, QString &key) - : QObject(*(new QSessionManagerPrivate(this, id, key)), app) + : QObject(*(new QSessionManagerPrivate(id, key)), app) { - Q_D(QSessionManager); - d->restartHint = RestartIfRunning; } QSessionManager::~QSessionManager() @@ -160,7 +156,7 @@ QSessionManager::~QSessionManager() QString QSessionManager::sessionId() const { Q_D(const QSessionManager); - return d->sessionId; + return d->platformSessionManager->sessionId(); } /*! @@ -178,7 +174,7 @@ QString QSessionManager::sessionId() const QString QSessionManager::sessionKey() const { Q_D(const QSessionManager); - return d->sessionKey; + return d->platformSessionManager->sessionKey(); } @@ -213,7 +209,8 @@ QString QSessionManager::sessionKey() const */ bool QSessionManager::allowsInteraction() { - return false; + Q_D(QSessionManager); + return d->platformSessionManager->allowsInteraction(); } /*! @@ -229,7 +226,8 @@ bool QSessionManager::allowsInteraction() */ bool QSessionManager::allowsErrorInteraction() { - return false; + Q_D(QSessionManager); + return d->platformSessionManager->allowsErrorInteraction(); } /*! @@ -240,6 +238,8 @@ bool QSessionManager::allowsErrorInteraction() */ void QSessionManager::release() { + Q_D(QSessionManager); + d->platformSessionManager->release(); } /*! @@ -250,6 +250,8 @@ void QSessionManager::release() */ void QSessionManager::cancel() { + Q_D(QSessionManager); + d->platformSessionManager->cancel(); } /*! @@ -268,7 +270,7 @@ void QSessionManager::cancel() void QSessionManager::setRestartHint(QSessionManager::RestartHint hint) { Q_D(QSessionManager); - d->restartHint = hint; + d->platformSessionManager->setRestartHint(hint); } /*! @@ -282,7 +284,7 @@ void QSessionManager::setRestartHint(QSessionManager::RestartHint hint) QSessionManager::RestartHint QSessionManager::restartHint() const { Q_D(const QSessionManager); - return d->restartHint; + return d->platformSessionManager->restartHint(); } /*! @@ -308,7 +310,7 @@ QSessionManager::RestartHint QSessionManager::restartHint() const void QSessionManager::setRestartCommand(const QStringList &command) { Q_D(QSessionManager); - d->restartCommand = command; + d->platformSessionManager->setRestartCommand(command); } /*! @@ -323,7 +325,7 @@ void QSessionManager::setRestartCommand(const QStringList &command) QStringList QSessionManager::restartCommand() const { Q_D(const QSessionManager); - return d->restartCommand; + return d->platformSessionManager->restartCommand(); } /*! @@ -334,7 +336,7 @@ QStringList QSessionManager::restartCommand() const void QSessionManager::setDiscardCommand(const QStringList &command) { Q_D(QSessionManager); - d->discardCommand = command; + d->platformSessionManager->setDiscardCommand(command); } /*! @@ -349,7 +351,7 @@ void QSessionManager::setDiscardCommand(const QStringList &command) QStringList QSessionManager::discardCommand() const { Q_D(const QSessionManager); - return d->discardCommand; + return d->platformSessionManager->discardCommand(); } /*! @@ -363,8 +365,7 @@ QStringList QSessionManager::discardCommand() const void QSessionManager::setManagerProperty(const QString &name, const QString &value) { - Q_UNUSED(name); - Q_UNUSED(value); + setManagerProperty(name, QStringList(value)); } /*! @@ -376,8 +377,8 @@ void QSessionManager::setManagerProperty(const QString &name, void QSessionManager::setManagerProperty(const QString &name, const QStringList &value) { - Q_UNUSED(name); - Q_UNUSED(value); + Q_D(QSessionManager); + d->platformSessionManager->setManagerProperty(name, value); } /*! @@ -388,7 +389,8 @@ void QSessionManager::setManagerProperty(const QString &name, */ bool QSessionManager::isPhase2() const { - return false; + Q_D(const QSessionManager); + return d->platformSessionManager->isPhase2(); } /*! @@ -409,6 +411,8 @@ bool QSessionManager::isPhase2() const */ void QSessionManager::requestPhase2() { + Q_D(QSessionManager); + d->platformSessionManager->requestPhase2(); } QT_END_NAMESPACE diff --git a/src/gui/kernel/qsessionmanager_p.h b/src/gui/kernel/qsessionmanager_p.h new file mode 100644 index 0000000000..dd249fdb67 --- /dev/null +++ b/src/gui/kernel/qsessionmanager_p.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Samuel Gaist +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtGui module 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSESSIONMANAGER_P_H +#define QSESSIONMANAGER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include + +#ifndef QT_NO_SESSIONMANAGER + +QT_BEGIN_NAMESPACE + +class QPlatformSessionManager; + +class QSessionManagerPrivate : public QObjectPrivate +{ +public: + QSessionManagerPrivate(const QString &id, + const QString &key); + + virtual ~QSessionManagerPrivate(); + + QPlatformSessionManager *platformSessionManager; +}; + +QT_END_NAMESPACE + +#endif // QT_NO_SESSIONMANAGER + +#endif // QSESSIONMANAGER_P_H -- cgit v1.2.3