diff --git a/src/libtomahawk/jobview/JobStatusItem.h b/src/libtomahawk/jobview/JobStatusItem.h index e81aad32e..2f63415b7 100644 --- a/src/libtomahawk/jobview/JobStatusItem.h +++ b/src/libtomahawk/jobview/JobStatusItem.h @@ -20,6 +20,7 @@ #define JOB_STATUS_ITEM #include +#include class QStyledItemDelegate; class QPixmap; @@ -67,4 +68,6 @@ signals: void finished(); }; +Q_DECLARE_METATYPE( JobStatusItem* ); + #endif diff --git a/src/libtomahawk/jobview/JobStatusModel.cpp b/src/libtomahawk/jobview/JobStatusModel.cpp index 81c664f15..7c92a24b0 100644 --- a/src/libtomahawk/jobview/JobStatusModel.cpp +++ b/src/libtomahawk/jobview/JobStatusModel.cpp @@ -26,6 +26,7 @@ JobStatusModel::JobStatusModel( QObject* parent ) : QAbstractListModel ( parent ) + , m_aclJobCount( 0 ) { } @@ -41,6 +42,12 @@ JobStatusModel::~JobStatusModel() void JobStatusModel::addJob( JobStatusItem* item ) { + if ( item->type() == "acljob" && m_aclJobCount >= 3 ) + { + m_aclJobQueue.enqueue( item ); + return; + } + connect( item, SIGNAL( statusChanged() ), this, SLOT( itemUpdated() ) ); connect( item, SIGNAL( finished() ), this, SLOT( itemFinished() ) ); @@ -174,7 +181,19 @@ JobStatusModel::itemFinished() m_items.removeAll( item ); endRemoveRows(); + if ( item->customDelegate() ) + emit customDelegateJobRemoved( idx, item->customDelegate() ); + + if ( item->type() == "acljob" ) + m_aclJobCount--; + item->deleteLater(); + + if ( !m_aclJobQueue.empty() ) + { + JobStatusItem* item = m_aclJobQueue.dequeue(); + QMetaObject::invokeMethod( this, "addJob", Qt::QueuedConnection, Q_ARG( JobStatusItem*, item ) ); + } } diff --git a/src/libtomahawk/jobview/JobStatusModel.h b/src/libtomahawk/jobview/JobStatusModel.h index fe592e547..d3e179066 100644 --- a/src/libtomahawk/jobview/JobStatusModel.h +++ b/src/libtomahawk/jobview/JobStatusModel.h @@ -22,6 +22,7 @@ #include "dllmacro.h" #include +#include class QStyledItemDelegate; class JobStatusItem; @@ -44,11 +45,13 @@ public: virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const; virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const; - /// Takes ownership of job - void addJob( JobStatusItem* item ); - signals: void customDelegateJobInserted( int row, QStyledItemDelegate* delegate ); + void customDelegateJobRemoved( int row, QStyledItemDelegate* delegate ); + +public slots: + /// Takes ownership of job + void addJob( JobStatusItem* item ); private slots: void itemUpdated(); @@ -57,6 +60,8 @@ private slots: private: QList< JobStatusItem* > m_items; QHash< QString, QList< JobStatusItem* > > m_collapseCount; + QQueue< JobStatusItem* > m_aclJobQueue; + int m_aclJobCount; }; #endif // JOBSTATUSMODEL_H diff --git a/src/libtomahawk/jobview/JobStatusView.cpp b/src/libtomahawk/jobview/JobStatusView.cpp index 2b838feda..bd6151b8a 100644 --- a/src/libtomahawk/jobview/JobStatusView.cpp +++ b/src/libtomahawk/jobview/JobStatusView.cpp @@ -87,6 +87,7 @@ JobStatusView::setModel( JobStatusModel* m ) connect( m_view->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( checkCount() ) ); connect( m_view->model(), SIGNAL( modelReset() ), this, SLOT( checkCount() ) ); connect( m_view->model(), SIGNAL( customDelegateJobInserted( int, QStyledItemDelegate* ) ), this, SLOT( customDelegateJobInserted( int, QStyledItemDelegate* ) ) ); + connect( m_view->model(), SIGNAL( customDelegateJobRemoved( int, QStyledItemDelegate* ) ), this, SLOT( customDelegateJobRemoved( int, QStyledItemDelegate* ) ) ); } @@ -100,6 +101,16 @@ JobStatusView::customDelegateJobInserted( int row, QStyledItemDelegate* delegate } +void +JobStatusView::customDelegateJobRemoved( int row, QStyledItemDelegate* delegate ) +{ + if ( !delegate ) + return; + + m_view->setItemDelegateForRow( row, m_view->itemDelegate() ); +} + + void JobStatusView::checkCount() { diff --git a/src/libtomahawk/jobview/JobStatusView.h b/src/libtomahawk/jobview/JobStatusView.h index 466cae125..19ccb55a7 100644 --- a/src/libtomahawk/jobview/JobStatusView.h +++ b/src/libtomahawk/jobview/JobStatusView.h @@ -53,6 +53,7 @@ public: private slots: void checkCount(); void customDelegateJobInserted( int row, QStyledItemDelegate* delegate ); + void customDelegateJobRemoved( int row, QStyledItemDelegate* delegate ); private: QListView* m_view;