1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 11:20:22 +02:00

Only remove rows from model if removing a manual resolver. Update otherwise

This commit is contained in:
Leo Franchi
2012-02-16 23:21:37 -05:00
parent 06be1868ea
commit e6f4674064

View File

@@ -509,25 +509,38 @@ AccountModel::accountStateChanged( Account* account , Account::ConnectionState )
void void
AccountModel::accountRemoved( Account* account ) AccountModel::accountRemoved( Account* account )
{ {
// Find the factory this belongs up, and update // Find the row this belongs to and update/remove
AccountFactory* factory = AccountManager::instance()->factoryForAccount( account ); AccountFactory* factory = AccountManager::instance()->factoryForAccount( account );
for ( int i = 0; i < m_accounts.size(); i++ ) for ( int i = 0; i < m_accounts.size(); i++ )
{ {
AccountModelNode* n = m_accounts.at( i ); AccountModelNode* n = m_accounts.at( i );
if ( n->type == AccountModelNode::FactoryType && bool found = false;
n->factory == factory ) // Account in a factory, remove child and update
if ( ( n->type == AccountModelNode::FactoryType && n->factory == factory ) ||
( n->type == AccountModelNode::UniqueFactoryType && n->accounts.size() && n->accounts.first() == account ) )
{ {
n->accounts.removeAll( account ); n->accounts.removeAll( account );
found = true;
}
// Attica account, just clear the account but leave the attica shell
if ( n->type == AccountModelNode::AtticaType && n->atticaAccount && n->atticaAccount == account )
{
n->resolverAccount = 0;
found = true;
}
if ( found )
{
const QModelIndex idx = index( i, 0, QModelIndex() ); const QModelIndex idx = index( i, 0, QModelIndex() );
emit dataChanged( idx, idx ); emit dataChanged( idx, idx );
return; return;
} }
if ( ( n->type == AccountModelNode::UniqueFactoryType && n->accounts.size() && n->accounts.first() == account ) || // Manual resolver added, remove the row now
( n->type == AccountModelNode::AtticaType && n->atticaAccount && n->atticaAccount == account ) || if ( n->type == AccountModelNode::ManualResolverType && n->resolverAccount && n->resolverAccount == account )
( n->type == AccountModelNode::ManualResolverType && n->resolverAccount && n->resolverAccount == account ) )
{ {
beginRemoveRows( QModelIndex(), i, i ); beginRemoveRows( QModelIndex(), i, i );
m_accounts.removeAt( i ); m_accounts.removeAt( i );