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.
you confuse me
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
Moving from "kio/kfile" component to "kfile" product, helps sorting out duplicates.
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...
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/ ?
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?
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...
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...
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
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