kmail

kmmsgdict.h

00001 /*
00002  * This file is part of KMail, the KDE mail client
00003  * Copyright (c)  Ronen Tzur <rtzur@shani.net>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  */
00020 #ifndef __KMMSGDICT
00021 #define __KMMSGDICT
00022 
00023 class KMFolder;
00024 class KMMsgBase;
00025 class KMMessage;
00026 class KMMsgDictEntry;
00027 class KMMsgDictREntry;
00028 class KMDict;
00029 class QString;
00030 class FolderStorage;
00031 
00049 class KMMsgDict
00050 {
00051   template<class> friend class KStaticDeleter;
00052   public:
00054     static const KMMsgDict* instance();
00055 
00058     void getLocation( unsigned long key, KMFolder **retFolder, int *retIndex ) const;
00061     void getLocation( const KMMsgBase *msg, KMFolder **retFolder, int *retIndex ) const;
00064     void getLocation( const KMMessage *msg, KMFolder **retFolder, int *retIndex ) const;
00065 
00069     unsigned long getMsgSerNum( KMFolder *folder, int index ) const;
00070 
00071 private:
00072  /* FIXME It would be better to do without these, they are the classes
00073   * involved in filling and maintaining the dict. The MsgList needs access
00074   * because of things it does that should be in FolderIndex, probably, which
00075   * the message list is an implementation detail of. */
00076   friend class FolderStorage;
00077   friend class KMMsgList;
00078   friend class KMFolderIndex;
00079 
00080   // Access for those altering the dict, our friend classes
00081   static KMMsgDict* mutableInstance();
00082 
00086   unsigned long insert(unsigned long msgSerNum, const KMMsgBase *msg, int index = -1);
00087 
00091   unsigned long insert(const KMMsgBase *msg, int index = -1);
00092 
00094   void replace(unsigned long msgSerNum,
00095                const KMMsgBase *msg, int index = -1);
00096 
00098   void remove(unsigned long msgSerNum);
00099 
00101   unsigned long remove(const KMMsgBase *msg);
00102 
00104   void update(const KMMsgBase *msg, int index, int newIndex);
00105 
00106 
00107   // ----- per folder serial number on-disk structure handling ("ids files")
00108   
00110   static QString getFolderIdsLocation( const FolderStorage &folder );
00111 
00113   bool isFolderIdsOutdated( const FolderStorage &folder );
00114 
00116   int readFolderIds( FolderStorage & );
00117 
00119   int writeFolderIds( const FolderStorage & );
00120 
00122   int touchFolderIds( const FolderStorage & );
00123 
00126   int appendToFolderIds( FolderStorage&, int index );
00127 
00129   bool hasFolderIds( const FolderStorage & );
00130 
00132   bool removeFolderIds( FolderStorage & );
00133 
00136   KMMsgDictREntry *openFolderIds( const FolderStorage &, bool truncate);
00137 
00138 
00139   // --------- helpers ------------
00140 
00143   static void deleteRentry(KMMsgDictREntry *entry);
00144 
00146   unsigned long getNextMsgSerNum();
00147 
00148   // prevent creation and deletion, we are a singleton
00149   KMMsgDict();
00150   ~KMMsgDict();
00151 
00153   unsigned long nextMsgSerNum;
00154 
00156   KMDict *dict;
00157 
00159   static KMMsgDict *m_self;
00160 };
00161 
00162 #endif /* __KMMSGDICT */
KDE Home | KDE Accessibility Home | Description of Access Keys