Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source code, headers and unit testing code for the LANG vCard property for...
[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         int EmailCount = 0;
89         int IMCount = 0;
90         int TelephoneCount = 0;
91         int LanguageCount = 0;
92         wxString ContactLine;
93         wxString PropertyLine;
94         wxString PropertySeg1;
95         wxString PropertySeg2;
96         wxString PropertyNextLine;
97         wxString Property;
98         
99         for (std::map<int,wxString>::iterator iter = ContactFileLines.begin(); 
100          iter != ContactFileLines.end(); ++iter){
102                 ExtraLineSeek = TRUE;
103                 QuoteMode = FALSE;
104                 PropertyFind = TRUE;
105                 ContactLineLen = 0;
106                 QuoteBreakPoint = 0;
107                 ContactLine.Clear();
108                 PropertyLine.Clear();
109                 PropertySeg1.Clear();
110                 PropertySeg2.Clear();
111                 Property.Clear();
112          
113                 ContactLine = iter->second;
114                 
115                 while (ExtraLineSeek == TRUE){
116                 
117                         // Check if there is extra data on the next line 
118                         // (indicated by space or tab at the start) and add data.
119                 
120                         iter++;
121                         
122                         if (iter == ContactFileLines.end()){
123                         
124                                 iter--;
125                                 break;
126                         
127                         }                       
128                 
129                         PropertyNextLine = iter->second;
130                 
131                         if (PropertyNextLine.Mid(0, 1) == wxT(" ") || PropertyNextLine.Mid(0, 1) == wxT("\t")){
132                 
133                                 PropertyNextLine.Remove(0, 1);
134                                 ContactLine.Append(PropertyNextLine);
135                 
136                         } else {
137                         
138                                 iter--;
139                                 ExtraLineSeek = FALSE;
140                         
141                         }
142                 
143                 }
145                 ContactLineLen = ContactLine.Len();
146                 
147                 // Make sure we are not in quotation mode.
148                 // Make sure colon does not have \ or \\ before it.
149                 
150                 for (int i = 0; i <= ContactLineLen; i++){
151                 
152                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
153                         
154                                 PropertyFind = FALSE;
155                         
156                         } else if (PropertyFind == TRUE){
157                         
158                                 Property.Append(ContactLine.Mid(i, 1));
159                         
160                         }               
161                 
162                         if (ContactLine.Mid(i, 1) == wxT("\"")){
163                         
164                                 if (QuoteMode == TRUE){
165                                 
166                                         QuoteMode = FALSE;
167                                 
168                                 } else {
169                         
170                                         QuoteMode = TRUE;
171                                         
172                                 }
173                         
174                         }
175                         
176                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
177                         
178                                 QuoteBreakPoint = i;
179                                 break;
180                         
181                         }
182                 
183                 }
184                 
185                 // Split that line at the point into two variables (ignore the colon).
186                 
187                 PropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
188                 PropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
189                 
190                  if (Property == wxT("KIND") && KindProcessed == FALSE){
191                                 
192                         ProcessKind(PropertySeg2);
193                 
194                 } else if (Property == wxT("MEMBER")){
196                         ProcessMember(PropertySeg1, PropertySeg2, &GroupCount);
197                         GroupCount++;   
198                 
199                 } else if (Property == wxT("FN")){
200                 
201                         ProcessFN(PropertySeg1, PropertySeg2, &FNCount);
202                         FNCount++;
203                 
204                 } else if (Property == wxT("N") && NameProcessed == FALSE){
205                 
206                         ProcessN(PropertySeg1, PropertySeg2);
207                         NameProcessed = TRUE;
208                 
209                 } else if (Property == wxT("NICKNAME")){
210                                                 
211                         ProcessNickname(PropertySeg1, PropertySeg2, &NicknameCount);
212                         NicknameCount++;
213                         
214                 } else if (Property == wxT("GENDER") && GenderProcessed == FALSE){
215                 
216                         ProcessGender(PropertySeg1, PropertySeg2);
217                         GenderProcessed = TRUE;
218                 
219                 } else if (Property == wxT("BDAY") && BirthdayProcessed == FALSE){
220                 
221                         ProcessBirthday(PropertySeg1, PropertySeg2);
222                         BirthdayProcessed = TRUE;
223                 
224                 } else if (Property == wxT("ANNIVERSARY") && AnniversaryProcessed == FALSE){
225                 
226                         ProcessAnniversary(PropertySeg1, PropertySeg2);
227                         AnniversaryProcessed = TRUE;
228                 
229                 } else if (Property == wxT("TZ")){
230                 
231                         ProcessTimeZone(PropertySeg1, PropertySeg2, &TimeZoneCount);
232                         TimeZoneCount++;
233                 
234                 } else if (Property == wxT("ADR")){
235                 
236                         ProcessAddress(PropertySeg1, PropertySeg2, &AddressCount);
237                         AddressCount++;
238                 
239                 } else if (Property == wxT("EMAIL")){
240                                         
241                         ProcessEmail(PropertySeg1, PropertySeg2, &EmailCount);  
242                         EmailCount++;
243                 
244                 } else if (Property == wxT("IMPP")){
245                 
246                         ProcessIM(PropertySeg1, PropertySeg2, &IMCount);
247                         IMCount++;
248                         
249                 } else if (Property == wxT("TEL")){
250                                 
251                         ProcessTelephone(PropertySeg1, PropertySeg2, &TelephoneCount);
252                         TelephoneCount++;
253                 
254                 } else if (Property == wxT("LANG")){
255                 
256                         // See frmContactEditor-LoadLanguage.cpp
257                         
258                         ProcessLanguage(PropertySeg1, PropertySeg2, &LanguageCount);
259                         LanguageCount++;
260                 
261                 }
262                 
263         }
264         
265         return CONTACTLOAD_OK;
269 void ContactDataObject::ProcessKind(wxString KindType){
271         if (KindType == wxT("individual")){
272                         
273                 ContactKind = CONTACTKIND_INDIVIDUAL;
274                         
275         } else if (KindType == wxT("group")){
276                         
277                 ContactKind = CONTACTKIND_GROUP;
278                         
279         } else if (KindType == wxT("org")){
280                         
281                 ContactKind = CONTACTKIND_ORGANISATION;
282                         
283         } else if (KindType == wxT("location")){
284                         
285                 ContactKind = CONTACTKIND_LOCATION;
286                         
287         } else {
288                         
289                 ContactKind = CONTACTKIND_NONE;                 
290         }
294 void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount){
296         std::map<int, int> SplitPoints;
297         std::map<int, int> SplitLength;
299         int intPrevValue = 8;
300         int intPref = 0;                        
301         int intType = 0;
302         
303         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
305         intPrevValue = 7;
306         
307         wxString PropertyName;
308         wxString PropertyValue;
309         wxString PropertyData;
310         wxString PropertyTokens;
311         std::map<int,int>::iterator SLiter;
312         bool FirstToken = TRUE;
313         
314         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
315         intiter != SplitPoints.end(); ++intiter){
316         
317                 SLiter = SplitLength.find(intiter->first);
318         
319                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
320                 
321                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
322                 PropertyName = PropertyElement.GetNextToken();                          
323                 PropertyValue = PropertyElement.GetNextToken();
324                 
325                 intPrevValue = intiter->second;
326                 
327                 CaptureString(&PropertyValue, FALSE);
328         
329                 if (PropertyName == wxT("ALTID")){
331                         GroupsListAltID.erase(*GroupCount);
332                         GroupsListAltID.insert(std::make_pair(*GroupCount, PropertyValue));
333                 
334                 } else if (PropertyName == wxT("PID")){
336                         GroupsListPID.erase(*GroupCount);
337                         GroupsListPID.insert(std::make_pair(*GroupCount, PropertyValue));
338                 
339                 } else if (PropertyName == wxT("PREF")){
341                         int PriorityNumber = 0;
342                         bool ValidNumber = TRUE;
343                         
344                         try{
345                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
346                         }
347                         
348                         catch(std::invalid_argument &e){
349                                 ValidNumber = FALSE;
350                         }
352                         if (ValidNumber == TRUE){
354                                 GroupsListPref.erase(*GroupCount);
355                                 GroupsListPref.insert(std::make_pair(*GroupCount, PriorityNumber));
356                 
357                         }
358                 
359                 } else if (PropertyName == wxT("MEDIATYPE")){
361                         GroupsListMediaType.erase(*GroupCount);
362                         GroupsListMediaType.insert(std::make_pair(*GroupCount, PropertyValue));
363                 
364                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
365                         
366                         if (FirstToken == TRUE){
367                                 
368                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
369                                 FirstToken = FALSE;
370                                 
371                         } else {
372                         
373                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
374                                 
375                         }
376                         
377                 }
378                 
379         }
381         GroupsList.insert(std::make_pair(*GroupCount, PropertySeg2));
383         if (!PropertyTokens.IsEmpty()){
384         
385                 GroupsListTokens.insert(std::make_pair(*GroupCount, PropertyTokens));
386         
387         }
392 void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount){
394         std::map<int, int> SplitPoints;
395         std::map<int, int> SplitLength;
397         int intPrevValue = 4;
398         int intPref = 0;                        
399         int intType = 0;
400         
401         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
403         intPrevValue = 3;
404         
405         wxString PropertyName;
406         wxString PropertyValue;
407         wxString PropertyData;
408         wxString PropertyTokens;
409         std::map<int,int>::iterator SLiter;
410         bool FirstToken = TRUE;
411         
412         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
413         intiter != SplitPoints.end(); ++intiter){
414         
415                 SLiter = SplitLength.find(intiter->first);
416         
417                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
418                 
419                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
420                 PropertyName = PropertyElement.GetNextToken();                          
421                 PropertyValue = PropertyElement.GetNextToken();
422                 
423                 intPrevValue = intiter->second;
424                 
425                 CaptureString(&PropertyValue, FALSE);
426                 
427                 if (PropertyName == wxT("TYPE")){
429                         if (!PropertyValue.IsEmpty() || PropertyValue == wxT("home") ||
430                                 PropertyValue == wxT("work") ){
432                                 FullNamesListType.erase(*FNCount);
433                                 FullNamesListType.insert(std::make_pair(*FNCount, PropertyValue));
434                 
435                         }
436                 
437                 } else if (PropertyName == wxT("LANGUAGE")){
439                         FullNamesListLanguage.erase(*FNCount);
440                         FullNamesListLanguage.insert(std::make_pair(*FNCount, PropertyValue));
441                 
442                 } else if (PropertyName == wxT("ALTID")){
443                 
444                         FullNamesListAltID.erase(*FNCount);
445                         FullNamesListAltID.insert(std::make_pair(*FNCount, PropertyValue));
446                 
447                 } else if (PropertyName == wxT("PID")){
449                         FullNamesListPID.erase(*FNCount);
450                         FullNamesListPID.insert(std::make_pair(*FNCount, PropertyValue));
451                 
452                 } else if (PropertyName == wxT("PREF")){
454                         int PriorityNumber = 0;
455                         bool ValidNumber = TRUE;
456                         
457                         try{
458                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
459                         }
460                         
461                         catch(std::invalid_argument &e){
462                                 ValidNumber = FALSE;
463                         }
465                         if (ValidNumber == TRUE){
467                                 FullNamesListPref.erase(*FNCount);
468                                 FullNamesListPref.insert(std::make_pair(*FNCount, PriorityNumber));
470                         }
471                 
472                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
473                         
474                         if (FirstToken == TRUE){
475                                 
476                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
477                                 FirstToken = FALSE;
478                                 
479                         } else {
480                         
481                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
482                                 
483                         }
484                         
485                 } 
486         
487         }
489         FullNamesList.insert(std::make_pair(*FNCount, PropertySeg2));
491         if (!PropertyTokens.IsEmpty()){
492         
493                 FullNamesListTokens.insert(std::make_pair(*FNCount, PropertyTokens));
494         
495         }
499 void ContactDataObject::ProcessN(wxString PropertySeg1, wxString PropertySeg2){
501         std::map<int, int> SplitPoints;
502         std::map<int, int> SplitLength;
504         int intPrevValue = 3;
505         int intPref = 0;                        
506         int intType = 0;
507         
508         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
509         
510         intPrevValue = 2;
511         
512         wxString PropertyName;
513         wxString PropertyValue;
514         wxString PropertyData;
515         wxString PropertyTokens;
516         std::map<int,int>::iterator SLiter;
517         bool FirstToken = TRUE;
518         
519         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
520         intiter != SplitPoints.end(); ++intiter){
521         
522                 SLiter = SplitLength.find(intiter->first);
523         
524                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
525                 
526                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
527                 PropertyName = PropertyElement.GetNextToken();                          
528                 PropertyValue = PropertyElement.GetNextToken();
529                 
530                 intPrevValue = intiter->second;
531                 
532                 CaptureString(&PropertyValue, FALSE);
533                 
534                 if (PropertyName == wxT("ALTID")){
536                         NameAltID = PropertyValue;
537                 
538                 } else if (PropertyName == wxT("LANGUAGE")){
539                 
540                         NameLanguage = PropertyValue;
541                 
542                 } else if (PropertyName == wxT("SORT-AS")){
543                 
544                         if (PropertyValue.Left(1) == wxT("\"") && PropertyValue.Right(1) == wxT("\"") &&
545                                 PropertyValue.Len() >= 3){
546                                 NameDisplayAs = PropertyValue.Mid(1, (PropertyValue.Len() - 2));
547                         }
548                 
549                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
550                         
551                         if (FirstToken == TRUE){
552                                 
553                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
554                                 FirstToken = FALSE;
555                                 
556                         } else {
557                         
558                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
559                                 
560                         }
561                         
562                 }
563         
564         }
565         
566         // Split the name data.
567         
568         int intSplitSeek = 0;           
569         int intSplitsFound = 0;
570         int intSplitSize = 0;
571         int intPropertyLen = PropertySeg2.Len();
572         
573         std::map<int,wxString> NameValues;
574         intPrevValue = 0;                                       
575         
576         for (int i = 0; i <= intPropertyLen; i++){
577         
578                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
579                         
580                         NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, intSplitSize)));
581                         
582                         intSplitSeek = i;
583                         intSplitSeek++;
584                         
585                         if (intSplitsFound == 4){
586                         
587                                 NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, wxString::npos)));
588                                 break;
589                         
590                         }
591                         
592                         intSplitSize = 0;
593                         continue;
594         
595                 }
596                 
597                 intSplitSize++;
599         }
600         
601         // Split the data into several parts.
602                         
603         for (std::map<int, wxString>::iterator iter = NameValues.begin(); 
604         iter != NameValues.end(); ++iter){
605         
606                 if (iter->first == 1){
607                 
608                         // Deal with family name.
609                         
610                         NameSurname = iter->second;
611                 
612                 } else if (iter->first == 2){
613                 
614                         // Deal with given names.
615                         
616                         NameForename = iter->second;
617                 
618                 } else if (iter->first == 3){
619                 
620                         // Deal with additional names.
621                         
622                         NameOtherNames = iter->second;
623                 
624                 } else if (iter->first == 4){
625                 
626                         // Deal with honorifix prefixes and suffixes.
628                         NameTitle = iter->second;
629                 
630                         iter++;
631                         
632                         if (iter == NameValues.end()){
633                         
634                                 break;
635                         
636                         }
637                 
638                         NameSuffix = iter->second;
639                 
640                 }
641         
642         }
643         
644         // Add the name token data.
645         
646         if (!PropertyTokens.IsEmpty()){
647         
648                 NameTokens = PropertyTokens;
649         
650         }
654 void ContactDataObject::ProcessNickname(wxString PropertySeg1, wxString PropertySeg2, int *NicknameCount){
656         std::map<int, int> SplitPoints;
657         std::map<int, int> SplitLength;
659         int intPrevValue = 10;
660         int intPref = 0;                        
661         
662         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
663         
664         intPrevValue = 9;
665         
666         PropertyType PropType = PROPERTY_NONE;
667         
668         // Look for type before continuing.
669         
670         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
671         
672         intPrevValue = 9;
673         
674         std::map<int, wxString> *NicknamesList = NULL;
675         std::map<int, wxString> *NicknamesListType = NULL;
676         std::map<int, wxString> *NicknamesListLanguage = NULL;
677         std::map<int, wxString> *NicknamesListAltID = NULL;
678         std::map<int, wxString> *NicknamesListPID = NULL;
679         std::map<int, wxString> *NicknamesListTokens = NULL;            
680         std::map<int, int> *NicknamesListPref = NULL;
681         
682         switch(PropType){
683                 case PROPERTY_NONE:
684                         NicknamesList = &GeneralNicknamesList;
685                         NicknamesListType = &GeneralNicknamesListType;
686                         NicknamesListLanguage = &GeneralNicknamesListLanguage;
687                         NicknamesListAltID = &GeneralNicknamesListAltID;
688                         NicknamesListPID = &GeneralNicknamesListPID;
689                         NicknamesListTokens = &GeneralNicknamesListTokens;
690                         NicknamesListPref = &GeneralNicknamesListPref;
691                         break;
692                 case PROPERTY_HOME:
693                         NicknamesList = &HomeNicknamesList;
694                         NicknamesListType = &HomeNicknamesListType;
695                         NicknamesListLanguage = &HomeNicknamesListLanguage;
696                         NicknamesListAltID = &HomeNicknamesListAltID;
697                         NicknamesListPID = &HomeNicknamesListPID;
698                         NicknamesListTokens = &HomeNicknamesListTokens;
699                         NicknamesListPref = &HomeNicknamesListPref;
700                         break;
701                 case PROPERTY_WORK:
702                         NicknamesList = &BusinessNicknamesList;
703                         NicknamesListType = &BusinessNicknamesListType;
704                         NicknamesListLanguage = &BusinessNicknamesListLanguage;
705                         NicknamesListAltID = &BusinessNicknamesListAltID;
706                         NicknamesListPID = &BusinessNicknamesListPID;
707                         NicknamesListTokens = &BusinessNicknamesListTokens;
708                         NicknamesListPref = &BusinessNicknamesListPref;
709                         break;
710         }
711         
712         std::map<int, int>::iterator SLiter;    
713         wxString PropertyData;
714         wxString PropertyName;
715         wxString PropertyValue;
716         wxString PropertyTokens;
717         bool FirstToken = TRUE;
718         
719         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
720         intiter != SplitPoints.end(); ++intiter){
721         
722                 SLiter = SplitLength.find(intiter->first);
723         
724                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
725                 
726                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
727                 PropertyName = PropertyElement.GetNextToken();                          
728                 PropertyValue = PropertyElement.GetNextToken();
729                 
730                 intPrevValue = intiter->second;
731                 
732                 CaptureString(&PropertyValue, FALSE);
733                 
734                 if (PropertyName == wxT("ALTID")){
736                         NicknamesListAltID->erase(*NicknameCount);
737                         NicknamesListAltID->insert(std::make_pair(*NicknameCount, PropertyValue));
738                 
739                 } else if (PropertyName == wxT("PID")){
741                         NicknamesListPID->erase(*NicknameCount);
742                         NicknamesListPID->insert(std::make_pair(*NicknameCount, PropertyValue));        
744                 } else if (PropertyName == wxT("PREF")){
746                         int PriorityNumber = 0;
747                         bool ValidNumber = TRUE;
748                         
749                         try{
750                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
751                         }
752                         
753                         catch(std::invalid_argument &e){
754                                 ValidNumber = FALSE;
755                         }
757                         if (ValidNumber == TRUE){
759                                 NicknamesListPref->erase(*NicknameCount);
760                                 NicknamesListPref->insert(std::make_pair(*NicknameCount, PriorityNumber));
762                         }
763                 
764                 } else if (PropertyName == wxT("LANGUAGE")){
766                         NicknamesListLanguage->erase(*NicknameCount);
767                         NicknamesListLanguage->insert(std::make_pair(*NicknameCount, PropertyValue));   
769                 } else {
770                 
771                         // Something else we don't know about so append
772                         // to the tokens variable.
773                 
774                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
775                 
776                                 if (FirstToken == TRUE){
777                         
778                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
779                                         FirstToken = FALSE;
780                         
781                                 } else {
782                         
783                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
784                         
785                                 }
786                 
787                         }
788                 
789                 }
790                 
791         }
792         
793         NicknamesList->insert(std::make_pair(*NicknameCount, PropertySeg2));
794         
795         // Add the name token data.
796         
797         if (!PropertyTokens.IsEmpty()){
798         
799                 NicknamesListTokens->insert(std::make_pair(*NicknameCount, PropertyTokens));
800         
801         }
805 void ContactDataObject::ProcessGender(wxString PropertySeg1, wxString PropertySeg2){
807         std::map<int, int> SplitPoints;
808         std::map<int, int> SplitLength;
809         std::map<int, int>::iterator SLiter;                    
810         wxString PropertyData;
811         wxString PropertyName;
812         wxString PropertyValue;
813         wxString PropertyTokens;
814         bool FirstToken = TRUE;
815         int intPrevValue = 8;
817         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
819         intPrevValue = 7;                       
820         
821         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
822         intiter != SplitPoints.end(); ++intiter){
823         
824                 SLiter = SplitLength.find(intiter->first);
825         
826                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
827                 
828                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
829                 PropertyName = PropertyElement.GetNextToken();                          
830                 PropertyValue = PropertyElement.GetNextToken();
831                 
832                 intPrevValue = intiter->second;
833                 
834                 // Process properties.
835                 
836                 size_t intPropertyValueLen = PropertyValue.Len();
837                 
838                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
839                         
840                         PropertyValue.Trim();
841                         PropertyValue.RemoveLast();
842                         
843                 }                               
844                 
845                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
846                         
847                         PropertyValue.Remove(0, 1);
848                         
849                 }                               
850                 
851                 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
853                         if (FirstToken == TRUE){
854         
855                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
856                                 FirstToken = FALSE;
857         
858                         } else {
859         
860                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
861         
862                         }
864                 }
865         
866         }       
868         wxStringTokenizer GenderData (PropertySeg2, wxT(";"));
869         
870         wxString GenderComponent;
871         
872         if (GenderData.CountTokens() >= 2){
873         
874                 Gender = GenderData.GetNextToken();
875                 GenderDetails = GenderData.GetString();
876         
877                 CaptureString(&GenderDetails, FALSE);
878                                                 
879         } else {
880         
881                 Gender = GenderData.GetNextToken();
882         
883         }
884         
885         if (!PropertyTokens.IsEmpty()){
886         
887                 GenderTokens = PropertyTokens;
888         
889         }
893 void ContactDataObject::ProcessBirthday(wxString PropertySeg1, wxString PropertySeg2){
895         // Process date. Preserve the remainder in the string.
897         std::map<int, int> SplitPoints;
898         std::map<int, int> SplitLength;
899         std::map<int, int>::iterator SLiter;                    
900         wxString PropertyData;
901         wxString PropertyName;
902         wxString PropertyValue;
903         wxString PropertyTokens;
904         bool BirthdayText = FALSE;
905         int intPrevValue = 6;
907         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
909         intPrevValue = 5;
911         // Look for type before continuing.
913         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
914         intiter != SplitPoints.end(); ++intiter){
916                 SLiter = SplitLength.find(intiter->first);
918                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
919         
920                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
921                 PropertyName = PropertyElement.GetNextToken();                          
922                 PropertyValue = PropertyElement.GetNextToken();
923         
924                 intPrevValue = intiter->second;
925         
926                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){
927         
928                         CaptureString(&PropertySeg2, FALSE);
929                         Birthday = PropertySeg2;
930                         BirthdayText = TRUE;
931         
932                 }
934         }
936         // Setup blank lines for later on.
937         
938         intPrevValue = 5;
939         bool FirstToken = TRUE;
941         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
942         intiter != SplitPoints.end(); ++intiter){
944                 SLiter = SplitLength.find(intiter->first);
946                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
947         
948                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
949                 PropertyName = PropertyElement.GetNextToken();                          
950                 PropertyValue = PropertyElement.GetNextToken();
951         
952                 intPrevValue = intiter->second;
953         
954                 // Process properties.
955         
956                 CaptureString(&PropertyValue, FALSE);
957         
958                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
959                 
960                         PropertyValue.Trim();
961                         PropertyValue.RemoveLast();
962                 
963                 }                               
964         
965                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
966                 
967                         PropertyValue.Remove(0, 1);
968                 
969                 }                               
970         
971                 if (PropertyName == wxT("ALTID")){
973                         BirthdayAltID = PropertyValue;
974         
975                 } else if (PropertyName == wxT("CALSCALE")){
976         
977                         BirthdayCalScale = PropertyValue;
978         
979                 } else if (PropertyName != wxT("VALUE")) {
980         
981                         // Something else we don't know about so append
982                         // to the tokens variable.
983                 
984                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
985                 
986                                 if (FirstToken == TRUE){
987         
988                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
989                                         FirstToken = FALSE;
990         
991                                 } else {
992         
993                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
994         
995                                 }
996                                 
997                         }
998                         
999                 }
1001         }       
1003         // Add the data to the variables and form.
1004         
1005         if (BirthdayText == FALSE){
1006         
1007                 Birthday = PropertySeg2;
1009         }
1010         
1011         if (!PropertyTokens.IsEmpty()){
1012         
1013                 BirthdayTokens = PropertyTokens;
1015         }
1019 void ContactDataObject::ProcessAnniversary(wxString PropertySeg1, wxString PropertySeg2){
1021         // Process date. Preserve the remainder in the string.
1023         std::map<int, int> SplitPoints;
1024         std::map<int, int> SplitLength;
1025         std::map<int, int>::iterator SLiter;                    
1026         wxString PropertyData;
1027         wxString PropertyName;
1028         wxString PropertyValue;
1029         wxString PropertyTokens;
1030         bool AnniversaryText = FALSE;
1031         int intPrevValue = 13;
1033         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1035         intPrevValue = 12;
1037         // Look for type before continuing.
1039         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1040         intiter != SplitPoints.end(); ++intiter){
1042                 SLiter = SplitLength.find(intiter->first);
1044                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1045         
1046                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1047                 PropertyName = PropertyElement.GetNextToken();                          
1048                 PropertyValue = PropertyElement.GetNextToken();
1049         
1050                 intPrevValue = intiter->second;
1051         
1052                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){
1053         
1054                         CaptureString(&PropertySeg2, FALSE);
1055                         Anniversary = PropertySeg2;
1056                         AnniversaryText = TRUE;
1057         
1058                 }
1060         }
1062         // Setup blank lines for later on.
1063         
1064         intPrevValue = 12;
1065         bool FirstToken = TRUE;
1067         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1068         intiter != SplitPoints.end(); ++intiter){
1070                 SLiter = SplitLength.find(intiter->first);
1072                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1073         
1074                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1075                 PropertyName = PropertyElement.GetNextToken();                          
1076                 PropertyValue = PropertyElement.GetNextToken();
1077         
1078                 intPrevValue = intiter->second;
1079         
1080                 // Process properties.
1081         
1082                 CaptureString(&PropertyValue, FALSE);
1083         
1084                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
1085                 
1086                         PropertyValue.Trim();
1087                         PropertyValue.RemoveLast();
1088                 
1089                 }                               
1090         
1091                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
1092                 
1093                         PropertyValue.Remove(0, 1);
1094                 
1095                 }                               
1096         
1097                 if (PropertyName == wxT("ALTID")){
1099                         AnniversaryAltID = PropertyValue;
1100         
1101                 } else if (PropertyName == wxT("CALSCALE")){
1102         
1103                         AnniversaryCalScale = PropertyValue;
1104         
1105                 } else if (PropertyName != wxT("VALUE")) {
1106         
1107                         // Something else we don't know about so append
1108                         // to the tokens variable.
1109                 
1110                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
1111                 
1112                                 if (FirstToken == TRUE){
1113         
1114                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1115                                         FirstToken = FALSE;
1116         
1117                                 } else {
1118         
1119                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1120         
1121                                 }
1122                                 
1123                         }
1124                         
1125                 }
1127         }       
1129         // Add the data to the variables and form.
1130         
1131         if (AnniversaryText == FALSE){
1132         
1133                 Anniversary = PropertySeg2;
1135         }
1136         
1137         if (!PropertyTokens.IsEmpty()){
1138         
1139                 AnniversaryTokens = PropertyTokens;
1141         }
1145 void ContactDataObject::ProcessTimeZone(wxString PropertySeg1, wxString PropertySeg2, int *TimeZoneCount){
1147         std::map<int, int> SplitPoints;
1148         std::map<int, int> SplitLength;
1150         int intPrevValue = 4;
1151         int intPref = 0;                        
1152         
1153         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1154         
1155         intPrevValue = 3;
1156         
1157         PropertyType PropType = PROPERTY_NONE;
1158         
1159         // Look for type before continuing.
1160         
1161         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1162         
1163         intPrevValue = 3;
1164         
1165         std::map<int, wxString> *TZList = NULL;
1166         std::map<int, wxString> *TZListType = NULL;
1167         std::map<int, wxString> *TZListMediatype = NULL;
1168         std::map<int, wxString> *TZListAltID = NULL;
1169         std::map<int, wxString> *TZListPID = NULL;
1170         std::map<int, wxString> *TZListTokens = NULL;           
1171         std::map<int, int> *TZListPref = NULL;
1172         
1173         switch(PropType){
1174                 case PROPERTY_NONE:
1175                         TZList = &GeneralTZList;
1176                         TZListType = &GeneralTZListType;
1177                         TZListMediatype = &GeneralTZListMediatype;
1178                         TZListAltID = &GeneralTZListAltID;
1179                         TZListPID = &GeneralTZListPID;
1180                         TZListTokens = &GeneralTZListTokens;
1181                         TZListPref = &GeneralTZListPref;
1182                         break;
1183                 case PROPERTY_HOME:
1184                         TZList = &HomeTZList;
1185                         TZListType = &HomeTZListType;
1186                         TZListMediatype = &HomeTZListMediatype;
1187                         TZListAltID = &HomeTZListAltID;
1188                         TZListPID = &HomeTZListPID;
1189                         TZListTokens = &HomeTZListTokens;
1190                         TZListPref = &HomeTZListPref;
1191                         break;
1192                 case PROPERTY_WORK:
1193                         TZList = &BusinessTZList;
1194                         TZListType = &BusinessTZListType;
1195                         TZListMediatype = &BusinessTZListMediatype;
1196                         TZListAltID = &BusinessTZListAltID;
1197                         TZListPID = &BusinessTZListPID;
1198                         TZListTokens = &BusinessTZListTokens;
1199                         TZListPref = &BusinessTZListPref;
1200                         break;
1201         }
1202         
1203         std::map<int, int>::iterator SLiter;    
1204         wxString PropertyData;
1205         wxString PropertyName;
1206         wxString PropertyValue;
1207         wxString PropertyTokens;
1208         bool FirstToken = TRUE;
1209         
1210         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1211         intiter != SplitPoints.end(); ++intiter){
1212         
1213                 SLiter = SplitLength.find(intiter->first);
1214         
1215                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1216                 
1217                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1218                 PropertyName = PropertyElement.GetNextToken();                          
1219                 PropertyValue = PropertyElement.GetNextToken();
1220                 
1221                 intPrevValue = intiter->second;
1222                 
1223                 CaptureString(&PropertyValue, FALSE);
1225                 if (PropertyName == wxT("ALTID")){
1227                         TZListAltID->erase(*TimeZoneCount);
1228                         TZListAltID->insert(std::make_pair(*TimeZoneCount, PropertyValue));
1229                 
1230                 } else if (PropertyName == wxT("PID")){
1232                         TZListPID->erase(*TimeZoneCount);
1233                         TZListPID->insert(std::make_pair(*TimeZoneCount, PropertyValue));       
1235                 } else if (PropertyName == wxT("PREF")){
1237                         int PriorityNumber = 0;
1238                         bool ValidNumber = TRUE;
1239                         
1240                         try{
1241                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1242                         }
1243                         
1244                         catch(std::invalid_argument &e){
1245                                 ValidNumber = FALSE;
1246                         }
1248                         if (ValidNumber == TRUE){
1250                                 TZListPref->erase(*TimeZoneCount);
1251                                 TZListPref->insert(std::make_pair(*TimeZoneCount, PriorityNumber));
1253                         }
1254                 
1255                 } else if (PropertyName == wxT("MEDIATYPE")){
1257                         TZListMediatype->erase(*TimeZoneCount);
1258                         TZListMediatype->insert(std::make_pair(*TimeZoneCount, PropertyValue)); 
1260                 } else {
1261                 
1262                         // Something else we don't know about so append
1263                         // to the tokens variable.
1264                 
1265                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1266                 
1267                                 if (FirstToken == TRUE){
1268                         
1269                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1270                                         FirstToken = FALSE;
1271                         
1272                                 } else {
1273                         
1274                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1275                         
1276                                 }
1277                 
1278                         }
1279                 
1280                 }
1281                 
1282         }
1283         
1284         TZList->insert(std::make_pair(*TimeZoneCount, PropertySeg2));
1285         
1286         // Add the name token data.
1287         
1288         if (!PropertyTokens.IsEmpty()){
1289         
1290                 TZListTokens->insert(std::make_pair(*TimeZoneCount, PropertyTokens));
1291         
1292         }
1297 void ContactDataObject::ProcessAddress(wxString PropertySeg1, wxString PropertySeg2, int *AddressCount){
1299         size_t intPropertyLen = PropertySeg1.Len();
1300         std::map<int, int> SplitPoints;
1301         std::map<int, int> SplitLength;
1302         std::map<int, int>::iterator SLiter;                    
1303         wxString PropertyData;
1304         wxString PropertyName;
1305         wxString PropertyValue;
1306         wxString PropertyTokens;
1307         wxString AddressLabel;
1308         wxString AddressLang;
1309         wxString AddressAltID;
1310         wxString AddressPID;
1311         wxString AddressTokens;
1312         wxString AddressGeo;
1313         wxString AddressTimezone;
1314         wxString AddressType;
1315         wxString AddressMediatype;
1316         wxString AddressPOBox;
1317         wxString AddressExtended;
1318         wxString AddressStreet;
1319         wxString AddressLocality;
1320         wxString AddressCity;
1321         wxString AddressRegion;
1322         wxString AddressPostalCode;
1323         wxString AddressCountry;
1324         bool FirstToken = TRUE;                 
1325         int intSplitsFound = 0;
1326         int intSplitSize = 0;
1327         int intPrevValue = 5;
1328         int intPref = 0;                        
1329         int intType = 0;
1330         long ListCtrlIndex;
1331         
1332         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1333         
1334         intPrevValue = 4;
1335         
1336         PropertyType PropType = PROPERTY_NONE;
1337                 
1338         // Look for type before continuing.
1339         
1340         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1341         
1342         intPrevValue = 4;
1343         
1344         std::map<int, wxString> *AddressList = NULL;
1345         std::map<int, wxString> *AddressListTown = NULL;
1346         std::map<int, wxString> *AddressListCounty = NULL;
1347         std::map<int, wxString> *AddressListPostCode = NULL;
1348         std::map<int, wxString> *AddressListCountry = NULL;
1349         std::map<int, wxString> *AddressListLabel = NULL;
1350         std::map<int, wxString> *AddressListLang = NULL;                
1351         std::map<int, wxString> *AddressListAltID = NULL;
1352         std::map<int, wxString> *AddressListPID = NULL;
1353         std::map<int, wxString> *AddressListTokens = NULL;
1354         std::map<int, wxString> *AddressListGeo = NULL;
1355         std::map<int, wxString> *AddressListTimezone = NULL;            
1356         std::map<int, wxString> *AddressListType = NULL;
1357         std::map<int, wxString> *AddressListMediatype = NULL;
1358         std::map<int, int> *AddressListPref = NULL;
1360         switch(PropType){
1361                 case PROPERTY_NONE:
1362                         AddressList = &GeneralAddressList;
1363                         AddressListTown = &GeneralAddressListTown;
1364                         AddressListCounty = &GeneralAddressListCounty;
1365                         AddressListPostCode = &GeneralAddressListPostCode;
1366                         AddressListCountry = &GeneralAddressListCountry;
1367                         AddressListLabel = &GeneralAddressListLabel;
1368                         AddressListLang = &GeneralAddressListLang;              
1369                         AddressListAltID = &GeneralAddressListAltID;
1370                         AddressListPID = &GeneralAddressListPID;
1371                         AddressListTokens = &GeneralAddressListTokens;
1372                         AddressListGeo = &GeneralAddressListGeo;
1373                         AddressListTimezone = &GeneralAddressListTimezone;
1374                         AddressListType = &GeneralAddressListType;
1375                         AddressListMediatype = &GeneralAddressListMediatype;
1376                         AddressListPref = &GeneralAddressListPref;              
1377                         break;
1378                 case PROPERTY_HOME:
1379                         AddressList = &HomeAddressList;
1380                         AddressListTown = &HomeAddressListTown;
1381                         AddressListCounty = &HomeAddressListCounty;
1382                         AddressListPostCode = &HomeAddressListPostCode;
1383                         AddressListCountry = &HomeAddressListCountry;
1384                         AddressListLabel = &HomeAddressListLabel;
1385                         AddressListLang = &HomeAddressListLang;         
1386                         AddressListAltID = &HomeAddressListAltID;
1387                         AddressListPID = &HomeAddressListPID;
1388                         AddressListTokens = &HomeAddressListTokens;
1389                         AddressListGeo = &HomeAddressListGeo;
1390                         AddressListTimezone = &HomeAddressListTimezone;
1391                         AddressListType = &HomeAddressListType;
1392                         AddressListMediatype = &HomeAddressListMediatype;
1393                         AddressListPref = &HomeAddressListPref;
1394                         break;
1395                 case PROPERTY_WORK:
1396                         AddressList = &BusinessAddressList;
1397                         AddressListTown = &BusinessAddressListTown;
1398                         AddressListCounty = &BusinessAddressListCounty;
1399                         AddressListPostCode = &BusinessAddressListPostCode;
1400                         AddressListCountry = &BusinessAddressListCountry;
1401                         AddressListLabel = &BusinessAddressListLabel;
1402                         AddressListLang = &BusinessAddressListLang;             
1403                         AddressListAltID = &BusinessAddressListAltID;
1404                         AddressListPID = &BusinessAddressListPID;
1405                         AddressListTokens = &BusinessAddressListTokens;
1406                         AddressListGeo = &BusinessAddressListGeo;
1407                         AddressListTimezone = &BusinessAddressListTimezone;
1408                         AddressListType = &BusinessAddressListType;
1409                         AddressListMediatype = &BusinessAddressListMediatype;
1410                         AddressListPref = &BusinessAddressListPref;
1411                         break;
1412         }
1413         
1414         intPrevValue = 4;
1415         
1416         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1417         intiter != SplitPoints.end(); ++intiter){
1418         
1419                 SLiter = SplitLength.find(intiter->first);
1420         
1421                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1422                 
1423                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1424                 PropertyName = PropertyElement.GetNextToken();                          
1425                 PropertyValue = PropertyElement.GetNextToken();
1426                 
1427                 intPrevValue = intiter->second;
1428                 
1429                 CaptureString(&PropertyValue, FALSE);
1430                 
1431                 // Process properties.
1432                 
1433                 if (PropertyName == wxT("LABEL")){
1434                 
1435                         AddressListLabel->erase(*AddressCount);
1436                         AddressListLabel->insert(std::make_pair(*AddressCount, PropertyValue));
1437                                 
1438                 } else if (PropertyName == wxT("LANGUAGE")){
1439                 
1440                         AddressListLang->erase(*AddressCount);
1441                         AddressListLang->insert(std::make_pair(*AddressCount, PropertyValue));                  
1442                 
1443                 } else if (PropertyName == wxT("ALTID")){
1445                         AddressListAltID->erase(*AddressCount);
1446                         AddressListAltID->insert(std::make_pair(*AddressCount, PropertyValue));
1447                 
1448                 } else if (PropertyName == wxT("PID")){
1450                         AddressListPID->erase(*AddressCount);
1451                         AddressListPID->insert(std::make_pair(*AddressCount, PropertyValue));
1452                 
1453                 } else if (PropertyName == wxT("GEO")){
1454                 
1455                         AddressListGeo->erase(*AddressCount);
1456                         AddressListGeo->insert(std::make_pair(*AddressCount, PropertyValue));
1457                 
1458                 } else if (PropertyName == wxT("TZ")){
1460                         AddressListTimezone->erase(*AddressCount);
1461                         AddressListTimezone->insert(std::make_pair(*AddressCount, PropertyValue));
1462                 
1463                 } else if (PropertyName == wxT("MEDIATYPE")){
1465                         AddressListMediatype->erase(*AddressCount);
1466                         AddressListMediatype->insert(std::make_pair(*AddressCount, PropertyValue));
1467                 
1468                 } else if (PropertyName == wxT("PREF")){
1469                         
1470                         int PriorityNumber = 0;
1471                         bool ValidNumber = TRUE;
1472                         
1473                         try{
1474                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1475                         }
1476                         
1477                         catch(std::invalid_argument &e){
1478                                 ValidNumber = FALSE;
1479                         }
1481                         if (ValidNumber == TRUE){
1483                                 AddressListPref->erase(*AddressCount);
1484                                 AddressListPref->insert(std::make_pair(*AddressCount, PriorityNumber));
1486                         }
1487                 
1488                 } else {
1489                 
1490                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1491                         
1492                                 if (FirstToken == TRUE){
1493                                 
1494                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1495                                         FirstToken = FALSE;
1496                                 
1497                                 } else {
1498                                 
1499                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1500                                 
1501                                 }
1502                         
1503                         }
1504                 
1505                 }
1506         
1507         }                       
1508         
1509         // Split the address. 
1511         //std::map<int, int>::iterator SLiter;
1512         intPropertyLen = PropertySeg2.Len();
1513         SplitPoints.clear();
1514         SplitLength.clear();
1515         intSplitsFound = 0;
1516         intSplitSize = 0;
1517         intPrevValue = 0;
1518         
1519         for (int i = 0; i <= intPropertyLen; i++){
1521                 intSplitSize++;
1522         
1523                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
1524         
1525                         intSplitsFound++;
1526                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
1527                         
1528                         if (intSplitsFound == 6){ 
1529                         
1530                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1531                                 break; 
1532                                 
1533                         } else {
1534                         
1535                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1536                         
1537                         }
1538                         
1539                         intSplitSize = 0;                                       
1540         
1541                 }
1543         }
1544         
1545         // Split the data into several parts.                   
1546         
1547         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1548         intiter != SplitPoints.end(); ++intiter){
1549                         
1550                 if (intiter->first == 1){
1551                 
1552                         // Deal with PO Box.
1553                         
1554                         SLiter = SplitLength.find(1);
1555                                                                 
1556                         //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
1557                         AddressPOBox = PropertySeg2.Mid(0, SLiter->second);
1558                         intPrevValue = intiter->second;
1559                 
1560                 } else if (intiter->first == 2){
1561                 
1562                         // Deal with extended address.
1563                         
1564                         SLiter = SplitLength.find(2);
1565                         
1566                         AddressExtended = PropertySeg2.Mid(intPrevValue, SLiter->second);
1567                         //txtForename->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1568                         intPrevValue = intiter->second;
1569                 
1570                 } else if (intiter->first == 3){
1571                 
1572                         // Deal with street address.
1573                         
1574                         SLiter = SplitLength.find(3);
1575                                                                 
1576                         AddressStreet = PropertySeg2.Mid(intPrevValue, SLiter->second);
1577                         //txtOtherNames->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1578                         intPrevValue = intiter->second;
1579                 
1580                 } else if (intiter->first == 4){
1581                 
1582                         // Deal with locality
1584                         SLiter = SplitLength.find(4);
1585                         
1586                         AddressLocality = PropertySeg2.Mid(intPrevValue, SLiter->second);
1587                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1588                         intPrevValue = intiter->second;
1589                         
1590                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1591                 
1592                 } else if (intiter->first == 5){
1593                 
1594                         // Deal with region.
1596                         SLiter = SplitLength.find(5);
1597                         
1598                         AddressRegion = PropertySeg2.Mid(intPrevValue, SLiter->second);
1599                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1600                         intPrevValue = intiter->second;
1601                         
1602                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1603                 
1604                 } else if (intiter->first == 6){
1605                 
1606                         // Deal with post code.
1608                         SLiter = SplitLength.find(6);
1609                         
1610                         AddressPostalCode = PropertySeg2.Mid(intPrevValue, SLiter->second);
1611                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1612                         intPrevValue = intiter->second;
1613                         
1614                         // Deal with country.
1615                                                 
1616                         AddressCountry = PropertySeg2.Mid(intPrevValue, wxString::npos);
1617                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1618                         
1619                         break;
1620                 
1621                 }
1622         
1623         }       
1624         
1625         // Add the data to the General/Home/Work address variables.
1626         
1627         CaptureString(&AddressStreet, FALSE); 
1628         CaptureString(&AddressLocality, FALSE);
1629         CaptureString(&AddressRegion, FALSE);
1630         CaptureString(&AddressPostalCode, FALSE);
1631         CaptureString(&AddressCountry, FALSE);
1632                 
1633         if (!PropertyTokens.IsEmpty()){
1634         
1635                 AddressListTokens->insert(std::make_pair(*AddressCount, PropertyTokens));
1636         
1637         }
1639         AddressListCountry->insert(std::make_pair(*AddressCount, AddressCountry));      
1640         AddressList->insert(std::make_pair(*AddressCount, AddressStreet));
1641         AddressListTown->insert(std::make_pair(*AddressCount, AddressLocality));
1642         AddressListCounty->insert(std::make_pair(*AddressCount, AddressRegion));
1643         AddressListPostCode->insert(std::make_pair(*AddressCount, AddressPostalCode));
1645         switch(PropType){
1646                 case PROPERTY_NONE:
1647                         AddressListType->insert(std::make_pair(*AddressCount, wxT("")));
1648                         break;
1649                 case PROPERTY_HOME:
1650                         AddressListType->insert(std::make_pair(*AddressCount, wxT("home")));
1651                         break;
1652                 case PROPERTY_WORK:
1653                         AddressListType->insert(std::make_pair(*AddressCount, wxT("work")));    
1654                         break;
1655         }
1656         
1657         AddressListTokens->insert(std::make_pair(*AddressCount, PropertyTokens));
1661 void ContactDataObject::ProcessEmail(wxString PropertySeg1, wxString PropertySeg2, int *EmailCount){
1663         std::map<int, int> SplitPoints;
1664         std::map<int, int> SplitLength;
1666         int intPrevValue = 7;
1667         int intPref = 0;                        
1668         
1669         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1670         
1671         intPrevValue = 6;
1672         
1673         PropertyType PropType = PROPERTY_NONE;
1674                 
1675         // Look for type before continuing.
1676         
1677         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1678         
1679         std::map<int, wxString> *EmailList = NULL;
1680         std::map<int, wxString> *EmailListType = NULL;
1681         std::map<int, wxString> *EmailListAltID = NULL;
1682         std::map<int, wxString> *EmailListPID = NULL;
1683         std::map<int, wxString> *EmailListTokens = NULL;                
1684         std::map<int, int> *EmailListPref = NULL;
1686         switch(PropType){
1687                 case PROPERTY_NONE:
1688                         EmailList = &GeneralEmailList;
1689                         EmailListType = &GeneralEmailListType;
1690                         EmailListAltID = &GeneralEmailListAltID;
1691                         EmailListPID = &GeneralEmailListPID;
1692                         EmailListTokens = &GeneralEmailListTokens;              
1693                         EmailListPref = &GeneralEmailListPref;  
1694                         break;
1695                 case PROPERTY_HOME:
1696                         EmailList = &HomeEmailList;
1697                         EmailListType = &HomeEmailListType;
1698                         EmailListAltID = &HomeEmailListAltID;
1699                         EmailListPID = &HomeEmailListPID;
1700                         EmailListTokens = &HomeEmailListTokens;         
1701                         EmailListPref = &HomeEmailListPref;     
1702                         break;
1703                 case PROPERTY_WORK:
1704                         EmailList = &BusinessEmailList;
1705                         EmailListType = &BusinessEmailListType;
1706                         EmailListAltID = &BusinessEmailListAltID;
1707                         EmailListPID = &BusinessEmailListPID;
1708                         EmailListTokens = &BusinessEmailListTokens;             
1709                         EmailListPref = &BusinessEmailListPref; 
1710                         break;
1711         }
1712         
1713         intPrevValue = 6;
1714         
1715         std::map<int,int>::iterator SLiter;
1716         wxString PropertyData;
1717         wxString PropertyName;
1718         wxString PropertyValue;
1719         wxString PropertyTokens;
1720         bool FirstToken = TRUE;
1721         
1722         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1723         intiter != SplitPoints.end(); ++intiter){
1724         
1725                 SLiter = SplitLength.find(intiter->first);
1726         
1727                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1728                 
1729                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1730                 PropertyName = PropertyElement.GetNextToken();                          
1731                 PropertyValue = PropertyElement.GetNextToken();
1732                 
1733                 intPrevValue = intiter->second;
1734                 
1735                 CaptureString(&PropertyValue, FALSE);
1736                 
1737                 // Process properties.
1738                 
1739                 if (PropertyName == wxT("ALTID")){
1741                         EmailListAltID->erase(*EmailCount);
1742                         EmailListAltID->insert(std::make_pair(*EmailCount, PropertyValue));
1743                 
1744                 } else if (PropertyName == wxT("PID")){
1746                         EmailListPID->erase(*EmailCount);
1747                         EmailListPID->insert(std::make_pair(*EmailCount, PropertyValue));
1748                 
1749                 } else if (PropertyName == wxT("PREF")){
1750                         
1751                         int PriorityNumber = 0;
1752                         bool ValidNumber = TRUE;
1753                         
1754                         try{
1755                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1756                         }
1757                         
1758                         catch(std::invalid_argument &e){
1759                                 ValidNumber = FALSE;
1760                         }
1762                         if (ValidNumber == TRUE){
1764                                 EmailListPref->erase(*EmailCount);
1765                                 EmailListPref->insert(std::make_pair(*EmailCount, PriorityNumber));
1767                         }
1768                 
1769                 } else {
1770                 
1771                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1772                         
1773                                 if (FirstToken == TRUE){
1774                                 
1775                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1776                                         FirstToken = FALSE;
1777                                 
1778                                 } else {
1779                                 
1780                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1781                                 
1782                                 }
1783                         
1784                         }
1785                 
1786                 }
1787         
1788         }
1789         
1790         EmailList->insert(std::make_pair(*EmailCount, PropertySeg2));
1791         
1792         // Add the name token data.
1793         
1794         if (!PropertyTokens.IsEmpty()){
1795         
1796                 EmailListTokens->insert(std::make_pair(*EmailCount, PropertyTokens));
1797         
1798         }       
1803 void ContactDataObject::ProcessIM(wxString PropertySeg1, wxString PropertySeg2, int *IMCount){
1805         std::map<int, int> SplitPoints;
1806         std::map<int, int> SplitLength;
1808         int intPrevValue = 6;
1809         int intPref = 0;                        
1810         
1811         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1812         
1813         intPrevValue = 5;
1814         
1815         PropertyType PropType = PROPERTY_NONE;
1816                 
1817         // Look for type before continuing.
1818         
1819         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1820         
1821         std::map<int, wxString> *IMList = NULL;
1822         std::map<int, wxString> *IMListType = NULL;
1823         std::map<int, wxString> *IMListAltID = NULL;
1824         std::map<int, wxString> *IMListPID = NULL;
1825         std::map<int, wxString> *IMListTokens = NULL;
1826         std::map<int, wxString> *IMListMediatype = NULL;        
1827         std::map<int, int> *IMListPref = NULL;
1829         switch(PropType){
1830                 case PROPERTY_NONE:
1831                         IMList = &GeneralIMList;
1832                         IMListType = &GeneralIMListType;
1833                         IMListAltID = &GeneralIMListAltID;
1834                         IMListPID = &GeneralIMListPID;
1835                         IMListTokens = &GeneralIMListTokens;
1836                         IMListMediatype = &GeneralIMListMediatype;
1837                         IMListPref = &GeneralIMListPref;        
1838                         break;
1839                 case PROPERTY_HOME:
1840                         IMList = &HomeIMList;
1841                         IMListType = &HomeIMListType;
1842                         IMListAltID = &HomeIMListAltID;
1843                         IMListPID = &HomeIMListPID;
1844                         IMListTokens = &HomeIMListTokens;
1845                         IMListMediatype = &HomeIMListMediatype;         
1846                         IMListPref = &HomeIMListPref;   
1847                         break;
1848                 case PROPERTY_WORK:
1849                         IMList = &BusinessIMList;
1850                         IMListType = &BusinessIMListType;
1851                         IMListAltID = &BusinessIMListAltID;
1852                         IMListPID = &BusinessIMListPID;
1853                         IMListTokens = &BusinessIMListTokens;   
1854                         IMListMediatype = &BusinessIMListMediatype;     
1855                         IMListPref = &BusinessIMListPref;       
1856                         break;
1857         }
1858         
1859         intPrevValue = 5;
1860         
1861         std::map<int,int>::iterator SLiter;
1862         wxString PropertyData;
1863         wxString PropertyName;
1864         wxString PropertyValue;
1865         wxString PropertyTokens;
1866         bool FirstToken = TRUE;
1867         
1868         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1869         intiter != SplitPoints.end(); ++intiter){
1870         
1871                 SLiter = SplitLength.find(intiter->first);
1872         
1873                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1874                 
1875                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1876                 PropertyName = PropertyElement.GetNextToken();                          
1877                 PropertyValue = PropertyElement.GetNextToken();
1878                 
1879                 intPrevValue = intiter->second;
1880                 
1881                 CaptureString(&PropertyValue, FALSE);
1882                 
1883                 // Process properties.
1884                 
1885                 if (PropertyName == wxT("ALTID")){
1887                         IMListAltID->erase(*IMCount);
1888                         IMListAltID->insert(std::make_pair(*IMCount, PropertyValue));
1889                 
1890                 } else if (PropertyName == wxT("PID")){
1892                         IMListPID->erase(*IMCount);
1893                         IMListPID->insert(std::make_pair(*IMCount, PropertyValue));
1894                 
1895                 } else if (PropertyName == wxT("MEDIATYPE")){
1897                         IMListMediatype->erase(*IMCount);
1898                         IMListMediatype->insert(std::make_pair(*IMCount, PropertyValue));
1899                 
1900                 } else if (PropertyName == wxT("PREF")){
1901                         
1902                         int PriorityNumber = 0;
1903                         bool ValidNumber = TRUE;
1904                         
1905                         try{
1906                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1907                         }
1908                         
1909                         catch(std::invalid_argument &e){
1910                                 ValidNumber = FALSE;
1911                         }
1913                         if (ValidNumber == TRUE){
1915                                 IMListPref->erase(*IMCount);
1916                                 IMListPref->insert(std::make_pair(*IMCount, PriorityNumber));
1918                         }
1919                 
1920                 } else {
1921                 
1922                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1923                         
1924                                 if (FirstToken == TRUE){
1925                                 
1926                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1927                                         FirstToken = FALSE;
1928                                 
1929                                 } else {
1930                                 
1931                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1932                                 
1933                                 }
1934                         
1935                         }
1936                 
1937                 }
1938         
1939         }
1940                 
1941         IMList->insert(std::make_pair(*IMCount, PropertySeg2));
1942         
1943         // Add the name token data.
1944         
1945         if (!PropertyTokens.IsEmpty()){
1946         
1947                 IMListTokens->insert(std::make_pair(*IMCount, PropertyTokens));
1948         
1949         }
1953 void ContactDataObject::ProcessTelephone(wxString PropertySeg1, wxString PropertySeg2, int *TelephoneCount){
1955         std::map<int, int> SplitPoints;
1956         std::map<int, int> SplitLength;
1957         std::map<int, int>::iterator SLiter;
1958         
1959         int intPref = 0;
1960         
1961         PropertyType PropType = PROPERTY_NONE;
1962                 
1963         // Look for type before continuing.
1964         
1965         wxString TelTypeUI;
1966         wxString TelTypeDetail;
1967         wxString PropertyData;
1968         wxString PropertyName;
1969         wxString PropertyValue;
1970         wxString PropertyTokens;
1971         
1972         std::map<int,int> TypeSplitPoints;
1973         std::map<int,int> TypeSplitLength;
1974         std::map<int,int>::iterator TSLiter;
1975         
1976         int intSplitSize = 0;
1977         int intSplitsFound = 0;
1978         int intSplitPoint = 0;
1979         int intType = 0;
1980         int intPrevValue = 5;
1981                 
1982         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1983         
1984         intPrevValue = 4;
1985         
1986         // Look for type before continuing.
1987         
1988         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1989         intiter != SplitPoints.end(); ++intiter){
1990         
1991                 SLiter = SplitLength.find(intiter->first);
1992         
1993                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1994                 
1995                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1996                 PropertyName = PropertyElement.GetNextToken();                          
1997                 PropertyValue = PropertyElement.GetNextToken();
1998                 
1999                 intPrevValue = intiter->second;
2001                 if (PropertyName == wxT("TYPE")){
2002                 
2003                         // Process each value in type and translate each
2004                         // part.
2005                 
2006                         // Strip out the quotes if they are there.
2007                 
2008                         size_t intPropertyValueLen = PropertyValue.Len();
2009                 
2010                         if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
2011                         
2012                                 PropertyValue.Trim();
2013                                 PropertyValue.RemoveLast();
2014                         
2015                         }                               
2016                 
2017                         if (PropertyValue.Mid(0, 1) == wxT("\"")){
2018                         
2019                                 PropertyValue.Remove(0, 1);
2020                         
2021                         }
2022                         
2023                         TelTypeDetail = PropertyValue;
2024                         
2025                         intSplitSize = 0;
2026                         intSplitsFound = 0;
2027                         intSplitPoint = 0;
2028                         
2029                         for (int i = 0; i <= intPropertyValueLen; i++){
2030         
2031                                 intSplitSize++;
2032         
2033                                 if (PropertyValue.Mid(i, 1) == wxT(",") && PropertyValue.Mid((i - 1), 1) != wxT("\\")){
2034         
2035                                         if (intSplitsFound == 0){
2037                                                 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
2038                                                 TypeSplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
2039                         
2040                                         } else {
2041                         
2042                                                 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
2043                                                 TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
2044                         
2045                                         }                       
2047                                         intSplitsFound++;
2048                                         i++;
2049                                         intSplitPoint = i;
2050                                         intSplitSize = 0;
2051         
2052                                 }
2053         
2054                         }
2055                         
2056                         TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
2057                         TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));                                                           
2058                 
2059                         int intTypeSeek = 0;
2060                 
2061                         for (std::map<int, int>::iterator typeiter = TypeSplitPoints.begin(); 
2062                         typeiter != TypeSplitPoints.end(); ++typeiter){
2063                         
2064                                 wxString TypePropertyName;
2065                                 
2066                                 TSLiter = TypeSplitLength.find(typeiter->first);
2067                                 
2068                                 TypePropertyName = PropertyValue.Mid(typeiter->second, TSLiter->second);
2069                                 
2070                                 if (intTypeSeek == 0){
2071                                 
2072                                 
2073                                 } else {
2074                                                                                 
2075                                         TelTypeUI.Append(wxT(","));                                                     
2076                                 
2077                                 }
2078                         
2079                                 if (TypePropertyName == wxT("home")){
2080                                 
2081                                         PropType = PROPERTY_HOME;
2082                                 
2083                                 } else if (TypePropertyName == wxT("work")){
2084                                 
2085                                         PropType = PROPERTY_WORK;
2086                                                                         
2087                                 }
2088                                 
2089                                 
2090                                 if (TypePropertyName == wxT("text")){
2091                                 
2092                                         TelTypeUI.Append(_("text"));
2093                                         intTypeSeek++;
2094                                 
2095                                 } else if (TypePropertyName == wxT("voice")){
2096                                 
2097                                         TelTypeUI.Append(_("voice"));
2098                                         intTypeSeek++;
2099                                 
2100                                 } else if (TypePropertyName == wxT("fax")){
2101                                 
2102                                         TelTypeUI.Append(_("fax"));
2103                                         intTypeSeek++;
2104                                 
2105                                 } else if (TypePropertyName == wxT("cell")){
2106                                 
2107                                         TelTypeUI.Append(_("mobile"));
2108                                         intTypeSeek++;
2109                                 
2110                                 } else if (TypePropertyName == wxT("video")){
2111                                 
2112                                         TelTypeUI.Append(_("video"));
2113                                         intTypeSeek++;
2114                                 
2115                                 } else if (TypePropertyName == wxT("pager")){
2116                                 
2117                                         TelTypeUI.Append(_("pager"));
2118                                         intTypeSeek++;
2119                                 
2120                                 } else if (TypePropertyName == wxT("textphone")){
2121                                 
2122                                         TelTypeUI.Append(_("textphone"));
2123                                         intTypeSeek++;
2124                                 
2125                                 }
2126                         
2127                         }
2128                 
2129                 }
2130                 
2131         }
2132         
2133         std::map<int, wxString> *TelephoneList = NULL;
2134         std::map<int, wxString> *TelephoneListType = NULL;
2135         std::map<int, wxString> *TelephoneListAltID = NULL;
2136         std::map<int, wxString> *TelephoneListPID = NULL;
2137         std::map<int, wxString> *TelephoneListTokens = NULL;
2138         std::map<int, wxString> *TelephoneListTypeInfo = NULL;  
2139         std::map<int, int> *TelephoneListPref = NULL;
2141         switch(PropType){
2142                 case PROPERTY_NONE:
2143                         TelephoneList = &GeneralTelephoneList;
2144                         TelephoneListType = &GeneralTelephoneListType;
2145                         TelephoneListAltID = &GeneralTelephoneListAltID;
2146                         TelephoneListPID = &GeneralTelephoneListPID;
2147                         TelephoneListTokens = &GeneralTelephoneListTokens;
2148                         TelephoneListTypeInfo = &GeneralTelephoneListTypeInfo;
2149                         TelephoneListPref = &GeneralTelephoneListPref;  
2150                         break;
2151                 case PROPERTY_HOME:
2152                         TelephoneList = &HomeTelephoneList;
2153                         TelephoneListType = &HomeTelephoneListType;
2154                         TelephoneListAltID = &HomeTelephoneListAltID;
2155                         TelephoneListPID = &HomeTelephoneListPID;
2156                         TelephoneListTokens = &HomeTelephoneListTokens;
2157                         TelephoneListTypeInfo = &HomeTelephoneListTypeInfo;     
2158                         TelephoneListPref = &HomeTelephoneListPref;     
2159                         break;
2160                 case PROPERTY_WORK:
2161                         TelephoneList = &BusinessTelephoneList;
2162                         TelephoneListType = &BusinessTelephoneListType;
2163                         TelephoneListAltID = &BusinessTelephoneListAltID;
2164                         TelephoneListPID = &BusinessTelephoneListPID;
2165                         TelephoneListTokens = &BusinessTelephoneListTokens;     
2166                         TelephoneListTypeInfo = &BusinessTelephoneListTypeInfo; 
2167                         TelephoneListPref = &BusinessTelephoneListPref; 
2168                         break;
2169         }
2170                 
2171         // Process the properties.
2172         
2173         bool FirstToken = TRUE;
2174         
2175         intPrevValue = 5;
2176         SplitPoints.clear();
2177         SplitLength.clear();
2179         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
2181         intPrevValue = 4;
2182         
2183         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
2184         intiter != SplitPoints.end(); ++intiter){
2185         
2186                 SLiter = SplitLength.find(intiter->first);
2187         
2188                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2189                 
2190                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2191                 PropertyName = PropertyElement.GetNextToken();                          
2192                 PropertyValue = PropertyElement.GetNextToken();
2193                 
2194                 intPrevValue = intiter->second;
2195                 
2196                 CaptureString(&PropertyValue, FALSE);
2197                 
2198                 // Process properties.
2199                 
2200                 if (PropertyName == wxT("ALTID")){
2202                         TelephoneListAltID->erase(*TelephoneCount);
2203                         TelephoneListAltID->insert(std::make_pair(*TelephoneCount, PropertyValue));
2204                 
2205                 } else if (PropertyName == wxT("PID")){
2207                         TelephoneListPID->erase(*TelephoneCount);
2208                         TelephoneListPID->insert(std::make_pair(*TelephoneCount, PropertyValue));
2209                 
2210                 } else if (PropertyName == wxT("PREF")){
2211                         
2212                         int PriorityNumber = 0;
2213                         bool ValidNumber = TRUE;
2214                         
2215                         try{
2216                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
2217                         }
2218                         
2219                         catch(std::invalid_argument &e){
2220                                 ValidNumber = FALSE;
2221                         }
2223                         if (ValidNumber == TRUE){
2225                                 TelephoneListPref->erase(*TelephoneCount);
2226                                 TelephoneListPref->insert(std::make_pair(*TelephoneCount, PriorityNumber));
2228                         }
2229                 
2230                 } else {
2231                 
2232                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
2233                         
2234                                 if (FirstToken == TRUE){
2235                                 
2236                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
2237                                         FirstToken = FALSE;
2238                                 
2239                                 } else {
2240                                 
2241                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
2242                                 
2243                                 }
2244                         
2245                         }
2246                 
2247                 }
2248         
2249         }
2250                 
2251         TelephoneList->insert(std::make_pair(*TelephoneCount, PropertySeg2));
2252         TelephoneListTypeInfo->insert(std::make_pair(*TelephoneCount, TelTypeUI));
2253         
2254         // Add the name token data.
2255         
2256         if (!PropertyTokens.IsEmpty()){
2257         
2258                 TelephoneListTokens->insert(std::make_pair(*TelephoneCount, PropertyTokens));
2259         
2260         }
2264 void ContactDataObject::ProcessLanguage(wxString PropertySeg1, wxString PropertySeg2, int *LanguageCount){
2266         std::map<int, int> SplitPoints;
2267         std::map<int, int> SplitLength;
2269         int intPrevValue = 6;
2270         int intPref = 0;                        
2271         
2272         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
2273         
2274         intPrevValue = 5;
2275         
2276         PropertyType PropType = PROPERTY_NONE;
2277                 
2278         // Look for type before continuing.
2279         
2280         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
2281         
2282         std::map<int, wxString> *LanguageList = NULL;
2283         std::map<int, wxString> *LanguageListType = NULL;
2284         std::map<int, wxString> *LanguageListAltID = NULL;
2285         std::map<int, wxString> *LanguageListPID = NULL;
2286         std::map<int, wxString> *LanguageListTokens = NULL;
2287         std::map<int, int> *LanguageListPref = NULL;
2289         switch(PropType){
2290                 case PROPERTY_NONE:
2291                         LanguageList = &GeneralLanguageList;
2292                         LanguageListType = &GeneralLanguageListType;
2293                         LanguageListAltID = &GeneralLanguageListAltID;
2294                         LanguageListPID = &GeneralLanguageListPID;
2295                         LanguageListTokens = &GeneralLanguageListTokens;
2296                         LanguageListPref = &GeneralLanguageListPref;    
2297                         break;
2298                 case PROPERTY_HOME:
2299                         LanguageList = &HomeLanguageList;
2300                         LanguageListType = &HomeLanguageListType;
2301                         LanguageListAltID = &HomeLanguageListAltID;
2302                         LanguageListPID = &HomeLanguageListPID;
2303                         LanguageListTokens = &HomeLanguageListTokens;   
2304                         LanguageListPref = &HomeLanguageListPref;       
2305                         break;
2306                 case PROPERTY_WORK:
2307                         LanguageList = &BusinessLanguageList;
2308                         LanguageListType = &BusinessLanguageListType;
2309                         LanguageListAltID = &BusinessLanguageListAltID;
2310                         LanguageListPID = &BusinessLanguageListPID;
2311                         LanguageListTokens = &BusinessLanguageListTokens;       
2312                         LanguageListPref = &BusinessLanguageListPref;
2313                         break;
2314         }
2315         
2316         intPrevValue = 5;
2317         
2318         std::map<int,int>::iterator SLiter;
2319         wxString PropertyData;
2320         wxString PropertyName;
2321         wxString PropertyValue;
2322         wxString PropertyTokens;
2323         bool FirstToken = TRUE;
2324         
2325         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
2326         intiter != SplitPoints.end(); ++intiter){
2327         
2328                 SLiter = SplitLength.find(intiter->first);
2329         
2330                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2331                 
2332                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2333                 PropertyName = PropertyElement.GetNextToken();                          
2334                 PropertyValue = PropertyElement.GetNextToken();
2335                 
2336                 intPrevValue = intiter->second;
2337                 
2338                 CaptureString(&PropertyValue, FALSE);
2339                 
2340                 // Process properties.
2341                 
2342                 if (PropertyName == wxT("ALTID")){
2344                         LanguageListAltID->erase(*LanguageCount);
2345                         LanguageListAltID->insert(std::make_pair(*LanguageCount, PropertyValue));
2346                 
2347                 } else if (PropertyName == wxT("PID")){
2349                         LanguageListPID->erase(*LanguageCount);
2350                         LanguageListPID->insert(std::make_pair(*LanguageCount, PropertyValue));
2351                 
2352                 } else if (PropertyName == wxT("PREF")){
2353                         
2354                         int PriorityNumber = 0;
2355                         bool ValidNumber = TRUE;
2356                         
2357                         try{
2358                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
2359                         }
2360                         
2361                         catch(std::invalid_argument &e){
2362                                 ValidNumber = FALSE;
2363                         }
2365                         if (ValidNumber == TRUE){
2367                                 LanguageListPref->erase(*LanguageCount);
2368                                 LanguageListPref->insert(std::make_pair(*LanguageCount, PriorityNumber));
2370                         }
2371                 
2372                 } else {
2373                 
2374                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
2375                         
2376                                 if (FirstToken == TRUE){
2377                                 
2378                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
2379                                         FirstToken = FALSE;
2380                                 
2381                                 } else {
2382                                 
2383                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
2384                                 
2385                                 }
2386                         
2387                         }
2388                 
2389                 }
2390         
2391         }
2392                 
2393         LanguageList->insert(std::make_pair(*LanguageCount, PropertySeg2));
2394         
2395         // Add the name token data.
2396         
2397         if (!PropertyTokens.IsEmpty()){
2398         
2399                 LanguageListTokens->insert(std::make_pair(*LanguageCount, PropertyTokens));
2400         
2401         }
2405 void SplitValues(wxString *PropertyLine, 
2406         std::map<int,int> *SplitPoints, 
2407         std::map<int,int> *SplitLength, 
2408         int intSize){
2409         
2410         size_t intPropertyLen = PropertyLine->Len();
2411         int intSplitsFound = 0;
2412         int intSplitSize = 0;
2413         int intSplitSeek = 0;
2414         
2415         for (int i = intSize; i <= intPropertyLen; i++){
2417                 intSplitSize++;
2418         
2419                 if (PropertyLine->Mid(i, 1) == wxT(";") &&
2420                     PropertyLine->Mid((i - 1), 1) != wxT("\\")){
2421            
2422                     if (intSplitsFound == 0){
2423             
2424                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
2425           
2426                     } else {
2427            
2428                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
2429             
2430                     }
2431             
2432                     SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
2433             
2434                     intSplitsFound++;
2435                     intSplitSeek = i;
2436                     intSplitSize = 0;
2437             
2438                 }
2440         }
2442         if (intSplitsFound == 0){
2444                 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
2445                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
2447         } else {
2449                 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
2450                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
2452         }
2456 void CheckType(wxString *PropertySeg1, 
2457         std::map<int,int> *SplitPoints, 
2458         std::map<int,int> *SplitLength, 
2459         int *intPrevValue, 
2460         PropertyType *PropType){
2461         
2462         wxString PropertyData;
2463         wxString PropertyName;
2464         wxString PropertyValue;
2465         std::map<int,int>::iterator SLiter;
2466         
2467         for (std::map<int, int>::iterator intiter = SplitPoints->begin(); 
2468         intiter != SplitPoints->end(); ++intiter){
2469         
2470                 SLiter = SplitLength->find(intiter->first);
2471         
2472                 PropertyData = PropertySeg1->Mid(*intPrevValue, (SLiter->second));
2473                 
2474                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2475                 PropertyName = PropertyElement.GetNextToken();                          
2476                 PropertyValue = PropertyElement.GetNextToken();
2477                 
2478                 *intPrevValue = intiter->second;
2479                 
2480                 if (PropertyName == wxT("TYPE")){
2481                                 
2482                         if (PropertyValue == wxT("work")){
2483                         
2484                                 *PropType = PROPERTY_WORK;
2485                                                         
2486                         } else if (PropertyValue == wxT("home")){
2488                                 *PropType = PROPERTY_HOME;
2489                                                         
2490                         } else {
2491                         
2492                                 *PropType = PROPERTY_NONE;
2493                         
2494                         }
2495                 
2496                         return;
2497                 
2498                 }
2499         
2500         }
2501         
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