From 75ea38010f444c80abf96dd5e29ff1deeeef9183 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Tue, 14 Feb 2012 18:38:44 -0500 Subject: [PATCH] fix creating factory and other first start issue --- src/AccountDelegate.cpp | 23 ++++------------ .../xmpp/googlewrapper/googlewrapper.cpp | 1 + src/accounts/xmpp/xmppconfigwidget.cpp | 12 ++++++--- src/libtomahawk/accounts/AccountModel.cpp | 26 ++++++++++++------- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/AccountDelegate.cpp b/src/AccountDelegate.cpp index cbad1e51e..618f7d59c 100644 --- a/src/AccountDelegate.cpp +++ b/src/AccountDelegate.cpp @@ -632,28 +632,15 @@ AccountDelegate::drawConfigWrench ( QPainter* painter, QStyleOptionViewItemV4& o QRect AccountDelegate::checkRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const { - // the checkbox for this row was hit - const AccountModel::RowType rowType = static_cast< AccountModel::RowType >( idx.data( AccountModel::RowTypeRole ).toInt() ); - QStyleOptionViewItemV4 opt = option; initStyleOption( &opt, idx ); - if ( rowType == AccountModel::TopLevelAccount || rowType == AccountModel::TopLevelFactory ) - { - // Top level item, return the corresponding rect - const int ypos = ( opt.rect.top() + opt.rect.height() / 2 ) - ( WRENCH_SIZE / 2 ); - QRect checkRect = QRect( PADDING, ypos, WRENCH_SIZE, WRENCH_SIZE ); - return checkRect; - } /*else if ( rowType == AccountModel::ChildAccount ) - { - // Return smaller rect of individual child account - const int smallWrenchSize = opt.rect.height() - PADDING; - int ypos = ( opt.rect.center().y() ) - ( smallWrenchSize / 2 ); - QRect checkRect = QRect( opt.rect.left() + PADDING, ypos, smallWrenchSize, smallWrenchSize ); - return checkRect; - }*/ + // Top level item, return the corresponding rect + const int ypos = ( opt.rect.top() + opt.rect.height() / 2 ) - ( WRENCH_SIZE / 2 ); + const QRect checkRect = QRect( PADDING, ypos, WRENCH_SIZE, WRENCH_SIZE ); + + return checkRect; - return QRect(); } diff --git a/src/accounts/xmpp/googlewrapper/googlewrapper.cpp b/src/accounts/xmpp/googlewrapper/googlewrapper.cpp index d60a91740..858565aba 100644 --- a/src/accounts/xmpp/googlewrapper/googlewrapper.cpp +++ b/src/accounts/xmpp/googlewrapper/googlewrapper.cpp @@ -81,6 +81,7 @@ GoogleWrapper::GoogleWrapper ( const QString& pluginID ) config->m_ui->headerLabel->setText( tr( "Configure this Google Account" ) ); config->m_ui->emailLabel->setText( tr( "Google Address" ) ); config->m_ui->xmppBlurb->setText( tr( "Enter your Google login to connect with your friends using Tomahawk!" ) ); + config->m_ui->xmppUsername->setPlaceholderText( tr( "username@gmail.com" ) ); config->m_ui->logoLabel->setPixmap( QPixmap( ":/gmail-logo.png" ) ); config->m_ui->xmppServer->setText( "talk.google.com" ); config->m_ui->xmppPort->setValue( 5222 ); diff --git a/src/accounts/xmpp/xmppconfigwidget.cpp b/src/accounts/xmpp/xmppconfigwidget.cpp index 9a9390e82..b85b6e7c3 100644 --- a/src/accounts/xmpp/xmppconfigwidget.cpp +++ b/src/accounts/xmpp/xmppconfigwidget.cpp @@ -57,12 +57,16 @@ void XmppConfigWidget::saveConfig() { QVariantHash credentials = m_account->credentials(); - credentials[ "username" ] = m_ui->xmppUsername->text(); - credentials[ "password" ] = m_ui->xmppPassword->text(); - credentials[ "server" ] = m_ui->xmppServer->text(); - credentials[ "port" ] = m_ui->xmppPort->text(); + credentials[ "username" ] = m_ui->xmppUsername->text().trimmed(); + credentials[ "password" ] = m_ui->xmppPassword->text().trimmed(); + + QVariantHash configuration = m_account->configuration(); + configuration[ "server" ] = m_ui->xmppServer->text().trimmed(); + configuration[ "port" ] = m_ui->xmppPort->text().trimmed(); + m_account->setAccountFriendlyName( m_ui->xmppUsername->text() ); m_account->setCredentials( credentials ); + m_account->setConfiguration( configuration); m_account->sync(); static_cast< XmppSipPlugin* >( m_account->sipPlugin() )->checkSettings(); diff --git a/src/libtomahawk/accounts/AccountModel.cpp b/src/libtomahawk/accounts/AccountModel.cpp index 795e355b0..c9073dd2c 100644 --- a/src/libtomahawk/accounts/AccountModel.cpp +++ b/src/libtomahawk/accounts/AccountModel.cpp @@ -33,6 +33,13 @@ AccountModel::AccountModel( QObject* parent ) : QAbstractListModel( parent ) { connect( AtticaManager::instance(), SIGNAL( resolversLoaded( Attica::Content::List ) ), this, SLOT( loadData() ) ); + + connect( AccountManager::instance(), SIGNAL( added( Tomahawk::Accounts::Account* ) ), this, SLOT( accountAdded( Tomahawk::Accounts::Account* ) ) ); + connect( AccountManager::instance(), SIGNAL( removed( Tomahawk::Accounts::Account* ) ), this, SLOT( accountRemoved( Tomahawk::Accounts::Account* ) ) ); + 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 ) ) ); + loadData(); } @@ -70,12 +77,6 @@ AccountModel::loadData() } } - connect ( AccountManager::instance(), SIGNAL( added( Tomahawk::Accounts::Account* ) ), this, SLOT( accountAdded( Tomahawk::Accounts::Account* ) ) ); - connect ( AccountManager::instance(), SIGNAL( removed( Tomahawk::Accounts::Account* ) ), this, SLOT( accountRemoved( Tomahawk::Accounts::Account* ) ) ); - 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(); } @@ -296,8 +297,14 @@ AccountModel::setData( const QModelIndex& index, const QVariant& value, int role switch ( node->type ) { case AccountModelNode::UniqueFactoryType: - Q_ASSERT( node->accounts.size() == 1 ); - acct = node->accounts.first(); + if ( node->accounts.isEmpty() ) + { + // No account for this unique factory, create it + // Don't add it to node->accounts here, slot attached to accountmanager::accountcreated will do it for us + acct = node->factory->createAccount(); + AccountManager::instance()->addAccount( acct ); + TomahawkSettings::instance()->addAccount( acct->accountId() ); + } break; case AccountModelNode::AtticaType: { @@ -411,6 +418,7 @@ void AccountModel::accountAdded( Account* account ) { // Find the factory this belongs up, and update + qDebug() << "IN ACCOUNT ADDED!!!!"; AccountFactory* factory = AccountManager::instance()->factoryForAccount( account ); AtticaResolverAccount* attica = qobject_cast< AtticaResolverAccount* >( account ); for ( int i = 0; i < m_accounts.size(); i++ ) @@ -421,8 +429,6 @@ AccountModel::accountAdded( Account* account ) { n->accounts << account; thisIsTheOne = true; - - return; } else if ( attica && n->atticaContent.id() == attica->atticaId() ) {