kmail

kmheaders.h
1 #ifndef __KMHEADERS
2 #define __KMHEADERS
3 
4 #include "kmime_util.h"
5 #include "headeritem.h"
8 
9 #include <tdelistview.h>
10 #include <kfoldertree.h> // for KPaintInfo
11 #include <kmmsgbase.h> // for KMMsgStatus
12 
13 #include <tqwidget.h>
14 #include <tqstrlist.h>
15 #include <tqmemarray.h>
16 #include <tqmap.h>
17 #include <tqdragobject.h>
18 #include <tqdict.h>
19 #include <tqguardedptr.h>
20 
21 class KMFolder;
22 class KMMessage;
23 class KMMsgBase;
24 class KMCommand;
25 class KMMainWidget;
26 class TDEPopupMenu;
27 class TQPalette;
28 class TQPixmap;
29 class TQIconSet;
30 class TQDateTime;
31 
32 typedef TQPtrList<KMMsgBase> KMMessageList;
33 typedef TQValueList<TQ_UINT32> SerNumList;
34 typedef TQMap<int,KMFolder*> KMMenuToFolder;
35 enum NestingPolicy { AlwaysOpen = 0, DefaultOpen, DefaultClosed, OpenUnread };
36 
37 
38 #define KMAIL_SORT_VERSION 1012
39 #define KMAIL_SORT_FILE(x) x->indexLocation() + ".sorted"
40 #define KMAIL_SORT_HEADER "## KMail Sort V%04d\n\t"
41 #define KMAIL_MAGIC_HEADER_OFFSET 21 //strlen(KMAIL_SORT_HEADER)
42 #define KMAIL_MAX_KEY_LEN 16384
43 #define KMAIL_RESERVED 3
44 
46 class KMHeaders : public TDEListView
47 {
48  Q_OBJECT
49 
50 
51  friend class ::KMail::HeaderItem; // For easy access to the pixmaps
52 
53 public:
54  KMHeaders(KMMainWidget *owner, TQWidget *parent=0, const char *name=0);
55  virtual ~KMHeaders();
56 
61  virtual void setFolder(KMFolder *, bool forceJumpToUnread = false);
62 
64  KMFolder* folder(void) { return mFolder; }
65 
67  void refreshNestedState(void);
68 
71  virtual void setCurrentMsg(int msgId);
72 
74  TQPtrList<TQListViewItem> currentThread() const;
75 
78  virtual void setThreadStatus(KMMsgStatus status, bool toggle=false);
79 
80  /* Set message status to read if it is new, or unread */
81  virtual void setMsgRead(int msgId);
82 
84  virtual void setMsgStatus(KMMsgStatus status, bool toggle=false);
85  virtual void deleteMsg();
86  virtual void applyFiltersOnMsg();
87  virtual void undo();
88  virtual bool canUndo() const;
89  virtual HeaderItem * prepareMove( int *contentX, int *contentY );
90  virtual void finalizeMove( HeaderItem *item, int contentX, int contentY );
91 
95  virtual void moveMsgToFolder( KMFolder* destination,
96  bool askForConfirmation=true );
97 
100  virtual void copyMsgToFolder(KMFolder* destination,
101  KMMessage* aMsg = 0);
102 
104  virtual void clearSelectableAndAboutToBeDeleted(TQ_UINT32 serNum);
107  virtual KMMessageList* selectedMsgs(bool toBeDeleted = false);
108 
110  TQValueList<int> selectedItems();
111 
113  TQValueList<TQ_UINT32> selectedSernums();
114 
118  TQValueList<TQ_UINT32> selectedVisibleSernums();
119 
121  int indexOfGetMsg (void) const { return getMsgIndex; }
122 
124  KMMainWidget* owner(void) const { return mOwner; }
125 
127  const KPaintInfo *paintInfo(void) const { return &mPaintInfo; }
128 
130  virtual void readConfig(void);
131 
133  virtual void readColorConfig(void);
134 
142  void restoreColumnLayout( TDEConfig *config, const TQString &group );
143 
145  virtual KMMessage* currentMsg();
147  virtual HeaderItem* currentHeaderItem();
149  virtual int currentItemIndex();
151  virtual void setCurrentItemByIndex( int msgIdx );
153  void setCurrentItemBySerialNum( unsigned long serialNum );
155  virtual int topItemIndex();
158  virtual void setTopItemByIndex( int aMsgIdx );
159  virtual void setNestedOverride( bool override );
160  virtual void setSubjectThreading( bool subjThreading );
162  virtual void setOpen ( TQListViewItem *, bool );
163 
164  NestingPolicy getNestingPolicy() const { return nestingPolicy; }
166  bool isThreaded() const {
167  return mNested != mNestedOverride; // xor
168  }
169 
172  virtual int findUnread(bool findNext, int startAt=-1, bool onlyNew = false, bool acceptCurrent = false);
173 
174  void highlightMessage(TQListViewItem*, bool markitread);
175  void highlightCurrentThread();
176 
178  static TQString fancyDate( time_t otime );
179 
180  bool noRepaint;
181 
182  // filter events for popup
183  bool eventFilter ( TQObject *o, TQEvent *e );
184 
186  const KMMsgBase * getMsgBaseForItem( const TQListViewItem *item ) const;
187 
188  // accessors
189  TQFont newFont() const { return mNewFont; }
190  TQFont unreadFont() const { return mUnreadFont; }
191  TQFont importantFont() const { return mImportantFont; }
192  TQFont todoFont() const { return mTodoFont; }
193  TQFont dateFont() const { return mDateFont; }
194 
200  void setCopiedMessages( const TQValueList<TQ_UINT32> &msgs, bool move );
201 
206  bool isMessageCut( TQ_UINT32 serNum ) const;
207 
209  virtual void writeConfig(void);
210 
211 signals:
214  void selected(KMMessage *);
217  void activated(KMMessage *);
219  void maybeDeleting();
221  void messageListUpdated();
222 
228  void msgAddedToListView( TQListViewItem* );
229 
230 public slots:
232  void selectMessage(TQListViewItem*);
234  void highlightMessage(TQListViewItem*);
236  void slotRMB();
238  void msgHeaderChanged(KMFolder *folder, int msgId);
240  void msgChanged();
242  void folderCleared();
244  void folderClosed();
246  void msgAdded(int);
248  void msgRemoved( int, TQString );
250  void nextMessage();
252  void selectNextMessage();
254  void prevMessage();
256  void selectPrevMessage();
259  bool nextUnreadMessage(bool acceptCurrent = false);
262  bool prevUnreadMessage();
264  void incCurrentMessage();
266  void decCurrentMessage();
268  void selectCurrentMessage();
270  void slotNoDrag();
272  void resetCurrentTime();
273 
275  void reset();
276 
279  void slotExpandOrCollapseThread( bool expand );
282  void slotExpandOrCollapseAllThreads( bool expand );
283 
284  virtual void ensureCurrentItemVisible();
285 
288  virtual void setSelected(TQListViewItem *item, bool selected);
289 
293  void setSelectedByIndex(TQValueList<int> items, bool selected);
294 
297  void slotToggleColumn(int id, int mode = -1);
298 
300  void setFolderInfoStatus();
301 
302 protected:
303  static TQPixmap *pixNew, *pixUns, *pixDel, *pixRead, *pixRep, *pixSent,
304  *pixQueued, *pixFwd, *pixFlag, *pixWatched, *pixIgnored, *pixSpam, *pixHam,
305  *pixFullySigned, *pixPartiallySigned, *pixUndefinedSigned,
306  *pixFullyEncrypted, *pixPartiallyEncrypted, *pixUndefinedEncrypted,
307  *pixFiller, *pixEncryptionProblematic,
308  *pixSignatureProblematic, *pixAttachment, *pixInvitation,
309  *pixReadFwd, *pixReadReplied, *pixReadFwdReplied, *pixTodo;
310 
312  virtual bool event(TQEvent *e);
313 
315  virtual void paintEmptyArea( TQPainter * p, const TQRect & rect );
316 
318  void makeHeaderVisible();
319 
321  void findUnreadAux( HeaderItem*&, bool &, bool, bool );
322 
327  virtual int firstSelectedMsg() const;
328 
330  virtual void readFolderConfig(void);
331 
333  virtual void writeFolderConfig(void);
334 
336  virtual void contentsMousePressEvent(TQMouseEvent*);
337  virtual void contentsMouseReleaseEvent(TQMouseEvent* e);
338  virtual void keyPressEvent( TQKeyEvent * e );
339 
341  virtual void setSorting( int column, bool ascending = true);
342 
344  void contentsMouseMoveEvent( TQMouseEvent *e );
345 
348  void styleChange( TQStyle& oldStyle );
349 
353 
354 protected slots:
357  virtual void moveSelectedToFolder( int menuId );
359  virtual void copySelectedToFolder( int menuId );
361  virtual int slotFilterMsg( KMMessage * );
363  void dirtySortOrder(int);
365  void rightButtonPressed( TQListViewItem *, const TQPoint &, int );
366 
367 private slots:
368  void slotMoveCompleted( KMCommand * );
369 
370  void copyMessages();
371  void cutMessages();
372  void pasteMessages();
373 
374  void updateActions();
375 
376 private:
379  virtual void updateMessageList( bool set_selection=false,
380  bool forceJumpToUnread = false );
381 
383  TQGuardedPtr<KMFolder> mFolder;
385  KMMainWidget* mOwner;
387  int mTopItem;
389  int mCurrentItem;
391  unsigned long mCurrentItemSerNum;
393  TQMemArray<HeaderItem*> mItems;
394 
395  // ===== threading and sorting ==========
396  bool mNested, mNestedOverride, mSubjThreading;
397  NestingPolicy nestingPolicy;
398  int mSortCol;
399  bool mSortDescending;
400  bool mIgnoreSortOrderChanges;
401 
402  struct {
403  uint ascending : 1;
404  uint dirty : 1;
405  short column;
406  uint fakeSort : 1;
407  uint removed : 1;
408  } mSortInfo;
409 
410 
412  TQDict< SortCacheItem > mSortCacheItems;
414  TQDict< TQPtrList< SortCacheItem > > mSubjectLists;
416  TQPtrList<HeaderItem> mImperfectlyThreadedList;
417 
419  void printSubjectThreadingTree( );
420  void printThreadingTree( );
422  void buildThreadingTree( TQMemArray<SortCacheItem *> sortCache );
424  void buildSubjectThreadingTree( TQMemArray<SortCacheItem *> sortCache );
426  SortCacheItem* findParent(SortCacheItem *item);
428  SortCacheItem* findParentBySubject(SortCacheItem *item);
429  SortCacheItem* mRoot; // used to represent the list view itself while threading
430 
432  void appendItemToSortFile(HeaderItem *);
434  bool writeSortOrder();
436  bool readSortOrder( bool set_selection = false,
437  bool forceJumpToUnread = false );
438 
440  int getMsgIndex;
442  bool getMsgMulti;
444  HeaderItem* getMsgItem;
446  KMMessageList mSelMsgBaseList;
447  HeaderItem* mPrevCurrent;
448 
450  KPaintInfo mPaintInfo;
451 
452  TQFont mNewFont, mUnreadFont, mImportantFont, mDateFont,mTodoFont;
453 
455  static TQIconSet *up, *down;
457  KMMenuToFolder mMenuToFolder;
458 
460  bool mMousePressed;
462  TQPoint mPressPos;
463 
464  KMime::DateFormatter mDate;
465  bool mReaderWindowActive;
466 
468  TDEPopupMenu* mPopup;
469 
470  // copied messages
471  TQValueList<TQ_UINT32> mCopiedMessages;
472  bool mMoveMessages;
473 }; // class
474 #endif