-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogtext.h
75 lines (66 loc) · 1.94 KB
/
logtext.h
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
#ifndef LOGTEXT_H
#define LOGTEXT_H
#include <QObject>
#include <QProcess>
#include <QDebug>
#include <QThread>
#include <QEventLoop>
class LogText : public QObject
{
Q_OBJECT
public:
explicit LogText(QObject *parent = 0);
Q_PROPERTY(QString logText MEMBER m_logText NOTIFY logTextChanged)
Q_PROPERTY(QString sText MEMBER m_sText NOTIFY sTextChanged)
Q_PROPERTY(int wPort MEMBER m_wport NOTIFY wPortChanged)
Q_INVOKABLE void start();
Q_INVOKABLE void stop(bool restart);
Q_INVOKABLE void configHasChanged();
signals:
void logTextChanged();
void sTextChanged();
void wPortChanged();
public slots:
void started() {
running = true;
QString status = "<span style=\"color: green;font-weight: bold;\">running</span>";
m_sText = status;
emit sTextChanged();
}
void finished(int,QProcess::ExitStatus) {
m_logText += "</table>";
m_sText = "<span style=\"color: red;font-weight: bold;\">off</span>";
running = false;
if(restart) {
start();
restart = false;
}
emit sTextChanged();
emit logTextChanged();
}
void readyRead() {
//qDebug() << p.readAll();
// qDebug() << "readyRead";
auto text = p.readAll();
auto t2 = text;
if(t2.contains("binding websocket to")) {
auto segments = t2.split(' ');
for(int i = 0; i < segments.size() - 2; i++) {
if(segments[i] == "websocket" && segments[i + 1] == "to") {
m_wport = segments[i + 2].toInt();
emit wPortChanged();
}
}
}
m_logText += text;
emit logTextChanged();
}
private:
QString m_sText = "<span style=\"color: red;font-weight: bold;\">off</span>";
QString m_logText = "";
QProcess p;
int m_wport;
bool running = false;
bool restart = false;
};
#endif // LOGTEXT_H