]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/draganddrophelper.h
GIT_SILENT Sync po/docbooks with svn
[dolphin.git] / src / views / draganddrophelper.h
1 /*
2 * SPDX-FileCopyrightText: 2007-2011 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8 #ifndef DRAGANDDROPHELPER_H
9 #define DRAGANDDROPHELPER_H
10
11 #include "dolphin_export.h"
12
13 #include <KFileItem>
14
15 #include <QList>
16 #include <QString>
17 #include <QUrl>
18
19 class QDropEvent;
20 class QMimeData;
21 class QWidget;
22 namespace KIO
23 {
24 class DropJob;
25 }
26
27 class DOLPHIN_EXPORT DragAndDropHelper
28 {
29 public:
30 /**
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.
35 *
36 * @param destUrl URL of the item destination. Is used only if destItem::isNull()
37 * is true.
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.
42 */
43 static KIO::DropJob *dropUrls(const QUrl &destUrl, QDropEvent *event, QWidget *window);
44
45 /**
46 * Checks if the destination supports dropping.
47 *
48 * @param destItem The item destination.
49 * @return True if the destination is a directory and is writable, or it's a desktop file.
50 * False otherwise.
51 */
52 static bool supportsDropping(const KFileItem &destItem);
53
54 /**
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.
58 *
59 * @param event Drop event.
60 * @param destUrl Destination URL.
61 */
62 static void updateDropAction(QDropEvent *event, const QUrl &destUrl);
63
64 /**
65 * @return True if destUrl is contained in the urls parameter.
66 */
67 static bool urlListMatchesUrl(const QList<QUrl> &urls, const QUrl &destUrl);
68
69 /**
70 * @return True if mimeData contains Ark's drag and drop mime types.
71 */
72 static bool isArkDndMimeType(const QMimeData *mimeData);
73 static QString arkDndServiceMimeType()
74 {
75 return QStringLiteral("application/x-kde-ark-dndextract-service");
76 }
77 static QString arkDndPathMimeType()
78 {
79 return QStringLiteral("application/x-kde-ark-dndextract-path");
80 }
81
82 /**
83 * clear the internal cache.
84 */
85 static void clearUrlListMatchesUrlCache();
86
87 private:
88 /**
89 * Stores the results of the expensive checks made in urlListMatchesUrl.
90 */
91 static QHash<QUrl, bool> m_urlListMatchesUrlCache;
92 };
93
94 #endif