KUrlMimeData Namespace

Header: #include <KUrlMimeData>
CMake: find_package(KF6 REQUIRED COMPONENTS CoreAddons)
target_link_libraries(mytarget PRIVATE KF6::CoreAddons)
Since: 5.0

Types

enum DecodeOption { PreferKdeUrls, PreferLocalUrls }
flags DecodeOptions

Functions

bool exportUrlsToPortal(QMimeData *mimeData)
QStringList mimeDataTypes()
void setMetaData(const KUrlMimeData::MetaDataMap &metaData, QMimeData *mimeData)
void setUrls(const QList<QUrl> &urls, const QList<QUrl> &mostLocalUrls, QMimeData *mimeData)
QList<QUrl> urlsFromMimeData(const QMimeData *mimeData, KUrlMimeData::DecodeOptions decodeOptions = PreferKdeUrls, KUrlMimeData::MetaDataMap *metaData = nullptr)

Detailed Description

Utility functions for using URLs in QMimeData. In addition to QMimeData::setUrls() and QMimeData::urls(), these functions allow to:

- Store two sets of URLs, the KDE-specific URLs and the equivalent local-file URLs for compatibility with non-KDE applications - Store KIO metadata, such as the HTTP referrer for a given URL (some websites require it for downloading e.g. an image)

Type Documentation

enum KUrlMimeData::DecodeOption
flags KUrlMimeData::DecodeOptions

Flags to be used in urlsFromMimeData.

ConstantValueDescription
KUrlMimeData::PreferKdeUrls0When the mimedata contains both KDE-style URLs (eg: desktop:/foo) and the "most local" version of the URLs (eg: file:///home/dfaure/Desktop/foo), decode it as the KDE-style URL. Useful in DnD code e.g. when moving icons, and the kde-style url is used as identifier for the icons.
KUrlMimeData::PreferLocalUrls1When the mimedata contains both KDE-style URLs (eg: desktop:/foo) and the "most local" version of the URLs (eg: file:///home/dfaure/Desktop/foo), decode it as local urls. Useful in paste/drop operations that end up calling KIO, so that urls from other users work as well.

The DecodeOptions type is a typedef for QFlags<DecodeOption>. It stores an OR combination of DecodeOption values.

Function Documentation

bool KUrlMimeData::exportUrlsToPortal(QMimeData *mimeData)

Export URLs through the XDG Documents Portal to allow interaction from/with sandbox code. This implements the application/vnd.portal.filetransfer mimetype extension. When built without dbus support or the portal isn't installed on the target system, then this is no-op and returns false. Remote URLs are automatically mounted into the file system using kio-fuse Returns whether all URLS were exported through the portal

QStringList KUrlMimeData::mimeDataTypes()

Return the list of mimeTypes that can be decoded by urlsFromMimeData

void KUrlMimeData::setMetaData(const KUrlMimeData::MetaDataMap &metaData, QMimeData *mimeData)

metaData KIO metadata shipped in the mime data, which is used for instance to set a correct HTTP referrer (some websites require it for downloading e.g. an image)

void KUrlMimeData::setUrls(const QList<QUrl> &urls, const QList<QUrl> &mostLocalUrls, QMimeData *mimeData)

Adds URLs and KIO metadata into the given QMimeData.

WARNING: do not call this method multiple times on the same mimedata object, you can add urls only once. But you can add other things, e.g. images, XML...

mimeData the QMimeData instance used to drag or copy this URL

QList<QUrl> KUrlMimeData::urlsFromMimeData(const QMimeData *mimeData, KUrlMimeData::DecodeOptions decodeOptions = PreferKdeUrls, KUrlMimeData::MetaDataMap *metaData = nullptr)

Extract a list of urls from the contents of mimeData.

Compared to QMimeData::urls(), this method has support for retrieving KDE-specific URLs when urls() would retrieve "most local URLs" instead as well as support for the XDG Documents Portal via the application/vnd.portal.filetransfer mimedata extension.

Decoding will fail if mimeData does not contain any URLs, or if at least one extracted URL is not valid.

When application/vnd.portal.filetransfer is set you'll only receive URLs retrieved from the XDG Documents Portal. When the portal is not available application/vnd.portal.filetransfer gets ignored.

mimeData the mime data to extract from; cannot be 0

decodeOptions options for decoding

metaData optional pointer to a map which will hold the metadata after this call

Returns the list of urls