From 802fc1f39f1e4eb23c1ec9014381eb3208caa602 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Wed, 25 Apr 2012 21:26:00 +0200 Subject: [PATCH 1/5] First version of stop playback after this track also in systray context menu --- src/TomahawkTrayIcon.cpp | 27 +++++++++++++++++++++++++++ src/TomahawkTrayIcon.h | 5 +++++ src/libtomahawk/audio/AudioEngine.h | 4 +++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/TomahawkTrayIcon.cpp b/src/TomahawkTrayIcon.cpp index 31df4e67d..d3a87268b 100644 --- a/src/TomahawkTrayIcon.cpp +++ b/src/TomahawkTrayIcon.cpp @@ -26,6 +26,7 @@ #include "audio/AudioEngine.h" #include "TomahawkApp.h" #include "TomahawkWindow.h" +#include "Query.h" #include "utils/Logger.h" #include @@ -35,6 +36,7 @@ TomahawkTrayIcon::TomahawkTrayIcon( QObject* parent ) : QSystemTrayIcon( parent ) , m_currentAnimationFrame( 0 ) , m_showWindowAction( 0 ) + , m_stopContinueAfterTrackAction( 0 ) { QIcon icon( RESPATH "icons/tomahawk-icon-128x128-grayscale.png" ); setIcon( icon ); @@ -43,15 +45,20 @@ TomahawkTrayIcon::TomahawkTrayIcon( QObject* parent ) m_contextMenu = new QMenu(); setContextMenu( m_contextMenu ); + + m_stopContinueAfterTrackAction = new QAction( tr( "&Stop Playback after this Track" ), this ); ActionCollection *ac = ActionCollection::instance(); m_contextMenu->addAction( ac->getAction( "playPause" ) ); m_contextMenu->addAction( ac->getAction( "stop" ) ); + m_contextMenu->addAction( m_stopContinueAfterTrackAction ); m_contextMenu->addSeparator(); m_contextMenu->addAction( ac->getAction( "previousTrack" ) ); m_contextMenu->addAction( ac->getAction( "nextTrack" ) ); m_contextMenu->addSeparator(); m_contextMenu->addAction( ActionCollection::instance()->getAction( "togglePrivacy" ) ); + + connect( m_stopContinueAfterTrackAction, SIGNAL( triggered(bool) ), this, SLOT( stopContinueAfterTrackActionTriggered() ) ); #ifdef Q_WS_MAC // On mac you can close the windows while leaving the app open. We then need a way to show the main window again @@ -71,6 +78,7 @@ TomahawkTrayIcon::TomahawkTrayIcon( QObject* parent ) connect( AudioEngine::instance(), SIGNAL( resumed() ), this, SLOT( enablePause() ) ); connect( AudioEngine::instance(), SIGNAL( stopped() ), this, SLOT( enablePlay() ) ); connect( AudioEngine::instance(), SIGNAL( paused() ), this, SLOT( enablePlay() ) ); + connect( AudioEngine::instance(), SIGNAL( stopContinueAfterTrack() ) , this, SLOT( stopContinueAfterTrackStatusChanged() ) ); connect( &m_animationTimer, SIGNAL( timeout() ), SLOT( onAnimationTimer() ) ); connect( this, SIGNAL( activated( QSystemTrayIcon::ActivationReason ) ), SLOT( onActivated( QSystemTrayIcon::ActivationReason ) ) ); @@ -227,6 +235,25 @@ TomahawkTrayIcon::enablePause() } +void +TomahawkTrayIcon::stopContinueAfterTrackStatusChanged() +{ + if ( AudioEngine::instance()->currentTrack()->toQuery()->equals( AudioEngine::instance()->stopAfterTrack() ) ) + m_stopContinueAfterTrackAction->setText( tr( "&Continue Playback after this Track" ) ); + else + m_stopContinueAfterTrackAction->setText( tr( "&Stop Playback after this Track" ) ); +} + + +void TomahawkTrayIcon::stopContinueAfterTrackActionTriggered() +{ + if ( !AudioEngine::instance()->currentTrack()->toQuery()->equals( AudioEngine::instance()->stopAfterTrack() ) ) + AudioEngine::instance()->setStopAfterTrack( AudioEngine::instance()->currentTrack()->toQuery() ); + else + AudioEngine::instance()->setStopAfterTrack( Tomahawk::query_ptr() ); +} + + bool TomahawkTrayIcon::event( QEvent* e ) { diff --git a/src/TomahawkTrayIcon.h b/src/TomahawkTrayIcon.h index ecd4d8e24..66d9f313b 100644 --- a/src/TomahawkTrayIcon.h +++ b/src/TomahawkTrayIcon.h @@ -46,6 +46,10 @@ private slots: void enablePlay(); void enablePause(); + + void stopContinueAfterTrackStatusChanged(); + + void stopContinueAfterTrackActionTriggered(); void menuAboutToShow(); private: @@ -61,6 +65,7 @@ private: QMenu* m_contextMenu; QAction* m_showWindowAction; + QAction* m_stopContinueAfterTrackAction; }; #endif // TOMAHAWK_TRAYICON_H diff --git a/src/libtomahawk/audio/AudioEngine.h b/src/libtomahawk/audio/AudioEngine.h index 5abdc207a..4187306f0 100644 --- a/src/libtomahawk/audio/AudioEngine.h +++ b/src/libtomahawk/audio/AudioEngine.h @@ -96,7 +96,7 @@ public slots: void setPlaylist( Tomahawk::playlistinterface_ptr playlist ); void setQueue( Tomahawk::playlistinterface_ptr queue ) { m_queue = queue; } - void setStopAfterTrack( const Tomahawk::query_ptr& query ) { m_stopAfterTrack = query; } + void setStopAfterTrack( const Tomahawk::query_ptr& query ) { m_stopAfterTrack = query; emit stopContinueAfterTrack(); } signals: void loading( const Tomahawk::result_ptr& track ); @@ -105,6 +105,8 @@ signals: void stopped(); void paused(); void resumed(); + + void stopContinueAfterTrack(); void seeked( qint64 ms ); From a191a7648bdaf8218aca411959ea325ec46c3e20 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Thu, 26 Apr 2012 14:08:00 +0200 Subject: [PATCH 2/5] Changed text from after this Track to after current Track, connect started signal with additional slot, check if current track is null --- src/TomahawkTrayIcon.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/TomahawkTrayIcon.cpp b/src/TomahawkTrayIcon.cpp index d3a87268b..c6b569a29 100644 --- a/src/TomahawkTrayIcon.cpp +++ b/src/TomahawkTrayIcon.cpp @@ -46,7 +46,7 @@ TomahawkTrayIcon::TomahawkTrayIcon( QObject* parent ) m_contextMenu = new QMenu(); setContextMenu( m_contextMenu ); - m_stopContinueAfterTrackAction = new QAction( tr( "&Stop Playback after this Track" ), this ); + m_stopContinueAfterTrackAction = new QAction( tr( "&Stop Playback after current Track" ), this ); ActionCollection *ac = ActionCollection::instance(); m_contextMenu->addAction( ac->getAction( "playPause" ) ); @@ -75,6 +75,7 @@ TomahawkTrayIcon::TomahawkTrayIcon( QObject* parent ) connect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), SLOT( setResult( Tomahawk::result_ptr ) ) ); connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( enablePause() ) ); + connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( stopContinueAfterTrackStatusChanged()) ); connect( AudioEngine::instance(), SIGNAL( resumed() ), this, SLOT( enablePause() ) ); connect( AudioEngine::instance(), SIGNAL( stopped() ), this, SLOT( enablePlay() ) ); connect( AudioEngine::instance(), SIGNAL( paused() ), this, SLOT( enablePlay() ) ); @@ -238,19 +239,25 @@ TomahawkTrayIcon::enablePause() void TomahawkTrayIcon::stopContinueAfterTrackStatusChanged() { - if ( AudioEngine::instance()->currentTrack()->toQuery()->equals( AudioEngine::instance()->stopAfterTrack() ) ) - m_stopContinueAfterTrackAction->setText( tr( "&Continue Playback after this Track" ) ); - else - m_stopContinueAfterTrackAction->setText( tr( "&Stop Playback after this Track" ) ); + if ( !AudioEngine::instance()->currentTrack().isNull() ) + { + if ( AudioEngine::instance()->currentTrack()->toQuery()->equals( AudioEngine::instance()->stopAfterTrack() ) ) + m_stopContinueAfterTrackAction->setText( tr( "&Continue Playback after current Track" ) ); + else + m_stopContinueAfterTrackAction->setText( tr( "&Stop Playback after current Track" ) ); + } } void TomahawkTrayIcon::stopContinueAfterTrackActionTriggered() { - if ( !AudioEngine::instance()->currentTrack()->toQuery()->equals( AudioEngine::instance()->stopAfterTrack() ) ) - AudioEngine::instance()->setStopAfterTrack( AudioEngine::instance()->currentTrack()->toQuery() ); - else - AudioEngine::instance()->setStopAfterTrack( Tomahawk::query_ptr() ); + if ( !AudioEngine::instance()->currentTrack().isNull() ) + { + if ( !AudioEngine::instance()->currentTrack()->toQuery()->equals( AudioEngine::instance()->stopAfterTrack() ) ) + AudioEngine::instance()->setStopAfterTrack( AudioEngine::instance()->currentTrack()->toQuery() ); + else + AudioEngine::instance()->setStopAfterTrack( Tomahawk::query_ptr() ); + } } From dab5d5195273413a379fd41026ad0e3eff78cf84 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Thu, 26 Apr 2012 23:08:47 +0200 Subject: [PATCH 3/5] rename slots & signals, disable Stop After Current Track in systray if track is stopped --- src/TomahawkTrayIcon.cpp | 34 +++++++++++++++++++++-------- src/TomahawkTrayIcon.h | 8 ++++--- src/libtomahawk/audio/AudioEngine.h | 4 ++-- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/TomahawkTrayIcon.cpp b/src/TomahawkTrayIcon.cpp index c6b569a29..4e46f7a41 100644 --- a/src/TomahawkTrayIcon.cpp +++ b/src/TomahawkTrayIcon.cpp @@ -74,12 +74,11 @@ TomahawkTrayIcon::TomahawkTrayIcon( QObject* parent ) m_contextMenu->addAction( ac->getAction( "quit" ) ); connect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), SLOT( setResult( Tomahawk::result_ptr ) ) ); - connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( enablePause() ) ); - connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( stopContinueAfterTrackStatusChanged()) ); - connect( AudioEngine::instance(), SIGNAL( resumed() ), this, SLOT( enablePause() ) ); - connect( AudioEngine::instance(), SIGNAL( stopped() ), this, SLOT( enablePlay() ) ); - connect( AudioEngine::instance(), SIGNAL( paused() ), this, SLOT( enablePlay() ) ); - connect( AudioEngine::instance(), SIGNAL( stopContinueAfterTrack() ) , this, SLOT( stopContinueAfterTrackStatusChanged() ) ); + connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( onPlay() ) ); + connect( AudioEngine::instance(), SIGNAL( resumed() ), this, SLOT( onResume() ) ); + connect( AudioEngine::instance(), SIGNAL( stopped() ), this, SLOT( onStop() ) ); + connect( AudioEngine::instance(), SIGNAL( paused() ), this, SLOT( onPause() ) ); + connect( AudioEngine::instance(), SIGNAL( stopAfterTrack_changed() ) , this, SLOT( stopContinueAfterTrack_StatusChanged() ) ); connect( &m_animationTimer, SIGNAL( timeout() ), SLOT( onAnimationTimer() ) ); connect( this, SIGNAL( activated( QSystemTrayIcon::ActivationReason ) ), SLOT( onActivated( QSystemTrayIcon::ActivationReason ) ) ); @@ -223,21 +222,38 @@ TomahawkTrayIcon::onActivated( QSystemTrayIcon::ActivationReason reason ) void -TomahawkTrayIcon::enablePlay() +TomahawkTrayIcon::onPause() { ActionCollection::instance()->getAction( "playPause" )->setText( tr( "Play" ) ); } void -TomahawkTrayIcon::enablePause() +TomahawkTrayIcon::onPlay() +{ + m_stopContinueAfterTrackAction->setEnabled( true ); + onResume(); + stopContinueAfterTrack_StatusChanged(); +} + + +void +TomahawkTrayIcon::onStop() +{ + m_stopContinueAfterTrackAction->setEnabled( false ); + onPause(); +} + + +void +TomahawkTrayIcon::onResume() { ActionCollection::instance()->getAction( "playPause" )->setText( tr( "Pause" ) ); } void -TomahawkTrayIcon::stopContinueAfterTrackStatusChanged() +TomahawkTrayIcon::stopContinueAfterTrack_StatusChanged() { if ( !AudioEngine::instance()->currentTrack().isNull() ) { diff --git a/src/TomahawkTrayIcon.h b/src/TomahawkTrayIcon.h index 66d9f313b..d1504e835 100644 --- a/src/TomahawkTrayIcon.h +++ b/src/TomahawkTrayIcon.h @@ -44,10 +44,12 @@ private slots: void onActivated( QSystemTrayIcon::ActivationReason reason ); void showWindow(); - void enablePlay(); - void enablePause(); + void onPause(); + void onPlay(); + void onStop(); + void onResume(); - void stopContinueAfterTrackStatusChanged(); + void stopContinueAfterTrack_StatusChanged(); void stopContinueAfterTrackActionTriggered(); diff --git a/src/libtomahawk/audio/AudioEngine.h b/src/libtomahawk/audio/AudioEngine.h index 4187306f0..56a194d6f 100644 --- a/src/libtomahawk/audio/AudioEngine.h +++ b/src/libtomahawk/audio/AudioEngine.h @@ -96,7 +96,7 @@ public slots: void setPlaylist( Tomahawk::playlistinterface_ptr playlist ); void setQueue( Tomahawk::playlistinterface_ptr queue ) { m_queue = queue; } - void setStopAfterTrack( const Tomahawk::query_ptr& query ) { m_stopAfterTrack = query; emit stopContinueAfterTrack(); } + void setStopAfterTrack( const Tomahawk::query_ptr& query ) { if ( m_stopAfterTrack != query ) { m_stopAfterTrack = query; emit stopAfterTrack_changed(); } } signals: void loading( const Tomahawk::result_ptr& track ); @@ -106,7 +106,7 @@ signals: void paused(); void resumed(); - void stopContinueAfterTrack(); + void stopAfterTrack_changed(); void seeked( qint64 ms ); From b92f7f551ea46a0401f8e31c219ad1e42930ac12 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Fri, 27 Apr 2012 13:29:18 +0200 Subject: [PATCH 4/5] move code from AudioEngine header to cpp file --- src/libtomahawk/audio/AudioEngine.cpp | 10 ++++++++++ src/libtomahawk/audio/AudioEngine.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/audio/AudioEngine.cpp b/src/libtomahawk/audio/AudioEngine.cpp index 08420d878..b11f64324 100644 --- a/src/libtomahawk/audio/AudioEngine.cpp +++ b/src/libtomahawk/audio/AudioEngine.cpp @@ -714,6 +714,16 @@ AudioEngine::setPlaylist( Tomahawk::playlistinterface_ptr playlist ) } +void +AudioEngine::setStopAfterTrack(const query_ptr& query) +{ + if ( m_stopAfterTrack != query ) + { + m_stopAfterTrack = query; emit stopAfterTrack_changed(); + } +} + + void AudioEngine::setCurrentTrack( const Tomahawk::result_ptr& result ) { diff --git a/src/libtomahawk/audio/AudioEngine.h b/src/libtomahawk/audio/AudioEngine.h index 56a194d6f..ab65fb522 100644 --- a/src/libtomahawk/audio/AudioEngine.h +++ b/src/libtomahawk/audio/AudioEngine.h @@ -96,7 +96,7 @@ public slots: void setPlaylist( Tomahawk::playlistinterface_ptr playlist ); void setQueue( Tomahawk::playlistinterface_ptr queue ) { m_queue = queue; } - void setStopAfterTrack( const Tomahawk::query_ptr& query ) { if ( m_stopAfterTrack != query ) { m_stopAfterTrack = query; emit stopAfterTrack_changed(); } } + void setStopAfterTrack( const Tomahawk::query_ptr& query ); signals: void loading( const Tomahawk::result_ptr& track ); From 6d6ca1e94a50b9f05de6bac9d08dca5d31711370 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 27 Apr 2012 10:37:16 -0400 Subject: [PATCH 5/5] fix style --- src/libtomahawk/Result.h | 2 +- src/libtomahawk/audio/AudioEngine.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libtomahawk/Result.h b/src/libtomahawk/Result.h index 54527aa52..be86e0157 100644 --- a/src/libtomahawk/Result.h +++ b/src/libtomahawk/Result.h @@ -120,7 +120,7 @@ signals: private slots: void onOffline(); void onOnline(); - + private: // private constructor explicit Result( const QString& url ); diff --git a/src/libtomahawk/audio/AudioEngine.cpp b/src/libtomahawk/audio/AudioEngine.cpp index b11f64324..26be43e3b 100644 --- a/src/libtomahawk/audio/AudioEngine.cpp +++ b/src/libtomahawk/audio/AudioEngine.cpp @@ -715,11 +715,12 @@ AudioEngine::setPlaylist( Tomahawk::playlistinterface_ptr playlist ) void -AudioEngine::setStopAfterTrack(const query_ptr& query) +AudioEngine::setStopAfterTrack( const query_ptr& query ) { if ( m_stopAfterTrack != query ) { - m_stopAfterTrack = query; emit stopAfterTrack_changed(); + m_stopAfterTrack = query; + emit stopAfterTrack_changed(); } }