4#include <ImageIO/ImageIO.h>
5#include <CoreFoundation/CoreFoundation.h>
7#include <QtCore/qsystemdetection.h>
8#include <QtCore/qurl.h>
9#include <QtGui/qimage.h>
10#include <QtCore/qmimedata.h>
11#include <QtCore/qstringconverter.h>
13#if defined(Q_OS_MACOS)
16#include <MobileCoreServices/MobileCoreServices.h>
19#if defined(QT_PLATFORM_UIKIT)
20#import <UIKit/UIKit.h>
26#include "private/qcore_mac_p.h"
178 const QString &uti)
const override;
180 const QString &uti)
const override;
186 if (
mime ==
"application/x-qt-mime-type-name"_L1)
189 return ret.replace(u
'/',
"--"_L1);
194 const QString any_prefix =
"com.trolltech.anymime."_L1;
203 if (
data.count() > 1)
204 qWarning(
"QMacMimeAny: Cannot handle multiple member data");
206 if (
mime ==
"text/plain"_L1)
217 if (
mime ==
"text/plain"_L1)
218 ret.append(
data.toString().toUtf8());
220 ret.append(
data.toByteArray());
238 if (
mime ==
"application/x-qt-mime-type-name"_L1)
239 return u
"com.trolltech.qt.MimeTypeName"_s;
257 ret.append(
QString(
"x-qt-mime-type-name"_L1).toUtf8());
267 const QString &uti)
const override;
269 const QString &uti)
const override;
274 if (
mime ==
"text/plain"_L1)
275 return "public.text"_L1;
281 if (uti ==
"public.text"_L1)
282 return "text/plain"_L1;
290 if (
data.count() > 1)
291 qWarning(
"QMacMimePlainTextFallback: Cannot handle multiple member data");
293 if (uti ==
"public.text"_L1) {
298 reinterpret_cast<const UInt8 *
>(firstData.
constData()),
299 firstData.
size(), kCFStringEncodingUTF8,
false)));
312 if (uti ==
"public.text"_L1)
313 ret.append(
string.toUtf8());
323 const QString &uti)
const override;
325 const QString &uti)
const override;
330 if (
mime ==
"text/plain"_L1)
331 return "public.utf16-plain-text"_L1;
337 if (cs ==
"system"_L1)
338 return "public.utf8-plain-text"_L1;
339 else if (cs ==
"iso-10646-ucs-2"_L1 || cs ==
"utf16"_L1)
340 return "public.utf16-plain-text"_L1;
347 if (uti ==
"public.utf16-plain-text"_L1 || uti ==
"public.utf8-plain-text"_L1)
348 return "text/plain"_L1;
356 if (
data.count() > 1)
357 qWarning(
"QMacMimeUnicodeText: Cannot handle multiple member data");
361 if (uti ==
"public.utf8-plain-text"_L1) {
363 }
else if (uti ==
"public.utf16-plain-text"_L1) {
378 if (uti ==
"public.utf8-plain-text"_L1)
379 ret.append(
string.toUtf8());
380 else if (uti ==
"public.utf16-plain-text"_L1) {
381 QStringEncoder::Flags
f;
382#if defined(Q_OS_MACOS)
395 ret.append(encoder(
string));
406 const QString &uti)
const override;
408 const QString &uti)
const override;
413 if (
mime ==
"text/html"_L1)
414 return "public.html"_L1;
420 if (uti ==
"public.html"_L1)
421 return "text/html"_L1;
431 if (
data.count() > 1)
432 qWarning(
"QMacMimeHTMLText: Cannot handle multiple member data");
443 ret.append(
data.toByteArray());
453 const QString &uti)
const override;
455 const QString &uti)
const override;
460 if (
mime ==
"text/html"_L1)
461 return "public.rtf"_L1;
467 if (uti ==
"public.rtf"_L1)
468 return "text/html"_L1;
478 if (
data.count() > 1)
479 qWarning(
"QMacMimeHTMLText: Cannot handle multiple member data");
482 NSAttributedString *
string = [[NSAttributedString alloc] initWithData:
data.at(0).toNSData()
483 options:@{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType}
484 documentAttributes:nil
489 NSDictionary *dict = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
490 NSData *htmlData = [
string dataFromRange:
range documentAttributes:dict
error:&
error];
491 return QByteArray::fromNSData(htmlData);
502 NSAttributedString *
string = [[NSAttributedString alloc] initWithData:
data.toByteArray().toNSData()
503 options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}
504 documentAttributes:nil
509 NSDictionary *dict = @{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType};
510 NSData *rtfData = [
string dataFromRange:
range documentAttributes:dict
error:&
error];
511 ret << QByteArray::fromNSData(rtfData);
521 const QString &uti)
const override;
523 const QString &uti)
const override;
529 if (
mime ==
"text/uri-list"_L1)
530 return "public.file-url"_L1;
536 if (uti ==
"public.file-url"_L1)
537 return "text/uri-list"_L1;
548 for (
int i = 0;
i <
data.size(); ++
i) {
550 NSString *urlString = [[[NSString alloc] initWithBytesNoCopy:(
void *)
a.data()
length:
a.size()
551 encoding:NSUTF8StringEncoding freeWhenDone:NO] autorelease];
552 NSURL *nsurl = [NSURL URLWithString:urlString];
555 if ([nsurl isFileReferenceURL]) {
556 url = QUrl::fromNSURL([nsurl filePathURL]);
558 url = QUrl::fromNSURL(nsurl);
578 for (
int i = 0;
i < urls.
size(); ++
i) {
604 const QString &uti)
const override;
606 const QString &uti)
const override;
611 if (
mime.startsWith(
"text/uri-list"_L1))
612 return "public.url"_L1;
618 if (uti ==
"public.url"_L1)
619 return "text/uri-list"_L1;
630 for (
int i=0;
i<
data.size(); ++
i) {
648 for (
int i=0;
i<urls.
size(); ++
i) {
668 const QString &uti)
const override;
670 const QString &uti)
const override;
675 if (
mime.startsWith(
"text/vcard"_L1))
676 return "public.vcard"_L1;
682 if (uti ==
"public.vcard"_L1)
683 return "text/vcard"_L1;
693 if (uti ==
"public.vcard"_L1) {
694 for (
int i=0;
i<
data.size(); ++
i)
707 if (
mime ==
"text/vcard"_L1)
708 ret.append(
data.toString().toUtf8());
721 const QString &uti)
const override;
723 const QString &uti)
const override;
728 if (
mime.startsWith(
"application/x-qt-image"_L1))
729 return "public.tiff"_L1;
735 if (uti ==
"public.tiff"_L1)
736 return "application/x-qt-image"_L1;
743 if (
data.count() > 1)
744 qWarning(
"QMacMimeTiff: Cannot handle multiple member data");
768 if (!imageDestination)
772 NSDictionary *
props = @{
773 static_cast<NSString *
>(kCGImagePropertyPixelWidth): @(
img.width()),
774 static_cast<NSString *
>(kCGImagePropertyPixelHeight): @(
img.height())
778 static_cast<CFDictionaryRef
>(
props));
779 CGImageDestinationFinalize(imageDestination);
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
char at(qsizetype i) const
Returns the byte at index position i in the byte array.
QByteArray first(qsizetype n) const
qsizetype size() const noexcept
QList< T > toList() const noexcept
const_reference at(qsizetype i) const noexcept
qsizetype count() const noexcept
QString utiForMime(const QString &mime) const override
Returns the Mac UTI used for MIME type mime, or an empty string if this converter does not support co...
QString mimeForUti(const QString &uti) const override
Returns the MIME type used for Mac UTI uti, or an empty string if this converter does not support con...
QList< QByteArray > convertFromMime(const QString &mime, const QVariant &data, const QString &uti) const override
Returns data converted from MIME type mime to Mac UTI uti.
QVariant convertToMime(const QString &mime, const QList< QByteArray > &data, const QString &uti) const override
Returns data converted from Mac UTI uti to MIME type mime.
int count(const QMimeData *mimeData) const override
Returns the item count for the given mimeData.
QList< QByteArray > convertFromMime(const QString &mime, const QVariant &data, const QString &uti) const override
Returns data converted from MIME type mime to Mac UTI uti.
QVariant convertToMime(const QString &mime, const QList< QByteArray > &data, const QString &uti) const override
Returns data converted from Mac UTI uti to MIME type mime.
QString utiForMime(const QString &mime) const override
Returns the Mac UTI used for MIME type mime, or an empty string if this converter does not support co...
QString mimeForUti(const QString &uti) const override
Returns the MIME type used for Mac UTI uti, or an empty string if this converter does not support con...
QString utiForMime(const QString &mime) const override
Returns the Mac UTI used for MIME type mime, or an empty string if this converter does not support co...
QString mimeForUti(const QString &uti) const override
Returns the MIME type used for Mac UTI uti, or an empty string if this converter does not support con...
QVariant convertToMime(const QString &mime, const QList< QByteArray > &data, const QString &uti) const override
Returns data converted from Mac UTI uti to MIME type mime.
QList< QByteArray > convertFromMime(const QString &mime, const QVariant &data, const QString &uti) const override
Returns data converted from MIME type mime to Mac UTI uti.
QString utiForMime(const QString &mime) const override
Returns the Mac UTI used for MIME type mime, or an empty string if this converter does not support co...
QList< QByteArray > convertFromMime(const QString &mime, const QVariant &data, const QString &uti) const override
Returns data converted from MIME type mime to Mac UTI uti.
QVariant convertToMime(const QString &mime, const QList< QByteArray > &data, const QString &uti) const override
Returns data converted from Mac UTI uti to MIME type mime.
QString mimeForUti(const QString &uti) const override
Returns the MIME type used for Mac UTI uti, or an empty string if this converter does not support con...
QString utiForMime(const QString &mime) const override
Returns the Mac UTI used for MIME type mime, or an empty string if this converter does not support co...
QVariant convertToMime(const QString &mime, const QList< QByteArray > &data, const QString &uti) const override
Returns data converted from Mac UTI uti to MIME type mime.
QString mimeForUti(const QString &uti) const override
Returns the MIME type used for Mac UTI uti, or an empty string if this converter does not support con...
QList< QByteArray > convertFromMime(const QString &mime, const QVariant &data, const QString &uti) const override
Returns data converted from MIME type mime to Mac UTI uti.
QString mimeForUti(const QString &uti) const override
Returns the MIME type used for Mac UTI uti, or an empty string if this converter does not support con...
QVariant convertToMime(const QString &mime, const QList< QByteArray > &data, const QString &uti) const override
Returns data converted from Mac UTI uti to MIME type mime.
QList< QByteArray > convertFromMime(const QString &mime, const QVariant &data, const QString &uti) const override
Returns data converted from MIME type mime to Mac UTI uti.
QString utiForMime(const QString &mime) const override
Returns the Mac UTI used for MIME type mime, or an empty string if this converter does not support co...
QString utiForMime(const QString &mime) const override
Returns the Mac UTI used for MIME type mime, or an empty string if this converter does not support co...
QVariant convertToMime(const QString &mime, const QList< QByteArray > &data, const QString &uti) const override
Returns data converted from Mac UTI uti to MIME type mime.
QList< QByteArray > convertFromMime(const QString &mime, const QVariant &data, const QString &uti) const override
Returns data converted from MIME type mime to Mac UTI uti.
QString mimeForUti(const QString &uti) const override
Returns the MIME type used for Mac UTI uti, or an empty string if this converter does not support con...
QVariant convertToMime(const QString &mime, const QList< QByteArray > &data, const QString &uti) const override
Returns data converted from Mac UTI uti to MIME type mime.
QList< QByteArray > convertFromMime(const QString &mime, const QVariant &data, const QString &uti) const override
Returns data converted from MIME type mime to Mac UTI uti.
QString mimeForUti(const QString &uti) const override
Returns the MIME type used for Mac UTI uti, or an empty string if this converter does not support con...
QString utiForMime(const QString &mime) const override
Returns the Mac UTI used for MIME type mime, or an empty string if this converter does not support co...
QString mimeForUti(const QString &uti) const override
Returns the MIME type used for Mac UTI uti, or an empty string if this converter does not support con...
QVariant convertToMime(const QString &mime, const QList< QByteArray > &data, const QString &uti) const override
Returns data converted from Mac UTI uti to MIME type mime.
QList< QByteArray > convertFromMime(const QString &mime, const QVariant &data, const QString &uti) const override
Returns data converted from MIME type mime to Mac UTI uti.
QString utiForMime(const QString &mime) const override
Returns the Mac UTI used for MIME type mime, or an empty string if this converter does not support co...
QVariant convertToMime(const QString &mime, const QList< QByteArray > &data, const QString &uti) const override
Returns data converted from Mac UTI uti to MIME type mime.
QString utiForMime(const QString &mime) const override
Returns the Mac UTI used for MIME type mime, or an empty string if this converter does not support co...
QString mimeForUti(const QString &uti) const override
Returns the MIME type used for Mac UTI uti, or an empty string if this converter does not support con...
QList< QByteArray > convertFromMime(const QString &mime, const QVariant &data, const QString &uti) const override
Returns data converted from MIME type mime to Mac UTI uti.
QList< QUrl > urls() const
Returns a list of URLs contained within the MIME data object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QString & replace(qsizetype i, qsizetype len, QChar after)
qsizetype size() const
Returns the number of characters in this string.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString toLower() const &
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
qsizetype length() const
Returns the number of characters in this string.
QString normalized(NormalizationForm mode, QChar::UnicodeVersion version=QChar::Unicode_Unassigned) const
Returns the string in the given Unicode normalization mode, according to the given version of the Uni...
QString host(ComponentFormattingOptions=FullyDecoded) const
Returns the host of the URL if it is defined; otherwise an empty string is returned.
QByteArray toEncoded(FormattingOptions options=FullyEncoded) const
Returns the encoded representation of the URL if it's valid; otherwise an empty QByteArray is returne...
QString scheme() const
Returns the scheme of the URL.
void setScheme(const QString &scheme)
Sets the scheme of the URL to scheme.
void setHost(const QString &host, ParsingMode mode=DecodedMode)
Sets the host of the URL to host.
void setPath(const QString &path, ParsingMode mode=DecodedMode)
Sets the path of the URL to path.
static QUrl fromEncoded(QByteArrayView input, ParsingMode mode=TolerantMode)
Parses input and returns the corresponding QUrl.
QString path(ComponentFormattingOptions options=FullyDecoded) const
Returns the path of the URL.
The QUtiMimeConverter class converts between a MIME type and a \l{https://developer....
bool canConvert(const QString &mime, const QString &uti) const
Returns true if the converter can convert (both ways) between mime and uti; otherwise returns false.
virtual ~QUtiMimeConverter()
Destroys a conversion object, removing it from the global list of available converters.
QUtiMimeConverter()
Constructs a new conversion object and adds it to the globally accessed list of available converters.
virtual int count(const QMimeData *mimeData) const
Returns the item count for the given mimeData.
void unregisterMimeConverter(QUtiMimeConverter *macMime)
void registerBuiltInTypes()
void registerMimeConverter(QUtiMimeConverter *macMime)
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLenum GLsizei length
GLenum GLenum GLsizei count
GLenum GLuint GLsizei const GLenum * props
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
#define qPrintable(string)
QImage qt_mac_toQImage(CGImageRef image)
CGImageRef qt_mac_toCGImage(const QImage &qImage)
QUrl url("example.com")
[constructor-url-reference]
application x qt windows mime
[2]