ctkHostAppExampleWidget.cpp 2.6 KB

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