ctkHostAppExampleWidget.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 host;
  24. delete ui;
  25. }
  26. void ctkHostAppExampleWidget::startButtonClicked()
  27. {
  28. qDebug() << "start button clicked";
  29. if (host)
  30. {
  31. host->StartApplication(appFileName);
  32. }
  33. }
  34. void ctkHostAppExampleWidget::runButtonClicked()
  35. {
  36. qDebug() << "run button clicked";
  37. if (host)
  38. {
  39. bool reply = host->getDicomAppService()->setState(ctkDicomWG23::INPROGRESS);
  40. qDebug() << " setState(INPROGRESS) returned: " << reply;
  41. }
  42. }
  43. void ctkHostAppExampleWidget::stopButtonClicked()
  44. {
  45. qDebug() << "stop button clicked";
  46. }
  47. void ctkHostAppExampleWidget::loadButtonClicked()
  48. {
  49. qDebug() << "load button clicked";
  50. this->setAppFileName(QFileDialog::getOpenFileName(this,"Choose hosted application",QApplication::applicationDirPath()));
  51. }
  52. void ctkHostAppExampleWidget::setAppFileName(QString name)
  53. {
  54. this->appFileName = name;
  55. if (QFile(this->appFileName).permissions() & QFile::ExeUser )
  56. {
  57. this->ui->applicationPathLabel->setText(this->appFileName);
  58. }
  59. else
  60. {
  61. this->ui->applicationPathLabel->setText(QString("<font color='red'>Not executable:</font>").append(this->appFileName));
  62. }
  63. }
  64. void ctkHostAppExampleWidget::appProcessError(QProcess::ProcessError error)
  65. {
  66. if (error == QProcess::Crashed)
  67. {
  68. qDebug() << "crash detected";
  69. ui->crashLabel->setVisible(true);
  70. }
  71. }
  72. void ctkHostAppExampleWidget::appProcessStateChanged(QProcess::ProcessState state)
  73. {
  74. QString labelText;
  75. switch (state){
  76. case QProcess::Running:
  77. ui->processStateLabel->setText("Running");
  78. break;
  79. case QProcess::NotRunning:
  80. if (host->getAppProcess().exitStatus() == QProcess::CrashExit )
  81. {
  82. labelText = "crashed";
  83. }
  84. else
  85. {
  86. labelText = "Not Running, last exit code ";
  87. labelText.append(QString::number(host->getAppProcess().exitCode()));
  88. }
  89. ui->processStateLabel->setText(labelText);
  90. break;
  91. case QProcess::Starting:
  92. ui->processStateLabel->setText("Starting");
  93. break;
  94. default:
  95. ;
  96. }
  97. }
  98. void ctkHostAppExampleWidget::placeholderResized()
  99. {
  100. qDebug() << "resized";
  101. //ui->placeholderFrame->printPosition();
  102. }