Skip to content

Commit

Permalink
Rename QPermission namespace to QApplicationPermission
Browse files Browse the repository at this point in the history
Pick-to: 6.2
Task-number: QTBUG-94407
Change-Id: Ie9c05dbe498cd372c015b5125e6cb8d59ca96b59
Reviewed-by: Edward Welbourne <[email protected]>
Reviewed-by: Tor Arne Vestbø <[email protected]>
  • Loading branch information
Issam-b committed Jul 14, 2021
1 parent b612014 commit 07d4ecd
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 113 deletions.
5 changes: 3 additions & 2 deletions examples/network/http/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);

auto permission = QPermission::WriteStorage;
if (QCoreApplication::requestPermission(permission).result() != QPermission::Authorized) {
auto permission = QApplicationPermission::WriteStorage;
if (QCoreApplication::requestPermission(permission).result()
!= QApplicationPermission::Authorized) {
qWarning() << "Couldn't get 'WriteStorage' permission!";
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/corelib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ qt_internal_add_module(Core
kernel/qobjectcleanuphandler.cpp kernel/qobjectcleanuphandler.h
kernel/qobjectdefs.h
kernel/qobjectdefs_impl.h
kernel/qpermission.h
kernel/qapplicationpermission.h
kernel/qpointer.cpp kernel/qpointer.h
kernel/qproperty.cpp kernel/qproperty.h kernel/qproperty_p.h
kernel/qpropertyprivate.h
Expand Down
32 changes: 16 additions & 16 deletions src/corelib/doc/snippets/permissions/permissions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ void requestCameraPermissionAndroid()
{
//! [Request camera permission on Android]
QCoreApplication::requestPermission(QStringLiteral("android.permission.CAMERA"))
.then([=](QPermission::PermissionResult result) {
if (result == QPermission::Authorized)
.then([=](QApplicationPermission::PermissionResult result) {
if (result == QApplicationPermission::Authorized)
takeSelfie();
});
//! [Request camera permission on Android]
Expand All @@ -68,9 +68,9 @@ void requestCameraPermissionAndroid()
void requestCameraPermission()
{
//! [Request camera permission]
QCoreApplication::requestPermission(QPermission::Camera)
.then([=](QPermission::PermissionResult result) {
if (result == QPermission::Authorized)
QCoreApplication::requestPermission(QApplicationPermission::Camera)
.then([=](QApplicationPermission::PermissionResult result) {
if (result == QApplicationPermission::Authorized)
takeSelfie();
});
//! [Request camera permission]
Expand All @@ -81,17 +81,17 @@ void requestCameraPermissionSyncAndroid()
//! [Request camera permission sync on Android]
auto future = QCoreApplication::requestPermission(QStringLiteral("android.permission.CAMERA"));
auto result = future.result(); // blocks and waits for the result to be ready
if (result == QPermission::Authorized)
if (result == QApplicationPermission::Authorized)
takeSelfie();
//! [Request camera permission sync on Android]
}

void requestCameraPermissionSync()
{
//! [Request camera permission sync]
auto future = QCoreApplication::requestPermission(QPermission::Camera);
auto future = QCoreApplication::requestPermission(QApplicationPermission::Camera);
auto result = future.result(); // blocks and waits for the result to be ready
if (result == QPermission::Authorized)
if (result == QApplicationPermission::Authorized)
takeSelfie();
//! [Request camera permission sync]
}
Expand All @@ -100,8 +100,8 @@ void checkCameraPermissionAndroid()
{
//! [Check camera permission on Android]
QCoreApplication::checkPermission(QStringLiteral("android.permission.CAMERA"))
.then([=](QPermission::PermissionResult result) {
if (result == QPermission::Authorized)
.then([=](QApplicationPermission::PermissionResult result) {
if (result == QApplicationPermission::Authorized)
takeSelfie();
});
//! [Check camera permission on Android]
Expand All @@ -110,9 +110,9 @@ void checkCameraPermissionAndroid()
void checkCameraPermission()
{
//! [Check camera permission]
QCoreApplication::checkPermission(QPermission::Camera)
.then([=](QPermission::PermissionResult result) {
if (result == QPermission::Authorized)
QCoreApplication::checkPermission(QApplicationPermission::Camera)
.then([=](QApplicationPermission::PermissionResult result) {
if (result == QApplicationPermission::Authorized)
takeSelfie();
});
//! [Check camera permission]
Expand All @@ -124,18 +124,18 @@ void checkCameraPermissionAndroidSync()
auto future = QCoreApplication::checkPermission(QStringLiteral("android.permission.CAMERA"));
// may block and wait for the result to be ready on some platforms
auto result = future.result();
if (result == QPermission::Authorized)
if (result == QApplicationPermission::Authorized)
takeSelfie();
//! [Check camera permission sync on Android]
}

void checkCameraPermissionSync()
{
//! [Check camera permission sync]
auto future = QCoreApplication::checkPermission(QPermission::Camera);
auto future = QCoreApplication::checkPermission(QApplicationPermission::Camera);
// may block and wait for the result to be ready on some platforms
auto result = future.result();
if (result == QPermission::Authorized)
if (result == QApplicationPermission::Authorized)
takeSelfie();
//! [Check camera permission sync]
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
**
****************************************************************************/

#ifndef QPERMISSION_H
#define QPERMISSION_H
#ifndef QAPPLICATIONPERMISSION_H
#define QAPPLICATIONPERMISSION_H

#include <QtCore/qglobal.h>

QT_BEGIN_NAMESPACE

namespace QPermission
namespace QApplicationPermission
{

enum PermissionType {
Expand All @@ -71,8 +71,11 @@ enum PermissionResult {
Restricted,
Undetermined
};
} // QPermission
} // QApplicationPermission

// TODO: remove after usages in other modules are renamed.
namespace QPermission = QApplicationPermission;

QT_END_NAMESPACE

#endif // QPERMISSION_H
#endif // QAPPLICATIONPERMISSION_H
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@
****************************************************************************/

/*!
\namespace QPermission
\namespace QApplicationPermission

\brief The QPermission namespace contains enums for app permission types and results.
\brief The QApplicationPermission namespace contains enums for app permission
types and results.

This namespace's enums are used by \l {QCoreApplication::requestPermission()} and
\l {QCoreApplication::checkPermission()}.
*/

/*!
\enum QPermission::PermissionType
\enum QApplicationPermission::PermissionType

Predefined sets of permission values.

Expand Down Expand Up @@ -87,7 +88,7 @@
*/

/*!
\enum QPermission::PermissionResult
\enum QApplicationPermission::PermissionResult

The result values for a permission check or request.

Expand Down
40 changes: 20 additions & 20 deletions src/corelib/kernel/qcoreapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3086,42 +3086,42 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc
#if QT_CONFIG(future) && !defined(QT_NO_QOBJECT)
#if !defined(Q_OS_ANDROID)

QFuture<QPermission::PermissionResult> defaultPermissionFuture()
QFuture<QApplicationPermission::PermissionResult> defaultPermissionFuture()
{
QPromise<QPermission::PermissionResult> promise;
QFuture<QPermission::PermissionResult> future = promise.future();
QPromise<QApplicationPermission::PermissionResult> promise;
QFuture<QApplicationPermission::PermissionResult> future = promise.future();
promise.start();
#if defined(QT_DEBUG)
qWarning() << "This platform doesn't have an implementation"
<< "for the application permissions API.";
#endif
promise.addResult(QPermission::Authorized);
promise.addResult(QApplicationPermission::Authorized);
promise.finish();
return future;
}

QFuture<QPermission::PermissionResult>
QCoreApplicationPrivate::requestPermission(QPermission::PermissionType permission)
QFuture<QApplicationPermission::PermissionResult>
QCoreApplicationPrivate::requestPermission(QApplicationPermission::PermissionType permission)
{
Q_UNUSED(permission)
return defaultPermissionFuture();
}

QFuture<QPermission::PermissionResult>
QFuture<QApplicationPermission::PermissionResult>
QCoreApplicationPrivate::requestPermission(const QString &permission)
{
Q_UNUSED(permission)
return defaultPermissionFuture();
}

QFuture<QPermission::PermissionResult>
QCoreApplicationPrivate::checkPermission(QPermission::PermissionType permission)
QFuture<QApplicationPermission::PermissionResult>
QCoreApplicationPrivate::checkPermission(QApplicationPermission::PermissionType permission)
{
Q_UNUSED(permission)
return defaultPermissionFuture();
}

QFuture<QPermission::PermissionResult>
QFuture<QApplicationPermission::PermissionResult>
QCoreApplicationPrivate::checkPermission(const QString &permission)
{
Q_UNUSED(permission)
Expand All @@ -3148,14 +3148,14 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc
\snippet permissions/permissions.cpp Request camera permission sync
\note Any platform that doesn't have an implementation for this API,
returns QPermission::Authorized by default. Currently, only Android
returns QApplicationPermission::Authorized by default. Currently, only Android
has an implemtation for this API.
\since 6.2
\sa checkPermission()
*/
QFuture<QPermission::PermissionResult>
QCoreApplication::requestPermission(QPermission::PermissionType permission)
QFuture<QApplicationPermission::PermissionResult>
QCoreApplication::requestPermission(QApplicationPermission::PermissionType permission)
{
return QCoreApplicationPrivate::requestPermission(permission);
}
Expand All @@ -3180,13 +3180,13 @@ QCoreApplication::requestPermission(QPermission::PermissionType permission)
\snippet permissions/permissions.cpp Request camera permission sync on Android
\note Any platform that doesn't have an implementation for this API,
returns QPermission::Authorized by default. Currently, only Android
returns QApplicationPermission::Authorized by default. Currently, only Android
has an implemtation for this API.
\since 6.2
\sa checkPermission()
*/
QFuture<QPermission::PermissionResult>
QFuture<QApplicationPermission::PermissionResult>
QCoreApplication::requestPermission(const QString &permission)
{
return QCoreApplicationPrivate::requestPermission(permission);
Expand All @@ -3206,14 +3206,14 @@ QCoreApplication::requestPermission(const QString &permission)
\snippet permissions/permissions.cpp Check camera permission sync
\note Any platform that doesn't have an implementation for this API,
returns QPermission::Authorized by default. Currently, only Android
returns QApplicationPermission::Authorized by default. Currently, only Android
has an implemtation for this API.
\since 6.2
\sa requestPermission()
*/
QFuture<QPermission::PermissionResult>
QCoreApplication::checkPermission(QPermission::PermissionType permission)
QFuture<QApplicationPermission::PermissionResult>
QCoreApplication::checkPermission(QApplicationPermission::PermissionType permission)
{
return QCoreApplicationPrivate::checkPermission(permission);
}
Expand All @@ -3233,13 +3233,13 @@ QCoreApplication::checkPermission(QPermission::PermissionType permission)
\snippet permissions/permissions.cpp Check camera permission sync on Android
\note Any platform that doesn't have an implementation for this API,
returns QPermission::Authorized by default. Currently, only Android
returns QApplicationPermission::Authorized by default. Currently, only Android
has an implemtation for this API.
\since 6.2
\sa requestPermission()
*/
QFuture<QPermission::PermissionResult>
QFuture<QApplicationPermission::PermissionResult>
QCoreApplication::checkPermission(const QString &permission)
{
return QCoreApplicationPrivate::checkPermission(permission);
Expand Down
18 changes: 10 additions & 8 deletions src/corelib/kernel/qcoreapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include <QtCore/qeventloop.h>
#if QT_CONFIG(future)
#include <QtCore/qfuture.h>
#include <QtCore/qpermission.h>
#include <QtCore/qapplicationpermission.h>
#endif
#include <QtCore/qobject.h>
#else
Expand Down Expand Up @@ -168,13 +168,15 @@ class Q_CORE_EXPORT QCoreApplication

#ifndef QT_NO_QOBJECT
#if QT_CONFIG(future)
static QFuture<QPermission::PermissionResult> requestPermission(
QPermission::PermissionType permission);
static QFuture<QPermission::PermissionResult> requestPermission(const QString &permission);

static QFuture<QPermission::PermissionResult> checkPermission(
QPermission::PermissionType permission);
static QFuture<QPermission::PermissionResult> checkPermission(const QString &permission);
static QFuture<QApplicationPermission::PermissionResult>
requestPermission(QApplicationPermission::PermissionType permission);
static QFuture<QApplicationPermission::PermissionResult>
requestPermission(const QString &permission);

static QFuture<QApplicationPermission::PermissionResult>
checkPermission(QApplicationPermission::PermissionType permission);
static QFuture<QApplicationPermission::PermissionResult>
checkPermission(const QString &permission);
#endif
void installNativeEventFilter(QAbstractNativeEventFilter *filterObj);
void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj);
Expand Down
Loading

0 comments on commit 07d4ecd

Please sign in to comment.