~ubuntu-branches/ubuntu/raring/ginkgocadx/raring-proposed

« back to all changes in this revision

Viewing changes to src/cadxcore/commands/openremovableunit.cpp

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2012-01-29 12:02:54 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120129120254-nu7giync5p156icb
Tags: 2.8.0.4602-1
New upstream version (adapted patch, removed patch applied upstream)
Closes: #657827

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
*
 
3
*  $Id: sendhl7command.cpp 4319 2011-10-20 06:57:50Z carlos $
 
4
*  Ginkgo CADx Project
 
5
*
 
6
*  Copyright 2008-10 MetaEmotion S.L. All rights reserved.
 
7
*  http://ginkgo-cadx.com
 
8
*
 
9
*  This file is licensed under LGPL v3 license.
 
10
*  See License.txt for details
 
11
*
 
12
*/
 
13
#include <wx/window.h>
 
14
#include <wx/volume.h>
 
15
#include <wx/msgdlg.h>
 
16
#include <api/globals.h>
 
17
#include "openremovableunit.h"
 
18
#include <wx/file.h>
 
19
#include <wx/dir.h>
 
20
#include <main/controllers/controladorlog.h>
 
21
#include <main/controllers/pacscontroller.h>
 
22
#include <main/gui/open/opendialogs.h>
 
23
#include <main/gui/open/abrir.h>
 
24
#include <commands/comandoincluirhistorial.h>
 
25
#include <main/entorno.h>
 
26
 
 
27
namespace GADAPI
 
