From 6c9c3ce7ecaa50e94cfda145ca80e76c430a1ea6 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Tue, 20 Sep 2011 10:58:32 -0400 Subject: [PATCH] Fix sourcelist returning local source, and send stop listening along msg at right time --- src/libtomahawk/jobview/LatchedStatusItem.cpp | 3 ++ src/libtomahawk/sourcelist.cpp | 5 ++++ src/sourcetree/sourcetreeview.cpp | 30 ++++++++++++++----- src/sourcetree/sourcetreeview.h | 8 +++++ 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/libtomahawk/jobview/LatchedStatusItem.cpp b/src/libtomahawk/jobview/LatchedStatusItem.cpp index 2b50cd1e7..4041d2abe 100644 --- a/src/libtomahawk/jobview/LatchedStatusItem.cpp +++ b/src/libtomahawk/jobview/LatchedStatusItem.cpp @@ -22,6 +22,7 @@ #include "sourcelist.h" #include "JobStatusView.h" #include "JobStatusModel.h" +#include "utils/tomahawkutils.h" LatchedStatusItem::LatchedStatusItem( const Tomahawk::source_ptr& from, const Tomahawk::source_ptr& to, LatchedStatusManager* parent ) : JobStatusItem() @@ -64,6 +65,8 @@ LatchedStatusManager::LatchedStatusManager( QObject* parent ) { connect( SourceList::instance(), SIGNAL( sourceLatchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), this, SLOT( latchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) ); connect( SourceList::instance(), SIGNAL( sourceLatchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), this, SLOT( latchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) ); + + m_pixmap.load( RESPATH "images/headphones.png" ); } void diff --git a/src/libtomahawk/sourcelist.cpp b/src/libtomahawk/sourcelist.cpp index 7cc7fd54a..ffc9b72a4 100644 --- a/src/libtomahawk/sourcelist.cpp +++ b/src/libtomahawk/sourcelist.cpp @@ -188,6 +188,11 @@ SourceList::get( const QString& username, const QString& friendlyName ) QMutexLocker lock( &m_mut ); source_ptr source; + if ( Database::instance()->dbid() == username ) + { + return m_local; + } + if ( !m_sources.contains( username ) ) { source = source_ptr( new Source( -1, username ) ); diff --git a/src/sourcetree/sourcetreeview.cpp b/src/sourcetree/sourcetreeview.cpp index 3218c9347..16202a767 100644 --- a/src/sourcetree/sourcetreeview.cpp +++ b/src/sourcetree/sourcetreeview.cpp @@ -99,6 +99,8 @@ SourceTreeView::SourceTreeView( QWidget* parent ) showOfflineSources( TomahawkSettings::instance()->showOfflineSources() ); + connect( AudioEngine::instance(), SIGNAL( playlistChanged( Tomahawk::PlaylistInterface* ) ), this, SLOT( playlistChanged( Tomahawk::PlaylistInterface* ) ) ); + // Light-blue sourcetree on osx #ifdef Q_WS_MAC setStyleSheet( "SourceTreeView:active { background: #DDE4EB; } " @@ -363,9 +365,30 @@ SourceTreeView::latchOn() cmd->setTimestamp( QDateTime::currentDateTime().toTime_t() ); Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); + m_latch = source->getPlaylistInterface(); AudioEngine::instance()->playItem( source->getPlaylistInterface().data(), source->getPlaylistInterface()->nextItem() ); } +void +SourceTreeView::playlistChanged( PlaylistInterface* newInterface ) +{ + // If we were latched on and changed, send the listening along stop + if ( !m_latch.isNull() ) + { + SourcePlaylistInterface* sourcepi = dynamic_cast< SourcePlaylistInterface* >( m_latch.data() ); + Q_ASSERT( sourcepi ); + + const source_ptr source = sourcepi->source(); + DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction(); + cmd->setSource( SourceList::instance()->getLocal() ); + cmd->setAction( "latchOff"); + cmd->setComment( source->userName() ); + cmd->setTimestamp( QDateTime::currentDateTime().toTime_t() ); + Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); + + m_latch.clear(); + } +} void SourceTreeView::latchOff() @@ -382,13 +405,6 @@ SourceTreeView::latchOff() const CollectionItem* item = itemFromIndex< CollectionItem >( m_contextMenuIndex ); const source_ptr source = item->source(); - DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction(); - cmd->setSource( SourceList::instance()->getLocal() ); - cmd->setAction( "latchOff"); - cmd->setComment( source->userName() ); - cmd->setTimestamp( QDateTime::currentDateTime().toTime_t() ); - Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); - AudioEngine::instance()->playItem( source->getPlaylistInterface().data(), source->getPlaylistInterface()->nextItem() ); diff --git a/src/sourcetree/sourcetreeview.h b/src/sourcetree/sourcetreeview.h index 567259634..0259c19de 100644 --- a/src/sourcetree/sourcetreeview.h +++ b/src/sourcetree/sourcetreeview.h @@ -19,9 +19,15 @@ #ifndef SOURCETREEVIEW_H #define SOURCETREEVIEW_H +#include "typedefs.h" + #include #include +namespace Tomahawk { + class PlaylistInterface; +} + class CollectionModel; class PlaylistModel; class SourcesModel; @@ -59,6 +65,7 @@ private slots: void latchOn(); void latchOff(); + void playlistChanged( Tomahawk::PlaylistInterface* ); void onCustomContextMenu( const QPoint& pos ); @@ -94,6 +101,7 @@ private: QAction* m_addToLocalAction; QAction* m_latchOnAction; QAction* m_latchOffAction; + Tomahawk::playlistinterface_ptr m_latch; bool m_dragging; QRect m_dropRect;