find_package(Qt5Core REQUIRED)
find_package(Qt5Network REQUIRED)
-find_package(Qt5Script REQUIRED)
+find_package(Qt5Qml REQUIRED)
if(Qt5Core_FOUND)
message(STATUS "using Qt5")
- set(QT_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} ${Qt5Script_INCLUDE_DIRS})
- set(QT_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Script_LIBRARIES})
+ set(QT_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} ${Qt5Qml_INCLUDE_DIRS})
+ set(QT_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Qml_LIBRARIES})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
add_definitions(${Qt5Core_DEFINITIONS})
include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${communi_INCLUDE_DIRS} ${QT_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/plugins/common)
-set(bluemonkeyplugin_headers bluemonkey.h authenticate.h agent.h)
-set(bluemonkeyplugin_sources bluemonkey.cpp authenticate.cpp agent.cpp)
+set(bluemonkeyplugin_headers bluemonkey.h authenticate.h)
+set(bluemonkeyplugin_sources bluemonkey.cpp authenticate.cpp)
add_library(bluemonkeyplugin MODULE ${bluemonkeyplugin_sources})
set_target_properties(bluemonkeyplugin PROPERTIES PREFIX "")
#include "debugout.h"
#include <QJsonDocument>
-#include <QScriptEngine>
+#include <QJSEngine>
#include <QDateTime>
#include <QString>
#include <QFile>
#include <QTimer>
-
-Q_SCRIPT_DECLARE_QMETAOBJECT(QTimer, QObject*)
+#include <QtQml>
#define foreach Q_FOREACH
}
-BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* e, map<string, string> config, AbstractSource &parent): QObject(0), AmbPluginImpl(e, config, parent), agent(nullptr), engine(nullptr), mSilentMode(false)
+BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* e, map<string, string> config, AbstractSource &parent): QObject(0), AmbPluginImpl(e, config, parent), engine(nullptr), mSilentMode(false)
{
QTimer::singleShot(1,this,SLOT(reloadEngine()));
auth = new Authenticate(config, this);
+ qmlRegisterType<QTimer>("", 1, 0, "QTimer");
+
/* connect(irc, &IrcCommunication::message, [&](QString sender, QString prefix, QString codes ) {
if(codes.startsWith("authenticate"))
return new Property(str.toStdString(), "", routingEngine, this);
}
-QObject *BluemonkeySink::subscribeTo(QString str, QString srcFilter)
+QObject *BluemonkeySink::subscribeToSource(QString str, QString srcFilter)
{
return new Property(str.toStdString(), srcFilter, routingEngine, this);
}
DebugOut()<<"evaluating script: "<<script.toStdString()<<endl;
- QScriptValue val = engine->evaluate(script);
+ QJSValue val = engine->evaluate(script);
DebugOut()<<val.toString().toStdString()<<endl;
}
if(engine)
engine->deleteLater();
- engine = new QScriptEngine(this);
-
- if(agent) delete agent;
-
- agent = new BluemonkeyAgent(engine);
+ engine = new QJSEngine(this);
- //engine->setAgent(agent);
-
- QScriptValue value = engine->newQObject(this);
+ QJSValue value = engine->newQObject(this);
engine->globalObject().setProperty("bluemonkey", value);
- QScriptValue qtimerClass = engine->scriptValueFromQMetaObject<QTimer>();
- engine->globalObject().setProperty("QTimer", qtimerClass);
-
-// QScriptValue ircValue = engine->newQObject(irc);
-// engine->globalObject().setProperty("irc", ircValue);
-
loadConfig(configuration["config"].c_str());
}
void BluemonkeySink::writeProgram(QString program)
{
- QScriptSyntaxCheckResult result = QScriptEngine::checkSyntax(program);
- if(result.state() != QScriptSyntaxCheckResult::Valid)
+
+ QJSEngine temp;
+ QJSValue result = temp.evaluate(program);
+ if(result.isError())
{
- DebugOut(DebugOut::Error)<<"Syntax error in program: "<<result.errorMessage().toStdString()<<endl;
+ DebugOut(DebugOut::Error)<<"Syntax error in program: "<<result.toString().toStdString()<<endl;
return;
}
DebugOut()<<str.toStdString()<<endl;
}
-void BluemonkeySink::getHistory(QStringList properties, QDateTime begin, QDateTime end, QScriptValue cbFunction)
+QObject *BluemonkeySink::createTimer()
+{
+ return new QTimer(this);
+}
+
+void BluemonkeySink::getHistory(QStringList properties, QDateTime begin, QDateTime end, QJSValue cbFunction)
{
double b = (double)begin.toMSecsSinceEpoch() / 1000.0;
double e = (double)end.toMSecsSinceEpoch() / 1000.0;
return;
}
- if(cbFunction.isFunction())
+ if(cbFunction.isCallable())
{
QVariantList list;
list.append(gvariantToQVariant(val->toVariant()));
}
- cbFunction.call(QScriptValue(),cbFunction.engine()->newVariant(list));
+ QJSValue val = cbFunction.engine()->toScriptValue<QVariantList>(list);
+
+ cbFunction.call(QJSValueList()<<val);
}
routingEngine->getRangePropertyAsync(request);
}
-void BluemonkeySink::createCustomProperty(QString name, QScriptValue defaultValue)
+void BluemonkeySink::createCustomProperty(QString name, QJSValue defaultValue)
{
auto create = [defaultValue, name]() -> AbstractPropertyType*
routingEngine->setProperty(request);
}
-void Property::getHistory(QDateTime begin, QDateTime end, QScriptValue cbFunction)
+void Property::getHistory(QDateTime begin, QDateTime end, QJSValue cbFunction)
{
double b = (double)begin.toMSecsSinceEpoch() / 1000.0;
double e = (double)end.toMSecsSinceEpoch() / 1000.0;
return;
}
- if(cbFunction.isFunction())
+ if(cbFunction.isCallable())
{
QVariantList list;
list.append(gvariantToQVariant(val->toVariant()));
}
-
- cbFunction.call(QScriptValue(),cbFunction.engine()->newVariant(list));
+ QJSValue val = cbFunction.engine()->toScriptValue<QVariantList>(list);
+ cbFunction.call(QJSValueList()<<val);
}
#include <QVariant>
#include <QJsonDocument>
#include <QDateTime>
-#include <QScriptValue>
+#include <QJSValue>
#include "uuidhelper.h"
#include "authenticate.h"
-#include "agent.h"
-class QScriptEngine;
+class QJSEngine;
class ModuleInterface
{
QVariant value();
void setValue(QVariant v);
- void getHistory(QDateTime begin, QDateTime end, QScriptValue cbFunction);
+ void getHistory(QDateTime begin, QDateTime end, QJSValue cbFunction);
Q_SIGNALS:
void changed(QVariant val);
virtual void propertyChanged(AbstractPropertyType* value);
virtual const std::string uuid() const;
- QScriptEngine* engine;
+ QJSEngine* engine;
virtual int supportedOperations();
public Q_SLOTS:
QObject* subscribeTo(QString str);
- QObject* subscribeTo(QString str, QString srcFilter);
+ QObject* subscribeToSource(QString str, QString srcFilter);
QStringList sourcesForProperty(QString property);
void log(QString str);
- void getHistory(QStringList properties, QDateTime begin, QDateTime end, QScriptValue cbFunction);
+ QObject* createTimer();
+
+ void getHistory(QStringList properties, QDateTime begin, QDateTime end, QJSValue cbFunction);
void setSilentMode(bool m)
{
mSilentMode = m;
}
- void createCustomProperty(QString name, QScriptValue defaultValue);
+ void createCustomProperty(QString name, QJSValue defaultValue);
private:
QStringList configsToLoad;
Authenticate* auth;
- BluemonkeyAgent* agent;
bool mSilentMode;
};