Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source, header and unit tests to the ADR vCard property in ContactDataObject.
[xestiaab/.git] / source / contacteditor / ContactDataObject.cpp
1 // ContactDataObject.cpp - Client Data Object.
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 "ContactDataObject.h"
21 ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
22         
23         if (!wxFileExists(Filename)){
24         
25                 return CONTACTLOAD_FILEMISSING;
26         
27         }
28         
29         wxFile ContactFile;
30         
31         if (!ContactFile.Open(Filename, wxFile::read, wxS_DEFAULT)){
32         
33                 return CONTACTLOAD_FILEERROR;
34         
35         }
36         
37         // Check that the vCard is a valid vCard 4.0 file.
39         vCard vCard4FormatCheck;
40         
41         vCard4FormatCheck.LoadFile(Filename);
42         
43         if (vCard4FormatCheck.Get("VERSION") != wxT("4.0")){
44         
45                 return CONTACTLOAD_FILEINVALIDFORMAT;
46         
47         }
49         // Check that the vCard meets the base specification.
50         
51         if (!vCard4FormatCheck.MeetBaseSpecification()){
52         
53                 return CONTACTLOAD_FILEBASESPECFAIL;
54         
55         }
56         
57         wxStringTokenizer wSTContactFileLines(vCard4FormatCheck.WriteString(), wxT("\r\n"));
58         
59         std::map<int, wxString> ContactFileLines;
61         int ContactLineSeek = 0;
63         while (wSTContactFileLines.HasMoreTokens() == TRUE){
65                 wxString ContactLine = wSTContactFileLines.GetNextToken();
66                 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
67                 ContactLineSeek++;              
68         
69         }
70         
71         wxString wxSPropertyNextLine;
72         
73         bool ExtraLineSeek = TRUE;
74         bool QuoteMode = FALSE;
75         bool PropertyFind = TRUE;
76         bool KindProcessed = FALSE;
77         bool NameProcessed = FALSE;
78         bool GenderProcessed = FALSE;
79         bool BirthdayProcessed = FALSE;
80         bool AnniversaryProcessed = FALSE;
81         int ContactLineLen = 0;
82         int QuoteBreakPoint = 0;
83         int GroupCount = 0;
84         int FNCount = 0;
85         int NicknameCount = 0;
86         int TimeZoneCount = 0;
87         int AddressCount = 0;
88         wxString ContactLine;
89         wxString PropertyLine;
90         wxString PropertySeg1;
91         wxString PropertySeg2;
92         wxString PropertyNextLine;
93         wxString Property;
94         
95         for (std::map<int,wxString>::iterator iter = ContactFileLines.begin(); 
96          iter != ContactFileLines.end(); ++iter){
98                 ExtraLineSeek = TRUE;
99                 QuoteMode = FALSE;
100                 PropertyFind = TRUE;
101                 ContactLineLen = 0;
102                 QuoteBreakPoint = 0;
103                 ContactLine.Clear();
104                 PropertyLine.Clear();
105                 PropertySeg1.Clear();
106                 PropertySeg2.Clear();
107                 Property.Clear();
108          
109                 ContactLine = iter->second;
110                 
111                 while (ExtraLineSeek == TRUE){
112                 
113                         // Check if there is extra data on the next line 
114                         // (indicated by space or tab at the start) and add data.
115                 
116                         iter++;
117                         
118                         if (iter == ContactFileLines.end()){
119                         
120                                 iter--;
121                                 break;
122                         
123                         }                       
124                 
125                         PropertyNextLine = iter->second;
126                 
127                         if (PropertyNextLine.Mid(0, 1) == wxT(" ") || PropertyNextLine.Mid(0, 1) == wxT("\t")){
128                 
129                                 PropertyNextLine.Remove(0, 1);
130                                 ContactLine.Append(PropertyNextLine);
131                 
132                         } else {
133                         
134                                 iter--;
135                                 ExtraLineSeek = FALSE;
136                         
137                         }
138                 
139                 }
141                 ContactLineLen = ContactLine.Len();
142                 
143                 // Make sure we are not in quotation mode.
144                 // Make sure colon does not have \ or \\ before it.
145                 
146                 for (int i = 0; i <= ContactLineLen; i++){
147                 
148                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
149                         
150                                 PropertyFind = FALSE;
151                         
152                         } else if (PropertyFind == TRUE){
153                         
154                                 Property.Append(ContactLine.Mid(i, 1));
155                         
156                         }               
157                 
158                         if (ContactLine.Mid(i, 1) == wxT("\"")){
159                         
160                                 if (QuoteMode == TRUE){
161                                 
162                                         QuoteMode = FALSE;
163                                 
164                                 } else {
165                         
166                                         QuoteMode = TRUE;
167                                         
168                                 }
169                         
170                         }
171                         
172                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
173                         
174                                 QuoteBreakPoint = i;
175                                 break;
176                         
177                         }
178                 
179                 }
180                 
181                 // Split that line at the point into two variables (ignore the colon).
182                 
183                 PropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
184                 PropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
185                 
186                  if (Property == wxT("KIND") && KindProcessed == FALSE){
187                                 
188                         ProcessKind(PropertySeg2);
189                 
190                 } else if (Property == wxT("MEMBER")){
192                         ProcessMember(PropertySeg1, PropertySeg2, &GroupCount);
193                         GroupCount++;   
194                 
195                 } else if (Property == wxT("FN")){
196                 
197                         ProcessFN(PropertySeg1, PropertySeg2, &FNCount);
198                         FNCount++;
199                 
200                 } else if (Property == wxT("N") && NameProcessed == FALSE){
201                 
202                         ProcessN(PropertySeg1, PropertySeg2);
203                         NameProcessed = TRUE;
204                 
205                 } else if (Property == wxT("NICKNAME")){
206                                                 
207                         ProcessNickname(PropertySeg1, PropertySeg2, &NicknameCount);
208                         NicknameCount++;
209                         
210                 } else if (Property == wxT("GENDER") && GenderProcessed == FALSE){
211                 
212                         ProcessGender(PropertySeg1, PropertySeg2);
213                         GenderProcessed = TRUE;
214                 
215                 } else if (Property == wxT("BDAY") && BirthdayProcessed == FALSE){
216                 
217                         ProcessBirthday(PropertySeg1, PropertySeg2);
218                         BirthdayProcessed = TRUE;
219                 
220                 } else if (Property == wxT("ANNIVERSARY") && AnniversaryProcessed == FALSE){
221                 
222                         ProcessAnniversary(PropertySeg1, PropertySeg2);
223                         AnniversaryProcessed = TRUE;
224                 
225                 } else if (Property == wxT("TZ")){
226                 
227                         ProcessTimeZone(PropertySeg1, PropertySeg2, &TimeZoneCount);
228                         TimeZoneCount++;
229                 
230                 } else if (Property == wxT("ADR")){
231                 
232                         ProcessAddress(PropertySeg1, PropertySeg2, &AddressCount);
233                         AddressCount++;
234                 
235                 }
236                 
237         }
238         
239         return CONTACTLOAD_OK;
243 void ContactDataObject::ProcessKind(wxString KindType){
245         if (KindType == wxT("individual")){
246                         
247                 ContactKind = CONTACTKIND_INDIVIDUAL;
248                         
249         } else if (KindType == wxT("group")){
250                         
251                 ContactKind = CONTACTKIND_GROUP;
252                         
253         } else if (KindType == wxT("org")){
254                         
255                 ContactKind = CONTACTKIND_ORGANISATION;
256                         
257         } else if (KindType == wxT("location")){
258                         
259                 ContactKind = CONTACTKIND_LOCATION;
260                         
261         } else {
262                         
263                 ContactKind = CONTACTKIND_NONE;                 
264         }
268 void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount){
270         std::map<int, int> SplitPoints;
271         std::map<int, int> SplitLength;
273         int intPrevValue = 8;
274         int intPref = 0;                        
275         int intType = 0;
276         
277         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
279         intPrevValue = 7;
280         
281         wxString PropertyName;
282         wxString PropertyValue;
283         wxString PropertyData;
284         wxString PropertyTokens;
285         std::map<int,int>::iterator SLiter;
286         bool FirstToken = TRUE;
287         
288         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
289         intiter != SplitPoints.end(); ++intiter){
290         
291                 SLiter = SplitLength.find(intiter->first);
292         
293                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
294                 
295                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
296                 PropertyName = PropertyElement.GetNextToken();                          
297                 PropertyValue = PropertyElement.GetNextToken();
298                 
299                 intPrevValue = intiter->second;
300                 
301                 CaptureString(&PropertyValue, FALSE);
302         
303                 if (PropertyName == wxT("ALTID")){
305                         GroupsListAltID.erase(*GroupCount);
306                         GroupsListAltID.insert(std::make_pair(*GroupCount, PropertyValue));
307                 
308                 } else if (PropertyName == wxT("PID")){
310                         GroupsListPID.erase(*GroupCount);
311                         GroupsListPID.insert(std::make_pair(*GroupCount, PropertyValue));
312                 
313                 } else if (PropertyName == wxT("PREF")){
315                         int PriorityNumber = 0;
316                         bool ValidNumber = TRUE;
317                         
318                         try{
319                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
320                         }
321                         
322                         catch(std::invalid_argument &e){
323                                 ValidNumber = FALSE;
324                         }
326                         if (ValidNumber == TRUE){
328                                 GroupsListPref.erase(*GroupCount);
329                                 GroupsListPref.insert(std::make_pair(*GroupCount, PriorityNumber));
330                 
331                         }
332                 
333                 } else if (PropertyName == wxT("MEDIATYPE")){
335                         GroupsListMediaType.erase(*GroupCount);
336                         GroupsListMediaType.insert(std::make_pair(*GroupCount, PropertyValue));
337                 
338                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
339                         
340                         if (FirstToken == TRUE){
341                                 
342                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
343                                 FirstToken = FALSE;
344                                 
345                         } else {
346                         
347                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
348                                 
349                         }
350                         
351                 }
352                 
353         }
355         GroupsList.insert(std::make_pair(*GroupCount, PropertySeg2));
357         if (!PropertyTokens.IsEmpty()){
358         
359                 GroupsListTokens.insert(std::make_pair(*GroupCount, PropertyTokens));
360         
361         }
366 void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount){
368         std::map<int, int> SplitPoints;
369         std::map<int, int> SplitLength;
371         int intPrevValue = 4;
372         int intPref = 0;                        
373         int intType = 0;
374         
375         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
377         intPrevValue = 3;
378         
379         wxString PropertyName;
380         wxString PropertyValue;
381         wxString PropertyData;
382         wxString PropertyTokens;
383         std::map<int,int>::iterator SLiter;
384         bool FirstToken = TRUE;
385         
386         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
387         intiter != SplitPoints.end(); ++intiter){
388         
389                 SLiter = SplitLength.find(intiter->first);
390         
391                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
392                 
393                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
394                 PropertyName = PropertyElement.GetNextToken();                          
395                 PropertyValue = PropertyElement.GetNextToken();
396                 
397                 intPrevValue = intiter->second;
398                 
399                 CaptureString(&PropertyValue, FALSE);
400                 
401                 if (PropertyName == wxT("TYPE")){
403                         if (!PropertyValue.IsEmpty() || PropertyValue == wxT("home") ||
404                                 PropertyValue == wxT("work") ){
406                                 FullNamesListType.erase(*FNCount);
407                                 FullNamesListType.insert(std::make_pair(*FNCount, PropertyValue));
408                 
409                         }
410                 
411                 } else if (PropertyName == wxT("LANGUAGE")){
413                         FullNamesListLanguage.erase(*FNCount);
414                         FullNamesListLanguage.insert(std::make_pair(*FNCount, PropertyValue));
415                 
416                 } else if (PropertyName == wxT("ALTID")){
417                 
418                         FullNamesListAltID.erase(*FNCount);
419                         FullNamesListAltID.insert(std::make_pair(*FNCount, PropertyValue));
420                 
421                 } else if (PropertyName == wxT("PID")){
423                         FullNamesListPID.erase(*FNCount);
424                         FullNamesListPID.insert(std::make_pair(*FNCount, PropertyValue));
425                 
426                 } else if (PropertyName == wxT("PREF")){
428                         int PriorityNumber = 0;
429                         bool ValidNumber = TRUE;
430                         
431                         try{
432                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
433                         }
434                         
435                         catch(std::invalid_argument &e){
436                                 ValidNumber = FALSE;
437                         }
439                         if (ValidNumber == TRUE){
441                                 FullNamesListPref.erase(*FNCount);
442                                 FullNamesListPref.insert(std::make_pair(*FNCount, PriorityNumber));
444                         }
445                 
446                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
447                         
448                         if (FirstToken == TRUE){
449                                 
450                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
451                                 FirstToken = FALSE;
452                                 
453                         } else {
454                         
455                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
456                                 
457                         }
458                         
459                 } 
460         
461         }
463         FullNamesList.insert(std::make_pair(*FNCount, PropertySeg2));
465         if (!PropertyTokens.IsEmpty()){
466         
467                 FullNamesListTokens.insert(std::make_pair(*FNCount, PropertyTokens));
468         
469         }
473 void ContactDataObject::ProcessN(wxString PropertySeg1, wxString PropertySeg2){
475         std::map<int, int> SplitPoints;
476         std::map<int, int> SplitLength;
478         int intPrevValue = 3;
479         int intPref = 0;                        
480         int intType = 0;
481         
482         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
483         
484         intPrevValue = 2;
485         
486         wxString PropertyName;
487         wxString PropertyValue;
488         wxString PropertyData;
489         wxString PropertyTokens;
490         std::map<int,int>::iterator SLiter;
491         bool FirstToken = TRUE;
492         
493         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
494         intiter != SplitPoints.end(); ++intiter){
495         
496                 SLiter = SplitLength.find(intiter->first);
497         
498                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
499                 
500                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
501                 PropertyName = PropertyElement.GetNextToken();                          
502                 PropertyValue = PropertyElement.GetNextToken();
503                 
504                 intPrevValue = intiter->second;
505                 
506                 CaptureString(&PropertyValue, FALSE);
507                 
508                 if (PropertyName == wxT("ALTID")){
510                         NameAltID = PropertyValue;
511                 
512                 } else if (PropertyName == wxT("LANGUAGE")){
513                 
514                         NameLanguage = PropertyValue;
515                 
516                 } else if (PropertyName == wxT("SORT-AS")){
517                 
518                         if (PropertyValue.Left(1) == wxT("\"") && PropertyValue.Right(1) == wxT("\"") &&
519                                 PropertyValue.Len() >= 3){
520                                 NameDisplayAs = PropertyValue.Mid(1, (PropertyValue.Len() - 2));
521                         }
522                 
523                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
524                         
525                         if (FirstToken == TRUE){
526                                 
527                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
528                                 FirstToken = FALSE;
529                                 
530                         } else {
531                         
532                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
533                                 
534                         }
535                         
536                 }
537         
538         }
539         
540         // Split the name data.
541         
542         int intSplitSeek = 0;           
543         int intSplitsFound = 0;
544         int intSplitSize = 0;
545         int intPropertyLen = PropertySeg2.Len();
546         
547         std::map<int,wxString> NameValues;
548         intPrevValue = 0;                                       
549         
550         for (int i = 0; i <= intPropertyLen; i++){
551         
552                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
553                         
554                         NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, intSplitSize)));
555                         
556                         intSplitSeek = i;
557                         intSplitSeek++;
558                         
559                         if (intSplitsFound == 4){
560                         
561                                 NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, wxString::npos)));
562                                 break;
563                         
564                         }
565                         
566                         intSplitSize = 0;
567                         continue;
568         
569                 }
570                 
571                 intSplitSize++;
573         }
574         
575         // Split the data into several parts.
576                         
577         for (std::map<int, wxString>::iterator iter = NameValues.begin(); 
578         iter != NameValues.end(); ++iter){
579         
580                 if (iter->first == 1){
581                 
582                         // Deal with family name.
583                         
584                         NameSurname = iter->second;
585                 
586                 } else if (iter->first == 2){
587                 
588                         // Deal with given names.
589                         
590                         NameForename = iter->second;
591                 
592                 } else if (iter->first == 3){
593                 
594                         // Deal with additional names.
595                         
596                         NameOtherNames = iter->second;
597                 
598                 } else if (iter->first == 4){
599                 
600                         // Deal with honorifix prefixes and suffixes.
602                         NameTitle = iter->second;
603                 
604                         iter++;
605                         
606                         if (iter == NameValues.end()){
607                         
608                                 break;
609                         
610                         }
611                 
612                         NameSuffix = iter->second;
613                 
614                 }
615         
616         }
617         
618         // Add the name token data.
619         
620         if (!PropertyTokens.IsEmpty()){
621         
622                 NameTokens = PropertyTokens;
623         
624         }
628 void ContactDataObject::ProcessNickname(wxString PropertySeg1, wxString PropertySeg2, int *NicknameCount){
630         std::map<int, int> SplitPoints;
631         std::map<int, int> SplitLength;
633         int intPrevValue = 10;
634         int intPref = 0;                        
635         
636         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
637         
638         intPrevValue = 9;
639         
640         PropertyType PropType;
641         
642         // Look for type before continuing.
643         
644         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
645         
646         intPrevValue = 9;
647         
648         std::map<int, wxString> *NicknamesList = NULL;
649         std::map<int, wxString> *NicknamesListType = NULL;
650         std::map<int, wxString> *NicknamesListLanguage = NULL;
651         std::map<int, wxString> *NicknamesListAltID = NULL;
652         std::map<int, wxString> *NicknamesListPID = NULL;
653         std::map<int, wxString> *NicknamesListTokens = NULL;            
654         std::map<int, int> *NicknamesListPref = NULL;
655         
656         switch(PropType){
657                 case PROPERTY_NONE:
658                         NicknamesList = &GeneralNicknamesList;
659                         NicknamesListType = &GeneralNicknamesListType;
660                         NicknamesListLanguage = &GeneralNicknamesListLanguage;
661                         NicknamesListAltID = &GeneralNicknamesListAltID;
662                         NicknamesListPID = &GeneralNicknamesListPID;
663                         NicknamesListTokens = &GeneralNicknamesListTokens;
664                         NicknamesListPref = &GeneralNicknamesListPref;
665                         break;
666                 case PROPERTY_HOME:
667                         NicknamesList = &HomeNicknamesList;
668                         NicknamesListType = &HomeNicknamesListType;
669                         NicknamesListLanguage = &HomeNicknamesListLanguage;
670                         NicknamesListAltID = &HomeNicknamesListAltID;
671                         NicknamesListPID = &HomeNicknamesListPID;
672                         NicknamesListTokens = &HomeNicknamesListTokens;
673                         NicknamesListPref = &HomeNicknamesListPref;
674                         break;
675                 case PROPERTY_WORK:
676                         NicknamesList = &BusinessNicknamesList;
677                         NicknamesListType = &BusinessNicknamesListType;
678                         NicknamesListLanguage = &BusinessNicknamesListLanguage;
679                         NicknamesListAltID = &BusinessNicknamesListAltID;
680                         NicknamesListPID = &BusinessNicknamesListPID;
681                         NicknamesListTokens = &BusinessNicknamesListTokens;
682                         NicknamesListPref = &BusinessNicknamesListPref;
683                         break;
684         }
685         
686         std::map<int, int>::iterator SLiter;    
687         wxString PropertyData;
688         wxString PropertyName;
689         wxString PropertyValue;
690         wxString PropertyTokens;
691         bool FirstToken = TRUE;
692         
693         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
694         intiter != SplitPoints.end(); ++intiter){
695         
696                 SLiter = SplitLength.find(intiter->first);
697         
698                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
699                 
700                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
701                 PropertyName = PropertyElement.GetNextToken();                          
702                 PropertyValue = PropertyElement.GetNextToken();
703                 
704                 intPrevValue = intiter->second;
705                 
706                 CaptureString(&PropertyValue, FALSE);
707                 
708                 if (PropertyName == wxT("ALTID")){
710                         NicknamesListAltID->erase(*NicknameCount);
711                         NicknamesListAltID->insert(std::make_pair(*NicknameCount, PropertyValue));
712                 
713                 } else if (PropertyName == wxT("PID")){
715                         NicknamesListPID->erase(*NicknameCount);
716                         NicknamesListPID->insert(std::make_pair(*NicknameCount, PropertyValue));        
718                 } else if (PropertyName == wxT("PREF")){
720                         int PriorityNumber = 0;
721                         bool ValidNumber = TRUE;
722                         
723                         try{
724                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
725                         }
726                         
727                         catch(std::invalid_argument &e){
728                                 ValidNumber = FALSE;
729                         }
731                         if (ValidNumber == TRUE){
733                                 NicknamesListPref->erase(*NicknameCount);
734                                 NicknamesListPref->insert(std::make_pair(*NicknameCount, PriorityNumber));
736                         }
737                 
738                 } else if (PropertyName == wxT("LANGUAGE")){
740                         NicknamesListLanguage->erase(*NicknameCount);
741                         NicknamesListLanguage->insert(std::make_pair(*NicknameCount, PropertyValue));   
743                 } else {
744                 
745                         // Something else we don't know about so append
746                         // to the tokens variable.
747                 
748                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
749                 
750                                 if (FirstToken == TRUE){
751                         
752                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
753                                         FirstToken = FALSE;
754                         
755                                 } else {
756                         
757                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
758                         
759                                 }
760                 
761                         }
762                 
763                 }
764                 
765         }
766         
767         NicknamesList->insert(std::make_pair(*NicknameCount, PropertySeg2));
768         
769         // Add the name token data.
770         
771         if (!PropertyTokens.IsEmpty()){
772         
773                 NicknamesListTokens->insert(std::make_pair(*NicknameCount, PropertyTokens));
774         
775         }
779 void ContactDataObject::ProcessGender(wxString PropertySeg1, wxString PropertySeg2){
781         std::map<int, int> SplitPoints;
782         std::map<int, int> SplitLength;
783         std::map<int, int>::iterator SLiter;                    
784         wxString PropertyData;
785         wxString PropertyName;
786         wxString PropertyValue;
787         wxString PropertyTokens;
788         bool FirstToken = TRUE;
789         int intPrevValue = 8;
791         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
793         intPrevValue = 7;                       
794         
795         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
796         intiter != SplitPoints.end(); ++intiter){
797         
798                 SLiter = SplitLength.find(intiter->first);
799         
800                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
801                 
802                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
803                 PropertyName = PropertyElement.GetNextToken();                          
804                 PropertyValue = PropertyElement.GetNextToken();
805                 
806                 intPrevValue = intiter->second;
807                 
808                 // Process properties.
809                 
810                 size_t intPropertyValueLen = PropertyValue.Len();
811                 
812                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
813                         
814                         PropertyValue.Trim();
815                         PropertyValue.RemoveLast();
816                         
817                 }                               
818                 
819                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
820                         
821                         PropertyValue.Remove(0, 1);
822                         
823                 }                               
824                 
825                 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
827                         if (FirstToken == TRUE){
828         
829                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
830                                 FirstToken = FALSE;
831         
832                         } else {
833         
834                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
835         
836                         }
838                 }
839         
840         }       
842         wxStringTokenizer GenderData (PropertySeg2, wxT(";"));
843         
844         wxString GenderComponent;
845         
846         if (GenderData.CountTokens() >= 2){
847         
848                 Gender = GenderData.GetNextToken();
849                 GenderDetails = GenderData.GetString();
850         
851                 CaptureString(&GenderDetails, FALSE);
852                                                 
853         } else {
854         
855                 Gender = GenderData.GetNextToken();
856         
857         }
858         
859         if (!PropertyTokens.IsEmpty()){
860         
861                 GenderTokens = PropertyTokens;
862         
863         }
867 void ContactDataObject::ProcessBirthday(wxString PropertySeg1, wxString PropertySeg2){
869         // Process date. Preserve the remainder in the string.
871         std::map<int, int> SplitPoints;
872         std::map<int, int> SplitLength;
873         std::map<int, int>::iterator SLiter;                    
874         wxString PropertyData;
875         wxString PropertyName;
876         wxString PropertyValue;
877         wxString PropertyTokens;
878         bool BirthdayText = FALSE;
879         int intPrevValue = 6;
881         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
883         intPrevValue = 5;
885         // Look for type before continuing.
887         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
888         intiter != SplitPoints.end(); ++intiter){
890                 SLiter = SplitLength.find(intiter->first);
892                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
893         
894                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
895                 PropertyName = PropertyElement.GetNextToken();                          
896                 PropertyValue = PropertyElement.GetNextToken();
897         
898                 intPrevValue = intiter->second;
899         
900                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){
901         
902                         CaptureString(&PropertySeg2, FALSE);
903                         Birthday = PropertySeg2;
904                         BirthdayText = TRUE;
905         
906                 }
908         }
910         // Setup blank lines for later on.
911         
912         intPrevValue = 5;
913         bool FirstToken = TRUE;
915         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
916         intiter != SplitPoints.end(); ++intiter){
918                 SLiter = SplitLength.find(intiter->first);
920                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
921         
922                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
923                 PropertyName = PropertyElement.GetNextToken();                          
924                 PropertyValue = PropertyElement.GetNextToken();
925         
926                 intPrevValue = intiter->second;
927         
928                 // Process properties.
929         
930                 CaptureString(&PropertyValue, FALSE);
931         
932                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
933                 
934                         PropertyValue.Trim();
935                         PropertyValue.RemoveLast();
936                 
937                 }                               
938         
939                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
940                 
941                         PropertyValue.Remove(0, 1);
942                 
943                 }                               
944         
945                 if (PropertyName == wxT("ALTID")){
947                         BirthdayAltID = PropertyValue;
948         
949                 } else if (PropertyName == wxT("CALSCALE")){
950         
951                         BirthdayCalScale = PropertyValue;
952         
953                 } else if (PropertyName != wxT("VALUE")) {
954         
955                         // Something else we don't know about so append
956                         // to the tokens variable.
957                 
958                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
959                 
960                                 if (FirstToken == TRUE){
961         
962                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
963                                         FirstToken = FALSE;
964         
965                                 } else {
966         
967                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
968         
969                                 }
970                                 
971                         }
972                         
973                 }
975         }       
977         // Add the data to the variables and form.
978         
979         if (BirthdayText == FALSE){
980         
981                 Birthday = PropertySeg2;
983         }
984         
985         if (!PropertyTokens.IsEmpty()){
986         
987                 BirthdayTokens = PropertyTokens;
989         }
993 void ContactDataObject::ProcessAnniversary(wxString PropertySeg1, wxString PropertySeg2){
995         // Process date. Preserve the remainder in the string.
997         std::map<int, int> SplitPoints;
998         std::map<int, int> SplitLength;
999         std::map<int, int>::iterator SLiter;                    
1000         wxString PropertyData;
1001         wxString PropertyName;
1002         wxString PropertyValue;
1003         wxString PropertyTokens;
1004         bool AnniversaryText = FALSE;
1005         int intPrevValue = 13;
1007         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1009         intPrevValue = 12;
1011         // Look for type before continuing.
1013         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1014         intiter != SplitPoints.end(); ++intiter){
1016                 SLiter = SplitLength.find(intiter->first);
1018                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1019         
1020                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1021                 PropertyName = PropertyElement.GetNextToken();                          
1022                 PropertyValue = PropertyElement.GetNextToken();
1023         
1024                 intPrevValue = intiter->second;
1025         
1026                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){
1027         
1028                         CaptureString(&PropertySeg2, FALSE);
1029                         Anniversary = PropertySeg2;
1030                         AnniversaryText = TRUE;
1031         
1032                 }
1034         }
1036         // Setup blank lines for later on.
1037         
1038         intPrevValue = 12;
1039         bool FirstToken = TRUE;
1041         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1042         intiter != SplitPoints.end(); ++intiter){
1044                 SLiter = SplitLength.find(intiter->first);
1046                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1047         
1048                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1049                 PropertyName = PropertyElement.GetNextToken();                          
1050                 PropertyValue = PropertyElement.GetNextToken();
1051         
1052                 intPrevValue = intiter->second;
1053         
1054                 // Process properties.
1055         
1056                 CaptureString(&PropertyValue, FALSE);
1057         
1058                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
1059                 
1060                         PropertyValue.Trim();
1061                         PropertyValue.RemoveLast();
1062                 
1063                 }                               
1064         
1065                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
1066                 
1067                         PropertyValue.Remove(0, 1);
1068                 
1069                 }                               
1070         
1071                 if (PropertyName == wxT("ALTID")){
1073                         AnniversaryAltID = PropertyValue;
1074         
1075                 } else if (PropertyName == wxT("CALSCALE")){
1076         
1077                         AnniversaryCalScale = PropertyValue;
1078         
1079                 } else if (PropertyName != wxT("VALUE")) {
1080         
1081                         // Something else we don't know about so append
1082                         // to the tokens variable.
1083                 
1084                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
1085                 
1086                                 if (FirstToken == TRUE){
1087         
1088                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1089                                         FirstToken = FALSE;
1090         
1091                                 } else {
1092         
1093                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1094         
1095                                 }
1096                                 
1097                         }
1098                         
1099                 }
1101         }       
1103         // Add the data to the variables and form.
1104         
1105         if (AnniversaryText == FALSE){
1106         
1107                 Anniversary = PropertySeg2;
1109         }
1110         
1111         if (!PropertyTokens.IsEmpty()){
1112         
1113                 AnniversaryTokens = PropertyTokens;
1115         }
1119 void ContactDataObject::ProcessTimeZone(wxString PropertySeg1, wxString PropertySeg2, int *TimeZoneCount){
1121         std::map<int, int> SplitPoints;
1122         std::map<int, int> SplitLength;
1124         int intPrevValue = 4;
1125         int intPref = 0;                        
1126         
1127         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1128         
1129         intPrevValue = 3;
1130         
1131         PropertyType PropType;
1132         
1133         // Look for type before continuing.
1134         
1135         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1136         
1137         intPrevValue = 3;
1138         
1139         std::map<int, wxString> *TZList = NULL;
1140         std::map<int, wxString> *TZListType = NULL;
1141         std::map<int, wxString> *TZListMediatype = NULL;
1142         std::map<int, wxString> *TZListAltID = NULL;
1143         std::map<int, wxString> *TZListPID = NULL;
1144         std::map<int, wxString> *TZListTokens = NULL;           
1145         std::map<int, int> *TZListPref = NULL;
1146         
1147         switch(PropType){
1148                 case PROPERTY_NONE:
1149                         TZList = &GeneralTZList;
1150                         TZListType = &GeneralTZListType;
1151                         TZListMediatype = &GeneralTZListMediatype;
1152                         TZListAltID = &GeneralTZListAltID;
1153                         TZListPID = &GeneralTZListPID;
1154                         TZListTokens = &GeneralTZListTokens;
1155                         TZListPref = &GeneralTZListPref;
1156                         break;
1157                 case PROPERTY_HOME:
1158                         TZList = &HomeTZList;
1159                         TZListType = &HomeTZListType;
1160                         TZListMediatype = &HomeTZListMediatype;
1161                         TZListAltID = &HomeTZListAltID;
1162                         TZListPID = &HomeTZListPID;
1163                         TZListTokens = &HomeTZListTokens;
1164                         TZListPref = &HomeTZListPref;
1165                         break;
1166                 case PROPERTY_WORK:
1167                         TZList = &BusinessTZList;
1168                         TZListType = &BusinessTZListType;
1169                         TZListMediatype = &BusinessTZListMediatype;
1170                         TZListAltID = &BusinessTZListAltID;
1171                         TZListPID = &BusinessTZListPID;
1172                         TZListTokens = &BusinessTZListTokens;
1173                         TZListPref = &BusinessTZListPref;
1174                         break;
1175         }
1176         
1177         std::map<int, int>::iterator SLiter;    
1178         wxString PropertyData;
1179         wxString PropertyName;
1180         wxString PropertyValue;
1181         wxString PropertyTokens;
1182         bool FirstToken = TRUE;
1183         
1184         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1185         intiter != SplitPoints.end(); ++intiter){
1186         
1187                 SLiter = SplitLength.find(intiter->first);
1188         
1189                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1190                 
1191                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1192                 PropertyName = PropertyElement.GetNextToken();                          
1193                 PropertyValue = PropertyElement.GetNextToken();
1194                 
1195                 intPrevValue = intiter->second;
1196                 
1197                 CaptureString(&PropertyValue, FALSE);
1199                 if (PropertyName == wxT("ALTID")){
1201                         TZListAltID->erase(*TimeZoneCount);
1202                         TZListAltID->insert(std::make_pair(*TimeZoneCount, PropertyValue));
1203                 
1204                 } else if (PropertyName == wxT("PID")){
1206                         TZListPID->erase(*TimeZoneCount);
1207                         TZListPID->insert(std::make_pair(*TimeZoneCount, PropertyValue));       
1209                 } else if (PropertyName == wxT("PREF")){
1211                         int PriorityNumber = 0;
1212                         bool ValidNumber = TRUE;
1213                         
1214                         try{
1215                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1216                         }
1217                         
1218                         catch(std::invalid_argument &e){
1219                                 ValidNumber = FALSE;
1220                         }
1222                         if (ValidNumber == TRUE){
1224                                 TZListPref->erase(*TimeZoneCount);
1225                                 TZListPref->insert(std::make_pair(*TimeZoneCount, PriorityNumber));
1227                         }
1228                 
1229                 } else if (PropertyName == wxT("MEDIATYPE")){
1231                         TZListMediatype->erase(*TimeZoneCount);
1232                         TZListMediatype->insert(std::make_pair(*TimeZoneCount, PropertyValue)); 
1234                 } else {
1235                 
1236                         // Something else we don't know about so append
1237                         // to the tokens variable.
1238                 
1239                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1240                 
1241                                 if (FirstToken == TRUE){
1242                         
1243                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1244                                         FirstToken = FALSE;
1245                         
1246                                 } else {
1247                         
1248                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1249                         
1250                                 }
1251                 
1252                         }
1253                 
1254                 }
1255                 
1256         }
1257         
1258         TZList->insert(std::make_pair(*TimeZoneCount, PropertySeg2));
1259         
1260         // Add the name token data.
1261         
1262         if (!PropertyTokens.IsEmpty()){
1263         
1264                 TZListTokens->insert(std::make_pair(*TimeZoneCount, PropertyTokens));
1265         
1266         }
1271 void ContactDataObject::ProcessAddress(wxString PropertySeg1, wxString PropertySeg2, int *AddressCount){
1273         size_t intPropertyLen = PropertySeg1.Len();
1274         std::map<int, int> SplitPoints;
1275         std::map<int, int> SplitLength;
1276         std::map<int, int>::iterator SLiter;                    
1277         wxString PropertyData;
1278         wxString PropertyName;
1279         wxString PropertyValue;
1280         wxString PropertyTokens;
1281         wxString AddressLabel;
1282         wxString AddressLang;
1283         wxString AddressAltID;
1284         wxString AddressPID;
1285         wxString AddressTokens;
1286         wxString AddressGeo;
1287         wxString AddressTimezone;
1288         wxString AddressType;
1289         wxString AddressMediatype;
1290         wxString AddressPOBox;
1291         wxString AddressExtended;
1292         wxString AddressStreet;
1293         wxString AddressLocality;
1294         wxString AddressCity;
1295         wxString AddressRegion;
1296         wxString AddressPostalCode;
1297         wxString AddressCountry;
1298         bool FirstToken = TRUE;                 
1299         int intSplitsFound = 0;
1300         int intSplitSize = 0;
1301         int intPrevValue = 5;
1302         int intPref = 0;                        
1303         int intType = 0;
1304         long ListCtrlIndex;
1305         
1306         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1307         
1308         intPrevValue = 4;
1309         
1310         PropertyType PropType;
1311         
1312         // Look for type before continuing.
1313         
1314         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1315         
1316         intPrevValue = 4;
1317         
1318         std::map<int, wxString> *AddressList = NULL;
1319         std::map<int, wxString> *AddressListTown = NULL;
1320         std::map<int, wxString> *AddressListCounty = NULL;
1321         std::map<int, wxString> *AddressListPostCode = NULL;
1322         std::map<int, wxString> *AddressListCountry = NULL;
1323         std::map<int, wxString> *AddressListLabel = NULL;
1324         std::map<int, wxString> *AddressListLang = NULL;                
1325         std::map<int, wxString> *AddressListAltID = NULL;
1326         std::map<int, wxString> *AddressListPID = NULL;
1327         std::map<int, wxString> *AddressListTokens = NULL;
1328         std::map<int, wxString> *AddressListGeo = NULL;
1329         std::map<int, wxString> *AddressListTimezone = NULL;            
1330         std::map<int, wxString> *AddressListType = NULL;
1331         std::map<int, wxString> *AddressListMediatype = NULL;
1332         std::map<int, int> *AddressListPref = NULL;
1334         switch(PropType){
1335                 case PROPERTY_NONE:
1336                         AddressList = &GeneralAddressList;
1337                         AddressListTown = &GeneralAddressListTown;
1338                         AddressListCounty = &GeneralAddressListCounty;
1339                         AddressListPostCode = &GeneralAddressListPostCode;
1340                         AddressListCountry = &GeneralAddressListCountry;
1341                         AddressListLabel = &GeneralAddressListLabel;
1342                         AddressListLang = &GeneralAddressListLang;              
1343                         AddressListAltID = &GeneralAddressListAltID;
1344                         AddressListPID = &GeneralAddressListPID;
1345                         AddressListTokens = &GeneralAddressListTokens;
1346                         AddressListGeo = &GeneralAddressListGeo;
1347                         AddressListTimezone = &GeneralAddressListTimezone;
1348                         AddressListType = &GeneralAddressListType;
1349                         AddressListMediatype = &GeneralAddressListMediatype;
1350                         AddressListPref = &GeneralAddressListPref;              
1351                         break;
1352                 case PROPERTY_HOME:
1353                         AddressList = &HomeAddressList;
1354                         AddressListTown = &HomeAddressListTown;
1355                         AddressListCounty = &HomeAddressListCounty;
1356                         AddressListPostCode = &HomeAddressListPostCode;
1357                         AddressListCountry = &HomeAddressListCountry;
1358                         AddressListLabel = &HomeAddressListLabel;
1359                         AddressListLang = &HomeAddressListLang;         
1360                         AddressListAltID = &HomeAddressListAltID;
1361                         AddressListPID = &HomeAddressListPID;
1362                         AddressListTokens = &HomeAddressListTokens;
1363                         AddressListGeo = &HomeAddressListGeo;
1364                         AddressListTimezone = &HomeAddressListTimezone;
1365                         AddressListType = &HomeAddressListType;
1366                         AddressListMediatype = &HomeAddressListMediatype;
1367                         AddressListPref = &HomeAddressListPref;
1368                         break;
1369                 case PROPERTY_WORK:
1370                         AddressList = &BusinessAddressList;
1371                         AddressListTown = &BusinessAddressListTown;
1372                         AddressListCounty = &BusinessAddressListCounty;
1373                         AddressListPostCode = &BusinessAddressListPostCode;
1374                         AddressListCountry = &BusinessAddressListCountry;
1375                         AddressListLabel = &BusinessAddressListLabel;
1376                         AddressListLang = &BusinessAddressListLang;             
1377                         AddressListAltID = &BusinessAddressListAltID;
1378                         AddressListPID = &BusinessAddressListPID;
1379                         AddressListTokens = &BusinessAddressListTokens;
1380                         AddressListGeo = &BusinessAddressListGeo;
1381                         AddressListTimezone = &BusinessAddressListTimezone;
1382                         AddressListType = &BusinessAddressListType;
1383                         AddressListMediatype = &BusinessAddressListMediatype;
1384                         AddressListPref = &BusinessAddressListPref;
1385                         break;
1386         }
1387         
1388         intPrevValue = 4;
1389         
1390         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1391         intiter != SplitPoints.end(); ++intiter){
1392         
1393                 SLiter = SplitLength.find(intiter->first);
1394         
1395                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1396                 
1397                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1398                 PropertyName = PropertyElement.GetNextToken();                          
1399                 PropertyValue = PropertyElement.GetNextToken();
1400                 
1401                 intPrevValue = intiter->second;
1402                 
1403                 CaptureString(&PropertyValue, FALSE);
1404                 
1405                 // Process properties.
1406                 
1407                 if (PropertyName == wxT("LABEL")){
1408                 
1409                         AddressListLabel->erase(*AddressCount);
1410                         AddressListLabel->insert(std::make_pair(*AddressCount, PropertyValue));
1411                                 
1412                 } else if (PropertyName == wxT("LANGUAGE")){
1413                 
1414                         AddressListLang->erase(*AddressCount);
1415                         AddressListLang->insert(std::make_pair(*AddressCount, PropertyValue));                  
1416                 
1417                 } else if (PropertyName == wxT("ALTID")){
1419                         AddressListAltID->erase(*AddressCount);
1420                         AddressListAltID->insert(std::make_pair(*AddressCount, PropertyValue));
1421                 
1422                 } else if (PropertyName == wxT("PID")){
1424                         AddressListPID->erase(*AddressCount);
1425                         AddressListPID->insert(std::make_pair(*AddressCount, PropertyValue));
1426                 
1427                 } else if (PropertyName == wxT("GEO")){
1428                 
1429                         AddressListGeo->erase(*AddressCount);
1430                         AddressListGeo->insert(std::make_pair(*AddressCount, PropertyValue));
1431                 
1432                 } else if (PropertyName == wxT("TZ")){
1434                         AddressListTimezone->erase(*AddressCount);
1435                         AddressListTimezone->insert(std::make_pair(*AddressCount, PropertyValue));
1436                 
1437                 } else if (PropertyName == wxT("MEDIATYPE")){
1439                         AddressListMediatype->erase(*AddressCount);
1440                         AddressListMediatype->insert(std::make_pair(*AddressCount, PropertyValue));
1441                 
1442                 } else if (PropertyName == wxT("PREF")){
1443                         
1444                         int PriorityNumber = 0;
1445                         bool ValidNumber = TRUE;
1446                         
1447                         try{
1448                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1449                         }
1450                         
1451                         catch(std::invalid_argument &e){
1452                                 ValidNumber = FALSE;
1453                         }
1455                         if (ValidNumber == TRUE){
1457                                 AddressListPref->erase(*AddressCount);
1458                                 AddressListPref->insert(std::make_pair(*AddressCount, PriorityNumber));
1460                         }
1461                 
1462                 } else {
1463                 
1464                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1465                         
1466                                 if (FirstToken == TRUE){
1467                                 
1468                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1469                                         FirstToken = FALSE;
1470                                 
1471                                 } else {
1472                                 
1473                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1474                                 
1475                                 }
1476                         
1477                         }
1478                 
1479                 }
1480         
1481         }                       
1482         
1483         // Split the address. 
1485         //std::map<int, int>::iterator SLiter;
1486         intPropertyLen = PropertySeg2.Len();
1487         SplitPoints.clear();
1488         SplitLength.clear();
1489         intSplitsFound = 0;
1490         intSplitSize = 0;
1491         intPrevValue = 0;
1492         
1493         for (int i = 0; i <= intPropertyLen; i++){
1495                 intSplitSize++;
1496         
1497                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
1498         
1499                         intSplitsFound++;
1500                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
1501                         
1502                         if (intSplitsFound == 6){ 
1503                         
1504                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1505                                 break; 
1506                                 
1507                         } else {
1508                         
1509                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1510                         
1511                         }
1512                         
1513                         intSplitSize = 0;                                       
1514         
1515                 }
1517         }
1518         
1519         // Split the data into several parts.                   
1520         
1521         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1522         intiter != SplitPoints.end(); ++intiter){
1523                         
1524                 if (intiter->first == 1){
1525                 
1526                         // Deal with PO Box.
1527                         
1528                         SLiter = SplitLength.find(1);
1529                                                                 
1530                         //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
1531                         AddressPOBox = PropertySeg2.Mid(0, SLiter->second);
1532                         intPrevValue = intiter->second;
1533                 
1534                 } else if (intiter->first == 2){
1535                 
1536                         // Deal with extended address.
1537                         
1538                         SLiter = SplitLength.find(2);
1539                         
1540                         AddressExtended = PropertySeg2.Mid(intPrevValue, SLiter->second);
1541                         //txtForename->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1542                         intPrevValue = intiter->second;
1543                 
1544                 } else if (intiter->first == 3){
1545                 
1546                         // Deal with street address.
1547                         
1548                         SLiter = SplitLength.find(3);
1549                                                                 
1550                         AddressStreet = PropertySeg2.Mid(intPrevValue, SLiter->second);
1551                         //txtOtherNames->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1552                         intPrevValue = intiter->second;
1553                 
1554                 } else if (intiter->first == 4){
1555                 
1556                         // Deal with locality
1558                         SLiter = SplitLength.find(4);
1559                         
1560                         AddressLocality = PropertySeg2.Mid(intPrevValue, SLiter->second);
1561                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1562                         intPrevValue = intiter->second;
1563                         
1564                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1565                 
1566                 } else if (intiter->first == 5){
1567                 
1568                         // Deal with region.
1570                         SLiter = SplitLength.find(5);
1571                         
1572                         AddressRegion = PropertySeg2.Mid(intPrevValue, SLiter->second);
1573                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1574                         intPrevValue = intiter->second;
1575                         
1576                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1577                 
1578                 } else if (intiter->first == 6){
1579                 
1580                         // Deal with post code.
1582                         SLiter = SplitLength.find(6);
1583                         
1584                         AddressPostalCode = PropertySeg2.Mid(intPrevValue, SLiter->second);
1585                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1586                         intPrevValue = intiter->second;
1587                         
1588                         // Deal with country.
1589                                                 
1590                         AddressCountry = PropertySeg2.Mid(intPrevValue, wxString::npos);
1591                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1592                         
1593                         break;
1594                 
1595                 }
1596         
1597         }       
1598         
1599         // Add the data to the General/Home/Work address variables.
1600         
1601         CaptureString(&AddressStreet, FALSE); 
1602         CaptureString(&AddressLocality, FALSE);
1603         CaptureString(&AddressRegion, FALSE);
1604         CaptureString(&AddressPostalCode, FALSE);
1605         CaptureString(&AddressCountry, FALSE);
1606                 
1607         if (!PropertyTokens.IsEmpty()){
1608         
1609                 AddressListTokens->insert(std::make_pair(*AddressCount, PropertyTokens));
1610         
1611         }
1613         AddressListCountry->insert(std::make_pair(*AddressCount, AddressCountry));      
1614         AddressList->insert(std::make_pair(*AddressCount, AddressStreet));
1615         AddressListTown->insert(std::make_pair(*AddressCount, AddressLocality));
1616         AddressListCounty->insert(std::make_pair(*AddressCount, AddressRegion));
1617         AddressListPostCode->insert(std::make_pair(*AddressCount, AddressPostalCode));
1619         switch(PropType){
1620                 case PROPERTY_NONE:
1621                         AddressListType->insert(std::make_pair(*AddressCount, wxT("")));
1622                         break;
1623                 case PROPERTY_HOME:
1624                         AddressListType->insert(std::make_pair(*AddressCount, wxT("home")));
1625                         break;
1626                 case PROPERTY_WORK:
1627                         AddressListType->insert(std::make_pair(*AddressCount, wxT("work")));    
1628                         break;
1629         }
1630         
1631         AddressListTokens->insert(std::make_pair(*AddressCount, PropertyTokens));
1635 void SplitValues(wxString *PropertyLine, 
1636         std::map<int,int> *SplitPoints, 
1637         std::map<int,int> *SplitLength, 
1638         int intSize){
1639         
1640         size_t intPropertyLen = PropertyLine->Len();
1641         int intSplitsFound = 0;
1642         int intSplitSize = 0;
1643         int intSplitSeek = 0;
1644         
1645         for (int i = intSize; i <= intPropertyLen; i++){
1647                 intSplitSize++;
1648         
1649                 if (PropertyLine->Mid(i, 1) == wxT(";") &&
1650                     PropertyLine->Mid((i - 1), 1) != wxT("\\")){
1651            
1652                     if (intSplitsFound == 0){
1653             
1654                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
1655           
1656                     } else {
1657            
1658                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1659             
1660                     }
1661             
1662                     SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
1663             
1664                     intSplitsFound++;
1665                     intSplitSeek = i;
1666                     intSplitSize = 0;
1667             
1668                 }
1670         }
1672         if (intSplitsFound == 0){
1674                 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
1675                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1677         } else {
1679                 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
1680                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1682         }
1686 void CheckType(wxString *PropertySeg1, 
1687         std::map<int,int> *SplitPoints, 
1688         std::map<int,int> *SplitLength, 
1689         int *intPrevValue, 
1690         PropertyType *PropType){
1691         
1692         wxString PropertyData;
1693         wxString PropertyName;
1694         wxString PropertyValue;
1695         std::map<int,int>::iterator SLiter;
1696         
1697         for (std::map<int, int>::iterator intiter = SplitPoints->begin(); 
1698         intiter != SplitPoints->end(); ++intiter){
1699         
1700                 SLiter = SplitLength->find(intiter->first);
1701         
1702                 PropertyData = PropertySeg1->Mid(*intPrevValue, (SLiter->second));
1703                 
1704                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1705                 PropertyName = PropertyElement.GetNextToken();                          
1706                 PropertyValue = PropertyElement.GetNextToken();
1707                 
1708                 *intPrevValue = intiter->second;
1709                 
1710                 if (PropertyName == wxT("TYPE")){
1711                                 
1712                         if (PropertyValue == wxT("work")){
1713                         
1714                                 *PropType = PROPERTY_WORK;
1715                                                         
1716                         } else if (PropertyValue == wxT("home")){
1718                                 *PropType = PROPERTY_HOME;
1719                                                         
1720                         } else {
1721                         
1722                                 *PropType = PROPERTY_NONE;
1723                         
1724                         }
1725                 
1726                         return;
1727                 
1728                 }
1729         
1730         }
1731         
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