2009-07-04 06:30:57 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2011-03-28 16:54:00 +02:00
|
|
|
* it under the terms of the GNU Library General Public License as
|
2009-07-04 06:30:57 +02:00
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef JAVASCRIPTDATAENGINE_H
|
|
|
|
#define JAVASCRIPTDATAENGINE_H
|
|
|
|
|
|
|
|
#include <Plasma/DataEngineScript>
|
|
|
|
|
|
|
|
#include <QScriptValue>
|
|
|
|
|
2010-01-07 03:27:54 +01:00
|
|
|
class ScriptEnv;
|
2009-07-04 06:30:57 +02:00
|
|
|
class QScriptContext;
|
2010-02-22 12:33:21 +01:00
|
|
|
class QScriptEngine;
|
2009-07-04 06:30:57 +02:00
|
|
|
|
|
|
|
class JavaScriptDataEngine : public Plasma::DataEngineScript
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(int sourceCount WRITE jsSetMaxSourceCount READ maxSourceCount)
|
2010-05-19 23:58:18 +02:00
|
|
|
Q_PROPERTY(int minimumPollingInterval WRITE jsSetMinimumPollingInterval READ jsMinimumPollingInterval)
|
2009-07-04 06:30:57 +02:00
|
|
|
Q_PROPERTY(int pollingInterval WRITE jsSetPollingInterval READ pollingInterval)
|
|
|
|
|
|
|
|
public:
|
|
|
|
JavaScriptDataEngine(QObject *parent, const QVariantList &args);
|
|
|
|
bool init();
|
|
|
|
|
2010-08-06 06:21:42 +02:00
|
|
|
QScriptEngine *engine() const;
|
|
|
|
QString filePath(const char *type, const QString &file) const;
|
|
|
|
|
2009-07-04 06:30:57 +02:00
|
|
|
QStringList sources() const;
|
|
|
|
bool sourceRequestEvent(const QString &name);
|
|
|
|
bool updateSourceEvent(const QString &source);
|
2010-01-21 00:29:53 +01:00
|
|
|
Plasma::Service *serviceForSource(const QString &source);
|
2009-07-04 06:30:57 +02:00
|
|
|
|
|
|
|
int maxSourceCount() const;
|
|
|
|
void jsSetMaxSourceCount(int count);
|
|
|
|
void jsSetMinimumPollingInterval(int interval);
|
2010-05-19 23:58:18 +02:00
|
|
|
int jsMinimumPollingInterval() const;
|
2009-07-04 06:30:57 +02:00
|
|
|
void jsSetPollingInterval(int interval);
|
|
|
|
int pollingInterval() const;
|
|
|
|
|
2010-06-30 00:11:15 +02:00
|
|
|
public Q_SLOTS:
|
|
|
|
bool include(const QString &file);
|
|
|
|
|
2010-01-07 03:27:54 +01:00
|
|
|
private Q_SLOTS:
|
|
|
|
void reportError(ScriptEnv *engine, bool fatal) const;
|
|
|
|
|
2009-07-04 06:30:57 +02:00
|
|
|
private:
|
|
|
|
static JavaScriptDataEngine *extractIFace(QScriptEngine *engine, QString &error);
|
|
|
|
static QScriptValue jsSetData(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue jsRemoveAllData(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue jsRemoveData(QScriptContext *context, QScriptEngine *engine);
|
|
|
|
static QScriptValue jsRemoveAllSources(QScriptContext *context, QScriptEngine *engine);
|
2010-08-06 06:21:42 +02:00
|
|
|
static QScriptValue serviceCtor(QScriptContext *context, QScriptEngine *engine);
|
2009-07-04 06:30:57 +02:00
|
|
|
|
2010-08-05 23:14:00 +02:00
|
|
|
QScriptValue callFunction(const QString &functionName, const QScriptValueList &args);
|
2009-07-04 06:30:57 +02:00
|
|
|
|
2010-02-22 12:33:21 +01:00
|
|
|
QScriptEngine *m_qscriptEngine;
|
|
|
|
ScriptEnv *m_env;
|
2010-06-22 03:55:53 +02:00
|
|
|
QScriptValue m_iface;
|
2010-05-19 23:58:18 +02:00
|
|
|
int m_pollingInterval;
|
2009-07-04 06:30:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|