~ubuntu-branches/ubuntu/wily/ginkgocadx/wily-proposed

« back to all changes in this revision

Viewing changes to src/cadxcore/main/gui/configuration/localdatabaseconfigurationpanel.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2013-10-24 21:28:17 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20131024212817-ej1skb9og09d3ht6
Tags: 3.5.0.1137.31+dfsg-1
New upstream release [October 2013]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  
 
3
 *  $Id: LocalDatabaseConfigurationPanel.cpp $
 
4
 *  Ginkgo CADx Project
 
5
 *
 
6
 *  Copyright 2008-14 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
 */
 
14
#include <vector>
 
15
 
 
16
#include <wx/checkbox.h>
 
17
#include <wx/msgdlg.h>
 
18
#include <wx/msgout.h>
 
19
#include <wx/dirdlg.h>
 
20
#include <wx/filename.h>
 
21
#include <wx/wxhttpengine/proxysettingsdlg.h>
 
22
#include <main/controllers/configurationcontroller.h>
 
23
#include <sstream>
 
24
#include <wx/file.h>
 
25
#include <wx/dir.h>
 
26
#include <wx/stdpaths.h>
 
27
#include <wx/xml/xml.h>
 
28
 
 
29
#include <wx/ginkgostyle/ginkgostyle.h>
 
30
 
 
31
#include "localdatabaseconfigurationpanel.h"
 
32
 
 
33
#include <main/controllers/controladorextensiones.h>
 
34
#include <main/controllers/controladoreventos.h>
 
35
#include <main/controllers/controladorvistas.h>
 
36
#include <main/controllers/commandcontroller.h>
 
37
#include <main/controllers/historycontroller.h>
 
38
#include <main/controllers/autocleaningcontroller.h>
 
39
#include <main/gui/history3/historypanel3.h>
 
40
#include <main/entorno.h>
 
41
#include <api/controllers/icontroladorinternacionalizacion.h>
 
42
#include <api/internationalization/internationalization.h>
 
