1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 22:26:32 +02:00

Fix last.fm rsolver part of lastfm account

This commit is contained in:
Leo Franchi
2012-02-24 18:52:16 -06:00
parent ea47a5556d
commit b2247febc1
6 changed files with 59 additions and 18 deletions

View File

@@ -26,16 +26,12 @@
#include <QPixmap> #include <QPixmap>
#include "dllmacro.h" #include "dllmacro.h"
#include "accounts/Account.h"
#include <attica/provider.h> #include <attica/provider.h>
#include <attica/providermanager.h> #include <attica/providermanager.h>
#include <attica/content.h> #include <attica/content.h>
namespace Tomahawk {
namespace Accounts {
class Account;
}
}
class DLLEXPORT AtticaManager : public QObject class DLLEXPORT AtticaManager : public QObject
{ {
@@ -137,6 +133,19 @@ private:
static AtticaManager* s_instance; 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 ); Q_DECLARE_METATYPE( Attica::Content );
#endif // ATTICAMANAGER_H #endif // ATTICAMANAGER_H

View File

@@ -215,8 +215,6 @@ AccountManager::connectAll()
{ {
acc->authenticate(); acc->authenticate();
m_enabledAccounts << acc; m_enabledAccounts << acc;
// if ( acc->types() & Accounts::SipType && acc->sipPlugin() )
// acc->sipPlugin()->connectPlugin();
} }
m_connected = true; m_connected = true;

View File

@@ -318,6 +318,12 @@ AccountModel::data( const QModelIndex& index, int role ) const
Q_ASSERT( node->factory ); Q_ASSERT( node->factory );
Account* account = node->customAccount; 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 ) switch ( role )
{ {
case Qt::DisplayRole: case Qt::DisplayRole:
@@ -328,9 +334,15 @@ AccountModel::data( const QModelIndex& index, int role ) const
return ShippedWithTomahawk; return ShippedWithTomahawk;
case Qt::ToolTipRole: case Qt::ToolTipRole:
case DescriptionRole: case DescriptionRole:
return node->factory->description(); return hasAttica ? node->atticaContent.description() : node->factory->description();
case CanRateRole: 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: case RowTypeRole:
return CustomAccount; return CustomAccount;
case AccountData: case AccountData:
@@ -378,7 +390,8 @@ AccountModel::setData( const QModelIndex& index, const QVariant& value, int role
acct = node->factory->createAccount(); acct = node->factory->createAccount();
AccountManager::instance()->addAccount( acct ); AccountManager::instance()->addAccount( acct );
TomahawkSettings::instance()->addAccount( acct->accountId() ); TomahawkSettings::instance()->addAccount( acct->accountId() );
} else if ( !node->accounts.isEmpty() ) }
else
{ {
Q_ASSERT( node->accounts.size() == 1 ); Q_ASSERT( node->accounts.size() == 1 );
acct = node->accounts.first(); acct = node->accounts.first();

View File

@@ -22,6 +22,7 @@
#include "Account.h" #include "Account.h"
#include "AccountManager.h" #include "AccountManager.h"
#include "ResolverAccount.h" #include "ResolverAccount.h"
#include "AtticaManager.h"
#include <attica/content.h> #include <attica/content.h>
@@ -124,6 +125,9 @@ struct AccountModelNode {
init(); init();
customAccount = account; customAccount = account;
factory = AccountManager::instance()->factoryForAccount( account ); factory = AccountManager::instance()->factoryForAccount( account );
if ( CustomAtticaAccount* customAtticaAccount = qobject_cast< CustomAtticaAccount* >( account ) )
atticaContent = customAtticaAccount->atticaContent();
} }
void init() void init()

View File

@@ -52,7 +52,7 @@ LastFmAccountFactory::icon() const
LastFmAccount::LastFmAccount( const QString& accountId ) LastFmAccount::LastFmAccount( const QString& accountId )
: Account( accountId ) : CustomAtticaAccount( accountId )
{ {
m_infoPlugin = QWeakPointer< LastFmPlugin >( new LastFmPlugin( this ) ); m_infoPlugin = QWeakPointer< LastFmPlugin >( new LastFmPlugin( this ) );
@@ -86,13 +86,19 @@ LastFmAccount::authenticate()
const Attica::Content res = AtticaManager::instance()->resolverForId( "lastfm" ); const Attica::Content res = AtticaManager::instance()->resolverForId( "lastfm" );
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res ); 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(); hookupResolver();
} else }
else if ( m_resolver.isNull() )
{ {
AtticaManager::instance()->installResolver( res, false ); AtticaManager::instance()->installResolver( res, false );
} }
else
{
m_resolver.data()->start();
}
emit connectionStateChanged( connectionState() ); emit connectionStateChanged( connectionState() );
} }
@@ -121,7 +127,7 @@ LastFmAccount::configurationWidget()
Account::ConnectionState Account::ConnectionState
LastFmAccount::connectionState() const 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 bool
LastFmAccount::isAuthenticated() const 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() ) ) ); m_resolver = QWeakPointer< ExternalResolverGui >( qobject_cast< ExternalResolverGui* >( Pipeline::instance()->addScriptResolver( data.scriptPath, enabled() ) ) );
connect( m_resolver.data(), SIGNAL( changed() ), this, SLOT( resolverChanged() ) ); connect( m_resolver.data(), SIGNAL( changed() ), this, SLOT( resolverChanged() ) );
} }
Attica::Content
LastFmAccount::atticaContent() const
{
return AtticaManager::instance()->resolverForId( "lastfm" );
}

View File

@@ -20,6 +20,9 @@
#define LASTFMACCOUNT_H #define LASTFMACCOUNT_H
#include "accounts/Account.h" #include "accounts/Account.h"
#include "AtticaManager.h"
#include <attica/content.h>
#include <QObject> #include <QObject>
@@ -58,7 +61,7 @@ private:
* but the user can install the attica resolver on-demand. So we take care of both there. * 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 Q_OBJECT
public: public:
@@ -88,6 +91,8 @@ public:
bool scrobble() const; bool scrobble() const;
void setScrobble( bool scrobble ); void setScrobble( bool scrobble );
Attica::Content atticaContent() const;
private slots: private slots:
void resolverInstalled( const QString& resolverId ); void resolverInstalled( const QString& resolverId );
@@ -95,7 +100,6 @@ private slots:
private: private:
void hookupResolver(); void hookupResolver();
bool m_authenticated;
QWeakPointer<Tomahawk::ExternalResolverGui> m_resolver; QWeakPointer<Tomahawk::ExternalResolverGui> m_resolver;
QWeakPointer<Tomahawk::InfoSystem::LastFmPlugin> m_infoPlugin; QWeakPointer<Tomahawk::InfoSystem::LastFmPlugin> m_infoPlugin;
QWeakPointer<LastFmConfig> m_configWidget; QWeakPointer<LastFmConfig> m_configWidget;