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 
00106   virtual void copyDecryptedMsgToFolder(KMFolder* destination,
00107                                KMMessage* aMsg = 0);
00108 
00110   virtual void clearSelectableAndAboutToBeDeleted(Q_UINT32 serNum);
00113   virtual KMMessageList* selectedMsgs(bool toBeDeleted = false);
00114 
00116   QValueList<int> selectedItems();
00117 
00119   QValueList<Q_UINT32> selectedSernums();
00120 
00124   QValueList<Q_UINT32> selectedVisibleSernums();
00125 
00127   int indexOfGetMsg (void) const { return getMsgIndex; }
00128 
00130   KMMainWidget* owner(void) const { return mOwner; }
00131 
00133   const KPaintInfo *paintInfo(void) const { return &mPaintInfo; }
00134 
00136   virtual void readConfig(void);
00137 
00139   virtual void readColorConfig(void);
00140 
00148   void restoreColumnLayout( KConfig *config, const QString &group );
00149 
00151   virtual KMMessage* currentMsg();
00153   virtual HeaderItem* currentHeaderItem();
00155   virtual int currentItemIndex();
00157   virtual void setCurrentItemByIndex( int msgIdx );
00159   void setCurrentItemBySerialNum( unsigned long serialNum );
00161   virtual int topItemIndex();
00164   virtual void setTopItemByIndex( int aMsgIdx );
00165   virtual void setNestedOverride( bool override );
00166   virtual void setSubjectThreading( bool subjThreading );
00168   virtual void setOpen ( QListViewItem *, bool );
00169 
00170   NestingPolicy getNestingPolicy() const { return nestingPolicy; }
00172   bool isThreaded() const {
00173     return mNested != mNestedOverride; // xor
00174   }
00175 
00178   virtual int findUnread(bool findNext, int startAt=-1, bool onlyNew = false, bool acceptCurrent = false);
00179 
00180   void highlightMessage(QListViewItem*, bool markitread);
00181   void highlightCurrentThread();
00182 
00184   static QString fancyDate( time_t otime );
00185 
00186   bool noRepaint;
00187 
00188   // filter events for popup
00189   bool eventFilter ( QObject *o, QEvent *e );
00190 
00192   const KMMsgBase * getMsgBaseForItem( const QListViewItem *item ) const;
00193 
00194   // accessors
00195   QFont newFont() const { return mNewFont; }
00196   QFont unreadFont() const { return mUnreadFont; }
00197   QFont importantFont() const { return mImportantFont; }
00198   QFont todoFont() const { return mTodoFont; }
00199   QFont dateFont() const { return mDateFont; }
00200 
00206   void setCopiedMessages( const QValueList<Q_UINT32> &msgs, bool move );
00207 
00212   bool isMessageCut( Q_UINT32 serNum ) const;
00213 
00215   virtual void writeConfig(void);
00216 
00217 signals:
00220   void selected(KMMessage *);
00223   void activated(KMMessage *);
00225   void maybeDeleting();
00227   void messageListUpdated();
00228 
00234   void msgAddedToListView( QListViewItem* );
00235 
00236 public slots:
00238   void selectMessage(QListViewItem*);
00240   void highlightMessage(QListViewItem*);
00242   void slotRMB();
00244   void msgHeaderChanged(KMFolder *folder, int msgId);
00246   void msgChanged();
00248   void folderCleared();
00250   void folderClosed();
00252   void msgAdded(int);
00254   void msgRemoved( int, QString );
00256   void nextMessage();
00258   void selectNextMessage();
00260   void prevMessage();
00262   void selectPrevMessage();
00265   bool nextUnreadMessage(bool acceptCurrent = false);
00268   bool prevUnreadMessage();
00270   void incCurrentMessage();
00272   void decCurrentMessage();
00274   void selectCurrentMessage();
00276   void slotNoDrag();
00278   void resetCurrentTime();
00279 
00281   void reset();
00282 
00285   void slotExpandOrCollapseThread( bool expand );
00288   void slotExpandOrCollapseAllThreads( bool expand );
00289 
00290   virtual void ensureCurrentItemVisible();
00291 
00294   virtual void setSelected(QListViewItem *item, bool selected);
00295 
00299   void setSelectedByIndex(QValueList<int> items, bool selected);
00300 
00303   void slotToggleColumn(int id, int mode = -1);
00304 
00306   void setFolderInfoStatus();
00307 
00308 protected:
00309   static QPixmap *pixNew, *pixUns, *pixDel, *pixRead, *pixRep, *pixSent,
00310     *pixQueued, *pixFwd, *pixFlag, *pixWatched, *pixIgnored, *pixSpam, *pixHam,
00311     *pixFullySigned, *pixPartiallySigned, *pixUndefinedSigned,
00312     *pixFullyEncrypted, *pixPartiallyEncrypted, *pixUndefinedEncrypted,
00313     *pixFiller, *pixEncryptionProblematic,
00314     *pixSignatureProblematic, *pixAttachment, *pixInvitation,
00315     *pixReadFwd, *pixReadReplied, *pixReadFwdReplied, *pixTodo;
00316 
00318   virtual bool event(QEvent *e);
00319 
00321   virtual void paintEmptyArea( QPainter * p, const QRect & rect );
00322 
00324   void makeHeaderVisible();
00325 
00327   void findUnreadAux( HeaderItem*&, bool &, bool, bool );
00328 
00333   virtual int firstSelectedMsg() const;
00334 
00336   virtual void readFolderConfig(void);
00337 
00339   virtual void writeFolderConfig(void);
00340 
00342   virtual void contentsMousePressEvent(QMouseEvent*);
00343   virtual void contentsMouseReleaseEvent(QMouseEvent* e);
00344   virtual void keyPressEvent( QKeyEvent * e );
00345 
00347   virtual void setSorting( int column, bool ascending = true);
00348 
00350   void contentsMouseMoveEvent( QMouseEvent *e );
00351 
00354   void styleChange( QStyle& oldStyle );
00355 
00358   void setStyleDependantFrameWidth();
00359 
00360 protected slots:
00363   virtual void moveSelectedToFolder( int menuId );
00365   virtual void copySelectedToFolder( int menuId );
00367   virtual void decryptedCopySelectedToFolder( int menuId );
00369   virtual int slotFilterMsg( KMMessage * );
00371   void dirtySortOrder(int);
00373   void rightButtonPressed( QListViewItem *, const QPoint &, int );
00374 
00375 private slots:
00376   void slotMoveCompleted( KMCommand * );
00377 
00378   void copyMessages();
00379   void cutMessages();
00380   void pasteMessages();
00381 
00382   void updateActions();
00383 
00384   void batchRemovingStarted();
00385   void batchRemovingFinished();
00386 
00387 private:
00390   virtual void updateMessageList( bool set_selection=false,
00391       bool forceJumpToUnread = false );
00392 
00394   QGuardedPtr<KMFolder> mFolder;
00396   KMMainWidget* mOwner;
00398   int mTopItem;
00400   int mCurrentItem;
00402   unsigned long mCurrentItemSerNum;
00404   QMemArray<HeaderItem*> mItems;
00405 
00406   // ===== threading and sorting ==========
00407   bool mNested, mNestedOverride, mSubjThreading;
00408   NestingPolicy nestingPolicy;
00409   int mSortCol;
00410   bool mSortDescending;
00411   bool mIgnoreSortOrderChanges;
00412 
00413   struct {
00414       uint ascending : 1;
00415       uint dirty : 1;
00416       short column;
00417       uint fakeSort : 1;
00418       uint removed : 1;
00419   } mSortInfo;
00420 
00421 
00423   QDict< SortCacheItem > mSortCacheItems;
00425   QDict< QPtrList< SortCacheItem > > mSubjectLists;
00427   QPtrList<HeaderItem> mImperfectlyThreadedList;
00428 
00430   void printSubjectThreadingTree( );
00431   void printThreadingTree( );
00433   void buildThreadingTree( QMemArray<SortCacheItem *> sortCache );
00435   void buildSubjectThreadingTree( QMemArray<SortCacheItem *> sortCache );
00437   SortCacheItem* findParent(SortCacheItem *item);
00439   SortCacheItem* findParentBySubject(SortCacheItem *item);
00440   SortCacheItem* mRoot; // used to represent the list view itself while threading
00441 
00443   void appendItemToSortFile(HeaderItem *);
00445   bool writeSortOrder();
00447   bool readSortOrder( bool set_selection = false,
00448       bool forceJumpToUnread = false );
00449 
00451   int getMsgIndex;
00453   bool getMsgMulti;
00455   HeaderItem* getMsgItem;
00457   KMMessageList mSelMsgBaseList;
00458   HeaderItem* mPrevCurrent;
00459 
00461   KPaintInfo mPaintInfo;
00462 
00463   QFont mNewFont, mUnreadFont, mImportantFont, mDateFont,mTodoFont;
00464 
00466   static QIconSet *up, *down;
00468   KMMenuToFolder mMenuToFolder;
00469 
00471   bool mMousePressed;
00473   QPoint mPressPos;
00474 
00475   KMime::DateFormatter mDate;
00476   bool mReaderWindowActive;
00477 
00479   KPopupMenu* mPopup;
00480 
00481   // copied messages
00482   QValueList<Q_UINT32> mCopiedMessages;
00483   bool mMoveMessages;
00484 
00485   // Info about this in folderstorage.h:batchRemovingStarts()
00486   bool mBatchRemovingInProgress;
00487 
00488 }; // class
00489 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys