From 2bba9ba000dd48a55a3a611241d0152ecfdec6c4 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 21 Nov 2011 03:57:26 +0100 Subject: [PATCH] ifdefs--: make pipeline ready for tomahawk-core --- src/libtomahawk/pipeline.cpp | 27 ++++++++++++------- src/libtomahawk/pipeline.h | 9 ++++--- .../resolvers/qtscriptresolver.cpp | 18 +++++++++++-- src/libtomahawk/resolvers/qtscriptresolver.h | 1 + src/libtomahawk/resolvers/scriptresolver.cpp | 16 +++++++++++ src/libtomahawk/resolvers/scriptresolver.h | 1 + src/tomahawkapp.cpp | 8 ++++++ 7 files changed, 65 insertions(+), 15 deletions(-) diff --git a/src/libtomahawk/pipeline.cpp b/src/libtomahawk/pipeline.cpp index caf146d80..1d459048a 100644 --- a/src/libtomahawk/pipeline.cpp +++ b/src/libtomahawk/pipeline.cpp @@ -114,22 +114,29 @@ Pipeline::addResolver( Resolver* r ) } +void +Pipeline::addExternalResolverFactory(boost::function< ExternalResolver*(QString) > resolverFactory) +{ + m_resolverFactories << resolverFactory; +} + + Tomahawk::ExternalResolver* Pipeline::addScriptResolver( const QString& path, bool start ) { ExternalResolver* res = 0; -#ifndef ENABLE_HEADLESS - const QFileInfo fi( path ); - if ( fi.suffix() == "js" || fi.suffix() == "script" ) - res = new QtScriptResolver( path ); - else - res = new ScriptResolver( path ); + Q_FOREACH(boost::function factory, m_resolverFactories) + { + res = factory( path ); - m_scriptResolvers << res; - if ( start ) - res->start(); -#endif + if( !res ) + continue; + + m_scriptResolvers << res; + if ( start ) + res->start(); + } return res; } diff --git a/src/libtomahawk/pipeline.h b/src/libtomahawk/pipeline.h index a9c0ea3e3..1ffcf42ed 100644 --- a/src/libtomahawk/pipeline.h +++ b/src/libtomahawk/pipeline.h @@ -19,14 +19,16 @@ #ifndef PIPELINE_H #define PIPELINE_H +#include "typedefs.h" +#include "query.h" + #include #include #include #include #include -#include "typedefs.h" -#include "query.h" +#include #include "dllmacro.h" @@ -50,6 +52,7 @@ public: void reportResults( QID qid, const QList< result_ptr >& results ); + void addExternalResolverFactory( boost::function resolverFactory ); Tomahawk::ExternalResolver* addScriptResolver( const QString& scriptPath, bool start = true ); void stopScriptResolver( const QString& scriptPath ); void removeScriptResolver( const QString& scriptPath ); @@ -101,7 +104,7 @@ private: QList< Resolver* > m_resolvers; QList< Tomahawk::ExternalResolver* > m_scriptResolvers; - + QList< boost::function > m_resolverFactories; QMap< QID, bool > m_qidsTimeout; QMap< QID, unsigned int > m_qidsState; QMap< QID, query_ptr > m_qids; diff --git a/src/libtomahawk/resolvers/qtscriptresolver.cpp b/src/libtomahawk/resolvers/qtscriptresolver.cpp index ab6de6a4f..2481be2a0 100644 --- a/src/libtomahawk/resolvers/qtscriptresolver.cpp +++ b/src/libtomahawk/resolvers/qtscriptresolver.cpp @@ -194,11 +194,9 @@ void ScriptEngine::javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& sourceID ) { tLog() << "JAVASCRIPT:" << m_scriptPath << message << lineNumber << sourceID; -#ifndef ENABLE_HEADLESS #ifdef DEBUG_BUILD QMessageBox::critical( 0, "Script Resolver Error", QString( "%1 %2 %3 %4" ).arg( m_scriptPath ).arg( message ).arg( lineNumber ).arg( sourceID ) ); #endif -#endif } @@ -232,6 +230,22 @@ QtScriptResolver::~QtScriptResolver() delete m_engine; } + +Tomahawk::ExternalResolver* QtScriptResolver::factory( const QString& scriptPath ) +{ + ExternalResolver* res = 0; + + const QFileInfo fi( scriptPath ); + if ( fi.suffix() == "js" || fi.suffix() == "script" ) + { + res = new QtScriptResolver( scriptPath ); + tLog() << Q_FUNC_INFO << scriptPath << "Loaded."; + } + + return res; +} + + bool QtScriptResolver::running() const { diff --git a/src/libtomahawk/resolvers/qtscriptresolver.h b/src/libtomahawk/resolvers/qtscriptresolver.h index a1c6b11d4..c7fcba1f4 100644 --- a/src/libtomahawk/resolvers/qtscriptresolver.h +++ b/src/libtomahawk/resolvers/qtscriptresolver.h @@ -123,6 +123,7 @@ friend class ::QtScriptResolverHelper; public: explicit QtScriptResolver( const QString& scriptPath ); virtual ~QtScriptResolver(); + static ExternalResolver* factory( const QString& scriptPath ); virtual QString name() const { return m_name; } virtual unsigned int weight() const { return m_weight; } diff --git a/src/libtomahawk/resolvers/scriptresolver.cpp b/src/libtomahawk/resolvers/scriptresolver.cpp index 9353ba1f7..959253b2b 100644 --- a/src/libtomahawk/resolvers/scriptresolver.cpp +++ b/src/libtomahawk/resolvers/scriptresolver.cpp @@ -79,6 +79,22 @@ ScriptResolver::~ScriptResolver() delete m_configWidget.data(); } +Tomahawk::ExternalResolver* +ScriptResolver::factory(const QString& exe) +{ + ExternalResolver* res = 0; + + const QFileInfo fi( exe ); + if ( fi.suffix() != "js" && fi.suffix() != "script" ) + { + res = new ScriptResolver( exe ); + tLog() << Q_FUNC_INFO << exe << "Loaded."; + } + + return res; +} + + void ScriptResolver::start() { diff --git a/src/libtomahawk/resolvers/scriptresolver.h b/src/libtomahawk/resolvers/scriptresolver.h index 8cf904e49..e635089ec 100644 --- a/src/libtomahawk/resolvers/scriptresolver.h +++ b/src/libtomahawk/resolvers/scriptresolver.h @@ -39,6 +39,7 @@ Q_OBJECT public: explicit ScriptResolver( const QString& exe ); virtual ~ScriptResolver(); + static ExternalResolver* factory( const QString& exe ); virtual QString name() const { return m_name; } virtual unsigned int weight() const { return m_weight; } diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index 912ceb70e..edac4a16e 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -65,6 +65,8 @@ #include "config.h" #ifndef ENABLE_HEADLESS + #include "resolvers/qtscriptresolver.h" + #include "resolvers/scriptresolver.h" #include "utils/spotifyparser.h" #include "AtticaManager.h" #include "tomahawkwindow.h" @@ -164,9 +166,15 @@ TomahawkApp::init() m_audioEngine = QWeakPointer( new AudioEngine ); m_scanManager = QWeakPointer( new ScanManager( this ) ); + + // init pipeline and resolver factories new Pipeline( this ); #ifndef ENABLE_HEADLESS + Pipeline::instance()->addExternalResolverFactory( boost::bind( &QtScriptResolver::factory, _1 ) ); + Pipeline::instance()->addExternalResolverFactory( boost::bind( &ScriptResolver::factory, _1 ) ); + + new ActionCollection( this ); connect( ActionCollection::instance()->getAction( "quit" ), SIGNAL( triggered() ), SLOT( quit() ), Qt::UniqueConnection ); #endif