1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-10 08:04:25 +02:00

Hook up some removing

This commit is contained in:
Leo Franchi
2012-01-29 10:04:20 -05:00
parent b78a348712
commit 7e13f1ae62
5 changed files with 43 additions and 6 deletions

View File

@@ -464,6 +464,9 @@ AtticaManager::extractPayload( const QString& filename, const QString& resolverI
void void
AtticaManager::uninstallResolver( const QString& pathToResolver ) AtticaManager::uninstallResolver( const QString& pathToResolver )
{ {
// when is this used? find and fix
Q_ASSERT(false);
// User manually removed a resolver not through attica dialog, simple remove // User manually removed a resolver not through attica dialog, simple remove
QRegExp r( ".*([^/]*)/contents/code/main.js" ); QRegExp r( ".*([^/]*)/contents/code/main.js" );
r.indexIn( pathToResolver ); r.indexIn( pathToResolver );
@@ -495,6 +498,19 @@ AtticaManager::uninstallResolver( const Content& resolver )
m_resolverStates[ resolver.id() ].state = Uninstalled; m_resolverStates[ resolver.id() ].state = Uninstalled;
TomahawkSettingsGui::instanceGui()->setAtticaResolverState( resolver.id(), Uninstalled ); TomahawkSettingsGui::instanceGui()->setAtticaResolverState( resolver.id(), Uninstalled );
// remove account as well
QList< Tomahawk::Accounts::Account* > accounts = Tomahawk::Accounts::AccountManager::instance()->accounts( Tomahawk::Accounts::ResolverType );
foreach ( Tomahawk::Accounts::Account* account, accounts )
{
if ( Tomahawk::Accounts::AtticaResolverAccount* atticaAccount = qobject_cast< Tomahawk::Accounts::AtticaResolverAccount* >( account ) )
{
if ( atticaAccount->atticaId() == resolver.id() ) // this is the account we want to remove
{
Tomahawk::Accounts::AccountManager::instance()->removeAccount( atticaAccount );
}
}
}
} }
Tomahawk::Pipeline::instance()->removeScriptResolver( pathFromId( resolver.id() ) ); Tomahawk::Pipeline::instance()->removeScriptResolver( pathFromId( resolver.id() ) );

View File

@@ -49,7 +49,10 @@ Account*
ResolverAccountFactory::createFromPath( const QString& path, bool isAttica ) ResolverAccountFactory::createFromPath( const QString& path, bool isAttica )
{ {
if ( isAttica ) if ( isAttica )
return new AtticaResolverAccount( generateId( "resolveraccount" ), path ); {
QFileInfo info( path );
return new AtticaResolverAccount( generateId( "resolveraccount" ), path, info.baseName() );
}
else else
return new ResolverAccount( generateId( "resolveraccount" ), path ); return new ResolverAccount( generateId( "resolveraccount" ), path );
} }
@@ -159,11 +162,13 @@ void
ResolverAccount::removeFromConfig() ResolverAccount::removeFromConfig()
{ {
// TODO // TODO
Account::removeFromConfig();
} }
void ResolverAccount::saveConfig() void ResolverAccount::saveConfig()
{ {
Account::saveConfig();
m_resolver->saveConfig(); m_resolver->saveConfig();
} }
@@ -188,12 +193,18 @@ ResolverAccount::resolverChanged()
AtticaResolverAccount::AtticaResolverAccount( const QString& accountId ) AtticaResolverAccount::AtticaResolverAccount( const QString& accountId )
: ResolverAccount( accountId ) : ResolverAccount( accountId )
{ {
m_atticaId = configuration().value( "atticaId" ).toString();
loadIcon(); loadIcon();
} }
AtticaResolverAccount::AtticaResolverAccount( const QString& accountId, const QString& path ) AtticaResolverAccount::AtticaResolverAccount( const QString& accountId, const QString& path, const QString& atticaId )
: ResolverAccount( accountId, path ) : ResolverAccount( accountId, path )
, m_atticaId( atticaId )
{ {
QVariantHash conf = configuration();
conf[ "atticaid" ] = atticaId;
setConfiguration( conf );
loadIcon(); loadIcon();
} }

View File

@@ -54,6 +54,7 @@ class ResolverAccount : public Account
{ {
Q_OBJECT Q_OBJECT
public: public:
// Loads from config. Must already exist.
explicit ResolverAccount( const QString& accountId ); explicit ResolverAccount( const QString& accountId );
virtual ~ResolverAccount(); virtual ~ResolverAccount();
@@ -80,6 +81,7 @@ private slots:
void resolverChanged(); void resolverChanged();
protected: protected:
// Created by factory, when user installs a new resolver
ResolverAccount( const QString& accountId, const QString& path ); ResolverAccount( const QString& accountId, const QString& path );
ExternalResolverGui* m_resolver; ExternalResolverGui* m_resolver;
@@ -95,17 +97,21 @@ class AtticaResolverAccount : public ResolverAccount
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AtticaResolverAccount(const QString& accountId); // Loads from config
explicit AtticaResolverAccount( const QString& accountId );
virtual ~AtticaResolverAccount(); virtual ~AtticaResolverAccount();
virtual QPixmap icon() const; virtual QPixmap icon() const;
QString atticaId() const { return m_atticaId; }
private: private:
AtticaResolverAccount( const QString& accountId, const QString& path ); // Created by factory, when user installs a new resolver
AtticaResolverAccount( const QString& accountId, const QString& path, const QString& atticaId );
void loadIcon(); void loadIcon();
QPixmap m_icon; QPixmap m_icon;
QString m_atticaId;
friend class ResolverAccountFactory; friend class ResolverAccountFactory;
}; };

View File

@@ -273,12 +273,17 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion )
QVariantHash configuration; QVariantHash configuration;
configuration[ "path" ] = resolver; configuration[ "path" ] = resolver;
setValue( "configuration", configuration );
// reasonably ugly check for attica resolvers // reasonably ugly check for attica resolvers
if ( resolver.contains( "atticaresolvers" ) && resolver.contains( "code" ) ) if ( resolver.contains( "atticaresolvers" ) && resolver.contains( "code" ) )
{
setValue( "atticaresolver", true ); setValue( "atticaresolver", true );
QFileInfo info( resolver );
configuration[ "atticaId" ] = info.baseName();
}
setValue( "configuration", configuration );
endGroup(); endGroup();
} }

View File

@@ -573,7 +573,6 @@ SettingsDialog::accountCreateConfigClosed( int finished )
void void
SettingsDialog::handleAccountAdded( Account* account, bool added ) SettingsDialog::handleAccountAdded( Account* account, bool added )
{ {
AccountFactory* f = AccountManager::instance()->factoryForAccount( account );
if ( added ) if ( added )
{ {
account->setEnabled( true ); account->setEnabled( true );