UDS_TARGET_URL issues with copy, drag/drop and "add to places"
nf2
nf2 at scheinwelt.at
Fri Sep 19 14:02:40 BST 2008
Hi,
First a little explanation:
An uds-entry which defines UDS_TARGET_URL is a kind of phantom in a
directory listing. The file doesn't really exist in this directory, but
in a different hierarchy.
This means: Usually KFileItem::url() and KFileItem::targetUrl() return
the same url, but not when UDS_TARGET_URL is defined.
Samples use cases are:
* listing a smb workgroup smb://workgroup/*
smb://workgroup/server -> smb://server
smb://workgroup/server2 -> smb://server2
* results of a desktop search (i guess, but didn't check in detail)
* in my gio bridge:
remote:///ftp as user on ftp.server.org -> ftp://user@ftp.server.org
For the last example this means:
KFileItem::url() = "remote:///ftp as user on ftp.server.org" (UDS_NAME
is just a display-name).
KFileItem::targetUrl() = "ftp://user@ftp.server.org"
Dolphin already follows KFileItem::targetUrl(), but only when clicking
on such an item. Bookmarking, copying, drag&drop hasn't been fixed yet.
At the moment KFileItem::url() is used for bookmarking, copying,
drag&drop, but that doesn't work - or wouldn't make sense, because
either there is no file at KFileItem::url() - or it's just a
placeholder. I think KFileItem::targetUrl() has to be used for those
operations as well...
Here are some changes i did in my working copy. Thanks to David and
Kevin for helping me.
1) For bookmarking via "add to places" i did a change in:
Index: apps/dolphin/src/dolphincontextmenu.cpp
===================================================================
--- apps/dolphin/src/dolphincontextmenu.cpp (revision 861725)
+++ apps/dolphin/src/dolphincontextmenu.cpp (working copy)
@@ -213,9 +213,19 @@
QAction* activatedAction = popup->exec(QCursor::pos());
if ((addToPlacesAction != 0) && (activatedAction ==
addToPlacesAction)) {
- const KUrl selectedUrl(m_fileInfo.url());
+ const KUrl selectedUrl(m_fileInfo.targetUrl());
if (selectedUrl.isValid()) {
-
DolphinSettings::instance().placesModel()->addPlace(placesName(selectedUrl),
+ QString name;
+ if (m_fileInfo.url() != m_fileInfo.targetUrl() &&
!m_fileInfo.text().isEmpty()) {
+ // this is pointing to a different hierarchy
+ // UDS_DISPLAY_NAME might be a good choice
+ name = m_fileInfo.text();
+ }
+ else
+ {
+ name = placesName(selectedUrl);
+ }
+ DolphinSettings::instance().placesModel()->addPlace(name,
selectedUrl);
}
}
2) For drag and drop i had to change KDirModel::mimeData()
Index: kio/kio/kdirmodel.cpp
===================================================================
--- kio/kio/kdirmodel.cpp (revision 861858)
+++ kio/kio/kdirmodel.cpp (working copy)
@@ -603,7 +603,7 @@
{
KUrl::List urls;
foreach ( const QModelIndex &index, indexes ) {
- urls << d->nodeForIndex( index )->item().url();
+ urls << d->nodeForIndex( index )->item().targetUrl();
}
QMimeData *data = new QMimeData();
urls.populateMimeData( data );
2) For "copy" i changed DolphinView::selectedUrls()
Index: apps/dolphin/src/dolphinview.cpp
===================================================================
--- apps/dolphin/src/dolphinview.cpp (revision 862586)
+++ apps/dolphin/src/dolphinview.cpp (working copy)
@@ -327,7 +327,7 @@
KUrl::List urls;
const KFileItemList list = selectedItems();
foreach (const KFileItem &item, list) {
- urls.append(item.url());
+ urls.append(item.targetUrl());
}
return urls;
}
Of course this is a quite tricky issue. It will need more work to find
out if it doesn't break things elsewhere... And i didn't look at
DolphinView::renameSelectedItems() yet.
Another thing i would like to introduce, is an UDS_ switch to forbid
copy/drag&drop, because for instance for smb://workgroup/server it might
not be a good idea to allow this (while for search results it might be ok).
Regards,
Norbert
More information about the kde-core-devel
mailing list