ctkHostAppExampleWidget.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "ctkHostAppExampleWidget.h"
  2. #include "ui_ctkHostAppExampleWidget.h"
  3. #include "ctkDicomExampleHost.h"
  4. #include <QDebug>
  5. #include <QFileDialog>
  6. #include <QProcess>
  7. ctkHostAppExampleWidget::ctkHostAppExampleWidget(QWidget *parent) :
  8. QWidget(parent),
  9. ui(new Ui::ctkHostAppExampleWidget)
  10. {
  11. qDebug() << "setup ui";
  12. ui->setupUi(this);
  13. ui->crashLabel->setVisible(false);
  14. ui->messageOutput->setVisible(false);
  15. this->host = new ctkDicomExampleHost();
  16. connect(&this->host->getAppProcess(),SIGNAL(error(QProcess::ProcessError)),SLOT(appProcessError(QProcess::ProcessError)));
  17. connect(&this->host->getAppProcess(),SIGNAL(stateChanged(QProcess::ProcessState)),SLOT(appProcessStateChanged(QProcess::ProcessState)));
  18. }
  19. ctkHostAppExampleWidget::~ctkHostAppExampleWidget()
  20. {
  21. delete ui;
  22. }
  23. void ctkHostAppExampleWidget::startButtonClicked()
  24. {
  25. qDebug() << "start button clicked";
  26. if (host)
  27. {
  28. host->StartApplication(appFileName);
  29. }
  30. }
  31. void ctkHostAppExampleWidget::stopButtonClicked()
  32. {
  33. qDebug() << "stop button clicked";
  34. }
  35. void ctkHostAppExampleWidget::loadButtonClicked()
  36. {
  37. qDebug() << "load button clicked";
  38. this->appFileName = QFileDialog::getOpenFileName(this,"Choose hosted application",QApplication::applicationDirPath());
  39. if (QFile(this->appFileName).permissions() & QFile::ExeUser )
  40. {
  41. this->ui->applicationPathLabel->setText(this->appFileName);
  42. }
  43. else
  44. {
  45. this->ui->applicationPathLabel->setText(QString("<font color='red'>Not executable:</font>").append(this->appFileName));
  46. }
  47. }
  48. void ctkHostAppExampleWidget::appProcessError(QProcess::ProcessError error)
  49. {
  50. if (error == QProcess::Crashed)
  51. {
  52. qDebug() << "crash detected";
  53. ui->crashLabel->setVisible(true);
  54. }
  55. }
  56. void ctkHostAppExampleWidget::appProcessStateChanged(QProcess::ProcessState state)
  57. {
  58. QString labelText;
  59. switch (state){
  60. case QProcess::Running:
  61. ui->processStateLabel->setText("Running");
  62. break;
  63. case QProcess::NotRunning:
  64. if (host->getAppProcess().exitStatus() == QProcess::CrashExit )
  65. {
  66. labelText = "crashed";
  67. }
  68. else
  69. {
  70. labelText = "Not Running, last exit code ";
  71. labelText.append(QString::number(host->getAppProcess().exitCode()));
  72. }
  73. ui->processStateLabel->setText(labelText);
  74. break;
  75. case QProcess::Starting:
  76. ui->processStateLabel->setText("Starting");
  77. break;
  78. default:
  79. ;
  80. }
  81. }