/src/libtomahawk/collection.h

http://github.com/tomahawk-player/tomahawk · C Header · 132 lines · 76 code · 32 blank · 24 comment · 0 complexity · 502b47984c84bb706d06e55945c09005 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. *
  5. * Tomahawk 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. *
  10. * Tomahawk is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*
  19. The collection - acts as container for someones music library
  20. load() -> async populate by calling addArtists etc,
  21. then finishedLoading() is emitted.
  22. then use artists() etc to get the data.
  23. */
  24. #ifndef TOMAHAWK_COLLECTION_H
  25. #define TOMAHAWK_COLLECTION_H
  26. #include <QHash>
  27. #include <QDir>
  28. #include <QList>
  29. #include <QSharedPointer>
  30. #include "Typedefs.h"
  31. #include "FuncTimeout.h"
  32. #include "Playlist.h"
  33. #include "playlist/dynamic/DynamicPlaylist.h"
  34. #include "DllMacro.h"
  35. namespace Tomahawk
  36. {
  37. class DLLEXPORT Collection : public QObject
  38. {
  39. Q_OBJECT
  40. public:
  41. Collection( const source_ptr& source, const QString& name, QObject* parent = 0 );
  42. virtual ~Collection();
  43. virtual QString name() const;
  44. virtual void loadPlaylists() { qDebug() << Q_FUNC_INFO; }
  45. virtual void loadAutoPlaylists() { qDebug() << Q_FUNC_INFO; }
  46. virtual void loadStations() { qDebug() << Q_FUNC_INFO; }
  47. virtual Tomahawk::playlist_ptr playlist( const QString& guid );
  48. virtual Tomahawk::dynplaylist_ptr autoPlaylist( const QString& guid );
  49. virtual Tomahawk::dynplaylist_ptr station( const QString& guid );
  50. virtual void addPlaylist( const Tomahawk::playlist_ptr& p );
  51. virtual void deletePlaylist( const Tomahawk::playlist_ptr& p );
  52. virtual void addAutoPlaylist( const Tomahawk::dynplaylist_ptr& p );
  53. virtual void deleteAutoPlaylist( const Tomahawk::dynplaylist_ptr& p );
  54. virtual void addStation( const Tomahawk::dynplaylist_ptr& s );
  55. virtual void deleteStation( const Tomahawk::dynplaylist_ptr& s );
  56. virtual QList< Tomahawk::playlist_ptr > playlists() { return m_playlists.values(); }
  57. virtual QList< Tomahawk::dynplaylist_ptr > autoPlaylists() { return m_autoplaylists.values(); }
  58. virtual QList< Tomahawk::dynplaylist_ptr > stations() { return m_stations.values(); }
  59. const source_ptr& source() const;
  60. unsigned int lastmodified() const { return m_lastmodified; }
  61. signals:
  62. void tracksAdded( const QList<unsigned int>& fileids );
  63. void tracksRemoved( const QList<unsigned int>& fileids );
  64. void playlistsAdded( const QList<Tomahawk::playlist_ptr>& );
  65. void playlistsDeleted( const QList<Tomahawk::playlist_ptr>& );
  66. void autoPlaylistsAdded( const QList<Tomahawk::dynplaylist_ptr>& );
  67. void autoPlaylistsDeleted( const QList<Tomahawk::dynplaylist_ptr>& );
  68. void stationsAdded( const QList<Tomahawk::dynplaylist_ptr>& );
  69. void stationsDeleted( const QList<Tomahawk::dynplaylist_ptr>& );
  70. void changed();
  71. public slots:
  72. virtual void addTracks( const QList<QVariant>& newitems ) = 0;
  73. virtual void removeTracks( const QDir& dir ) = 0;
  74. void setPlaylists( const QList<Tomahawk::playlist_ptr>& plists );
  75. void setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& autoplists );
  76. void setStations( const QList< Tomahawk::dynplaylist_ptr >& stations );
  77. void setTracks( const QList<unsigned int>& fileids );
  78. void delTracks( const QList<unsigned int>& fileids );
  79. protected:
  80. QString m_name;
  81. unsigned int m_lastmodified; // unix time of last change to collection
  82. private slots:
  83. void onSynced();
  84. private:
  85. bool m_changed;
  86. source_ptr m_source;
  87. QHash< QString, Tomahawk::playlist_ptr > m_playlists;
  88. QHash< QString, Tomahawk::dynplaylist_ptr > m_autoplaylists;
  89. QHash< QString, Tomahawk::dynplaylist_ptr > m_stations;
  90. // HACK see line 99 in the dbcmd for why we need this for backwards-compatibility
  91. void moveAutoToStation( const QString& guid );
  92. void moveStationToAuto( const QString& guid );
  93. friend class ::DatabaseCommand_SetDynamicPlaylistRevision;
  94. };
  95. }; // ns
  96. inline uint qHash( const QSharedPointer<Tomahawk::Collection>& key )
  97. {
  98. return qHash( (void *)key.data() );
  99. }
  100. #endif // TOMAHAWK_COLLECTION_H