00001
00002
00003 #ifndef __KMHEADERS
00004 #define __KMHEADERS
00005
00006 #include "kmmessage.h"
00007 #include "kmime_util.h"
00008 #include "kmcommands.h"
00009
00010 #include <klistview.h>
00011 #include <kfoldertree.h>
00012 #include <kpopupmenu.h>
00013
00014 #include <qwidget.h>
00015 #include <qstrlist.h>
00016 #include <qmemarray.h>
00017 #include <qmap.h>
00018 #include <qdragobject.h>
00019 #include <qdict.h>
00020
00021 class KMFolder;
00022 class KMMessage;
00023 class KMMsgBase;
00024 class KMMainWidget;
00025 class QPalette;
00026 class KMHeaderItem;
00027 class QPixmap;
00028 class QIconSet;
00029 class QDateTime;
00030 class KMSortCacheItem;
00031
00032 typedef QPtrList<KMMsgBase> KMMessageList;
00033 typedef QValueList<Q_UINT32> SerNumList;
00034 typedef QMap<int,KMFolder*> KMMenuToFolder;
00035 enum NestingPolicy { AlwaysOpen = 0, DefaultOpen, DefaultClosed, OpenUnread };
00036
00038 class KMHeaders : public KListView
00039 {
00040 Q_OBJECT
00041
00042 friend class KMHeaderItem;
00043
00044 public:
00045 KMHeaders(KMMainWidget *owner, QWidget *parent=0, const char *name=0);
00046 virtual ~KMHeaders();
00047
00052 virtual void setFolder(KMFolder *, bool forceJumpToUnread = false);
00053
00055 KMFolder* folder(void) { return mFolder; }
00056
00058 void refreshNestedState(void);
00059
00062 virtual void setCurrentMsg(int msgId);
00063
00065 QPtrList<QListViewItem> currentThread() const;
00066
00069 virtual void setThreadStatus(KMMsgStatus status, bool toggle=false);
00070
00071
00072 virtual void setMsgRead(int msgId);
00073
00075 virtual void setMsgStatus(KMMsgStatus status, bool toggle=false);
00076 virtual void deleteMsg();
00077 virtual void applyFiltersOnMsg();
00078 virtual void undo();
00079 virtual bool canUndo() const;
00080 virtual KMHeaderItem * prepareMove( int *contentX, int *contentY );
00081 virtual void finalizeMove( KMHeaderItem *item, int contentX, int contentY );
00082
00086 virtual void moveMsgToFolder( KMFolder* destination,
00087 bool askForConfirmation=true );
00088
00091 virtual void copyMsgToFolder(KMFolder* destination,
00092 KMMessage* aMsg = 0);
00093
00095 virtual void clearSelectableAndAboutToBeDeleted(Q_UINT32 serNum);
00098 virtual KMMessageList* selectedMsgs(bool toBeDeleted = false);
00099
00101 QValueList<int> selectedItems();
00102
00104 int indexOfGetMsg (void) const { return getMsgIndex; }
00105
00107 KMMainWidget* owner(void) const { return mOwner; }
00108
00110 const KPaintInfo *paintInfo(void) const { return &mPaintInfo; }
00111
00113 virtual void readConfig(void);
00114
00116 virtual void readColorConfig(void);
00117
00119 virtual void reset(void);
00120
00122 void showNewMail();
00123
00125 virtual KMMessage* currentMsg();
00127 virtual KMHeaderItem* currentHeaderItem();
00129 virtual int currentItemIndex();
00131 virtual void setCurrentItemByIndex( int msgIdx );
00133 void setCurrentItemBySerialNum( unsigned long serialNum );
00135 virtual int topItemIndex();
00138 virtual void setTopItemByIndex( int aMsgIdx );
00139 virtual void setNestedOverride( bool override );
00140 virtual void setSubjectThreading( bool subjThreading );
00142 virtual void setOpen ( QListViewItem *, bool );
00143
00144 NestingPolicy getNestingPolicy() const { return nestingPolicy; }
00146 bool isThreaded() const {
00147 return mNested != mNestedOverride;
00148 }
00149
00152 virtual int findUnread(bool findNext, int startAt=-1, bool onlyNew = false, bool acceptCurrent = false);
00153
00154 void highlightMessage(QListViewItem*, bool markitread);
00155
00157 static QString fancyDate( time_t otime );
00158
00159 QFont dateFont;
00160
00161 bool noRepaint;
00162
00163
00164 bool eventFilter ( QObject *o, QEvent *e );
00165
00167 const KMMsgBase * getMsgBaseForItem( const QListViewItem *item ) const;
00168
00169 signals:
00172 void selected(KMMessage *);
00175 void activated(KMMessage *);
00177 void maybeDeleting();
00179 void messageListUpdated();
00180
00186 void msgAddedToListView( QListViewItem* );
00187
00188 public slots:
00190 void selectMessage(QListViewItem*);
00192 void highlightMessage(QListViewItem*);
00194 void slotRMB();
00196 void msgHeaderChanged(KMFolder *folder, int msgId);
00198 void msgChanged();
00200 void folderCleared();
00202 void msgAdded(int);
00204 void msgRemoved(int, QString, QString);
00206 void nextMessage();
00208 void selectNextMessage();
00210 void prevMessage();
00212 void selectPrevMessage();
00215 bool nextUnreadMessage(bool acceptCurrent = false);
00218 bool prevUnreadMessage();
00220 void slotNoDrag();
00222 void resetCurrentTime();
00223
00226 void slotExpandOrCollapseThread( bool expand );
00229 void slotExpandOrCollapseAllThreads( bool expand );
00230
00231 virtual void ensureCurrentItemVisible();
00232
00235 virtual void setSelected(QListViewItem *item, bool selected);
00236
00240 void setSelectedByIndex(QValueList<int> items, bool selected);
00241
00244 void slotToggleSizeColumn(int mode = -1);
00245
00247 void setFolderInfoStatus();
00248
00249 protected:
00250 static QPixmap *pixNew, *pixUns, *pixDel, *pixRead, *pixRep, *pixSent,
00251 *pixQueued, *pixFwd, *pixFlag, *pixWatched, *pixIgnored, *pixSpam, *pixHam,
00252 *pixFullySigned, *pixPartiallySigned, *pixUndefinedSigned,
00253 *pixFullyEncrypted, *pixPartiallyEncrypted, *pixUndefinedEncrypted,
00254 *pixFiller, *pixEncryptionProblematic,
00255 *pixSignatureProblematic, *pixAttachment;
00256
00258 virtual bool event(QEvent *e);
00259
00261 virtual void paintEmptyArea( QPainter * p, const QRect & rect );
00262
00264 void makeHeaderVisible();
00265
00267 void findUnreadAux( KMHeaderItem*&, bool &, bool, bool );
00268
00273 virtual int firstSelectedMsg() const;
00274
00276 virtual void readFolderConfig(void);
00277
00279 virtual void writeFolderConfig(void);
00280
00282 virtual void writeConfig(void);
00283
00285 virtual void contentsMousePressEvent(QMouseEvent*);
00286 virtual void contentsMouseReleaseEvent(QMouseEvent* e);
00287 virtual void keyPressEvent( QKeyEvent * e );
00288
00290 virtual void setSorting( int column, bool ascending = true);
00291
00293 void contentsMouseMoveEvent( QMouseEvent *e );
00294
00297 void styleChange( QStyle& oldStyle );
00298
00301 void setStyleDependantFrameWidth();
00302
00303 protected slots:
00306 virtual void moveSelectedToFolder( int menuId );
00308 virtual void copySelectedToFolder( int menuId );
00310 virtual int slotFilterMsg( KMMessage * );
00312 void dirtySortOrder(int);
00314 void rightButtonPressed( QListViewItem *, const QPoint &, int );
00315
00316 private slots:
00317 void slotMoveCompleted( KMCommand * );
00318
00319 private:
00322 virtual void updateMessageList( bool set_selection=false,
00323 bool forceJumpToUnread = false );
00324
00326 QGuardedPtr<KMFolder> mFolder;
00328 KMMainWidget* mOwner;
00330 int mTopItem;
00332 int mCurrentItem;
00334 unsigned long mCurrentItemSerNum;
00336 QMemArray<KMHeaderItem*> mItems;
00337
00338
00339 bool mNested, mNestedOverride, mSubjThreading;
00340 NestingPolicy nestingPolicy;
00341 int mSortCol;
00342 bool mSortDescending;
00343
00344 struct {
00345 uint ascending : 1;
00346 uint dirty : 1;
00347 short column;
00348 uint fakeSort : 1;
00349 uint removed : 1;
00350 } mSortInfo;
00351
00352
00354 QDict< KMSortCacheItem > mSortCacheItems;
00356 QDict< QPtrList< KMSortCacheItem > > mSubjectLists;
00358 QPtrList<KMHeaderItem> mImperfectlyThreadedList;
00359
00361 void buildThreadingTree( QMemArray<KMSortCacheItem *> sortCache );
00363 void buildSubjectThreadingTree( QMemArray<KMSortCacheItem *> sortCache );
00365 KMSortCacheItem* findParent(KMSortCacheItem *item);
00367 KMSortCacheItem* findParentBySubject(KMSortCacheItem *item);
00368
00370 void appendItemToSortFile(KMHeaderItem *);
00372 bool writeSortOrder();
00374 bool readSortOrder( bool set_selection = false,
00375 bool forceJumpToUnread = false );
00376
00378 int getMsgIndex;
00380 bool getMsgMulti;
00382 KMHeaderItem* getMsgItem;
00384 KMMessageList mSelMsgBaseList;
00385 QPtrList<KMMessage> mSelMsgList;
00386 KMHeaderItem* mPrevCurrent;
00387
00389 KPaintInfo mPaintInfo;
00390
00392 static QIconSet *up, *down;
00394 KMMenuToFolder mMenuToFolder;
00395
00397 bool mMousePressed;
00399 QPoint mPressPos;
00400
00401 KMime::DateFormatter mDate;
00402 bool mReaderWindowActive;
00403
00405 KPopupMenu* mPopup;
00406 int mSizeColumn;
00407 };
00408
00409 #endif