1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 16:29:43 +01:00

Refactor the resolver system a bit so we have real objects instead of paths

This commit is contained in:
Leo Franchi 2011-09-09 18:16:18 -04:00
parent 6ec2fae320
commit dbb9d14deb
12 changed files with 237 additions and 141 deletions

View File

@ -161,7 +161,8 @@ AtticaManager::payloadFetched()
if( !resolverPath.isEmpty() )
{
TomahawkApp::instance()->enableScriptResolver( resolverPath );
// Do the install / add to tomahawk
TomahawkApp::instance()->addScriptResolver( resolverPath, true );
m_resolverStates[ resolverId ] = Installed;
TomahawkSettings::instance()->setAtticaResolverState( resolverId, Installed );
emit resolverInstalled( resolverId );
@ -243,34 +244,63 @@ AtticaManager::extractPayload( const QString& filename, const QString& resolverI
return QString( QFile( resolverDir.absolutePath() + "/contents/code/main.js" ).fileName() );
}
void
AtticaManager::uninstallResolver( const QString& pathToResolver )
{
// User manually removed a resolver not through attica dialog, simple remove
QRegExp r( ".*([^/]*)/contents/code/main.js" );
r.indexIn( pathToResolver );
const QString& atticaId = r.cap( 1 );
tDebug() << "Got resolver ID to remove:" << atticaId;
if ( !atticaId.isEmpty() ) // this is an attica-installed resolver, mark as uninstalled
{
foreach ( const Content& resolver, m_resolvers )
{
if ( resolver.id() == atticaId ) // this is the one
{
m_resolverStates[ atticaId ] = Uninstalled;
TomahawkSettings::instance()->setAtticaResolverState( atticaId, Uninstalled );
doResolverRemove( atticaId );
}
}
}
}
void
AtticaManager::uninstallResolver( const Content& resolver )
{
TomahawkApp::instance()->disableScriptResolver( resolver.id() );
m_resolverStates[ resolver.id() ] = Uninstalled;
TomahawkSettings::instance()->setAtticaResolverState( resolver.id(), Uninstalled );
emit resolverUninstalled( resolver.id() );
emit resolverStateChanged( resolver.id() );
TomahawkApp::instance()->removeScriptResolver( pathFromId( resolver.id() ) );
m_resolverStates[ resolver.id() ] = Uninstalled;
TomahawkSettings::instance()->setAtticaResolverState( resolver.id(), Uninstalled );
doResolverRemove( resolver.id() );
}
void
AtticaManager::doResolverRemove( const QString& id ) const
{
// uninstalling is easy... just delete it! :)
QDir resolverDir = TomahawkUtils::appDataDir();
if ( !resolverDir.cd( QString( "atticaresolvers/%1" ).arg( resolver.id() ) ) )
if ( !resolverDir.cd( QString( "atticaresolvers/%1" ).arg( id ) ) )
return;
if ( resolver.id().isEmpty() )
if ( id.isEmpty() )
return;
// sanity check
if ( !resolverDir.absolutePath().contains( "atticaresolvers" ) ||
!resolverDir.absolutePath().contains( resolver.id() ) )
!resolverDir.absolutePath().contains( id ) )
return;
removeDirectory( resolverDir.absolutePath() );
}
// taken from util/fileutils.cpp in kdevplatform
bool
AtticaManager::removeDirectory( const QString& dir ) const

View File

@ -63,6 +63,7 @@ public:
void installResolver( const Attica::Content& resolver );
void uninstallResolver( const Attica::Content& resolver );
void uninstallResolver( const QString& pathToResolver );
QString pathFromId( const QString& resolverId ) const;
signals:
@ -80,6 +81,7 @@ private slots:
private:
QString extractPayload( const QString& filename, const QString& resolverId ) const;
void doResolverRemove( const QString& id ) const;
bool removeDirectory( const QString& dir ) const;
Attica::ProviderManager m_manager;

View File

