kmail

partNode.h

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 #include <map>
00049 
00050 class KMMimePartTreeItem;
00051 class KMMimePartTree;
00052 
00053 class KMReaderWin;
00054 
00055 /*
00056  ===========================================================================
00057 
00058 
00059        S T A R T    O F     T E M P O R A R Y     M I M E     C O D E
00060 
00061 
00062  ===========================================================================
00063   N O T E :   The partNode structure will most likely be replaced by KMime.
00064               It's purpose: Speed optimization for KDE 3.   (khz, 28.11.01)
00065  ===========================================================================
00066 */
00067 class partNode
00068 {
00069     partNode();
00070 
00071     int calcNodeIdOrFindNode( int& curId, const partNode* calcNode,
00072                               int findId, partNode** findNode );
00073 
00074     partNode( KMReaderWin * win, DwBodyPart* dwPart,
00075               int explicitType    = DwMime::kTypeUnknown,
00076               int explicitSubType = DwMime::kSubtypeUnknown,
00077           bool deleteDwBodyPart = false );
00078 
00079 public:
00080 
00081     struct AttachmentDisplayInfo
00082     {
00083       QString label;
00084       QString icon;
00085       bool displayInHeader;
00086     };
00087 
00088     static partNode * fromMessage( const KMMessage * msg, KMReaderWin * win=0 );
00089 
00090     partNode( bool deleteDwBodyPart,
00091               DwBodyPart* dwPart );
00092 
00093     ~partNode();
00094 
00095     void dump( int chars=0 ) const;
00096 
00097     void buildObjectTree( bool processSiblings=true );
00098 
00099     DwBodyPart* dwPart() const {
00100         return mDwPart;
00101     }
00102 
00103     void setDwPart( DwBodyPart* part ) {
00104         mDwPart = part;
00105         mMsgPartOk = false;
00106     }
00107 
00108     KMMessagePart& msgPart() const {
00109         if( !mMsgPartOk ) {
00110             KMMessage::bodyPart(mDwPart, &mMsgPart);
00111             mMsgPartOk = true;
00112         }
00113         return mMsgPart;
00114     }
00115 
00116     const QCString & encodedBody();
00117 
00118     void setType( int type ) {
00119         mType = type;
00120     }
00121 
00122     void setSubType( int subType ) {
00123         mSubType = subType;
00124     }
00125 
00126     int type() const {
00127         return mType;
00128     }
00129 
00130     QCString typeString() const;
00131 
00132     int subType() const {
00133         return mSubType;
00134     }
00135 
00136     QCString subTypeString() const;
00137 
00138     bool hasType( int type ) {
00139       return mType == type;
00140     }
00141 
00142     bool hasSubType( int subType ) {
00143       return mSubType == subType;
00144     }
00145 
00146     void setEncryptionState( KMMsgEncryptionState state ) {
00147         mEncryptionState = state;
00148     }
00149     KMMsgEncryptionState encryptionState() const {
00150         return mEncryptionState;
00151     }
00152 
00153     // look at the encryption states of all children and return result
00154     KMMsgEncryptionState overallEncryptionState() const ;
00155 
00156     // look at the signature states of all children and return result
00157     KMMsgSignatureState  overallSignatureState() const ;
00158 
00159     void setSignatureState( KMMsgSignatureState state ) {
00160         mSignatureState = state;
00161     }
00162     KMMsgSignatureState signatureState() const {
00163         return mSignatureState;
00164     }
00165 
00166     // path is a hierarchical path to this partNode. It is designed to
00167     // be stable under decryption, where new child nodes are
00168     // added. Treat it as an opaque string.
00169     QCString path() const;
00170 
00171     int nodeId() const;  // node ids start at 1 (this is the top level root node)
00172 
00173     partNode* findId( int id );  // returns the node which has the given id (or 0, resp.)
00174 
00175     partNode* findType( int type, int subType, bool deep=true, bool wide=true );
00176 
00177     partNode* findTypeNot( int type, int subType, bool deep=true,
00178                            bool wide=true );
00179 
00180     partNode* findNodeForDwPart( DwBodyPart* part );
00181 
00182     void fillMimePartTree( KMMimePartTreeItem* parentItem,
00183                            KMMimePartTree*     mimePartTree,
00184                            QString labelDescr    = QString::null,
00185                            QString labelCntType  = QString::null,
00186                            QString labelEncoding = QString::null,
00187                            KIO::filesize_t size=0,
00188                            bool revertOrder = false );
00189 
00190     void adjustDefaultType( partNode* node );
00191 
00192     void setNext( partNode* next ) {
00193         mNext = next;
00194         if( mNext ){
00195             mNext->mRoot = mRoot;
00196             adjustDefaultType( mNext );
00197         }
00198     }
00199 
00200     void setFirstChild( partNode* child ) {
00201         mChild = child;
00202         if( mChild ) {
00203             mChild->mRoot = this;
00204             adjustDefaultType( mChild );
00205         }
00206     }
00207 
00208     void setProcessed( bool processed, bool recurse ) {
00209         mWasProcessed = processed;
00210     if ( recurse ) {
00211       if( mChild )
00212             mChild->setProcessed( processed, true );
00213       if( mNext )
00214             mNext->setProcessed( processed, true );
00215     }
00216     }
00217 
00218     void setMimePartTreeItem( KMMimePartTreeItem* item ) {
00219         mMimePartTreeItem = item;
00220     }
00221 
00222     KMMimePartTreeItem* mimePartTreeItem() const {
00223         return mMimePartTreeItem;
00224     }
00225 
00226     void setFromAddress( const QString& address ) {
00227         mFromAddress = address;
00228     }
00229 
00230     bool isAttachment() const;
00231     bool isHeuristicalAttachment() const;
00235     bool isFirstTextPart() const;
00236 
00237     bool isToltecMessage() const;
00238 
00242     bool isInEncapsulatedMessage() const;
00243 
00244     bool hasContentDispositionInline() const;
00245 
00246     QString contentTypeParameter( const char * name ) const;
00247 
00248     const QString& trueFromAddress() const;
00249 
00250     const partNode * topLevelParent() const;
00251     partNode * parentNode() const { return mRoot; }
00252     partNode * nextSibling() const { return mNext; }
00253     partNode * firstChild() const { return mChild; }
00254     partNode * next( bool allowChildren=true ) const;
00255     int childCount() const;
00256     int totalChildCount() const;
00257     bool processed() const { return mWasProcessed; }
00258 
00259     KMail::Interface::BodyPartMemento * bodyPartMemento( const QCString & which ) const;
00260     void setBodyPartMemento( const QCString & which, KMail::Interface::BodyPartMemento * memento );
00261 
00262     // A flag to remember if the node was embedded. This is useful for attachment nodes, the reader
00263     // needs to know if they were displayed inline or not.
00264     bool isDisplayedEmbedded() const;
00265     void setDisplayedEmbedded( bool displayedEmbedded );
00266 
00267     // Same as above, but this time determines if the node was hidden or not
00268     bool isDisplayedHidden() const;
00269     void setDisplayedHidden( bool displayedHidden );
00270 
00271     // Get a href in the form attachment:<nodeId>?place=<place>, used by ObjectTreeParser and
00272     // UrlHandlerManager.
00273     QString asHREF( const QString &place ) const;
00274 
00275     AttachmentDisplayInfo attachmentDisplayInfo() const;
00276 
00277 private:
00278     KMReaderWin * reader() const {
00279         return mReader ? mReader : mRoot ? mRoot->reader() : 0 ;
00280     }
00281     KMail::Interface::BodyPartMemento * internalBodyPartMemento( const QCString & ) const;
00282     void internalSetBodyPartMemento( const QCString & which, KMail::Interface::BodyPartMemento * memento );
00283 
00284 private:
00285     partNode*     mRoot;
00286     partNode*     mNext;
00287     partNode*     mChild;
00288     bool          mWasProcessed; // to be used by parseObjectTree()
00289 private:
00290     DwBodyPart*   mDwPart;   // may be zero
00291     mutable KMMessagePart mMsgPart;  // is valid - even if mDwPart is zero
00292     QCString      mEncodedBody;
00293     QString       mFromAddress;
00294     int           mType;
00295     int           mSubType;
00296     KMMsgEncryptionState mEncryptionState;
00297     KMMsgSignatureState  mSignatureState;
00298     mutable bool  mMsgPartOk;
00299     bool          mEncodedOk;
00300     bool          mDeleteDwBodyPart;
00301     KMMimePartTreeItem* mMimePartTreeItem;
00302     std::map<QCString,KMail::Interface::BodyPartMemento*> mBodyPartMementoMap;
00303     KMReaderWin * mReader;
00304     bool mDisplayedEmbedded;
00305     bool mDisplayedHidden;
00306 };
00307 
00308 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys