From a84b5024f63e87e584f0ed6683fc7ef40755ad55 Mon Sep 17 00:00:00 2001 From: Kilian Lackhove Date: Wed, 12 Sep 2012 13:31:36 +0200 Subject: [PATCH] use resolver icons from scriptresolver --- src/libtomahawk/resolvers/QtScriptResolver.cpp | 15 ++++++++++++++- src/libtomahawk/resolvers/QtScriptResolver.h | 2 ++ src/libtomahawk/resolvers/ScriptResolver.cpp | 18 ++++++++++++++++-- src/libtomahawk/resolvers/ScriptResolver.h | 2 ++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 6b1d1ec5e..769572bd1 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -231,6 +231,13 @@ QtScriptResolver::QtScriptResolver( const QString& scriptPath ) m_engine = new ScriptEngine( this ); m_name = QFileInfo( filePath() ).baseName(); + // set the icon, if we launch properly we'll get the icon the resolver reports + QString iconPath = QFileInfo( filePath() ).path() + "/../images/icon.png"; + if ( !m_icon.load( iconPath ) ) + { + m_icon = QPixmap( RESPATH "images/resolver-default.png" ); + } + if ( !QFile::exists( filePath() ) ) { tLog() << Q_FUNC_INFO << "Failed loading JavaScript resolver:" << scriptPath; @@ -322,13 +329,18 @@ QtScriptResolver::init() m_name = m.value( "name" ).toString(); m_weight = m.value( "weight", 0 ).toUInt(); m_timeout = m.value( "timeout", 25 ).toUInt() * 1000; + QString iconPath = QFileInfo( filePath() ).path() + "/" + m.value( "icon" ).toString(); + if ( !m_icon.load( iconPath ) ) + { + iconPath = "none"; + } // load config widget and apply settings loadUi(); QVariantMap config = resolverUserConfig(); fillDataInWidgets( config ); - qDebug() << "JS" << filePath() << "READY," << "name" << m_name << "weight" << m_weight << "timeout" << m_timeout; + qDebug() << "JS" << filePath() << "READY," << "name" << m_name << "weight" << m_weight << "timeout" << m_timeout << "icon" << iconPath; m_ready = true; } @@ -426,6 +438,7 @@ QtScriptResolver::parseResultVariantList( const QVariantList& reslist ) rp->setSize( m.value( "size" ).toUInt() ); rp->setRID( uuid() ); rp->setFriendlySource( name() ); + rp->setSourceIcon( icon() ); rp->setScore( m.value( "score" ).toFloat() ); rp->setDiscNumber( m.value( "discnumber" ).toUInt() ); diff --git a/src/libtomahawk/resolvers/QtScriptResolver.h b/src/libtomahawk/resolvers/QtScriptResolver.h index c2dae5210..cc157d511 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.h +++ b/src/libtomahawk/resolvers/QtScriptResolver.h @@ -130,6 +130,7 @@ public: static ExternalResolver* factory( const QString& scriptPath ); virtual QString name() const { return m_name; } + virtual QPixmap icon() const { return m_icon; } virtual unsigned int weight() const { return m_weight; } virtual unsigned int timeout() const { return m_timeout; } @@ -168,6 +169,7 @@ private: ScriptEngine* m_engine; QString m_name; + QPixmap m_icon; unsigned int m_weight, m_timeout; bool m_ready, m_stopped; diff --git a/src/libtomahawk/resolvers/ScriptResolver.cpp b/src/libtomahawk/resolvers/ScriptResolver.cpp index b5d5742cc..6d17687fa 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.cpp +++ b/src/libtomahawk/resolvers/ScriptResolver.cpp @@ -35,7 +35,7 @@ #include #endif -ScriptResolver::ScriptResolver( const QString& exe ) +ScriptResolver::ScriptResolver(const QString& exe) : Tomahawk::ExternalResolverGui( exe ) , m_num_restarts( 0 ) , m_msgsize( 0 ) @@ -57,6 +57,13 @@ ScriptResolver::ScriptResolver( const QString& exe ) // set the name to the binary, if we launch properly we'll get the name the resolver reports m_name = QFileInfo( filePath() ).baseName(); + + // set the icon, if we launch properly we'll get the icon the resolver reports + QString iconPath = QFileInfo( filePath() ).path() + "/../images/icon.png"; + if ( !m_icon.load( iconPath ) ) + { + m_icon = QPixmap( RESPATH "images/resolver-default.png" ); + } } @@ -279,6 +286,7 @@ ScriptResolver::handleMsg( const QByteArray& msg ) rp->setSize( m.value( "size" ).toUInt() ); rp->setRID( uuid() ); rp->setFriendlySource( m_name ); + rp->setSourceIcon( m_icon ); rp->setYear( m.value( "year").toUInt() ); rp->setDiscNumber( m.value( "discnumber" ).toUInt() ); @@ -371,7 +379,13 @@ ScriptResolver::doSetup( const QVariantMap& m ) m_name = m.value( "name" ).toString(); m_weight = m.value( "weight", 0 ).toUInt(); m_timeout = m.value( "timeout", 5 ).toUInt() * 1000; - qDebug() << "SCRIPT" << filePath() << "READY," << "name" << m_name << "weight" << m_weight << "timeout" << m_timeout; + QString iconPath = QFileInfo( filePath() ).path() + "/" + m.value( "icon" ).toString(); + if ( !m_icon.load( iconPath ) ) + { + iconPath = "none"; + } + + qDebug() << "SCRIPT" << filePath() << "READY," << "name" << m_name << "weight" << m_weight << "timeout" << m_timeout << "icon" << iconPath; m_ready = true; m_configSent = false; diff --git a/src/libtomahawk/resolvers/ScriptResolver.h b/src/libtomahawk/resolvers/ScriptResolver.h index 0ffb3ac33..2b19bc1c3 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.h +++ b/src/libtomahawk/resolvers/ScriptResolver.h @@ -42,6 +42,7 @@ public: static ExternalResolver* factory( const QString& exe ); virtual QString name() const { return m_name; } + virtual QPixmap icon() const { return m_icon; } virtual unsigned int weight() const { return m_weight; } virtual unsigned int preference() const { return m_preference; } virtual unsigned int timeout() const { return m_timeout; } @@ -82,6 +83,7 @@ private: QProcess m_proc; QString m_name; + QPixmap m_icon; unsigned int m_weight, m_preference, m_timeout, m_num_restarts; QWeakPointer< QWidget > m_configWidget;