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

« back to all changes in this revision

Viewing changes to src/cadxcore/main/gui/configuration/panelconfiguracionpermisos.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: panelconfiguracionpermisos.cpp 3526 2011-03-16 19:56:19Z carlos $
 
4
 *  Ginkgo CADx Project
 
5
 *
 
6
 *  Copyright 2008-10 MetaEmotion S.L. All rights reserved.
 
7
 *  http://ginkgo-cadx.com
 
8
 *
 
9
 *  This file is licensed under LGPL v3 license.
 
10
 *  See License.txt for details
 
11
 *
 
12
 *
 
13
 */
 
14
#include <vector>
 
15
#include <sstream>
 
16
#include <limits>
 
17
 
 
18
#include <wx/msgdlg.h>
 
19
#include <wx/msgout.h>
 
20
#include <wx/filename.h>
 
21
#include <wx/confbase.h>
 
22
#include <wx/valtext.h>
 
23
#include <wx/ginkgostyle/ginkgostyle.h>
 
24
#include <wx/mstream.h>
 
25
 
 
26
#include <wx/file.h>
 
27
#include <wx/dir.h>
 
28
#include <wx/log.h>
 
29
#include <wx/busyinfo.h>
 
30
#include <wx/xml/xml.h>
 
31
#include <wx/log.h>
 
32
#include <api/internacionalizacion.h>
 
33
#include <wx/tokenzr.h>
 
34
 
 
35
#include "panelconfiguracionpermisos.h"
 
36
 
 
37
#include <sstream>
 
38
 
 
39
#include <main/controllers/controladorextensiones.h>
 
40
#include <main/controllers/controladorlog.h>
 
41
#include <main/controllers/controladorpermisos.h>
 
42
#include <main/entorno.h>
 
43
 
 
44
#define SEPARADOR "|"
 