@ -54,6 +54,12 @@ public slots:
virtual void resolve( const Tomahawk::query_ptr& query ) = 0;
};
/**
* Generic resolver object, used to manage a resolver that Tomahawk knows about
*
* You *must* start() a resolver after creating an ExternalResolver in order to use it,
* otherwise it will not do anything.
*/
class DLLEXPORT ExternalResolver : public Resolver
{
Q_OBJECT
@ -73,8 +79,10 @@ public:
virtual void reload() {} // Reloads from file (especially useful to check if file now exists)
virtual ErrorState error() const;
virtual bool running() const = 0;
public slots:
virtual void start() = 0;
virtual void stop() = 0;
signals:

View File

@ -163,7 +163,7 @@ ScriptEngine::javaScriptConsoleMessage( const QString& message, int lineNumber,
QtScriptResolver::QtScriptResolver( const QString& scriptPath )
: Tomahawk::ExternalResolver( scriptPath )
, m_ready( false )
, m_stopped( false )
, m_stopped( true )
, m_error( Tomahawk::ExternalResolver::NoError )
, m_resolverHelper( new QtScriptResolverHelper( scriptPath, this ) )
{
@ -179,7 +179,6 @@ QtScriptResolver::QtScriptResolver( const QString& scriptPath )
{
init();
}
}
@ -189,6 +188,11 @@ QtScriptResolver::~QtScriptResolver()
delete m_engine;
}
bool
QtScriptResolver::running() const
{
return m_ready && !m_stopped;
}
void
QtScriptResolver::reload()
@ -247,7 +251,16 @@ QtScriptResolver::init()
qDebug() << "JS" << filePath() << "READY," << "name" << m_name << "weight" << m_weight << "timeout" << m_timeout;
m_ready = true;
Tomahawk::Pipeline::instance()->addResolver( this );
}
void
QtScriptResolver::start()
{
m_stopped = false;
if ( m_ready )
Tomahawk::Pipeline::instance()->addResolver( this );
else
init();
}
@ -359,7 +372,8 @@ void
QtScriptResolver::stop()
{
m_stopped = true;
emit finished();
Tomahawk::Pipeline::instance()->removeResolver( this );
emit stopped();
}

View File

@ -128,14 +128,16 @@ public:
virtual void saveConfig();
virtual ExternalResolver::ErrorState error() const;
virtual bool running() const;
virtual void reload();
public slots:
virtual void resolve( const Tomahawk::query_ptr& query );
virtual void stop();
virtual void start();
signals:
void finished();
void stopped();
private:
void init();

View File

@ -36,10 +36,10 @@ ScriptResolver::ScriptResolver( const QString& exe )
, m_num_restarts( 0 )
, m_msgsize( 0 )
, m_ready( false )
, m_stopped( false )
, m_stopped( true )
, m_error( Tomahawk::ExternalResolver::NoError )
{
tLog() << Q_FUNC_INFO << "Loading script resolver:" << exe;
tLog() << Q_FUNC_INFO << "Created script resolver:" << exe;
connect( &m_proc, SIGNAL( readyReadStandardError() ), SLOT( readStderr() ) );
connect( &m_proc, SIGNAL( readyReadStandardOutput() ), SLOT( readStdout() ) );
connect( &m_proc, SIGNAL( finished( int, QProcess::ExitStatus ) ), SLOT( cmdExited( int, QProcess::ExitStatus ) ) );
@ -73,6 +73,16 @@ ScriptResolver::~ScriptResolver()
delete m_configWidget.data();
}
void
ScriptResolver::start()
{
m_stopped = false;
if ( m_ready )
Tomahawk::Pipeline::instance()->addResolver( this );
else
sendConfig();
}
void
ScriptResolver::sendConfig()
@ -116,6 +126,11 @@ ScriptResolver::reload()
}
}
bool
ScriptResolver::running() const
{
return !m_stopped;
}
void
ScriptResolver::readStderr()
@ -123,7 +138,6 @@ ScriptResolver::readStderr()
tLog() << "SCRIPT_STDERR" << filePath() << m_proc.readAllStandardError();
}
ScriptResolver::ErrorState
ScriptResolver::error() const
{
@ -255,7 +269,7 @@ ScriptResolver::cmdExited( int code, QProcess::ExitStatus status )
if ( m_stopped )
{
tLog() << "*** Script resolver stopped ";
emit finished();
emit stopped();
return;
}
@ -310,7 +324,9 @@ ScriptResolver::doSetup( const QVariantMap& m )
qDebug() << "SCRIPT" << filePath() << "READY," << "name" << m_name << "weight" << m_weight << "timeout" << m_timeout;
m_ready = true;
Tomahawk::Pipeline::instance()->addResolver( this );
if ( !m_stopped )
Tomahawk::Pipeline::instance()->addResolver( this );
}
@ -363,5 +379,5 @@ void
ScriptResolver::stop()
{
m_stopped = true;
m_proc.kill();
Tomahawk::Pipeline::instance()->removeResolver( this );
}