28
{
 
29
        OpenRemovableUnitCommand::OpenRemovableUnitCommand(OpenRemovableUnitCommandParams* pParams) : IComando(pParams)
 
30
        {
 
31
                m_pOpenParams = pParams;
 
32
        }
 
33
 
 
34
        void OpenRemovableUnitCommand::Execute()
 
35
        {
 
36
                #ifdef _WIN32
 
37
                NotificarProgreso(0.15f, _Std("Exploring drives..."));
 
38
                wxArrayString volumes = wxFSVolume::GetVolumes(wxFS_VOL_MOUNTED|wxFS_VOL_REMOVABLE );
 
39
                NotificarProgreso(0.75f, _Std("Exploring drives..."));
 
40
                wxArrayString mountedVolumes;
 
41
                for (wxArrayString::iterator it = volumes.begin(); it != volumes.end(); it++) {
 
42
                        wxFSVolume fs((*it));
 
43
                        if (fs.IsOk()) {
 
44
                                OpenRemovableUnitCommandParams::TRemovableUnit unit;
 
45
                                unit.path = TOPATH(fs.GetName());
 
46
                                //first of all list files in path if it isn't mounted ... error
 
47
                                wxDir dir;
 
48
                                wxString tmp;
 
49
                                if (dir.Open(fs.GetName()) && dir.GetFirst(&tmp)) {
 
50
                                        //second check if it includes dicomdir
 
51
                                        wxString dicomDirPath = fs.GetName() + wxT("DICOMDIR");
 
52
                                        unit.hasDicomDir = wxFileExists(dicomDirPath) && GIL::DICOM::PACSController::Instance()->EsDICOM(TOPATH(dicomDirPath),true,false);
 
53
 
 
54
                                        unit.displayName = fs.GetDisplayName().ToUTF8();
 
55
                                        m_pOpenParams->units.push_back(unit);
 
56
                                }                       
 
57
                        }
 
58
                }               
 
59
                #endif
 
60
        }
 
61
 
 
62
        void OpenRemovableUnitCommand::Update()
 
63
        {
 
64
                if (EstaAbortado()) {
 
65
                    return;
 
66
                }
 
67
                if (m_pOpenParams->units.empty()) {
 
68
                        //no units
 
69
                        if (wxMessageBox(_("No DICOMDIR found in removable units.\nWould you like to scan other path recursively?"), _("Info"), wxOK|wxCANCEL, m_pOpenParams->m_pParent) == wxOK) {
 
70
                                GNC::GUI::Abrir::AbrirDirectorio(m_pOpenParams->m_pParent);
 
71
                        }
 
72
                } else {
 
73
                        if (!OpenDicomDir()) {
 
74
                                ScanRecursively();
 
75
                        }
 
76
                }
 
77
        }
 
78
        bool OpenRemovableUnitCommand::OpenDicomDir()
 
79
        {
 
80
                int numberOfUnits = 0;
 
81
                std::string path;
 
82
                for (OpenRemovableUnitCommandParams::TListOfUnits::iterator it = m_pOpenParams->units.begin(); it != m_pOpenParams->units.end(); it++) {
 
83
                        if ((*it).hasDicomDir) {
 
84
                                numberOfUnits++;
 
85
                                path = (*it).path;
 
86
                        }
 
87
                }
 
88
                if (numberOfUnits == 0) {
 
89
                        return false;
 
90
                } else if (numberOfUnits == 1) {
 
91
                        //dialogo de adquisicion a traves de dicomdir...
 
92
                        LaunchOpenDicomDir(path);
 
93
                } else {
 
94
                        //show dialog listing units..
 
95
                        SelectDrive(true);
 
96
                }
 
97
                return true;
 
98
        }
 
99
 
 
100
        bool OpenRemovableUnitCommand::ScanRecursively()
 
101
        {
 
102
                if (m_pOpenParams->units.size() == 1) {
 
103
                        wxString name = wxString::FromUTF8(m_pOpenParams->units.front().displayName.c_str());
 
104
                        wxString message = wxString::Format(_("No DICOMDIR found in removable units, would you like to scan recursively %s drive"), name.c_str());
 
105
                        if (wxMessageBox(message, _("Info"), wxOK|wxCANCEL, m_pOpenParams->m_pParent) == wxOK) 
 
106
                        {
 
107
                                LaunchOpenRecursively(m_pOpenParams->units.front().path);
 
108
                        }
 
109
                } else {
 
110
                        SelectDrive(false);
 
111
                }
 
112
                return true;
 
113
        }
 
114
 
 
115
        void OpenRemovableUnitCommand::SelectDrive(bool hasDicomDir)
 
116
        {
 
117
                GNC::GUI::SelectDrive::TListOfDrives listOfDrives;
 
118
                for (OpenRemovableUnitCommandParams::TListOfUnits::iterator it = m_pOpenParams->units.begin(); it != m_pOpenParams->units.end(); ++it) {
 
119
                        if ((*it).hasDicomDir == hasDicomDir) {
 
120
                                listOfDrives.push_back(GNC::GUI::SelectDrive::TDrive((*it).path, (*it).displayName));
 
121
                        }
 
122
                }
 
123
                GNC::GUI::SelectDrive dialog(m_pOpenParams->m_pParent, listOfDrives);
 
124
                if (hasDicomDir) {
 
125
                        dialog.SetMessage(_("Select drive you want to open"));
 
126
                } else {
 
127
                        dialog.SetMessage(_("Ginkgo CADx has detected more than one removable units,\nbut none of them includes a DICOMDIR at root.\nSelect drive where you want to acquire recursively"));
 
128
                }
 
129
                if (dialog.ShowModal() == wxID_OK) {
 
130
                        std::string path = dialog.GetSelectedDrive();
 
131
                        if (hasDicomDir) {
 
132
                                LaunchOpenDicomDir(path);
 
133
                        } else {
 
134
                                LaunchOpenRecursively(path);
 
135
                        }
 
136
                }
 
137
        }
 
138
 
 
139
        void OpenRemovableUnitCommand::LaunchOpenRecursively(const std::string& path)
 
140
        {
 
141
                GADAPI::ComandoIncluirHistorial::ComandoIncluirHistorialParams* pParams = new GADAPI::ComandoIncluirHistorial::ComandoIncluirHistorialParams(path,true);
 
142
                GADAPI::ComandoIncluirHistorial::ComandoIncluirHistorial* pCmd = new GADAPI::ComandoIncluirHistorial::ComandoIncluirHistorial(pParams);
 
143
                GNC::Entorno::Instance()->GetControladorComandos()->ProcessAsync(_Std("Storing in the history..."),pCmd, NULL);
 
144
        }
 
145
 
 
146
        void OpenRemovableUnitCommand::LaunchOpenDicomDir(const std::string& path)
 
147
        {
 
148
                std::ostringstream ostr;
 
149
                ostr << path << "DICOMDIR";
 
150
                GNC::GUI::DialogoDicomDir dicomDirDialog(m_pOpenParams->m_pParent, ostr.str());
 
151
                dicomDirDialog.ShowModal();
 
152
        }
 
153
}