mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-18 23:09:42 +01:00
Fix turning on/off toplevel accounts
This commit is contained in:
parent
82c77e64c6
commit
79fd0278ce
@ -185,6 +185,8 @@ AccountManager::enableAccount( Account* account )
|
||||
|
||||
account->setEnabled( true );
|
||||
m_enabledAccounts << account;
|
||||
|
||||
account->sync();
|
||||
}
|
||||
|
||||
|
||||
@ -197,6 +199,8 @@ AccountManager::disableAccount( Account* account )
|
||||
account->deauthenticate();
|
||||
account->setEnabled( false );
|
||||
m_enabledAccounts.removeAll( account );
|
||||
|
||||
account->sync();
|
||||
}
|
||||
|
||||
|
||||
|
@ -117,6 +117,27 @@ AccountModel::data( const QModelIndex& index, int role ) const
|
||||
return !node->accounts.isEmpty();
|
||||
case AccountTypeRole:
|
||||
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:
|
||||
return QVariant();
|
||||
}
|
||||
@ -300,9 +321,18 @@ AccountModel::setData( const QModelIndex& index, const QVariant& value, int role
|
||||
|
||||
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 );
|
||||
@ -313,7 +343,6 @@ AccountModel::setData( const QModelIndex& index, const QVariant& value, int role
|
||||
else if( state == Qt::Unchecked )
|
||||
AccountManager::instance()->disableAccount( acct );
|
||||
|
||||
acct->sync();
|
||||
emit dataChanged( index, index );
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user