1 // frmContactEditor-LoadKey.cpp - frmContactEditor load key subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmContactEditor.h"
21 void frmContactEditor::LoadKey(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *KeyCount){
23 size_t intPropertyLen = wxSPropertySeg1.Len();
24 std::map<int, int> SplitPoints;
25 std::map<int, int> SplitLength;
26 std::map<int, int>::iterator SLiter;
27 wxString PropertyData;
28 wxString PropertyName;
29 wxString PropertyValue;
30 wxString PropertyTokens;
31 bool FirstToken = TRUE;
32 int intSplitsFound = 0;
39 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
43 // Look for type before continuing.
45 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
46 intiter != SplitPoints.end(); ++intiter){
48 SLiter = SplitLength.find(intiter->first);
50 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
52 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
53 PropertyName = PropertyElement.GetNextToken();
54 PropertyValue = PropertyElement.GetNextToken();
56 intPrevValue = intiter->second;
58 if (PropertyName == wxT("TYPE")){
60 if (PropertyValue == wxT("work")){
64 } else if (PropertyValue == wxT("home")){
78 // Setup blank lines for later on.
80 KeyList.insert(std::make_pair(intValueSeek, wxT("")));
81 KeyListAltID.insert(std::make_pair(intValueSeek, wxT("")));
82 KeyListPID.insert(std::make_pair(intValueSeek, wxT("")));
83 KeyListPref.insert(std::make_pair(intValueSeek, 0));
84 KeyListKeyType.insert(std::make_pair(intValueSeek, FALSE));
85 KeyListDataType.insert(std::make_pair(intValueSeek, wxT("")));
86 KeyListDataEncType.insert(std::make_pair(intValueSeek, wxT("")));
87 KeyListTokens.insert(std::make_pair(intValueSeek, wxT("")));
91 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
92 intiter != SplitPoints.end(); ++intiter){
94 SLiter = SplitLength.find(intiter->first);
96 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
98 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
99 PropertyName = PropertyElement.GetNextToken();
100 PropertyValue = PropertyElement.GetNextToken();
102 intPrevValue = intiter->second;
104 // Process properties.
106 size_t intPropertyValueLen = PropertyValue.Len();
108 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
110 PropertyValue.Trim();
111 PropertyValue.RemoveLast();
115 if (PropertyValue.Mid(0, 1) == wxT("\"")){
117 PropertyValue.Remove(0, 1);
121 if (PropertyName == wxT("ALTID")){
123 KeyListAltID.erase(intValueSeek); KeyListAltID.insert(std::make_pair(intValueSeek, PropertyValue));
125 } else if (PropertyName == wxT("PID")){
127 KeyListPID.erase(intValueSeek); KeyListPID.insert(std::make_pair(intValueSeek, PropertyValue));
129 } else if (PropertyName == wxT("PREF")){
131 intPref = wxAtoi(PropertyValue);
133 KeyListPref.erase(intValueSeek); KeyListPref.insert(std::make_pair(intValueSeek, intPref));
137 // Something else we don't know about so append
138 // to the tokens variable.
140 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
142 if (FirstToken == TRUE){
144 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
149 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
159 intPropertyLen = wxSPropertySeg2.Len();
166 for (int i = 0; i <= intPropertyLen; i++){
170 if (wxSPropertySeg2.Mid(i, 1) == wxT(";") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
173 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
175 if (intSplitsFound == 6){
177 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
182 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
194 wxString wxSKeyEncoding;
196 std::string base64enc;
198 if (intSplitsFound == 0){
202 std::map<int, int>::iterator striter;
204 striter = SplitLength.find(1);
206 wxStringTokenizer wSTDataType(wxSPropertySeg2.Mid(0, striter->second), wxT(":"));
208 while (wSTDataType.HasMoreTokens() == TRUE){
210 wxSKeyURI = wSTDataType.GetNextToken();
211 wxSKeyMIME = wSTDataType.GetNextToken();
216 if (wxSKeyURI == wxT("data")){
218 wxStringTokenizer wSTDataInfo(wxSPropertySeg2.Mid((striter->second + 2)), wxT(","));
220 while (wSTDataInfo.HasMoreTokens() == TRUE){
222 wxSKeyEncoding = wSTDataInfo.GetNextToken();
223 wxSKeyData = wSTDataInfo.GetNextToken();
232 // Add the data to the General/Home/Work address variables.
236 coldata.SetId(intValueSeek);
237 coldata.SetData(intValueSeek);
239 if (wxSKeyURI == wxT("data")){
241 if (wxSKeyMIME == wxT("application/pgp-keys")){
243 coldata.SetText(_("PGP Key"));
247 coldata.SetText(_("Key"));
251 KeyListDataEncType.erase(intValueSeek);
252 KeyListKeyType.erase(intValueSeek);
253 KeyListDataEncType.insert(std::make_pair(intValueSeek, wxSKeyEncoding));
254 KeyListKeyType.insert(std::make_pair(intValueSeek, TRUE));
256 KeyList.erase(intValueSeek);
257 KeyList.insert(std::make_pair(intValueSeek, wxSKeyData));
261 coldata.SetText(wxSPropertySeg2);
263 KeyList.erase(intValueSeek);
264 KeyList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
268 ListCtrlIndex = lboKeys->InsertItem(coldata);
270 if (intPref > 0 && intPref < 101){
272 lboKeys->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
277 KeyListType.erase(intValueSeek);
278 KeyListTokens.erase(intValueSeek);
279 KeyListDataType.erase(intValueSeek);
281 KeyListDataType.insert(std::make_pair(intValueSeek, wxSKeyMIME));
284 case 0: KeyListType.insert(std::make_pair(intValueSeek, wxT("")));
285 case 1: KeyListType.insert(std::make_pair(intValueSeek, wxT("home")));
286 case 2: KeyListType.insert(std::make_pair(intValueSeek, wxT("work")));
289 KeyListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));