diff options
author | Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com> | 2015-02-18 13:43:02 +0100 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com> | 2015-03-15 23:05:09 +0000 |
commit | a273ca9c439b515358607acd05fd90346b49a448 (patch) | |
tree | 9782dccbdadd55405d959fc8f86776b0e73b49cc /src/plugins | |
parent | 3806dc3571c6d3a3295b752e2ad001156dcef956 (diff) |
iOS: return file urls rather than asset urls from file dialog
We need to pass the asset url around as a file url in the
application, so that QUrl::fromLocalFile()/toLocalFile()
works.
Note that QUrl::fromLocalFile() will remove double slashes.
We therefore need to check for this, and restore missing
slashes, when loading files in the file engine.
Change-Id: I2de6b91d7a112354590cf2981f7b403eacf92a59
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/ios/qiosfiledialog.mm | 3 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qiosfileengineassetslibrary.mm | 24 |
2 files changed, 19 insertions, 8 deletions
diff --git a/src/plugins/platforms/ios/qiosfiledialog.mm b/src/plugins/platforms/ios/qiosfiledialog.mm index 1d4298a158..28b9c0d883 100644 --- a/src/plugins/platforms/ios/qiosfiledialog.mm +++ b/src/plugins/platforms/ios/qiosfiledialog.mm @@ -60,7 +60,8 @@ { Q_UNUSED(picker); NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL]; - m_fileDialog->selectedFilesChanged(QList<QUrl>() << QUrl::fromNSURL(url)); + QUrl fileUrl = QUrl::fromLocalFile(QString::fromNSString([url description])); + m_fileDialog->selectedFilesChanged(QList<QUrl>() << fileUrl); emit m_fileDialog->accept(); } diff --git a/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm b/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm index c4be7cf4dc..73bfc2a87f 100644 --- a/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm +++ b/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm @@ -42,9 +42,9 @@ class QIOSAssetData : public QObject { public: - QIOSAssetData(const QString &fileName, QIOSFileEngineAssetsLibrary *engine) + QIOSAssetData(const QString &assetUrl, QIOSFileEngineAssetsLibrary *engine) : m_asset(0) - , m_fileName(fileName) + , m_assetUrl(assetUrl) , m_assetLibrary(0) { switch ([ALAssetsLibrary authorizationStatus]) { @@ -71,7 +71,7 @@ public: // reuse its data. Since QFile is (mostly) reentrant, we need to protect m_currentAssetData // from being modified by several threads at the same time. QMutexLocker lock(&g_mutex); - if (g_currentAssetData && g_currentAssetData->m_fileName == fileName) { + if (g_currentAssetData && g_currentAssetData->m_assetUrl == assetUrl) { m_assetLibrary = [g_currentAssetData->m_assetLibrary retain]; m_asset = [g_currentAssetData->m_asset retain]; return; @@ -87,7 +87,7 @@ public: dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - NSURL *url = [NSURL URLWithString:m_fileName.toNSString()]; + NSURL *url = [NSURL URLWithString:assetUrl.toNSString()]; m_assetLibrary = [[ALAssetsLibrary alloc] init]; [m_assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) { m_asset = [asset retain]; @@ -117,7 +117,7 @@ public: ALAsset *m_asset; private: - QString m_fileName; + QString m_assetUrl; ALAssetsLibrary *m_assetLibrary; static QBasicMutex g_mutex; @@ -143,8 +143,18 @@ QIOSFileEngineAssetsLibrary::~QIOSFileEngineAssetsLibrary() ALAsset *QIOSFileEngineAssetsLibrary::loadAsset() const { - if (!m_data) - m_data = new QIOSAssetData(m_fileName, const_cast<QIOSFileEngineAssetsLibrary *>(this)); + if (!m_data) { + // QUrl::fromLocalFile() will remove double slashes. Since the asset url is passed around as a file + // name in the app (and converted to/from a file url, e.g in QFileDialog), we need to check if we still + // have two leading slashes after the scheme, and restore the second slash if not. + QString assetUrl = m_fileName; + const int index = 16; // "assets-library://" + if (assetUrl[index] != QLatin1Char('/')) + assetUrl.insert(index, '/'); + + m_data = new QIOSAssetData(assetUrl, const_cast<QIOSFileEngineAssetsLibrary *>(this)); + } + return m_data->m_asset; } |