KCoreAddons

kurlmimedata.h
1 /*
2  This file is part of the KDE libraries
3 
4  SPDX-FileCopyrightText: 2005-2012 David Faure <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #ifndef KURLMIMEDATA_H
10 #define KURLMIMEDATA_H
11 
12 #include "kcoreaddons_export.h"
13 #include <QMap>
14 #include <QUrl>
15 QT_BEGIN_NAMESPACE
16 class QMimeData;
17 QT_END_NAMESPACE
18 
19 /**
20  * Utility functions for using URLs in QMimeData.
21  * In addition to QMimeData::setUrls() and QMimeData::urls(), these functions allow to:
22  *
23  * - Store two sets of URLs, the KDE-specific URLs and the equivalent local-file URLs
24  * for compatibility with non-KDE applications
25  * - Store KIO metadata, such as the HTTP referrer for a given URL (some websites
26  * require it for downloading e.g. an image)
27  *
28  * @since 5.0
29  */
30 namespace KUrlMimeData
31 {
33 
34 /**
35  * Adds URLs and KIO metadata into the given QMimeData.
36  *
37  * WARNING: do not call this method multiple times on the same mimedata object,
38  * you can add urls only once. But you can add other things, e.g. images, XML...
39  *
40  * @param mimeData the QMimeData instance used to drag or copy this URL
41  */
42 KCOREADDONS_EXPORT void setUrls(const QList<QUrl> &urls, const QList<QUrl> &mostLocalUrls, QMimeData *mimeData);
43 /**
44  * @param metaData KIO metadata shipped in the mime data, which is used for instance to
45  * set a correct HTTP referrer (some websites require it for downloading e.g. an image)
46  */
47 KCOREADDONS_EXPORT void setMetaData(const MetaDataMap &metaData, QMimeData *mimeData);
48 
49 /**
50  * Return the list of mimeTypes that can be decoded by urlsFromMimeData
51  */
52 KCOREADDONS_EXPORT QStringList mimeDataTypes();
53 
54 /**
55  * Flags to be used in urlsFromMimeData.
56  */
58  /**
59  * When the mimedata contains both KDE-style URLs (eg: desktop:/foo) and
60  * the "most local" version of the URLs (eg: file:///home/dfaure/Desktop/foo),
61  * decode it as local urls. Useful in paste/drop operations that end up calling KIO,
62  * so that urls from other users work as well.
63  */
65  /**
66  * When the mimedata contains both KDE-style URLs (eg: desktop:/foo) and
67  * the "most local" version of the URLs (eg: file:///home/dfaure/Desktop/foo),
68  * decode it as the KDE-style URL. Useful in DnD code e.g. when moving icons,
69  * and the kde-style url is used as identifier for the icons.
70  */
72 };
73 
74 /**
75  * Extract a list of urls from the contents of @p mimeData.
76  *
77  * Compared to QMimeData::urls(), this method has support for retrieving KDE-specific URLs
78  * when urls() would retrieve "most local URLs" instead.
79  *
80  * Decoding will fail if @p mimeData does not contain any URLs, or if at
81  * least one extracted URL is not valid.
82  *
83  * @param mimeData the mime data to extract from; cannot be 0
84  * @param decodeOptions options for decoding
85  * @param metaData optional pointer to a map which will hold the metadata after this call
86  * @return the list of urls
87  */
88 KCOREADDONS_EXPORT QList<QUrl> urlsFromMimeData(const QMimeData *mimeData, DecodeOptions decodeOptions = PreferKdeUrls, MetaDataMap *metaData = nullptr);
89 
90 }
91 
92 #endif /* KURLMIMEDATA_H */
KCOREADDONS_EXPORT void setUrls(const QList< QUrl > &urls, const QList< QUrl > &mostLocalUrls, QMimeData *mimeData)
Adds URLs and KIO metadata into the given QMimeData.
KCOREADDONS_EXPORT QList< QUrl > urlsFromMimeData(const QMimeData *mimeData, DecodeOptions decodeOptions=PreferKdeUrls, MetaDataMap *metaData=nullptr)
Extract a list of urls from the contents of mimeData.
Utility functions for using URLs in QMimeData.
Definition: kurlmimedata.h:30
When the mimedata contains both KDE-style URLs (eg: desktop:/foo) and the "most local" version of the...
Definition: kurlmimedata.h:64
When the mimedata contains both KDE-style URLs (eg: desktop:/foo) and the "most local" version of the...
Definition: kurlmimedata.h:71
KCOREADDONS_EXPORT void setMetaData(const MetaDataMap &metaData, QMimeData *mimeData)
DecodeOptions
Flags to be used in urlsFromMimeData.
Definition: kurlmimedata.h:57
KCOREADDONS_EXPORT QStringList mimeDataTypes()
Return the list of mimeTypes that can be decoded by urlsFromMimeData.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Apr 18 2021 23:02:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.