ctkHostAppExampleWidget.cpp 3.3 KB

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