cache.h 1.98 KB
Newer Older
1
/***************************************************************************
2
    begin                : Sat Sep 7 2002
3
    copyright            : (C) 2002 - 2004 by Scott Wheeler
4
    email                : wheeler@kde.org
5
 ***************************************************************************/
6 7 8 9 10 11 12 13 14 15

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

16 17
#ifndef CACHE_H
#define CACHE_H
18

19
#include <QDataStream>
20 21

#include "stringhash.h"
Tim Beaulen's avatar
Tim Beaulen committed
22

23
class Tag;
24 25 26
class Playlist;
class PlaylistCollection;

27 28 29
template<class T>
class QList;

Tim Beaulen's avatar
Tim Beaulen committed
30
typedef QList<Playlist *> PlaylistList;
31

32
class Cache : public FileHandleHash
33
{
34
public:
35
    static Cache *instance();
36
    void save();
37

38 39 40
    static void loadPlaylists(PlaylistCollection *collection);
    static void savePlaylists(const PlaylistList &playlists);

41 42
    static bool cacheFileExists();

43 44
protected:
    Cache();
45
    void load();
46

47
private:
48 49 50 51 52 53 54 55 56 57 58 59
    static const int m_currentVersion = 1;
};

/**
 * A simple QDataStream subclass that has an extra field to indicate the cache
 * version.
 */

class CacheDataStream : public QDataStream
{
public:
    CacheDataStream(QIODevice *d) : QDataStream(d), m_cacheVersion(0) {}
60
    CacheDataStream(QByteArray &a, int mode) : QDataStream(&a, mode), m_cacheVersion(0) {}
61 62 63 64 65

    virtual ~CacheDataStream() {}

    int cacheVersion() const { return m_cacheVersion; }
    void setCacheVersion(int v) { m_cacheVersion = v; }
66

67 68
private:
    int m_cacheVersion;
69 70 71
};

#endif
72 73

// vim: set et sw=4 tw=0 sta: