Refactor: split QMacMime registry and virtual interface

The logic for registration of converter implementations is only used
internally through static functions. Move those, and related global
functions, to a QMacMimeRegistry namespace.

Reduce the QMacInternalPasteboardMime to the abstract interface for
converting between native and Qt clipboard data.

Historically, mime converters can have different "types"; make that API
type-safe.

Task-number: QTBUG-93632
Change-Id: I0e16fefa350398b693486199fe10357fd84abcd6
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Volker Hilsheimer 2022-10-31 17:01:43 +01:00
parent c5d4de1557
commit d5300a6d2a
15 changed files with 270 additions and 191 deletions

View File

@ -389,6 +389,7 @@ qt_internal_extend_target(Gui CONDITION APPLE
painting/qcoregraphics.mm painting/qcoregraphics_p.h painting/qcoregraphics.mm painting/qcoregraphics_p.h
painting/qrasterbackingstore.cpp painting/qrasterbackingstore_p.h painting/qrasterbackingstore.cpp painting/qrasterbackingstore_p.h
painting/qrhibackingstore.cpp painting/qrhibackingstore_p.h painting/qrhibackingstore.cpp painting/qrhibackingstore_p.h
platform/darwin/qmacmimeregistry.mm platform/darwin/qmacmimeregistry_p.h
platform/darwin/qmacmime.mm platform/darwin/qmacmime_p.h platform/darwin/qmacmime.mm platform/darwin/qmacmime_p.h
platform/darwin/qapplekeymapper.mm platform/darwin/qapplekeymapper_p.h platform/darwin/qapplekeymapper.mm platform/darwin/qapplekeymapper_p.h
text/coretext/qcoretextfontdatabase.mm text/coretext/qcoretextfontdatabase_p.h text/coretext/qcoretextfontdatabase.mm text/coretext/qcoretextfontdatabase_p.h

View File

@ -20,6 +20,7 @@
#endif #endif
#include "qmacmime_p.h" #include "qmacmime_p.h"
#include "qmacmimeregistry_p.h"
#include "qguiapplication.h" #include "qguiapplication.h"
#include "private/qcore_mac_p.h" #include "private/qcore_mac_p.h"
@ -27,47 +28,6 @@ QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals; using namespace Qt::StringLiterals;
typedef QList<QMacInternalPasteboardMime*> MimeList;
Q_GLOBAL_STATIC(MimeList, globalMimeList)
Q_GLOBAL_STATIC(QStringList, globalDraggedTypesList)
void qt_mac_addToGlobalMimeList(QMacInternalPasteboardMime *macMime)
{
// globalMimeList is in decreasing priority order. Recently added
// converters take prioity over previously added converters: prepend
// to the list.
globalMimeList()->prepend(macMime);
}
void qt_mac_removeFromGlobalMimeList(QMacInternalPasteboardMime *macMime)
{
if (!QGuiApplication::closingDown())
globalMimeList()->removeAll(macMime);
}
/*!
\fn void qRegisterDraggedTypes(const QStringList &types)
\relates QMacPasteboardMime
Registers the given \a types as custom pasteboard types.
This function should be called to enable the Drag and Drop events
for custom pasteboard types on Cocoa implementations. This is required
in addition to a QMacPasteboardMime subclass implementation. By default
drag and drop is enabled for all standard pasteboard types.
\sa QMacPasteboardMime
*/
void qt_mac_registerDraggedTypes(const QStringList &types)
{
(*globalDraggedTypesList()) += types;
}
const QStringList& qt_mac_enabledDraggedTypes()
{
return (*globalDraggedTypesList());
}
/***************************************************************************** /*****************************************************************************
QDnD debug facilities QDnD debug facilities
*****************************************************************************/ *****************************************************************************/
@ -127,9 +87,10 @@ const QStringList& qt_mac_enabledDraggedTypes()
Constructs a new conversion object of type \a t, adding it to the Constructs a new conversion object of type \a t, adding it to the
globally accessed list of available converters. globally accessed list of available converters.
*/ */
QMacInternalPasteboardMime::QMacInternalPasteboardMime(char t) : type(t) QMacInternalPasteboardMime::QMacInternalPasteboardMime(QMacPasteboardMimeType t)
: m_type(t)
{ {
qt_mac_addToGlobalMimeList(this); QMacMimeRegistry::registerMimeConverter(this);
} }
/* /*
@ -138,7 +99,7 @@ QMacInternalPasteboardMime::QMacInternalPasteboardMime(char t) : type(t)
*/ */
QMacInternalPasteboardMime::~QMacInternalPasteboardMime() QMacInternalPasteboardMime::~QMacInternalPasteboardMime()
{ {
qt_mac_removeFromGlobalMimeList(this); QMacMimeRegistry::unregisterMimeConverter(this);
} }
/* /*
@ -151,13 +112,9 @@ int QMacInternalPasteboardMime::count(QMimeData *mimeData)
} }
class QMacPasteboardMimeAny : public QMacInternalPasteboardMime { class QMacPasteboardMimeAny : public QMacInternalPasteboardMime {
private:
public: public:
QMacPasteboardMimeAny() : QMacInternalPasteboardMime(MIME_QT_CONVERTOR|MIME_ALL) { QMacPasteboardMimeAny() : QMacInternalPasteboardMime(MIME_ALL_COMPATIBLE) {}
}
~QMacPasteboardMimeAny() {
}
QString convertorName(); QString convertorName();
QString flavorFor(const QString &mime); QString flavorFor(const QString &mime);
@ -220,10 +177,8 @@ class QMacPasteboardMimeTypeName : public QMacInternalPasteboardMime {
private: private:
public: public:
QMacPasteboardMimeTypeName() : QMacInternalPasteboardMime(MIME_QT_CONVERTOR|MIME_ALL) { QMacPasteboardMimeTypeName(): QMacInternalPasteboardMime(MIME_ALL_COMPATIBLE) {}
}
~QMacPasteboardMimeTypeName() {
}
QString convertorName(); QString convertorName();
QString flavorFor(const QString &mime); QString flavorFor(const QString &mime);
@ -270,7 +225,7 @@ QList<QByteArray> QMacPasteboardMimeTypeName::convertFromMime(const QString &, Q
class QMacPasteboardMimePlainTextFallback : public QMacInternalPasteboardMime { class QMacPasteboardMimePlainTextFallback : public QMacInternalPasteboardMime {
public: public:
QMacPasteboardMimePlainTextFallback() : QMacInternalPasteboardMime(MIME_ALL) { } QMacPasteboardMimePlainTextFallback() : QMacInternalPasteboardMime(MIME_ALL) {}
QString convertorName(); QString convertorName();
QString flavorFor(const QString &mime); QString flavorFor(const QString &mime);
@ -333,7 +288,7 @@ QList<QByteArray> QMacPasteboardMimePlainTextFallback::convertFromMime(const QSt
class QMacPasteboardMimeUnicodeText : public QMacInternalPasteboardMime { class QMacPasteboardMimeUnicodeText : public QMacInternalPasteboardMime {
public: public:
QMacPasteboardMimeUnicodeText() : QMacInternalPasteboardMime(MIME_ALL) { } QMacPasteboardMimeUnicodeText() : QMacInternalPasteboardMime(MIME_ALL) {}
QString convertorName(); QString convertorName();
QString flavorFor(const QString &mime); QString flavorFor(const QString &mime);
@ -425,7 +380,7 @@ QList<QByteArray> QMacPasteboardMimeUnicodeText::convertFromMime(const QString &
class QMacPasteboardMimeHTMLText : public QMacInternalPasteboardMime { class QMacPasteboardMimeHTMLText : public QMacInternalPasteboardMime {
public: public:
QMacPasteboardMimeHTMLText() : QMacInternalPasteboardMime(MIME_ALL) { } QMacPasteboardMimeHTMLText() : QMacInternalPasteboardMime(MIME_ALL) {}
QString convertorName(); QString convertorName();
QString flavorFor(const QString &mime); QString flavorFor(const QString &mime);
@ -479,7 +434,7 @@ QList<QByteArray> QMacPasteboardMimeHTMLText::convertFromMime(const QString &mim
class QMacPasteboardMimeRtfText : public QMacInternalPasteboardMime { class QMacPasteboardMimeRtfText : public QMacInternalPasteboardMime {
public: public:
QMacPasteboardMimeRtfText() : QMacInternalPasteboardMime(MIME_ALL) { } QMacPasteboardMimeRtfText() : QMacInternalPasteboardMime(MIME_ALL) {}
QString convertorName(); QString convertorName();
QString flavorFor(const QString &mime); QString flavorFor(const QString &mime);
@ -554,7 +509,7 @@ QList<QByteArray> QMacPasteboardMimeRtfText::convertFromMime(const QString &mime
class QMacPasteboardMimeFileUri : public QMacInternalPasteboardMime { class QMacPasteboardMimeFileUri : public QMacInternalPasteboardMime {
public: public:
QMacPasteboardMimeFileUri() : QMacInternalPasteboardMime(MIME_ALL) { } QMacPasteboardMimeFileUri() : QMacInternalPasteboardMime(MIME_ALL) {}
QString convertorName(); QString convertorName();
QString flavorFor(const QString &mime); QString flavorFor(const QString &mime);
@ -644,7 +599,7 @@ int QMacPasteboardMimeFileUri::count(QMimeData *mimeData)
class QMacPasteboardMimeUrl : public QMacInternalPasteboardMime { class QMacPasteboardMimeUrl : public QMacInternalPasteboardMime {
public: public:
QMacPasteboardMimeUrl() : QMacInternalPasteboardMime(MIME_ALL) { } QMacPasteboardMimeUrl() : QMacInternalPasteboardMime(MIME_ALL) {}
QString convertorName(); QString convertorName();
QString flavorFor(const QString &mime); QString flavorFor(const QString &mime);
@ -719,7 +674,7 @@ QList<QByteArray> QMacPasteboardMimeUrl::convertFromMime(const QString &mime, QV
class QMacPasteboardMimeVCard : public QMacInternalPasteboardMime class QMacPasteboardMimeVCard : public QMacInternalPasteboardMime
{ {
public: public:
QMacPasteboardMimeVCard() : QMacInternalPasteboardMime(MIME_ALL){ } QMacPasteboardMimeVCard() : QMacInternalPasteboardMime(MIME_ALL) {}
QString convertorName(); QString convertorName();
QString flavorFor(const QString &mime); QString flavorFor(const QString &mime);
@ -776,7 +731,7 @@ extern CGImageRef qt_mac_toCGImage(const QImage &qImage);
class QMacPasteboardMimeTiff : public QMacInternalPasteboardMime { class QMacPasteboardMimeTiff : public QMacInternalPasteboardMime {
public: public:
QMacPasteboardMimeTiff() : QMacInternalPasteboardMime(MIME_ALL) { } QMacPasteboardMimeTiff() : QMacInternalPasteboardMime(MIME_ALL) {}
QString convertorName(); QString convertorName();
QString flavorFor(const QString &mime); QString flavorFor(const QString &mime);
@ -850,107 +805,28 @@ QList<QByteArray> QMacPasteboardMimeTiff::convertFromMime(const QString &mime, Q
return QList<QByteArray>() << QByteArray::fromCFData(data); return QList<QByteArray>() << QByteArray::fromCFData(data);
} }
/*! namespace QMacMimeRegistry {
\internal
This is an internal function. void registerBuiltInTypes()
*/
void QMacInternalPasteboardMime::initializeMimeTypes()
{ {
if (globalMimeList()->isEmpty()) { // Create QMacPasteboardMimeAny first to put it at the end of globalMimeList
// Create QMacPasteboardMimeAny first to put it at the end of globalMimeList // with lowest priority. (the constructor prepends to the list)
// with lowest priority. (the constructor prepends to the list) new QMacPasteboardMimeAny;
new QMacPasteboardMimeAny;
//standard types that we wrap //standard types that we wrap
new QMacPasteboardMimeTiff; new QMacPasteboardMimeTiff;
new QMacPasteboardMimePlainTextFallback; new QMacPasteboardMimePlainTextFallback;
new QMacPasteboardMimeUnicodeText; new QMacPasteboardMimeUnicodeText;
new QMacPasteboardMimeRtfText; new QMacPasteboardMimeRtfText;
new QMacPasteboardMimeHTMLText; new QMacPasteboardMimeHTMLText;
new QMacPasteboardMimeFileUri; new QMacPasteboardMimeFileUri;
new QMacPasteboardMimeUrl; new QMacPasteboardMimeUrl;
new QMacPasteboardMimeTypeName; new QMacPasteboardMimeTypeName;
new QMacPasteboardMimeVCard; new QMacPasteboardMimeVCard;
}
} }
/*!
\internal
*/
void QMacInternalPasteboardMime::destroyMimeTypes()
{
MimeList *mimes = globalMimeList();
while (!mimes->isEmpty())
delete mimes->takeFirst();
} }
/*
Returns the most-recently created QMacPasteboardMime of type \a t that can convert
between the \a mime and \a flav formats. Returns 0 if no such convertor
exists.
*/
QMacInternalPasteboardMime*
QMacInternalPasteboardMime::convertor(uchar t, const QString &mime, QString flav)
{
MimeList *mimes = globalMimeList();
for (MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) {
#ifdef DEBUG_MIME_MAPS
qDebug("QMacPasteboardMime::convertor: seeing if %s (%d) can convert %s to %d[%c%c%c%c] [%d]",
(*it)->convertorName().toLatin1().constData(),
(*it)->type & t, mime.toLatin1().constData(),
flav, (flav >> 24) & 0xFF, (flav >> 16) & 0xFF, (flav >> 8) & 0xFF, (flav) & 0xFF,
(*it)->canConvert(mime,flav));
for (int i = 0; i < (*it)->countFlavors(); ++i) {
int f = (*it)->flavor(i);
qDebug(" %d) %d[%c%c%c%c] [%s]", i, f,
(f >> 24) & 0xFF, (f >> 16) & 0xFF, (f >> 8) & 0xFF, (f) & 0xFF,
(*it)->convertorName().toLatin1().constData());
}
#endif
if (((*it)->type & t) && (*it)->canConvert(mime, flav))
return (*it);
}
return 0;
}
/*
Returns a MIME type of type \a t for \a flav, or 0 if none exists.
*/
QString QMacInternalPasteboardMime::flavorToMime(uchar t, QString flav)
{
MimeList *mimes = globalMimeList();
for (MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) {
#ifdef DEBUG_MIME_MAPS
qDebug("QMacMIme::flavorToMime: attempting %s (%d) for flavor %d[%c%c%c%c] [%s]",
(*it)->convertorName().toLatin1().constData(),
(*it)->type & t, flav, (flav >> 24) & 0xFF, (flav >> 16) & 0xFF, (flav >> 8) & 0xFF, (flav) & 0xFF,
(*it)->mimeFor(flav).toLatin1().constData());
#endif
if ((*it)->type & t) {
QString mimeType = (*it)->mimeFor(flav);
if (!mimeType.isNull())
return mimeType;
}
}
return QString();
}
/*
Returns a list of all currently defined QMacPasteboardMime objects of type \a t.
*/
QList<QMacInternalPasteboardMime*> QMacInternalPasteboardMime::all(uchar t)
{
MimeList ret;
MimeList *mimes = globalMimeList();
for (MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) {
if ((*it)->type & t)
ret.append((*it));
}
return ret;
}
/* /*
\fn QString QMacPasteboardMime::convertorName() \fn QString QMacPasteboardMime::convertorName()

View File

@ -22,25 +22,23 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
// Duplicate of QMacPasteboardMime in QtMacExtras. Keep in sync! class Q_GUI_EXPORT QMacInternalPasteboardMime
class Q_GUI_EXPORT QMacInternalPasteboardMime { {
char type;
public: public:
enum QMacPasteboardMimeType { MIME_DND=0x01, enum QMacPasteboardMimeType
MIME_CLIP=0x02, {
MIME_QT_CONVERTOR=0x04, MIME_DND = 0x01,
MIME_QT3_CONVERTOR=0x08, MIME_CLIP = 0x02,
MIME_ALL=MIME_DND|MIME_CLIP MIME_QT_CONVERTOR = 0x04,
MIME_QT3_CONVERTOR = 0x08,
MIME_ALL = MIME_DND|MIME_CLIP,
MIME_ALL_COMPATIBLE = MIME_ALL|MIME_QT_CONVERTOR
}; };
explicit QMacInternalPasteboardMime(char);
explicit QMacInternalPasteboardMime(QMacPasteboardMimeType);
virtual ~QMacInternalPasteboardMime(); virtual ~QMacInternalPasteboardMime();
static void initializeMimeTypes(); char type() const { return m_type; }
static void destroyMimeTypes();
static QList<QMacInternalPasteboardMime*> all(uchar);
static QMacInternalPasteboardMime *convertor(uchar, const QString &mime, QString flav);
static QString flavorToMime(uchar, QString flav);
virtual QString convertorName() = 0; virtual QString convertorName() = 0;
@ -50,12 +48,10 @@ public:
virtual QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav) = 0; virtual QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav) = 0;
virtual QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav) = 0; virtual QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav) = 0;
virtual int count(QMimeData *mimeData); virtual int count(QMimeData *mimeData);
};
Q_GUI_EXPORT void qt_mac_addToGlobalMimeList(QMacInternalPasteboardMime *macMime); private:
Q_GUI_EXPORT void qt_mac_removeFromGlobalMimeList(QMacInternalPasteboardMime *macMime); const QMacPasteboardMimeType m_type;
Q_GUI_EXPORT void qt_mac_registerDraggedTypes(const QStringList &types); };
Q_GUI_EXPORT const QStringList& qt_mac_enabledDraggedTypes();
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -0,0 +1,151 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QtCore/qmimedata.h>
#include "qmacmime_p.h"
#include "qmacmimeregistry_p.h"
#include "qguiapplication.h"
#include "private/qcore_mac_p.h"
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
namespace QMacMimeRegistry {
typedef QList<QMacInternalPasteboardMime*> MimeList;
Q_GLOBAL_STATIC(MimeList, globalMimeList)
Q_GLOBAL_STATIC(QStringList, globalDraggedTypesList)
// implemented in qmacmime.mm
void registerBuiltInTypes();
/*!
\fn void qRegisterDraggedTypes(const QStringList &types)
\relates QMacPasteboardMime
Registers the given \a types as custom pasteboard types.
This function should be called to enable the Drag and Drop events
for custom pasteboard types on Cocoa implementations. This is required
in addition to a QMacPasteboardMime subclass implementation. By default
drag and drop is enabled for all standard pasteboard types.
\sa QMacPasteboardMime
*/
void registerDraggedTypes(const QStringList &types)
{
(*globalDraggedTypesList()) += types;
}
const QStringList& enabledDraggedTypes()
{
return (*globalDraggedTypesList());
}
/*****************************************************************************
QDnD debug facilities
*****************************************************************************/
//#define DEBUG_MIME_MAPS
/*!
\class QMacMimeRegistry
\internal
\ingroup draganddrop
*/
/*!
\internal
This is an internal function.
*/
void initializeMimeTypes()
{
if (globalMimeList()->isEmpty())
registerBuiltInTypes();
}
/*!
\internal
*/
void destroyMimeTypes()
{
MimeList *mimes = globalMimeList();
while (!mimes->isEmpty())
delete mimes->takeFirst();
}
/*
Returns the most-recently created QMacPasteboardMime of type \a t that can convert
between the \a mime and \a flav formats. Returns 0 if no such convertor
exists.
*/
QMacInternalPasteboardMime *convertor(uchar t, const QString &mime, QString flav)
{
MimeList *mimes = globalMimeList();
for (MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) {
#ifdef DEBUG_MIME_MAPS
qDebug("QMacMimeRegistry::convertor: seeing if %s (%d) can convert %s to %s [%d]",
qPrintable((*it)->convertorName()), (*it)->type() & t, qPrintable(mime),
qPrintable(flav), (*it)->canConvert(mime,flav));
#endif
if (((*it)->type() & t) && (*it)->canConvert(mime, flav))
return (*it);
}
return 0;
}
/*
Returns a MIME type of type \a t for \a flav, or 0 if none exists.
*/
QString flavorToMime(uchar t, QString flav)
{
MimeList *mimes = globalMimeList();
for (MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) {
#ifdef DEBUG_MIME_MAPS
qDebug("QMacMimeRegistry::flavorToMime: attempting %s (%d) for flavor %s [%s]",
qPrintable((*it)->convertorName()), (*it)->type() & t, qPrintable(flav),
qPrintable((*it)->mimeFor(flav)));
#endif
if ((*it)->type() & t) {
QString mimeType = (*it)->mimeFor(flav);
if (!mimeType.isNull())
return mimeType;
}
}
return QString();
}
void registerMimeConverter(QMacInternalPasteboardMime *macMime)
{
// globalMimeList is in decreasing priority order. Recently added
// converters take prioity over previously added converters: prepend
// to the list.
globalMimeList()->prepend(macMime);
}
void unregisterMimeConverter(QMacInternalPasteboardMime *macMime)
{
if (!QGuiApplication::closingDown())
globalMimeList()->removeAll(macMime);
}
/*
Returns a list of all currently defined QMacPasteboardMime objects of type \a t.
*/
QList<QMacInternalPasteboardMime *> all(uchar t)
{
MimeList ret;
MimeList *mimes = globalMimeList();
for (MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) {
if ((*it)->type() & t)
ret.append((*it));
}
return ret;
}
} // namespace QMacMimeRegistry
QT_END_NAMESPACE

