DirectoryEntryDlg.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 "DirectoryEntryDlg.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 "DirectoryEntryDlg.h"
00024 #include "ExtractInfoFromCertDlg.h"
00025 
00026 #include <iostream>
00027 #include <sstream>
00028 
00029 using namespace std;
00030 
00031 
00032 
00033 wxChar CPKIFDirectoryEntryDlg::m_intIncludes[] = wxT("1234567890");
00034 wxString CPKIFDirectoryEntryDlg::m_longLiveThisString;
00035 
00036 // WDR: class implementations
00037 
00038 //----------------------------------------------------------------------------
00039 // CPKIFDirectoryEntryDlg
00040 //----------------------------------------------------------------------------
00041 
00042 // WDR: event table for CPKIFDirectoryEntryDlg
00043 
00044 BEGIN_EVENT_TABLE(CPKIFDirectoryEntryDlg,wxDialog)
00045     EVT_BUTTON( wxID_OK, CPKIFDirectoryEntryDlg::OnOk )
00046     EVT_BUTTON( wxID_CANCEL, CPKIFDirectoryEntryDlg::OnCancel )
00047     EVT_BUTTON( ID_BUTTON_ADD_DIR_NAMESPACE, CPKIFDirectoryEntryDlg::AddNamespace )
00048     EVT_BUTTON( ID_BUTTON_REMOVE_DIR_NAMESPACE, CPKIFDirectoryEntryDlg::RemoveNamespace )
00049     EVT_INIT_DIALOG( CPKIFDirectoryEntryDlg::OnInitDialog )
00050 END_EVENT_TABLE()
00058 CPKIFDirectoryEntryDlg::CPKIFDirectoryEntryDlg( wxWindow *parent, wxWindowID id, const wxString &title,
00059     const wxPoint &position, const wxSize& size, long style ) :
00060     wxDialog( parent, id, title, position, size, style ),
00061     m_intValidator(wxFILTER_INCLUDE_CHAR_LIST, &m_longLiveThisString)
00062 {
00063     m_port = 389;
00064 
00065     // WDR: dialog function DirectoryEntryDlg for CPKIFDirectoryEntryDlg
00066     DirectoryEntryDlg( this, TRUE ); 
00067 
00068     wxArrayString sl;
00069     for(int ii = 0; 0x00 != m_intIncludes[ii]; ++ii)
00070         sl.Add((wxString)m_intIncludes[ii]);
00071     m_intValidator.SetIncludes(sl);
00072 
00073     GetTextPort()->SetValidator(m_intValidator);
00074 
00075 }
00076 
00077 // WDR: handler implementations for CPKIFDirectoryEntryDlg
00085 void CPKIFDirectoryEntryDlg::OnOk(wxCommandEvent &event)
00086 {
00087     wxTextCtrl* tcAddr = GetTextAddress();
00088     wxString tmpAddr = tcAddr->GetValue();
00089     wxTextCtrl* tcPort = GetTextPort();
00090     int tmpPort = atoi(tcPort->GetValue().mb_str());
00091 
00092     if(tmpAddr.IsEmpty() || 0 >= m_port || 0xffff < m_port)
00093     {
00094         wxMessageBox(wxT("Please enter valid server information before clicking OK."));
00095         return;
00096     }
00097 
00098     m_address = tmpAddr;
00099     m_port = tmpPort;
00100 
00101     event.Skip();
00102 }
00110 void CPKIFDirectoryEntryDlg::OnCancel(wxCommandEvent &event)
00111 {
00112     event.Skip();
00113 }
00121 void CPKIFDirectoryEntryDlg::GetAddress(wxString& address) const
00122 {
00123     address = m_address;
00124 }
00132 int CPKIFDirectoryEntryDlg::GetPort() const
00133 {
00134     return m_port;
00135 }
00143 void CPKIFDirectoryEntryDlg::SetAddress(const wxString& address)
00144 {
00145     m_address = address;
00146 }
00154 void CPKIFDirectoryEntryDlg::SetPort(int port)
00155 {
00156     m_port = port;
00157 }
00165 void CPKIFDirectoryEntryDlg::OnInitDialog(wxInitDialogEvent& event)
00166 {
00167     wxTextCtrl* tcAddr = GetTextAddress();
00168     if(!m_address.IsEmpty())
00169         tcAddr->SetValue(m_address);
00170 
00171     wxTextCtrl* tcPort = GetTextPort();
00172     //static char numbuf[25];
00173     ostringstream os;
00174     os << m_port;
00175     wxString portStr(os.str().c_str(),wxConvUTF8);
00176     tcPort->SetValue(portStr);
00177 
00178 
00179     CPKIFGeneralSubtreeList::iterator pos;
00180     CPKIFGeneralSubtreeList::iterator end = m_rndList.end();
00181     for(pos = m_rndList.begin(); pos != end; ++pos)
00182     {
00183         string str1 = (*pos)->GetBase()->directoryName()->ToString();
00184         wxString wxNS(str1.c_str(),wxConvUTF8);
00185         GetNamespaceList()->InsertItems(1, &wxNS, 0);
00186     }
00187 }
00195 void CPKIFDirectoryEntryDlg::AddNamespace(wxCommandEvent &event)
00196 {
00197     static wxString filter = wxT("Certificate files (*.cer, *.der, *.crt)|*.cer;*.der;*.crt|All files (*.*)|*.*");
00198     wxString certLocation = wxFileSelector(wxT("Select Certificate File"), 0, 0, 0, filter);//wxT("CRT files (*.crt)|*.crt|DER files (*.der)|*.der|CER files (*.cer)|*.cer"));
00199     if(certLocation != wxT(""))
00200     {
00201         try {
00202             CExtractInfoFromCertDialog dlg((wxWindow *) this, -1 , wxT("Extract Info From Certificate"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, certLocation);
00203             dlg.Centre();
00204             if(wxID_OK == dlg.ShowModal())
00205             {   
00206                 CPKIFGeneralSubtreePtr ns = dlg.GetNamespace();
00207 
00208                 if(ns != (CPKIFGeneralSubtree*)NULL)
00209                 {
00210                     m_rndList.push_back(ns);
00211                     wxString wxNS(ns->GetBase()->directoryName()->ToString(),wxConvUTF8);
00212                     GetNamespaceList()->InsertItems(1, &wxNS, 0);
00213                 }
00214             }
00215         }catch(CPKIFException &){
00216             wxMessageBox(wxT("Unable to decode certificate."),wxT("Error"),wxICON_ERROR|wxOK);
00217         }
00218     }
00219 }
00227 void CPKIFDirectoryEntryDlg::RemoveNamespace(wxCommandEvent &event)
00228 {
00229     wxListBox* lb = GetNamespaceList();
00230     wxASSERT(lb);
00231     int sel = lb->GetSelection();
00232     string selection;
00233     if(wxNOT_FOUND != sel)
00234     {
00235         selection = lb->GetStringSelection().mb_str();
00236         lb->Delete(sel);
00237     }
00238 
00239     CPKIFGeneralSubtreeList::iterator pos;
00240     CPKIFGeneralSubtreeList::iterator end = m_rndList.end();
00241     for(pos = m_rndList.begin(); pos != end; ++pos)
00242     {
00243         string str1 = (*pos)->GetBase()->directoryName()->ToString();
00244         if(strcmp(str1.c_str(), selection.c_str()) == 0 )
00245         {
00246             m_rndList.erase(pos);
00247             break;
00248         }
00249     }
00250 }
00258 CPKIFGeneralSubtreeList CPKIFDirectoryEntryDlg::GetNamespaces() const
00259 {
00260     return m_rndList;
00261 }
00269 void CPKIFDirectoryEntryDlg::SetNamespaces(
00271     CPKIFGeneralSubtreeList &rdnList)
00272 {
00273     m_rndList = rdnList;
00274 }

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