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