2 * SPDX-FileCopyrightText: 2007-2011 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org>
5 * SPDX-License-Identifier: GPL-2.0-or-later
8 #ifndef DRAGANDDROPHELPER_H
9 #define DRAGANDDROPHELPER_H
11 #include "dolphin_export.h"
27 class DOLPHIN_EXPORT DragAndDropHelper
31 * Handles the dropping of URLs to the given destination. A context menu
32 * with the options 'Move Here', 'Copy Here', 'Link Here' and 'Cancel' is
33 * offered to the user. The drag destination must represent a directory or
34 * a desktop-file, otherwise the dropping gets ignored.
36 * @param destUrl URL of the item destination. Is used only if destItem::isNull()
38 * @param event Drop event.
39 * @param window Widget where the drop happened, will be used as parent of the drop menu.
40 * @return KIO::DropJob pointer or null in case the destUrl is contained
41 * in the mimeData url list.
43 static KIO::DropJob
*dropUrls(const QUrl
&destUrl
, QDropEvent
*event
, QWidget
*window
);
46 * Checks if the destination supports dropping.
48 * @param destItem The item destination.
49 * @return True if the destination is a directory and is writable, or it's a desktop file.
52 static bool supportsDropping(const KFileItem
&destItem
);
55 * Updates the drop action according to whether the destination supports dropping.
56 * If supportsDropping(destUrl), set dropAction = proposedAction. Otherwise, set
57 * dropAction = Qt::IgnoreAction.
59 * @param event Drop event.
60 * @param destUrl Destination URL.
62 static void updateDropAction(QDropEvent
*event
, const QUrl
&destUrl
);
65 * @return True if destUrl is contained in the urls parameter.
67 static bool urlListMatchesUrl(const QList
<QUrl
> &urls
, const QUrl
&destUrl
);
70 * @return True if mimeData contains Ark's drag and drop mime types.
72 static bool isArkDndMimeType(const QMimeData
*mimeData
);
73 static QString
arkDndServiceMimeType()
75 return QStringLiteral("application/x-kde-ark-dndextract-service");
77 static QString
arkDndPathMimeType()
79 return QStringLiteral("application/x-kde-ark-dndextract-path");
83 * clear the internal cache.
85 static void clearUrlListMatchesUrlCache();
89 * Stores the results of the expensive checks made in urlListMatchesUrl.
91 static QHash
<QUrl
, bool> m_urlListMatchesUrlCache
;