diff --git a/src/libtomahawk/AclRegistry.cpp b/src/libtomahawk/AclRegistry.cpp index 66132a629..09e63cdc2 100644 --- a/src/libtomahawk/AclRegistry.cpp +++ b/src/libtomahawk/AclRegistry.cpp @@ -103,14 +103,14 @@ ACLRegistry::~ACLRegistry() ACLRegistry::ACL ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACLRegistry::ACL globalType, bool skipEmission ) { - tDebug() << Q_FUNC_INFO; + tLog() << Q_FUNC_INFO; if ( QThread::currentThread() != TOMAHAWK_APPLICATION::instance()->thread() ) { if ( !skipEmission ) QMetaObject::invokeMethod( this, "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( const QString&, dbid ), Q_ARG( const QString &, username ), Q_ARG( ACLRegistry::ACL, globalType ), Q_ARG( bool, skipEmission ) ); return ACLRegistry::NotFound; } - tDebug() << Q_FUNC_INFO << "in right thread"; + tLog() << Q_FUNC_INFO << "in right thread"; //FIXME: Remove when things are working // emit aclResult( dbid, username, ACLRegistry::Stream ); // return ACLRegistry::NotFound; @@ -176,35 +176,40 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL void ACLRegistry::getUserDecision( ACLRegistry::User user, const QString &username ) { - tDebug() << Q_FUNC_INFO; + tLog() << Q_FUNC_INFO; AclJobItem* job = new AclJobItem( user, username ); m_jobQueue.enqueue( job ); - queueNextJob(); + QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); } void ACLRegistry::userDecision( ACLRegistry::User user ) { - tDebug() << Q_FUNC_INFO; + tLog() << Q_FUNC_INFO; m_cache.append( user ); save(); emit aclResult( user.knownDbids.first(), user.knownAccountIds.first(), user.acl ); m_jobCount--; if ( !m_jobQueue.isEmpty() ) - queueNextJob(); + QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); } void ACLRegistry::queueNextJob() { - tDebug() << Q_FUNC_INFO << "jobCount = " << m_jobCount; + if ( QThread::currentThread() != TOMAHAWK_APPLICATION::instance()->thread() ) + { + QMetaObject::invokeMethod( this, "queueNextJob", Qt::QueuedConnection ); + return; + } + tLog() << Q_FUNC_INFO << "jobCount = " << m_jobCount; + tLog() << Q_FUNC_INFO << "jobQueue size = " << m_jobQueue.length(); if ( m_jobCount != 0 ) return; - tDebug() << Q_FUNC_INFO << "jobQueue size = " << m_jobQueue.length(); if ( !m_jobQueue.isEmpty() ) { AclJobItem* job = m_jobQueue.dequeue(); @@ -215,21 +220,21 @@ ACLRegistry::queueNextJob() ACLRegistry::ACL acl = isAuthorizedUser( dbid, job->username(), ACLRegistry::NotFound, true ); if ( acl != ACLRegistry::NotFound ) { - tDebug() << Q_FUNC_INFO << "Found existing acl entry for = " << user.knownAccountIds.first(); + tLog() << Q_FUNC_INFO << "Found existing acl entry for = " << user.knownAccountIds.first(); found = true; break; } } if ( found ) { - tDebug() << Q_FUNC_INFO << "deleting job, already have ACL for " << user.knownAccountIds.first(); + tLog() << Q_FUNC_INFO << "deleting job, already have ACL for " << user.knownAccountIds.first(); delete job; QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); return; } else { - tDebug() << Q_FUNC_INFO << "activating job for user" << user.knownAccountIds.first(); + tLog() << Q_FUNC_INFO << "activating job for user" << user.knownAccountIds.first(); m_jobCount++; JobStatusView::instance()->model()->addJob( job ); connect( job, SIGNAL( userDecision( ACLRegistry::User ) ), this, SLOT( userDecision( ACLRegistry::User ) ) ); @@ -243,13 +248,13 @@ ACLRegistry::queueNextJob() void ACLRegistry::load() { - tDebug() << Q_FUNC_INFO; + tLog() << Q_FUNC_INFO; QVariantList entryList = TomahawkSettings::instance()->aclEntries(); foreach ( QVariant entry, entryList ) { if ( !entry.isValid() || !entry.canConvert< ACLRegistry::User >() ) continue; - tDebug() << Q_FUNC_INFO << "loading entry"; + tLog() << Q_FUNC_INFO << "loading entry"; ACLRegistry::User entryUser = entry.value< ACLRegistry::User >(); if ( entryUser.knownAccountIds.empty() || entryUser.knownDbids.empty() ) continue; @@ -261,11 +266,11 @@ ACLRegistry::load() void ACLRegistry::save() { - tDebug() << Q_FUNC_INFO; + tLog() << Q_FUNC_INFO; QVariantList entryList; foreach ( ACLRegistry::User user, m_cache ) { - tDebug() << Q_FUNC_INFO << "user is " << user.uuid << " with known name " << user.knownAccountIds.first(); + tLog() << Q_FUNC_INFO << "user is " << user.uuid << " with known name " << user.knownAccountIds.first(); QVariant val = QVariant::fromValue< ACLRegistry::User >( user ); if ( val.isValid() ) entryList.append( val ); diff --git a/src/libtomahawk/jobview/AclJobItem.cpp b/src/libtomahawk/jobview/AclJobItem.cpp index b46232657..12a46bab1 100644 --- a/src/libtomahawk/jobview/AclJobItem.cpp +++ b/src/libtomahawk/jobview/AclJobItem.cpp @@ -40,6 +40,13 @@ AclJobDelegate::AclJobDelegate( QObject* parent ) : QStyledItemDelegate ( parent ) { + tLog() << Q_FUNC_INFO; +} + + +AclJobDelegate::~AclJobDelegate() +{ + tLog() << Q_FUNC_INFO; } @@ -148,17 +155,22 @@ AclJobItem::AclJobItem( ACLRegistry::User user, const QString &username ) , m_user( user ) , m_username( username ) { + tLog() << Q_FUNC_INFO; } AclJobItem::~AclJobItem() { + tLog() << Q_FUNC_INFO; + if ( m_delegate ) + delete m_delegate; } void AclJobItem::createDelegate( QObject* parent ) { + tLog() << Q_FUNC_INFO; if ( m_delegate ) return; @@ -179,15 +191,9 @@ AclJobDelegate::emitSizeHintChanged( const QModelIndex& index ) void AclJobItem::aclResult( ACLRegistry::ACL result ) { + tLog() << Q_FUNC_INFO; m_user.acl = result; emit userDecision( m_user ); - done(); -} - - -void -AclJobItem::done() -{ emit finished(); } diff --git a/src/libtomahawk/jobview/AclJobItem.h b/src/libtomahawk/jobview/AclJobItem.h index df6bd425a..d258ed1f3 100644 --- a/src/libtomahawk/jobview/AclJobItem.h +++ b/src/libtomahawk/jobview/AclJobItem.h @@ -33,7 +33,7 @@ class AclJobDelegate : public QStyledItemDelegate public: explicit AclJobDelegate ( QObject* parent = 0 ); - virtual ~AclJobDelegate() {} + virtual ~AclJobDelegate(); virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; @@ -63,8 +63,6 @@ public: explicit AclJobItem( ACLRegistry::User user, const QString &username ); virtual ~AclJobItem(); - void done(); - virtual QString rightColumnText() const { return QString(); } virtual QString mainText() const { return QString(); } virtual QPixmap icon() const { return QPixmap(); } diff --git a/src/libtomahawk/jobview/JobStatusModel.cpp b/src/libtomahawk/jobview/JobStatusModel.cpp index e3ec86e9a..28e1ce36c 100644 --- a/src/libtomahawk/jobview/JobStatusModel.cpp +++ b/src/libtomahawk/jobview/JobStatusModel.cpp @@ -41,6 +41,7 @@ JobStatusModel::~JobStatusModel() void JobStatusModel::addJob( JobStatusItem* item ) { + tLog() << Q_FUNC_INFO << "current jobs of item type: " << m_jobTypeCount[ item->type() ] << ", current queue size of item type: " << m_jobQueue[ item->type() ].size(); if ( item->concurrentJobLimit() > 0 ) { if ( m_jobTypeCount[ item->type() ] >= item->concurrentJobLimit() ) @@ -53,6 +54,8 @@ JobStatusModel::addJob( JobStatusItem* item ) m_jobTypeCount[ item->type() ] = currentJobCount; } + tLog() << Q_FUNC_INFO << "new current jobs of item type: " << m_jobTypeCount[ item->type() ]; + connect( item, SIGNAL( statusChanged() ), SLOT( itemUpdated() ) ); connect( item, SIGNAL( finished() ), SLOT( itemFinished() ) ); @@ -70,7 +73,7 @@ JobStatusModel::addJob( JobStatusItem* item ) } } - qDebug() << "Adding item:" << item; + tLog() << Q_FUNC_INFO << "Adding item:" << item; int currentEndRow = m_items.count(); beginInsertRows( QModelIndex(), currentEndRow, currentEndRow ); @@ -79,7 +82,7 @@ JobStatusModel::addJob( JobStatusItem* item ) if ( item->hasCustomDelegate() ) { - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "job has custom delegate"; + tLog() << Q_FUNC_INFO << "job has custom delegate"; emit customDelegateJobInserted( currentEndRow, item ); } } @@ -200,6 +203,8 @@ JobStatusModel::itemFinished() if ( item->customDelegate() ) emit customDelegateJobRemoved( idx ); + + tLog() << Q_FUNC_INFO << "current jobs of item type: " << m_jobTypeCount[ item->type() ] << ", current queue size of item type: " << m_jobQueue[ item->type() ].size(); if ( item->concurrentJobLimit() > 0 ) { int currentJobs = m_jobTypeCount[ item->type() ]; diff --git a/src/libtomahawk/jobview/JobStatusView.cpp b/src/libtomahawk/jobview/JobStatusView.cpp index 4555ae73f..393b47ba3 100644 --- a/src/libtomahawk/jobview/JobStatusView.cpp +++ b/src/libtomahawk/jobview/JobStatusView.cpp @@ -100,22 +100,24 @@ JobStatusView::setModel( JobStatusModel* m ) void JobStatusView::customDelegateJobInserted( int row, JobStatusItem* item ) { - tDebug( LOGVERBOSE ) << Q_FUNC_INFO; + tLog() << Q_FUNC_INFO << "item is " << item << ", row is " << row; if ( !item ) return; - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "telling item to create delegate"; + tLog() << Q_FUNC_INFO << "telling item to create delegate"; item->createDelegate( m_view ); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "item delegate is " << item->customDelegate(); + tLog() << Q_FUNC_INFO << "item delegate is " << item->customDelegate(); m_view->setItemDelegateForRow( row, item->customDelegate() ); - m_customDelegateRefCounter[ row ] = m_customDelegateRefCounter[ row ] + 1; AclJobDelegate* delegate = qobject_cast< AclJobDelegate* >( item->customDelegate() ); if ( delegate ) { + tLog() << Q_FUNC_INFO << "delegate found"; connect( delegate, SIGNAL( update( const QModelIndex& ) ), m_view, SLOT( update( const QModelIndex & ) ) ); connect( delegate, SIGNAL( aclResult( ACLRegistry::ACL ) ), item, SLOT( aclResult( ACLRegistry::ACL ) ) ); delegate->emitSizeHintChanged( m_model->index( row ) ); } + else + tLog() << Q_FUNC_INFO << "delegate was not properly found!"; checkCount(); } @@ -124,9 +126,24 @@ JobStatusView::customDelegateJobInserted( int row, JobStatusItem* item ) void JobStatusView::customDelegateJobRemoved( int row ) { - if ( m_customDelegateRefCounter[ row ] == 1 ) - m_view->setItemDelegateForRow( row, m_view->itemDelegate() ); - m_customDelegateRefCounter[ row ] = m_customDelegateRefCounter[ row ] - 1; + tLog() << Q_FUNC_INFO << "row is " << row; + int count = m_model->rowCount(); + for ( int i = 0; i < count; i++ ) + { + tLog() << Q_FUNC_INFO << "checking row " << i; + QModelIndex index = m_model->index( i ); + QVariant itemVar = index.data( JobStatusModel::JobDataRole ); + if ( !itemVar.canConvert< JobStatusItem* >() || !itemVar.value< JobStatusItem* >() ) + { + tLog() << Q_FUNC_INFO << "unable to fetch JobStatusItem* at row " << i; + continue; + } + JobStatusItem* item = itemVar.value< JobStatusItem* >(); + if ( item->hasCustomDelegate() ) + m_view->setItemDelegateForRow( i, item->customDelegate() ); + else + m_view->setItemDelegateForRow( i, m_view->itemDelegate() ); + } checkCount(); } diff --git a/src/libtomahawk/jobview/JobStatusView.h b/src/libtomahawk/jobview/JobStatusView.h index 43b5a398a..1a5edf665 100644 --- a/src/libtomahawk/jobview/JobStatusView.h +++ b/src/libtomahawk/jobview/JobStatusView.h @@ -61,7 +61,6 @@ private: JobStatusModel* m_model; AnimatedSplitter* m_parent; mutable int m_cachedHeight; - QHash< int, int > m_customDelegateRefCounter; static JobStatusView* s_instance; };