Commit 9252c449 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

EffectsEngine: Cache the plugins.

parent 1abba296
......@@ -26,11 +26,16 @@
#include "EffectInstance.h"
#include "Types.h"
#include <QDesktopServices>
#include <QDir>
#include <QSettings>
#include <QtDebug>
EffectsEngine::EffectsEngine()
{
m_cache = new QSettings( QDesktopServices::storageLocation(
QDesktopServices::CacheLocation ) + "/effects",
QSettings::IniFormat, this );
}
EffectsEngine::~EffectsEngine()
......@@ -61,14 +66,36 @@ EffectsEngine::effect( const QString& name )
bool
EffectsEngine::loadEffect( const QString &fileName )
{
Effect* e = new Effect( fileName );
Effect* e = new Effect( fileName );
QString name;
Effect::Type type;
if ( m_cache->contains( fileName + "/name" ) == true &&
m_cache->contains( fileName + "/type" ) == true )
{
name = m_cache->value( fileName + "/name" ).toString();
int typeInt = m_cache->value( fileName + "/type" ).toInt();
if ( typeInt < Effect::Unknown || typeInt > Effect::Mixer3 )
qWarning() << "Invalid plugin type.";
else
{
type = static_cast<Effect::Type>( typeInt );
m_effects[name] = e;
emit effectAdded( e, type );
return true;
}
}
if ( e->load() == false )
{
delete e;
return false;
}
m_effects[e->name()] = e;
emit effectAdded( e, e->type() );
m_cache->setValue( fileName + "/name", e->name() );
m_cache->setValue( fileName + "/type", e->type() );
name = e->name();
type = e->type();
emit effectAdded( e, type );
return true;
}
......
......@@ -31,6 +31,8 @@
#include <QObject>
#include <QHash>
class QSettings;
class EffectsEngine : public QObject, public Singleton<EffectsEngine>
{
Q_OBJECT
......@@ -58,6 +60,7 @@ class EffectsEngine : public QObject, public Singleton<EffectsEngine>
~EffectsEngine();
QHash<QString, Effect*> m_effects;
QSettings *m_cache;
signals:
void effectAdded( Effect*, Effect::Type );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment