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 <tdelistview.h>
00012 #include <kfoldertree.h> // for KPaintInfo
00013 #include <kmmsgbase.h>   // for KMMsgStatus
00014 
00015 #include <tqwidget.h>
00016 #include <tqstrlist.h>
00017 #include <tqmemarray.h>
00018 #include <tqmap.h>
00019 #include <tqdragobject.h>
00020 #include <tqdict.h>
00021 #include <tqguardedptr.h>
00022 
00023 class KMFolder;
00024 class KMMessage;
00025 class KMMsgBase;
00026 class KMCommand;
00027 class KMMainWidget;
00028 class TDEPopupMenu;
00029 class TQPalette;
00030 class TQPixmap;
00031 class TQIconSet;
00032 class TQDateTime;
00033 
00034 typedef TQPtrList<KMMsgBase> KMMessageList;
00035 typedef TQValueList<TQ_UINT32> SerNumList;
00036 typedef TQMap<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 TDEListView
00049 {
00050   Q_OBJECT
00051   
00052 
00053   friend class ::KMail::HeaderItem; // For easy access to the pixmaps
00054 
00055 public:
00056   KMHeaders(KMMainWidget *owner, TQWidget *parent=0, const char *name=0);
00057   virtual ~KMHeaders();
00058 
00063   virtual void setFolder(KMFolder *, bool forceJumpToUnread = false);
00064 
00066   KMFolder* folder(void) { return mFolder; }
00067 
00069   void refreshNestedState(void);
00070 
00073   virtual void setCurrentMsg(int msgId);
00074 
00076   TQPtrList<TQListViewItem> currentThread() const;
00077 
00080   virtual void setThreadStatus(KMMsgStatus status, bool toggle=false);
00081 
00082   /* Set message status to read if it is new, or unread */
00083   virtual void setMsgRead(int msgId);
00084 
00086   virtual void setMsgStatus(KMMsgStatus status, bool toggle=false);
00087   virtual void deleteMsg();
00088   virtual void applyFiltersOnMsg();
00089   virtual void undo();
00090   virtual bool canUndo() const;
00091   virtual HeaderItem * prepareMove( int *contentX, int *contentY );
00092   virtual void finalizeMove( HeaderItem *item, int contentX, int contentY );
00093 
00097   virtual void moveMsgToFolder( KMFolder* destination,
00098                                 bool askForConfirmation=true );
00099 
00102   virtual void copyMsgToFolder(KMFolder* destination,
00103                                KMMessage* aMsg = 0);
00104 
00106   virtual void clearSelectableAndAboutToBeDeleted(TQ_UINT32 serNum);
00109   virtual KMMessageList* selectedMsgs(bool toBeDeleted = false);
00110 
00112   TQValueList<int> selectedItems();
00113 
00115   TQValueList<TQ_UINT32> selectedSernums();
00116 
00120   TQValueList<TQ_UINT32> selectedVisibleSernums();
00121 
00123   int indexOfGetMsg (void) const { return getMsgIndex; }
00124 
00126   KMMainWidget* owner(void) const { return mOwner; }
00127 
00129   const KPaintInfo *paintInfo(void) const { return &mPaintInfo; }
00130 
00132   virtual void readConfig(void);
00133 
00135   virtual void readColorConfig(void);
00136 
00144   void restoreColumnLayout( TDEConfig *config, const TQString &group );
00145 
00147   virtual KMMessage* currentMsg();
00149   virtual HeaderItem* currentHeaderItem();
00151   virtual int currentItemIndex();
00153   virtual void setCurrentItemByIndex( int msgIdx );
00155   void setCurrentItemBySerialNum( unsigned long serialNum );
00157   virtual int topItemIndex();
00160   virtual void setTopItemByIndex( int aMsgIdx );
00161   virtual void setNestedOverride( bool override );
00162   virtual void setSubjectThreading( bool subjThreading );
00164   virtual void setOpen ( TQListViewItem *, bool );
00165 
00166   NestingPolicy getNestingPolicy() const { return nestingPolicy; }
00168   bool isThreaded() const {
00169     return mNested != mNestedOverride; // xor
00170   }
00171 
00174   virtual int findUnread(bool findNext, int startAt=-1, bool onlyNew = false, bool acceptCurrent = false);
00175 
00176   void highlightMessage(TQListViewItem*, bool markitread);
00177   void highlightCurrentThread();
00178 
00180   static TQString fancyDate( time_t otime );
00181 
00182   bool noRepaint;
00183 
00184   // filter events for popup
00185   bool eventFilter ( TQObject *o, TQEvent *e );
00186 
00188   const KMMsgBase * getMsgBaseForItem( const TQListViewItem *item ) const;
00189 
00190   // accessors
00191   TQFont newFont() const { return mNewFont; }
00192   TQFont unreadFont() const { return mUnreadFont; }
00193   TQFont importantFont() const { return mImportantFont; }
00194   TQFont todoFont() const { return mTodoFont; }
00195   TQFont dateFont() const { return mDateFont; }
00196 
00202   void setCopiedMessages( const TQValueList<TQ_UINT32> &msgs, bool move );
00203 
00208   bool isMessageCut( TQ_UINT32 serNum ) const;
00209 
00211   virtual void writeConfig(void);
00212 
00213 signals:
00216   void selected(KMMessage *);
00219   void activated(KMMessage *);
00221   void maybeDeleting();
00223   void messageListUpdated();
00224 
00230   void msgAddedToListView( TQListViewItem* );
00231 
00232 public slots:
00234   void selectMessage(TQListViewItem*);
00236   void highlightMessage(TQListViewItem*);
00238   void slotRMB();
00240   void msgHeaderChanged(KMFolder *folder, int msgId);
00242   void msgChanged();
00244   void folderCleared();
00246   void folderClosed();
00248   void msgAdded(int);
00250   void msgRemoved( int, TQString );
00252   void nextMessage();
00254   void selectNextMessage();
00256   void prevMessage();
00258   void selectPrevMessage();
00261   bool nextUnreadMessage(bool acceptCurrent = false);
00264   bool prevUnreadMessage();
00266   void incCurrentMessage();
00268   void decCurrentMessage();
00270   void selectCurrentMessage();
00272   void slotNoDrag();
00274   void resetCurrentTime();
00275 
00277   void reset();
00278 
00281   void slotExpandOrCollapseThread( bool expand );
00284   void slotExpandOrCollapseAllThreads( bool expand );
00285 
00286   virtual void ensureCurrentItemVisible();
00287 
00290   virtual void setSelected(TQListViewItem *item, bool selected);
00291 
00295   void setSelectedByIndex(TQValueList<int> items, bool selected);
00296 
00299   void slotToggleColumn(int id, int mode = -1);
00300 
00302   void setFolderInfoStatus();
00303 
00304 protected:
00305   static TQPixmap *pixNew, *pixUns, *pixDel, *pixRead, *pixRep, *pixSent,
00306     *pixQueued, *pixFwd, *pixFlag, *pixWatched, *pixIgnored, *pixSpam, *pixHam,
00307     *pixFullySigned, *pixPartiallySigned, *pixUndefinedSigned,
00308     *pixFullyEncrypted, *pixPartiallyEncrypted, *pixUndefinedEncrypted,
00309     *pixFiller, *pixEncryptionProblematic,
00310     *pixSignatureProblematic, *pixAttachment, *pixInvitation,
00311     *pixReadFwd, *pixReadReplied, *pixReadFwdReplied, *pixTodo;
00312 
00314   virtual bool event(TQEvent *e);
00315 
00317   virtual void paintEmptyArea( TQPainter * p, const TQRect & rect );
00318 
00320   void makeHeaderVisible();
00321 
00323   void findUnreadAux( HeaderItem*&, bool &, bool, bool );
00324 
00329   virtual int firstSelectedMsg() const;
00330 
00332   virtual void readFolderConfig(void);
00333 
00335   virtual void writeFolderConfig(void);
00336 
00338   virtual void contentsMousePressEvent(TQMouseEvent*);
00339   virtual void contentsMouseReleaseEvent(TQMouseEvent* e);
00340   virtual void keyPressEvent( TQKeyEvent * e );
00341 
00343   virtual void setSorting( int column, bool ascending = true);
00344 
00346   void contentsMouseMoveEvent( TQMouseEvent *e );
00347 
00350   void styleChange( TQStyle& oldStyle );
00351 
00354   void setStyleDependantFrameWidth();
00355 
00356 protected slots:
00359   virtual void moveSelectedToFolder( int menuId );
00361   virtual void copySelectedToFolder( int menuId );
00363   virtual int slotFilterMsg( KMMessage * );
00365   void dirtySortOrder(int);
00367   void rightButtonPressed( TQListViewItem *, const TQPoint &, int );
00368 
00369 private slots:
00370   void slotMoveCompleted( KMCommand * );
00371 
00372   void copyMessages();
00373   void cutMessages();
00374   void pasteMessages();
00375 
00376   void updateActions();
00377 
00378 private:
00381   virtual void updateMessageList( bool set_selection=false,
00382       bool forceJumpToUnread = false );
00383 
00385   TQGuardedPtr<KMFolder> mFolder;
00387   KMMainWidget* mOwner;
00389   int mTopItem;
00391   int mCurrentItem;
00393   unsigned long mCurrentItemSerNum;
00395   TQMemArray<HeaderItem*> mItems;
00396 
00397   // ===== threading and sorting ==========
00398   bool mNested, mNestedOverride, mSubjThreading;
00399   NestingPolicy nestingPolicy;
00400   int mSortCol;
00401   bool mSortDescending;
00402   bool mIgnoreSortOrderChanges;
00403 
00404   struct {
00405       uint ascending : 1;
00406       uint dirty : 1;
00407       short column;
00408       uint fakeSort : 1;
00409       uint removed : 1;
00410   } mSortInfo;
00411 
00412 
00414   TQDict< SortCacheItem > mSortCacheItems;
00416   TQDict< TQPtrList< SortCacheItem > > mSubjectLists;
00418   TQPtrList<HeaderItem> mImperfectlyThreadedList;
00419 
00421   void printSubjectThreadingTree( );
00422   void printThreadingTree( );
00424   void buildThreadingTree( TQMemArray<SortCacheItem *> sortCache );
00426   void buildSubjectThreadingTree( TQMemArray<SortCacheItem *> sortCache );
00428   SortCacheItem* findParent(SortCacheItem *item);
00430   SortCacheItem* findParentBySubject(SortCacheItem *item);
00431   SortCacheItem* mRoot; // used to represent the list view itself while threading
00432 
00434   void appendItemToSortFile(HeaderItem *);
00436   bool writeSortOrder();
00438   bool readSortOrder( bool set_selection = false,
00439       bool forceJumpToUnread = false );
00440 
00442   int getMsgIndex;
00444   bool getMsgMulti;
00446   HeaderItem* getMsgItem;
00448   KMMessageList mSelMsgBaseList;
00449   HeaderItem* mPrevCurrent;
00450 
00452   KPaintInfo mPaintInfo;
00453 
00454   TQFont mNewFont, mUnreadFont, mImportantFont, mDateFont,mTodoFont;
00455 
00457   static TQIconSet *up, *down;
00459   KMMenuToFolder mMenuToFolder;
00460 
00462   bool mMousePressed;
00464   TQPoint mPressPos;
00465 
00466   KMime::DateFormatter mDate;
00467   bool mReaderWindowActive;
00468 
00470   TDEPopupMenu* mPopup;
00471 
00472   // copied messages
00473   TQValueList<TQ_UINT32> mCopiedMessages;
00474   bool mMoveMessages;
00475 }; // class
00476 #endif