Linux showPlatformDialog messes up file names.

3 posts / 0 new
Last post
peterv
Offline
Last seen: 7 months 2 days ago
Joined: 10 Oct 2008 - 12:54
Linux showPlatformDialog messes up file names.

As the title says, the FileChooser returns true if cancel button is pressed with browseForFileToSave(true). Also when I want to save a file using FileChooser and browseForFileToSave function I get an additional character (") in the name textfield. Deleting the character and saving a file also results in having a character appended on the saved filename .I am using the native file chooser. On my Mac this does not happen only on Linux.

UPDATE:

Had to rename the title, because its not a FileChooser problem, its a Linux native showPlatformDialog problem. If I use the JUCE file dialog, I dont have any problems.

I debugged the showPlatformDialog and the strange thing is that somethings wrong with the escape character. The zenity command lokks like this:
zenity --file-selection --title=\\"Please select the file to save new database to...\\" --filename=\\"/home/peter\\" --save 2>&1

and when I choose a file the result is:
/home/peter/Desktop/testfile.sqlite\\n


Peter

jfitzpat
Offline
Last seen: 2 weeks 1 day ago
Joined: 10 Jan 2012 - 05:29
Re: Linux showPlatformDialog messes up file names.

This seems to be two bugs in the Linux FileChooser::showPlatformDialog. The criticl part of the original looks like this:

    ChildProcess child;
    if (child.start (command))
    {
        const String result (child.readAllProcessOutput());
        StringArray tokens;

        if (selectMultipleFiles)
            tokens.addTokens (result, separator, "\"");
        else
            tokens.add (result);

        for (int i = 0; i < tokens.size(); i++)
            results.add (File (tokens[i]));

        child.waitForProcessToFinish (60 * 1000);
    }

It doesn't check for "" returned from readAllProcessOutput(), so it doesn't handle cancel. Also, if you capture the same zenity command line from a terminal, you will see that the \n at the end is also normal. So I tweaked the function to this:

    ChildProcess child;
    if (child.start (command))
    {
        const String result (child.readAllProcessOutput().trim());

        if (result.isNotEmpty())
        {
            StringArray tokens;

            if (selectMultipleFiles)
                tokens.addTokens (result, separator, "\"");
            else
                tokens.add (result);

            for (int i = 0; i < tokens.size(); i++)
                results.add (File (tokens[i]));
        }

        child.waitForProcessToFinish (60 * 1000);
    }

Basically, .trim() the results from readAllProcessOutput(), and then only add tokens if the string isn't empty. This seemed to help a lot in getting the latest Introjucer to work as well. Module path and file open seemed to have corrupt (\n) file values from the native file chooser as well.

jules
Offline
Last seen: 11 hours 12 min ago
Joined: 29 Apr 2013 - 18:37
Re: Linux showPlatformDialog messes up file names.

Great, much appreciated!