-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBeaconCommandlineProgram.hpp
115 lines (110 loc) · 4.06 KB
/
BeaconCommandlineProgram.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef BF_COMMANDLINEPROGRAM
#define BF_COMMANDLINEPROGRAM
#define BF_COMMANDLINEPROGRAMVERSION "1.0.0"
#include <QObject>
#include <QDebug>
#include <QDir>
#include "BeaconExternalProgram.hpp"
#include "BeaconPlatformInfo.hpp"
class BeaconCommandlineProgram : public BeaconExternalProgram
{
Q_OBJECT
public:
explicit BeaconCommandlineProgram(QString platform=QString("auto"))
{
if(platform=="auto"){
if(BeaconPlatformInfo::isWindows())platform=QString("windows");
else if(BeaconPlatformInfo::isMacos())platform=QString("macos");
else if(BeaconPlatformInfo::isLinux())platform=QString("linux");
}
if(platform=="windows"){
//qDebug() << "Current Directory:" << QDir::
if(QFile::exists("./ConEmu/ConEmu64.exe")){
bashBased=true;
setProgram("./ConEmu/ConEmu64.exe");
prefixArgument << "-run";
}
setProgram("cmd");
prefixArgument << "/k";
}
else if(platform=="macos"){
setProgram("open");
}
else if(platform=="linux"){
//yakuake&guake not supported
//liri not supported
if(QFile::exists("/usr/bin/konsole")){
bashBased=true;
setProgram("konsole");
prefixArgument << "--noclose" << "-e" ;
prefixArgument << "bash" << "-c";
}
else if(QFile::exists("/usr/bin/gnome-terminal")){
bashBased=true;
manualHalt=true;
prefixArgument << "--" << "bash" << "-c";
setProgram("gnome-terminal");
}
else if(QFile::exists("/usr/bin/mate-terminal")){
bashBased=true;
manualHalt=true;
prefixArgument << "--" << "bash" << "-c";
setProgram("mate-terminal");
}
else if(QFile::exists("/usr/bin/deepin-terminal")){
bashBased=true;
manualHalt=true;
prefixArgument << "-e" << "bash" << "-c";
setProgram("deepin-terminal");
}
else if(QFile::exists("/usr/bin/xfce4-terminal")){
bashBased=true;
manualHalt=true;
prefixArgument << "-x" << "bash" << "-c";
setProgram("xfce4-terminal");
}
else if(QFile::exists("/usr/bin/lxterminal")){
bashBased=true;
manualHalt=true;
prefixArgument << "-e" << "bash" << "-c";
setProgram("lxterminal");
}
else if(QFile::exists("/usr/bin/uxterm")){
bashBased=true;
manualHalt=true;
prefixArgument << "-e" << "bash" << "-c";
setProgram("uxterm");
}
else if(QFile::exists("/usr/bin/xterm")){
bashBased=true;
manualHalt=true;
prefixArgument << "-e" << "bash" << "-c";
setProgram("xterm");
}
//else
}
}
void setArguments(QStringList arg)
{
QString t=arg.first();
QStringList pathL=t.split("/");
pathL.removeLast();
QString path=pathL.join("/");
this->program.setWorkingDirectory(path);
QStringList arguments=prefixArgument;
if(bashBased){
QString mid;
if(manualHalt)mid = QString("""%1;echo \"\n------Program Exited------\";sleep 2147483647""").arg(arg.first());
else mid = QString("""%1;echo \"\n------Program Exited------\"").arg(arg.first());
arguments.append(mid);
}
else arguments.append(arg);
//arguments.append(suffixArgument);
this->program.setArguments(arguments);
}
QStringList prefixArgument;
QStringList suffixArgument;
bool bashBased=false;
bool manualHalt=false;
};
#endif // BF_COMMANDLINEPROGRAM