Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qmacmimeregistry.mm
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QtCore/qmimedata.h>
5
6#include "qutimimeconverter.h"
8#include "qguiapplication.h"
9#include "private/qcore_mac_p.h"
10
12
13using namespace Qt::StringLiterals;
14
16
18Q_GLOBAL_STATIC(MimeList, globalMimeList)
19Q_GLOBAL_STATIC(QStringList, globalDraggedTypesList)
20
21// implemented in qutimimeconverter.mm
23
39{
40 (*globalDraggedTypesList()) += types;
41}
42
44{
45 return (*globalDraggedTypesList());
46}
47
48/*****************************************************************************
49 QDnD debug facilities
50 *****************************************************************************/
51//#define DEBUG_MIME_MAPS
52
65{
66 if (globalMimeList()->isEmpty())
68}
69
74{
75 MimeList *mimes = globalMimeList();
76 while (!mimes->isEmpty())
77 delete mimes->takeFirst();
78}
79
80/*
81 Returns a MIME type of for scope \a scope for \a uti, or \nullptr if none exists.
82*/
83QString flavorToMime(QUtiMimeConverter::HandlerScope scope, const QString &uti)
84{
85 const MimeList &mimes = *globalMimeList();
86 for (const auto &mime : mimes) {
87 const bool relevantScope = mime->scope() & scope;
88#ifdef DEBUG_MIME_MAPS
89 qDebug("QMacMimeRegistry::flavorToMime: attempting (%d) for uti %s [%s]",
90 relevantScope, qPrintable(uti), qPrintable((*it)->mimeForUti(uti)));
91#endif
92 if (relevantScope) {
93 const QString mimeType = mime->mimeForUti(uti);
94 if (!mimeType.isNull())
95 return mimeType;
96 }
97 }
98 return QString();
99}
100
102{
103 // globalMimeList is in decreasing priority order. Recently added
104 // converters take prioity over previously added converters: prepend
105 // to the list.
106 globalMimeList()->prepend(macMime);
107}
108
110{
112 globalMimeList()->removeAll(macMime);
113}
114
115
116/*
117 Returns a list of all currently defined QUtiMimeConverter objects for scope \a scope.
118*/
119QList<QUtiMimeConverter *> all(QUtiMimeConverter::HandlerScope scope)
120{
122 const MimeList &mimes = *globalMimeList();
123 for (const auto &mime : mimes) {
124 if (mime->scope() & scope)
125 ret.append(mime);
126 }
127 return ret;
128}
129
130} // namespace QMacMimeRegistry
131
static bool closingDown()
Returns true if the application objects are being destroyed; otherwise returns false.
Definition qlist.h:74
bool isEmpty() const noexcept
Definition qlist.h:390
value_type takeFirst()
Definition qlist.h:549
QList< QUtiMimeConverter * > MimeList
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
The QUtiMimeConverter class converts between a MIME type and a \l{https://developer....
void unregisterMimeConverter(QUtiMimeConverter *macMime)
const QStringList & enabledDraggedTypes()
QList< QUtiMimeConverter * > all(QUtiMimeConverter::HandlerScope scope)
QString flavorToMime(QUtiMimeConverter::HandlerScope scope, const QString &uti)
void registerDraggedTypes(const QStringList &types)
void registerMimeConverter(QUtiMimeConverter *macMime)
Combined button and popup list for selecting options.
const char * mimeType
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define qDebug
[1]
Definition qlogging.h:160
return ret
GLsizei GLenum GLenum * types
#define qPrintable(string)
Definition qstring.h:1391
application x qt windows mime
[2]