From 77fd8e102a3775ac0683ee4d3ce6fd17977fd24e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 25 May 2009 09:48:49 +0000 Subject: [PATCH] Async KMail Reader (3/5): Allow storing of BodyPartMemento's in KMReader. This lets selected BodyPartMementos transcend the (temporary) partNode hierarchy in KMReader which is destroyed on every parseMsg() svn path=/branches/kdepim/enterprise/kdepim/; revision=972556 --- kmreaderwin.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++- kmreaderwin.h | 19 ++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/kmreaderwin.cpp b/kmreaderwin.cpp index ebe7efc1c..5d90fbcb6 100644 --- a/kmreaderwin.cpp +++ b/kmreaderwin.cpp @@ -1197,9 +1197,10 @@ void KMReaderWin::setMsg(KMMessage* aMsg, bool force) kdDebug(5006) << "(" << aMsg->getMsgSerNum() << ", last " << mLastSerNum << ") " << aMsg->subject() << " " << aMsg->fromStrip() << ", readyToShow " << (aMsg->readyToShow()) << endl; - //Reset the level quote if the msg has changed. + // Reset message-transient state if (aMsg && aMsg->getMsgSerNum() != mLastSerNum ){ mLevelQuote = GlobalSettings::self()->collapseQuoteLevelSpin()-1; + clearBodyPartMementos(); } if ( mPrinting ) mLevelQuote = -1; @@ -2780,6 +2781,51 @@ QString KMReaderWin::renderAttachments(partNode * node, const QColor &bgColor ) return html; } +using namespace KMail::Interface; + +void KMReaderWin::setBodyPartMemento( const partNode * node, const QCString & which, BodyPartMemento * memento ) +{ + const QCString index = node->path() + ':' + which.lower(); + + const std::map::iterator it = mBodyPartMementoMap.lower_bound( index ); + if ( it != mBodyPartMementoMap.end() && it->first == index ) { + + if ( memento && memento == it->second ) + return; + + delete it->second; + + if ( memento ) + it->second = memento; + else + mBodyPartMementoMap.erase( it ); + + } else { + if ( memento ) + mBodyPartMementoMap.insert( it, std::make_pair( index, memento ) ); + } + + if ( Observable * o = memento ? memento->asObservable() : 0 ) + o->attach( this ); +} + +BodyPartMemento * KMReaderWin::bodyPartMemento( const partNode * node, const QCString & which ) const +{ + const QCString index = node->path() + ':' + which.lower(); + const std::map::const_iterator it = mBodyPartMementoMap.find( index ); + if ( it == mBodyPartMementoMap.end() ) + return 0; + else + return it->second; +} + +void KMReaderWin::clearBodyPartMementos() +{ + for ( std::map::const_iterator it = mBodyPartMementoMap.begin(), end = mBodyPartMementoMap.end() ; it != end ; ++it ) + delete it->second; + mBodyPartMementoMap.clear(); +} + #include "kmreaderwin.moc" diff --git a/kmreaderwin.h b/kmreaderwin.h index 45e500c00..aa70d1dec 100644 --- a/kmreaderwin.h +++ b/kmreaderwin.h @@ -14,6 +14,8 @@ #include "kmmimeparttree.h" // Needed for friend declaration. #include "interfaces/observer.h" +#include + class QFrame; class QSplitter; class QHBox; @@ -42,6 +44,7 @@ class KMMessagePart; namespace KMail { namespace Interface { class Observable; + class BodyPartMemento; } class PartMetaData; class ObjectTreeParser; @@ -302,6 +305,19 @@ public: /* show or hide the list that points to the attachments */ void setShowAttachmentQuicklist( bool showAttachmentQuicklist = true ) { mShowAttachmentQuicklist = showAttachmentQuicklist; } + /* retrieve BodyPartMemento of id \a which for partNode \a node */ + KMail::Interface::BodyPartMemento * bodyPartMemento( const partNode * node, const QCString & which ) const; + + /* set/replace BodyPartMemento \a memento of id \a which for + partNode \a node. If there was a BodyPartMemento registered + already, replaces (deletes) that one. */ + void setBodyPartMemento( const partNode * node, const QCString & which, KMail::Interface::BodyPartMemento * memento ); + +private: + /* deletes all BodyPartMementos. Use this when skipping to another + message (as opposed to re-loading the same one again). */ + void clearBodyPartMementos(); + signals: /** Emitted after parsing of a message to have it stored in unencrypted state in it's folder. */ @@ -530,12 +546,13 @@ private: KToggleAction *mToggleFixFontAction; KURL mUrlClicked; KMail::HtmlWriter * mHtmlWriter; + std::map mBodyPartMementoMap; // an attachment should be updated bool mAtmUpdate; int mChoice; unsigned long mWaitingForSerNum; float mSavedRelativePosition; - int mLevelQuote; + int mLevelQuote; bool mDecrytMessageOverwrite; bool mShowSignatureDetails; bool mShowAttachmentQuicklist;