1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

Properly load spotify account

This commit is contained in:
Leo Franchi 2012-03-09 21:49:50 -05:00
parent ccee34eaa7
commit 970b3e79a9
8 changed files with 90 additions and 1 deletions

View File

@ -180,6 +180,10 @@ public:
virtual AccountTypes types() const = 0;
virtual Account* createAccount( const QString& accountId = QString() ) = 0;
/// If this resolver type accepts this path on disk (For general and special resolver accounts)
virtual bool acceptsPath( const QString& path ) const { return false; }
virtual Account* createFromPath( const QString& path ) { return 0; }
};
};

View File

@ -22,6 +22,7 @@
#include "sourcelist.h"
#include "ResolverAccount.h"
#include "LastFmAccount.h"
#include "SpotifyAccount.h"
#include <QtCore/QLibrary>
#include <QtCore/QDir>
@ -59,9 +60,14 @@ AccountManager::AccountManager( QObject *parent )
// We include the resolver factory manually, not in a plugin
ResolverAccountFactory* f = new ResolverAccountFactory();
m_accountFactories[ f->factoryId() ] = f;
registerAccountFactoryForFilesystem( f );
LastFmAccountFactory* l = new LastFmAccountFactory();
m_accountFactories[ l->factoryId() ] = l;
SpotifyAccountFactory* s = new SpotifyAccountFactory;
m_accountFactories[ s->factoryId() ] = s;
registerAccountFactoryForFilesystem( s );
}
@ -331,6 +337,30 @@ AccountManager::removeAccount( Account* account )
}
Account*
AccountManager::accountFromPath( const QString& accountPath )
{
foreach ( AccountFactory* factory, m_factoriesForFilesytem )
{
if ( factory->acceptsPath( accountPath ) )
{
return factory->createFromPath( accountPath );
}
}
Q_ASSERT_X( false, "Shouldn't have had no account factory accepting a path.. at least ResolverAccount!!", "");
return 0;
}
void
AccountManager::registerAccountFactoryForFilesystem( AccountFactory* factory )
{
m_factoriesForFilesytem.prepend( factory );
}
void
AccountManager::hookupAccount( Account* account ) const
{

View File

@ -61,6 +61,21 @@ public:
QList< Account* > accounts() const { return m_accounts; };
QList< Account* > accounts( Tomahawk::Accounts::AccountType type ) const { return m_accountsByAccountType[ type ]; }
/**
* Returns a new Account for a certain path on disk. This will go through all on-disk resolver account providers
* to find the most specific account that matches this.
*
* The fallback is ResolverAccount, which handles our generic external script resolvers.
*/
Account* accountFromPath( const QString& path );
/**
* Registers an account factory as being able to "handle" resolvers on disk. When accountFromPath is called
* AccountManager will go through all registered account factories in order until it finds one that can handle the path.
* This is searched in LIFO order.
*/
void registerAccountFactoryForFilesystem( AccountFactory* factory );
public slots:
void connectAll();
void disconnectAll();
@ -97,6 +112,7 @@ private:
QHash< AccountType, QList< Account* > > m_accountsByAccountType;
QHash< QString, AccountFactory* > m_accountFactories;
QList< AccountFactory* > m_factoriesForFilesytem;
static AccountManager* s_instance;
};

View File

@ -45,6 +45,13 @@ ResolverAccountFactory::createAccount( const QString& accountId )
}
Account*
ResolverAccountFactory::createFromPath( const QString& path )
{
return createFromPath( path, false );
}
Account*
ResolverAccountFactory::createFromPath( const QString& path, bool isAttica )
{

View File

@ -44,6 +44,10 @@ public:
// Used to create a new resolver from a script on disk, either chosen by
// the user, or installed from synchrotron
virtual bool acceptsPath( const QString& path ) const { return true; } // This is the catch-all filesystem account
virtual Account* createFromPath( const QString& path );
// Internal use
static Account* createFromPath( const QString& path, bool isAttica );
};

View File

@ -35,6 +35,22 @@ SpotifyAccountFactory::createAccount( const QString& accountId )
return new SpotifyAccount( accountId );
}
bool
SpotifyAccountFactory::acceptsPath( const QString& path ) const
{
QFileInfo info( path );
return info.baseName().startsWith( "spotify_" );
}
Account*
SpotifyAccountFactory::createFromPath( const QString& path )
{
return new SpotifyAccount( generateId( "spotifyaccount" ), path );
}
QPixmap
SpotifyAccountFactory::icon() const
{
@ -52,6 +68,13 @@ SpotifyAccount::SpotifyAccount( const QString& accountId )
}
SpotifyAccount::SpotifyAccount( const QString& accountId, const QString& path )
: ResolverAccount( accountId, path )
{
}
QPixmap
SpotifyAccount::icon() const
{

View File

@ -44,6 +44,9 @@ public:
virtual QString factoryId() const { return "spotifyaccount"; }
virtual QString prettyName() const { return "Spotify"; }
virtual bool acceptsPath( const QString& path ) const;
virtual Account* createFromPath( const QString& path );
virtual AccountTypes types() const { return AccountTypes( ResolverType ); }
virtual bool allowUserCreation() const { return false; }
virtual QPixmap icon() const;
@ -56,6 +59,7 @@ class SpotifyAccount : public ResolverAccount
Q_OBJECT
public:
SpotifyAccount( const QString& accountId );
SpotifyAccount( const QString& accountId, const QString& path );
virtual ~SpotifyAccount() {}
virtual QPixmap icon() const;

View File

@ -396,7 +396,8 @@ SettingsDialog::installFromFile()
if( !resolver.isEmpty() )
{
Account* acct = ResolverAccountFactory::createFromPath( resolver, false );
Account* acct = AccountManager::instance()->accountFromPath( resolver );
AccountManager::instance()->addAccount( acct );
TomahawkSettings::instance()->addAccount( acct->accountId() );
AccountManager::instance()->enableAccount( acct );