mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-13 20:39:57 +01:00
Make job counting generic
This commit is contained in:
parent
0b796a3085
commit
eb0ed267fa
@ -45,6 +45,13 @@ JobStatusItem::collapseItem() const
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
JobStatusItem::concurrentJobLimit() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
JobStatusItem::hasCustomDelegate() const
|
||||
{
|
||||
|
@ -58,6 +58,8 @@ public:
|
||||
virtual bool collapseItem() const;
|
||||
virtual bool allowMultiLine() const;
|
||||
|
||||
virtual int concurrentJobLimit() const;
|
||||
|
||||
virtual bool hasCustomDelegate() const;
|
||||
virtual void createDelegate( QObject* parent );
|
||||
virtual QStyledItemDelegate* customDelegate() const;
|
||||
|
@ -26,7 +26,6 @@
|
||||
|
||||
JobStatusModel::JobStatusModel( QObject* parent )
|
||||
: QAbstractListModel ( parent )
|
||||
, m_aclJobCount( 0 )
|
||||
{
|
||||
|
||||
}
|
||||
@ -42,12 +41,19 @@ JobStatusModel::~JobStatusModel()
|
||||
void
|
||||
JobStatusModel::addJob( JobStatusItem* item )
|
||||
{
|
||||
if ( item->type() == "acljob" && m_aclJobCount >= 3 )
|
||||
if ( item->concurrentJobLimit() > 0 )
|
||||
{
|
||||
m_aclJobQueue.enqueue( item );
|
||||
return;
|
||||
if ( m_jobTypeCount[ item->type() ] >= item->concurrentJobLimit() )
|
||||
{
|
||||
m_jobQueue[ item->type() ].enqueue( item );
|
||||
return;
|
||||
}
|
||||
int currentJobCount = m_jobTypeCount[ item->type() ];
|
||||
currentJobCount++;
|
||||
m_jobTypeCount[ item->type() ] = currentJobCount;
|
||||
}
|
||||
|
||||
|
||||
connect( item, SIGNAL( statusChanged() ), this, SLOT( itemUpdated() ) );
|
||||
connect( item, SIGNAL( finished() ), this, SLOT( itemFinished() ) );
|
||||
|
||||
@ -184,16 +190,20 @@ JobStatusModel::itemFinished()
|
||||
if ( item->customDelegate() )
|
||||
emit customDelegateJobRemoved( idx );
|
||||
|
||||
if ( item->type() == "acljob" )
|
||||
m_aclJobCount--;
|
||||
|
||||
item->deleteLater();
|
||||
|
||||
if ( !m_aclJobQueue.empty() )
|
||||
if ( item->concurrentJobLimit() > 0 )
|
||||
{
|
||||
JobStatusItem* item = m_aclJobQueue.dequeue();
|
||||
QMetaObject::invokeMethod( this, "addJob", Qt::QueuedConnection, Q_ARG( JobStatusItem*, item ) );
|
||||
int currentJobs = m_jobTypeCount[ item->type() ];
|
||||
currentJobs--;
|
||||
m_jobTypeCount[ item->type() ] = currentJobs;
|
||||
|
||||
if ( !m_jobQueue[ item->type() ].isEmpty() )
|
||||
{
|
||||
JobStatusItem* item = m_jobQueue[ item->type() ].dequeue();
|
||||
QMetaObject::invokeMethod( this, "addJob", Qt::QueuedConnection, Q_ARG( JobStatusItem*, item ) );
|
||||
}
|
||||
}
|
||||
|
||||
item->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
|
@ -60,8 +60,8 @@ private slots:
|
||||
private:
|
||||
QList< JobStatusItem* > m_items;
|
||||
QHash< QString, QList< JobStatusItem* > > m_collapseCount;
|
||||
QQueue< JobStatusItem* > m_aclJobQueue;
|
||||
int m_aclJobCount;
|
||||
QHash< QString, QQueue< JobStatusItem* > > m_jobQueue;
|
||||
QHash< QString, int > m_jobTypeCount;
|
||||
};
|
||||
|
||||
#endif // JOBSTATUSMODEL_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user