From 76735f3fa0fdf772aa4fba9a9aaa241415eaf922 Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@digia.com>
Date: Wed, 5 Nov 2014 14:57:03 +0100
Subject: [PATCH] Windows native file dialog: Work around display bug of
 IFileDialog.

Any filter not filtering on suffix shows up duplicated in filter
combo.

Change-Id: I9fc9e33b6081cf6894fabc6dd52c12a4d3dfd393
Task-number: QTBUG-42405
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
---
 .../platforms/windows/qwindowsdialoghelpers.cpp     | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
index 4cbead44c51..f1f472b3e26 100644
--- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
+++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp
@@ -1224,16 +1224,21 @@ void QWindowsNativeFileDialogBase::setNameFilters(const QStringList &filters)
     QScopedArrayPointer<WCHAR> buffer(new WCHAR[totalStringLength + 2 * size]);
     QScopedArrayPointer<COMDLG_FILTERSPEC> comFilterSpec(new COMDLG_FILTERSPEC[size]);
 
-    const QString matchesAll = QStringLiteral(" (*)");
     WCHAR *ptr = buffer.data();
     // Split filter specification as 'Texts (*.txt[;] *.doc)'
     // into description and filters specification as '*.txt;*.doc'
 
     for (int i = 0; i < size; ++i) {
-        // Display glitch (CLSID only): 'All files (*)' shows up as 'All files (*) (*)'
+        // Display glitch (CLSID only): Any filter not filtering on suffix (such as
+        // '*', 'a.*') will be duplicated in combo: 'All files (*) (*)',
+        // 'AAA files (a.*) (a.*)'
         QString description = specs[i].description;
-        if (!m_hideFiltersDetails && description.endsWith(matchesAll))
-            description.truncate(description.size() - matchesAll.size());
+        const QString &filter = specs[i].filter;
+        if (!m_hideFiltersDetails && !filter.startsWith(QLatin1String("*."))) {
+            const int pos = description.lastIndexOf(QLatin1Char('('));
+            if (pos > 0)
+                description.truncate(pos);
+        }
         // Add to buffer.
         comFilterSpec[i].pszName = ptr;
         ptr += description.toWCharArray(ptr);
-- 
GitLab