kmail

kmheaders.h

Go to the documentation of this file.
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   QValueList<Q_UINT32> selectedSernums();
00115 
00119   QValueList<Q_UINT32> selectedVisibleSernums();
00120 
00122   int indexOfGetMsg (void) const { return getMsgIndex; }
00123 
00125   KMMainWidget* owner(void) const { return mOwner; }
00126 
00128   const KPaintInfo *paintInfo(void) const { return &mPaintInfo; }
00129 
00131   virtual void readConfig(void);
00132 
00134   virtual void readColorConfig(void);
00135 
00137   virtual KMMessage* currentMsg();
00139   virtual HeaderItem* currentHeaderItem();
00141   virtual int currentItemIndex();
00143   virtual void setCurrentItemByIndex( int msgIdx );
00145   void setCurrentItemBySerialNum( unsigned long serialNum );
00147   virtual int topItemIndex();
00150   virtual void setTopItemByIndex( int aMsgIdx );
00151   virtual void setNestedOverride( bool override );
00152   virtual void setSubjectThreading( bool subjThreading );
00154   virtual void setOpen ( QListViewItem *, bool );
00155 
00156   NestingPolicy getNestingPolicy() const { return nestingPolicy; }
00158   bool isThreaded() const {
00159     return mNested != mNestedOverride; // xor
00160   }
00161 
00164   virtual int findUnread(bool findNext, int startAt=-1, bool onlyNew = false, bool acceptCurrent = false);
00165 
00166   void highlightMessage(QListViewItem*, bool markitread);
00167   void highlightCurrentThread();
00168 
00170   static QString fancyDate( time_t otime );
00171 
00172   bool noRepaint;
00173 
00174   // filter events for popup
00175   bool eventFilter ( QObject *o, QEvent *e );
00176 
00178   const KMMsgBase * getMsgBaseForItem( const QListViewItem *item ) const;
00179 
00180   // accessors
00181   QFont newFont() const { return mNewFont; }
00182   QFont unreadFont() const { return mUnreadFont; }
00183   QFont importantFont() const { return mImportantFont; }
00184   QFont todoFont() const { return mTodoFont; }
00185   QFont dateFont() const { return mDateFont; }
00186 
00192   void setCopiedMessages( const QValueList<Q_UINT32> &msgs, bool move );
00193 
00198   bool isMessageCut( Q_UINT32 serNum ) const;
00199 
00200 signals:
00203   void selected(KMMessage *);
00206   void activated(KMMessage *);
00208   void maybeDeleting();
00210   void messageListUpdated();
00211 
00217   void msgAddedToListView( QListViewItem* );
00218 
00219 public slots:
00221   void selectMessage(QListViewItem*);
00223   void highlightMessage(QListViewItem*);
00225   void slotRMB();
00227   void msgHeaderChanged(KMFolder *folder, int msgId);
00229   void msgChanged();
00231   void folderCleared();
00233   void folderClosed();
00235   void msgAdded(int);
00237   void msgRemoved( int, QString );
00239   void nextMessage();
00241   void selectNextMessage();
00243   void prevMessage();
00245   void selectPrevMessage();
00248   bool nextUnreadMessage(bool acceptCurrent = false);
00251   bool prevUnreadMessage();
00253   void incCurrentMessage();
00255   void decCurrentMessage();
00257   void selectCurrentMessage();
00259   void slotNoDrag();
00261   void resetCurrentTime();
00262 
00264   void reset();
00265 
00268   void slotExpandOrCollapseThread( bool expand );
00271   void slotExpandOrCollapseAllThreads( bool expand );
00272 
00273   virtual void ensureCurrentItemVisible();
00274 
00277   virtual void setSelected(QListViewItem *item, bool selected);
00278 
00282   void setSelectedByIndex(QValueList<int> items, bool selected);
00283 
00286   void slotToggleColumn(int id, int mode = -1);
00287 
00289   void setFolderInfoStatus();
00290 
00291 protected:
00292   static QPixmap *pixNew, *pixUns, *pixDel, *pixRead, *pixRep, *pixSent,
00293     *pixQueued, *pixFwd, *pixFlag, *pixWatched, *pixIgnored, *pixSpam, *pixHam,
00294     *pixFullySigned, *pixPartiallySigned, *pixUndefinedSigned,
00295     *pixFullyEncrypted, *pixPartiallyEncrypted, *pixUndefinedEncrypted,
00296     *pixFiller, *pixEncryptionProblematic,
00297     *pixSignatureProblematic, *pixAttachment,
00298     *pixReadFwd, *pixReadReplied, *pixReadFwdReplied,*pixTodo;
00299 
00301   virtual bool event(QEvent *e);
00302 
00304   virtual void paintEmptyArea( QPainter * p, const QRect & rect );
00305 
00307   void makeHeaderVisible();
00308 
00310   void findUnreadAux( HeaderItem*&, bool &, bool, bool );
00311 
00316   virtual int firstSelectedMsg() const;
00317 
00319   virtual void readFolderConfig(void);
00320 
00322   virtual void writeFolderConfig(void);
00323 
00325   virtual void writeConfig(void);
00326 
00328   virtual void contentsMousePressEvent(QMouseEvent*);
00329   virtual void contentsMouseReleaseEvent(QMouseEvent* e);
00330   virtual void keyPressEvent( QKeyEvent * e );
00331 
00333   virtual void setSorting( int column, bool ascending = true);
00334 
00336   void contentsMouseMoveEvent( QMouseEvent *e );
00337 
00340   void styleChange( QStyle& oldStyle );
00341 
00344   void setStyleDependantFrameWidth();
00345 
00346 protected slots:
00349   virtual void moveSelectedToFolder( int menuId );
00351   virtual void copySelectedToFolder( int menuId );
00353   virtual int slotFilterMsg( KMMessage * );
00355   void dirtySortOrder(int);
00357   void rightButtonPressed( QListViewItem *, const QPoint &, int );
00358 
00359 private slots:
00360   void slotMoveCompleted( KMCommand * );
00361 
00362   void copyMessages();
00363   void cutMessages();
00364   void pasteMessages();
00365 
00366   void updateActions();
00367 
00368 private:
00371   virtual void updateMessageList( bool set_selection=false,
00372       bool forceJumpToUnread = false );
00373 
00375   QGuardedPtr<KMFolder> mFolder;
00377   KMMainWidget* mOwner;
00379   int mTopItem;
00381   int mCurrentItem;
00383   unsigned long mCurrentItemSerNum;
00385   QMemArray<HeaderItem*> mItems;
00386 
00387   // ===== threading and sorting ==========
00388   bool mNested, mNestedOverride, mSubjThreading;
00389   NestingPolicy nestingPolicy;
00390   int mSortCol;
00391   bool mSortDescending;
00392 
00393   struct {
00394       uint ascending : 1;
00395       uint dirty : 1;
00396       short column;
00397       uint fakeSort : 1;
00398       uint removed : 1;
00399   } mSortInfo;
00400 
00401 
00403   QDict< SortCacheItem > mSortCacheItems;
00405   QDict< QPtrList< SortCacheItem > > mSubjectLists;
00407   QPtrList<HeaderItem> mImperfectlyThreadedList;
00408 
00410   void printSubjectThreadingTree( );
00411   void printThreadingTree( );
00413   void buildThreadingTree( QMemArray<SortCacheItem *> sortCache );
00415   void buildSubjectThreadingTree( QMemArray<SortCacheItem *> sortCache );
00417   SortCacheItem* findParent(SortCacheItem *item);
00419   SortCacheItem* findParentBySubject(SortCacheItem *item);
00420   SortCacheItem* mRoot; // used to represent the list view itself while threading
00421 
00423   void appendItemToSortFile(HeaderItem *);
00425   bool writeSortOrder();
00427   bool readSortOrder( bool set_selection = false,
00428       bool forceJumpToUnread = false );
00429 
00431   int getMsgIndex;
00433   bool getMsgMulti;
00435   HeaderItem* getMsgItem;
00437   KMMessageList mSelMsgBaseList;
00438   HeaderItem* mPrevCurrent;
00439 
00441   KPaintInfo mPaintInfo;
00442 
00443   QFont mNewFont, mUnreadFont, mImportantFont, mDateFont,mTodoFont;
00444 
00446   static QIconSet *up, *down;
00448   KMMenuToFolder mMenuToFolder;
00449 
00451   bool mMousePressed;
00453   QPoint mPressPos;
00454 
00455   KMime::DateFormatter mDate;
00456   bool mReaderWindowActive;
00457 
00459   KPopupMenu* mPopup;
00460 
00461   // copied messages
00462   QValueList<Q_UINT32> mCopiedMessages;
00463   bool mMoveMessages;
00464 }; // class
00465 #endif