┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/dolphinview.cpp
diff options
context:
space:
mode:
authorDavid Faure <[email protected]>2007-11-15 20:04:05 +0000
committerDavid Faure <[email protected]>2007-11-15 20:04:05 +0000
commitf8302197daca5667aa3d4963528ce09e344eb27f (patch)
tree1b274b695dd4f1520efcb82651e877e42916c554 /src/dolphinview.cpp
parent247f37a58081e4debaf21a3994848971d8203be3 (diff)
Implement cut/copy/paste in dolphinpart.
Had to move more code to DolphinView, to use it from the part. svn path=/trunk/KDE/kdebase/apps/; revision=737203
Diffstat (limited to 'src/dolphinview.cpp')
-rw-r--r--src/dolphinview.cpp94
1 files changed, 92 insertions, 2 deletions
diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp
index 590a813a8..30b07ce42 100644
--- a/src/dolphinview.cpp
+++ b/src/dolphinview.cpp
@@ -29,6 +29,7 @@
#include <QBoxLayout>
#include <QTimer>
#include <QScrollBar>
+#include <QClipboard>
#include <kcolorscheme.h>
#include <kdirlister.h>
@@ -1035,7 +1036,7 @@ void DolphinView::renameSelectedItems()
KUrl newUrl = oldUrl;
newUrl.setFileName(name);
KonqOperations::rename(this, oldUrl, newUrl);
- emit renaming();
+ emit doingOperation(KonqFileUndoManager::RENAME);
}
++it;
}
@@ -1061,9 +1062,98 @@ void DolphinView::renameSelectedItems()
KUrl newUrl = oldUrl;
newUrl.setFileName(newName);
KonqOperations::rename(this, oldUrl, newUrl);
- emit renaming();
+ emit doingOperation(KonqFileUndoManager::RENAME);
+ }
+ }
+}
+
+void DolphinView::cutSelectedItems()
+{
+ QMimeData* mimeData = new QMimeData();
+ const KUrl::List kdeUrls = selectedUrls();
+ const KUrl::List mostLocalUrls;
+ KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true);
+ QApplication::clipboard()->setMimeData(mimeData);
+}
+
+void DolphinView::copySelectedItems()
+{
+ QMimeData* mimeData = new QMimeData();
+ const KUrl::List kdeUrls = selectedUrls();
+ const KUrl::List mostLocalUrls;
+ KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, false);
+ QApplication::clipboard()->setMimeData(mimeData);
+}
+
+void DolphinView::paste()
+{
+ QClipboard* clipboard = QApplication::clipboard();
+ const QMimeData* mimeData = clipboard->mimeData();
+
+ const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
+
+ // per default the pasting is done into the current Url of the view
+ KUrl destUrl(url());
+
+ // check whether the pasting should be done into a selected directory
+ const KUrl::List selectedUrls = this->selectedUrls();
+ if (selectedUrls.count() == 1) {
+ const KFileItem fileItem(S_IFDIR,
+ KFileItem::Unknown,
+ selectedUrls.first(),
+ true);
+ if (fileItem.isDir()) {
+ // only one item is selected which is a directory, hence paste
+ // into this directory
+ destUrl = selectedUrls.first();
+ }
+ }
+
+ if (KonqMimeData::decodeIsCutSelection(mimeData)) {
+ KonqOperations::copy(this, KonqOperations::MOVE, sourceUrls, destUrl);
+ emit doingOperation(KonqFileUndoManager::MOVE);
+ clipboard->clear();
+ } else {
+ KonqOperations::copy(this, KonqOperations::COPY, sourceUrls, destUrl);
+ emit doingOperation(KonqFileUndoManager::COPY);
+ }
+}
+
+QPair<bool, QString> DolphinView::pasteInfo() const
+{
+ QPair<bool, QString> ret;
+ QClipboard* clipboard = QApplication::clipboard();
+ const QMimeData* mimeData = clipboard->mimeData();
+
+ KUrl::List urls = KUrl::List::fromMimeData(mimeData);
+ if (!urls.isEmpty()) {
+ ret.first = true;
+ ret.second = i18ncp("@action:inmenu", "Paste One File", "Paste %1 Files", urls.count());
+ } else {
+ ret.first = false;
+ ret.second = i18nc("@action:inmenu", "Paste");
+ }
+
+ if (ret.first) {
+ const KUrl::List urls = selectedUrls();
+ const uint count = urls.count();
+ if (count > 1) {
+ // pasting should not be allowed when more than one file
+ // is selected
+ ret.first = false;
+ } else if (count == 1) {
+ // Only one file is selected. Pasting is only allowed if this
+ // file is a directory.
+ // TODO: this doesn't work with remote protocols; instead we need a
+ // m_activeViewContainer->selectedFileItems() to get the real KFileItems
+ const KFileItem fileItem(S_IFDIR,
+ KFileItem::Unknown,
+ urls.first(),
+ true);
+ ret.first = fileItem.isDir();
}
}
+ return ret;
}
#include "dolphinview.moc"