-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommand.cpp
71 lines (56 loc) · 1.67 KB
/
command.cpp
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
#include "command.h"
#include <QString>
#include <QProcess>
#include <QDebug>
#include <QStringList>
#include "service.h"
const char* Command::CMD_LIST = "l";
const char* Command::CMD_LIST_RUNNING = "lr";
const char* Command::CMD_LIST_STOPED = "ls";
const char* Command::CMD_RENAME = "r";
const QString Command::HEAD_TABLE = "[ ID ] [ STATUS ] [ NAME ]\n";
Command::Command()
{
}
QString Command::list(){
QProcess pingProcess;
pingProcess.start(SERVICE_EXE" --status-all");
pingProcess.waitForFinished();
QString output(pingProcess.readAllStandardOutput());
output.replace("[ + ]","\033[1;42m[ + ]\033[0m");
output.replace("[ - ]","\033[1;41m[ - ]\033[0m");
return output;
}
QString Command::listClean(){
QProcess pingProcess;
pingProcess.start(SERVICE_EXE" --status-all");
pingProcess.waitForFinished();
QString output(pingProcess.readAllStandardOutput());
output.replace("[ + ]","");
output.replace("[ - ]","");
output.replace(" ","");
return output;
}
QString Command::listRunning(){
QString output= this->list();
QStringList list = output.split('\n', QString::SkipEmptyParts);
QString result=this->HEAD_TABLE;
foreach (const QString &str, list) {
if (str.contains("[ + ]"))
result += str+"\n";
}
return result;
}
QString Command::listStoped(){
QString output= this->list();
QStringList list = output.split('\n', QString::SkipEmptyParts);
QString result=this->HEAD_TABLE;
foreach (const QString &str, list) {
if (str.contains("[ - ]"))
result += str+"\n";
}
return result;
}
QString Command::rename(QString service,QString name){
return "";
}