File indexing completed on 2024-04-28 05:45:25
0001 /* 0002 * SPDX-FileCopyrightText: 2007-2011 Peter Penz <peter.penz19@gmail.com> 0003 * SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef DRAGANDDROPHELPER_H 0009 #define DRAGANDDROPHELPER_H 0010 0011 #include "dolphin_export.h" 0012 0013 #include <QList> 0014 #include <QString> 0015 #include <QUrl> 0016 0017 class QDropEvent; 0018 class QMimeData; 0019 class QWidget; 0020 namespace KIO 0021 { 0022 class DropJob; 0023 } 0024 0025 class DOLPHIN_EXPORT DragAndDropHelper 0026 { 0027 public: 0028 /** 0029 * Handles the dropping of URLs to the given destination. A context menu 0030 * with the options 'Move Here', 'Copy Here', 'Link Here' and 'Cancel' is 0031 * offered to the user. The drag destination must represent a directory or 0032 * a desktop-file, otherwise the dropping gets ignored. 0033 * 0034 * @param destUrl URL of the item destination. Is used only if destItem::isNull() 0035 * is true. 0036 * @param event Drop event. 0037 * @param window Widget where the drop happened, will be used as parent of the drop menu. 0038 * @return KIO::DropJob pointer or null in case the destUrl is contained 0039 * in the mimeData url list. 0040 */ 0041 static KIO::DropJob *dropUrls(const QUrl &destUrl, QDropEvent *event, QWidget *window); 0042 0043 /** 0044 * @return True if destUrl is contained in the urls parameter. 0045 */ 0046 static bool urlListMatchesUrl(const QList<QUrl> &urls, const QUrl &destUrl); 0047 0048 /** 0049 * @return True if mimeData contains Ark's drag and drop mime types. 0050 */ 0051 static bool isArkDndMimeType(const QMimeData *mimeData); 0052 static QString arkDndServiceMimeType() 0053 { 0054 return QStringLiteral("application/x-kde-ark-dndextract-service"); 0055 } 0056 static QString arkDndPathMimeType() 0057 { 0058 return QStringLiteral("application/x-kde-ark-dndextract-path"); 0059 } 0060 0061 /** 0062 * clear the internal cache. 0063 */ 0064 static void clearUrlListMatchesUrlCache(); 0065 0066 private: 0067 /** 0068 * Stores the results of the expensive checks made in urlListMatchesUrl. 0069 */ 0070 static QHash<QUrl, bool> m_urlListMatchesUrlCache; 0071 }; 0072 0073 #endif