From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kmail/kmmsglist.cpp | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 kmail/kmmsglist.cpp (limited to 'kmail/kmmsglist.cpp') diff --git a/kmail/kmmsglist.cpp b/kmail/kmmsglist.cpp new file mode 100644 index 000000000..b5af84894 --- /dev/null +++ b/kmail/kmmsglist.cpp @@ -0,0 +1,186 @@ +// kmmsglist.cpp + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "kmmsglist.h" +#include "kmmsgdict.h" // FIXME Till - move those into kmfolderindex +#include "kmkernel.h" +#include +#include + +//----------------------------------------------------------------------------- +KMMsgList::KMMsgList(int initSize) + : QMemArray(initSize), + mHigh( 0 ), mCount( 0 ) +{ + if ( size() > 0 ) + for (unsigned int i=size(); i>0; i--) + QMemArray::at(i-1) = 0; +} + + +//----------------------------------------------------------------------------- +KMMsgList::~KMMsgList() +{ + clear(TRUE); +} + + +//----------------------------------------------------------------------------- +void KMMsgList::clear(bool doDelete, bool syncDict) +{ + if ( mHigh > 0 ) + for (unsigned int i=mHigh; i>0; i--) + { + KMMsgBase * msg = at(i-1); + if (msg) { + if ( syncDict ) + KMMsgDict::mutableInstance()->remove(msg); + at(i-1) = 0; + if (doDelete) delete msg; + } + } + mHigh = 0; + mCount = 0; +} + + +//----------------------------------------------------------------------------- +bool KMMsgList::resize(unsigned int aSize) +{ + unsigned int i, oldSize = size(); + KMMsgBase* msg; + + // delete messages that will get lost, if any + if (aSize < mHigh) + { + for (i=aSize; i::resize(aSize)) return FALSE; + + // initialize new elements + for (i=oldSize; i= size()) + resize( idx > 2 * size() ? idx + 16 : 2 * size() ); + + if (!at(idx) && aMsg) mCount++; + else if (at(idx) && !aMsg) mCount--; + + at(idx) = aMsg; + + if (!aMsg || idx >= mHigh) rethinkHigh(); +} + + +//----------------------------------------------------------------------------- +void KMMsgList::insert(unsigned int idx, KMMsgBase* aMsg, bool syncDict) +{ + if (idx >= size()) + resize( idx > 2 * size() ? idx + 16 : 2 * size() ); + + if (aMsg) mCount++; + + for (unsigned int i=mHigh; i>idx; i--) { + if ( syncDict ) + KMMsgDict::mutableInstance()->remove(at(i - 1)); + at(i) = at(i-1); + if ( syncDict ) + KMMsgDict::mutableInstance()->insert(at(i), i); + } + + at(idx) = aMsg; + if ( syncDict ) + KMMsgDict::mutableInstance()->insert(at(idx), idx); + + mHigh++; +} + + +//----------------------------------------------------------------------------- +unsigned int KMMsgList::append(KMMsgBase* aMsg, bool syncDict) +{ + const unsigned int idx = mHigh; + insert(idx, aMsg, syncDict); // mHigh gets modified in here + return idx; +} + + +//----------------------------------------------------------------------------- +void KMMsgList::remove(unsigned int idx) +{ + assert(idxremove(at(idx)); + } + + mHigh--; + for (unsigned int i=idx; iupdate(at(i + 1), i + 1, i); + at(i) = at(i+1); + } + + at(mHigh) = 0; + + rethinkHigh(); +} + + +//----------------------------------------------------------------------------- +KMMsgBase* KMMsgList::take(unsigned int idx) +{ + KMMsgBase* msg=at(idx); + remove(idx); + return msg; +} + + +//----------------------------------------------------------------------------- +void KMMsgList::rethinkHigh() +{ + unsigned int sz = size(); + + if (mHigh < sz && at(mHigh)) + { + // forward search + while (mHigh < sz && at(mHigh)) + mHigh++; + } + else + { + // backward search + while (mHigh>0 && !at(mHigh-1)) + mHigh--; + } +} -- cgit v1.2.1