SVN commit 1214217 by skelly: React to notifications of agent removal before handling removal of individual collections. M +1 -0 entitytreemodel.h M +27 -0 entitytreemodel_p.cpp M +2 -0 entitytreemodel_p.h --- trunk/KDE/kdepimlibs/akonadi/entitytreemodel.h #1214216:1214217 @@ -662,6 +662,7 @@ Q_PRIVATE_SLOT( d_func(), void changeFetchState( const Akonadi::Collection & ) ) Q_PRIVATE_SLOT( d_func(), void agentInstanceAdvancedStatusChanged( const QString&, const QVariantMap& ) ) + Q_PRIVATE_SLOT( d_func(), void agentInstanceRemoved( Akonadi::AgentInstance ) ) //@endcond }; --- trunk/KDE/kdepimlibs/akonadi/entitytreemodel_p.cpp #1214216:1214217 @@ -81,6 +81,11 @@ QObject::connect( manager, SIGNAL( agentInstanceAdvancedStatusChanged( const QString&, const QVariantMap& ) ), q_ptr, SLOT( agentInstanceAdvancedStatusChanged( const QString&, const QVariantMap& ) ) ); + + Akonadi::AgentManager *agentManager = Akonadi::AgentManager::self(); + QObject::connect( agentManager, SIGNAL( instanceRemoved( Akonadi::AgentInstance ) ), + q_ptr, SLOT( agentInstanceRemoved( Akonadi::AgentInstance ) ) ); + } EntityTreeModelPrivate::~EntityTreeModelPrivate() @@ -226,6 +231,28 @@ q->dataChanged(collectionIndex, collectionIndex); } +void EntityTreeModelPrivate::agentInstanceRemoved( const Akonadi::AgentInstance &instance ) +{ + Q_Q( EntityTreeModel ); + + QList childEntities = m_childEntities[m_rootNode->id]; + + int row = 0; + for ( int row = 0; row < childEntities.size(); ++row ) { + Node *node = childEntities.at( row ); + if ( node->type == Node::Collection ) { + const Collection::Id collectionId = node->id; + if ( m_collections[collectionId].resource() == instance.identifier() ) { + q->beginRemoveRows(QModelIndex(), row, row); + removeChildEntities( collectionId ); + q->endRemoveRows(); + --row; + } + } + ++row; + } +} + void EntityTreeModelPrivate::agentInstanceAdvancedStatusChanged( const QString&, const QVariantMap &status ) { const QString key = status.value( QLatin1String( "key" ) ).toString(); --- trunk/KDE/kdepimlibs/akonadi/entitytreemodel_p.h #1214216:1214217 @@ -36,6 +36,7 @@ { class ItemFetchJob; class ChangeRecorder; +class AgentInstance; } struct Node @@ -126,6 +127,7 @@ void runItemFetchJob( ItemFetchJob* itemFetchJob, const Collection &parent ) const; void changeFetchState( const Collection &parent ); void agentInstanceAdvancedStatusChanged( const QString&, const QVariantMap& ); + void agentInstanceRemoved( const Akonadi::AgentInstance &instace ); QHash m_collections; QHash m_items;