00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
#ifndef __koffice_filter_chain_h__
00020
#define __koffice_filter_chain_h__
00021
00022
#include <qcstring.h>
00023
#include <qasciidict.h>
00024
#include <qptrlist.h>
00025
#include <qstringlist.h>
00026
00027
#include <koFilter.h>
00028
#include <koQueryTrader.h>
00029
#include <koStoreDevice.h>
00030
00031
class KTempFile;
00032
class KoFilterManager;
00033
class KoDocument;
00034
class QStrList;
00035
00036
namespace KOffice {
00037
class Graph;
00038 }
00039
00048 class KoFilterChain :
public KShared
00049 {
00050
00051
00052
friend class KOffice::Graph;
00053
friend class KoFilterManager;
00054
00055
public:
00056
typedef KSharedPtr<KoFilterChain> Ptr;
00057
00058
virtual ~
KoFilterChain();
00059
00063 const KoFilterManager*
manager()
const {
return m_manager; }
00064
00070 KoFilter::ConversionStatus
invokeChain();
00071
00077
QString chainOutput() const;
00078
00083
QString inputFile();
00088
QString outputFile();
00089
00100
KoStoreDevice* storageFile( const
QString& name = "root",
KoStore::Mode mode =
KoStore::Read );
00101
00108
KoDocument* inputDocument();
00115
KoDocument* outputDocument();
00116
00117
00118
00119
void dump() const;
00120
00121 private:
00122
00123
00124
00125
KoFilterChain( const
KoFilterManager* manager );
00126
00127
void appendChainLink(
KoFilterEntry::Ptr filterEntry, const
QCString& from, const
QCString& to );
00128
void prependChainLink(
KoFilterEntry::Ptr filterEntry, const
QCString& from, const
QCString& to );
00129
00130
00131
00132
00133
00134
00135 friend
void KoEmbeddingFilter::filterChainEnterDirectory( const
QString& directory ) const;
00136
void enterDirectory( const
QString& directory );
00137 friend
void KoEmbeddingFilter::filterChainLeaveDirectory() const;
00138
void leaveDirectory();
00139
00140
00141
00142
00143
QString filterManagerImportFile() const;
00144
QString filterManagerExportFile() const;
00145
KoDocument* filterManagerKoDocument() const;
00146
int filterManagerDirection() const;
00147
KoFilterChain* const filterManagerParentChain() const;
00148
00149
00150
00151
00152
00153
void manageIO();
00154
void finalizeIO();
00155
00156
bool createTempFile( KTempFile** tempFile,
bool autoDelete = true );
00157
00158
void inputFileHelper(
KoDocument* document, const
QString& alternativeFile );
00159
void outputFileHelper(
bool autoDelete );
00160
KoStoreDevice* storageNewStreamHelper(
KoStore** storage,
KoStoreDevice** device, const
QString& name );
00161
KoStoreDevice* storageHelper( const
QString& file, const
QString& streamName,
00162
KoStore::Mode mode,
KoStore** storage,
KoStoreDevice** device );
00163
void storageInit( const
QString& file,
KoStore::Mode mode,
KoStore** storage );
00164
KoStoreDevice* storageInitEmbedding( const
QString& name );
00165
KoStoreDevice* storageCreateFirstStream( const
QString& streamName,
KoStore** storage,
KoStoreDevice** device );
00166
KoStoreDevice* storageCleanupHelper(
KoStore** storage );
00167
00168
KoDocument* createDocument( const
QString& file );
00169
KoDocument* createDocument( const
QCString& mimeType );
00170
00171
00172
00173 class ChainLink
00174 {
00175
00176
public:
00177 ChainLink(
KoFilterChain* chain, KoFilterEntry::Ptr filterEntry,
00178
const QCString& from,
const QCString& to );
00179
00180 KoFilter::ConversionStatus invokeFilter(
const ChainLink*
const parentChainLink );
00181
00182
QCString from()
const {
return m_from; }
00183
QCString to()
const {
return m_to; }
00184
00185
00186
void dump() const;
00187
00188
00189
00190
int lruPartIndex() const;
00191
00192 private:
00193 ChainLink( const ChainLink& rhs );
00194 ChainLink& operator=( const ChainLink& rhs );
00195
00196
void setupCommunication( const
KoFilter* const parentFilter ) const;
00197
void setupConnections( const
KoFilter* sender, const
QStrList& sigs,
00198 const
KoFilter* receiver, const
QStrList& sl0ts ) const;
00199
00200
KoFilterChain* m_chain;
00201
KoFilterEntry::Ptr m_filterEntry;
00202
QCString m_from, m_to;
00203
00204
00205
00206
KoFilter* m_filter;
00207
00208 class Private;
00209 Private* d;
00210 };
00211
00212
00213
00214 enum Whole { Beginning = 1, Middle = 2, End = 4, Done = 8 };
00215
00216
00217
KoFilterChain(
const KoFilterChain& rhs );
00218
KoFilterChain& operator=(
const KoFilterChain& rhs );
00219
00220
const KoFilterManager*
const m_manager;
00221
QPtrList<ChainLink> m_chainLinks;
00222
00223
00224
int m_state;
00225
00226
QString m_inputFile;
00227
QString m_outputFile;
00228
00229
KoStore* m_inputStorage;
00230
KoStoreDevice* m_inputStorageDevice;
00231
KoStore* m_outputStorage;
00232
KoStoreDevice* m_outputStorageDevice;
00233
00234
KoDocument* m_inputDocument;
00235
KoDocument* m_outputDocument;
00236
00237 KTempFile* m_inputTempFile;
00238 KTempFile* m_outputTempFile;
00239
00240
00241
00242
enum IOState { Nil, File, Storage,
Document };
00243 IOState m_inputQueried, m_outputQueried;
00244
00245
00246
00247
00248
00249
00250
QStringList m_internalEmbeddingDirectories;
00251
00252
class Private;
00253 Private* d;
00254 };
00255
00256
00257
00258
namespace KOffice
00259 {
00260
class Vertex;
00261
template<
class T>
class PriorityQueue;
00262
00263
00264
class Edge
00265 {
00266
00267
public:
00268
00269 Edge( Vertex* vertex, KoFilterEntry::Ptr filterEntry );
00270 ~Edge() {}
00271
00272
unsigned int weight()
const {
return m_filterEntry ? m_filterEntry->weight : 0; }
00273 KoFilterEntry::Ptr filterEntry()
const {
return m_filterEntry; }
00274
const Vertex* vertex()
const {
return m_vertex; }
00275
00276
00277
00278
00279
00280
00281
void relax(
const Vertex* predecessor, PriorityQueue<Vertex>& queue );
00282
00283
00284
void dump(
const QCString& indent )
const;
00285
00286
private:
00287 Edge(
const Edge& rhs );
00288 Edge& operator=(
const Edge& rhs );
00289
00290 Vertex* m_vertex;
00291 KoFilterEntry::Ptr m_filterEntry;
00292
00293
class Private;
00294 Private* d;
00295 };
00296
00297
00298
00299
class Vertex
00300 {
00301
00302
public:
00303 Vertex(
const QCString& mimeType );
00304 ~Vertex() {}
00305
00306
QCString mimeType()
const {
return m_mimeType; }
00307
00308
00309
00310
00311
bool setKey(
unsigned int key );
00312
unsigned int key()
const {
return m_weight; }
00313
00314
00315
void reset();
00316
00317
00318
void setIndex(
int index ) { m_index=index; }
00319
int index()
const {
return m_index; }
00320
00321
00322
00323
void setPredecessor(
const Vertex* predecessor ) { m_predecessor=predecessor; }
00324
const Vertex* predecessor()
const {
return m_predecessor; }
00325
00326
00327
void addEdge(
const Edge* edge );
00328
00329
00330
const Edge* findEdge(
const Vertex* vertex )
const;
00331
00332
00333
00334
void relaxVertices( PriorityQueue<Vertex>& queue );
00335
00336
00337
void dump(
const QCString& indent )
const;
00338
00339
private:
00340 Vertex(
const Vertex& rhs );
00341 Vertex& operator=(
const Vertex& rhs );
00342
00343
QPtrList<Edge> m_edges;
00344
const Vertex* m_predecessor;
00345
QCString m_mimeType;
00346
unsigned int m_weight;
00347
int m_index;
00348
00349
class Private;
00350 Private* d;
00351 };
00352
00353
00354
00355
00356
class Graph
00357 {
00358
00359
public:
00360 Graph(
const QCString& from );
00361 ~Graph() {}
00362
00363
bool isValid()
const {
return m_graphValid; }
00364
00365
QCString sourceMimeType()
const {
return m_from; }
00366
void setSourceMimeType(
const QCString& from );
00367
00368
00369
00370
00371
00372
00373 KoFilterChain::Ptr chain(
const KoFilterManager* manager,
QCString& to )
const;
00374
00375
00376
void dump() const;
00377
00378 private:
00379 Graph( const Graph& rhs );
00380 Graph& operator=( const Graph& rhs );
00381
00382
void buildGraph();
00383
void shortestPaths();
00384
QCString findKOfficePart() const;
00385
00386
QAsciiDict<Vertex> m_vertices;
00387
QCString m_from;
00388
bool m_graphValid;
00389
00390 class Private;
00391 Private* d;
00392 };
00393
00394 }
00395
00396 #endif