UserPolicySetPanel.cpp

Go to the documentation of this file.
00001 
00010 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && defined(PKIFRESOURCES_ALLOW_GCC_PRAGMA)
00011     #pragma implementation "UserPolicySetPanel.cpp"
00012 #endif
00013 
00014 //Pick up PKIF windows SDK configuration macros instead of WX's 
00015 #include "PKIFdll.h"
00016 // For compilers that support precompilation, includes "wx/wx.h".
00017 #include "wx/wxprec.h"
00018 
00019 #ifdef __BORLANDC__
00020     #pragma hdrstop
00021 #endif
00022 
00023 #include "UserPolicySetPanel.h"
00024 #include "CertificatePolicyEntryDlg.h"
00025 #include "OID.h"
00026 
00027 // WDR: class implementations
00028 
00029 //----------------------------------------------------------------------------
00030 // CPKIFUserPolicySetPanel
00031 //----------------------------------------------------------------------------
00032 
00033 // WDR: event table for CPKIFUserPolicySetPanel
00034 
00035 BEGIN_EVENT_TABLE(CPKIFUserPolicySetPanel,wxPanel)
00036     EVT_BUTTON( ID_BUTTON_ADD_POLICY, CPKIFUserPolicySetPanel::OnAddPolicy )
00037     EVT_BUTTON( ID_BUTTON_EDIT_POLICY, CPKIFUserPolicySetPanel::OnEditPolicy )
00038     EVT_BUTTON( ID_BUTTON_REMOVE_POLICY, CPKIFUserPolicySetPanel::OnRemovePolicy )
00039 END_EVENT_TABLE()
00047 CPKIFUserPolicySetPanel::CPKIFUserPolicySetPanel( wxWindow *parent, wxWindowID id,
00048     const wxPoint &position, const wxSize& size, long style ) :
00049     wxPanel( parent, id, position, size, style )
00050 {
00051     // WDR: dialog function UserPolicySetDefinitionPanel for CPKIFUserPolicySetPanel
00052     UserPolicySetDefinitionPanel( this, TRUE ); 
00053 }
00061 CPKIFPolicyInformationListPtr CPKIFUserPolicySetPanel::GetPolicies()
00062 {
00063     wxListBox* lb = GetListboxUserPolicies();
00064     wxASSERT(lb);
00065 
00066     const int numPols = lb->GetCount();
00067     if(0 >= numPols)
00068     {
00069         CPKIFPolicyInformationListPtr nullPil;
00070         return nullPil;
00071     }
00072 
00073     CPKIFPolicyInformationListPtr pil(new CPKIFPolicyInformationList);
00074 
00075     for(int ii = 0; ii < numPols; ++ii)
00076     {
00077         wxString tmpString = lb->GetString(ii);
00078 
00079         std::string tmpStdString(tmpString.ToAscii());
00080         CPKIFOIDPtr tmpOID(new CPKIFOID(tmpStdString));
00081         
00082         CPKIFPolicyInformationPtr tmpPolicy(new CPKIFPolicyInformation(tmpOID));
00083         pil->push_back(tmpPolicy);
00084     }
00085 
00086     return pil;
00087 }
00088 
00089 // WDR: handler implementations for CPKIFUserPolicySetPanel
00097 void CPKIFUserPolicySetPanel::OnRemovePolicy( wxCommandEvent &event )
00098 {
00099     wxListBox* lb = GetListboxUserPolicies();
00100     wxASSERT(lb);
00101     int sel = lb->GetSelection();
00102     if(wxNOT_FOUND != sel)
00103         lb->Delete(sel);
00104 }
00112 void CPKIFUserPolicySetPanel::OnEditPolicy( wxCommandEvent &event )
00113 {
00114     wxListBox* lb = GetListboxUserPolicies();
00115     wxASSERT(lb);
00116     int sel = lb->GetSelection();
00117     if(wxNOT_FOUND != sel)
00118     {
00119         CPKIFCertificatePolicyEntryDlg cpeDlg(this, -1, wxT("Enter an OID"));
00120         cpeDlg.Centre();
00121         wxTextCtrl* tc = cpeDlg.GetTextPolicyOid();
00122         tc->SetValue(lb->GetStringSelection());
00123         if(wxID_OK == cpeDlg.ShowModal())
00124         {
00125             wxListBox* lb = GetListboxUserPolicies();
00126             wxASSERT(lb);
00127         
00128             wxString policy = tc->GetValue();
00129             bool there = false;
00130             for(unsigned int i = 0; i < lb->GetCount(); ++i)
00131             {
00132                 wxString value = lb->GetString(i);
00133                 if(value == policy)
00134                     there  = true;
00135             }
00136 
00137             if(!there)
00138                 lb->SetString(sel, tc->GetValue());
00139             else
00140                 lb->Delete(sel);
00141         }
00142     }
00143     else
00144     {
00145         wxMessageBox(wxT("You must select a policy to edit."));
00146     }
00147 }
00155 void CPKIFUserPolicySetPanel::OnAddPolicy( wxCommandEvent &event )
00156 {
00157     CPKIFCertificatePolicyEntryDlg cpeDlg(this, -1, wxT("Enter an OID"));
00158     cpeDlg.Centre();
00159     if(wxID_OK == cpeDlg.ShowModal())
00160     {
00161         wxListBox* lb = GetListboxUserPolicies();
00162         wxASSERT(lb);
00163         
00164         wxTextCtrl* tc = cpeDlg.GetTextPolicyOid();
00165         wxString policy = tc->GetValue();
00166         bool there = false;
00167         for(unsigned int i = 0; i < lb->GetCount(); ++i)
00168         {
00169             wxString value = lb->GetString(i);
00170             if(value == policy)
00171                 there  = true;
00172         }
00173         if(!there)
00174             lb->Insert(tc->GetValue(), 0);
00175     }
00176 }
00184 void CPKIFUserPolicySetPanel::SetInitialPathSettings(CPKIFPathSettingsPtr& ps)
00185 {
00186     m_initialPathSettings = ps;
00187 }
00195 void CPKIFUserPolicySetPanel::OnInitDialog(wxInitDialogEvent& event)
00196 {
00197     if(m_initialPathSettings != (CPKIFPathSettings*)NULL)
00198     {
00199         wxListBox* lb = GetListboxUserPolicies();
00200         wxASSERT(lb);
00201 
00202         CPKIFPolicyInformationListPtr initPolSet;
00203         m_initialPathSettings->GetInitialPolicySet(initPolSet);
00204 
00205         CPKIFPolicyInformationList::iterator pos = initPolSet->begin();
00206         CPKIFPolicyInformationList::iterator end = initPolSet->end();
00207 
00208         for(int ii = 0; pos != end; ++ii, ++pos)
00209         {
00210             lb->Insert(wxString((*pos)->PolicyOID()->ToString(),wxConvUTF8), 0);
00211         }
00212     }
00213 }

Generated on Mon Nov 15 11:15:57 2010 for PublicKeyInfrastructureFramework(PKIF) by  doxygen 1.5.6