View File

@ -39,6 +39,7 @@ public:
explicit ScriptResolver( const QString& exe );
virtual ~ScriptResolver();
virtual QString name() const { return m_name; }
virtual unsigned int weight() const { return m_weight; }
virtual unsigned int preference() const { return m_preference; }
@ -50,12 +51,14 @@ public:
virtual ExternalResolver::ErrorState error() const;
virtual void reload();
virtual bool running() const;
signals:
void finished();
void stopped();
public slots:
virtual void stop();
virtual void resolve( const Tomahawk::query_ptr& query );
virtual void start();
private slots:
void readStderr();

View File

@ -1,6 +1,6 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -27,22 +27,9 @@
#include "utils/logger.h"
ResolversModel::ResolversModel( const QStringList& allResolvers, const QStringList& enabledResolvers, QObject* parent )
ResolversModel::ResolversModel( QObject* parent )
: QAbstractListModel( parent )
, m_allResolvers( allResolvers )
, m_enabledResolvers( enabledResolvers )
{
// do some sanity checking just in case
bool changed = false;
foreach( const QString& l, m_enabledResolvers ) {
if( !m_allResolvers.contains( l ) ) {
m_enabledResolvers.removeAll( l );
changed = true;
}
}
if( changed )
TomahawkSettings::instance()->setEnabledScriptResolvers( m_enabledResolvers );
addInstalledResolvers();
}
@ -55,33 +42,25 @@ ResolversModel::~ResolversModel()
QVariant
ResolversModel::data( const QModelIndex& index, int role ) const
{
if( !index.isValid() )
if( !index.isValid() || !hasIndex( index.row(), index.column(), QModelIndex() ) )
return QVariant();
Tomahawk::ExternalResolver* res = TomahawkApp::instance()->scriptResolvers().at( index.row() );
switch( role )
{
case Qt::DisplayRole:
case ResolversModel::ResolverName:
{
QFileInfo info( m_allResolvers.at( index.row() ) );
return info.baseName();
}
return res->name();
case ResolversModel::ResolverPath:
return m_allResolvers.at( index.row() );
return res->filePath();
case ResolversModel::HasConfig:
if( Tomahawk::ExternalResolver* r = TomahawkApp::instance()->resolverForPath( m_allResolvers.at( index.row() ) ) ) // if we have one, it means we are loaded too!
return r->configUI() != 0;
return false;
return res->configUI() != 0;
case ResolversModel::ErrorState:
if( Tomahawk::ExternalResolver* r = TomahawkApp::instance()->resolverForPath( m_allResolvers.at( index.row() ) ) ) // if we have one, it means we are loaded too!
return r->error();
else if( !QFile::exists( m_allResolvers.at( index.row() ) ) )
return Tomahawk::ExternalResolver::FileNotFound;
return Tomahawk::ExternalResolver::NoError;
return res->error();
case Qt::CheckStateRole:
return m_enabledResolvers.contains( m_allResolvers.at( index.row() ) ) ? Qt::Checked : Qt::Unchecked;
return res->running() ? Qt::Checked : Qt::Unchecked;
case Qt::ToolTipRole:
return m_allResolvers.at( index.row() );
return res->filePath();
default:
return QVariant();
}
@ -90,37 +69,35 @@ ResolversModel::data( const QModelIndex& index, int role ) const
bool
ResolversModel::setData( const QModelIndex& index, const QVariant& value, int role )
{
Tomahawk::ExternalResolver* r = TomahawkApp::instance()->resolverForPath( m_allResolvers.at( index.row() ) );
if( r && r->error() == Tomahawk::ExternalResolver::FileNotFound ) // give it a shot to see if the user manually fixed paths
if ( !hasIndex( index.row(), index.column(), QModelIndex() ) )
return false;
Tomahawk::ExternalResolver* r = TomahawkApp::instance()->scriptResolvers().at( index.row() );
if ( r && r->error() == Tomahawk::ExternalResolver::FileNotFound ) // give it a shot to see if the user manually fixed paths
{
r->reload();
if( r->error() == Tomahawk::ExternalResolver::FileNotFound ) // Nope, no luck. Doesn't exist on disk, don't let user mess with it
return false;
} else if( !r && !QFile::exists( index.data( ResolverPath ).toString() ) ) {
}
else if ( !r && !QFile::exists( r->filePath() ) )
{
return false;
}
if( role == Qt::CheckStateRole ) {
if ( role == Qt::CheckStateRole )
{
Qt::CheckState state = static_cast< Qt::CheckState >( value.toInt() );
QString resolver = m_allResolvers.at( index.row() );
if( state == Qt::Checked && !m_enabledResolvers.contains( resolver ) ) {
m_enabledResolvers.append( resolver );
TomahawkApp::instance()->enableScriptResolver( resolver );
emit dataChanged( index, index );
if( Tomahawk::ExternalResolver* res = TomahawkApp::instance()->resolverForPath( resolver ) ) {
connect( res, SIGNAL( changed() ), this, SLOT( resolverChanged() ) );
}
} else if( state == Qt::Unchecked ) {
m_enabledResolvers.removeAll( resolver );
TomahawkApp::instance()->disableScriptResolver( resolver );
if ( state == Qt::Checked && !r->running() ) {
r->start();
}
else if ( state == Qt::Unchecked )
{
r->stop();
}
dataChanged( index, index );
emit dataChanged( index, index );
return true;
}
return false;
@ -131,7 +108,7 @@ int
ResolversModel::rowCount( const QModelIndex& parent ) const
{
Q_UNUSED( parent );
return m_allResolvers.size();
return APP->scriptResolvers().count();
}
int
@ -151,52 +128,50 @@ ResolversModel::flags( const QModelIndex& index ) const
void
ResolversModel::addResolver( const QString& resolver, bool enable )
{
beginInsertRows( QModelIndex(), m_allResolvers.count(), m_allResolvers.count() );
m_allResolvers << resolver;
if( enable )
m_enabledResolvers << resolver;
if( Tomahawk::ExternalResolver* res = TomahawkApp::instance()->resolverForPath( resolver ) ) {
qDebug() << "Added resolver with config and stuff:" << res->configUI();
connect( res, SIGNAL( changed() ), this, SLOT( resolverChanged() ) );
} else
qDebug() << "No resolver object for path yet:" << resolver;
const int count = rowCount( QModelIndex() );
beginInsertRows( QModelIndex(), count, count );
Tomahawk::ExternalResolver* res = APP->addScriptResolver( resolver, enable );
connect( res, SIGNAL( changed() ), this, SLOT( resolverChanged() ) );
endInsertRows();
}
void
ResolversModel::atticaResolverInstalled( const QString& resolverId )
{
Tomahawk::ExternalResolver* r = APP->resolverForPath( AtticaManager::instance()->pathFromId( resolverId ) );
if ( !r )
return;
const int idx = APP->scriptResolvers().indexOf( r );
if ( idx >= 0 )
{
beginInsertRows( QModelIndex(), idx, idx );
endInsertRows();
}
}
void
ResolversModel::removeResolver( const QString& resolver )
{
for( int i = 0; i < m_allResolvers.count(); i++ ) {
if( m_allResolvers.at( i ) == resolver ) {
beginRemoveRows( QModelIndex(), i, i );
m_allResolvers.takeAt( i );
endRemoveRows();
}
}
m_enabledResolvers.removeAll( resolver );
}
const int idx = APP->scriptResolvers().indexOf( APP->resolverForPath( resolver ) );
if ( idx < 0 )
return;
QStringList
ResolversModel::allResolvers() const
{
return m_allResolvers;
}
QStringList
ResolversModel::enabledResolvers() const
{
return m_enabledResolvers;
beginRemoveRows( QModelIndex(), idx, idx );
APP->removeScriptResolver( resolver );
endRemoveRows();
}
void
ResolversModel::resolverChanged()
{
Q_ASSERT( qobject_cast< Tomahawk::ExternalResolver* >( sender() ) );
Tomahawk::ExternalResolver* res = qobject_cast< Tomahawk::ExternalResolver* >( sender() );
qDebug() << "Got resolverChanged signal, does it have a config UI yet?" << res->configUI();
if( m_enabledResolvers.contains( res->filePath() ) ) {
QModelIndex idx = index( m_allResolvers.indexOf( res->filePath() ), 0, QModelIndex() );
Q_ASSERT( res );
if ( APP->scriptResolvers().contains( res ) )
{
qDebug() << "Got resolverChanged signal, does it have a config UI yet?" << res->configUI();
const QModelIndex idx = index( APP->scriptResolvers().indexOf( res ), 0, QModelIndex() );
emit dataChanged( idx, idx );
}
}
@ -220,10 +195,30 @@ ResolversModel::addInstalledResolvers()
foreach ( QString fileName, pluginDir.entryList( QStringList() << "*_tomahawkresolver*", QDir::Files ) ){
if ( fileName.contains( "_tomahawkresolver" ) ) {
const QString path = pluginDir.absoluteFilePath( fileName );
if( !m_allResolvers.contains( path ) ) {
m_allResolvers.append( path );
bool found = false;
foreach ( Tomahawk::ExternalResolver* res, APP->scriptResolvers() )
{
if ( res->filePath() == path )
found = true;
}
if ( !found ) {
APP->addScriptResolver( path, false );
}
}
}
}
}
void
ResolversModel::saveScriptResolvers()
{
QStringList enabled, all;
foreach ( Tomahawk::ExternalResolver* res, APP->scriptResolvers() )
{
all << res->filePath();
if ( res->running() )
enabled << res->filePath();
}
TomahawkSettings::instance()->setAllScriptResolvers( all );
TomahawkSettings::instance()->setEnabledScriptResolvers( enabled );
}

View File

@ -1,6 +1,6 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -35,7 +35,7 @@ public:
ErrorState = Qt::UserRole + 18
};
explicit ResolversModel( const QStringList& allResolvers, const QStringList& enabledResolvers, QObject* parent = 0 );
explicit ResolversModel( QObject* parent = 0 );
virtual ~ResolversModel();
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
@ -45,19 +45,15 @@ public:
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
void addResolver( const QString& resolver, bool enable = false );
void atticaResolverInstalled ( const QString& resolverId );
void removeResolver( const QString& resolver );
QStringList allResolvers() const;
QStringList enabledResolvers() const;
void saveScriptResolvers();
private slots:
void resolverChanged();
private:
void addInstalledResolvers();
QStringList m_allResolvers;
QStringList m_enabledResolvers;
};
#endif // RESOLVERSMODEL_H

View File

@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -188,7 +189,7 @@ SettingsDialog::SettingsDialog( QWidget *parent )
ResolverConfigDelegate* del = new ResolverConfigDelegate( this );
connect( del, SIGNAL( openConfig( QString ) ), this, SLOT( openResolverConfig( QString ) ) );
ui->scriptList->setItemDelegate( del );
m_resolversModel = new ResolversModel( s->allScriptResolvers(), s->enabledScriptResolvers(), this );
m_resolversModel = new ResolversModel( this );
ui->scriptList->setModel( m_resolversModel );
#ifdef LIBATTICA_FOUND
@ -239,8 +240,7 @@ SettingsDialog::~SettingsDialog()
s->setLastFmUsername( ui->lineEditLastfmUsername->text() );
s->setLastFmPassword( ui->lineEditLastfmPassword->text() );
s->setAllScriptResolvers( m_resolversModel->allResolvers() );
s->setEnabledScriptResolvers( m_resolversModel->enabledResolvers() );
m_resolversModel->saveScriptResolvers();
s->applyChanges();
}
@ -527,8 +527,8 @@ SettingsDialog::addScriptResolver()
QString resolver = QFileDialog::getOpenFileName( this, tr( "Load script resolver file" ), TomahawkSettings::instance()->scriptDefaultPath() );
if( !resolver.isEmpty() )
{
TomahawkApp::instance()->enableScriptResolver( resolver );
m_resolversModel->addResolver( resolver, true );
QFileInfo resolverAbsoluteFilePath = resolver;
TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() );
}
@ -542,9 +542,8 @@ SettingsDialog::removeScriptResolver()
if( !ui->scriptList->selectionModel()->selectedIndexes().isEmpty() )
{
QString resolver = ui->scriptList->selectionModel()->selectedIndexes().first().data( ResolversModel::ResolverPath ).toString();
AtticaManager::instance()->uninstallResolver( resolver );
m_resolversModel->removeResolver( resolver );
TomahawkApp::instance()->disableScriptResolver( resolver );
}
}
@ -567,7 +566,7 @@ SettingsDialog::getMoreResolvers()
void
SettingsDialog::atticaResolverInstalled( const QString& resolverId )
{
m_resolversModel->addResolver( AtticaManager::instance()->pathFromId( resolverId ), true );
m_resolversModel->atticaResolverInstalled( resolverId );
}
void

