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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille
  • Date: 2011-05-02 08:09:26 UTC
  • Revision ID: james.westby@ubuntu.com-20110502080926-bql5wep49c7hg91t
Tags: upstream-2.4.1.1
ImportĀ upstreamĀ versionĀ 2.4.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  
 
3
 *  $Id: panelconfiguracionpacs.cpp 3787 2011-04-29 06:38:01Z tovar $
 
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
 */
 
14
#include <vector>
 
15
#include <sstream>
 
16
#include <limits>
 
17
 
 
18
#include <main/controllers/dcmtk/dicomservers.h>
 
19
#include <main/controllers/controladorextensiones.h>
 
20
#include <main/controllers/dcmtk/dicomnetwork.h>
 
21
#include <main/controllers/dcmtk/dicomechoassociation.h>
 
22
#include <main/controllers/controladorlog.h>
 
23
#include <main/controllers/controladorpermisos.h>
 
24
 
 
25
#include <wx/msgdlg.h>
 
26
#include <wx/msgout.h>
 
27
#include <wx/filename.h>
 
28
#include <wx/confbase.h>
 
29
#include <wx/valtext.h>
 
30
#include <wx/ginkgostyle/ginkgostyle.h>
 
31
 
 
32
#include <wx/file.h>
 
33
#include <wx/textfile.h>
 
34
#include <wx/dir.h>
 
35
#include <wx/filedlg.h>
 
36
#include <wx/log.h>
 
37
#include <wx/busyinfo.h>
 
38
#include <wx/xml/xml.h>
 
39
#include <api/internacionalizacion.h>
 
40
 
 
41
#include "panelconfiguracionpacs.h"
 
42
 
 
43
#include <sstream>
 
44
 
 
45
#include <main/entorno.h>
 
46
#include <resources/ginkgoresourcemanager.h>
 
