diff --git a/src/libtomahawk/GlobalActionManager.cpp b/src/libtomahawk/GlobalActionManager.cpp index 8efca639d..e4c898637 100644 --- a/src/libtomahawk/GlobalActionManager.cpp +++ b/src/libtomahawk/GlobalActionManager.cpp @@ -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 ) { diff --git a/src/libtomahawk/GlobalActionManager.h b/src/libtomahawk/GlobalActionManager.h index e09fb1cf9..09e7d94b2 100644 --- a/src/libtomahawk/GlobalActionManager.h +++ b/src/libtomahawk/GlobalActionManager.h @@ -46,6 +46,8 @@ public: QUrl openLink( const QString& title, const QString& artist, const QString& album ) const; + void installResolverFromFile( const QString& resolverPath ); + public slots: /** diff --git a/src/tomahawk/TomahawkApp.cpp b/src/tomahawk/TomahawkApp.cpp index 8dc0390e6..fe9d394fd 100644 --- a/src/tomahawk/TomahawkApp.cpp +++ b/src/tomahawk/TomahawkApp.cpp @@ -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 ); diff --git a/src/tomahawk/dialogs/SettingsDialog.cpp b/src/tomahawk/dialogs/SettingsDialog.cpp index f58495df8..6c0b3a5e2 100644 --- a/src/tomahawk/dialogs/SettingsDialog.cpp +++ b/src/tomahawk/dialogs/SettingsDialog.cpp @@ -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 ); } }