diff --git a/src/libtomahawk/AtticaManager.cpp b/src/libtomahawk/AtticaManager.cpp index 26a4838d4..eeab67066 100644 --- a/src/libtomahawk/AtticaManager.cpp +++ b/src/libtomahawk/AtticaManager.cpp @@ -32,6 +32,8 @@ #include #include "utils/logger.h" +#include "accounts/ResolverAccount.h" +#include "accounts/AccountManager.h" using namespace Attica; @@ -374,6 +376,9 @@ AtticaManager::payloadFetched() // Do the install / add to tomahawk Tomahawk::Pipeline::instance()->addScriptResolver( resolverPath, true ); + 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 ); emit resolverInstalled( resolverId ); diff --git a/src/libtomahawk/accounts/ResolverAccount.cpp b/src/libtomahawk/accounts/ResolverAccount.cpp index c2408f10d..72c1dc575 100644 --- a/src/libtomahawk/accounts/ResolverAccount.cpp +++ b/src/libtomahawk/accounts/ResolverAccount.cpp @@ -45,6 +45,16 @@ ResolverAccountFactory::createAccount( const QString& accountId ) } +Account* +ResolverAccountFactory::createFromPath( const QString& path, bool isAttica ) +{ + if ( isAttica ) + return new AtticaResolverAccount( generateId( "resolveraccount" ), path ); + else + return new ResolverAccount( generateId( "resolveraccount" ), path ); +} + + ResolverAccount::ResolverAccount( const QString& accountId ) : Account( accountId ) { @@ -65,6 +75,25 @@ ResolverAccount::ResolverAccount( const QString& accountId ) } +ResolverAccount::ResolverAccount( const QString& accountId, const QString& path ) + : Account( accountId ) +{ + QVariantHash configuration; + configuration[ "path" ] = path; + setConfiguration( configuration ); + setEnabled( true ); + + m_resolver = qobject_cast< ExternalResolverGui* >( Pipeline::instance()->addScriptResolver( path, true ) ); + connect( m_resolver, SIGNAL( changed() ), this, SLOT( resolverChanged() ) ); + + // What resolver do we have here? Should only be types that are 'real' resolvers + Q_ASSERT ( m_resolver ); + + setAccountFriendlyName( m_resolver->name() ); + setTypes( AccountType( ResolverType ) ); +} + + ResolverAccount::~ResolverAccount() { delete m_resolver; @@ -152,19 +181,34 @@ ResolverAccount::resolverChanged() AtticaResolverAccount::AtticaResolverAccount( const QString& accountId ) : ResolverAccount( accountId ) { - const QFileInfo fi( m_resolver->filePath() ); - QDir codeDir = fi.absoluteDir(); - codeDir.cd( "../images" ); - - if ( codeDir.exists() && codeDir.exists( "icon.png" ) ) - m_icon.load( codeDir.absoluteFilePath( "icon.png" ) ); + loadIcon(); } +AtticaResolverAccount::AtticaResolverAccount( const QString& accountId, const QString& path ) + : ResolverAccount( accountId, path ) +{ + loadIcon(); +} + + AtticaResolverAccount::~AtticaResolverAccount() { } +void +AtticaResolverAccount::loadIcon() +{ + const QFileInfo fi( m_resolver->filePath() ); + QDir codeDir = fi.absoluteDir(); + codeDir.cd( "../images" ); + + if ( codeDir.exists() && codeDir.exists( "icon.png" ) ) + m_icon.load( codeDir.absoluteFilePath( "icon.png" ) ); + +} + + QPixmap AtticaResolverAccount::icon() const { diff --git a/src/libtomahawk/accounts/ResolverAccount.h b/src/libtomahawk/accounts/ResolverAccount.h index 228479de6..88cf0c7e3 100644 --- a/src/libtomahawk/accounts/ResolverAccount.h +++ b/src/libtomahawk/accounts/ResolverAccount.h @@ -39,6 +39,10 @@ public: virtual QString description() const { return QString(); } virtual QString prettyName() const { return QString(); } // Internal, not displayed virtual bool allowUserCreation() const { return false; } + + // Used to create a new resolver from a script on disk, either chosen by + // the user, or installed from synchrotron + static Account* createFromPath( const QString& path, bool isAttica ); }; /** @@ -74,7 +78,10 @@ private slots: void resolverChanged(); protected: + ResolverAccount( const QString& accountId, const QString& path ); ExternalResolverGui* m_resolver; + + friend class ResolverAccountFactory; }; @@ -92,7 +99,13 @@ public: virtual QPixmap icon() const; private: + AtticaResolverAccount( const QString& accountId, const QString& path ); + + void loadIcon(); + QPixmap m_icon; + + friend class ResolverAccountFactory; }; }