diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 84fc5b202..17df86396 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -82,7 +82,6 @@ set( libGuiSources playlist/dynamic/widgets/CollapsibleControls.cpp playlist/dynamic/widgets/DynamicSetupWidget.cpp - resolvers/ExternalResolverGui.cpp resolvers/ScriptResolver.cpp resolvers/JSInfoPlugin.cpp resolvers/JSInfoSystemHelper.cpp diff --git a/src/libtomahawk/Result.cpp b/src/libtomahawk/Result.cpp index 361c09cdb..f4d985281 100644 --- a/src/libtomahawk/Result.cpp +++ b/src/libtomahawk/Result.cpp @@ -24,7 +24,7 @@ #include "database/DatabaseCommand_AllTracks.h" #include "database/DatabaseCommand_AddFiles.h" #include "filemetadata/MetadataEditor.h" -#include "resolvers/ExternalResolverGui.h" +#include "resolvers/ExternalResolver.h" #include "resolvers/Resolver.h" #include "utils/TomahawkUtilsGui.h" #include "utils/Logger.h" diff --git a/src/libtomahawk/accounts/ResolverAccount.cpp b/src/libtomahawk/accounts/ResolverAccount.cpp index 4b83949f2..972df22ea 100644 --- a/src/libtomahawk/accounts/ResolverAccount.cpp +++ b/src/libtomahawk/accounts/ResolverAccount.cpp @@ -27,7 +27,6 @@ #include "AtticaManager.h" #include "ConfigStorage.h" #include "resolvers/ExternalResolver.h" -#include "resolvers/ExternalResolverGui.h" #include "utils/Json.h" #include "utils/Logger.h" @@ -352,8 +351,7 @@ ResolverAccount::hookupResolver() if ( configuration().contains( "scripts" ) ) additionalPaths = configuration().value( "scripts" ).toStringList(); - Tomahawk::ExternalResolver* er = Pipeline::instance()->addScriptResolver( accountId(), mainScriptPath, additionalPaths ); - m_resolver = QPointer< ExternalResolverGui >( qobject_cast< ExternalResolverGui* >( er ) ); + m_resolver = Pipeline::instance()->addScriptResolver( accountId(), mainScriptPath, additionalPaths ); connect( m_resolver.data(), SIGNAL( changed() ), this, SLOT( resolverChanged() ) ); // What resolver do we have here? Should only be types that are 'real' resolvers diff --git a/src/libtomahawk/accounts/ResolverAccount.h b/src/libtomahawk/accounts/ResolverAccount.h index f54621777..ee8da4b1c 100644 --- a/src/libtomahawk/accounts/ResolverAccount.h +++ b/src/libtomahawk/accounts/ResolverAccount.h @@ -29,7 +29,7 @@ class QDir; namespace Tomahawk { -class ExternalResolverGui; +class ExternalResolver; namespace Accounts { @@ -107,7 +107,7 @@ protected: ResolverAccount( const QString& accountId, const QString& path, const QVariantHash& initialConfiguration = QVariantHash() ); void hookupResolver(); - QPointer m_resolver; + QPointer m_resolver; private: void init( const QString& path ); diff --git a/src/libtomahawk/accounts/lastfm/LastFmAccount.cpp b/src/libtomahawk/accounts/lastfm/LastFmAccount.cpp index 3963b6fe1..981a04565 100644 --- a/src/libtomahawk/accounts/lastfm/LastFmAccount.cpp +++ b/src/libtomahawk/accounts/lastfm/LastFmAccount.cpp @@ -21,7 +21,7 @@ #include "infosystem/InfoSystem.h" #include "LastFmInfoPlugin.h" -#include "resolvers/ExternalResolverGui.h" +#include "resolvers/ExternalResolver.h" #include "utils/TomahawkUtilsGui.h" #include "AtticaManager.h" #include "Pipeline.h" @@ -286,11 +286,7 @@ LastFmAccount::hookupResolver() const AtticaManager::Resolver data = AtticaManager::instance()->resolverData( res.id() ); - m_resolver = QPointer< ExternalResolverGui >( - qobject_cast< ExternalResolverGui* >( - Pipeline::instance()->addScriptResolver( accountId(), data.scriptPath ) - ) - ); + m_resolver = Pipeline::instance()->addScriptResolver( accountId(), data.scriptPath ); m_resolver.data()->setIcon( icon() ); connect( m_resolver.data(), SIGNAL( changed() ), this, SLOT( resolverChanged() ) ); } diff --git a/src/libtomahawk/accounts/lastfm/LastFmAccount.h b/src/libtomahawk/accounts/lastfm/LastFmAccount.h index a61a0220f..df4a02cb9 100644 --- a/src/libtomahawk/accounts/lastfm/LastFmAccount.h +++ b/src/libtomahawk/accounts/lastfm/LastFmAccount.h @@ -30,7 +30,7 @@ namespace Tomahawk { - class ExternalResolverGui; + class ExternalResolver; namespace InfoSystem { @@ -104,7 +104,7 @@ private slots: private: void hookupResolver(); - QPointer m_resolver; + QPointer m_resolver; QPointer m_infoPlugin; QPointer m_configWidget; }; diff --git a/src/libtomahawk/resolvers/ExternalResolver.cpp b/src/libtomahawk/resolvers/ExternalResolver.cpp index aa6724928..400fcde10 100644 --- a/src/libtomahawk/resolvers/ExternalResolver.cpp +++ b/src/libtomahawk/resolvers/ExternalResolver.cpp @@ -18,11 +18,120 @@ #include "ExternalResolver.h" -#include "PlaylistEntry.h" +#include "accounts/AccountConfigWidget.h" #include "utils/Logger.h" +#include "PlaylistEntry.h" + +#include +#include +#include +#include +#include Tomahawk::ExternalResolver::ErrorState Tomahawk::ExternalResolver::error() const { return NoError; } + + +QVariant +Tomahawk::ExternalResolver::configMsgFromWidget( QWidget* w ) +{ + if( !w ) + return QVariant(); + + // generate a qvariantmap of all the widgets in the hierarchy, and for each one include the list of properties and values + QVariantMap widgetMap; + addChildProperties( w, widgetMap ); +// qDebug() << "Generated widget variant:" << widgetMap; + return widgetMap; +} + + +void +Tomahawk::ExternalResolver::addChildProperties( QObject* widget, QVariantMap& m ) +{ + // recursively add all properties of this widget to the map, then repeat on all children. + // bare QWidgets are boring---so skip them! They have no input that the user can set. + if( !widget || !widget->isWidgetType() ) + return; + + if( qstrcmp( widget->metaObject()->className(), "QWidget" ) != 0 ) + { +// qDebug() << "Adding properties for this:" << widget->metaObject()->className(); + // add this widget's properties + QVariantMap props; + for( int i = 0; i < widget->metaObject()->propertyCount(); i++ ) + { + QString prop = widget->metaObject()->property( i ).name(); + QVariant val = widget->property( prop.toLatin1() ); + // clean up for QJson.... + if( val.canConvert< QPixmap >() || val.canConvert< QImage >() || val.canConvert< QIcon >() ) + continue; + props[ prop ] = val.toString(); +// qDebug() << QString( "%1: %2" ).arg( prop ).arg( props[ prop ].toString() ); + } + m[ widget->objectName() ] = props; + } + // and recurse + foreach( QObject* child, widget->children() ) + addChildProperties( child, m ); +} + + +AccountConfigWidget* +Tomahawk::ExternalResolver::widgetFromData( QByteArray& data, QWidget* parent ) +{ + if( data.isEmpty() ) + return 0; + + AccountConfigWidget* configWidget = new AccountConfigWidget( parent ); + + QUiLoader l; + QBuffer b( &data ); + QWidget* w = l.load( &b, configWidget ); + + // HACK: proper way would be to create a designer plugin for this widget type + configWidget->setLayout( new QBoxLayout( QBoxLayout::TopToBottom ) ); + configWidget->layout()->addWidget( w ); + +#ifdef Q_OS_MAC + w->setContentsMargins( 12, 12, 12, 12 ); +#else + w->setContentsMargins( 6, 6, 6, 6 ); +#endif + + return configWidget; +} + + +QByteArray +Tomahawk::ExternalResolver::fixDataImagePaths( const QByteArray& data, bool compressed, const QVariantMap& images ) +{ + // with a list of images and image data, write each to a temp file, replace the path in the .ui file with the temp file path + QString uiFile = QString::fromUtf8( data ); + foreach( const QString& filename, images.keys() ) + { + if( !uiFile.contains( filename ) ) // make sure the image is used + continue; + + QString fullPath = QDir::tempPath() + "/" + filename; + QFile imgF( fullPath ); + if( !imgF.open( QIODevice::WriteOnly ) ) + { + qWarning() << "Failed to write to temporary image in UI file:" << filename << fullPath; + continue; + } + QByteArray data = images[ filename ].toByteArray(); + +// qDebug() << "expanding data:" << data << compressed; + data = compressed ? qUncompress( QByteArray::fromBase64( data ) ) : QByteArray::fromBase64( data ); + imgF.write( data ); + imgF.close(); + + // replace the path to the image with the real path + uiFile.replace( filename, fullPath ); + } + return uiFile.toUtf8(); +} diff --git a/src/libtomahawk/resolvers/ExternalResolver.h b/src/libtomahawk/resolvers/ExternalResolver.h index 6c8ff4199..6037d03ab 100644 --- a/src/libtomahawk/resolvers/ExternalResolver.h +++ b/src/libtomahawk/resolvers/ExternalResolver.h @@ -105,6 +105,8 @@ public: virtual void enqueue( const QSharedPointer< ScriptCommand >& req ) { m_commandQueue->enqueue( req ); } + virtual AccountConfigWidget* configUI() const = 0; + public slots: virtual void start() = 0; virtual void stop() = 0; @@ -132,8 +134,15 @@ protected: // UrlLookup virtual void lookupUrl( const QString& url ) = 0; + AccountConfigWidget* widgetFromData( QByteArray& data, QWidget* parent = 0 ); + QVariant configMsgFromWidget( QWidget* w ); + QByteArray fixDataImagePaths( const QByteArray& data, bool compressed, const QVariantMap& images ); + + private: QString m_filePath; + + void addChildProperties( QObject* parent, QVariantMap& m ); }; Q_DECLARE_OPERATORS_FOR_FLAGS( ExternalResolver::Capabilities ) diff --git a/src/libtomahawk/resolvers/ExternalResolverGui.cpp b/src/libtomahawk/resolvers/ExternalResolverGui.cpp deleted file mode 100644 index b5014fb2c..000000000 --- a/src/libtomahawk/resolvers/ExternalResolverGui.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2010-2011, Christian Muehlhaeuser - * - * 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 "ExternalResolverGui.h" - - -#include "Source.h" -#include "utils/Logger.h" -#include "accounts/AccountConfigWidget.h" - -#include -#include -#include -#include -#include -#include -#include - -Tomahawk::ExternalResolverGui::ExternalResolverGui(const QString& filePath) - : Tomahawk::ExternalResolver(filePath) -{ -} - - -QVariant -Tomahawk::ExternalResolverGui::configMsgFromWidget( QWidget* w ) -{ - if( !w ) - return QVariant(); - - // generate a qvariantmap of all the widgets in the hierarchy, and for each one include the list of properties and values - QVariantMap widgetMap; - addChildProperties( w, widgetMap ); -// qDebug() << "Generated widget variant:" << widgetMap; - return widgetMap; -} - - -void -Tomahawk::ExternalResolverGui::addChildProperties( QObject* widget, QVariantMap& m ) -{ - // recursively add all properties of this widget to the map, then repeat on all children. - // bare QWidgets are boring---so skip them! They have no input that the user can set. - if( !widget || !widget->isWidgetType() ) - return; - - if( qstrcmp( widget->metaObject()->className(), "QWidget" ) != 0 ) - { -// qDebug() << "Adding properties for this:" << widget->metaObject()->className(); - // add this widget's properties - QVariantMap props; - for( int i = 0; i < widget->metaObject()->propertyCount(); i++ ) - { - QString prop = widget->metaObject()->property( i ).name(); - QVariant val = widget->property( prop.toLatin1() ); - // clean up for QJson.... - if( val.canConvert< QPixmap >() || val.canConvert< QImage >() || val.canConvert< QIcon >() ) - continue; - props[ prop ] = val.toString(); -// qDebug() << QString( "%1: %2" ).arg( prop ).arg( props[ prop ].toString() ); - } - m[ widget->objectName() ] = props; - } - // and recurse - foreach( QObject* child, widget->children() ) - addChildProperties( child, m ); -} - - -AccountConfigWidget* -Tomahawk::ExternalResolverGui::widgetFromData( QByteArray& data, QWidget* parent ) -{ - if( data.isEmpty() ) - return 0; - - AccountConfigWidget* configWidget = new AccountConfigWidget( parent ); - - QUiLoader l; - QBuffer b( &data ); - QWidget* w = l.load( &b, configWidget ); - - // HACK: proper way would be to create a designer plugin for this widget type - configWidget->setLayout( new QBoxLayout( QBoxLayout::TopToBottom ) ); - configWidget->layout()->addWidget( w ); - -#ifdef Q_OS_MAC - w->setContentsMargins( 12, 12, 12, 12 ); -#else - w->setContentsMargins( 6, 6, 6, 6 ); -#endif - - return configWidget; -} - - -QByteArray -Tomahawk::ExternalResolverGui::fixDataImagePaths( const QByteArray& data, bool compressed, const QVariantMap& images ) -{ - // with a list of images and image data, write each to a temp file, replace the path in the .ui file with the temp file path - QString uiFile = QString::fromUtf8( data ); - foreach( const QString& filename, images.keys() ) - { - if( !uiFile.contains( filename ) ) // make sure the image is used - continue; - - QString fullPath = QDir::tempPath() + "/" + filename; - QFile imgF( fullPath ); - if( !imgF.open( QIODevice::WriteOnly ) ) - { - qWarning() << "Failed to write to temporary image in UI file:" << filename << fullPath; - continue; - } - QByteArray data = images[ filename ].toByteArray(); - -// qDebug() << "expanding data:" << data << compressed; - data = compressed ? qUncompress( QByteArray::fromBase64( data ) ) : QByteArray::fromBase64( data ); - imgF.write( data ); - imgF.close(); - - // replace the path to the image with the real path - uiFile.replace( filename, fullPath ); - } - return uiFile.toUtf8(); -} diff --git a/src/libtomahawk/resolvers/ExternalResolverGui.h b/src/libtomahawk/resolvers/ExternalResolverGui.h deleted file mode 100644 index a4bba0d7e..000000000 --- a/src/libtomahawk/resolvers/ExternalResolverGui.h +++ /dev/null @@ -1,58 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2010-2011, Christian Muehlhaeuser - * - * 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 EXTERNALRESOLVERGUI_H -#define EXTERNALRESOLVERGUI_H - -#include "ExternalResolver.h" -#include "DllMacro.h" - -#include - -class QWidget; -class AccountConfigWidget; - -namespace Tomahawk -{ - -/** - * 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 ExternalResolverGui : public ExternalResolver -{ -Q_OBJECT - -public: - ExternalResolverGui( const QString& filePath ); - virtual AccountConfigWidget* configUI() const = 0; - -protected: - AccountConfigWidget* widgetFromData( QByteArray& data, QWidget* parent = 0 ); - QVariant configMsgFromWidget( QWidget* w ); - QByteArray fixDataImagePaths( const QByteArray& data, bool compressed, const QVariantMap& images ); - -private: - void addChildProperties( QObject* parent, QVariantMap& m ); -}; - -}; //ns - -#endif // RESOLVER_H diff --git a/src/libtomahawk/resolvers/JSResolver.cpp b/src/libtomahawk/resolvers/JSResolver.cpp index 82a560a28..43bb1d1ce 100644 --- a/src/libtomahawk/resolvers/JSResolver.cpp +++ b/src/libtomahawk/resolvers/JSResolver.cpp @@ -57,7 +57,7 @@ using namespace Tomahawk; JSResolver::JSResolver( const QString& accountId, const QString& scriptPath, const QStringList& additionalScriptPaths ) - : Tomahawk::ExternalResolverGui( scriptPath ) + : Tomahawk::ExternalResolver( scriptPath ) , d_ptr( new JSResolverPrivate( this, accountId, scriptPath, additionalScriptPaths ) ) { Q_D( JSResolver ); diff --git a/src/libtomahawk/resolvers/JSResolver.h b/src/libtomahawk/resolvers/JSResolver.h index 916457ac5..22adc2fb4 100644 --- a/src/libtomahawk/resolvers/JSResolver.h +++ b/src/libtomahawk/resolvers/JSResolver.h @@ -24,7 +24,7 @@ #include "config.h" #include "DllMacro.h" -#include "ExternalResolverGui.h" +#include "ExternalResolver.h" #include "Typedefs.h" namespace Tomahawk @@ -35,7 +35,7 @@ class JSResolverHelper; class JSResolverPrivate; class ScriptEngine; -class DLLEXPORT JSResolver : public Tomahawk::ExternalResolverGui +class DLLEXPORT JSResolver : public Tomahawk::ExternalResolver { Q_OBJECT diff --git a/src/libtomahawk/resolvers/JSResolver_p.h b/src/libtomahawk/resolvers/JSResolver_p.h index 9cf837673..082920fa9 100644 --- a/src/libtomahawk/resolvers/JSResolver_p.h +++ b/src/libtomahawk/resolvers/JSResolver_p.h @@ -57,7 +57,7 @@ private: QString name; QPixmap icon; unsigned int weight, timeout; - Tomahawk::ExternalResolverGui::Capabilities capabilities; + Tomahawk::ExternalResolver::Capabilities capabilities; bool ready; bool stopped; diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index a1e21335e..e4293cca5 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -20,7 +20,7 @@ #include "ScriptCollection.h" #include "Source.h" -#include "ExternalResolverGui.h" +#include "ExternalResolver.h" #include "utils/TomahawkUtilsGui.h" #include "utils/Logger.h" #include "resolvers/ScriptCommand_AllArtists.h" diff --git a/src/libtomahawk/resolvers/ScriptResolver.cpp b/src/libtomahawk/resolvers/ScriptResolver.cpp index 090ecbbab..d04dbb152 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.cpp +++ b/src/libtomahawk/resolvers/ScriptResolver.cpp @@ -21,6 +21,7 @@ #include "ScriptResolver.h" #include "accounts/AccountConfigWidget.h" +#include "utils/TomahawkUtils.h" #include "utils/TomahawkUtilsGui.h" #include "utils/Json.h" #include "utils/Logger.h" @@ -47,7 +48,7 @@ using namespace Tomahawk; ScriptResolver::ScriptResolver( const QString& exe ) - : Tomahawk::ExternalResolverGui( exe ) + : Tomahawk::ExternalResolver( exe ) , m_num_restarts( 0 ) , m_msgsize( 0 ) , m_ready( false ) diff --git a/src/libtomahawk/resolvers/ScriptResolver.h b/src/libtomahawk/resolvers/ScriptResolver.h index 403cbcf89..3393cb39a 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.h +++ b/src/libtomahawk/resolvers/ScriptResolver.h @@ -25,7 +25,7 @@ #include "Artist.h" #include "Album.h" #include "collection/Collection.h" -#include "ExternalResolverGui.h" +#include "ExternalResolver.h" #include "DllMacro.h" #include @@ -35,7 +35,7 @@ class QWidget; namespace Tomahawk { -class DLLEXPORT ScriptResolver : public Tomahawk::ExternalResolverGui +class DLLEXPORT ScriptResolver : public Tomahawk::ExternalResolver { Q_OBJECT diff --git a/src/tomahawk/dialogs/SettingsDialog.cpp b/src/tomahawk/dialogs/SettingsDialog.cpp index 9c1a36ca5..7b18a2344 100644 --- a/src/tomahawk/dialogs/SettingsDialog.cpp +++ b/src/tomahawk/dialogs/SettingsDialog.cpp @@ -36,7 +36,6 @@ #include "accounts/DelegateConfigWrapper.h" #include "Pipeline.h" #include "resolvers/Resolver.h" -#include "resolvers/ExternalResolverGui.h" #include "utils/TomahawkUtilsGui.h" #include "utils/GuiHelpers.h" #include "accounts/AccountDelegate.h"