lib Library API Documentation

koFilter.h

00001 /* This file is part of the KOffice libraries
00002    Copyright (C) 2001 Werner Trobin <trobin@kde.org>
00003                  2002 Werner Trobin <trobin@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef __koffice_filter_h__
00021 #define __koffice_filter_h__
00022 
00023 #include <qobject.h>
00024 #include <qmap.h>
00025 #include <qptrstack.h>
00026 
00027 class QIODevice;
00028 class KoFilterChain;
00029 
00047 class KoFilter : public QObject
00048 {
00049     Q_OBJECT
00050 
00051     friend class KoFilterEntry;  // needed for the filter chain pointer :(
00052     friend class KoFilterChain;
00053 
00054 public:
00061     enum ConversionStatus { OK, StupidError, UsageError, CreationError, FileNotFound,
00062                             StorageCreationError, BadMimeType, BadConversionGraph,
00063                             EmbeddedDocError, WrongFormat, NotImplemented,
00064                             ParsingError, InternalError, UnexpectedEOF,
00065                             UnexpectedOpcode, UserCancelled, OutOfMemory,
00066                             JustInCaseSomeBrokenCompilerUsesLessThanAByte = 255 };
00067 
00068     virtual ~KoFilter();
00069 
00081     virtual ConversionStatus convert( const QCString& from, const QCString& to ) = 0;
00082 
00083 signals:
00091     void sigProgress( int value );
00092 
00093 protected:
00097     KoFilter();
00098 
00104     KoFilterChain* m_chain;
00105 
00106 private:
00107     KoFilter( const KoFilter& rhs );
00108     KoFilter& operator=( const KoFilter& rhs );
00109 
00110     class Private;
00111     Private* d;
00112 };
00113 
00114 
00142 class KoEmbeddingFilter : public KoFilter
00143 {
00144     Q_OBJECT
00145 
00146     friend class KoFilterChain;
00147 
00148 public:
00149     virtual ~KoEmbeddingFilter();
00150 
00159     int lruPartIndex() const;
00160 
00167     static QString mimeTypeByExtension( const QString& extension );
00168 
00169 protected:
00174     KoEmbeddingFilter();
00175 
00197     int embedPart( const QCString& from, QCString& to,
00198                    KoFilter::ConversionStatus& status,
00199                    const QString& key = QString::null );
00200 
00211     void startInternalEmbedding( const QString& key, const QCString& mimeType );
00212 
00219     void endInternalEmbedding();
00220 
00230     int internalPartReference( const QString& key ) const;
00231 
00240     QCString internalPartMimeType( const QString& key ) const;
00241 
00242 private:
00243     // Holds the directory's number and the mimetype of the part
00244     // for internal parts. This is all we need to locate a part.
00245     struct PartReference
00246     {
00247         PartReference( int index = -1, const QCString& mimeType = "" );
00248         bool isValid() const;
00249 
00250         int m_index;
00251         QCString m_mimeType;
00252     };
00253 
00254     // This struct keeps track of the last used index for a
00255     // child part and all references to existing children
00256     // We use it to build a whole stack, one PartState per
00257     // embedding level.
00258     struct PartState
00259     {
00260         PartState();
00261 
00262         int m_lruPartIndex;
00263         QMap<QString, PartReference> m_partReferences;
00264     };
00265 
00266     // Better don't copy or assign the filters
00267     KoEmbeddingFilter( const KoEmbeddingFilter& rhs );
00268     KoEmbeddingFilter& operator=( const KoEmbeddingFilter& rhs );
00269 
00280     virtual void savePartContents( QIODevice* file );
00281 
00282     // Internal methods to support the start/endInternalEmbedding
00283     // methods (we have to change directories and stuff).
00284     // These methods are declared friends of the KoFilterChain
00285     void filterChainEnterDirectory( const QString& directory ) const;
00286     void filterChainLeaveDirectory() const;
00287 
00288     // A stack which keeps track of the current part references.
00289     // We push one PartState structure for every embedding level.
00290     QPtrStack<PartState> m_partStack;
00291 
00292     class Private;
00293     Private* d;
00294 };
00295 
00296 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Mar 11 11:47:41 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003