Bug 407642 - KFileWidget selects the the wrong filter on filter change with enabled automatic extensions
Summary: KFileWidget selects the the wrong filter on filter change with enabled automa...
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kio
Classification: Frameworks and Libraries
Component: Open/save dialogs (show other bugs)
Version: 5.54.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: David Faure
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-17 13:18 UTC by Jan-Marek Glogowski
Modified: 2019-05-22 08:10 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Simple test file picker program (610 bytes, text/x-c++src)
2019-05-17 13:18 UTC, Jan-Marek Glogowski
Details
qmake file (74 bytes, text/plain)
2019-05-17 13:34 UTC, Jan-Marek Glogowski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan-Marek Glogowski 2019-05-17 13:18:23 UTC
Created attachment 120135 [details]
Simple test file picker program

If your filter list has two matching filters for an extension, KFileWidget will always select the first filter, even if the current filter already matches the file name.

The result is that a user selects a filter and it's not honored by the UI. This resulted in two bugs in LibreOffice with the KDE backend:

* https://bugs.documentfoundation.org/show_bug.cgi?id=125267
* https://bugs.documentfoundation.org/show_bug.cgi?id=120950

Our workaround is now to ignore the returned filter string.
This bug doesn't happen with the non-native QFileDialog.

STEPS TO REPRODUCE
1. Compile and run the attached program
2. Make sure that "auto extension" checkbox is enable
2. Select the last file filter (DocBook (.xml)) via dropdown list

OBSERVED RESULT
Filter is "Word 2003 XML (.xml)"

EXPECTED RESULT
Filter is "DocBook (.xml)"

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Debian Buster with KIO 5.54

I already have a patch for this.
Comment 1 Jan-Marek Glogowski 2019-05-17 13:34:52 UTC
Created attachment 120136 [details]
qmake file
Comment 2 Jan-Marek Glogowski 2019-05-17 14:25:45 UTC
Patch: https://phabricator.kde.org/D21249
Comment 3 Nate Graham 2019-05-21 19:49:31 UTC
Git commit c4e90b5a6bf41816b2938dc2df4820e56ed6e42e by Nate Graham, on behalf of Jan-Marek Glogowski.
Committed on 21/05/2019 at 19:49.
Pushed by ngraham into branch 'master'.

Test current filter before setting a new one

Summary:
If KFileWidget's filter list has two matching filters for an extension,
it will always select the first filter, even if the current filter
already matches the file name.

This is fine, if you auto-select the filter to match the file name, but
breaks, if you want to auto-change the file name's extension via the
selected filter.

So this checks, if the current filter already matches the file name
before trying to find a matching filter and select it.

Test Plan:
1. Compile and run the attached program to the bug report 407642
2. Make sure that "auto extension" checkbox is enable
2. Select the last file filter (DocBook (.xml)) via dropdown list

OBSERVED RESULT
Filter is "Word 2003 XML (.xml)"

EXPECTED RESULT
Filter is "DocBook (.xml)"

Reviewers: #frameworks, ngraham, dfaure

Reviewed By: dfaure

Subscribers: elvisangelaccio, ngraham, michaelweghorn, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D21249

M  +63   -0    autotests/kfilewidgettest.cpp
M  +23   -9    src/filewidgets/kfilewidget.cpp

https://commits.kde.org/kio/c4e90b5a6bf41816b2938dc2df4820e56ed6e42e
Comment 4 Michael Weghorn 2019-05-22 08:10:13 UTC
Thanks for the fix!

I just retested and while the issue reported here is gone, the original LibrOffice use case is unfortunately still not working. I created follow-up bug report bug 407819 for this (correct filter is displayed, but not returned when calling 'QFileDialog::selectedNameFilter'.

(I tested with kio version 5.54 from Debian testing + the patch on top, since master branch has more dependencies not fulfilled in Debian testing).