diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 074f5d3e4..8c8eef10e 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -281,6 +281,7 @@ set( libSources aclsystem.cpp artist.cpp + artistplaylistinterface.cpp album.cpp collection.cpp playlist.cpp @@ -413,6 +414,7 @@ set( libHeaders sourceplaylistinterface.h artist.h + artistplaylistinterface.h album.h playlist.h diff --git a/src/libtomahawk/artist.cpp b/src/libtomahawk/artist.cpp index 263c57804..eafd6b7e7 100644 --- a/src/libtomahawk/artist.cpp +++ b/src/libtomahawk/artist.cpp @@ -18,10 +18,10 @@ #include "artist.h" +#include "artistplaylistinterface.h" #include "collection.h" #include "database/database.h" #include "database/databaseimpl.h" -#include "database/databasecommand_alltracks.h" #include "query.h" #include "utils/logger.h" @@ -71,11 +71,9 @@ Artist::get( unsigned int id, const QString& name ) Artist::Artist( unsigned int id, const QString& name ) - : PlaylistInterface( this ) + : QObject() , m_id( id ) , m_name( name ) - , m_currentItem( 0 ) - , m_currentTrack( 0 ) { m_sortname = DatabaseImpl::sortname( name, true ); } @@ -86,61 +84,19 @@ Artist::onTracksAdded( const QList& tracks ) { qDebug() << Q_FUNC_INFO; - m_queries << tracks; + Tomahawk::ArtistPlaylistInterface* api = dynamic_cast< Tomahawk::ArtistPlaylistInterface* >( getPlaylistInterface().data() ); + if ( api ) + api->addQueries( tracks ); emit tracksAdded( tracks ); } - -Tomahawk::result_ptr -Artist::siblingItem( int itemsAway ) +Tomahawk::playlistinterface_ptr +Artist::getPlaylistInterface() { - 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; -} - - -bool -Artist::hasNextItem() -{ - int p = m_currentTrack; - p++; - if ( p < 0 || p >= m_queries.count() ) - return false; - - return true; -} - -result_ptr -Artist::currentItem() const -{ - return m_currentItem; -} - - -QList -Artist::tracks() -{ - if ( m_queries.isEmpty() ) + if ( m_playlistInterface.isNull() ) { - DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks(); - cmd->setArtist( this ); - cmd->setSortOrder( DatabaseCommand_AllTracks::Album ); - - connect( cmd, SIGNAL( tracks( QList, QVariant ) ), - SLOT( onTracksAdded( QList ) ) ); - - Database::instance()->enqueue( QSharedPointer( cmd ) ); + m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::ArtistPlaylistInterface( this ) ); } - return m_queries; + return m_playlistInterface; } diff --git a/src/libtomahawk/artist.h b/src/libtomahawk/artist.h index f49865c1b..97ea054b1 100644 --- a/src/libtomahawk/artist.h +++ b/src/libtomahawk/artist.h @@ -23,13 +23,12 @@ #include #include "typedefs.h" -#include "playlistinterface.h" #include "dllmacro.h" namespace Tomahawk { -class DLLEXPORT Artist : public QObject, public Tomahawk::PlaylistInterface +class DLLEXPORT Artist : public QObject { Q_OBJECT @@ -45,33 +44,10 @@ public: QString name() const { return m_name; } QString sortname() const { return m_sortname; } - virtual QList tracks(); - - virtual int trackCount() const { return 0; } - 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 ); @@ -83,9 +59,7 @@ private: QString m_name; QString m_sortname; - QList m_queries; - result_ptr m_currentItem; - unsigned int m_currentTrack; + Tomahawk::playlistinterface_ptr m_playlistInterface; }; }; // ns diff --git a/src/libtomahawk/artistplaylistinterface.cpp b/src/libtomahawk/artistplaylistinterface.cpp new file mode 100644 index 000000000..11972cb71 --- /dev/null +++ b/src/libtomahawk/artistplaylistinterface.cpp @@ -0,0 +1,105 @@ +/* === 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 "artistplaylistinterface.h" + +#include "artist.h" +#include "collection.h" +#include "query.h" +#include "database/database.h" +#include "database/databasecommand_alltracks.h" + +#include "utils/logger.h" + +using namespace Tomahawk; + + +ArtistPlaylistInterface::ArtistPlaylistInterface( Tomahawk::Artist *artist ) + : Tomahawk::PlaylistInterface() + , m_currentItem( 0 ) + , m_currentTrack( 0 ) + , m_artist( QWeakPointer< Tomahawk::Artist >( artist ) ) +{ +} + + +ArtistPlaylistInterface::~ArtistPlaylistInterface() +{ +} + + +Tomahawk::result_ptr +ArtistPlaylistInterface::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; +} + + +bool +ArtistPlaylistInterface::hasNextItem() +{ + int p = m_currentTrack; + p++; + if ( p < 0 || p >= m_queries.count() ) + return false; + + return true; +} + +result_ptr +ArtistPlaylistInterface::currentItem() const +{ + return m_currentItem; +} + + +QList +ArtistPlaylistInterface::tracks() +{ + if ( m_queries.isEmpty() && m_artist ) + { + DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks(); + cmd->setArtist( m_artist.data() ); + cmd->setSortOrder( DatabaseCommand_AllTracks::Album ); + + connect( cmd, SIGNAL( tracks( QList, QVariant ) ), + SLOT( onTracksAdded( QList ) ) ); + + Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); + } + + return m_queries; +} + + +void +ArtistPlaylistInterface::addQueries( const QList< query_ptr >& tracks ) +{ + m_queries << tracks; +} diff --git a/src/libtomahawk/artistplaylistinterface.h b/src/libtomahawk/artistplaylistinterface.h new file mode 100644 index 000000000..eed599886 --- /dev/null +++ b/src/libtomahawk/artistplaylistinterface.h @@ -0,0 +1,83 @@ +/* === 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 TOMAHAWKARTISTPLAYLISTINTERFACE_H +#define TOMAHAWKARTISTPLAYLISTINTERFACE_H + +#include +#include + +#include "typedefs.h" +#include "playlistinterface.h" +#include "dllmacro.h" + +namespace Tomahawk +{ + +class Artist; + +class DLLEXPORT ArtistPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface +{ +Q_OBJECT + +public: + ArtistPlaylistInterface( Tomahawk::Artist *artist ); + virtual ~ArtistPlaylistInterface(); + + virtual QList tracks(); + + virtual int trackCount() const { return 0; } + 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( ArtistPlaylistInterface ) + + QList< Tomahawk::query_ptr > m_queries; + result_ptr m_currentItem; + unsigned int m_currentTrack; + + QWeakPointer< Tomahawk::Artist > m_artist; +}; + +}; // ns + +#endif diff --git a/src/libtomahawk/dropjob.cpp b/src/libtomahawk/dropjob.cpp index 5e67b724e..40e4cd154 100644 --- a/src/libtomahawk/dropjob.cpp +++ b/src/libtomahawk/dropjob.cpp @@ -764,7 +764,7 @@ QList< query_ptr > DropJob::getArtist( const QString &artist ) { artist_ptr artistPtr = Artist::get( artist ); - if ( artistPtr->tracks().isEmpty() ) + if ( artistPtr->getPlaylistInterface()->tracks().isEmpty() ) { connect( artistPtr.data(), SIGNAL( tracksAdded( QList ) ), SLOT( onTracksAdded( QList ) ) ); @@ -772,7 +772,7 @@ DropJob::getArtist( const QString &artist ) return QList< query_ptr >(); } else - return artistPtr->tracks(); + return artistPtr->getPlaylistInterface()->tracks(); } diff --git a/src/libtomahawk/playlist/playlistmodel.cpp b/src/libtomahawk/playlist/playlistmodel.cpp index 87f6cfca9..2458f4273 100644 --- a/src/libtomahawk/playlist/playlistmodel.cpp +++ b/src/libtomahawk/playlist/playlistmodel.cpp @@ -172,7 +172,7 @@ PlaylistModel::append( const Tomahawk::artist_ptr& artist ) m_isTemporary = true; } - append( artist->tracks() ); + append( artist->getPlaylistInterface()->tracks() ); } diff --git a/src/libtomahawk/playlistinterface.h b/src/libtomahawk/playlistinterface.h index 88909f2c4..381d9f707 100644 --- a/src/libtomahawk/playlistinterface.h +++ b/src/libtomahawk/playlistinterface.h @@ -83,6 +83,8 @@ public: return m_sharedPtr; } + //virtual void findMoreIfaces() = 0; + public slots: virtual void setRepeatMode( RepeatMode mode ) = 0; virtual void setShuffled( bool enabled ) = 0; diff --git a/src/libtomahawk/source.cpp b/src/libtomahawk/source.cpp index bf45bd031..6f0e6d540 100644 --- a/src/libtomahawk/source.cpp +++ b/src/libtomahawk/source.cpp @@ -188,7 +188,7 @@ Source::setOffline() m_cc = 0; DatabaseCommand_SourceOffline* cmd = new DatabaseCommand_SourceOffline( id() ); - Database::instance()->enqueue( QSharedPointer(cmd) ); + Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); }