1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 09:19:41 +01:00

Show spinner for an account while it's connecting

This commit is contained in:
Leo Franchi 2012-04-28 16:29:21 -04:00
parent 56edc1ba0c
commit 812bfd7ca5
5 changed files with 86 additions and 5 deletions

View File

@ -24,6 +24,7 @@
#include "accounts/AccountModel.h"
#include "accounts/Account.h"
#include "accounts/AccountManager.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
@ -55,6 +56,7 @@ using namespace Accounts;
AccountDelegate::AccountDelegate( QObject* parent )
: QStyledItemDelegate ( parent )
, m_accountRowHeight( -1 )
, m_model( 0 )
{
m_defaultCover.load( RESPATH "images/sipplugin-online.png" );
@ -128,6 +130,9 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option,
painter->setRenderHint( QPainter::Antialiasing );
if ( m_model == 0 || m_model != index.model() )
m_model = const_cast<QAbstractItemModel*>( index.model() );
QFont titleFont = opt.font;
titleFont.setBold( true );
titleFont.setPointSize( titleFont.pointSize() + 2 );
@ -596,7 +601,7 @@ AccountDelegate::drawStatus( QPainter* painter, const QPointF& rightTopEdge, Acc
{
QPixmap p;
QString statusText;
Account::ConnectionState state = acct->connectionState();
const Account::ConnectionState state = acct->connectionState();
if ( state == Account::Connected )
{
p = m_onlineIcon;
@ -615,7 +620,29 @@ AccountDelegate::drawStatus( QPainter* painter, const QPointF& rightTopEdge, Acc
const int yPos = rightTopEdge.y();
const QRect connectIconRect( rightTopEdge.x() - STATUS_ICON_SIZE, yPos, STATUS_ICON_SIZE, STATUS_ICON_SIZE );
painter->drawPixmap( connectIconRect, p );
if ( state == Account::Connecting )
{
if ( !m_connectingSpinners.contains( acct ) )
{
AnimatedSpinner* anim = new AnimatedSpinner( connectIconRect.size(), true );
_detail::Closure* closure = new _detail::Closure( anim, SIGNAL( requestUpdate() ), const_cast<AccountDelegate*>(this), SLOT( doUpdateIndexWithAccount( Tomahawk::Accounts::Account* ) ), C_ARG( Tomahawk::Accounts::Account*, acct ) );
closure->setAutoDelete( false );
m_connectingSpinners[ acct ] = anim;
}
const QPixmap pm = m_connectingSpinners[acct]->pixmap();
painter->drawPixmap( connectIconRect, pm );
}
else
{
if ( m_connectingSpinners.contains( acct ) )
delete m_connectingSpinners.take( acct );
painter->drawPixmap( connectIconRect, p );
}
int leftEdge = connectIconRect.x();
if ( drawText )
@ -713,3 +740,35 @@ AccountDelegate::doUpdateIndex( const QPersistentModelIndex& idx )
emit update( idx );
}
void
AccountDelegate::doUpdateIndexWithAccount( Account* account )
{
// Urgh, have to go through the list and check based on the type
for ( int i = 0; i < m_model->rowCount(); i++ )
{
const QModelIndex index = m_model->index( i, 0, QModelIndex() );
const AccountModel::RowType rowType = static_cast< AccountModel::RowType >( index.data( AccountModel::RowTypeRole ).toInt() );
if ( rowType == AccountModel::TopLevelAccount ||
rowType == AccountModel::CustomAccount )
{
Account* acct = qobject_cast< Account* >( index.data( AccountModel::AccountData ).value< QObject* >() );
if ( account == acct )
{
emit update( index );
return;
}
}
else if ( rowType == AccountModel::TopLevelFactory || rowType == AccountModel::UniqueFactory )
{
const QList< Account* > accts = index.data( AccountModel::ChildrenOfFactoryRole ).value< QList< Tomahawk::Accounts::Account* > >();
if ( accts.contains( account ) )
{
emit update( index );
return;
}
}
}
}

View File

@ -54,6 +54,9 @@ signals:
void openConfig( Tomahawk::Accounts::Account* );
void openConfig( Tomahawk::Accounts::AccountFactory* );
private slots:
void doUpdateIndexWithAccount( Tomahawk::Accounts::Account* account );
private:
void drawRoundedButton( QPainter* painter, const QRect& buttonRect, bool red = false ) const;
// Returns new left edge
@ -73,7 +76,10 @@ private:
mutable QHash< QPersistentModelIndex, QRect > m_cachedConfigRects;
mutable QHash< QPersistentModelIndex, QSize > m_sizeHints;
mutable QHash< QPersistentModelIndex, AnimatedSpinner* > m_loadingSpinners;
mutable QHash< Account*, AnimatedSpinner* > m_connectingSpinners;
mutable int m_accountRowHeight;
mutable QAbstractItemModel* m_model;
};
}

View File

@ -188,6 +188,7 @@ public:
Q_DECLARE_INTERFACE( Tomahawk::Accounts::AccountFactory, "tomahawk.AccountFactory/1.0" )
Q_DECLARE_METATYPE( Tomahawk::Accounts::Account* )
Q_DECLARE_METATYPE( QList< Tomahawk::Accounts::Account* > )
Q_DECLARE_METATYPE( Tomahawk::Accounts::AccountTypes )
#endif

View File

@ -74,7 +74,7 @@ AccountManager::init()
QTimer::singleShot( 0, this, SLOT( init() ) );
return;
}
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) );
loadPluginFactories( findPluginFactories() );
@ -347,6 +347,19 @@ AccountManager::removeAccount( Account* account )
}
QList< Account* >
AccountManager::accountsFromFactory( AccountFactory* factory ) const
{
QList< Account* > accts;
foreach ( Account* acct, m_accounts )
{
if ( factoryForAccount( acct ) == factory )
accts << acct;
}
return accts;
}
Account*
AccountManager::accountFromPath( const QString& accountPath )
{

View File

@ -43,7 +43,7 @@ public:
explicit AccountManager( QObject *parent );
virtual ~AccountManager();
void loadFromConfig();
void initSIP();
@ -61,6 +61,8 @@ public:
QList< Account* > accounts() const { return m_accounts; };
QList< Account* > accounts( Tomahawk::Accounts::AccountType type ) const { return m_accountsByAccountType[ type ]; }
QList< Account* > accountsFromFactory( Tomahawk::Accounts::AccountFactory* factory ) const;
/**
* Returns a new Account for a certain path on disk. This will go through all on-disk resolver account providers
* to find the most specific account that matches this.
@ -85,7 +87,7 @@ public slots:
signals:
void ready();
void added( Tomahawk::Accounts::Account* );
void removed( Tomahawk::Accounts::Account* );