File indexing completed on 2024-06-23 05:20:25
0001 /* 0002 Copyright (C) 2012 Andras Mantia <amantia@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Lesser General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Lesser General Public License for more details. 0013 0014 You should have received a copy of the GNU Lesser General Public 0015 License along with this library; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0017 */ 0018 0019 0020 #ifndef KEYCACHE_H 0021 #define KEYCACHE_H 0022 0023 /** @brief a cache for the maildir keys (file names in cur/new folders). 0024 * It is used to find if a file is in cur or new 0025 */ 0026 0027 #include <QSet> 0028 #include <QHash> 0029 0030 class KeyCache { 0031 0032 public: 0033 static KeyCache *self() 0034 { 0035 if ( !mSelf ) 0036 mSelf = new KeyCache(); 0037 return mSelf; 0038 } 0039 0040 /** Find the new and cur keys on the disk for @param dir and add them to the cache */ 0041 void addKeys( const QString& dir ); 0042 0043 /** Refresh the new and cur keys for @param dir */ 0044 void refreshKeys( const QString& dir ); 0045 0046 /** Add a "new" key for @param dir. */ 0047 void addNewKey( const QString& dir, const QString& key ); 0048 0049 /** Add a "cur" key for @param dir. */ 0050 void addCurKey( const QString& dir, const QString& key ); 0051 0052 /** Remove all keys associated with @param dir. */ 0053 void removeKey( const QString& dir, const QString& key ); 0054 0055 /** Check if the @param key is a "cur" key in @param dir */ 0056 bool isCurKey( const QString& dir, const QString& key ) const; 0057 0058 /** Check if the @param key is a "new" key in @param dir */ 0059 bool isNewKey( const QString& dir, const QString& key ) const; 0060 0061 private: 0062 KeyCache() { 0063 } 0064 0065 QSet<QString> listNew( const QString& dir ) const; 0066 0067 QSet<QString> listCurrent( const QString& dir ) const; 0068 0069 QHash< QString, QSet<QString> > mNewKeys; 0070 QHash< QString, QSet<QString> > mCurKeys; 0071 0072 static KeyCache* mSelf; 0073 0074 }; 0075 0076 0077 #endif // KEYCACHE_H