kmail

headeritem.h
00001 /*******************************************************************************
00002 **
00003 ** Filename   : headeritem.h
00004 ** Created on : 28 November, 2004
00005 ** Copyright  : (c) 2004 Till Adam
00006 ** Email      : adam@kde.org
00007 **
00008 *******************************************************************************/
00009 
00010 /*******************************************************************************
00011 **
00012 **   This program is free software; you can redistribute it and/or modify
00013 **   it under the terms of the GNU General Public License as published by
00014 **   the Free Software Foundation; either version 2 of the License, or
00015 **   (at your option) any later version.
00016 **
00017 **   In addition, as a special exception, the copyright holders give
00018 **   permission to link the code of this program with any edition of
00019 **   the TQt library by Trolltech AS, Norway (or with modified versions
00020 **   of TQt that use the same license as TQt), and distribute linked
00021 **   combinations including the two.  You must obey the GNU General
00022 **   Public License in all respects for all of the code used other than
00023 **   TQt.  If you modify this file, you may extend this exception to
00024 **   your version of the file, but you are not obligated to do so.  If
00025 **   you do not wish to do so, delete this exception statement from
00026 **   your version.
00027 **
00028 *******************************************************************************/
00029 #ifndef HEADERITEM_H
00030 #define HEADERITEM_H
00031 
00032 #include <stdlib.h>
00033 
00034 #include <klistview.h> // include for the base class
00035 
00036 class KMMsgBase;
00037 class KPaintInfo;
00038 class KMFolder;
00039 class KMHeaders;
00040 
00041 namespace KMail
00042 {
00043 class HeaderItem; // forward declaration
00044 
00054 class SortCacheItem {
00055 
00056 public:
00057     SortCacheItem() : mItem(0), mParent(0), mId(-1), mSortOffset(-1),
00058         mUnsortedCount(0), mUnsortedSize(0), mUnsortedChildren(0),
00059         mImperfectlyThreaded (true), mSubjThreadingList(0) { }
00060     SortCacheItem(int i, TQString k, int o=-1)
00061         : mItem(0), mParent(0), mId(i), mSortOffset(o), mKey(k),
00062           mUnsortedCount(0), mUnsortedSize(0), mUnsortedChildren(0),
00063           mImperfectlyThreaded (true), mSubjThreadingList(0) { }
00064     ~SortCacheItem() { if(mUnsortedChildren) free(mUnsortedChildren); }
00065 
00068     SortCacheItem *parent() const { return mParent; }
00074     bool isImperfectlyThreaded() const
00075         { return mImperfectlyThreaded; }
00078     void setImperfectlyThreaded (bool val)
00079         { mImperfectlyThreaded = val; }
00081     bool hasChildren() const
00082         { return mSortedChildren.count() || mUnsortedCount; }
00085     const TQPtrList<SortCacheItem> *sortedChildren() const
00086         { return &mSortedChildren; }
00089     SortCacheItem **unsortedChildren(int &count) const
00090         { count = mUnsortedCount; return mUnsortedChildren; }
00092     void addSortedChild(SortCacheItem *i) {
00093         i->mParent = this;
00094         mSortedChildren.append(i);
00095     }
00097     void addUnsortedChild(SortCacheItem *i) {
00098         i->mParent = this;
00099         if(!mUnsortedChildren)
00100             mUnsortedChildren = (SortCacheItem **)malloc((mUnsortedSize = 25) * sizeof(SortCacheItem *));
00101         else if(mUnsortedCount >= mUnsortedSize)
00102             mUnsortedChildren = (SortCacheItem **)realloc(mUnsortedChildren,
00103                                                             (mUnsortedSize *= 2) * sizeof(SortCacheItem *));
00104         mUnsortedChildren[mUnsortedCount++] = i;
00105     }
00106 
00108     void clearChildren() {
00109       mSortedChildren.clear();
00110       free( mUnsortedChildren );
00111       mUnsortedChildren = 0;
00112       mUnsortedCount = mUnsortedSize = 0;
00113     }
00114 
00116     HeaderItem *item() const { return mItem; }
00118     void setItem(HeaderItem *i) { Q_ASSERT(!mItem); mItem = i; }
00119 
00121     const TQString &key() const { return mKey; }
00123     void setKey(const TQString &key) { mKey = key; }
00124 
00125     int id() const { return mId; }
00126     void setId(int id) { mId = id; }
00127 
00129     int offset() const { return mSortOffset; }
00130     void setOffset(int x) { mSortOffset = x; }
00131 
00132     void updateSortFile( FILE *sortStream, KMFolder *folder,
00133                          bool waiting_for_parent = false,
00134                          bool update_discovered_count = false);
00135 
00138     void setSubjectThreadingList( TQPtrList<SortCacheItem> *list ) { mSubjThreadingList = list; }
00140     TQPtrList<SortCacheItem>* subjectThreadingList() const { return mSubjThreadingList; }
00141 
00142 private:
00143     HeaderItem *mItem;
00144     SortCacheItem *mParent;
00145     int mId, mSortOffset;
00146     TQString mKey;
00147 
00148     TQPtrList<SortCacheItem> mSortedChildren;
00149     int mUnsortedCount, mUnsortedSize;
00150     SortCacheItem **mUnsortedChildren;
00151     bool mImperfectlyThreaded;
00152     // pointer to the list it might be on so it can be remove from it
00153     // when the item goes away.
00154     TQPtrList<SortCacheItem>* mSubjThreadingList;
00155 };
00156 
00157 
00163 class HeaderItem : public KListViewItem
00164 {
00165 public:
00166   HeaderItem( TQListView* parent, int msgId, const TQString& key = TQString() );
00167   HeaderItem( TQListViewItem* parent, int msgId, const TQString& key = TQString() );
00168   ~HeaderItem ();
00169 
00172   void setMsgId( int aMsgId );
00173 
00174   // Profiling note: About 30% of the time taken to initialize the
00175   // listview is spent in this function. About 60% is spent in operator
00176   // new and TQListViewItem::TQListViewItem.
00177   void irefresh();
00178 
00180   int msgId() const;
00181 
00182   TQString to() const;
00183   TQString from() const;
00184 
00185   // Return the serial number of the message associated with this item;
00186   TQ_UINT32 msgSerNum() const;
00187 
00189   void setOpenRecursive( bool open );
00190 
00192   TQString text( int col) const;
00193 
00194   void setup();
00195 
00196   typedef TQValueList<TQPixmap> PixmapList;
00197 
00198   TQPixmap pixmapMerge( PixmapList pixmaps ) const;
00199 
00200   const TQPixmap *cryptoIcon(KMMsgBase *msgBase) const;
00201   const TQPixmap *signatureIcon(KMMsgBase *msgBase) const;
00202   const TQPixmap *statusIcon(KMMsgBase *msgBase) const;
00203 
00204   const TQPixmap *pixmap(int col) const;
00205 
00206   void paintCell( TQPainter * p, const TQColorGroup & cg,
00207                                 int column, int width, int align );
00208 
00209   static TQString generate_key( KMHeaders *headers, KMMsgBase *msg, const KPaintInfo *paintInfo, int sortOrder );
00210 
00211   virtual TQString key( int column, bool /*ascending*/ ) const;
00212 
00213   void setTempKey( TQString key );
00214 
00215   int compare( TQListViewItem *i, int col, bool ascending ) const;
00216   
00217   TQListViewItem* firstChildNonConst(); /* Non const! */ 
00218 
00222   bool aboutToBeDeleted() const { return mAboutToBeDeleted; }
00225   void setAboutToBeDeleted( bool val ) { mAboutToBeDeleted = val; }
00226 
00229   void setSortCacheItem( SortCacheItem *item ) { mSortCacheItem = item; }
00231   SortCacheItem* sortCacheItem() const { return mSortCacheItem; }
00232 
00233 private:
00234   int mMsgId;
00235   TQ_UINT32 mSerNum;
00236   TQString mKey;
00237   bool mAboutToBeDeleted;
00238   SortCacheItem *mSortCacheItem;
00239 }; // End of class HeaderItem
00240 
00241 } // End of namespace KMail
00242 
00243 
00244 #endif // HEADERITEM_H