kmail

headeritem.h

Go to the documentation of this file.
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 Qt library by Trolltech AS, Norway (or with modified versions
00020 **   of Qt that use the same license as Qt), 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 **   Qt.  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, QString 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 QPtrList<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 QString &key() const { return mKey; }
00123     void setKey(const QString &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( QPtrList<SortCacheItem> *list ) { mSubjThreadingList = list; }
00140     QPtrList<SortCacheItem>* subjectThreadingList() const { return mSubjThreadingList; }
00141 
00142 private:
00143     HeaderItem *mItem;
00144     SortCacheItem *mParent;
00145     int mId, mSortOffset;
00146     QString mKey;
00147 
00148     QPtrList<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     QPtrList<SortCacheItem>* mSubjThreadingList;
00155 };
00156 
00157 
00163 class HeaderItem : public KListViewItem
00164 {
00165 public:
00166   HeaderItem( QListView* parent, int msgId, const QString& key = QString::null );
00167   HeaderItem( QListViewItem* parent, int msgId, const QString& key = QString::null );
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 QListViewItem::QListViewItem.
00177   void irefresh();
00178 
00180   int msgId() const;
00181 
00182   // Return the serial number of the message associated with this item;
00183   Q_UINT32 msgSerNum() const;
00184 
00186   void setOpenRecursive( bool open );
00187 
00189   QString text( int col) const;
00190 
00191   void setup();
00192 
00193   typedef QValueList<QPixmap> PixmapList;
00194 
00195   QPixmap pixmapMerge( PixmapList pixmaps ) const;
00196 
00197   const QPixmap *cryptoIcon(KMMsgBase *msgBase) const;
00198   const QPixmap *signatureIcon(KMMsgBase *msgBase) const;
00199   const QPixmap *statusIcon(KMMsgBase *msgBase) const;
00200 
00201   const QPixmap *pixmap(int col) const;
00202 
00203   void paintCell( QPainter * p, const QColorGroup & cg,
00204                                 int column, int width, int align );
00205 
00206   static QString generate_key( KMHeaders *headers, KMMsgBase *msg, const KPaintInfo *paintInfo, int sortOrder );
00207 
00208   virtual QString key( int column, bool /*ascending*/ ) const;
00209 
00210   void setTempKey( QString key );
00211 
00212   int compare( QListViewItem *i, int col, bool ascending ) const;
00213   
00214   QListViewItem* firstChildNonConst(); /* Non const! */ 
00215 
00219   bool aboutToBeDeleted() const { return mAboutToBeDeleted; }
00222   void setAboutToBeDeleted( bool val ) { mAboutToBeDeleted = val; }
00223 
00226   void setSortCacheItem( SortCacheItem *item ) { mSortCacheItem = item; }
00228   SortCacheItem* sortCacheItem() const { return mSortCacheItem; }
00229 
00230 private:
00231   int mMsgId;
00232   Q_UINT32 mSerNum;
00233   QString mKey;
00234   bool mAboutToBeDeleted;
00235   SortCacheItem *mSortCacheItem;
00236 }; // End of class HeaderItem
00237 
00238 } // End of namespace KMail
00239 
00240 
00241 #endif // HEADERITEM_H