1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 23:39:42 +01:00

Install resolver AXE by passing the path as argument.

This commit is contained in:
Teo Mrnjavac 2014-08-21 22:12:38 +02:00
parent 7f6eda66a8
commit da97f8ac63
4 changed files with 76 additions and 47 deletions

View File

@ -23,8 +23,14 @@
#include "GlobalActionManager.h"
#include "accounts/AccountManager.h"
#include "accounts/spotify/SpotifyAccount.h"
#include "accounts/ResolverAccount.h"
#include "audio/AudioEngine.h"
#include "database/LocalCollection.h"
#include "jobview/ErrorStatusMessage.h"
#include "jobview/JobStatusModel.h"
#include "jobview/JobStatusView.h"
#include "playlist/dynamic/GeneratorInterface.h"
#include "playlist/PlaylistTemplate.h"
#include "playlist/PlaylistView.h"
@ -136,6 +142,60 @@ GlobalActionManager::openLink( const QString& title, const QString& artist, cons
}
void
GlobalActionManager::installResolverFromFile( const QString& resolverPath )
{
const QFileInfo resolverAbsoluteFilePath( resolverPath );
TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() );
if ( resolverAbsoluteFilePath.baseName() == "spotify_tomahawkresolver" )
{
// HACK if this is a spotify resolver, we treat it 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.
Accounts::SpotifyAccount* acct = 0;
foreach ( Accounts::Account* account, Accounts::AccountManager::instance()->accounts() )
{
if ( Accounts::SpotifyAccount* spotify = qobject_cast< Accounts::SpotifyAccount* >( account ) )
{
acct = spotify;
break;
}
}
if ( acct )
{
acct->setManualResolverPath( resolverPath );
return;
}
}
Accounts::Account* acct =
Accounts::AccountManager::instance()->accountFromPath( resolverPath );
if ( !acct )
{
QFileInfo fi( resolverPath );
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
tr( "Resolver installation from file %1 failed." )
.arg( fi.fileName() ) ) );
tDebug() << "Resolver was not installed:" << resolverPath;
return;
}
Accounts::AccountManager::instance()->addAccount( acct );
TomahawkSettings::instance()->addAccount( acct->accountId() );
Accounts::AccountManager::instance()->enableAccount( acct );
}
bool
GlobalActionManager::openUrl( const QString& url )
{

View File

@ -46,6 +46,8 @@ public:
QUrl openLink( const QString& title, const QString& artist, const QString& album ) const;
void installResolverFromFile( const QString& resolverPath );
public slots:
/**

View File

@ -790,6 +790,17 @@ TomahawkApp::loadUrl( const QString& url )
return true;
}
else if ( info.suffix() == "axe" )
{
QFileInfo fi( url );
if ( fi.exists() )
{
tDebug( LOGINFO ) << "Loading AXE from file:" << url;
GlobalActionManager::instance()->installResolverFromFile( fi.absoluteFilePath() );
return true;
}
}
}
return GlobalActionManager::instance()->openUrl( url );

View File

@ -30,6 +30,7 @@
#include "AtticaManager.h"
#include "network/acl/AclRegistry.h"
#include "GlobalActionManager.h"
#include "TomahawkApp.h"
#include "TomahawkSettings.h"
#include "accounts/DelegateConfigWrapper.h"
@ -510,54 +511,9 @@ SettingsDialog::installFromFile()
0,
QFileDialog::ReadOnly );
if ( !resolver.isEmpty() )
if ( !resolver.isEmpty() && QFileInfo( resolver ).exists() )
{
const QFileInfo resolverAbsoluteFilePath( resolver );
TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() );
if ( resolverAbsoluteFilePath.baseName() == "spotify_tomahawkresolver" )
{
// HACK if this is a spotify resolver, we treat it 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 );
if ( !acct )
{
QFileInfo fi( resolver );
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
tr( "Resolver installation from file %1 failed." )
.arg( fi.fileName() ) ) );
tDebug() << "Resolver was not installed:" << resolver;
return;
}
AccountManager::instance()->addAccount( acct );
TomahawkSettings::instance()->addAccount( acct->accountId() );
AccountManager::instance()->enableAccount( acct );
GlobalActionManager::instance()->installResolverFromFile( resolver );
}
}