diff --git a/src/controllers/controller.cpp b/src/controllers/controller.cpp index e2bf6f4689f2..9973eeb4dd10 100644 --- a/src/controllers/controller.cpp +++ b/src/controllers/controller.cpp @@ -5,10 +5,12 @@ * @brief Base class representing a physical (or software) controller. */ +#include "controllers/controller.h" + #include #include -#include "controllers/controller.h" +#include "control/controlobject.h" #include "controllers/controllerdebug.h" #include "controllers/defs_controllers.h" #include "util/screensaver.h" @@ -21,6 +23,9 @@ Controller::Controller(const QString& group) m_bIsOpen(false), m_bLearning(false) { m_userActivityInhibitTimer.start(); + + m_pReloadScripts = make_parented(ConfigKey(group, "reload_scripts"), this); + connect(m_pReloadScripts, &ControlObject::valueChanged, this, &Controller::slotReloadScripts); } Controller::~Controller() { @@ -88,6 +93,14 @@ void Controller::stopLearning() { } +void Controller::slotReloadScripts(double v) { + if (!v || !m_pEngine) { + return; + } + + m_pEngine->reloadScripts(); +} + void Controller::send(QList data, unsigned int length) { // If you change this implementation, also change it in HidController (That // function is required due to HID devices having report IDs) diff --git a/src/controllers/controller.h b/src/controllers/controller.h index a57a7323aed0..ece417d31e05 100644 --- a/src/controllers/controller.h +++ b/src/controllers/controller.h @@ -19,7 +19,9 @@ #include "controllers/controllervisitor.h" #include "controllers/engine/controllerengine.h" #include "util/duration.h" +#include "util/parented_ptr.h" +class ControlObject; class ControllerJSProxy; class Controller : public QObject, ConstControllerPresetVisitor { @@ -106,6 +108,8 @@ class Controller : public QObject, ConstControllerPresetVisitor { void startLearning(); void stopLearning(); + void slotReloadScripts(double v); + protected: // The length parameter is here for backwards compatibility for when scripts // were required to specify it. @@ -184,6 +188,8 @@ class Controller : public QObject, ConstControllerPresetVisitor { bool m_bLearning; QElapsedTimer m_userActivityInhibitTimer; + parented_ptr m_pReloadScripts; + friend class ControllerJSProxy; // accesses lots of our stuff, but in the same thread friend class ControllerManager; diff --git a/src/controllers/engine/controllerengine.h b/src/controllers/engine/controllerengine.h index af9eed4093e4..73e741318482 100644 --- a/src/controllers/engine/controllerengine.h +++ b/src/controllers/engine/controllerengine.h @@ -51,6 +51,8 @@ class ControllerEngine : public QObject { m_bTesting = testing; }; + void reloadScripts(); + protected: double getValue(QString group, QString name); void setValue(QString group, QString name, double newValue); @@ -115,7 +117,6 @@ class ControllerEngine : public QObject { bool evaluateScriptFile(const QFileInfo& scriptFile); void initializeScriptEngine(); void uninitializeScriptEngine(); - void reloadScripts(); void scriptErrorDialog(const QString& detailedError, const QString& key, bool bFatal = false); void generateScriptFunctions(const QString& code);