~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/scriptengines/webkit/plasmajs.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 2007 Zack Rusin <zack@kde.org>
 
3
 
 
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:
 
10
 
 
11
The above copyright notice and this permission notice shall be included in
 
12
all copies or substantial portions of the Software.
 
13
 
 
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
 
20
THE SOFTWARE.
 
21
 */
 
22
#include "plasmajs.h"
 
23
#include "plasmawebapplet.h"
 
24
 
 
25
#include <Plasma/DataEngine>
 
26
 
 
27
using namespace Plasma;
 
28
 
 
29
ConfigGroupWrapper::ConfigGroupWrapper(const KConfigGroup &config)
 
30
: m_config(config)
 
31
{
 
32
}
 
33
 
 
34
void ConfigGroupWrapper::setConfig(const KConfigGroup &config)
 
35
{
 
36
    //kDebug() << config.config()->name() << config.name();
 
37
    m_config = config;
 
38
}
 
39
 
 
40
QVariant ConfigGroupWrapper::readEntry(const QString &key, const QVariant &aDefault) const
 
41
{
 
42
    // Should KConfig do this?
 
43
    // There is readEntry(key, QVariant) but it does not seem to work
 
44
    // (if writeEntry was not QVariant??)
 
45
    // kDebug() << aDefault.typeName();
 
46
    if (aDefault.type() == QVariant::Int) {
 
47
        return m_config.readEntry(key, aDefault.toInt());
 
48
    } else if (aDefault.type() == QVariant::Double) {
 
49
        return m_config.readEntry(key, aDefault.toDouble());
 
50
    } else if (aDefault.type() == QVariant::Bool) {
 
51
        return m_config.readEntry(key, aDefault.toBool());
 
52
    } else {
 
53
        return m_config.readEntry(key, aDefault.toString());
 
54
    }
 
55
}
 
56
 
 
57
void ConfigGroupWrapper::writeEntry(const QString &key, const QVariant& value)
 
58
{
 
59
    m_config.writeEntry(key, value);
 
60
}
 
61
 
 
62
DataEngineDataWrapper::DataEngineDataWrapper(const DataEngine::Data &data)
 
63
    : m_data(data)
 
64
{
 
65
}
 
66
 
 
67
int DataEngineDataWrapper::length() const
 
68
{
 
69
    return m_data.count();
 
70
}
 
71
 
 
72
void DataEngineDataWrapper::setData(const Plasma::DataEngine::Data &data)
 
73
{
 
74
    m_data = data;
 
75
}
 
76
 
 
77
QVariant DataEngineDataWrapper::value(const QString &key) const
 
78
{
 
79
    return m_data[key];
 
80
}
 
81
 
 
82
bool DataEngineDataWrapper::contains(const QString &key) const
 
83
{
 
84
    return m_data.keys().contains(key);
 
85
}
 
86
 
 
87
QStringList DataEngineDataWrapper::keys() const
 
88
{
 
89
    return m_data.keys();
 
90
}
 
91
 
 
92
QString DataEngineDataWrapper::key(int i) const
 
93
{
 
94
    return m_data.keys().at(i);
 
95
}
 
96
 
 
97
DataEngineWrapper::DataEngineWrapper(Plasma::DataEngine *engine, QObject *applet)
 
98
    : QObject(engine), m_engine(engine), m_applet(applet)
 
99
{
 
100
}
 
101
 
 
102
QStringList DataEngineWrapper::sources() const
 
103
{
 
104
    return m_engine->sources();
 
105
}
 
106
 
 
107
QString DataEngineWrapper::engineName() const
 
108
{
 
109
    return m_engine->name();
 
110
}
 
111
 
 
112
bool DataEngineWrapper::isValid() const
 
113
{
 
114
    return m_engine->isValid();
 
115
}
 
116
 
 
117
QString DataEngineWrapper::icon() const
 
118
{
 
119
    return m_engine->icon();
 
120
}
 
121
 
 
122
QObject * DataEngineWrapper::query(const QString &str) const
 
123
{
 
124
    DataEngine::Data data = m_engine->query(str);
 
125
    return new DataEngineDataWrapper(data);
 
126
}
 
127
 
 
128
DataEngineWrapper::~DataEngineWrapper()
 
129
{
 
130
}
 
131
 
 
132
void DataEngineWrapper::connectSource(const QString& source,
 
133
                                      uint pollingInterval, uint intervalAlignment)
 
134
{
 
135
    if (m_applet) {
 
136
        m_engine->connectSource(source, m_applet, pollingInterval,
 
137
                                (Plasma::IntervalAlignment)intervalAlignment);
 
138
    }
 
139
}
 
140
 
 
141
#include "plasmajs.moc"