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