PageRenderTime 82ms CodeModel.GetById 41ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/thirdparty/liblastfm2/src/scrobble/ScrobbleCache.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 84 lines | 45 code | 16 blank | 23 comment | 0 complexity | e7e936e8f89fc709699291379578b275 MD5 | raw file
 1/*
 2   Copyright 2009 Last.fm Ltd. 
 3      - Primarily authored by Max Howell, Jono Cole and Doug Mansell
 4
 5   This file is part of liblastfm.
 6
 7   liblastfm is free software: you can redistribute it and/or modify
 8   it under the terms of the GNU General Public License as published by
 9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   liblastfm is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with liblastfm.  If not, see <http://www.gnu.org/licenses/>.
19*/
20#ifndef LASTFM_SCROBBLE_CACHE_H
21#define LASTFM_SCROBBLE_CACHE_H
22
23#include "lastfm/Track"
24#include <QList>
25#include <QString>
26
27#if LASTFM_VERSION >= 0x00010000
28namespace lastfm {
29#else
30using lastfm::Track;
31#endif
32
33/** absolutely not thread-safe */
34class LASTFM_DLLEXPORT ScrobbleCache
35{
36    QString m_username;
37
38    void write(); /// writes m_tracks to m_path
39
40protected:
41    ScrobbleCache()
42    {}
43
44    QString m_path;
45    QList<Track> m_tracks;
46    
47    void read( QDomDocument& xml );  /// reads from m_path into m_tracks   
48    
49public:
50    explicit ScrobbleCache( const QString& username );
51
52    /** note this is unique for Track::sameAs() and equal timestamps 
53      * obviously playcounts will not be increased for the same timestamp */
54    void add( const QList<Track>& );
55
56    /** returns the number of tracks left in the queue */
57    int remove( const QList<Track>& );
58
59    QList<Track> tracks() const { return m_tracks; }
60    QString path() const { return m_path; }
61    QString username() const { return m_username; }
62
63private:
64    bool operator==( const ScrobbleCache& ); //undefined
65
66    enum Invalidity
67    {
68        TooShort,
69        ArtistNameMissing,
70        TrackNameMissing,
71        ArtistInvalid,
72        NoTimestamp,
73        FromTheFuture,
74        FromTheDistantPast
75    };
76
77    bool isValid( const Track& track, Invalidity* = 0 );
78};
79
80#if LASTFM_VERSION >= 0x00010000
81}
82#endif
83
84#endif