From 970b6e11c975c13d30885613ec2c5b8490f29b7c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 25 May 2009 09:58:57 +0000 Subject: [PATCH] Async KMail Reader (4/5): Extend partNode::setBodyPartMemento in two ways: 1. Allow more than one memento per node, by designating them with a string id 2. If backed by a KMReader, store the mementos there instead of in the partNode. Ideally, this would not be necessary, but it was deemed too risky to change KMReaderWin to avoid destroying the partNode hierarchy. svn path=/branches/kdepim/enterprise/kdepim/; revision=972564 --- kmreaderwin.cpp | 2 +- objecttreeparser.cpp | 3 ++ partNode.cpp | 66 ++++++++++++++++++++++++++++++++++++++------ partNode.h | 28 +++++++++++++------ partnodebodypart.cpp | 4 +-- 5 files changed, 82 insertions(+), 21 deletions(-) diff --git a/kmreaderwin.cpp b/kmreaderwin.cpp index 5d90fbcb6..7752db7c4 100644 --- a/kmreaderwin.cpp +++ b/kmreaderwin.cpp @@ -1560,7 +1560,7 @@ void KMReaderWin::parseMsg(KMMessage* aMsg) return; } else delete mRootNode; - mRootNode = partNode::fromMessage( aMsg ); + mRootNode = partNode::fromMessage( aMsg, this ); const QCString mainCntTypeStr = mRootNode->typeString() + '/' + mRootNode->subTypeString(); QString cntDesc = aMsg->subject(); diff --git a/objecttreeparser.cpp b/objecttreeparser.cpp index d98d0f66a..855f7f761 100644 --- a/objecttreeparser.cpp +++ b/objecttreeparser.cpp @@ -271,9 +271,12 @@ namespace KMail { // identity of KMail::Interface::BodyPart::Display and AttachmentStrategy::Display part.setDefaultDisplay( (KMail::Interface::BodyPart::Display) attachmentStrategy()->defaultDisplay( node ) ); const Interface::BodyPartFormatter::Result result = formatter->format( &part, htmlWriter() ); +#if 0 + // done in KMReaderWin::setBodyPartMemento() now if ( mReader && node->bodyPartMemento() ) if ( Interface::Observable * obs = node->bodyPartMemento()->asObservable() ) obs->attach( mReader ); +#endif switch ( result ) { case Interface::BodyPartFormatter::AsIcon: processResult.setNeverDisplayInline( true ); diff --git a/partNode.cpp b/partNode.cpp index e86ab3299..e5f207267 100644 --- a/partNode.cpp +++ b/partNode.cpp @@ -30,7 +30,10 @@ */ #include + #include "partNode.h" +#include "kmreaderwin.h" + #include #include #include "kmmimeparttree.h" @@ -64,12 +67,13 @@ partNode::partNode() mEncodedOk( false ), mDeleteDwBodyPart( false ), mMimePartTreeItem( 0 ), - mBodyPartMemento( 0 ) + mBodyPartMementoMap(), + mReader( 0 ) { adjustDefaultType( this ); } -partNode::partNode( DwBodyPart* dwPart, int explicitType, int explicitSubType, +partNode::partNode( KMReaderWin * win, DwBodyPart* dwPart, int explicitType, int explicitSubType, bool deleteDwBodyPart ) : mRoot( 0 ), mNext( 0 ), mChild( 0 ), mWasProcessed( false ), @@ -80,7 +84,8 @@ partNode::partNode( DwBodyPart* dwPart, int explicitType, int explicitSubType, mEncodedOk( false ), mDeleteDwBodyPart( deleteDwBodyPart ), mMimePartTreeItem( 0 ), - mBodyPartMemento( 0 ) + mBodyPartMementoMap(), + mReader( win ) { if ( explicitType != DwMime::kTypeUnknown ) { mType = explicitType; // this happens e.g. for the Root Node @@ -105,7 +110,7 @@ partNode::partNode( DwBodyPart* dwPart, int explicitType, int explicitSubType, #endif } -partNode * partNode::fromMessage( const KMMessage * msg ) { +partNode * partNode::fromMessage( const KMMessage * msg, KMReaderWin * win ) { if ( !msg ) return 0; @@ -124,7 +129,7 @@ partNode * partNode::fromMessage( const KMMessage * msg ) { // as just another DwBodyPart... DwBodyPart * mainBody = new DwBodyPart( *msg->getTopLevelPart() ); - partNode * root = new partNode( mainBody, mainType, mainSubType, true ); + partNode * root = new partNode( win, mainBody, mainType, mainSubType, true ); root->buildObjectTree(); root->setFromAddress( msg->from() ); @@ -142,7 +147,8 @@ partNode::partNode( bool deleteDwBodyPart, DwBodyPart* dwPart ) mEncodedOk( false ), mDeleteDwBodyPart( deleteDwBodyPart ), mMimePartTreeItem( 0 ), - mBodyPartMemento( 0 ) + mBodyPartMementoMap(), + mReader( 0 ) { if ( dwPart && dwPart->hasHeaders() && dwPart->Headers().HasContentType() ) { mType = (!dwPart->Headers().ContentType().Type())?DwMime::kTypeUnknown:dwPart->Headers().ContentType().Type(); @@ -159,7 +165,9 @@ partNode::~partNode() { mDwPart = 0; delete mChild; mChild = 0; delete mNext; mNext = 0; - delete mBodyPartMemento; mBodyPartMemento = 0; + for ( std::map::const_iterator it = mBodyPartMementoMap.begin(), end = mBodyPartMementoMap.end() ; it != end ; ++it ) + delete it->second; + mBodyPartMementoMap.clear(); } #ifndef NDEBUG @@ -194,7 +202,7 @@ void partNode::buildObjectTree( bool processSiblings ) while( curNode && curNode->dwPart() ) { //dive into multipart messages while( DwMime::kTypeMultipart == curNode->type() ) { - partNode * newNode = new partNode( curNode->dwPart()->Body().FirstBodyPart() ); + partNode * newNode = new partNode( mReader, curNode->dwPart()->Body().FirstBodyPart() ); curNode->setFirstChild( newNode ); curNode = newNode; } @@ -210,7 +218,7 @@ void partNode::buildObjectTree( bool processSiblings ) return; // store next node if( curNode && curNode->dwPart() && curNode->dwPart()->Next() ) { - partNode* nextNode = new partNode( curNode->dwPart()->Next() ); + partNode* nextNode = new partNode( mReader, curNode->dwPart()->Next() ); curNode->setNext( nextNode ); curNode = nextNode; } else @@ -625,3 +633,43 @@ const QString& partNode::trueFromAddress() const node = node->mRoot; return node->mFromAddress; } + +KMail::Interface::BodyPartMemento * partNode::bodyPartMemento( const QCString & which ) const +{ + if ( const KMReaderWin * r = reader() ) + return r->bodyPartMemento( this, which ); + else + return internalBodyPartMemento( which ); +} + +KMail::Interface::BodyPartMemento * partNode::internalBodyPartMemento( const QCString & which ) const +{ + assert( !reader() ); + + const std::map::const_iterator it = mBodyPartMementoMap.find( which.lower() ); + return it != mBodyPartMementoMap.end() ? it->second : 0 ; +} + +void partNode::setBodyPartMemento( const QCString & which, KMail::Interface::BodyPartMemento * memento ) +{ + if ( KMReaderWin * r = reader() ) + r->setBodyPartMemento( this, which, memento ); + else + internalSetBodyPartMemento( which, memento ); +} + +void partNode::internalSetBodyPartMemento( const QCString & which, KMail::Interface::BodyPartMemento * memento ) +{ + assert( !reader() ); + + const std::map::iterator it = mBodyPartMementoMap.lower_bound( which.lower() ); + if ( it != mBodyPartMementoMap.end() && it->first == which.lower() ) { + delete it->second; + if ( memento ) + it->second = memento; + else + mBodyPartMementoMap.erase( it ); + } else { + mBodyPartMementoMap.insert( it, std::make_pair( which.lower(), memento ) ); + } +} diff --git a/partNode.h b/partNode.h index 2c4a2459f..2f05602c6 100644 --- a/partNode.h +++ b/partNode.h @@ -45,9 +45,13 @@ #include #include +#include + class KMMimePartTreeItem; class KMMimePartTree; +class KMReaderWin; + /* =========================================================================== @@ -67,14 +71,14 @@ class partNode int calcNodeIdOrFindNode( int& curId, const partNode* calcNode, int findId, partNode** findNode ); -public: - static partNode * fromMessage( const KMMessage * msg ); - - partNode( DwBodyPart* dwPart, + partNode( KMReaderWin * win, DwBodyPart* dwPart, int explicitType = DwMime::kTypeUnknown, int explicitSubType = DwMime::kSubtypeUnknown, bool deleteDwBodyPart = false ); +public: + static partNode * fromMessage( const KMMessage * msg, KMReaderWin * win=0 ); + partNode( bool deleteDwBodyPart, DwBodyPart* dwPart ); @@ -235,10 +239,15 @@ public: int childCount() const; bool processed() const { return mWasProcessed; } - KMail::Interface::BodyPartMemento * bodyPartMemento() const { return mBodyPartMemento; }; - void setBodyPartMemento( KMail::Interface::BodyPartMemento * memento ) { - mBodyPartMemento = memento; - }; + KMail::Interface::BodyPartMemento * bodyPartMemento( const QCString & which ) const; + void setBodyPartMemento( const QCString & which, KMail::Interface::BodyPartMemento * memento ); + +private: + KMReaderWin * reader() const { + return mReader ? mReader : mRoot ? mRoot->reader() : 0 ; + } + KMail::Interface::BodyPartMemento * internalBodyPartMemento( const QCString & ) const; + void internalSetBodyPartMemento( const QCString & which, KMail::Interface::BodyPartMemento * memento ); private: partNode* mRoot; @@ -258,7 +267,8 @@ private: bool mEncodedOk; bool mDeleteDwBodyPart; KMMimePartTreeItem* mMimePartTreeItem; - KMail::Interface::BodyPartMemento * mBodyPartMemento; + std::map mBodyPartMementoMap; + KMReaderWin * mReader; }; #endif diff --git a/partnodebodypart.cpp b/partnodebodypart.cpp index 50ec3cda4..3b4e0f227 100644 --- a/partnodebodypart.cpp +++ b/partnodebodypart.cpp @@ -82,11 +82,11 @@ bool KMail::PartNodeBodyPart::hasCompleteBody() const { } KMail::Interface::BodyPartMemento * KMail::PartNodeBodyPart::memento() const { - return mPartNode.bodyPartMemento(); + return mPartNode.bodyPartMemento( "__plugin__" ); } void KMail::PartNodeBodyPart::setBodyPartMemento( Interface::BodyPartMemento * memento ) { - mPartNode.setBodyPartMemento( memento ); + mPartNode.setBodyPartMemento( "__plugin__", memento ); } KMail::Interface::BodyPart::Display KMail::PartNodeBodyPart::defaultDisplay() const {