summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2016-09-28 13:58:56 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2016-10-26 08:55:10 +0000
commit99ce5d5e85007cb656cd48ab161be14af8f16238 (patch)
tree45a1f975156cd16fd5505793de0ca3df583cad45
parent60dbd80e5a26182b3ed9e2c60bb7212dfd32632b (diff)
iOS: refactor usage of photos into optional plugin
Starting from iOS 10, apps that tries to access photos on the device need to specify the reason for this up front by adding the key 'NSPhotoLibraryUsageDescription' into Info.plist. If the key is missing, the app will be rejected from AppStore. This causes problems for the iOS plugin as it stands since parts of it already tries to access photos, e.g to show an image picker dialog if a file dialog is set to open QStandardPaths::PicturesLocation. This means that currently, all apps written with Qt will be rejected from AppStore unless the developer adds this key, whether he tries to access photos or not. To solve this, we choose to split the plugin into two parts, one that contains the core functionality, and one that contains optional support. The latter will need to be enabled explicit by the developer in the pro file, or in this case, indirectly by adding the right key to the Info.plist. This patch refactors the code in the plugin that gives access to photos into a separate optional plugin called 'nsphotolibrarysupport'. Change-Id: Ic4351eb0bbfffdf840fd88cd00bb29a25907798f Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Jake Petroules <jake.petroules@qt.io>
-rw-r--r--src/gui/gui.pro1
-rw-r--r--src/plugins/platforms/ios/ios.pro63
-rw-r--r--src/plugins/platforms/ios/kernel.pro58
-rw-r--r--src/plugins/platforms/ios/optional/nsphotolibrarysupport/nsphotolibrarysupport.pro22
-rw-r--r--src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.json3
-rw-r--r--src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.mm64
-rw-r--r--src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h (renamed from src/plugins/platforms/ios/qiosfileengineassetslibrary.h)2
-rw-r--r--src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm (renamed from src/plugins/platforms/ios/qiosfileengineassetslibrary.mm)2
-rw-r--r--src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h (renamed from src/plugins/platforms/ios/qiosfileenginefactory.h)2
-rw-r--r--src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h42
-rw-r--r--src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm66
-rw-r--r--src/plugins/platforms/ios/optional/optional.pro2
-rw-r--r--src/plugins/platforms/ios/qiosfiledialog.h2
-rw-r--r--src/plugins/platforms/ios/qiosfiledialog.mm79
-rw-r--r--src/plugins/platforms/ios/qiosintegration.h7
-rw-r--r--src/plugins/platforms/ios/qiosintegration.mm8
-rw-r--r--src/plugins/platforms/ios/qiosoptionalplugininterface.h59
17 files changed, 370 insertions, 112 deletions
diff --git a/src/gui/gui.pro b/src/gui/gui.pro
index 69434e801f..2cdb3a7ab7 100644
--- a/src/gui/gui.pro
+++ b/src/gui/gui.pro
@@ -9,6 +9,7 @@ QMAKE_DOCS = $$PWD/doc/qtgui.qdocconf
MODULE_PLUGIN_TYPES = \
platforms \
+ platforms/darwin \
xcbglintegrations \
platformthemes \
platforminputcontexts \
diff --git a/src/plugins/platforms/ios/ios.pro b/src/plugins/platforms/ios/ios.pro
index 545db8c093..594ccefcf1 100644
--- a/src/plugins/platforms/ios/ios.pro
+++ b/src/plugins/platforms/ios/ios.pro
@@ -1,61 +1,2 @@
-TARGET = qios
-
-QT += core-private gui-private platformsupport-private
-LIBS += -framework Foundation -framework UIKit -framework QuartzCore -framework AssetsLibrary
-
-OBJECTIVE_SOURCES = \
- plugin.mm \
- qiosintegration.mm \
- qioseventdispatcher.mm \
- qioswindow.mm \
- qiosscreen.mm \
- qiosbackingstore.mm \
- qiosapplicationdelegate.mm \
- qiosapplicationstate.mm \
- qiosviewcontroller.mm \
- qioscontext.mm \
- qiosinputcontext.mm \
- qiostheme.mm \
- qiosglobal.mm \
- qiosservices.mm \
- quiview.mm \
- qiosclipboard.mm \
- quiaccessibilityelement.mm \
- qiosplatformaccessibility.mm \
- qiostextresponder.mm \
- qiosmenu.mm \
- qiosfileengineassetslibrary.mm \
- qiosfiledialog.mm
-
-HEADERS = \
- qiosintegration.h \
- qioseventdispatcher.h \
- qioswindow.h \
- qiosscreen.h \
- qiosbackingstore.h \
- qiosapplicationdelegate.h \
- qiosapplicationstate.h \
- qiosviewcontroller.h \
- qioscontext.h \
- qiosinputcontext.h \
- qiostheme.h \
- qiosglobal.h \
- qiosservices.h \
- quiview.h \
- qiosclipboard.h \
- quiaccessibilityelement.h \
- qiosplatformaccessibility.h \
- qiostextresponder.h \
- qiosmenu.h \
- qiosfileenginefactory.h \
- qiosfileengineassetslibrary.h \
- qiosfiledialog.h
-
-OTHER_FILES = \
- quiview_textinput.mm \
- quiview_accessibility.mm
-
-PLUGIN_TYPE = platforms
-PLUGIN_CLASS_NAME = QIOSIntegrationPlugin
-!equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = -
-load(qt_plugin)
+TEMPLATE = subdirs
+SUBDIRS = kernel.pro optional
diff --git a/src/plugins/platforms/ios/kernel.pro b/src/plugins/platforms/ios/kernel.pro
new file mode 100644
index 0000000000..84035877c5
--- /dev/null
+++ b/src/plugins/platforms/ios/kernel.pro
@@ -0,0 +1,58 @@
+TARGET = qios
+
+QT += core-private gui-private platformsupport-private
+LIBS += -framework Foundation -framework UIKit -framework QuartzCore
+
+OBJECTIVE_SOURCES = \
+ plugin.mm \
+ qiosintegration.mm \
+ qioseventdispatcher.mm \
+ qioswindow.mm \
+ qiosscreen.mm \
+ qiosbackingstore.mm \
+ qiosapplicationdelegate.mm \
+ qiosapplicationstate.mm \
+ qiosviewcontroller.mm \
+ qioscontext.mm \
+ qiosinputcontext.mm \
+ qiostheme.mm \
+ qiosglobal.mm \
+ qiosservices.mm \
+ quiview.mm \
+ qiosclipboard.mm \
+ quiaccessibilityelement.mm \
+ qiosplatformaccessibility.mm \
+ qiostextresponder.mm \
+ qiosmenu.mm \
+ qiosfiledialog.mm
+
+HEADERS = \
+ qiosintegration.h \
+ qioseventdispatcher.h \
+ qioswindow.h \
+ qiosscreen.h \
+ qiosbackingstore.h \
+ qiosapplicationdelegate.h \
+ qiosapplicationstate.h \
+ qiosviewcontroller.h \
+ qioscontext.h \
+ qiosinputcontext.h \
+ qiostheme.h \
+ qiosglobal.h \
+ qiosservices.h \
+ quiview.h \
+ qiosclipboard.h \
+ quiaccessibilityelement.h \
+ qiosplatformaccessibility.h \
+ qiostextresponder.h \
+ qiosmenu.h \
+ qiosfiledialog.h
+
+OTHER_FILES = \
+ quiview_textinput.mm \
+ quiview_accessibility.mm
+
+PLUGIN_TYPE = platforms
+PLUGIN_CLASS_NAME = QIOSIntegrationPlugin
+!equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = -
+load(qt_plugin)
diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/nsphotolibrarysupport.pro b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/nsphotolibrarysupport.pro
new file mode 100644
index 0000000000..f4588dda03
--- /dev/null
+++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/nsphotolibrarysupport.pro
@@ -0,0 +1,22 @@
+TARGET = qiosnsphotolibrarysupport
+
+QT += core gui gui-private
+LIBS += -framework UIKit -framework AssetsLibrary
+
+HEADERS = \
+ qiosfileengineassetslibrary.h \
+ qiosfileenginefactory.h \
+ qiosimagepickercontroller.h
+
+OBJECTIVE_SOURCES = \
+ plugin.mm \
+ qiosfileengineassetslibrary.mm \
+ qiosimagepickercontroller.mm \
+
+OTHER_FILES = \
+ plugin.json
+
+PLUGIN_CLASS_NAME = QIosOptionalPlugin_NSPhotoLibrary
+PLUGIN_EXTENDS = -
+PLUGIN_TYPE = platforms/darwin
+load(qt_plugin)
diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.json b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.json
new file mode 100644
index 0000000000..4491fb3d59
--- /dev/null
+++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.json
@@ -0,0 +1,3 @@
+{
+ "Keys": [ "NSPhotoLibrarySupport" ]
+}
diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.mm b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.mm
new file mode 100644
index 0000000000..2ec0d33a41
--- /dev/null
+++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.mm
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "../../qiosoptionalplugininterface.h"
+#include "../../qiosfiledialog.h"
+
+#include "qiosimagepickercontroller.h"
+#include "qiosfileenginefactory.h"
+
+QT_BEGIN_NAMESPACE
+
+class QIosOptionalPlugin_NSPhotoLibrary : public QObject, QIosOptionalPluginInterface
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QIosOptionalPluginInterface_iid FILE "plugin.json")
+ Q_INTERFACES(QIosOptionalPluginInterface)
+
+public:
+ explicit QIosOptionalPlugin_NSPhotoLibrary(QObject* = 0) {};
+ ~QIosOptionalPlugin_NSPhotoLibrary() {}
+
+ UIViewController* createImagePickerController(QIOSFileDialog *fileDialog) const override
+ {
+ return [[[QIOSImagePickerController alloc] initWithQIOSFileDialog:fileDialog] autorelease];
+ }
+
+private:
+ QIOSFileEngineFactory m_fileEngineFactory;
+
+};
+
+QT_END_NAMESPACE
+
+#include "plugin.moc"
diff --git a/src/plugins/platforms/ios/qiosfileengineassetslibrary.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h
index 37bbc7bf23..0e29a1003e 100644
--- a/src/plugins/platforms/ios/qiosfileengineassetslibrary.h
+++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
diff --git a/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm
index bb12c164d6..2e88c37c01 100644
--- a/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm
+++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
diff --git a/src/plugins/platforms/ios/qiosfileenginefactory.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h
index a8604c77d1..29f543caae 100644
--- a/src/plugins/platforms/ios/qiosfileenginefactory.h
+++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h
new file mode 100644
index 0000000000..df3f6b9fa3
--- /dev/null
+++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h
@@ -0,0 +1,42 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#import <UIKit/UIKit.h>
+
+#include "../../qiosfiledialog.h"
+
+@interface QIOSImagePickerController : UIImagePickerController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
+ QIOSFileDialog *m_fileDialog;
+}
+- (id)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog;
+@end
diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm
new file mode 100644
index 0000000000..f9662b964a
--- /dev/null
+++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#import <UIKit/UIKit.h>
+
+#include "qiosimagepickercontroller.h"
+
+@implementation QIOSImagePickerController
+
+- (id)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog
+{
+ self = [super init];
+ if (self) {
+ m_fileDialog = fileDialog;
+ [self setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
+ [self setDelegate:self];
+ }
+ return self;
+}
+
+- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
+{
+ Q_UNUSED(picker);
+ NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
+ QUrl fileUrl = QUrl::fromLocalFile(QString::fromNSString([url description]));
+ m_fileDialog->selectedFilesChanged(QList<QUrl>() << fileUrl);
+ emit m_fileDialog->accept();
+}
+
+- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
+{
+ Q_UNUSED(picker)
+ emit m_fileDialog->reject();
+}
+
+@end
diff --git a/src/plugins/platforms/ios/optional/optional.pro b/src/plugins/platforms/ios/optional/optional.pro
new file mode 100644
index 0000000000..5e3421a025
--- /dev/null
+++ b/src/plugins/platforms/ios/optional/optional.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+SUBDIRS = nsphotolibrarysupport
diff --git a/src/plugins/platforms/ios/qiosfiledialog.h b/src/plugins/platforms/ios/qiosfiledialog.h
index b4bf85edd9..668cf18caf 100644
--- a/src/plugins/platforms/ios/qiosfiledialog.h
+++ b/src/plugins/platforms/ios/qiosfiledialog.h
@@ -66,6 +66,8 @@ private:
QList<QUrl> m_selection;
QEventLoop m_eventLoop;
UIViewController *m_viewController;
+
+ bool showImagePickerDialog(QWindow *parent);
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/ios/qiosfiledialog.mm b/src/plugins/platforms/ios/qiosfiledialog.mm
index 7c32784e9d..a70eb11ef8 100644
--- a/src/plugins/platforms/ios/qiosfiledialog.mm
+++ b/src/plugins/platforms/ios/qiosfiledialog.mm
@@ -31,52 +31,18 @@
**
****************************************************************************/
-#include "qiosfiledialog.h"
-
#import <UIKit/UIKit.h>
#include <QtCore/qstandardpaths.h>
#include <QtGui/qwindow.h>
+#include <QDebug>
-@interface QIOSImagePickerController : UIImagePickerController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
- QIOSFileDialog *m_fileDialog;
-}
-@end
-
-@implementation QIOSImagePickerController
-
-- (id)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog
-{
- self = [super init];
- if (self) {
- m_fileDialog = fileDialog;
- [self setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
- [self setDelegate:self];
- }
- return self;
-}
-
-- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
-{
- Q_UNUSED(picker);
- NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
- QUrl fileUrl = QUrl::fromLocalFile(QString::fromNSString([url description]));
- m_fileDialog->selectedFilesChanged(QList<QUrl>() << fileUrl);
- emit m_fileDialog->accept();
-}
-
-- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
-{
- Q_UNUSED(picker)
- emit m_fileDialog->reject();
-}
-
-@end
-
-// --------------------------------------------------------------------------
+#include "qiosfiledialog.h"
+#include "qiosintegration.h"
+#include "qiosoptionalplugininterface.h"
QIOSFileDialog::QIOSFileDialog()
- : m_viewController(0)
+ : m_viewController(Q_NULLPTR)
{
}
@@ -98,17 +64,36 @@ 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:"))) {
- m_viewController = [[QIOSImagePickerController alloc] initWithQIOSFileDialog:this];
- UIWindow *window = parent ? reinterpret_cast<UIView *>(parent->winId()).window
- : [UIApplication sharedApplication].keyWindow;
- [window.rootViewController presentViewController:m_viewController animated:YES completion:nil];
- return true;
- }
+ if (acceptOpen && directory.startsWith(QLatin1String("assets-library:")))
+ return showImagePickerDialog(parent);
return false;
}
+bool QIOSFileDialog::showImagePickerDialog(QWindow *parent)
+{
+ if (!m_viewController) {
+ QFactoryLoader *plugins = QIOSIntegration::instance()->optionalPlugins();
+ for (int i = 0; i < plugins->metaData().size(); ++i) {
+ QIosOptionalPluginInterface *plugin = qobject_cast<QIosOptionalPluginInterface *>(plugins->instance(i));
+ m_viewController = [plugin->createImagePickerController(this) retain];
+ if (m_viewController)
+ break;
+ }
+ }
+
+ if (!m_viewController) {
+ qWarning() << "QIOSFileDialog: Could not resolve Qt plugin that gives access to photos on iOS";
+ return false;
+ }
+
+ UIWindow *window = parent ? reinterpret_cast<UIView *>(parent->winId()).window
+ : [UIApplication sharedApplication].keyWindow;
+ [window.rootViewController presentViewController:m_viewController animated:YES completion:nil];
+
+ return true;
+}
+
void QIOSFileDialog::hide()
{
// QFileDialog will remember the last directory set, and open subsequent dialogs in the same
@@ -120,6 +105,8 @@ void QIOSFileDialog::hide()
emit directoryEntered(QUrl::fromLocalFile(QDir::currentPath()));
[m_viewController dismissViewControllerAnimated:YES completion:nil];
+ [m_viewController release];
+ m_viewController = Q_NULLPTR;
m_eventLoop.exit();
}
diff --git a/src/plugins/platforms/ios/qiosintegration.h b/src/plugins/platforms/ios/qiosintegration.h
index 7d23fe1d62..25eb8990cb 100644
--- a/src/plugins/platforms/ios/qiosintegration.h
+++ b/src/plugins/platforms/ios/qiosintegration.h
@@ -38,8 +38,9 @@
#include <qpa/qplatformnativeinterface.h>
#include <qpa/qwindowsysteminterface.h>
+#include <QtCore/private/qfactoryloader_p.h>
+
#include "qiosapplicationstate.h"
-#include "qiosfileenginefactory.h"
QT_BEGIN_NAMESPACE
@@ -91,6 +92,8 @@ public:
void setDebugWindowManagement(bool);
bool debugWindowManagement() const;
+ QFactoryLoader *optionalPlugins() { return m_optionalPlugins; }
+
private:
QPlatformFontDatabase *m_fontDatabase;
QPlatformClipboard *m_clipboard;
@@ -99,7 +102,7 @@ private:
QIOSApplicationState m_applicationState;
QIOSServices *m_platformServices;
mutable QPlatformAccessibility *m_accessibility;
- QIOSFileEngineFactory m_fileEngineFactory;
+ QFactoryLoader *m_optionalPlugins;
bool m_debugWindowManagement;
};
diff --git a/src/plugins/platforms/ios/qiosintegration.mm b/src/plugins/platforms/ios/qiosintegration.mm
index 85b5c477cc..d33c8cf47c 100644
--- a/src/plugins/platforms/ios/qiosintegration.mm
+++ b/src/plugins/platforms/ios/qiosintegration.mm
@@ -43,6 +43,7 @@
#include "qiosinputcontext.h"
#include "qiostheme.h"
#include "qiosservices.h"
+#include "qiosoptionalplugininterface.h"
#include <QtGui/private/qguiapplication_p.h>
@@ -68,6 +69,7 @@ QIOSIntegration::QIOSIntegration()
, m_inputContext(0)
, m_platformServices(new QIOSServices)
, m_accessibility(0)
+ , m_optionalPlugins(new QFactoryLoader(QIosOptionalPluginInterface_iid, QLatin1String("/platforms/darwin")))
, m_debugWindowManagement(false)
{
if (![UIApplication sharedApplication]) {
@@ -112,6 +114,9 @@ QIOSIntegration::QIOSIntegration()
m_touchDevice->setCapabilities(touchCapabilities);
QWindowSystemInterface::registerTouchDevice(m_touchDevice);
QMacInternalPasteboardMime::initializeMimeTypes();
+
+ for (int i = 0; i < m_optionalPlugins->metaData().size(); ++i)
+ qobject_cast<QIosOptionalPluginInterface *>(m_optionalPlugins->instance(i))->initPlugin();
}
QIOSIntegration::~QIOSIntegration()
@@ -134,6 +139,9 @@ QIOSIntegration::~QIOSIntegration()
delete m_accessibility;
m_accessibility = 0;
+
+ delete m_optionalPlugins;
+ m_optionalPlugins = 0;
}
bool QIOSIntegration::hasCapability(Capability cap) const
diff --git a/src/plugins/platforms/ios/qiosoptionalplugininterface.h b/src/plugins/platforms/ios/qiosoptionalplugininterface.h
new file mode 100644
index 0000000000..bcb8978e02
--- /dev/null
+++ b/src/plugins/platforms/ios/qiosoptionalplugininterface.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QIOPLUGININTERFACE_H
+#define QIOPLUGININTERFACE_H
+
+#include <QtCore/QtPlugin>
+
+#include "qiosfiledialog.h"
+
+QT_BEGIN_NAMESPACE
+
+Q_FORWARD_DECLARE_OBJC_CLASS(UIViewController);
+
+#define QIosOptionalPluginInterface_iid "org.qt-project.Qt.QPA.ios.optional"
+
+class QIosOptionalPluginInterface
+{
+public:
+ virtual ~QIosOptionalPluginInterface() {}
+ virtual void initPlugin() const {};
+ virtual UIViewController* createImagePickerController(QIOSFileDialog *) const { return Q_NULLPTR; };
+};
+
+Q_DECLARE_INTERFACE(QIosOptionalPluginInterface, QIosOptionalPluginInterface_iid)
+
+QT_END_NAMESPACE
+
+#endif // QIOPLUGININTERFACE_H