diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-11-07 15:35:05 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-11-09 13:22:30 +0100 |
commit | 7cc0a8741c88d6a9de414fdce169db981e41736e (patch) | |
tree | 366e7dcd51bc888b6ebb8f4b917f24c18aa69563 /src/plugins/platforms/cocoa/qmacclipboard.mm | |
parent | 2bdc027f5c6be9c551d40c80e510b19b6e2939a7 (diff) |
Make QMacMime::canConvert a non-virtual helper for other virtuals
Implementors are expected to return whether the converter can convert
both ways between a mime and a uti. However, this is implied in the
mimeForUti and utiForMime functions, and almost all converter implemented
canConvert by returning mimeForUti(uti) == mime.
A notable exception is the QMacMimeTypeName implementation, which can
only convert from from mime to uti using hard-coded special format names
and dummy data to provide place holders for drag'n'drop operations that
originate in Qt. That converter returned always false from canConvert,
but mapped the special "application/x-qt-mime-type-name" mime type to
the special "com.trolltech.qt.MimeTypeName" uti. Since nobody ever
requests data as "com.trolltech.qt.MimeTypeName", we still always ignore
that converter. The uti is then special-cased in the QMacClipboard code.
Lower-level code where only mime type or UTI are known can still call
the virtuals directly and check whether the returned string is empty,
which indicates that the converter does not support the conversion.
As a drive-by, fix coding style and variable naming.
Change-Id: I3d5d60faa82f8b31d9873c9da0097a308b9eeb50
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qmacclipboard.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qmacclipboard.mm | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/plugins/platforms/cocoa/qmacclipboard.mm b/src/plugins/platforms/cocoa/qmacclipboard.mm index 69102ae9c1..48b440923a 100644 --- a/src/plugins/platforms/cocoa/qmacclipboard.mm +++ b/src/plugins/platforms/cocoa/qmacclipboard.mm @@ -130,9 +130,8 @@ OSStatus QMacPasteboard::promiseKeeper(PasteboardRef paste, PasteboardItemID id, const long promise_id = (long)id; // Find the kept promise - QList<QMacMime*> availableConverters - = QMacMimeRegistry::all(QMacMime::HandlerScope::All); - const QString flavorAsQString = QString::fromCFString(uti); + const QList<QMacMime*> availableConverters = QMacMimeRegistry::all(QMacMime::HandlerScope::All); + const QString utiAsQString = QString::fromCFString(uti); QMacPasteboard::Promise promise; for (int i = 0; i < qpaste->promises.size(); i++){ const QMacPasteboard::Promise tmp = qpaste->promises[i]; @@ -146,13 +145,13 @@ OSStatus QMacPasteboard::promiseKeeper(PasteboardRef paste, PasteboardItemID id, continue; } - if (tmp.itemId == promise_id && tmp.converter->canConvert(tmp.mime, flavorAsQString)){ + if (tmp.itemId == promise_id && tmp.converter->canConvert(tmp.mime, utiAsQString)) { promise = tmp; break; } } - if (!promise.itemId && flavorAsQString == "com.trolltech.qt.MimeTypeName"_L1) { + if (!promise.itemId && utiAsQString == "com.trolltech.qt.MimeTypeName"_L1) { // we have promised this data, but won't be able to convert, so return null data. // This helps in making the application/x-qt-mime-type-name hidden from normal use. QByteArray ba; @@ -164,12 +163,12 @@ OSStatus QMacPasteboard::promiseKeeper(PasteboardRef paste, PasteboardItemID id, if (!promise.itemId) { // There was no promise that could deliver data for the // given id and uti. This should not happen. - qDebug("Pasteboard: %d: Request for %ld, %s, but no promise found!", __LINE__, promise_id, qPrintable(flavorAsQString)); + qDebug("Pasteboard: %d: Request for %ld, %s, but no promise found!", __LINE__, promise_id, qPrintable(utiAsQString)); return cantGetFlavorErr; } qCDebug(lcQpaClipboard, "PasteBoard: Calling in promise for %s[%ld] [%s] [%d]", qPrintable(promise.mime), promise_id, - qPrintable(flavorAsQString), promise.offset); + qPrintable(utiAsQString), promise.offset); // Get the promise data. If this is a "lazy" promise call variantData() // to request the data from the application. @@ -187,7 +186,7 @@ OSStatus QMacPasteboard::promiseKeeper(PasteboardRef paste, PasteboardItemID id, promiseData = promise.variantData; } - const QList<QByteArray> md = promise.converter->convertFromMime(promise.mime, promiseData, flavorAsQString); + const QList<QByteArray> md = promise.converter->convertFromMime(promise.mime, promiseData, utiAsQString); if (md.size() <= promise.offset) return cantGetFlavorErr; const QByteArray &ba = md[promise.offset]; |