kmail

kmfolderindex.h
00001 /* -*- mode: C++; c-file-style: "gnu" -*-
00002     This file is part of KMail, the KDE mail client.
00003     Copyright (c) 2000 Don Sanders <sanders@kde.org>
00004 
00005     KMail is free software; you can redistribute it and/or modify it
00006     under the terms of the GNU General Public License, version 2, as
00007     published by the Free Software Foundation.
00008 
00009     KMail is distributed in the hope that it will be useful, but
00010     WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017 */
00018 // Virtual base class for mail folder with .*.index style index
00019 
00020 #ifndef kmfolderindex_h
00021 #define kmfolderindex_h
00022 
00023 #include "folderstorage.h"
00024 #include "kmmsglist.h"
00025 
00037 class KMFolderIndex: public FolderStorage
00038 {
00039   Q_OBJECT
00040   
00041   //TODO:Have to get rid of this friend declaration and add necessary pure
00042   //virtuals to kmfolder.h so that KMMsgBase::parent() can be a plain KMFolder
00043   //rather than a KMFolderIndex. Need this for database indices.
00044   friend class ::KMMsgBase;
00045 public:
00046 
00050   enum IndexStatus { IndexOk,
00051                      IndexMissing,
00052                      IndexCorrupt,
00053                      IndexTooOld
00054   };
00055 
00059   KMFolderIndex(KMFolder* folder, const char* name=0);
00060   virtual ~KMFolderIndex();
00061   virtual int count(bool cache = false) const;
00062 
00063   virtual KMMsgBase* takeIndexEntry( int idx ) { return mMsgList.take( idx ); }
00064   virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg );
00065   virtual void clearIndex(bool autoDelete=true, bool syncDict = false);
00066   virtual void truncateIndex();
00067 
00068   virtual const KMMsgBase* getMsgBase(int idx) const { return mMsgList[idx]; }
00069   virtual KMMsgBase* getMsgBase(int idx) { return mMsgList[idx]; }
00070 
00071   virtual int find(const KMMsgBase* msg) const { return mMsgList.find((KMMsgBase*)msg); }
00072   int find( const KMMessage * msg ) const { return FolderStorage::find( msg ); }
00073 
00075   int serialIndexId() const { return mIndexId; }
00076 
00077   uchar *indexStreamBasePtr() { return mIndexStreamPtr; }
00078 
00079   bool indexSwapByteOrder() { return mIndexSwapByteOrder; }
00080   int  indexSizeOfLong() { return mIndexSizeOfLong; }
00081 
00082   virtual TQString indexLocation() const;
00083   virtual int writeIndex( bool createEmptyIndex = false );
00084 
00085   void recreateIndex( bool readIndexAfterwards = true );
00086   void silentlyRecreateIndex();
00087 
00094   virtual IndexStatus indexStatus() = 0;
00095 
00096 public slots:
00098   virtual int updateIndex();
00099 
00100 protected:
00101   bool readIndex();
00102 
00104   bool readIndexHeader(int *gv=0);
00105 
00109   virtual int createIndexFromContents() = 0;
00110 
00111   bool updateIndexStreamPtr(bool just_close=FALSE);
00112 
00117   virtual void fillMessageDict();
00118 
00120   FILE* mIndexStream;
00122   KMMsgList mMsgList;
00123 
00125   off_t mHeaderOffset;
00126 
00127   uchar *mIndexStreamPtr;
00128   int mIndexStreamPtrLength, mIndexId;
00129   bool mIndexSwapByteOrder; // Index file was written with swapped byte order
00130   int mIndexSizeOfLong; // Index file was written with longs of this size
00131 
00132 private:
00133   void updateInvitationAndAddressFieldsFromContents();
00134 
00135 };
00136 
00137 #endif /*kmfolderindex_h*/