diff --git a/src/libtomahawk/AtticaManager.h b/src/libtomahawk/AtticaManager.h index 0b6fcfef6..62ba665e8 100644 --- a/src/libtomahawk/AtticaManager.h +++ b/src/libtomahawk/AtticaManager.h @@ -26,16 +26,12 @@ #include #include "dllmacro.h" +#include "accounts/Account.h" #include #include #include -namespace Tomahawk { -namespace Accounts { -class Account; -} -} class DLLEXPORT AtticaManager : public QObject { @@ -137,6 +133,19 @@ private: static AtticaManager* s_instance; }; +class DLLEXPORT CustomAtticaAccount : public Tomahawk::Accounts::Account +{ + Q_OBJECT +public: + virtual ~CustomAtticaAccount() {} + + virtual Attica::Content atticaContent() const = 0; + +protected: + // No, you can't. + CustomAtticaAccount( const QString& id ) : Tomahawk::Accounts::Account( id ) {} +}; + Q_DECLARE_METATYPE( Attica::Content ); #endif // ATTICAMANAGER_H diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index 6c5715113..bef708937 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -215,8 +215,6 @@ AccountManager::connectAll() { acc->authenticate(); m_enabledAccounts << acc; -// if ( acc->types() & Accounts::SipType && acc->sipPlugin() ) -// acc->sipPlugin()->connectPlugin(); } m_connected = true; @@ -409,4 +407,4 @@ AccountManager::onStateChanged( Account::ConnectionState state ) }; -}; \ No newline at end of file +}; diff --git a/src/libtomahawk/accounts/AccountModel.cpp b/src/libtomahawk/accounts/AccountModel.cpp index ad3c93d8e..32748ecac 100644 --- a/src/libtomahawk/accounts/AccountModel.cpp +++ b/src/libtomahawk/accounts/AccountModel.cpp @@ -318,6 +318,12 @@ AccountModel::data( const QModelIndex& index, int role ) const Q_ASSERT( node->factory ); Account* account = node->customAccount; + // This is sort of ugly. CustomAccounts are pure Account*, but we know that + // some might also be linked to attica resolvers (not always). If that is the case + // they have a Attica::Content set on the node, so we use that to display some + // extra metadata and rating + const bool hasAttica = !node->atticaContent.id().isEmpty(); + switch ( role ) { case Qt::DisplayRole: @@ -328,9 +334,15 @@ AccountModel::data( const QModelIndex& index, int role ) const return ShippedWithTomahawk; case Qt::ToolTipRole: case DescriptionRole: - return node->factory->description(); + return hasAttica ? node->atticaContent.description() : node->factory->description(); case CanRateRole: - return false; + return hasAttica; + case AuthorRole: + return hasAttica ? node->atticaContent.author() : QString(); + case RatingRole: + return hasAttica ? node->atticaContent.rating() / 20 : 0; // rating is out of 100 + case DownloadCounterRole: + return hasAttica ? node->atticaContent.downloads() : QVariant(); case RowTypeRole: return CustomAccount; case AccountData: @@ -378,7 +390,8 @@ AccountModel::setData( const QModelIndex& index, const QVariant& value, int role acct = node->factory->createAccount(); AccountManager::instance()->addAccount( acct ); TomahawkSettings::instance()->addAccount( acct->accountId() ); - } else if ( !node->accounts.isEmpty() ) + } + else { Q_ASSERT( node->accounts.size() == 1 ); acct = node->accounts.first(); diff --git a/src/libtomahawk/accounts/AccountModelNode.h b/src/libtomahawk/accounts/AccountModelNode.h index 795e17b6f..042d913cf 100644 --- a/src/libtomahawk/accounts/AccountModelNode.h +++ b/src/libtomahawk/accounts/AccountModelNode.h @@ -22,6 +22,7 @@ #include "Account.h" #include "AccountManager.h" #include "ResolverAccount.h" +#include "AtticaManager.h" #include @@ -124,6 +125,9 @@ struct AccountModelNode { init(); customAccount = account; factory = AccountManager::instance()->factoryForAccount( account ); + + if ( CustomAtticaAccount* customAtticaAccount = qobject_cast< CustomAtticaAccount* >( account ) ) + atticaContent = customAtticaAccount->atticaContent(); } void init() diff --git a/src/libtomahawk/accounts/LastFmAccount.cpp b/src/libtomahawk/accounts/LastFmAccount.cpp index fae2f3132..b22cafd9c 100644 --- a/src/libtomahawk/accounts/LastFmAccount.cpp +++ b/src/libtomahawk/accounts/LastFmAccount.cpp @@ -52,7 +52,7 @@ LastFmAccountFactory::icon() const LastFmAccount::LastFmAccount( const QString& accountId ) - : Account( accountId ) + : CustomAtticaAccount( accountId ) { m_infoPlugin = QWeakPointer< LastFmPlugin >( new LastFmPlugin( this ) ); @@ -86,13 +86,19 @@ LastFmAccount::authenticate() const Attica::Content res = AtticaManager::instance()->resolverForId( "lastfm" ); const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res ); - if ( state == AtticaManager::Installed ) + qDebug() << "Last.FM account authenticating..."; + if ( m_resolver.isNull() && state == AtticaManager::Installed ) { hookupResolver(); - } else + } + else if ( m_resolver.isNull() ) { AtticaManager::instance()->installResolver( res, false ); } + else + { + m_resolver.data()->start(); + } emit connectionStateChanged( connectionState() ); } @@ -121,7 +127,7 @@ LastFmAccount::configurationWidget() Account::ConnectionState LastFmAccount::connectionState() const { - return m_authenticated ? Account::Connected : Account::Disconnected; + return m_resolver.data()->running() ? Account::Connected : Account::Disconnected; } @@ -141,7 +147,7 @@ LastFmAccount::infoPlugin() bool LastFmAccount::isAuthenticated() const { - return m_authenticated; + return !m_resolver.isNull() && m_resolver.data()->running(); } @@ -253,3 +259,10 @@ LastFmAccount::hookupResolver() m_resolver = QWeakPointer< ExternalResolverGui >( qobject_cast< ExternalResolverGui* >( Pipeline::instance()->addScriptResolver( data.scriptPath, enabled() ) ) ); connect( m_resolver.data(), SIGNAL( changed() ), this, SLOT( resolverChanged() ) ); } + + +Attica::Content +LastFmAccount::atticaContent() const +{ + return AtticaManager::instance()->resolverForId( "lastfm" ); +} diff --git a/src/libtomahawk/accounts/LastFmAccount.h b/src/libtomahawk/accounts/LastFmAccount.h index 015afce8e..3e7aaf651 100644 --- a/src/libtomahawk/accounts/LastFmAccount.h +++ b/src/libtomahawk/accounts/LastFmAccount.h @@ -20,6 +20,9 @@ #define LASTFMACCOUNT_H #include "accounts/Account.h" +#include "AtticaManager.h" + +#include #include @@ -58,7 +61,7 @@ private: * but the user can install the attica resolver on-demand. So we take care of both there. * */ -class LastFmAccount : public Account +class LastFmAccount : public CustomAtticaAccount { Q_OBJECT public: @@ -88,6 +91,8 @@ public: bool scrobble() const; void setScrobble( bool scrobble ); + Attica::Content atticaContent() const; + private slots: void resolverInstalled( const QString& resolverId ); @@ -95,7 +100,6 @@ private slots: private: void hookupResolver(); - bool m_authenticated; QWeakPointer m_resolver; QWeakPointer m_infoPlugin; QWeakPointer m_configWidget;