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::LoadName(wxString *NameTitle, wxString *NameForename,
235 wxString *NameSurname, wxString *NameOtherNames,
236 wxString *NameSuffix){
238 txtTitle->SetValue(*NameTitle);
239 txtForename->SetValue(*NameForename);
240 txtSurname->SetValue(*NameSurname);
241 txtOtherNames->SetValue(*NameOtherNames);
242 txtSuffix->SetValue(*NameSuffix);
246 void frmContactEditor::LoadN(wxString wxSPropertySeg1, wxString wxSPropertySeg2, bool *NameProcessed,
249 size_t intPropertyLen = wxSPropertySeg1.Len();
250 std::map<int, int> SplitPoints;
251 std::map<int, int> SplitLength;
252 std::map<int, int>::iterator SLiter;
253 wxString PropertyData;
254 wxString PropertyName;
255 wxString PropertyValue;
256 wxString PropertyTokens;
257 bool FirstToken = TRUE;
258 int intSplitsFound = 0;
259 int intSplitSize = 0;
260 int intPrevValue = 3;
261 int intSplitSeek = 0;
263 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
265 // Look for type before continuing.
269 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
270 intiter != SplitPoints.end(); ++intiter){
272 SLiter = SplitLength.find(intiter->first);
274 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
276 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
277 PropertyName = PropertyElement.GetNextToken();
278 PropertyValue = PropertyElement.GetNextToken();
280 intPrevValue = intiter->second;
286 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
287 intiter != SplitPoints.end(); ++intiter){
289 SLiter = SplitLength.find(intiter->first);
291 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
293 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
294 PropertyName = PropertyElement.GetNextToken();
295 PropertyValue = PropertyElement.GetNextToken();
297 ProcessCaptureStrings(&PropertyValue);
299 intPrevValue = intiter->second;
301 // Process properties.
303 if (PropertyName == wxT("ALTID")){
305 NameAltID = PropertyValue;
307 } else if (PropertyName == wxT("LANG")){
309 NameLanguage = PropertyValue;
311 } else if (PropertyName == wxT("SORT-AS")){
313 NameDisplayAs = PropertyValue;
317 // Something else we don't know about so append
318 // to the tokens variable.
320 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
322 if (FirstToken == TRUE){
324 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
329 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
339 intPropertyLen = wxSPropertySeg2.Len();
347 for (int i = 0; i <= intPropertyLen; i++){
351 if (wxSPropertySeg2.Mid(i, 1) == wxT(";") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
354 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
356 if (intSplitsFound == 4){
358 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
363 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
373 // Split the data into several parts.
375 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
376 intiter != SplitPoints.end(); ++intiter){
378 if (intiter->first == 1){
380 // Deal with family name.
382 SLiter = SplitLength.find(1);
384 txtSurname->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
386 intPrevValue = intiter->second;
387 NameSurname = wxSPropertySeg2.Mid(0, SLiter->second);
389 } else if (intiter->first == 2){
391 // Deal with given names.
393 SLiter = SplitLength.find(2);
395 txtForename->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
396 intPrevValue = intiter->second;
397 NameForename = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
399 } else if (intiter->first == 3){
401 // Deal with additional names.
403 SLiter = SplitLength.find(3);
405 txtOtherNames->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
406 intPrevValue = intiter->second;
407 NameOtherNames = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
409 } else if (intiter->first == 4){
411 // Deal with honorifix prefixes and suffixes.
413 SLiter = SplitLength.find(4);
415 txtTitle->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
416 intPrevValue = intiter->second;
417 NameTitle = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
419 txtSuffix->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
420 NameSuffix = wxSPropertySeg2.Mid(intPrevValue);
426 NameTokens = PropertyTokens;
427 *NameProcessed = TRUE;