ctkHostAppExampleWidget.cpp 2.9 KB

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