Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added copyright and license header to the C++ source and header files in the contacte...
[xestiaab/.git] / source / contacteditor / frmContactEditor-LoadKey.cpp
1 // frmContactEditor-LoadKey.cpp - frmContactEditor load key subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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;
33         int intSplitSize = 0;
34         int intPrevValue = 5;
35         int intPref = 0;                        
36         int intType = 0;
37         long ListCtrlIndex;
38         
39         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
40         
41         intPrevValue = 4;
42         
43         // Look for type before continuing.
44         
45         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
46         intiter != SplitPoints.end(); ++intiter){
47         
48                 SLiter = SplitLength.find(intiter->first);
49         
50                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
51                 
52                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
53                 PropertyName = PropertyElement.GetNextToken();                          
54                 PropertyValue = PropertyElement.GetNextToken();
55                 
56                 intPrevValue = intiter->second;
57                 
58                 if (PropertyName == wxT("TYPE")){
59                 
60                         if (PropertyValue == wxT("work")){
61                         
62                                 intType = 2;                                    
63                         
64                         } else if (PropertyValue == wxT("home")){
66                                 intType = 1;
67                         
68                         } else {
69                         
70                                 intType = 0;
71                         
72                         }
73                 
74                 }
75         
76         }
77         
78         // Setup blank lines for later on.
79         
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("")));
89         intPrevValue = 4;
91         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
92         intiter != SplitPoints.end(); ++intiter){
93         
94                 SLiter = SplitLength.find(intiter->first);
95         
96                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
97                 
98                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
99                 PropertyName = PropertyElement.GetNextToken();                          
100                 PropertyValue = PropertyElement.GetNextToken();
101                 
102                 intPrevValue = intiter->second;
103                 
104                 // Process properties.
105                 
106                 size_t intPropertyValueLen = PropertyValue.Len();
107                 
108                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
109                         
110                         PropertyValue.Trim();
111                         PropertyValue.RemoveLast();
112                         
113                 }                               
114                 
115                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
116                         
117                         PropertyValue.Remove(0, 1);
118                         
119                 }                               
120                 
121                 if (PropertyName == wxT("ALTID")){
123                         KeyListAltID.erase(intValueSeek); KeyListAltID.insert(std::make_pair(intValueSeek, PropertyValue));
124                 
125                 } else if (PropertyName == wxT("PID")){
127                         KeyListPID.erase(intValueSeek); KeyListPID.insert(std::make_pair(intValueSeek, PropertyValue));
128                 
129                 } else if (PropertyName == wxT("PREF")){
130                         
131                         intPref = wxAtoi(PropertyValue);
132                 
133                         KeyListPref.erase(intValueSeek); KeyListPref.insert(std::make_pair(intValueSeek, intPref));
134                 
135                 } else {
136                 
137                         // Something else we don't know about so append
138                         // to the tokens variable.
139                         
140                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
141                         
142                                 if (FirstToken == TRUE){
143                                 
144                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
145                                         FirstToken = FALSE;
146                                 
147                                 } else {
148                                 
149                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
150                                 
151                                 }
152                         
153                         }
154                 
155                 }
156         
157         }                               
158         
159         intPropertyLen = wxSPropertySeg2.Len();
160         SplitPoints.clear();
161         SplitLength.clear();
162         intSplitsFound = 0;
163         intSplitSize = 0;
164         intPrevValue = 0;                       
165         
166         for (int i = 0; i <= intPropertyLen; i++){
168                 intSplitSize++;
169         
170                 if (wxSPropertySeg2.Mid(i, 1) == wxT(";") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
171         
172                         intSplitsFound++;
173                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
174                         
175                         if (intSplitsFound == 6){ 
176                         
177                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
178                                 break; 
179                                 
180                         } else {
181                         
182                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
183                         
184                         }
185                         
186                         intSplitSize = 0;                                       
187         
188                 }
190         }
191         
192         wxString wxSKeyURI;
193         wxString wxSKeyMIME;
194         wxString wxSKeyEncoding;
195         wxString wxSKeyData;
196         std::string base64enc;
197         
198         if (intSplitsFound == 0){
199         
200         } else {
201         
202                 std::map<int, int>::iterator striter;
203         
204                 striter = SplitLength.find(1);
205         
206                 wxStringTokenizer wSTDataType(wxSPropertySeg2.Mid(0, striter->second), wxT(":"));
207         
208                 while (wSTDataType.HasMoreTokens() == TRUE){
209                 
210                         wxSKeyURI = wSTDataType.GetNextToken();
211                         wxSKeyMIME = wSTDataType.GetNextToken();
212                         break;
213                 
214                 }                       
215         
216                 if (wxSKeyURI == wxT("data")){
217                 
218                                 wxStringTokenizer wSTDataInfo(wxSPropertySeg2.Mid((striter->second + 2)), wxT(","));                    
219         
220                                 while (wSTDataInfo.HasMoreTokens() == TRUE){
221                 
222                                 wxSKeyEncoding = wSTDataInfo.GetNextToken();
223                                 wxSKeyData = wSTDataInfo.GetNextToken();
224                                 break;
225                 
226                         }
227                 
228                 }
229         
230         }
231         
232         // Add the data to the General/Home/Work address variables.
233         
234         wxListItem coldata;
236         coldata.SetId(intValueSeek);
237         coldata.SetData(intValueSeek);
238         
239         if (wxSKeyURI == wxT("data")){
240         
241                 if (wxSKeyMIME == wxT("application/pgp-keys")){
242         
243                         coldata.SetText(_("PGP Key"));
244                 
245                 } else {
246                 
247                         coldata.SetText(_("Key"));
248                 
249                 }
250                 
251                 KeyListDataEncType.erase(intValueSeek);
252                 KeyListKeyType.erase(intValueSeek);
253                 KeyListDataEncType.insert(std::make_pair(intValueSeek, wxSKeyEncoding));
254                 KeyListKeyType.insert(std::make_pair(intValueSeek, TRUE));
255                 
256                 KeyList.erase(intValueSeek);
257                 KeyList.insert(std::make_pair(intValueSeek, wxSKeyData));
258         
259         } else {
260         
261                 coldata.SetText(wxSPropertySeg2);
262                 
263                 KeyList.erase(intValueSeek);
264                 KeyList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
265         
266         }
267         
268         ListCtrlIndex = lboKeys->InsertItem(coldata);
269                 
270         if (intPref > 0 && intPref < 101){
271                 
272                 lboKeys->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
273         
274         }
275                 
277         KeyListType.erase(intValueSeek);
278         KeyListTokens.erase(intValueSeek);
279         KeyListDataType.erase(intValueSeek);
281         KeyListDataType.insert(std::make_pair(intValueSeek, wxSKeyMIME));
282                 
283         switch (intType){
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")));
287         }
289         KeyListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
290         
291         KeyCount++;
292         intValueSeek++;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy