mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
Port ScriptInfoPlugins to ScriptPluginFactory
This commit is contained in:
@@ -84,7 +84,6 @@ set( libGuiSources
|
|||||||
|
|
||||||
resolvers/ExternalResolverGui.cpp
|
resolvers/ExternalResolverGui.cpp
|
||||||
resolvers/ScriptResolver.cpp
|
resolvers/ScriptResolver.cpp
|
||||||
resolvers/ScriptInfoPlugin.cpp
|
|
||||||
resolvers/JSResolver.cpp
|
resolvers/JSResolver.cpp
|
||||||
resolvers/JSResolverHelper.cpp
|
resolvers/JSResolverHelper.cpp
|
||||||
resolvers/ScriptEngine.cpp
|
resolvers/ScriptEngine.cpp
|
||||||
@@ -356,6 +355,9 @@ list(APPEND libSources
|
|||||||
# ScriptPlugins
|
# ScriptPlugins
|
||||||
resolvers/ScriptCollection.cpp
|
resolvers/ScriptCollection.cpp
|
||||||
resolvers/plugins/ScriptCollectionFactory.cpp
|
resolvers/plugins/ScriptCollectionFactory.cpp
|
||||||
|
resolvers/ScriptInfoPlugin.cpp
|
||||||
|
resolvers/plugins/ScriptInfoPluginFactory.cpp
|
||||||
|
|
||||||
|
|
||||||
sip/SipPlugin.cpp
|
sip/SipPlugin.cpp
|
||||||
sip/SipInfo.cpp
|
sip/SipInfo.cpp
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include "../Typedefs.h"
|
#include "../Typedefs.h"
|
||||||
|
|
||||||
#include "plugins/ScriptCollectionFactory.h"
|
#include "plugins/ScriptCollectionFactory.h"
|
||||||
|
#include "plugins/ScriptInfoPluginFactory.h"
|
||||||
|
|
||||||
// TODO: register factory methods instead of hardcoding all plugin types in here
|
// TODO: register factory methods instead of hardcoding all plugin types in here
|
||||||
#include "../utils/LinkGenerator.h"
|
#include "../utils/LinkGenerator.h"
|
||||||
@@ -43,6 +44,7 @@ ScriptAccount::ScriptAccount( const QString& name )
|
|||||||
, m_name( name )
|
, m_name( name )
|
||||||
, m_stopped( false )
|
, m_stopped( false )
|
||||||
, m_collectionFactory( new ScriptCollectionFactory() )
|
, m_collectionFactory( new ScriptCollectionFactory() )
|
||||||
|
, m_infoPluginFactory( new ScriptInfoPluginFactory() )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +52,7 @@ ScriptAccount::ScriptAccount( const QString& name )
|
|||||||
ScriptAccount::~ScriptAccount()
|
ScriptAccount::~ScriptAccount()
|
||||||
{
|
{
|
||||||
delete m_collectionFactory;
|
delete m_collectionFactory;
|
||||||
|
delete m_infoPluginFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -193,6 +196,10 @@ ScriptAccount::unregisterScriptPlugin( const QString& type, const QString& objec
|
|||||||
{
|
{
|
||||||
m_collectionFactory->unregisterPlugin( object );
|
m_collectionFactory->unregisterPlugin( object );
|
||||||
}
|
}
|
||||||
|
else if ( type == "infoPlugin" )
|
||||||
|
{
|
||||||
|
m_infoPluginFactory->unregisterPlugin( object );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tLog() << "This plugin type is not handled by Tomahawk or simply cannot be removed yet";
|
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" )
|
else if ( type == "infoPlugin" )
|
||||||
{
|
{
|
||||||
// create infoplugin instance
|
m_infoPluginFactory->registerPlugin( object, this );
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
else if( type == "collection" )
|
else if( type == "collection" )
|
||||||
{
|
{
|
||||||
|
@@ -39,6 +39,7 @@ namespace Tomahawk {
|
|||||||
class ScriptObject;
|
class ScriptObject;
|
||||||
class ScriptJob;
|
class ScriptJob;
|
||||||
class ScriptCollectionFactory;
|
class ScriptCollectionFactory;
|
||||||
|
class ScriptInfoPluginFactory;
|
||||||
|
|
||||||
class DLLEXPORT ScriptAccount : public QObject
|
class DLLEXPORT ScriptAccount : public QObject
|
||||||
{
|
{
|
||||||
@@ -89,7 +90,9 @@ private: // TODO: pimple, might be renamed before tho
|
|||||||
QHash< QString, ScriptJob* > m_jobs;
|
QHash< QString, ScriptJob* > m_jobs;
|
||||||
QHash< QString, scriptobject_ptr > m_objects;
|
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
|
} // ns: Tomahawk
|
||||||
|
@@ -0,0 +1,46 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Dominik Schmidt <domme@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#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 );
|
||||||
|
}
|
40
src/libtomahawk/resolvers/plugins/ScriptInfoPluginFactory.h
Normal file
40
src/libtomahawk/resolvers/plugins/ScriptInfoPluginFactory.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Dominik Schmidt <domme@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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
|
Reference in New Issue
Block a user