File indexing completed on 2024-04-28 05:50:31
0001 0002 /* 0003 * Copyright 2019 Eike Hein <hein@kde.org> 0004 * 0005 * This program is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU General Public License as 0007 * published by the Free Software Foundation; either version 2 of 0008 * the License or (at your option) version 3 or any later version 0009 * accepted by the membership of KDE e.V. (or its successor approved 0010 * by the membership of KDE e.V.), which shall act as a proxy 0011 * defined in Section 14 of version 3 of the license. 0012 * 0013 * This program is distributed in the hope that it will be useful, 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0016 * GNU General Public License for more details. 0017 * 0018 * You should have received a copy of the GNU General Public License 0019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0020 */ 0021 0022 #include "permissions.h" 0023 0024 #ifdef Q_OS_ANDROID 0025 #include <QtAndroid> 0026 #endif 0027 0028 Permissions::Permissions(const QStringList &permissions, QObject *parent) 0029 : QObject(parent) 0030 , m_permissions(permissions) 0031 , m_granted(false) 0032 { 0033 } 0034 0035 Permissions::~Permissions() 0036 { 0037 } 0038 0039 bool Permissions::granted() const 0040 { 0041 return true; 0042 } 0043 0044 void Permissions::request() 0045 { 0046 if (m_granted) { 0047 return; 0048 } 0049 0050 #ifdef Q_OS_ANDROID 0051 QtAndroid::requestPermissions(m_permissions, [this](const QtAndroid::PermissionResultMap &permissions) { 0052 int granted = 0; 0053 0054 for (const QString &permission : m_permissions) { 0055 if (permissions.contains(permission) && permissions.value(permission) == QtAndroid::PermissionResult::Granted) { 0056 ++granted; 0057 } 0058 } 0059 0060 m_granted = (granted = m_permissions.count()); 0061 }); 0062 #else 0063 m_granted = true; 0064 emit grantedChanged(); 0065 #endif 0066 }