diff --git a/src/libtomahawk/ExternalResolver.h b/src/libtomahawk/ExternalResolver.h index 7cebac9aa..a99a2eb43 100644 --- a/src/libtomahawk/ExternalResolver.h +++ b/src/libtomahawk/ExternalResolver.h @@ -71,6 +71,7 @@ public: virtual ErrorState error() const; virtual bool running() const = 0; virtual Capabilities capabilities() const = 0; + virtual QList< Tomahawk::collection_ptr > collections() { return m_collections; } public slots: virtual void start() = 0; diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index a01bc7078..2b7efd52f 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +24,7 @@ #include "Album.h" #include "config.h" #include "Pipeline.h" +#include "ScriptCollection.h" #include "SourceList.h" #include "accounts/AccountConfigWidget.h" @@ -368,6 +370,8 @@ QtScriptResolver::init() QVariantMap config = resolverUserConfig(); fillDataInWidgets( config ); + loadCollections(); + qDebug() << "JS" << filePath() << "READY," << "name" << m_name << "weight" << m_weight << "timeout" << m_timeout << "icon received" << success; m_ready = true; @@ -504,6 +508,13 @@ void QtScriptResolver::stop() { m_stopped = true; + + foreach ( const Tomahawk::collection_ptr& collection, m_collections ) + { + emit collectionRemoved( collection ); + } + m_collections.clear(); + Tomahawk::Pipeline::instance()->removeResolver( this ); emit stopped(); } @@ -634,6 +645,22 @@ QtScriptResolver::fillDataInWidgets( const QVariantMap& data ) } +void +QtScriptResolver::loadCollections() +{ + if ( m_capabilities.testFlag( Browsable ) ) + { + m_collections.clear(); + // at this point we assume that all the tracks browsable through a resolver belong to the local source + Tomahawk::collection_ptr collection( new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this ) ); + m_collections.append( collection ); + emit collectionAdded( collection ); + + //TODO: implement multiple collections from a resolver + } +} + + QVariantMap QtScriptResolver::resolverSettings() { @@ -654,3 +681,10 @@ QtScriptResolver::resolverInit() return m_engine->mainFrame()->evaluateJavaScript( RESOLVER_LEGACY_CODE "resolver.init();" ).toMap(); } + +QVariantMap +QtScriptResolver::resolverCollections() +{ + return QVariantMap(); //TODO: add a way to distinguish collections +} + diff --git a/src/libtomahawk/resolvers/QtScriptResolver.h b/src/libtomahawk/resolvers/QtScriptResolver.h index 1a6a5f596..a57795099 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.h +++ b/src/libtomahawk/resolvers/QtScriptResolver.h @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -144,6 +145,7 @@ public: virtual void reload(); virtual void setIcon( const QPixmap& icon ) { m_icon = icon; } + public slots: virtual void resolve( const Tomahawk::query_ptr& query ); virtual void stop(); @@ -160,11 +162,13 @@ private: QVariant widgetData( QWidget* widget, const QString& property ); QVariantMap loadDataFromWidgets(); void fillDataInWidgets( const QVariantMap& data ); + void loadCollections(); // encapsulate javascript calls QVariantMap resolverSettings(); QVariantMap resolverUserConfig(); QVariantMap resolverInit(); + QVariantMap resolverCollections(); QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist ); diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index 73e9752f3..91131c65f 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -25,7 +25,7 @@ using namespace Tomahawk; ScriptCollection::ScriptCollection( const source_ptr& source, - QtScriptResolver* resolver, + ExternalResolver* resolver, QObject* parent ) : Collection( source, resolver->name(), parent ) { diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index 81ba3baeb..949a3ddc4 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -20,7 +20,7 @@ #ifndef SCRIPTCOLLECTION_H #define SCRIPTCOLLECTION_H -#include "resolvers/QtScriptResolver.h" +#include "ExternalResolver.h" #include "Collection.h" #include "Typedefs.h" @@ -36,12 +36,12 @@ class DLLEXPORT ScriptCollection : public Collection public: explicit ScriptCollection( const source_ptr& source, - QtScriptResolver* resolver, + ExternalResolver* resolver, QObject* parent = 0 ); virtual ~ScriptCollection(); private: - QtScriptResolver* m_resolver; + ExternalResolver* m_resolver; }; diff --git a/src/libtomahawk/resolvers/ScriptResolver.cpp b/src/libtomahawk/resolvers/ScriptResolver.cpp index fbaed680a..dfc1de05f 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.cpp +++ b/src/libtomahawk/resolvers/ScriptResolver.cpp @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,6 +23,7 @@ #include "Artist.h" #include "Album.h" #include "Pipeline.h" +#include "ScriptCollection.h" #include "SourceList.h" #include "accounts/AccountConfigWidget.h" @@ -415,6 +417,8 @@ ScriptResolver::doSetup( const QVariantMap& m ) m_configSent = false; m_num_restarts = 0; + loadCollections(); + if ( !m_stopped ) Tomahawk::Pipeline::instance()->addResolver( this ); @@ -442,6 +446,22 @@ ScriptResolver::setupConfWidget( const QVariantMap& m ) } +void +ScriptResolver::loadCollections() +{ + if ( m_capabilities.testFlag( Browsable ) ) + { + m_collections.clear(); + // at this point we assume that all the tracks browsable through a resolver belong to the local source + Tomahawk::collection_ptr collection( new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this ) ); + m_collections.append( collection ); + emit collectionAdded( collection ); + + //TODO: implement multiple collections from a resolver + } +} + + void ScriptResolver::startProcess() { @@ -537,5 +557,12 @@ void ScriptResolver::stop() { m_stopped = true; + + foreach ( const Tomahawk::collection_ptr& collection, m_collections ) + { + emit collectionRemoved( collection ); + } + m_collections.clear(); + Tomahawk::Pipeline::instance()->removeResolver( this ); } diff --git a/src/libtomahawk/resolvers/ScriptResolver.h b/src/libtomahawk/resolvers/ScriptResolver.h index a063b42c4..36e02d3f5 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.h +++ b/src/libtomahawk/resolvers/ScriptResolver.h @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -81,6 +82,7 @@ private: void sendMsg( const QByteArray& msg ); void doSetup( const QVariantMap& m ); void setupConfWidget( const QVariantMap& m ); + void loadCollections(); void startProcess();