Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
e3d5f13aae0542ebb9216352be1bc634313b7447
[xestiaab/.git] / source / contacteditor / frmContactEditor-LoadAddress.cpp
1 // frmContactEditor-LoadAddress.cpp - frmContactEditor load address 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::LoadADR(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *ADRCount){
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         wxString AddressLabel;
32         wxString AddressLang;
33         wxString AddressAltID;
34         wxString AddressPID;
35         wxString AddressTokens;
36         wxString AddressGeo;
37         wxString AddressTimezone;
38         wxString AddressType;
39         wxString AddressMediatype;
40         wxString AddressPOBox;
41         wxString AddressExtended;
42         wxString AddressStreet;
43         wxString AddressLocality;
44         wxString AddressCity;
45         wxString AddressRegion;
46         wxString AddressPostalCode;
47         wxString AddressCountry;
48         bool FirstToken = TRUE;                 
49         int intSplitsFound = 0;
50         int intSplitSize = 0;
51         int intPrevValue = 5;
52         int intPref = 0;                        
53         int intType = 0;
54         long ListCtrlIndex;
55         
56         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
57         
58         intPrevValue = 4;
59         
60         // Look for type before continuing.
61         
62         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
63         intiter != SplitPoints.end(); ++intiter){
64         
65                 SLiter = SplitLength.find(intiter->first);
66         
67                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
68                 
69                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
70                 PropertyName = PropertyElement.GetNextToken();                          
71                 PropertyValue = PropertyElement.GetNextToken();
72                 
73                 intPrevValue = intiter->second;
74                 
75                 if (PropertyName == wxT("TYPE")){
76                 
77                         if (PropertyValue == wxT("work")){
78                         
79                                 intType = 2;                                    
80                         
81                         } else if (PropertyValue == wxT("home")){
83                                 intType = 1;
84                         
85                         } else {
86                         
87                                 intType = 0;
88                         
89                         }
90                 
91                 }
92         
93         }
94         
95         // Setup blank lines for later on.
96         
97         if (intType == 0){
98         
99                 GeneralAddressList.insert(std::make_pair(intValueSeek, wxT("")));
100                 GeneralAddressListTown.insert(std::make_pair(intValueSeek, wxT("")));
101                 GeneralAddressListCounty.insert(std::make_pair(intValueSeek, wxT("")));
102                 GeneralAddressListPostCode.insert(std::make_pair(intValueSeek, wxT("")));
103                 GeneralAddressListCountry.insert(std::make_pair(intValueSeek, wxT("")));
104                 GeneralAddressListLabel.insert(std::make_pair(intValueSeek, wxT("")));
105                 GeneralAddressListLang.insert(std::make_pair(intValueSeek, wxT("")));
106                 GeneralAddressListAltID.insert(std::make_pair(intValueSeek, wxT("")));
107                 GeneralAddressListPID.insert(std::make_pair(intValueSeek, wxT("")));
108                 GeneralAddressListGeo.insert(std::make_pair(intValueSeek, wxT("")));
109                 GeneralAddressListTimezone.insert(std::make_pair(intValueSeek, wxT("")));
110                 GeneralAddressListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
111                 GeneralAddressListPref.insert(std::make_pair(intValueSeek, 0));
112                 GeneralAddressListTokens.insert(std::make_pair(intValueSeek, wxT("")));
114         } else if (intType == 1){
115         
116                 HomeAddressList.insert(std::make_pair(intValueSeek, wxT("")));
117                 HomeAddressListTown.insert(std::make_pair(intValueSeek, wxT("")));
118                 HomeAddressListCounty.insert(std::make_pair(intValueSeek, wxT("")));
119                 HomeAddressListPostCode.insert(std::make_pair(intValueSeek, wxT("")));
120                 HomeAddressListCountry.insert(std::make_pair(intValueSeek, wxT("")));
121                 HomeAddressListLabel.insert(std::make_pair(intValueSeek, wxT("")));
122                 HomeAddressListLang.insert(std::make_pair(intValueSeek, wxT("")));
123                 HomeAddressListAltID.insert(std::make_pair(intValueSeek, wxT("")));
124                 HomeAddressListPID.insert(std::make_pair(intValueSeek, wxT("")));
125                 HomeAddressListGeo.insert(std::make_pair(intValueSeek, wxT("")));
126                 HomeAddressListTimezone.insert(std::make_pair(intValueSeek, wxT("")));
127                 HomeAddressListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
128                 HomeAddressListPref.insert(std::make_pair(intValueSeek, 0));
129                 HomeAddressListTokens.insert(std::make_pair(intValueSeek, wxT("")));
130         
131         } else if (intType == 2){
133                 BusinessAddressList.insert(std::make_pair(intValueSeek, wxT("")));
134                 BusinessAddressListTown.insert(std::make_pair(intValueSeek, wxT("")));
135                 BusinessAddressListCounty.insert(std::make_pair(intValueSeek, wxT("")));
136                 BusinessAddressListPostCode.insert(std::make_pair(intValueSeek, wxT("")));
137                 BusinessAddressListCountry.insert(std::make_pair(intValueSeek, wxT("")));
138                 BusinessAddressListLabel.insert(std::make_pair(intValueSeek, wxT("")));
139                 BusinessAddressListLang.insert(std::make_pair(intValueSeek, wxT("")));
140                 BusinessAddressListAltID.insert(std::make_pair(intValueSeek, wxT("")));
141                 BusinessAddressListPID.insert(std::make_pair(intValueSeek, wxT("")));
142                 BusinessAddressListGeo.insert(std::make_pair(intValueSeek, wxT("")));
143                 BusinessAddressListTimezone.insert(std::make_pair(intValueSeek, wxT("")));
144                 BusinessAddressListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
145                 BusinessAddressListPref.insert(std::make_pair(intValueSeek, 0));
146                 BusinessAddressListTokens.insert(std::make_pair(intValueSeek, wxT("")));
147         
148         }
149         
150         intPrevValue = 4;
151         
152         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
153         intiter != SplitPoints.end(); ++intiter){
154         
155                 SLiter = SplitLength.find(intiter->first);
156         
157                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
158                 
159                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
160                 PropertyName = PropertyElement.GetNextToken();                          
161                 PropertyValue = PropertyElement.GetNextToken();
162                 
163                 intPrevValue = intiter->second;
164                 
165                 ProcessCaptureStrings(&PropertyValue);
166                 
167                 // Process properties.
168                 
169                 if (PropertyName == wxT("LABEL")){
170                 
171                         if (intType == 0){ GeneralAddressListLabel.erase(intValueSeek); GeneralAddressListLabel.insert(std::make_pair(intValueSeek, PropertyValue)); }
172                         else if (intType == 1){ HomeAddressListLabel.erase(intValueSeek); HomeAddressListLabel.insert(std::make_pair(intValueSeek, PropertyValue)); }
173                         else if (intType == 2){ BusinessAddressListLabel.erase(intValueSeek); BusinessAddressListLabel.insert(std::make_pair(intValueSeek, PropertyValue));}
174                 
175                 } else if (PropertyName == wxT("LANGUAGE")){
176                 
177                         if (intType == 0){ GeneralAddressListLang.erase(intValueSeek); GeneralAddressListLang.insert(std::make_pair(intValueSeek, PropertyValue)); }
178                         else if (intType == 1){ HomeAddressListLang.erase(intValueSeek); HomeAddressListLang.insert(std::make_pair(intValueSeek, PropertyValue)); }
179                         else if (intType == 2){ BusinessAddressListLang.erase(intValueSeek); BusinessAddressListLang.insert(std::make_pair(intValueSeek, PropertyValue)); }                             
180                 
181                 } else if (PropertyName == wxT("ALTID")){
183                         if (intType == 0){ GeneralAddressListAltID.erase(intValueSeek); GeneralAddressListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
184                         else if (intType == 1){ HomeAddressListAltID.erase(intValueSeek); HomeAddressListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
185                         else if (intType == 2){ BusinessAddressListAltID.erase(intValueSeek); BusinessAddressListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
186                 
187                 } else if (PropertyName == wxT("PID")){
189                         if (intType == 0){ GeneralAddressListPID.erase(intValueSeek); GeneralAddressListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
190                         else if (intType == 1){ HomeAddressListPID.erase(intValueSeek); HomeAddressListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
191                         else if (intType == 2){ BusinessAddressListPID.erase(intValueSeek); BusinessAddressListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
192                 
193                 } else if (PropertyName == wxT("GEO")){
194                 
195                         if (intType == 0){ GeneralAddressListGeo.erase(intValueSeek); GeneralAddressListGeo.insert(std::make_pair(intValueSeek, PropertyValue)); }
196                         else if (intType == 1){ HomeAddressListGeo.erase(intValueSeek); HomeAddressListGeo.insert(std::make_pair(intValueSeek, PropertyValue)); }
197                         else if (intType == 2){ BusinessAddressListGeo.erase(intValueSeek); BusinessAddressListGeo.insert(std::make_pair(intValueSeek, PropertyValue)); }
198                 
199                 } else if (PropertyName == wxT("TZ")){
201                         if (intType == 0){ GeneralAddressListTimezone.erase(intValueSeek); GeneralAddressListTimezone.insert(std::make_pair(intValueSeek, PropertyValue)); }
202                         else if (intType == 1){ HomeAddressListTimezone.erase(intValueSeek); HomeAddressListTimezone.insert(std::make_pair(intValueSeek, PropertyValue)); }
203                         else if (intType == 2){ BusinessAddressListTimezone.erase(intValueSeek); BusinessAddressListTimezone.insert(std::make_pair(intValueSeek, PropertyValue)); }
204                 
205                 } else if (PropertyName == wxT("MEDIATYPE")){
207                         if (intType == 0){ GeneralAddressListMediatype.erase(intValueSeek); GeneralAddressListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
208                         else if (intType == 1){ HomeAddressListMediatype.erase(intValueSeek); HomeAddressListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
209                         else if (intType == 2){ BusinessAddressListMediatype.erase(intValueSeek); BusinessAddressListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
210                 
211                 } else if (PropertyName == wxT("PREF")){
212                         
213                         intPref = wxAtoi(PropertyValue);
214                         
215                         if (intPref > 0 && intPref < 101){
216                                                 
217                                 if (intType == 0){ GeneralAddressListPref.erase(intValueSeek); GeneralAddressListPref.insert(std::make_pair(intValueSeek, intPref)); }
218                                 else if (intType == 1){ HomeAddressListPref.erase(intValueSeek); HomeAddressListPref.insert(std::make_pair(intValueSeek, intPref)); }
219                                 else if (intType == 2){ BusinessAddressListPref.erase(intValueSeek); BusinessAddressListPref.insert(std::make_pair(intValueSeek, intPref)); }
220                                 
221                         }
222                 
223                 } else {
224                 
225                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
226                         
227                                 if (FirstToken == TRUE){
228                                 
229                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
230                                         FirstToken = FALSE;
231                                 
232                                 } else {
233                                 
234                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
235                                 
236                                 }
237                         
238                         }
239                 
240                 }
241         
242         }                       
243         
244         // Split the address. 
246         //std::map<int, int>::iterator SLiter;
247         intPropertyLen = wxSPropertySeg2.Len();
248         SplitPoints.clear();
249         SplitLength.clear();
250         intSplitsFound = 0;
251         intSplitSize = 0;
252         intPrevValue = 0;
253         
254         for (int i = 0; i <= intPropertyLen; i++){
256                 intSplitSize++;
257         
258                 if (wxSPropertySeg2.Mid(i, 1) == wxT(";") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
259         
260                         intSplitsFound++;
261                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
262                         
263                         if (intSplitsFound == 6){ 
264                         
265                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
266                                 break; 
267                                 
268                         } else {
269                         
270                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
271                         
272                         }
273                         
274                         intSplitSize = 0;                                       
275         
276                 }
278         }
279         
280         // Split the data into several parts.                   
281         
282         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
283         intiter != SplitPoints.end(); ++intiter){
284                         
285                 if (intiter->first == 1){
286                 
287                         // Deal with PO Box.
288                         
289                         SLiter = SplitLength.find(1);
290                                                                 
291                         //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
292                         AddressPOBox = wxSPropertySeg2.Mid(0, SLiter->second);
293                         intPrevValue = intiter->second;
294                 
295                 } else if (intiter->first == 2){
296                 
297                         // Deal with extended address.
298                         
299                         SLiter = SplitLength.find(2);
300                         
301                         AddressExtended = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
302                         //txtForename->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
303                         intPrevValue = intiter->second;
304                 
305                 } else if (intiter->first == 3){
306                 
307                         // Deal with street address.
308                         
309                         SLiter = SplitLength.find(3);
310                                                                 
311                         AddressStreet = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
312                         //txtOtherNames->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
313                         intPrevValue = intiter->second;
314                 
315                 } else if (intiter->first == 4){
316                 
317                         // Deal with locality
319                         SLiter = SplitLength.find(4);
320                         
321                         AddressLocality = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
322                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
323                         intPrevValue = intiter->second;
324                         
325                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
326                 
327                 } else if (intiter->first == 5){
328                 
329                         // Deal with region.
331                         SLiter = SplitLength.find(5);
332                         
333                         AddressRegion = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
334                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
335                         intPrevValue = intiter->second;
336                         
337                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
338                 
339                 } else if (intiter->first == 6){
340                 
341                         // Deal with post code.
343                         SLiter = SplitLength.find(6);
344                         
345                         AddressPostalCode = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
346                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
347                         intPrevValue = intiter->second;
348                         
349                         // Deal with country.
350                         
351                         AddressCountry = wxSPropertySeg2.Mid(intPrevValue);
352                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
353                 
354                 }
355         
356         }       
357         
358         // Add the data to the General/Home/Work address variables.
359         
360         ProcessCaptureStrings(&AddressStreet, &AddressLocality, &AddressRegion, &AddressPostalCode, &AddressCountry);
361         
362         wxListItem coldata;
364         coldata.SetId(intValueSeek);
365         coldata.SetData(intValueSeek);
366         coldata.SetText(AddressStreet);
367         
368         if (intType == 0){
369         
370                 ListCtrlIndex = lboAddresses->InsertItem(coldata);
371                 lboAddresses->SetItem(ListCtrlIndex, 1, AddressLocality);
372                 lboAddresses->SetItem(ListCtrlIndex, 2, AddressRegion);
373                 lboAddresses->SetItem(ListCtrlIndex, 3, AddressPostalCode);
374                 
375                 if (intPref > 0 && intPref < 101){
376                 
377                         lboAddresses->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), intPref));
378                         
379                 }
380                 
381                 GeneralAddressList.erase(intValueSeek);
382                 GeneralAddressListTown.erase(intValueSeek);
383                 GeneralAddressListCounty.erase(intValueSeek);
384                 GeneralAddressListPostCode.erase(intValueSeek);
385                 GeneralAddressListCountry.erase(intValueSeek);
386                 GeneralAddressListType.erase(intValueSeek);
387                 GeneralAddressListTokens.erase(intValueSeek);
388                 GeneralAddressList.insert(std::make_pair(intValueSeek, AddressStreet));
389                 GeneralAddressListTown.insert(std::make_pair(intValueSeek, AddressLocality));
390                 GeneralAddressListCounty.insert(std::make_pair(intValueSeek, AddressRegion));
391                 GeneralAddressListPostCode.insert(std::make_pair(intValueSeek, AddressPostalCode));
392                 GeneralAddressListCountry.insert(std::make_pair(intValueSeek, AddressCountry));
393                 GeneralAddressListType.insert(std::make_pair(intValueSeek, wxT("")));
394                 GeneralAddressListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
395         
396         } else if (intType == 1){ 
397         
398                 ListCtrlIndex = lboHomeAddresses->InsertItem(coldata);
399                 lboHomeAddresses->SetItem(ListCtrlIndex, 1, AddressLocality);
400                 lboHomeAddresses->SetItem(ListCtrlIndex, 2, AddressRegion);
401                 lboHomeAddresses->SetItem(ListCtrlIndex, 3, AddressPostalCode);
403                 if (intPref > 0 && intPref < 101){
404                 
405                         lboHomeAddresses->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
406                         
407                 }
409                 HomeAddressList.erase(intValueSeek);
410                 HomeAddressListTown.erase(intValueSeek);
411                 HomeAddressListCounty.erase(intValueSeek);
412                 HomeAddressListPostCode.erase(intValueSeek);
413                 HomeAddressListCountry.erase(intValueSeek);
414                 HomeAddressListType.erase(intValueSeek);
415                 HomeAddressListTokens.erase(intValueSeek);                              
416                 HomeAddressList.insert(std::make_pair(intValueSeek, AddressStreet));
417                 HomeAddressListTown.insert(std::make_pair(intValueSeek, AddressLocality));
418                 HomeAddressListCounty.insert(std::make_pair(intValueSeek, AddressRegion));
419                 HomeAddressListPostCode.insert(std::make_pair(intValueSeek, AddressPostalCode));
420                 HomeAddressListCountry.insert(std::make_pair(intValueSeek, AddressCountry));
421                 HomeAddressListType.insert(std::make_pair(intValueSeek, wxT("home")));
422                 HomeAddressListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
423         
424         } else if (intType == 2){ 
425         
426                 ListCtrlIndex = lboBusinessAddresses->InsertItem(coldata);
427                 lboBusinessAddresses->SetItem(ListCtrlIndex, 1, AddressLocality);
428                 lboBusinessAddresses->SetItem(ListCtrlIndex, 2, AddressRegion);
429                 lboBusinessAddresses->SetItem(ListCtrlIndex, 3, AddressPostalCode);
431                 if (intPref > 0 && intPref < 101){
432                 
433                         lboBusinessAddresses->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
434                         
435                 }
436                 
437                 BusinessAddressList.erase(intValueSeek);
438                 BusinessAddressListTown.erase(intValueSeek);
439                 BusinessAddressListCounty.erase(intValueSeek);
440                 BusinessAddressListPostCode.erase(intValueSeek);
441                 BusinessAddressListCountry.erase(intValueSeek);
442                 BusinessAddressListType.erase(intValueSeek);
443                 BusinessAddressListTokens.erase(intValueSeek);
444                 BusinessAddressList.insert(std::make_pair(intValueSeek, AddressStreet));
445                 BusinessAddressListTown.insert(std::make_pair(intValueSeek, AddressLocality));
446                 BusinessAddressListCounty.insert(std::make_pair(intValueSeek, AddressRegion));
447                 BusinessAddressListPostCode.insert(std::make_pair(intValueSeek, AddressPostalCode));
448                 BusinessAddressListCountry.insert(std::make_pair(intValueSeek, AddressCountry));
449                 BusinessAddressListType.insert(std::make_pair(intValueSeek, wxT("work")));
450                 BusinessAddressListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));                         
451         
452         }
453         
454         ADRCount++;
455         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