SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
commandoutputdialog.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #include "commandoutputdialog.h"
19 #include "ui_commandoutputdialog.h"
20 #include "commands/command.h"
21 
22 #include <QDateTime>
23 
25  QDialog(parent),
26  ui(new Ui::CommandOutputDialog),
27  m_command(command)
28 {
29  ui->setupUi(this);
30  refresh();
31 }
32 
34 {
35  delete ui;
36 }
37 
39 {
40  ui->commandText->setText(m_command.getLastProcessCommandLine());
41  ui->processPid->setText(QString("%1").arg(m_command.getLastProcessPid()));
42 
44  ui->startTime->setText(("..."));
45  }
46  else
47  {
48  QDateTime dt = QDateTime::fromMSecsSinceEpoch(m_command.getLastProcessStartTimestampms());
49  QString dateStr = dt.toString("yyyy-MM-dd HH:mm:ss.zzz");
50  ui->startTime->setText(dateStr);
51  }
52 
54  ui->endTime->setText(("..."));
55  }
56  else
57  {
58  QDateTime dt = QDateTime::fromMSecsSinceEpoch(m_command.getLastProcessFinishTimestampms());
59  QString dateStr = dt.toString("yyyy-MM-dd HH:mm:ss.zzz");
60  ui->endTime->setText(dateStr);
61  }
62 
63  ui->runningState->setChecked(m_command.getLastProcessState() == QProcess::Running);
64  QProcess::ProcessError processError;
65 
66  if (m_command.getLastProcessStartTimestampms() == 0) // not started
67  {
68  ui->errorText->setText("...");
69  ui->exitCode->setText("-");
70  ui->exitText->setText("...");
71  ui->runningState->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
72  }
73  else if (m_command.getLastProcessState() != QProcess::NotRunning) // running
74  {
75  ui->errorText->setText("...");
76  ui->runningState->setStyleSheet("QToolButton { background-color : orange; }");
77  }
78  else // finished
79  {
80  if (m_command.getLastProcessError(processError)) // finished
81  {
82  ui->runningState->setStyleSheet("QToolButton { background-color : red; }");
83  setErrorText(processError);
84  }
85  else
86  {
87  ui->runningState->setStyleSheet("QToolButton { background-color : green; }");
88  ui->errorText->setText("No error");
89  }
90 
91  int processExitCode;
92  QProcess::ExitStatus processExitStatus;
93 
94  if (m_command.getLastProcessExit(processExitCode, processExitStatus))
95  {
96  ui->exitCode->setText(QString("%1").arg(processExitCode));
97  setExitText(processExitStatus);
98  }
99  else
100  {
101  ui->exitCode->setText("-");
102  ui->exitText->setText("...");
103  }
104  }
105 
106  ui->logEdit->setPlainText(m_command.getLastProcessLog());
107 }
108 
109 void CommandOutputDialog::setErrorText(const QProcess::ProcessError& processError)
110 {
111  switch(processError)
112  {
113  case QProcess::FailedToStart:
114  ui->errorText->setText("Failed to start");
115  break;
116  case QProcess::Crashed:
117  ui->errorText->setText("Crashed");
118  break;
119  case QProcess::Timedout:
120  ui->errorText->setText("Timed out");
121  break;
122  case QProcess::WriteError:
123  ui->errorText->setText("Write error");
124  break;
125  case QProcess::ReadError:
126  ui->errorText->setText("Read error");
127  break;
128  case QProcess::UnknownError:
129  default:
130  ui->errorText->setText("Unknown error");
131  break;
132  }
133 }
134 
135 void CommandOutputDialog::setExitText(const QProcess::ExitStatus& processExit)
136 {
137  switch(processExit)
138  {
139  case QProcess::NormalExit:
140  ui->exitText->setText("Normal exit");
141  break;
142  case QProcess::CrashExit:
143  ui->exitText->setText("Program crashed");
144  break;
145  default:
146  ui->exitText->setText("Unknown state");
147  break;
148  }
149 }
150 
152 {
153  if (checked)
154  {
155  refresh();
156  ui->processRefresh->setChecked(false);
157  }
158 }
159 
161 {
162  if (checked)
163  {
164  m_command.kill();
165  ui->processKill->setChecked(false);
166  }
167 }
168 
void on_processKill_toggled(bool checked)
void setErrorText(const QProcess::ProcessError &processError)
QProcess::ProcessState getLastProcessState() const
Definition: command.cpp:218
uint64_t getLastProcessFinishTimestampms() const
Definition: command.h:68
const QString & getLastProcessCommandLine() const
Definition: command.h:69
void kill()
Definition: command.cpp:209
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
qint64 getLastProcessPid() const
Definition: command.h:70
uint64_t getLastProcessStartTimestampms() const
Definition: command.h:67
const QString & getLastProcessLog() const
Definition: command.cpp:243
void on_processRefresh_toggled(bool checked)
void setExitText(const QProcess::ExitStatus &processExit)
Ui::CommandOutputDialog * ui
CommandOutputDialog(Command &command, QWidget *parent=0)
bool getLastProcessError(QProcess::ProcessError &error) const
Definition: command.cpp:223
bool getLastProcessExit(int &exitCode, QProcess::ExitStatus &exitStatus) const
Definition: command.cpp:232