1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 15:29:42 +01:00

Work towards latch actions -- need to debug corner cases

This commit is contained in:
Jeff Mitchell 2011-11-06 14:38:58 -05:00
parent f70f61ac2f
commit a1b3538131
8 changed files with 51 additions and 23 deletions

View File

@ -249,6 +249,7 @@ set( libHeaders
functimeout.h
aclsystem.h
actioncollection.h
collection.h
query.h
resolver.h

View File

@ -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" ) );
}

View File

@ -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 );
}

View File

@ -24,13 +24,14 @@
#include <QAction>
class DLLEXPORT ActionCollection
class DLLEXPORT ActionCollection : public QObject
{
Q_OBJECT
public:
static ActionCollection* instance();
ActionCollection();
ActionCollection( QObject *parent);
~ActionCollection();
void initActions();

View File

@ -700,6 +700,7 @@ AudioEngine::setPlaylist( PlaylistInterface* playlist )
if ( !playlist )
{
m_playlist.clear();
emit playlistChanged( playlist );
return;
}

View File

@ -28,6 +28,7 @@
#include <QSize>
#include <QFileDialog>
#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()
{

View File

@ -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:

View File

@ -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.";
}