File indexing completed on 2024-12-22 04:57:32
0001 /* 0002 SPDX-FileCopyrightText: 2012 Andras Mantia <amantia@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #pragma once 0008 0009 /** @brief a cache for the maildir keys (file names in cur/new folders). 0010 * It is used to find if a file is in cur or new 0011 */ 0012 0013 #include <QHash> 0014 #include <QSet> 0015 0016 class KeyCache 0017 { 0018 public: 0019 static KeyCache *self() 0020 { 0021 if (!mSelf) { 0022 mSelf = new KeyCache(); 0023 } 0024 return mSelf; 0025 } 0026 0027 /** Find the new and cur keys on the disk for @param dir and add them to the cache */ 0028 void addKeys(const QString &dir); 0029 0030 /** Refresh the new and cur keys for @param dir */ 0031 void refreshKeys(const QString &dir); 0032 0033 /** Add a "new" key for @param dir. */ 0034 void addNewKey(const QString &dir, const QString &key); 0035 0036 /** Add a "cur" key for @param dir. */ 0037 void addCurKey(const QString &dir, const QString &key); 0038 0039 /** Remove all keys associated with @param dir. */ 0040 void removeKey(const QString &dir, const QString &key); 0041 0042 /** Check if the @param key is a "cur" key in @param dir */ 0043 bool isCurKey(const QString &dir, const QString &key) const; 0044 0045 /** Check if the @param key is a "new" key in @param dir */ 0046 bool isNewKey(const QString &dir, const QString &key) const; 0047 0048 private: 0049 KeyCache() = default; 0050 0051 QSet<QString> listNew(const QString &dir) const; 0052 0053 QSet<QString> listCurrent(const QString &dir) const; 0054 0055 QHash<QString, QSet<QString>> mNewKeys; 0056 QHash<QString, QSet<QString>> mCurKeys; 0057 0058 static KeyCache *mSelf; 0059 };