diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 12ab51677..406343ea6 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -249,6 +249,7 @@ set( libHeaders functimeout.h aclsystem.h + actioncollection.h collection.h query.h resolver.h diff --git a/src/libtomahawk/LatchManager.cpp b/src/libtomahawk/LatchManager.cpp index 8955a306d..c47482a88 100644 --- a/src/libtomahawk/LatchManager.cpp +++ b/src/libtomahawk/LatchManager.cpp @@ -18,6 +18,7 @@ #include "LatchManager.h" +#include "actioncollection.h" #include "audio/audioengine.h" #include "database/database.h" @@ -81,6 +82,8 @@ LatchManager::playlistChanged( PlaylistInterface* ) cmd->setTimestamp( QDateTime::currentDateTime().toTime_t() ); Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); + ActionCollection::instance()->getAction( "latchOn" )->setText( tr( "&Catch Up" ) ); + // If not, then keep waiting return; } @@ -113,6 +116,8 @@ LatchManager::playlistChanged( PlaylistInterface* ) m_latchedInterface.clear(); m_state = NotLatched; + + ActionCollection::instance()->getAction( "latchOn" )->setText( tr( "&Listen Along" ) ); } @@ -126,9 +131,8 @@ LatchManager::catchUpRequest() void LatchManager::unlatchRequest( const source_ptr& source ) { - AudioEngine::instance()->playItem( source->getPlaylistInterface().data(), source->getPlaylistInterface()->nextItem() ); - - AudioEngine::instance()->stop(); AudioEngine::instance()->setPlaylist( 0 ); + + ActionCollection::instance()->getAction( "latchOn" )->setText( tr( "&Listen Along" ) ); } diff --git a/src/libtomahawk/actioncollection.cpp b/src/libtomahawk/actioncollection.cpp index 679703a22..42fbb59e3 100644 --- a/src/libtomahawk/actioncollection.cpp +++ b/src/libtomahawk/actioncollection.cpp @@ -25,7 +25,8 @@ ActionCollection* ActionCollection::instance() } -ActionCollection::ActionCollection() +ActionCollection::ActionCollection( QObject *parent ) + : QObject( parent ) { s_instance = this; initActions(); @@ -35,7 +36,8 @@ ActionCollection::ActionCollection() void ActionCollection::initActions() { - + m_actionCollection[ "latchOn" ] = new QAction( tr( "&Listen Along" ), this ); + m_actionCollection[ "latchOff" ] = new QAction( tr( "&Stop Listening Along" ), this ); } diff --git a/src/libtomahawk/actioncollection.h b/src/libtomahawk/actioncollection.h index 7118f7bfa..336796c1c 100644 --- a/src/libtomahawk/actioncollection.h +++ b/src/libtomahawk/actioncollection.h @@ -24,13 +24,14 @@ #include -class DLLEXPORT ActionCollection +class DLLEXPORT ActionCollection : public QObject { - + Q_OBJECT + public: static ActionCollection* instance(); - ActionCollection(); + ActionCollection( QObject *parent); ~ActionCollection(); void initActions(); diff --git a/src/libtomahawk/audio/audioengine.cpp b/src/libtomahawk/audio/audioengine.cpp index c0555c4f4..6cc461757 100644 --- a/src/libtomahawk/audio/audioengine.cpp +++ b/src/libtomahawk/audio/audioengine.cpp @@ -700,6 +700,7 @@ AudioEngine::setPlaylist( PlaylistInterface* playlist ) if ( !playlist ) { m_playlist.clear(); + emit playlistChanged( playlist ); return; } diff --git a/src/sourcetree/sourcetreeview.cpp b/src/sourcetree/sourcetreeview.cpp index 39771bdc7..f28af0760 100644 --- a/src/sourcetree/sourcetreeview.cpp +++ b/src/sourcetree/sourcetreeview.cpp @@ -28,6 +28,7 @@ #include #include +#include "actioncollection.h" #include "playlist.h" #include "viewmanager.h" #include "sourcesproxymodel.h" @@ -80,8 +81,8 @@ SourceTreeView::SourceTreeView( QWidget* parent ) // setAnimated( true ); m_delegate = new SourceDelegate( this ); - connect( m_delegate, SIGNAL( latchOn( Tomahawk::source_ptr ) ), this, SIGNAL( latchRequest( Tomahawk::source_ptr ) ), Qt::QueuedConnection ); - connect( m_delegate, SIGNAL( latchOff( Tomahawk::source_ptr ) ), this, SIGNAL( unlatchRequest( Tomahawk::source_ptr ) ), Qt::QueuedConnection ); + connect( m_delegate, SIGNAL( latchOn( Tomahawk::source_ptr ) ), this, SLOT( latchOnOrCatchUp( Tomahawk::source_ptr ) ) ); + connect( m_delegate, SIGNAL( latchOff( Tomahawk::source_ptr ) ), this, SLOT( latchOff( Tomahawk::source_ptr ) ) ); setItemDelegate( m_delegate ); @@ -141,7 +142,8 @@ SourceTreeView::setupMenus() } } - m_latchOnAction = m_latchMenu.addAction( tr( "&Listen Along" ) ); + QAction* latchOnAction = ActionCollection::instance()->getAction( "latchOn" ); + m_latchMenu.addAction( latchOnAction ); if ( type == SourcesModel::Collection ) { @@ -151,10 +153,10 @@ SourceTreeView::setupMenus() { if ( m_latchManager->isLatched( source ) ) { - m_latchOnAction->setText( tr( "&Catch Up" ) ); m_latchMenu.addSeparator(); - m_latchOffAction = m_latchMenu.addAction( tr( "&Stop Listening Along" ) ); - connect( m_latchOffAction, SIGNAL( triggered() ), SLOT( latchOff() ) ); + QAction *latchOffAction = ActionCollection::instance()->getAction( "latchOff" ); + m_latchMenu.addAction( latchOffAction ); + connect( latchOffAction, SIGNAL( triggered() ), SLOT( latchOff() ) ); } } } @@ -189,7 +191,7 @@ SourceTreeView::setupMenus() connect( m_deletePlaylistAction, SIGNAL( triggered() ), SLOT( deletePlaylist() ) ); connect( m_copyPlaylistAction, SIGNAL( triggered() ), SLOT( copyPlaylistLink() ) ); connect( m_addToLocalAction, SIGNAL( triggered() ), SLOT( addToLocal() ) ); - connect( m_latchOnAction, SIGNAL( triggered() ), SLOT( latchOnOrCatchUp() ) ); + connect( latchOnAction, SIGNAL( triggered() ), SLOT( latchOnOrCatchUp() ) ); } @@ -342,6 +344,7 @@ SourceTreeView::addToLocal() void SourceTreeView::latchOnOrCatchUp() { + disconnect( this, SLOT( latchOnOrCatchUp() ) ); if ( !m_contextMenuIndex.isValid() ) return; @@ -352,16 +355,14 @@ SourceTreeView::latchOnOrCatchUp() CollectionItem* item = itemFromIndex< CollectionItem >( m_contextMenuIndex ); source_ptr source = item->source(); - if ( m_latchManager->isLatched( source ) ) - emit catchUpRequest(); - else - emit latchRequest( source ); + latchOnOrCatchUp( source ); } void SourceTreeView::latchOff() { + disconnect( this, SLOT( latchOff() ) ); qDebug() << Q_FUNC_INFO; if ( !m_contextMenuIndex.isValid() ) return; @@ -372,11 +373,29 @@ SourceTreeView::latchOff() const CollectionItem* item = itemFromIndex< CollectionItem >( m_contextMenuIndex ); const source_ptr source = item->source(); + + latchOff( source ); +} + +void +SourceTreeView::latchOnOrCatchUp( const Tomahawk::source_ptr& source ) +{ + if ( m_latchManager->isLatched( source ) ) + emit catchUpRequest(); + else + emit latchRequest( source ); +} + + +void +SourceTreeView::latchOff( const Tomahawk::source_ptr& source ) +{ emit unlatchRequest( source ); } + void SourceTreeView::renamePlaylist() { diff --git a/src/sourcetree/sourcetreeview.h b/src/sourcetree/sourcetreeview.h index 96b26b993..bd07f79d6 100644 --- a/src/sourcetree/sourcetreeview.h +++ b/src/sourcetree/sourcetreeview.h @@ -72,7 +72,9 @@ private slots: void latchOnOrCatchUp(); void latchOff(); - + void latchOnOrCatchUp( const Tomahawk::source_ptr& source ); + void latchOff( const Tomahawk::source_ptr& source ); + void onCustomContextMenu( const QPoint& pos ); protected: diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index e42cb75b4..6e9a506bd 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -161,7 +161,7 @@ TomahawkApp::init() new TomahawkSettings( this ); TomahawkSettings* s = TomahawkSettings::instance(); - new ActionCollection(); + new ActionCollection( this ); tDebug( LOGINFO ) << "Setting NAM."; #ifdef LIBLASTFM_FOUND @@ -319,8 +319,6 @@ TomahawkApp::~TomahawkApp() #ifdef LIBATTICA_FOUND delete AtticaManager::instance(); #endif - - delete ActionCollection::instance(); tLog() << "Finished shutdown."; }