mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
Fix turning on/off toplevel accounts
This commit is contained in:
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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;
|
||||||
|
Reference in New Issue
Block a user