[PATCH] Let KUrl::List::fromMimeData() follow XDnd spec
David Faure
faure at kde.org
Thu Nov 12 12:09:15 GMT 2009
On Thursday 12 November 2009, Tobias Koenig wrote:
> Hej,
>
> according to the XDnd spec, the URIs from a text/uri-list drag object must
> contain a hostname from where the drag where initiated. In 99% of the time
> this will be the local machine, so the hostname can be simply ignored.
> In the other 1% the drag'n'drop framework would somehow have to download
> the files locally and rewrite the uris (which seems to be a broken idea
> IMHO... well specs...)
Well, another outcome can be: with a "remote hostname", nothing will happen
(since we don't know which protocol to use), but at least you won't be copying
the file with same name on your local machine. Better not do anything than do
the wrong thing and give unexpected results.
> However in trunk, KDE applications can't accept drags from applications
> that follow the XDnd spec, because the KIO classes (or better said
> QUrl::toLocalPath()) can't handle URIs like file://myhost/tmp/foo.pdf
> correctly.
KUrl has its own KUrl::toLocalFile(), how about adding the logic there?
KUrl already has the logic to check the hostname in isLocalFile().
All we need is to fix toLocalFile() similarly.
> The attached patch simply removes the host information in
> KUrl::List::fromMimeData().
I don't think this is a good idea. It breaks the whole idea of having the
hostname in the url in the first place and can lead to unexpected behavior.
I would rather see something like this:
Index: kurl.cpp
===================================================================
--- kurl.cpp (revision 1045411)
+++ kurl.cpp (working copy)
@@ -848,7 +848,12 @@
QString KUrl::toLocalFile( AdjustPathOption trailing ) const
{
- return trailingSlash( trailing, QUrl::toLocalFile() );
+ if (hasHost() && isLocalFile()) {
+ KUrl urlWithoutHost = *this;
+ urlWithoutHost.setHost(QString());
+ return trailingSlash(trailing, urlWithoutHost.toLocalFile());
+ }
+ return trailingSlash(trailing, QUrl::toLocalFile());
}
inline static bool hasSubUrl( const QUrl& url );
Please test and add a unit test in kurltest.cpp. Thanks!
--
David Faure, faure at kde.org, http://www.davidfaure.fr
Sponsored by Nokia to work on KDE, incl. Konqueror (http://www.konqueror.org).
More information about the kde-core-devel
mailing list