Bug 185463

Summary: KFileDialog::getSaveUrl() and similar will not accept a non-local start directory
Product: [Frameworks and Libraries] kdelibs Reporter: Jonathan Marten <jjm>
Component: generalAssignee: kdelibs bugs <kdelibs-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: bugzilla.kde
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Proposed patch
Updated patch

Description Jonathan Marten 2009-02-24 18:58:28 UTC
Version:            (using Devel)
OS:                Linux
Installed from:    Compiled sources

If a non-local 'dir' parameter is specified to KFileDialog::getSaveUrl() - and possibly getSaveFileName() and getSaveFilenameWid() also - the remote protocol is lost and the local directory of the remote URL's path is selected.

For example, if a starting directory of "ftp://user@hostname/home/user/filename" is specified, the dialogue opens with "/home/user" listed and "filename" selected.  Clicking "Save" tries to save to the local file, not via the ftp protocol.

KFileDialog::getSaveurl() does:

    bool defaultDir = dir.isEmpty();
    bool specialDir = !defaultDir && dir.protocol()=="kfiledialog";
    KFileDialog dlg(specialDir ? dir : KUrl(), filter, parent);
    if ( !specialDir )
        dlg.setSelection( dir.url() );

KFileWidget::setSelection(url) calls KFileWidgetPrivate::setLocationText(url), which in turn calls KFileWidget::setURL(url.path()).  This discards the original protocol information from the URL and lists the local directory with that path.

Applying the attached patch to kdelibs/kfile/kfilewidget.cpp appears to solve the problem.  Could a kfile expert check it?
Comment 1 Jonathan Marten 2009-02-24 18:59:52 UTC
Created attachment 31612 [details]
Proposed patch
Comment 2 Jonathan Marten 2009-02-25 18:11:57 UTC
Created attachment 31635 [details]
Updated patch

The previous patch doesn't work in the case where no starting location but only a file name is specified - it selects the root directory in that case.
Comment 3 Ben Boeckel 2009-05-28 06:36:17 UTC
Hmm, I see something like this when trying to open a remote file. I traverse to /home/boeckb/ on the remote server (via sftp) and when I choose the file, the places widget jump me to my local /home/boeckb/ causing the file to not be found. Bug #194385
Comment 4 Jonathan Marten 2009-07-20 11:16:29 UTC
Fixed by commit 951469.