Medical Imaging Interaction Toolkit  2018.4.99-08619e4f
Medical Imaging Interaction Toolkit
BlueBerryExampleLauncherDialog.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 #include "ui_BlueBerryExampleLauncherDialog.h"
15 
16 #include <QCoreApplication>
17 #include <QDir>
18 #include <QEventLoop>
19 #include <QPushButton>
20 
22  : QDialog(parent), ui(new Ui::BlueBerryExampleLauncherDialog)
23 {
24  ui->setupUi(this);
25 
26  connect(this, SIGNAL(accepted()), this, SLOT(configurationSelected()));
27  connect(this, SIGNAL(rejected()), this, SLOT(dialogCanceled()));
28  connect(ui->appList, SIGNAL(currentRowChanged(int)), this, SLOT(selectionChanged(int)));
29 
30  // Get all BlueBerryExampleLauncher_*.provisioning files
31  QDir appDir(QApplication::applicationDirPath());
32 #ifdef CMAKE_INTDIR
33  appDir.cdUp();
34 #endif
35 
36  provisioningFiles = appDir.entryList(
37  QStringList(QApplication::applicationName() + "_*.provisioning"), QDir::Files | QDir::Readable, QDir::Name);
38 
39 #ifdef Q_OS_MAC
40  /*
41  * On Mac, if started from the build directory the .provisioning file is located at:
42  * <MITK-build/bin/BlueBerryExampleLauncher_*.provisioning>
43  * but the executable path is:
44  * <MITK-build/bin/BlueBerryExampleLauncher.app/Contents/MacOS/BlueBerryExampleLauncher>
45  * In this case we have to cdUp threetimes.
46  *
47  * During packaging however the MitkWorkbench.provisioning file is placed at the same
48  * level like the executable, hence nothing has to be done.
49  */
50 
51  if (provisioningFiles.empty())
52  {
53  appDir.cdUp();
54  appDir.cdUp();
55  appDir.cdUp();
56  provisioningFiles = appDir.entryList(
57  QStringList(QApplication::applicationName() + "_*.provisioning"), QDir::Files | QDir::Readable, QDir::Name);
58  }
59 #endif
60 
61  foreach (QString provFile, provisioningFiles)
62  {
63  int startIndex = provFile.indexOf('_');
64  int endIndex = provFile.lastIndexOf('.');
65  ui->appList->addItem(provFile.mid(startIndex + 1, endIndex - startIndex - 1));
66 
67  descriptions.push_back(QString());
68  QString descriptionFileName = provFile.left(provFile.lastIndexOf('.')) + ".txt";
69  QFile descriptionFile(appDir.filePath(descriptionFileName));
70 
71  if (descriptionFile.exists())
72  {
73  if (descriptionFile.open(QIODevice::ReadOnly))
74  {
75  descriptions.back() = descriptionFile.readAll();
76  }
77  }
78  }
79 
80  if (ui->appList->currentRow() == -1)
81  ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
82 }
83 
85 {
86  delete ui;
87 }
88 
90 {
91  this->show();
92 
93  if (eventLoop.exec() == 0)
94  {
95  QDir appDir = QCoreApplication::applicationDirPath();
96 
97 #ifdef CMAKE_INTDIR
98  appDir.cdUp();
99 #endif
100 
101 #ifdef Q_OS_MAC
102  /*
103  * On Mac, if started from the build directory the .provisioning file is located at:
104  * <MITK-build/bin/BlueBerryExampleLauncher_*.provisioning>
105  * but the executable path is:
106  * <MITK-build/bin/BlueBerryExampleLauncher.app/Contents/MacOS/BlueBerryExampleLauncher>
107  * In this case we have to cdUp threetimes.
108  *
109  * During packaging however the MitkWorkbench.provisioning file is placed at the same
110  * level like the executable, hence nothing has to be done.
111  */
112  QFileInfo filePath(appDir.filePath(provisioningFiles[ui->appList->currentRow()]));
113 
114  if (!filePath.exists())
115  {
116  appDir.cdUp();
117  appDir.cdUp();
118  appDir.cdUp();
119  }
120 #endif
121 
122  return appDir.filePath(provisioningFiles[ui->appList->currentRow()]);
123  }
124 
125  return QString();
126 }
127 
128 void BlueBerryExampleLauncherDialog::configurationSelected()
129 {
130  eventLoop.exit(0);
131 }
132 
133 void BlueBerryExampleLauncherDialog::dialogCanceled()
134 {
135  eventLoop.exit(1);
136 }
137 
138 void BlueBerryExampleLauncherDialog::selectionChanged(int row)
139 {
140  if (row > -1)
141  {
142  ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
143  ui->description->setHtml(this->descriptions[row]);
144  }
145  else
146  {
147  ui->description->clear();
148  }
149 }
BlueBerryExampleLauncherDialog(QWidget *parent=nullptr)