1 // frmContactEditor-LoadName.cpp - frmContactEditor load name 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::LoadFN(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *FNCount,
22 bool *FNProcessed, vCard *ContactData){
24 size_t intPropertyLen = wxSPropertySeg1.Len();
25 std::map<int, int> SplitPoints;
26 std::map<int, int> SplitLength;
27 std::map<int, int>::iterator SLiter;
28 wxString PropertyData;
29 wxString PropertyName;
30 wxString PropertyValue;
31 wxString PropertyTokens;
32 bool FirstToken = TRUE;
33 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 FullNamesList.insert(std::make_pair(intValueSeek, wxT("")));
81 FullNamesListAltID.insert(std::make_pair(intValueSeek, wxT("")));
82 FullNamesListPID.insert(std::make_pair(intValueSeek, wxT("")));
83 FullNamesListPref.insert(std::make_pair(intValueSeek, 0));
84 FullNamesListType.insert(std::make_pair(intValueSeek, wxT("")));
85 FullNamesListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
86 FullNamesListTokens.insert(std::make_pair(intValueSeek, wxT("")));
90 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
91 intiter != SplitPoints.end(); ++intiter){
93 SLiter = SplitLength.find(intiter->first);
95 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
97 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
98 PropertyName = PropertyElement.GetNextToken();
99 PropertyValue = PropertyElement.GetNextToken();
101 ProcessCaptureStrings(&PropertyValue);
103 intPrevValue = intiter->second;
105 // Process properties.
107 if (PropertyName == wxT("ALTID")){
109 FullNamesListAltID.erase(intValueSeek); FullNamesListAltID.insert(std::make_pair(intValueSeek, PropertyValue));
111 } else if (PropertyName == wxT("PID")){
113 FullNamesListPID.erase(intValueSeek); FullNamesListPID.insert(std::make_pair(intValueSeek, PropertyValue));
115 } else if (PropertyName == wxT("PREF")){
117 intPref = wxAtoi(PropertyValue);
119 if (intPref > 0 && intPref < 101){
121 FullNamesListPref.erase(intValueSeek); FullNamesListPref.insert(std::make_pair(intValueSeek, intPref));
125 } else if (PropertyName == wxT("LANG")){
127 FullNamesListLanguage.erase(intValueSeek); FullNamesListLanguage.insert(std::make_pair(intValueSeek, PropertyValue));
131 // Something else we don't know about so append
132 // to the tokens variable.
134 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
136 if (FirstToken == TRUE){
138 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
143 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
153 // Split the address.
155 //std::map<int, int>::iterator SLiter;
156 intPropertyLen = wxSPropertySeg2.Len();
163 for (int i = 0; i <= intPropertyLen; i++){
167 if (wxSPropertySeg2.Mid(i, 1) == wxT(":") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
170 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
172 if (intSplitsFound == 1){
174 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
185 // Add the data to the General/Home/Work address variables.
191 coldata.SetId(intValueSeek);
192 coldata.SetData(intValueSeek);
193 coldata.SetText(IMPPType);
197 //ProcessCaptureStrings(wxsPropertySeg2);
199 ProcessCaptureStrings(&wxSPropertySeg2);
201 FullNamesList.erase(intValueSeek);
202 FullNamesListType.erase(intValueSeek);
203 FullNamesListTokens.erase(intValueSeek);
204 FullNamesList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
205 FullNamesListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
209 FullNamesListType.insert(std::make_pair(intValueSeek, wxT("")));
211 } else if (intType == 1){
213 FullNamesListType.insert(std::make_pair(intValueSeek, wxT("home")));
215 } else if (intType == 2){
217 FullNamesListType.insert(std::make_pair(intValueSeek, wxT("work")));
221 if (*FNProcessed == FALSE){
223 NameDisplayAs = wxSPropertySeg2;
224 cmbDisplayAs->SetValue(ContactData->Convert(wxSPropertySeg2, TRUE));
234 void frmContactEditor::LoadN(wxString wxSPropertySeg1, wxString wxSPropertySeg2, bool *NameProcessed,
237 size_t intPropertyLen = wxSPropertySeg1.Len();
238 std::map<int, int> SplitPoints;
239 std::map<int, int> SplitLength;
240 std::map<int, int>::iterator SLiter;
241 wxString PropertyData;
242 wxString PropertyName;
243 wxString PropertyValue;
244 wxString PropertyTokens;
245 bool FirstToken = TRUE;
246 int intSplitsFound = 0;
247 int intSplitSize = 0;
248 int intPrevValue = 3;
249 int intSplitSeek = 0;
251 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
253 // Look for type before continuing.
257 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
258 intiter != SplitPoints.end(); ++intiter){
260 SLiter = SplitLength.find(intiter->first);
262 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
264 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
265 PropertyName = PropertyElement.GetNextToken();
266 PropertyValue = PropertyElement.GetNextToken();
268 intPrevValue = intiter->second;
274 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
275 intiter != SplitPoints.end(); ++intiter){
277 SLiter = SplitLength.find(intiter->first);
279 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
281 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
282 PropertyName = PropertyElement.GetNextToken();
283 PropertyValue = PropertyElement.GetNextToken();
285 ProcessCaptureStrings(&PropertyValue);
287 intPrevValue = intiter->second;
289 // Process properties.
291 if (PropertyName == wxT("ALTID")){
293 NameAltID = PropertyValue;
295 } else if (PropertyName == wxT("LANG")){
297 NameLanguage = PropertyValue;
299 } else if (PropertyName == wxT("SORT-AS")){
301 NameDisplayAs = PropertyValue;
305 // Something else we don't know about so append
306 // to the tokens variable.
308 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
310 if (FirstToken == TRUE){
312 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
317 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
327 intPropertyLen = wxSPropertySeg2.Len();
335 for (int i = 0; i <= intPropertyLen; i++){
339 if (wxSPropertySeg2.Mid(i, 1) == wxT(";") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
342 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
344 if (intSplitsFound == 4){
346 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
351 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
361 // Split the data into several parts.
363 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
364 intiter != SplitPoints.end(); ++intiter){
366 if (intiter->first == 1){
368 // Deal with family name.
370 SLiter = SplitLength.find(1);
372 txtSurname->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
374 intPrevValue = intiter->second;
375 NameSurname = wxSPropertySeg2.Mid(0, SLiter->second);
377 } else if (intiter->first == 2){
379 // Deal with given names.
381 SLiter = SplitLength.find(2);
383 txtForename->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
384 intPrevValue = intiter->second;
385 NameForename = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
387 } else if (intiter->first == 3){
389 // Deal with additional names.
391 SLiter = SplitLength.find(3);
393 txtOtherNames->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
394 intPrevValue = intiter->second;
395 NameOtherNames = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
397 } else if (intiter->first == 4){
399 // Deal with honorifix prefixes and suffixes.
401 SLiter = SplitLength.find(4);
403 txtTitle->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
404 intPrevValue = intiter->second;
405 NameTitle = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
407 txtSuffix->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
408 NameSuffix = wxSPropertySeg2.Mid(intPrevValue);
414 NameTokens = PropertyTokens;
415 *NameProcessed = TRUE;