File indexing completed on 2024-05-05 16:38:59
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003,2009 Carsten Pfeiffer <pfeiffer@kde.org> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, version 2. 0007 0008 This program is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 General Public License for more details. 0012 0013 You should have received a copy of the GNU General Public License 0014 along with this program; see the file COPYING. If not, write to 0015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0016 Boston, MA 02110-1301, USA. 0017 */ 0018 #ifndef FILECACHE_H 0019 #define FILECACHE_H 0020 0021 #include <QCache> 0022 0023 class QString; 0024 class QTemporaryDir; 0025 class QTemporaryFile; 0026 class QUrl; 0027 class KuickFile; 0028 0029 0030 class FileCache 0031 { 0032 public: 0033 static FileCache * self(); 0034 static void shutdown(); 0035 0036 KuickFile * getFile( const QUrl& url ); 0037 void setLimit( int numFiles ); 0038 int getLimit() const { return m_limit; } 0039 0040 /** 0041 * @return the temporary directory or QString() if none available 0042 */ 0043 QString tempDir(); 0044 0045 /** 0046 * Creates a new QTemporaryFile in this cache's temp dir and returns it unopened. 0047 * It is the responsibility of the caller to delete the object when it is no longer needed. 0048 * @return the QTemporaryFile object, or nullptr on error 0049 */ 0050 QTemporaryFile* createTempFile(const QString& suffix, const QString& prefix = QString()); 0051 0052 private: 0053 static FileCache *s_self; 0054 FileCache(); 0055 ~FileCache(); 0056 0057 QTemporaryDir* createTempDir(); 0058 QCache<QString,KuickFile> m_files; 0059 0060 int m_limit; 0061 QTemporaryDir* m_tempDir; 0062 0063 }; 0064 0065 #endif // FILECACHE_H