mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 00:09:47 +01:00
Added timeout support to ScriptCommandQueue.
This commit is contained in:
parent
1c3941c16b
commit
3da3969ad2
@ -33,6 +33,7 @@ signals:
|
||||
protected:
|
||||
friend class ScriptCommandQueue;
|
||||
virtual void exec() = 0;
|
||||
virtual void reportFailure() = 0;
|
||||
};
|
||||
|
||||
#endif // SCRIPTCOMMAND_H
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 );
|
||||
|
@ -42,6 +42,7 @@ signals:
|
||||
|
||||
protected:
|
||||
virtual void exec();
|
||||
virtual void reportFailure();
|
||||
|
||||
private slots:
|
||||
void onResolverDone( const QList< Tomahawk::artist_ptr >& );
|
||||
|
Loading…
x
Reference in New Issue
Block a user