diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 5ce805f2e..73796508f 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -283,6 +283,7 @@ set( libSources artist.cpp artistplaylistinterface.cpp album.cpp + albumplaylistinterface.cpp collection.cpp playlist.cpp resolver.cpp @@ -416,6 +417,7 @@ set( libHeaders artist.h artistplaylistinterface.h album.h + albumplaylistinterface.h playlist.h EchonestCatalogSynchronizer.h diff --git a/src/libtomahawk/album.cpp b/src/libtomahawk/album.cpp index ade2e33ef..7515b01bb 100644 --- a/src/libtomahawk/album.cpp +++ b/src/libtomahawk/album.cpp @@ -19,6 +19,7 @@ #include "album.h" #include "artist.h" +#include "albumplaylistinterface.h" #include "database/database.h" #include "database/databaseimpl.h" #include "database/databasecommand_alltracks.h" @@ -63,12 +64,10 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar Album::Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist ) - : PlaylistInterface( this ) + : QObject() , m_id( id ) , m_name( name ) , m_artist( artist ) - , m_currentItem( 0 ) - , m_currentTrack( 0 ) { } @@ -78,65 +77,28 @@ Album::onTracksAdded( const QList& tracks ) { qDebug() << Q_FUNC_INFO; - m_queries << tracks; + Tomahawk::AlbumPlaylistInterface* api = dynamic_cast< Tomahawk::AlbumPlaylistInterface* >( getPlaylistInterface().data() ); + if ( api ) + api->addQueries( tracks ); + emit tracksAdded( tracks ); } -Tomahawk::result_ptr -Album::siblingItem( int itemsAway ) -{ - int p = m_currentTrack; - p += itemsAway; - - if ( p < 0 ) - return Tomahawk::result_ptr(); - - if ( p >= m_queries.count() ) - return Tomahawk::result_ptr(); - - m_currentTrack = p; - m_currentItem = m_queries.at( p )->results().first(); - return m_currentItem; -} - -result_ptr -Album::currentItem() const -{ - return m_currentItem; -} - -bool -Album::hasNextItem() -{ - int p = m_currentTrack; - p++; - if ( p < 0 || p >= m_queries.count() ) - return false; - - return true; -} - artist_ptr Album::artist() const { return m_artist; } -QList -Album::tracks() + +Tomahawk::playlistinterface_ptr +Album::getPlaylistInterface() { - if ( m_queries.isEmpty() ) + if ( m_playlistInterface.isNull() ) { - DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks(); - cmd->setAlbum( this ); - cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition ); - - connect( cmd, SIGNAL( tracks( QList, QVariant ) ), - SLOT( onTracksAdded( QList ) ) ); - - Database::instance()->enqueue( QSharedPointer( cmd ) ); + m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::AlbumPlaylistInterface( this ) ); } - - return m_queries; -} + + return m_playlistInterface; +} \ No newline at end of file diff --git a/src/libtomahawk/album.h b/src/libtomahawk/album.h index b2a6474f3..14fb9d749 100644 --- a/src/libtomahawk/album.h +++ b/src/libtomahawk/album.h @@ -19,8 +19,8 @@ #ifndef TOMAHAWKALBUM_H #define TOMAHAWKALBUM_H -#include -#include +#include +#include #include "typedefs.h" #include "playlistinterface.h" @@ -29,7 +29,7 @@ namespace Tomahawk { -class DLLEXPORT Album : public QObject, public Tomahawk::PlaylistInterface +class DLLEXPORT Album : public QObject { Q_OBJECT @@ -44,47 +44,24 @@ public: QString name() const { return m_name; } artist_ptr artist() const; - QList tracks(); - - virtual int trackCount() const { return m_queries.count(); } - virtual int unfilteredTrackCount() const { return m_queries.count(); } - - virtual Tomahawk::result_ptr siblingItem( int itemsAway ); - - virtual bool hasNextItem(); - virtual Tomahawk::result_ptr currentItem() const; - - 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*/ ) {} + Tomahawk::playlistinterface_ptr getPlaylistInterface(); signals: - void repeatModeChanged( PlaylistInterface::RepeatMode mode ); - void shuffleModeChanged( bool enabled ); - void tracksAdded( const QList& tracks ); - void trackCountChanged( unsigned int tracks ); - void sourceTrackCountChanged( unsigned int tracks ); - - void nextTrackReady(); private slots: void onTracksAdded( const QList& tracks ); private: + Q_DISABLE_COPY( Album ) Album(); unsigned int m_id; QString m_name; artist_ptr m_artist; - QList m_queries; - result_ptr m_currentItem; - unsigned int m_currentTrack; + + Tomahawk::playlistinterface_ptr m_playlistInterface; }; }; // ns diff --git a/src/libtomahawk/albumplaylistinterface.cpp b/src/libtomahawk/albumplaylistinterface.cpp new file mode 100644 index 000000000..3f9b4c131 --- /dev/null +++ b/src/libtomahawk/albumplaylistinterface.cpp @@ -0,0 +1,103 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "albumplaylistinterface.h" + +#include "artist.h" +#include "database/database.h" +#include "database/databaseimpl.h" +#include "database/databasecommand_alltracks.h" +#include "query.h" + +#include "utils/logger.h" + +using namespace Tomahawk; + +AlbumPlaylistInterface::AlbumPlaylistInterface() {} +AlbumPlaylistInterface::~AlbumPlaylistInterface() {} + +AlbumPlaylistInterface::AlbumPlaylistInterface( Tomahawk::Album *album ) + : Tomahawk::PlaylistInterface( this ) + , m_currentItem( 0 ) + , m_currentTrack( 0 ) + , m_album( QWeakPointer< Tomahawk::Album >( album ) ) +{ +} + + +Tomahawk::result_ptr +AlbumPlaylistInterface::siblingItem( int itemsAway ) +{ + int p = m_currentTrack; + p += itemsAway; + + if ( p < 0 ) + return Tomahawk::result_ptr(); + + if ( p >= m_queries.count() ) + return Tomahawk::result_ptr(); + + m_currentTrack = p; + m_currentItem = m_queries.at( p )->results().first(); + return m_currentItem; +} + + +result_ptr +AlbumPlaylistInterface::currentItem() const +{ + return m_currentItem; +} + + +bool +AlbumPlaylistInterface::hasNextItem() +{ + int p = m_currentTrack; + p++; + if ( p < 0 || p >= m_queries.count() ) + return false; + + return true; +} + + +QList< Tomahawk::query_ptr > +AlbumPlaylistInterface::tracks() +{ + if ( m_queries.isEmpty() && m_album ) + { + DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks(); + cmd->setAlbum( m_album.data() ); + cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition ); + + connect( cmd, SIGNAL( tracks( QList, QVariant ) ), + SLOT( onTracksAdded( QList ) ) ); + + Database::instance()->enqueue( QSharedPointer( cmd ) ); + } + + return m_queries; +} + + +void +AlbumPlaylistInterface::addQueries( const QList< query_ptr >& tracks ) +{ + m_queries << tracks; +} \ No newline at end of file diff --git a/src/libtomahawk/albumplaylistinterface.h b/src/libtomahawk/albumplaylistinterface.h new file mode 100644 index 000000000..4ddb58d06 --- /dev/null +++ b/src/libtomahawk/albumplaylistinterface.h @@ -0,0 +1,85 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef TOMAHAWKALBUMPLAYLISTINTERFACE_H +#define TOMAHAWKALBUMPLAYLISTINTERFACE_H + +#include +#include + +#include "typedefs.h" +#include "playlistinterface.h" +#include "dllmacro.h" + +namespace Tomahawk +{ + +class Album; + + +class DLLEXPORT AlbumPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface +{ +Q_OBJECT + +public: + AlbumPlaylistInterface( Tomahawk::Album *album ); + virtual ~AlbumPlaylistInterface(); + + QList tracks(); + + virtual int trackCount() const { return m_queries.count(); } + virtual int unfilteredTrackCount() const { return m_queries.count(); } + + virtual Tomahawk::result_ptr siblingItem( int itemsAway ); + + virtual bool hasNextItem(); + virtual Tomahawk::result_ptr currentItem() const; + + 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*/ ) {} + + virtual void addQueries( const QList& tracks ); + +signals: + void repeatModeChanged( PlaylistInterface::RepeatMode mode ); + void shuffleModeChanged( bool enabled ); + + void trackCountChanged( unsigned int tracks ); + void sourceTrackCountChanged( unsigned int tracks ); + + void nextTrackReady(); + +private: + Q_DISABLE_COPY( AlbumPlaylistInterface ) + AlbumPlaylistInterface(); + + QList< Tomahawk::query_ptr > m_queries; + result_ptr m_currentItem; + unsigned int m_currentTrack; + + QWeakPointer< Tomahawk::Album > m_album; +}; + +}; // ns + +#endif diff --git a/src/libtomahawk/dropjob.cpp b/src/libtomahawk/dropjob.cpp index 40e4cd154..3afabb540 100644 --- a/src/libtomahawk/dropjob.cpp +++ b/src/libtomahawk/dropjob.cpp @@ -785,7 +785,7 @@ DropJob::getAlbum(const QString &artist, const QString &album) if ( albumPtr.isNull() ) return QList< query_ptr >(); - if ( albumPtr->tracks().isEmpty() ) + if ( albumPtr->getPlaylistInterface()->tracks().isEmpty() ) { m_dropJob = new DropJobNotifier( QPixmap( RESPATH "images/album-icon.png" ), Album ); connect( albumPtr.data(), SIGNAL( tracksAdded( QList ) ), @@ -796,7 +796,7 @@ DropJob::getAlbum(const QString &artist, const QString &album) return QList< query_ptr >(); } else - return albumPtr->tracks(); + return albumPtr->getPlaylistInterface()->tracks(); } diff --git a/src/libtomahawk/playlist/playlistmodel.cpp b/src/libtomahawk/playlist/playlistmodel.cpp index 2458f4273..8c111156f 100644 --- a/src/libtomahawk/playlist/playlistmodel.cpp +++ b/src/libtomahawk/playlist/playlistmodel.cpp @@ -152,7 +152,7 @@ PlaylistModel::append( const Tomahawk::album_ptr& album ) m_isTemporary = true; } - append( album->tracks() ); + append( album->getPlaylistInterface()->tracks() ); } diff --git a/src/libtomahawk/playlistinterface.h b/src/libtomahawk/playlistinterface.h index 381d9f707..aeb8d9dc0 100644 --- a/src/libtomahawk/playlistinterface.h +++ b/src/libtomahawk/playlistinterface.h @@ -19,7 +19,7 @@ #ifndef PLAYLISTINTERFACE_H #define PLAYLISTINTERFACE_H -#include +#include #include "typedefs.h" #include "dllmacro.h"