kmail

kmheaders.h

00001 // -*- mode: C++ -*-
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> // for KPaintInfo
00013 #include <kmmsgbase.h>   // for KMMsgStatus
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; // For easy access to the pixmaps
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   /* Set message status to read if it is new, or unread */
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; // xor
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   // filter events for popup
00167   bool eventFilter ( QObject *o, QEvent *e );
00168 
00170   const KMMsgBase * getMsgBaseForItem( const QListViewItem *item ) const;
00171 
00172   // accessors
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 
00179 signals:
00182   void selected(KMMessage *);
00185   void activated(KMMessage *);
00187   void maybeDeleting();
00189   void messageListUpdated();
00190 
00196   void msgAddedToListView( QListViewItem* );
00197 
00198 public slots:
00200   void selectMessage(QListViewItem*);
00202   void highlightMessage(QListViewItem*);
00204   void slotRMB();
00206   void msgHeaderChanged(KMFolder *folder, int msgId);
00208   void msgChanged();
00210   void folderCleared();
00212   void msgAdded(int);
00214   void msgRemoved( int, QString );
00216   void nextMessage();
00218   void selectNextMessage();
00220   void prevMessage();
00222   void selectPrevMessage();
00225   bool nextUnreadMessage(bool acceptCurrent = false);
00228   bool prevUnreadMessage();
00230   void incCurrentMessage();
00232   void decCurrentMessage();
00234   void selectCurrentMessage();
00236   void slotNoDrag();
00238   void resetCurrentTime();
00239 
00241   void reset();
00242 
00245   void slotExpandOrCollapseThread( bool expand );
00248   void slotExpandOrCollapseAllThreads( bool expand );
00249 
00250   virtual void ensureCurrentItemVisible();
00251 
00254   virtual void setSelected(QListViewItem *item, bool selected);
00255 
00259   void setSelectedByIndex(QValueList<int> items, bool selected);
00260 
00263   void slotToggleColumn(int id, int mode = -1);
00264 
00266   void setFolderInfoStatus();
00267 
00268 protected:
00269   static QPixmap *pixNew, *pixUns, *pixDel, *pixRead, *pixRep, *pixSent,
00270     *pixQueued, *pixFwd, *pixFlag, *pixWatched, *pixIgnored, *pixSpam, *pixHam,
00271     *pixFullySigned, *pixPartiallySigned, *pixUndefinedSigned,
00272     *pixFullyEncrypted, *pixPartiallyEncrypted, *pixUndefinedEncrypted,
00273     *pixFiller, *pixEncryptionProblematic,
00274     *pixSignatureProblematic, *pixAttachment,
00275     *pixReadFwd, *pixReadReplied, *pixReadFwdReplied,*pixTodo;
00276 
00278   virtual bool event(QEvent *e);
00279 
00281   virtual void paintEmptyArea( QPainter * p, const QRect & rect );
00282 
00284   void makeHeaderVisible();
00285 
00287   void findUnreadAux( HeaderItem*&, bool &, bool, bool );
00288 
00293   virtual int firstSelectedMsg() const;
00294 
00296   virtual void readFolderConfig(void);
00297 
00299   virtual void writeFolderConfig(void);
00300 
00302   virtual void writeConfig(void);
00303 
00305   virtual void contentsMousePressEvent(QMouseEvent*);
00306   virtual void contentsMouseReleaseEvent(QMouseEvent* e);
00307   virtual void keyPressEvent( QKeyEvent * e );
00308 
00310   virtual void setSorting( int column, bool ascending = true);
00311 
00313   void contentsMouseMoveEvent( QMouseEvent *e );
00314 
00317   void styleChange( QStyle& oldStyle );
00318 
00321   void setStyleDependantFrameWidth();
00322 
00323 protected slots:
00326   virtual void moveSelectedToFolder( int menuId );
00328   virtual void copySelectedToFolder( int menuId );
00330   virtual int slotFilterMsg( KMMessage * );
00332   void dirtySortOrder(int);
00334   void rightButtonPressed( QListViewItem *, const QPoint &, int );
00335 
00336 private slots:
00337   void slotMoveCompleted( KMCommand * );
00338 
00339 private:
00342   virtual void updateMessageList( bool set_selection=false,
00343       bool forceJumpToUnread = false );
00344 
00346   QGuardedPtr<KMFolder> mFolder;
00348   KMMainWidget* mOwner;
00350   int mTopItem;
00352   int mCurrentItem;
00354   unsigned long mCurrentItemSerNum;
00356   QMemArray<HeaderItem*> mItems;
00357 
00358   // ===== threading and sorting ==========
00359   bool mNested, mNestedOverride, mSubjThreading;
00360   NestingPolicy nestingPolicy;
00361   int mSortCol;
00362   bool mSortDescending;
00363 
00364   struct {
00365       uint ascending : 1;
00366       uint dirty : 1;
00367       short column;
00368       uint fakeSort : 1;
00369       uint removed : 1;
00370   } mSortInfo;
00371 
00372 
00374   QDict< SortCacheItem > mSortCacheItems;
00376   QDict< QPtrList< SortCacheItem > > mSubjectLists;
00378   QPtrList<HeaderItem> mImperfectlyThreadedList;
00379 
00381   void printSubjectThreadingTree( );
00382   void printThreadingTree( );
00384   void buildThreadingTree( QMemArray<SortCacheItem *> sortCache );
00386   void buildSubjectThreadingTree( QMemArray<SortCacheItem *> sortCache );
00388   SortCacheItem* findParent(SortCacheItem *item);
00390   SortCacheItem* findParentBySubject(SortCacheItem *item);
00391   SortCacheItem* mRoot; // used to represent the list view itself while threading
00392 
00394   void appendItemToSortFile(HeaderItem *);
00396   bool writeSortOrder();
00398   bool readSortOrder( bool set_selection = false,
00399       bool forceJumpToUnread = false );
00400 
00402   int getMsgIndex;
00404   bool getMsgMulti;
00406   HeaderItem* getMsgItem;
00408   KMMessageList mSelMsgBaseList;
00409   HeaderItem* mPrevCurrent;
00410 
00412   KPaintInfo mPaintInfo;
00413 
00414   QFont mNewFont, mUnreadFont, mImportantFont, mDateFont,mTodoFont;
00415 
00417   static QIconSet *up, *down;
00419   KMMenuToFolder mMenuToFolder;
00420 
00422   bool mMousePressed;
00424   QPoint mPressPos;
00425 
00426   KMime::DateFormatter mDate;
00427   bool mReaderWindowActive;
00428 
00430   KPopupMenu* mPopup;
00431 
00432 }; // class
00433 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys