mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
slight work on spotify account
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
#include "resolvers/ScriptResolver.h"
|
#include "resolvers/ScriptResolver.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "ActionCollection.h"
|
#include "ActionCollection.h"
|
||||||
|
#include "Pipeline.h"
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
#include "jobview/JobStatusView.h"
|
#include "jobview/JobStatusView.h"
|
||||||
@@ -51,21 +52,6 @@ SpotifyAccountFactory::createAccount( const QString& 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( factoryId() ), path );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QPixmap
|
QPixmap
|
||||||
SpotifyAccountFactory::icon() const
|
SpotifyAccountFactory::icon() const
|
||||||
{
|
{
|
||||||
@@ -77,14 +63,7 @@ SpotifyAccountFactory::icon() const
|
|||||||
|
|
||||||
|
|
||||||
SpotifyAccount::SpotifyAccount( const QString& accountId )
|
SpotifyAccount::SpotifyAccount( const QString& accountId )
|
||||||
: ResolverAccount( accountId )
|
: CustomAtticaAccount( accountId )
|
||||||
{
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SpotifyAccount::SpotifyAccount( const QString& accountId, const QString& path )
|
|
||||||
: ResolverAccount( accountId, path )
|
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
@@ -101,8 +80,36 @@ SpotifyAccount::init()
|
|||||||
{
|
{
|
||||||
qRegisterMetaType< Tomahawk::Accounts::SpotifyPlaylistInfo* >( "Tomahawk::Accounts::SpotifyPlaylist*" );
|
qRegisterMetaType< Tomahawk::Accounts::SpotifyPlaylistInfo* >( "Tomahawk::Accounts::SpotifyPlaylist*" );
|
||||||
|
|
||||||
m_spotifyResolver = dynamic_cast< ScriptResolver* >( m_resolver.data() );
|
AtticaManager::instance()->registerCustomAccount( "spotify", this );
|
||||||
|
|
||||||
|
connect( AtticaManager::instance(), SIGNAL( resolverInstalled( QString ) ), this, SLOT( resolverInstalled( QString ) ) );
|
||||||
|
|
||||||
|
const Attica::Content res = AtticaManager::instance()->resolverForId( "spotify" );
|
||||||
|
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res );
|
||||||
|
|
||||||
|
if ( state == AtticaManager::Installed )
|
||||||
|
{
|
||||||
|
hookupResolver();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccount::hookupResolver()
|
||||||
|
{
|
||||||
|
// initialize the resolver itself. this is called if the account actually has an installed spotify resolver,
|
||||||
|
// as it might not.
|
||||||
|
// 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( "spotify" );
|
||||||
|
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res );
|
||||||
|
Q_ASSERT( state == AtticaManager::Installed );
|
||||||
|
Q_UNUSED( state );
|
||||||
|
|
||||||
|
const AtticaManager::Resolver data = AtticaManager::instance()->resolverData( res.id() );
|
||||||
|
|
||||||
|
m_spotifyResolver = QWeakPointer< ScriptResolver >( qobject_cast< ScriptResolver* >( Pipeline::instance()->addScriptResolver( data.scriptPath, enabled() ) ) );
|
||||||
|
|
||||||
|
connect( m_spotifyResolver.data(), SIGNAL( changed() ), this, SLOT( resolverChanged() ) );
|
||||||
connect( m_spotifyResolver.data(), SIGNAL( customMessage( QString,QVariantMap ) ), this, SLOT( resolverMessage( QString, QVariantMap ) ) );
|
connect( m_spotifyResolver.data(), SIGNAL( customMessage( QString,QVariantMap ) ), this, SLOT( resolverMessage( QString, QVariantMap ) ) );
|
||||||
|
|
||||||
const bool hasMigrated = configuration().value( "hasMigrated" ).toBool();
|
const bool hasMigrated = configuration().value( "hasMigrated" ).toBool();
|
||||||
@@ -113,6 +120,94 @@ SpotifyAccount::init()
|
|||||||
msg[ "_msgtype" ] = "getCredentials";
|
msg[ "_msgtype" ] = "getCredentials";
|
||||||
m_spotifyResolver.data()->sendMessage( msg );
|
m_spotifyResolver.data()->sendMessage( msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccount::resolverChanged()
|
||||||
|
{
|
||||||
|
setAccountFriendlyName( m_spotifyResolver.data()->name() );
|
||||||
|
emit connectionStateChanged( connectionState() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Attica::Content
|
||||||
|
SpotifyAccount::atticaContent() const
|
||||||
|
{
|
||||||
|
return AtticaManager::instance()->resolverForId( "spotify" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccount::authenticate()
|
||||||
|
{
|
||||||
|
if ( !AtticaManager::instance()->resolversLoaded() )
|
||||||
|
{
|
||||||
|
// If we're still waiting to load, wait for the attica resolvers to come down the pipe
|
||||||
|
connect( AtticaManager::instance(), SIGNAL( resolversLoaded( Attica::Content::List ) ), this, SLOT( atticaLoaded( Attica::Content::List ) ), Qt::UniqueConnection );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Attica::Content res = AtticaManager::instance()->resolverForId( "spotify" );
|
||||||
|
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res );
|
||||||
|
|
||||||
|
qDebug() << "Spotify account authenticating...";
|
||||||
|
if ( m_spotifyResolver.isNull() && state == AtticaManager::Installed )
|
||||||
|
{
|
||||||
|
// We don;t have the resolver but it has been installed via attica already, so lets just turn it on
|
||||||
|
hookupResolver();
|
||||||
|
}
|
||||||
|
else if ( m_spotifyResolver.isNull() )
|
||||||
|
{
|
||||||
|
qDebug() << "Got null resolver but asked to authenticate, so installing if we have one from attica:" << res.isValid() << res.id();
|
||||||
|
if ( res.isValid() && !res.id().isEmpty() )
|
||||||
|
AtticaManager::instance()->installResolver( res, false );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_spotifyResolver.data()->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
emit connectionStateChanged( connectionState() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccount::deauthenticate()
|
||||||
|
{
|
||||||
|
if ( !m_spotifyResolver.isNull() && m_spotifyResolver.data()->running() )
|
||||||
|
m_spotifyResolver.data()->stop();
|
||||||
|
|
||||||
|
emit connectionStateChanged( connectionState() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
SpotifyAccount::isAuthenticated() const
|
||||||
|
{
|
||||||
|
return !m_spotifyResolver.isNull() && m_spotifyResolver.data()->running();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Account::ConnectionState
|
||||||
|
SpotifyAccount::connectionState() const
|
||||||
|
{
|
||||||
|
return (!m_spotifyResolver.isNull() && m_spotifyResolver.data()->running()) ? Account::Connected : Account::Disconnected;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccount::resolverInstalled(const QString& resolverId)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccount::atticaLoaded( Attica::Content::List )
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "accounts/ResolverAccount.h"
|
#include "accounts/ResolverAccount.h"
|
||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
|
#include "AtticaManager.h"
|
||||||
#include "Playlist.h"
|
#include "Playlist.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/SmartPointerList.h"
|
#include "utils/SmartPointerList.h"
|
||||||
@@ -61,9 +62,6 @@ 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;
|
||||||
@@ -71,7 +69,7 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SpotifyAccount : public ResolverAccount
|
class SpotifyAccount : public CustomAtticaAccount
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@@ -83,6 +81,11 @@ public:
|
|||||||
virtual QWidget* configurationWidget();
|
virtual QWidget* configurationWidget();
|
||||||
virtual QWidget* aboutWidget();
|
virtual QWidget* aboutWidget();
|
||||||
virtual void saveConfig();
|
virtual void saveConfig();
|
||||||
|
virtual Attica::Content atticaContent() const;
|
||||||
|
virtual void authenticate();
|
||||||
|
virtual ConnectionState connectionState() const;
|
||||||
|
virtual bool isAuthenticated() const;
|
||||||
|
virtual void deauthenticate();
|
||||||
|
|
||||||
virtual QWidget* aclWidget() { return 0; }
|
virtual QWidget* aclWidget() { return 0; }
|
||||||
virtual Tomahawk::InfoSystem::InfoPluginPtr infoPlugin() { return Tomahawk::InfoSystem::InfoPluginPtr(); }
|
virtual Tomahawk::InfoSystem::InfoPluginPtr infoPlugin() { return Tomahawk::InfoSystem::InfoPluginPtr(); }
|
||||||
@@ -98,8 +101,12 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void aboutToShow( QAction* action, const Tomahawk::playlist_ptr& playlist );
|
void aboutToShow( QAction* action, const Tomahawk::playlist_ptr& playlist );
|
||||||
void syncActionTriggered( bool );
|
void syncActionTriggered( bool );
|
||||||
|
void atticaLoaded(Attica::Content::List);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void resolverChanged();
|
||||||
|
void resolverInstalled( const QString& resolverId );
|
||||||
|
|
||||||
void resolverMessage( const QString& msgType, const QVariantMap& msg );
|
void resolverMessage( const QString& msgType, const QVariantMap& msg );
|
||||||
|
|
||||||
void login( const QString& username, const QString& password );
|
void login( const QString& username, const QString& password );
|
||||||
@@ -110,6 +117,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
|
void hookupResolver();
|
||||||
void loadPlaylists();
|
void loadPlaylists();
|
||||||
void clearUser( bool permanentlyDelete = false );
|
void clearUser( bool permanentlyDelete = false );
|
||||||
|
|
||||||
|
@@ -98,7 +98,7 @@ AtticaManager::AtticaManager( QObject* parent )
|
|||||||
|
|
||||||
// resolvers
|
// resolvers
|
||||||
// m_manager.addProviderFile( QUrl( "http://bakery.tomahawk-player.org/resolvers/providers.xml" ) );
|
// m_manager.addProviderFile( QUrl( "http://bakery.tomahawk-player.org/resolvers/providers.xml" ) );
|
||||||
m_manager.addProviderFile( QUrl( "http://localhost/resolvers/providers.xml" ) );
|
m_manager.addProviderFile( QUrl( "http://lycophron/resolvers/providers.xml" ) );
|
||||||
|
|
||||||
qRegisterMetaType< Attica::Content >( "Attica::Content" );
|
qRegisterMetaType< Attica::Content >( "Attica::Content" );
|
||||||
}
|
}
|
||||||
|
@@ -99,7 +99,7 @@ protected:
|
|||||||
* Extends ResolverAccount with what attica additionally provides---e.g. icon
|
* Extends ResolverAccount with what attica additionally provides---e.g. icon
|
||||||
* Assumes certain file layout on disk.
|
* Assumes certain file layout on disk.
|
||||||
*/
|
*/
|
||||||
class AtticaResolverAccount : public ResolverAccount
|
class DLLEXPORT AtticaResolverAccount : public ResolverAccount
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
Reference in New Issue
Block a user