diff --git a/src/libtomahawk/playlist/RecentlyAddedModel.cpp b/src/libtomahawk/playlist/RecentlyAddedModel.cpp index 243a43f76..8a0004f53 100644 --- a/src/libtomahawk/playlist/RecentlyAddedModel.cpp +++ b/src/libtomahawk/playlist/RecentlyAddedModel.cpp @@ -33,21 +33,10 @@ using namespace Tomahawk; -RecentlyAddedModel::RecentlyAddedModel( const source_ptr& source, QObject* parent ) +RecentlyAddedModel::RecentlyAddedModel( QObject* parent ) : PlayableModel( parent ) - , m_source( source ) , m_limit( LATEST_TRACK_ITEMS ) { - if ( source.isNull() ) - { - connect( SourceList::instance(), SIGNAL( ready() ), SLOT( onSourcesReady() ) ); - connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) ); - } - else - { - onSourceAdded( source ); - loadHistory(); - } } @@ -63,6 +52,7 @@ RecentlyAddedModel::loadHistory() { clear(); } + startLoading(); DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_source->collection() ); cmd->setLimit( m_limit ); @@ -88,6 +78,28 @@ RecentlyAddedModel::onSourcesReady() } +void +RecentlyAddedModel::setSource( const Tomahawk::source_ptr& source ) +{ + m_source = source; + + if ( source.isNull() ) + { + if ( SourceList::instance()->isReady() ) + onSourcesReady(); + else + connect( SourceList::instance(), SIGNAL( ready() ), SLOT( onSourcesReady() ) ); + + connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) ); + } + else + { + onSourceAdded( source ); + loadHistory(); + } +} + + void RecentlyAddedModel::onSourceAdded( const Tomahawk::source_ptr& source ) { diff --git a/src/libtomahawk/playlist/RecentlyAddedModel.h b/src/libtomahawk/playlist/RecentlyAddedModel.h index e4a3a98fa..8b26e4a8e 100644 --- a/src/libtomahawk/playlist/RecentlyAddedModel.h +++ b/src/libtomahawk/playlist/RecentlyAddedModel.h @@ -32,7 +32,7 @@ class DLLEXPORT RecentlyAddedModel : public PlayableModel Q_OBJECT public: - explicit RecentlyAddedModel( const Tomahawk::source_ptr& source, QObject* parent = 0 ); + explicit RecentlyAddedModel( QObject* parent = 0 ); ~RecentlyAddedModel(); unsigned int limit() const { return m_limit; } @@ -40,6 +40,9 @@ public: bool isTemporary() const; +public slots: + void setSource( const Tomahawk::source_ptr& source ); + private slots: void onSourcesReady(); void onSourceAdded( const Tomahawk::source_ptr& source );