Commit 6e5c9e9b authored by Fabian Vogt's avatar Fabian Vogt

Use QJSValue as method parameter type for the scripting interface

Summary:
If a slot or Q_INVOKABLE has a QVariant as parameter and gets called
from a QJSEngine's script, it receives a QJSValue wrapped as QVariant.
To get a QVariant with the actual value wrapped, calling QJSValue::toVariant
is necessary.

I'm not entirely sure whether this is intentional behaviour of QJSEngine, but
even if it's a bug we'll have to workaround it.

BUG: 397338

Test Plan: I have favorites in kickoff again.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D14822
parent ec4dfb97
......@@ -102,16 +102,16 @@ QStringList Applet::configGroups() const
return QStringList();
}
QVariant Applet::readConfig(const QString &key, const QVariant &def) const
QVariant Applet::readConfig(const QString &key, const QJSValue &def) const
{
if (d->configGroup.isValid()) {
return d->configGroup.readEntry(key, def);
return d->configGroup.readEntry(key, def.toVariant());
} else {
return QVariant();
}
}
void Applet::writeConfig(const QString &key, const QVariant &value)
void Applet::writeConfig(const QString &key, const QJSValue &value)
{
if (d->configGroup.isValid()) {
if (d->inWallpaperConfig) {
......@@ -119,13 +119,13 @@ void Applet::writeConfig(const QString &key, const QVariant &value)
QObject *wallpaperGraphicsObject = applet()->property("wallpaperGraphicsObject").value<QObject *>();
if (wallpaperGraphicsObject) {
KDeclarative::ConfigPropertyMap *config = static_cast<KDeclarative::ConfigPropertyMap *>(wallpaperGraphicsObject->property("configuration").value<QObject *>());
config->setProperty(key.toLatin1(), value);
config->setProperty(key.toLatin1(), value.toVariant());
}
} else if (applet()->configScheme()) {
//check if it can be written in the applets' configScheme
KConfigSkeletonItem *item = applet()->configScheme()->findItemByName(key);
if (item) {
item->setProperty(value);
item->setProperty(value.toVariant());
applet()->configScheme()->blockSignals(true);
applet()->configScheme()->save();
//why read? read will update KConfigSkeletonItem::mLoadedValue,
......@@ -136,7 +136,7 @@ void Applet::writeConfig(const QString &key, const QVariant &value)
}
}
d->configGroup.writeEntry(key, value);
d->configGroup.writeEntry(key, value.toVariant());
d->configDirty = true;
}
}
......@@ -181,19 +181,19 @@ QStringList Applet::globalConfigGroups() const
return QStringList();
}
QVariant Applet::readGlobalConfig(const QString &key, const QVariant &def) const
QVariant Applet::readGlobalConfig(const QString &key, const QJSValue &def) const
{
if (d->globalConfigGroup.isValid()) {
return d->globalConfigGroup.readEntry(key, def);
return d->globalConfigGroup.readEntry(key, def.toVariant());
} else {
return QVariant();
}
}
void Applet::writeGlobalConfig(const QString &key, const QVariant &value)
void Applet::writeGlobalConfig(const QString &key, const QJSValue &value)
{
if (d->globalConfigGroup.isValid()) {
d->globalConfigGroup.writeEntry(key, value);
d->globalConfigGroup.writeEntry(key, value.toVariant());
d->configDirty = true;
}
}
......
......@@ -21,6 +21,7 @@
#define APPLET
#include <QObject>
#include <QJSValue>
#include <QWeakPointer>
#include <kconfiggroup.h>
......@@ -66,10 +67,10 @@ protected:
void reloadConfigIfNeeded();
public Q_SLOTS:
virtual QVariant readConfig(const QString &key, const QVariant &def = QString()) const;
virtual void writeConfig(const QString &key, const QVariant &value);
virtual QVariant readGlobalConfig(const QString &key, const QVariant &def = QString()) const;
virtual void writeGlobalConfig(const QString &key, const QVariant &value);
virtual QVariant readConfig(const QString &key, const QJSValue &def = QString()) const;
virtual void writeConfig(const QString &key, const QJSValue &value);
virtual QVariant readGlobalConfig(const QString &key, const QJSValue &def = QString()) const;
virtual void writeGlobalConfig(const QString &key, const QJSValue &value);
virtual void reloadConfig();
private:
......
......@@ -181,13 +181,13 @@ bool ConfigGroup::readConfigFile()
// Bound methods and slots
bool ConfigGroup::writeEntry(const QString& key, const QVariant& value)
bool ConfigGroup::writeEntry(const QString& key, const QJSValue& value)
{
if (!d->configGroup) {
return false;
}
d->configGroup->writeEntry(key, value);
d->configGroup->writeEntry(key, value.toVariant());
d->synchTimer->start();
return true;
}
......
......@@ -22,6 +22,7 @@
#include <QObject>
#include <QVariant>
#include <QJSValue>
#include <KSharedConfig>
......@@ -52,7 +53,7 @@ public:
QStringList groupList() const;
Q_INVOKABLE QVariant readEntry(const QString &key);
Q_INVOKABLE bool writeEntry(const QString &key, const QVariant &value);
Q_INVOKABLE bool writeEntry(const QString &key, const QJSValue &value);
Q_INVOKABLE void deleteEntry(const QString& key);
Q_SIGNALS:
......
......@@ -323,7 +323,7 @@ void loadSerializedConfigs(Object *object, const QJSValue &configs)
// Read other properties and set the configuration
SCRIPT_OBJECT_FOREACH(key, value, config) {
object->writeConfig(key, value.toVariant());
object->writeConfig(key, value);
};
};
}
......
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