mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-21 17:30:15 +00:00
Dolphin: port from KonqOperations::doDrop to the new KIO::DropJob
REVIEW: 121678
This commit is contained in:
parent
119f7a3fce
commit
7bd5bec219
|
@ -23,7 +23,6 @@
|
|||
#include "dolphintabpage.h"
|
||||
#include "dolphinviewcontainer.h"
|
||||
#include "dolphin_generalsettings.h"
|
||||
#include "views/draganddrophelper.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <KConfigGroup>
|
||||
|
@ -286,13 +285,8 @@ void DolphinTabWidget::openNewActivatedTab(int index)
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,10 +28,8 @@
|
|||
#include <KFileItemActions>
|
||||
#include <KFilePlacesModel>
|
||||
#include <KLocalizedString>
|
||||
#include <KIO/NetAccess>
|
||||
#include <KIO/PreviewJob>
|
||||
#include <KMessageWidget>
|
||||
#include <konq_operations.h>
|
||||
#include <KShell>
|
||||
#include <QUrl>
|
||||
#include <KUrlComboBox>
|
||||
|
@ -45,7 +43,6 @@
|
|||
#include "filterbar/filterbar.h"
|
||||
#include "search/dolphinsearchbox.h"
|
||||
#include "statusbar/dolphinstatusbar.h"
|
||||
#include "views/draganddrophelper.h"
|
||||
#include "views/viewmodecontroller.h"
|
||||
#include "views/viewproperties.h"
|
||||
|
||||
|
@ -60,9 +57,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
|
|||
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
|
||||
|
@ -74,8 +69,6 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
|
|||
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,
|
||||
|
@ -147,6 +140,8 @@ DolphinViewContainer::DolphinViewContainer(const QUrl& url, QWidget* parent) :
|
|||
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);
|
||||
|
@ -612,41 +607,6 @@ void DolphinViewContainer::slotUrlNavigatorLocationChanged(const QUrl& url)
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -257,24 +257,6 @@ private slots:
|
|||
*/
|
||||
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
|
||||
|
@ -341,9 +323,6 @@ private:
|
|||
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;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <KJobWidgets>
|
||||
#include <KJobUiDelegate>
|
||||
#include <KIO/CopyJob>
|
||||
#include <KIO/DropJob>
|
||||
#include <KIO/FileUndoManager>
|
||||
|
||||
#include <QApplication>
|
||||
|
@ -239,10 +240,9 @@ void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* eve
|
|||
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()); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <KDirNotify>
|
||||
#include <QIcon>
|
||||
#include <KIO/Job>
|
||||
#include <KIO/DropJob>
|
||||
#include <KIO/EmptyTrashJob>
|
||||
#include <KIO/JobUiDelegate>
|
||||
#include <KJobWidgets>
|
||||
|
@ -375,11 +376,7 @@ void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
|
|||
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)
|
||||
|
@ -390,12 +387,7 @@ 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;
|
||||
|
@ -414,13 +406,10 @@ void PlacesPanel::slotAboveItemDropEvent(int index, QGraphicsSceneDragDropEvent*
|
|||
|
||||
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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -20,25 +20,20 @@
|
|||
|
||||
#include "draganddrophelper.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusConnection>
|
||||
#include <QDropEvent>
|
||||
#include <QMimeData>
|
||||
|
||||
#include <KFileItem>
|
||||
#include <KLocalizedString>
|
||||
#include <konq_operations.h>
|
||||
#include <QUrl>
|
||||
#include <QApplication>
|
||||
#include <QtDBus>
|
||||
#include <QDropEvent>
|
||||
#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;
|
||||
|
|
|
@ -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,
|
||||
static KIO::DropJob* dropUrls(const QUrl& destUrl,
|
||||
QDropEvent* event,
|
||||
QString& error);
|
||||
QWidget *window);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue