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   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 
00143   void restoreColumnLayout( KConfig *config, const QString &group );
00144 
00146   virtual KMMessage* currentMsg();
00148   virtual HeaderItem* currentHeaderItem();
00150   virtual int currentItemIndex();
00152   virtual void setCurrentItemByIndex( int msgIdx );
00154   void setCurrentItemBySerialNum( unsigned long serialNum );
00156   virtual int topItemIndex();
00159   virtual void setTopItemByIndex( int aMsgIdx );
00160   virtual void setNestedOverride( bool override );
00161   virtual void setSubjectThreading( bool subjThreading );
00163   virtual void setOpen ( QListViewItem *, bool );
00164 
00165   NestingPolicy getNestingPolicy() const { return nestingPolicy; }
00167   bool isThreaded() const {
00168     return mNested != mNestedOverride; // xor
00169   }
00170 
00173   virtual int findUnread(bool findNext, int startAt=-1, bool onlyNew = false, bool acceptCurrent = false);
00174 
00175   void highlightMessage(QListViewItem*, bool markitread);
00176   void highlightCurrentThread();
00177 
00179   static QString fancyDate( time_t otime );
00180 
00181   bool noRepaint;
00182 
00183   // filter events for popup
00184   bool eventFilter ( QObject *o, QEvent *e );
00185 
00187   const KMMsgBase * getMsgBaseForItem( const QListViewItem *item ) const;
00188 
00189   // accessors
00190   QFont newFont() const { return mNewFont; }
00191   QFont unreadFont() const { return mUnreadFont; }
00192   QFont importantFont() const { return mImportantFont; }
00193   QFont todoFont() const { return mTodoFont; }
00194   QFont dateFont() const { return mDateFont; }
00195 
00201   void setCopiedMessages( const QValueList<Q_UINT32> &msgs, bool move );
00202 
00207   bool isMessageCut( Q_UINT32 serNum ) const;
00208 
00210   virtual void writeConfig(void);
00211 
00212 signals:
00215   void selected(KMMessage *);
00218   void activated(KMMessage *);
00220   void maybeDeleting();
00222   void messageListUpdated();
00223 
00229   void msgAddedToListView( QListViewItem* );
00230 
00231 public slots:
00233   void selectMessage(QListViewItem*);
00235   void highlightMessage(QListViewItem*);
00237   void slotRMB();
00239   void msgHeaderChanged(KMFolder *folder, int msgId);
00241   void msgChanged();
00243   void folderCleared();
00245   void folderClosed();
00247   void msgAdded(int);
00249   void msgRemoved( int, QString );
00251   void nextMessage();
00253   void selectNextMessage();
00255   void prevMessage();
00257   void selectPrevMessage();
00260   bool nextUnreadMessage(bool acceptCurrent = false);
00263   bool prevUnreadMessage();
00265   void incCurrentMessage();
00267   void decCurrentMessage();
00269   void selectCurrentMessage();
00271   void slotNoDrag();
00273   void resetCurrentTime();
00274 
00276   void reset();
00277 
00280   void slotExpandOrCollapseThread( bool expand );
00283   void slotExpandOrCollapseAllThreads( bool expand );
00284 
00285   virtual void ensureCurrentItemVisible();
00286 
00289   virtual void setSelected(QListViewItem *item, bool selected);
00290 
00294   void setSelectedByIndex(QValueList<int> items, bool selected);
00295 
00298   void slotToggleColumn(int id, int mode = -1);
00299 
00301   void setFolderInfoStatus();
00302 
00303 protected:
00304   static QPixmap *pixNew, *pixUns, *pixDel, *pixRead, *pixRep, *pixSent,
00305     *pixQueued, *pixFwd, *pixFlag, *pixWatched, *pixIgnored, *pixSpam, *pixHam,
00306     *pixFullySigned, *pixPartiallySigned, *pixUndefinedSigned,
00307     *pixFullyEncrypted, *pixPartiallyEncrypted, *pixUndefinedEncrypted,
00308     *pixFiller, *pixEncryptionProblematic,
00309     *pixSignatureProblematic, *pixAttachment, *pixInvitation,
00310     *pixReadFwd, *pixReadReplied, *pixReadFwdReplied, *pixTodo;
00311 
00313   virtual bool event(QEvent *e);
00314 
00316   virtual void paintEmptyArea( QPainter * p, const QRect & rect );
00317 
00319   void makeHeaderVisible();
00320 
00322   void findUnreadAux( HeaderItem*&, bool &, bool, bool );
00323 
00328   virtual int firstSelectedMsg() const;
00329 
00331   virtual void readFolderConfig(void);
00332 
00334   virtual void writeFolderConfig(void);
00335 
00337   virtual void contentsMousePressEvent(QMouseEvent*);
00338   virtual void contentsMouseReleaseEvent(QMouseEvent* e);
00339   virtual void keyPressEvent( QKeyEvent * e );
00340 
00342   virtual void setSorting( int column, bool ascending = true);
00343 
00345   void contentsMouseMoveEvent( QMouseEvent *e );
00346 
00349   void styleChange( QStyle& oldStyle );
00350 
00353   void setStyleDependantFrameWidth();
00354 
00355 protected slots:
00358   virtual void moveSelectedToFolder( int menuId );
00360   virtual void copySelectedToFolder( int menuId );
00362   virtual int slotFilterMsg( KMMessage * );
00364   void dirtySortOrder(int);
00366   void rightButtonPressed( QListViewItem *, const QPoint &, int );
00367 
00368 private slots:
00369   void slotMoveCompleted( KMCommand * );
00370 
00371   void copyMessages();
00372   void cutMessages();
00373   void pasteMessages();
00374 
00375   void updateActions();
00376 
00377 private:
00380   virtual void updateMessageList( bool set_selection=false,
00381       bool forceJumpToUnread = false );
00382 
00384   QGuardedPtr<KMFolder> mFolder;
00386   KMMainWidget* mOwner;
00388   int mTopItem;
00390   int mCurrentItem;
00392   unsigned long mCurrentItemSerNum;
00394   QMemArray<HeaderItem*> mItems;
00395 
00396   // ===== threading and sorting ==========
00397   bool mNested, mNestedOverride, mSubjThreading;
00398   NestingPolicy nestingPolicy;
00399   int mSortCol;
00400   bool mSortDescending;
00401   bool mIgnoreSortOrderChanges;
00402 
00403   struct {
00404       uint ascending : 1;
00405       uint dirty : 1;
00406       short column;
00407       uint fakeSort : 1;
00408       uint removed : 1;
00409   } mSortInfo;
00410 
00411 
00413   QDict< SortCacheItem > mSortCacheItems;
00415   QDict< QPtrList< SortCacheItem > > mSubjectLists;
00417   QPtrList<HeaderItem> mImperfectlyThreadedList;
00418 
00420   void printSubjectThreadingTree( );
00421   void printThreadingTree( );
00423   void buildThreadingTree( QMemArray<SortCacheItem *> sortCache );
00425   void buildSubjectThreadingTree( QMemArray<SortCacheItem *> sortCache );
00427   SortCacheItem* findParent(SortCacheItem *item);
00429   SortCacheItem* findParentBySubject(SortCacheItem *item);
00430   SortCacheItem* mRoot; // used to represent the list view itself while threading
00431 
00433   void appendItemToSortFile(HeaderItem *);
00435   bool writeSortOrder();
00437   bool readSortOrder( bool set_selection = false,
00438       bool forceJumpToUnread = false );
00439 
00441   int getMsgIndex;
00443   bool getMsgMulti;
00445   HeaderItem* getMsgItem;
00447   KMMessageList mSelMsgBaseList;
00448   HeaderItem* mPrevCurrent;
00449 
00451   KPaintInfo mPaintInfo;
00452 
00453   QFont mNewFont, mUnreadFont, mImportantFont, mDateFont,mTodoFont;
00454 
00456   static QIconSet *up, *down;
00458   KMMenuToFolder mMenuToFolder;
00459 
00461   bool mMousePressed;
00463   QPoint mPressPos;
00464 
00465   KMime::DateFormatter mDate;
00466   bool mReaderWindowActive;
00467 
00469   KPopupMenu* mPopup;
00470 
00471   // copied messages
00472   QValueList<Q_UINT32> mCopiedMessages;
00473   bool mMoveMessages;
00474 }; // class
00475 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys