summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios/qiosfiledialog.mm
diff options
context:
space:
mode:
authorHarald Meyer <dev@meh.at>2020-03-10 19:16:20 +0100
committerHarald Meyer <dev@meh.at>2020-03-14 16:22:17 +0100
commit91436e2409f8950389ca959c00175bf91da2dafc (patch)
treec94b3c64d1b09a919f76ea05234f76508144e5db /src/plugins/platforms/ios/qiosfiledialog.mm
parent395e2d9bc48941d64d7ca0e7998dcacb0a0606af (diff)
Add native iOS file dialog
This patch adds native iOS file open and directory picking support for the QFileDialog using the iOS UIDocumentPickerViewController class. Change-Id: Ia724a59742650a01c62067aed3477f82ab1fd546 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/ios/qiosfiledialog.mm')
-rw-r--r--src/plugins/platforms/ios/qiosfiledialog.mm30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/plugins/platforms/ios/qiosfiledialog.mm b/src/plugins/platforms/ios/qiosfiledialog.mm
index e8a3f5b30e..edf04016fd 100644
--- a/src/plugins/platforms/ios/qiosfiledialog.mm
+++ b/src/plugins/platforms/ios/qiosfiledialog.mm
@@ -48,6 +48,7 @@
#include "qiosfiledialog.h"
#include "qiosintegration.h"
#include "qiosoptionalplugininterface.h"
+#include "qiosdocumentpickercontroller.h"
QIOSFileDialog::QIOSFileDialog()
: m_viewController(nullptr)
@@ -72,8 +73,12 @@ bool QIOSFileDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality window
bool acceptOpen = options()->acceptMode() == QFileDialogOptions::AcceptOpen;
QString directory = options()->initialDirectory().toLocalFile();
- if (acceptOpen && directory.startsWith(QLatin1String("assets-library:")))
- return showImagePickerDialog(parent);
+ if (acceptOpen) {
+ if (directory.startsWith(QLatin1String("assets-library:")))
+ return showImagePickerDialog(parent);
+ else
+ return showNativeDocumentPickerDialog(parent);
+ }
return false;
}
@@ -102,6 +107,25 @@ bool QIOSFileDialog::showImagePickerDialog(QWindow *parent)
return true;
}
+bool QIOSFileDialog::showNativeDocumentPickerDialog(QWindow *parent)
+{
+#ifndef Q_OS_TVOS
+ if (options()->fileMode() == QFileDialogOptions::Directory ||
+ options()->fileMode() == QFileDialogOptions::DirectoryOnly)
+ return false;
+
+ m_viewController = [[QIOSDocumentPickerController alloc] initWithQIOSFileDialog:this];
+
+ UIWindow *window = parent ? reinterpret_cast<UIView *>(parent->winId()).window
+ : qt_apple_sharedApplication().keyWindow;
+ [window.rootViewController presentViewController:m_viewController animated:YES completion:nil];
+
+ return true;
+#else
+ return false;
+#endif
+}
+
void QIOSFileDialog::hide()
{
// QFileDialog will remember the last directory set, and open subsequent dialogs in the same
@@ -123,7 +147,7 @@ QList<QUrl> QIOSFileDialog::selectedFiles() const
return m_selection;
}
-void QIOSFileDialog::selectedFilesChanged(QList<QUrl> selection)
+void QIOSFileDialog::selectedFilesChanged(const QList<QUrl> &selection)
{
m_selection = selection;
emit filesSelected(m_selection);