summaryrefslogtreecommitdiffstats
path: root/examples/maildirresource/libmaildir/keycache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/maildirresource/libmaildir/keycache.cpp')
-rw-r--r--examples/maildirresource/libmaildir/keycache.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/examples/maildirresource/libmaildir/keycache.cpp b/examples/maildirresource/libmaildir/keycache.cpp
new file mode 100644
index 0000000..814ce6c
--- /dev/null
+++ b/examples/maildirresource/libmaildir/keycache.cpp
@@ -0,0 +1,88 @@
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#include "keycache.h"
21
22#include <QDir>
23
24KeyCache* KeyCache::mSelf = 0;
25
26void KeyCache::addKeys( const QString& dir )
27{
28 if ( !mNewKeys.contains( dir ) ) {
29 mNewKeys.insert( dir, listNew( dir ) );
30 //kDebug() << "Added new keys for: " << dir;
31 }
32
33 if ( !mCurKeys.contains( dir ) ) {
34 mCurKeys.insert( dir, listCurrent( dir ) );
35 //kDebug() << "Added cur keys for: " << dir;
36 }
37}
38
39void KeyCache::refreshKeys( const QString& dir )
40{
41 mNewKeys.remove( dir );
42 mCurKeys.remove( dir );
43 addKeys( dir );
44}
45
46void KeyCache::addNewKey( const QString& dir, const QString& key )
47{
48 mNewKeys[dir].insert( key );
49 // kDebug() << "Added new key for : " << dir << " key: " << key;
50}
51
52void KeyCache::addCurKey( const QString& dir, const QString& key )
53{
54 mCurKeys[dir].insert( key );
55 // kDebug() << "Added cur key for : " << dir << " key:" << key;
56}
57
58void KeyCache::removeKey( const QString& dir, const QString& key )
59{
60 //kDebug() << "Removed new and cur key for: " << dir << " key:" << key;
61 mNewKeys[dir].remove( key );
62 mCurKeys[dir].remove( key );
63}
64
65bool KeyCache::isCurKey( const QString& dir, const QString& key ) const
66{
67 return mCurKeys.value( dir ).contains( key );
68}
69
70bool KeyCache::isNewKey( const QString& dir, const QString& key ) const
71{
72 return mNewKeys.value( dir ).contains( key );
73}
74
75QSet< QString > KeyCache::listNew( const QString& dir ) const
76{
77 QDir d( dir + QString::fromLatin1( "/new" ) );
78 d.setSorting(QDir::NoSort);
79 return d.entryList( QDir::Files ).toSet();
80}
81
82QSet< QString > KeyCache::listCurrent( const QString& dir ) const
83{
84 QDir d( dir + QString::fromLatin1( "/cur" ) );
85 d.setSorting(QDir::NoSort);
86 return d.entryList( QDir::Files ).toSet();
87}
88