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

Reimplemented updateEntries and handled connection states better.

This commit is contained in:
Teo Mrnjavac
2012-08-15 14:07:28 +02:00
parent fbee760723
commit 20cd15662e
2 changed files with 45 additions and 23 deletions

View File

@@ -44,13 +44,22 @@ AccountListWidget::AccountListWidget( AccountModelFactoryProxy* model, QWidget*
void void
AccountListWidget::updateEntries( const QModelIndex& topLeft, const QModelIndex& bottomRight ) AccountListWidget::updateEntries( const QModelIndex& topLeft, const QModelIndex& bottomRight )
{ {
Q_UNUSED( topLeft ) for( int row = topLeft.row(); row <= bottomRight.row(); ++row )
Q_UNUSED( bottomRight )
for ( QHash< QPersistentModelIndex, QList< AccountWidget* > >::iterator it
= m_entries.begin();
it != m_entries.end(); ++it )
{ {
updateEntry( it.key() ); QPersistentModelIndex idx( m_model->index( row, 0 ) );
int newCount = idx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole )
.value< QList< Tomahawk::Accounts::Account* > >().count();
if( m_entries.value( idx ).count() == newCount )
{
updateEntry( idx );
}
else
{
removeEntries( idx.parent(), idx.row(), idx.row() );
insertEntries( idx.parent(), idx.row(), idx.row() );
}
} }
} }
@@ -101,7 +110,10 @@ AccountListWidget::insertEntries( const QModelIndex& parent, int start, int end
updateEntry( idx ); updateEntry( idx );
for ( int j = 0; j < entryAccounts.length(); ++j ) for ( int j = 0; j < entryAccounts.length(); ++j )
{
entryAccounts[ j ]->update( idx, j );
entryAccounts[ j ]->setupConnections( idx, j ); entryAccounts[ j ]->setupConnections( idx, j );
}
} }
} }
@@ -115,8 +127,6 @@ AccountListWidget::removeEntries( const QModelIndex& parent, int start, int end
for ( int j = 0; j < entryAccounts.count(); ++j ) for ( int j = 0; j < entryAccounts.count(); ++j )
{ {
AccountWidget *a = entryAccounts.at( j ); AccountWidget *a = entryAccounts.at( j );
qDebug() << "Removing entry " << idx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole )
.value< QList< Tomahawk::Accounts::Account* > >().at( j )->accountId();
m_layout->removeWidget( a ); m_layout->removeWidget( a );
a->deleteLater(); a->deleteLater();
} }

View File

@@ -170,27 +170,39 @@ AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx )
switch ( account->connectionState() ) switch ( account->connectionState() )
{ {
case Tomahawk::Accounts::Account::Disconnected:
m_spinner->fadeOut();
m_statusToggle->setChecked( false );
m_statusToggle->setBackChecked( false );
setInviteWidgetsEnabled( false );
break;
case Tomahawk::Accounts::Account::Connecting:
m_spinner->fadeIn();
m_statusToggle->setChecked( true );
m_statusToggle->setBackChecked( false );
setInviteWidgetsEnabled( false );
break;
case Tomahawk::Accounts::Account::Connected: case Tomahawk::Accounts::Account::Connected:
if ( account->enabled() )
m_statusToggle->setChecked( true );
else
qDebug() << "AccountWidget warning:" << account->accountFriendlyName()
<< "is Connected but Disabled!";
m_spinner->fadeOut(); m_spinner->fadeOut();
m_statusToggle->setChecked( true );
m_statusToggle->setBackChecked( true ); m_statusToggle->setBackChecked( true );
setInviteWidgetsEnabled( true ); setInviteWidgetsEnabled( true );
break; break;
case Tomahawk::Accounts::Account::Disconnecting: case Tomahawk::Accounts::Account::Connecting:
if ( !account->enabled() )
qDebug() << "AccountWidget warning:" << account->accountFriendlyName()
<< "is Connecting but Disabled!";
m_spinner->fadeIn();
m_statusToggle->setBackChecked( false );
setInviteWidgetsEnabled( false );
break;
case Tomahawk::Accounts::Account::Disconnected:
if ( !account->enabled() )
m_statusToggle->setChecked( false );
else
qDebug() << "AccountWidget warning:" << account->accountFriendlyName()
<< "is Disconnected but Enabled!";
m_spinner->fadeOut();
m_statusToggle->setBackChecked( false );
setInviteWidgetsEnabled( false );
break;
case Tomahawk::Accounts::Account::Disconnecting:
if ( account->enabled() )
qDebug() << "AccountWidget warning:" << account->accountFriendlyName()
<< "is Disconnecting but Enabled!";
m_spinner->fadeIn(); m_spinner->fadeIn();
m_statusToggle->setChecked( false );
m_statusToggle->setBackChecked( true ); m_statusToggle->setBackChecked( true );
setInviteWidgetsEnabled( false ); setInviteWidgetsEnabled( false );
} }