45
 
 
46
 
 
47
namespace GNC {
 
48
        namespace GUI {
 
49
 
 
50
                class ProfileDialog: public ProfileDialogBase
 
51
                {
 
52
                        typedef struct TipoPermiso {
 
53
                                std::string clave;
 
54
                                bool valor;
 
55
 
 
56
                                TipoPermiso() {}
 
57
 
 
58
                                TipoPermiso(const std::string& clave, bool valor)
 
59
                                {
 
60
                                        this->clave = clave;
 
61
                                        valor = valor;
 
62
                                }
 
63
                        } TipoPermiso;
 
64
                        typedef std::map <std::string, GNC::GCS::Permisos::EstadoPermiso> TipoMapaPermisos;
 
65
                public:
 
66
                        ProfileDialog(wxWindow* pParent, std::list<std::string>& listaNombres, bool isnew = false):ProfileDialogBase(pParent)
 
67
                        {
 
68
 
 
69
                                m_Ok = false;
 
70
                                m_listaNombres = listaNombres;
 
71
 
 
72
                                if (isnew) {
 
73
 
 
74
                                        long     idNombreAutomatico = 0;
 
75
                                        std::string profile_template = _Std("Profile");
 
76
                                        std::string nombre_automatico;
 
77
 
 
78
                                        for (std::list<std::string>::iterator it = listaNombres.begin(); it != listaNombres.end(); it++)
 
79
                                        {
 
80
                                                std::istringstream is (*it);
 
81
                                                std::string t_name;
 
82
                                                long id = -1;
 
83
                                                is >> t_name >> id;
 
84
 
 
85
                                                if (!is.fail() && t_name == profile_template && id > 0) {
 
86
                                                        idNombreAutomatico = std::max<long>(id, idNombreAutomatico);
 
87
                                                }
 
88
 
 
89
                                        }
 
90
                                        {
 
91
                                                std::ostringstream os;
 
92
                                                os << profile_template << " " << (idNombreAutomatico + 1);
 
93
                                                m_pName->SetValue( wxString::FromUTF8( os.str().c_str() ) );
 
94
                                        }
 
95
                                }
 
96
 
 
97
                                const GNC::GCS::ControladorPermisos::TipoMapaDefiniciones& definiciones = GNC::GCS::ControladorPermisos::Instance()->GetMapaDefiniciones();
 
98
 
 
99
                                //bool defaultValue = GNC::GCS::ControladorPermisos::Instance()->GetDefaultPermiso();
 
100
                                //cargamos los permisos "publicos" definidos
 
101
                                std::string ultimaCategoria = "";
 
102
                                wxPGProperty* cat = NULL;
 
103
                                m_gridPermisos->SetColumnCount(4);
 
104
                                m_gridPermisos->MakeColumnEditable(2, true);
 
105
                                m_gridPermisos->SetColumnProportion(0, 3);
 
106
                                m_gridPermisos->SetColumnProportion(1, 1);
 
107
                                m_gridPermisos->SetColumnProportion(2, 2);
 
108
                                m_gridPermisos->SetColumnProportion(3, 2);
 
109
                                for(GNC::GCS::ControladorPermisos::TipoMapaDefiniciones::const_iterator it = definiciones.begin(); it != definiciones.end(); ++it)
 
110
                                {
 
111
                                        if(!(*it).second.privado) {
 
112
                                                if ((*it).second.espacioNombres != ultimaCategoria) {
 
113
                                                        ultimaCategoria = (*it).second.espacioNombres;
 
114
                                                        cat = m_gridPermisos->Append(new wxPropertyCategory(wxString::FromUTF8((*it).second.descripcionNamespace.c_str()),wxString::FromUTF8(ultimaCategoria.c_str())));
 
115
                                                }
 
116
                                                std::string clave = (*it).second.espacioNombres + SEPARADOR + (*it).second.id;
 
117
                                                wxPGProperty* prop = cat->AppendChild(new wxBoolProperty(wxString::FromUTF8((*it).second.descripcion.c_str()), wxString::FromUTF8(clave.c_str()), (*it).second.activoPorDefecto ) );
 
118
                                                prop->SetCell(2, new wxPGCell( wxString::FromUTF8( ((*it).second.valorPorDefecto).c_str())) );
 
119
                                                prop->SetCell(3, new wxPGCell( _("Default value") ));
 
120
                                        }
 
121
                                }
 
122
                        }
 
123
 
 
124
                        ~ProfileDialog()
 
125
                        {
 
126
 
 
127
                        }
 
128
 
 
129
                        void GetParametros(std::string &nombre, std::string &xml)
 
130
                        {
 
131
                                nombre = std::string(m_pName->GetValue().ToUTF8());
 
132
 
 
133
                                //transformamos lo que esta viendo el usuario a un xml...
 
134
                                std::ostringstream ostr;
 
135
                                ostr << "<?xml version=\"1.0\"?>\n";
 
136
                                ostr << "<permisos>\n";
 
137
 
 
138
                                for(wxPropertyGridIterator it = m_gridPermisos->GetIterator(); !it.AtEnd(); it.Next())
 
139
                                {
 
140
                                        wxBoolProperty* pProperty = (wxBoolProperty*) it.GetProperty();
 
141
 
 
142
                                        wxString clave = pProperty->GetName();
 
143
 
 
144
 
 
145
                                        wxStringTokenizer tkz(clave, wxString::FromUTF8(SEPARADOR));
 
146
                                        std::string espacioNombres ="", id="";
 
147
                                        if ( tkz.HasMoreTokens() )
 
148
                                        {
 
149
                                                espacioNombres = tkz.GetNextToken().ToUTF8();
 
150
                                                if (tkz.HasMoreTokens()) {
 
151
                                                        id = tkz.GetNextToken().ToUTF8();
 
152
                                                }
 
153
                                        }
 
154
 
 
155
                                        if (id != "" && espacioNombres != "") {
 
156
 
 
157
                                                std::string stdclave( espacioNombres + "." + id );
 
158
 
 
159
                                                std::string accion;
 
160
                                                if (pProperty->GetValue()) {
 
161
                                                        accion = "activar";
 
162
                                                } else {
 
163
                                                        accion = "desactivar";
 
164
                                                }
 
165
 
 
166
                                                std::string val(pProperty->GetCell(2)->GetText().ToUTF8());
 
167
                                                std::string activopordefecto = "true";
 
168
 
 
169
                                                GNC::GCS::ControladorPermisos::TipoMapaDefiniciones mapa = GNC::GCS::ControladorPermisos::Instance()->GetMapaDefiniciones();
 
170
                                                GNC::GCS::ControladorPermisos::TipoMapaDefiniciones::iterator it = mapa.find(stdclave);
 
171
                                                GNC::GCS::ControladorPermisos::TipoDefinicionPermiso def;
 
172
 
 
173
                                                if (it != mapa.end()) {
 
174
                                                        def = (*it).second;
 
175
                                                }
 
176
 
 
177
                                                if (!def.activoPorDefecto) {
 
178
                                                        activopordefecto = "false";
 
179
                                                }
 
180
 
 
181
                                                ostr << "<permiso namespace=\"" << espacioNombres << "\" id=\"" << id << "\" valorpordefecto=\"" << def.valorPorDefecto << "\" activopordefecto=\"" << activopordefecto << "\" accion=\"" << accion << "\" valor=\"" << val << "\"/>" << std::endl;
 
182
                                        }
 
183
                                }
 
184
                                ostr << "</permisos>\n";
 
185
                                xml = ostr.str();
 
186
                        }
 
187
 
 
188
                        void SetParametros(const std::string &nombre, const std::string &xml)
 
189
                        {
 
190
                                m_nombreEditar = nombre;
 
191
                                m_pName->SetValue(wxString::FromUTF8(nombre.c_str()));
 
192
 
 
193
                                TipoMapaPermisos mapa = GetPermisosFromXml(xml);
 
194
 
 
195
                                for(wxPropertyGridIterator it = m_gridPermisos->GetIterator(); !it.AtEnd(); it.Next())
 
196
                                {
 
197
                                        wxBoolProperty* pProperty = dynamic_cast<wxBoolProperty*> (it.GetProperty());
 
198
                                        if(pProperty != NULL) {
 
199
 
 
200
                                                wxStringTokenizer tkz(pProperty->GetName(), wxString::FromUTF8(SEPARADOR));
 
201
                                                std::string espacioNombres = "" , id = "";
 
202
                                                if ( tkz.HasMoreTokens() )
 
203
                                                {
 
204
                                                        espacioNombres = tkz.GetNextToken().ToUTF8();
 
205
                                                        if (tkz.HasMoreTokens()) {
 
206
                                                                id = tkz.GetNextToken().ToUTF8();
 
207
                                                        }
 
208
                                                }
 
209
 
 
210
                                                /*
 
211
                                                GNC::GCS::Permisos::EstadoPermiso perm = //GNC::GCS::ControladorPermisos::Instance()->Get(espacioNombres + "." + id);
 
212
                                                pProperty->SetValue((bool)perm);
 
213
                                                */
 
214
                                                TipoMapaPermisos::iterator itp = mapa.find(std::string(pProperty->GetName().ToUTF8()));
 
215
                                                if (itp != mapa.end()) {
 
216
                                                        GNC::GCS::Permisos::EstadoPermiso& perm = (*itp).second;
 
217
                                                        pProperty->SetValue( (bool)perm );
 
218
                                                        pProperty->GetCell(2)->SetText( wxString::FromUTF8(perm.ObtenerValor<std::string>().c_str()));
 
219
                                                        if (perm.TieneValorPorDefecto()) {
 
220
                                                                pProperty->GetCell(3)->SetText(_("Default value"));
 
221
                                                        }
 
222
                                                        else {
 
223
                                                                pProperty->GetCell(3)->SetText(_("Set by user"));
 
224
                                                        }
 
225
                                                }
 
226
 
 
227
                                        }
 
228
                                }
 
229
                                //free memory
 
230
                        }
 
231
 
 
232
                        TipoMapaPermisos GetPermisosFromXml(const std::string& stdCadena)
 
233
                        {
 
234
                                TipoMapaPermisos permisos;
 
235
                                try {
 
236
                                        GNC::GCS::ControladorPermisos::TipoMapaPermisosNamespace mapaPermisosNamespace = GNC::GCS::ControladorPermisos::Instance()->GetPermisosFromXML(stdCadena);
 
237
                                        for( GNC::GCS::ControladorPermisos::TipoIteradorMapaPermisosNamespace itNames = mapaPermisosNamespace.begin(); itNames != mapaPermisosNamespace.end(); ++itNames )
 
238
                                        {
 
239
                                                for( GNC::GCS::ControladorPermisos::TipoIteradorMapaPermisos itPermisos = (*itNames).second->begin(); itPermisos != (*itNames).second->end(); ++itPermisos)
 
240
                                                {
 
241
                                                        permisos[itNames->first + SEPARADOR + itPermisos->first] = itPermisos->second;
 
242
                                                }
 
243
                                                delete (*itNames).second;
 
244
                                        }
 
245
                                } catch (GNC::GCS::ControladorPermisosException& ce)
 
246
                                {
 
247
                                        LOG_WARN("GestionPermisos", "Existe en la configuraciļæ½n un xml de permisos mal formado " << ce.GetCause());
 
248
                                }
 
249
                                return permisos;
 
250
                        }
 
251
 
 
252
                        virtual void OnCancelClick(wxCommandEvent &){
 
253
                                Close();
 
254
                        }
 
255
 
 
256
                        virtual void OnOkClick(wxCommandEvent &){
 
257
                                if (Validar()) {
 
258
                                        m_Ok=true;
 
259
                                        Close();
 
260
                                }
 
261
                        }
 
262
 
 
263
                        bool Validar() {
 
264
                                if(m_pName->GetValue() != wxEmptyString) {
 
265
                                        //no puede duplicar un nombre que estļæ½ en la lista y que no sea el mismo
 
266
                                        std::string nombre (m_pName->GetValue().ToUTF8());
 
267
                                        if (nombre != m_nombreEditar) {
 
268
                                                for (std::list<std::string>::iterator it = m_listaNombres.begin(); it != m_listaNombres.end(); ++it)
 
269
                                                {
 
270
                                                        if ((*it) == nombre) {
 
271
                                                                wxMessageBox(_("Profile name can't be repeated"),_("Info"),wxOK | wxICON_INFORMATION, this);
 
272
                                                                return false;
 
273
                                                        }
 
274
                                                }
 
275
                                        }
 
276
                                        return true;
 
277
                                }else{
 
278
                                        wxMessageBox(_("You must fill in name field to continue"),_("Info"),wxOK | wxICON_INFORMATION, this);
 
279
                                }
 
280
                                return false;
 
281
                        }
 
282
 
 
283
                        bool m_Ok;
 
284
                        std::list<std::string> m_listaNombres;
 
285
                        std::string m_nombreEditar;
 
286
                };
 
287
 
 
288
 
 
289
                ////////////////-------------------------------------------------------------------------------------/////////////////////////////
 
290
 
 
291
                PanelConfiguracionPermisos::PanelConfiguracionPermisos(wxWindow* pParent,IDialogoConfiguracion* pDialogo): PanelConfiguracionPermisosBase(pParent), IPasoConfiguracion(pDialogo)
 
292
                {
 
293
                        this->m_pTreeListProfiles->AddColumn(_("Name"), 200, wxALIGN_LEFT, -1, true, false);
 
294
                        this->m_pTreeListProfiles->AddColumn(_("Active"), 50, wxALIGN_LEFT, -1, true, false);
 
295
                        Recargar();
 
296
                        m_permisosCambiados = false;
 
297
 
 
298
                        m_pTreeListProfiles->Connect(wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( PanelConfiguracionPermisos::OnListaPermisosDClick ), NULL, this );
 
299
                        m_pTreeListProfiles->Connect(wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( PanelConfiguracionPermisos::OnListaPermisosChangeSelection ), NULL, this );
 
300
                }
 
301
 
 
302
                PanelConfiguracionPermisos::~PanelConfiguracionPermisos()
 
303
                {
 
304
                        m_profiles.clear();
 
305
                }
 
306
 
 
307
                void PanelConfiguracionPermisos::Recargar()
 
308
                {
 
309
                        wxConfigBase * config = wxConfigBase::Get();
 
310
 
 
311
                        m_pTreeListProfiles->DeleteRoot();
 
312
                        wxTreeItemId idRoot = m_pTreeListProfiles->AddRoot(wxT("Root"));
 
313
 
 
314
                        config->SetPath(wxT("/GinkgoCore/Profiles"));
 
315
                        wxString str;
 
316
                        bool aplicar;
 
317
                        long dummy;
 
318
 
 
319
                        bool primero = true;
 
320
 
 
321
                        bool bCont = config->GetFirstGroup(str, dummy);
 
322
                        while ( bCont ) {
 
323
                                config->SetPath(str);
 
324
                                config->Read(wxT("Name"),&str);
 
325
                                wxTreeItemId idItem = m_pTreeListProfiles->AppendItem(idRoot,str);
 
326
                                std::string nombre(str.ToUTF8());
 
327
                                config->Read(wxT("XML"),&str);
 
328
                                std::string xml(str.ToUTF8());
 
329
                                config->Read(wxT("Apply"),&aplicar);
 
330
 
 
331
                                if(aplicar) {
 
332
                                        m_pTreeListProfiles->SetItemText(idItem, 1, _("Yes"));
 
333
                                } else {
 
334
                                        m_pTreeListProfiles->SetItemText(idItem, 1, _("No"));
 
335
                                }
 
336
                                m_profiles.push_back(TipoProfile(nombre,xml,aplicar));
 
337
 
 
338
                                if(primero) {
 
339
                                        m_pTreeListProfiles->SelectItem(idItem);
 
340
                                        m_pBEdit->Enable(true);
 
341
                                        m_pBDelete->Enable(true);
 
342
                                        m_pBActive->Enable(true);
 
343
                                        primero = false;
 
344
                                }
 
345
 
 
346
                                config->SetPath(wxT(".."));
 
347
                                bCont = config->GetNextGroup(str, dummy);
 
348
                        }
 
349
                }
 
350
 
 
351
                //region "Metodos de IPasoConfiguracion"
 
352
                wxWindow* PanelConfiguracionPermisos::GetPanel()
 
353
                {
 
354
                        return this;
 
355
                }
 
356
 
 
357
                std::string PanelConfiguracionPermisos::GetTitle()
 
358
                {
 
359
                        return _Std("Profiles");
 
360
                }
 
361
 
 
362
                std::string PanelConfiguracionPermisos::GetCabecera()
 
363
                {
 
364
                        return _Std("Profiles Settings");
 
365
                }
 
366
 
 
367
                bool PanelConfiguracionPermisos::Validar()
 
368
                {
 
369
                        bool ok = true;
 
370
                        //si modificado... los cambios se aplicarļæ½n al volver a reiniciar
 
371
                        if(m_permisosCambiados) {
 
372
                                wxMessageBox(_("Ginkgo CADx must restart for the permission changes to take effect"),_("Info"));
 
373
                        }
 
374
                        return ok;
 
375
                }
 
376
 
 
377
                bool PanelConfiguracionPermisos::Guardar()
 
378
                {
 
379
                        wxConfigBase * config = wxConfigBase::Get();
 
380
                        //se actualiza el fichero de configuracion
 
381
 
 
382
                        config->DeleteGroup(wxT("/GinkgoCore/Profiles"));
 
383
                        config->SetPath(wxT("/GinkgoCore/Profiles"));
 
384
                        int i=0;
 
385
                        wxString clave;
 
386
                        wxString valor;
 
387
                        for(TipoListaProfiles::iterator it = m_profiles.begin(); it!= m_profiles.end(); it++,i++){
 
388
                                clave = wxString::Format(wxT("Profile%d/Name"),i);
 
389
                                valor = wxString::FromUTF8((*it).nombre.c_str());
 
390
                                config->Write(clave,valor);
 
391
 
 
392
                                clave = wxString::Format(wxT("Profile%d/Apply"),i);
 
393
                                config->Write(clave,(*it).aplicar);
 
394
 
 
395
                                clave = wxString::Format(wxT("Profile%d/XML"),i);
 
396
                                valor = wxString::FromUTF8((*it).xml.c_str());
 
397
                                config->Write(clave,valor);
 
398
                        }
 
399
 
 
400
                        return true;
 
401
                }
 
402
 
 
403
                void PanelConfiguracionPermisos::Exportar(wxXmlNode* pNodo)
 
404
                {
 
405
                        wxXmlNode* pProfiles = NULL;
 
406
                        for(pProfiles =pNodo->GetChildren(); pProfiles!=NULL; pProfiles = pProfiles->GetNext()) {
 
407
                                if(pProfiles->GetName() == wxT("Profiles")) {
 
408
                                        break;
 
409
                                }
 
410
                        }
 
411
                        if(pProfiles == NULL) {
 
412
                                pProfiles = new wxXmlNode(pNodo,wxXML_ELEMENT_NODE,wxT("Profiles"));
 
413
                        }
 
414
 
 
415
                        wxString clave;
 
416
                        wxString valor;
 
417
                        for(TipoListaProfiles::iterator it = m_profiles.begin(); it!= m_profiles.end(); it++){
 
418
                                wxXmlNode* pTag = new wxXmlNode(pProfiles,wxXML_ELEMENT_NODE,wxT("Profile"));
 
419
                                pTag->AddProperty(wxT("Name"),wxString::FromUTF8((*it).nombre.c_str()));
 
420
                                if((*it).aplicar)
 
421
                                        pTag->AddProperty(wxT("Apply"),wxT("Yes"));
 
422
                                else
 
423
                                        pTag->AddProperty(wxT("Apply"),wxT("No"));
 
424
                                pTag->AddProperty(wxT("XML"),wxString::FromUTF8((*it).xml.c_str()));
 
425
                        }
 
426
                }
 
427
 
 
428
                void PanelConfiguracionPermisos::Importar(wxXmlNode* pNodo)
 
429
                {
 
430
                        wxConfigBase * config = wxConfigBase::Get();
 
431
                        //se actualiza el fichero de configuracion
 
432
 
 
433
                        config->DeleteGroup(wxT("/GinkgoCore/Profiles"));
 
434
                        config->SetPath(wxT("/GinkgoCore/Profiles"));
 
435
 
 
436
                        wxXmlNode* pProfiles = NULL;
 
437
                        for(pProfiles = pNodo->GetChildren(); pProfiles != NULL; pProfiles = pProfiles->GetNext()) {
 
438
                                if(pProfiles->GetName() == wxT("Profiles")) {
 
439
                                        break;
 
440
                                }
 
441
                        }
 
442
                        if(pProfiles != NULL) {
 
443
                                int i=0;
 
444
                                wxString clave;
 
445
                                for(wxXmlNode* pTag=pProfiles->GetChildren(); pTag!=NULL; pTag = pTag->GetNext(),i++) {
 
446
                                        wxString nombre;
 
447
                                        pTag->GetPropVal(wxT("Name"),&nombre);
 
448
                                        wxString xml;
 
449
                                        pTag->GetPropVal(wxT("XML"),&xml);
 
450
                                        wxString aplicar;
 
451
                                        pTag->GetPropVal(wxT("Apply"),&aplicar);
 
452
                                        wxString puerto;
 
453
 
 
454
                                        clave = wxString::Format(wxT("Profile%d/Name"),i);
 
455
                                        config->Write(clave,nombre);
 
456
 
 
457
                                        clave = wxString::Format(wxT("Profile%d/XML"),i);
 
458
                                        config->Write(clave,xml);
 
459
 
 
460
                                        bool bAplicar = aplicar == wxT("Yes");
 
461
                                        clave = wxString::Format(wxT("Profile%d/Apply"),i);
 
462
                                        config->Write(clave,bAplicar);
 
463
                                }
 
464
                        }
 
465
                }
 
466
 
 
467
                //endregion
 
468
 
 
469
 
 
470
                void PanelConfiguracionPermisos::OnListaPermisosDClick(wxTreeEvent& )
 
471
                {
 
472
                        wxCommandEvent evt;
 
473
                        OnEditarClick(evt);
 
474
                }
 
475
 
 
476
                void PanelConfiguracionPermisos::OnListaPermisosChangeSelection(wxTreeEvent& event)
 
477
                {
 
478
                        if(event.GetItem().IsOk()) {
 
479
                                m_pBEdit->Enable(true);
 
480
                                m_pBDelete->Enable(true);
 
481
                                m_pBActive->Enable(true);
 
482
                        } else {
 
483
                                m_pBEdit->Enable(false);
 
484
                                m_pBDelete->Enable(false);
 
485
                                m_pBActive->Enable(false);
 
486
                        }
 
487
                }
 
488
 
 
489
                void PanelConfiguracionPermisos::OnSetActive(wxCommandEvent &)
 
490
                {
 
491
                        wxTreeItemId item = m_pTreeListProfiles->GetSelection();
 
492
                        if (item.IsOk()) {
 
493
                                std::string nombreSeleccionado( m_pTreeListProfiles->GetItemText(item).ToUTF8() );
 
494
 
 
495
                                for(TipoListaProfiles::iterator it = m_profiles.begin(); it != m_profiles.end(); it++) {
 
496
                                        if((*it).nombre == nombreSeleccionado) {
 
497
                                                (*it).aplicar = true;
 
498
                                        } else {
 
499
                                                (*it).aplicar = false;
 
500
                                        }
 
501
                                }
 
502
 
 
503
                                wxTreeItemIdValue cookie;
 
504
                                wxTreeItemId itemActual = m_pTreeListProfiles->GetFirstChild(m_pTreeListProfiles->GetRootItem(), cookie);
 
505
                                while (itemActual.IsOk())
 
506
                                {
 
507
                                        if (itemActual == item) {
 
508
                                                m_pTreeListProfiles->SetItemText(itemActual,1,_("Yes"));
 
509
                                        } else {
 
510
                                                m_pTreeListProfiles->SetItemText(itemActual,1,_("No"));
 
511
                                        }
 
512
                                        itemActual = m_pTreeListProfiles->GetNextChild(m_pTreeListProfiles->GetRootItem(), cookie);
 
513
                                }
 
514
 
 
515
                                OnPropiedadCambiada();
 
516
                        }
 
517
                }
 
518
 
 
519
                void PanelConfiguracionPermisos::OnNuevoClick(wxCommandEvent &){
 
520
                        //se le pasa la lista de identificadores para que no duplique
 
521
                        std::list<std::string> listaNombres;
 
522
                        for (TipoListaProfiles::iterator it = m_profiles.begin(); it != m_profiles.end(); ++it)
 
523
                        {
 
524
                                listaNombres.push_back((*it).nombre);
 
525
                        }
 
526
 
 
527
                        ProfileDialog dialogo(this, listaNombres, true);
 
528
                        dialogo.ShowModal();
 
529
                        if(dialogo.m_Ok){
 
530
                                bool es_unico = false;
 
531
 
 
532
                                if (m_pTreeListProfiles->GetChildrenCount(m_pTreeListProfiles->GetRootItem(), false) == 0) {
 
533
                                        es_unico = true;
 
534
                                }
 
535
 
 
536
                                TipoProfile tp;
 
537
                                dialogo.GetParametros(tp.nombre, tp.xml);
 
538
                                tp.aplicar = es_unico;
 
539
                                m_profiles.push_back(tp);
 
540
 
 
541
                                wxTreeItemId idItem = m_pTreeListProfiles->AppendItem(m_pTreeListProfiles->GetRootItem(),wxString::FromUTF8(tp.nombre.c_str()));
 
542
                                if(tp.aplicar) {
 
543
                                        m_pTreeListProfiles->SetItemText(idItem, 1, _("Yes"));
 
544
                                } else {
 
545
                                        m_pTreeListProfiles->SetItemText(idItem, 1, _("No"));
 
546
                                }
 
547
                                m_pTreeListProfiles->SelectItem(idItem);
 
548
 
 
549
                                OnPropiedadCambiada();
 
550
                        }
 
551
                }
 
552
 
 
553
                void PanelConfiguracionPermisos::OnEditarClick(wxCommandEvent &){
 
554
                        wxTreeItemId item = m_pTreeListProfiles->GetSelection();
 
555
                        if (item.IsOk()) {
 
556
                                //se le pasa la lista de identificadores para que no duplique
 
557
                                std::list<std::string> listaNombres;
 
558
                                for (TipoListaProfiles::iterator it = m_profiles.begin(); it != m_profiles.end(); ++it)
 
559
                                {
 
560
                                        listaNombres.push_back((*it).nombre);
 
561
                                }
 
562
                                //item seleccionado
 
563
                                std::string nombreSeleccionado( m_pTreeListProfiles->GetItemText(item).ToUTF8() );
 
564
 
 
565
                                for(TipoListaProfiles::iterator it = m_profiles.begin(); it != m_profiles.end(); it++){
 
566
                                        if((*it).nombre == nombreSeleccionado) {
 
567
                                                ProfileDialog dialogo(this, listaNombres);
 
568
 
 
569
                                                dialogo.SetParametros((*it).nombre,(*it).xml);
 
570
 
 
571
                                                dialogo.ShowModal();
 
572
                                                if(dialogo.m_Ok){
 
573
                                                        dialogo.GetParametros((*it).nombre, (*it).xml);
 
574
                                                        //se cambia el nombre en el arbol...
 
575
                                                        m_pTreeListProfiles->SetItemText(item, wxString::FromUTF8((*it).nombre.c_str()) );
 
576
                                                        OnPropiedadCambiada();
 
577
                                                }
 
578
                                        }
 
579
                                }
 
580
                        }
 
581
                }
 
582
 
 
583
                void PanelConfiguracionPermisos::OnEliminarClick(wxCommandEvent &){
 
584
                        wxTreeItemId item = m_pTreeListProfiles->GetSelection();
 
585
                        if(item.IsOk()){
 
586
                                std::string nombre(m_pTreeListProfiles->GetItemText(item).ToUTF8());
 
587
                                int answer = wxMessageBox(_("Confirm the removal of the profile ") + wxString::FromUTF8(nombre.c_str()), _("Data modified"), wxYES_NO | wxCANCEL, this);
 
588
                                if(answer == wxYES){
 
589
                                        for(TipoListaProfiles::iterator it = m_profiles.begin(); it != m_profiles.end(); it++){
 
590
                                                if((*it).nombre == nombre){
 
591
                                                        m_pTreeListProfiles->Delete(item);
 
592
                                                        m_profiles.erase(it);
 
593
                                                        break;
 
594
                                                }
 
595
                                        }
 
596
                                        OnPropiedadCambiada();
 
597
                                }
 
598
                        }
 
599
                }
 
600
 
 
601
                void PanelConfiguracionPermisos::OnPropiedadCambiada()
 
602
                {
 
603
                        m_permisosCambiados = true;
 
604
                        IPasoConfiguracion::OnPropiedadCambiada();
 
605
                }
 
606
 
 
607
                void PanelConfiguracionPermisos::OnTextoCambiado(wxCommandEvent & )
 
608
                {
 
609
                }
 
610
 
 
611
                void PanelConfiguracionPermisos::OnSize(wxSizeEvent & event){
 
612
                        event.Skip(true);
 
613
                }
 
614
        }
 
615
}