kmail

partNode.h

Go to the documentation of this file.
00001 /* -*- c++ -*-
00002     partNode.h A node in a MIME tree.
00003 
00004     This file is part of KMail, the KDE mail client.
00005     Copyright (c) 2002,2004 Klarälvdalens Datakonsult AB
00006 
00007     KMail is free software; you can redistribute it and/or modify it
00008     under the terms of the GNU General Public License, version 2, as
00009     published by the Free Software Foundation.
00010 
00011     KMail is distributed in the hope that it will be useful, but
00012     WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020     In addition, as a special exception, the copyright holders give
00021     permission to link the code of this program with any edition of
00022     the Qt library by Trolltech AS, Norway (or with modified versions
00023     of Qt that use the same license as Qt), and distribute linked
00024     combinations including the two.  You must obey the GNU General
00025     Public License in all respects for all of the code used other than
00026     Qt.  If you modify this file, you may extend this exception to
00027     your version of the file, but you are not obligated to do so.  If
00028     you do not wish to do so, delete this exception statement from
00029     your version.
00030 */
00031 
00032 #ifndef PARTNODE_H
00033 #define PARTNODE_H
00034 
00035 #include "kmmsgpart.h"
00036 #include "kmmsgbase.h"
00037 #include "kmmessage.h"
00038 
00039 #include "interfaces/bodypart.h"
00040 
00041 #include <mimelib/mimepp.h>
00042 #include <mimelib/body.h>
00043 #include <mimelib/utility.h>
00044 
00045 #include <kio/global.h>
00046 #include <kdebug.h>
00047 
00048 class KMMimePartTreeItem;
00049 class KMMimePartTree;
00050 
00051 /*
00052  ===========================================================================
00053 
00054 
00055        S T A R T    O F     T E M P O R A R Y     M I M E     C O D E
00056 
00057 
00058  ===========================================================================
00059   N O T E :   The partNode structure will most likely be replaced by KMime.
00060               It's purpose: Speed optimization for KDE 3.   (khz, 28.11.01)
00061  ===========================================================================
00062 */
00063 class partNode
00064 {
00065     partNode();
00066 
00067     int calcNodeIdOrFindNode( int& curId, const partNode* calcNode,
00068                               int findId, partNode** findNode );
00069 
00070 public:
00071     static partNode * fromMessage( const KMMessage * msg );
00072 
00073     partNode( DwBodyPart* dwPart,
00074               int explicitType    = DwMime::kTypeUnknown,
00075               int explicitSubType = DwMime::kSubtypeUnknown,
00076           bool deleteDwBodyPart = false );
00077 
00078     partNode( bool deleteDwBodyPart,
00079               DwBodyPart* dwPart );
00080 
00081     ~partNode();
00082 
00083     void dump( int chars=0 ) const;
00084 
00085     void buildObjectTree( bool processSiblings=true );
00086 
00087     DwBodyPart* dwPart() const {
00088         return mDwPart;
00089     }
00090 
00091     void setDwPart( DwBodyPart* part ) {
00092         mDwPart = part;
00093         mMsgPartOk = false;
00094     }
00095 
00096     KMMessagePart& msgPart() const {
00097         if( !mMsgPartOk ) {
00098             KMMessage::bodyPart(mDwPart, &mMsgPart);
00099             mMsgPartOk = true;
00100         }
00101         return mMsgPart;
00102     }
00103 
00104     const QCString & encodedBody();
00105 
00106     void setType( int type ) {
00107         mType = type;
00108     }
00109 
00110     void setSubType( int subType ) {
00111         mSubType = subType;
00112     }
00113 
00114     int type() const {
00115         return mType;
00116     }
00117 
00118     QCString typeString() const;
00119 
00120     int subType() const {
00121         return mSubType;
00122     }
00123 
00124     QCString subTypeString() const;
00125 
00126     bool hasType( int type ) {
00127       return mType == type;
00128     }
00129 
00130     bool hasSubType( int subType ) {
00131       return mSubType == subType;
00132     }
00133 
00134     void setEncryptionState( KMMsgEncryptionState state ) {
00135         mEncryptionState = state;
00136     }
00137     KMMsgEncryptionState encryptionState() const {
00138         return mEncryptionState;
00139     }
00140 
00141     // look at the encryption states of all children and return result
00142     KMMsgEncryptionState overallEncryptionState() const ;
00143 
00144     // look at the signature states of all children and return result
00145     KMMsgSignatureState  overallSignatureState() const ;
00146 
00147     void setSignatureState( KMMsgSignatureState state ) {
00148         mSignatureState = state;
00149     }
00150     KMMsgSignatureState signatureState() const {
00151         return mSignatureState;
00152     }
00153 
00154     int nodeId() const;  // node ids start at 1 (this is the top level root node)
00155 
00156     partNode* findId( int id );  // returns the node which has the given id (or 0, resp.)
00157 
00158     partNode* findType( int type, int subType, bool deep=true, bool wide=true );
00159 
00160     partNode* findTypeNot( int type, int subType, bool deep=true,
00161                            bool wide=true );
00162 
00163     partNode* findNodeForDwPart( DwBodyPart* part );
00164 
00165     void fillMimePartTree( KMMimePartTreeItem* parentItem,
00166                            KMMimePartTree*     mimePartTree,
00167                            QString labelDescr    = QString::null,
00168                            QString labelCntType  = QString::null,
00169                            QString labelEncoding = QString::null,
00170                            KIO::filesize_t size=0,
00171                            bool revertOrder = false );
00172 
00173     void adjustDefaultType( partNode* node );
00174 
00175     void setNext( partNode* next ) {
00176         mNext = next;
00177         if( mNext ){
00178             mNext->mRoot = mRoot;
00179             adjustDefaultType( mNext );
00180         }
00181     }
00182 
00183     void setFirstChild( partNode* child ) {
00184         mChild = child;
00185         if( mChild ) {
00186             mChild->mRoot = this;
00187             adjustDefaultType( mChild );
00188         }
00189     }
00190 
00191     void setProcessed( bool processed, bool recurse ) {
00192         mWasProcessed = processed;
00193     if ( recurse ) {
00194       if( mChild )
00195             mChild->setProcessed( processed, true );
00196       if( mNext )
00197             mNext->setProcessed( processed, true );
00198     }
00199     }
00200 
00201     void setMimePartTreeItem( KMMimePartTreeItem* item ) {
00202         mMimePartTreeItem = item;
00203     }
00204 
00205     KMMimePartTreeItem* mimePartTreeItem() {
00206         return mMimePartTreeItem;
00207     }
00208 
00209     void setFromAddress( const QString& address ) {
00210         mFromAddress = address;
00211     }
00212 
00213     bool isAttachment() const;
00214     bool isHeuristicalAttachment() const;
00218     bool isFirstTextPart() const;
00219 
00220     bool hasContentDispositionInline() const;
00221 
00222     QString contentTypeParameter( const char * name ) const;
00223 
00224     const QString& trueFromAddress() const;
00225 
00226     partNode * parentNode() const { return mRoot; }
00227     partNode * nextSibling() const { return mNext; }
00228     partNode * firstChild() const { return mChild; }
00229     partNode * next( bool allowChildren=true ) const;
00230     int childCount() const;
00231     bool processed() const { return mWasProcessed; }
00232 
00233     KMail::Interface::BodyPartMemento * bodyPartMemento() const { return mBodyPartMemento; };
00234     void setBodyPartMemento( KMail::Interface::BodyPartMemento * memento ) {
00235         mBodyPartMemento = memento;
00236     };
00237 
00238 private:
00239     partNode*     mRoot;
00240     partNode*     mNext;
00241     partNode*     mChild;
00242     bool          mWasProcessed; // to be used by parseObjectTree()
00243 private:
00244     DwBodyPart*   mDwPart;   // may be zero
00245     mutable KMMessagePart mMsgPart;  // is valid - even if mDwPart is zero
00246     QCString      mEncodedBody;
00247     QString       mFromAddress;
00248     int           mType;
00249     int           mSubType;
00250     KMMsgEncryptionState mEncryptionState;
00251     KMMsgSignatureState  mSignatureState;
00252     mutable bool  mMsgPartOk;
00253     bool          mEncodedOk;
00254     bool          mDeleteDwBodyPart;
00255     KMMimePartTreeItem* mMimePartTreeItem;
00256     KMail::Interface::BodyPartMemento * mBodyPartMemento;
00257 };
00258 
00259 #endif