2 Copyright (c) 2007 Zack Rusin <zack@kde.org>
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 #include "plasmawebapplet.h"
25 #include <Plasma/DataEngineManager>
26 #include <Plasma/DataEngine>
28 using namespace Plasma
;
30 PlasmaJs::PlasmaJs(QObject
*parent
)
35 QStringList
PlasmaJs::knownEngines()
37 return DataEngineManager::listAllEngines();
40 ConfigGroupWrapper::ConfigGroupWrapper(const KConfigGroup
&config
)
45 void ConfigGroupWrapper::setConfig(const KConfigGroup
&config
)
47 //kDebug() << config.config()->name() << config.name();
51 QVariant
ConfigGroupWrapper::readEntry(const QString
&key
, const QVariant
&aDefault
) const
53 // Should KConfig do this?
54 // There is readEntry(key, QVariant) but it does not seem to work
55 // (if writeEntry was not QVariant??)
56 // kDebug() << aDefault.typeName();
57 if (aDefault
.type() == QVariant::Int
) {
58 return m_config
.readEntry(key
, aDefault
.toInt());
59 } else if (aDefault
.type() == QVariant::Double
) {
60 return m_config
.readEntry(key
, aDefault
.toDouble());
61 } else if (aDefault
.type() == QVariant::Bool
) {
62 return m_config
.readEntry(key
, aDefault
.toBool());
64 return m_config
.readEntry(key
, aDefault
.toString());
68 void ConfigGroupWrapper::writeEntry(const QString
&key
, const QVariant
& value
)
70 m_config
.writeEntry(key
, value
);
73 DataEngineDataWrapper::DataEngineDataWrapper(const DataEngine::Data
&data
)
78 int DataEngineDataWrapper::size() const
80 return m_data
.count();
83 void DataEngineDataWrapper::setData(const Plasma::DataEngine::Data
&data
)
88 QVariant
DataEngineDataWrapper::value(const QString
&key
) const
93 bool DataEngineDataWrapper::contains(const QString
&key
) const
95 return m_data
.keys().contains(key
);
98 QStringList
DataEngineDataWrapper::keys() const
100 return m_data
.keys();
103 QString
DataEngineDataWrapper::key(int i
) const
105 return m_data
.keys().at(i
);
108 DataEngineWrapper::DataEngineWrapper(Plasma::DataEngine
*engine
, QObject
*applet
)
109 : QObject(engine
), m_engine(engine
), m_applet(applet
)
113 QStringList
DataEngineWrapper::sources() const
115 return m_engine
->sources();
118 QString
DataEngineWrapper::engineName() const
120 return m_engine
->name();
123 bool DataEngineWrapper::isValid() const
125 return m_engine
->isValid();
128 QString
DataEngineWrapper::icon() const
130 return m_engine
->icon();
133 QObject
* DataEngineWrapper::query(const QString
&str
) const
135 DataEngine::Data data
= m_engine
->query(str
);
136 return new DataEngineDataWrapper(data
);
139 DataEngineWrapper::~DataEngineWrapper()
143 void DataEngineWrapper::connectSource(const QString
& source
,
144 uint pollingInterval
, uint intervalAlignment
)
147 m_engine
->connectSource(source
, m_applet
, pollingInterval
,
148 (Plasma::IntervalAlignment
)intervalAlignment
);
152 #include "plasmajs.moc"