Review Request 106475: Check if the startDir has an schema before discarting it

David Faure faure at kde.org
Wed Jan 16 08:11:23 GMT 2013



> On Oct. 4, 2012, 4:28 p.m., Christoph Feck wrote:
> > Causes a regression. When using "Save Image As..." in Konqueror, the file dialog starts at "Custom Path" (and lists root folder), without remembering the previously used path.
> 
> Jonathan Marten wrote:
>     Doing the test as follows appears to work, for both local files and smb:
>     
>           if (!startDir.directory().isEmpty() ||
>               (!startDir.scheme().isEmpty() && !startDir.isLocalFile()))
>
> 
> Christoph Feck wrote:
>     If this is the correct fix, can you please commit it?

Sorry for the non working suggestion, then. But I'm still confused about this code, it doesn't make sense to me.

The current code says:
 (1) Has directory -> use full url as start dir
 (2) No scheme, or local file -> set as fileName, use default dir
 (3) Otherwise (other protocols, but with no directory) -> use full url as start dir

So, currently:
  "ftp://foo/bar/", "file:///tmp" -> full url (rule 1), OK
  "foo.jpg" -> fileName (rule 2), OK [this is the "save image as" case]
  "smb://", "smb:" -> full url (rule 3), OK  [this is the bugfix that led to this review request initially]
  "foo/bar" -> has directory, so this is used as start dir URL, i.e. the method returns a relative URL. Surprising, I wonder if it works.

The "or local file" part of rule 2 seems pointless, a file URL always has a directory ("file:" doesn't exist, and KUrl("fileName").isLocalFile() is *false* nowadays). So a file URL will always use rule 1 anyway.

My suggested patch was "if relative, set as fileName". Needs adjustment for the corner case "foo/bar", but other than that, it should work.

Proof:
  QVERIFY(KUrl("smb://").directory().isEmpty());
  QVERIFY(KUrl("blah").directory().isEmpty());
  QVERIFY(!KUrl("foo/bar").directory().isEmpty());
  QVERIFY(!KUrl("blah").isLocalFile());

Ah, the konqueror breakage comes from this code (kwebpage.cpp and khtml_ext.cpp) :

118│     const QString fileName = suggestedName.isEmpty() ? srcUrl.fileName() : suggestedName;
119│     // convert filename to URL using fromPath to avoid trouble with ':' in filenames (#184202)
120├>    KUrl destUrl = KFileDialog::getSaveFileName(KUrl::fromPath(fileName), QString(), parent);

This turns "foo.jpg" into "file:foo.jpg", i.e. "file://foo.jpg". Ouch.
More from me later...


- David


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://git.reviewboard.kde.org/r/106475/#review19914
-----------------------------------------------------------


On Sept. 17, 2012, 10:39 a.m., Àlex Fiestas wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://git.reviewboard.kde.org/r/106475/
> -----------------------------------------------------------
> 
> (Updated Sept. 17, 2012, 10:39 a.m.)
> 
> 
> Review request for kdelibs and David Faure.
> 
> 
> Description
> -------
> 
> This patch addresses the following bug:
> When an user clicks in a KUrlRequestUrl("smb://") to open the dialog, the KFIleDialog will be opened with the "current working dir" instead of smb://
> 
> Debugging the issue, I reached KFileWidget::getStartUrl, in that method there is a check that looks if the directory is not empty, in case it is the directory (startDir) is discarded in favor of some magic code that looks for recent folders blablabla.
> 
> this code apparently was added to support the case where an url is composed only by a fileName, for example when Konqueror Save as (commit 4d3933d4). So the solution I thought is to check if the schema is not empty, in case both directory and schema are empty the KUrl will be discarded as well, instead if any of them is not empty the directory will be used.
> 
> 
> Diffs
> -----
> 
>   kfile/kfilewidget.cpp 7069a49 
> 
> Diff: http://git.reviewboard.kde.org/r/106475/diff/
> 
> 
> Testing
> -------
> 
> Used Konqueror (as indicated in the commit) with both khtml and webkit.
> Tested samba-mounter
> Tested bluedevil
> 
> Everything seems to work.
> 
> 
> Thanks,
> 
> Àlex Fiestas
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20130116/ae26d375/attachment.htm>


More information about the kde-core-devel mailing list