47
 
 
48
 
 
49
namespace GNC {
 
50
        namespace GUI {
 
51
 
 
52
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
53
///////////////////////DialogoEditarCertificado//////////////////////////////////////////////////////////////////////////////////
 
54
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
55
 
 
56
                class DialogoEditarCertificado: public DialogoEditarCertificadoBase
 
57
                {
 
58
                public:
 
59
                        DialogoEditarCertificado(wxWindow* pParent, const std::string& cert, const std::string& privateKey, bool permitirDefecto): DialogoEditarCertificadoBase(pParent)
 
60
                        {
 
61
                                m_Ok = false;
 
62
                                m_pTextoCertificado->SetValue(wxString::FromUTF8(cert.c_str()));
 
63
                                m_pTextoPrivateKey->SetValue(wxString::FromUTF8(privateKey.c_str()));
 
64
                                
 
65
                                if (permitirDefecto) {
 
66
                                        m_pCheckDefault->SetValue(cert.size() == 0 && privateKey.size() == 0);
 
67
                                } else {
 
68
                                        m_pCheckDefault->SetValue(false);
 
69
                                        m_pPanelDefault->Show(false);
 
70
                                        m_pSepDefault->Show(false);
 
71
                                        m_pBody->Layout();
 
72
                                        Layout();
 
73
                                        Refresh(true);
 
74
                                }
 
75
                                
 
76
                                RefrescarEstado();
 
77
                        }
 
78
                        ~DialogoEditarCertificado()
 
79
                        {}
 
80
 
 
81
                        virtual void OnAceptarClick(wxCommandEvent&)
 
82
                        {
 
83
                                if (Validar()) {
 
84
                                        m_Ok = true;
 
85
                                        Close();
 
86
                                }
 
87
                        }
 
88
 
 
89
                        void CargarFichero(bool publicKey) 
 
90
                        {
 
91
                                wxFileDialog seleccionarFichero (this, _("Select certificate"), wxT(""), wxT(""), _("PEM files(*.pem;*.key)|*.pem;*.key|All files (*.*)|*.*"),wxFD_FILE_MUST_EXIST|wxFD_OPEN);
 
92
                                int response = seleccionarFichero.ShowModal();
 
93
                                if (response == wxID_OK) {
 
94
                                        wxTextFile textFile(seleccionarFichero.GetPath());
 
95
                                        if (textFile.Open()) {
 
96
                                                wxString cadena;
 
97
                                                if (!textFile.Eof()) {
 
98
                                                        cadena += textFile.GetNextLine();
 
99
                                                        while(!textFile.Eof()) {
 
100
                                                                cadena += wxT("\n") + textFile.GetNextLine();
 
101
                                                        }
 
102
                                                }
 
103
                                                if (publicKey) {
 
104
                                                        m_pTextoCertificado->SetValue(cadena);
 
105
                                                } else {
 
106
                                                        m_pTextoPrivateKey->SetValue(cadena);
 
107
                                                }
 
108
                                                textFile.Close();
 
109
                                        }
 
110
                                }                               
 
111
                        }
 
112
 
 
113
                        virtual void OnLoadPrivateClick(wxCommandEvent& )
 
114
                        {
 
115
                                CargarFichero(false);
 
116
                        }
 
117
 
 
118
                        virtual void OnLoadPublicClick(wxCommandEvent& )
 
119
                        {
 
120
                                CargarFichero(true);
 
121
                        }
 
122
 
 
123
                        virtual void OnResetToDefault(wxCommandEvent& ) 
 
124
                        {
 
125
                                if (m_pPanelDefault->IsShown()) {
 
126
                                        m_pCheckDefault->SetValue(true);
 
127
                                } else {
 
128
                                        //cargamos el certificado por defecto...
 
129
#ifdef GINKGO_PUBLIC_KEY
 
130
                                        m_pTextoCertificado->SetValue(wxString::FromUTF8(GINKGO_PUBLIC_KEY));
 
131
#else
 
132
                                        m_pTextoCertificado->SetValue(wxT(""));
 
133
#endif
 
134
#ifdef GINKGO_PRIVATE_KEY
 
135
                                        m_pTextoPrivateKey->SetValue(wxString::FromUTF8(GINKGO_PRIVATE_KEY));
 
136
#else
 
137
                                        m_pTextoPrivateKey->SetValue(wxT(""));
 
138
#endif
 
139
                                }
 
140
 
 
141
                                RefrescarEstado();
 
142
                        }
 
143
 
 
144
                        virtual void OnCheckDefault(wxCommandEvent&)
 
145
                        {
 
146
                                RefrescarEstado();
 
147
                        }
 
148
                        virtual void RefrescarEstado()
 
149
                        {
 
150
                                m_pPanelPublic->Enable(!m_pCheckDefault->IsChecked());
 
151
                                m_pPanelPublic->Refresh();
 
152
                                m_pPanelPrivate->Enable(!m_pCheckDefault->IsChecked());
 
153
                                m_pPanelPrivate->Refresh();
 
154
 
 
155
                                if (m_pCheckDefault->IsChecked()) {
 
156
                                        m_pTextoCertificado->SetValue(wxT(""));
 
157
                                        m_pTextoPrivateKey->SetValue(wxT(""));
 
158
                                }
 
159
                        }
 
160
 
 
161
                        std::string GetPublicValue()
 
162
                        {
 
163
                                std::string cert(m_pTextoCertificado->GetValue().ToUTF8());
 
164
                                return cert;
 
165
                        }
 
166
 
 
167
                        std::string GetPrivateValue()
 
168
                        {
 
169
                                std::string cert(m_pTextoPrivateKey->GetValue().ToUTF8());
 
170
                                return cert;
 
171
                        }
 
172
                        
 
173
                        bool GetUseDefaultCert()
 
174
                        {
 
175
                                return m_pCheckDefault->GetValue();
 
176
                        }
 
177
                        
 
178
                        bool Validar()
 
179
                        {
 
180
                                bool ok = true;
 
181
                                std::stringstream sstream;
 
182
 
 
183
                                if (!m_pCheckDefault->IsChecked() && m_pCheckDefault->IsShown()) {
 
184
                                        if (m_pTextoCertificado->GetValue().size() == 0 || m_pTextoPrivateKey->GetValue().size() == 0)
 
185
                                        {
 
186
                                                ok = false;
 
187
                                                sstream << _Std("You have to set private and public key") ;
 
188
                                        }
 
189
                                        if (!ok) {
 
190
                                                wxMessageBox(wxString::FromUTF8(sstream.str().c_str()),_("Info"),wxOK | wxICON_INFORMATION, this);
 
191
                                        }
 
192
                                }
 
193
                                return ok;
 
194
                        }
 
195
 
 
196
                        bool m_Ok;      
 
197
                };
 
198
 
 
199
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
200
///////////////////////DialogoLocalPACS//////////////////////////////////////////////////////////////////////////////////////////
 
201
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
202
 
 
203
                class DialogoLocalPACS: public DialogoLocalPACSBase
 
204
                {
 
205
                public:
 
206
                        DialogoLocalPACS(wxWindow* pParent): DialogoLocalPACSBase(pParent)
 
207
                        {
 
208
                                m_Ok = false;
 
209
                        }
 
210
                        ~DialogoLocalPACS()
 
211
                        {}
 
212
 
 
213
                        void SetParametros(PanelConfiguracionPACS::TipoConfigLocal& pacsLocal)
 
214
                        {
 
215
                                m_pUseTLS->SetValue(pacsLocal.useTLS);
 
216
 
 
217
                                m_pVerifyServer->SetValue(pacsLocal.verifyCredentials);
 
218
 
 
219
                                m_certificado = pacsLocal.certificate;
 
220
                                m_privateKey = pacsLocal.privateKey;
 
221
                                if (m_certificado.size()>0 || m_privateKey.size()>0) {
 
222
                                        m_pBCert->SetLabel(_("Change ..."));
 
223
                                } else {
 
224
                                        m_pBCert->SetLabel(_("Import ..."));
 
225
                                }
 
226
                        }
 
227
 
 
228
                        void GetParametros(PanelConfiguracionPACS::TipoConfigLocal& pacsLocal)
 
229
                        {
 
230
                                pacsLocal.useTLS = m_pUseTLS->GetValue();
 
231
 
 
232
                                pacsLocal.verifyCredentials = m_pVerifyServer->GetValue();
 
233
 
 
234
                                pacsLocal.certificate = m_certificado;
 
235
                                pacsLocal.privateKey = m_privateKey;
 
236
                        }
 
237
 
 
238
 
 
239
                        virtual void OnEditCertificate(wxCommandEvent&)
 
240
                        {
 
241
                                DialogoEditarCertificado dlg(this, m_certificado, m_privateKey, false);
 
242
                                dlg.ShowModal();
 
243
                                if (dlg.m_Ok) {
 
244
                                        m_certificado = dlg.GetPublicValue();
 
245
                                        m_privateKey = dlg.GetPrivateValue();
 
246
                                        if (m_certificado.size()>0 || m_privateKey.size()>0) {
 
247
                                                m_pBCert->SetLabel(_("Change ..."));
 
248
                                        } else {
 
249
                                                m_pBCert->SetLabel(_("Import ..."));
 
250
                                        }
 
251
                                }
 
252
                        }
 
253
 
 
254
                        virtual void OnAceptarClick(wxCommandEvent&)
 
255
                        {
 
256
                                if (Validar()) {
 
257
                                        m_Ok = true;
 
258
                                        Close();
 
259
                                }
 
260
                        }
 
261
 
 
262
                        bool Validar()
 
263
                        {
 
264
                                bool ok = true;
 
265
                                std::stringstream sstream;
 
266
 
 
267
                                if (m_pUseTLS->GetValue() 
 
268
                                        && (m_certificado.size() == 0 || m_privateKey.size() == 0))
 
269
                                {
 
270
                                        ok = false;
 
271
                                        sstream << _Std("If you want to use SSL/TLS you have to set a valid certificate and a valid private key") ;
 
272
                                }
 
273
                                if (!ok) {
 
274
                                        wxMessageBox(wxString::FromUTF8(sstream.str().c_str()),_("Info"),wxOK | wxICON_INFORMATION, this);
 
275
                                }
 
276
                                return ok;
 
277
                        }
 
278
 
 
279
                        bool m_Ok;
 
280
                        std::string m_certificado;
 
281
                        std::string m_privateKey;
 
282
                };
 
283
 
 
284
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
285
///////////////////////DialogoServidorPACS///////////////////////////////////////////////////////////////////////////////////////
 
286
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
287
                class DialogoServidorPACS: public DialogoServidorPACSBase
 
288
                {
 
289
                public:
 
290
                        DialogoServidorPACS(wxWindow* pParent, PanelConfiguracionPACS::TipoConfigLocal& configLocal, const wxString& strPuertoLocal, const wxString& aetLocal) : DialogoServidorPACSBase(pParent), m_configLocal(configLocal)
 
291
                        {
 
292
                                wxTextValidator OnlyNum = wxTextValidator(wxFILTER_NUMERIC);
 
293
                                m_pPuerto->SetValidator(OnlyNum);
 
294
 
 
295
                                m_pPDU->SetValue(16384);
 
296
 
 
297
                                m_aetLocal= aetLocal.ToUTF8();
 
298
 
 
299
                                long puertoLocal;
 
300
                                if(strPuertoLocal.ToLong(&puertoLocal)){
 
301
                                        m_puertoLocal = puertoLocal;
 
302
                                }
 
303
                                else {
 
304
                                        m_puertoLocal = 11112;
 
305
                                }
 
306
 
 
307
                                if(!GNC::GCS::ControladorPermisos::Instance()->Get("core.pacs.limits","pacs_tls")) {
 
308
                                        m_pPanelSeguridad->Show(false);
 
309
                                        m_notebook1->RemovePage(1);
 
310
                                }
 
311
                        }
 
312
 
 
313
                        ~DialogoServidorPACS()
 
314
                        {
 
315
 
 
316
                        }
 
317
 
 
318
                        void GetParametros(PanelConfiguracionPACS::TipoPACS& tipoPacs)
 
319
                        {
 
320
                                tipoPacs.id = std::string(m_pId->GetValue().ToUTF8());
 
321
                                tipoPacs.aet= std::string(m_pAET->GetValue().ToUTF8());
 
322
                                tipoPacs.host = std::string(m_pHost->GetValue().ToUTF8());
 
323
                                tipoPacs.puerto = atoi(m_pPuerto->GetValue().ToUTF8());
 
324
                                tipoPacs.pdu = m_pPDU->GetValue();
 
325
 
 
326
                                tipoPacs.retrieveWithMove = m_pRetrieveMethod->GetSelection() == 0;
 
327
                                tipoPacs.retrieveSeries = m_pRetrieveMode->GetSelection() == 0;
 
328
 
 
329
                                if(GNC::GCS::ControladorPermisos::Instance()->Get("core.pacs.limits","pacs_tls")) {
 
330
                                        tipoPacs.useTLS = m_pUseSSL->GetValue();
 
331
 
 
332
                                        tipoPacs.pacsUser = m_pUser->GetValue().ToUTF8();
 
333
                                        tipoPacs.pacsPass = m_pPassword->GetValue().ToUTF8();
 
334
                                        
 
335
                                        tipoPacs.verifyCredentials = m_pVerifyServer->GetValue();
 
336
 
 
337
                                        tipoPacs.certificate = m_certificado;
 
338
                                        tipoPacs.privateKey = m_privateKey;
 
339
                                }
 
340
                        }
 
341
 
 
342
                        void SetParametros(PanelConfiguracionPACS::TipoPACS& tipoPacs)
 
343
                        {
 
344
                                m_pId->SetValue(wxString::FromUTF8(tipoPacs.id.c_str()));
 
345
                                m_pAET->SetValue(wxString::FromUTF8(tipoPacs.aet.c_str()));
 
346
                                m_pHost->SetValue(wxString::FromUTF8(tipoPacs.host.c_str()));
 
347
                                m_pPuerto->SetValue(wxString::Format(wxT("%d"), tipoPacs.puerto));
 
348
                                m_pPDU->SetValue(wxString::Format(wxT("%d"), tipoPacs.pdu));
 
349
 
 
350
                                m_pRetrieveMethod->SetSelection(tipoPacs.retrieveWithMove?0:1);
 
351
                                m_pRetrieveMode->SetSelection(tipoPacs.retrieveSeries?0:1);
 
352
 
 
353
                                if(GNC::GCS::ControladorPermisos::Instance()->Get("core.pacs.limits","pacs_tls")) {
 
354
                                        m_pUseSSL->SetValue(tipoPacs.useTLS);
 
355
                                        m_pUser->SetValue(wxString::FromUTF8(tipoPacs.pacsUser.c_str()));
 
356
                                        m_pPassword->SetValue(wxString::FromUTF8(tipoPacs.pacsPass.c_str()));
 
357
 
 
358
                                        m_pVerifyServer->SetValue(tipoPacs.verifyCredentials);
 
359
 
 
360
                                        m_certificado = tipoPacs.certificate;
 
361
                                        m_privateKey = tipoPacs.privateKey;
 
362
                                }
 
363
                        }
 
364
 
 
365
                        virtual void OnAdvancedConfiguration(wxCommandEvent&)
 
366
                        {
 
367
                                DialogoEditarCertificado dlg(this, m_certificado, m_privateKey, true);
 
368
                                dlg.ShowModal();
 
369
                                if (dlg.m_Ok) {
 
370
                                        if (dlg.GetUseDefaultCert()) {
 
371
                                                m_certificado = m_configLocal.certificate;
 
372
                                                m_privateKey = m_configLocal.privateKey;
 
373
                                        }
 
374
                                        else {
 
375
                                                m_certificado = dlg.GetPublicValue();
 
376
                                                m_privateKey = dlg.GetPrivateValue();
 
377
                                        }
 
378
                                }
 
379
                        }
 
380
 
 
381
                        virtual void OnCancelClick(wxCommandEvent &){
 
382
                                m_Ok=false;
 
383
                                Close();
 
384
                        }
 
385
 
 
386
                        virtual void OnOkClick(wxCommandEvent &){
 
387
                                if(Validar()) {
 
388
                                        m_Ok=true;
 
389
                                        Close();
 
390
                                }
 
391
                        }
 
392
 
 
393
                        bool Validar ()
 
394
                        {
 
395
                                bool ok = true;
 
396
                                if(m_pId->GetValue() != wxEmptyString && m_pAET->GetValue() != wxEmptyString && m_pHost->GetValue() != wxEmptyString && m_pPuerto->GetValue() != wxEmptyString){
 
397
                                        std::stringstream sstream;
 
398
                                        sstream << _Std("There are this errors: ");
 
399
 
 
400
                                        long numero;
 
401
                                        if(!m_pPuerto->GetValue().ToLong(&numero)){
 
402
                                                ok = false;
 
403
                                                sstream << _Std("\n- The port must be a positive short integer (16 bits)");
 
404
                                        } else{
 
405
                                                if(numero > 32767){//maxshort
 
406
                                                        ok = false;
 
407
                                                        sstream <<_Std("\n- The port is too large");
 
408
                                                }
 
409
                                        }
 
410
 
 
411
                                        if(m_pAET->GetLabel().size() >16) {
 
412
                                                ok = false;
 
413
                                                sstream <<_Std("\n- The maximum length of the AET is 16 characters");
 
414
                                        }
 
415
 
 
416
                                        if (m_pPDU->GetValue() != 0) {
 
417
 
 
418
                                                if(!m_pPDU->GetValue()){
 
419
                                                        ok = false;
 
420
                                                        sstream << _Std("\n- The PDU size should be greater than or equal to zero (default = 16384)");
 
421
                                                } else{
 
422
                                                        if(m_pPDU->GetValue() > MAX_PDU_LENGTH){ // max, viene de esta constante ASC_MAXIMUMPDUSIZE de DCMTK
 
423
                                                                ok = false;
 
424
                                                                sstream << _Std("\n- The maximum value of the PDU is ") <<  MAX_PDU_LENGTH << "(" << MAX_PDU_LENGTH/1024 << "K)";
 
425
                                                        }
 
426
                                                        if(m_pPDU->GetValue() < MIN_PDU_LENGTH){ // min, viene de esta constante ASC_MINIMUMPDUSIZE de DCMTK
 
427
                                                                ok = false;
 
428
                                                                sstream << _Std("\n- The minimum value of the PDU is ") <<  MIN_PDU_LENGTH << "(" << MIN_PDU_LENGTH/1024 << "K)" ;
 
429
                                                        }
 
430
                                                }
 
431
                                        }
 
432
 
 
433
                                        if (m_pUseSSL->GetValue() && ( (m_certificado.size() == 0 || m_privateKey.size() == 0) && (m_configLocal.certificate.size() == 0 || m_configLocal.privateKey.size() == 0 )  ) )
 
434
                                        {
 
435
                                                ok = false;
 
436
                                                sstream << _Std("\n- If you want to use SSL/TLS you have to set a valid certificate and private key") ;
 
437
                                        }
 
438
 
 
439
                                        if(!ok)
 
440
                                                wxMessageBox(wxString::FromUTF8(sstream.str().c_str()),_("Info"),wxOK | wxICON_INFORMATION, this);
 
441
                                }else{
 
442
                                        ok = false;
 
443
                                        wxMessageBox(_("You must fill in all fields to continue"),_("Info"),wxOK | wxICON_INFORMATION, this);
 
444
                                }
 
445
                                return ok;
 
446
                        }
 
447
                        virtual void OnProbarClick(wxCommandEvent &)
 
448
                        {
 
449
                                if(Validar()) {
 
450
                                        long puerto;
 
451
                                        long pdu = m_pPDU->GetValue();
 
452
                                        if(m_pPuerto->GetValue().ToLong(&puerto)){
 
453
 
 
454
                                                EchoAssociation as("C-ECHO");
 
455
                                                if (m_pUseSSL->GetValue()) {
 
456
                                                        if (m_certificado.empty() || m_privateKey.empty()) {                                                    
 
457
                                                                as.SetTLS(m_configLocal.certificate, m_configLocal.privateKey, m_pVerifyServer->GetValue());
 
458
                                                        }
 
459
                                                        else {
 
460
                                                                as.SetTLS(m_certificado, m_privateKey, m_pVerifyServer->GetValue());
 
461
                                                        }
 
462
                                                }
 
463
                                                if (m_pUser->GetValue() != wxEmptyString) {
 
464
                                                        as.SetUserPass(std::string(m_pUser->GetValue().ToUTF8()), std::string(m_pPassword->GetValue().ToUTF8()));
 
465
                                                }
 
466
                                                CONDITION cond;
 
467
                                                wxBusyInfo* info = new wxBusyInfo(_("Testing the connection to the server ..."));
 
468
                                                
 
469
                                                std::string aet(m_pAET->GetValue().ToUTF8());
 
470
                                                std::string host(m_pHost->GetValue().ToUTF8());
 
471
 
 
472
                                                as.Create(aet, host, puerto, m_aetLocal, UID_VerificationSOPClass);
 
473
 
 
474
                                                GIL::DICOM::DCMTK::Network* pNetwork = NULL;
 
475
                                                try {
 
476
                                                        pNetwork = GIL::DICOM::DCMTK::Network::Instance(this);
 
477
                                                }
 
478
                                                catch(...)
 
479
                                                {
 
480
                                                }
 
481
                                                if(pNetwork != NULL) {
 
482
                                                        as.SetTimeout(5);
 
483
                                                        pNetwork->InitializeNetwork(as.GetTimeout());
 
484
                                                        cond = pNetwork->ConnectAssociation(&as, pdu);
 
485
                                                        if (cond.good()) {
 
486
                                                                if (as.SendEchoRequest())
 
487
                                                                {                       
 
488
                                                                        LOG_DEBUG("C-TEST", _Std("Connection test successful"));
 
489
                                                                        delete info;
 
490
                                                                        info = NULL;
 
491
                                                                        wxMessageBox(_("Successful connection test."),_("Info"),wxOK | wxICON_INFORMATION, this);
 
492
                                                                }
 
493
                                                                else {
 
494
                                                                        delete info;
 
495
                                                                        info = NULL;
 
496
                                                                        wxMessageBox(_("The service did not respond correctly to the C-ECHO"),_("Error"), wxICON_ERROR, this);
 
497
                                                                }
 
498
                                                        }
 
499
                                                        else {
 
500
                                                                LOG_ERROR("C-TEST", _Std("The service did not respond properly:") << cond.text());
 
501
                                                                delete info;
 
502
                                                                info = NULL;
 
503
                                                                wxMessageBox(_("The service did not respond correctly to the DICOM standard:")  + wxString::FromUTF8(cond.text()), _("Error"), wxICON_ERROR, this);
 
504
                                                        }
 
505
                                                        as.Drop();
 
506
                                                        GIL::DICOM::DCMTK::Network::FreeInstance(this);
 
507
                                                        pNetwork = NULL;
 
508
                                                }
 
509
                                                else {
 
510
                                                        LOG_ERROR("C-TEST", _Std("Unable to connect: Could not start network support."));
 
511
                                                        delete info;
 
512
                                                        info = NULL;
 
513
                                                        wxMessageBox(_("Error starting network support"), _("Error"), wxICON_ERROR, this);
 
514
                                                }
 
515
                                        }
 
516
                                }
 
517
 
 
518
                        }
 
519
 
 
520
                        PanelConfiguracionPACS::TipoConfigLocal& m_configLocal;
 
521
 
 
522
                        bool m_Ok;
 
523
                        std::string m_aetLocal;
 
524
                        long m_puertoLocal;
 
525
                        std::string m_certificado;
 
526
                        std::string m_privateKey;
 
527
                };
 
528
 
 
529
 
 
530
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
531
///////////////////////PanelConfiguracionPACS////////////////////////////////////////////////////////////////////////////////////
 
532
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
533
 
 
534
                PanelConfiguracionPACS::PanelConfiguracionPACS(wxWindow* pParent,IDialogoConfiguracion* pDialogo): PanelConfiguracionPACSBase(pParent), IPasoConfiguracion(pDialogo)
 
535
                {
 
536
                        this->m_pTreeListPACS->AddColumn(_("Name"), 200, wxALIGN_LEFT, -1, true, false);
 
537
                        this->m_pTreeListPACS->AddColumn(_("Default"), 50, wxALIGN_LEFT, -1, true, false);
 
538
                        Recargar();
 
539
                        
 
540
                        m_pHelpBitmap->SetBitmap(GinkgoResourcesManager::IconosMenus::GetIcoHelp());
 
541
 
 
542
                        if(!GNC::GCS::ControladorPermisos::Instance()->Get("core.pacs.limits","pacs_tls")) {
 
543
                                m_pBAdvanced->Show(false);
 
544
                                m_pPACSLocal->Layout();
 
545
                                this->Layout();
 
546
                                this->Refresh(true);
 
547
                        }
 
548
 
 
549
                        m_pTreeListPACS->Connect(wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( PanelConfiguracionPACS::OnListaPACSDClick ), NULL, this );
 
550
                        m_pTreeListPACS->Connect(wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( PanelConfiguracionPACS::OnListaPACSChoice ), NULL, this );
 
551
                }
 
552
 
 
553
                PanelConfiguracionPACS::~PanelConfiguracionPACS()
 
554
                {
 
555
                        m_servidores.clear();
 
556
                }
 
557
 
 
558
                void PanelConfiguracionPACS::Recargar()
 
559
                {
 
560
                        wxConfigBase * config = wxConfigBase::Get();
 
561
                        //se actualiza el fichero de configuracion
 
562
 
 
563
                        config->SetPath(wxT("/GinkgoCore/PACS/Local"));
 
564
 
 
565
                        wxString valor;
 
566
                        if(!config->Read(wxT("AET"),&valor,wxT("GINKGO_%IP4"))){
 
567
                                config->Write(wxT("AET"),valor);
 
568
                        }
 
569
                        m_pAETLocal->SetValue(valor);
 
570
                        m_pAETReal->SetLabel(wxString::FromUTF8( GNC::Entorno::Instance()->ParseAET(std::string(valor.ToUTF8())).substr(0, 16).c_str() ));
 
571
 
 
572
                        DicomServer* serverLocal = DicomServerList::Instance()->GetLocalServer();
 
573
                        m_pPuertoLocal->SetValue(wxString::Format(wxT("%d"),serverLocal->GetPort()));
 
574
 
 
575
                        wxTextValidator OnlyNum = wxTextValidator(wxFILTER_NUMERIC);
 
576
                        m_pPuertoLocal->SetValidator(OnlyNum);
 
577
 
 
578
                        m_configLocal.useTLS = serverLocal->GetUseTLS();
 
579
 
 
580
                        m_configLocal.verifyCredentials = serverLocal->GetverifyCredentials();
 
581
                        m_configLocal.privateKey = serverLocal->GetPrivateKey();
 
582
                        m_configLocal.certificate = serverLocal->GetCertificate();
 
583
 
 
584
 
 
585
                        if(GNC::GCS::ControladorPermisos::Instance()->Get("core.pacs.limits","remote_pacs")) {
 
586
                                m_pPACSServers->Enable(true);
 
587
 
 
588
                                
 
589
                                m_pTreeListPACS->DeleteRoot();
 
590
                                wxTreeItemId idRoot = m_pTreeListPACS->AddRoot(wxT("Root"));
 
591
                                m_servidores.clear();
 
592
 
 
593
                                for (DicomServerHolder* sl = DicomServerList::Instance()->GetList(); sl != NULL; sl = sl->next) {
 
594
                                        TipoPACS tp;
 
595
                                        tp.id = sl->server.ID;
 
596
                                        tp.aet = sl->server.AET;
 
597
                                        tp.host = sl->server.HostName;
 
598
                                        tp.isDefault = sl->server.isDefault;
 
599
                                        tp.puerto = sl->server.Port;
 
600
                                        tp.pdu = sl->server.PDU;
 
601
                                        tp.retrieveWithMove = sl->server.retrieveWithMove;
 
602
                                        tp.retrieveSeries = sl->server.retrieveSeries;
 
603
                                        
 
604
                                        tp.useTLS = sl->server.useTLS;
 
605
                                        tp.pacsUser = sl->server.pacsUser;
 
606
                                        tp.pacsPass = sl->server.pacsPass;
 
607
                                        
 
608
                                        tp.verifyCredentials = sl->server.verifyCredentials;
 
609
                                        tp.certificate = sl->server.certificate;
 
610
                                        tp.privateKey = sl->server.privateKey;
 
611
                                        m_servidores.push_back(tp);
 
612
                                        wxTreeItemId idItem = m_pTreeListPACS->AppendItem(idRoot, wxString::FromUTF8(tp.id.c_str()));
 
613
                                        if(tp.isDefault) {
 
614
                                                m_pTreeListPACS->SetItemText(idItem, 1, _("Yes"));
 
615
                                        } else {
 
616
                                                m_pTreeListPACS->SetItemText(idItem, 1, _("No"));
 
617
                                        }
 
618
                                }
 
619
 
 
620
                                if(m_pTreeListPACS->GetChildrenCount(idRoot) > 0){
 
621
                                        wxTreeItemIdValue cookie;
 
622
                                        m_pTreeListPACS->SelectItem(m_pTreeListPACS->GetFirstChild(idRoot, cookie));
 
623
                                        wxTreeEvent evt;
 
624
                                        OnListaPACSChoice(evt);
 
625
                                }
 
626
                        }
 
627
                        else {
 
628
                                m_pPACSServers->Enable(false);
 
629
                        }
 
630
 
 
631
                }
 
632
 
 
633
                //region "Metodos de IPasoConfiguracion"
 
634
                wxWindow* PanelConfiguracionPACS::GetPanel()
 
635
                {
 
636
                        return this;
 
637
                }
 
638
 
 
639
                std::string PanelConfiguracionPACS::GetTitle()
 
640
                {
 
641
                        return _Std("PACS Servers");
 
642
                }
 
643
 
 
644
                std::string PanelConfiguracionPACS::GetCabecera()
 
645
                {
 
646
                        return _Std("PACS Server Settings");
 
647
                }
 
648
 
 
649
                bool PanelConfiguracionPACS::Validar()
 
650
                {
 
651
                        bool ok = true;
 
652
                        std::stringstream sstream;
 
653
                        sstream << _Std("They have produced the following errors:");
 
654
 
 
655
                        long numero;
 
656
                        if(!m_pPuertoLocal->GetValue().ToLong(&numero) && m_pPuertoLocal->GetValue().size() > 0){
 
657
                                ok = false;
 
658
                                sstream << _Std("\n- The local port must be a positive short integer (16 bits)");
 
659
                        } else{
 
660
                                if(numero > 32767){//maxshort
 
661
                                        ok = false;
 
662
                                        sstream << _Std("\n- The local port is too large");
 
663
                                }
 
664
                        }
 
665
 
 
666
                        if(m_pAETReal->GetLabel().size() >16) {
 
667
                                ok = false;
 
668
                                sstream << _Std("\n- Maximum length of local AET is 16 characters");
 
669
                        }
 
670
 
 
671
                        if(!ok)
 
672
                                wxMessageBox(wxString::FromUTF8(sstream.str().c_str()),_("Info"),wxOK | wxICON_INFORMATION, this);
 
673
                        return ok;
 
674
                }
 
675
 
 
676
                bool PanelConfiguracionPACS::Guardar()
 
677
                {
 
678
                        wxConfigBase * config = wxConfigBase::Get();
 
679
                        //se actualiza el fichero de configuracion
 
680
 
 
681
                        config->SetPath(wxT("/GinkgoCore/PACS/Local"));
 
682
 
 
683
                        config->Write(wxT("AET"),m_pAETLocal->GetValue());
 
684
                        config->Write(wxT("Puerto"),m_pPuertoLocal->GetValue());
 
685
 
 
686
                        //local advanced
 
687
                        config->Write(wxT("useTLS"),m_configLocal.useTLS);
 
688
                        config->Write(wxT("verifyCredentials"), m_configLocal.verifyCredentials);
 
689
                        config->Write(wxT("privateKey"), wxString::FromUTF8(m_configLocal.privateKey.c_str()));
 
690
                        config->Write(wxT("certificate"), wxString::FromUTF8(m_configLocal.certificate.c_str()));
 
691
 
 
692
                        config->DeleteGroup(wxT("/GinkgoCore/PACS/Servidores"));
 
693
                        config->SetPath(wxT("/GinkgoCore/PACS/Servidores"));
 
694
 
 
695
                        if(GNC::GCS::ControladorPermisos::Instance()->Get("core.pacs.limits","remote_pacs")) {
 
696
                                int i=0;
 
697
                                wxString clave;
 
698
                                wxString valor;
 
699
                                for(TipoListaPACS::iterator it = m_servidores.begin(); it!= m_servidores.end(); it++,i++){
 
700
                                        clave = wxString::Format(wxT("Servidor%d/Identificador"),i);
 
701
                                        valor = wxString::FromUTF8((*it).id.c_str());
 
702
                                        config->Write(clave,valor);
 
703
 
 
704
                                        clave = wxString::Format(wxT("Servidor%d/AET"),i);
 
705
                                        valor = wxString::FromUTF8((*it).aet.c_str());
 
706
                                        config->Write(clave,valor);
 
707
 
 
708
                                        clave = wxString::Format(wxT("Servidor%d/Host"),i);
 
709
                                        valor = wxString::FromUTF8((*it).host.c_str());
 
710
                                        config->Write(clave,valor);
 
711
 
 
712
                                        clave = wxString::Format(wxT("Servidor%d/Puerto"),i);
 
713
                                        config->Write(clave,(*it).puerto);
 
714
 
 
715
                                        clave = wxString::Format(wxT("Servidor%d/PDU"),i);
 
716
                                        config->Write(clave,(*it).pdu);
 
717
 
 
718
                                        clave = wxString::Format(wxT("Servidor%d/isDefault"),i);
 
719
                                        config->Write(clave,(*it).isDefault);
 
720
 
 
721
                                        clave = wxString::Format(wxT("Servidor%d/useTLS"),i);
 
722
                                        config->Write(clave,(*it).useTLS);
 
723
 
 
724
                                        clave = wxString::Format(wxT("Servidor%d/pacsUser"),i);
 
725
                                        config->Write(clave,wxString::FromUTF8((*it).pacsUser.c_str()) );
 
726
 
 
727
                                        clave = wxString::Format(wxT("Servidor%d/pacsPass"),i);
 
728
                                        config->Write(clave,wxString::FromUTF8((*it).pacsPass.c_str()) );
 
729
                                        
 
730
                                        clave = wxString::Format(wxT("Servidor%d/verifyCredentials"),i);
 
731
                                        config->Write(clave,(*it).verifyCredentials);
 
732
                                        
 
733
                                        clave = wxString::Format(wxT("Servidor%d/certificate"),i);
 
734
                                        config->Write(clave,wxString::FromUTF8((*it).certificate.c_str()) );
 
735
                                        
 
736
                                        clave = wxString::Format(wxT("Servidor%d/privateKey"),i);
 
737
                                        config->Write(clave,wxString::FromUTF8((*it).privateKey.c_str()) );
 
738
                                        
 
739
                                        clave = wxString::Format(wxT("Servidor%d/retrieveWithMove"),i);
 
740
                                        config->Write(clave,(*it).retrieveWithMove );
 
741
 
 
742
                                        clave = wxString::Format(wxT("Servidor%d/retrieveSeries"),i);
 
743
                                        config->Write(clave,(*it).retrieveSeries );
 
744
                                }
 
745
                                DicomServerList::Instance()->Reload();
 
746
                        }
 
747
                        else {
 
748
                                DicomServerList::Instance()->FreeInstance();
 
749
                        }
 
750
 
 
751
                        return true;
 
752
                }
 
753
 
 
754
                void PanelConfiguracionPACS::Exportar(wxXmlNode* pNodo)
 
755
                {
 
756
                        wxXmlNode* pPACS = NULL;
 
757
                        for(pPACS =pNodo->GetChildren(); pPACS!=NULL; pPACS = pPACS->GetNext()) {
 
758
                                if(pPACS->GetName() == wxT("PACS")) {
 
759
                                        break;
 
760
                                }
 
761
                        }
 
762
                        if(pPACS == NULL) {
 
763
                                pPACS = new wxXmlNode(pNodo,wxXML_ELEMENT_NODE,wxT("PACS"));
 
764
                        }
 
765
 
 
766
                        wxXmlNode* pLocal = NULL;
 
767
                        for(pLocal =pPACS->GetChildren(); pLocal!=NULL; pLocal = pLocal->GetNext()) {
 
768
                                if(pLocal->GetName() == wxT("Local")) {
 
769
                                        break;
 
770
                                }
 
771
                        }
 
772
                        if(pLocal == NULL) {
 
773
                                pLocal = new wxXmlNode(pPACS,wxXML_ELEMENT_NODE,wxT("Local"));
 
774
                        }
 
775
 
 
776
                        wxXmlNode* nodo  = new wxXmlNode(pLocal,wxXML_ELEMENT_NODE,wxT("AET"));
 
777
                        new wxXmlNode(nodo,wxXML_TEXT_NODE,wxT(""),m_pAETLocal->GetValue());
 
778
 
 
779
                        nodo  = new wxXmlNode(pLocal,wxXML_ELEMENT_NODE,wxT("Puerto"));
 
780
                        new wxXmlNode(nodo,wxXML_TEXT_NODE,wxT(""),m_pPuertoLocal->GetValue());
 
781
 
 
782
                        nodo  = new wxXmlNode(pLocal,wxXML_ELEMENT_NODE,wxT("useTLS"));
 
783
                        new wxXmlNode(nodo,wxXML_TEXT_NODE,wxT(""),m_configLocal.useTLS?wxT("true"):wxT("false"));
 
784
 
 
785
                        nodo  = new wxXmlNode(pLocal,wxXML_ELEMENT_NODE,wxT("verifyCredentials"));
 
786
                        new wxXmlNode(nodo,wxXML_TEXT_NODE,wxT(""),m_configLocal.verifyCredentials?wxT("true"):wxT("false"));
 
787
 
 
788
                        nodo  = new wxXmlNode(pLocal,wxXML_ELEMENT_NODE,wxT("privateKey"));
 
789
                        new wxXmlNode(nodo,wxXML_TEXT_NODE,wxT(""),wxString::FromUTF8(m_configLocal.privateKey.c_str()));
 
790
 
 
791
                        nodo  = new wxXmlNode(pLocal,wxXML_ELEMENT_NODE,wxT("certificate"));
 
792
                        new wxXmlNode(nodo,wxXML_TEXT_NODE,wxT(""),wxString::FromUTF8(m_configLocal.certificate.c_str()));
 
793
 
 
794
                        if(GNC::GCS::ControladorPermisos::Instance()->Get("core.pacs.limits","remote_pacs")) {
 
795
 
 
796
                                wxXmlNode* pServidores = NULL;
 
797
                                for(pServidores =pPACS->GetChildren(); pServidores!=NULL; pServidores = pServidores->GetNext()) {
 
798
                                        if(pServidores->GetName() == wxT("Servidores")) {
 
799
                                                break;
 
800
                                        }
 
801
                                }
 
802
                                if(pServidores == NULL) {
 
803
                                        pServidores = new wxXmlNode(pPACS,wxXML_ELEMENT_NODE,wxT("Servidores"));
 
804
                                }
 
805
 
 
806
                                wxString clave;
 
807
                                wxString valor;
 
808
                                for(TipoListaPACS::iterator it = m_servidores.begin(); it!= m_servidores.end(); it++){
 
809
                                        wxXmlNode* pTag = new wxXmlNode(pServidores,wxXML_ELEMENT_NODE,wxT("Servidor"));
 
810
                                        pTag->AddProperty(wxT("Identificador"),wxString::FromUTF8((*it).id.c_str()));
 
811
                                        pTag->AddProperty(wxT("AET"),wxString::FromUTF8((*it).aet.c_str()));
 
812
                                        pTag->AddProperty(wxT("Host"),wxString::FromUTF8((*it).host.c_str()));
 
813
                                        pTag->AddProperty(wxT("Puerto"),wxString::Format(wxT("%d"),(*it).puerto));
 
814
                                        pTag->AddProperty(wxT("isDefault"), (*it).isDefault?wxT("true"):wxT("false"));
 
815
                                        pTag->AddProperty(wxT("PDU"),wxString::Format(wxT("%d"),(*it).pdu));
 
816
                                        pTag->AddProperty(wxT("useTLS"), (*it).useTLS?wxT("true"):wxT("false"));
 
817
                                        pTag->AddProperty(wxT("pacsUser"), wxString::FromUTF8((*it).pacsUser.c_str()));
 
818
                                        pTag->AddProperty(wxT("pacsPass"), wxString::FromUTF8((*it).pacsPass.c_str()));
 
819
                                        pTag->AddProperty(wxT("verifyCredentials"), (*it).verifyCredentials?wxT("true"):wxT("false"));
 
820
                                        pTag->AddProperty(wxT("certificate"), wxString::FromUTF8((*it).certificate.c_str()));
 
821
                                        pTag->AddProperty(wxT("privateKey"), wxString::FromUTF8((*it).privateKey.c_str()));
 
822
                                        pTag->AddProperty(wxT("retrieveWithMove"), (*it).retrieveWithMove?wxT("true"):wxT("false"));
 
823
                                        pTag->AddProperty(wxT("retrieveSeries"), (*it).retrieveSeries?wxT("true"):wxT("false"));
 
824
                                }
 
825
                        }
 
826
                }
 
827
 
 
828
                void PanelConfiguracionPACS::Importar(wxXmlNode* pNodo)
 
829
                {
 
830
                        wxConfigBase * config = wxConfigBase::Get();
 
831
                        //se actualiza el fichero de configuracion
 
832
 
 
833
                        config->SetPath(wxT("/GinkgoCore/PACS/Local"));
 
834
                        config->DeleteEntry(wxT("AET"));
 
835
                        config->DeleteEntry(wxT("Puerto"));
 
836
 
 
837
                        wxXmlNode* pPACS = NULL;
 
838
                        for(pPACS = pNodo->GetChildren(); pPACS != NULL; pPACS = pPACS->GetNext()) {
 
839
                                if(pPACS->GetName() == wxT("PACS")) {
 
840
                                        break;
 
841
                                }
 
842
                        }
 
843
                        if(pPACS != NULL) {
 
844
                                wxXmlNode* pLocal = NULL;
 
845
                                for(pLocal =pPACS->GetChildren(); pLocal!=NULL; pLocal = pLocal->GetNext()) {
 
846
                                        if(pLocal->GetName() == wxT("Local")) {
 
847
                                                break;
 
848
                                        }
 
849
                                }
 
850
                                if(pLocal != NULL) {
 
851
                                        config->SetPath(wxT("/GinkgoCore/PACS/Local"));
 
852
                                        for(wxXmlNode* pNodo = pLocal->GetChildren(); pNodo!= NULL; pNodo =pNodo->GetNext())
 
853
                                        {
 
854
                                                if(pNodo->GetChildren() != NULL) {
 
855
                                                        if(pNodo->GetName() == wxT("AET")) {
 
856
                                                                config->Write(wxT("AET"),pNodo->GetChildren()->GetContent());
 
857
                                                        }
 
858
                                                        if(pNodo->GetName() == wxT("Puerto")) {
 
859
                                                                config->Write(wxT("Puerto"),pNodo->GetChildren()->GetContent());
 
860
                                                        }
 
861
                                                        if(pNodo->GetName() == wxT("useTLS")) {
 
862
                                                                config->Write(wxT("useTLS"),pNodo->GetChildren()->GetContent()==wxT("true"));
 
863
                                                        }
 
864
                                                        if(pNodo->GetName() == wxT("useUserPass")) {
 
865
                                                                config->Write(wxT("useUserPass"),pNodo->GetChildren()->GetContent()==wxT("true"));
 
866
                                                        }
 
867
                                                        if(pNodo->GetName() == wxT("pacsUser")) {
 
868
                                                                config->Write(wxT("pacsUser"),pNodo->GetChildren()->GetContent());
 
869
                                                        }
 
870
                                                        if(pNodo->GetName() == wxT("pacsPass")) {
 
871
                                                                config->Write(wxT("pacsPass"),pNodo->GetChildren()->GetContent());
 
872
                                                        }
 
873
                                                        if(pNodo->GetName() == wxT("verifyCredentials")) {
 
874
                                                                config->Write(wxT("verifyCredentials"),pNodo->GetChildren()->GetContent()==wxT("true"));
 
875
                                                        }
 
876
                                                        if(pNodo->GetName() == wxT("privateKey")) {
 
877
                                                                config->Write(wxT("privateKey"),pNodo->GetChildren()->GetContent());
 
878
                                                        }
 
879
                                                        if(pNodo->GetName() == wxT("certificate")) {
 
880
                                                                config->Write(wxT("certificate"),pNodo->GetChildren()->GetContent());
 
881
                                                        }
 
882
                                                }
 
883
                                        }
 
884
                                }
 
885
                        }
 
886
 
 
887
                        config->DeleteGroup(wxT("/GinkgoCore/PACS/Servidores"));
 
888
                        config->SetPath(wxT("/GinkgoCore/PACS/Servidores"));
 
889
 
 
890
                        for(pPACS = pNodo->GetChildren(); pPACS != NULL; pPACS = pPACS->GetNext()) {
 
891
                                if(pPACS->GetName() == wxT("PACS")) {
 
892
                                        break;
 
893
                                }
 
894
                        }
 
895
                        if(pPACS != NULL) {
 
896
                                wxXmlNode* pServidores = NULL;
 
897
                                for(pServidores =pPACS->GetChildren(); pServidores!=NULL; pServidores = pServidores->GetNext()) {
 
898
                                        if(pServidores->GetName() == wxT("Servidores")) {
 
899
                                                break;
 
900
                                        }
 
901
                                }
 
902
                                if(pServidores != NULL) {
 
903
                                        int i=0;
 
904
                                        wxString clave;
 
905
                                        for(wxXmlNode* pTag=pServidores->GetChildren(); pTag!=NULL; pTag = pTag->GetNext(),i++) {
 
906
                                                wxString identificador;
 
907
                                                pTag->GetPropVal(wxT("Identificador"),&identificador);
 
908
                                                wxString aet;
 
909
                                                pTag->GetPropVal(wxT("AET"),&aet);
 
910
                                                wxString host;
 
911
                                                pTag->GetPropVal(wxT("Host"),&host);
 
912
                                                wxString puerto;
 
913
                                                pTag->GetPropVal(wxT("Puerto"),&puerto);
 
914
                                                wxString pdu;
 
915
                                                if(!pTag->GetPropVal(wxT("PDU"),&pdu)) {
 
916
                                                        std::stringstream sstream;
 
917
                                                        sstream << DEFAULT_PDU_LENGTH;
 
918
                                                        pdu = wxString::FromUTF8(sstream.str().c_str()); //16k es el default
 
919
                                                }
 
920
                                                wxString tmpStr;
 
921
                                                TipoPACS pacsTmp;
 
922
 
 
923
                                                tmpStr = pTag->GetPropVal(wxT("isDefault"),wxT("false"));
 
924
                                                pacsTmp.isDefault = tmpStr == wxT("true");
 
925
                                                tmpStr = pTag->GetPropVal(wxT("useTLS"),wxT("false"));
 
926
                                                pacsTmp.useTLS = tmpStr == wxT("true");
 
927
                                                tmpStr = pTag->GetPropVal(wxT("pacsUser"),wxT(""));
 
928
                                                pacsTmp.pacsUser = tmpStr.ToUTF8();
 
929
                                                tmpStr = pTag->GetPropVal(wxT("pacsPass"),wxT(""));
 
930
                                                pacsTmp.pacsPass =  tmpStr.ToUTF8();
 
931
                                                tmpStr = pTag->GetPropVal(wxT("verifyCredentials"),wxT("false"));
 
932
                                                pacsTmp.verifyCredentials = tmpStr == wxT("true");
 
933
                                                tmpStr = pTag->GetPropVal(wxT("certificate"),wxT(""));
 
934
                                                pacsTmp.certificate = tmpStr.ToUTF8();
 
935
                                                tmpStr = pTag->GetPropVal(wxT("privateKey"),wxT(""));
 
936
                                                pacsTmp.privateKey = tmpStr.ToUTF8();
 
937
                                                tmpStr = pTag->GetPropVal(wxT("retrieveWithMove"),wxT("true"));
 
938
                                                pacsTmp.retrieveWithMove = tmpStr == wxT("true");
 
939
                                                tmpStr = pTag->GetPropVal(wxT("retrieveSeries"),wxT("true"));
 
940
                                                pacsTmp.retrieveSeries = tmpStr == wxT("true");
 
941
 
 
942
                                                clave = wxString::Format(wxT("Servidor%d/Identificador"),i);
 
943
                                                config->Write(clave,identificador);
 
944
 
 
945
                                                clave = wxString::Format(wxT("Servidor%d/AET"),i);
 
946
                                                config->Write(clave,aet);
 
947
 
 
948
                                                clave = wxString::Format(wxT("Servidor%d/Host"),i);
 
949
                                                config->Write(clave,host);
 
950
 
 
951
                                                clave = wxString::Format(wxT("Servidor%d/Puerto"),i);
 
952
                                                config->Write(clave,puerto);
 
953
 
 
954
                                                clave = wxString::Format(wxT("Servidor%d/PDU"),i);
 
955
                                                config->Write(clave,pdu);
 
956
 
 
957
                                                clave = wxString::Format(wxT("Servidor%d/useTLS"),i);
 
958
                                                config->Write(clave,pacsTmp.useTLS);
 
959
 
 
960
                                                clave = wxString::Format(wxT("Servidor%d/pacsUser"),i);
 
961
                                                config->Write(clave,wxString::FromUTF8(pacsTmp.pacsUser.c_str()));
 
962
 
 
963
                                                clave = wxString::Format(wxT("Servidor%d/pacsPass"),i);
 
964
                                                config->Write(clave,wxString::FromUTF8(pacsTmp.pacsPass.c_str()));
 
965
                                                
 
966
                                                clave = wxString::Format(wxT("Servidor%d/verifyCredentials"),i);
 
967
                                                config->Write(clave,pacsTmp.verifyCredentials);
 
968
                                                
 
969
                                                clave = wxString::Format(wxT("Servidor%d/certificate"),i);
 
970
                                                config->Write(clave,wxString::FromUTF8(pacsTmp.certificate.c_str()) );
 
971
 
 
972
                                                clave = wxString::Format(wxT("Servidor%d/privateKey"),i);
 
973
                                                config->Write(clave,wxString::FromUTF8(pacsTmp.privateKey.c_str()) );
 
974
                                                
 
975
                                                clave = wxString::Format(wxT("Servidor%d/retrieveWithMove"),i);
 
976
                                                config->Write(clave,pacsTmp.retrieveWithMove );
 
977
 
 
978
                                                clave = wxString::Format(wxT("Servidor%d/retrieveSeries"),i);
 
979
                                                config->Write(clave,pacsTmp.retrieveSeries );
 
980
                                        }
 
981
                                }
 
982
                        }
 
983
                        DicomServerList::Instance()->Reload();
 
984
                }
 
985
                //endregion
 
986
 
 
987
                void PanelConfiguracionPACS::OnAdvancedLocal(wxCommandEvent &)
 
988
                {
 
989
                        DialogoLocalPACS dlg(this);
 
990
                        dlg.SetParametros(m_configLocal);
 
991
                        dlg.ShowModal();
 
992
                        if(dlg.m_Ok){
 
993
                                dlg.GetParametros(m_configLocal);
 
994
                                OnPropiedadCambiada();
 
995
                        }
 
996
                }
 
997
 
 
998
                void PanelConfiguracionPACS::OnListaPACSChoice(wxTreeEvent &){
 
999
                        //se carga la descripcion
 
1000
                        bool enable = m_pTreeListPACS->GetSelection().IsOk();
 
1001
                        m_pEditButton->Enable(enable);
 
1002
                        m_pDelButton->Enable(enable);
 
1003
                        m_pDefaultButton->Enable(enable);
 
1004
                }
 
1005
 
 
1006
                void PanelConfiguracionPACS::OnListaPACSDClick(wxTreeEvent &)
 
1007
                {
 
1008
                        wxCommandEvent evt;
 
1009
                        OnEditarClick(evt);
 
1010
                }
 
1011
 
 
1012
                void PanelConfiguracionPACS::OnNuevoClick(wxCommandEvent &){
 
1013
                        DialogoServidorPACS dialogo(this, m_configLocal, m_pPuertoLocal->GetValue(), wxString::FromUTF8( GNC::Entorno::Instance()->ParseAET( std::string(m_pAETLocal->GetValue().ToUTF8()) ).c_str() ) );
 
1014
                        dialogo.ShowModal();
 
1015
                        if(dialogo.m_Ok){
 
1016
                                TipoPACS tp;
 
1017
                                dialogo.GetParametros(tp);
 
1018
                                if (m_pTreeListPACS->GetChildrenCount(m_pTreeListPACS->GetRootItem()) == 0) {
 
1019
                                        tp.isDefault = true;
 
1020
                                }
 
1021
                                m_servidores.push_back(tp);
 
1022
 
 
1023
                                wxTreeItemId idItem = m_pTreeListPACS->AppendItem(m_pTreeListPACS->GetRootItem(), wxString::FromUTF8(tp.id.c_str()));
 
1024
                                if(tp.isDefault) {
 
1025
                                        m_pTreeListPACS->SetItemText(idItem, 1, _("Yes"));
 
1026
                                } else {
 
1027
                                        m_pTreeListPACS->SetItemText(idItem, 1, _("No"));
 
1028
                                }
 
1029
 
 
1030
                                m_pTreeListPACS->SelectItem(idItem);
 
1031
                                wxTreeEvent evt;
 
1032
                                OnListaPACSChoice(evt);
 
1033
                                OnPropiedadCambiada();
 
1034
                        }
 
1035
                }
 
1036
 
 
1037
                void PanelConfiguracionPACS::OnEditarClick(wxCommandEvent &){
 
1038
                        wxTreeItemId id  = m_pTreeListPACS->GetSelection();
 
1039
                        if(id.IsOk()){
 
1040
                                std::string idSeleccionado(m_pTreeListPACS->GetItemText(id).ToUTF8());
 
1041
 
 
1042
                                for(TipoListaPACS::iterator it = m_servidores.begin(); it != m_servidores.end(); it++){
 
1043
                                        if((*it).id == idSeleccionado){
 
1044
                                                DialogoServidorPACS dialogo(this, m_configLocal, m_pPuertoLocal->GetValue(), wxString::FromUTF8( GNC::Entorno::Instance()->ParseAET( std::string( m_pAETLocal->GetValue().ToUTF8() ) ).c_str() ) );
 
1045
                                                dialogo.SetParametros((*it));
 
1046
 
 
1047
                                                dialogo.ShowModal();
 
1048
                                                if(dialogo.m_Ok){
 
1049
                                                        dialogo.GetParametros((*it));
 
1050
                                                        //se refresca el combo
 
1051
                                                        m_pTreeListPACS->SetItemText(id,wxString::FromUTF8((*it).id.c_str()));
 
1052
                                                        m_pTreeListPACS->SelectItem(id);
 
1053
 
 
1054
                                                        wxTreeEvent evt;
 
1055
                                                        OnListaPACSChoice(evt);
 
1056
                                                        OnPropiedadCambiada();
 
1057
                                                }
 
1058
                                        }
 
1059
                                }
 
1060
                        }
 
1061
                }
 
1062
 
 
1063
                void PanelConfiguracionPACS::OnEliminarClick(wxCommandEvent &){
 
1064
                        wxTreeItemId itemSeleccionado = m_pTreeListPACS->GetSelection();
 
1065
                        if(itemSeleccionado.IsOk()){
 
1066
                                std::string idSeleccionado(m_pTreeListPACS->GetItemText(itemSeleccionado).ToUTF8());
 
1067
                                int answer = wxMessageBox(_("Confirm the removal of the server") + wxString::FromUTF8(idSeleccionado.c_str()), _("Data modified"), wxYES_NO | wxCANCEL, this);
 
1068
                                if(answer == wxYES){
 
1069
                                        for(TipoListaPACS::iterator it = m_servidores.begin(); it != m_servidores.end(); it++){
 
1070
                                                if((*it).id == idSeleccionado){
 
1071
                                                        m_pTreeListPACS->Delete(itemSeleccionado);
 
1072
                                                        m_servidores.erase(it);
 
1073
                                                        break;
 
1074
                                                }
 
1075
                                        }
 
1076
                                        wxTreeEvent evt;
 
1077
                                        OnListaPACSChoice(evt);
 
1078
                                        OnPropiedadCambiada();
 
1079
                                }
 
1080
                        }
 
1081
                }
 
1082
 
 
1083
                void PanelConfiguracionPACS::OnSetDefaultClick(wxCommandEvent &)
 
1084
                {
 
1085
                        wxTreeItemId itemSeleccionado = m_pTreeListPACS->GetSelection();
 
1086
                        if(itemSeleccionado.IsOk()){
 
1087
                                std::string idSeleccionado(m_pTreeListPACS->GetItemText(itemSeleccionado).ToUTF8());
 
1088
                                for(TipoListaPACS::iterator it = m_servidores.begin(); it != m_servidores.end(); it++){
 
1089
                                        if((*it).id == idSeleccionado){
 
1090
                                                (*it).isDefault = true;
 
1091
                                        } else {
 
1092
                                                (*it).isDefault = false;
 
1093
                                        }
 
1094
                                }
 
1095
                                wxTreeItemIdValue cookie;
 
1096
                                wxTreeItemId itemActual = m_pTreeListPACS->GetFirstChild(m_pTreeListPACS->GetRootItem(), cookie);
 
1097
                                while (itemActual.IsOk())
 
1098
                                {
 
1099
                                        if (itemActual == itemSeleccionado) {
 
1100
                                                m_pTreeListPACS->SetItemText(itemActual,1,_("Yes"));
 
1101
                                        } else {
 
1102
                                                m_pTreeListPACS->SetItemText(itemActual,1,_("No"));
 
1103
                                        }
 
1104
                                        itemActual = m_pTreeListPACS->GetNextChild(m_pTreeListPACS->GetRootItem(), cookie);
 
1105
                                }
 
1106
                                wxTreeEvent evt;
 
1107
                                OnListaPACSChoice(evt);
 
1108
                                OnPropiedadCambiada();
 
1109
                        }
 
1110
                }
 
1111
 
 
1112
                void PanelConfiguracionPACS::OnTextoCambiado(wxCommandEvent & )
 
1113
                {
 
1114
                        m_pAETReal->SetLabel(wxString::FromUTF8( GNC::Entorno::Instance()->ParseAET(std::string(m_pAETLocal->GetValue().ToUTF8())).c_str() ));
 
1115
                        OnPropiedadCambiada();
 
1116
                }
 
1117
 
 
1118
                void PanelConfiguracionPACS::OnSize(wxSizeEvent & event){
 
1119
                        wxSize oldSize = m_staticTextExplicacion->GetSize();
 
1120
                        Freeze();
 
1121
                        m_staticTextExplicacion->Freeze();
 
1122
                        m_staticTextExplicacion->SetLabel(_("You must configure the local AET, which is used to communicate with the PACS server. The specified port must be opened in the firewall, as it is essential for transfers."));
 
1123
                        m_staticTextExplicacion->Wrap( event.GetSize().x-25 );
 
1124
                        m_staticTextExplicacion->Thaw();
 
1125
                        //Layout();
 
1126
                        Thaw();
 
1127
                        wxSize newSize = m_staticTextExplicacion->GetSize();
 
1128
                        if (newSize != oldSize) {
 
1129
                                Layout();
 
1130
                                event.Skip(false);
 
1131
                        } else {
 
1132
                                event.Skip(true);
 
1133
                        }
 
1134
                }
 
1135
        }
 
1136
}