diff options
| author | Kai Uwe Broulik <[email protected]> | 2022-04-12 15:47:42 +0200 |
|---|---|---|
| committer | Kai Uwe Broulik <[email protected]> | 2022-04-12 15:47:42 +0200 |
| commit | d5d710ed0a282089498b9370af6f0ec76f3bdc05 (patch) | |
| tree | 8f27269a6cef50ea79459de8ef57754fd40b8db8 | |
| parent | f4a94b2601a0d1d3826032cb7902db77ccc6c444 (diff) | |
| parent | 0c7f7c92ed961ce46a7b42aeeb1c30070c95ae17 (diff) | |
Merge branch 'release/22.04'
| -rw-r--r-- | src/dolphinplacesmodelsingleton.cpp | 21 | ||||
| -rw-r--r-- | src/dolphinplacesmodelsingleton.h | 3 | ||||
| -rw-r--r-- | src/views/draganddrophelper.cpp | 12 | ||||
| -rw-r--r-- | src/views/draganddrophelper.h | 9 |
4 files changed, 41 insertions, 4 deletions
diff --git a/src/dolphinplacesmodelsingleton.cpp b/src/dolphinplacesmodelsingleton.cpp index c31ffc4c3..258be155b 100644 --- a/src/dolphinplacesmodelsingleton.cpp +++ b/src/dolphinplacesmodelsingleton.cpp @@ -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) { diff --git a/src/dolphinplacesmodelsingleton.h b/src/dolphinplacesmodelsingleton.h index 996f9de78..13e119342 100644 --- a/src/dolphinplacesmodelsingleton.h +++ b/src/dolphinplacesmodelsingleton.h @@ -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; diff --git a/src/views/draganddrophelper.cpp b/src/views/draganddrophelper.cpp index 2466b2ab7..b3f2a4c3e 100644 --- a/src/views/draganddrophelper.cpp +++ b/src/views/draganddrophelper.cpp @@ -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()); +} diff --git a/src/views/draganddrophelper.h b/src/views/draganddrophelper.h index 5f9d3754b..19a30404e 100644 --- a/src/views/draganddrophelper.h +++ b/src/views/draganddrophelper.h @@ -11,9 +11,11 @@ #include "dolphin_export.h" #include <QList> +#include <QString> #include <QUrl> class QDropEvent; +class QMimeData; class QWidget; namespace KIO { class DropJob; } @@ -43,6 +45,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. */ static void clearUrlListMatchesUrlCache(); |
