summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-11-02 14:13:54 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-11-07 09:31:04 +0100
commitbf08aac46ad50ae08cc0c5481bc66e962b8105bb (patch)
tree24226c619c687dc56c64819ce930c03b06c67ba7 /src/gui
parenta1622083db02514cb82a49d5c792e8de70fb2f9f (diff)
macOS: Make QMacMime's handler scope type-safe
The value indicates for which systems the handler is relevant, e.g. clipboard and/or drag'n'drop. Rename the enum from "MimeType", which is something else already, to "HandlerScope". Make the enum a scoped enum to avoid implicit conversion to uchar, and to allow for better value names. Use the type in APIs and only convert to uchar when needed. Make respective arguments default to both DnD and clipboard implicitly, instead of explicitly interpreting an invalid zero-value as a default value. Task-number: QTBUG-93632 Change-Id: I85ab982f6c9fe78ea4d030dd0b0791c8ab866f67 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/platform/darwin/qmacmime.mm26
-rw-r--r--src/gui/platform/darwin/qmacmime_p.h20
-rw-r--r--src/gui/platform/darwin/qmacmimeregistry.mm16
-rw-r--r--src/gui/platform/darwin/qmacmimeregistry_p.h7
4 files changed, 36 insertions, 33 deletions
diff --git a/src/gui/platform/darwin/qmacmime.mm b/src/gui/platform/darwin/qmacmime.mm
index 880667f429..12bd70358e 100644
--- a/src/gui/platform/darwin/qmacmime.mm
+++ b/src/gui/platform/darwin/qmacmime.mm
@@ -84,11 +84,11 @@ using namespace Qt::StringLiterals;
*/
/*
- Constructs a new conversion object of type \a t, adding it to the
+ Constructs a new conversion object of type \a scope, adding it to the
globally accessed list of available converters.
*/
-QMacMime::QMacMime(QMacPasteboardMimeType t)
- : m_type(t)
+QMacMime::QMacMime(HandlerScope scope)
+ : m_scope(scope)
{
QMacMimeRegistry::registerMimeConverter(this);
}
@@ -98,8 +98,9 @@ QMacMime::QMacMime(QMacPasteboardMimeType t)
globally accessed list of available converters.
*/
QMacMime::QMacMime()
- : QMacMime(MIME_ALL)
-{}
+ : QMacMime(HandlerScope::All)
+{
+}
/*
Destroys a conversion object, removing it from the global
@@ -119,10 +120,9 @@ int QMacMime::count(const QMimeData *mimeData) const
return 1;
}
-class QMacMimeAny : public QMacMime
-{
+class QMacMimeAny : public QMacMime {
public:
- QMacMimeAny() : QMacMime(MIME_ALL_COMPATIBLE) {}
+ QMacMimeAny() : QMacMime(HandlerScope::AllCompatible) {}
QString flavorFor(const QString &mime) const override;
QString mimeFor(const QString &flav) const override;
@@ -175,10 +175,11 @@ QList<QByteArray> QMacMimeAny::convertFromMime(const QString &mime, const QVaria
return ret;
}
-class QMacMimeTypeName : public QMacMime
-{
+class QMacMimeTypeName : public QMacMime {
+private:
+
public:
- QMacMimeTypeName(): QMacMime(MIME_ALL_COMPATIBLE) {}
+ QMacMimeTypeName(): QMacMime(HandlerScope::AllCompatible) {}
QString flavorFor(const QString &mime) const override;
QString mimeFor(const QString &flav) const override;
@@ -217,7 +218,8 @@ QList<QByteArray> QMacMimeTypeName::convertFromMime(const QString &, const QVari
return ret;
}
-class QMacMimePlainTextFallback : public QMacMime {
+class QMacMimePlainTextFallback : public QMacMime
+{
public:
QString flavorFor(const QString &mime) const override;
QString mimeFor(const QString &flav) const override;
diff --git a/src/gui/platform/darwin/qmacmime_p.h b/src/gui/platform/darwin/qmacmime_p.h
index 52465be4aa..ece7ad9fa2 100644
--- a/src/gui/platform/darwin/qmacmime_p.h
+++ b/src/gui/platform/darwin/qmacmime_p.h
@@ -25,21 +25,21 @@ QT_BEGIN_NAMESPACE
class Q_GUI_EXPORT QMacMime
{
public:
- enum QMacPasteboardMimeType
+ enum class HandlerScope : uchar
{
- MIME_DND = 0x01,
- MIME_CLIP = 0x02,
- MIME_QT_CONVERTOR = 0x04,
- MIME_QT3_CONVERTOR = 0x08,
- MIME_ALL = MIME_DND|MIME_CLIP,
- MIME_ALL_COMPATIBLE = MIME_ALL|MIME_QT_CONVERTOR
+ DnD = 0x01,
+ Clipboard = 0x02,
+ Qt_compatible = 0x04,
+ Qt3_compatible = 0x08,
+ All = DnD|Clipboard,
+ AllCompatible = All|Qt_compatible
};
QMacMime();
- explicit QMacMime(QMacPasteboardMimeType type); // internal
+ explicit QMacMime(HandlerScope scope); // internal
virtual ~QMacMime();
- char type() const { return m_type; }
+ HandlerScope scope() const { return m_scope; }
virtual bool canConvert(const QString &mime, const QString &flav) const = 0;
virtual QString mimeFor(const QString &flav) const = 0;
@@ -49,7 +49,7 @@ public:
virtual int count(const QMimeData *mimeData) const;
private:
- const QMacPasteboardMimeType m_type;
+ const HandlerScope m_scope;
};
QT_END_NAMESPACE
diff --git a/src/gui/platform/darwin/qmacmimeregistry.mm b/src/gui/platform/darwin/qmacmimeregistry.mm
index 38e562bd75..cd8468fca5 100644
--- a/src/gui/platform/darwin/qmacmimeregistry.mm
+++ b/src/gui/platform/darwin/qmacmimeregistry.mm
@@ -78,17 +78,18 @@ void destroyMimeTypes()
}
/*
- Returns a MIME type of type \a t for \a flav, or 0 if none exists.
+ Returns a MIME type of for scope \a scope for \a flav, or \nullptr if none exists.
*/
-QString flavorToMime(uchar t, QString flav)
+QString flavorToMime(QMacMime::HandlerScope scope, const QString &flav)
{
MimeList *mimes = globalMimeList();
for (MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) {
+ const bool relevantScope = uchar((*it)->scope()) & uchar(scope);
#ifdef DEBUG_MIME_MAPS
qDebug("QMacMimeRegistry::flavorToMime: attempting (%d) for flavor %s [%s]",
- (*it)->type() & t, qPrintable(flav), qPrintable((*it)->mimeFor(flav)));
+ relevantScope, qPrintable(flav), qPrintable((*it)->mimeFor(flav)));
#endif
- if ((*it)->type() & t) {
+ if (relevantScope) {
QString mimeType = (*it)->mimeFor(flav);
if (!mimeType.isNull())
return mimeType;
@@ -113,14 +114,15 @@ void unregisterMimeConverter(QMacMime *macMime)
/*
- Returns a list of all currently defined QMacMime objects of type \a t.
+ Returns a list of all currently defined QMacMime objects for scope \a scope.
*/
-QList<QMacMime *> all(uchar t)
+QList<QMacMime *> all(QMacMime::HandlerScope scope)
{
MimeList ret;
MimeList *mimes = globalMimeList();
for (MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) {
- if ((*it)->type() & t)
+ const bool relevantScope = uchar((*it)->scope()) & uchar(scope);
+ if (relevantScope)
ret.append((*it));
}
return ret;
diff --git a/src/gui/platform/darwin/qmacmimeregistry_p.h b/src/gui/platform/darwin/qmacmimeregistry_p.h
index 8dc9c105b4..fb35bd8304 100644
--- a/src/gui/platform/darwin/qmacmimeregistry_p.h
+++ b/src/gui/platform/darwin/qmacmimeregistry_p.h
@@ -17,13 +17,12 @@
#include <QtGui/private/qtguiglobal_p.h>
+#include <QtGui/private/qmacmime_p.h>
#include <CoreFoundation/CoreFoundation.h>
QT_BEGIN_NAMESPACE
-class QMacMime;
-
namespace QMacMimeRegistry {
Q_GUI_EXPORT void initializeMimeTypes();
Q_GUI_EXPORT void destroyMimeTypes();
@@ -31,8 +30,8 @@ namespace QMacMimeRegistry {
Q_GUI_EXPORT void registerMimeConverter(QMacMime *);
Q_GUI_EXPORT void unregisterMimeConverter(QMacMime *);
- Q_GUI_EXPORT QList<QMacMime *> all(uchar);
- Q_GUI_EXPORT QString flavorToMime(uchar, QString flav);
+ Q_GUI_EXPORT QList<QMacMime *> all(QMacMime::HandlerScope scope);
+ Q_GUI_EXPORT QString flavorToMime(QMacMime::HandlerScope scope, const QString &flav);
Q_GUI_EXPORT void registerDraggedTypes(const QStringList &types);
Q_GUI_EXPORT const QStringList& enabledDraggedTypes();