ctkHostAppExampleWidget.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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->setAppFileName(QFileDialog::getOpenFileName(this,"Choose hosted application",QApplication::applicationDirPath()));
  50. }
  51. void ctkHostAppExampleWidget::setAppFileName(QString name)
  52. {
  53. this->appFileName = name;
  54. if (QFile(this->appFileName).permissions() & QFile::ExeUser )
  55. {
  56. this->ui->applicationPathLabel->setText(this->appFileName);
  57. }
  58. else
  59. {
  60. this->ui->applicationPathLabel->setText(QString("<font color='red'>Not executable:</font>").append(this->appFileName));
  61. }
  62. }
  63. void ctkHostAppExampleWidget::appProcessError(QProcess::ProcessError error)
  64. {
  65. if (error == QProcess::Crashed)
  66. {
  67. qDebug() << "crash detected";
  68. ui->crashLabel->setVisible(true);
  69. }
  70. }
  71. void ctkHostAppExampleWidget::appProcessStateChanged(QProcess::ProcessState state)
  72. {
  73. QString labelText;
  74. switch (state){
  75. case QProcess::Running:
  76. ui->processStateLabel->setText("Running");
  77. break;
  78. case QProcess::NotRunning:
  79. if (host->getAppProcess().exitStatus() == QProcess::CrashExit )
  80. {
  81. labelText = "crashed";
  82. }
  83. else
  84. {
  85. labelText = "Not Running, last exit code ";
  86. labelText.append(QString::number(host->getAppProcess().exitCode()));
  87. }
  88. ui->processStateLabel->setText(labelText);
  89. break;
  90. case QProcess::Starting:
  91. ui->processStateLabel->setText("Starting");
  92. break;
  93. default:
  94. ;
  95. }
  96. }
  97. void ctkHostAppExampleWidget::placeholderResized()
  98. {
  99. qDebug() << "resized";
  100. //ui->placeholderFrame->printPosition();
  101. }