1 #include "frmContactEditor.h"
3 void frmContactEditor::LoadKey(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *KeyCount){
5 size_t intPropertyLen = wxSPropertySeg1.Len();
6 std::map<int, int> SplitPoints;
7 std::map<int, int> SplitLength;
8 std::map<int, int>::iterator SLiter;
10 wxString PropertyName;
11 wxString PropertyValue;
12 wxString PropertyTokens;
13 bool FirstToken = TRUE;
14 int intSplitsFound = 0;
21 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
25 // Look for type before continuing.
27 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
28 intiter != SplitPoints.end(); ++intiter){
30 SLiter = SplitLength.find(intiter->first);
32 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
34 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
35 PropertyName = PropertyElement.GetNextToken();
36 PropertyValue = PropertyElement.GetNextToken();
38 intPrevValue = intiter->second;
40 if (PropertyName == wxT("TYPE")){
42 if (PropertyValue == wxT("work")){
46 } else if (PropertyValue == wxT("home")){
60 // Setup blank lines for later on.
62 KeyList.insert(std::make_pair(intValueSeek, wxT("")));
63 KeyListAltID.insert(std::make_pair(intValueSeek, wxT("")));
64 KeyListPID.insert(std::make_pair(intValueSeek, wxT("")));
65 KeyListPref.insert(std::make_pair(intValueSeek, 0));
66 KeyListKeyType.insert(std::make_pair(intValueSeek, FALSE));
67 KeyListDataType.insert(std::make_pair(intValueSeek, wxT("")));
68 KeyListDataEncType.insert(std::make_pair(intValueSeek, wxT("")));
69 KeyListTokens.insert(std::make_pair(intValueSeek, wxT("")));
73 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
74 intiter != SplitPoints.end(); ++intiter){
76 SLiter = SplitLength.find(intiter->first);
78 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
80 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
81 PropertyName = PropertyElement.GetNextToken();
82 PropertyValue = PropertyElement.GetNextToken();
84 intPrevValue = intiter->second;
86 // Process properties.
88 size_t intPropertyValueLen = PropertyValue.Len();
90 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
93 PropertyValue.RemoveLast();
97 if (PropertyValue.Mid(0, 1) == wxT("\"")){
99 PropertyValue.Remove(0, 1);
103 if (PropertyName == wxT("ALTID")){
105 KeyListAltID.erase(intValueSeek); KeyListAltID.insert(std::make_pair(intValueSeek, PropertyValue));
107 } else if (PropertyName == wxT("PID")){
109 KeyListPID.erase(intValueSeek); KeyListPID.insert(std::make_pair(intValueSeek, PropertyValue));
111 } else if (PropertyName == wxT("PREF")){
113 intPref = wxAtoi(PropertyValue);
115 KeyListPref.erase(intValueSeek); KeyListPref.insert(std::make_pair(intValueSeek, intPref));
119 // Something else we don't know about so append
120 // to the tokens variable.
122 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
124 if (FirstToken == TRUE){
126 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
131 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
141 intPropertyLen = wxSPropertySeg2.Len();
148 for (int i = 0; i <= intPropertyLen; i++){
152 if (wxSPropertySeg2.Mid(i, 1) == wxT(";") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
155 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
157 if (intSplitsFound == 6){
159 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
164 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
176 wxString wxSKeyEncoding;
178 std::string base64enc;
180 if (intSplitsFound == 0){
184 std::map<int, int>::iterator striter;
186 striter = SplitLength.find(1);
188 wxStringTokenizer wSTDataType(wxSPropertySeg2.Mid(0, striter->second), wxT(":"));
190 while (wSTDataType.HasMoreTokens() == TRUE){
192 wxSKeyURI = wSTDataType.GetNextToken();
193 wxSKeyMIME = wSTDataType.GetNextToken();
198 if (wxSKeyURI == wxT("data")){
200 wxStringTokenizer wSTDataInfo(wxSPropertySeg2.Mid((striter->second + 2)), wxT(","));
202 while (wSTDataInfo.HasMoreTokens() == TRUE){
204 wxSKeyEncoding = wSTDataInfo.GetNextToken();
205 wxSKeyData = wSTDataInfo.GetNextToken();
214 // Add the data to the General/Home/Work address variables.
218 coldata.SetId(intValueSeek);
219 coldata.SetData(intValueSeek);
221 if (wxSKeyURI == wxT("data")){
223 if (wxSKeyMIME == wxT("application/pgp-keys")){
225 coldata.SetText(_("PGP Key"));
229 coldata.SetText(_("Key"));
233 KeyListDataEncType.erase(intValueSeek);
234 KeyListKeyType.erase(intValueSeek);
235 KeyListDataEncType.insert(std::make_pair(intValueSeek, wxSKeyEncoding));
236 KeyListKeyType.insert(std::make_pair(intValueSeek, TRUE));
238 KeyList.erase(intValueSeek);
239 KeyList.insert(std::make_pair(intValueSeek, wxSKeyData));
243 coldata.SetText(wxSPropertySeg2);
245 KeyList.erase(intValueSeek);
246 KeyList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
250 ListCtrlIndex = lboKeys->InsertItem(coldata);
252 if (intPref > 0 && intPref < 101){
254 lboKeys->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
259 KeyListType.erase(intValueSeek);
260 KeyListTokens.erase(intValueSeek);
261 KeyListDataType.erase(intValueSeek);
263 KeyListDataType.insert(std::make_pair(intValueSeek, wxSKeyMIME));
266 case 0: KeyListType.insert(std::make_pair(intValueSeek, wxT("")));
267 case 1: KeyListType.insert(std::make_pair(intValueSeek, wxT("home")));
268 case 2: KeyListType.insert(std::make_pair(intValueSeek, wxT("work")));
271 KeyListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));