Bug 470893 - KDE's filedialog ignores unnamed QFileDialog NameFilter
Summary: KDE's filedialog ignores unnamed QFileDialog NameFilter
Status: RESOLVED FIXED
Alias: None
Product: plasma-integration
Classification: Plasma
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-11 08:19 UTC by shenlebantongying
Modified: 2023-12-25 15:59 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description shenlebantongying 2023-06-11 08:19:50 UTC
SUMMARY

QFileDialog has an unnamed name filter, which KDE's file dialog silently ignores.

https://doc.qt.io/qt-6/qfiledialog.html#setNameFilter

Found during this kialog's bug https://bugs.kde.org/show_bug.cgi?id=467868

STEPS TO REPRODUCE

Run this code:

 ```
#include <QApplication>
#include <QFileDialog>

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

// Doesn't work on KDE (only have problem on KDE)
    auto *dlg1 = new QFileDialog();
    dlg1->setNameFilter("*.txt");
    dlg1->exec();

// Works
    auto *dlg2 = new QFileDialog();
    dlg2->setNameFilter("Force to work with KDE (*.txt)");
    dlg2->exec();

    return QApplication::exec();
}
```

OBSERVED RESULT

The dlg1's name filter is ignored in KDE :(

EXPECTED RESULT

It shouldn't

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 5.27.5
KDE Frameworks Version: 5.106.0
Qt Version: 5.15.9
Kernel Version: 6.3.5-arch1-1 (64-bit)
Comment 1 Bug Janitor Service 2023-06-24 16:21:36 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-integration/-/merge_requests/92
Comment 2 Bug Janitor Service 2023-12-21 14:46:53 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-integration/-/merge_requests/128
Comment 3 Nicolas Fella 2023-12-21 17:12:47 UTC
Git commit 8a9b3a5d31777920bf551da1bae3cf01167788ff by Nicolas Fella.
Committed on 21/12/2023 at 17:22.
Pushed by nicolasfella into branch 'master'.

Simplify file filter parsing

Currently we parse the Qt filter syntax into KDE syntax and then into KFileFilter

Cut out the middle step and directly create KFileFilter objects from the Qt filters

To parse those use the cleanFilterList helper from QPlatformFileDialogHelper

This matches what Qt's GTK file dialog integration does

It has the nice side benefit of making nameless filters work

M  +2    -1    qt6/src/platformtheme/kdeplatformfiledialogbase_p.h
M  +23   -36   qt6/src/platformtheme/kdeplatformfiledialoghelper.cpp
M  +4    -1    qt6/src/platformtheme/kdeplatformfiledialoghelper.h
M  +1    -1    qt6/src/platformtheme/kdirselectdialog.cpp
M  +1    -1    qt6/src/platformtheme/kdirselectdialog_p.h

https://invent.kde.org/plasma/plasma-integration/-/commit/8a9b3a5d31777920bf551da1bae3cf01167788ff
Comment 4 Nicolas Fella 2023-12-25 15:59:05 UTC
Git commit 925a36a0b49afa3632b1f9e64eaabedb9e3ee6c9 by Nicolas Fella.
Committed on 25/12/2023 at 16:56.
Pushed by nicolasfella into branch 'master'.

Simplify qt2KdeFilter

Use the cleanFilterList helper from QPlatformFileDialogHelper

This makes nameless filters work

M  +17   -19   qt5/src/platformtheme/kdeplatformfiledialoghelper.cpp
M  +1    -0    qt5/src/platformtheme/kdeplatformfiledialoghelper.h

https://invent.kde.org/plasma/plasma-integration/-/commit/925a36a0b49afa3632b1f9e64eaabedb9e3ee6c9