1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

Fix turning on/off toplevel accounts

This commit is contained in:
Leo Franchi
2012-02-12 11:56:14 -05:00
parent 82c77e64c6
commit 79fd0278ce
2 changed files with 36 additions and 3 deletions

View File

@@ -185,6 +185,8 @@ AccountManager::enableAccount( Account* account )
account->setEnabled( true ); account->setEnabled( true );
m_enabledAccounts << account; m_enabledAccounts << account;
account->sync();
} }
@@ -197,6 +199,8 @@ AccountManager::disableAccount( Account* account )
account->deauthenticate(); account->deauthenticate();
account->setEnabled( false ); account->setEnabled( false );
m_enabledAccounts.removeAll( account ); m_enabledAccounts.removeAll( account );
account->sync();
} }

View File

@@ -117,6 +117,27 @@ AccountModel::data( const QModelIndex& index, int role ) const
return !node->accounts.isEmpty(); return !node->accounts.isEmpty();
case AccountTypeRole: case AccountTypeRole:
return QVariant::fromValue< AccountTypes >( node->factory->types() ); return QVariant::fromValue< AccountTypes >( node->factory->types() );
case Qt::CheckStateRole:
{
if ( node->accounts.isEmpty() )
return Qt::Unchecked;
// If all are checked or unchecked, return that
bool someOn = false, someOff = false;
foreach ( const Account* acct, node->accounts )
{
if ( acct->enabled() )
someOn = true;
else
someOff = true;
}
if ( someOn && !someOff )
return Qt::Checked;
else if ( someOff & !someOn )
return Qt::Unchecked;
else
return Qt::PartiallyChecked;
}
default: default:
return QVariant(); return QVariant();
} }
@@ -300,9 +321,18 @@ AccountModel::setData( const QModelIndex& index, const QVariant& value, int role
if ( node->type == AccountModelNode::FactoryType ) if ( node->type == AccountModelNode::FactoryType )
{ {
// TODO handle overall on/off // Turn on or off all accounts for this factory
return false; Qt::CheckState state = static_cast< Qt::CheckState >( value.toInt() );
foreach ( Account* acct, node->accounts )
{
state == Qt::Checked ? AccountManager::instance()->enableAccount( acct )
: AccountManager::instance()->disableAccount( acct );
}
emit dataChanged( index, index );
return true;
} }
Q_ASSERT( acct ); Q_ASSERT( acct );
@@ -313,7 +343,6 @@ AccountModel::setData( const QModelIndex& index, const QVariant& value, int role
else if( state == Qt::Unchecked ) else if( state == Qt::Unchecked )
AccountManager::instance()->disableAccount( acct ); AccountManager::instance()->disableAccount( acct );
acct->sync();
emit dataChanged( index, index ); emit dataChanged( index, index );
return true; return true;