Bug 92237 - KURLRequester requires absolute path to work
Summary: KURLRequester requires absolute path to work
Status: RESOLVED FIXED
Alias: None
Product: kfile
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: kdelibs bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-28 04:28 UTC by George Staikos
Modified: 2014-10-20 00:19 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.14.3


Attachments
Proposed fix. WARNING: newbie code! (2.87 KB, patch)
2014-05-25 22:59 UTC, SB
Details

Note You need to log in before you can comment on or make changes to this bug.
Description George Staikos 2004-10-28 04:28:38 UTC
Maybe this should be filed against kdelibs somewhere because Kst also exhibits 
this behavior.  Files that I attempt to upload in a form via a file input form 
element don't get sent (and silently not sent, no less!!!) unless I put an 
absolute path in.  However the autocompletion completes against relative 
filenames.  It's very confusing.
Comment 1 Stephan Kulow 2004-10-28 09:38:27 UTC
you confuse me
Comment 2 George Staikos 2004-10-29 05:03:08 UTC
The problem is that KURLRequester's completion object defaults to $HOME as the directory.  In Kst I setDir(QDir::currentDirPath()) to circumvent this and things work fine.  Should this not be the default?  The problem is illustrated with this code when not run from $HOME:

QString u = _url->url();
QFile f(u);
f.open(IO_ReadOnly); // fails for a file that autocompleted
Comment 3 Christoph Feck 2009-08-27 02:35:54 UTC
Moving from "kio/kfile" component to "kfile" product, helps sorting out duplicates.
Comment 4 SB 2014-05-25 22:59:53 UTC
Created attachment 86820 [details]
Proposed fix. WARNING: newbie code!

The patch fixes this pretty old bug. It also makes a few additional changes so that the set-start-directory part works as described in the doc.

I have a doubt, though:
the documentation says: "The default [...] start directory is the current working directory, or the last directory where a file has been selected.". 
Consider the following scenario: a startDir has been set programmatically via setStartDir(), then the user selects a file with the file dialog. What should be the startDir at this point? The one set with setStartDir() or the directory where a file has been selected?
In other words, wich one of these alternatives is the better one?
a) setStartDir() has the precedence, i.e. once a custom start dir has been set, it will not change when the user selects a file in a different location.
b) startDir always changes when user selects a file.
For the patch, I chose variant a).

I guess the simplest solution would be to change the documentation as follow: 
"The default [...] start directory is the current working directory." 
and - of course - change the code accrodingly. 
But this would be a change to the API, and I don't know what the rules and policies are for that...
Comment 5 Christoph Feck 2014-06-04 20:32:17 UTC
Thanks Simon for the patch. I cannot decide if it can be applied as is. Could you please create a review request at https://git.reviewboard.kde.org/ ?
Comment 6 David Faure 2014-06-22 15:24:52 UTC
I would recommend fixing one problem at a time.

For sure url() should never ever return a relative URL. Does the patch really fix this?
I don't see how (maybe that bug doesn't exist anymore?). It only seems to address the "what should the start dir be", doesn't it?
Comment 7 SB 2014-06-24 20:54:36 UTC
David, 
as I see it, it _is_ only one problem, and the bug definitely still exist. 
url() does always return an absolute path - relative paths are completed correctly against the current working dir.

The actual problem is that the base dir for the autocompletion is not set to the cwd, it will always be $HOME (the default for KUrlCompletion). 
This makes autocompletion useless, or even misleading:
if you start writing a relative path in the KLineEdit widget, the autocompleiton feature will show you choices from your home directory, leading you to believe that you're entering a path relaive to $HOME, while you're actually entering a path relative to the cwd. 

Hope this made it a little clearer...
Comment 8 SB 2014-06-26 21:33:37 UTC
Please ignore comment #7. It's plain wrong - except for the part that the bug still exists.
Today I learned that I should really test things instead of just making assumptions...
Comment 9 David Faure 2014-10-19 09:18:19 UTC
Git commit 010c241da47da7a153671e2f02d699ea2f3b7ff7 by David Faure, on behalf of Simon Bachmann.
Committed on 19/10/2014 at 09:15.
Pushed by dfaure into branch 'KDE/4.14'.

KUrlRequester: fixing handling of start directory

The handling of the start directory in the KUrlRequester was only halfway implemented:
- m_startDir (the private field holding the start directory) is not initialised - the default value of startDir() is an empty URL instead of the current working dir.
- when the start dir changes, it is not always passed to the KUrlCompletion object of the lineedit. The suggestions showed when entering a relative path into the LineEdit might be wrong as a consequence.
- when selecting a file, the start directory does not change to the directory of the selected file - the API doc says it should.
- when the user entered a relative path into the LineEdit, url() returns a relative path instead of an absolute one.
REVIEW: 119014
FIXED-IN: 4.14.3

M  +32   -4    kio/kfile/kurlrequester.cpp
M  +3    -3    kio/kfile/kurlrequester.h

http://commits.kde.org/kdelibs/010c241da47da7a153671e2f02d699ea2f3b7ff7
Comment 10 David Faure 2014-10-19 09:35:59 UTC
Git commit 2e9b9bfc61bca5a8f5708fe681f11f6ec3284850 by David Faure.
Committed on 19/10/2014 at 09:35.
Pushed by dfaure into branch 'master'.

KUrlRequester: fixing handling of start directory

Forwardport of kdelibs.git 010c241da47da7a153671e2f02d699ea2f3b7ff7

Change-Id: Ieed4b00eb0bc3f8fffd48d81fe14c31d330fd71f

M  +36   -4    src/widgets/kurlrequester.cpp
M  +3    -3    src/widgets/kurlrequester.h

http://commits.kde.org/kio/2e9b9bfc61bca5a8f5708fe681f11f6ec3284850