diff options
Diffstat (limited to 'examples/maildirresource/libmaildir/keycache.h')
-rw-r--r-- | examples/maildirresource/libmaildir/keycache.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/examples/maildirresource/libmaildir/keycache.h b/examples/maildirresource/libmaildir/keycache.h new file mode 100644 index 0000000..3cce6f0 --- /dev/null +++ b/examples/maildirresource/libmaildir/keycache.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | Copyright (C) 2012 Andras Mantia <amantia@kde.org> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2.1 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General Public | ||
15 | License along with this library; if not, write to the Free Software | ||
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
17 | */ | ||
18 | |||
19 | |||
20 | #ifndef KEYCACHE_H | ||
21 | #define KEYCACHE_H | ||
22 | |||
23 | /** @brief a cache for the maildir keys (file names in cur/new folders). | ||
24 | * It is used to find if a file is in cur or new | ||
25 | */ | ||
26 | |||
27 | #include <QSet> | ||
28 | #include <QHash> | ||
29 | |||
30 | class KeyCache { | ||
31 | |||
32 | public: | ||
33 | static KeyCache *self() | ||
34 | { | ||
35 | if ( !mSelf ) | ||
36 | mSelf = new KeyCache(); | ||
37 | return mSelf; | ||
38 | } | ||
39 | |||
40 | /** Find the new and cur keys on the disk for @param dir and add them to the cache */ | ||
41 | void addKeys( const QString& dir ); | ||
42 | |||
43 | /** Refresh the new and cur keys for @param dir */ | ||
44 | void refreshKeys( const QString& dir ); | ||
45 | |||
46 | /** Add a "new" key for @param dir. */ | ||
47 | void addNewKey( const QString& dir, const QString& key ); | ||
48 | |||
49 | /** Add a "cur" key for @param dir. */ | ||
50 | void addCurKey( const QString& dir, const QString& key ); | ||
51 | |||
52 | /** Remove all keys associated with @param dir. */ | ||
53 | void removeKey( const QString& dir, const QString& key ); | ||
54 | |||
55 | /** Check if the @param key is a "cur" key in @param dir */ | ||
56 | bool isCurKey( const QString& dir, const QString& key ) const; | ||
57 | |||
58 | /** Check if the @param key is a "new" key in @param dir */ | ||
59 | bool isNewKey( const QString& dir, const QString& key ) const; | ||
60 | |||
61 | private: | ||
62 | KeyCache() { | ||
63 | } | ||
64 | |||
65 | QSet<QString> listNew( const QString& dir ) const; | ||
66 | |||
67 | QSet<QString> listCurrent( const QString& dir ) const; | ||
68 | |||
69 | QHash< QString, QSet<QString> > mNewKeys; | ||
70 | QHash< QString, QSet<QString> > mCurKeys; | ||
71 | |||
72 | static KeyCache* mSelf; | ||
73 | |||
74 | }; | ||
75 | |||
76 | |||
77 | #endif // KEYCACHE_H | ||