diff --git a/src/libtomahawk/artist.h b/src/libtomahawk/artist.h index 2749fd619..cc69534db 100644 --- a/src/libtomahawk/artist.h +++ b/src/libtomahawk/artist.h @@ -29,7 +29,7 @@ public: Tomahawk::collection_ptr collection() const; - QList tracks(); + virtual QList tracks(); virtual int trackCount() const { return 0; } virtual int unfilteredTrackCount() const { return m_queries.count(); } diff --git a/src/libtomahawk/playlist.cpp b/src/libtomahawk/playlist.cpp index 50666134e..9f6a5033d 100644 --- a/src/libtomahawk/playlist.cpp +++ b/src/libtomahawk/playlist.cpp @@ -32,12 +32,14 @@ PlaylistEntry::queryVariant() const return m_query->toVariant(); } + void PlaylistEntry::setQuery( const Tomahawk::query_ptr& q ) { m_query = q; } + const Tomahawk::query_ptr& PlaylistEntry::query() const { @@ -51,12 +53,14 @@ PlaylistEntry::lastSource() const return m_lastsource; } + void PlaylistEntry::setLastSource( source_ptr s ) { m_lastsource = s; } + Playlist::Playlist( const source_ptr& author ) : m_source( author ) , m_lastmodified( 0 ) @@ -64,6 +68,7 @@ Playlist::Playlist( const source_ptr& author ) qDebug() << Q_FUNC_INFO << "JSON"; } + // used when loading from DB: Playlist::Playlist( const source_ptr& src, const QString& currentrevision, @@ -107,16 +112,18 @@ Playlist::Playlist( const source_ptr& author, init(); } + void - Playlist::init() { m_locallyChanged = false; connect( Pipeline::instance(), SIGNAL( idle() ), SLOT( onResolvingFinished() ) ); } + Playlist::~Playlist() {} + playlist_ptr Playlist::create( const source_ptr& author, const QString& guid, @@ -293,6 +300,7 @@ Playlist::setRevision( const QString& rev, emit revisionLoaded( pr ); } + PlaylistRevision Playlist::setNewRevision( const QString& rev, const QList& neworderedguids, @@ -373,12 +381,14 @@ Playlist::setNewRevision( const QString& rev, return pr; } + const source_ptr& Playlist::author() { return m_source; } + void Playlist::resolve() { @@ -391,6 +401,7 @@ Playlist::resolve() Pipeline::instance()->resolve( qlist ); } + void Playlist::onResultsFound( const QList& results ) { @@ -409,6 +420,7 @@ Playlist::onResolvingFinished() } } + void Playlist::addEntry( const query_ptr& query, const QString& oldrev ) { @@ -430,6 +442,7 @@ Playlist::addEntries( const QList& queries, const QString& oldrev ) createNewRevision( newrev, oldrev, el ); } + QList Playlist::addEntriesInternal( const QList& queries ) { @@ -458,15 +471,27 @@ QList< plentry_ptr > Playlist::newEntries( const QList< plentry_ptr >& entries ) { QSet currentguids; - foreach( plentry_ptr p, m_entries ) + foreach( const plentry_ptr& p, m_entries ) currentguids.insert( p->guid() ); // could be cached as member? // calc list of newly added entries: QList added; - foreach( plentry_ptr p, entries ) + foreach( const plentry_ptr& p, entries ) { if( !currentguids.contains( p->guid() ) ) added << p; } return added; } + + +QList +Playlist::tracks() +{ + QList queries; + foreach( const plentry_ptr& p, m_entries ) + queries << p->query(); + + return queries; +} + diff --git a/src/libtomahawk/playlist.h b/src/libtomahawk/playlist.h index a68ae6365..d1837d3b6 100644 --- a/src/libtomahawk/playlist.h +++ b/src/libtomahawk/playlist.h @@ -10,6 +10,8 @@ #include "query.h" #include "typedefs.h" +#include "playlistinterface.h" + #include "dllmacro.h" class DatabaseCommand_LoadAllPlaylists; @@ -79,7 +81,7 @@ struct PlaylistRevision }; -class DLLEXPORT Playlist : public QObject +class DLLEXPORT Playlist : public QObject, public PlaylistInterface { Q_OBJECT Q_PROPERTY( QString guid READ guid WRITE setGuid ) @@ -137,6 +139,21 @@ public: void setShared( bool b ) { m_shared = b; } // + virtual QList tracks(); + + virtual int unfilteredTrackCount() const { return m_entries.count(); } + virtual int trackCount() const { return m_entries.count(); } + + virtual Tomahawk::result_ptr siblingItem( int itemsAway ) { return result_ptr(); } + + virtual PlaylistInterface::RepeatMode repeatMode() const { return PlaylistInterface::NoRepeat; } + virtual bool shuffled() const { return false; } + + virtual void setRepeatMode( PlaylistInterface::RepeatMode ) {} + virtual void setShuffled( bool ) {} + + virtual void setFilter( const QString& pattern ) {} + signals: /// emitted when the playlist revision changes (whenever the playlist changes) void revisionLoaded( Tomahawk::PlaylistRevision ); @@ -144,6 +161,12 @@ signals: /// watch for this to see when newly created playlist is synced to DB (if you care) void created(); + void repeatModeChanged( PlaylistInterface::RepeatMode mode ); + void shuffleModeChanged( bool enabled ); + + void trackCountChanged( unsigned int tracks ); + void sourceTrackCountChanged( unsigned int tracks ); + public slots: // want to update the playlist from the model? // generate a newrev using uuid() and call this: diff --git a/src/libtomahawk/playlist/albumproxymodel.h b/src/libtomahawk/playlist/albumproxymodel.h index 0abd4e1a7..d87c855db 100644 --- a/src/libtomahawk/playlist/albumproxymodel.h +++ b/src/libtomahawk/playlist/albumproxymodel.h @@ -18,6 +18,8 @@ public: virtual AlbumModel* sourceModel() const { return m_model; } virtual void setSourceModel( AlbumModel* sourceModel ); + virtual QList tracks() { Q_ASSERT( FALSE ); QList queries; return queries; } + virtual int unfilteredTrackCount() const { return sourceModel()->rowCount( QModelIndex() ); } virtual int trackCount() const { return rowCount( QModelIndex() ); } virtual int albumCount() const { return rowCount( QModelIndex() ); } diff --git a/src/libtomahawk/playlist/playlistmanager.h b/src/libtomahawk/playlist/playlistmanager.h index 273e279ae..0c327e494 100644 --- a/src/libtomahawk/playlist/playlistmanager.h +++ b/src/libtomahawk/playlist/playlistmanager.h @@ -45,6 +45,8 @@ public: bool isSuperCollectionVisible() const { return true; } + PlaylistInterface* currentPlaylistInterface() const { return m_currentInterface; } + bool show( const Tomahawk::playlist_ptr& playlist ); bool show( const Tomahawk::dynplaylist_ptr& playlist ); bool show( const Tomahawk::artist_ptr& artist ); diff --git a/src/libtomahawk/playlist/trackproxymodel.h b/src/libtomahawk/playlist/trackproxymodel.h index 37ef9b23c..2c7f706d5 100644 --- a/src/libtomahawk/playlist/trackproxymodel.h +++ b/src/libtomahawk/playlist/trackproxymodel.h @@ -21,6 +21,8 @@ public: virtual QPersistentModelIndex currentItem() const { return mapFromSource( m_model->currentItem() ); } virtual void setCurrentItem( const QModelIndex& index ) { m_model->setCurrentItem( mapToSource( index ) ); } + virtual QList tracks() { Q_ASSERT( FALSE ); QList queries; return queries; } + virtual int unfilteredTrackCount() const { return sourceModel()->rowCount( QModelIndex() ); } virtual int trackCount() const { return rowCount( QModelIndex() ); } diff --git a/src/libtomahawk/playlistinterface.h b/src/libtomahawk/playlistinterface.h index c9b375f07..0e845acc6 100644 --- a/src/libtomahawk/playlistinterface.h +++ b/src/libtomahawk/playlistinterface.h @@ -17,6 +17,8 @@ public: PlaylistInterface( QObject* parent = 0 ) : m_widget( 0 ), m_object( parent ) {} virtual ~PlaylistInterface() {} + virtual QList< Tomahawk::query_ptr > tracks() = 0; + virtual int unfilteredTrackCount() const = 0; virtual int trackCount() const = 0;