summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2012-10-04 11:36:11 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-04 11:58:48 +0200
commitbf55c0ac3b9c4ab8ab900ebdf2347faa1f17e12b (patch)
tree2651d6673fc044917eeb58ae553c9d55d4c19a69 /src
parentd24b867e56e7e4519185f37c12f02bcebd1c31f2 (diff)
Windows: Append file suffix in save-dialog.
Task-number: QTBUG-27186 Change-Id: I04304fce1cbf6fb6794f352ff896eb463699d42b Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/windows/qwindowsdialoghelpers.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
index 8b053a5ee4..34c8d69668 100644
--- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
+++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
@@ -1025,6 +1025,26 @@ public:
virtual QStringList selectedFiles() const;
};
+// Append a suffix from the name filter "Foo files (*.foo;*.bar)"
+// unless the file name already has one.
+static inline QString appendSuffix(const QString &fileName, const QString &filter)
+{
+ const int lastDot = fileName.lastIndexOf(QLatin1Char('.'));
+ const int lastSlash = fileName.lastIndexOf(QLatin1Char('/'));
+ if (lastDot >= 0 && (lastSlash == -1 || lastDot > lastSlash))
+ return fileName;
+ int suffixPos = filter.indexOf(QLatin1String("(*."));
+ if (suffixPos < 0)
+ return fileName;
+ suffixPos += 3;
+ int endPos = filter.indexOf(QLatin1Char(';'), suffixPos + 1);
+ if (endPos < 0)
+ endPos = filter.indexOf(QLatin1Char(')'), suffixPos + 1);
+ if (endPos < 0)
+ return fileName;
+ return fileName + QLatin1Char('.') + filter.mid(suffixPos, endPos - suffixPos);
+}
+
QPlatformDialogHelper::DialogCode QWindowsNativeSaveFileDialog::fileResult(QStringList *result /* = 0 */) const
{
if (result)
@@ -1034,7 +1054,7 @@ QPlatformDialogHelper::DialogCode QWindowsNativeSaveFileDialog::fileResult(QStri
if (FAILED(hr) || !item)
return QPlatformDialogHelper::Rejected;
if (result)
- result->push_back(QWindowsNativeFileDialogBase::itemPath(item));
+ result->push_back(appendSuffix(QWindowsNativeFileDialogBase::itemPath(item), selectedNameFilter()));
return QPlatformDialogHelper::Accepted;
}