View File

@ -266,10 +266,7 @@ TomahawkApp::~TomahawkApp()
tLog() << "Shutting down Tomahawk...";
// stop script resolvers
foreach( Tomahawk::ExternalResolver* r, m_scriptResolvers.values() )
{
delete r;
}
qDeleteAll( m_scriptResolvers );
m_scriptResolvers.clear();
if ( !m_servent.isNull() )
@ -449,32 +446,58 @@ TomahawkApp::initPipeline()
Pipeline::instance()->addResolver( new DatabaseResolver( 100 ) );
// load script resolvers
foreach( QString resolver, TomahawkSettings::instance()->enabledScriptResolvers() )
enableScriptResolver( resolver );
QStringList enabled = TomahawkSettings::instance()->enabledScriptResolvers();
foreach ( QString resolver, TomahawkSettings::instance()->allScriptResolvers() )
{
const bool enable = enabled.contains( resolver );
addScriptResolver( resolver, enable );
}
}
void
TomahawkApp::enableScriptResolver( const QString& path )
Tomahawk::ExternalResolver*
TomahawkApp::addScriptResolver( const QString& path, bool start )
{
const QFileInfo fi( path );
ExternalResolver* res = 0;
if ( fi.suffix() == "js" || fi.suffix() == "script" )
m_scriptResolvers.insert( path, new QtScriptResolver( path ) );
res = new QtScriptResolver( path );
else
m_scriptResolvers.insert( path, new ScriptResolver( path ) );
res = new ScriptResolver( path );
m_scriptResolvers << res;
if ( start )
res->start();
return res;
}
void
TomahawkApp::disableScriptResolver( const QString& path )
TomahawkApp::stopScriptResolver( const QString& path )
{
if ( m_scriptResolvers.contains( path ) )
foreach ( ExternalResolver* res, m_scriptResolvers )
{
Tomahawk::ExternalResolver* r = m_scriptResolvers.take( path );
if ( res->filePath() == path )
res->stop();
}
}
connect( r, SIGNAL( finished() ), r, SLOT( deleteLater() ) );
void
TomahawkApp::removeScriptResolver( const QString& scriptPath )
{
ExternalResolver* r = 0;
foreach ( ExternalResolver* res, m_scriptResolvers )
{
if ( res->filePath() == scriptPath )
r = res;
}
m_scriptResolvers.removeAll( r );
if ( r )
{
r->stop();
return;
connect( r, SIGNAL( stopped() ), r, SLOT( deleteLater() ) );
}
}
@ -482,7 +505,12 @@ TomahawkApp::disableScriptResolver( const QString& path )
Tomahawk::ExternalResolver*
TomahawkApp::resolverForPath( const QString& scriptPath )
{
return m_scriptResolvers.value( scriptPath, 0 );
foreach ( ExternalResolver* res, m_scriptResolvers )
{
if ( res->filePath() == scriptPath )
return res;
}
return 0;
}

View File

@ -90,8 +90,11 @@ public:
TomahawkWindow* mainWindow() const { return m_mainwindow; }
#endif
void enableScriptResolver( const QString& scriptPath );
void disableScriptResolver( const QString& scriptPath );
Tomahawk::ExternalResolver* addScriptResolver( const QString& scriptPath, bool start = true );
void stopScriptResolver( const QString& scriptPath );
void removeScriptResolver( const QString& scriptPath );
QList< Tomahawk::ExternalResolver* > scriptResolvers() const { return m_scriptResolvers; }
Tomahawk::ExternalResolver* resolverForPath( const QString& scriptPath );
// PlatformInterface
@ -120,7 +123,7 @@ private:
void loadPlugins();
QList<Tomahawk::collection_ptr> m_collections;
QHash<QString, Tomahawk::ExternalResolver*> m_scriptResolvers;
QList<Tomahawk::ExternalResolver*> m_scriptResolvers;
QWeakPointer<Database> m_database;
QWeakPointer<ScanManager> m_scanManager;