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                      IndexTooOld
00052   };
00053 
00057   KMFolderIndex(KMFolder* folder, const char* name=0);
00058   virtual ~KMFolderIndex();
00059   virtual int count(bool cache = false) const;
00060 
00061   virtual KMMsgBase* takeIndexEntry( int idx ) { return mMsgList.take( idx ); }
00062   virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg );
00063   virtual void clearIndex(bool autoDelete=true, bool syncDict = false);
00064   virtual void truncateIndex();
00065 
00066   virtual const KMMsgBase* getMsgBase(int idx) const { return mMsgList[idx]; }
00067   virtual KMMsgBase* getMsgBase(int idx) { return mMsgList[idx]; }
00068 
00069   virtual int find(const KMMsgBase* msg) const { return mMsgList.find((KMMsgBase*)msg); }
00070   int find( const KMMessage * msg ) const { return FolderStorage::find( msg ); }
00071 
00073   int serialIndexId() const { return mIndexId; }
00074 
00075   uchar *indexStreamBasePtr() { return mIndexStreamPtr; }
00076 
00077   bool indexSwapByteOrder() { return mIndexSwapByteOrder; }
00078   int  indexSizeOfLong() { return mIndexSizeOfLong; }
00079 
00080   virtual QString indexLocation() const;
00081   virtual int writeIndex( bool createEmptyIndex = false );
00082 
00083 public slots:
00085   virtual int updateIndex();
00086 
00087 protected:
00088   bool readIndex();
00089 
00091   bool readIndexHeader(int *gv=0);
00092 
00096   virtual int createIndexFromContents() = 0;
00097 
00098   bool updateIndexStreamPtr(bool just_close=FALSE);
00099 
00106   virtual IndexStatus indexStatus() = 0;
00107 
00112   virtual void fillMessageDict();
00113 
00115   FILE* mIndexStream;
00117   KMMsgList mMsgList;
00118 
00120   off_t mHeaderOffset;
00121 
00122   uchar *mIndexStreamPtr;
00123   int mIndexStreamPtrLength, mIndexId;
00124   bool mIndexSwapByteOrder; // Index file was written with swapped byte order
00125   int mIndexSizeOfLong; // Index file was written with longs of this size
00126 };
00127 
00128 #endif /*kmfolderindex_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys