1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-03 12:47:45 +02:00

Fix sourcelist returning local source, and send stop listening along msg at right time

This commit is contained in:
Leo Franchi
2011-09-20 10:58:32 -04:00
parent 495fe05a75
commit 6c9c3ce7ec
4 changed files with 39 additions and 7 deletions

View File

@@ -22,6 +22,7 @@
#include "sourcelist.h" #include "sourcelist.h"
#include "JobStatusView.h" #include "JobStatusView.h"
#include "JobStatusModel.h" #include "JobStatusModel.h"
#include "utils/tomahawkutils.h"
LatchedStatusItem::LatchedStatusItem( const Tomahawk::source_ptr& from, const Tomahawk::source_ptr& to, LatchedStatusManager* parent ) LatchedStatusItem::LatchedStatusItem( const Tomahawk::source_ptr& from, const Tomahawk::source_ptr& to, LatchedStatusManager* parent )
: JobStatusItem() : 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( 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 ) ) ); 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 void

View File

@@ -188,6 +188,11 @@ SourceList::get( const QString& username, const QString& friendlyName )
QMutexLocker lock( &m_mut ); QMutexLocker lock( &m_mut );
source_ptr source; source_ptr source;
if ( Database::instance()->dbid() == username )
{
return m_local;
}
if ( !m_sources.contains( username ) ) if ( !m_sources.contains( username ) )
{ {
source = source_ptr( new Source( -1, username ) ); source = source_ptr( new Source( -1, username ) );

View File

@@ -99,6 +99,8 @@ SourceTreeView::SourceTreeView( QWidget* parent )
showOfflineSources( TomahawkSettings::instance()->showOfflineSources() ); showOfflineSources( TomahawkSettings::instance()->showOfflineSources() );
connect( AudioEngine::instance(), SIGNAL( playlistChanged( Tomahawk::PlaylistInterface* ) ), this, SLOT( playlistChanged( Tomahawk::PlaylistInterface* ) ) );
// Light-blue sourcetree on osx // Light-blue sourcetree on osx
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
setStyleSheet( "SourceTreeView:active { background: #DDE4EB; } " setStyleSheet( "SourceTreeView:active { background: #DDE4EB; } "
@@ -363,9 +365,30 @@ SourceTreeView::latchOn()
cmd->setTimestamp( QDateTime::currentDateTime().toTime_t() ); cmd->setTimestamp( QDateTime::currentDateTime().toTime_t() );
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
m_latch = source->getPlaylistInterface();
AudioEngine::instance()->playItem( source->getPlaylistInterface().data(), source->getPlaylistInterface()->nextItem() ); 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 void
SourceTreeView::latchOff() SourceTreeView::latchOff()
@@ -382,13 +405,6 @@ SourceTreeView::latchOff()
const CollectionItem* item = itemFromIndex< CollectionItem >( m_contextMenuIndex ); const CollectionItem* item = itemFromIndex< CollectionItem >( m_contextMenuIndex );
const source_ptr source = item->source(); 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() ); AudioEngine::instance()->playItem( source->getPlaylistInterface().data(), source->getPlaylistInterface()->nextItem() );

View File

@@ -19,9 +19,15 @@
#ifndef SOURCETREEVIEW_H #ifndef SOURCETREEVIEW_H
#define SOURCETREEVIEW_H #define SOURCETREEVIEW_H
#include "typedefs.h"
#include <QTreeView> #include <QTreeView>
#include <QMenu> #include <QMenu>
namespace Tomahawk {
class PlaylistInterface;
}
class CollectionModel; class CollectionModel;
class PlaylistModel; class PlaylistModel;
class SourcesModel; class SourcesModel;
@@ -59,6 +65,7 @@ private slots:
void latchOn(); void latchOn();
void latchOff(); void latchOff();
void playlistChanged( Tomahawk::PlaylistInterface* );
void onCustomContextMenu( const QPoint& pos ); void onCustomContextMenu( const QPoint& pos );
@@ -94,6 +101,7 @@ private:
QAction* m_addToLocalAction; QAction* m_addToLocalAction;
QAction* m_latchOnAction; QAction* m_latchOnAction;
QAction* m_latchOffAction; QAction* m_latchOffAction;
Tomahawk::playlistinterface_ptr m_latch;
bool m_dragging; bool m_dragging;
QRect m_dropRect; QRect m_dropRect;