diff --git a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDirectoryListener.cpp b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDirectoryListener.cpp index 36aa237b6e..beed8bf87b 100644 --- a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDirectoryListener.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDirectoryListener.cpp @@ -1,141 +1,126 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkDicomDirectoryListener.h" #include #include #include QmitkDicomDirectoryListener::QmitkDicomDirectoryListener() -: m_LastRetrievedFile(new QStringList()) -, m_CurrentRetrievedFile(new QStringList()) -, m_FileSystemWatcher(new QFileSystemWatcher()) -, m_Timer(new QTimer(this)) +: m_FileSystemWatcher(new QFileSystemWatcher()) +, m_FilesToImport(new QStringList()) +, m_ImportingFiles(new QStringList()) , m_DicomListenerDirectory(QString()) { - m_Timer->setSingleShot(true); - m_Timer->blockSignals(true); connect(m_FileSystemWatcher,SIGNAL(directoryChanged(const QString&)),this,SLOT(OnDirectoryChanged(const QString&))); - } QmitkDicomDirectoryListener::~QmitkDicomDirectoryListener() { + delete m_FilesToImport; + delete m_ImportingFiles; delete m_FileSystemWatcher; - delete m_CurrentRetrievedFile; - delete m_LastRetrievedFile; - delete m_Timer; } -void QmitkDicomDirectoryListener::OnDirectoryChanged(const QString& changedFile) +void QmitkDicomDirectoryListener::OnDirectoryChanged(const QString&) { - - // set m_CurrentRetrievedFile stays empty if the folder doesn't contain any new files e.g. if a file was deleted - m_CurrentRetrievedFile = SetRetrievedFile(changedFile); - - //Situation: directory is empty and there is a new incoming file - if(!m_Timer->isActive() && !m_CurrentRetrievedFile->isEmpty()) - { - m_Timer->start(30000); - emit StartImportingFile(*m_CurrentRetrievedFile); - m_LastRetrievedFile = m_CurrentRetrievedFile; - m_CurrentRetrievedFile->clear(); - } - //Situation: A new file comes in and the timer is still running -> indicates the last download is finished - if(m_Timer->isActive()&& !m_CurrentRetrievedFile->isEmpty()) - { - m_Timer->stop(); - emit StartImportingFile(*m_LastRetrievedFile); - m_Timer->start(30000); - emit StartImportingFile(*m_CurrentRetrievedFile); - m_LastRetrievedFile = m_CurrentRetrievedFile; - m_CurrentRetrievedFile->clear(); - } - + m_Mutex.lock(); + SetFilesToImport(); + m_ImportingFiles->append(*m_FilesToImport); + emit SignalAddDicomData(*m_FilesToImport); + m_Mutex.unlock(); } -QStringList* QmitkDicomDirectoryListener::SetRetrievedFile(const QString& filename) +void QmitkDicomDirectoryListener::OnDicomImportFinished(const QStringList& finishedFiles) { - QDir listenerDirectory(filename); - //if the listenordirectory is empty you have deleted the last file - if(!listenerDirectory.entryList().isEmpty()) + m_Mutex.lock(); + RemoveFilesFromDirectoryAndImportingFilesList(finishedFiles); + m_Mutex.unlock(); +} + +void QmitkDicomDirectoryListener::SetFilesToImport() +{ + m_FilesToImport->clear(); + QDir listenerDirectory(m_DicomListenerDirectory); + QFileInfoList entries = listenerDirectory.entryInfoList(QDir::Files); + if(!entries.isEmpty()) { - QFileInfoList directoryMembers; - directoryMembers = listenerDirectory.entryInfoList(); - QFileInfoList::iterator member; - member=directoryMembers.begin(); - QStringList temp; - - //filter files, no directories wanted - while(member!=directoryMembers.end()) + QFileInfoList::const_iterator file; + for(file = entries.constBegin(); file != entries.constEnd(); ++file ) { - if((*member).isFile()){ - temp.append((*member).absoluteFilePath()); + if(!m_ImportingFiles->contains((*file).absoluteFilePath())) + { + m_FilesToImport->append((*file).absoluteFilePath()); } - ++member; } + } +} - //check if there is an existing new file - if(!temp.isEmpty()) +void QmitkDicomDirectoryListener::RemoveFilesFromDirectoryAndImportingFilesList(const QStringList& files) +{ + QStringListIterator fileToDeleteIterator(files); + while(fileToDeleteIterator.hasNext()) + { + QFile file(fileToDeleteIterator.next()); + if(m_ImportingFiles->contains(file.fileName())) { - return new QStringList(temp); + m_ImportingFiles->removeOne(file.fileName()); + file.remove(); } } - return new QStringList(); } void QmitkDicomDirectoryListener::SetDicomListenerDirectory(const QString& directory) { if(isOnlyListenedDirectory(directory)) { QDir listenerDirectory = QDir(directory); CreateListenerDirectory(listenerDirectory); m_DicomListenerDirectory=listenerDirectory.absolutePath(); m_FileSystemWatcher->addPath(m_DicomListenerDirectory); } - } const QString& QmitkDicomDirectoryListener::GetDicomListenerDirectory() { return m_DicomListenerDirectory; } void QmitkDicomDirectoryListener::CreateListenerDirectory(const QDir& directory) { if(!directory.exists()) { directory.mkpath(directory.absolutePath()); } } bool QmitkDicomDirectoryListener::isOnlyListenedDirectory(const QString& directory) { bool isOnlyListenedDirectory = false; if(m_FileSystemWatcher->directories().count()==0||m_FileSystemWatcher->directories().count()==1) { if(!m_FileSystemWatcher->directories().contains(directory)) { isOnlyListenedDirectory = true; } } return isOnlyListenedDirectory; } \ No newline at end of file diff --git a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDirectoryListener.h b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDirectoryListener.h index 6412fa0cad..ceed36f1f0 100644 --- a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDirectoryListener.h +++ b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDirectoryListener.h @@ -1,73 +1,80 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef QmitkDicomDirectoryListener_h #define QmitkDicomDirectoryListener_h #include #include #include #include #include +#include #include class QmitkDicomDirectoryListener : public QObject { Q_OBJECT public: QmitkDicomDirectoryListener(); virtual ~QmitkDicomDirectoryListener(); /// @brief sets listened directory, note that only one directory can be set. void SetDicomListenerDirectory(const QString&); /// @brief get filepath to the listened directory. const QString& GetDicomListenerDirectory(); signals: /// @brief signal starts the dicom import of the given file (the QStringList will only contain one file here). - void StartImportingFile(QStringList&); + void SignalAddDicomData(const QStringList&); public slots: /// \brief called when listener directory changes - void OnDirectoryChanged(const QString& changedFile); + void OnDirectoryChanged(const QString&); + + /// \brief called when import is finished + void OnDicomImportFinished(const QStringList&); protected: /// \brief creates directory if it's not already existing. void CreateListenerDirectory(const QDir& directory); /// \brief checks wheter the given directory is the only directory that is listened. bool isOnlyListenedDirectory(const QString& directory); /// \brief Composes the filename and initializes m_LastRetrievedFile with it - QStringList* SetRetrievedFile(const QString& filename); + void SetFilesToImport(); + + /// \brief removes files from + void RemoveFilesFromDirectoryAndImportingFilesList(const QStringList& files); - QTimer* m_Timer; QFileSystemWatcher* m_FileSystemWatcher; - QStringList* m_CurrentRetrievedFile; - QStringList* m_LastRetrievedFile; + QStringList* m_FilesToImport; + QStringList* m_ImportingFiles; QString m_DicomListenerDirectory; + QMutex m_Mutex; }; #endif // QmitkDicomListener_h \ No newline at end of file diff --git a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkStoreSCPLauncher.cpp b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkStoreSCPLauncher.cpp index 601e75d566..0e64abea97 100644 --- a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkStoreSCPLauncher.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkStoreSCPLauncher.cpp @@ -1,124 +1,120 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkStoreSCPLauncher.h" #include #include #include #include //#include QmitkStoreSCPLauncher::QmitkStoreSCPLauncher(QmitkStoreSCPLauncherBuilder* builder) : m_StoreSCP(new QProcess()) { connect( m_StoreSCP, SIGNAL(error(QProcess::ProcessError)),this, SLOT(OnProcessError(QProcess::ProcessError))); connect( m_StoreSCP, SIGNAL(stateChanged(QProcess::ProcessState)),this, SLOT(OnStateChanged(QProcess::ProcessState))); SetArgumentList(builder); } QmitkStoreSCPLauncher::~QmitkStoreSCPLauncher() { m_StoreSCP->kill(); delete m_StoreSCP; } void QmitkStoreSCPLauncher::StartStoreSCP() { QString storeSCP; storeSCP.append(GetPathToExecutable()); storeSCP.append(QString("/storescp.exe")); - - MITK_INFO << ArgumentListToQString().toStdString(); //m_StoreSCP->start(storeSCP,m_ArgumentList); QProcess::startDetached(storeSCP,m_ArgumentList); } QString QmitkStoreSCPLauncher::GetPathToExecutable() { QDir root; QString currentPath = root.currentPath(); currentPath = currentPath.split("MITK").at(0); currentPath.append("MITK/CTK-build/CMakeExternals/Install/bin"); return currentPath; } void QmitkStoreSCPLauncher::OnProcessError(QProcess::ProcessError err) { switch(err) { case QProcess::FailedToStart: QMessageBox::information(0,"FailedToStart",QString("FailedToStart:\n").append(m_StoreSCP->errorString())); break; case QProcess::Crashed: QMessageBox::information(0,"Crashed",QString("Crashed:\n").append(m_StoreSCP->errorString())); break; case QProcess::Timedout: QMessageBox::information(0,"Timedout",QString("Timedout:\n").append(m_StoreSCP->errorString())); break; case QProcess::WriteError: QMessageBox::information(0,"WriteError",QString("WriteError:\n").append(m_StoreSCP->errorString())); break; case QProcess::ReadError: QMessageBox::information(0,"ReadError",QString("ReadError:\n").append(m_StoreSCP->errorString())); break; case QProcess::UnknownError: QMessageBox::information(0,"UnknownError",QString("UnknownError:\n").append(m_StoreSCP->errorString())); break; default: QMessageBox::information(0,"default",QString("default:\n").append(m_StoreSCP->errorString())); break; } } void QmitkStoreSCPLauncher::OnStateChanged(QProcess::ProcessState status) { switch(status) { case QProcess::NotRunning: QMessageBox::information(0,"NotRunning",QString("NotRunning:\n").append(m_StoreSCP->errorString())); break; case QProcess::Starting: QMessageBox::information(0,"Starting",QString("Starting")); break; case QProcess::Running: QMessageBox::information(0,"Running",QString("Running")); break; default: QMessageBox::information(0,"default",QString("default:\n").append(m_StoreSCP->errorString())); break; } } void QmitkStoreSCPLauncher::SetArgumentList(QmitkStoreSCPLauncherBuilder* builder) { m_ArgumentList << *builder->GetPort() << QString("-aet") <<*builder->GetAETitle() << *builder->GetTransferSyntax() << *builder->GetOtherNetworkOptions() << *builder->GetMode() << QString("-od") << *builder->GetOutputDirectory(); } QString QmitkStoreSCPLauncher::ArgumentListToQString() { QString argumentString; QStringListIterator argumentIterator(m_ArgumentList); - while(argumentIterator.hasNext()) { argumentString.append(" "); argumentString.append(argumentIterator.next()); } - return argumentString; } \ No newline at end of file