From 893a0df84593764fc76dd0103ce61e1f456b3af8 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sat, 10 Jan 2015 02:39:59 +0100 Subject: [PATCH] Port ScriptInfoPlugins to ScriptPluginFactory --- src/libtomahawk/CMakeLists.txt | 4 +- src/libtomahawk/resolvers/ScriptAccount.cpp | 17 ++++--- src/libtomahawk/resolvers/ScriptAccount.h | 5 +- .../plugins/ScriptInfoPluginFactory.cpp | 46 +++++++++++++++++++ .../plugins/ScriptInfoPluginFactory.h | 40 ++++++++++++++++ 5 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 src/libtomahawk/resolvers/plugins/ScriptInfoPluginFactory.cpp create mode 100644 src/libtomahawk/resolvers/plugins/ScriptInfoPluginFactory.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index bc8e2eb6d..5d5ddfaa0 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -84,7 +84,6 @@ set( libGuiSources resolvers/ExternalResolverGui.cpp resolvers/ScriptResolver.cpp - resolvers/ScriptInfoPlugin.cpp resolvers/JSResolver.cpp resolvers/JSResolverHelper.cpp resolvers/ScriptEngine.cpp @@ -356,6 +355,9 @@ list(APPEND libSources # ScriptPlugins resolvers/ScriptCollection.cpp resolvers/plugins/ScriptCollectionFactory.cpp + resolvers/ScriptInfoPlugin.cpp + resolvers/plugins/ScriptInfoPluginFactory.cpp + sip/SipPlugin.cpp sip/SipInfo.cpp diff --git a/src/libtomahawk/resolvers/ScriptAccount.cpp b/src/libtomahawk/resolvers/ScriptAccount.cpp index 86830baee..d6c597f89 100644 --- a/src/libtomahawk/resolvers/ScriptAccount.cpp +++ b/src/libtomahawk/resolvers/ScriptAccount.cpp @@ -23,6 +23,7 @@ #include "../Typedefs.h" #include "plugins/ScriptCollectionFactory.h" +#include "plugins/ScriptInfoPluginFactory.h" // TODO: register factory methods instead of hardcoding all plugin types in here #include "../utils/LinkGenerator.h" @@ -43,6 +44,7 @@ ScriptAccount::ScriptAccount( const QString& name ) , m_name( name ) , m_stopped( false ) , m_collectionFactory( new ScriptCollectionFactory() ) + , m_infoPluginFactory( new ScriptInfoPluginFactory() ) { } @@ -50,6 +52,7 @@ ScriptAccount::ScriptAccount( const QString& name ) ScriptAccount::~ScriptAccount() { delete m_collectionFactory; + delete m_infoPluginFactory; } @@ -193,6 +196,10 @@ ScriptAccount::unregisterScriptPlugin( const QString& type, const QString& objec { m_collectionFactory->unregisterPlugin( object ); } + else if ( type == "infoPlugin" ) + { + m_infoPluginFactory->unregisterPlugin( object ); + } else { tLog() << "This plugin type is not handled by Tomahawk or simply cannot be removed yet"; @@ -226,15 +233,7 @@ ScriptAccount::scriptPluginFactory( const QString& type, const scriptobject_ptr& } else if ( type == "infoPlugin" ) { - // create infoplugin instance - ScriptInfoPlugin* scriptInfoPlugin = new ScriptInfoPlugin( object, m_name ); - Tomahawk::InfoSystem::InfoPluginPtr infoPlugin( scriptInfoPlugin ); - - // move it to infosystem thread - infoPlugin->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() ); - - // add it to infosystem - Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin ); + m_infoPluginFactory->registerPlugin( object, this ); } else if( type == "collection" ) { diff --git a/src/libtomahawk/resolvers/ScriptAccount.h b/src/libtomahawk/resolvers/ScriptAccount.h index 3bd74cb50..9966f4289 100644 --- a/src/libtomahawk/resolvers/ScriptAccount.h +++ b/src/libtomahawk/resolvers/ScriptAccount.h @@ -39,6 +39,7 @@ namespace Tomahawk { class ScriptObject; class ScriptJob; class ScriptCollectionFactory; +class ScriptInfoPluginFactory; class DLLEXPORT ScriptAccount : public QObject { @@ -89,7 +90,9 @@ private: // TODO: pimple, might be renamed before tho QHash< QString, ScriptJob* > m_jobs; QHash< QString, scriptobject_ptr > m_objects; - ScriptCollectionFactory* m_collectionFactory; // port to QScopedPointer when pimple'd + // port to QScopedPointer when pimple'd + ScriptCollectionFactory* m_collectionFactory; + ScriptInfoPluginFactory* m_infoPluginFactory; }; } // ns: Tomahawk diff --git a/src/libtomahawk/resolvers/plugins/ScriptInfoPluginFactory.cpp b/src/libtomahawk/resolvers/plugins/ScriptInfoPluginFactory.cpp new file mode 100644 index 000000000..59e601f95 --- /dev/null +++ b/src/libtomahawk/resolvers/plugins/ScriptInfoPluginFactory.cpp @@ -0,0 +1,46 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright (C) 2015 Dominik Schmidt + * + * 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 2 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 "ScriptInfoPluginFactory.h" + +#include "SourceList.h" +#include "../ScriptAccount.h" + +using namespace Tomahawk; + +void ScriptInfoPluginFactory::addPlugin( const QSharedPointer< ScriptInfoPlugin >& infoPlugin ) const +{ + Tomahawk::InfoSystem::InfoSystem::instance()->addInfoPlugin( infoPlugin.data() ); +} + +void ScriptInfoPluginFactory::removePlugin( const QSharedPointer< ScriptInfoPlugin >& infoPlugin ) const +{ + Tomahawk::InfoSystem::InfoSystem::instance()->removeInfoPlugin( infoPlugin.data() ); +} + +const QSharedPointer< ScriptInfoPlugin > ScriptInfoPluginFactory::createPlugin( const scriptobject_ptr& object, ScriptAccount* scriptAccount ) +{ + // create infoplugin instance + ScriptInfoPlugin* scriptInfoPlugin = new ScriptInfoPlugin( object, scriptAccount->name() ); + + Tomahawk::InfoSystem::InfoPluginPtr infoPlugin( scriptInfoPlugin ); + + // move it to infosystem thread + infoPlugin->moveToThread( Tomahawk::InfoSystem::InfoSystem::instance()->workerThread().data() ); + + return QSharedPointer< ScriptInfoPlugin >( scriptInfoPlugin ); +} diff --git a/src/libtomahawk/resolvers/plugins/ScriptInfoPluginFactory.h b/src/libtomahawk/resolvers/plugins/ScriptInfoPluginFactory.h new file mode 100644 index 000000000..eedad0d22 --- /dev/null +++ b/src/libtomahawk/resolvers/plugins/ScriptInfoPluginFactory.h @@ -0,0 +1,40 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright (C) 2015 Dominik Schmidt + * + * 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 2 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 . + */ + +#pragma once +#ifndef TOMAHAWK_SCRIPTINFOPLUGINFACTORY_H +#define TOMAHAWK_SCRIPTINFOPLUGINFACTORY_H + +#include "Typedefs.h" +#include "../ScriptPluginFactory.h" +#include "../ScriptInfoPlugin.h" + +namespace Tomahawk +{ +class ScriptAccount; + +class DLLEXPORT ScriptInfoPluginFactory : public ScriptPluginFactory< ScriptInfoPlugin > +{ + const QSharedPointer< ScriptInfoPlugin > createPlugin( const scriptobject_ptr&, ScriptAccount* ) override; + void addPlugin( const QSharedPointer< ScriptInfoPlugin >& scriptPlugin ) const override; + void removePlugin( const QSharedPointer< ScriptInfoPlugin >& scriptPlugin ) const override; +}; + +} // ns: Tomahawk + +#endif // TOMAHAWK_SCRIPTINFOPLUGINFACTORY_H