Drop Plasma::ConfigLoader again
It doesn't make really any sense for the effects. Instead the JS API allows to specify a default value for not present keys.
This commit is contained in:
parent
875df96143
commit
fa66940966
2 changed files with 7 additions and 61 deletions
|
@ -21,9 +21,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include "scriptedeffect.h"
|
#include "scriptedeffect.h"
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
// KDE
|
// KDE
|
||||||
|
#include <KDE/KConfigGroup>
|
||||||
#include <KDE/KDebug>
|
#include <KDE/KDebug>
|
||||||
#include <KDE/KStandardDirs>
|
#include <KDE/KStandardDirs>
|
||||||
#include <KDE/Plasma/ConfigLoader>
|
|
||||||
// Qt
|
// Qt
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtScript/QScriptEngine>
|
#include <QtScript/QScriptEngine>
|
||||||
|
@ -129,7 +129,6 @@ ScriptedEffect::ScriptedEffect()
|
||||||
: AnimationEffect()
|
: AnimationEffect()
|
||||||
, m_engine(new QScriptEngine(this))
|
, m_engine(new QScriptEngine(this))
|
||||||
, m_scriptFile(QString())
|
, m_scriptFile(QString())
|
||||||
, m_currentConfig(QString("main"))
|
|
||||||
{
|
{
|
||||||
connect(m_engine, SIGNAL(signalHandlerException(QScriptValue)), SLOT(signalHandlerException(QScriptValue)));
|
connect(m_engine, SIGNAL(signalHandlerException(QScriptValue)), SLOT(signalHandlerException(QScriptValue)));
|
||||||
}
|
}
|
||||||
|
@ -143,7 +142,6 @@ bool ScriptedEffect::init(const QString &effectName, const QString &pathToScript
|
||||||
}
|
}
|
||||||
m_effectName = effectName;
|
m_effectName = effectName;
|
||||||
m_scriptFile = pathToScript;
|
m_scriptFile = pathToScript;
|
||||||
loadConfig("main");
|
|
||||||
|
|
||||||
QScriptValue effectsObject = m_engine->newQObject(effects, QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater);
|
QScriptValue effectsObject = m_engine->newQObject(effects, QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater);
|
||||||
m_engine->globalObject().setProperty("effects", effectsObject, QScriptValue::Undeletable);
|
m_engine->globalObject().setProperty("effects", effectsObject, QScriptValue::Undeletable);
|
||||||
|
@ -212,51 +210,10 @@ void ScriptedEffect::reconfigure(ReconfigureFlags flags)
|
||||||
emit configChanged();
|
emit configChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ScriptedEffect::activeConfig() const
|
QVariant ScriptedEffect::readConfig(const QString &key, const QVariant defaultValue)
|
||||||
{
|
{
|
||||||
return m_currentConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScriptedEffect::setActiveConfig(const QString &name)
|
|
||||||
{
|
|
||||||
if (name.isEmpty()) {
|
|
||||||
m_currentConfig = "main";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Plasma::ConfigLoader *loader = m_configs.value(name, 0);
|
|
||||||
|
|
||||||
if (!loader) {
|
|
||||||
if (!loadConfig(name)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_currentConfig = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant ScriptedEffect::readConfig(const QString& key)
|
|
||||||
{
|
|
||||||
Plasma::ConfigLoader *config = m_configs.value(m_currentConfig);
|
|
||||||
QVariant result;
|
|
||||||
|
|
||||||
if (config) {
|
|
||||||
result = config->property(key);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ScriptedEffect::loadConfig(const QString& name)
|
|
||||||
{
|
|
||||||
const QString path = KStandardDirs::locate("data", "kwin/effects/" + m_effectName + "/contents/config/" + name + ".xml");
|
|
||||||
if (path.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile f(path);
|
|
||||||
KConfigGroup cg = effects->effectConfig(m_effectName);
|
KConfigGroup cg = effects->effectConfig(m_effectName);
|
||||||
Plasma::ConfigLoader *loader = new Plasma::ConfigLoader(&cg, &f, this);
|
return cg.readEntry(key, defaultValue);
|
||||||
m_configs.insert(name, loader);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -26,10 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
class QScriptEngine;
|
class QScriptEngine;
|
||||||
class QScriptValue;
|
class QScriptValue;
|
||||||
|
|
||||||
namespace Plasma {
|
|
||||||
class ConfigLoader;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -37,12 +33,6 @@ class ScriptedEffect : public KWin::AnimationEffect
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_ENUMS(DataRole)
|
Q_ENUMS(DataRole)
|
||||||
/**
|
|
||||||
* The current active configuration description. For instance, setting it to "foo" would cause the
|
|
||||||
* Effect to try and reference the contents/config/foo.xml KConfigXT file. Setting this to an empty
|
|
||||||
* string will switch to the main.xml file.
|
|
||||||
**/
|
|
||||||
Q_PROPERTY(QString activeConfig READ activeConfig WRITE setActiveConfig)
|
|
||||||
public:
|
public:
|
||||||
// copied from kwineffects.h
|
// copied from kwineffects.h
|
||||||
enum DataRole {
|
enum DataRole {
|
||||||
|
@ -71,10 +61,12 @@ public:
|
||||||
**/
|
**/
|
||||||
Q_SCRIPTABLE bool isGrabbed(KWin::EffectWindow *w, DataRole grabRole);
|
Q_SCRIPTABLE bool isGrabbed(KWin::EffectWindow *w, DataRole grabRole);
|
||||||
/**
|
/**
|
||||||
* Reads the value from the configuration data for the given key as defined by the currently active configuration.
|
* Reads the value from the configuration data for the given key.
|
||||||
|
* @param key The key to search for
|
||||||
|
* @param defaultValue The value to return if the key is not found
|
||||||
* @returns The config value if present
|
* @returns The config value if present
|
||||||
**/
|
**/
|
||||||
Q_SCRIPTABLE QVariant readConfig(const QString &key);
|
Q_SCRIPTABLE QVariant readConfig(const QString &key, const QVariant defaultValue = QVariant());
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void animate(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), uint meta = 0, QEasingCurve curve = QEasingCurve(), int delay = 0);
|
void animate(KWin::EffectWindow *w, Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from = KWin::FPx2(), uint meta = 0, QEasingCurve curve = QEasingCurve(), int delay = 0);
|
||||||
|
@ -90,12 +82,9 @@ private Q_SLOTS:
|
||||||
private:
|
private:
|
||||||
ScriptedEffect();
|
ScriptedEffect();
|
||||||
bool init(const QString &effectName, const QString &pathToScript);
|
bool init(const QString &effectName, const QString &pathToScript);
|
||||||
bool loadConfig(const QString &name);
|
|
||||||
QScriptEngine *m_engine;
|
QScriptEngine *m_engine;
|
||||||
QString m_effectName;
|
QString m_effectName;
|
||||||
QString m_scriptFile;
|
QString m_scriptFile;
|
||||||
QString m_currentConfig;
|
|
||||||
QMap<QString, Plasma::ConfigLoader*> m_configs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue