File indexing completed on 2024-05-19 04:29:13

0001 /*
0002     This file is part of the Calligra libraries
0003 
0004     SPDX-FileCopyrightText: 2001 Werner Trobin <trobin@kde.org>
0005     SPDX-FileCopyrightText: 2002 Werner Trobin <trobin@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #ifndef KIS_IMPORT_EXPORT_FILTER_H
0011 #define KIS_IMPORT_EXPORT_FILTER_H
0012 
0013 #include <QObject>
0014 #include <QIODevice>
0015 #include <QMap>
0016 #include <QPointer>
0017 #include <QString>
0018 #include <QPair>
0019 #include <QList>
0020 #include <KoID.h>
0021 #include <QSharedPointer>
0022 #include <kis_properties_configuration.h>
0023 #include <kis_types.h>
0024 #include <KisExportCheckBase.h>
0025 
0026 class KoUpdater;
0027 class KisDocument;
0028 class KisConfigWidget;
0029 class KisImportUserFeedbackInterface;
0030 
0031 #include "kritaui_export.h"
0032 #include "KisImportExportErrorCode.h"
0033 
0034 /**
0035  * @brief The base class for import and export filters.
0036  *
0037  * Derive your filter class from this base class and implement
0038  * the @ref convert() method. Don't forget to specify the Q_OBJECT
0039  * macro in your class even if you don't use signals or slots.
0040  * This is needed as filters are created on the fly.
0041  *
0042  * @note Take care: The m_chain pointer is invalid while the constructor
0043  * runs due to the implementation -- @em don't use it in the constructor.
0044  * After the constructor, when running the @ref convert() method it's
0045  * guaranteed to be valid, so no need to check against 0.
0046  *
0047  * @note If the code is compiled in debug mode, setting CALLIGRA_DEBUG_FILTERS
0048  * environment variable to any value disables deletion of temporary files while
0049  * importing/exporting. This is useful for testing purposes.
0050  *
0051  * @author Werner Trobin <trobin@kde.org>
0052  * @todo the class has no constructor and therefore cannot initialize its private class
0053  */
0054 class KRITAUI_EXPORT KisImportExportFilter : public QObject
0055 {
0056     Q_OBJECT
0057 public:
0058     static const QString ImageContainsTransparencyTag;
0059     static const QString ColorModelIDTag;
0060     static const QString ColorDepthIDTag;
0061     static const QString sRGBTag;
0062     static const QString HDRTag;
0063     static const QString CICPPrimariesTag;
0064     static const QString CICPTransferCharacteristicsTag;
0065 public:
0066 
0067     ~KisImportExportFilter() override;
0068 
0069     void setBatchMode(bool batchmode);
0070     void setImportUserFeedBackInterface(KisImportUserFeedbackInterface *interface);
0071     void setFilename(const QString &filename);
0072     void setRealFilename(const QString &filename);
0073     void setMimeType(const QString &mime);
0074     void setUpdater(QPointer<KoUpdater> updater);
0075     QPointer<KoUpdater> updater();
0076 
0077     /**
0078      * The filter chain calls this method to perform the actual conversion.
0079      * The passed mimetypes should be a pair of those you specified in your
0080      * .desktop file.
0081      * You @em have to implement this method to make the filter work.
0082      *
0083      * @return The error status, see the @ref #ConversionStatus enum.
0084      *         KisImportExportFilter::OK means that everything is alright.
0085      */
0086     virtual KisImportExportErrorCode convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration = 0) = 0;
0087 
0088     /**
0089      * @brief defaultConfiguration defines the default settings for the given import export filter
0090      * @param from The mimetype of the source file/document
0091      * @param to The mimetype of the destination file/document
0092      * @return a serializable KisPropertiesConfiguration object
0093      */
0094     virtual KisPropertiesConfigurationSP defaultConfiguration(const QByteArray& from = "", const QByteArray& to = "") const;
0095 
0096     /**
0097      * @brief lastSavedConfiguration return the last saved configuration for this filter
0098      * @param from The mimetype of the source file/document
0099      * @param to The mimetype of the destination file/document
0100      * @return a serializable KisPropertiesConfiguration object
0101      */
0102     KisPropertiesConfigurationSP lastSavedConfiguration(const QByteArray &from = "", const QByteArray &to = "") const;
0103 
0104     /**
0105      * @brief createConfigurationWidget creates a widget that can be used to define the settings for a given import/export filter
0106      * @param parent the owner of the widget; the caller is responsible for deleting
0107      * @param from The mimetype of the source file/document
0108      * @param to The mimetype of the destination file/document
0109      *
0110      * @return the widget
0111      */
0112     virtual KisConfigWidget *createConfigurationWidget(QWidget *parent, const QByteArray& from = "", const QByteArray& to = "") const;
0113 
0114     /**
0115      * @brief generate and return the list of capabilities of this export filter. The list
0116      * @return returns the list of capabilities of this export filter
0117      */
0118     virtual QMap<QString, KisExportCheckBase*> exportChecks();
0119 
0120     /// Override and return false for the filters that use a library that cannot handle file handles, only file names.
0121     virtual bool supportsIO() const { return true; }
0122 
0123     /// Verify whether the given file is correct and readable
0124     virtual QString verify(const QString &fileName) const;
0125 
0126 protected:
0127     /**
0128      * This is the constructor your filter has to call, obviously.
0129      */
0130     KisImportExportFilter(QObject *parent = 0);
0131 
0132     QString filename() const;
0133     QString realFilename() const;
0134     bool batchMode() const;
0135     KisImportUserFeedbackInterface* importUserFeedBackInterface() const;
0136     QByteArray mimeType() const;
0137 
0138     void setProgress(int value);
0139     virtual void initializeCapabilities();
0140     void addCapability(KisExportCheckBase *capability);
0141     void addSupportedColorModels(QList<QPair<KoID, KoID> > supportedColorModels, const QString &name, KisExportCheckBase::Level level = KisExportCheckBase::PARTIALLY);
0142 
0143     QString verifyZiPBasedFiles(const QString &fileName, const QStringList &filesToCheck) const;
0144 
0145 private:
0146 
0147     KisImportExportFilter(const KisImportExportFilter& rhs);
0148     KisImportExportFilter& operator=(const KisImportExportFilter& rhs);
0149 
0150     class Private;
0151     Private *const d;
0152 
0153 };
0154 
0155 #endif