| Summary: | FileChooser handles mixed types of filters inconsistently | ||
|---|---|---|---|
| Product: | [Plasma] xdg-desktop-portal-kde | Reporter: | Alfred Wingate <parona> |
| Component: | general | Assignee: | Plasma Bugs List <plasma-bugs-null> |
| Status: | CONFIRMED --- | ||
| Severity: | normal | CC: | aleixpol, nate, nicolas.fella |
| Priority: | NOR | ||
| Version First Reported In: | 6.2.4 | ||
| Target Milestone: | --- | ||
| Platform: | Other | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
| Attachments: | plasma/xdg-desktop-portal-kde: Don't ignore current_filter parameter with multiple filter strings | ||
Can reproduce. The problem seems to be that when KCoreDirLister is passed both MIME filters and name filters it treats them so that both must match for a file to be shown, which is not what we want here Created attachment 176601 [details]
plasma/xdg-desktop-portal-kde: Don't ignore current_filter parameter with multiple filter strings
The current_filter one is a different issue (Scenario 5 vs 6), as filters with more than one string* are explicitly ignored.
With this patch it works as expected on my end. (Scenario 6 gets me two working filters and it picks "Windows Executable/MSI Installer" as the default one even if I change order of the filters)
I'm not familiar with portal internals so I don't how much input validation is needed here, but I don't think its right reject this.
* I don't know what the correct terminology is. pattern? filter rule?
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kio/-/merge_requests/1769 (In reply to Alfred Wingate from comment #3) > Created attachment 176601 [details] > plasma/xdg-desktop-portal-kde: Don't ignore current_filter parameter with > multiple filter strings > > The current_filter one is a different issue (Scenario 5 vs 6), as filters > with more than one string* are explicitly ignored. > > With this patch it works as expected on my end. (Scenario 6 gets me two > working filters and it picks "Windows Executable/MSI Installer" as the > default one even if I change order of the filters) > > I'm not familiar with portal internals so I don't how much input validation > is needed here, but I don't think its right reject this. > > * I don't know what the correct terminology is. pattern? filter rule? You're right, this seems wrong and is a leftover from previous refactoring. Can you make a merge request with your change? A possibly relevant merge request was started @ https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/336 Git commit 4655b7e8cd0109ac6168c4dd824c179638049511 by Nicolas Fella. Committed on 14/12/2024 at 14:38. Pushed by cullmann into branch 'master'. [kfilefiltercombo] Fix creating 'All supported types' filter We would only pass the mime types and discard the name patterns M +19 -0 autotests/kfilefiltercombotest.cpp M +6 -4 src/filewidgets/kfilefiltercombo.cpp https://invent.kde.org/frameworks/kio/-/commit/4655b7e8cd0109ac6168c4dd824c179638049511 Git commit f5b2d63442dd569d66737631e60c1fc956a9d13f by Nicolas Fella, on behalf of Alfred Wingate. Committed on 15/12/2024 at 15:46. Pushed by nicolasfella into branch 'master'. [FileChooser] Don't ignore current_filter parameter with multiple name patterns Signed-off-by: Alfred Wingate <parona@protonmail.com> M +2 -2 src/filechooser.cpp https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/commit/f5b2d63442dd569d66737631e60c1fc956a9d13f Git commit e92de218b2e1bd75167a4bede437fe52db082c80 by Nicolas Fella, on behalf of Alfred Wingate. Committed on 15/12/2024 at 15:57. Pushed by nicolasfella into branch 'Plasma/6.2'. [FileChooser] Don't ignore current_filter parameter with multiple name patterns Signed-off-by: Alfred Wingate <parona@protonmail.com> (cherry picked from commit f5b2d63442dd569d66737631e60c1fc956a9d13f) M +2 -2 src/filechooser.cpp https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/commit/e92de218b2e1bd75167a4bede437fe52db082c80 |
SUMMARY FileChooser mangles filters if mimetypes and globs are mixed. Even ignoring current_filter in some cases. I'll be using gdbus and GVariant format out of convenience. I initially encountered this behaviour in a GTK program after porting FileChooserDialog to FileChooserNative. GTK dialog worked as expected. SCENARIO 1 Two filters both using globs. $ gdbus call --session --dest org.freedesktop.portal.Desktop --object-path /org/freedesktop/portal/desktop --method org.freedesktop.portal.FileChooser.OpenFile "" "Please choose a file" "{ 'filters': <[ ( 'Windows Executable/MSI Installer', [ (@u 0, '*.[mM][sS][iI]'), (@u 0, '*.[eE][xX][eE]') ]), ( 'Any file', [ (@u 0, '*') ]) ]> }" { 'filters': <[ ( 'Windows Executable/MSI Installer', [ (@u 0, '*.[mM][sS][iI]'), (@u 0, '*.[eE][xX][eE]') ] ), ( 'Any file', [ (@u 0, '*') ] ) ]> } RESULT Works as expected with "Windows Executable/MSI Installer" as the default filter. SCENARIO 2 Filter with one mimetype and a filter with one glob $ gdbus call --session --dest org.freedesktop.portal.Desktop --object-path /org/freedesktop/portal/desktop --method org.freedesktop.portal.FileChooser.OpenFile "" "Please choose a file" "{ 'filters': <[ ( 'Windows Executable', [ (@u 1, 'application/x-ms-dos-executable') ]), ( 'Any file', [ (@u 0, '*') ]) ]> }" { 'filters': <[ ( 'Windows Executable', [ (@u 1, 'application/x-ms-dos-executable') ] ), ( 'Any file', [ (@u 0, '*') ] ) ]> } RESULT An additional filter "Windows Executable, Any file" is shown and selected. It only shows files of type application/x-ms-dos-executable. SCENARIO 3 Filter with two mimetypes and a filter with one glob $ gdbus call --session --dest org.freedesktop.portal.Desktop --object-path /org/freedesktop/portal/desktop --method org.freedesktop.portal.FileChooser.OpenFile "" "Please choose a file" "{ 'multiple': <false>, 'filters': <[ ( 'Windows Executable/MSI Installer', [ (@u 1, 'application/x-ms-dos-executable'), (@u 1, 'application/x-msi') ]), ( 'Any file', [ (@u 0, '*') ]) ]> }" { 'multiple': <false>, 'filters': <[ ( 'Windows Executable/MSI Installer', [ (@u 1, 'application/x-ms-dos-executable'), (@u 1, 'application/x-msi') ] ), ( 'Any file', [ (@u 0, '*') ] ) ]> } RESULT An additional filter "Windows Executable/MSI Installer, Any file" is shown and selected. It shows nothing. SCENARIO 4 Two filters both using globs, but with the second filter as the current_filter. $ gdbus call --session --dest org.freedesktop.portal.Desktop --object-path /org/freedesktop/portal/desktop --method org.freedesktop.portal.FileChooser.OpenFile "" "Please choose a file" "{ 'filters': <[ ( 'Windows Executable/MSI Installer', [ (@u 0, '*.[mM][sS][iI]'), (@u 0, '*.[eE][xX][eE]') ]), ( 'Any file', [ (@u 0, '*') ]) ]>, 'current_filter': <( 'Any file', [ (@u 0, '*') ])> }" { 'filters': <[ ( 'Windows Executable/MSI Installer', [ (@u 0, '*.[mM][sS][iI]'), (@u 0, '*.[eE][xX][eE]') ] ), ( 'Any file', [ (@u 0, '*') ] ) ]>, 'current_filter': <( 'Any file', [ (@u 0, '*') ] )> } RESULT Works as expected with "Any file" as the default filter. SCENARIO 5 Filter with two mimetypes and a filter with one glob, but with the second filter as the current_filter. $ gdbus call --session --dest org.freedesktop.portal.Desktop --object-path /org/freedesktop/portal/desktop --method org.freedesktop.portal.FileChooser.OpenFile "" "Please choose a file" "{ 'filters': <[ ( 'Windows Executable/MSI Installer', [ (@u 1, 'application/x-ms-dos-executable'), (@u 1, 'application/x-msi') ]), ( 'Any file', [ (@u 0, '*') ]) ]>, 'current_filter': <( 'Any file', [ (@u 0, '*') ])> }" { 'filters': <[ ( 'Windows Executable/MSI Installer', [ (@u 1, 'application/x-ms-dos-executable'), (@u 1, 'application/x-msi') ] ), ( 'Any file', [ (@u 0, '*') ] ) ]>, 'current_filter': <( 'Any file', [ (@u 0, '*') ] )> } RESULT Works as expected with "Any file" as the default filter and no extra mangled filter. SCENARIO 6 Filter with two mimetypes and a filter with one glob, but with the first filter as the current_filter. $ gdbus call --session --dest org.freedesktop.portal.Desktop --object-path /org/freedesktop/portal/desktop --method org.freedesktop.portal.FileChooser.OpenFile "" "Please choose a file" "{ 'filters': <[ ( 'Windows Executable/MSI Installer', [ (@u 1, 'application/x-ms-dos-executable'), (@u 1, 'application/x-msi') ]), ( 'Any file', [ (@u 0, '*') ]) ]>, 'current_filter': <( 'Windows Executable/MSI Installer', [ (@u 1, 'application/x-ms-dos-executable'), (@u 1, 'application/x-msi') ])> }" { 'filters': <[ ( 'Windows Executable/MSI Installer', [ (@u 1, 'application/x-ms-dos-executable'), (@u 1, 'application/x-msi') ] ), ( 'Any file', [ (@u 0, '*') ] ) ]>, 'current_filter': <( 'Windows Executable/MSI Installer', [ (@u 1, 'application/x-ms-dos-executable'), (@u 1, 'application/x-msi') ] )> } RESULT An additional filter "Windows Executable/MSI Installer, Any file" is shown and selected. It shows nothing SOFTWARE/OS VERSIONS Operating System: Gentoo Linux 2.17 KDE Plasma Version: 6.2.4 KDE Frameworks Version: 6.8.0 Qt Version: 6.8.1 Kernel Version: 6.12.4-xanmod1-dist (64-bit) Graphics Platform: Wayland Processors: 12 × AMD Ryzen 5 3600 6-Core Processor Memory: 47.0 GiB of RAM Graphics Processor: AMD Radeon RX 5700 XT