diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-28 09:39:58 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-28 13:14:15 +0200 |
commit | 0f4cf6d96561a0a635c78cef7636ae6fe97a7353 (patch) | |
tree | 6747a2e98662e716efc06306b19fb18c725b4228 | |
parent | a25e455017fefef310642c6f33da4b8fd9ece4d2 (diff) |
Remove QWinMime
QWinMime extends the newly added QWindowsMime by the functionality
to register/unregister automatically in the constructor, destructor.
There is no good way of porting though since it would inherit from
a so-far private class. Remove it instead.
Task-number: QTBUG-83252
Change-Id: I2d43ad3c29bea328cee5274ea9c87f593695e346
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r-- | src/winextras/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/winextras/qwinmime.cpp | 188 | ||||
-rw-r--r-- | src/winextras/qwinmime.h | 84 | ||||
-rw-r--r-- | src/winextras/winextras.pro | 6 | ||||
-rw-r--r-- | tests/auto/.prev_CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/auto.pro | 3 | ||||
-rw-r--r-- | tests/auto/qwinmime/qwinmime.pro | 4 | ||||
-rw-r--r-- | tests/auto/qwinmime/tst_qwinmime.cpp | 137 |
9 files changed, 3 insertions, 422 deletions
diff --git a/src/winextras/CMakeLists.txt b/src/winextras/CMakeLists.txt index 9d6e7f8..47d6eac 100644 --- a/src/winextras/CMakeLists.txt +++ b/src/winextras/CMakeLists.txt @@ -13,7 +13,6 @@ qt_add_module(WinExtras qwinjumplist.cpp qwinjumplist.h qwinjumplist_p.h qwinjumplistcategory.cpp qwinjumplistcategory.h qwinjumplistcategory_p.h qwinjumplistitem.cpp qwinjumplistitem.h qwinjumplistitem_p.h - qwinmime.cpp qwinmime.h qwintaskbarbutton.cpp qwintaskbarbutton.h qwintaskbarbutton_p.h qwintaskbarprogress.cpp qwintaskbarprogress.h qwinthumbnailtoolbar.cpp qwinthumbnailtoolbar.h qwinthumbnailtoolbar_p.h diff --git a/src/winextras/qwinmime.cpp b/src/winextras/qwinmime.cpp deleted file mode 100644 index c0300ae..0000000 --- a/src/winextras/qwinmime.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWinExtras module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinmime.h" - -#include <QtGui/qguiapplication.h> -#include <QtCore/qmetaobject.h> -#include <QtCore/qdebug.h> - -#include <QtGui/qpa/qplatformnativeinterface.h> - -QT_BEGIN_NAMESPACE - -/*! - \class QWinMime - \inmodule QtWinExtras - \brief The QWinMime class maps open-standard MIME to Window Clipboard formats. - - Qt's drag-and-drop and clipboard facilities use the MIME standard. - On X11, this maps trivially to the Xdnd protocol, but on Windows - although some applications use MIME types to describe clipboard - formats, others use arbitrary non-standardized naming conventions, - or unnamed built-in formats of Windows. - - By instantiating subclasses of QWinMime that provide conversions - between Windows Clipboard and MIME formats, you can convert - proprietary clipboard formats to MIME formats. - - Qt has predefined support for the following Windows Clipboard formats: - - \table - \header \li Windows Format \li Equivalent MIME type - \row \li \c CF_UNICODETEXT \li \c text/plain - \row \li \c CF_TEXT \li \c text/plain - \row \li \c CF_DIB \li \c{image/xyz}, where \c xyz is - a \l{QImageWriter::supportedImageFormats()}{Qt image format} - \row \li \c CF_HDROP \li \c text/uri-list - \row \li \c CF_INETURL \li \c text/uri-list - \row \li \c CF_HTML \li \c text/html - \endtable - - An example use of this class would be to map the Windows Metafile - clipboard format (\c CF_METAFILEPICT) to and from the MIME type - \c{image/x-wmf}. This conversion might simply be adding or removing - a header, or even just passing on the data. See \l{Drag and Drop} - for more information on choosing and definition MIME types. - - You can check if a MIME type is convertible using canConvertFromMime() and - can perform conversions with convertToMime() and convertFromMime(). - - \since 5.4 -*/ - -/*! - Constructs a new conversion object, adding it to the globally accessed - list of available converters. -*/ -QWinMime::QWinMime() -{ - if (!QMetaObject::invokeMethod(QGuiApplication::platformNativeInterface(), - "registerWindowsMime", Q_ARG(void *, this))) { - qWarning() << Q_FUNC_INFO << "Unable to register mime type."; - } -} - -/*! - Destroys a conversion object, removing it from the global - list of available converters. -*/ -QWinMime::~QWinMime() -{ - if (!QMetaObject::invokeMethod(QGuiApplication::platformNativeInterface(), - "unregisterWindowsMime", Q_ARG(void *, this))) { - qWarning() << Q_FUNC_INFO << "Unable to unregister mime type."; - } -} - -/*! - Registers the MIME type \a mime, and returns an ID number - identifying the format on Windows. -*/ -int QWinMime::registerMimeType(const QString &mime) -{ - int result = 0; - if (!QMetaObject::invokeMethod(QGuiApplication::platformNativeInterface(), - "registerMimeType", - Q_RETURN_ARG(int, result), - Q_ARG(QString, mime))) { - qWarning() << Q_FUNC_INFO << "Unable to register mime type " << mime; - } - return result; -} - -/*! - \fn bool QWinMime::canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const - - Returns true if the converter can convert from the \a mimeData to - the format specified in \a formatetc. - - All subclasses must reimplement this pure virtual function. -*/ - -/*! - \fn bool QWinMime::canConvertToMime(const QString &mimeType, IDataObject *pDataObj) const - - Returns true if the converter can convert to the \a mimeType from - the available formats in \a pDataObj. - - All subclasses must reimplement this pure virtual function. -*/ - -/*! - \fn QString QWinMime::mimeForFormat(const FORMATETC &formatetc) const - - Returns the mime type that will be created form the format specified - in \a formatetc, or an empty string if this converter does not support - \a formatetc. - - All subclasses must reimplement this pure virtual function. -*/ - -/*! - \fn QList<FORMATETC> QWinMime::formatsForMime(const QString &mimeType, const QMimeData *mimeData) const - - Returns a QList of FORMATETC structures representing the different windows clipboard - formats that can be provided for the \a mimeType from the \a mimeData. - - All subclasses must reimplement this pure virtual function. -*/ - -/*! - \fn QVariant QWinMime::convertToMime(const QString &mimeType, IDataObject *pDataObj, - QVariant::Type preferredType) const - - Returns a QVariant containing the converted data for \a mimeType from \a pDataObj. - If possible the QVariant should be of the \a preferredType to avoid needless conversions. - - All subclasses must reimplement this pure virtual function. -*/ - -/*! - \fn bool QWinMime::convertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData, STGMEDIUM * pmedium) const - - Convert the \a mimeData to the format specified in \a formatetc. - The converted data should then be placed in \a pmedium structure. - - Return true if the conversion was successful. - - All subclasses must reimplement this pure virtual function. -*/ - -QT_END_NAMESPACE diff --git a/src/winextras/qwinmime.h b/src/winextras/qwinmime.h deleted file mode 100644 index 008911c..0000000 --- a/src/winextras/qwinmime.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWinExtras module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINMIME_H -#define QWINMIME_H - -#include <QtWinExtras/qwinextrasglobal.h> - -#include <QtCore/qt_windows.h> -#include <QtCore/qlist.h> -#include <QtCore/qvariant.h> - -QT_BEGIN_NAMESPACE - -class QMimeData; - -#ifdef Q_CLANG_QDOC -typedef struct _FORMATETC {} FORMATETC; -typedef struct _STGMEDIUM {} STGMEDIUM; -typedef void *HBITMAP; -typedef void *HICON; -typedef void *HRGN; -typedef void *IDataObject; -#endif - -class Q_WINEXTRAS_EXPORT QWinMime // Keep in sync with QWindowsMime in the Windows platform plugin. -{ - Q_DISABLE_COPY(QWinMime) -public: - QWinMime(); - virtual ~QWinMime(); - - // for converting from Qt - virtual bool canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const = 0; - virtual bool convertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData, STGMEDIUM * pmedium) const = 0; - virtual QList<FORMATETC> formatsForMime(const QString &mimeType, const QMimeData *mimeData) const = 0; - - // for converting to Qt - virtual bool canConvertToMime(const QString &mimeType, IDataObject *pDataObj) const = 0; - virtual QVariant convertToMime(const QString &mimeType, IDataObject *pDataObj, QVariant::Type preferredType) const = 0; - virtual QString mimeForFormat(const FORMATETC &formatetc) const = 0; - - static int registerMimeType(const QString &mime); -}; - -QT_END_NAMESPACE - -#endif // QWINMIME_H diff --git a/src/winextras/winextras.pro b/src/winextras/winextras.pro index 8f582a5..caedc0a 100644 --- a/src/winextras/winextras.pro +++ b/src/winextras/winextras.pro @@ -13,8 +13,7 @@ SOURCES += \ qwineventfilter.cpp \ qwinthumbnailtoolbar.cpp \ qwinthumbnailtoolbutton.cpp \ - qwinevent.cpp \ - qwinmime.cpp + qwinevent.cpp HEADERS += \ qwinfunctions.h \ @@ -37,8 +36,7 @@ HEADERS += \ qwinthumbnailtoolbutton.h \ qwinthumbnailtoolbutton_p.h \ qwinevent.h \ - windowsguidsdefs_p.h \ - qwinmime.h + windowsguidsdefs_p.h QMAKE_DOCS = $$PWD/doc/qtwinextras.qdocconf diff --git a/tests/auto/.prev_CMakeLists.txt b/tests/auto/.prev_CMakeLists.txt index 3198e58..bac7e9e 100644 --- a/tests/auto/.prev_CMakeLists.txt +++ b/tests/auto/.prev_CMakeLists.txt @@ -6,4 +6,3 @@ add_subdirectory(qpixmap) add_subdirectory(qwintaskbarbutton) add_subdirectory(qwintaskbarprogress) add_subdirectory(qwinjumplist) -add_subdirectory(qwinmime) diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt index a73c4dc..e8a3f77 100644 --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -6,4 +6,3 @@ add_subdirectory(qpixmap) add_subdirectory(qwintaskbarbutton) add_subdirectory(qwintaskbarprogress) add_subdirectory(qwinjumplist) -add_subdirectory(qwinmime) diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 9d16ff3..331bf7a 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -5,5 +5,4 @@ SUBDIRS += \ qpixmap \ qwintaskbarbutton \ qwintaskbarprogress \ - qwinjumplist \ - qwinmime + qwinjumplist diff --git a/tests/auto/qwinmime/qwinmime.pro b/tests/auto/qwinmime/qwinmime.pro deleted file mode 100644 index 9a1563a..0000000 --- a/tests/auto/qwinmime/qwinmime.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qwinmime -QT += testlib winextras widgets -SOURCES += tst_qwinmime.cpp diff --git a/tests/auto/qwinmime/tst_qwinmime.cpp b/tests/auto/qwinmime/tst_qwinmime.cpp deleted file mode 100644 index 20a404a..0000000 --- a/tests/auto/qwinmime/tst_qwinmime.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QWinMime> -#include <QtTest/QtTest> -#include <QtGui/QClipboard> -#include <QtGui/QPixmap> -#include <QtCore/QVariant> - -class TestMime : public QWinMime -{ -public: - TestMime(bool verbose = false) : m_verbose(verbose) {} - - bool canConvertFromMime(const FORMATETC &, const QMimeData *mimeData) const Q_DECL_OVERRIDE - { - if (m_verbose) - qDebug() << Q_FUNC_INFO << mimeData->formats(); - return false; - } - - bool convertFromMime(const FORMATETC &, const QMimeData *, STGMEDIUM *) const Q_DECL_OVERRIDE - { - if (m_verbose) - qDebug() << Q_FUNC_INFO; - return false; - } - - QList<FORMATETC> formatsForMime(const QString &mimeType, const QMimeData *mimeData) const Q_DECL_OVERRIDE - { - formatsForMimeCalled = true; - if (m_verbose) - qDebug() << Q_FUNC_INFO << mimeType << mimeData->formats(); - return QList<FORMATETC>(); - } - - bool canConvertToMime(const QString &mimeType, IDataObject *) const Q_DECL_OVERRIDE - { - if (m_verbose) - qDebug() << Q_FUNC_INFO << mimeType; - return false; - } - - QVariant convertToMime(const QString &mimeType, IDataObject *, QVariant::Type preferredType) const Q_DECL_OVERRIDE - { - if (m_verbose) - qDebug() << Q_FUNC_INFO << mimeType << preferredType; - return QVariant(); - } - - QString mimeForFormat(const FORMATETC &) const Q_DECL_OVERRIDE - { - if (m_verbose) - qDebug() << Q_FUNC_INFO; - return QString(); - } - - mutable bool formatsForMimeCalled = false; - -private: - const bool m_verbose; -}; - -class tst_QWinMime : public QObject -{ - Q_OBJECT - -private slots: - void testRegisterType(); - void testWinMime_data(); - void testWinMime(); -}; - -void tst_QWinMime::testRegisterType() -{ - const int type = QWinMime::registerMimeType("foo/bar"); - QVERIFY2(type >= 0, QByteArray::number(type)); -} - -void tst_QWinMime::testWinMime_data() -{ - QTest::addColumn<QVariant>("data"); - QTest::newRow("string") << QVariant(QStringLiteral("bla")); - QPixmap pm(10, 10); - pm.fill(Qt::black); - QTest::newRow("pixmap") << QVariant(pm); -} - -void tst_QWinMime::testWinMime() -{ - QFETCH(QVariant, data); - // Basic smoke test for crashes, copy some text into clipboard and check whether - // the test implementation is called. - TestMime testMime; - QClipboard *clipboard = QApplication::clipboard(); - switch (data.type()) { - case QMetaType::QString: - clipboard->setText(data.toString()); - break; - case QMetaType::QPixmap: - clipboard->setPixmap(data.value<QPixmap>()); - break; - default: - break; - } - QTRY_VERIFY(testMime.formatsForMimeCalled); -} - -QTEST_MAIN(tst_QWinMime) - -#include "tst_qwinmime.moc" |