/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. *
*/
css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL QtTransferable::getTransferDataFlavors()
{ if (!m_pMimeData) return css::uno::Sequence<css::datatransfer::DataFlavor>();
QStringList aFormatList(m_pMimeData->formats()); // we might add the UTF-16 mime text variant later constint nMimeTypeSeqSize = aFormatList.size() + 1; bool bHaveNoCharset = false, bHaveUTF16 = false, bHaveUTF8 = false;
css::uno::Sequence<css::datatransfer::DataFlavor> aMimeTypeSeq(nMimeTypeSeqSize); auto pMimeTypeSeq = aMimeTypeSeq.getArray();
css::datatransfer::DataFlavor aFlavor; int nMimeTypeCount = 0;
for (const QString& rMimeType : aFormatList)
{ // filter out non-MIME types such as TARGETS, MULTIPLE, TIMESTAMP if (rMimeType.indexOf('/') == -1) continue;
// gtk3 thinks it is not well defined - skip too if (rMimeType == QStringLiteral("text/plain;charset=unicode")) continue;
// At least the Qt6 Wasm implementation may announce text/uri-list even though the actual // list of URLs is empty (presumably since // <https://github.com/qt/qtbase/commit/0ffe8050bd5b55d64da37f5177a7e20dd9d14232> "wasm: // implement async drag-and-drop" unconditionally calls setUrls in // DataTransfer::toMimeDataWithFile's MimeContext::deref): if (rMimeType == QStringLiteral("text/uri-list"))
{ if (m_pMimeData->urls().empty())
{ continue;
}
}
// LO doesn't like 'text/plain', so we have to provide UTF-16 bool bIsNoCharset = false, bIsUTF16 = false, bIsUTF8 = false; if (lcl_textMimeInfo(toOUString(rMimeType), bIsNoCharset, bIsUTF16, bIsUTF8))
{
bHaveNoCharset |= bIsNoCharset;
bHaveUTF16 |= bIsUTF16;
bHaveUTF8 |= bIsUTF8; if (bIsUTF16)
aFlavor.DataType = cppu::UnoType<OUString>::get(); else
aFlavor.DataType = cppu::UnoType<css::uno::Sequence<sal_Int8>>::get();
} else
aFlavor.DataType = cppu::UnoType<css::uno::Sequence<sal_Int8>>::get();
bool QtMimeData::deepCopy(QMimeData** const pMimeCopy) const
{ if (!pMimeCopy) returnfalse;
QMimeData* pMimeData = new QMimeData(); for (QString& format : formats())
{
QByteArray aData = data(format); // Checking for custom MIME types if (format.startsWith("application/x-qt"))
{ // Retrieving true format name int indexBegin = format.indexOf('"') + 1; int indexEnd = format.indexOf('"', indexBegin);
format = format.mid(indexBegin, indexEnd - indexBegin);
}
pMimeData->setData(format, aData);
}
*pMimeCopy = pMimeData; returntrue;
}
QStringList QtMimeData::formats() const
{ if (!m_aMimeTypeList.isEmpty()) return m_aMimeTypeList;
// For the Qt6 Wasm backend, as a hack report only a single format for now: "text/plain" if // aFormats contains any "text/plain" entries, or else (randomly) the first entry (if any) of // aFormats. This is for two reasons: For one, // <https://github.com/qt/qtbase/commit/f0be152896471aa392bb1b2b649b66feb31480cc> "wasm: improve // clipboard support" has a commented-out "break;" ("Clipboard write is only supported with one // ClipboardItem at the moment but somehow this still works?") in the loop in // QWasmClipboard::writeToClipboardApi, and multiple formats would make that not work and would // indeed cause a NotAllowedError ("Failed to execute 'write' on 'Clipboard': Support for // multiple ClipboardItems is not implemented.") at least with Chrome 131. And for another, // <https://github.com/qt/qtbase/commit/f0be152896471aa392bb1b2b649b66feb31480cc> "wasm: improve // clipboard support" also has code to "prefer html over text" in // QWasmClipboard::writeToClipboardApi, so if we reported both "text/plain" and "text/html", // that code would pick "text/html", but the HTML provided by LO apparently always contains a // trailing "</p>", so would always add a newline when pasted.
// we provide a locale encoded and a UTF-8 variant, if missing if (m_bHaveNoCharset || bHaveUTF16 || m_bHaveUTF8)
{ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) && defined EMSCRIPTEN
aList << QStringLiteral("text/plain"); #else // if there is a text representation from LO point of view, it'll be UTF-16
assert(bHaveUTF16); if (!m_bHaveUTF8)
aList << QStringLiteral("text/plain;charset=utf-8"); if (!m_bHaveNoCharset)
aList << QStringLiteral("text/plain"); #endif
} #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) && defined EMSCRIPTEN elseif (aFormats.hasElements())
{
aList << toQString(aFormats[0].MimeType);
} #endif
try
{ // tdf#129809 take a reference in case m_aContents is replaced during this call
css::uno::Reference<css::datatransfer::XTransferable> xCurrentContents(m_aContents);
aValue = xCurrentContents->getTransferData(aFlavor);
} catch (...)
{
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.