-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathqtmonkey_gui.hpp
100 lines (90 loc) · 2.63 KB
/
qtmonkey_gui.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#pragma once
#include <QWidget>
#include <QtCore/QProcess>
#include <QtCore/QStringList>
#include <QtCore/QTimer>
#include "ui_qtmonkey_gui.h"
class QtMonkeyAppCtrl
#ifndef Q_MOC_RUN
final
#endif
: public QObject
{
Q_OBJECT
signals:
void monkeyAppFinishedSignal(QString msg);
void monkeyAppNewEvent(const QString &scriptLine);
void monkeyUserAppError(const QString &errMsg);
void monkeyScriptEnd();
void monkeScriptLog(const QString &);
void criticalError(const QString &);
public:
explicit QtMonkeyAppCtrl(const QString &appPath, const QStringList &appArgs,
QObject *parent = nullptr);
void runScript(const QString &script,
const QString &scriptFilename = QString());
private slots:
void monkeyAppError(QProcess::ProcessError);
void monkeyAppFinished(int, QProcess::ExitStatus);
void monkeyAppNewOutput();
void monkeyAppNewErrOutput();
private:
QProcess qtmonkeyApp_;
QByteArray jsonFromMonkey_;
};
class QtMonkeyWindow
#ifndef Q_MOC_RUN
final
#endif
: public QWidget,
private Ui::QtMonkeyMainWin
{
Q_OBJECT
public:
QtMonkeyWindow(QWidget *parent = nullptr);
~QtMonkeyWindow();
void setEncoding(QByteArray enc) { encoding_ = std::move(enc); }
private slots:
// auto connection
void on_pbStartRecording__pressed();
void on_leTestApp__textEdited(const QString &text);
void on_leTestAppArgs__textEdited(const QString &text);
void on_pbBrowse__pressed();
void on_pbRunScript__pressed();
void on_pbClearLog__pressed();
void on_cbProtocolRunning__toggled(bool checked);
void on_pbSaveScriptToFile__pressed();
void on_pbLoadScriptFromFile__pressed();
void on_pbSaveScript__pressed();
// manual connection
void onMonkeyAppFinishedSignal(QString);
void savePrefs();
void onMonkeyAppNewEvent(const QString &scriptLine);
void onMonkeyUserAppError(const QString &);
void onMonkeyScriptEnd();
void onMonkeScriptLog(const QString &);
void showError(const QString &msg);
private:
enum class State {
DoNothing,
RecordEvents,
PlayingEvents,
};
enum class MsgType {
Default,
Error,
Protocol,
};
QtMonkeyAppCtrl *monkeyCtrl_ = nullptr;
QTimer savePrefsTimer_;
State state_ = State::DoNothing;
QString scriptDir_;
QByteArray encoding_{"UTF-8"};
QString scriptFileName_;
QtMonkeyAppCtrl *getMonkeyCtrl();
void loadPrefs();
void scheduleSave();
void changeState(State val);
void logNewLine(MsgType, const QString &);
void saveScriptToFile(const QString &fileName);
};