┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/views
diff options
context:
space:
mode:
authorDavid Faure <[email protected]>2014-12-26 08:57:42 +0100
committerDavid Faure <[email protected]>2015-01-05 09:07:10 +0100
commit7bd5bec21977c733dd3e1fc70f5afd66dda3ab97 (patch)
treec05c3ecc54e25320dbd609ae65b6afdc23d07c0d /src/views
parent119f7a3fce241efddc7e7f9eef8e729cf9ad35c2 (diff)
Dolphin: port from KonqOperations::doDrop to the new KIO::DropJob
REVIEW: 121678
Diffstat (limited to 'src/views')
-rw-r--r--src/views/dolphinview.cpp25
-rw-r--r--src/views/dolphinview.h5
-rw-r--r--src/views/draganddrophelper.cpp39
-rw-r--r--src/views/draganddrophelper.h21
4 files changed, 39 insertions, 51 deletions
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index cb25c6555..32e182ce7 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -51,13 +51,13 @@
#include <KIO/JobUiDelegate>
#include <KIO/NetAccess>
#include <KIO/PreviewJob>
+#include <KIO/DropJob>
#include <KIO/PasteJob>
#include <KIO/Paste>
#include <KJob>
#include <QMenu>
#include <KMessageBox>
#include <KJobWidgets>
-#include <konq_operations.h>
#include <QUrl>
#include "dolphinnewfilemenuobserver.h"
@@ -1039,22 +1039,22 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
event->mimeData(),
event->buttons(),
event->modifiers());
+ dropUrls(destUrl, &dropEvent);
- QString error;
- KonqOperations* job = DragAndDropHelper::dropUrls(destItem, destUrl, &dropEvent, error);
- if (!error.isEmpty()) {
- emit infoMessage(error);
- }
+ setActive(true);
+}
+
+void DolphinView::dropUrls(const QUrl &destUrl, QDropEvent *dropEvent)
+{
+ KIO::DropJob* job = DragAndDropHelper::dropUrls(destUrl, dropEvent, this);
if (job && destUrl == url()) {
// Mark the dropped urls as selected.
m_clearSelectionBeforeSelectingNewItems = true;
m_markFirstNewlySelectedItemAsCurrent = true;
- connect(job, &KonqOperations::itemCreated, this, &DolphinView::slotItemCreated);
- //connect(job, &KIO::InteractiveDropJob::result, this, &DolphinView::slotPasteJobResult);
+ connect(job, &KIO::DropJob::itemCreated, this, &DolphinView::slotItemCreated);
+ connect(job, &KIO::DropJob::result, this, &DolphinView::slotPasteJobResult);
}
-
- setActive(true);
}
void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* previous)
@@ -1096,8 +1096,11 @@ void DolphinView::slotItemCreated(const QUrl& url)
m_selectedUrls << url;
}
-void DolphinView::slotPasteJobResult(KJob *)
+void DolphinView::slotPasteJobResult(KJob *job)
{
+ if (job->error()) {
+ emit errorMessage(job->errorString());
+ }
if (!m_selectedUrls.isEmpty()) {
m_selectedUrls << KDirModel::simplifiedUrlList(m_selectedUrls);
}
diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h
index c054c311a..aa4492bc3 100644
--- a/src/views/dolphinview.h
+++ b/src/views/dolphinview.h
@@ -362,6 +362,11 @@ public slots:
*/
void pasteIntoFolder();
+ /**
+ * Handles a drop of @p dropEvent onto @p destUrl
+ */
+ void dropUrls(const QUrl &destUrl, QDropEvent *dropEvent);
+
void stopLoading();
/** Activates the view if the item list container gets focus. */
diff --git a/src/views/draganddrophelper.cpp b/src/views/draganddrophelper.cpp
index a09faa345..f740fd520 100644
--- a/src/views/draganddrophelper.cpp
+++ b/src/views/draganddrophelper.cpp
@@ -20,25 +20,20 @@
#include "draganddrophelper.h"
-#include <KFileItem>
-#include <KLocalizedString>
-#include <konq_operations.h>
#include <QUrl>
-#include <QApplication>
-#include <QtDBus>
+#include <QDBusMessage>
+#include <QDBusConnection>
#include <QDropEvent>
+#include <QMimeData>
+
+#include <KFileItem>
+#include <KLocalizedString>
#include <KUrlMimeData>
+#include <KIO/DropJob>
+#include <KJobWidgets>
-KonqOperations* DragAndDropHelper::dropUrls(const KFileItem& destItem, const QUrl& destUrl, QDropEvent* event, QString& error)
+KIO::DropJob* DragAndDropHelper::dropUrls(const QUrl& destUrl, QDropEvent* event, QWidget* window)
{
- error.clear();
-
- if (!destItem.isNull() && !destItem.isWritable()) {
- error = xi18nc("@info:status", "Access denied. Could not write to <filename>%1</filename>",
- destUrl.toDisplayString(QUrl::PreferLocalFile));
- return 0;
- }
-
const QMimeData* mimeData = event->mimeData();
if (mimeData->hasFormat("application/x-kde-ark-dndextract-service") &&
mimeData->hasFormat("application/x-kde-ark-dndextract-path")) {
@@ -49,19 +44,11 @@ KonqOperations* DragAndDropHelper::dropUrls(const KFileItem& destItem, const QUr
"org.kde.ark.DndExtract", "extractSelectedFilesTo");
message.setArguments({destUrl.toDisplayString(QUrl::PreferLocalFile)});
QDBusConnection::sessionBus().call(message);
- } else if (!destItem.isNull() && (destItem.isDir() || destItem.isDesktopFile())) {
- // Drop into a directory or a desktop-file
- const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData);
- foreach (const QUrl& url, urls) {
- if (url == destUrl) {
- error = i18nc("@info:status", "A folder cannot be dropped into itself");
- return 0;
- }
- }
-
- return KonqOperations::doDrop(destItem, destUrl, event, QApplication::activeWindow(), QList<QAction*>());
} else {
- return KonqOperations::doDrop(KFileItem(), destUrl, event, QApplication::activeWindow(), QList<QAction*>());
+ // Drop into a directory or a desktop-file
+ KIO::DropJob *job = KIO::drop(event, destUrl);
+ KJobWidgets::setWindow(job, window);
+ return job;
}
return 0;
diff --git a/src/views/draganddrophelper.h b/src/views/draganddrophelper.h
index c4ae974b5..85268eb4f 100644
--- a/src/views/draganddrophelper.h
+++ b/src/views/draganddrophelper.h
@@ -25,10 +25,10 @@
#include <QString>
-class KFileItem;
class QUrl;
class QDropEvent;
-class KonqOperations;
+class QWidget;
+namespace KIO { class DropJob; }
class LIBDOLPHINPRIVATE_EXPORT DragAndDropHelper
{
@@ -39,22 +39,15 @@ public:
* offered to the user. The drag destination must represent a directory or
* a desktop-file, otherwise the dropping gets ignored.
*
- * @param destItem Item of the destination. Can be 0 (KFileItem::isNull()) if
- * no file-item is available for the destination. In this case
- * destUrl is used as fallback. For performance reasons it is
- * recommended to pass a file-item if available.
* @param destUrl URL of the item destination. Is used only if destItem::isNull()
* is true.
* @param event Drop event.
- * @param error Error message intended to be shown for users if dropping is not
- * possible. If an empty string is returned, the dropping has been
- * successful.
- * @return KonqOperations pointer
+ * @param window Associated widget.
+ * @return KIO::DropJob pointer
*/
- static KonqOperations* dropUrls(const KFileItem& destItem,
- const QUrl& destUrl,
- QDropEvent* event,
- QString& error);
+ static KIO::DropJob* dropUrls(const QUrl& destUrl,
+ QDropEvent* event,
+ QWidget *window);
};
#endif