Commit 0c7f7c92 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[Places Panel] Support drag and drop from Ark

Accepts Ark's special dnd mime types so that archive contents can
be dragged onto a place to extract and/or (mount and) switch to the
hovered location.
parent 3bf471e0
Pipeline #163059 passed with stage
in 6 minutes and 40 seconds
......@@ -6,11 +6,13 @@
#include "dolphinplacesmodelsingleton.h"
#include "trash/dolphintrash.h"
#include "views/draganddrophelper.h"
#include <KAboutData>
#include <KFilePlacesModel>
#include <QIcon>
#include <QMimeData>
DolphinPlacesModel::DolphinPlacesModel(const QString &alternativeApplicationName, QObject *parent)
: KFilePlacesModel(alternativeApplicationName, parent)
......@@ -47,6 +49,25 @@ void DolphinPlacesModel::setPanelsLocked(bool locked)
}
}
QStringList DolphinPlacesModel::mimeTypes() const
{
QStringList types = KFilePlacesModel::mimeTypes();
types << DragAndDropHelper::arkDndServiceMimeType()
<< DragAndDropHelper::arkDndPathMimeType();
return types;
}
bool DolphinPlacesModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
// We make the view accept the drag by returning them from mimeTypes()
// but the drop should be handled exclusively by PlacesPanel::slotUrlsDropped
if (DragAndDropHelper::isArkDndMimeType(data)) {
return false;
}
return KFilePlacesModel::dropMimeData(data, action, row, column, parent);
}
QVariant DolphinPlacesModel::data(const QModelIndex &index, int role) const
{
switch (role) {
......
......@@ -29,6 +29,9 @@ public:
bool panelsLocked() const;
void setPanelsLocked(bool locked);
QStringList mimeTypes() const override;
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
protected:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
......
......@@ -35,10 +35,9 @@ bool DragAndDropHelper::urlListMatchesUrl(const QList<QUrl>& urls, const QUrl& d
KIO::DropJob* DragAndDropHelper::dropUrls(const QUrl& destUrl, QDropEvent* event, QWidget* window)
{
const QMimeData* mimeData = event->mimeData();
if (mimeData->hasFormat(QStringLiteral("application/x-kde-ark-dndextract-service")) &&
mimeData->hasFormat(QStringLiteral("application/x-kde-ark-dndextract-path"))) {
const QString remoteDBusClient = mimeData->data(QStringLiteral("application/x-kde-ark-dndextract-service"));
const QString remoteDBusPath = mimeData->data(QStringLiteral("application/x-kde-ark-dndextract-path"));
if (isArkDndMimeType(mimeData)) {
const QString remoteDBusClient = mimeData->data(arkDndServiceMimeType());
const QString remoteDBusPath = mimeData->data(arkDndPathMimeType());
QDBusMessage message = QDBusMessage::createMethodCall(remoteDBusClient, remoteDBusPath,
QStringLiteral("org.kde.ark.DndExtract"), QStringLiteral("extractSelectedFilesTo"));
......@@ -63,3 +62,8 @@ void DragAndDropHelper::clearUrlListMatchesUrlCache()
DragAndDropHelper::m_urlListMatchesUrlCache.clear();
}
bool DragAndDropHelper::isArkDndMimeType(const QMimeData *mimeData)
{
return mimeData->hasFormat(arkDndServiceMimeType())
&& mimeData->hasFormat(arkDndPathMimeType());
}
......@@ -11,9 +11,11 @@
#include "dolphin_export.h"
#include <QList>
#include <QString>
#include <QUrl>
class QDropEvent;
class QMimeData;
class QWidget;
namespace KIO { class DropJob; }
......@@ -42,6 +44,13 @@ public:
*/
static bool urlListMatchesUrl(const QList<QUrl>& urls, const QUrl& destUrl);
/**
* @return True if mimeData contains Ark's drag and drop mime types.
*/
static bool isArkDndMimeType(const QMimeData *mimeData);
static QString arkDndServiceMimeType() { return QStringLiteral("application/x-kde-ark-dndextract-service"); }
static QString arkDndPathMimeType() { return QStringLiteral("application/x-kde-ark-dndextract-path"); }
/**
* clear the internal cache.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment