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   //TODO:Have to get rid of this friend declaration and add necessary pure
00041   //virtuals to kmfolder.h so that KMMsgBase::parent() can be a plain KMFolder
00042   //rather than a KMFolderIndex. Need this for database indices.
00043   friend class ::KMMsgBase;
00044 public:
00045 
00049   enum IndexStatus { IndexOk,
00050                      IndexMissing,
00051                      IndexCorrupt,
00052                      IndexTooOld
00053   };
00054 
00058   KMFolderIndex(KMFolder* folder, const char* name=0);
00059   virtual ~KMFolderIndex();
00060   virtual int count(bool cache = false) const;
00061 
00062   virtual KMMsgBase* takeIndexEntry( int idx ) { return mMsgList.take( idx ); }
00063   virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg );
00064   virtual void clearIndex(bool autoDelete=true, bool syncDict = false);
00065   virtual void truncateIndex();
00066 
00067   virtual const KMMsgBase* getMsgBase(int idx) const { return mMsgList[idx]; }
00068   virtual KMMsgBase* getMsgBase(int idx) { return mMsgList[idx]; }
00069 
00070   virtual int find(const KMMsgBase* msg) const { return mMsgList.find((KMMsgBase*)msg); }
00071   int find( const KMMessage * msg ) const { return FolderStorage::find( msg ); }
00072 
00074   int serialIndexId() const { return mIndexId; }
00075 
00076   uchar *indexStreamBasePtr() { return mIndexStreamPtr; }
00077 
00078   bool indexSwapByteOrder() { return mIndexSwapByteOrder; }
00079   int  indexSizeOfLong() { return mIndexSizeOfLong; }
00080 
00081   virtual QString indexLocation() const;
00082   virtual int writeIndex( bool createEmptyIndex = false );
00083 
00084   void recreateIndex( bool readIndexAfterwards = true );
00085   void silentlyRecreateIndex();
00086 
00093   virtual IndexStatus indexStatus() = 0;
00094 
00095 public slots:
00097   virtual int updateIndex();
00098 
00099 protected:
00100   bool readIndex();
00101 
00103   bool readIndexHeader(int *gv=0);
00104 
00108   virtual int createIndexFromContents() = 0;
00109 
00110   bool updateIndexStreamPtr(bool just_close=FALSE);
00111 
00116   virtual void fillMessageDict();
00117 
00119   FILE* mIndexStream;
00121   KMMsgList mMsgList;
00122 
00124   off_t mHeaderOffset;
00125 
00126   uchar *mIndexStreamPtr;
00127   int mIndexStreamPtrLength, mIndexId;
00128   bool mIndexSwapByteOrder; // Index file was written with swapped byte order
00129   int mIndexSizeOfLong; // Index file was written with longs of this size
00130 
00131 private:
00132   void updateInvitationAndAddressFieldsFromContents();
00133 
00134 };
00135 
00136 #endif /*kmfolderindex_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys