kmail

headeritem.h
1/*******************************************************************************
2**
3** Filename : headeritem.h
4** Created on : 28 November, 2004
5** Copyright : (c) 2004 Till Adam
6** Email : adam@kde.org
7**
8*******************************************************************************/
9
10/*******************************************************************************
11**
12** This program is free software; you can redistribute it and/or modify
13** it under the terms of the GNU General Public License as published by
14** the Free Software Foundation; either version 2 of the License, or
15** (at your option) any later version.
16**
17** In addition, as a special exception, the copyright holders give
18** permission to link the code of this program with any edition of
19** the TQt library by Trolltech AS, Norway (or with modified versions
20** of TQt that use the same license as TQt), and distribute linked
21** combinations including the two. You must obey the GNU General
22** Public License in all respects for all of the code used other than
23** TQt. If you modify this file, you may extend this exception to
24** your version of the file, but you are not obligated to do so. If
25** you do not wish to do so, delete this exception statement from
26** your version.
27**
28*******************************************************************************/
29#ifndef HEADERITEM_H
30#define HEADERITEM_H
31
32#include <stdlib.h>
33
34#include <tdelistview.h> // include for the base class
35
36class KMMsgBase;
37class KPaintInfo;
38class KMFolder;
39class KMHeaders;
40
41namespace KMail
42{
43class HeaderItem; // forward declaration
44
55
56public:
57 SortCacheItem() : mItem(0), mParent(0), mId(-1), mSortOffset(-1),
58 mUnsortedCount(0), mUnsortedSize(0), mUnsortedChildren(0),
59 mImperfectlyThreaded (true), mSubjThreadingList(0) { }
60 SortCacheItem(int i, TQString k, int o=-1)
61 : mItem(0), mParent(0), mId(i), mSortOffset(o), mKey(k),
62 mUnsortedCount(0), mUnsortedSize(0), mUnsortedChildren(0),
63 mImperfectlyThreaded (true), mSubjThreadingList(0) { }
64 ~SortCacheItem() { if(mUnsortedChildren) free(mUnsortedChildren); }
65
68 SortCacheItem *parent() const { return mParent; }
75 { return mImperfectlyThreaded; }
78 void setImperfectlyThreaded (bool val)
79 { mImperfectlyThreaded = val; }
81 bool hasChildren() const
82 { return mSortedChildren.count() || mUnsortedCount; }
85 const TQPtrList<SortCacheItem> *sortedChildren() const
86 { return &mSortedChildren; }
89 SortCacheItem **unsortedChildren(int &count) const
90 { count = mUnsortedCount; return mUnsortedChildren; }
93 i->mParent = this;
94 mSortedChildren.append(i);
95 }
98 i->mParent = this;
99 if(!mUnsortedChildren)
100 mUnsortedChildren = (SortCacheItem **)malloc((mUnsortedSize = 25) * sizeof(SortCacheItem *));
101 else if(mUnsortedCount >= mUnsortedSize)
102 mUnsortedChildren = (SortCacheItem **)realloc(mUnsortedChildren,
103 (mUnsortedSize *= 2) * sizeof(SortCacheItem *));
104 mUnsortedChildren[mUnsortedCount++] = i;
105 }
106
109 mSortedChildren.clear();
110 free( mUnsortedChildren );
111 mUnsortedChildren = 0;
112 mUnsortedCount = mUnsortedSize = 0;
113 }
114
116 HeaderItem *item() const { return mItem; }
118 void setItem(HeaderItem *i) { Q_ASSERT(!mItem); mItem = i; }
119
121 const TQString &key() const { return mKey; }
123 void setKey(const TQString &key) { mKey = key; }
124
125 int id() const { return mId; }
126 void setId(int id) { mId = id; }
127
129 int offset() const { return mSortOffset; }
130 void setOffset(int x) { mSortOffset = x; }
131
132 void updateSortFile( FILE *sortStream, KMFolder *folder,
133 bool waiting_for_parent = false,
134 bool update_discovered_count = false);
135
138 void setSubjectThreadingList( TQPtrList<SortCacheItem> *list ) { mSubjThreadingList = list; }
140 TQPtrList<SortCacheItem>* subjectThreadingList() const { return mSubjThreadingList; }
141
142private:
143 HeaderItem *mItem;
144 SortCacheItem *mParent;
145 int mId, mSortOffset;
146 TQString mKey;
147
148 TQPtrList<SortCacheItem> mSortedChildren;
149 int mUnsortedCount, mUnsortedSize;
150 SortCacheItem **mUnsortedChildren;
151 bool mImperfectlyThreaded;
152 // pointer to the list it might be on so it can be remove from it
153 // when the item goes away.
154 TQPtrList<SortCacheItem>* mSubjThreadingList;
155};
156
157
163class HeaderItem : public TDEListViewItem
164{
165public:
166 HeaderItem( TQListView* parent, int msgId, const TQString& key = TQString() );
167 HeaderItem( TQListViewItem* parent, int msgId, const TQString& key = TQString() );
168 ~HeaderItem ();
169
172 void setMsgId( int aMsgId );
173
174 // Profiling note: About 30% of the time taken to initialize the
175 // listview is spent in this function. About 60% is spent in operator
176 // new and TQListViewItem::TQListViewItem.
177 void irefresh();
178
180 int msgId() const;
181
182 TQString to() const;
183 TQString from() const;
184
185 // Return the serial number of the message associated with this item;
186 TQ_UINT32 msgSerNum() const;
187
189 void setOpenRecursive( bool open );
190
192 TQString text( int col) const;
193
194 void setup();
195
196 typedef TQValueList<TQPixmap> PixmapList;
197
198 TQPixmap pixmapMerge( PixmapList pixmaps ) const;
199
200 const TQPixmap *cryptoIcon(KMMsgBase *msgBase) const;
201 const TQPixmap *signatureIcon(KMMsgBase *msgBase) const;
202 const TQPixmap *statusIcon(KMMsgBase *msgBase) const;
203
204 const TQPixmap *pixmap(int col) const;
205
206 void paintCell( TQPainter * p, const TQColorGroup & cg,
207 int column, int width, int align );
208
209 static TQString generate_key( KMHeaders *headers, KMMsgBase *msg, const KPaintInfo *paintInfo, int sortOrder );
210
211 virtual TQString key( int column, bool /*ascending*/ ) const;
212
213 void setTempKey( TQString key );
214
215 int compare( TQListViewItem *i, int col, bool ascending ) const;
216
217 TQListViewItem* firstChildNonConst(); /* Non const! */
218
222 bool aboutToBeDeleted() const { return mAboutToBeDeleted; }
225 void setAboutToBeDeleted( bool val ) { mAboutToBeDeleted = val; }
226
229 void setSortCacheItem( SortCacheItem *item ) { mSortCacheItem = item; }
231 SortCacheItem* sortCacheItem() const { return mSortCacheItem; }
232
233private:
234 int mMsgId;
235 TQ_UINT32 mSerNum;
236 TQString mKey;
237 bool mAboutToBeDeleted;
238 SortCacheItem *mSortCacheItem;
239}; // End of class HeaderItem
240
241} // End of namespace KMail
242
243
244#endif // HEADERITEM_H
Mail folder.
Definition: kmfolder.h:69
The widget that shows the contents of folders.
Definition: kmheaders.h:47
Visual representation of a member of the set of displayables (mails in the current folder).
Definition: headeritem.h:164
void setAboutToBeDeleted(bool val)
Set the item to be in about-to-be-deleted state, which means it cannot be selected and will be painte...
Definition: headeritem.h:225
SortCacheItem * sortCacheItem() const
Returns the KMail::SortCacheItem associated with this display item.
Definition: headeritem.h:231
TQString text(int col) const
Returns the text of the list view item.
Definition: headeritem.cpp:164
int msgId() const
Return the msgId of the message associated with this item.
Definition: headeritem.cpp:113
bool aboutToBeDeleted() const
Returns whether the item is about to be removed from the list view as a result of some user action.
Definition: headeritem.h:222
void setSortCacheItem(SortCacheItem *item)
Associate a KMail::SortCacheItem with this item.
Definition: headeritem.h:229
void setOpenRecursive(bool open)
Expands all children of the list view item.
Definition: headeritem.cpp:149
void setMsgId(int aMsgId)
Set the message id of this item, which is the offset/index in the folder currently displayed by the K...
Definition: headeritem.cpp:72
Represents an item in the set of mails to be displayed but only as far as sorting,...
Definition: headeritem.h:54
SortCacheItem * parent() const
The parent node of the item in the threading hierarchy.
Definition: headeritem.h:68
bool isImperfectlyThreaded() const
Returs whether the item is so far imperfectly threaded.
Definition: headeritem.h:74
void addUnsortedChild(SortCacheItem *i)
Add an item to this itme's list of unsorted children.
Definition: headeritem.h:97
int offset() const
offset in the cache file stream
Definition: headeritem.h:129
TQPtrList< SortCacheItem > * subjectThreadingList() const
The list of mails with a certain subject that this item is on.
Definition: headeritem.h:140
void clearChildren()
Clear the sorted and unsorted children datastructures.
Definition: headeritem.h:108
const TQPtrList< SortCacheItem > * sortedChildren() const
The sorted children are an array of sortcache items we know are below the current one and are already...
Definition: headeritem.h:85
void addSortedChild(SortCacheItem *i)
Add an item to this itme's list of already sorted children.
Definition: headeritem.h:92
void setImperfectlyThreaded(bool val)
Set whether the item is currently imperfectly threaded (by References or Subject, not by In-Reply-To)...
Definition: headeritem.h:78
bool hasChildren() const
Returns whether the item has other items below it.
Definition: headeritem.h:81
SortCacheItem ** unsortedChildren(int &count) const
The unsorted children are an array of sortcache items we know are below the current one,...
Definition: headeritem.h:89
void setSubjectThreadingList(TQPtrList< SortCacheItem > *list)
Set the list of mails with a certain subject that this item is on.
Definition: headeritem.h:138
HeaderItem * item() const
The corresponding KMail::HeaderItem.
Definition: headeritem.h:116
const TQString & key() const
sort key as used by the listview
Definition: headeritem.h:121
void setItem(HeaderItem *i)
Set the corresponding KMail::HeaderItem.
Definition: headeritem.h:118
void setKey(const TQString &key)
Set the sort key used by the list view.
Definition: headeritem.h:123
folderdiaquotatab.h
Definition: aboutdata.cpp:40