diff --git a/Plugins/org.mitk.gui.qt.xnat/resources/xnat-connect.png b/Plugins/org.mitk.gui.qt.xnat/resources/xnat-connect.png
new file mode 100644
index 0000000000..2e4c85d1ea
Binary files /dev/null and b/Plugins/org.mitk.gui.qt.xnat/resources/xnat-connect.png differ
diff --git a/Plugins/org.mitk.gui.qt.xnat/resources/xnat-disconnect.png b/Plugins/org.mitk.gui.qt.xnat/resources/xnat-disconnect.png
new file mode 100644
index 0000000000..6423104172
Binary files /dev/null and b/Plugins/org.mitk.gui.qt.xnat/resources/xnat-disconnect.png differ
diff --git a/Plugins/org.mitk.gui.qt.xnat/resources/xnat.qrc b/Plugins/org.mitk.gui.qt.xnat/resources/xnat.qrc
index da7032238c..efdd0f6eda 100644
--- a/Plugins/org.mitk.gui.qt.xnat/resources/xnat.qrc
+++ b/Plugins/org.mitk.gui.qt.xnat/resources/xnat.qrc
@@ -1,8 +1,10 @@
xnat-download.png
xnat-upload.png
xnat-folder.png
xnat-icon.png
+ xnat-connect.png
+ xnat-disconnect.png
diff --git a/Plugins/org.mitk.gui.qt.xnat/resources/xnat_treebrowser_icon.png b/Plugins/org.mitk.gui.qt.xnat/resources/xnat_treebrowser_icon.png
index 5d85c84a18..a7d55719f8 100644
Binary files a/Plugins/org.mitk.gui.qt.xnat/resources/xnat_treebrowser_icon.png and b/Plugins/org.mitk.gui.qt.xnat/resources/xnat_treebrowser_icon.png differ
diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePage.cpp b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePage.cpp
index 6f245ce7ad..e8866dd8ea 100644
--- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePage.cpp
+++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePage.cpp
@@ -1,316 +1,309 @@
/*===================================================================
The Medical Imaging Interaction Toolkit (MITK)
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "QmitkXnatConnectionPreferencePage.h"
#include "QmitkXnatTreeBrowserView.h"
#include "org_mitk_gui_qt_xnatinterface_Activator.h"
#include "berryIPreferencesService.h"
#include "berryPlatform.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include "ctkXnatSession.h"
#include "ctkXnatLoginProfile.h"
#include "ctkXnatException.h"
#include
using namespace berry;
QmitkXnatConnectionPreferencePage::QmitkXnatConnectionPreferencePage()
: m_Control(0)
{
}
void QmitkXnatConnectionPreferencePage::Init(berry::IWorkbench::Pointer)
{
}
void QmitkXnatConnectionPreferencePage::CreateQtControl(QWidget* parent)
{
IPreferencesService* prefService = Platform::GetPreferencesService();
berry::IPreferences::Pointer _XnatConnectionPreferencesNode = prefService->GetSystemPreferences()->Node(QmitkXnatTreeBrowserView::VIEW_ID);
m_XnatConnectionPreferencesNode = _XnatConnectionPreferencesNode;
m_Controls.setupUi(parent);
m_Control = new QWidget(parent);
m_Control->setLayout(m_Controls.gridLayout);
ctkXnatSession* session;
try
{
session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetService(
- mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
}
catch (std::invalid_argument)
{
session = nullptr;
}
- if (session != nullptr)
+ if (session != nullptr && session->isOpen())
{
- if (session->isOpen())
- {
- m_Controls.xnatTestConnectionButton->setText("Disconnect");
- }
- else
- {
- m_Controls.xnatTestConnectionButton->setText("Connect");
- }
+ m_Controls.xnatTestConnectionLabel->setStyleSheet("QLabel { color: green; }");
+ m_Controls.xnatTestConnectionLabel->setText("Already connected.");
+ m_Controls.xnatTestConnectionButton->setEnabled(false);
}
-
const QIntValidator *portV = new QIntValidator(0, 65535, parent);
m_Controls.inXnatPort->setValidator(portV);
const QRegExp hostRx("^(https?)://[^ /](\\S)+$");
const QRegExpValidator *hostV = new QRegExpValidator(hostRx, parent);
m_Controls.inXnatHostAddress->setValidator(hostV);
- connect(m_Controls.xnatTestConnectionButton, SIGNAL(clicked()), this, SLOT(ToggleConnection()));
+ connect(m_Controls.xnatTestConnectionButton, SIGNAL(clicked()), this, SLOT(TestConnection()));
connect(m_Controls.inXnatHostAddress, SIGNAL(editingFinished()), this, SLOT(UrlChanged()));
connect(m_Controls.inXnatDownloadPath, SIGNAL(editingFinished()), this, SLOT(DownloadPathChanged()));
connect(m_Controls.cbUseNetworkProxy, SIGNAL(toggled(bool)), this, SLOT(onUseNetworkProxy(bool)));
connect(m_Controls.btnDownloadPath, SIGNAL(clicked()), this, SLOT(OnDownloadPathButtonClicked()));
m_Controls.groupBoxProxySettings->setVisible(m_Controls.cbUseNetworkProxy->isChecked());
this->Update();
}
QWidget* QmitkXnatConnectionPreferencePage::GetQtControl() const
{
return m_Control;
}
bool QmitkXnatConnectionPreferencePage::PerformOk()
{
if (!UserInformationEmpty())
{
IPreferences::Pointer _XnatConnectionPreferencesNode = m_XnatConnectionPreferencesNode.Lock();
if (_XnatConnectionPreferencesNode.IsNotNull())
{
_XnatConnectionPreferencesNode->Put(m_Controls.xnatHostAddressLabel->text(), m_Controls.inXnatHostAddress->text());
_XnatConnectionPreferencesNode->Put(m_Controls.xnatPortLabel->text(), m_Controls.inXnatPort->text());
_XnatConnectionPreferencesNode->Put(m_Controls.xnatUsernameLabel->text(), m_Controls.inXnatUsername->text());
_XnatConnectionPreferencesNode->Put(m_Controls.xnatPasswortLabel->text(), m_Controls.inXnatPassword->text());
_XnatConnectionPreferencesNode->Put(m_Controls.xnatDownloadPathLabel->text(), m_Controls.inXnatDownloadPath->text());
// Network proxy settings
_XnatConnectionPreferencesNode->PutBool(m_Controls.cbUseNetworkProxy->text(), m_Controls.cbUseNetworkProxy->isChecked());
_XnatConnectionPreferencesNode->Put(m_Controls.proxyAddressLabel->text(), m_Controls.inProxyAddress->text());
_XnatConnectionPreferencesNode->Put(m_Controls.proxyPortLabel->text(), m_Controls.inProxyPort->text());
_XnatConnectionPreferencesNode->Put(m_Controls.proxyUsernameLabel->text(), m_Controls.inProxyUsername->text());
_XnatConnectionPreferencesNode->Put(m_Controls.proxyPasswordLabel->text(), m_Controls.inProxyPassword->text());
+
+ // Silent Mode
+ _XnatConnectionPreferencesNode->PutBool(m_Controls.cbUseSilentMode->text(), m_Controls.cbUseSilentMode->isChecked());
+
+ //Write
_XnatConnectionPreferencesNode->Flush();
return true;
}
}
else
{
QMessageBox::critical(QApplication::activeWindow(), "Saving Preferences failed",
- "The connection parameters in XNAT Preferences were empty.\nPlease use the 'Connect' button to validate the connection parameters.");
+ "The connection parameters in XNAT Preferences were empty.\nPlease use the 'Connect' button to validate the connection parameters.");
}
return false;
}
void QmitkXnatConnectionPreferencePage::PerformCancel()
{
}
bool QmitkXnatConnectionPreferencePage::UserInformationEmpty()
{
// To check empty QLineEdits in the following
QString errString;
if (m_Controls.inXnatHostAddress->text().isEmpty())
{
errString += "Server Address is empty.\n";
}
if (m_Controls.inXnatUsername->text().isEmpty())
{
errString += "Username is empty.\n";
}
if (m_Controls.inXnatPassword->text().isEmpty())
{
errString += "Password is empty.\n";
}
// if something is empty
if (!errString.isEmpty())
{
m_Controls.xnatTestConnectionLabel->setStyleSheet("QLabel { color: red; }");
m_Controls.xnatTestConnectionLabel->setText("Connecting failed.\n" + errString);
return true;
}
else
{
return false;
}
}
void QmitkXnatConnectionPreferencePage::Update()
{
IPreferences::Pointer _XnatConnectionPreferencesNode = m_XnatConnectionPreferencesNode.Lock();
if (_XnatConnectionPreferencesNode.IsNotNull())
{
m_Controls.inXnatHostAddress->setText(_XnatConnectionPreferencesNode->Get(
- m_Controls.xnatHostAddressLabel->text(), m_Controls.inXnatHostAddress->text()));
+ m_Controls.xnatHostAddressLabel->text(), m_Controls.inXnatHostAddress->text()));
m_Controls.inXnatPort->setText(_XnatConnectionPreferencesNode->Get(
- m_Controls.xnatPortLabel->text(), m_Controls.inXnatPort->text()));
+ m_Controls.xnatPortLabel->text(), m_Controls.inXnatPort->text()));
m_Controls.inXnatUsername->setText(_XnatConnectionPreferencesNode->Get(
- m_Controls.xnatUsernameLabel->text(), m_Controls.inXnatUsername->text()));
+ m_Controls.xnatUsernameLabel->text(), m_Controls.inXnatUsername->text()));
m_Controls.inXnatPassword->setText(_XnatConnectionPreferencesNode->Get(
- m_Controls.xnatPasswortLabel->text(), m_Controls.inXnatPassword->text()));
+ m_Controls.xnatPasswortLabel->text(), m_Controls.inXnatPassword->text()));
m_Controls.inXnatDownloadPath->setText(_XnatConnectionPreferencesNode->Get(
- m_Controls.xnatDownloadPathLabel->text(), m_Controls.inXnatDownloadPath->text()));
+ m_Controls.xnatDownloadPathLabel->text(), m_Controls.inXnatDownloadPath->text()));
// Network proxy settings
m_Controls.cbUseNetworkProxy->setChecked(_XnatConnectionPreferencesNode->GetBool(
- m_Controls.cbUseNetworkProxy->text(), false));
+ m_Controls.cbUseNetworkProxy->text(), false));
m_Controls.inProxyAddress->setText(_XnatConnectionPreferencesNode->Get(
- m_Controls.proxyAddressLabel->text(), m_Controls.inProxyAddress->text()));
+ m_Controls.proxyAddressLabel->text(), m_Controls.inProxyAddress->text()));
m_Controls.inProxyPort->setText(_XnatConnectionPreferencesNode->Get(
- m_Controls.proxyPortLabel->text(), m_Controls.inProxyPort->text()));
+ m_Controls.proxyPortLabel->text(), m_Controls.inProxyPort->text()));
m_Controls.inProxyUsername->setText(_XnatConnectionPreferencesNode->Get(
- m_Controls.proxyUsernameLabel->text(), m_Controls.inProxyUsername->text()));
+ m_Controls.proxyUsernameLabel->text(), m_Controls.inProxyUsername->text()));
m_Controls.inProxyPassword->setText(_XnatConnectionPreferencesNode->Get(
- m_Controls.proxyPasswordLabel->text(), m_Controls.inProxyPassword->text()));
+ m_Controls.proxyPasswordLabel->text(), m_Controls.inProxyPassword->text()));
+
+ // Silent Mode
+ m_Controls.cbUseSilentMode->setChecked(_XnatConnectionPreferencesNode->GetBool(
+ m_Controls.cbUseSilentMode->text(), false));
}
}
void QmitkXnatConnectionPreferencePage::UrlChanged()
{
m_Controls.inXnatHostAddress->setStyleSheet("QLineEdit { background-color: white; }");
QString str = m_Controls.inXnatHostAddress->text();
while (str.endsWith("/"))
{
str = str.left(str.length() - 1);
}
m_Controls.inXnatHostAddress->setText(str);
QUrl url(m_Controls.inXnatHostAddress->text());
if (!url.isValid())
{
m_Controls.inXnatHostAddress->setStyleSheet("QLineEdit { background-color: red; }");
}
}
void QmitkXnatConnectionPreferencePage::DownloadPathChanged()
{
m_Controls.inXnatDownloadPath->setStyleSheet("QLineEdit { background-color: white; }");
QString downloadPath = m_Controls.inXnatDownloadPath->text();
if (!downloadPath.isEmpty())
{
if (downloadPath.lastIndexOf("/") != downloadPath.size() - 1)
{
downloadPath.append("/");
m_Controls.inXnatDownloadPath->setText(downloadPath);
}
QFileInfo path(m_Controls.inXnatDownloadPath->text());
if (!path.isDir())
{
m_Controls.inXnatDownloadPath->setStyleSheet("QLineEdit { background-color: red; }");
}
}
}
void QmitkXnatConnectionPreferencePage::onUseNetworkProxy(bool status)
{
m_Controls.groupBoxProxySettings->setVisible(status);
}
void QmitkXnatConnectionPreferencePage::OnDownloadPathButtonClicked()
{
QString dir = QFileDialog::getExistingDirectory();
if (!dir.endsWith("/") || !dir.endsWith("\\"))
dir.append("/");
m_Controls.inXnatDownloadPath->setText(dir);
}
-void QmitkXnatConnectionPreferencePage::ToggleConnection()
+void QmitkXnatConnectionPreferencePage::TestConnection()
{
ctkXnatSession* session = 0;
try
{
session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetService(
- mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
}
catch (std::invalid_argument)
{
if (!UserInformationEmpty())
{
PerformOk();
mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->CreateXnatSession();
session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetService(
- mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
}
}
- if (session != 0 && session->isOpen())
+ try
{
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->OpenXnatSession();
+
+ m_Controls.xnatTestConnectionLabel->setStyleSheet("QLabel { color: green; }");
+ m_Controls.xnatTestConnectionLabel->setText("Connecting successful.");
+
mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->CloseXnatSession();
- m_Controls.xnatTestConnectionButton->setText("Connect");
- m_Controls.xnatTestConnectionLabel->clear();
}
- else if (session != 0 && !session->isOpen())
+ catch (const ctkXnatAuthenticationException& auth)
{
- m_Controls.xnatTestConnectionButton->setEnabled(false);
-
- try
- {
- mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->OpenXnatSession();
-
- m_Controls.xnatTestConnectionButton->setText("Disconnect");
- m_Controls.xnatTestConnectionLabel->setStyleSheet("QLabel { color: green; }");
- m_Controls.xnatTestConnectionLabel->setText("Connecting successful.");
- }
- catch (const ctkXnatAuthenticationException& auth)
- {
- m_Controls.xnatTestConnectionLabel->setStyleSheet("QLabel { color: red; }");
- m_Controls.xnatTestConnectionLabel->setText("Connecting failed:\nAuthentication error.");
- MITK_INFO << auth.message().toStdString();
- mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->CloseXnatSession();
- }
- catch (const ctkException& e)
- {
- m_Controls.xnatTestConnectionLabel->setStyleSheet("QLabel { color: red; }");
- m_Controls.xnatTestConnectionLabel->setText("Connecting failed:\nInvalid Server Adress");
- MITK_INFO << e.message().toStdString();
- mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->CloseXnatSession();
- }
- m_Controls.xnatTestConnectionButton->setEnabled(true);
+ m_Controls.xnatTestConnectionLabel->setStyleSheet("QLabel { color: red; }");
+ m_Controls.xnatTestConnectionLabel->setText("Connecting failed:\nAuthentication error.");
+ MITK_INFO << auth.message().toStdString();
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->CloseXnatSession();
}
+ catch (const ctkException& e)
+ {
+ m_Controls.xnatTestConnectionLabel->setStyleSheet("QLabel { color: red; }");
+ m_Controls.xnatTestConnectionLabel->setText("Connecting failed:\nInvalid Server Adress");
+ MITK_INFO << e.message().toStdString();
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->CloseXnatSession();
+ }
+
}
diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePage.h b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePage.h
index 5b2feb14e8..9a1ebf597c 100644
--- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePage.h
+++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePage.h
@@ -1,87 +1,87 @@
/*===================================================================
The Medical Imaging Interaction Toolkit (MITK)
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef QMITKXNATCONNECTIONPREFERENCEPAGE_H_
#define QMITKXNATCONNECTIONPREFERENCEPAGE_H_
#include "berryIQtPreferencePage.h"
#include
#include "ui_QmitkXnatConnectionPreferencePageControls.h"
class QWidget;
class QLineEdit;
struct QmitkXnatConnectionPreferencePage : public QObject, public berry::IQtPreferencePage
{
Q_OBJECT
Q_INTERFACES(berry::IPreferencePage)
public:
QmitkXnatConnectionPreferencePage();
void Init(berry::IWorkbench::Pointer workbench) override;
void CreateQtControl(QWidget* widget) override;
QWidget* GetQtControl() const override;
///
/// \see IPreferencePage::PerformOk()
///
virtual bool PerformOk() override;
///
/// \see IPreferencePage::PerformCancel()
///
virtual void PerformCancel() override;
///
/// \see IPreferencePage::Update()
///
virtual void Update() override;
protected slots:
virtual void UrlChanged();
virtual void DownloadPathChanged();
void OnDownloadPathButtonClicked();
///
/// Toggles the Connection in the Service Registry from opened to closed or the other way around.
///
- virtual void ToggleConnection();
+ virtual void TestConnection();
virtual void onUseNetworkProxy(bool);
protected:
Ui::QmitkXnatConnectionPreferencePageControls m_Controls;
QWidget* m_Control;
berry::IPreferences::WeakPtr m_XnatConnectionPreferencesNode;
private:
///
/// Checks if the entered user information is empty.
///
virtual bool UserInformationEmpty();
};
#endif /* QMITKXNATCONNECTIONPREFERENCEPAGE_H_ */
diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePageControls.ui b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePageControls.ui
index 92edcda670..a5044a5b3c 100644
--- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePageControls.ui
+++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePageControls.ui
@@ -1,262 +1,320 @@
QmitkXnatConnectionPreferencePageControls
0
0
742
- 349
+ 419
0
0
653
116
16777215
16777215
Form
- -
-
-
- Use Network Proxy
-
-
- true
-
-
-
- -
-
+
-
+
- XNAT Connection Settings
+ Network Proxy Settings
-
-
-
-
-
- Server Address
-
-
-
- -
-
-
- <html><head/><body><p>Examples:</p><p>https://central.xnat.org<br/>http://localhost/xnat</p></body></html>
-
-
- http(s)://
-
-
-
- -
-
-
- Port
-
-
-
- -
-
+
+
-
+
50
16777215
Standard-Port: 80
- -
-
+
-
+
- Username
+ Proxy Password
+
+
+
+ -
+
+
+ Proxy Username
-
-
+
+
+ <html><head/><body><p>Examples:</p><p>https://central.xnat.org<br/>http://localhost/xnat</p></body></html>
+
- testuser
+ http(s)://
- -
-
+
-
+
- Password
+ Proxy Port
- -
-
+
-
+
QLineEdit::Password
testpassword
- -
-
-
- Download Path
+
-
+
+
+ testuser
- -
-
-
- -
-
+
-
+
- Connect
+ Proxy Server Address
- -
-
-
- Qt::LeftToRight
-
-
- 1
+
+
+
+ -
+
+
+ XNAT Connection Settings
+
+
+
-
+
+
+ Port
+
+
+ -
+
-
+ Username
-
- Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop
+
+
+ -
+
+
+ Password
- -
-
+
-
+
- ...
+ Server Address
-
-
-
- -
-
-
- Network Proxy Settings
-
-
-
-
-
+
-
+
50
16777215
Standard-Port: 80
- -
-
-
- Proxy Password
-
-
-
- -
-
-
- Proxy Username
-
-
-
-
-
-
- <html><head/><body><p>Examples:</p><p>https://central.xnat.org<br/>http://localhost/xnat</p></body></html>
-
+
- http(s)://
+ testuser
- -
-
+
-
+
- Proxy Port
+ ...
- -
-
+
-
+
QLineEdit::Password
testpassword
- -
-
-
- testuser
+
-
+
+
+ -
+
+
+ Download Path
- -
-
-
- Proxy Server Address
+
-
+
+
+ <html><head/><body><p>Examples:</p><p>https://central.xnat.org<br/>http://localhost/xnat</p></body></html>
+
+
+ http(s)://
- -
+
-
Qt::Vertical
20
40
+ -
+
+
+ Use Network Proxy
+
+
+ true
+
+
+
+ -
+
+
+ 6
+
+
-
+
+
-
+
+
+ Test Connection
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+
+
+ -
+
+
+ Qt::LeftToRight
+
+
+ 1
+
+
+
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop
+
+
+
+
+
+ -
+
+
-
+
+
+ Silent Mode
+
+
+ true
+
+
+
+ -
+
+
+ (Suppresses most message popups)
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+
+
diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.cpp b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.cpp
index 4bc02a9c1a..50edfd7f84 100644
--- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.cpp
+++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.cpp
@@ -1,1007 +1,1091 @@
/*===================================================================
The Medical Imaging Interaction Toolkit (MITK)
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "QmitkXnatTreeBrowserView.h"
// Qmitk
#include "org_mitk_gui_qt_xnatinterface_Activator.h"
// Blueberry
#include
// CTK XNAT Core
#include
#include
#include
#include
#include
#include "ctkXnatFile.h"
#include
#include
#include
#include
#include
#include
#include
#include
// MITK XNAT
#include
#include
#include
#include
#include
#include
#include
// Qt
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
+#include
// Poco
#include
const QString QmitkXnatTreeBrowserView::VIEW_ID = "org.mitk.views.xnat.treebrowser";
QmitkXnatTreeBrowserView::QmitkXnatTreeBrowserView() :
-m_DataStorageServiceTracker(mitk::org_mitk_gui_qt_xnatinterface_Activator::GetContext()),
-m_TreeModel(new QmitkXnatTreeModel()),
-m_Tracker(0),
-m_DownloadPath(berry::Platform::GetPreferencesService()->GetSystemPreferences()->Node(VIEW_ID)->Get("Download Path", ""))
+ m_DataStorageServiceTracker(mitk::org_mitk_gui_qt_xnatinterface_Activator::GetContext()),
+ m_TreeModel(new QmitkXnatTreeModel()),
+ m_Tracker(0),
+ m_DownloadPath(berry::Platform::GetPreferencesService()->GetSystemPreferences()->Node(VIEW_ID)->Get("Download Path", "")),
+ m_SilentMode(false)
{
m_DataStorageServiceTracker.open();
// Set DownloadPath
if (m_DownloadPath.isEmpty())
{
QString xnatFolder = "XNAT_DOWNLOADS";
QDir dir(mitk::org_mitk_gui_qt_xnatinterface_Activator::GetContext()->getDataFile("").absoluteFilePath());
dir.mkdir(xnatFolder);
dir.setPath(dir.path() + "/" + xnatFolder);
m_DownloadPath = dir.path() + "/";
}
}
QmitkXnatTreeBrowserView::~QmitkXnatTreeBrowserView()
{
m_DataStorageServiceTracker.close();
delete m_TreeModel;
delete m_Tracker;
}
void QmitkXnatTreeBrowserView::SetFocus()
{
}
+void QmitkXnatTreeBrowserView::ToggleConnection()
+{
+ ctkXnatSession* session = 0;
+
+ try
+ {
+ session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetService(
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
+ }
+ catch (std::invalid_argument)
+ {
+ if (true)
+ {
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->CreateXnatSession();
+ session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetService(
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
+ }
+ }
+
+ if (session != 0 && session->isOpen())
+ {
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->CloseXnatSession();
+ m_Controls.btnXnatConnect->setToolTip("Connect");
+ m_Controls.btnXnatConnect->setIcon(QIcon(":/xnat-plugin/xnat-connect.png"));
+ CleanUp();
+ }
+ else if (session != 0 && !session->isOpen())
+ {
+ try
+ {
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->OpenXnatSession();
+ m_Controls.btnXnatConnect->setToolTip("Disconnect");
+ m_Controls.btnXnatConnect->setIcon(QIcon(":/xnat-plugin/xnat-disconnect.png"));
+ }
+ catch (const ctkXnatAuthenticationException& auth)
+ {
+ MITK_INFO << auth.message().toStdString();
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->CloseXnatSession();
+ QmitkPreferencesDialog _PreferencesDialog(QApplication::activeWindow());
+ _PreferencesDialog.SetSelectedPage("org.mitk.gui.qt.application.XnatConnectionPreferencePage");
+ _PreferencesDialog.exec();
+ }
+ catch (const ctkException& e)
+ {
+ MITK_INFO << e.message().toStdString();
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->CloseXnatSession();
+ QmitkPreferencesDialog _PreferencesDialog(QApplication::activeWindow());
+ _PreferencesDialog.SetSelectedPage("org.mitk.gui.qt.application.XnatConnectionPreferencePage");
+ _PreferencesDialog.exec();
+ }
+ catch (...)
+ {
+ QmitkPreferencesDialog _PreferencesDialog(QApplication::activeWindow());
+ _PreferencesDialog.SetSelectedPage("org.mitk.gui.qt.application.XnatConnectionPreferencePage");
+ _PreferencesDialog.exec();
+ }
+ }
+}
+
void QmitkXnatTreeBrowserView::CreateQtPartControl(QWidget *parent)
{
// Create GUI widgets from the Qt Designer's .ui file
m_Controls.setupUi(parent);
m_Controls.treeView->setModel(m_TreeModel);
m_Controls.treeView->header()->hide();
m_Controls.treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_Controls.treeView->setAcceptDrops(true);
m_Controls.treeView->setDropIndicatorShown(true);
- m_Controls.labelError->setText("Please use the 'Connect' button in the Preferences.");
- m_Controls.labelError->setStyleSheet("QLabel { color: red; }");
m_Controls.treeView->setSelectionMode(QAbstractItemView::SingleSelection);
m_Controls.treeView->setContextMenuPolicy(Qt::CustomContextMenu);
m_Controls.groupBox->hide();
m_Controls.wgtExperimentInfo->hide();
m_Controls.wgtSubjectInfo->hide();
m_Controls.wgtProjectInfo->hide();
m_Tracker = new mitk::XnatSessionTracker(mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext());
m_ContextMenu = new QMenu(m_Controls.treeView);
connect(m_Controls.treeView, SIGNAL(clicked(const QModelIndex&)), SLOT(itemSelected(const QModelIndex&)));
connect(m_Controls.treeView, SIGNAL(customContextMenuRequested(const QPoint&)),
- this, SLOT(OnContextMenuRequested(const QPoint&)));
+ this, SLOT(OnContextMenuRequested(const QPoint&)));
connect(m_Tracker, SIGNAL(AboutToBeClosed(ctkXnatSession*)), this, SLOT(CleanTreeModel(ctkXnatSession*)));
connect(m_Tracker, SIGNAL(Opened(ctkXnatSession*)), this, SLOT(UpdateSession(ctkXnatSession*)));
m_Tracker->Open();
ctkXnatSession* session;
try
{
session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetService(
- mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
}
catch (std::invalid_argument)
{
session = 0;
}
- if (session != 0)
- {
- m_Controls.labelError->setVisible(false);
- }
- else
- {
- m_Controls.labelError->setVisible(true);
- }
-
connect(m_Controls.treeView, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(OnActivatedNode(const QModelIndex&)));
connect(m_Controls.treeView, SIGNAL(clicked(const QModelIndex&)), this, SLOT(OnXnatNodeSelected(const QModelIndex&)));
connect(m_TreeModel, SIGNAL(ResourceDropped(const QList&, ctkXnatObject*, const QModelIndex&)), this, SLOT(OnUploadResource(const QList&, ctkXnatObject*, const QModelIndex&)));
+ connect(m_Controls.btnXnatConnect, SIGNAL(clicked()), SLOT(ToggleConnection()));
connect(m_Controls.btnXnatUpload, SIGNAL(clicked()), this, SLOT(OnUploadFromDataStorage()));
connect(m_Controls.btnXnatDownload, SIGNAL(clicked()), this, SLOT(OnDownloadSelectedXnatFile()));
connect(m_Controls.btnCreateXnatFolder, SIGNAL(clicked()), this, SLOT(OnCreateResourceFolder()));
}
void QmitkXnatTreeBrowserView::OnCreateResourceFolder()
{
QModelIndex index = m_Controls.treeView->selectionModel()->currentIndex();
if(!index.isValid()) return;
ctkXnatObject* parent = index.data(Qt::UserRole).value();
this->InternalAddResourceFolder(parent);
m_TreeModel->refresh(index);
}
void QmitkXnatTreeBrowserView::OnDownloadSelectedXnatFile()
{
QModelIndex index = m_Controls.treeView->selectionModel()->currentIndex();
if(!index.isValid()) return;
ctkXnatObject* selectedXnatObject = index.data(Qt::UserRole).value();
bool enableDownload = dynamic_cast(selectedXnatObject) != nullptr;
enableDownload |= dynamic_cast(selectedXnatObject) != nullptr;
if (enableDownload)
{
this->InternalFileDownload(index, true);
}
}
void QmitkXnatTreeBrowserView::OnUploadFromDataStorage()
{
QmitkXnatUploadFromDataStorageDialog dialog;
dialog.SetDataStorage(this->GetDataStorage());
int result = dialog.exec();
if (result == QDialog::Accepted)
{
QList nodes;
nodes << dialog.GetSelectedNode().GetPointer();
QModelIndex index = m_Controls.treeView->selectionModel()->currentIndex();
if (!index.isValid()) return;
ctkXnatObject* parent = m_TreeModel->xnatObject(index);
this->OnUploadResource(nodes, parent, index);
}
}
void QmitkXnatTreeBrowserView::OnXnatNodeSelected(const QModelIndex& index)
{
// Enable download button
if (!index.isValid()) return;
ctkXnatObject* selectedXnatObject = index.data(Qt::UserRole).value();
bool enableDownload = dynamic_cast(selectedXnatObject) != nullptr;
enableDownload |= dynamic_cast(selectedXnatObject) != nullptr;
m_Controls.btnXnatDownload->setEnabled(enableDownload);
bool enableCreateFolder = dynamic_cast(selectedXnatObject) != nullptr;
enableCreateFolder |= dynamic_cast(selectedXnatObject) != nullptr;
enableCreateFolder |= dynamic_cast(selectedXnatObject) != nullptr;
m_Controls.btnCreateXnatFolder->setEnabled(enableCreateFolder);
bool enableUpload = dynamic_cast(selectedXnatObject) != nullptr;
m_Controls.btnXnatUpload->setEnabled(enableUpload);
}
void QmitkXnatTreeBrowserView::OnActivatedNode(const QModelIndex& index)
{
if (!index.isValid()) return;
ctkXnatObject* selectedXnatObject = index.data(Qt::UserRole).value();
bool enableDownload = dynamic_cast(selectedXnatObject) != nullptr;
enableDownload |= dynamic_cast(selectedXnatObject) != nullptr;
if (enableDownload)
{
- QMessageBox msgBox;
- QString msg ("Do you want to download "+selectedXnatObject->name()+"?");
- msgBox.setWindowTitle("MITK XNAT upload");
- msgBox.setText(msg);
- msgBox.setIcon(QMessageBox::Question);
- msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
- int result = msgBox.exec();
- if (result == QMessageBox::Ok)
+ if(!m_SilentMode)
+ {
+ QMessageBox msgBox;
+ QString msg ("Do you want to download "+selectedXnatObject->name()+"?");
+ msgBox.setWindowTitle("MITK XNAT download");
+ msgBox.setText(msg);
+ msgBox.setIcon(QMessageBox::Question);
+ msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
+ int result = msgBox.exec();
+ if (result == QMessageBox::Ok)
+ {
+ InternalFileDownload(index, true);
+ }
+ }
+ else
+ {
InternalFileDownload(index, true);
+ }
}
}
void QmitkXnatTreeBrowserView::UpdateSession(ctkXnatSession* session)
{
if (session != 0 && session->isOpen())
{
- m_Controls.labelError->setVisible(false);
// Fill model and show in the GUI
m_TreeModel->addDataModel(session->dataModel());
m_Controls.treeView->reset();
connect(session, SIGNAL(progress(QUuid,double)), this, SLOT(OnProgress(QUuid,double)));
connect(session, SIGNAL(timedOut()), this, SLOT(sessionTimedOutMsg()));
connect(session, SIGNAL(aboutToTimeOut()), this, SLOT(sessionTimesOutSoonMsg()));
}
}
void QmitkXnatTreeBrowserView::CleanTreeModel(ctkXnatSession* session)
{
if (session != 0)
{
m_TreeModel->removeDataModel(session->dataModel());
m_Controls.treeView->reset();
}
}
void QmitkXnatTreeBrowserView::OnProgress(QUuid /*queryID*/, double progress)
{
if (progress > 0)
{
unsigned int currentProgress = progress*100;
if (m_Controls.groupBox->isHidden())
{
m_Controls.groupBox->show();
m_Controls.progressBar->setValue(0);
}
m_Controls.progressBar->setValue(currentProgress);
}
}
void QmitkXnatTreeBrowserView::OnPreferencesChanged(const berry::IBerryPreferences* prefs)
{
QString downloadPath = prefs->Get("Download Path", "");
QDir downloadDir (downloadPath);
if (downloadPath.length() != 0 && downloadDir.exists())
m_DownloadPath = downloadPath;
+
+ m_SilentMode = prefs->GetBool("Silent Mode", false);
}
void QmitkXnatTreeBrowserView::InternalFileDownload(const QModelIndex& index, bool loadData)
{
if (!index.isValid())
return;
ctkXnatObject* xnatObject = m_TreeModel->xnatObject(index);
if (xnatObject != nullptr)
{
m_Controls.progressBar->setMinimum(0);
m_Controls.progressBar->setMaximum(100);
// The path to the downloaded file
QString filePath;
QDir downloadPath (m_DownloadPath);
QString serverURL = berry::Platform::GetPreferencesService()->GetSystemPreferences()->Node(VIEW_ID)->Get("Server Address", "");
bool isDICOM (false);
// If a scan was selected, downloading the contained DICOM folder as ZIP
ctkXnatScan* scan = dynamic_cast(xnatObject);
if (scan != nullptr)
{
isDICOM = true;
if (!scan->isFetched())
scan->fetch();
QList children = scan->children();
foreach (ctkXnatObject* obj, children)
{
if (obj->name() == "DICOM")
{
QString folderName = obj->resourceUri();
folderName.replace("/","_");
downloadPath = m_DownloadPath + folderName;
this->InternalDICOMDownload(obj, downloadPath);
serverURL = obj->resourceUri();
}
}
}
else
{
ctkXnatFile* file = dynamic_cast(xnatObject);
if (file == nullptr)
{
MITK_ERROR << "Selected XNAT object not downloadable!";
return;
}
QString uriId = file->parent()->resourceUri();
uriId.replace("/data/archive/projects/", "");
QString folderName = m_DownloadPath + uriId + "/";
downloadPath = folderName;
QDir dir(downloadPath);
if (!dir.exists())
{
dir.mkpath(".");
}
filePath = folderName + file->name();
// Checking if the file exists already
if (downloadPath.exists(file->name()))
{
MITK_INFO << "File '" << file->name().toStdString() << "' already exists!";
serverURL = file->parent()->resourceUri();
}
else
{
if (file->property("collection") == QString("DICOM"))
{
isDICOM = true;
ctkXnatObject* parent = file->parent();
QString folderName = parent->resourceUri();
folderName.replace("/","_");
downloadPath = m_DownloadPath + folderName;
this->InternalDICOMDownload(parent, downloadPath);
serverURL = parent->resourceUri();
}
else
{
this->SetStatusInformation("Downloading file " + file->name());
file->download(filePath);
serverURL = file->parent()->resourceUri();
// Checking if the file exists now
if (downloadPath.exists(file->name()))
{
MITK_INFO << "Download of " << file->name().toStdString() << " completed!";
- QMessageBox msgBox;
- msgBox.setText("Download of " + file->name() + " completed!");
- msgBox.setIcon(QMessageBox::Information);
- msgBox.exec();
+ if(!m_SilentMode)
+ {
+ QMessageBox msgBox;
+ msgBox.setText("Download of " + file->name() + " completed!");
+ msgBox.setIcon(QMessageBox::Information);
+ msgBox.exec();
+ }
m_Controls.groupBox->hide();
}
else
{
MITK_INFO << "Download of " << file->name().toStdString() << " failed!";
QMessageBox msgBox;
msgBox.setText("Download of " + file->name() + " failed!");
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
m_Controls.groupBox->hide();
return;
}
}
}
}
if (loadData)
{
QFileInfoList fileList;
if (isDICOM)
{
fileList = downloadPath.entryInfoList(QDir::Files);
}
else
{
QFileInfo fileInfo(filePath);
fileList << fileInfo;
}
mitk::StringProperty::Pointer xnatURL = mitk::StringProperty::New(serverURL.toStdString());
this->InternalOpenFiles(fileList, xnatURL);
}
}
}
void QmitkXnatTreeBrowserView::InternalDICOMDownload(ctkXnatObject *obj, QDir &DICOMDirPath)
{
QString filePath = m_DownloadPath + obj->property("label") + ".zip";
this->SetStatusInformation("Downloading DICOM series " + obj->parent()->name());
// In case of DICOM zip download we do not know the total file size
// Because of that the dowload progres cannot be calculated
// Because of that we use the busy indicator of the progress bar by setting min and max to 0
m_Controls.progressBar->setMinimum(0);
m_Controls.progressBar->setMaximum(0);
m_Controls.progressBar->show();
obj->download(filePath);
std::ifstream in(filePath.toStdString().c_str(), std::ios::binary);
poco_assert(in);
// decompress to XNAT_DOWNLOAD dir
Poco::Zip::Decompress dec(in, Poco::Path(DICOMDirPath.path().toStdString()), true);
dec.decompressAllFiles();
in.close();
QFile::remove(filePath);
// Checking if the file exists now
if (DICOMDirPath.exists())
{
MITK_INFO << "Download of DICOM series " << obj->parent()->name().toStdString() << " completed!";
QMessageBox msgBox;
msgBox.setText("Download of DICOM series " + obj->parent()->name() + " completed!");
msgBox.setIcon(QMessageBox::Information);
msgBox.exec();
m_Controls.groupBox->hide();
}
else
{
MITK_INFO << "Download of DICOM series " << obj->parent()->name().toStdString() << " failed!";
QMessageBox msgBox;
msgBox.setText("Download of DICOM series " + obj->parent()->name() + " failed!");
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
m_Controls.groupBox->hide();
}
}
void QmitkXnatTreeBrowserView::InternalOpenFiles(const QFileInfoList & fileList, mitk::StringProperty::Pointer xnatURL)
{
if (fileList.isEmpty())
{
MITK_WARN << "No files available for laoding!";
return;
}
mitk::IDataStorageService* dsService = m_DataStorageServiceTracker.getService();
mitk::DataStorage::Pointer dataStorage = dsService->GetDataStorage()->GetDataStorage();
QStringList list;
list << fileList.at(0).absoluteFilePath();
try
{
mitk::DataStorage::SetOfObjects::Pointer nodes = QmitkIOUtil::Load(list, *dataStorage);
if (nodes->size() == 1)
{
mitk::DataNode* node = nodes->at(0);
node->SetProperty("xnat.url", xnatURL);
}
}
catch (const mitk::Exception& e)
{
MITK_INFO << e;
return;
}
mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(
dsService->GetDataStorage()->GetDataStorage());
}
void QmitkXnatTreeBrowserView::OnContextMenuDownloadFile()
{
QModelIndex index = m_Controls.treeView->currentIndex();
InternalFileDownload(index, false);
}
void QmitkXnatTreeBrowserView::OnContextMenuDownloadAndOpenFile()
{
QModelIndex index = m_Controls.treeView->currentIndex();
InternalFileDownload(index, true);
}
void QmitkXnatTreeBrowserView::OnContextMenuCreateResourceFolder()
{
const QModelIndex index = m_Controls.treeView->selectionModel()->currentIndex();
ctkXnatObject* parentObject = m_TreeModel->xnatObject(index);
if (parentObject != nullptr)
{
this->InternalAddResourceFolder(parentObject);
}
}
ctkXnatResource* QmitkXnatTreeBrowserView::InternalAddResourceFolder(ctkXnatObject *parent)
{
bool ok;
QString folderName = QInputDialog::getText(m_Controls.treeView, tr("Create XNAT resource folder"),
- tr("Folder name:"), QLineEdit::Normal, tr("data"), &ok);
+ tr("Folder name:"), QLineEdit::Normal, tr("data"), &ok);
if (ok)
{
if (folderName.isEmpty())
folderName = "NO LABEL";
return parent->addResourceFolder(folderName);
}
else
{
return nullptr;
}
}
void QmitkXnatTreeBrowserView::InternalFileUpload(ctkXnatFile* file)
{
m_Controls.groupBox->setTitle("Uploading file...");
m_Controls.groupBox->show();
try
{
file->save();
MITK_INFO << "Upload of " << file->name().toStdString() << " completed!";
- QMessageBox msgBox;
- msgBox.setText("Upload of " + file->name() + " completed!");
- msgBox.setIcon(QMessageBox::Information);
- msgBox.show();
- msgBox.exec();
+ if(!m_SilentMode)
+ {
+ QMessageBox msgBox;
+ msgBox.setText("Upload of " + file->name() + " completed!");
+ msgBox.setIcon(QMessageBox::Information);
+ msgBox.show();
+ msgBox.exec();
+ }
}
catch (ctkXnatException &e)
{
QMessageBox msgbox;
msgbox.setText(e.what());
msgbox.setIcon(QMessageBox::Critical);
msgbox.exec();
m_Controls.progressBar->setValue(0);
}
m_Controls.groupBox->hide();
}
void QmitkXnatTreeBrowserView::OnContextMenuUploadFile()
{
QString filename = QFileDialog::getOpenFileName(m_Controls.treeView, tr("Open File"), QDir::homePath());
const QModelIndex index = m_Controls.treeView->selectionModel()->currentIndex();
ctkXnatResource* resource = dynamic_cast(m_TreeModel->xnatObject(index));
if (resource != nullptr && filename.length() != 0)
{
ctkXnatFile* file = new ctkXnatFile(resource);
file->setLocalFilePath(filename);
QFileInfo fileInfo (filename);
file->setName(fileInfo.fileName());
this->InternalFileUpload(file);
m_TreeModel->addChildNode(index, file);
}
}
void QmitkXnatTreeBrowserView::OnContextMenuCopyXNATUrlToClipboard()
{
const QModelIndex index = m_Controls.treeView->selectionModel()->currentIndex();
ctkXnatObject* currentXnatObject = m_TreeModel->xnatObject(index);
if (currentXnatObject != nullptr)
{
QString serverURL = berry::Platform::GetPreferencesService()->GetSystemPreferences()->Node(VIEW_ID)->Get("Server Address", "");
serverURL.append(currentXnatObject->resourceUri());
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(serverURL);
}
}
void QmitkXnatTreeBrowserView::OnContextMenuRefreshItem()
{
const QModelIndex index = m_Controls.treeView->selectionModel()->currentIndex();
if (index.isValid())
{
this->m_TreeModel->refresh(index);
}
}
void QmitkXnatTreeBrowserView::OnUploadResource(const QList& droppedNodes, ctkXnatObject* parentObject, const QModelIndex& parentIndex)
{
if (parentObject == nullptr)
return;
//1. If not dropped on a resource, create a new folder
+ //temporarily remove the annoying message box that upload was successfull..
ctkXnatResource* resource = dynamic_cast(parentObject);
if (resource == nullptr)
{
resource = this->InternalAddResourceFolder(parentObject);
}
if (resource == nullptr)
{
MITK_WARN << "Could not upload file! No resource available!";
QMessageBox msgbox;
msgbox.setText("Could not upload file! No resource available!");
msgbox.setIcon(QMessageBox::Critical);
msgbox.exec();
return;
}
//2. Save files locally
//3. Upload file
mitk::DataNode* node = NULL;
foreach (node, droppedNodes)
{
mitk::BaseData* data = node->GetData();
if (!data)
return;
QString fileName (QString::fromStdString(node->GetName()));
ctkXnatFile* xnatFile = new ctkXnatFile(resource);
if (dynamic_cast(data))
{
fileName.append(".nrrd");
}
else if (dynamic_cast(data))
{
fileName.append(".vtk");
}
else if (dynamic_cast(data))
{
fileName.append(".mps");
}
else
{
MITK_WARN << "Could not upload file! File-type not supported";
QMessageBox msgbox;
msgbox.setText("Could not upload file! File-type not supported");
msgbox.setIcon(QMessageBox::Critical);
msgbox.exec();
return;
}
xnatFile->setName(fileName);
QString xnatFolder = "XNAT_UPLOADS";
QDir dir(mitk::org_mitk_gui_qt_xnatinterface_Activator::GetContext()->getDataFile("").absoluteFilePath());
dir.mkdir(xnatFolder);
fileName = dir.path().append("/" + fileName);
mitk::IOUtil::Save (data, fileName.toStdString());
// TODO Check if file exists
// AbstractFileReader::SetDefaultDataNodeProperties
// und in die andere SetDefaultDataNodeProperties
// PropertyName klein: mtime.initial + Kommentar
mitk::StringProperty::Pointer orignalFilePath = mitk::StringProperty::New();
node->GetProperty(orignalFilePath, "path");
xnatFile->setLocalFilePath(fileName);
this->InternalFileUpload(xnatFile);
QFile::remove(fileName);
m_TreeModel->refresh(parentIndex);
// The filename for uploading
-// QFileInfo fileInfo;
+ // QFileInfo fileInfo;
// if (surface)
// {
// // Save surface
// fileName.append(".stl");
// xnatFile->setName(fileName);
// dir.setPath(dir.path().append("/" + fileName));
-// QString origFile = QString::fromStdString(orignalFilePath->GetValueAsString());
-// origFile.append("/" + fileName);
+ // QString origFile = QString::fromStdString(orignalFilePath->GetValueAsString());
+ // origFile.append("/" + fileName);
// origFile.append(".stl");
// fileInfo.setFile(origFile);
// if (!fileInfo.exists())
// mitk::IOUtil::SaveSurface(surface, dir.path().toStdString());
// }
-// this->uploadFileToXnat(xnatFile, dir.path());
+ // this->uploadFileToXnat(xnatFile, dir.path());
}
}
void QmitkXnatTreeBrowserView::OnContextMenuRequested(const QPoint & pos)
{
m_ContextMenu->clear();
QAction* actRefreshItem = new QAction("Refresh", m_ContextMenu);
m_ContextMenu->addAction(actRefreshItem);
connect(actRefreshItem, SIGNAL(triggered()), this, SLOT(OnContextMenuRefreshItem()));
m_ContextMenu->popup(QCursor::pos());
QAction* actGetXNATURL = new QAction("Copy XNAT URL to clipboard", m_ContextMenu);
m_ContextMenu->addAction(actGetXNATURL);
connect(actGetXNATURL, SIGNAL(triggered()), this, SLOT(OnContextMenuCopyXNATUrlToClipboard()));
m_ContextMenu->addSeparator();
QModelIndex index = m_Controls.treeView->indexAt(pos);
ctkXnatObject* xnatObject = m_TreeModel->xnatObject(index);
bool downloadable = false;
downloadable |= dynamic_cast(xnatObject)!=NULL;
downloadable |= dynamic_cast(xnatObject)!=NULL;
downloadable |= dynamic_cast(xnatObject)!=NULL;
downloadable |= dynamic_cast(xnatObject)!=NULL;
downloadable |= dynamic_cast(xnatObject)!=NULL;
downloadable |= dynamic_cast(xnatObject)!=NULL;
downloadable |= dynamic_cast(xnatObject)!=NULL;
downloadable |= dynamic_cast(xnatObject)!=NULL;
bool canHaveResourceFolder = false;
canHaveResourceFolder |= dynamic_cast(xnatObject) != NULL;
canHaveResourceFolder |= dynamic_cast(xnatObject) != NULL;
canHaveResourceFolder |= dynamic_cast(xnatObject) != NULL;
bool uploadFilePossible = false;
uploadFilePossible |= dynamic_cast(xnatObject) != NULL;
uploadFilePossible |= dynamic_cast(xnatObject) != NULL;
uploadFilePossible |= dynamic_cast(xnatObject) != NULL;
if (downloadable)
{
QAction* actDownload = new QAction("Download", m_ContextMenu);
connect(actDownload, SIGNAL(triggered()), this, SLOT(OnContextMenuDownloadFile()));
m_ContextMenu->addAction(actDownload);
ctkXnatFile* file = dynamic_cast(xnatObject);
if (file)
{
QAction* actView = new QAction("Download and Open", m_ContextMenu);
connect(actView, SIGNAL(triggered()), this, SLOT(OnContextMenuDownloadAndOpenFile()));
m_ContextMenu->addAction(actView);
}
}
if (canHaveResourceFolder)
{
QAction* actCreateResource = new QAction("Add resource folder", m_ContextMenu);
connect(actCreateResource, SIGNAL(triggered()), this, SLOT(OnContextMenuCreateResourceFolder()));
m_ContextMenu->addAction(actCreateResource);
}
if (uploadFilePossible)
{
QAction* actUploadFile = new QAction("Upload File", m_ContextMenu);
connect(actUploadFile, SIGNAL(triggered()), this, SLOT(OnContextMenuUploadFile()));
m_ContextMenu->addAction(actUploadFile);
}
ctkXnatProject* project = dynamic_cast(xnatObject);
if (project != nullptr)
{
QAction* actCreateSubject = new QAction("Create new subject", m_ContextMenu);
m_ContextMenu->addAction(actCreateSubject);
connect(actCreateSubject, SIGNAL(triggered()), this, SLOT(OnContextMenuCreateNewSubject()));
m_ContextMenu->popup(QCursor::pos());
}
ctkXnatSubject* subject = dynamic_cast(xnatObject);
if (subject != nullptr)
{
QAction* actCreateExperiment = new QAction("Create new experiment", m_ContextMenu);
m_ContextMenu->addAction(actCreateExperiment);
connect(actCreateExperiment, SIGNAL(triggered()), this, SLOT(OnContextMenuCreateNewExperiment()));
m_ContextMenu->popup(QCursor::pos());
}
m_ContextMenu->popup(QCursor::pos());
}
+void QmitkXnatTreeBrowserView::CleanUp()
+{
+ m_Controls.wgtExperimentInfo->hide();
+ m_Controls.wgtSubjectInfo->hide();
+ m_Controls.wgtProjectInfo->hide();
+ m_Controls.btnCreateXnatFolder->setEnabled(false);
+ m_Controls.btnXnatDownload->setEnabled(false);
+ m_Controls.btnXnatUpload->setEnabled(false);
+}
+
void QmitkXnatTreeBrowserView::itemSelected(const QModelIndex& index)
{
QVariant variant = m_TreeModel->data(index, Qt::UserRole);
if (variant.isValid())
{
ctkXnatSession *session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetService(
- mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
ctkXnatObject* object = variant.value();
ctkXnatProject* project = dynamic_cast(object);
ctkXnatSubject* subject = dynamic_cast(object);
ctkXnatExperiment* experiment = dynamic_cast(object);
if (project != nullptr)
{
m_Controls.wgtExperimentInfo->hide();
m_Controls.wgtSubjectInfo->hide();
m_Controls.wgtProjectInfo->SetProject(project);
m_Controls.wgtProjectInfo->show();
}
else if (subject != nullptr)
{
QMap paramMap;
paramMap.insert("columns", "dob,gender,handedness,weight,height");
QUuid requestID = session->httpGet(QString("%1/subjects").arg(subject->parent()->resourceUri()), paramMap);
QList results = session->httpSync(requestID);
foreach(const QVariantMap& propertyMap, results)
{
QMapIterator it(propertyMap);
bool isConcretSubject = false;
if (it.hasNext())
{
it.next();
QVariant var = it.value();
// After CTK Change (subjectID = name) to (subjectID = ID)
// CHANGE TO: if (var == subject->property("ID"))
if (var == subject->property("URI").right(11))
{
isConcretSubject = true;
}
else
{
isConcretSubject = false;
}
it.toFront();
}
while (it.hasNext() && isConcretSubject)
{
it.next();
QString str = it.key().toLatin1().data();
QVariant var = it.value();
subject->setProperty(str, var);
}
}
m_Controls.wgtExperimentInfo->hide();
m_Controls.wgtProjectInfo->hide();
m_Controls.wgtSubjectInfo->SetSubject(subject);
m_Controls.wgtSubjectInfo->show();
}
else if (experiment != nullptr)
{
QMap paramMap;
paramMap.insert("columns", "date,time,scanner,modality");
QUuid requestID = session->httpGet(QString("%1/experiments").arg(experiment->parent()->resourceUri()), paramMap);
QList results = session->httpSync(requestID);
foreach(const QVariantMap& propertyMap, results)
{
QMapIterator it(propertyMap);
bool isConcretExperiment = false;
if (it.hasNext())
{
it.next();
QVariant var = it.value();
if (var == experiment->property("URI"))
{
isConcretExperiment = true;
}
else
{
isConcretExperiment = false;
}
it.toFront();
}
while (it.hasNext() && isConcretExperiment)
{
it.next();
QString str = it.key().toLatin1().data();
QVariant var = it.value();
experiment->setProperty(str, var);
}
}
m_Controls.wgtSubjectInfo->hide();
m_Controls.wgtProjectInfo->hide();
m_Controls.wgtExperimentInfo->SetExperiment(experiment);
m_Controls.wgtExperimentInfo->show();
}
}
}
void QmitkXnatTreeBrowserView::OnContextMenuCreateNewSubject()
{
QModelIndex index = m_Controls.treeView->currentIndex();
QVariant variant = m_TreeModel->data(index, Qt::UserRole);
if (variant.isValid())
{
QmitkXnatCreateObjectDialog* dialog = new QmitkXnatCreateObjectDialog(QmitkXnatCreateObjectDialog::SpecificType::SUBJECT);
if (dialog->exec() == QDialog::Accepted)
{
ctkXnatProject* project = dynamic_cast(variant.value());
ctkXnatSubject* subject = dynamic_cast(dialog->GetXnatObject());
subject->setParent(project);
subject->save();
// Get xnat session from micro service
ctkXnatSession* session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetService(
- mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
// Update View
m_TreeModel->removeDataModel(session->dataModel());
+
UpdateSession(session);
+
}
}
}
void QmitkXnatTreeBrowserView::OnContextMenuCreateNewExperiment()
{
QModelIndex index = m_Controls.treeView->currentIndex();
QVariant variant = m_TreeModel->data(index, Qt::UserRole);
if (variant.isValid())
{
QmitkXnatCreateObjectDialog* dialog = new QmitkXnatCreateObjectDialog(QmitkXnatCreateObjectDialog::SpecificType::EXPERIMENT);
if (dialog->exec() == QDialog::Accepted)
{
ctkXnatSubject* subject = dynamic_cast(variant.value());
ctkXnatExperiment* experiment = dynamic_cast(dialog->GetXnatObject());
experiment->setParent(subject);
experiment->setProperty("xsiType", experiment->imageModality());
experiment->save();
// Get xnat session from micro service
ctkXnatSession* session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetService(
- mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
+ mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference());
// Update View
m_TreeModel->removeDataModel(session->dataModel());
UpdateSession(session);
}
}
}
void QmitkXnatTreeBrowserView::SetStatusInformation(const QString& text)
{
m_Controls.groupBox->setTitle(text);
m_Controls.progressBar->setValue(0);
m_Controls.groupBox->show();
}
void QmitkXnatTreeBrowserView::sessionTimedOutMsg()
{
ctkXnatSession* session = qobject_cast(QObject::sender());
if (session == nullptr)
return;
ctkXnatDataModel* dataModel = session->dataModel();
m_TreeModel->removeDataModel(dataModel);
m_Controls.treeView->reset();
session->close();
- m_Controls.labelError->show();
QMessageBox::warning(m_Controls.treeView, "Session Timeout", "The session timed out.");
+
+ m_Controls.btnXnatConnect->setToolTip("Connect");
+ m_Controls.btnXnatConnect->setIcon(QIcon(":/xnat-plugin/xnat-connect.png"));
+
+ CleanUp();
}
void QmitkXnatTreeBrowserView::sessionTimesOutSoonMsg()
{
ctkXnatSession* session = qobject_cast(QObject::sender());
if (session == nullptr)
return;
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Warning);
msgBox.setWindowTitle("Session Timeout Soon");
msgBox.setText("The session will time out in 1 minute.\nDo you want to renew the session?");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
msgBox.show();
QTimer* timer = new QTimer(this);
timer->start(60000);
this->connect(timer, SIGNAL(timeout()), &msgBox, SLOT(reject()));
if (msgBox.exec() == QMessageBox::Yes){
session->renew();
}
timer->stop();
}
diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.h b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.h
index 88eae213bb..4b7a6978f3 100644
--- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.h
+++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.h
@@ -1,129 +1,135 @@
/*===================================================================
The Medical Imaging Interaction Toolkit (MITK)
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef QMITKXNATTREEBROWSERVIEW_H
#define QMITKXNATTREEBROWSERVIEW_H
#include
#include "ui_QmitkXnatTreeBrowserViewControls.h"
// ctkXnatCore
#include "ctkXnatSession.h"
// ctkXnatWidget
#include "QmitkXnatTreeModel.h"
// MitkXNAT Module
#include "mitkXnatSessionTracker.h"
#include
#include
#include
class QMenu;
/*!
\brief QmitkXnatTreeBrowserView
\warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation.
\sa QmitkFunctionality
\ingroup ${plugin_target}_internal
*/
class QmitkXnatTreeBrowserView : public QmitkAbstractView
{
// this is needed for all Qt objects that should have a Qt meta-object
// (everything that derives from QObject and wants to have signal/slots)
Q_OBJECT
public:
QmitkXnatTreeBrowserView();
~QmitkXnatTreeBrowserView();
static const QString VIEW_ID;
virtual void CreateQtPartControl(QWidget *parent) override;
protected slots:
/// \brief Opens or reuses the xnat editor with the activated node as root item.
void OnActivatedNode(const QModelIndex& index);
/// \brief Updates the ctkXnatSession and the user interface
void UpdateSession(ctkXnatSession* session);
/// \brief Cleans the tree model
void CleanTreeModel(ctkXnatSession* session);
void OnContextMenuRequested(const QPoint & pos);
void OnContextMenuDownloadAndOpenFile();
void OnContextMenuDownloadFile();
void OnContextMenuCreateResourceFolder();
void OnContextMenuUploadFile();
void OnContextMenuCreateNewSubject();
void OnContextMenuCreateNewExperiment();
void OnContextMenuCopyXNATUrlToClipboard();
void OnContextMenuRefreshItem();
void OnUploadResource(const QList& , ctkXnatObject *, const QModelIndex &parentIndex);
void OnProgress(QUuid, double);
void itemSelected(const QModelIndex& index);
void OnUploadFromDataStorage();
void sessionTimedOutMsg();
void sessionTimesOutSoonMsg();
+ void ToggleConnection();
+
protected:
virtual void SetFocus() override;
Ui::QmitkXnatTreeBrowserViewControls m_Controls;
private slots:
void OnXnatNodeSelected(const QModelIndex &index);
void OnDownloadSelectedXnatFile();
void OnCreateResourceFolder();
private:
void OnPreferencesChanged(const berry::IBerryPreferences*) override;
void InternalFileDownload(const QModelIndex& index, bool loadData);
void InternalDICOMDownload(ctkXnatObject* obj, QDir &DICOMDirPath);
void InternalFileUpload(ctkXnatFile *file);
ctkXnatResource* InternalAddResourceFolder(ctkXnatObject* parent);
void InternalOpenFiles(const QFileInfoList&, mitk::StringProperty::Pointer xnatURL);
void SetStatusInformation(const QString&);
+ void CleanUp();
+
ctkServiceTracker m_DataStorageServiceTracker;
QmitkXnatTreeModel* m_TreeModel;
mitk::XnatSessionTracker* m_Tracker;
QString m_DownloadPath;
QMenu* m_ContextMenu;
+
+ bool m_SilentMode;
};
#endif // QMITKXNATTREEBROWSERVIEW_H
diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserViewControls.ui b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserViewControls.ui
index d14a755b51..1a11790912 100644
--- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserViewControls.ui
+++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserViewControls.ui
@@ -1,191 +1,201 @@
QmitkXnatTreeBrowserViewControls
0
0
455
332
0
0
QmitkTemplate
- -
-
-
-
-
-
- Qt::AlignCenter
-
-
- 5
-
-
- 0
-
-
-
-
-
false
Upload to XNAT
:/xnat-plugin/xnat-upload.png:/xnat-plugin/xnat-upload.png
32
32
-
false
Download File
:/xnat-plugin/xnat-download.png:/xnat-plugin/xnat-download.png
32
32
-
false
Create Folder
:/xnat-plugin/xnat-folder.png:/xnat-plugin/xnat-folder.png
32
32
+ -
+
+
+ true
+
+
+ Connect
+
+
+
+
+
+
+ :/xnat-plugin/xnat-connect.png:/xnat-plugin/xnat-connect.png
+
+
+
+ 32
+ 32
+
+
+
+ false
+
+
+
-
Qt::Horizontal
40
20
+ -
+
+
-
+
+
+
+
-
Dowloading file ...
-
0
- -
-
-
-
-
-
-
-
-
-
-
-
QmitkXnatProjectWidget
QWidget
1
QmitkXnatSubjectWidget
QWidget
1
QmitkXnatExperimentWidget
QWidget
QmitkXnatExperimentWidget.h
1