From 1710fab0965d32b883dfcc327c36d3fd38a91357 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 15 Dec 2015 17:05:20 +0100 Subject: A read-only maildir resource. Respectively a first prototype thereof. --- examples/maildirresource/libmaildir/keycache.h | 77 ++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 examples/maildirresource/libmaildir/keycache.h (limited to 'examples/maildirresource/libmaildir/keycache.h') 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 @@ +/* + Copyright (C) 2012 Andras Mantia + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +#ifndef KEYCACHE_H +#define KEYCACHE_H + +/** @brief a cache for the maildir keys (file names in cur/new folders). + * It is used to find if a file is in cur or new + */ + +#include +#include + +class KeyCache { + +public: + static KeyCache *self() + { + if ( !mSelf ) + mSelf = new KeyCache(); + return mSelf; + } + + /** Find the new and cur keys on the disk for @param dir and add them to the cache */ + void addKeys( const QString& dir ); + + /** Refresh the new and cur keys for @param dir */ + void refreshKeys( const QString& dir ); + + /** Add a "new" key for @param dir. */ + void addNewKey( const QString& dir, const QString& key ); + + /** Add a "cur" key for @param dir. */ + void addCurKey( const QString& dir, const QString& key ); + + /** Remove all keys associated with @param dir. */ + void removeKey( const QString& dir, const QString& key ); + + /** Check if the @param key is a "cur" key in @param dir */ + bool isCurKey( const QString& dir, const QString& key ) const; + + /** Check if the @param key is a "new" key in @param dir */ + bool isNewKey( const QString& dir, const QString& key ) const; + +private: + KeyCache() { + } + + QSet listNew( const QString& dir ) const; + + QSet listCurrent( const QString& dir ) const; + + QHash< QString, QSet > mNewKeys; + QHash< QString, QSet > mCurKeys; + + static KeyCache* mSelf; + +}; + + +#endif // KEYCACHE_H -- cgit v1.2.3