Use Plasma::ConfigLoader to read config values in scripted effects
Advantage is that the default value is no longer needed and scripted effects are anyway supposed to add a kconfigxt file.
This commit is contained in:
parent
787c572535
commit
d9d9aad674
2 changed files with 23 additions and 2 deletions
|
@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include "workspace_wrapper.h"
|
#include "workspace_wrapper.h"
|
||||||
#ifdef KWIN_BUILD_SCREENEDGES
|
#ifdef KWIN_BUILD_SCREENEDGES
|
||||||
#include "../screenedge.h"
|
#include "../screenedge.h"
|
||||||
|
#include <Plasma/ConfigLoader>
|
||||||
#endif
|
#endif
|
||||||
// KDE
|
// KDE
|
||||||
#include <KDE/KConfigGroup>
|
#include <KDE/KConfigGroup>
|
||||||
|
@ -270,6 +271,7 @@ ScriptedEffect::ScriptedEffect()
|
||||||
: AnimationEffect()
|
: AnimationEffect()
|
||||||
, m_engine(new QScriptEngine(this))
|
, m_engine(new QScriptEngine(this))
|
||||||
, m_scriptFile(QString())
|
, m_scriptFile(QString())
|
||||||
|
, m_config(NULL)
|
||||||
{
|
{
|
||||||
connect(m_engine, SIGNAL(signalHandlerException(QScriptValue)), SLOT(signalHandlerException(QScriptValue)));
|
connect(m_engine, SIGNAL(signalHandlerException(QScriptValue)), SLOT(signalHandlerException(QScriptValue)));
|
||||||
}
|
}
|
||||||
|
@ -288,6 +290,15 @@ bool ScriptedEffect::init(const QString &effectName, const QString &pathToScript
|
||||||
m_effectName = effectName;
|
m_effectName = effectName;
|
||||||
m_scriptFile = pathToScript;
|
m_scriptFile = pathToScript;
|
||||||
|
|
||||||
|
// does the effect contain an KConfigXT file?
|
||||||
|
const QString kconfigXTFile = KStandardDirs::locate("data", QLatin1String(KWIN_NAME) + "/effects/" + m_effectName + "/contents/config/main.xml");
|
||||||
|
if (!kconfigXTFile.isNull()) {
|
||||||
|
KConfigGroup cg = effects->effectConfig(m_effectName);
|
||||||
|
QFile xmlFile(kconfigXTFile);
|
||||||
|
m_config = new Plasma::ConfigLoader(&cg, &xmlFile, this);
|
||||||
|
m_config->readConfig();
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
m_engine->globalObject().setProperty("Effect", m_engine->newQMetaObject(&ScriptedEffect::staticMetaObject));
|
m_engine->globalObject().setProperty("Effect", m_engine->newQMetaObject(&ScriptedEffect::staticMetaObject));
|
||||||
|
@ -386,6 +397,9 @@ bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRol
|
||||||
void ScriptedEffect::reconfigure(ReconfigureFlags flags)
|
void ScriptedEffect::reconfigure(ReconfigureFlags flags)
|
||||||
{
|
{
|
||||||
AnimationEffect::reconfigure(flags);
|
AnimationEffect::reconfigure(flags);
|
||||||
|
if (m_config) {
|
||||||
|
m_config->readConfig();
|
||||||
|
}
|
||||||
emit configChanged();
|
emit configChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,8 +422,10 @@ bool ScriptedEffect::borderActivated(ElectricBorder edge)
|
||||||
|
|
||||||
QVariant ScriptedEffect::readConfig(const QString &key, const QVariant defaultValue)
|
QVariant ScriptedEffect::readConfig(const QString &key, const QVariant defaultValue)
|
||||||
{
|
{
|
||||||
KConfigGroup cg = effects->effectConfig(m_effectName);
|
if (!m_config) {
|
||||||
return cg.readEntry(key, defaultValue);
|
return defaultValue;
|
||||||
|
}
|
||||||
|
return m_config->property(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationData::AnimationData (QObject* parent)
|
AnimationData::AnimationData (QObject* parent)
|
||||||
|
|
|
@ -26,6 +26,10 @@ 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
|
||||||
{
|
{
|
||||||
class ScriptedEffect;
|
class ScriptedEffect;
|
||||||
|
@ -147,6 +151,7 @@ private:
|
||||||
QString m_scriptFile;
|
QString m_scriptFile;
|
||||||
QHash<QAction*, QScriptValue> m_shortcutCallbacks;
|
QHash<QAction*, QScriptValue> m_shortcutCallbacks;
|
||||||
QHash<int, QList<QScriptValue> > m_screenEdgeCallbacks;
|
QHash<int, QList<QScriptValue> > m_screenEdgeCallbacks;
|
||||||
|
Plasma::ConfigLoader *m_config;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue