mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 03:40:16 +02:00
Properly load spotify account
This commit is contained in:
@@ -180,6 +180,10 @@ public:
|
|||||||
virtual AccountTypes types() const = 0;
|
virtual AccountTypes types() const = 0;
|
||||||
|
|
||||||
virtual Account* createAccount( const QString& accountId = QString() ) = 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; }
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "sourcelist.h"
|
#include "sourcelist.h"
|
||||||
#include "ResolverAccount.h"
|
#include "ResolverAccount.h"
|
||||||
#include "LastFmAccount.h"
|
#include "LastFmAccount.h"
|
||||||
|
#include "SpotifyAccount.h"
|
||||||
|
|
||||||
#include <QtCore/QLibrary>
|
#include <QtCore/QLibrary>
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
@@ -59,9 +60,14 @@ AccountManager::AccountManager( QObject *parent )
|
|||||||
// We include the resolver factory manually, not in a plugin
|
// We include the resolver factory manually, not in a plugin
|
||||||
ResolverAccountFactory* f = new ResolverAccountFactory();
|
ResolverAccountFactory* f = new ResolverAccountFactory();
|
||||||
m_accountFactories[ f->factoryId() ] = f;
|
m_accountFactories[ f->factoryId() ] = f;
|
||||||
|
registerAccountFactoryForFilesystem( f );
|
||||||
|
|
||||||
LastFmAccountFactory* l = new LastFmAccountFactory();
|
LastFmAccountFactory* l = new LastFmAccountFactory();
|
||||||
m_accountFactories[ l->factoryId() ] = l;
|
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
|
void
|
||||||
AccountManager::hookupAccount( Account* account ) const
|
AccountManager::hookupAccount( Account* account ) const
|
||||||
{
|
{
|
||||||
|
@@ -61,6 +61,21 @@ public:
|
|||||||
QList< Account* > accounts() const { return m_accounts; };
|
QList< Account* > accounts() const { return m_accounts; };
|
||||||
QList< Account* > accounts( Tomahawk::Accounts::AccountType type ) const { return m_accountsByAccountType[ type ]; }
|
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:
|
public slots:
|
||||||
void connectAll();
|
void connectAll();
|
||||||
void disconnectAll();
|
void disconnectAll();
|
||||||
@@ -97,6 +112,7 @@ private:
|
|||||||
|
|
||||||
QHash< AccountType, QList< Account* > > m_accountsByAccountType;
|
QHash< AccountType, QList< Account* > > m_accountsByAccountType;
|
||||||
QHash< QString, AccountFactory* > m_accountFactories;
|
QHash< QString, AccountFactory* > m_accountFactories;
|
||||||
|
QList< AccountFactory* > m_factoriesForFilesytem;
|
||||||
|
|
||||||
static AccountManager* s_instance;
|
static AccountManager* s_instance;
|
||||||
};
|
};
|
||||||
|
@@ -45,6 +45,13 @@ ResolverAccountFactory::createAccount( const QString& accountId )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Account*
|
||||||
|
ResolverAccountFactory::createFromPath( const QString& path )
|
||||||
|
{
|
||||||
|
return createFromPath( path, false );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Account*
|
Account*
|
||||||
ResolverAccountFactory::createFromPath( const QString& path, bool isAttica )
|
ResolverAccountFactory::createFromPath( const QString& path, bool isAttica )
|
||||||
{
|
{
|
||||||
|
@@ -44,6 +44,10 @@ public:
|
|||||||
|
|
||||||
// Used to create a new resolver from a script on disk, either chosen by
|
// Used to create a new resolver from a script on disk, either chosen by
|
||||||
// the user, or installed from synchrotron
|
// 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 );
|
static Account* createFromPath( const QString& path, bool isAttica );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -35,6 +35,22 @@ SpotifyAccountFactory::createAccount( const QString& accountId )
|
|||||||
return new SpotifyAccount( 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
|
QPixmap
|
||||||
SpotifyAccountFactory::icon() const
|
SpotifyAccountFactory::icon() const
|
||||||
{
|
{
|
||||||
@@ -52,6 +68,13 @@ SpotifyAccount::SpotifyAccount( const QString& accountId )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SpotifyAccount::SpotifyAccount( const QString& accountId, const QString& path )
|
||||||
|
: ResolverAccount( accountId, path )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QPixmap
|
QPixmap
|
||||||
SpotifyAccount::icon() const
|
SpotifyAccount::icon() const
|
||||||
{
|
{
|
||||||
|
@@ -44,6 +44,9 @@ public:
|
|||||||
virtual QString factoryId() const { return "spotifyaccount"; }
|
virtual QString factoryId() const { return "spotifyaccount"; }
|
||||||
virtual QString prettyName() const { return "Spotify"; }
|
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 AccountTypes types() const { return AccountTypes( ResolverType ); }
|
||||||
virtual bool allowUserCreation() const { return false; }
|
virtual bool allowUserCreation() const { return false; }
|
||||||
virtual QPixmap icon() const;
|
virtual QPixmap icon() const;
|
||||||
@@ -56,6 +59,7 @@ class SpotifyAccount : public ResolverAccount
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SpotifyAccount( const QString& accountId );
|
SpotifyAccount( const QString& accountId );
|
||||||
|
SpotifyAccount( const QString& accountId, const QString& path );
|
||||||
virtual ~SpotifyAccount() {}
|
virtual ~SpotifyAccount() {}
|
||||||
|
|
||||||
virtual QPixmap icon() const;
|
virtual QPixmap icon() const;
|
||||||
|
@@ -396,7 +396,8 @@ SettingsDialog::installFromFile()
|
|||||||
|
|
||||||
if( !resolver.isEmpty() )
|
if( !resolver.isEmpty() )
|
||||||
{
|
{
|
||||||
Account* acct = ResolverAccountFactory::createFromPath( resolver, false );
|
Account* acct = AccountManager::instance()->accountFromPath( resolver );
|
||||||
|
|
||||||
AccountManager::instance()->addAccount( acct );
|
AccountManager::instance()->addAccount( acct );
|
||||||
TomahawkSettings::instance()->addAccount( acct->accountId() );
|
TomahawkSettings::instance()->addAccount( acct->accountId() );
|
||||||
AccountManager::instance()->enableAccount( acct );
|
AccountManager::instance()->enableAccount( acct );
|
||||||
|
Reference in New Issue
Block a user