コード例 #1
0
void
AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx )
{
    Tomahawk::Accounts::Account* account =
        idx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole )
        .value< QList< Tomahawk::Accounts::Account* > >().at( accountIdx );
    if ( account )
    {
        const QPixmap& pixmap = account->icon();
        QSize pixmapSize( 32, 32 );
        m_imageLabel->setPixmap( pixmap.scaled( pixmapSize, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
        m_imageLabel->setFixedSize( pixmapSize );

        QFontMetrics fm = m_idLabel->fontMetrics();
        m_idLabel->setText( account->accountFriendlyName() );
        m_idLabel->setToolTip( "<b>" +
                               account->accountServiceName() +
                               "</b><br>" +
                               account->accountFriendlyName() );

        //we already know it's a factory because of the FactoryProxy
        Tomahawk::Accounts::AccountFactory* fac =
            qobject_cast< Tomahawk::Accounts::AccountFactory* >(
                idx.data( Tomahawk::Accounts::AccountModel::AccountData )
                .value< QObject* >() );
        if ( fac->factoryId() == "twitteraccount" )
        {
            m_inviteContainer->setVisible( false );
            m_inviteButton->setVisible( false );
        }

        switch ( account->connectionState() )
        {
        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_statusToggle->setBackChecked( true );
            setInviteWidgetsEnabled( true );
            break;
        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_statusToggle->setBackChecked( true );
            setInviteWidgetsEnabled( false );
        }
    }
}
コード例 #2
0
ファイル: AccountWidget.cpp プロジェクト: pmpontes/tomahawk
void
AccountWidget::update( const QPersistentModelIndex& idx, int accountIdx )
{
    Tomahawk::Accounts::Account* account =
            idx.data( Tomahawk::Accounts::AccountModel::ChildrenOfFactoryRole )
            .value< QList< Tomahawk::Accounts::Account* > >().at( accountIdx );

    if ( account )
    {
        const QPixmap& pixmap = account->icon();
        QSize pixmapSize( scaled( 32, 32 ) );
        m_imageLabel->setPixmap( pixmap.scaled( pixmapSize, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
        m_imageLabel->setFixedSize( pixmapSize );

        QFontMetrics fm = m_idLabel->fontMetrics();
        m_idLabel->setText( account->accountFriendlyName() );
        m_idLabel->setToolTip( "<b>" +
                               account->accountServiceName() +
                               "</b><br>" +
                               account->accountFriendlyName() );

        switch ( account->connectionState() )
        {
            case Tomahawk::Accounts::Account::Connected:
            {
                if ( account->enabled() )
                    m_statusToggle->setChecked( true );
                else
                    tDebug() << "AccountWidget warning:" << account->accountFriendlyName()
                             << "is Connected but Disabled!";
                m_spinner->fadeOut();
                m_statusToggle->setBackChecked( true );
                setInviteWidgetsEnabled( true );
                break;
            }

            case Tomahawk::Accounts::Account::Connecting:
            {
                if ( !account->enabled() )
                    tDebug() << "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
                    tDebug() << "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() )
                    tDebug() << "AccountWidget warning:" << account->accountFriendlyName()
                             << "is Disconnecting but Enabled!";
                m_spinner->fadeIn();
                m_statusToggle->setBackChecked( true );
                setInviteWidgetsEnabled( false );
            }
        }

        if ( !account->enabled() && account->connectionState() == Tomahawk::Accounts::Account::Disconnected )
        {
            m_spinner->fadeOut();
            m_statusToggle->setBackChecked( false );
            m_statusToggle->setChecked( false );
            setInviteWidgetsEnabled( false );
        }
        else if ( account->enabled() && account->connectionState() == Tomahawk::Accounts::Account::Connected )
        {
            m_spinner->fadeOut();
            m_statusToggle->setBackChecked( true );
            m_statusToggle->setChecked( true );
            setInviteWidgetsEnabled( true );
        }
    }
}