| 1 | // Copyright (C) 2016 The Qt Company Ltd. | 
|---|---|
| 2 | // Copyright (C) 2016 Alex Char. | 
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | 
| 4 | |
| 5 | #include <QtGui/qimageiohandler.h> | 
| 6 | #include "qicnshandler_p.h" | 
| 7 | |
| 8 | #ifndef QT_NO_IMAGEFORMATPLUGIN | 
| 9 | #ifndef QT_NO_DATASTREAM | 
| 10 | |
| 11 | QT_BEGIN_NAMESPACE | 
| 12 | |
| 13 | class QICNSPlugin : public QImageIOPlugin | 
| 14 | { | 
| 15 | Q_OBJECT | 
| 16 |     Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface"FILE "icns.json")  | 
| 17 | |
| 18 | public: | 
| 19 | Capabilities capabilities(QIODevice *device, const QByteArray &format) const override; | 
| 20 | QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const override; | 
| 21 | }; | 
| 22 | |
| 23 | QImageIOPlugin::Capabilities QICNSPlugin::capabilities(QIODevice *device, const QByteArray &format) const | 
| 24 | { | 
| 25 |     if (format == QByteArrayLiteral("icns"))  | 
| 26 | return Capabilities(CanRead | CanWrite); | 
| 27 | Capabilities cap; | 
| 28 | if (!format.isEmpty()) | 
| 29 | return cap; | 
| 30 | if (!device || !device->isOpen()) | 
| 31 | return cap; | 
| 32 | |
| 33 | if (device->isReadable() && QICNSHandler::canRead(device)) | 
| 34 | cap |= CanRead; | 
| 35 | if (device->isWritable()) | 
| 36 | cap |= CanWrite; | 
| 37 | return cap; | 
| 38 | } | 
| 39 | |
| 40 | QImageIOHandler *QICNSPlugin::create(QIODevice *device, const QByteArray &format) const | 
| 41 | { | 
| 42 | QImageIOHandler *handler = new QICNSHandler(); | 
| 43 | handler->setDevice(device); | 
| 44 | handler->setFormat(format); | 
| 45 | return handler; | 
| 46 | } | 
| 47 | |
| 48 | QT_END_NAMESPACE | 
| 49 | |
| 50 | #include "main.moc" | 
| 51 | |
| 52 | #endif // QT_NO_DATASTREAM | 
| 53 | |
| 54 | #endif // QT_NO_IMAGEFORMATPLUGIN | 
| 55 | 
