#include "dolphintabpage.h"
#include "dolphinviewcontainer.h"
#include "dolphin_generalsettings.h"
-#include "views/draganddrophelper.h"
#include <QApplication>
#include <KConfigGroup>
void DolphinTabWidget::tabDropEvent(int index, QDropEvent* event)
{
if (index >= 0) {
- const DolphinView* view = tabPageAt(index)->activeViewContainer()->view();
-
- QString error;
- DragAndDropHelper::dropUrls(view->rootItem(), view->url(), event, error);
- if (!error.isEmpty()) {
- currentTabPage()->activeViewContainer()->showMessage(error, DolphinViewContainer::Error);
- }
+ DolphinView* view = tabPageAt(index)->activeViewContainer()->view();
+ view->dropUrls(view->url(), event);
}
}
#include <KFileItemActions>
#include <KFilePlacesModel>
#include <KLocalizedString>
-#include <KIO/NetAccess>
#include <KIO/PreviewJob>
#include <KMessageWidget>
-#include <konq_operations.h>
#include <KShell>
#include <QUrl>
#include <KUrlComboBox>
#include "filterbar/filterbar.h"
#include "search/dolphinsearchbox.h"
#include "statusbar/dolphinstatusbar.h"
-#include "views/draganddrophelper.h"
#include "views/viewmodecontroller.h"
#include "views/viewproperties.h"
m_statusBar(0),
m_statusBarTimer(0),
m_statusBarTimestamp(),
- m_autoGrabFocus(true),
- m_dropDestination(),
- m_dropEvent(0)
+ m_autoGrabFocus(true)
#ifdef KActivities_FOUND
, m_activityResourceInstance(0)
#endif
m_topLayout->setMargin(0);
m_urlNavigator = new KUrlNavigator(new KFilePlacesModel(this), url, this);
- connect(m_urlNavigator, &KUrlNavigator::urlsDropped,
- this, &DolphinViewContainer::dropUrls);
connect(m_urlNavigator, &KUrlNavigator::activated,
this, &DolphinViewContainer::activate);
connect(m_urlNavigator->editor(), &KUrlComboBox::completionModeChanged,
this, &DolphinViewContainer::slotHistoryChanged);
connect(m_urlNavigator, &KUrlNavigator::returnPressed,
this, &DolphinViewContainer::slotReturnPressed);
+ connect(m_urlNavigator, &KUrlNavigator::urlsDropped,
+ m_view, &DolphinView::dropUrls);
// Initialize status bar
m_statusBar = new DolphinStatusBar(this);
}
}
-void DolphinViewContainer::dropUrls(const QUrl& destination, QDropEvent* event)
-{
- m_dropDestination = destination;
-
- const QMimeData* mimeData = event->mimeData();
- QMimeData* mimeDataCopy = new QMimeData;
- foreach (const QString& format, mimeData->formats()) {
- mimeDataCopy->setData(format, mimeData->data(format));
- }
-
- m_dropEvent.reset(new QDropEvent(event->pos(),
- event->possibleActions(),
- mimeDataCopy,
- event->mouseButtons(),
- event->keyboardModifiers()));
-
- QTimer::singleShot(0, this, SLOT(dropUrlsDelayed()));
-}
-
-void DolphinViewContainer::dropUrlsDelayed()
-{
- if (m_dropEvent.isNull()) {
- return;
- }
-
- QString error;
- DragAndDropHelper::dropUrls(KFileItem(), m_dropDestination, m_dropEvent.data(), error);
- if (!error.isEmpty()) {
- showMessage(error, Error);
- }
-
- delete m_dropEvent->mimeData();
- m_dropEvent.reset();
-}
-
void DolphinViewContainer::redirect(const QUrl& oldUrl, const QUrl& newUrl)
{
Q_UNUSED(oldUrl);
*/
void slotUrlNavigatorLocationChanged(const QUrl& url);
- /**
- * Is connected with the URL navigator and drops the URLs
- * above the destination \a destination.
- *
- * Creates a copy of \a event and invokes \a dropUrlsDelayed with a
- * queued connection.
- */
- void dropUrls(const QUrl& destination, QDropEvent* event);
-
- /**
- * Is invoked with a queued connection by \a dropUrls to prevent that the
- * drop actions are executed in the URL navigator menu's nested event loop,
- * which might cause a crash. Simply using a queued connection from the URL
- * navigator to \a dropUrls would not work because the \a event pointer
- * would be dangling then.
- */
- void dropUrlsDelayed();
-
/**
* Is invoked when a redirection is done and changes the
* URL of the URL navigator to \a newUrl without triggering
QElapsedTimer m_statusBarTimestamp; // Time in ms since last update
bool m_autoGrabFocus;
- QUrl m_dropDestination;
- QScopedPointer<QDropEvent> m_dropEvent;
-
#ifdef KF5Activities_FOUND
private:
KActivities::ResourceInstance * m_activityResourceInstance;
#include <KJobWidgets>
#include <KJobUiDelegate>
#include <KIO/CopyJob>
+#include <KIO/DropJob>
#include <KIO/FileUndoManager>
#include <QApplication>
event->buttons(),
event->modifiers());
- QString error;
- DragAndDropHelper::dropUrls(destItem, destItem.url(), &dropEvent, error);
- if (!error.isEmpty()) {
- emit errorMessage(error);
+ KIO::DropJob *job = DragAndDropHelper::dropUrls(destItem.url(), &dropEvent, this);
+ if (job) {
+ connect(job, &KIO::DropJob::result, this, [this](KJob *job) { if (job->error()) emit errorMessage(job->errorString()); });
}
}
}
#include <KDirNotify>
#include <QIcon>
#include <KIO/Job>
+#include <KIO/DropJob>
#include <KIO/EmptyTrashJob>
#include <KIO/JobUiDelegate>
#include <KJobWidgets>
event->buttons(),
event->modifiers());
- QString error;
- DragAndDropHelper::dropUrls(KFileItem(), destUrl, &dropEvent, error);
- if (!error.isEmpty()) {
- emit errorMessage(error);
- }
+ slotUrlsDropped(destUrl, &dropEvent, this);
}
void PlacesPanel::slotItemDropEventStorageSetupDone(int index, bool success)
if ((index == m_itemDropEventIndex) && m_itemDropEvent && m_itemDropEventMimeData) {
if (success) {
QUrl destUrl = m_model->placesItem(index)->url();
-
- QString error;
- DragAndDropHelper::dropUrls(KFileItem(), destUrl, m_itemDropEvent, error);
- if (!error.isEmpty()) {
- emit errorMessage(error);
- }
+ slotUrlsDropped(destUrl, m_itemDropEvent, this);
}
delete m_itemDropEventMimeData;
void PlacesPanel::slotUrlsDropped(const QUrl& dest, QDropEvent* event, QWidget* parent)
{
- Q_UNUSED(parent);
- QString error;
- DragAndDropHelper::dropUrls(KFileItem(), dest, event, error);
- if (!error.isEmpty()) {
- emit errorMessage(error);
+ KIO::DropJob *job = DragAndDropHelper::dropUrls(dest, event, parent);
+ if (job) {
+ connect(job, &KIO::DropJob::result, this, [this](KJob *job) { if (job->error()) emit errorMessage(job->errorString()); });
}
-
}
void PlacesPanel::slotTrashUpdated(KJob* job)
#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"
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)
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);
}
*/
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. */
#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")) {
"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;
#include <QString>
-class KFileItem;
class QUrl;
class QDropEvent;
-class KonqOperations;
+class QWidget;
+namespace KIO { class DropJob; }
class LIBDOLPHINPRIVATE_EXPORT DragAndDropHelper
{
* 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