kmail

kmheaders.h
1 // -*- mode: C++ -*-
2 
3 #ifndef __KMHEADERS
4 #define __KMHEADERS
5 
6 #include "kmime_util.h"
7 #include "headeritem.h"
10 
11 #include <tdelistview.h>
12 #include <kfoldertree.h> // for KPaintInfo
13 #include <kmmsgbase.h> // for KMMsgStatus
14 
15 #include <tqwidget.h>
16 #include <tqstrlist.h>
17 #include <tqmemarray.h>
18 #include <tqmap.h>
19 #include <tqdragobject.h>
20 #include <tqdict.h>
21 #include <tqguardedptr.h>
22 
23 class KMFolder;
24 class KMMessage;
25 class KMMsgBase;
26 class KMCommand;
27 class KMMainWidget;
28 class TDEPopupMenu;
29 class TQPalette;
30 class TQPixmap;
31 class TQIconSet;
32 class TQDateTime;
33 
34 typedef TQPtrList<KMMsgBase> KMMessageList;
35 typedef TQValueList<TQ_UINT32> SerNumList;
36 typedef TQMap<int,KMFolder*> KMMenuToFolder;
37 enum NestingPolicy { AlwaysOpen = 0, DefaultOpen, DefaultClosed, OpenUnread };
38 
39 
40 #define KMAIL_SORT_VERSION 1012
41 #define KMAIL_SORT_FILE(x) x->indexLocation() + ".sorted"
42 #define KMAIL_SORT_HEADER "## KMail Sort V%04d\n\t"
43 #define KMAIL_MAGIC_HEADER_OFFSET 21 //strlen(KMAIL_SORT_HEADER)
44 #define KMAIL_MAX_KEY_LEN 16384
45 #define KMAIL_RESERVED 3
46 
48 class KMHeaders : public TDEListView
49 {
50  Q_OBJECT
51 
52 
53  friend class ::KMail::HeaderItem; // For easy access to the pixmaps
54 
55 public:
56  KMHeaders(KMMainWidget *owner, TQWidget *parent=0, const char *name=0);
57  virtual ~KMHeaders();
58 
63  virtual void setFolder(KMFolder *, bool forceJumpToUnread = false);
64 
66  KMFolder* folder(void) { return mFolder; }
67 
69  void refreshNestedState(void);
70 
73  virtual void setCurrentMsg(int msgId);
74 
76  TQPtrList<TQListViewItem> currentThread() const;
77 
80  virtual void setThreadStatus(KMMsgStatus status, bool toggle=false);
81 
82  /* Set message status to read if it is new, or unread */
83  virtual void setMsgRead(int msgId);
84 
86  virtual void setMsgStatus(KMMsgStatus status, bool toggle=false);
87  virtual void deleteMsg();
88  virtual void applyFiltersOnMsg();
89  virtual void undo();
90  virtual bool canUndo() const;
91  virtual HeaderItem * prepareMove( int *contentX, int *contentY );
92  virtual void finalizeMove( HeaderItem *item, int contentX, int contentY );
93 
97  virtual void moveMsgToFolder( KMFolder* destination,
98  bool askForConfirmation=true );
99 
102  virtual void copyMsgToFolder(KMFolder* destination,
103  KMMessage* aMsg = 0);
104 
106  virtual void clearSelectableAndAboutToBeDeleted(TQ_UINT32 serNum);
109  virtual KMMessageList* selectedMsgs(bool toBeDeleted = false);
110 
112  TQValueList<int> selectedItems();
113 
115  TQValueList<TQ_UINT32> selectedSernums();
116 
120  TQValueList<TQ_UINT32> selectedVisibleSernums();
121 
123  int indexOfGetMsg (void) const { return getMsgIndex; }
124 
126  KMMainWidget* owner(void) const { return mOwner; }
127 
129  const KPaintInfo *paintInfo(void) const { return &mPaintInfo; }
130 
132  virtual void readConfig(void);
133 
135  virtual void readColorConfig(void);
136 
144  void restoreColumnLayout( TDEConfig *config, const TQString &group );
145 
147  virtual KMMessage* currentMsg();
149  virtual HeaderItem* currentHeaderItem();
151  virtual int currentItemIndex();
153  virtual void setCurrentItemByIndex( int msgIdx );
155  void setCurrentItemBySerialNum( unsigned long serialNum );
157  virtual int topItemIndex();
160  virtual void setTopItemByIndex( int aMsgIdx );
161  virtual void setNestedOverride( bool override );
162  virtual void setSubjectThreading( bool subjThreading );
164  virtual void setOpen ( TQListViewItem *, bool );
165 
166  NestingPolicy getNestingPolicy() const { return nestingPolicy; }
168  bool isThreaded() const {
169  return mNested != mNestedOverride; // xor
170  }
171 
174  virtual int findUnread(bool findNext, int startAt=-1, bool onlyNew = false, bool acceptCurrent = false);
175 
176  void highlightMessage(TQListViewItem*, bool markitread);
177  void highlightCurrentThread();
178 
180  static TQString fancyDate( time_t otime );
181 
182  bool noRepaint;
183 
184  // filter events for popup
185  bool eventFilter ( TQObject *o, TQEvent *e );
186 
188  const KMMsgBase * getMsgBaseForItem( const TQListViewItem *item ) const;
189 
190  // accessors
191  TQFont newFont() const { return mNewFont; }
192  TQFont unreadFont() const { return mUnreadFont; }
193  TQFont importantFont() const { return mImportantFont; }
194  TQFont todoFont() const { return mTodoFont; }
195  TQFont dateFont() const { return mDateFont; }
196 
202  void setCopiedMessages( const TQValueList<TQ_UINT32> &msgs, bool move );
203 
208  bool isMessageCut( TQ_UINT32 serNum ) const;
209 
211  virtual void writeConfig(void);
212 
213 signals:
216  void selected(KMMessage *);
219  void activated(KMMessage *);
221  void maybeDeleting();
223  void messageListUpdated();
224 
230  void msgAddedToListView( TQListViewItem* );
231 
232 public slots:
234  void selectMessage(TQListViewItem*);
236  void highlightMessage(TQListViewItem*);
238  void slotRMB();
240  void msgHeaderChanged(KMFolder *folder, int msgId);
242  void msgChanged();
244  void folderCleared();
246  void folderClosed();
248  void msgAdded(int);
250  void msgRemoved( int, TQString );
252  void nextMessage();
254  void selectNextMessage();
256  void prevMessage();
258  void selectPrevMessage();
261  bool nextUnreadMessage(bool acceptCurrent = false);
264  bool prevUnreadMessage();
266  void incCurrentMessage();
268  void decCurrentMessage();
270  void selectCurrentMessage();
272  void slotNoDrag();
274  void resetCurrentTime();
275 
277  void reset();
278 
281  void slotExpandOrCollapseThread( bool expand );
284  void slotExpandOrCollapseAllThreads( bool expand );
285 
286  virtual void ensureCurrentItemVisible();
287 
290  virtual void setSelected(TQListViewItem *item, bool selected);
291 
295  void setSelectedByIndex(TQValueList<int> items, bool selected);
296 
299  void slotToggleColumn(int id, int mode = -1);
300 
302  void setFolderInfoStatus();
303 
304 protected:
305  static TQPixmap *pixNew, *pixUns, *pixDel, *pixRead, *pixRep, *pixSent,
306  *pixQueued, *pixFwd, *pixFlag, *pixWatched, *pixIgnored, *pixSpam, *pixHam,
307  *pixFullySigned, *pixPartiallySigned, *pixUndefinedSigned,
308  *pixFullyEncrypted, *pixPartiallyEncrypted, *pixUndefinedEncrypted,
309  *pixFiller, *pixEncryptionProblematic,
310  *pixSignatureProblematic, *pixAttachment, *pixInvitation,
311  *pixReadFwd, *pixReadReplied, *pixReadFwdReplied, *pixTodo;
312 
314  virtual bool event(TQEvent *e);
315 
317  virtual void paintEmptyArea( TQPainter * p, const TQRect & rect );
318 
320  void makeHeaderVisible();
321 
323  void findUnreadAux( HeaderItem*&, bool &, bool, bool );
324 
329  virtual int firstSelectedMsg() const;
330 
332  virtual void readFolderConfig(void);
333 
335  virtual void writeFolderConfig(void);
336 
338  virtual void contentsMousePressEvent(TQMouseEvent*);
339  virtual void contentsMouseReleaseEvent(TQMouseEvent* e);
340  virtual void keyPressEvent( TQKeyEvent * e );
341 
343  virtual void setSorting( int column, bool ascending = true);
344 
346  void contentsMouseMoveEvent( TQMouseEvent *e );
347 
350  void styleChange( TQStyle& oldStyle );
351 
355 
356 protected slots:
359  virtual void moveSelectedToFolder( int menuId );
361  virtual void copySelectedToFolder( int menuId );
363  virtual int slotFilterMsg( KMMessage * );
365  void dirtySortOrder(int);
367  void rightButtonPressed( TQListViewItem *, const TQPoint &, int );
368 
369 private slots:
370  void slotMoveCompleted( KMCommand * );
371 
372  void copyMessages();
373  void cutMessages();
374  void pasteMessages();
375 
376  void updateActions();
377 
378 private:
381  virtual void updateMessageList( bool set_selection=false,
382  bool forceJumpToUnread = false );
383 
385  TQGuardedPtr<KMFolder> mFolder;
387  KMMainWidget* mOwner;
389  int mTopItem;
391  int mCurrentItem;
393  unsigned long mCurrentItemSerNum;
395  TQMemArray<HeaderItem*> mItems;
396 
397  // ===== threading and sorting ==========
398  bool mNested, mNestedOverride, mSubjThreading;
399  NestingPolicy nestingPolicy;
400  int mSortCol;
401  bool mSortDescending;
402  bool mIgnoreSortOrderChanges;
403 
404  struct {
405  uint ascending : 1;
406  uint dirty : 1;
407  short column;
408  uint fakeSort : 1;
409  uint removed : 1;
410  } mSortInfo;
411 
412 
414  TQDict< SortCacheItem > mSortCacheItems;
416  TQDict< TQPtrList< SortCacheItem > > mSubjectLists;
418  TQPtrList<HeaderItem> mImperfectlyThreadedList;
419 
421  void printSubjectThreadingTree( );
422  void printThreadingTree( );
424  void buildThreadingTree( TQMemArray<SortCacheItem *> sortCache );
426  void buildSubjectThreadingTree( TQMemArray<SortCacheItem *> sortCache );
428  SortCacheItem* findParent(SortCacheItem *item);
430  SortCacheItem* findParentBySubject(SortCacheItem *item);
431  SortCacheItem* mRoot; // used to represent the list view itself while threading
432 
434  void appendItemToSortFile(HeaderItem *);
436  bool writeSortOrder();
438  bool readSortOrder( bool set_selection = false,
439  bool forceJumpToUnread = false );
440 
442  int getMsgIndex;
444  bool getMsgMulti;
446  HeaderItem* getMsgItem;
448  KMMessageList mSelMsgBaseList;
449  HeaderItem* mPrevCurrent;
450 
452  KPaintInfo mPaintInfo;
453 
454  TQFont mNewFont, mUnreadFont, mImportantFont, mDateFont,mTodoFont;
455 
457  static TQIconSet *up, *down;
459  KMMenuToFolder mMenuToFolder;
460 
462  bool mMousePressed;
464  TQPoint mPressPos;
465 
466  KMime::DateFormatter mDate;
467  bool mReaderWindowActive;
468 
470  TDEPopupMenu* mPopup;
471 
472  // copied messages
473  TQValueList<TQ_UINT32> mCopiedMessages;
474  bool mMoveMessages;
475 }; // class
476 #endif
bool isThreaded() const
Returns true if the current header list is threaded.
Definition: kmheaders.h:168
void contentsMouseMoveEvent(TQMouseEvent *e)
To initiate a drag operation.
Definition: kmheaders.cpp:2376
void msgAdded(int)
For when the message with the given message id has been added to a folder.
Definition: kmheaders.cpp:896
void selected(KMMessage *)
emitted when the list view item corresponding to this message has been selected
virtual void readColorConfig(void)
Read color options and set palette.
Definition: kmheaders.cpp:427
virtual void contentsMousePressEvent(TQMouseEvent *)
Handle shift and control selection.
Definition: kmheaders.cpp:2277
TQValueList< int > selectedItems()
Returns the index values of currently selected items.
Definition: kmheaders.cpp:1777
void setCurrentItemBySerialNum(unsigned long serialNum)
Set the current item to the one corresponding to the given serial number (slow!)
Definition: kmheaders.cpp:3514
virtual void setSelected(TQListViewItem *item, bool selected)
Select an item and if it is the parent of a closed thread, also recursively select its children...
Definition: kmheaders.cpp:1708
void maybeDeleting()
emitted when we might be about to delete messages
void dirtySortOrder(int)
dirties the sort order
Definition: kmheaders.cpp:2866
bool isMessageCut(TQ_UINT32 serNum) const
Returns true if the message with the given serial number has been cut.
Definition: kmheaders.cpp:3597
void prevMessage()
Make the previous header visible scrolling if necessary.
Definition: kmheaders.cpp:1842
virtual void moveMsgToFolder(KMFolder *destination, bool askForConfirmation=true)
If destination is 0 then the messages are deleted, otherwise they are moved to this folder...
Definition: kmheaders.cpp:1587
virtual void setCurrentMsg(int msgId)
Set current message.
Definition: kmheaders.cpp:1693
virtual int currentItemIndex()
Return the index of the message corresponding to the current item.
Definition: kmheaders.cpp:2534
void rightButtonPressed(TQListViewItem *, const TQPoint &, int)
show context menu
Definition: kmheaders.cpp:2264
void restoreColumnLayout(TDEConfig *config, const TQString &group)
Same as TDEListView::restoreLayout(), only that this does not restore the sort order.
Definition: kmheaders.cpp:560
virtual int firstSelectedMsg() const
Returns message index of first selected message of the messages where the message with the given id i...
Definition: kmheaders.cpp:1792
void messageListUpdated()
emitted when the list of messages has been completely rebuilt
void folderClosed()
For when the folder has been cleared.
Definition: kmheaders.cpp:2702
virtual void moveSelectedToFolder(int menuId)
Move messages corresponding to the selected items to the folder corresponding to the given menuId...
Definition: kmheaders.cpp:1532
virtual int findUnread(bool findNext, int startAt=-1, bool onlyNew=false, bool acceptCurrent=false)
Find next/prev unread message.
Definition: kmheaders.cpp:1961
int indexOfGetMsg(void) const
Returns index of message returned by last getMsg() call.
Definition: kmheaders.h:123
The widget that shows the contents of folders.
Definition: kmheaders.h:48
TQValueList< TQ_UINT32 > selectedSernums()
Returns the sernums of all selected items.
Definition: kmheaders.cpp:3602
virtual void copyMsgToFolder(KMFolder *destination, KMMessage *aMsg=0)
Messages are duplicated and added to given folder.
Definition: kmheaders.cpp:1675
void setFolderInfoStatus()
Provide information about number of messages in a folder.
Definition: kmheaders.cpp:1392
TQPtrList< TQListViewItem > currentThread() const
Get a list of all items in the current thread.
Definition: kmheaders.cpp:1235
void resetCurrentTime()
timer function to set the current time regularly
Definition: kmheaders.cpp:2158
virtual int slotFilterMsg(KMMessage *)
Apply the filter Rules to a single message.
Definition: kmheaders.cpp:1306
KMMainWidget * owner(void) const
Returns pointer to owning main window.
Definition: kmheaders.h:126
void slotExpandOrCollapseThread(bool expand)
Expands (expand == true) or collapses (expand == false) the current thread.
Definition: kmheaders.cpp:1328
void slotRMB()
For when righ mouse button is pressed.
Definition: kmheaders.cpp:2425
void decCurrentMessage()
Focus the previous message, but don&#39;t select it.
Definition: kmheaders.cpp:1898
const KPaintInfo * paintInfo(void) const
PaintInfo pointer.
Definition: kmheaders.h:129
virtual void readFolderConfig(void)
Read per-folder config options and apply them.
Definition: kmheaders.cpp:609
Mail folder.
Definition: kmfolder.h:68
Represents an item in the set of mails to be displayed but only as far as sorting, threading and reading/writing of the current sort order to a disk cache is concerned.
Definition: headeritem.h:54
void styleChange(TQStyle &oldStyle)
reimplemented in order to update the frame width in case of a changed GUI style
Definition: kmheaders.cpp:1385
void selectMessage(TQListViewItem *)
For when a list view item has been double clicked.
Definition: kmheaders.cpp:2167
void slotNoDrag()
Don&#39;t show a drag cursor.
Definition: kmheaders.cpp:2087
const KMMsgBase * getMsgBaseForItem(const TQListViewItem *item) const
gets the message represented by the item as a KMMsgBase.
Definition: kmheaders.cpp:2610
void reset()
Refresh the list of message headers shown.
Definition: kmheaders.cpp:571
void msgChanged()
For when the list of messages in a folder has changed.
Definition: kmheaders.cpp:817
virtual void paintEmptyArea(TQPainter *p, const TQRect &rect)
Overridden to support backing pixmap.
Definition: kmheaders.cpp:404
void activated(KMMessage *)
emitted when the list view item corresponding to this message has been double clicked ...
KMFolder * folder(void)
Return the folder whose message headers are being displayed.
Definition: kmheaders.h:66
virtual int topItemIndex()
Return the message id of the top most visible item.
Definition: kmheaders.cpp:2561
virtual KMMessage * currentMsg()
Return the current message.
Definition: kmheaders.cpp:2518
virtual void setTopItemByIndex(int aMsgIdx)
Make the item corresponding to the message with the given id the top most visible item...
Definition: kmheaders.cpp:2571
void nextMessage()
Make the next header visible scrolling if necessary.
Definition: kmheaders.cpp:1805
virtual void setFolder(KMFolder *, bool forceJumpToUnread=false)
A new folder has been selected update the list of headers shown To override the global settings for j...
Definition: kmheaders.cpp:679
void makeHeaderVisible()
Ensure the current item is visible.
Definition: kmheaders.cpp:2099
void selectCurrentMessage()
Select the message which currently has focus, if it&#39;s not already selected.
Definition: kmheaders.cpp:1915
void selectPrevMessage()
Same as prevMessage() but don&#39;t clear the current selection.
Definition: kmheaders.cpp:1854
static TQString fancyDate(time_t otime)
return a string relativ to the current time
virtual HeaderItem * currentHeaderItem()
Return the current list view item.
Definition: kmheaders.cpp:2528
void setCopiedMessages(const TQValueList< TQ_UINT32 > &msgs, bool move)
Sets the list of copied/cutted messages.
Definition: kmheaders.cpp:3590
void incCurrentMessage()
Focus the next message, but don&#39;t select it.
Definition: kmheaders.cpp:1880
void msgHeaderChanged(KMFolder *folder, int msgId)
Refresh list view item corresponding to the messae with the given id.
Definition: kmheaders.cpp:1211
void msgAddedToListView(TQListViewItem *)
emitted after a new item has been fully built and added to the list view.
void refreshNestedState(void)
read the config file and update nested state if necessary
Definition: kmheaders.cpp:590
virtual void writeFolderConfig(void)
Write per-folder config options.
Definition: kmheaders.cpp:639
virtual void setCurrentItemByIndex(int msgIdx)
Set the current item to the one corresponding to the given msg id.
Definition: kmheaders.cpp:2544
This is a Mime Message.
Definition: kmmessage.h:68
TQValueList< TQ_UINT32 > selectedVisibleSernums()
Returns the sernums of all visible (ie.
Definition: kmheaders.cpp:3617
bool nextUnreadMessage(bool acceptCurrent=false)
Make the nextUnread message header visible scrolling if necessary, returning true if an unread messag...
Definition: kmheaders.cpp:2041
void slotExpandOrCollapseAllThreads(bool expand)
Expands (expand == true) or collapses (expand == false) all threads.
Definition: kmheaders.cpp:1345
virtual void copySelectedToFolder(int menuId)
Same thing but copy.
Definition: kmheaders.cpp:1667
void msgRemoved(int, TQString)
For when the message with the given id has been removed for a folder.
Definition: kmheaders.cpp:1082
virtual void setOpen(TQListViewItem *, bool)
Double force items to always be open.
Definition: kmheaders.cpp:2603
virtual bool event(TQEvent *e)
Look for color changes.
Definition: kmheaders.cpp:415
void setSelectedByIndex(TQValueList< int > items, bool selected)
Select several items by message index and if they are the parent of a closed thread, also recursively select their children.
Definition: kmheaders.cpp:1728
virtual void setSorting(int column, bool ascending=true)
Called when a header is clicked.
Definition: kmheaders.cpp:2617
void selectNextMessage()
Same as nextMessage() but don&#39;t clear the current selection.
Definition: kmheaders.cpp:1817
void folderCleared()
For when the folder has been cleared.
Definition: kmheaders.cpp:2692
virtual KMMessageList * selectedMsgs(bool toBeDeleted=false)
Returns list of selected messages.
Definition: kmheaders.cpp:1756
virtual void setMsgStatus(KMMsgStatus status, bool toggle=false)
The following methods processes all selected messages.
Definition: kmheaders.cpp:1223
void findUnreadAux(HeaderItem *&, bool &, bool, bool)
Auxillary method to findUnread.
Definition: kmheaders.cpp:1922
Visual representation of a member of the set of displayables (mails in the current folder)...
Definition: headeritem.h:163
virtual void clearSelectableAndAboutToBeDeleted(TQ_UINT32 serNum)
Resets toBeDeleted and selectable status of all selected items.
Definition: kmheaders.cpp:1739
bool prevUnreadMessage()
Make the previous message header visible scrolling if necessary, returning true if an unread message ...
Definition: kmheaders.cpp:2067
void setStyleDependantFrameWidth()
Set the width of the frame to a reasonable value for the current GUI style.
Definition: kmheaders.cpp:1370
virtual void readConfig(void)
Read config options.
Definition: kmheaders.cpp:469
virtual void writeConfig(void)
Write global config options.
Definition: kmheaders.cpp:660
void slotToggleColumn(int id, int mode=-1)
switch a column with the given id (see KPaintInfo enum) 1 for activate, 0 for deactivate, -1 for toggle
Definition: kmheaders.cpp:260
virtual void setThreadStatus(KMMsgStatus status, bool toggle=false)
Set all messages in the current thread to status status or toggle it, if specified.
Definition: kmheaders.cpp:1257