diff --git a/Plugins/org.mitk.gui.qt.xnatinterface/src/internal/XNATProjects.cpp b/Plugins/org.mitk.gui.qt.xnatinterface/src/internal/XNATProjects.cpp index f252def372..c09c52e5ae 100644 --- a/Plugins/org.mitk.gui.qt.xnatinterface/src/internal/XNATProjects.cpp +++ b/Plugins/org.mitk.gui.qt.xnatinterface/src/internal/XNATProjects.cpp @@ -1,325 +1,365 @@ /*=================================================================== 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. ===================================================================*/ // Qmitk #include "XNATProjects.h" // Standard #include #include #include // CTK Widgets //#include "ctkXnatLoginDialog.h" // CTK Core #include "ctkXnatServer.h" #include "ctkXnatConnectionFactory.h" #include "ctkXnatConnection.h" #include "ctkXnatProject.h" #include "ctkXnatSubject.h" #include "ctkXnatListModel.h" #include "ctkXnatScanFolder.h" +#include "ctkXnatScanResource.h" // Blueberry #include #include // Qt #include #include #include #include #include #include #include #include #include #include #include #include // Poco #include "Poco/Net/HTTPClientSession.h" #include "Poco/Net/HTTPRequest.h" #include "Poco/Net/HTTPResponse.h" #include "Poco/Net/HTTPBasicCredentials.h" #include "Poco/DOM/NodeList.h" #include "Poco/SAX/InputSource.h" #include "Poco/URI.h" #include "Poco/NumberParser.h" #include "Poco/SAX/SAXParser.h" #include "Poco/DOM/DOMParser.h" #include "Poco/DOM/Document.h" #include "Poco/DOM/NodeIterator.h" #include "Poco/DOM/NodeFilter.h" #include "Poco/DOM/AutoPtr.h" #include "Poco/DOM/Node.h" #include "Poco/StreamCopier.h" const std::string XNATProjects::EDITOR_ID = "org.mitk.editors.xnatprojects"; XNATProjects::XNATProjects() : m_ConnectionFactory(new ctkXnatConnectionFactory()), m_Connection(0), m_ProjectsModel(new ctkXnatListModel()), m_SubjectsModel(new ctkXnatListModel()), m_ExperimentsModel(new ctkXnatListModel()), m_ScansModel(new ctkXnatListModel()), - m_ResourceModel(new ctkXnatListModel()) + m_ResourceModel(new ctkXnatListModel()), + m_FileModel(new ctkXnatListModel()) { } XNATProjects::~XNATProjects() { if ( m_Connection ) delete m_Connection; delete m_ConnectionFactory; delete m_SubjectsModel; delete m_ProjectsModel; delete m_ExperimentsModel; delete m_ScansModel; delete m_ResourceModel; + delete m_FileModel; } bool XNATProjects::IsDirty() const { return false; } bool XNATProjects::IsSaveAsAllowed() const { return false; } void XNATProjects::Init(berry::IEditorSite::Pointer site, berry::IEditorInput::Pointer input) { this->SetSite(site); this->SetInput(input); } void XNATProjects::DoSave() { } void XNATProjects::DoSaveAs() { } void XNATProjects::SetFocus() { m_Controls.buttonGetAllProjects->setFocus(); - m_Controls.buttonLoginDialog->setFocus(); + m_Controls.buttonDownloadResource->setFocus(); + m_Controls.buttonDownloadFile->setFocus(); } void XNATProjects::CreateQtPartControl( QWidget *parent ) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); m_Controls.projectTreeView->setModel(m_ProjectsModel); m_Controls.subjectTreeView->setModel(m_SubjectsModel); m_Controls.experimentTreeView->setModel(m_ExperimentsModel); m_Controls.scanTreeView->setModel(m_ScansModel); m_Controls.resourceTreeView->setModel(m_ResourceModel); + m_Controls.fileTreeView->setModel(m_FileModel); connect( m_Controls.buttonGetAllProjects, SIGNAL(clicked()), this, SLOT(GetAllProjects()) ); - connect( m_Controls.projectTreeView, SIGNAL(clicked(QModelIndex)), SLOT(projectSelected(QModelIndex)) ); - connect( m_Controls.subjectTreeView, SIGNAL(clicked(QModelIndex)), SLOT(subjectSelected(QModelIndex)) ); - connect( m_Controls.experimentTreeView, SIGNAL(clicked(QModelIndex)), SLOT(experimentSelected(QModelIndex)) ); - connect( m_Controls.scanTreeView, SIGNAL(clicked(QModelIndex)), SLOT(scanSelected(QModelIndex)) ); - - connect( m_Controls.buttonLoginDialog, SIGNAL(clicked()), this, SLOT(OpenLoginDialog()) ); + connect( m_Controls.buttonDownloadResource, SIGNAL(clicked()), this, SLOT(DownloadResource()) ); + connect( m_Controls.buttonDownloadFile, SIGNAL(clicked()), this, SLOT(DownloadFile()) ); + + connect( m_Controls.projectTreeView, SIGNAL(clicked(QModelIndex)), SLOT(ProjectSelected(QModelIndex)) ); + connect( m_Controls.subjectTreeView, SIGNAL(clicked(QModelIndex)), SLOT(SubjectSelected(QModelIndex)) ); + connect( m_Controls.experimentTreeView, SIGNAL(clicked(QModelIndex)), SLOT(ExperimentSelected(QModelIndex)) ); + connect( m_Controls.scanTreeView, SIGNAL(clicked(QModelIndex)), SLOT(ScanSelected(QModelIndex)) ); + connect( m_Controls.resourceTreeView, SIGNAL(clicked(QModelIndex)), SLOT(ResourceSelected(QModelIndex)) ); } void XNATProjects::OnSelectionChanged( berry::IWorkbenchPart::Pointer /*source*/, const QList& nodes ) { // iterate all selected objects, adjust warning visibility //foreach( mitk::DataNode::Pointer node, nodes ) //{ // if( node.IsNotNull() && dynamic_cast(node->GetData()) ) // { // m_Controls.labelWarning->setVisible( false ); // m_Controls.buttonGetAllProjects->setEnabled( true ); // return; // } //} //m_Controls.labelWarning->setVisible( true ); //m_Controls.buttonGetAllProjects->setEnabled( false ); } /** \brief To get all Projects */ void XNATProjects::GetAllProjects() { // Clear existing treeView m_SubjectsModel->setRootObject(ctkXnatObject::Pointer()); m_ExperimentsModel->setRootObject(ctkXnatObject::Pointer()); m_ScansModel->setRootObject(ctkXnatObject::Pointer()); m_ResourceModel->setRootObject(ctkXnatObject::Pointer()); + m_FileModel->setRootObject(ctkXnatObject::Pointer()); m_Controls.subjectTreeView->reset(); m_Controls.experimentTreeView->reset(); m_Controls.scanTreeView->reset(); m_Controls.resourceTreeView->reset(); + m_Controls.fileTreeView->reset(); // Validate user input if ( m_Controls.inHostAddress->text().isEmpty() || m_Controls.inUser->text().isEmpty() || m_Controls.inPassword->text().isEmpty() ) { if ( m_Controls.inHostAddress->text().isEmpty() ) { MITK_INFO << "No host address!"; m_Controls.inHostAddress->setStyleSheet("QLineEdit{ background-color: rgb(255,0,0) }"); } if ( m_Controls.inUser->text().isEmpty() ) { MITK_INFO << "No user !"; m_Controls.inUser->setStyleSheet("QLineEdit{ background-color: rgb(255,0,0) }"); } if ( m_Controls.inPassword->text().isEmpty() ) { MITK_INFO << "No password!"; m_Controls.inPassword->setStyleSheet("QLineEdit{ background-color: rgb(255,0,0) }"); } return; } else { m_Controls.inHostAddress->setStyleSheet("QLineEdit{ background-color: rgb(255,255,255) }"); m_Controls.inUser->setStyleSheet("QLineEdit{ background-color: rgb(255,255,255) }"); m_Controls.inPassword->setStyleSheet("QLineEdit{ background-color: rgb(255,255,255) }"); } // Regular Expression for uri QRegExp uriregex("^(https?)://([a-zA-Z0-9\\.]+):([0-9]+)(/[^ /]+)*$"); // Validate address if ( ! uriregex.exactMatch(m_Controls.inHostAddress->text()) ) { MITK_INFO << m_Controls.inHostAddress->text().toStdString(); MITK_INFO << "Host address not valid"; m_Controls.inHostAddress->setStyleSheet("QLineEdit{ background-color: rgb(255,0,0) }"); return; } else { m_Controls.inHostAddress->setStyleSheet("QLineEdit{ background-color: rgb(255,255,255) }"); } // create ctkXnatConnection m_Connection = m_ConnectionFactory->makeConnection(m_Controls.inHostAddress->text(), m_Controls.inUser->text(), m_Controls.inPassword->text()); ctkXnatServer::Pointer server(ctkXnatServer::Create(m_Connection)); // fetch projects from server server->fetch(); // list projects m_ProjectsModel->setRootObject(server); // Set tree visible m_Controls.projectTreeView->reset(); } /** \brief ******** SEARCH ******** */ void XNATProjects::SearchWithXmlFilePath(QString filepath) { /* bla.. blaa... blaaa.... */ } /** \brief Converts a Poco::XML::XMLString to QString */ QString XNATProjects::ConvertFromXMLString(const Poco::XML::XMLString xmlstr) { const char* cstr = (Poco::XML::fromXMLString(xmlstr).c_str()); QString qstr = cstr; return qstr; } -/** -\brief *****DOES NOT THAT WHAT IT IS THERE FOR***** -*/ -void XNATProjects::OpenLoginDialog() -{ -} - /** \brief *****fetchs subjects from chosen project***** */ -void XNATProjects::projectSelected(const QModelIndex& index) +void XNATProjects::ProjectSelected(const QModelIndex& index) { QVariant variant = m_ProjectsModel->data(index, Qt::UserRole); - if (variant.isValid()) + if ( variant.isValid() ) { ctkXnatObject::Pointer project = variant.value(); project->fetch(); m_SubjectsModel->setRootObject(project); m_Controls.subjectTreeView->reset(); } } /** \brief *****fetchs experiments from chosen subject***** */ -void XNATProjects::subjectSelected(const QModelIndex& index) +void XNATProjects::SubjectSelected(const QModelIndex& index) { QVariant variant = m_SubjectsModel->data(index, Qt::UserRole); - if (variant.isValid()) + if ( variant.isValid() ) { ctkXnatObject::Pointer subject = variant.value(); subject->fetch(); m_ExperimentsModel->setRootObject(subject); m_Controls.experimentTreeView->reset(); } } /** \brief *****fetchs data from chosen experiment***** */ -void XNATProjects::experimentSelected(const QModelIndex& index) +void XNATProjects::ExperimentSelected(const QModelIndex& index) { QVariant variant = m_ExperimentsModel->data(index, Qt::UserRole); - if (variant.isValid()) + if ( variant.isValid() ) { ctkXnatObject::Pointer experiment = variant.value(); experiment->fetch(); ctkXnatObject::Pointer scanfolder = experiment->children().takeFirst(); scanfolder->fetch(); m_ScansModel->setRootObject(scanfolder); m_Controls.scanTreeView->reset(); - MITK_INFO << scanfolder->children().takeFirst()->uri().toStdString(); } } /** \brief *****fetchs download data from chosen experiment***** */ -void XNATProjects::scanSelected(const QModelIndex& index) +void XNATProjects::ScanSelected(const QModelIndex& index) { QVariant variant = m_ScansModel->data(index, Qt::UserRole); - if (variant.isValid()) + if ( variant.isValid() ) { ctkXnatObject::Pointer scan = variant.value(); scan->fetch(); m_ResourceModel->setRootObject(scan); m_Controls.resourceTreeView->reset(); - MITK_INFO << scan->children().takeAt(2)->uri().toStdString(); + } +} + +void XNATProjects::ResourceSelected(const QModelIndex& index) +{ + QVariant variant = m_ResourceModel->data(index, Qt::UserRole); + if ( variant.isValid() ) + { + ctkXnatObject::Pointer resource = variant.value(); + resource->fetch(); + m_FileModel->setRootObject(resource); + m_Controls.fileTreeView->reset(); + } +} + +void XNATProjects::DownloadResource() +{ + const QModelIndex index = m_Controls.resourceTreeView->selectionModel()->currentIndex(); + QVariant variant = m_ResourceModel->data(index, Qt::UserRole); + if ( variant.isValid() ) + { + ctkXnatObject::Pointer resource = variant.value(); + MITK_INFO << "Download started ..."; + MITK_INFO << "..."; + resource->download(resource->id()+(".zip")); + MITK_INFO << "Download finished!"; + } +} + +void XNATProjects::DownloadFile() +{ + const QModelIndex index = m_Controls.fileTreeView->selectionModel()->currentIndex(); + QVariant variant = m_FileModel->data(index, Qt::UserRole); + if ( variant.isValid() ) + { + ctkXnatObject::Pointer file = variant.value(); + MITK_INFO << "Download started ..."; + MITK_INFO << "..."; + file->download(file->id()); + MITK_INFO << "Download finished!"; } } diff --git a/Plugins/org.mitk.gui.qt.xnatinterface/src/internal/XNATProjects.h b/Plugins/org.mitk.gui.qt.xnatinterface/src/internal/XNATProjects.h index 05ed015a6c..7a131daf33 100644 --- a/Plugins/org.mitk.gui.qt.xnatinterface/src/internal/XNATProjects.h +++ b/Plugins/org.mitk.gui.qt.xnatinterface/src/internal/XNATProjects.h @@ -1,103 +1,108 @@ /*=================================================================== 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 XNATProjects_h #define XNATProjects_h #include #include #include "berryIEditorInput.h" #include "berryIEditorSite.h" #include #include "ui_XNATProjectsControls.h" #include "Poco/DOM/Node.h" #include "Poco/URI.h" #include #include #include #include "ctkXnatListModel.h" #include "ctkXnatConnectionFactory.h" #include "ctkXnatConnection.h" +#include "ctkXnatScanResource.h" /*! \brief XNATProjects \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 XNATProjects : public berry::QtEditorPart { // 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: XNATProjects(); ~XNATProjects(); static const std::string EDITOR_ID; void CreateQtPartControl(QWidget *parent); void SearchWithXmlFilePath(QString filepath); void DoSave(/*IProgressMonitor monitor*/); void DoSaveAs(); void Init(berry::IEditorSite::Pointer site, berry::IEditorInput::Pointer input); bool IsDirty() const; bool IsSaveAsAllowed() const; protected slots: /// \brief Called when the user clicks the GUI button void GetAllProjects(); - void OpenLoginDialog(); - void projectSelected(const QModelIndex& index); - void subjectSelected(const QModelIndex& index); - void experimentSelected(const QModelIndex& index); - void scanSelected(const QModelIndex& index); + void DownloadResource(); + void DownloadFile(); + + void ProjectSelected(const QModelIndex& index); + void SubjectSelected(const QModelIndex& index); + void ExperimentSelected(const QModelIndex& index); + void ScanSelected(const QModelIndex& index); + void ResourceSelected(const QModelIndex& index); protected: virtual void SetFocus(); /// \brief called by QmitkFunctionality when DataManager's selection has changed virtual void OnSelectionChanged( berry::IWorkbenchPart::Pointer source, const QList& nodes ); Ui::XNATProjectsControls m_Controls; private: //QMap::QMap m_Profiles; QString ConvertFromXMLString(const Poco::XML::XMLString); ctkXnatConnectionFactory* m_ConnectionFactory; ctkXnatConnection* m_Connection; ctkXnatListModel* m_ProjectsModel; ctkXnatListModel* m_SubjectsModel; ctkXnatListModel* m_ExperimentsModel; ctkXnatListModel* m_ScansModel; ctkXnatListModel* m_ResourceModel; + ctkXnatListModel* m_FileModel; }; #endif // XNATProjects_h diff --git a/Plugins/org.mitk.gui.qt.xnatinterface/src/internal/XNATProjectsControls.ui b/Plugins/org.mitk.gui.qt.xnatinterface/src/internal/XNATProjectsControls.ui index 035b4bbf3d..7f42b3d7ed 100644 --- a/Plugins/org.mitk.gui.qt.xnatinterface/src/internal/XNATProjectsControls.ui +++ b/Plugins/org.mitk.gui.qt.xnatinterface/src/internal/XNATProjectsControls.ui @@ -1,161 +1,160 @@ XNATProjectsControls 0 0 838 975 0 0 QmitkTemplate xnat_icon.icoxnat_icon.ico QLabel { color: rgb(255, 0, 0) } Please insert your XNAT host address: 230 0 <html><head/><body><p>Examples:</p><p>&quot;http://localhost:8080/xnat&quot;</p><p>&quot;http://central.xnat.org:80&quot;</p><p>&quot;https://xnat.myserver.de:443&quot;</p></body></html> http://localhost:12345/xnat http(s)://host:port/pathToXnatServerInstance admin User 53 0 admin QLineEdit::Password Password true Get all projects Get all projects - - - - Login Dialog - - - + + + + + + + + + - + - Download + (no function) - + - Upload + Download Folder - - - - - - - - + + + Download File + +