diff options
Diffstat (limited to 'src/corelib/kernel/qcoreapplication.h')
-rw-r--r-- | src/corelib/kernel/qcoreapplication.h | 105 |
1 files changed, 62 insertions, 43 deletions
diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h index a72b0b6439..0078dc3295 100644 --- a/src/corelib/kernel/qcoreapplication.h +++ b/src/corelib/kernel/qcoreapplication.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore 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 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) 2021 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 #ifndef QCOREAPPLICATION_H #define QCOREAPPLICATION_H @@ -44,11 +8,8 @@ #include <QtCore/qstring.h> #ifndef QT_NO_QOBJECT #include <QtCore/qcoreevent.h> +#include <QtCore/qdeadlinetimer.h> #include <QtCore/qeventloop.h> -#if QT_CONFIG(future) -#include <QtCore/qfuture.h> -#include <QtCore/qapplicationpermission.h> -#endif #include <QtCore/qobject.h> #else #include <QtCore/qscopedpointer.h> @@ -72,6 +33,11 @@ class QTranslator; class QPostEventList; class QAbstractEventDispatcher; class QAbstractNativeEventFilter; +class QEventLoopLocker; + +#if QT_CONFIG(permissions) || defined(Q_QDOC) +class QPermission; +#endif #define qApp QCoreApplication::instance() @@ -94,6 +60,11 @@ class Q_CORE_EXPORT QCoreApplication #endif Q_DECLARE_PRIVATE(QCoreApplication) + friend class QEventLoopLocker; +#if QT_CONFIG(permissions) + using RequestPermissionPrototype = void(*)(QPermission); +#endif + public: enum { ApplicationFlags = QT_VERSION }; @@ -123,12 +94,13 @@ public: static void setSetuidAllowed(bool allow); static bool isSetuidAllowed(); - static QCoreApplication *instance() { return self; } + static QCoreApplication *instance() noexcept { return self; } #ifndef QT_NO_QOBJECT static int exec(); static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime); + static void processEvents(QEventLoop::ProcessEventsFlags flags, QDeadlineTimer deadline); static bool sendEvent(QObject *receiver, QEvent *event); static void postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority); @@ -147,6 +119,53 @@ public: static QString applicationFilePath(); static qint64 applicationPid() Q_DECL_CONST_FUNCTION; +#if QT_CONFIG(permissions) || defined(Q_QDOC) + Qt::PermissionStatus checkPermission(const QPermission &permission); + +# ifdef Q_QDOC + template <typename Functor> + void requestPermission(const QPermission &permission, const QObject *context, Functor functor); +# else + // requestPermission with context or receiver object; need to require here that receiver is the + // right type to avoid ambiguity with the private implementation function. + template <typename Functor, + std::enable_if_t< + QtPrivate::AreFunctionsCompatible<RequestPermissionPrototype, Functor>::value, + bool> = true> + void requestPermission(const QPermission &permission, + const typename QtPrivate::ContextTypeForFunctor<Functor>::ContextType *receiver, + Functor &&func) + { + requestPermission(permission, + QtPrivate::makeCallableObject<RequestPermissionPrototype>(std::forward<Functor>(func)), + receiver); + } +# endif // Q_QDOC + +#ifndef QT_NO_CONTEXTLESS_CONNECT + #ifdef Q_QDOC + template <typename Functor> + #else + // requestPermission to a functor or function pointer (without context) + template <typename Functor, + std::enable_if_t< + QtPrivate::AreFunctionsCompatible<RequestPermissionPrototype, Functor>::value, + bool> = true> + #endif + void requestPermission(const QPermission &permission, Functor &&func) + { + requestPermission(permission, nullptr, std::forward<Functor>(func)); + } +#endif // QT_NO_CONTEXTLESS_CONNECT + +private: + // ### Qt 7: rename to requestPermissionImpl to avoid ambiguity + void requestPermission(const QPermission &permission, + QtPrivate::QSlotObjectBase *slotObj, const QObject *context); +public: + +#endif // QT_CONFIG(permission) + #if QT_CONFIG(library) static void setLibraryPaths(const QStringList &); static QStringList libraryPaths(); |