6#import <Photos/Photos.h>
8#include <QtCore/qstandardpaths.h>
9#include <QtGui/qwindow.h>
12#include <QtCore/private/qcore_mac_p.h>
20#include <QtCore/qpointer.h>
49 const QString scheme = initialDir.scheme();
52 if (
directory.startsWith(
"assets-library:"_L1) || scheme ==
"assets-library"_L1)
53 return showImagePickerDialog(
parent);
55 return showNativeDocumentPickerDialog(
parent);
61void QIOSFileDialog::showImagePickerDialog_helper(
QWindow *parent)
64 [
window.rootViewController presentViewController:m_viewController animated:YES completion:nil];
67bool QIOSFileDialog::showImagePickerDialog(
QWindow *parent)
69 if (!m_viewController) {
74 m_viewController = [
plugin->createImagePickerController(
this) retain];
80 if (!m_viewController) {
81 qWarning() <<
"QIOSFileDialog: Could not resolve Qt plugin that gives access to photos on iOS";
94 const auto authStatus = [PHPhotoLibrary authorizationStatus];
95 if (authStatus == PHAuthorizationStatusAuthorized) {
96 showImagePickerDialog_helper(
parent);
97 }
else if (authStatus == PHAuthorizationStatusNotDetermined) {
98 QPointer<QWindow> winGuard(
parent);
99 QPointer<QIOSFileDialog> thisGuard(
this);
100 [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
101 dispatch_async(dispatch_get_main_queue(), ^{
102 if (status == PHAuthorizationStatusAuthorized) {
103 if (thisGuard && winGuard)
104 thisGuard->showImagePickerDialog_helper(winGuard);
106 }
else if (thisGuard) {
107 emit thisGuard->reject();
114 qWarning() <<
"QIOSFileDialog: insufficient permission, cannot pick images";
121bool QIOSFileDialog::showNativeDocumentPickerDialog(
QWindow *parent)
127 [
window.rootViewController presentViewController:m_viewController animated:YES completion:nil];
145 [m_viewController dismissViewControllerAnimated:YES completion:nil];
147 m_viewController =
nullptr;
160 if (m_selection.
count() == 1)
static QString currentPath()
Returns the absolute path of the application's current directory.
int exec(ProcessEventsFlags flags=AllEvents)
Enters the main event loop and waits until exit() is called.
void exit(int returnCode=0)
Tells the event loop to exit with a return code.
MetaDataList metaData() const
QObject * instance(int index) const
AcceptMode acceptMode() const
QUrl initialDirectory() const
QUrl directory() const override
QList< QUrl > selectedFiles() const override
bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) override
void selectedFilesChanged(const QList< QUrl > &selection)
static QIOSIntegration * instance()
qsizetype count() const noexcept
QObject * parent() const
Returns a pointer to the parent object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
UIWindow * presentationWindow(QWindow *)
GLenum GLuint GLintptr GLsizeiptr size
[1]
QItemSelection * selection
[0]