Some changes

Refactor execCMDWithOutput
Add UI for advanced settings
Add stop button(reconnect)
Update translations
This commit is contained in:
wh201906
2021-02-13 23:58:11 +08:00
parent a56a503b23
commit 5330ed8d14
9 changed files with 1046 additions and 319 deletions
+12 -4
View File
@@ -22,13 +22,16 @@ void Util::processOutput(const QString& output)
void Util::execCMD(const QString& cmd)
{
qDebug() << cmd;
qDebug() << "executing: " << cmd;
if(isRunning)
emit write(cmd + "\r\n");
}
QString Util::execCMDWithOutput(const QString& cmd, ReturnTrigger trigger)
{
// if the trigger is empty, this function will wait trigger.waitTime then return all outputs during the wait time.
// otherwise, this function will return empty string if no trigger is detected, or return outputs if any trigger is detected.
// the waitTime will be refreshed if the client have new outputs
bool isResultFound = false;
QRegularExpression re;
re.setPatternOptions(QRegularExpression::DotMatchesEverythingOption);
@@ -42,27 +45,32 @@ QString Util::execCMDWithOutput(const QString& cmd, ReturnTrigger trigger)
execCMD(cmd);
while(QTime::currentTime() < targetTime)
{
if(!isRunning)
break;
QApplication::processEvents();
for(QString otpt : trigger.expectedOutputs)
{
re.setPattern(otpt);
isResultFound = re.match(*requiredOutput).hasMatch();
if(requiredOutput->contains(otpt))
if(isResultFound)
{
qDebug() << "output Matched: " << *requiredOutput;
break;
}
}
if(isResultFound)
{
delay(200);
break;
}
if(timeStamp > currTime)
if(timeStamp > currTime) //has new output
{
currTime = timeStamp;
targetTime = timeStamp.addMSecs(trigger.waitTime);
}
}
isRequiringOutput = false;
return *requiredOutput;
return (isResultFound || trigger.expectedOutputs.isEmpty() ? *requiredOutput : "");
}
void Util::delay(unsigned int msec)
+1
View File
@@ -50,6 +50,7 @@ public:
QString execCMDWithOutput(const QString& cmd, ReturnTrigger trigger = 10000);
void delay(unsigned int msec);
ClientType getClientType();
static const int rawTabIndex = 1;
public slots:
void processOutput(const QString& output);
void setClientType(Util::ClientType clientType);