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 
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 folderClosed();
00227   void msgAdded(int);
00229   void msgRemoved( int, QString );
00231   void nextMessage();
00233   void selectNextMessage();
00235   void prevMessage();
00237   void selectPrevMessage();
00240   bool nextUnreadMessage(bool acceptCurrent = false);
00243   bool prevUnreadMessage();
00245   void incCurrentMessage();
00247   void decCurrentMessage();
00249   void selectCurrentMessage();
00251   void slotNoDrag();
00253   void resetCurrentTime();
00254 
00256   void reset();
00257 
00260   void slotExpandOrCollapseThread( bool expand );
00263   void slotExpandOrCollapseAllThreads( bool expand );
00264 
00265   virtual void ensureCurrentItemVisible();
00266 
00269   virtual void setSelected(QListViewItem *item, bool selected);
00270 
00274   void setSelectedByIndex(QValueList<int> items, bool selected);
00275 
00278   void slotToggleColumn(int id, int mode = -1);
00279 
00281   void setFolderInfoStatus();
00282 
00283 protected:
00284   static QPixmap *pixNew, *pixUns, *pixDel, *pixRead, *pixRep, *pixSent,
00285     *pixQueued, *pixFwd, *pixFlag, *pixWatched, *pixIgnored, *pixSpam, *pixHam,
00286     *pixFullySigned, *pixPartiallySigned, *pixUndefinedSigned,
00287     *pixFullyEncrypted, *pixPartiallyEncrypted, *pixUndefinedEncrypted,
00288     *pixFiller, *pixEncryptionProblematic,
00289     *pixSignatureProblematic, *pixAttachment,
00290     *pixReadFwd, *pixReadReplied, *pixReadFwdReplied,*pixTodo;
00291 
00293   virtual bool event(QEvent *e);
00294 
00296   virtual void paintEmptyArea( QPainter * p, const QRect & rect );
00297 
00299   void makeHeaderVisible();
00300 
00302   void findUnreadAux( HeaderItem*&, bool &, bool, bool );
00303 
00308   virtual int firstSelectedMsg() const;
00309 
00311   virtual void readFolderConfig(void);
00312 
00314   virtual void writeFolderConfig(void);
00315 
00317   virtual void writeConfig(void);
00318 
00320   virtual void contentsMousePressEvent(QMouseEvent*);
00321   virtual void contentsMouseReleaseEvent(QMouseEvent* e);
00322   virtual void keyPressEvent( QKeyEvent * e );
00323 
00325   virtual void setSorting( int column, bool ascending = true);
00326 
00328   void contentsMouseMoveEvent( QMouseEvent *e );
00329 
00332   void styleChange( QStyle& oldStyle );
00333 
00336   void setStyleDependantFrameWidth();
00337 
00338 protected slots:
00341   virtual void moveSelectedToFolder( int menuId );
00343   virtual void copySelectedToFolder( int menuId );
00345   virtual int slotFilterMsg( KMMessage * );
00347   void dirtySortOrder(int);
00349   void rightButtonPressed( QListViewItem *, const QPoint &, int );
00350 
00351 private slots:
00352   void slotMoveCompleted( KMCommand * );
00353 
00354   void copyMessages();
00355   void cutMessages();
00356   void pasteMessages();
00357 
00358   void updateActions();
00359 
00360 private:
00363   virtual void updateMessageList( bool set_selection=false,
00364       bool forceJumpToUnread = false );
00365 
00367   QGuardedPtr<KMFolder> mFolder;
00369   KMMainWidget* mOwner;
00371   int mTopItem;
00373   int mCurrentItem;
00375   unsigned long mCurrentItemSerNum;
00377   QMemArray<HeaderItem*> mItems;
00378 
00379   // ===== threading and sorting ==========
00380   bool mNested, mNestedOverride, mSubjThreading;
00381   NestingPolicy nestingPolicy;
00382   int mSortCol;
00383   bool mSortDescending;
00384 
00385   struct {
00386       uint ascending : 1;
00387       uint dirty : 1;
00388       short column;
00389       uint fakeSort : 1;
00390       uint removed : 1;
00391   } mSortInfo;
00392 
00393 
00395   QDict< SortCacheItem > mSortCacheItems;
00397   QDict< QPtrList< SortCacheItem > > mSubjectLists;
00399   QPtrList<HeaderItem> mImperfectlyThreadedList;
00400 
00402   void printSubjectThreadingTree( );
00403   void printThreadingTree( );
00405   void buildThreadingTree( QMemArray<SortCacheItem *> sortCache );
00407   void buildSubjectThreadingTree( QMemArray<SortCacheItem *> sortCache );
00409   SortCacheItem* findParent(SortCacheItem *item);
00411   SortCacheItem* findParentBySubject(SortCacheItem *item);
00412   SortCacheItem* mRoot; // used to represent the list view itself while threading
00413 
00415   void appendItemToSortFile(HeaderItem *);
00417   bool writeSortOrder();
00419   bool readSortOrder( bool set_selection = false,
00420       bool forceJumpToUnread = false );
00421 
00423   int getMsgIndex;
00425   bool getMsgMulti;
00427   HeaderItem* getMsgItem;
00429   KMMessageList mSelMsgBaseList;
00430   HeaderItem* mPrevCurrent;
00431 
00433   KPaintInfo mPaintInfo;
00434 
00435   QFont mNewFont, mUnreadFont, mImportantFont, mDateFont,mTodoFont;
00436 
00438   static QIconSet *up, *down;
00440   KMMenuToFolder mMenuToFolder;
00441 
00443   bool mMousePressed;
00445   QPoint mPressPos;
00446 
00447   KMime::DateFormatter mDate;
00448   bool mReaderWindowActive;
00449 
00451   KPopupMenu* mPopup;
00452 
00453   // copied messages
00454   QValueList<Q_UINT32> mCopiedMessages;
00455   bool mMoveMessages;
00456 }; // class
00457 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys