Skip to content

Commit

Permalink
controllers: Add CO to reload scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Jun 18, 2020
1 parent 1ba9748 commit 31d346f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/controllers/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* @brief Base class representing a physical (or software) controller.
*/

#include "controllers/controller.h"

#include <QApplication>
#include <QJSValue>

#include "controllers/controller.h"
#include "control/controlobject.h"
#include "controllers/controllerdebug.h"
#include "controllers/defs_controllers.h"
#include "util/screensaver.h"
Expand All @@ -21,6 +23,9 @@ Controller::Controller(const QString& group)
m_bIsOpen(false),
m_bLearning(false) {
m_userActivityInhibitTimer.start();

m_pReloadScripts = make_parented<ControlObject>(ConfigKey(group, "reload_scripts"), this);
connect(m_pReloadScripts, &ControlObject::valueChanged, this, &Controller::slotReloadScripts);
}

Controller::~Controller() {
Expand Down Expand Up @@ -88,6 +93,14 @@ void Controller::stopLearning() {

}

void Controller::slotReloadScripts(double v) {
if (!v || !m_pEngine) {
return;
}

m_pEngine->reloadScripts();
}

void Controller::send(QList<int> 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)
Expand Down
6 changes: 6 additions & 0 deletions src/controllers/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -184,6 +188,8 @@ class Controller : public QObject, ConstControllerPresetVisitor {
bool m_bLearning;
QElapsedTimer m_userActivityInhibitTimer;

parented_ptr<ControlObject> m_pReloadScripts;

friend class ControllerJSProxy;
// accesses lots of our stuff, but in the same thread
friend class ControllerManager;
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/engine/controllerengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 31d346f

Please sign in to comment.