43
 
 
44
namespace GNC {
 
45
        namespace GUI {
 
46
 
 
47
                LocalDatabaseConfigurationPanel::LocalDatabaseConfigurationPanel(wxWindow* pParent,IDialogoConfiguracion* pDialogo): LocalDatabaseConfigurationPanelBase(pParent), IPasoConfiguracion(pDialogo)
 
48
                {       
 
49
                        if (GNC::GCS::ControladorVistas::Instance()->GetVistas().size() > 0)
 
50
                        {
 
51
                                m_pDICOMDir->Enable(false);
 
52
                                m_buttonSeleccionarDICOMDir->Enable(false);
 
53
                                m_pstaticTextAdvertencia->Show(true);
 
54
                        }
 
55
                        else
 
56
                        {
 
57
                                m_pstaticTextAdvertencia->Show(false);
 
58
                        }
 
59
 
 
60
                        m_mapTimePeriods[1] = _Std("One day");
 
61
                        m_mapTimePeriods[2] = _Std("Two days");
 
62
                        m_mapTimePeriods[3] = _Std("Three days");
 
63
                        m_mapTimePeriods[7] = _Std("One week");
 
64
                        m_mapTimePeriods[14] = _Std("Two weeks");
 
65
                        m_mapTimePeriods[30] = _Std("One month");
 
66
                        m_mapTimePeriods[90] = _Std("Three months");
 
67
                        m_mapTimePeriods[365] = _Std("One year");
 
68
 
 
69
                        for (std::map<int, std::string>::const_iterator it = m_mapTimePeriods.begin(); it != m_mapTimePeriods.end(); ++it) {
 
70
                                m_pChoiceDeleteOlder->AppendString(wxString::FromUTF8((*it).second.c_str()));
 
71
                        }
 
72
                        m_pChoiceDeleteOlder->SetSelection(6);
 
73
 
 
74
                        Recargar();
 
75
                        Layout();
 
76
                }
 
77
 
 
78
                LocalDatabaseConfigurationPanel::~LocalDatabaseConfigurationPanel()
 
79
                {
 
80
                }
 
81
 
 
82
                void LocalDatabaseConfigurationPanel::Recargar()
 
83
                {
 
84
                        std::string dicomDir;
 
85
                        
 
86
                        if(!GNC::GCS::ConfigurationController::Instance()->readStringUser("/GinkgoCore/Estacion","DicomDir", dicomDir)) {
 
87
                                m_pathDicomDir = FROMPATH(GNC::GCS::HistoryController::Instance()->GetGinkgoDicomDir());
 
88
                        } else {
 
89
                                m_pathDicomDir = wxString::FromUTF8(dicomDir.c_str());
 
90
                        }
 
91
                        m_pDICOMDir->SetValue(m_pathDicomDir);
 
92
                        
 
93
                        //autocleaning dicomdir
 
94
                        int tmp;
 
95
                        //older than...
 
96
                        GNC::GCS::ConfigurationController::Instance()->readIntUser("/GinkgoCore/Station/CleanDicomDir", "AcquisitionOlderThan", tmp, -1);
 
97
                        if (tmp > 0) {
 
98
                                int i = 0;
 
99
                                for (std::map<int, std::string>::const_iterator it = m_mapTimePeriods.begin(); it != m_mapTimePeriods.end(); ++it,i++) {
 
100
                                        if ((*it).first == tmp) {
 
101
                                                m_pChoiceDeleteOlder->SetSelection(i);
 
102
                                                break;
 
103
                                        }
 
104
                                }
 
105
                                m_pChoiceDeleteOlder->Enable(true);
 
106
                                m_pCheckDeleteOlder->SetValue(true);
 
107
                        } else {
 
108
                                m_pChoiceDeleteOlder->Enable(false);
 
109
                                m_pCheckDeleteOlder->SetValue(false);
 
110
                        }
 
111
                        //hdFreeSpace...
 
112
                        GNC::GCS::ConfigurationController::Instance()->readIntUser("/GinkgoCore/Station/CleanDicomDir", "HDFreeSpace", tmp, -1);
 
113
                        if (tmp > 0) {
 
114
                                m_pSpinHDSpace->SetValue(tmp);
 
115
                                m_pSpinHDSpace->Enable(true);
 
116
                                m_pCheckHDFreeSpace->SetValue(true);
 
117
                        } else {
 
118
                                m_pSpinHDSpace->Enable(false);
 
119
                                m_pCheckHDFreeSpace->SetValue(false);
 
120
                        }
 
121
                        //DicomDirSize...
 
122
                        GNC::GCS::ConfigurationController::Instance()->readIntUser("/GinkgoCore/Station/CleanDicomDir", "DicomDirSize", tmp, -1);
 
123
                        if (tmp > 0) {
 
124
                                m_pSpinDicomDirSize->SetValue(tmp);
 
125
                                m_pSpinDicomDirSize->Enable(true);
 
126
                                m_pCheckDicomDirSize->SetValue(true);
 
127
                        } else {
 
128
                                m_pSpinDicomDirSize->Enable(false);
 
129
                                m_pCheckDicomDirSize->SetValue(false);
 
130
                        }
 
131
                }
 
132
 
 
133
                //region "Metodos de IPasoConfiguracion"
 
134
                wxWindow* LocalDatabaseConfigurationPanel::GetPanel()
 
135
                {
 
136
                        return this;
 
137
                }
 
138
 
 
139
                std::string LocalDatabaseConfigurationPanel::GetTitle()
 
140
                {
 
141
                        return _Std("Local database");
 
142
                }
 
143
 
 
144
                std::string LocalDatabaseConfigurationPanel::GetCabecera()
 
145
                {
 
146
                        return _Std("Local DICOM Dir setup");
 
147
                }
 
148
 
 
149
                bool LocalDatabaseConfigurationPanel::Validar()
 
150
                {
 
151
                        wxString path = m_pDICOMDir->GetValue();
 
152
                        wxFileName fileName(path);
 
153
                        if(!fileName.IsAbsolute()) {
 
154
                                wxFileName pathOfExec(wxStandardPaths::Get().GetExecutablePath());
 
155
                                fileName.MakeAbsolute(pathOfExec.GetPath());
 
156
                                path = fileName.GetFullPath();
 
157
                        }
 
158
 
 
159
                        if(!wxDir::Exists(path)) {
 
160
                                //se pregunta si desea crearlo
 
161
                                int answer = wxMessageBox(_("The selected directory does not exist\nWould you like to create it?"),_("Info"),wxYES_NO,this);
 
162
                                if(answer == wxNO) {
 
163
                                        return false;
 
164
                                } else {
 
165
                #ifdef _WIN32
 
166
                                        wxMkdir(path,511);
 
167
                #else
 
168
                                        wxMkDir(path.ToUTF8(), 0770);
 
169
                #endif
 
170
                                        if(!wxDirExists(path))
 
171
                                        {
 
172
                                                wxMessageBox(_("Failed to create directory, make sure the path is correct and you have permissions on parent directory"), _("Info"));
 
173
                                                return false;
 
174
                                        }
 
175
                                }
 
176
                        } else {
 
177
                                //se comprueba que puede escribir(escribimos y borramos un fichero chorra)
 
178
                                wxString pathFicheroPrueba = path + wxFileName::GetPathSeparator() + wxString::Format(wxT("%d"),rand());
 
179
                                while(wxFileExists(pathFicheroPrueba)) {
 
180
                                        pathFicheroPrueba = path + wxFileName::GetPathSeparator() + wxString::Format(wxT("%d"),rand());
 
181
                                }
 
182
                                {
 
183
                                        wxFile ficheroTmp;
 
184
                                        if(!ficheroTmp.Create(pathFicheroPrueba,false)){
 
185
                                                if(!wxFileExists(pathFicheroPrueba) ) {
 
186
                                                        wxMessageBox(_("There was an error reading the directory, make sure you have write permissions on it"), _("Info"));
 
187
                                                                return false;
 
188
                                                }
 
189
                                        }
 
190
                                        ficheroTmp.Write(wxT("prueba"));
 
191
                                        ficheroTmp.Close();
 
192
                                }
 
193
                                wxRemoveFile(pathFicheroPrueba);
 
194
                        }
 
195
 
 
196
                        return true;
 
197
                }
 
198
 
 
199
                bool LocalDatabaseConfigurationPanel::Guardar()
 
200
                {
 
201
                        //se actualiza el fichero de configuracion
 
202
                        wxFileName dirAnterior(m_pathDicomDir);
 
203
                        wxFileName dirNuevo(m_pDICOMDir->GetValue());
 
204
                        if(dirAnterior != dirNuevo)
 
205
                        {
 
206
                                GNC::GCS::ConfigurationController::Instance()->writeStringUser("/GinkgoCore/Estacion", "DicomDir",std::string(m_pDICOMDir->GetValue().ToUTF8()));
 
207
                                //se vacia el dicomdir actual y se carga el nuevo...
 
208
                                GNC::GCS::HistoryController::FreeInstance();
 
209
                                if (!GNC::GCS::HistoryController::Instance()->IsOk()) {
 
210
                                        //revert changes....
 
211
                                        GNC::GCS::ConfigurationController::Instance()->writeStringUser("/GinkgoCore/Estacion", "DicomDir", std::string(m_pathDicomDir.ToUTF8()));
 
212
                                        //se vacia el dicomdir actual y se carga el nuevo...
 
213
                                        GNC::GCS::HistoryController::FreeInstance();
 
214
                                }
 
215
                                GNC::GUI::HistoryPanel3::Instance()->ReloadHistory();
 
216
                                
 
217
                        }
 
218
 
 
219
                        //dicomdir auto cleaning
 
220
                        //older than...
 
221
                        int tmp = -1;
 
222
                        if (m_pChoiceDeleteOlder->IsEnabled()) {
 
223
                                for (std::map<int, std::string>::const_iterator it = m_mapTimePeriods.begin(); it != m_mapTimePeriods.end(); ++it) {
 
224
                                        if (wxString::FromUTF8((*it).second.c_str()).CompareTo(m_pChoiceDeleteOlder->GetString(m_pChoiceDeleteOlder->GetSelection())) == 0) {
 
225
                                                tmp = (*it).first;
 
226
                                                break;
 
227
                                        }
 
228
                                }
 
229
                        }
 
230
                        GNC::GCS::ConfigurationController::Instance()->writeIntUser("/GinkgoCore/Station/CleanDicomDir", "AcquisitionOlderThan", tmp);
 
231
                        //hdFreeSpace...
 
232
                        tmp = -1;
 
233
                        if (m_pSpinHDSpace->IsEnabled()) {
 
234
                                tmp = m_pSpinHDSpace->GetValue();
 
235
                        }
 
236
                        GNC::GCS::ConfigurationController::Instance()->writeIntUser("/GinkgoCore/Station/CleanDicomDir", "HDFreeSpace", tmp);
 
237
                        //DicomDirSize...
 
238
                        tmp = -1;
 
239
                        if (m_pSpinDicomDirSize->IsEnabled()) {
 
240
                                tmp = m_pSpinDicomDirSize->GetValue();
 
241
                        }
 
242
                        GNC::GCS::ConfigurationController::Instance()->writeIntUser("/GinkgoCore/Station/CleanDicomDir", "DicomDirSize", tmp);
 
243
 
 
244
                        GNC::GCS::AutoCleaningController::Instance()->Reset();
 
245
 
 
246
                        return true;
 
247
                }
 
248
                //endregion
 
249
 
 
250
                void LocalDatabaseConfigurationPanel::OnTextoCambiado(wxCommandEvent &)
 
251
                {
 
252
                        if(IsShown()){
 
253
                                OnPropiedadCambiada();
 
254
                        }
 
255
                }
 
256
 
 
257
                void LocalDatabaseConfigurationPanel::OnSeleccionarDirectorio(wxCommandEvent &)
 
258
                {
 
259
                        wxDirDialog seleccionarDirectorio(this,_("Select DICOMDIR"),m_pDICOMDir->GetValue(),wxDD_DEFAULT_STYLE|wxDD_NEW_DIR_BUTTON);
 
260
                        int response = seleccionarDirectorio.ShowModal();
 
261
                        if (response == wxID_OK)
 
262
                        {
 
263
                                m_pDICOMDir->SetValue(seleccionarDirectorio.GetPath());
 
264
                        }
 
265
                }
 
266
 
 
267
                void LocalDatabaseConfigurationPanel::OnSize(wxSizeEvent & event){
 
268
                        wxSize oldSize = m_pstaticTextAdvertencia->GetSize();
 
269
                        Freeze();
 
270
                        m_pstaticTextAdvertencia->Freeze();
 
271
                        m_pstaticTextAdvertencia->SetLabel(_("Warning, to update the directory, you must close current opened series."));
 
272
                        m_pstaticTextAdvertencia->Wrap( event.GetSize().x - 25 );
 
273
                        m_pstaticTextAdvertencia->Thaw();
 
274
                        Thaw();
 
275
                        wxSize newSize = m_pstaticTextAdvertencia->GetSize();
 
276
                        if (newSize != oldSize) {
 
277
                                Layout();
 
278
                                event.Skip(false);
 
279
                        } else {
 
280
                                event.Skip(true);
 
281
                        }
 
282
                }
 
283
 
 
284
                
 
285
                void LocalDatabaseConfigurationPanel::OnCheckOlderStudies( wxCommandEvent& event )
 
286
                {
 
287
                        m_pChoiceDeleteOlder->Enable(m_pCheckDeleteOlder->GetValue());
 
288
                        OnPropiedadCambiada();
 
289
                        event.Skip(true);
 
290
                }
 
291
 
 
292
                void LocalDatabaseConfigurationPanel::OnCheckDicomDirSize(wxCommandEvent& event)
 
293
                {
 
294
                        m_pSpinDicomDirSize->Enable(m_pCheckDicomDirSize->GetValue());
 
295
                        OnPropiedadCambiada();
 
296
                        event.Skip(true);
 
297
                }
 
298
 
 
299
                void LocalDatabaseConfigurationPanel::OnCheckHDSpace(wxCommandEvent& event)
 
300
                {
 
301
                        m_pSpinHDSpace->Enable(m_pCheckHDFreeSpace->GetValue());
 
302
                        OnPropiedadCambiada();
 
303
                        event.Skip(true);
 
304
                }
 
305
 
 
306
                void LocalDatabaseConfigurationPanel::OnSpinCtrl(wxSpinEvent& /*evt*/)
 
307
                {
 
308
                        OnPropiedadCambiada();
 
309
                }
 
310
 
 
311
                void LocalDatabaseConfigurationPanel::OnOptionModified(wxCommandEvent& /*evt*/)
 
312
                {
 
313
                        OnPropiedadCambiada();
 
314
                }
 
315
        }
 
316
}