mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
Add hack/workaround for manually adding spotify resolver
This commit is contained in:
@@ -52,6 +52,7 @@
|
|||||||
#include <accounts/ResolverAccount.h>
|
#include <accounts/ResolverAccount.h>
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "AccountFactoryWrapper.h"
|
#include "AccountFactoryWrapper.h"
|
||||||
|
#include "accounts/spotify/SpotifyAccount.h"
|
||||||
|
|
||||||
#include "ui_ProxyDialog.h"
|
#include "ui_ProxyDialog.h"
|
||||||
#include "ui_StackedSettingsDialog.h"
|
#include "ui_StackedSettingsDialog.h"
|
||||||
@@ -458,15 +459,40 @@ SettingsDialog::installFromFile()
|
|||||||
|
|
||||||
if( !resolver.isEmpty() )
|
if( !resolver.isEmpty() )
|
||||||
{
|
{
|
||||||
|
const QFileInfo resolverAbsoluteFilePath( resolver );
|
||||||
|
TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() );
|
||||||
|
|
||||||
|
if ( resolverAbsoluteFilePath.baseName() == "spotify_tomahawkresolver" )
|
||||||
|
{
|
||||||
|
// HACK if this is a spotify resolver, we treat is specially.
|
||||||
|
// usually we expect the user to just download the spotify resolver from attica,
|
||||||
|
// however developers, those who build their own tomahawk, can't do that, or linux
|
||||||
|
// users can't do that. However, we have an already-existing SpotifyAccount that we
|
||||||
|
// know exists that we need to use this resolver path.
|
||||||
|
//
|
||||||
|
// Hence, we special-case the spotify resolver and directly set the path on it here.
|
||||||
|
SpotifyAccount* acct = 0;
|
||||||
|
foreach ( Account* account, AccountManager::instance()->accounts() )
|
||||||
|
{
|
||||||
|
if ( SpotifyAccount* spotify = qobject_cast< SpotifyAccount* >( account ) )
|
||||||
|
{
|
||||||
|
acct = spotify;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( acct )
|
||||||
|
{
|
||||||
|
acct->setManualResolverPath( resolver );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Account* acct = AccountManager::instance()->accountFromPath( resolver );
|
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 );
|
||||||
|
|
||||||
|
|
||||||
QFileInfo resolverAbsoluteFilePath( resolver );
|
|
||||||
TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include "ActionCollection.h"
|
#include "ActionCollection.h"
|
||||||
#include "Pipeline.h"
|
#include "Pipeline.h"
|
||||||
#include "accounts/AccountManager.h"
|
#include "accounts/AccountManager.h"
|
||||||
|
#include "utils/Closure.h"
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
#include "jobview/JobStatusView.h"
|
#include "jobview/JobStatusView.h"
|
||||||
@@ -105,12 +106,13 @@ SpotifyAccount::init()
|
|||||||
const Attica::Content res = AtticaManager::instance()->resolverForId( s_resolverId );
|
const Attica::Content res = AtticaManager::instance()->resolverForId( s_resolverId );
|
||||||
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res );
|
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res );
|
||||||
|
|
||||||
|
const QString path = configuration().value( "resolverPath" ).toString(); // Manual path override
|
||||||
if ( !checkForResolver() && state != AtticaManager::Uninstalled )
|
if ( !checkForResolver() && state != AtticaManager::Uninstalled )
|
||||||
{
|
{
|
||||||
// If the user manually deleted the resolver, mark it as uninstalled, so we re-fetch for the user
|
// If the user manually deleted the resolver, mark it as uninstalled, so we re-fetch for the user
|
||||||
AtticaManager::instance()->uninstallResolver( res );
|
AtticaManager::instance()->uninstallResolver( res );
|
||||||
}
|
}
|
||||||
else if ( state == AtticaManager::Installed )
|
else if ( state == AtticaManager::Installed || !path.isEmpty() )
|
||||||
{
|
{
|
||||||
hookupResolver();
|
hookupResolver();
|
||||||
}
|
}
|
||||||
@@ -122,16 +124,21 @@ SpotifyAccount::hookupResolver()
|
|||||||
{
|
{
|
||||||
// initialize the resolver itself. this is called if the account actually has an installed spotify resolver,
|
// initialize the resolver itself. this is called if the account actually has an installed spotify resolver,
|
||||||
// as it might not.
|
// as it might not.
|
||||||
// If there is a last.fm resolver from attica installed, create the corresponding ExternalResolver* and hook up to it
|
// If there is a spotify resolver from attica installed, create the corresponding ExternalResolver* and hook up to it
|
||||||
|
QString path = configuration().value( "resolverPath" ).toString();
|
||||||
|
if ( path.isEmpty() )
|
||||||
|
{
|
||||||
const Attica::Content res = AtticaManager::instance()->resolverForId( s_resolverId );
|
const Attica::Content res = AtticaManager::instance()->resolverForId( s_resolverId );
|
||||||
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res );
|
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res );
|
||||||
Q_ASSERT( state == AtticaManager::Installed );
|
Q_ASSERT( state == AtticaManager::Installed );
|
||||||
Q_UNUSED( state );
|
Q_UNUSED( state );
|
||||||
|
|
||||||
const AtticaManager::Resolver data = AtticaManager::instance()->resolverData( res.id() );
|
const AtticaManager::Resolver data = AtticaManager::instance()->resolverData( res.id() );
|
||||||
|
path = data.scriptPath;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "Starting spotify resolver with path:" << data.scriptPath;
|
qDebug() << "Starting spotify resolver with path:" << path;
|
||||||
m_spotifyResolver = QWeakPointer< ScriptResolver >( qobject_cast< ScriptResolver* >( Pipeline::instance()->addScriptResolver( data.scriptPath, enabled() ) ) );
|
m_spotifyResolver = QWeakPointer< ScriptResolver >( qobject_cast< ScriptResolver* >( Pipeline::instance()->addScriptResolver( path, enabled() ) ) );
|
||||||
|
|
||||||
connect( m_spotifyResolver.data(), SIGNAL( changed() ), this, SLOT( resolverChanged() ) );
|
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 ) ) );
|
||||||
@@ -162,7 +169,6 @@ bool SpotifyAccount::checkForResolver()
|
|||||||
void
|
void
|
||||||
SpotifyAccount::resolverChanged()
|
SpotifyAccount::resolverChanged()
|
||||||
{
|
{
|
||||||
setAccountFriendlyName( m_spotifyResolver.data()->name() );
|
|
||||||
emit connectionStateChanged( connectionState() );
|
emit connectionStateChanged( connectionState() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +205,7 @@ SpotifyAccount::authenticate()
|
|||||||
if ( res.isValid() && !res.id().isEmpty() )
|
if ( res.isValid() && !res.id().isEmpty() )
|
||||||
AtticaManager::instance()->installResolver( res, false );
|
AtticaManager::instance()->installResolver( res, false );
|
||||||
}
|
}
|
||||||
else
|
else if ( !m_spotifyResolver.data()->running() )
|
||||||
{
|
{
|
||||||
m_spotifyResolver.data()->start();
|
m_spotifyResolver.data()->start();
|
||||||
}
|
}
|
||||||
@@ -252,6 +258,40 @@ SpotifyAccount::atticaLoaded( Attica::Content::List )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccount::setManualResolverPath( const QString &resolverPath )
|
||||||
|
{
|
||||||
|
Q_ASSERT( !resolverPath.isEmpty() );
|
||||||
|
|
||||||
|
QVariantHash configuration;
|
||||||
|
configuration[ "resolverPath" ] = resolverPath;
|
||||||
|
setConfiguration( configuration );
|
||||||
|
sync();
|
||||||
|
|
||||||
|
if ( !m_spotifyResolver.isNull() )
|
||||||
|
{
|
||||||
|
// replace
|
||||||
|
//connect( m_spotifyResolver.data(), SIGNAL( destroyed( QObject* ) ), this, SLOT( hookupResolver() ) );
|
||||||
|
NewClosure( m_spotifyResolver.data(), SIGNAL( destroyed() ), this, SLOT( hookupAfterDeletion( bool ) ), true );
|
||||||
|
m_spotifyResolver.data()->deleteLater();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hookupResolver();
|
||||||
|
authenticate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SpotifyAccount::hookupAfterDeletion( bool autostart )
|
||||||
|
{
|
||||||
|
hookupResolver();
|
||||||
|
if ( autostart )
|
||||||
|
authenticate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SpotifyAccount::aboutToShow( QAction* action, const playlist_ptr& playlist )
|
SpotifyAccount::aboutToShow( QAction* action, const playlist_ptr& playlist )
|
||||||
{
|
{
|
||||||
|
@@ -98,6 +98,8 @@ public:
|
|||||||
|
|
||||||
bool deleteOnUnsync() const;
|
bool deleteOnUnsync() const;
|
||||||
|
|
||||||
|
void setManualResolverPath( const QString& resolverPath );
|
||||||
|
|
||||||
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 );
|
||||||
@@ -116,9 +118,11 @@ private slots:
|
|||||||
void playlistCreated( const QString& msgType, const QVariantMap& msg );
|
void playlistCreated( const QString& msgType, const QVariantMap& msg );
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
void hookupAfterDeletion( bool autostart );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void hookupResolver();
|
|
||||||
bool checkForResolver();
|
bool checkForResolver();
|
||||||
|
void hookupResolver();
|
||||||
|
|
||||||
void loadPlaylists();
|
void loadPlaylists();
|
||||||
void clearUser( bool permanentlyDelete = false );
|
void clearUser( bool permanentlyDelete = false );
|
||||||
|
@@ -92,7 +92,7 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
If the resolver coming from libattica has a native custom c++ account
|
If the resolver coming from libattica has a native custom c++ account
|
||||||
as well. For example the last.fm account.
|
as well. For example the last.fm & spotify accounts.
|
||||||
*/
|
*/
|
||||||
bool hasCustomAccountForAttica( const QString& id ) const;
|
bool hasCustomAccountForAttica( const QString& id ) const;
|
||||||
Tomahawk::Accounts::Account* customAccountForAttica( const QString& id ) const;
|
Tomahawk::Accounts::Account* customAccountForAttica( const QString& id ) const;
|
||||||
|
Reference in New Issue
Block a user