kmail

kmfolderindex.h
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2  This file is part of KMail, the KDE mail client.
3  Copyright (c) 2000 Don Sanders <sanders@kde.org>
4 
5  KMail is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License, version 2, as
7  published by the Free Software Foundation.
8 
9  KMail is distributed in the hope that it will be useful, but
10  WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 // Virtual base class for mail folder with .*.index style index
19 
20 #ifndef kmfolderindex_h
21 #define kmfolderindex_h
22 
23 #include "folderstorage.h"
24 #include "kmmsglist.h"
25 
38 {
39  Q_OBJECT
40  TQ_OBJECT
41  //TODO:Have to get rid of this friend declaration and add necessary pure
42  //virtuals to kmfolder.h so that KMMsgBase::parent() can be a plain KMFolder
43  //rather than a KMFolderIndex. Need this for database indices.
44  friend class ::KMMsgBase;
45 public:
46 
50  enum IndexStatus { IndexOk,
51  IndexMissing,
52  IndexCorrupt,
53  IndexTooOld
54  };
55 
59  KMFolderIndex(KMFolder* folder, const char* name=0);
60  virtual ~KMFolderIndex();
61  virtual int count(bool cache = false) const;
62 
63  virtual KMMsgBase* takeIndexEntry( int idx ) { return mMsgList.take( idx ); }
64  virtual KMMsgInfo* setIndexEntry( int idx, KMMessage *msg );
65  virtual void clearIndex(bool autoDelete=true, bool syncDict = false);
66  virtual void truncateIndex();
67 
68  virtual const KMMsgBase* getMsgBase(int idx) const { return mMsgList[idx]; }
69  virtual KMMsgBase* getMsgBase(int idx) { return mMsgList[idx]; }
70 
71  virtual int find(const KMMsgBase* msg) const { return mMsgList.find((KMMsgBase*)msg); }
72  int find( const KMMessage * msg ) const { return FolderStorage::find( msg ); }
73 
75  int serialIndexId() const { return mIndexId; }
76 
77  uchar *indexStreamBasePtr() { return mIndexStreamPtr; }
78 
79  bool indexSwapByteOrder() { return mIndexSwapByteOrder; }
80  int indexSizeOfLong() { return mIndexSizeOfLong; }
81 
82  virtual TQString indexLocation() const;
83  virtual int writeIndex( bool createEmptyIndex = false );
84 
85  void recreateIndex( bool readIndexAfterwards = true );
86  void silentlyRecreateIndex();
87 
94  virtual IndexStatus indexStatus() = 0;
95 
96 public slots:
98  virtual int updateIndex();
99 
100 protected:
101  bool readIndex();
102 
104  bool readIndexHeader(int *gv=0);
105 
109  virtual int createIndexFromContents() = 0;
110 
111  bool updateIndexStreamPtr(bool just_close=FALSE);
112 
117  virtual void fillMessageDict();
118 
123 
126 
127  uchar *mIndexStreamPtr;
128  int mIndexStreamPtrLength, mIndexId;
129  bool mIndexSwapByteOrder; // Index file was written with swapped byte order
130  int mIndexSizeOfLong; // Index file was written with longs of this size
131 
132 private:
133  void updateInvitationAndAddressFieldsFromContents();
134 
135 };
136 
137 #endif /*kmfolderindex_h*/