View File

@ -0,0 +1,44 @@
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QMACMIMEREGISTRY_H
#define QMACMIMEREGISTRY_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtGui/private/qtguiglobal_p.h>
#include <CoreFoundation/CoreFoundation.h>
QT_BEGIN_NAMESPACE
class QMacInternalPasteboardMime;
namespace QMacMimeRegistry {
Q_GUI_EXPORT void initializeMimeTypes();
Q_GUI_EXPORT void destroyMimeTypes();
Q_GUI_EXPORT void registerMimeConverter(QMacInternalPasteboardMime *);
Q_GUI_EXPORT void unregisterMimeConverter(QMacInternalPasteboardMime *);
Q_GUI_EXPORT QList<QMacInternalPasteboardMime *> all(uchar);
Q_GUI_EXPORT QMacInternalPasteboardMime *convertor(uchar, const QString &mime, QString flav);
Q_GUI_EXPORT QString flavorToMime(uchar, QString flav);
Q_GUI_EXPORT void registerDraggedTypes(const QStringList &types);
Q_GUI_EXPORT const QStringList& enabledDraggedTypes();
};
QT_END_NAMESPACE
#endif // QMACMIMEREGISTRY_H

View File

@ -3,6 +3,8 @@
#include "qcocoaclipboard.h" #include "qcocoaclipboard.h"
#include <QtGui/private/qmacmime_p.h>
#ifndef QT_NO_CLIPBOARD #ifndef QT_NO_CLIPBOARD
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE

