diff --git a/scriptengines/javascript/appletinterface.cpp b/scriptengines/javascript/appletinterface.cpp index c0d174949..cc188b90d 100644 --- a/scriptengines/javascript/appletinterface.cpp +++ b/scriptengines/javascript/appletinterface.cpp @@ -20,6 +20,7 @@ #include "appletinterface.h" #include +#include #include #include @@ -28,6 +29,7 @@ #include #include #include +#include #include "simplejavascriptapplet.h" @@ -109,9 +111,43 @@ void AppletInterface::update() applet()->update(); } +QString AppletInterface::activeConfig() const +{ + return m_currentConfig.isEmpty() ? "main" : m_currentConfig; +} + +void AppletInterface::setActiveConfig(const QString &name) +{ + if (name == "main") { + m_currentConfig = QString(); + return; + } + + Plasma::ConfigLoader *loader = m_configs.value(name, 0); + + if (!loader) { + QString path = applet()->package()->filePath("config", name + ".xml"); + if (path.isEmpty()) { + return; + } + + QFile f(path); + KConfigGroup cg = applet()->config(); + loader = new Plasma::ConfigLoader(&cg, &f, this); + m_configs.insert(name, loader); + } + + m_currentConfig = name; +} + QVariant AppletInterface::readConfig(const QString &entry) const { - Plasma::ConfigLoader *config = applet()->configScheme(); + Plasma::ConfigLoader *config = 0; + if (m_currentConfig.isEmpty()) { + config = applet()->configScheme(); + } else { + config = m_configs.value(m_currentConfig, 0); + } if (config) { return config->property(entry); diff --git a/scriptengines/javascript/appletinterface.h b/scriptengines/javascript/appletinterface.h index 9d7dd2d15..c3b57729e 100644 --- a/scriptengines/javascript/appletinterface.h +++ b/scriptengines/javascript/appletinterface.h @@ -34,6 +34,7 @@ class KConfigGroup; namespace Plasma { class Applet; + class ConfigLoader; } // namespace Plasa class AppletInterface : public QObject @@ -43,6 +44,8 @@ class AppletInterface : public QObject Q_ENUMS(Location) Q_ENUMS(AspectRatioMode) Q_ENUMS(QtOrientation) + Q_PROPERTY(QString activeConfig WRITE setActiveConfig READ activeConfig) + public: AppletInterface(SimpleJavaScriptApplet *parent); ~AppletInterface(); @@ -136,6 +139,10 @@ enum QtOrientation { Q_INVOKABLE void update(); + Q_INVOKABLE QString activeConfig() const; + + Q_INVOKABLE void setActiveConfig(const QString &name); + Q_INVOKABLE QVariant readConfig(const QString &entry) const; //FIXME bindings @@ -157,6 +164,8 @@ private: SimpleJavaScriptApplet *m_appletScriptEngine; QSet m_actions; QSignalMapper *m_actionSignals; + QString m_currentConfig; + QMap m_configs; }; #endif diff --git a/scriptengines/javascript/tests/javascript-config-test/contents/code/main.js b/scriptengines/javascript/tests/javascript-config-test/contents/code/main.js index e7a9e8039..7000f6672 100644 --- a/scriptengines/javascript/tests/javascript-config-test/contents/code/main.js +++ b/scriptengines/javascript/tests/javascript-config-test/contents/code/main.js @@ -1,2 +1,5 @@ print(plasmoid.readConfig("Test")); +plasmoid.activeConfig = "secondary"; +print(plasmoid.activeConfig); +print(plasmoid.readConfig("Test")); diff --git a/scriptengines/javascript/tests/javascript-config-test/contents/config/main.xml b/scriptengines/javascript/tests/javascript-config-test/contents/config/main.xml index b079839cc..b8e5869d7 100644 --- a/scriptengines/javascript/tests/javascript-config-test/contents/config/main.xml +++ b/scriptengines/javascript/tests/javascript-config-test/contents/config/main.xml @@ -8,7 +8,7 @@ - Heo hello! + Hello hello! diff --git a/scriptengines/javascript/tests/javascript-config-test/contents/config/secondary.xml b/scriptengines/javascript/tests/javascript-config-test/contents/config/secondary.xml new file mode 100644 index 000000000..efa58ce08 --- /dev/null +++ b/scriptengines/javascript/tests/javascript-config-test/contents/config/secondary.xml @@ -0,0 +1,15 @@ + + + + + + + + This is in the secondary config XML + + + +