diff options
Diffstat (limited to 'src/plugins/platforms/winrt')
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtfiledialoghelper.cpp | 64 | ||||
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtfileengine.cpp | 36 | ||||
-rw-r--r-- | src/plugins/platforms/winrt/qwinrtfileengine.h | 1 |
3 files changed, 64 insertions, 37 deletions
diff --git a/src/plugins/platforms/winrt/qwinrtfiledialoghelper.cpp b/src/plugins/platforms/winrt/qwinrtfiledialoghelper.cpp index 6cd99c38ef..417befeb63 100644 --- a/src/plugins/platforms/winrt/qwinrtfiledialoghelper.cpp +++ b/src/plugins/platforms/winrt/qwinrtfiledialoghelper.cpp @@ -298,42 +298,48 @@ bool QWinRTFileDialogHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModalit return false; } - ComPtr<IMap<HSTRING, IVector<HSTRING> *>> choices; - hr = picker->get_FileTypeChoices(&choices); - RETURN_FALSE_IF_FAILED("Failed to get file extension choices"); - foreach (const QString &namedFilter, dialogOptions->nameFilters()) { - ComPtr<IVector<HSTRING>> entry = Make<WindowsStringVector>(); - foreach (const QString &filter, QPlatformFileDialogHelper::cleanFilterList(namedFilter)) { - // Remove leading star - const int offset = (filter.length() > 1 && filter.startsWith(QLatin1Char('*'))) ? 1 : 0; - HStringReference filterRef(reinterpret_cast<const wchar_t *>(filter.utf16() + offset), - filter.length() - offset); - hr = entry->Append(filterRef.Get()); - if (FAILED(hr)) { - qWarning("Failed to add named file filter \"%s\": %s", - qPrintable(filter), qPrintable(qt_error_string(hr))); + if (!dialogOptions->nameFilters().isEmpty()) { + ComPtr<IMap<HSTRING, IVector<HSTRING> *>> choices; + hr = picker->get_FileTypeChoices(&choices); + RETURN_FALSE_IF_FAILED("Failed to get file extension choices"); + foreach (const QString &namedFilter, dialogOptions->nameFilters()) { + ComPtr<IVector<HSTRING>> entry = Make<WindowsStringVector>(); + foreach (const QString &filter, QPlatformFileDialogHelper::cleanFilterList(namedFilter)) { + // Remove leading star + const int offset = (filter.length() > 1 && filter.startsWith(QLatin1Char('*'))) ? 1 : 0; + HStringReference filterRef(reinterpret_cast<const wchar_t *>(filter.utf16() + offset), + filter.length() - offset); + hr = entry->Append(filterRef.Get()); + if (FAILED(hr)) { + qWarning("Failed to add named file filter \"%s\": %s", + qPrintable(filter), qPrintable(qt_error_string(hr))); + } } + const int offset = namedFilter.indexOf(QLatin1String(" (")); + const QString filterTitle = namedFilter.mid(0, offset); + HStringReference namedFilterRef(reinterpret_cast<const wchar_t *>(filterTitle.utf16()), + filterTitle.length()); + boolean replaced; + hr = choices->Insert(namedFilterRef.Get(), entry.Get(), &replaced); + RETURN_FALSE_IF_FAILED("Failed to insert file extension choice entry"); } - const int offset = namedFilter.indexOf(QLatin1String(" (")); - const QString filterTitle = offset > 0 ? namedFilter.left(offset) : filterTitle; - HStringReference namedFilterRef(reinterpret_cast<const wchar_t *>(filterTitle.utf16()), - filterTitle.length()); - boolean replaced; - hr = choices->Insert(namedFilterRef.Get(), entry.Get(), &replaced); - RETURN_FALSE_IF_FAILED("Failed to insert file extension choice entry"); } const QString suffix = dialogOptions->defaultSuffix(); - HStringReference nativeSuffix(reinterpret_cast<const wchar_t *>(suffix.utf16()), - suffix.length()); - hr = picker->put_DefaultFileExtension(nativeSuffix.Get()); - RETURN_FALSE_IF_FAILED("Failed to set default file extension"); + if (!suffix.isEmpty()) { + HStringReference nativeSuffix(reinterpret_cast<const wchar_t *>(suffix.utf16()), + suffix.length()); + hr = picker->put_DefaultFileExtension(nativeSuffix.Get()); + RETURN_FALSE_IF_FAILED("Failed to set default file extension"); + } const QString suggestedName = QFileInfo(d->saveFileName.toLocalFile()).fileName(); - HStringReference nativeSuggestedName(reinterpret_cast<const wchar_t *>(suggestedName.utf16()), - suggestedName.length()); - hr = picker->put_SuggestedFileName(nativeSuggestedName.Get()); - RETURN_FALSE_IF_FAILED("Failed to set suggested file name"); + if (!suggestedName.isEmpty()) { + HStringReference nativeSuggestedName(reinterpret_cast<const wchar_t *>(suggestedName.utf16()), + suggestedName.length()); + hr = picker->put_SuggestedFileName(nativeSuggestedName.Get()); + RETURN_FALSE_IF_FAILED("Failed to set suggested file name"); + } ComPtr<IAsyncOperation<StorageFile *>> op; hr = picker->PickSaveFileAsync(&op); diff --git a/src/plugins/platforms/winrt/qwinrtfileengine.cpp b/src/plugins/platforms/winrt/qwinrtfileengine.cpp index f4e307eb07..719bb18dd6 100644 --- a/src/plugins/platforms/winrt/qwinrtfileengine.cpp +++ b/src/plugins/platforms/winrt/qwinrtfileengine.cpp @@ -70,7 +70,7 @@ class QWinRTFileEnginePrivate { public: QWinRTFileEnginePrivate(const QString &fileName, IStorageItem *file) - : fileName(fileName), file(file) + : fileName(fileName), file(file), openMode(QIODevice::NotOpen) { HRESULT hr; hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_Buffer).Get(), @@ -101,6 +101,7 @@ public: int firstDot; ComPtr<IStorageItem> file; ComPtr<IRandomAccessStream> stream; + QIODevice::OpenMode openMode; qint64 pos; @@ -203,6 +204,8 @@ bool QWinRTFileEngine::open(QIODevice::OpenMode openMode) hr = QWinRTFunctions::await(op, d->stream.GetAddressOf()); RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::OpenError, false); + d->openMode = openMode; + return SUCCEEDED(hr); } @@ -220,9 +223,33 @@ bool QWinRTFileEngine::close() hr = closable->Close(); RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::UnspecifiedError, false); d->stream.Reset(); + d->openMode = QIODevice::NotOpen; return SUCCEEDED(hr); } +bool QWinRTFileEngine::flush() +{ + Q_D(QWinRTFileEngine); + + if (!d->stream) + return false; + + if (!(d->openMode & QIODevice::WriteOnly)) + return true; + + ComPtr<IOutputStream> stream; + HRESULT hr = d->stream.As(&stream); + RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, false); + ComPtr<IAsyncOperation<bool>> flushOp; + hr = stream->FlushAsync(&flushOp); + RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, false); + boolean flushed; + hr = QWinRTFunctions::await(flushOp, &flushed); + RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, false); + + return true; +} + qint64 QWinRTFileEngine::size() const { Q_D(const QWinRTFileEngine); @@ -484,13 +511,6 @@ qint64 QWinRTFileEngine::write(const char *data, qint64 maxlen) hr = QWinRTFunctions::await(op, &length); RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, -1); - ComPtr<IAsyncOperation<bool>> flushOp; - hr = stream->FlushAsync(&flushOp); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, -1); - boolean flushed; - hr = QWinRTFunctions::await(flushOp, &flushed); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, -1); - return qint64(length); } diff --git a/src/plugins/platforms/winrt/qwinrtfileengine.h b/src/plugins/platforms/winrt/qwinrtfileengine.h index 30357759fb..983338f2e2 100644 --- a/src/plugins/platforms/winrt/qwinrtfileengine.h +++ b/src/plugins/platforms/winrt/qwinrtfileengine.h @@ -71,6 +71,7 @@ public: bool open(QIODevice::OpenMode openMode) Q_DECL_OVERRIDE; bool close() Q_DECL_OVERRIDE; + bool flush() Q_DECL_OVERRIDE; qint64 size() const Q_DECL_OVERRIDE; qint64 pos() const Q_DECL_OVERRIDE; bool seek(qint64 pos) Q_DECL_OVERRIDE; |