2010-08-06 06:21:42 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Aaron J. Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation
|
|
|
|
*
|
|
|
|
* 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 JAVASCRIPTSERVICE_H
|
|
|
|
#define JAVASCRIPTSERVICE_H
|
|
|
|
|
|
|
|
#include <QWeakPointer>
|
|
|
|
#include <QScriptValue>
|
|
|
|
|
|
|
|
#include <Plasma/Package>
|
|
|
|
#include <Plasma/Service>
|
2010-08-07 01:07:52 +02:00
|
|
|
#include <Plasma/ServiceJob>
|
2010-08-06 06:21:42 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
class Package;
|
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
class JavaScriptDataEngine;
|
|
|
|
|
2010-08-07 01:07:52 +02:00
|
|
|
class JavaScriptServiceJob : public Plasma::ServiceJob
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString destination READ destination)
|
|
|
|
Q_PROPERTY(QString operationName READ operationName)
|
|
|
|
Q_PROPERTY(QVariantMap parameters READ parameters)
|
|
|
|
Q_PROPERTY(QVariant result READ result WRITE setResult)
|
|
|
|
Q_PROPERTY(int error READ error WRITE setError)
|
|
|
|
Q_PROPERTY(QString errorText READ errorText WRITE setErrorText)
|
|
|
|
Q_PROPERTY(QScriptValue start READ startFunction WRITE setStartFunction)
|
|
|
|
|
|
|
|
public:
|
|
|
|
JavaScriptServiceJob(QScriptEngine *engine, const QString &destination, const QString &operation,
|
|
|
|
const QMap<QString, QVariant> ¶meters, QObject *parent = 0);
|
|
|
|
|
|
|
|
void start();
|
|
|
|
|
|
|
|
QScriptValue startFunction() const;
|
|
|
|
void setStartFunction(const QScriptValue &v);
|
|
|
|
|
|
|
|
QScriptValue scriptValue() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QScriptValue m_startFunction;
|
|
|
|
QScriptValue m_thisObject;
|
|
|
|
};
|
|
|
|
|
2010-08-06 06:21:42 +02:00
|
|
|
class JavaScriptService : public Plasma::Service
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2010-08-06 21:42:08 +02:00
|
|
|
Q_PROPERTY(QString destination READ destination WRITE setDestination)
|
|
|
|
Q_PROPERTY(QStringList operationNames READ operationNames)
|
|
|
|
Q_PROPERTY(QString name READ name)
|
2010-08-07 01:07:52 +02:00
|
|
|
Q_PROPERTY(QScriptValue setupJob READ setupJobFunction WRITE setSetupJobFunction)
|
2010-08-06 06:21:42 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
JavaScriptService(const QString &serviceName, JavaScriptDataEngine *engine);
|
2010-08-06 21:34:59 +02:00
|
|
|
~JavaScriptService();
|
2010-08-06 06:21:42 +02:00
|
|
|
|
|
|
|
bool wasFound() const;
|
2010-08-07 01:07:52 +02:00
|
|
|
|
|
|
|
QScriptValue setupJobFunction() const;
|
|
|
|
void setSetupJobFunction(const QScriptValue &v);
|
2010-08-06 06:21:42 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Plasma::ServiceJob *createJob(const QString &operation, QMap<QString, QVariant> ¶meters);
|
|
|
|
void registerOperationsScheme();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QWeakPointer<JavaScriptDataEngine> m_dataEngine;
|
2010-08-07 01:07:52 +02:00
|
|
|
QScriptValue m_setupFunc;
|
2010-08-06 06:21:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|