PageRenderTime 102ms CodeModel.GetById 60ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 0ms

/src/libtomahawk/infosystem/InfoSystemCache.h

http://github.com/tomahawk-player/tomahawk
C Header | 79 lines | 38 code | 18 blank | 23 comment | 0 complexity | c4fe777060575537e9fe6a349ebbe5e8 MD5 | raw file
 1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 2 *
 3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
 4 *   Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
 5 *
 6 *   Tomahawk is free software: you can redistribute it and/or modify
 7 *   it under the terms of the GNU General Public License as published by
 8 *   the Free Software Foundation, either version 3 of the License, or
 9 *   (at your option) any later version.
10 *
11 *   Tomahawk is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *   GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef TOMAHAWK_INFOSYSTEMCACHE_H
21#define TOMAHAWK_INFOSYSTEMCACHE_H
22
23#include <QCache>
24#include <QDateTime>
25#include <QObject>
26#include <QtDebug>
27#include <QTimer>
28
29#include "InfoSystem.h"
30
31namespace Tomahawk
32{
33
34namespace InfoSystem
35{
36
37class DLLEXPORT InfoSystemCache : public QObject
38{
39Q_OBJECT
40
41public:
42    InfoSystemCache( QObject *parent = 0 );
43
44    virtual ~InfoSystemCache();
45
46signals:
47    void info( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
48
49public slots:
50    void getCachedInfoSlot( Tomahawk::InfoSystem::InfoStringHash criteria, qint64 newMaxAge, Tomahawk::InfoSystem::InfoRequestData requestData );
51    void updateCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, qint64 maxAge, Tomahawk::InfoSystem::InfoType type, QVariant output );
52
53private slots:
54    void pruneTimerFired();
55
56private:
57    /**
58     * Version number of the infosystem cache.
59     * If you change existing cached data,
60     * increase this number.
61     */
62    static const int s_infosystemCacheVersion;
63
64    void notInCache( QObject *receiver, Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData );
65    const QString criteriaMd5( const Tomahawk::InfoSystem::InfoStringHash &criteria, Tomahawk::InfoSystem::InfoType type = Tomahawk::InfoSystem::InfoNoInfo ) const;
66
67    QString m_cacheBaseDir;
68    QHash< InfoType, QHash< QString, QString > > m_fileLocationCache;
69    QTimer m_pruneTimer;
70    QCache< QString, QVariant > m_dataCache;
71};
72
73} //namespace InfoSystem
74
75} //namespace Tomahawk
76
77Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoSystemCache* )
78
79#endif //TOMAHAWK_INFOSYSTEMCACHE_H