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 #include "keycache.h" 0021 0022 #include <QDir> 0023 0024 KeyCache* KeyCache::mSelf = 0; 0025 0026 void KeyCache::addKeys( const QString& dir ) 0027 { 0028 if ( !mNewKeys.contains( dir ) ) { 0029 mNewKeys.insert( dir, listNew( dir ) ); 0030 //kDebug() << "Added new keys for: " << dir; 0031 } 0032 0033 if ( !mCurKeys.contains( dir ) ) { 0034 mCurKeys.insert( dir, listCurrent( dir ) ); 0035 //kDebug() << "Added cur keys for: " << dir; 0036 } 0037 } 0038 0039 void KeyCache::refreshKeys( const QString& dir ) 0040 { 0041 mNewKeys.remove( dir ); 0042 mCurKeys.remove( dir ); 0043 addKeys( dir ); 0044 } 0045 0046 void KeyCache::addNewKey( const QString& dir, const QString& key ) 0047 { 0048 mNewKeys[dir].insert( key ); 0049 // kDebug() << "Added new key for : " << dir << " key: " << key; 0050 } 0051 0052 void KeyCache::addCurKey( const QString& dir, const QString& key ) 0053 { 0054 mCurKeys[dir].insert( key ); 0055 // kDebug() << "Added cur key for : " << dir << " key:" << key; 0056 } 0057 0058 void KeyCache::removeKey( const QString& dir, const QString& key ) 0059 { 0060 //kDebug() << "Removed new and cur key for: " << dir << " key:" << key; 0061 mNewKeys[dir].remove( key ); 0062 mCurKeys[dir].remove( key ); 0063 } 0064 0065 bool KeyCache::isCurKey( const QString& dir, const QString& key ) const 0066 { 0067 return mCurKeys.value( dir ).contains( key ); 0068 } 0069 0070 bool KeyCache::isNewKey( const QString& dir, const QString& key ) const 0071 { 0072 return mNewKeys.value( dir ).contains( key ); 0073 } 0074 0075 QSet< QString > KeyCache::listNew( const QString& dir ) const 0076 { 0077 QDir d( dir + QString::fromLatin1( "/new" ) ); 0078 d.setSorting(QDir::NoSort); 0079 return d.entryList( QDir::Files ).toSet(); 0080 } 0081 0082 QSet< QString > KeyCache::listCurrent( const QString& dir ) const 0083 { 0084 QDir d( dir + QString::fromLatin1( "/cur" ) ); 0085 d.setSorting(QDir::NoSort); 0086 return d.entryList( QDir::Files ).toSet(); 0087 } 0088