Warning, file /office/calligra/libs/main/KoFilter.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the Calligra libraries 0002 Copyright (C) 2001 Werner Trobin <trobin@kde.org> 0003 2002 Werner Trobin <trobin@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef __KO_FILTER_H__ 0022 #define __KO_FILTER_H__ 0023 0024 #include <QObject> 0025 #include <QMap> 0026 #include <QPointer> 0027 0028 #include "komain_export.h" 0029 class KoFilterChain; 0030 class KoUpdater; 0031 0032 /** 0033 * @brief The base class for import and export filters. 0034 * 0035 * Derive your filter class from this base class and implement 0036 * the @ref convert() method. Don't forget to specify the Q_OBJECT 0037 * macro in your class even if you don't use signals or slots. 0038 * This is needed as filters are created on the fly. 0039 * The m_chain member allows access to the @ref KoFilterChain 0040 * which invokes the filter to query for input/output. 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 KOMAIN_EXPORT KoFilter : public QObject 0055 { 0056 Q_OBJECT 0057 0058 friend class KoFilterEntry; // needed for the filter chain pointer :( 0059 friend class KoFilterChain; 0060 0061 public: 0062 /** 0063 * This enum is used to signal the return state of your filter. 0064 * Return OK in @ref convert() in case everything worked as expected. 0065 * Feel free to add some more error conditions @em before the last item 0066 * if it's needed. 0067 */ 0068 enum ConversionStatus { OK, StupidError, UsageError, CreationError, FileNotFound, 0069 StorageCreationError, BadMimeType, BadConversionGraph, 0070 EmbeddedDocError, WrongFormat, NotImplemented, 0071 ParsingError, InternalError, UnexpectedEOF, 0072 UnexpectedOpcode, UserCancelled, OutOfMemory, 0073 PasswordProtected, InvalidFormat, FilterEntryNull, 0074 NoDocumentCreated, DownloadFailed, FilterCreationError, 0075 JustInCaseSomeBrokenCompilerUsesLessThanAByte = 255 0076 }; 0077 0078 ~KoFilter() override; 0079 0080 /** 0081 * The filter chain calls this method to perform the actual conversion. 0082 * The passed mimetypes should be a pair of those you specified in your 0083 * .desktop file. 0084 * You @em have to implement this method to make the filter work. 0085 * 0086 * @param from The mimetype of the source file/document 0087 * @param to The mimetype of the destination file/document 0088 * @return The error status, see the @ref #ConversionStatus enum. 0089 * KoFilter::OK means that everything is alright. 0090 */ 0091 virtual ConversionStatus convert(const QByteArray& from, const QByteArray& to) = 0; 0092 0093 /** 0094 * Set the updater to which the filter will report progress. 0095 * Every emit of the sigProgress signal is reported to the updater. 0096 */ 0097 void setUpdater(const QPointer<KoUpdater>& updater); 0098 0099 Q_SIGNALS: 0100 /** 0101 * Emit this signal with a value in the range of 1...100 to have some 0102 * progress feedback for the user in the statusbar of the application. 0103 * 0104 * @param value The actual progress state. Should always remain in 0105 * the range 1..100. 0106 */ 0107 void sigProgress(int value); 0108 0109 protected: 0110 /** 0111 * This is the constructor your filter has to call, obviously. 0112 */ 0113 KoFilter(QObject *parent = 0); 0114 0115 /** 0116 * Use this pointer to access all information about input/output 0117 * during the conversion. @em Don't use it in the constructor - 0118 * it's invalid while constructing the object! 0119 */ 0120 KoFilterChain *m_chain; 0121 0122 private: 0123 KoFilter(const KoFilter& rhs); 0124 KoFilter& operator=(const KoFilter& rhs); 0125 0126 class Private; 0127 Private *const d; 0128 0129 private Q_SLOTS: 0130 void slotProgress(int value); 0131 }; 0132 0133 #endif