Linux showPlatformDialog messes up file names.

For Linux specific issues

Linux showPlatformDialog messes up file names.

Postby peterv » Wed Feb 01, 2012 5:14 pm

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:
Code: Select all
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:
Code: Select all
/home/peter/Desktop/testfile.sqlite\\n



Peter
peterv
JUCE Geek
 
Posts: 44
Joined: Fri Oct 10, 2008 12:54 pm

Re: Linux showPlatformDialog messes up file names.

Postby jfitzpat » Sat Mar 17, 2012 4:29 am

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

Code: Select all
    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:

Code: Select all
    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.
User avatar
jfitzpat
JUCE UberWeenie
 
Posts: 251
Joined: Tue Jan 10, 2012 6:29 am
Location: Glendale, California

Re: Linux showPlatformDialog messes up file names.

Postby jules » Sun Mar 18, 2012 4:23 pm

Great, much appreciated!
User avatar
jules
Fearless Leader
 
Posts: 17218
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK


Return to Linux

Who is online

Users browsing this forum: No registered users and 1 guest