View File

@ -7,6 +7,7 @@
#include "qmacclipboard.h" #include "qmacclipboard.h"
#include "qcocoahelpers.h" #include "qcocoahelpers.h"
#include <QtGui/private/qcoregraphics_p.h> #include <QtGui/private/qcoregraphics_p.h>
#include <QtGui/private/qmacmime_p.h>
#include <QtCore/qsysinfo.h> #include <QtCore/qsysinfo.h>
#include <QtCore/private/qcore_mac_p.h> #include <QtCore/private/qcore_mac_p.h>

View File

@ -32,6 +32,7 @@
#include <QtCore/private/qcore_mac_p.h> #include <QtCore/private/qcore_mac_p.h>
#include <QtGui/private/qcoregraphics_p.h> #include <QtGui/private/qcoregraphics_p.h>
#include <QtGui/private/qmacmimeregistry_p.h>
#include <QtGui/private/qopenglcontext_p.h> #include <QtGui/private/qopenglcontext_p.h>
#include <QtGui/private/qrhibackingstore_p.h> #include <QtGui/private/qrhibackingstore_p.h>
#include <QtGui/private/qfontengine_coretext_p.h> #include <QtGui/private/qfontengine_coretext_p.h>
@ -164,7 +165,7 @@ QCocoaIntegration::QCocoaIntegration(const QStringList &paramList)
QCocoaScreen::initializeScreens(); QCocoaScreen::initializeScreens();
QMacInternalPasteboardMime::initializeMimeTypes(); QMacMimeRegistry::initializeMimeTypes();
QCocoaMimeTypes::initializeMimeTypes(); QCocoaMimeTypes::initializeMimeTypes();
QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(false); QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(false);
QWindowSystemInterface::registerInputDevice(new QInputDevice(QString("keyboard"), 0, QWindowSystemInterface::registerInputDevice(new QInputDevice(QString("keyboard"), 0,
@ -194,7 +195,7 @@ QCocoaIntegration::~QCocoaIntegration()
// Deleting the clipboard integration flushes promised pastes using // Deleting the clipboard integration flushes promised pastes using
// the mime converters - the ordering here is important. // the mime converters - the ordering here is important.
delete mCocoaClipboard; delete mCocoaClipboard;
QMacInternalPasteboardMime::destroyMimeTypes(); QMacMimeRegistry::destroyMimeTypes();
#endif #endif
QCocoaScreen::cleanupScreens(); QCocoaScreen::cleanupScreens();

View File

@ -26,6 +26,7 @@
#include <QtGui/qguiapplication.h> #include <QtGui/qguiapplication.h>
#include <qdebug.h> #include <qdebug.h>
#include <QtGui/private/qmacmimeregistry_p.h>
#include <QtGui/private/qcoregraphics_p.h> #include <QtGui/private/qcoregraphics_p.h>
#if QT_CONFIG(vulkan) #if QT_CONFIG(vulkan)
@ -120,7 +121,7 @@ void QCocoaNativeInterface::onAppFocusWindowChanged(QWindow *window)
void QCocoaNativeInterface::registerDraggedTypes(const QStringList &types) void QCocoaNativeInterface::registerDraggedTypes(const QStringList &types)
{ {
qt_mac_registerDraggedTypes(types); QMacMimeRegistry::registerDraggedTypes(types);
} }
void QCocoaNativeInterface::setEmbeddedInForeignView(QPlatformWindow *window, bool embedded) void QCocoaNativeInterface::setEmbeddedInForeignView(QPlatformWindow *window, bool embedded)

View File

@ -5,13 +5,14 @@
#define QMACCLIPBOARD_H #define QMACCLIPBOARD_H
#include <QtGui> #include <QtGui>
#include <QtGui/private/qmacmime_p.h>
#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QMacMimeData; class QMacMimeData;
class QMacInternalPasteboardMime;
class QMacPasteboard class QMacPasteboard
{ {
public: public:

View File

@ -4,6 +4,8 @@
#include <AppKit/AppKit.h> #include <AppKit/AppKit.h>
#include "qmacclipboard.h" #include "qmacclipboard.h"
#include <QtGui/private/qmacmimeregistry_p.h>
#include <QtGui/private/qmacmime_p.h>
#include <QtGui/qclipboard.h> #include <QtGui/qclipboard.h>
#include <QtGui/qguiapplication.h> #include <QtGui/qguiapplication.h>
#include <QtGui/qbitmap.h> #include <QtGui/qbitmap.h>
@ -130,7 +132,7 @@ OSStatus QMacPasteboard::promiseKeeper(PasteboardRef paste, PasteboardItemID id,
// Find the kept promise // Find the kept promise
QList<QMacInternalPasteboardMime*> availableConverters QList<QMacInternalPasteboardMime*> availableConverters
= QMacInternalPasteboardMime::all(QMacInternalPasteboardMime::MIME_ALL); = QMacMimeRegistry::all(QMacInternalPasteboardMime::MIME_ALL);
const QString flavorAsQString = QString::fromCFString(flavor); const QString flavorAsQString = QString::fromCFString(flavor);
QMacPasteboard::Promise promise; QMacPasteboard::Promise promise;
for (int i = 0; i < qpaste->promises.size(); i++){ for (int i = 0; i < qpaste->promises.size(); i++){
@ -297,7 +299,7 @@ QMacPasteboard::setMimeData(QMimeData *mime_src, DataRequestType dataRequestType
delete mime; delete mime;
mime = mime_src; mime = mime_src;
QList<QMacInternalPasteboardMime*> availableConverters = QMacInternalPasteboardMime::all(mime_type); QList<QMacInternalPasteboardMime*> availableConverters = QMacMimeRegistry::all(mime_type);
if (mime != nullptr) { if (mime != nullptr) {
clear_helper(); clear_helper();
QStringList formats = mime_src->formats(); QStringList formats = mime_src->formats();
@ -372,7 +374,7 @@ QMacPasteboard::formats() const
for (int i = 0; i < type_count; ++i) { for (int i = 0; i < type_count; ++i) {
const QString flavor = QString::fromCFString((CFStringRef)CFArrayGetValueAtIndex(types, i)); const QString flavor = QString::fromCFString((CFStringRef)CFArrayGetValueAtIndex(types, i));
qCDebug(lcQpaClipboard, " -%s", qPrintable(QString(flavor))); qCDebug(lcQpaClipboard, " -%s", qPrintable(QString(flavor)));
QString mimeType = QMacInternalPasteboardMime::flavorToMime(mime_type, flavor); QString mimeType = QMacMimeRegistry::flavorToMime(mime_type, flavor);
if (!mimeType.isEmpty() && !ret.contains(mimeType)) { if (!mimeType.isEmpty() && !ret.contains(mimeType)) {
qCDebug(lcQpaClipboard, " -<%lld> %s [%s]", ret.size(), qPrintable(mimeType), qPrintable(QString(flavor))); qCDebug(lcQpaClipboard, " -<%lld> %s [%s]", ret.size(), qPrintable(mimeType), qPrintable(QString(flavor)));
ret << mimeType; ret << mimeType;
@ -409,7 +411,7 @@ QMacPasteboard::hasFormat(const QString &format) const
for (int i = 0; i < type_count; ++i) { for (int i = 0; i < type_count; ++i) {
const QString flavor = QString::fromCFString((CFStringRef)CFArrayGetValueAtIndex(types, i)); const QString flavor = QString::fromCFString((CFStringRef)CFArrayGetValueAtIndex(types, i));
qCDebug(lcQpaClipboard, " -%s [0x%x]", qPrintable(QString(flavor)), mime_type); qCDebug(lcQpaClipboard, " -%s [0x%x]", qPrintable(QString(flavor)), mime_type);
QString mimeType = QMacInternalPasteboardMime::flavorToMime(mime_type, flavor); QString mimeType = QMacMimeRegistry::flavorToMime(mime_type, flavor);
if (!mimeType.isEmpty()) if (!mimeType.isEmpty())
qCDebug(lcQpaClipboard, " - %s", qPrintable(mimeType)); qCDebug(lcQpaClipboard, " - %s", qPrintable(mimeType));
if (mimeType == format) if (mimeType == format)
@ -432,7 +434,7 @@ QMacPasteboard::retrieveData(const QString &format, QMetaType) const
return QByteArray(); return QByteArray();
qCDebug(lcQpaClipboard, "Pasteboard: retrieveData [%s]", qPrintable(format)); qCDebug(lcQpaClipboard, "Pasteboard: retrieveData [%s]", qPrintable(format));
const QList<QMacInternalPasteboardMime *> mimes = QMacInternalPasteboardMime::all(mime_type); const QList<QMacInternalPasteboardMime *> mimes = QMacMimeRegistry::all(mime_type);
for (int mime = 0; mime < mimes.size(); ++mime) { for (int mime = 0; mime < mimes.size(); ++mime) {
QMacInternalPasteboardMime *c = mimes.at(mime); QMacInternalPasteboardMime *c = mimes.at(mime);
QString c_flavor = c->flavorFor(format); QString c_flavor = c->flavorFor(format);

View File

@ -34,6 +34,7 @@
#include "qcocoaglcontext.h" #include "qcocoaglcontext.h"
#endif #endif
#include "qcocoaintegration.h" #include "qcocoaintegration.h"
#include <QtGui/private/qmacmimeregistry_p.h>
// Private interface // Private interface
@interface QNSView () @interface QNSView ()

View File

@ -21,7 +21,7 @@
NSPasteboardTypeMultipleTextSelection, mimeTypeGeneric]]; NSPasteboardTypeMultipleTextSelection, mimeTypeGeneric]];
// Add custom types supported by the application // Add custom types supported by the application
for (const QString &customType : qt_mac_enabledDraggedTypes()) for (const QString &customType : QMacMimeRegistry::enabledDraggedTypes())
[supportedTypes addObject:customType.toNSString()]; [supportedTypes addObject:customType.toNSString()];
[self registerForDraggedTypes:supportedTypes]; [self registerForDraggedTypes:supportedTypes];

View File

@ -6,6 +6,7 @@
#ifndef QT_NO_CLIPBOARD #ifndef QT_NO_CLIPBOARD
#include <QtCore/qurl.h> #include <QtCore/qurl.h>
#include <QtGui/private/qmacmimeregistry_p.h>
#include <QtGui/private/qmacmime_p.h> #include <QtGui/private/qmacmime_p.h>
#include <QtCore/QMimeData> #include <QtCore/QMimeData>
#include <QtGui/QGuiApplication> #include <QtGui/QGuiApplication>
@ -116,7 +117,7 @@ QStringList QIOSMimeData::formats() const
for (NSUInteger i = 0; i < [pasteboardTypes count]; ++i) { for (NSUInteger i = 0; i < [pasteboardTypes count]; ++i) {
QString uti = QString::fromNSString([pasteboardTypes objectAtIndex:i]); QString uti = QString::fromNSString([pasteboardTypes objectAtIndex:i]);
QString mimeType = QMacInternalPasteboardMime::flavorToMime(QMacInternalPasteboardMime::MIME_ALL, uti); QString mimeType = QMacMimeRegistry::flavorToMime(QMacInternalPasteboardMime::MIME_ALL, uti);
if (!mimeType.isEmpty() && !foundMimeTypes.contains(mimeType)) if (!mimeType.isEmpty() && !foundMimeTypes.contains(mimeType))
foundMimeTypes << mimeType; foundMimeTypes << mimeType;
} }
@ -130,7 +131,7 @@ QVariant QIOSMimeData::retrieveData(const QString &mimeType, QMetaType) const
NSArray<NSString *> *pasteboardTypes = [pb pasteboardTypes]; NSArray<NSString *> *pasteboardTypes = [pb pasteboardTypes];
foreach (QMacInternalPasteboardMime *converter, foreach (QMacInternalPasteboardMime *converter,
QMacInternalPasteboardMime::all(QMacInternalPasteboardMime::MIME_ALL)) { QMacMimeRegistry::all(QMacInternalPasteboardMime::MIME_ALL)) {
if (!converter->canConvert(mimeType, converter->flavorFor(mimeType))) if (!converter->canConvert(mimeType, converter->flavorFor(mimeType)))
continue; continue;
@ -185,7 +186,7 @@ void QIOSClipboard::setMimeData(QMimeData *mimeData, QClipboard::Mode mode)
foreach (const QString &mimeType, mimeData->formats()) { foreach (const QString &mimeType, mimeData->formats()) {
foreach (QMacInternalPasteboardMime *converter, foreach (QMacInternalPasteboardMime *converter,
QMacInternalPasteboardMime::all(QMacInternalPasteboardMime::MIME_ALL)) { QMacMimeRegistry::all(QMacInternalPasteboardMime::MIME_ALL)) {
QString uti = converter->flavorFor(mimeType); QString uti = converter->flavorFor(mimeType);
if (uti.isEmpty() || !converter->canConvert(mimeType, uti)) if (uti.isEmpty() || !converter->canConvert(mimeType, uti))
continue; continue;

View File

@ -24,6 +24,7 @@
#include <qpa/qplatformoffscreensurface.h> #include <qpa/qplatformoffscreensurface.h>
#include <QtGui/private/qcoretextfontdatabase_p.h> #include <QtGui/private/qcoretextfontdatabase_p.h>
#include <QtGui/private/qmacmimeregistry_p.h>
#include <QtGui/private/qmacmime_p.h> #include <QtGui/private/qmacmime_p.h>
#include <QDir> #include <QDir>
#include <QOperatingSystemVersion> #include <QOperatingSystemVersion>
@ -89,7 +90,7 @@ void QIOSIntegration::initialize()
#if QT_CONFIG(tabletevent) #if QT_CONFIG(tabletevent)
QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(false); QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(false);
#endif #endif
QMacInternalPasteboardMime::initializeMimeTypes(); QMacMimeRegistry::initializeMimeTypes();
qsizetype size = QList<QPluginParsedMetaData>(m_optionalPlugins->metaData()).size(); qsizetype size = QList<QPluginParsedMetaData>(m_optionalPlugins->metaData()).size();
for (qsizetype i = 0; i < size; ++i) for (qsizetype i = 0; i < size; ++i)
@ -105,7 +106,7 @@ QIOSIntegration::~QIOSIntegration()
delete m_clipboard; delete m_clipboard;
m_clipboard = 0; m_clipboard = 0;
#endif #endif
QMacInternalPasteboardMime::destroyMimeTypes(); QMacMimeRegistry::destroyMimeTypes();
delete m_inputContext; delete m_inputContext;
m_inputContext = 0; m_inputContext = 0;