Warning, file /office/calligra/libs/main/KoFilterChain.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 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef __KO_FILTER_CHAIN_H__ 0021 #define __KO_FILTER_CHAIN_H__ 0022 0023 #include <QHash> 0024 #include <QList> 0025 #include <QStringList> 0026 0027 #include "KoFilter.h" 0028 #include "KoFilterEntry.h" 0029 #include <KoStoreDevice.h> 0030 #include "komain_export.h" 0031 #include "KoFilterChainLinkList.h" 0032 0033 class QTemporaryFile; 0034 class KoFilterManager; 0035 class KoDocument; 0036 0037 0038 namespace CalligraFilter 0039 { 0040 class Graph; 0041 class ChainLink; 0042 class Vertex; 0043 class Edge; 0044 } 0045 0046 /** 0047 * @brief This class represents a chain of plain KoFilter instances. 0048 * 0049 * Instances of this class are shared, so please just hold 0050 * KoFilterChain::Ptr pointers to it. 0051 * 0052 * @author Werner Trobin <trobin@kde.org> 0053 * @todo the class has no constructor and therefore cannot initialize its private class 0054 */ 0055 class KOMAIN_EXPORT KoFilterChain : public QSharedData 0056 { 0057 // Only Calligra::Graph is allowed to construct instances and 0058 // add chain links. 0059 friend class Graph; 0060 friend class KoFilterManager; 0061 0062 public: 0063 typedef QExplicitlySharedDataPointer<KoFilterChain> Ptr; 0064 0065 virtual ~KoFilterChain(); 0066 0067 /** 0068 * The filter manager returned may be 0! 0069 */ 0070 const KoFilterManager* manager() const { 0071 return m_manager; 0072 } 0073 0074 /** 0075 * Starts the filtering process. 0076 * @return The return status of the conversion. KoFilter::OK 0077 * if everything is alright. 0078 */ 0079 KoFilter::ConversionStatus invokeChain(); 0080 0081 /** 0082 * Tells the @ref KoFilterManager the output file of the 0083 * filter chain in case of an import operation. If it's 0084 * an empty QString we directly manipulated the document. 0085 */ 0086 QString chainOutput() const; 0087 0088 /** 0089 * Get the current file to read from. This part of the API 0090 * is for the filters in our chain. 0091 */ 0092 QString inputFile(); 0093 /** 0094 * Get the current file to write to. This part of the API 0095 * is for the filters in our chain. 0096 */ 0097 QString outputFile(); 0098 0099 /** 0100 * Get a file from a storage. May return 0! 0101 * This part of the API is for the filters in our chain. 0102 * If you call it multiple times with the same stream name 0103 * the stream will be closed and re-opened. 0104 * Note: @em Don't delete that KoStoreDevice we return. 0105 * @param name The name of the stream inside the storage 0106 * @param mode Whether we want to read or write from/to the stream 0107 * @return The storage device to access the stream. May be 0! 0108 */ 0109 KoStoreDevice* storageFile(const QString& name = "root", KoStore::Mode mode = KoStore::Read); 0110 0111 /** 0112 * This method allows your filter to work directly on the 0113 * KoDocument of the application. 0114 * This part of the API is for the filters in our chain. 0115 * @return The document containing the data. May return 0 on error. 0116 */ 0117 KoDocument* inputDocument(); 0118 /** 0119 * This method allows your filter to work directly on the 0120 * KoDocument of the application. 0121 * This part of the API is for the filters in our chain. 0122 * @return The document you have to write to. May return 0 on error. 0123 */ 0124 KoDocument* outputDocument(); 0125 0126 0127 /// returns the amount of filters this chain contains representing the weight 0128 int weight() const; 0129 0130 // debugging 0131 void dump(); 0132 0133 private: 0134 // ### API for Calligra::Graph: 0135 // Construct a filter chain belonging to some KoFilterManager. 0136 // The parent filter manager may be 0. 0137 0138 friend class CalligraFilter::Graph; 0139 0140 explicit KoFilterChain(const KoFilterManager* manager); 0141 0142 void appendChainLink(KoFilterEntry::Ptr filterEntry, const QByteArray& from, const QByteArray& to); 0143 void prependChainLink(KoFilterEntry::Ptr filterEntry, const QByteArray& from, const QByteArray& to); 0144 0145 // These methods are friends of KoFilterManager and provide access 0146 // to a private part of its API. As I don't want to include 0147 // koFilterManager.h in this header the direction is "int" here. 0148 QString filterManagerImportFile() const; 0149 QString filterManagerExportFile() const; 0150 KoDocument* filterManagerKoDocument() const; 0151 int filterManagerDirection() const; 0152 KoFilterChain* filterManagerParentChain() const; 0153 0154 0155 // Helper methods which keep track of all the temp files, documents, 0156 // storages,... and properly delete them as soon as they are not 0157 // needed anymore. 0158 void manageIO(); 0159 void finalizeIO(); 0160 0161 bool createTempFile(QTemporaryFile** tempFile, bool autoDelete = true); 0162 0163 void inputFileHelper(KoDocument* document, const QString& alternativeFile); 0164 void outputFileHelper(bool autoDelete); 0165 KoStoreDevice* storageNewStreamHelper(KoStore** storage, KoStoreDevice** device, const QString& name); 0166 KoStoreDevice* storageHelper(const QString& file, const QString& streamName, 0167 KoStore::Mode mode, KoStore** storage, KoStoreDevice** device); 0168 void storageInit(const QString& file, KoStore::Mode mode, KoStore** storage); 0169 KoStoreDevice* storageCreateFirstStream(const QString& streamName, KoStore** storage, KoStoreDevice** device); 0170 KoStoreDevice* storageCleanupHelper(KoStore** storage); 0171 0172 KoDocument* createDocument(const QString& file); 0173 KoDocument* createDocument(const QByteArray& mimeType); 0174 0175 // "A whole is that which has beginning, middle, and end" - Aristotle 0176 // ...but we also need to signal "Done" state, Mr. Aristotle 0177 enum Whole { Beginning = 1, Middle = 2, End = 4, Done = 8 }; 0178 0179 // Don't copy or assign filter chains 0180 KoFilterChain(const KoFilterChain& rhs); 0181 KoFilterChain& operator=(const KoFilterChain& rhs); 0182 0183 const KoFilterManager* const m_manager; 0184 0185 CalligraFilter::ChainLinkList m_chainLinks; 0186 0187 // stuff needed for bookkeeping 0188 int m_state; 0189 0190 QString m_inputFile; // Did we pass around plain files? 0191 QString m_outputFile; 0192 0193 KoStore* m_inputStorage; // ...or was it a storage+device? 0194 KoStoreDevice* m_inputStorageDevice; 0195 KoStore* m_outputStorage; 0196 KoStoreDevice* m_outputStorageDevice; 0197 0198 KoDocument* m_inputDocument; // ...or even documents? 0199 KoDocument* m_outputDocument; 0200 0201 QTemporaryFile* m_inputTempFile; 0202 QTemporaryFile* m_outputTempFile; 0203 0204 // These two flags keep track of the input/output the 0205 // filter (=user) asked for 0206 enum IOState { Nil, File, Storage, Document }; 0207 IOState m_inputQueried, m_outputQueried; 0208 0209 class Private; 0210 Private * const d; 0211 }; 0212 0213 #endif // __KO_FILTER_CHAIN_H__