mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 05:37:29 +02:00
Show spinner for an account while it's connecting
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include "accounts/AccountModel.h"
|
#include "accounts/AccountModel.h"
|
||||||
#include "accounts/Account.h"
|
#include "accounts/Account.h"
|
||||||
|
#include "accounts/AccountManager.h"
|
||||||
|
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
@@ -55,6 +56,7 @@ using namespace Accounts;
|
|||||||
AccountDelegate::AccountDelegate( QObject* parent )
|
AccountDelegate::AccountDelegate( QObject* parent )
|
||||||
: QStyledItemDelegate ( parent )
|
: QStyledItemDelegate ( parent )
|
||||||
, m_accountRowHeight( -1 )
|
, m_accountRowHeight( -1 )
|
||||||
|
, m_model( 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
m_defaultCover.load( RESPATH "images/sipplugin-online.png" );
|
m_defaultCover.load( RESPATH "images/sipplugin-online.png" );
|
||||||
@@ -128,6 +130,9 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
|
|
||||||
painter->setRenderHint( QPainter::Antialiasing );
|
painter->setRenderHint( QPainter::Antialiasing );
|
||||||
|
|
||||||
|
if ( m_model == 0 || m_model != index.model() )
|
||||||
|
m_model = const_cast<QAbstractItemModel*>( index.model() );
|
||||||
|
|
||||||
QFont titleFont = opt.font;
|
QFont titleFont = opt.font;
|
||||||
titleFont.setBold( true );
|
titleFont.setBold( true );
|
||||||
titleFont.setPointSize( titleFont.pointSize() + 2 );
|
titleFont.setPointSize( titleFont.pointSize() + 2 );
|
||||||
@@ -596,7 +601,7 @@ AccountDelegate::drawStatus( QPainter* painter, const QPointF& rightTopEdge, Acc
|
|||||||
{
|
{
|
||||||
QPixmap p;
|
QPixmap p;
|
||||||
QString statusText;
|
QString statusText;
|
||||||
Account::ConnectionState state = acct->connectionState();
|
const Account::ConnectionState state = acct->connectionState();
|
||||||
if ( state == Account::Connected )
|
if ( state == Account::Connected )
|
||||||
{
|
{
|
||||||
p = m_onlineIcon;
|
p = m_onlineIcon;
|
||||||
@@ -615,7 +620,29 @@ AccountDelegate::drawStatus( QPainter* painter, const QPointF& rightTopEdge, Acc
|
|||||||
|
|
||||||
const int yPos = rightTopEdge.y();
|
const int yPos = rightTopEdge.y();
|
||||||
const QRect connectIconRect( rightTopEdge.x() - STATUS_ICON_SIZE, yPos, STATUS_ICON_SIZE, STATUS_ICON_SIZE );
|
const QRect connectIconRect( rightTopEdge.x() - STATUS_ICON_SIZE, yPos, STATUS_ICON_SIZE, STATUS_ICON_SIZE );
|
||||||
|
|
||||||
|
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 );
|
painter->drawPixmap( connectIconRect, p );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int leftEdge = connectIconRect.x();
|
int leftEdge = connectIconRect.x();
|
||||||
if ( drawText )
|
if ( drawText )
|
||||||
@@ -713,3 +740,35 @@ AccountDelegate::doUpdateIndex( const QPersistentModelIndex& idx )
|
|||||||
emit update( 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -54,6 +54,9 @@ signals:
|
|||||||
void openConfig( Tomahawk::Accounts::Account* );
|
void openConfig( Tomahawk::Accounts::Account* );
|
||||||
void openConfig( Tomahawk::Accounts::AccountFactory* );
|
void openConfig( Tomahawk::Accounts::AccountFactory* );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void doUpdateIndexWithAccount( Tomahawk::Accounts::Account* account );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void drawRoundedButton( QPainter* painter, const QRect& buttonRect, bool red = false ) const;
|
void drawRoundedButton( QPainter* painter, const QRect& buttonRect, bool red = false ) const;
|
||||||
// Returns new left edge
|
// Returns new left edge
|
||||||
@@ -73,7 +76,10 @@ private:
|
|||||||
mutable QHash< QPersistentModelIndex, QRect > m_cachedConfigRects;
|
mutable QHash< QPersistentModelIndex, QRect > m_cachedConfigRects;
|
||||||
mutable QHash< QPersistentModelIndex, QSize > m_sizeHints;
|
mutable QHash< QPersistentModelIndex, QSize > m_sizeHints;
|
||||||
mutable QHash< QPersistentModelIndex, AnimatedSpinner* > m_loadingSpinners;
|
mutable QHash< QPersistentModelIndex, AnimatedSpinner* > m_loadingSpinners;
|
||||||
|
mutable QHash< Account*, AnimatedSpinner* > m_connectingSpinners;
|
||||||
mutable int m_accountRowHeight;
|
mutable int m_accountRowHeight;
|
||||||
|
|
||||||
|
mutable QAbstractItemModel* m_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -188,6 +188,7 @@ public:
|
|||||||
|
|
||||||
Q_DECLARE_INTERFACE( Tomahawk::Accounts::AccountFactory, "tomahawk.AccountFactory/1.0" )
|
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( QList< Tomahawk::Accounts::Account* > )
|
||||||
Q_DECLARE_METATYPE( Tomahawk::Accounts::AccountTypes )
|
Q_DECLARE_METATYPE( Tomahawk::Accounts::AccountTypes )
|
||||||
#endif
|
#endif
|
||||||
|
@@ -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*
|
Account*
|
||||||
AccountManager::accountFromPath( const QString& accountPath )
|
AccountManager::accountFromPath( const QString& accountPath )
|
||||||
{
|
{
|
||||||
|
@@ -61,6 +61,8 @@ public:
|
|||||||
QList< Account* > accounts() const { return m_accounts; };
|
QList< Account* > accounts() const { return m_accounts; };
|
||||||
QList< Account* > accounts( Tomahawk::Accounts::AccountType type ) const { return m_accountsByAccountType[ type ]; }
|
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
|
* 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.
|
* to find the most specific account that matches this.
|
||||||
|
Reference in New Issue
Block a user