mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 16:29:43 +01:00
Fix last.fm rsolver part of lastfm account
This commit is contained in:
parent
ea47a5556d
commit
b2247febc1
@ -26,16 +26,12 @@
|
||||
#include <QPixmap>
|
||||
|
||||
#include "dllmacro.h"
|
||||
#include "accounts/Account.h"
|
||||
|
||||
#include <attica/provider.h>
|
||||
#include <attica/providermanager.h>
|
||||
#include <attica/content.h>
|
||||
|
||||
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
|
||||
|
@ -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 )
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
@ -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();
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "Account.h"
|
||||
#include "AccountManager.h"
|
||||
#include "ResolverAccount.h"
|
||||
#include "AtticaManager.h"
|
||||
|
||||
#include <attica/content.h>
|
||||
|
||||
@ -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()
|
||||
|
@ -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" );
|
||||
}
|
||||
|
@ -20,6 +20,9 @@
|
||||
#define LASTFMACCOUNT_H
|
||||
|
||||
#include "accounts/Account.h"
|
||||
#include "AtticaManager.h"
|
||||
|
||||
#include <attica/content.h>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
@ -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<Tomahawk::ExternalResolverGui> m_resolver;
|
||||
QWeakPointer<Tomahawk::InfoSystem::LastFmPlugin> m_infoPlugin;
|
||||
QWeakPointer<LastFmConfig> m_configWidget;
|
||||
|
Loading…
x
Reference in New Issue
Block a user