2023-07-01 17:54:53 +01:00
|
|
|
#pragma once
|
|
|
|
#include <QThread>
|
|
|
|
#include <QJSEngine>
|
|
|
|
#include "../../QSbieAPI/SbieAPI.h"
|
|
|
|
|
|
|
|
#include "JSEngineExt.h"
|
|
|
|
|
|
|
|
class CBoxEngine : public QThread
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
CBoxEngine(QObject* parent = NULL);
|
|
|
|
~CBoxEngine();
|
|
|
|
|
2023-07-08 10:46:29 +01:00
|
|
|
bool RunScript(const QString& Script, const QString& Name, const QVariantMap& Params = QVariantMap());
|
2023-07-01 17:54:53 +01:00
|
|
|
|
2023-07-22 09:10:22 +01:00
|
|
|
static void StopAll();
|
|
|
|
|
2023-07-01 17:54:53 +01:00
|
|
|
enum EState {
|
|
|
|
eUnknown,
|
|
|
|
|
|
|
|
eRunning,
|
|
|
|
eRunningAsync,
|
|
|
|
eReady,
|
|
|
|
eQuery,
|
|
|
|
|
|
|
|
eCompleted,
|
|
|
|
eSuccess,
|
|
|
|
eFailed,
|
|
|
|
eError,
|
|
|
|
eCanceled
|
|
|
|
};
|
|
|
|
|
|
|
|
EState GetState() const { return m_State; }
|
|
|
|
|
|
|
|
bool IsRunning() const { return m_State == eRunning || m_State == eRunningAsync; }
|
|
|
|
bool Continue() { return Continue(false); }
|
|
|
|
|
|
|
|
bool HasFailed() const { return m_State == eFailed; }
|
|
|
|
bool HasError() const { return m_State == eError; }
|
2023-07-08 10:46:29 +01:00
|
|
|
bool WasSuccessfull() const { return m_State == eSuccess; }
|
2023-07-01 17:54:53 +01:00
|
|
|
|
|
|
|
bool IsReady() const { return m_State == eReady; }
|
|
|
|
bool HasQuery() const { return m_State == eQuery; }
|
|
|
|
QVariantMap GetQuery() const { QMutexLocker Locker(&m_Mutex); return m_State == eQuery ? m_Data : QVariantMap(); }
|
|
|
|
bool SetResult(const QVariantMap& Result);
|
|
|
|
QVariant GetResult() const { return m_Result; }
|
|
|
|
|
2023-07-08 10:46:29 +01:00
|
|
|
Q_INVOKABLE void AppendLog(const QString& Line);
|
2023-07-01 17:54:53 +01:00
|
|
|
//QString GetLog() const { QMutexLocker Locker(&m_Mutex); return m_Log; }
|
|
|
|
|
2023-07-08 10:46:29 +01:00
|
|
|
CJSEngineExt* GetEngine() { return m_pEngine; }
|
|
|
|
|
2023-07-01 17:54:53 +01:00
|
|
|
QObject* GetDebuggerBackend();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
void StateChanged(int state, const QString& Text = "");
|
|
|
|
|
|
|
|
void BoxUsed(const CSandBoxPtr& pBox);
|
|
|
|
|
|
|
|
void LogMessage(const QString& Line);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class JSysObject;
|
|
|
|
friend class JSbieObject;
|
|
|
|
friend class JIniObject;
|
|
|
|
friend class JConfObject;
|
|
|
|
friend class JBoxObject;
|
|
|
|
friend class JBoxWObject;
|
|
|
|
|
|
|
|
virtual void init();
|
|
|
|
virtual void run();
|
2023-07-22 09:10:22 +01:00
|
|
|
virtual void Stop();
|
2023-07-01 17:54:53 +01:00
|
|
|
//virtual bool Wait();
|
|
|
|
virtual bool Continue(bool bLocked, EState State = eRunning);
|
|
|
|
|
|
|
|
virtual void SetState(EState state, const QString& Text = "");
|
|
|
|
bool TestRunning();
|
|
|
|
bool WaitLocked();
|
|
|
|
|
|
|
|
CJSEngineExt* m_pEngine;
|
|
|
|
QObject* m_pDebuggerBackend;
|
|
|
|
QString m_Script;
|
|
|
|
QString m_Name;
|
2023-07-08 10:46:29 +01:00
|
|
|
QVariantMap m_Params;
|
2023-07-01 17:54:53 +01:00
|
|
|
QVariant m_Result;
|
|
|
|
|
|
|
|
mutable QMutex m_Mutex;
|
|
|
|
QWaitCondition m_Wait;
|
|
|
|
QVariantMap m_Data;
|
|
|
|
EState m_State;
|
|
|
|
|
|
|
|
//QString m_Log;
|
|
|
|
|
2023-07-22 09:10:22 +01:00
|
|
|
static QSet<CBoxEngine*> m_Instances;
|
2023-07-01 17:54:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CWizardEngine
|
|
|
|
//
|
|
|
|
|
|
|
|
class CWizardEngine : public CBoxEngine
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
CWizardEngine(QObject* parent = NULL);
|
|
|
|
~CWizardEngine();
|
|
|
|
|
|
|
|
QVariantMap GetReport() { return m_Report; }
|
|
|
|
|
|
|
|
bool ApplyShadowChanges();
|
|
|
|
|
|
|
|
QSharedPointer<CSbieIni> MakeShadow(const QSharedPointer<CSbieIni>& pIni);
|
|
|
|
void AddShadow(const QSharedPointer<CSbieIni>& pIni);
|
|
|
|
void SetApplyShadow(const QString& OriginalName, bool bApply = true);
|
|
|
|
bool IsNoAppliedShadow(const QString& OriginalName);
|
|
|
|
|
2023-07-22 09:10:22 +01:00
|
|
|
static int GetInstanceCount() { return m_InstanceCount; }
|
2023-07-08 10:46:29 +01:00
|
|
|
|
|
|
|
Q_INVOKABLE void OpenSettings(const QString& page);
|
|
|
|
Q_INVOKABLE void OpenOptions(const QString& box, const QString& page);
|
|
|
|
|
2023-07-01 17:54:53 +01:00
|
|
|
protected:
|
|
|
|
friend class JWizardObject;
|
|
|
|
|
|
|
|
virtual void init();
|
|
|
|
|
|
|
|
virtual void SetState(EState state, const QString& Text = "");
|
|
|
|
|
|
|
|
QVariantMap m_Report;
|
|
|
|
|
|
|
|
struct SBoxShadow {
|
|
|
|
SBoxShadow() : iApplyChanges(0) {}
|
|
|
|
QSharedPointer<CSbieIni> pShadow;
|
|
|
|
QSharedPointer<CSbieIni> pOriginal;
|
|
|
|
int iApplyChanges;
|
|
|
|
};
|
|
|
|
|
|
|
|
QMap<QString, SBoxShadow> m_Shadows;
|
2023-07-22 09:10:22 +01:00
|
|
|
|
|
|
|
static int m_InstanceCount;
|
2023-07-01 17:54:53 +01:00
|
|
|
};
|
|
|
|
|