diff --git a/src/libtomahawk/accounts/Account.cpp b/src/libtomahawk/accounts/Account.cpp index 62387f1aa..bc1501947 100644 --- a/src/libtomahawk/accounts/Account.cpp +++ b/src/libtomahawk/accounts/Account.cpp @@ -54,7 +54,7 @@ Account::aclWidget() QIcon Account::icon() const { - return QIcon(); + return QPixmap(); } void diff --git a/src/libtomahawk/accounts/ResolverAccount.cpp b/src/libtomahawk/accounts/ResolverAccount.cpp new file mode 100644 index 000000000..f7dcf4a62 --- /dev/null +++ b/src/libtomahawk/accounts/ResolverAccount.cpp @@ -0,0 +1,172 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Leo Franchi + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "ResolverAccount.h" + +#include "ExternalResolver.h" +#include "ExternalResolverGui.h" +#include "AccountManager.h" +#include +#include +#include +#include + +using namespace Tomahawk; +using namespace Accounts; + +Account* +ResolverAccountFactory::createAccount( const QString& accountId ) +{ + // Can't use this to create new accounts. Needs to be able to find account in config + // to load proper resolver account type. Creation is done from AtticaManager when path is known + Q_ASSERT( !accountId.isEmpty() ); + + // If it's an attica resolver, return it instead so we get an icon + const bool isFromAttica = TomahawkSettings::instance()->value( QString( "accounts/%1/atticaresolver" ).arg( accountId ), false ).toBool(); + if ( isFromAttica ) + return new AtticaResolverAccount( accountId ); + else + return new ResolverAccount( accountId ); +} + + +ResolverAccount::ResolverAccount( const QString& accountId ) + : Account( accountId ) +{ + + const QString path = configuration()[ "path" ].toString(); + + // We should have a valid saved path + Q_ASSERT( !path.isEmpty() ); + + m_resolver = qobject_cast< ExternalResolverGui* >( Pipeline::instance()->addScriptResolver( path, enabled() ) ); + 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; +} + + + +void +ResolverAccount::authenticate() +{ + if ( !m_resolver->running() ) + m_resolver->start(); + + emit connectionStateChanged( connectionState() ); +} + + +bool +ResolverAccount::isAuthenticated() const +{ + return m_resolver->running(); +} + + +void +ResolverAccount::deauthenticate() +{ + if ( m_resolver->running() ) + m_resolver->stop(); + + emit connectionStateChanged( connectionState() ); + +} + + +Account::ConnectionState +ResolverAccount::connectionState() const +{ + if ( m_resolver->running() ) + return Connected; + else + return Disconnected; +} + + +QWidget* +ResolverAccount::configurationWidget() +{ + return m_resolver->configUI(); +} + + +QString +ResolverAccount::errorMessage() const +{ + // TODO +// return m_resolver->error(); + return QString(); +} + + +void +ResolverAccount::removeFromConfig() +{ + // TODO +} + + +void ResolverAccount::saveConfig() +{ + m_resolver->saveConfig(); +} + + +void +ResolverAccount::resolverChanged() +{ + setAccountFriendlyName( m_resolver->name() ); + emit connectionStateChanged( connectionState() ); +} + + +/// AtticaResolverAccount + +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.addFile( codeDir.absoluteFilePath( "icon.png" ) ); +} + +AtticaResolverAccount::~AtticaResolverAccount() +{ + +} + +QIcon +AtticaResolverAccount::icon() const +{ + return QPixmap; +} diff --git a/src/libtomahawk/accounts/ResolverAccount.h b/src/libtomahawk/accounts/ResolverAccount.h new file mode 100644 index 000000000..4aeb159ce --- /dev/null +++ b/src/libtomahawk/accounts/ResolverAccount.h @@ -0,0 +1,99 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Leo Franchi + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef RESOLVERACCOUNT_H +#define RESOLVERACCOUNT_H + +#include "accounts/Account.h" + +namespace Tomahawk { + +class ExternalResolverGui; + +namespace Accounts { + +class ResolverAccountFactory : public AccountFactory +{ + Q_OBJECT +public: + ResolverAccountFactory() {} + virtual ~ResolverAccountFactory() {} + + virtual Account* createAccount(const QString& accountId = QString()); + virtual QString factoryId() const { return "resolveraccount"; } + virtual QString prettyName() const { return QString(); } // Internal, not displayed +}; + +/** + * Helper wrapper class that is a resolver-only account. + * + * Contains the resolver* that is it wrapping + */ +class ResolverAccount : public Account +{ + Q_OBJECT +public: + explicit ResolverAccount( const QString& accountId ); + virtual ~ResolverAccount(); + + virtual void authenticate(); + virtual void deauthenticate(); + virtual bool isAuthenticated() const; + virtual Tomahawk::Accounts::Account::ConnectionState connectionState() const; + + virtual QWidget* configurationWidget(); + virtual QString errorMessage() const; + + virtual void saveConfig(); + virtual void removeFromConfig(); + + // Not relevant + virtual QIcon icon() const { return QIcon(); } + virtual SipPlugin* sipPlugin() { return 0; } + virtual Tomahawk::InfoSystem::InfoPlugin* infoPlugin() { return 0; } + virtual QWidget* aclWidget() { return 0; } + +private slots: + void resolverChanged(); + +protected: + ExternalResolverGui* m_resolver; +}; + + +/** + * Extends ResolverAccount with what attica additionally provides---e.g. icon + * Assumes certain file layout on disk. + */ +class AtticaResolverAccount : public ResolverAccount +{ + Q_OBJECT +public: + explicit AtticaResolverAccount(const QString& accountId); + virtual ~AtticaResolverAccount(); + + virtual QIcon icon() const; + +private: + QIcon m_icon; +}; + +} +} + +#endif // RESOLVERACCOUNT_H diff --git a/src/libtomahawk/tomahawksettings.cpp b/src/libtomahawk/tomahawksettings.cpp index 63305d912..455ea29ff 100644 --- a/src/libtomahawk/tomahawksettings.cpp +++ b/src/libtomahawk/tomahawksettings.cpp @@ -275,6 +275,10 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion ) configuration[ "path" ] = resolver; setValue( "configuration", configuration ); + // reasonably ugly check for attica resolvers + if ( resolver.contains( "atticaresolvers" ) && resolver.contains( "code" ) ) + setValue( "atticaresolver", true ); + endGroup(); }