Procházet zdrojové kódy

CHG: keep track of the state of the hosted application process and display it in GUI

Marco Nolden před 15 roky
rodič
revize
0c253fc3b3

+ 30 - 1
Applications/ctkExampleHost/ctkHostAppExampleWidget.cpp

@@ -4,6 +4,7 @@
 
 #include <QDebug>
 #include <QFileDialog>
+#include <QProcess>
 
 ctkHostAppExampleWidget::ctkHostAppExampleWidget(QWidget *parent) :
     QWidget(parent),
@@ -11,8 +12,11 @@ ctkHostAppExampleWidget::ctkHostAppExampleWidget(QWidget *parent) :
 {
     qDebug() << "setup ui";
     ui->setupUi(this);
+    ui->crashLabel->setVisible(false);
+    ui->messageOutput->setVisible(false);
     this->host = new ctkDicomExampleHost();
-
+    connect(&this->host->getAppProcess(),SIGNAL(error(QProcess::ProcessError)),SLOT(appProcessError(QProcess::ProcessError)));
+    connect(&this->host->getAppProcess(),SIGNAL(stateChanged(QProcess::ProcessState)),SLOT(appProcessStateChanged(QProcess::ProcessState)));
   }
 
 
@@ -48,3 +52,28 @@ void ctkHostAppExampleWidget::loadButtonClicked()
       this->ui->applicationPathLabel->setText(QString("<font color='red'>Not executable:</font>").append(this->appFileName));
     }
 }
+void ctkHostAppExampleWidget::appProcessError(QProcess::ProcessError error)
+{
+  if (error == QProcess::Crashed)
+  {
+    qDebug() << "crash detected";
+    ui->crashLabel->setVisible(true);
+  }
+  }
+
+void ctkHostAppExampleWidget::appProcessStateChanged(QProcess::ProcessState state)
+{
+  switch (state){
+  case QProcess::Running:
+    ui->processStateLabel->setText("Running");
+    break;
+  case QProcess::NotRunning:
+    ui->processStateLabel->setText("Not Running");
+    break;
+  case QProcess::Starting:
+    ui->processStateLabel->setText("Starting");
+    break;
+  default:
+    ;
+  }
+  }

+ 5 - 0
Applications/ctkExampleHost/ctkHostAppExampleWidget.h

@@ -2,6 +2,8 @@
 #define CTKHOSTAPPEXAMPLEWIDGET_H
 
 #include <QWidget>
+#include <QProcess>
+
 
 class ctkDicomExampleHost;
 
@@ -20,6 +22,9 @@ public slots:
     void startButtonClicked();
     void stopButtonClicked();
     void loadButtonClicked();
+    void appProcessError(QProcess::ProcessError error);
+    void appProcessStateChanged(QProcess::ProcessState state);
+
 protected:
     ctkDicomExampleHost* host;
     QString appFileName;

+ 77 - 1
Applications/ctkExampleHost/ctkHostAppExampleWidget.ui

@@ -74,7 +74,7 @@
      <item>
       <widget class="QLabel" name="label">
        <property name="text">
-        <string>Status:</string>
+        <string>Plugin Status:</string>
        </property>
       </widget>
      </item>
@@ -92,6 +92,26 @@
       </widget>
      </item>
      <item>
+      <widget class="QLabel" name="label_3">
+       <property name="text">
+        <string>Process Status:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLabel" name="processStateLabel">
+       <property name="font">
+        <font>
+         <weight>75</weight>
+         <bold>true</bold>
+        </font>
+       </property>
+       <property name="text">
+        <string>Not running</string>
+       </property>
+      </widget>
+     </item>
+     <item>
       <spacer name="horizontalSpacer">
        <property name="orientation">
         <enum>Qt::Horizontal</enum>
@@ -120,6 +140,9 @@
        <property name="text">
         <string>Show Messages</string>
        </property>
+       <property name="checked">
+        <bool>false</bool>
+       </property>
       </widget>
      </item>
      <item>
@@ -145,6 +168,12 @@
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
+     <property name="font">
+      <font>
+       <weight>75</weight>
+       <bold>true</bold>
+      </font>
+     </property>
     </widget>
    </item>
    <item>
@@ -161,6 +190,53 @@
      <property name="frameShadow">
       <enum>QFrame::Raised</enum>
      </property>
+     <layout class="QHBoxLayout" name="horizontalLayout_4">
+      <item>
+       <spacer name="horizontalSpacer_4">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item>
+       <widget class="QLabel" name="crashLabel">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="text">
+         <string/>
+        </property>
+        <property name="pixmap">
+         <pixmap>crash.jpg</pixmap>
+        </property>
+        <property name="scaledContents">
+         <bool>false</bool>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <spacer name="horizontalSpacer_5">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
     </widget>
    </item>
   </layout>

+ 4 - 5
Plugins/org.commontk.dicom.examplehost/ctkDicomExampleHost.cpp

@@ -7,16 +7,15 @@ ctkDicomExampleHost::ctkDicomExampleHost() : ctkDicomAbstractHost(8080)
 }
 
 void ctkDicomExampleHost::StartApplication(QString AppPath, const QUrl& App_URL){
+
     QStringList l;
     l.append("--hostURL");
     l.append(QString("localhost:") + this->getPort() );
     l.append("--applicationURL");
     l.append(App_URL.toString());
-    if (!QProcess::startDetached (
-            AppPath,l))
-    {
-        qCritical() << "application failed to start!";
-    }
+
+    this->appProcess.start(AppPath,l);
+
 }
 
 QRect ctkDicomExampleHost::getAvailableScreen(const QRect& preferredScreen){

+ 5 - 0
Plugins/org.commontk.dicom.examplehost/ctkDicomExampleHost.h

@@ -5,6 +5,7 @@
 #include <org_commontk_dicom_examplehost_Export.h>
 
 #include <QUrl>
+#include <QProcess>
 
 class org_commontk_dicom_examplehost_EXPORT ctkDicomExampleHost : public ctkDicomAbstractHost{
     Q_OBJECT
@@ -17,11 +18,15 @@ public:
     virtual QString getOutputLocation(const QStringList& /*preferredProtocols*/) { return ""; }
     virtual void notifyStateChanged(ctkDicomWG23::State state);
     virtual void notifyStatus(const ctkDicomWG23::Status& status);
+    const QProcess& getAppProcess() const { return appProcess; }
 
 signals:
     void stateChangedReceived(ctkDicomWG23::State state);
     void statusReceived(const ctkDicomWG23::Status& status);
     void giveAvailableScreen(QRect rect);
+
+  protected:
+    QProcess appProcess;
 };
 
 #endif // CTKDICOMEXAMPLEHOST_H