mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-18 23:09:42 +01:00
Add first round of integration for custom attica accounts
This commit is contained in:
parent
b8ccf5a2e9
commit
d0b6d09255
@ -202,6 +202,38 @@ AtticaManager::userHasRated( const Content& c ) const
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
AtticaManager::hasCustomAccountForAttica( const QString &id ) const
|
||||
{
|
||||
// Only last.fm at the moment contains a custom account
|
||||
if ( id == "lastfm" )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Tomahawk::Accounts::Account*
|
||||
AtticaManager::customAccountForAttica( const QString &id ) const
|
||||
{
|
||||
return m_customAccounts.value( id );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AtticaManager::registerCustomAccount( const QString &atticaId, Tomahawk::Accounts::Account *account )
|
||||
{
|
||||
m_customAccounts.insert( atticaId, account );
|
||||
}
|
||||
|
||||
|
||||
AtticaManager::Resolver
|
||||
AtticaManager::resolverData(const QString &atticaId) const
|
||||
{
|
||||
return m_resolverStates.value( atticaId );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AtticaManager::providerAdded( const Provider& provider )
|
||||
{
|
||||
@ -324,7 +356,7 @@ AtticaManager::syncServerData()
|
||||
|
||||
|
||||
void
|
||||
AtticaManager::installResolver( const Content& resolver )
|
||||
AtticaManager::installResolver( const Content& resolver, bool autoCreateAccount )
|
||||
{
|
||||
Q_ASSERT( !resolver.id().isNull() );
|
||||
|
||||
@ -338,6 +370,7 @@ AtticaManager::installResolver( const Content& resolver )
|
||||
ItemJob< DownloadItem >* job = m_resolverProvider.downloadLink( resolver.id() );
|
||||
connect( job, SIGNAL( finished( Attica::BaseJob* ) ), this, SLOT( resolverDownloadFinished( Attica::BaseJob* ) ) );
|
||||
job->setProperty( "resolverId", resolver.id() );
|
||||
job->setProperty( "createAccount", autoCreateAccount );
|
||||
|
||||
job->start();
|
||||
}
|
||||
@ -373,6 +406,7 @@ AtticaManager::resolverDownloadFinished ( BaseJob* j )
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
||||
connect( reply, SIGNAL( finished() ), this, SLOT( payloadFetched() ) );
|
||||
reply->setProperty( "resolverId", job->property( "resolverId" ) );
|
||||
reply->setProperty( "createAccount", job->property( "createAccount" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -408,9 +442,12 @@ AtticaManager::payloadFetched()
|
||||
// update with absolute, not relative, path
|
||||
m_resolverStates[ resolverId ].scriptPath = resolverPath;
|
||||
|
||||
// Do the install / add to tomahawk
|
||||
Tomahawk::Accounts::Account* resolver = Tomahawk::Accounts::ResolverAccountFactory::createFromPath( resolverPath, true );
|
||||
Tomahawk::Accounts::AccountManager::instance()->addAccount( resolver );
|
||||
if ( reply->property( "createAccount" ).toBool() )
|
||||
{
|
||||
// Do the install / add to tomahawk
|
||||
Tomahawk::Accounts::Account* resolver = Tomahawk::Accounts::ResolverAccountFactory::createFromPath( resolverPath, true );
|
||||
Tomahawk::Accounts::AccountManager::instance()->addAccount( resolver );
|
||||
}
|
||||
|
||||
m_resolverStates[ resolverId ].state = Installed;
|
||||
TomahawkSettingsGui::instanceGui()->setAtticaResolverStates( m_resolverStates );
|
||||
|
@ -31,6 +31,12 @@
|
||||
#include <attica/providermanager.h>
|
||||
#include <attica/content.h>
|
||||
|
||||
namespace Tomahawk {
|
||||
namespace Accounts {
|
||||
class Account;
|
||||
}
|
||||
}
|
||||
|
||||
class DLLEXPORT AtticaManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -83,8 +89,18 @@ public:
|
||||
void uploadRating( const Attica::Content& c );
|
||||
bool userHasRated( const Attica::Content& c ) const;
|
||||
|
||||
/**
|
||||
If the resolver coming from libattica has a native custom c++ account
|
||||
as well. For example the last.fm account.
|
||||
*/
|
||||
bool hasCustomAccountForAttica( const QString& id ) const;
|
||||
Tomahawk::Accounts::Account* customAccountForAttica( const QString& id ) const;
|
||||
void registerCustomAccount( const QString& atticaId, Tomahawk::Accounts::Account* account );
|
||||
|
||||
AtticaManager::Resolver resolverData( const QString& atticaId ) const;
|
||||
|
||||
public slots:
|
||||
void installResolver( const Attica::Content& resolver );
|
||||
void installResolver( const Attica::Content& resolver, bool autoCreateAccount = true );
|
||||
void upgradeResolver( const Attica::Content& resolver );
|
||||
|
||||
signals:
|
||||
@ -116,6 +132,8 @@ private:
|
||||
Attica::Content::List m_resolvers;
|
||||
StateHash m_resolverStates;
|
||||
|
||||
QMap< QString, Tomahawk::Accounts::Account* > m_customAccounts;
|
||||
|
||||
static AtticaManager* s_instance;
|
||||
};
|
||||
|
||||
|
@ -73,15 +73,23 @@ AccountModel::loadData()
|
||||
foreach ( const Attica::Content& content, fromAttica )
|
||||
{
|
||||
qDebug() << "Loading ATTICA ACCOUNT with content:" << content.id() << content.name();
|
||||
m_accounts << new AccountModelNode( content );
|
||||
|
||||
foreach ( Account* acct, AccountManager::instance()->accounts( Accounts::ResolverType ) )
|
||||
if ( AtticaManager::instance()->hasCustomAccountForAttica( content.id() ) )
|
||||
{
|
||||
if ( AtticaResolverAccount* resolver = qobject_cast< AtticaResolverAccount* >( acct ) )
|
||||
Account* acct = AtticaManager::instance()->customAccountForAttica( content.id() );
|
||||
m_accounts << new AccountModelNode( acct );
|
||||
allAccounts.removeAll( acct );
|
||||
} else
|
||||
{
|
||||
m_accounts << new AccountModelNode( content );
|
||||
|
||||
foreach ( Account* acct, AccountManager::instance()->accounts( Accounts::ResolverType ) )
|
||||
{
|
||||
if ( resolver->atticaId() == content.id() )
|
||||
if ( AtticaResolverAccount* resolver = qobject_cast< AtticaResolverAccount* >( acct ) )
|
||||
{
|
||||
allAccounts.removeAll( acct );
|
||||
if ( resolver->atticaId() == content.id() )
|
||||
{
|
||||
allAccounts.removeAll( acct );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -90,6 +98,8 @@ AccountModel::loadData()
|
||||
// All other accounts we haven't dealt with yet
|
||||
foreach ( Account* acct, allAccounts )
|
||||
{
|
||||
Q_ASSERT( !qobject_cast< AtticaResolverAccount* >( acct ) ); // This should be caught above in the attica list
|
||||
|
||||
if ( qobject_cast< ResolverAccount* >( acct ) && !qobject_cast< AtticaResolverAccount* >( acct ) )
|
||||
m_accounts << new AccountModelNode( qobject_cast< ResolverAccount* >( acct ) );
|
||||
else
|
||||
@ -326,7 +336,7 @@ AccountModel::data( const QModelIndex& index, int role ) const
|
||||
case AccountTypeRole:
|
||||
return QVariant::fromValue< AccountTypes >( account->types() );
|
||||
case Qt::CheckStateRole:
|
||||
return account->enabled();
|
||||
return account->enabled() ? Qt::Checked : Qt::Unchecked;
|
||||
case ConnectionStateRole:
|
||||
return account->connectionState();
|
||||
default:
|
||||
|
@ -23,6 +23,9 @@
|
||||
#include "infosystem/infoplugins/generic/lastfmplugin.h"
|
||||
#include "utils/tomahawkutils.h"
|
||||
#include "resolvers/qtscriptresolver.h"
|
||||
#include "AtticaManager.h"
|
||||
#include "pipeline.h"
|
||||
#include "accounts/AccountManager.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
using namespace InfoSystem;
|
||||
@ -55,6 +58,18 @@ LastFmAccount::LastFmAccount( const QString& accountId )
|
||||
|
||||
setAccountFriendlyName( "Last.Fm" );
|
||||
m_icon.load( RESPATH "images/lastfm-icon.png" );
|
||||
|
||||
AtticaManager::instance()->registerCustomAccount( "lastfm", this );
|
||||
|
||||
connect( AtticaManager::instance(), SIGNAL( resolverInstalled( QString ) ), this, SLOT( resolverInstalled( QString ) ) );
|
||||
|
||||
const Attica::Content res = AtticaManager::instance()->resolverForId( "lastfm" );
|
||||
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res );
|
||||
|
||||
if ( state == AtticaManager::Installed )
|
||||
{
|
||||
hookupResolver();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -68,14 +83,28 @@ LastFmAccount::~LastFmAccount()
|
||||
void
|
||||
LastFmAccount::authenticate()
|
||||
{
|
||||
const Attica::Content res = AtticaManager::instance()->resolverForId( "lastfm" );
|
||||
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res );
|
||||
|
||||
if ( state == AtticaManager::Installed )
|
||||
{
|
||||
hookupResolver();
|
||||
} else
|
||||
{
|
||||
AtticaManager::instance()->installResolver( res, false );
|
||||
}
|
||||
|
||||
emit connectionStateChanged( connectionState() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LastFmAccount::deauthenticate()
|
||||
{
|
||||
if ( m_resolver.data()->running() )
|
||||
m_resolver.data()->stop();
|
||||
|
||||
emit connectionStateChanged( connectionState() );
|
||||
}
|
||||
|
||||
|
||||
@ -192,3 +221,35 @@ LastFmAccount::setScrobble( bool scrobble )
|
||||
setConfiguration( conf );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LastFmAccount::resolverInstalled( const QString &resolverId )
|
||||
{
|
||||
if ( resolverId == "lastfm" )
|
||||
{
|
||||
// We requested this install, so we want to launch it
|
||||
hookupResolver();
|
||||
AccountManager::instance()->enableAccount( this );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LastFmAccount::resolverChanged()
|
||||
{
|
||||
emit connectionStateChanged( connectionState() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LastFmAccount::hookupResolver()
|
||||
{
|
||||
// If there is a last.fm resolver from attica installed, create the corresponding ExternalResolver* and hook up to it
|
||||
const Attica::Content res = AtticaManager::instance()->resolverForId( "lastfm" );
|
||||
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res );
|
||||
Q_ASSERT( state == AtticaManager::Installed );
|
||||
|
||||
const AtticaManager::Resolver data = AtticaManager::instance()->resolverData( res.id() );
|
||||
|
||||
m_resolver = QWeakPointer< ExternalResolverGui >( qobject_cast< ExternalResolverGui* >( Pipeline::instance()->addScriptResolver( data.scriptPath, enabled() ) ) );
|
||||
connect( m_resolver.data(), SIGNAL( changed() ), this, SLOT( resolverChanged() ) );
|
||||
}
|
||||
|
@ -23,9 +23,9 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QtScriptResolver;
|
||||
|
||||
namespace Tomahawk {
|
||||
class ExternalResolverGui;
|
||||
|
||||
namespace InfoSystem {
|
||||
class LastFmPlugin;
|
||||
}
|
||||
@ -88,9 +88,15 @@ public:
|
||||
bool scrobble() const;
|
||||
void setScrobble( bool scrobble );
|
||||
|
||||
private slots:
|
||||
void resolverInstalled( const QString& resolverId );
|
||||
|
||||
void resolverChanged();
|
||||
private:
|
||||
void hookupResolver();
|
||||
|
||||
bool m_authenticated;
|
||||
QWeakPointer<QtScriptResolver> m_resolver;
|
||||
QWeakPointer<Tomahawk::ExternalResolverGui> m_resolver;
|
||||
QWeakPointer<Tomahawk::InfoSystem::LastFmPlugin> m_infoPlugin;
|
||||
QWeakPointer<LastFmConfig> m_configWidget;
|
||||
QPixmap m_icon;
|
||||
|
@ -303,7 +303,7 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion )
|
||||
const QString lfmPassword = value( "lastfm/password" ).toString();
|
||||
const bool scrobble = value( "lastfm/enablescrobbling", false ).toBool();
|
||||
beginGroup( "accounts/" + accountKey );
|
||||
// setValue( "enabled", false );
|
||||
setValue( "enabled", enabledResolvers.contains( "lastfm" ) == true );
|
||||
setValue( "autoconnect", true );
|
||||
setValue( "types", QStringList() << "ResolverType" << "StatusPushType" );
|
||||
QVariantHash credentials;
|
||||
|
Loading…
x
Reference in New Issue
Block a user