allow for non-main.xml configs as well

svn path=/trunk/KDE/kdebase/workspace/plasma/scriptengines/javascript/; revision=906351
This commit is contained in:
Aaron J. Seigo 2009-01-06 00:11:31 +00:00
parent 9cf1237aee
commit 4d8ac571a9
5 changed files with 65 additions and 2 deletions

View File

@ -20,6 +20,7 @@
#include "appletinterface.h"
#include <QAction>
#include <QFile>
#include <QSignalMapper>
#include <KDE/KIcon>
@ -28,6 +29,7 @@
#include <Plasma/Applet>
#include <Plasma/Context>
#include <Plasma/DataEngine>
#include <Plasma/Package>
#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);

View File

@ -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<QString> m_actions;
QSignalMapper *m_actionSignals;
QString m_currentConfig;
QMap<QString, Plasma::ConfigLoader*> m_configs;
};
#endif

View File

@ -1,2 +1,5 @@
print(plasmoid.readConfig("Test"));
plasmoid.activeConfig = "secondary";
print(plasmoid.activeConfig);
print(plasmoid.readConfig("Test"));

View File

@ -8,7 +8,7 @@
<group name="General">
<entry name="Test" type="String">
<label>A test label</label>
<default>Heo hello!</default>
<default>Hello hello!</default>
</entry>
</group>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name=""/>
<group name="General">
<entry name="Test" type="String">
<label>A test label</label>
<default>This is in the secondary config XML</default>
</entry>
</group>
</kcfg>