diff --git a/Modules/XNAT/CMakeLists.txt b/Modules/XNAT/CMakeLists.txt index efb735587d..ca490d3bdd 100644 --- a/Modules/XNAT/CMakeLists.txt +++ b/Modules/XNAT/CMakeLists.txt @@ -1,4 +1,4 @@ -MITK_CREATE_MODULE( XNAT - PACKAGE_DEPENDS CTK Qt +MITK_CREATE_MODULE( + PACKAGE_DEPENDS Qt4 CTK EXPORT_DEFINE MITK_XNAT_EXPORT ) diff --git a/Modules/XNAT/files.cmake b/Modules/XNAT/files.cmake index a15795d20d..52882a49b5 100644 --- a/Modules/XNAT/files.cmake +++ b/Modules/XNAT/files.cmake @@ -1,8 +1,12 @@ SET(CPP_FILES mitkXnatSessionTracker.cpp ) SET(H_FILES mitkXnatSession.h mitkXnatSessionTracker.h ) + +SET(MOC_H_FILES + mitkXnatSessionTracker.h +) diff --git a/Modules/XNAT/mitkXnatSessionTracker.cpp b/Modules/XNAT/mitkXnatSessionTracker.cpp index cb14ddc031..f95e06b74c 100644 --- a/Modules/XNAT/mitkXnatSessionTracker.cpp +++ b/Modules/XNAT/mitkXnatSessionTracker.cpp @@ -1,26 +1,60 @@ /*=================================================================== 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 "mitkXnatSessionTracker.h" +#include "ctkXnatLoginProfile.h" + namespace mitk { -XnatSessionTracker::XnatSessionTracker(us::ModuleContext* context) - : Superclass(context), - m_context(context) -{} + XnatSessionTracker::XnatSessionTracker(us::ModuleContext* context) + : Superclass(context), + m_Context(context) + { + } + + void XnatSessionTracker::SessionOpened() + { + ctkXnatSession* session = dynamic_cast(QObject::sender()); + emit Opened(session); + } + + void XnatSessionTracker::SessionAboutToBeClosed() + { + ctkXnatSession* session = dynamic_cast(QObject::sender()); + emit AboutToBeClosed(session); + } + + ctkXnatSession* XnatSessionTracker::AddingService(const ServiceReferenceType &reference) + { + ctkXnatSession* session = Superclass::AddingService(reference); + if(session->isOpen()) + { + emit Opened(session); + } + connect( session, SIGNAL(sessionOpened()), this, SLOT(SessionOpened()) ); + connect( session, SIGNAL(sessionAboutToBeClosed()), this, SLOT(SessionAboutToBeClosed()) ); + + return session; + } + + void XnatSessionTracker::RemovedService(const ServiceReferenceType& reference, ctkXnatSession* tracked) + { + emit AboutToBeClosed(tracked); + Superclass::RemovedService(reference, tracked); + } } // end of namespace mitk diff --git a/Modules/XNAT/mitkXnatSessionTracker.h b/Modules/XNAT/mitkXnatSessionTracker.h index ba00af3547..63411bae35 100644 --- a/Modules/XNAT/mitkXnatSessionTracker.h +++ b/Modules/XNAT/mitkXnatSessionTracker.h @@ -1,55 +1,54 @@ /*=================================================================== 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 MITKXNATSESSIONTRACKER_H #define MITKXNATSESSIONTRACKER_H +#include "usServiceTracker.h" + +#include "MitkXNATExports.h" + #include "mitkXnatSession.h" -#include namespace mitk { -class MITK_XNAT_EXPORT XnatSessionTracker : public us::ServiceTracker, public QObject +class MITK_XNAT_EXPORT XnatSessionTracker : public QObject, public us::ServiceTracker { Q_OBJECT public: XnatSessionTracker(us::ModuleContext* context); - virtual void Open(); - virtual void Close(); - - public signals: - void Opened(XnatSession*); - void AboutToBeClosed(XnatSession*); - - private slots: - void SessionOpened(); - void SessionAboutToBeClosed(): +signals: + void Opened(ctkXnatSession*); + void AboutToBeClosed(ctkXnatSession*); private: - typedef us::ServiceTracker Superclass; + typedef us::ServiceTracker Superclass; us::ModuleContext* m_Context; virtual TrackedType AddingService(const ServiceReferenceType &reference); - virtual void RemovedService(const ServiceReferenceType& /*reference*/, TrackedType tracked); + virtual void RemovedService(const ServiceReferenceType& reference, TrackedType tracked); + private slots: + void SessionOpened(); + void SessionAboutToBeClosed(); }; } // end of namespace mitk #endif // MITKXNATSESSIONTRACKER_H diff --git a/Plugins/org.mitk.gui.qt.xnat/CMakeLists.txt b/Plugins/org.mitk.gui.qt.xnat/CMakeLists.txt index ca499ba9a5..c5be1b1de7 100644 --- a/Plugins/org.mitk.gui.qt.xnat/CMakeLists.txt +++ b/Plugins/org.mitk.gui.qt.xnat/CMakeLists.txt @@ -1,6 +1,7 @@ project(org_mitk_gui_qt_xnat) MACRO_CREATE_MITK_CTK_PLUGIN( + MODULE_DEPENDS MitkXNAT EXPORT_DIRECTIVE XNAT_EXPORT EXPORTED_INCLUDE_SUFFIXES src ) 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 9cce9ad577..1e94d44c0a 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePage.cpp +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePage.cpp @@ -1,237 +1,275 @@ /*=================================================================== 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 "org_mitk_gui_qt_xnatinterface_Activator.h" #include "berryIPreferencesService.h" #include "berryPlatform.h" #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) + : m_Control(0) { } void QmitkXnatConnectionPreferencePage::Init(berry::IWorkbench::Pointer ) { } void QmitkXnatConnectionPreferencePage::CreateQtControl(QWidget* parent) { IPreferencesService::Pointer prefService = Platform::GetServiceRegistry().GetServiceById(IPreferencesService::ID); berry::IPreferences::Pointer _XnatConnectionPreferencesNode = prefService->GetSystemPreferences()->Node("/XnatConnection"); 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()); + } + catch(std::invalid_argument) + { + session = 0; + } + + if(session != 0) + { + if(session->isOpen()) + { + m_Controls.testConnectionButton->setText("Disconnect"); + } + else + { + m_Controls.testConnectionButton->setText("Connect"); + } + } + const QIntValidator *portV = new QIntValidator(0, 65535, parent); m_Controls.inPort->setValidator(portV); const QRegExp hostRx("^(https?)://[^ /](\\S)+$"); const QRegExpValidator *hostV = new QRegExpValidator(hostRx, parent); m_Controls.inHostAddress->setValidator(hostV); - connect( m_Controls.testConnectionButton, SIGNAL(clicked()), this, SLOT(PerformTestConnection()) ); + connect( m_Controls.testConnectionButton, SIGNAL(clicked()), this, SLOT(ToggleConnection()) ); connect(m_Controls.inHostAddress, SIGNAL(editingFinished()), this, SLOT(UrlChanged())); connect(m_Controls.inDownloadPath, SIGNAL(editingFinished()), this, SLOT(DownloadPathChanged())); this->Update(); } QWidget* QmitkXnatConnectionPreferencePage::GetQtControl() const { return m_Control; } bool QmitkXnatConnectionPreferencePage::PerformOk() { - if(PerformTestConnection()) + if(!UserInformationEmpty()) { IPreferences::Pointer _XnatConnectionPreferencesNode = m_XnatConnectionPreferencesNode.Lock(); if(_XnatConnectionPreferencesNode.IsNotNull()) { _XnatConnectionPreferencesNode->Put(m_Controls.hostAddressLabel->text().toStdString(), m_Controls.inHostAddress->text().toStdString()); _XnatConnectionPreferencesNode->Put(m_Controls.portLabel->text().toStdString(), m_Controls.inPort->text().toStdString()); _XnatConnectionPreferencesNode->Put(m_Controls.usernameLabel->text().toStdString(), m_Controls.inUsername->text().toStdString()); _XnatConnectionPreferencesNode->Put(m_Controls.passwortLabel->text().toStdString(), m_Controls.inPassword->text().toStdString()); _XnatConnectionPreferencesNode->Put(m_Controls.downloadPathLabel->text().toStdString(), m_Controls.inDownloadPath->text().toStdString()); _XnatConnectionPreferencesNode->Flush(); - mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->UpdateXnatSession(); - return true; } } else { QMessageBox::critical(QApplication::activeWindow(), "Saving Preferences failed", - "Something with the connection parameters in XNAT Preferences is not ok.\nPlease use the 'Test Connection Button' to validate the connection parameters."); + "Something with the connection parameters in XNAT Preferences is not ok.\nPlease use the 'Connect' button to validate the connection parameters."); } return false; } void QmitkXnatConnectionPreferencePage::PerformCancel() { } -bool QmitkXnatConnectionPreferencePage::PerformTestConnection() +bool QmitkXnatConnectionPreferencePage::UserInformationEmpty() { - // To check if test is ok - bool testOk = false; - // To check empty QLineEdits in the following QString errString; if(m_Controls.inHostAddress->text().isEmpty()) { errString += "Server Address is empty.\n"; } if(m_Controls.inUsername->text().isEmpty()) { errString += "Username is empty.\n"; } if(m_Controls.inPassword->text().isEmpty()) { errString += "Password is empty.\n"; } // if something is empty if(!errString.isEmpty()) { m_Controls.testConnectionLabel->setStyleSheet("QLabel { color: red; }"); - m_Controls.testConnectionLabel->setText("Test connection failed.\n" + errString); + m_Controls.testConnectionLabel->setText("Connecting failed.\n" + errString); + return true; } else { - // Modelling the url - QUrl testUrl(m_Controls.inHostAddress->text()); - if(!m_Controls.inPort->text().isEmpty()) - { - testUrl.setPort(m_Controls.inPort->text().toInt()); - } - - // Set up the session for the connection test - ctkXnatLoginProfile profile; - profile.setName("Default"); - profile.setServerUrl(testUrl); - profile.setUserName(m_Controls.inUsername->text()); - profile.setPassword(m_Controls.inPassword->text()); - profile.setDefault(true); - ctkXnatSession* session = new ctkXnatSession(profile); - - // Testing the inputs by trying to create a session - try - { - session->open(); - - m_Controls.testConnectionLabel->setStyleSheet("QLabel { color: green; }"); - m_Controls.testConnectionLabel->setText("Test connection successful."); - testOk = true; - } - catch(const ctkXnatAuthenticationException& auth) - { - m_Controls.testConnectionLabel->setStyleSheet("QLabel { color: red; }"); - m_Controls.testConnectionLabel->setText("Test connection failed:\nAuthentication error."); - MITK_INFO << auth.message().toStdString(); - testOk = false; - } - catch(const ctkException& e) - { - m_Controls.testConnectionLabel->setStyleSheet("QLabel { color: red; }"); - m_Controls.testConnectionLabel->setText("Test connection failed:\nInvalid Server Adress"); - MITK_INFO << e.message().toStdString(); - testOk = false; - } - delete session; + return false; } - return testOk; } void QmitkXnatConnectionPreferencePage::Update() { IPreferences::Pointer _XnatConnectionPreferencesNode = m_XnatConnectionPreferencesNode.Lock(); if(_XnatConnectionPreferencesNode.IsNotNull()) { m_Controls.inHostAddress->setText(QString::fromStdString(_XnatConnectionPreferencesNode->Get( m_Controls.hostAddressLabel->text().toStdString(), m_Controls.inHostAddress->text().toStdString()))); m_Controls.inPort->setText(QString::fromStdString(_XnatConnectionPreferencesNode->Get( m_Controls.portLabel->text().toStdString(), m_Controls.inPort->text().toStdString()))); m_Controls.inUsername->setText(QString::fromStdString(_XnatConnectionPreferencesNode->Get( m_Controls.usernameLabel->text().toStdString(), m_Controls.inUsername->text().toStdString()))); m_Controls.inPassword->setText(QString::fromStdString(_XnatConnectionPreferencesNode->Get( m_Controls.passwortLabel->text().toStdString(), m_Controls.inPassword->text().toStdString()))); m_Controls.inDownloadPath->setText(QString::fromStdString(_XnatConnectionPreferencesNode->Get( m_Controls.downloadPathLabel->text().toStdString(), m_Controls.inDownloadPath->text().toStdString()))); } } void QmitkXnatConnectionPreferencePage::UrlChanged() { m_Controls.inHostAddress->setStyleSheet("QLineEdit { background-color: white; }"); QString str = m_Controls.inHostAddress->text(); while(str.endsWith("/")) { str = str.left(str.length()-1); } m_Controls.inHostAddress->setText(str); QUrl url(m_Controls.inHostAddress->text()); if(!url.isValid()) { m_Controls.inHostAddress->setStyleSheet("QLineEdit { background-color: red; }"); } } void QmitkXnatConnectionPreferencePage::DownloadPathChanged() { m_Controls.inDownloadPath->setStyleSheet("QLineEdit { background-color: white; }"); if(!m_Controls.inDownloadPath->text().isEmpty()) { QFileInfo path(m_Controls.inDownloadPath->text()); if(!path.isDir()) { m_Controls.inDownloadPath->setStyleSheet("QLineEdit { background-color: red; }"); } } } + +void QmitkXnatConnectionPreferencePage::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(!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()); + } + } + + if(session != 0 && session->isOpen()) + { + mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->CloseXnatSession(); + m_Controls.testConnectionButton->setText("Connect"); + m_Controls.testConnectionLabel->clear(); + } + else if(session != 0 && !session->isOpen()) + { + m_Controls.testConnectionButton->setEnabled(false); + + try + { + mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->OpenXnatSession(); + } + catch(const ctkXnatAuthenticationException& auth) + { + m_Controls.testConnectionLabel->setStyleSheet("QLabel { color: red; }"); + m_Controls.testConnectionLabel->setText("Connecting failed:\nAuthentication error."); + MITK_ERROR << auth.message().toStdString(); + } + catch(const ctkXnatException& xnatEx) + { + MITK_ERROR << xnatEx.message().toStdString(); + } + catch(const ctkException& e) + { + m_Controls.testConnectionLabel->setStyleSheet("QLabel { color: red; }"); + m_Controls.testConnectionLabel->setText("Connecting failed:\nInvalid Server Adress"); + MITK_ERROR << e.message().toStdString(); + } + m_Controls.testConnectionButton->setText("Disconnect"); + m_Controls.testConnectionButton->setEnabled(true); + m_Controls.testConnectionLabel->setStyleSheet("QLabel { color: green; }"); + m_Controls.testConnectionLabel->setText("Connecting successful."); + } +} 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 a6a6704bb6..5368df231e 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePage.h +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePage.h @@ -1,77 +1,84 @@ /*=================================================================== 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); void CreateQtControl(QWidget* widget); QWidget* GetQtControl() const; /// /// \see IPreferencePage::PerformOk() /// virtual bool PerformOk(); /// /// \see IPreferencePage::PerformCancel() /// virtual void PerformCancel(); /// /// \see IPreferencePage::Update() /// virtual void Update(); protected slots: virtual void UrlChanged(); virtual void DownloadPathChanged(); /// - /// Creates a test connection to the entered server name with the entered user information. + /// Toggles the Connection in the Service Registry from opened to closed or the other way around. /// - virtual bool PerformTestConnection(); + virtual void ToggleConnection(); 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 4f55e5211f..9b26a9b683 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePageControls.ui +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatConnectionPreferencePageControls.ui @@ -1,143 +1,143 @@ QmitkXnatConnectionPreferencePageControls 0 0 742 208 0 0 653 116 16777215 16777215 Form Port <html><head/><body><p>Examples:</p><p>https://central.xnat.org<br/>http://localhost/xnat</p></body></html> http(s):// 50 16777215 Standard-Port: 80 Username testuser Server Address Password QLineEdit::Password testpassword Download Path - Test Connection + Connect Qt::LeftToRight 1 Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditor.cpp b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditor.cpp index 989dbb8a71..dd7c8b9970 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditor.cpp +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatEditor.cpp @@ -1,482 +1,482 @@ /*=================================================================== 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 "QmitkXnatEditor.h" // Qmitk #include "QmitkXnatObjectEditorInput.h" #include "org_mitk_gui_qt_xnatinterface_Activator.h" // CTK XNAT Core #include "ctkXnatObject.h" #include "ctkXnatDataModel.h" #include "ctkXnatScanFolder.h" #include "ctkXnatFile.h" // CTK XNAT Widgets #include "ctkXnatListModel.h" // Blueberry #include #include // Qt #include #include #include #include #include // MITK #include #include const std::string QmitkXnatEditor::EDITOR_ID = "org.mitk.editors.xnat.browser"; QmitkXnatEditor::QmitkXnatEditor() : m_DataStorageServiceTracker(mitk::org_mitk_gui_qt_xnatinterface_Activator::GetContext()), m_Session(0), m_ListModel(new ctkXnatListModel()), m_SelectionListener(new berry::SelectionChangedAdapter(this, &QmitkXnatEditor::SelectionChanged)), m_DownloadPath(berry::Platform::GetServiceRegistry(). GetServiceById(berry::IPreferencesService::ID)-> GetSystemPreferences()->Node("/XnatConnection")->Get("Download Path", "").c_str()) { m_DataStorageServiceTracker.open(); 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() + "/"; } } QmitkXnatEditor::~QmitkXnatEditor() { delete m_ListModel; berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); s->RemoveSelectionListener(m_SelectionListener); m_DataStorageServiceTracker.close(); } bool QmitkXnatEditor::IsDirty() const { return false; } bool QmitkXnatEditor::IsSaveAsAllowed() const { return false; } void QmitkXnatEditor::Init(berry::IEditorSite::Pointer site, berry::IEditorInput::Pointer input) { this->SetSite(site); berry::QtEditorPart::SetInput(input); this->SetInput(input); } void QmitkXnatEditor::DoSave() { } void QmitkXnatEditor::DoSaveAs() { } void QmitkXnatEditor::SetInput(berry::IEditorInput::Pointer input) { QmitkXnatObjectEditorInput::Pointer oPtr = input.Cast(); if(oPtr.IsNotNull()) { berry::QtEditorPart::SetInput(oPtr); this->GetEditorInput().Cast()->GetXnatObject()->fetch(); } } void QmitkXnatEditor::SetFocus() { } void QmitkXnatEditor::CreateQtPartControl( QWidget *parent ) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddSelectionListener(m_SelectionListener); connect( m_Controls.treeView, SIGNAL(activated(const QModelIndex&)), this, SLOT(OnObjectActivated(const QModelIndex&)) ); connect( m_Controls.buttonDownloadResource, SIGNAL(clicked()), this, SLOT(DownloadResource()) ); connect( m_Controls.buttonDownloadFile, SIGNAL(clicked()), this, SLOT(DownloadFile()) ); connect( m_Controls.buttonDataModel, SIGNAL(clicked()), this, SLOT(OnDataModelButtonClicked()) ); connect( m_Controls.buttonProject, SIGNAL(clicked()), this, SLOT(OnProjectButtonClicked()) ); connect( m_Controls.buttonSubject, SIGNAL(clicked()), this, SLOT(OnSubjectButtonClicked()) ); connect( m_Controls.buttonExperiment, SIGNAL(clicked()), this, SLOT(OnExperimentButtonClicked()) ); connect( m_Controls.buttonKindOfData, SIGNAL(clicked()), this, SLOT(OnKindOfDataButtonClicked()) ); connect( m_Controls.buttonSession, SIGNAL(clicked()), this, SLOT(OnSessionButtonClicked()) ); connect( m_Controls.buttonResource, SIGNAL(clicked()), this, SLOT(OnResourceButtonClicked()) ); // Makes the breadcrumb feature invisible for(int i = 0; i < m_Controls.breadcrumbHorizontalLayout->count()-1; i++) { QLayoutItem* child = m_Controls.breadcrumbHorizontalLayout->itemAt(i); child->widget()->setVisible(false); } for(int i = 0; i < m_Controls.breadcrumbDescriptionLayout->count()-1; i++) { QLayoutItem* child = m_Controls.breadcrumbDescriptionLayout->itemAt(i); child->widget()->setVisible(false); } QmitkXnatObjectEditorInput::Pointer oPtr = GetEditorInput().Cast(); if(oPtr.IsNotNull()) { UpdateList(); } else { - UpdateSession(); + //UpdateSession(); } } void QmitkXnatEditor::UpdateList() { QmitkXnatObjectEditorInput::Pointer xoPtr(GetEditorInput().Cast()); if( xoPtr.IsNull() ) return; ctkXnatObject* inputObject = xoPtr->GetXnatObject(); if( inputObject == NULL ) return; m_Controls.treeView->setModel(m_ListModel); m_ListModel->setRootObject( inputObject ); m_Controls.treeView->reset(); // recursive method to check parents of the inputObject m_ParentCount = ParentChecker(inputObject); // breadcrumb labels for(int i = 0; i < m_Controls.breadcrumbHorizontalLayout->count()-1; i++) { QLayoutItem* child = m_Controls.breadcrumbHorizontalLayout->itemAt(i); child->widget()->setVisible(false); } for(int i = 0; i < m_Controls.breadcrumbDescriptionLayout->count()-1; i++) { QLayoutItem* child = m_Controls.breadcrumbDescriptionLayout->itemAt(i); child->widget()->setVisible(false); } ctkXnatObject* parent = NULL; for(int i = m_ParentCount*2; i >= 0; i--) { if(i > 12) break; m_Controls.breadcrumbDescriptionLayout->itemAt(i)->widget()->setVisible(true); QLayoutItem* child = m_Controls.breadcrumbHorizontalLayout->itemAt(i); child->widget()->setVisible(true); if(i>0) { m_Controls.breadcrumbHorizontalLayout->itemAt(i-1)->widget()->setVisible(true); m_Controls.breadcrumbDescriptionLayout->itemAt(i-1)->widget()->setVisible(true); } if(parent == NULL) { parent = inputObject; } // create breadcrumb button QPushButton* breadcrumbButton = dynamic_cast(child->widget()); breadcrumbButton->setText(parent->id()); parent = parent->parent(); i--; } m_Controls.buttonDataModel->setText("root"); } void QmitkXnatEditor::SelectionChanged(berry::IWorkbenchPart::Pointer sourcepart, berry::ISelection::ConstPointer selection) { // check for null selection if (selection.IsNull()) { return; } // exclude own selection events and check whether this kind of selection can be handled if (sourcepart != this && selection.Cast()) { berry::IStructuredSelection::ConstPointer currentSelection = selection.Cast(); // iterates over the selection for (berry::IStructuredSelection::iterator itr = currentSelection->Begin(); itr != currentSelection->End(); ++itr) { if (berry::SmartPointer objectPointer = itr->Cast()) { // get object of selected ListWidgetElement ctkXnatObject* object = objectPointer->GetQModelIndex().data(Qt::UserRole).value(); // if a file is selected, don't change the input and list view if ( dynamic_cast(object) == NULL ) { QmitkXnatObjectEditorInput::Pointer oPtr = QmitkXnatObjectEditorInput::New( object ); berry::IEditorInput::Pointer editorInput( oPtr ); if ( !(editorInput == this->GetEditorInput()) ) this->SetInput(editorInput); UpdateList(); } } } } } void QmitkXnatEditor::DownloadResource() { if (!m_Controls.treeView->selectionModel()->hasSelection()) return; const QModelIndex index = m_Controls.treeView->selectionModel()->currentIndex(); QVariant variant = m_ListModel->data(index, Qt::UserRole); if ( variant.isValid() ) { ctkXnatScanFolder* resource = dynamic_cast(variant.value()); if (resource != NULL) { MITK_INFO << "Download started ..."; MITK_INFO << "..."; QString resourcePath = m_DownloadPath + resource->id() + ".zip"; resource->download(resourcePath); // Testing if the path exists QDir downDir(m_DownloadPath); if( downDir.exists(resource->id() + ".zip") ) { MITK_INFO << "Download of " << resource->id().toStdString() << ".zip was completed!"; } else { MITK_INFO << "Download of " << resource->id().toStdString() << ".zip failed!"; } } else { MITK_INFO << "Selection was not a resource folder!"; } } } void QmitkXnatEditor::DownloadFile() { if (!m_Controls.treeView->selectionModel()->hasSelection()) return; const QModelIndex index = m_Controls.treeView->selectionModel()->currentIndex(); InternalFileDownload(index); } void QmitkXnatEditor::ToHigherLevel() { ctkXnatObject* parent = GetEditorInput().Cast()->GetXnatObject()->parent(); if( parent == NULL) { return; } QmitkXnatObjectEditorInput::Pointer oPtr = QmitkXnatObjectEditorInput::New( parent ); berry::IEditorInput::Pointer editorInput( oPtr ); this->SetInput(editorInput); UpdateList(); } void QmitkXnatEditor::OnObjectActivated(const QModelIndex &index) { if (!index.isValid()) return; ctkXnatObject* child = GetEditorInput().Cast()->GetXnatObject()->children().at(index.row()); if( child != NULL ) { ctkXnatFile* file = dynamic_cast(child); if( file != NULL ) { // Download file and put into datamanager InternalFileDownload(index); mitk::IDataStorageService* dsService = m_DataStorageServiceTracker.getService(); if(dsService != NULL) { mitk::DataNode::Pointer node = mitk::IOUtil::LoadDataNode((m_DownloadPath + file->id()).toStdString()); if ( ( node.IsNotNull() ) && ( node->GetData() != NULL ) ) { dsService->GetDataStorage()->GetDataStorage()->Add(node); mitk::BaseData::Pointer basedata = node->GetData(); mitk::RenderingManager::GetInstance()->InitializeViews( basedata->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); } } } else { // Updates the root item QmitkXnatObjectEditorInput::Pointer oPtr = QmitkXnatObjectEditorInput::New( child ); berry::IEditorInput::Pointer editorInput( oPtr ); this->SetInput(editorInput); this->GetEditorInput().Cast()->GetXnatObject()->fetch(); UpdateList(); } } } void QmitkXnatEditor::InternalFileDownload(const QModelIndex& index) { QVariant variant = m_ListModel->data(index, Qt::UserRole); if ( variant.isValid() ) { ctkXnatFile* file = dynamic_cast(variant.value()); if (file != NULL) { MITK_INFO << "Download started ..."; MITK_INFO << "..."; QString filePath = m_DownloadPath + file->id(); file->download(filePath); // Testing if the file exists QDir downDir(m_DownloadPath); if( downDir.exists(file->id()) ) { MITK_INFO << "Download of " << file->id().toStdString() << " was completed!"; } else { MITK_INFO << "Download of " << file->id().toStdString() << " failed!"; } } else { MITK_INFO << "Selection was not a file!"; } } } int QmitkXnatEditor::ParentChecker(ctkXnatObject* child) { int sum; if( child->parent() == NULL ) { return 0; } else { sum = 1 + ParentChecker(child->parent()); } return sum; } void QmitkXnatEditor::OnDataModelButtonClicked() { for(int i = m_ParentCount; i > 0; i--) { ToHigherLevel(); } } void QmitkXnatEditor::OnProjectButtonClicked() { for(int i = m_ParentCount-1; i > 0; i--) { ToHigherLevel(); } } void QmitkXnatEditor::OnSubjectButtonClicked() { for(int i = m_ParentCount-2; i > 0; i--) { ToHigherLevel(); } } void QmitkXnatEditor::OnExperimentButtonClicked() { for(int i = m_ParentCount-3; i > 0; i--) { ToHigherLevel(); } } void QmitkXnatEditor::OnKindOfDataButtonClicked() { for(int i = m_ParentCount-4; i > 0; i--) { ToHigherLevel(); } } void QmitkXnatEditor::OnSessionButtonClicked() { for(int i = m_ParentCount-5; i > 0; i--) { ToHigherLevel(); } } void QmitkXnatEditor::OnResourceButtonClicked() { for(int i = m_ParentCount-6; i > 0; i--) { ToHigherLevel(); } } void QmitkXnatEditor::UpdateSession() { GetSite()->GetWorkbenchWindow()->GetSelectionService()->RemoveSelectionListener(m_SelectionListener); if(m_Session != 0 && m_Session->isOpen()) { m_ListModel->setRootObject(NULL); m_Controls.treeView->reset(); } - // Get the XNAT Session from Activator - m_Session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->GetXnatSession(); + // Get the XNAT Session from Activator <== CHANGED TO MICRO SERVICE + //m_Session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->GetXnatSession(); if(m_Session != NULL) { m_Controls.labelInfo->setText("Current Position:"); m_Controls.labelInfo->setStyleSheet("QLabel { color: black; }"); m_Controls.buttonDownloadFile->setEnabled(true); m_Controls.buttonDownloadResource->setEnabled(true); connect( this->m_Session, SIGNAL(aboutToBeClosed()), this, SLOT(UpdateSession()) ); // Fill model and show in the GUI QmitkXnatObjectEditorInput::Pointer xoPtr = QmitkXnatObjectEditorInput::New( m_Session->dataModel() ); berry::IEditorInput::Pointer editorInput( xoPtr ); this->SetInput(editorInput); this->GetEditorInput().Cast()->GetXnatObject()->fetch(); UpdateList(); } else { m_Controls.labelInfo->setText("Please check the Preferences of the XNAT Connection.\nMaybe they are not ok. Close and reopen the tab."); m_Controls.labelInfo->setStyleSheet("QLabel { color: red; }"); m_Controls.buttonDownloadFile->setEnabled(false); m_Controls.buttonDownloadResource->setEnabled(false); } GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddSelectionListener(m_SelectionListener); } diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatSessionManager.cpp b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatSessionManager.cpp index 575d78396e..5acee875b1 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatSessionManager.cpp +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatSessionManager.cpp @@ -1,83 +1,90 @@ /*=================================================================== 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 "QmitkXnatSessionManager.h" +#include "org_mitk_gui_qt_xnatinterface_Activator.h" + #include "berryPlatform.h" #include "berryIPreferences.h" #include "mitkLogMacros.h" #include #include +#include "ctkXnatSession.h" #include "ctkXnatException.h" - -QmitkXnatSessionManager::QmitkXnatSessionManager() : - m_Session(0) +QmitkXnatSessionManager::QmitkXnatSessionManager() { m_PreferencesService = berry::Platform::GetServiceRegistry(). GetServiceById(berry::IPreferencesService::ID); - - UpdateXnatSession(); } QmitkXnatSessionManager::~QmitkXnatSessionManager() { - delete m_Session; + CloseXnatSession(); } -ctkXnatSession* QmitkXnatSessionManager::GetXnatSession() +void QmitkXnatSessionManager::OpenXnatSession() { - if(m_Session == NULL) return NULL; + us::ServiceReference ref = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference(); + ctkXnatSession* session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetService(ref); + if(session == NULL) return; - if(!m_Session->isOpen()) + if(!session->isOpen()) { try { - m_Session->open(); + session->open(); } catch(const ctkException& e) { - MITK_ERROR << "Just look if your XNAT preferences are ok. Maybe the server is not running.\nTry to use 'Test Connection' funktionality.\n" << e.message().toStdString(); - return NULL; + QMessageBox::critical(QApplication::activeWindow(), "Failed to open Session", + "Something with the connection parameters in XNAT Preferences is not ok."); + MITK_ERROR << "Just look if your XNAT preferences are ok. Maybe the server is not running.\n" << e.message().toStdString(); } } - return m_Session; } -void QmitkXnatSessionManager::UpdateXnatSession() +void QmitkXnatSessionManager::CreateXnatSession() { - if(m_Session != 0) - { - m_Session->deleteLater(); - } - berry::IPreferencesService::Pointer prefService = m_PreferencesService.Lock(); berry::IPreferences::Pointer nodeConnectionPref = prefService->GetSystemPreferences()->Node("/XnatConnection"); QUrl url(QString::fromStdString(nodeConnectionPref->Get("Server Address", ""))); url.setPort(QString::fromStdString(nodeConnectionPref->Get("Port", "")).toInt()); ctkXnatLoginProfile profile; profile.setName("Default"); profile.setServerUrl(url); profile.setUserName(QString::fromStdString(nodeConnectionPref->Get("Username", ""))); profile.setPassword(QString::fromStdString(nodeConnectionPref->Get("Password", ""))); profile.setDefault(true); - m_Session = new ctkXnatSession(profile); + ctkXnatSession* session = new ctkXnatSession(profile); + + m_SessionRegistration = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->RegisterService(session); +} + +void QmitkXnatSessionManager::CloseXnatSession() +{ + us::ServiceReference ref = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetServiceReference(); + ctkXnatSession* session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()->GetService(ref); + session->close(); + m_SessionRegistration.Unregister(); + delete session; } diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatSessionManager.h b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatSessionManager.h index fdfa459a75..1442f6eb49 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatSessionManager.h +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatSessionManager.h @@ -1,47 +1,53 @@ /*=================================================================== 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 QMITKXNATSESSIONMANAGER_H_ #define QMITKXNATSESSIONMANAGER_H_ #include -#include "ctkXnatSession.h" #include "ctkXnatLoginProfile.h" +#include "mitkXnatSessionTracker.h" + class QmitkXnatSessionManager { public: QmitkXnatSessionManager(); ~QmitkXnatSessionManager(); /// \brief Opens a xnat session. - ctkXnatSession* GetXnatSession(); + void OpenXnatSession(); + + /// \brief Creates the xnat session. + void CreateXnatSession(); + + void CloseXnatSession(); - /// \brief Updates the xnat session. - void UpdateXnatSession(); + bool LastSessionIsValid(); + int AmountOfCreatedSessions(); private: - ctkXnatSession* m_Session; + us::ServiceRegistration m_SessionRegistration; berry::IPreferencesService::WeakPtr m_PreferencesService; }; #endif /*QMITKXNATSESSIONMANAGER_H_*/ 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 9f3b718a7d..7ae25ab6b7 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.cpp +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.cpp @@ -1,145 +1,161 @@ /*=================================================================== 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 "QmitkXnatObjectEditorInput.h" #include "QmitkXnatEditor.h" #include "org_mitk_gui_qt_xnatinterface_Activator.h" // Blueberry #include // CTK XNAT Core #include "ctkXnatFile.h" const std::string QmitkXnatTreeBrowserView::VIEW_ID = "org.mitk.views.xnat.treebrowser"; QmitkXnatTreeBrowserView::QmitkXnatTreeBrowserView(): - m_Session(0), - m_TreeModel(new ctkXnatTreeModel()) + m_TreeModel(new ctkXnatTreeModel()), + m_Tracker(0) { } QmitkXnatTreeBrowserView::~QmitkXnatTreeBrowserView() { delete m_TreeModel; + delete m_Tracker; } void QmitkXnatTreeBrowserView::SetFocus() { } 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.labelError->setText("Please check the Preferences of the XNAT Connection.\nMaybe they are not ok."); + m_Controls.labelError->setText("Please use the 'Connect' button in the Preferences."); m_Controls.labelError->setStyleSheet("QLabel { color: red; }"); m_SelectionProvider = new berry::QtSelectionProvider(); this->SetSelectionProvider(); m_Controls.treeView->setSelectionMode(QAbstractItemView::SingleSelection); - UpdateSession(); + m_Tracker = new mitk::XnatSessionTracker(mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext()); - if(m_Session == 0) + 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()); + } + catch(std::invalid_argument) + { + session = 0; + } + + if(session != 0) { - m_Controls.labelError->show(); - return; + m_Controls.labelError->setVisible(false); } else { - m_Controls.labelError->hide(); + m_Controls.labelError->setVisible(true); } connect( m_Controls.treeView, SIGNAL(activated(const QModelIndex&)), this, SLOT(OnActivatedNode(const QModelIndex&)) ); } void QmitkXnatTreeBrowserView::OnActivatedNode(const QModelIndex& index) { if (!index.isValid()) return; berry::IWorkbenchPage::Pointer page = GetSite()->GetPage(); QmitkXnatObjectEditorInput::Pointer oPtr = QmitkXnatObjectEditorInput::New( index.data(Qt::UserRole).value() ); berry::IEditorInput::Pointer editorInput( oPtr ); berry::IEditorPart::Pointer reuseEditor = page->FindEditor(editorInput); if(reuseEditor) { // Just set it activ page->Activate(reuseEditor); } else { std::vector editors = page->FindEditors(berry::IEditorInput::Pointer(0), QmitkXnatEditor::EDITOR_ID, berry::IWorkbenchPage::MATCH_ID); if (editors.empty()) { // No XnatEditor is currently open, create a new one ctkXnatFile* file = dynamic_cast(oPtr->GetXnatObject()); if(file != NULL) { // If a file is activated take the parent and open a new editor QmitkXnatObjectEditorInput::Pointer oPtr2 = QmitkXnatObjectEditorInput::New( file->parent() ); berry::IEditorInput::Pointer editorInput2( oPtr2 ); page->OpenEditor(editorInput2, QmitkXnatEditor::EDITOR_ID); } else { page->OpenEditor(editorInput, QmitkXnatEditor::EDITOR_ID); } } else { // Reuse an existing editor reuseEditor = editors.front()->GetEditor(true); page->ReuseEditor(reuseEditor.Cast(), editorInput); page->Activate(reuseEditor); } } } void QmitkXnatTreeBrowserView::SetSelectionProvider() { GetSite()->SetSelectionProvider(m_SelectionProvider); } -void QmitkXnatTreeBrowserView::UpdateSession() +void QmitkXnatTreeBrowserView::UpdateSession(ctkXnatSession* session) { - if(m_Session != 0 && m_Session->isOpen()) + if(session != 0 && session->isOpen()) { - m_TreeModel->removeDataModel(m_Session->dataModel()); + m_Controls.labelError->setVisible(false); + // Fill model and show in the GUI + m_TreeModel->addDataModel(session->dataModel()); m_Controls.treeView->reset(); + m_SelectionProvider->SetItemSelectionModel(m_Controls.treeView->selectionModel()); } +} - // Get the XNAT Session from Activator - m_Session = mitk::org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager()->GetXnatSession(); - - if(m_Session != NULL) +void QmitkXnatTreeBrowserView::CleanTreeModel(ctkXnatSession* session) +{ + if(session != 0) { - connect( this->m_Session, SIGNAL(aboutToBeClosed()), this, SLOT(UpdateSession()) ); - - // Fill model and show in the GUI - m_TreeModel->addDataModel(m_Session->dataModel()); + m_TreeModel->removeDataModel(session->dataModel()); m_Controls.treeView->reset(); - m_SelectionProvider->SetItemSelectionModel(m_Controls.treeView->selectionModel()); } } 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 d479113692..502d4b2a11 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.h +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserView.h @@ -1,78 +1,84 @@ /*=================================================================== 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 #include "ui_QmitkXnatTreeBrowserViewControls.h" // ctkXnatCore #include "ctkXnatSession.h" // ctkXnatWidget #include "ctkXnatTreeModel.h" +// MitkXNAT Module +#include "mitkXnatSessionTracker.h" + /*! \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 std::string VIEW_ID; virtual void CreateQtPartControl(QWidget *parent); 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(); + void UpdateSession(ctkXnatSession* session); + + /// \brief Cleans the tree model + void CleanTreeModel(ctkXnatSession* session); protected: virtual void SetFocus(); Ui::QmitkXnatTreeBrowserViewControls m_Controls; private: berry::QtSelectionProvider::Pointer m_SelectionProvider; void SetSelectionProvider(); - ctkXnatSession* m_Session; ctkXnatTreeModel* m_TreeModel; + mitk::XnatSessionTracker* m_Tracker; }; #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 2412175a3d..326b50c01a 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserViewControls.ui +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/QmitkXnatTreeBrowserViewControls.ui @@ -1,42 +1,54 @@ QmitkXnatTreeBrowserViewControls 0 0 455 975 0 0 QmitkTemplate + + 0 + + + Qt::AlignCenter + + + 5 + + + 0 + diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/org_mitk_gui_qt_xnatinterface_Activator.cpp b/Plugins/org.mitk.gui.qt.xnat/src/internal/org_mitk_gui_qt_xnatinterface_Activator.cpp index 8792aaaa78..d292f2425f 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/org_mitk_gui_qt_xnatinterface_Activator.cpp +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/org_mitk_gui_qt_xnatinterface_Activator.cpp @@ -1,57 +1,71 @@ /*=================================================================== 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 "org_mitk_gui_qt_xnatinterface_Activator.h" #include #include "QmitkXnatEditor.h" #include "QmitkXnatTreeBrowserView.h" #include "QmitkXnatConnectionPreferencePage.h" +#include +#include + +US_INITIALIZE_MODULE("MitkXNAT", "MitkXNAT") + namespace mitk { ctkPluginContext* org_mitk_gui_qt_xnatinterface_Activator::m_Context = 0; +us::ModuleContext* org_mitk_gui_qt_xnatinterface_Activator::m_ModuleContext = 0; QmitkXnatSessionManager* org_mitk_gui_qt_xnatinterface_Activator::GetXnatSessionManager() { static QmitkXnatSessionManager manager; return &manager; } ctkPluginContext* org_mitk_gui_qt_xnatinterface_Activator::GetContext() { return m_Context; } +us::ModuleContext* org_mitk_gui_qt_xnatinterface_Activator::GetXnatModuleContext() +{ + return m_ModuleContext; +} + void org_mitk_gui_qt_xnatinterface_Activator::start(ctkPluginContext* context) { this->m_Context = context; + this->m_ModuleContext = us::GetModuleContext(); BERRY_REGISTER_EXTENSION_CLASS(QmitkXnatEditor, context) BERRY_REGISTER_EXTENSION_CLASS(QmitkXnatTreeBrowserView, context) BERRY_REGISTER_EXTENSION_CLASS(QmitkXnatConnectionPreferencePage, context) } void org_mitk_gui_qt_xnatinterface_Activator::stop(ctkPluginContext* context) { Q_UNUSED(context) + Q_UNUSED(us::GetModuleContext()) this->m_Context = 0; + this->m_ModuleContext = 0; } } Q_EXPORT_PLUGIN2(org_mitk_gui_qt_xnatinterface, mitk::org_mitk_gui_qt_xnatinterface_Activator) diff --git a/Plugins/org.mitk.gui.qt.xnat/src/internal/org_mitk_gui_qt_xnatinterface_Activator.h b/Plugins/org.mitk.gui.qt.xnat/src/internal/org_mitk_gui_qt_xnatinterface_Activator.h index 72b524c6d3..29b284430c 100644 --- a/Plugins/org.mitk.gui.qt.xnat/src/internal/org_mitk_gui_qt_xnatinterface_Activator.h +++ b/Plugins/org.mitk.gui.qt.xnat/src/internal/org_mitk_gui_qt_xnatinterface_Activator.h @@ -1,48 +1,50 @@ /*=================================================================== 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 org_mitk_gui_qt_xnatinterface_Activator_h #define org_mitk_gui_qt_xnatinterface_Activator_h #include #include "QmitkXnatSessionManager.h" namespace mitk { class org_mitk_gui_qt_xnatinterface_Activator : public QObject, public ctkPluginActivator { Q_OBJECT Q_INTERFACES(ctkPluginActivator) public: static QmitkXnatSessionManager* GetXnatSessionManager(); static ctkPluginContext* GetContext(); + static us::ModuleContext* GetXnatModuleContext(); void start(ctkPluginContext* context); void stop(ctkPluginContext* context); private: static ctkPluginContext* m_Context; + static us::ModuleContext* m_ModuleContext; }; // org_mitk_gui_qt_xnatinterface_Activator } #endif // org_mitk_gui_qt_xnatinterface_Activator_h