diff --git a/src/libtomahawk/AtticaManager.cpp b/src/libtomahawk/AtticaManager.cpp index f437bce81..cea2f64ce 100644 --- a/src/libtomahawk/AtticaManager.cpp +++ b/src/libtomahawk/AtticaManager.cpp @@ -34,75 +34,13 @@ #include "utils/Logger.h" #include "accounts/ResolverAccount.h" #include "accounts/AccountManager.h" +#include "utils/BinaryInstallerHelper.h" using namespace Attica; AtticaManager* AtticaManager::s_instance = 0; -class BinaryInstallerHelper : public QObject -{ - Q_OBJECT -public: - explicit BinaryInstallerHelper( const QString& resolverId, bool createAccount, AtticaManager* manager) - : QObject( manager ) - , m_manager( QWeakPointer< AtticaManager >( manager ) ) - , m_resolverId( resolverId ) - , m_createAccount( createAccount ) - { - Q_ASSERT( !m_resolverId.isEmpty() ); - Q_ASSERT( !m_manager.isNull() ); - - setProperty( "resolverid", m_resolverId ); - } - - virtual ~BinaryInstallerHelper() {} - -public slots: - void installSucceeded( const QString& path ) - { - qDebug() << Q_FUNC_INFO << "install of binary resolver succeeded, enabling: " << path; - - if ( m_manager.isNull() ) - return; - - if ( m_createAccount ) - { - Tomahawk::Accounts::Account* acct = Tomahawk::Accounts::AccountManager::instance()->accountFromPath( path ); - - Tomahawk::Accounts::AccountManager::instance()->addAccount( acct ); - TomahawkSettings::instance()->addAccount( acct->accountId() ); - Tomahawk::Accounts::AccountManager::instance()->enableAccount( acct ); - } - - m_manager.data()->m_resolverStates[ m_resolverId ].scriptPath = path; - m_manager.data()->m_resolverStates[ m_resolverId ].state = AtticaManager::Installed; - - TomahawkSettingsGui::instanceGui()->setAtticaResolverStates( m_manager.data()->m_resolverStates ); - emit m_manager.data()->resolverInstalled( m_resolverId ); - emit m_manager.data()->resolverStateChanged( m_resolverId ); - - deleteLater(); - } - void installFailed() - { - qDebug() << Q_FUNC_INFO << "install failed"; - - if ( m_manager.isNull() ) - return; - - m_manager.data()->resolverInstallationFailed( m_resolverId ); - - deleteLater(); - } - -private: - QString m_resolverId; - bool m_createAccount; - QWeakPointer m_manager; -}; - - AtticaManager::AtticaManager( QObject* parent ) : QObject( parent ) , m_resolverJobsLoaded( 0 ) @@ -714,5 +652,3 @@ AtticaManager::doResolverRemove( const QString& id ) const TomahawkUtils::removeDirectory( resolverDir.absolutePath() ); } - -#include "AtticaManager.moc" diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 501ef3188..8afdf6205 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -123,6 +123,7 @@ set( libGuiSources utils/PixmapDelegateFader.cpp utils/SmartPointerList.h utils/AnimatedSpinner.cpp + utils/BinaryInstallerHelper.cpp widgets/AnimatedCounterLabel.cpp widgets/CheckDirTree.cpp diff --git a/src/libtomahawk/utils/BinaryInstallerHelper.cpp b/src/libtomahawk/utils/BinaryInstallerHelper.cpp new file mode 100644 index 000000000..972840a0b --- /dev/null +++ b/src/libtomahawk/utils/BinaryInstallerHelper.cpp @@ -0,0 +1,73 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012 Leo Franchi + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "BinaryInstallerHelper.h" + +#include "accounts/AccountManager.h" +#include "TomahawkSettingsGui.h" + +BinaryInstallerHelper::BinaryInstallerHelper( const QString& resolverId, bool createAccount, AtticaManager* manager ) + : QObject( manager ) + , m_manager( QWeakPointer< AtticaManager >( manager ) ) + , m_resolverId( resolverId ) + , m_createAccount( createAccount ) +{ + Q_ASSERT( !m_resolverId.isEmpty() ); + Q_ASSERT( !m_manager.isNull() ); + + setProperty( "resolverid", m_resolverId ); +} + + +void +BinaryInstallerHelper::installSucceeded( const QString& path ) +{ + qDebug() << Q_FUNC_INFO << "install of binary resolver succeeded, enabling: " << path; + + if ( m_manager.isNull() ) + return; + + if ( m_createAccount ) + { + Tomahawk::Accounts::Account* acct = Tomahawk::Accounts::AccountManager::instance()->accountFromPath( path ); + + Tomahawk::Accounts::AccountManager::instance()->addAccount( acct ); + TomahawkSettings::instance()->addAccount( acct->accountId() ); + Tomahawk::Accounts::AccountManager::instance()->enableAccount( acct ); + } + + m_manager.data()->m_resolverStates[ m_resolverId ].scriptPath = path; + m_manager.data()->m_resolverStates[ m_resolverId ].state = AtticaManager::Installed; + + TomahawkSettingsGui::instanceGui()->setAtticaResolverStates( m_manager.data()->m_resolverStates ); + emit m_manager.data()->resolverInstalled( m_resolverId ); + emit m_manager.data()->resolverStateChanged( m_resolverId ); + + deleteLater(); +} +void BinaryInstallerHelper::installFailed() +{ + qDebug() << Q_FUNC_INFO << "install failed"; + + if ( m_manager.isNull() ) + return; + + m_manager.data()->resolverInstallationFailed( m_resolverId ); + + deleteLater(); +} diff --git a/src/libtomahawk/utils/BinaryInstallerHelper.h b/src/libtomahawk/utils/BinaryInstallerHelper.h new file mode 100644 index 000000000..511584581 --- /dev/null +++ b/src/libtomahawk/utils/BinaryInstallerHelper.h @@ -0,0 +1,43 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012 Leo Franchi + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ +#ifndef BINARY_INSTALLER_HELPER +#define BINARY_INSTALLER_HELPER + +#include "AtticaManager.h" + +#include + +class BinaryInstallerHelper : public QObject +{ + Q_OBJECT +public: + explicit BinaryInstallerHelper( const QString& resolverId, bool createAccount, AtticaManager* manager ); + + virtual ~BinaryInstallerHelper() {} + +public slots: + void installSucceeded( const QString& path ); + void installFailed(); + +private: + QString m_resolverId; + bool m_createAccount; + QWeakPointer m_manager; +}; + +#endif \ No newline at end of file