From 78ad724bac38433dc392d26b1253ce5da4370675 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 23 Jan 2012 16:14:33 -0500 Subject: [PATCH] Clean up some sourceplaylistinterface logic to hopefully prevent it saying that a track couldn't be resolved when it gets resolved right afterwards. Also, have the latch mode changing (for instance on pause) affect the source's icon. --- src/libtomahawk/audio/audioengine.cpp | 15 ++++++---- src/libtomahawk/audio/audioengine.h | 5 +++- src/libtomahawk/playlistinterface.h | 1 + src/libtomahawk/sourceplaylistinterface.cpp | 33 ++++++++++++++------- src/libtomahawk/sourceplaylistinterface.h | 3 ++ src/sourcetree/items/sourceitem.cpp | 11 ++++++- src/sourcetree/items/sourceitem.h | 1 + src/tomahawkapp.cpp | 4 ++- 8 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/libtomahawk/audio/audioengine.cpp b/src/libtomahawk/audio/audioengine.cpp index ac67dc80d..226d99a3f 100644 --- a/src/libtomahawk/audio/audioengine.cpp +++ b/src/libtomahawk/audio/audioengine.cpp @@ -74,6 +74,8 @@ AudioEngine::AudioEngine() connect( m_audioOutput, SIGNAL( volumeChanged( qreal ) ), SLOT( onVolumeChanged( qreal ) ) ); + connect( this, SIGNAL( sendWaitingNotification() ), SLOT( sendWaitingNotificationSlot() ), Qt::QueuedConnection ); + onVolumeChanged( m_audioOutput->volume() ); #ifndef Q_WS_X11 @@ -178,9 +180,7 @@ AudioEngine::stop() map[ Tomahawk::InfoSystem::InfoNowStopped ] = QVariant(); if ( m_waitingOnNewTrack ) - { - sendWaitingNotification(); - } + emit sendWaitingNotification(); else if ( TomahawkSettings::instance()->verboseNotifications() ) { QVariantMap stopInfo; @@ -310,8 +310,13 @@ AudioEngine::mute() void -AudioEngine::sendWaitingNotification() const +AudioEngine::sendWaitingNotificationSlot() const { + tDebug( LOGVERBOSE ) << Q_FUNC_INFO; + //since it's async, after this is triggered our result could come in, so don't show the popup in that case + if ( !m_playlist.isNull() && m_playlist->hasNextItem() ) + return; + QVariantMap retryInfo; retryInfo["message"] = QString( "The current track could not be resolved. Tomahawk will pick back up with the next resolvable track from this source." ); Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( @@ -538,7 +543,7 @@ AudioEngine::playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk: { m_waitingOnNewTrack = true; if ( isStopped() ) - sendWaitingNotification(); + emit sendWaitingNotification(); else stop(); } diff --git a/src/libtomahawk/audio/audioengine.h b/src/libtomahawk/audio/audioengine.h index 995440d2d..839f6f11d 100644 --- a/src/libtomahawk/audio/audioengine.h +++ b/src/libtomahawk/audio/audioengine.h @@ -112,6 +112,8 @@ signals: void error( AudioEngine::AudioErrorCode errorCode ); + void sendWaitingNotification(); + private slots: bool loadTrack( const Tomahawk::result_ptr& result ); void loadPreviousTrack(); @@ -126,13 +128,14 @@ private slots: void onNowPlayingInfoReady(); void onPlaylistNextTrackReady(); + void sendWaitingNotificationSlot() const; + private: void setState( AudioState state ); bool isHttpResult( const QString& ) const; bool isLocalResult( const QString& ) const; - void sendWaitingNotification() const; void sendNowPlayingNotification(); QSharedPointer m_input; diff --git a/src/libtomahawk/playlistinterface.h b/src/libtomahawk/playlistinterface.h index 45350b9e1..8f172a809 100644 --- a/src/libtomahawk/playlistinterface.h +++ b/src/libtomahawk/playlistinterface.h @@ -89,6 +89,7 @@ signals: void shuffleModeChanged( bool enabled ); void trackCountChanged( unsigned int tracks ); void sourceTrackCountChanged( unsigned int tracks ); + void latchModeChanged( Tomahawk::PlaylistInterface::LatchMode mode ); void nextTrackReady(); protected: diff --git a/src/libtomahawk/sourceplaylistinterface.cpp b/src/libtomahawk/sourceplaylistinterface.cpp index d6108563d..d3ef4f011 100644 --- a/src/libtomahawk/sourceplaylistinterface.cpp +++ b/src/libtomahawk/sourceplaylistinterface.cpp @@ -61,15 +61,15 @@ Tomahawk::result_ptr SourcePlaylistInterface::nextItem() { tDebug( LOGEXTRA ) << Q_FUNC_INFO; - if ( m_source.isNull() || m_source.data()->currentTrack().isNull() || m_source.data()->currentTrack()->results().isEmpty() ) + if ( !sourceValid() ) { - tDebug( LOGEXTRA ) << Q_FUNC_INFO << " Results were empty for current track or source no longer valid"; + tDebug( LOGEXTRA ) << Q_FUNC_INFO << " Source no longer valid"; m_currentItem = Tomahawk::result_ptr(); return m_currentItem; } - else if ( !m_gotNextItem ) + else if ( !hasNextItem() ) { - tDebug( LOGEXTRA ) << Q_FUNC_INFO << " This song was already fetched"; + tDebug( LOGEXTRA ) << Q_FUNC_INFO << " This song was already fetched or the source isn't playing anything"; return Tomahawk::result_ptr(); } @@ -87,12 +87,22 @@ SourcePlaylistInterface::currentItem() const bool -SourcePlaylistInterface::hasNextItem() +SourcePlaylistInterface::sourceValid() { tDebug( LOGEXTRA ) << Q_FUNC_INFO; - if ( m_source.isNull() || m_source.data()->currentTrack().isNull() || m_source.data()->currentTrack()->results().isEmpty() ) + if ( m_source.isNull() || m_source.data()->currentTrack().isNull() ) return false; + return true; +} + + +bool +SourcePlaylistInterface::hasNextItem() +{ + if ( !sourceValid() ) + return false; + return m_gotNextItem; } @@ -115,10 +125,10 @@ SourcePlaylistInterface::source() const void SourcePlaylistInterface::reset() { - if ( !m_currentItem.isNull() ) - m_gotNextItem = true; - else + if ( m_currentItem.isNull() ) m_gotNextItem = false; + else + m_gotNextItem = true; } @@ -128,7 +138,7 @@ SourcePlaylistInterface::onSourcePlaybackStarted( const Tomahawk::query_ptr& que tDebug( LOGEXTRA ) << Q_FUNC_INFO; connect( query.data(), SIGNAL( resolvingFinished( bool ) ), SLOT( resolvingFinished( bool ) ) ); Pipeline::instance()->resolve( query, true ); - m_gotNextItem = true; + m_gotNextItem = false; } @@ -137,5 +147,8 @@ SourcePlaylistInterface::resolvingFinished( bool hasResults ) { tDebug( LOGEXTRA ) << Q_FUNC_INFO << " and has results? : " << (hasResults ? "true" : "false"); if ( hasResults ) + { + m_gotNextItem = true; emit nextTrackReady(); + } } diff --git a/src/libtomahawk/sourceplaylistinterface.h b/src/libtomahawk/sourceplaylistinterface.h index 40420831a..0e72632a8 100644 --- a/src/libtomahawk/sourceplaylistinterface.h +++ b/src/libtomahawk/sourceplaylistinterface.h @@ -44,6 +44,7 @@ public: virtual int unfilteredTrackCount() const { return 1; } virtual Tomahawk::result_ptr siblingItem( int itemsAway ); + virtual bool sourceValid(); virtual bool hasNextItem(); virtual Tomahawk::result_ptr nextItem(); virtual Tomahawk::result_ptr currentItem() const; @@ -54,6 +55,8 @@ public: virtual PlaylistInterface::RetryMode retryMode() const { return Retry; } virtual quint32 retryInterval() const { return 5000; } + virtual void setLatchMode( PlaylistInterface::LatchMode latchMode ) { m_latchMode = latchMode; emit latchModeChanged( latchMode ); } + virtual bool shuffled() const { return false; } virtual void setFilter( const QString& /*pattern*/ ) {} diff --git a/src/sourcetree/items/sourceitem.cpp b/src/sourcetree/items/sourceitem.cpp index 202c2691b..f4084b38e 100644 --- a/src/sourcetree/items/sourceitem.cpp +++ b/src/sourcetree/items/sourceitem.cpp @@ -108,7 +108,7 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw SLOT( onAutoPlaylistsAdded( QList ) ), Qt::QueuedConnection ); connect( source->collection().data(), SIGNAL( stationsAdded( QList ) ), SLOT( onStationsAdded( QList ) ), Qt::QueuedConnection ); - + if ( m_source->isLocal() ) QTimer::singleShot( 0, this, SLOT( requestExpanding() ) ); } @@ -209,6 +209,7 @@ SourceItem::latchedOff( const source_ptr& from, const source_ptr& to ) if ( from->isLocal() && ( m_source == to || m_source == from ) ) { m_latchedOn = false; + disconnect( m_latchedOnTo->playlistInterface().data(), SIGNAL( latchModeChanged( Tomahawk::PlaylistInterface::LatchMode ) ) ); m_latchedOnTo.clear(); emit updated(); } @@ -222,11 +223,19 @@ SourceItem::latchedOn( const source_ptr& from, const source_ptr& to ) { m_latchedOn = true; m_latchedOnTo = to; + connect( m_latchedOnTo->playlistInterface().data(), SIGNAL( latchModeChanged( Tomahawk::PlaylistInterface::LatchMode ) ), SLOT( latchModeChanged( Tomahawk::PlaylistInterface::LatchMode ) ) ); emit updated(); } } +void +SourceItem::latchModeChanged( Tomahawk::PlaylistInterface::LatchMode mode ) +{ + Q_UNUSED( mode ); + emit updated(); +} + void SourceItem::playlistsAddedInternal( SourceTreeItem* parent, const QList< dynplaylist_ptr >& playlists ) diff --git a/src/sourcetree/items/sourceitem.h b/src/sourcetree/items/sourceitem.h index da1d9cd27..4aa84443d 100644 --- a/src/sourcetree/items/sourceitem.h +++ b/src/sourcetree/items/sourceitem.h @@ -64,6 +64,7 @@ private slots: void latchedOn( const Tomahawk::source_ptr&, const Tomahawk::source_ptr& ); void latchedOff( const Tomahawk::source_ptr&, const Tomahawk::source_ptr& ); + void latchModeChanged( Tomahawk::PlaylistInterface::LatchMode mode ); void requestExpanding(); diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index 4be288d36..900ca7cfc 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -422,10 +422,12 @@ TomahawkApp::registerMetaTypes() qRegisterMetaType< Tomahawk::InfoSystem::InfoType >( "Tomahawk::InfoSystem::InfoType" ); qRegisterMetaType< Tomahawk::InfoSystem::InfoRequestData >( "Tomahawk::InfoSystem::InfoRequestData" ); qRegisterMetaType< Tomahawk::InfoSystem::InfoSystemCache* >( "Tomahawk::InfoSystem::InfoSystemCache*" ); - qRegisterMetaType< QList< Tomahawk::InfoSystem::InfoStringHash > >("QList< Tomahawk::InfoSystem::InfoStringHash > "); + qRegisterMetaTypeStreamOperators< QList< Tomahawk::InfoSystem::InfoStringHash > >("QList< Tomahawk::InfoSystem::InfoStringHash > "); qRegisterMetaType< QPersistentModelIndex >( "QPersistentModelIndex" ); + + qRegisterMetaType< Tomahawk::PlaylistInterface::LatchMode >( "Tomahawk::PlaylistInterface::LatchMode" ); }