diff --git a/src/libtomahawk/resolvers/ScriptCommand.h b/src/libtomahawk/resolvers/ScriptCommand.h index 13717c825..60ae4db7c 100644 --- a/src/libtomahawk/resolvers/ScriptCommand.h +++ b/src/libtomahawk/resolvers/ScriptCommand.h @@ -33,6 +33,7 @@ signals: protected: friend class ScriptCommandQueue; virtual void exec() = 0; + virtual void reportFailure() = 0; }; #endif // SCRIPTCOMMAND_H diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp index edf312bcb..6fb42ccbd 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp @@ -27,7 +27,6 @@ ScriptCommandQueue::ScriptCommandQueue( QObject* parent ) , m_timer( new QTimer( this ) ) { m_timer->setSingleShot( true ); - connect( m_timer, SIGNAL( timeout() ), SLOT( onTimeout() ) ); } @@ -51,6 +50,11 @@ ScriptCommandQueue::nextCommand() NewClosure( req.data(), SIGNAL( done() ), this, SLOT( onCommandDone( QSharedPointer< ScriptCommand > ) ), req ); + NewClosure( m_timer, SIGNAL( timeout() ), + this, SLOT( onTimeout( QSharedPointer< ScriptCommand > ) ), req ); + + m_timer->start( 2000 ); + req->exec(); } @@ -58,8 +62,28 @@ ScriptCommandQueue::nextCommand() void ScriptCommandQueue::onCommandDone( const QSharedPointer< ScriptCommand >& req ) { + disconnect( this, SLOT( onTimeout( QSharedPointer< ScriptCommand > ) ) ); + m_timer->stop(); + m_queue.removeAll( req ); req->deleteLater(); + + if ( m_queue.count() > 0 ) + nextCommand(); +} + + +void +ScriptCommandQueue::onTimeout( const QSharedPointer< ScriptCommand >& req ) +{ + disconnect( this, SLOT( onCommandDone( QSharedPointer< ScriptCommand > ) ) ); + + m_timer->stop(); + + m_queue.removeAll( req ); + req->reportFailure(); + req->deleteLater(); + if ( m_queue.count() > 0 ) nextCommand(); } diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.h b/src/libtomahawk/resolvers/ScriptCommandQueue.h index bd7ae2d41..c26aabc95 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.h +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.h @@ -31,12 +31,14 @@ class ScriptCommandQueue : public QObject Q_OBJECT public: explicit ScriptCommandQueue( QObject* parent = 0 ); + virtual ~ScriptCommandQueue() {} void enqueue( const QSharedPointer< ScriptCommand >& req ); private slots: void nextCommand(); void onCommandDone( const QSharedPointer< ScriptCommand >& req ); + void onTimeout( const QSharedPointer< ScriptCommand >& req ); private: QQueue< QSharedPointer< ScriptCommand > > m_queue; diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp index c949d672d..ec90c0a09 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp +++ b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp @@ -60,6 +60,14 @@ ScriptCommand_AllArtists::exec() } +void +ScriptCommand_AllArtists::reportFailure() +{ + emit artists( QList< Tomahawk::artist_ptr >() ); + emit done(); +} + + void ScriptCommand_AllArtists::onResolverDone( const QList< Tomahawk::artist_ptr >& a ) { emit artists( a ); diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h index 051d30001..d5adcb755 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h +++ b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h @@ -42,6 +42,7 @@ signals: protected: virtual void exec(); + virtual void reportFailure(); private slots: void onResolverDone( const QList< Tomahawk::artist_ptr >& );