diff --git a/src/AccountDelegate.cpp b/src/AccountDelegate.cpp index 5f7a4883f..cbad1e51e 100644 --- a/src/AccountDelegate.cpp +++ b/src/AccountDelegate.cpp @@ -82,13 +82,19 @@ AccountDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex return QSize( 200, TOPLEVEL_ACCOUNT_HEIGHT ); else if ( rowType == AccountModel::TopLevelFactory ) { - // Make more space for eacha ccount we have to show. + // Make more space for each account we have to show. AccountFactory* fac = qobject_cast< AccountFactory* >( index.data( AccountModel::AccountData ).value< QObject* >() ); if ( fac->isUnique() ) return QSize( 200, TOPLEVEL_ACCOUNT_HEIGHT ); const QList< Account* > accts = index.data( AccountModel::ChildrenOfFactoryRole ).value< QList< Tomahawk::Accounts::Account* > >(); - return QSize( 200, TOPLEVEL_ACCOUNT_HEIGHT + 12 * accts.size()-1 ); + const QSize s = QSize( 200, TOPLEVEL_ACCOUNT_HEIGHT + 12 * accts.size()-1 ); + + if ( s != m_sizeHints[ index ] ) + const_cast< AccountDelegate* >( this )->sizeHintChanged( index ); // FU KTHBBQ + + m_sizeHints[ index ] = s; + return s; } return QSize(); diff --git a/src/AccountDelegate.h b/src/AccountDelegate.h index eab8cdf7a..6787489b4 100644 --- a/src/AccountDelegate.h +++ b/src/AccountDelegate.h @@ -63,6 +63,7 @@ private: mutable QHash< QPersistentModelIndex, QRect > m_cachedButtonRects; mutable QHash< QPersistentModelIndex, QRect > m_cachedStarRects; mutable QHash< QPersistentModelIndex, QRect > m_cachedConfigRects; + mutable QHash< QPersistentModelIndex, QSize > m_sizeHints; }; } diff --git a/src/libtomahawk/AtticaManager.cpp b/src/libtomahawk/AtticaManager.cpp index 160fc5cd0..96cd70fc6 100644 --- a/src/libtomahawk/AtticaManager.cpp +++ b/src/libtomahawk/AtticaManager.cpp @@ -246,6 +246,8 @@ AtticaManager::resolversList( BaseJob* j ) } syncServerData(); + + emit resolversLoaded( m_resolvers ); } diff --git a/src/libtomahawk/AtticaManager.h b/src/libtomahawk/AtticaManager.h index d4fced92f..88333cf54 100644 --- a/src/libtomahawk/AtticaManager.h +++ b/src/libtomahawk/AtticaManager.h @@ -86,7 +86,7 @@ public slots: void upgradeResolver( const Attica::Content& resolver ); signals: - void resolversReloaded( const Attica::Content::List& resolvers ); + void resolversLoaded( const Attica::Content::List& resolvers ); void resolverStateChanged( const QString& resolverId ); void resolverInstalled( const QString& resolverId ); diff --git a/src/libtomahawk/accounts/AccountModel.cpp b/src/libtomahawk/accounts/AccountModel.cpp index 03631fa94..795e355b0 100644 --- a/src/libtomahawk/accounts/AccountModel.cpp +++ b/src/libtomahawk/accounts/AccountModel.cpp @@ -32,6 +32,7 @@ using namespace Accounts; AccountModel::AccountModel( QObject* parent ) : QAbstractListModel( parent ) { + connect( AtticaManager::instance(), SIGNAL( resolversLoaded( Attica::Content::List ) ), this, SLOT( loadData() ) ); loadData(); } @@ -41,6 +42,7 @@ AccountModel::loadData() beginResetModel(); qDeleteAll( m_accounts ); + m_accounts.clear(); // Add all factories QList< AccountFactory* > factories = AccountManager::instance()->factories(); @@ -73,6 +75,8 @@ AccountModel::loadData() connect ( AccountManager::instance(), SIGNAL( stateChanged( Account* ,Accounts::Account::ConnectionState ) ), this, SLOT( accountStateChanged( Account*, Accounts::Account::ConnectionState ) ) ); connect( AtticaManager::instance(), SIGNAL( resolverInstalled( QString ) ), this, SLOT( atticaInstalled( QString ) ) ); + + endResetModel(); } @@ -216,7 +220,7 @@ AccountModel::data( const QModelIndex& index, int role ) const if ( node->type == AccountModelNode::ManualResolverType ) acct = node->resolverAccount; else if ( node->type == AccountModelNode::UniqueFactoryType ) - acct = node->accounts.first(); + acct = node->accounts.isEmpty() ? 0 : node->accounts.first(); // If there's no account*, then it means it's a unique factory that hasn't been created if ( !acct ) @@ -443,6 +447,8 @@ AccountModel::accountAdded( Account* account ) beginInsertRows( QModelIndex(), count, count ); m_accounts << new AccountModelNode( resolver ); endInsertRows(); + + emit scrollTo( index( m_accounts.size() - 1, 0, QModelIndex() ) ); } } diff --git a/src/libtomahawk/accounts/AccountModel.h b/src/libtomahawk/accounts/AccountModel.h index 491723d22..cbdecf410 100644 --- a/src/libtomahawk/accounts/AccountModel.h +++ b/src/libtomahawk/accounts/AccountModel.h @@ -91,16 +91,18 @@ public: signals: void createAccount( Tomahawk::Accounts::AccountFactory* factory ); + void scrollTo( const QModelIndex& idx ); private slots: + void loadData(); + void accountAdded( Tomahawk::Accounts::Account* ); void accountRemoved( Tomahawk::Accounts::Account* ); void accountStateChanged( Account*, Accounts::Account::ConnectionState ); void atticaInstalled( const QString& atticaId ); -private: - void loadData(); +private: QList< AccountModelNode* > m_accounts; QSet< QString > m_waitingForAtticaInstall; }; diff --git a/src/libtomahawk/accounts/AccountModelFilterProxy.cpp b/src/libtomahawk/accounts/AccountModelFilterProxy.cpp index ff3de4063..23dca5dfc 100644 --- a/src/libtomahawk/accounts/AccountModelFilterProxy.cpp +++ b/src/libtomahawk/accounts/AccountModelFilterProxy.cpp @@ -31,6 +31,15 @@ AccountModelFilterProxy::AccountModelFilterProxy( QObject* parent ) } + +void +AccountModelFilterProxy::setSourceModel( QAbstractItemModel* sourceModel ) +{ + connect( sourceModel, SIGNAL( scrollTo( QModelIndex ) ), this, SLOT( onScrollTo( QModelIndex ) ) ); + QSortFilterProxyModel::setSourceModel( sourceModel ); +} + + bool AccountModelFilterProxy::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const { @@ -54,3 +63,10 @@ AccountModelFilterProxy::setFilterType( AccountType type ) m_filterType = type; invalidate(); } + + +void +AccountModelFilterProxy::onScrollTo( const QModelIndex& idx ) +{ + emit scrollTo( mapFromSource( idx ) ); +} diff --git a/src/libtomahawk/accounts/AccountModelFilterProxy.h b/src/libtomahawk/accounts/AccountModelFilterProxy.h index f22f8f4e9..92c61d469 100644 --- a/src/libtomahawk/accounts/AccountModelFilterProxy.h +++ b/src/libtomahawk/accounts/AccountModelFilterProxy.h @@ -35,9 +35,17 @@ public: void setFilterType( Tomahawk::Accounts::AccountType type ); + virtual void setSourceModel( QAbstractItemModel* sourceModel ); + +signals: + void scrollTo( const QModelIndex& idx ); + protected: virtual bool filterAcceptsRow ( int sourceRow, const QModelIndex& sourceParent ) const; +private slots: + void onScrollTo( const QModelIndex& idx ); + private: Tomahawk::Accounts::AccountType m_filterType; }; diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 0fe591af7..f784f34ae 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -118,11 +118,12 @@ SettingsDialog::SettingsDialog( QWidget *parent ) m_accountProxy = new AccountModelFilterProxy( m_accountModel ); m_accountProxy->setSourceModel( m_accountModel ); + connect( m_accountProxy, SIGNAL( scrollTo( QModelIndex ) ), this, SLOT( scrollTo( QModelIndex ) ) ); + ui->accountsView->setModel( m_accountProxy ); connect( ui->installFromFileBtn, SIGNAL( clicked( bool ) ), this, SLOT( installFromFile() ) ); connect( m_accountModel, SIGNAL( createAccount( Tomahawk::Accounts::AccountFactory* ) ), this, SLOT( createAccountFromFactory( Tomahawk::Accounts::AccountFactory* ) ) ); - connect( AccountManager::instance(), SIGNAL( added( Tomahawk::Accounts::Account* ) ), ui->accountsView, SLOT( scrollToBottom() ) ); ui->accountsFilterCombo->addItem( tr( "All" ), Accounts::NoType ); ui->accountsFilterCombo->addItem( accountTypeToString( SipType ), SipType ); @@ -628,6 +629,13 @@ SettingsDialog::installFromFile() } +void +SettingsDialog::scrollTo( const QModelIndex& idx ) +{ + ui->accountsView->scrollTo( idx, QAbstractItemView::PositionAtBottom ); +} + + void SettingsDialog::requiresRestart() { diff --git a/src/settingsdialog.h b/src/settingsdialog.h index 05bd3ba58..dc61925d7 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -100,6 +100,7 @@ private slots: void accountCreateConfigClosed( int value ); void installFromFile(); + void scrollTo( const QModelIndex& ); void updateScanOptionsView();