00001
00002
00003 #ifndef __KMHEADERS
00004 #define __KMHEADERS
00005
00006 #include "kmime_util.h"
00007 #include "headeritem.h"
00008 using KMail::SortCacheItem;
00009 using KMail::HeaderItem;
00010
00011 #include <klistview.h>
00012 #include <kfoldertree.h>
00013 #include <kmmsgbase.h>
00014
00015 #include <qwidget.h>
00016 #include <qstrlist.h>
00017 #include <qmemarray.h>
00018 #include <qmap.h>
00019 #include <qdragobject.h>
00020 #include <qdict.h>
00021 #include <qguardedptr.h>
00022
00023 class KMFolder;
00024 class KMMessage;
00025 class KMMsgBase;
00026 class KMCommand;
00027 class KMMainWidget;
00028 class KPopupMenu;
00029 class QPalette;
00030 class QPixmap;
00031 class QIconSet;
00032 class QDateTime;
00033
00034 typedef QPtrList<KMMsgBase> KMMessageList;
00035 typedef QValueList<Q_UINT32> SerNumList;
00036 typedef QMap<int,KMFolder*> KMMenuToFolder;
00037 enum NestingPolicy { AlwaysOpen = 0, DefaultOpen, DefaultClosed, OpenUnread };
00038
00039
00040 #define KMAIL_SORT_VERSION 1012
00041 #define KMAIL_SORT_FILE(x) x->indexLocation() + ".sorted"
00042 #define KMAIL_SORT_HEADER "## KMail Sort V%04d\n\t"
00043 #define KMAIL_MAGIC_HEADER_OFFSET 21 //strlen(KMAIL_SORT_HEADER)
00044 #define KMAIL_MAX_KEY_LEN 16384
00045 #define KMAIL_RESERVED 3
00046
00048 class KMHeaders : public KListView
00049 {
00050 Q_OBJECT
00051
00052 friend class ::KMail::HeaderItem;
00053
00054 public:
00055 KMHeaders(KMMainWidget *owner, QWidget *parent=0, const char *name=0);
00056 virtual ~KMHeaders();
00057
00062 virtual void setFolder(KMFolder *, bool forceJumpToUnread = false);
00063
00065 KMFolder* folder(void) { return mFolder; }
00066
00068 void refreshNestedState(void);
00069
00072 virtual void setCurrentMsg(int msgId);
00073
00075 QPtrList<QListViewItem> currentThread() const;
00076
00079 virtual void setThreadStatus(KMMsgStatus status, bool toggle=false);
00080
00081
00082 virtual void setMsgRead(int msgId);
00083
00085 virtual void setMsgStatus(KMMsgStatus status, bool toggle=false);
00086 virtual void deleteMsg();
00087 virtual void applyFiltersOnMsg();
00088 virtual void undo();
00089 virtual bool canUndo() const;
00090 virtual HeaderItem * prepareMove( int *contentX, int *contentY );
00091 virtual void finalizeMove( HeaderItem *item, int contentX, int contentY );
00092
00096 virtual void moveMsgToFolder( KMFolder* destination,
00097 bool askForConfirmation=true );
00098
00101 virtual void copyMsgToFolder(KMFolder* destination,
00102 KMMessage* aMsg = 0);
00103
00105 virtual void clearSelectableAndAboutToBeDeleted(Q_UINT32 serNum);
00108 virtual KMMessageList* selectedMsgs(bool toBeDeleted = false);
00109
00111 QValueList<int> selectedItems();
00112
00114 int indexOfGetMsg (void) const { return getMsgIndex; }
00115
00117 KMMainWidget* owner(void) const { return mOwner; }
00118
00120 const KPaintInfo *paintInfo(void) const { return &mPaintInfo; }
00121
00123 virtual void readConfig(void);
00124
00126 virtual void readColorConfig(void);
00127
00129 virtual KMMessage* currentMsg();
00131 virtual HeaderItem* currentHeaderItem();
00133 virtual int currentItemIndex();
00135 virtual void setCurrentItemByIndex( int msgIdx );
00137 void setCurrentItemBySerialNum( unsigned long serialNum );
00139 virtual int topItemIndex();
00142 virtual void setTopItemByIndex( int aMsgIdx );
00143 virtual void setNestedOverride( bool override );
00144 virtual void setSubjectThreading( bool subjThreading );
00146 virtual void setOpen ( QListViewItem *, bool );
00147
00148 NestingPolicy getNestingPolicy() const { return nestingPolicy; }
00150 bool isThreaded() const {
00151 return mNested != mNestedOverride;
00152 }
00153
00156 virtual int findUnread(bool findNext, int startAt=-1, bool onlyNew = false, bool acceptCurrent = false);
00157
00158 void highlightMessage(QListViewItem*, bool markitread);
00159 void highlightCurrentThread();
00160
00162 static QString fancyDate( time_t otime );
00163
00164 bool noRepaint;
00165
00166
00167 bool eventFilter ( QObject *o, QEvent *e );
00168
00170 const KMMsgBase * getMsgBaseForItem( const QListViewItem *item ) const;
00171
00172
00173 QFont newFont() const { return mNewFont; }
00174 QFont unreadFont() const { return mUnreadFont; }
00175 QFont importantFont() const { return mImportantFont; }
00176 QFont todoFont() const { return mTodoFont; }
00177 QFont dateFont() const { return mDateFont; }
00178
00184 void setCopiedMessages( const QValueList<Q_UINT32> &msgs, bool move );
00185
00190 bool isMessageCut( Q_UINT32 serNum ) const;
00191
00192 signals:
00195 void selected(KMMessage *);
00198 void activated(KMMessage *);
00200 void maybeDeleting();
00202 void messageListUpdated();
00203
00209 void msgAddedToListView( QListViewItem* );
00210
00211 public slots:
00213 void selectMessage(QListViewItem*);
00215 void highlightMessage(QListViewItem*);
00217 void slotRMB();
00219 void msgHeaderChanged(KMFolder *folder, int msgId);
00221 void msgChanged();
00223 void folderCleared();
00225 void msgAdded(int);
00227 void msgRemoved( int, QString );
00229 void nextMessage();
00231 void selectNextMessage();
00233 void prevMessage();
00235 void selectPrevMessage();
00238 bool nextUnreadMessage(bool acceptCurrent = false);
00241 bool prevUnreadMessage();
00243 void incCurrentMessage();
00245 void decCurrentMessage();
00247 void selectCurrentMessage();
00249 void slotNoDrag();
00251 void resetCurrentTime();
00252
00254 void reset();
00255
00258 void slotExpandOrCollapseThread( bool expand );
00261 void slotExpandOrCollapseAllThreads( bool expand );
00262
00263 virtual void ensureCurrentItemVisible();
00264
00267 virtual void setSelected(QListViewItem *item, bool selected);
00268
00272 void setSelectedByIndex(QValueList<int> items, bool selected);
00273
00276 void slotToggleColumn(int id, int mode = -1);
00277
00279 void setFolderInfoStatus();
00280
00281 protected:
00282 static QPixmap *pixNew, *pixUns, *pixDel, *pixRead, *pixRep, *pixSent,
00283 *pixQueued, *pixFwd, *pixFlag, *pixWatched, *pixIgnored, *pixSpam, *pixHam,
00284 *pixFullySigned, *pixPartiallySigned, *pixUndefinedSigned,
00285 *pixFullyEncrypted, *pixPartiallyEncrypted, *pixUndefinedEncrypted,
00286 *pixFiller, *pixEncryptionProblematic,
00287 *pixSignatureProblematic, *pixAttachment,
00288 *pixReadFwd, *pixReadReplied, *pixReadFwdReplied,*pixTodo;
00289
00291 virtual bool event(QEvent *e);
00292
00294 virtual void paintEmptyArea( QPainter * p, const QRect & rect );
00295
00297 void makeHeaderVisible();
00298
00300 void findUnreadAux( HeaderItem*&, bool &, bool, bool );
00301
00306 virtual int firstSelectedMsg() const;
00307
00309 virtual void readFolderConfig(void);
00310
00312 virtual void writeFolderConfig(void);
00313
00315 virtual void writeConfig(void);
00316
00318 virtual void contentsMousePressEvent(QMouseEvent*);
00319 virtual void contentsMouseReleaseEvent(QMouseEvent* e);
00320 virtual void keyPressEvent( QKeyEvent * e );
00321
00323 virtual void setSorting( int column, bool ascending = true);
00324
00326 void contentsMouseMoveEvent( QMouseEvent *e );
00327
00330 void styleChange( QStyle& oldStyle );
00331
00334 void setStyleDependantFrameWidth();
00335
00336 protected slots:
00339 virtual void moveSelectedToFolder( int menuId );
00341 virtual void copySelectedToFolder( int menuId );
00343 virtual int slotFilterMsg( KMMessage * );
00345 void dirtySortOrder(int);
00347 void rightButtonPressed( QListViewItem *, const QPoint &, int );
00348
00349 private slots:
00350 void slotMoveCompleted( KMCommand * );
00351
00352 void copyMessages();
00353 void cutMessages();
00354 void pasteMessages();
00355
00356 void updateActions();
00357
00358 private:
00361 virtual void updateMessageList( bool set_selection=false,
00362 bool forceJumpToUnread = false );
00363
00365 QGuardedPtr<KMFolder> mFolder;
00367 KMMainWidget* mOwner;
00369 int mTopItem;
00371 int mCurrentItem;
00373 unsigned long mCurrentItemSerNum;
00375 QMemArray<HeaderItem*> mItems;
00376
00377
00378 bool mNested, mNestedOverride, mSubjThreading;
00379 NestingPolicy nestingPolicy;
00380 int mSortCol;
00381 bool mSortDescending;
00382
00383 struct {
00384 uint ascending : 1;
00385 uint dirty : 1;
00386 short column;
00387 uint fakeSort : 1;
00388 uint removed : 1;
00389 } mSortInfo;
00390
00391
00393 QDict< SortCacheItem > mSortCacheItems;
00395 QDict< QPtrList< SortCacheItem > > mSubjectLists;
00397 QPtrList<HeaderItem> mImperfectlyThreadedList;
00398
00400 void printSubjectThreadingTree( );
00401 void printThreadingTree( );
00403 void buildThreadingTree( QMemArray<SortCacheItem *> sortCache );
00405 void buildSubjectThreadingTree( QMemArray<SortCacheItem *> sortCache );
00407 SortCacheItem* findParent(SortCacheItem *item);
00409 SortCacheItem* findParentBySubject(SortCacheItem *item);
00410 SortCacheItem* mRoot;
00411
00413 void appendItemToSortFile(HeaderItem *);
00415 bool writeSortOrder();
00417 bool readSortOrder( bool set_selection = false,
00418 bool forceJumpToUnread = false );
00419
00421 int getMsgIndex;
00423 bool getMsgMulti;
00425 HeaderItem* getMsgItem;
00427 KMMessageList mSelMsgBaseList;
00428 HeaderItem* mPrevCurrent;
00429
00431 KPaintInfo mPaintInfo;
00432
00433 QFont mNewFont, mUnreadFont, mImportantFont, mDateFont,mTodoFont;
00434
00436 static QIconSet *up, *down;
00438 KMMenuToFolder mMenuToFolder;
00439
00441 bool mMousePressed;
00443 QPoint mPressPos;
00444
00445 KMime::DateFormatter mDate;
00446 bool mReaderWindowActive;
00447
00449 KPopupMenu* mPopup;
00450
00451
00452 QValueList<Q_UINT32> mCopiedMessages;
00453 bool mMoveMessages;
00454 };
00455 #endif