PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 12ms RepoModel.GetById 28ms app.codeStats 0ms

/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/*
 20    The collection  - acts as container for someones music library
 21    load() -> async populate by calling addArtists etc,
 22    then finishedLoading() is emitted.
 23    then use artists() etc to get the data.
 24*/
 25
 26#ifndef TOMAHAWK_COLLECTION_H
 27#define TOMAHAWK_COLLECTION_H
 28
 29#include <QHash>
 30#include <QDir>
 31#include <QList>
 32#include <QSharedPointer>
 33
 34#include "Typedefs.h"
 35#include "FuncTimeout.h"
 36#include "Playlist.h"
 37#include "playlist/dynamic/DynamicPlaylist.h"
 38
 39#include "DllMacro.h"
 40
 41namespace Tomahawk
 42{
 43
 44class DLLEXPORT Collection : public QObject
 45{
 46Q_OBJECT
 47
 48public:
 49    Collection( const source_ptr& source, const QString& name, QObject* parent = 0 );
 50    virtual ~Collection();
 51
 52    virtual QString name() const;
 53
 54    virtual void loadPlaylists() { qDebug() << Q_FUNC_INFO; }
 55    virtual void loadAutoPlaylists() { qDebug() << Q_FUNC_INFO; }
 56    virtual void loadStations() { qDebug() << Q_FUNC_INFO; }
 57
 58    virtual Tomahawk::playlist_ptr playlist( const QString& guid );
 59    virtual Tomahawk::dynplaylist_ptr autoPlaylist( const QString& guid );
 60    virtual Tomahawk::dynplaylist_ptr station( const QString& guid );
 61
 62    virtual void addPlaylist( const Tomahawk::playlist_ptr& p );
 63    virtual void deletePlaylist( const Tomahawk::playlist_ptr& p );
 64
 65    virtual void addAutoPlaylist( const Tomahawk::dynplaylist_ptr& p );
 66    virtual void deleteAutoPlaylist( const Tomahawk::dynplaylist_ptr& p );
 67
 68    virtual void addStation( const Tomahawk::dynplaylist_ptr& s );
 69    virtual void deleteStation( const Tomahawk::dynplaylist_ptr& s );
 70
 71    virtual QList< Tomahawk::playlist_ptr > playlists() { return m_playlists.values(); }
 72    virtual QList< Tomahawk::dynplaylist_ptr > autoPlaylists() { return m_autoplaylists.values(); }
 73    virtual QList< Tomahawk::dynplaylist_ptr > stations() { return m_stations.values(); }
 74
 75    const source_ptr& source() const;
 76    unsigned int lastmodified() const { return m_lastmodified; }
 77
 78signals:
 79    void tracksAdded( const QList<unsigned int>& fileids );
 80    void tracksRemoved( const QList<unsigned int>& fileids );
 81
 82    void playlistsAdded( const QList<Tomahawk::playlist_ptr>& );
 83    void playlistsDeleted( const QList<Tomahawk::playlist_ptr>& );
 84
 85    void autoPlaylistsAdded( const QList<Tomahawk::dynplaylist_ptr>& );
 86    void autoPlaylistsDeleted( const QList<Tomahawk::dynplaylist_ptr>& );
 87
 88    void stationsAdded( const QList<Tomahawk::dynplaylist_ptr>& );
 89    void stationsDeleted( const QList<Tomahawk::dynplaylist_ptr>& );
 90
 91    void changed();
 92
 93public slots:
 94    virtual void addTracks( const QList<QVariant>& newitems ) = 0;
 95    virtual void removeTracks( const QDir& dir ) = 0;
 96
 97    void setPlaylists( const QList<Tomahawk::playlist_ptr>& plists );
 98    void setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& autoplists );
 99    void setStations( const QList< Tomahawk::dynplaylist_ptr >& stations );
100
101    void setTracks( const QList<unsigned int>& fileids );
102    void delTracks( const QList<unsigned int>& fileids );
103
104protected:
105    QString m_name;
106    unsigned int m_lastmodified; // unix time of last change to collection
107
108private slots:
109    void onSynced();
110
111private:
112    bool m_changed;
113
114    source_ptr m_source;
115    QHash< QString, Tomahawk::playlist_ptr > m_playlists;
116    QHash< QString, Tomahawk::dynplaylist_ptr > m_autoplaylists;
117    QHash< QString, Tomahawk::dynplaylist_ptr > m_stations;
118
119    // HACK see line 99 in the dbcmd for why we need this for backwards-compatibility
120    void moveAutoToStation( const QString& guid );
121    void moveStationToAuto( const QString& guid );
122    friend class ::DatabaseCommand_SetDynamicPlaylistRevision;
123};
124
125}; // ns
126
127inline uint qHash( const QSharedPointer<Tomahawk::Collection>& key )
128{
129    return qHash( (void *)key.data() );
130}
131
132#endif // TOMAHAWK_COLLECTION_H