14 changed files with 807 additions and 9 deletions
Binary file not shown.
@ -0,0 +1,160 @@
@@ -0,0 +1,160 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "commandoutputdialog.h" |
||||
#include "ui_commandoutputdialog.h" |
||||
#include "commands/command.h" |
||||
|
||||
#include <QDateTime> |
||||
|
||||
CommandOutputDialog::CommandOutputDialog(Command& command, QWidget* parent) : |
||||
QDialog(parent), |
||||
ui(new Ui::CommandOutputDialog), |
||||
m_command(command) |
||||
{ |
||||
ui->setupUi(this); |
||||
refresh(); |
||||
} |
||||
|
||||
CommandOutputDialog::~CommandOutputDialog() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
void CommandOutputDialog::refresh() |
||||
{ |
||||
ui->commandText->setText(m_command.getLastProcessCommandLine()); |
||||
ui->processPid->setText(QString("%1").arg(m_command.getLastProcessPid())); |
||||
|
||||
if (m_command.getLastProcessStartTimestamp().tv_sec == 0) { |
||||
ui->startTime->setText(("...")); |
||||
} |
||||
else |
||||
{ |
||||
struct timeval tv = m_command.getLastProcessStartTimestamp(); |
||||
QDateTime dt = QDateTime::fromMSecsSinceEpoch(tv.tv_sec * 1000LL + tv.tv_usec / 1000LL); |
||||
QString dateStr = dt.toString("yyyy-MM-dd hh:mm:ss.zzz"); |
||||
ui->startTime->setText(dateStr); |
||||
} |
||||
|
||||
if (m_command.getLastProcessFinishTimestamp().tv_sec == 0) { |
||||
ui->endTime->setText(("...")); |
||||
} |
||||
else |
||||
{ |
||||
struct timeval tv = m_command.getLastProcessFinishTimestamp(); |
||||
QDateTime dt = QDateTime::fromMSecsSinceEpoch(tv.tv_sec * 1000LL + tv.tv_usec / 1000LL); |
||||
QString dateStr = dt.toString("yyyy-MM-dd hh:mm:ss.zzz"); |
||||
ui->endTime->setText(dateStr); |
||||
} |
||||
|
||||
ui->runningState->setChecked(m_command.getLastProcessState() == QProcess::Running); |
||||
QProcess::ProcessError processError; |
||||
|
||||
if (m_command.getLastProcessStartTimestamp().tv_sec == 0) |
||||
{ |
||||
ui->errorText->setText("..."); |
||||
ui->exitCode->setText("-"); |
||||
ui->exitText->setText("..."); |
||||
ui->runningState->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); |
||||
} |
||||
else if (m_command.getLastProcessState() != QProcess::NotRunning) |
||||
{ |
||||
ui->errorText->setText("..."); |
||||
ui->runningState->setStyleSheet("QToolButton { background-color : blue; }"); |
||||
} |
||||
else if (m_command.getLastProcessError(processError)) |
||||
{ |
||||
ui->runningState->setStyleSheet("QToolButton { background-color : red; }"); |
||||
setErrorText(processError); |
||||
ui->exitCode->setText("-"); |
||||
ui->exitText->setText("..."); |
||||
} |
||||
else |
||||
{ |
||||
ui->runningState->setStyleSheet("QToolButton { background-color : green; }"); |
||||
ui->errorText->setText("No error"); |
||||
|
||||
int processExitCode; |
||||
QProcess::ExitStatus processExitStatus; |
||||
|
||||
if (m_command.getLastProcessTermination(processExitCode, processExitStatus)) |
||||
{ |
||||
ui->exitCode->setText(QString("%1").arg(processExitCode)); |
||||
setExitText(processExitStatus); |
||||
} |
||||
else |
||||
{ |
||||
ui->exitCode->setText("-"); |
||||
ui->exitText->setText("..."); |
||||
} |
||||
} |
||||
|
||||
ui->logEdit->setPlainText(m_command.getLastProcessLog()); |
||||
} |
||||
|
||||
void CommandOutputDialog::setErrorText(const QProcess::ProcessError& processError) |
||||
{ |
||||
switch(processError) |
||||
{ |
||||
case QProcess::FailedToStart: |
||||
ui->errorText->setText("Failed to start"); |
||||
break; |
||||
case QProcess::Crashed: |
||||
ui->errorText->setText("Crashed"); |
||||
break; |
||||
case QProcess::Timedout: |
||||
ui->errorText->setText("Timed out"); |
||||
break; |
||||
case QProcess::WriteError: |
||||
ui->errorText->setText("Write error"); |
||||
break; |
||||
case QProcess::ReadError: |
||||
ui->errorText->setText("Read error"); |
||||
break; |
||||
case QProcess::UnknownError: |
||||
default: |
||||
ui->errorText->setText("Unknown error"); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
void CommandOutputDialog::setExitText(const QProcess::ExitStatus& processExit) |
||||
{ |
||||
switch(processExit) |
||||
{ |
||||
case QProcess::NormalExit: |
||||
ui->exitText->setText("Normal exit"); |
||||
break; |
||||
case QProcess::CrashExit: |
||||
ui->exitText->setText("Program crashed"); |
||||
break; |
||||
default: |
||||
ui->exitText->setText("Unknown state"); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
void CommandOutputDialog::on_processRefresh_toggled(bool checked __attribute__((unused))) |
||||
{ |
||||
refresh(); |
||||
} |
||||
|
||||
void CommandOutputDialog::on_processKill_toggled(bool checked __attribute__((unused))) |
||||
{ |
||||
m_command.kill(); |
||||
} |
||||
|
||||
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation as version 3 of the License, or //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License V3 for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SDRGUI_GUI_COMMANDOUTPUTDIALOG_H_ |
||||
#define SDRGUI_GUI_COMMANDOUTPUTDIALOG_H_ |
||||
|
||||
#include <QDialog> |
||||
#include <QProcess> |
||||
|
||||
namespace Ui { |
||||
class CommandOutputDialog; |
||||
} |
||||
|
||||
class Command; |
||||
|
||||
class CommandOutputDialog : public QDialog { |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit CommandOutputDialog(Command& command, QWidget* parent = 0); |
||||
~CommandOutputDialog(); |
||||
|
||||
void fromCommand(const Command& command); |
||||
|
||||
private: |
||||
Ui::CommandOutputDialog* ui; |
||||
Command& m_command; |
||||
|
||||
void refresh(); |
||||
void setErrorText(const QProcess::ProcessError& processError); |
||||
void setExitText(const QProcess::ExitStatus& processExit); |
||||
|
||||
private slots: |
||||
void on_processRefresh_toggled(bool checked); |
||||
void on_processKill_toggled(bool checked); |
||||
}; |
||||
|
||||
|
||||
#endif /* SDRGUI_GUI_COMMANDOUTPUTDIALOG_H_ */ |
||||
@ -0,0 +1,332 @@
@@ -0,0 +1,332 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>CommandOutputDialog</class> |
||||
<widget class="QDialog" name="CommandOutputDialog"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>547</width> |
||||
<height>380</height> |
||||
</rect> |
||||
</property> |
||||
<property name="font"> |
||||
<font> |
||||
<family>Sans Serif</family> |
||||
<pointsize>9</pointsize> |
||||
</font> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Command output</string> |
||||
</property> |
||||
<layout class="QVBoxLayout" name="verticalLayout"> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="processLayout"> |
||||
<item> |
||||
<widget class="QToolButton" name="runningState"> |
||||
<property name="enabled"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Running state icon</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string/> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset resource="../resources/res.qrc"> |
||||
<normaloff>:/stop.png</normaloff> |
||||
<normalon>:/play.png</normalon>:/stop.png</iconset> |
||||
</property> |
||||
<property name="checkable"> |
||||
<bool>true</bool> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QToolButton" name="processRefresh"> |
||||
<property name="toolTip"> |
||||
<string>Refresh data</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string/> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset resource="../resources/res.qrc"> |
||||
<normaloff>:/recycle.png</normaloff>:/recycle.png</iconset> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="startTime"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>146</width> |
||||
<height>0</height> |
||||
</size> |
||||
</property> |
||||
<property name="font"> |
||||
<font> |
||||
<pointsize>8</pointsize> |
||||
</font> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Start time of last execution</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>2015-01-01 00:00:00.000</string> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="timeMidLabel"> |
||||
<property name="text"> |
||||
<string>-</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="endTime"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>146</width> |
||||
<height>0</height> |
||||
</size> |
||||
</property> |
||||
<property name="font"> |
||||
<font> |
||||
<pointsize>8</pointsize> |
||||
</font> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>End time of last execution</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>2015-01-01 00:00:00.000</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="processPid"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>32</width> |
||||
<height>0</height> |
||||
</size> |
||||
</property> |
||||
<property name="font"> |
||||
<font> |
||||
<pointsize>8</pointsize> |
||||
</font> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Process PID</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>00000</string> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<spacer name="horizontalSpacer"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="sizeHint" stdset="0"> |
||||
<size> |
||||
<width>40</width> |
||||
<height>20</height> |
||||
</size> |
||||
</property> |
||||
</spacer> |
||||
</item> |
||||
<item> |
||||
<widget class="QToolButton" name="processKill"> |
||||
<property name="toolTip"> |
||||
<string>Kill the process (SIGKILL)</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string/> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset resource="../resources/res.qrc"> |
||||
<normaloff>:/kill.png</normaloff>:/kill.png</iconset> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="commandLayout"> |
||||
<item> |
||||
<widget class="QLabel" name="commandLabel"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>0</width> |
||||
<height>23</height> |
||||
</size> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Cmd:</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLineEdit" name="commandText"> |
||||
<property name="enabled"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Command that was executed</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="errorExitLayout"> |
||||
<item> |
||||
<widget class="QLabel" name="errorLabel"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>0</width> |
||||
<height>23</height> |
||||
</size> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Error:</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="errorText"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Process error status</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>...</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="exitLabel"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>30</width> |
||||
<height>23</height> |
||||
</size> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Exit:</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="exitCode"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Return code</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>0</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="exitText"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Process exit status</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>...</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<widget class="QPlainTextEdit" name="logEdit"> |
||||
<property name="enabled"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Output log (stdout + stderr)</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QDialogButtonBox" name="buttonBox"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="standardButtons"> |
||||
<set>QDialogButtonBox::Close</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<tabstops> |
||||
<tabstop>buttonBox</tabstop> |
||||
</tabstops> |
||||
<resources> |
||||
<include location="../resources/res.qrc"/> |
||||
</resources> |
||||
<connections> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>accepted()</signal> |
||||
<receiver>CommandOutputDialog</receiver> |
||||
<slot>accept()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>257</x> |
||||
<y>194</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>157</x> |
||||
<y>203</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>rejected()</signal> |
||||
<receiver>CommandOutputDialog</receiver> |
||||
<slot>reject()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>314</x> |
||||
<y>194</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>286</x> |
||||
<y>203</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
</connections> |
||||
</ui> |
||||
|
After Width: | Height: | Size: 673 B |
Loading…
Reference in new issue