Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:07:33

0001 // Copyright (C) 2022 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QPERMISSIONS_H
0005 #define QPERMISSIONS_H
0006 
0007 #if 0
0008 #pragma qt_class(QPermissions)
0009 #endif
0010 
0011 #include <QtCore/qglobal.h>
0012 #include <QtCore/qtmetamacros.h>
0013 #include <QtCore/qvariant.h>
0014 
0015 #include <QtCore/qshareddata_impl.h>
0016 #include <QtCore/qtypeinfo.h>
0017 #include <QtCore/qmetatype.h>
0018 
0019 #include <optional>
0020 
0021 #if !defined(Q_QDOC)
0022 QT_REQUIRE_CONFIG(permissions);
0023 #endif
0024 
0025 QT_BEGIN_NAMESPACE
0026 
0027 #ifndef QT_NO_DEBUG_STREAM
0028 class QDebug;
0029 #endif
0030 
0031 struct QMetaObject;
0032 class QCoreApplication;
0033 
0034 class QPermission
0035 {
0036     template <typename T, typename Enable = void>
0037     static constexpr inline bool is_permission_v = false;
0038 
0039     template <typename T>
0040     using if_permission = std::enable_if_t<is_permission_v<T>, bool>;
0041 public:
0042     explicit QPermission() = default;
0043 
0044     template <typename T, if_permission<T> = true>
0045     QPermission(const T &t) : m_data(QVariant::fromValue(t)) {}
0046 
0047     Qt::PermissionStatus status() const { return m_status; }
0048 
0049     QMetaType type() const { return m_data.metaType(); }
0050 
0051     template <typename T, if_permission<T> = true>
0052     std::optional<T> value() const
0053     {
0054         if (auto p = data(QMetaType::fromType<T>()))
0055             return *static_cast<const T *>(p);
0056         return std::nullopt;
0057     }
0058 
0059 #ifndef QT_NO_DEBUG_STREAM
0060     friend Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QPermission &);
0061 #endif
0062 
0063 private:
0064     Q_CORE_EXPORT const void *data(QMetaType id) const;
0065 
0066     Qt::PermissionStatus m_status = Qt::PermissionStatus::Undetermined;
0067     QVariant m_data;
0068 
0069     friend class QCoreApplication;
0070 };
0071 
0072 template <typename T>
0073 constexpr bool QPermission::is_permission_v<T, typename T::QtPermissionHelper> = true;
0074 
0075 #define QT_PERMISSION(ClassName) \
0076     using QtPermissionHelper = void; \
0077     friend class QPermission; \
0078     union U { \
0079         U() : d(nullptr) {} \
0080         U(ShortData _data) : data(_data) {} \
0081         U(ClassName##Private *_d) : d(_d) {} \
0082         ShortData data; \
0083         ClassName##Private *d; \
0084     } u; \
0085 public: \
0086     Q_CORE_EXPORT ClassName(); \
0087     Q_CORE_EXPORT ClassName(const ClassName &other) noexcept; \
0088     ClassName(ClassName &&other) noexcept \
0089         : u{other.u} { other.u.d = nullptr; } \
0090     Q_CORE_EXPORT ~ClassName(); \
0091     Q_CORE_EXPORT ClassName &operator=(const ClassName &other) noexcept; \
0092     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(ClassName) \
0093     void swap(ClassName &other) noexcept { std::swap(u, other.u); } \
0094 private: \
0095     /*end*/
0096 
0097 class QLocationPermissionPrivate;
0098 class QLocationPermission
0099 {
0100     Q_GADGET_EXPORT(Q_CORE_EXPORT)
0101 public:
0102     enum Accuracy : quint8 {
0103         Approximate,
0104         Precise,
0105     };
0106     Q_ENUM(Accuracy)
0107 
0108     Q_CORE_EXPORT void setAccuracy(Accuracy accuracy);
0109     Q_CORE_EXPORT Accuracy accuracy() const;
0110 
0111     enum Availability : quint8 {
0112         WhenInUse,
0113         Always,
0114     };
0115     Q_ENUM(Availability)
0116 
0117     Q_CORE_EXPORT void setAvailability(Availability availability);
0118     Q_CORE_EXPORT Availability availability() const;
0119 
0120 private:
0121     struct ShortData {
0122         Accuracy accuracy;
0123         Availability availability;
0124         char reserved[sizeof(void*) - sizeof(accuracy) - sizeof(availability)];
0125     };
0126     QT_PERMISSION(QLocationPermission)
0127 };
0128 Q_DECLARE_SHARED(QLocationPermission)
0129 
0130 class QCalendarPermissionPrivate;
0131 class QCalendarPermission
0132 {
0133     Q_GADGET_EXPORT(Q_CORE_EXPORT)
0134 public:
0135     enum AccessMode : quint8 {
0136         ReadOnly,
0137         ReadWrite,
0138     };
0139     Q_ENUM(AccessMode)
0140 
0141     Q_CORE_EXPORT void setAccessMode(AccessMode mode);
0142     Q_CORE_EXPORT AccessMode accessMode() const;
0143 
0144 private:
0145     struct ShortData {
0146         AccessMode mode;
0147         char reserved[sizeof(void*) - sizeof(mode)];
0148     };
0149     QT_PERMISSION(QCalendarPermission)
0150 };
0151 Q_DECLARE_SHARED(QCalendarPermission)
0152 
0153 class QContactsPermissionPrivate;
0154 class QContactsPermission
0155 {
0156     Q_GADGET_EXPORT(Q_CORE_EXPORT)
0157 public:
0158     enum AccessMode : quint8 {
0159         ReadOnly,
0160         ReadWrite,
0161     };
0162     Q_ENUM(AccessMode)
0163 
0164     Q_CORE_EXPORT void setAccessMode(AccessMode mode);
0165     Q_CORE_EXPORT AccessMode accessMode() const;
0166 
0167 private:
0168     struct ShortData {
0169         AccessMode mode;
0170         char reserved[sizeof(void*) - sizeof(mode)];
0171     };
0172     QT_PERMISSION(QContactsPermission)
0173 };
0174 Q_DECLARE_SHARED(QContactsPermission)
0175 
0176 class QBluetoothPermissionPrivate;
0177 class QBluetoothPermission
0178 {
0179     Q_GADGET_EXPORT(Q_CORE_EXPORT)
0180 public:
0181     enum CommunicationMode : quint8 {
0182         Access = 0x01,
0183         Advertise = 0x02,
0184         Default = Access | Advertise,
0185     };
0186     Q_DECLARE_FLAGS(CommunicationModes, CommunicationMode)
0187     Q_FLAG(CommunicationModes)
0188 
0189     Q_CORE_EXPORT void setCommunicationModes(CommunicationModes modes);
0190     Q_CORE_EXPORT CommunicationModes communicationModes() const;
0191 
0192 private:
0193     struct ShortData {
0194         CommunicationMode mode;
0195         char reserved[sizeof(void*) - sizeof(mode)];
0196     };
0197     QT_PERMISSION(QBluetoothPermission)
0198 };
0199 Q_DECLARE_OPERATORS_FOR_FLAGS(QBluetoothPermission::CommunicationModes)
0200 Q_DECLARE_SHARED(QBluetoothPermission)
0201 
0202 #define Q_DECLARE_MINIMAL_PERMISSION(ClassName) \
0203     class ClassName##Private; \
0204     class ClassName \
0205     { \
0206         struct ShortData { char reserved[sizeof(void*)]; }; \
0207         QT_PERMISSION(ClassName) \
0208     }; \
0209     Q_DECLARE_SHARED(ClassName)
0210 
0211 Q_DECLARE_MINIMAL_PERMISSION(QCameraPermission)
0212 Q_DECLARE_MINIMAL_PERMISSION(QMicrophonePermission)
0213 
0214 #undef QT_PERMISSION
0215 #undef Q_DECLARE_MINIMAL_PERMISSION
0216 
0217 QT_END_NAMESPACE
0218 
0219 #endif // QPERMISSIONS_H