| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-19 13:31:45 +01:00
										 |  |  | // Copyright (C) 2018-2019 Edouard Griffiths, F4EXB <f4exb06@gmail.com>          //
 | 
					
						
							|  |  |  | // Copyright (C) 2018 beta-tester <alpha-beta-release@gmx.net>                   //
 | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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                  //
 | 
					
						
							| 
									
										
										
										
											2019-04-11 14:43:33 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-06 12:11:49 +00:00
										 |  |  | #if QT_CONFIG(process)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  | 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())); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 15:05:14 +01:00
										 |  |  |     if (m_command.getLastProcessStartTimestampms() == 0) { | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  |         ui->startTime->setText(("...")); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-11-12 15:05:14 +01:00
										 |  |  |         QDateTime dt = QDateTime::fromMSecsSinceEpoch(m_command.getLastProcessStartTimestampms()); | 
					
						
							| 
									
										
										
										
											2018-05-11 11:00:08 +02:00
										 |  |  |         QString dateStr = dt.toString("yyyy-MM-dd HH:mm:ss.zzz"); | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  |         ui->startTime->setText(dateStr); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 15:05:14 +01:00
										 |  |  |     if (m_command.getLastProcessFinishTimestampms() == 0) { | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  |         ui->endTime->setText(("...")); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-11-12 15:05:14 +01:00
										 |  |  |         QDateTime dt = QDateTime::fromMSecsSinceEpoch(m_command.getLastProcessFinishTimestampms()); | 
					
						
							| 
									
										
										
										
											2018-05-11 11:00:08 +02:00
										 |  |  |         QString dateStr = dt.toString("yyyy-MM-dd HH:mm:ss.zzz"); | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  |         ui->endTime->setText(dateStr); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ui->runningState->setChecked(m_command.getLastProcessState() == QProcess::Running); | 
					
						
							|  |  |  |     QProcess::ProcessError processError; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 15:05:14 +01:00
										 |  |  |     if (m_command.getLastProcessStartTimestampms() == 0) // not started
 | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         ui->errorText->setText("..."); | 
					
						
							|  |  |  |         ui->exitCode->setText("-"); | 
					
						
							|  |  |  |         ui->exitText->setText("..."); | 
					
						
							|  |  |  |         ui->runningState->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-04 23:10:05 +01:00
										 |  |  |     else if (m_command.getLastProcessState() != QProcess::NotRunning) // running
 | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         ui->errorText->setText("..."); | 
					
						
							| 
									
										
										
										
											2018-01-04 23:10:05 +01:00
										 |  |  |         ui->runningState->setStyleSheet("QToolButton { background-color : orange; }"); | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-04 23:10:05 +01:00
										 |  |  |     else // finished
 | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-01-04 23:10:05 +01:00
										 |  |  |         if (m_command.getLastProcessError(processError)) // finished
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             ui->runningState->setStyleSheet("QToolButton { background-color : red; }"); | 
					
						
							|  |  |  |             setErrorText(processError); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             ui->runningState->setStyleSheet("QToolButton { background-color : green; }"); | 
					
						
							|  |  |  |             ui->errorText->setText("No error"); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         int processExitCode; | 
					
						
							|  |  |  |         QProcess::ExitStatus processExitStatus; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-04 23:10:05 +01:00
										 |  |  |         if (m_command.getLastProcessExit(processExitCode, processExitStatus)) | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             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; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-04 23:10:05 +01:00
										 |  |  | void CommandOutputDialog::on_processRefresh_toggled(bool checked) | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-01-04 23:10:05 +01:00
										 |  |  |     if (checked) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         refresh(); | 
					
						
							|  |  |  |         ui->processRefresh->setChecked(false); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-04 23:10:05 +01:00
										 |  |  | void CommandOutputDialog::on_processKill_toggled(bool checked) | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-01-04 23:10:05 +01:00
										 |  |  |     if (checked) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_command.kill(); | 
					
						
							|  |  |  |         ui->processKill->setChecked(false); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-01-04 20:15:33 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-06 12:11:49 +00:00
										 |  |  | #endif // QT_CONFIG(process)
 |