Warning, /graphics/krita/3rdparty/ext_qt/0014-platform-android-Add-native-file-dialog.patch is written in an unsupported language. File is not indexed.
0001 From 4fd380d5c6a7d58ca2fe19dc6c2ec42c468597cc Mon Sep 17 00:00:00 2001 0002 From: Nicolas Fella <nicolas.fella@kdab.com> 0003 Date: Wed, 30 Jan 2019 14:13:12 +0100 0004 Subject: [PATCH 14/46] [platform/android] Add native file dialog 0005 0006 Add basic native file open dialog on Android. Not all features of QFileDialog can be mapped to the 0007 Android file dialog. 0008 0009 Most notably there is no "Save" dialog. The dialog returns a content:// URL. Patch 251038 adds 0010 support for those to QFile. 0011 0012 Change-Id: I13d02103edcd9a089afcce8193432f24b2e0fe43 0013 Reviewed-by: BogDan Vatra <bogdan@kdab.com> 0014 --- 0015 src/plugins/platforms/android/android.pro | 6 +- 0016 .../qandroidplatformfiledialoghelper.cpp | 149 ++++++++++++++++++ 0017 .../qandroidplatformfiledialoghelper.h | 81 ++++++++++ 0018 .../android/qandroidplatformtheme.cpp | 5 + 0019 4 files changed, 239 insertions(+), 2 deletions(-) 0020 create mode 100644 src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp 0021 create mode 100644 src/plugins/platforms/android/qandroidplatformfiledialoghelper.h 0022 0023 diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro 0024 index 940bd5fc55..78632a9bea 100644 0025 --- a/src/plugins/platforms/android/android.pro 0026 +++ b/src/plugins/platforms/android/android.pro 0027 @@ -47,7 +47,8 @@ SOURCES += $$PWD/androidplatformplugin.cpp \ 0028 $$PWD/qandroidplatformopenglcontext.cpp \ 0029 $$PWD/qandroidplatformforeignwindow.cpp \ 0030 $$PWD/qandroideventdispatcher.cpp \ 0031 - $$PWD/qandroidplatformoffscreensurface.cpp 0032 + $$PWD/qandroidplatformoffscreensurface.cpp \ 0033 + $$PWD/qandroidplatformfiledialoghelper.cpp 0034 0035 HEADERS += $$PWD/qandroidplatformintegration.h \ 0036 $$PWD/androidcontentfileengine.h \ 0037 @@ -77,7 +78,8 @@ HEADERS += $$PWD/qandroidplatformintegration.h \ 0038 $$PWD/qandroidplatformopenglcontext.h \ 0039 $$PWD/qandroidplatformforeignwindow.h \ 0040 $$PWD/qandroideventdispatcher.h \ 0041 - $$PWD/qandroidplatformoffscreensurface.h 0042 + $$PWD/qandroidplatformoffscreensurface.h \ 0043 + $$PWD/qandroidplatformfiledialoghelper.h 0044 0045 qtConfig(android-style-assets): SOURCES += $$PWD/extract.cpp 0046 else: SOURCES += $$PWD/extract-dummy.cpp 0047 diff --git a/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp b/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp 0048 new file mode 100644 0049 index 0000000000..4fb271a75c 0050 --- /dev/null 0051 +++ b/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp 0052 @@ -0,0 +1,149 @@ 0053 +/**************************************************************************** 0054 +** 0055 +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB) 0056 +** Contact: https://www.qt.io/licensing/ 0057 +** 0058 +** This file is part of the plugins of the Qt Toolkit. 0059 +** 0060 +** $QT_BEGIN_LICENSE:LGPL$ 0061 +** Commercial License Usage 0062 +** Licensees holding valid commercial Qt licenses may use this file in 0063 +** accordance with the commercial license agreement provided with the 0064 +** Software or, alternatively, in accordance with the terms contained in 0065 +** a written agreement between you and The Qt Company. For licensing terms 0066 +** and conditions see https://www.qt.io/terms-conditions. For further 0067 +** information use the contact form at https://www.qt.io/contact-us. 0068 +** 0069 +** GNU Lesser General Public License Usage 0070 +** Alternatively, this file may be used under the terms of the GNU Lesser 0071 +** General Public License version 3 as published by the Free Software 0072 +** Foundation and appearing in the file LICENSE.LGPL3 included in the 0073 +** packaging of this file. Please review the following information to 0074 +** ensure the GNU Lesser General Public License version 3 requirements 0075 +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 0076 +** 0077 +** GNU General Public License Usage 0078 +** Alternatively, this file may be used under the terms of the GNU 0079 +** General Public License version 2.0 or (at your option) the GNU General 0080 +** Public license version 3 or any later version approved by the KDE Free 0081 +** Qt Foundation. The licenses are as published by the Free Software 0082 +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 0083 +** included in the packaging of this file. Please review the following 0084 +** information to ensure the GNU General Public License requirements will 0085 +** be met: https://www.gnu.org/licenses/gpl-2.0.html and 0086 +** https://www.gnu.org/licenses/gpl-3.0.html. 0087 +** 0088 +** $QT_END_LICENSE$ 0089 +** 0090 +****************************************************************************/ 0091 + 0092 +#include "qandroidplatformfiledialoghelper.h" 0093 + 0094 +#include <androidjnimain.h> 0095 +#include <private/qjni_p.h> 0096 +#include <jni.h> 0097 + 0098 +QT_BEGIN_NAMESPACE 0099 + 0100 +namespace QtAndroidFileDialogHelper { 0101 + 0102 +#define RESULT_OK -1 0103 +#define REQUEST_CODE 1305 // Arbitrary 0104 + 0105 +QAndroidPlatformFileDialogHelper::QAndroidPlatformFileDialogHelper() 0106 + : QPlatformFileDialogHelper() 0107 + , m_selectedFile() 0108 +{ 0109 +} 0110 + 0111 +bool QAndroidPlatformFileDialogHelper::handleActivityResult(jint requestCode, jint resultCode, jobject data) 0112 +{ 0113 + if (requestCode != REQUEST_CODE) 0114 + return false; 0115 + 0116 + if (resultCode == RESULT_OK) { 0117 + const QJNIObjectPrivate intent = QJNIObjectPrivate::fromLocalRef(data); 0118 + const QJNIObjectPrivate uri = intent.callObjectMethod("getData", "()Landroid/net/Uri;"); 0119 + const QString uriStr = uri.callObjectMethod("toString", "()Ljava/lang/String;").toString(); 0120 + m_selectedFile = QUrl(uriStr); 0121 + Q_EMIT fileSelected(m_selectedFile); 0122 + Q_EMIT accept(); 0123 + } else { 0124 + Q_EMIT reject(); 0125 + } 0126 + 0127 + return true; 0128 +} 0129 + 0130 +bool QAndroidPlatformFileDialogHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) 0131 +{ 0132 + Q_UNUSED(windowFlags) 0133 + Q_UNUSED(windowModality) 0134 + Q_UNUSED(parent) 0135 + 0136 + if (options()->fileMode() != QFileDialogOptions::FileMode::ExistingFile) 0137 + return false; 0138 + 0139 + QtAndroidPrivate::registerActivityResultListener(this); 0140 + 0141 + const QJNIObjectPrivate ACTION_OPEN_DOCUMENT = QJNIObjectPrivate::getStaticObjectField("android/content/Intent", "ACTION_OPEN_DOCUMENT", "Ljava/lang/String;"); 0142 + QJNIObjectPrivate intent("android/content/Intent", "(Ljava/lang/String;)V", ACTION_OPEN_DOCUMENT.object()); 0143 + const QJNIObjectPrivate CATEGORY_OPENABLE = QJNIObjectPrivate::getStaticObjectField("android/content/Intent", "CATEGORY_OPENABLE", "Ljava/lang/String;"); 0144 + intent.callObjectMethod("addCategory", "(Ljava/lang/String;)Landroid/content/Intent;", CATEGORY_OPENABLE.object()); 0145 + intent.callObjectMethod("setType", "(Ljava/lang/String;)Landroid/content/Intent;", QJNIObjectPrivate::fromString(QStringLiteral("*/*")).object()); 0146 + 0147 + const QJNIObjectPrivate activity(QtAndroid::activity()); 0148 + activity.callMethod<void>("startActivityForResult", "(Landroid/content/Intent;I)V", intent.object(), REQUEST_CODE); 0149 + 0150 + return true; 0151 +} 0152 + 0153 +void QAndroidPlatformFileDialogHelper::exec() 0154 +{ 0155 +} 0156 + 0157 +void QAndroidPlatformFileDialogHelper::hide() 0158 +{ 0159 +} 0160 + 0161 +QString QAndroidPlatformFileDialogHelper::selectedNameFilter() const 0162 +{ 0163 + return QString(); 0164 +} 0165 + 0166 +void QAndroidPlatformFileDialogHelper::selectNameFilter(const QString &filter) 0167 +{ 0168 + Q_UNUSED(filter) 0169 +} 0170 + 0171 +void QAndroidPlatformFileDialogHelper::setFilter() 0172 +{ 0173 +} 0174 + 0175 +QList<QUrl> QAndroidPlatformFileDialogHelper::selectedFiles() const 0176 +{ 0177 + return {m_selectedFile}; 0178 +} 0179 + 0180 +void QAndroidPlatformFileDialogHelper::selectFile(const QUrl &file) 0181 +{ 0182 + Q_UNUSED(file) 0183 +} 0184 + 0185 +QUrl QAndroidPlatformFileDialogHelper::directory() const 0186 +{ 0187 + return QUrl(); 0188 +} 0189 + 0190 +void QAndroidPlatformFileDialogHelper::setDirectory(const QUrl &directory) 0191 +{ 0192 + Q_UNUSED(directory) 0193 +} 0194 + 0195 +bool QAndroidPlatformFileDialogHelper::defaultNameFilterDisables() const 0196 +{ 0197 + return false; 0198 +} 0199 +} 0200 + 0201 +QT_END_NAMESPACE 0202 diff --git a/src/plugins/platforms/android/qandroidplatformfiledialoghelper.h b/src/plugins/platforms/android/qandroidplatformfiledialoghelper.h 0203 new file mode 100644 0204 index 0000000000..e445aa2fef 0205 --- /dev/null 0206 +++ b/src/plugins/platforms/android/qandroidplatformfiledialoghelper.h 0207 @@ -0,0 +1,81 @@ 0208 +/**************************************************************************** 0209 +** 0210 +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB) 0211 +** Contact: https://www.qt.io/licensing/ 0212 +** 0213 +** This file is part of the plugins of the Qt Toolkit. 0214 +** 0215 +** $QT_BEGIN_LICENSE:LGPL$ 0216 +** Commercial License Usage 0217 +** Licensees holding valid commercial Qt licenses may use this file in 0218 +** accordance with the commercial license agreement provided with the 0219 +** Software or, alternatively, in accordance with the terms contained in 0220 +** a written agreement between you and The Qt Company. For licensing terms 0221 +** and conditions see https://www.qt.io/terms-conditions. For further 0222 +** information use the contact form at https://www.qt.io/contact-us. 0223 +** 0224 +** GNU Lesser General Public License Usage 0225 +** Alternatively, this file may be used under the terms of the GNU Lesser 0226 +** General Public License version 3 as published by the Free Software 0227 +** Foundation and appearing in the file LICENSE.LGPL3 included in the 0228 +** packaging of this file. Please review the following information to 0229 +** ensure the GNU Lesser General Public License version 3 requirements 0230 +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 0231 +** 0232 +** GNU General Public License Usage 0233 +** Alternatively, this file may be used under the terms of the GNU 0234 +** General Public License version 2.0 or (at your option) the GNU General 0235 +** Public license version 3 or any later version approved by the KDE Free 0236 +** Qt Foundation. The licenses are as published by the Free Software 0237 +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 0238 +** included in the packaging of this file. Please review the following 0239 +** information to ensure the GNU General Public License requirements will 0240 +** be met: https://www.gnu.org/licenses/gpl-2.0.html and 0241 +** https://www.gnu.org/licenses/gpl-3.0.html. 0242 +** 0243 +** $QT_END_LICENSE$ 0244 +** 0245 +****************************************************************************/ 0246 + 0247 +#ifndef QANDROIDPLATFORMFILEDIALOGHELPER_H 0248 +#define QANDROIDPLATFORMFILEDIALOGHELPER_H 0249 + 0250 +#include <jni.h> 0251 +#include <qpa/qplatformdialoghelper.h> 0252 +#include <QtCore/private/qjnihelpers_p.h> 0253 + 0254 +QT_BEGIN_NAMESPACE 0255 + 0256 +namespace QtAndroidFileDialogHelper { 0257 + 0258 +class QAndroidPlatformFileDialogHelper: public QPlatformFileDialogHelper, public QtAndroidPrivate::ActivityResultListener 0259 +{ 0260 + Q_OBJECT 0261 + 0262 +public: 0263 + QAndroidPlatformFileDialogHelper(); 0264 + void exec() override; 0265 + 0266 + bool show(Qt::WindowFlags windowFlags, 0267 + Qt::WindowModality windowModality, 0268 + QWindow *parent) override; 0269 + void hide() override; 0270 + 0271 + QString selectedNameFilter() const override; 0272 + void selectNameFilter(const QString &filter) override; 0273 + void setFilter() override; 0274 + QList<QUrl> selectedFiles() const override; 0275 + void selectFile(const QUrl &file) override; 0276 + QUrl directory() const override; 0277 + void setDirectory(const QUrl &directory) override; 0278 + bool defaultNameFilterDisables() const override; 0279 + bool handleActivityResult(jint requestCode, jint resultCode, jobject data) override; 0280 + 0281 +private: 0282 + QUrl m_selectedFile; 0283 +}; 0284 + 0285 +} 0286 +QT_END_NAMESPACE 0287 + 0288 +#endif // QANDROIDPLATFORMFILEDIALOGHELPER_H 0289 diff --git a/src/plugins/platforms/android/qandroidplatformtheme.cpp b/src/plugins/platforms/android/qandroidplatformtheme.cpp 0290 index 8d98d4ba8d..d3a8a53241 100644 0291 --- a/src/plugins/platforms/android/qandroidplatformtheme.cpp 0292 +++ b/src/plugins/platforms/android/qandroidplatformtheme.cpp 0293 @@ -44,6 +44,7 @@ 0294 #include "qandroidplatformmenu.h" 0295 #include "qandroidplatformmenuitem.h" 0296 #include "qandroidplatformdialoghelpers.h" 0297 +#include "qandroidplatformfiledialoghelper.h" 0298 0299 #include <QCoreApplication> 0300 #include <QDebug> 0301 @@ -513,6 +514,8 @@ bool QAndroidPlatformTheme::usePlatformNativeDialog(QPlatformTheme::DialogType t 0302 { 0303 if (type == MessageDialog) 0304 return qEnvironmentVariableIntValue("QT_USE_ANDROID_NATIVE_DIALOGS") == 1; 0305 + if (type == FileDialog) 0306 + return true; 0307 return false; 0308 } 0309 0310 @@ -521,6 +524,8 @@ QPlatformDialogHelper *QAndroidPlatformTheme::createPlatformDialogHelper(QPlatfo 0311 switch (type) { 0312 case MessageDialog: 0313 return new QtAndroidDialogHelpers::QAndroidPlatformMessageDialogHelper; 0314 + case FileDialog: 0315 + return new QtAndroidFileDialogHelper::QAndroidPlatformFileDialogHelper; 0316 default: 0317 return 0; 0318 } 0319 -- 0320 2.33.0 0321