Extension filtering on Linux with KDialog appears to be broken

I am using JUCE 6.0.1 on Ubuntu 20.04 with KDE (and have kdialog installed on system)

Following piece of code produces a kdialog window but it does not put restriction on the extensions like documented in FileChooser class.

FileChooser chooser{"Select files...",
                            File::getSpecialLocation(File::userHomeDirectory),
                            "*.mp3"};
        if (chooser.browseForMultipleFilesToOpen())
        {
            for (auto& url : chooser.getURLResults())
            {
                // do something;
            }
        }

I’ve confirmed that dialog being opened is indeed kdialog using xprop.

As per documentation of KDialog wildcard arguments should be wrapped in brackets like this: "Some helpful description (*.mp3)" however JUCE seems to be supplying them without round brackets as per this file: https://github.com/juce-framework/JUCE/blob/55df0897d104c9a20a1363c748389d821a7cea1f/modules/juce_gui_basics/native/juce_linux_FileChooser.cpp

I’ve confirmed by running command directly from terminal that passing wildcard with brackets indeed works.

Ref: https://techbase.kde.org/Development/Tutorials/Shell_Scripting_with_KDE_Dialogs#Example_28._--getopenfilename_dialog_box

This might be a KDE-specific issue as I can set the filter with no issues on Ubuntu 18.04 with GNOME, although adding parens works too so we could add this if it fixes KDE. Can you try changing this line in juce_linux_FileChooser.cpp to the following:

args.add ("(" + owner.filters.replaceCharacter (';', ' ') + ")");

and see if the filter is set correctly?

Yes, it’s KDE specific. It does work after I modified juce_linux_FileChooser.cpp while checking what args it uses for kdialog.

Digging more into KDialog documentation I found that what JUCE does is also supposed to work but for some reason it is not working.

Example 28: https://techbase.kde.org/Development/Tutorials/Shell_Scripting_with_KDE_Dialogs#Example_28._--getopenfilename_dialog_box

It only uses the extension in single quote. However when I try that from command line it does not work. Using (*.mp3) does work. So maybe it used to work before and Kdialog is now broken. I can’t say for sure.

OK, well if that fixes KDE and things still work correctly on GNOME then it seems like the way to go. We’ll get that added.

1 Like