Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source code, headers and unit tests for the IMPP vCard property type for Contac...
[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         wxString ContactLine;
91         wxString PropertyLine;
92         wxString PropertySeg1;
93         wxString PropertySeg2;
94         wxString PropertyNextLine;
95         wxString Property;
96         
97         for (std::map<int,wxString>::iterator iter = ContactFileLines.begin(); 
98          iter != ContactFileLines.end(); ++iter){
100                 ExtraLineSeek = TRUE;
101                 QuoteMode = FALSE;
102                 PropertyFind = TRUE;
103                 ContactLineLen = 0;
104                 QuoteBreakPoint = 0;
105                 ContactLine.Clear();
106                 PropertyLine.Clear();
107                 PropertySeg1.Clear();
108                 PropertySeg2.Clear();
109                 Property.Clear();
110          
111                 ContactLine = iter->second;
112                 
113                 while (ExtraLineSeek == TRUE){
114                 
115                         // Check if there is extra data on the next line 
116                         // (indicated by space or tab at the start) and add data.
117                 
118                         iter++;
119                         
120                         if (iter == ContactFileLines.end()){
121                         
122                                 iter--;
123                                 break;
124                         
125                         }                       
126                 
127                         PropertyNextLine = iter->second;
128                 
129                         if (PropertyNextLine.Mid(0, 1) == wxT(" ") || PropertyNextLine.Mid(0, 1) == wxT("\t")){
130                 
131                                 PropertyNextLine.Remove(0, 1);
132                                 ContactLine.Append(PropertyNextLine);
133                 
134                         } else {
135                         
136                                 iter--;
137                                 ExtraLineSeek = FALSE;
138                         
139                         }
140                 
141                 }
143                 ContactLineLen = ContactLine.Len();
144                 
145                 // Make sure we are not in quotation mode.
146                 // Make sure colon does not have \ or \\ before it.
147                 
148                 for (int i = 0; i <= ContactLineLen; i++){
149                 
150                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
151                         
152                                 PropertyFind = FALSE;
153                         
154                         } else if (PropertyFind == TRUE){
155                         
156                                 Property.Append(ContactLine.Mid(i, 1));
157                         
158                         }               
159                 
160                         if (ContactLine.Mid(i, 1) == wxT("\"")){
161                         
162                                 if (QuoteMode == TRUE){
163                                 
164                                         QuoteMode = FALSE;
165                                 
166                                 } else {
167                         
168                                         QuoteMode = TRUE;
169                                         
170                                 }
171                         
172                         }
173                         
174                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
175                         
176                                 QuoteBreakPoint = i;
177                                 break;
178                         
179                         }
180                 
181                 }
182                 
183                 // Split that line at the point into two variables (ignore the colon).
184                 
185                 PropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
186                 PropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
187                 
188                  if (Property == wxT("KIND") && KindProcessed == FALSE){
189                                 
190                         ProcessKind(PropertySeg2);
191                 
192                 } else if (Property == wxT("MEMBER")){
194                         ProcessMember(PropertySeg1, PropertySeg2, &GroupCount);
195                         GroupCount++;   
196                 
197                 } else if (Property == wxT("FN")){
198                 
199                         ProcessFN(PropertySeg1, PropertySeg2, &FNCount);
200                         FNCount++;
201                 
202                 } else if (Property == wxT("N") && NameProcessed == FALSE){
203                 
204                         ProcessN(PropertySeg1, PropertySeg2);
205                         NameProcessed = TRUE;
206                 
207                 } else if (Property == wxT("NICKNAME")){
208                                                 
209                         ProcessNickname(PropertySeg1, PropertySeg2, &NicknameCount);
210                         NicknameCount++;
211                         
212                 } else if (Property == wxT("GENDER") && GenderProcessed == FALSE){
213                 
214                         ProcessGender(PropertySeg1, PropertySeg2);
215                         GenderProcessed = TRUE;
216                 
217                 } else if (Property == wxT("BDAY") && BirthdayProcessed == FALSE){
218                 
219                         ProcessBirthday(PropertySeg1, PropertySeg2);
220                         BirthdayProcessed = TRUE;
221                 
222                 } else if (Property == wxT("ANNIVERSARY") && AnniversaryProcessed == FALSE){
223                 
224                         ProcessAnniversary(PropertySeg1, PropertySeg2);
225                         AnniversaryProcessed = TRUE;
226                 
227                 } else if (Property == wxT("TZ")){
228                 
229                         ProcessTimeZone(PropertySeg1, PropertySeg2, &TimeZoneCount);
230                         TimeZoneCount++;
231                 
232                 } else if (Property == wxT("ADR")){
233                 
234                         ProcessAddress(PropertySeg1, PropertySeg2, &AddressCount);
235                         AddressCount++;
236                 
237                 } else if (Property == wxT("EMAIL")){
238                 
239                         // See frmContactEditor-LoadEmail.cpp
240                         
241                         ProcessEmail(PropertySeg1, PropertySeg2, &EmailCount);  
242                         EmailCount++;
243                 
244                 } else if (Property == wxT("IMPP")){
245                 
246                         // See frmContactEditor-LoadIM.cpp
247                 
248                         ProcessIM(PropertySeg1, PropertySeg2, &IMCount);
249                         IMCount++;
250                         
251                 }
252                 
253         }
254         
255         return CONTACTLOAD_OK;
259 void ContactDataObject::ProcessKind(wxString KindType){
261         if (KindType == wxT("individual")){
262                         
263                 ContactKind = CONTACTKIND_INDIVIDUAL;
264                         
265         } else if (KindType == wxT("group")){
266                         
267                 ContactKind = CONTACTKIND_GROUP;
268                         
269         } else if (KindType == wxT("org")){
270                         
271                 ContactKind = CONTACTKIND_ORGANISATION;
272                         
273         } else if (KindType == wxT("location")){
274                         
275                 ContactKind = CONTACTKIND_LOCATION;
276                         
277         } else {
278                         
279                 ContactKind = CONTACTKIND_NONE;                 
280         }
284 void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount){
286         std::map<int, int> SplitPoints;
287         std::map<int, int> SplitLength;
289         int intPrevValue = 8;
290         int intPref = 0;                        
291         int intType = 0;
292         
293         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
295         intPrevValue = 7;
296         
297         wxString PropertyName;
298         wxString PropertyValue;
299         wxString PropertyData;
300         wxString PropertyTokens;
301         std::map<int,int>::iterator SLiter;
302         bool FirstToken = TRUE;
303         
304         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
305         intiter != SplitPoints.end(); ++intiter){
306         
307                 SLiter = SplitLength.find(intiter->first);
308         
309                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
310                 
311                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
312                 PropertyName = PropertyElement.GetNextToken();                          
313                 PropertyValue = PropertyElement.GetNextToken();
314                 
315                 intPrevValue = intiter->second;
316                 
317                 CaptureString(&PropertyValue, FALSE);
318         
319                 if (PropertyName == wxT("ALTID")){
321                         GroupsListAltID.erase(*GroupCount);
322                         GroupsListAltID.insert(std::make_pair(*GroupCount, PropertyValue));
323                 
324                 } else if (PropertyName == wxT("PID")){
326                         GroupsListPID.erase(*GroupCount);
327                         GroupsListPID.insert(std::make_pair(*GroupCount, PropertyValue));
328                 
329                 } else if (PropertyName == wxT("PREF")){
331                         int PriorityNumber = 0;
332                         bool ValidNumber = TRUE;
333                         
334                         try{
335                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
336                         }
337                         
338                         catch(std::invalid_argument &e){
339                                 ValidNumber = FALSE;
340                         }
342                         if (ValidNumber == TRUE){
344                                 GroupsListPref.erase(*GroupCount);
345                                 GroupsListPref.insert(std::make_pair(*GroupCount, PriorityNumber));
346                 
347                         }
348                 
349                 } else if (PropertyName == wxT("MEDIATYPE")){
351                         GroupsListMediaType.erase(*GroupCount);
352                         GroupsListMediaType.insert(std::make_pair(*GroupCount, PropertyValue));
353                 
354                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
355                         
356                         if (FirstToken == TRUE){
357                                 
358                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
359                                 FirstToken = FALSE;
360                                 
361                         } else {
362                         
363                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
364                                 
365                         }
366                         
367                 }
368                 
369         }
371         GroupsList.insert(std::make_pair(*GroupCount, PropertySeg2));
373         if (!PropertyTokens.IsEmpty()){
374         
375                 GroupsListTokens.insert(std::make_pair(*GroupCount, PropertyTokens));
376         
377         }
382 void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount){
384         std::map<int, int> SplitPoints;
385         std::map<int, int> SplitLength;
387         int intPrevValue = 4;
388         int intPref = 0;                        
389         int intType = 0;
390         
391         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
393         intPrevValue = 3;
394         
395         wxString PropertyName;
396         wxString PropertyValue;
397         wxString PropertyData;
398         wxString PropertyTokens;
399         std::map<int,int>::iterator SLiter;
400         bool FirstToken = TRUE;
401         
402         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
403         intiter != SplitPoints.end(); ++intiter){
404         
405                 SLiter = SplitLength.find(intiter->first);
406         
407                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
408                 
409                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
410                 PropertyName = PropertyElement.GetNextToken();                          
411                 PropertyValue = PropertyElement.GetNextToken();
412                 
413                 intPrevValue = intiter->second;
414                 
415                 CaptureString(&PropertyValue, FALSE);
416                 
417                 if (PropertyName == wxT("TYPE")){
419                         if (!PropertyValue.IsEmpty() || PropertyValue == wxT("home") ||
420                                 PropertyValue == wxT("work") ){
422                                 FullNamesListType.erase(*FNCount);
423                                 FullNamesListType.insert(std::make_pair(*FNCount, PropertyValue));
424                 
425                         }
426                 
427                 } else if (PropertyName == wxT("LANGUAGE")){
429                         FullNamesListLanguage.erase(*FNCount);
430                         FullNamesListLanguage.insert(std::make_pair(*FNCount, PropertyValue));
431                 
432                 } else if (PropertyName == wxT("ALTID")){
433                 
434                         FullNamesListAltID.erase(*FNCount);
435                         FullNamesListAltID.insert(std::make_pair(*FNCount, PropertyValue));
436                 
437                 } else if (PropertyName == wxT("PID")){
439                         FullNamesListPID.erase(*FNCount);
440                         FullNamesListPID.insert(std::make_pair(*FNCount, PropertyValue));
441                 
442                 } else if (PropertyName == wxT("PREF")){
444                         int PriorityNumber = 0;
445                         bool ValidNumber = TRUE;
446                         
447                         try{
448                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
449                         }
450                         
451                         catch(std::invalid_argument &e){
452                                 ValidNumber = FALSE;
453                         }
455                         if (ValidNumber == TRUE){
457                                 FullNamesListPref.erase(*FNCount);
458                                 FullNamesListPref.insert(std::make_pair(*FNCount, PriorityNumber));
460                         }
461                 
462                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
463                         
464                         if (FirstToken == TRUE){
465                                 
466                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
467                                 FirstToken = FALSE;
468                                 
469                         } else {
470                         
471                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
472                                 
473                         }
474                         
475                 } 
476         
477         }
479         FullNamesList.insert(std::make_pair(*FNCount, PropertySeg2));
481         if (!PropertyTokens.IsEmpty()){
482         
483                 FullNamesListTokens.insert(std::make_pair(*FNCount, PropertyTokens));
484         
485         }
489 void ContactDataObject::ProcessN(wxString PropertySeg1, wxString PropertySeg2){
491         std::map<int, int> SplitPoints;
492         std::map<int, int> SplitLength;
494         int intPrevValue = 3;
495         int intPref = 0;                        
496         int intType = 0;
497         
498         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
499         
500         intPrevValue = 2;
501         
502         wxString PropertyName;
503         wxString PropertyValue;
504         wxString PropertyData;
505         wxString PropertyTokens;
506         std::map<int,int>::iterator SLiter;
507         bool FirstToken = TRUE;
508         
509         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
510         intiter != SplitPoints.end(); ++intiter){
511         
512                 SLiter = SplitLength.find(intiter->first);
513         
514                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
515                 
516                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
517                 PropertyName = PropertyElement.GetNextToken();                          
518                 PropertyValue = PropertyElement.GetNextToken();
519                 
520                 intPrevValue = intiter->second;
521                 
522                 CaptureString(&PropertyValue, FALSE);
523                 
524                 if (PropertyName == wxT("ALTID")){
526                         NameAltID = PropertyValue;
527                 
528                 } else if (PropertyName == wxT("LANGUAGE")){
529                 
530                         NameLanguage = PropertyValue;
531                 
532                 } else if (PropertyName == wxT("SORT-AS")){
533                 
534                         if (PropertyValue.Left(1) == wxT("\"") && PropertyValue.Right(1) == wxT("\"") &&
535                                 PropertyValue.Len() >= 3){
536                                 NameDisplayAs = PropertyValue.Mid(1, (PropertyValue.Len() - 2));
537                         }
538                 
539                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
540                         
541                         if (FirstToken == TRUE){
542                                 
543                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
544                                 FirstToken = FALSE;
545                                 
546                         } else {
547                         
548                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
549                                 
550                         }
551                         
552                 }
553         
554         }
555         
556         // Split the name data.
557         
558         int intSplitSeek = 0;           
559         int intSplitsFound = 0;
560         int intSplitSize = 0;
561         int intPropertyLen = PropertySeg2.Len();
562         
563         std::map<int,wxString> NameValues;
564         intPrevValue = 0;                                       
565         
566         for (int i = 0; i <= intPropertyLen; i++){
567         
568                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
569                         
570                         NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, intSplitSize)));
571                         
572                         intSplitSeek = i;
573                         intSplitSeek++;
574                         
575                         if (intSplitsFound == 4){
576                         
577                                 NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, wxString::npos)));
578                                 break;
579                         
580                         }
581                         
582                         intSplitSize = 0;
583                         continue;
584         
585                 }
586                 
587                 intSplitSize++;
589         }
590         
591         // Split the data into several parts.
592                         
593         for (std::map<int, wxString>::iterator iter = NameValues.begin(); 
594         iter != NameValues.end(); ++iter){
595         
596                 if (iter->first == 1){
597                 
598                         // Deal with family name.
599                         
600                         NameSurname = iter->second;
601                 
602                 } else if (iter->first == 2){
603                 
604                         // Deal with given names.
605                         
606                         NameForename = iter->second;
607                 
608                 } else if (iter->first == 3){
609                 
610                         // Deal with additional names.
611                         
612                         NameOtherNames = iter->second;
613                 
614                 } else if (iter->first == 4){
615                 
616                         // Deal with honorifix prefixes and suffixes.
618                         NameTitle = iter->second;
619                 
620                         iter++;
621                         
622                         if (iter == NameValues.end()){
623                         
624                                 break;
625                         
626                         }
627                 
628                         NameSuffix = iter->second;
629                 
630                 }
631         
632         }
633         
634         // Add the name token data.
635         
636         if (!PropertyTokens.IsEmpty()){
637         
638                 NameTokens = PropertyTokens;
639         
640         }
644 void ContactDataObject::ProcessNickname(wxString PropertySeg1, wxString PropertySeg2, int *NicknameCount){
646         std::map<int, int> SplitPoints;
647         std::map<int, int> SplitLength;
649         int intPrevValue = 10;
650         int intPref = 0;                        
651         
652         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
653         
654         intPrevValue = 9;
655         
656         PropertyType PropType = PROPERTY_NONE;
657         
658         // Look for type before continuing.
659         
660         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
661         
662         intPrevValue = 9;
663         
664         std::map<int, wxString> *NicknamesList = NULL;
665         std::map<int, wxString> *NicknamesListType = NULL;
666         std::map<int, wxString> *NicknamesListLanguage = NULL;
667         std::map<int, wxString> *NicknamesListAltID = NULL;
668         std::map<int, wxString> *NicknamesListPID = NULL;
669         std::map<int, wxString> *NicknamesListTokens = NULL;            
670         std::map<int, int> *NicknamesListPref = NULL;
671         
672         switch(PropType){
673                 case PROPERTY_NONE:
674                         NicknamesList = &GeneralNicknamesList;
675                         NicknamesListType = &GeneralNicknamesListType;
676                         NicknamesListLanguage = &GeneralNicknamesListLanguage;
677                         NicknamesListAltID = &GeneralNicknamesListAltID;
678                         NicknamesListPID = &GeneralNicknamesListPID;
679                         NicknamesListTokens = &GeneralNicknamesListTokens;
680                         NicknamesListPref = &GeneralNicknamesListPref;
681                         break;
682                 case PROPERTY_HOME:
683                         NicknamesList = &HomeNicknamesList;
684                         NicknamesListType = &HomeNicknamesListType;
685                         NicknamesListLanguage = &HomeNicknamesListLanguage;
686                         NicknamesListAltID = &HomeNicknamesListAltID;
687                         NicknamesListPID = &HomeNicknamesListPID;
688                         NicknamesListTokens = &HomeNicknamesListTokens;
689                         NicknamesListPref = &HomeNicknamesListPref;
690                         break;
691                 case PROPERTY_WORK:
692                         NicknamesList = &BusinessNicknamesList;
693                         NicknamesListType = &BusinessNicknamesListType;
694                         NicknamesListLanguage = &BusinessNicknamesListLanguage;
695                         NicknamesListAltID = &BusinessNicknamesListAltID;
696                         NicknamesListPID = &BusinessNicknamesListPID;
697                         NicknamesListTokens = &BusinessNicknamesListTokens;
698                         NicknamesListPref = &BusinessNicknamesListPref;
699                         break;
700         }
701         
702         std::map<int, int>::iterator SLiter;    
703         wxString PropertyData;
704         wxString PropertyName;
705         wxString PropertyValue;
706         wxString PropertyTokens;
707         bool FirstToken = TRUE;
708         
709         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
710         intiter != SplitPoints.end(); ++intiter){
711         
712                 SLiter = SplitLength.find(intiter->first);
713         
714                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
715                 
716                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
717                 PropertyName = PropertyElement.GetNextToken();                          
718                 PropertyValue = PropertyElement.GetNextToken();
719                 
720                 intPrevValue = intiter->second;
721                 
722                 CaptureString(&PropertyValue, FALSE);
723                 
724                 if (PropertyName == wxT("ALTID")){
726                         NicknamesListAltID->erase(*NicknameCount);
727                         NicknamesListAltID->insert(std::make_pair(*NicknameCount, PropertyValue));
728                 
729                 } else if (PropertyName == wxT("PID")){
731                         NicknamesListPID->erase(*NicknameCount);
732                         NicknamesListPID->insert(std::make_pair(*NicknameCount, PropertyValue));        
734                 } else if (PropertyName == wxT("PREF")){
736                         int PriorityNumber = 0;
737                         bool ValidNumber = TRUE;
738                         
739                         try{
740                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
741                         }
742                         
743                         catch(std::invalid_argument &e){
744                                 ValidNumber = FALSE;
745                         }
747                         if (ValidNumber == TRUE){
749                                 NicknamesListPref->erase(*NicknameCount);
750                                 NicknamesListPref->insert(std::make_pair(*NicknameCount, PriorityNumber));
752                         }
753                 
754                 } else if (PropertyName == wxT("LANGUAGE")){
756                         NicknamesListLanguage->erase(*NicknameCount);
757                         NicknamesListLanguage->insert(std::make_pair(*NicknameCount, PropertyValue));   
759                 } else {
760                 
761                         // Something else we don't know about so append
762                         // to the tokens variable.
763                 
764                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
765                 
766                                 if (FirstToken == TRUE){
767                         
768                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
769                                         FirstToken = FALSE;
770                         
771                                 } else {
772                         
773                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
774                         
775                                 }
776                 
777                         }
778                 
779                 }
780                 
781         }
782         
783         NicknamesList->insert(std::make_pair(*NicknameCount, PropertySeg2));
784         
785         // Add the name token data.
786         
787         if (!PropertyTokens.IsEmpty()){
788         
789                 NicknamesListTokens->insert(std::make_pair(*NicknameCount, PropertyTokens));
790         
791         }
795 void ContactDataObject::ProcessGender(wxString PropertySeg1, wxString PropertySeg2){
797         std::map<int, int> SplitPoints;
798         std::map<int, int> SplitLength;
799         std::map<int, int>::iterator SLiter;                    
800         wxString PropertyData;
801         wxString PropertyName;
802         wxString PropertyValue;
803         wxString PropertyTokens;
804         bool FirstToken = TRUE;
805         int intPrevValue = 8;
807         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
809         intPrevValue = 7;                       
810         
811         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
812         intiter != SplitPoints.end(); ++intiter){
813         
814                 SLiter = SplitLength.find(intiter->first);
815         
816                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
817                 
818                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
819                 PropertyName = PropertyElement.GetNextToken();                          
820                 PropertyValue = PropertyElement.GetNextToken();
821                 
822                 intPrevValue = intiter->second;
823                 
824                 // Process properties.
825                 
826                 size_t intPropertyValueLen = PropertyValue.Len();
827                 
828                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
829                         
830                         PropertyValue.Trim();
831                         PropertyValue.RemoveLast();
832                         
833                 }                               
834                 
835                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
836                         
837                         PropertyValue.Remove(0, 1);
838                         
839                 }                               
840                 
841                 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
843                         if (FirstToken == TRUE){
844         
845                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
846                                 FirstToken = FALSE;
847         
848                         } else {
849         
850                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
851         
852                         }
854                 }
855         
856         }       
858         wxStringTokenizer GenderData (PropertySeg2, wxT(";"));
859         
860         wxString GenderComponent;
861         
862         if (GenderData.CountTokens() >= 2){
863         
864                 Gender = GenderData.GetNextToken();
865                 GenderDetails = GenderData.GetString();
866         
867                 CaptureString(&GenderDetails, FALSE);
868                                                 
869         } else {
870         
871                 Gender = GenderData.GetNextToken();
872         
873         }
874         
875         if (!PropertyTokens.IsEmpty()){
876         
877                 GenderTokens = PropertyTokens;
878         
879         }
883 void ContactDataObject::ProcessBirthday(wxString PropertySeg1, wxString PropertySeg2){
885         // Process date. Preserve the remainder in the string.
887         std::map<int, int> SplitPoints;
888         std::map<int, int> SplitLength;
889         std::map<int, int>::iterator SLiter;                    
890         wxString PropertyData;
891         wxString PropertyName;
892         wxString PropertyValue;
893         wxString PropertyTokens;
894         bool BirthdayText = FALSE;
895         int intPrevValue = 6;
897         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
899         intPrevValue = 5;
901         // Look for type before continuing.
903         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
904         intiter != SplitPoints.end(); ++intiter){
906                 SLiter = SplitLength.find(intiter->first);
908                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
909         
910                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
911                 PropertyName = PropertyElement.GetNextToken();                          
912                 PropertyValue = PropertyElement.GetNextToken();
913         
914                 intPrevValue = intiter->second;
915         
916                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){
917         
918                         CaptureString(&PropertySeg2, FALSE);
919                         Birthday = PropertySeg2;
920                         BirthdayText = TRUE;
921         
922                 }
924         }
926         // Setup blank lines for later on.
927         
928         intPrevValue = 5;
929         bool FirstToken = TRUE;
931         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
932         intiter != SplitPoints.end(); ++intiter){
934                 SLiter = SplitLength.find(intiter->first);
936                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
937         
938                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
939                 PropertyName = PropertyElement.GetNextToken();                          
940                 PropertyValue = PropertyElement.GetNextToken();
941         
942                 intPrevValue = intiter->second;
943         
944                 // Process properties.
945         
946                 CaptureString(&PropertyValue, FALSE);
947         
948                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
949                 
950                         PropertyValue.Trim();
951                         PropertyValue.RemoveLast();
952                 
953                 }                               
954         
955                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
956                 
957                         PropertyValue.Remove(0, 1);
958                 
959                 }                               
960         
961                 if (PropertyName == wxT("ALTID")){
963                         BirthdayAltID = PropertyValue;
964         
965                 } else if (PropertyName == wxT("CALSCALE")){
966         
967                         BirthdayCalScale = PropertyValue;
968         
969                 } else if (PropertyName != wxT("VALUE")) {
970         
971                         // Something else we don't know about so append
972                         // to the tokens variable.
973                 
974                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
975                 
976                                 if (FirstToken == TRUE){
977         
978                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
979                                         FirstToken = FALSE;
980         
981                                 } else {
982         
983                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
984         
985                                 }
986                                 
987                         }
988                         
989                 }
991         }       
993         // Add the data to the variables and form.
994         
995         if (BirthdayText == FALSE){
996         
997                 Birthday = PropertySeg2;
999         }
1000         
1001         if (!PropertyTokens.IsEmpty()){
1002         
1003                 BirthdayTokens = PropertyTokens;
1005         }
1009 void ContactDataObject::ProcessAnniversary(wxString PropertySeg1, wxString PropertySeg2){
1011         // Process date. Preserve the remainder in the string.
1013         std::map<int, int> SplitPoints;
1014         std::map<int, int> SplitLength;
1015         std::map<int, int>::iterator SLiter;                    
1016         wxString PropertyData;
1017         wxString PropertyName;
1018         wxString PropertyValue;
1019         wxString PropertyTokens;
1020         bool AnniversaryText = FALSE;
1021         int intPrevValue = 13;
1023         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1025         intPrevValue = 12;
1027         // Look for type before continuing.
1029         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1030         intiter != SplitPoints.end(); ++intiter){
1032                 SLiter = SplitLength.find(intiter->first);
1034                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1035         
1036                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1037                 PropertyName = PropertyElement.GetNextToken();                          
1038                 PropertyValue = PropertyElement.GetNextToken();
1039         
1040                 intPrevValue = intiter->second;
1041         
1042                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){
1043         
1044                         CaptureString(&PropertySeg2, FALSE);
1045                         Anniversary = PropertySeg2;
1046                         AnniversaryText = TRUE;
1047         
1048                 }
1050         }
1052         // Setup blank lines for later on.
1053         
1054         intPrevValue = 12;
1055         bool FirstToken = TRUE;
1057         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1058         intiter != SplitPoints.end(); ++intiter){
1060                 SLiter = SplitLength.find(intiter->first);
1062                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1063         
1064                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1065                 PropertyName = PropertyElement.GetNextToken();                          
1066                 PropertyValue = PropertyElement.GetNextToken();
1067         
1068                 intPrevValue = intiter->second;
1069         
1070                 // Process properties.
1071         
1072                 CaptureString(&PropertyValue, FALSE);
1073         
1074                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
1075                 
1076                         PropertyValue.Trim();
1077                         PropertyValue.RemoveLast();
1078                 
1079                 }                               
1080         
1081                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
1082                 
1083                         PropertyValue.Remove(0, 1);
1084                 
1085                 }                               
1086         
1087                 if (PropertyName == wxT("ALTID")){
1089                         AnniversaryAltID = PropertyValue;
1090         
1091                 } else if (PropertyName == wxT("CALSCALE")){
1092         
1093                         AnniversaryCalScale = PropertyValue;
1094         
1095                 } else if (PropertyName != wxT("VALUE")) {
1096         
1097                         // Something else we don't know about so append
1098                         // to the tokens variable.
1099                 
1100                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
1101                 
1102                                 if (FirstToken == TRUE){
1103         
1104                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1105                                         FirstToken = FALSE;
1106         
1107                                 } else {
1108         
1109                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1110         
1111                                 }
1112                                 
1113                         }
1114                         
1115                 }
1117         }       
1119         // Add the data to the variables and form.
1120         
1121         if (AnniversaryText == FALSE){
1122         
1123                 Anniversary = PropertySeg2;
1125         }
1126         
1127         if (!PropertyTokens.IsEmpty()){
1128         
1129                 AnniversaryTokens = PropertyTokens;
1131         }
1135 void ContactDataObject::ProcessTimeZone(wxString PropertySeg1, wxString PropertySeg2, int *TimeZoneCount){
1137         std::map<int, int> SplitPoints;
1138         std::map<int, int> SplitLength;
1140         int intPrevValue = 4;
1141         int intPref = 0;                        
1142         
1143         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1144         
1145         intPrevValue = 3;
1146         
1147         PropertyType PropType = PROPERTY_NONE;
1148         
1149         // Look for type before continuing.
1150         
1151         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1152         
1153         intPrevValue = 3;
1154         
1155         std::map<int, wxString> *TZList = NULL;
1156         std::map<int, wxString> *TZListType = NULL;
1157         std::map<int, wxString> *TZListMediatype = NULL;
1158         std::map<int, wxString> *TZListAltID = NULL;
1159         std::map<int, wxString> *TZListPID = NULL;
1160         std::map<int, wxString> *TZListTokens = NULL;           
1161         std::map<int, int> *TZListPref = NULL;
1162         
1163         switch(PropType){
1164                 case PROPERTY_NONE:
1165                         TZList = &GeneralTZList;
1166                         TZListType = &GeneralTZListType;
1167                         TZListMediatype = &GeneralTZListMediatype;
1168                         TZListAltID = &GeneralTZListAltID;
1169                         TZListPID = &GeneralTZListPID;
1170                         TZListTokens = &GeneralTZListTokens;
1171                         TZListPref = &GeneralTZListPref;
1172                         break;
1173                 case PROPERTY_HOME:
1174                         TZList = &HomeTZList;
1175                         TZListType = &HomeTZListType;
1176                         TZListMediatype = &HomeTZListMediatype;
1177                         TZListAltID = &HomeTZListAltID;
1178                         TZListPID = &HomeTZListPID;
1179                         TZListTokens = &HomeTZListTokens;
1180                         TZListPref = &HomeTZListPref;
1181                         break;
1182                 case PROPERTY_WORK:
1183                         TZList = &BusinessTZList;
1184                         TZListType = &BusinessTZListType;
1185                         TZListMediatype = &BusinessTZListMediatype;
1186                         TZListAltID = &BusinessTZListAltID;
1187                         TZListPID = &BusinessTZListPID;
1188                         TZListTokens = &BusinessTZListTokens;
1189                         TZListPref = &BusinessTZListPref;
1190                         break;
1191         }
1192         
1193         std::map<int, int>::iterator SLiter;    
1194         wxString PropertyData;
1195         wxString PropertyName;
1196         wxString PropertyValue;
1197         wxString PropertyTokens;
1198         bool FirstToken = TRUE;
1199         
1200         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1201         intiter != SplitPoints.end(); ++intiter){
1202         
1203                 SLiter = SplitLength.find(intiter->first);
1204         
1205                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1206                 
1207                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1208                 PropertyName = PropertyElement.GetNextToken();                          
1209                 PropertyValue = PropertyElement.GetNextToken();
1210                 
1211                 intPrevValue = intiter->second;
1212                 
1213                 CaptureString(&PropertyValue, FALSE);
1215                 if (PropertyName == wxT("ALTID")){
1217                         TZListAltID->erase(*TimeZoneCount);
1218                         TZListAltID->insert(std::make_pair(*TimeZoneCount, PropertyValue));
1219                 
1220                 } else if (PropertyName == wxT("PID")){
1222                         TZListPID->erase(*TimeZoneCount);
1223                         TZListPID->insert(std::make_pair(*TimeZoneCount, PropertyValue));       
1225                 } else if (PropertyName == wxT("PREF")){
1227                         int PriorityNumber = 0;
1228                         bool ValidNumber = TRUE;
1229                         
1230                         try{
1231                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1232                         }
1233                         
1234                         catch(std::invalid_argument &e){
1235                                 ValidNumber = FALSE;
1236                         }
1238                         if (ValidNumber == TRUE){
1240                                 TZListPref->erase(*TimeZoneCount);
1241                                 TZListPref->insert(std::make_pair(*TimeZoneCount, PriorityNumber));
1243                         }
1244                 
1245                 } else if (PropertyName == wxT("MEDIATYPE")){
1247                         TZListMediatype->erase(*TimeZoneCount);
1248                         TZListMediatype->insert(std::make_pair(*TimeZoneCount, PropertyValue)); 
1250                 } else {
1251                 
1252                         // Something else we don't know about so append
1253                         // to the tokens variable.
1254                 
1255                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1256                 
1257                                 if (FirstToken == TRUE){
1258                         
1259                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1260                                         FirstToken = FALSE;
1261                         
1262                                 } else {
1263                         
1264                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1265                         
1266                                 }
1267                 
1268                         }
1269                 
1270                 }
1271                 
1272         }
1273         
1274         TZList->insert(std::make_pair(*TimeZoneCount, PropertySeg2));
1275         
1276         // Add the name token data.
1277         
1278         if (!PropertyTokens.IsEmpty()){
1279         
1280                 TZListTokens->insert(std::make_pair(*TimeZoneCount, PropertyTokens));
1281         
1282         }
1287 void ContactDataObject::ProcessAddress(wxString PropertySeg1, wxString PropertySeg2, int *AddressCount){
1289         size_t intPropertyLen = PropertySeg1.Len();
1290         std::map<int, int> SplitPoints;
1291         std::map<int, int> SplitLength;
1292         std::map<int, int>::iterator SLiter;                    
1293         wxString PropertyData;
1294         wxString PropertyName;
1295         wxString PropertyValue;
1296         wxString PropertyTokens;
1297         wxString AddressLabel;
1298         wxString AddressLang;
1299         wxString AddressAltID;
1300         wxString AddressPID;
1301         wxString AddressTokens;
1302         wxString AddressGeo;
1303         wxString AddressTimezone;
1304         wxString AddressType;
1305         wxString AddressMediatype;
1306         wxString AddressPOBox;
1307         wxString AddressExtended;
1308         wxString AddressStreet;
1309         wxString AddressLocality;
1310         wxString AddressCity;
1311         wxString AddressRegion;
1312         wxString AddressPostalCode;
1313         wxString AddressCountry;
1314         bool FirstToken = TRUE;                 
1315         int intSplitsFound = 0;
1316         int intSplitSize = 0;
1317         int intPrevValue = 5;
1318         int intPref = 0;                        
1319         int intType = 0;
1320         long ListCtrlIndex;
1321         
1322         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1323         
1324         intPrevValue = 4;
1325         
1326         PropertyType PropType = PROPERTY_NONE;
1327                 
1328         // Look for type before continuing.
1329         
1330         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1331         
1332         intPrevValue = 4;
1333         
1334         std::map<int, wxString> *AddressList = NULL;
1335         std::map<int, wxString> *AddressListTown = NULL;
1336         std::map<int, wxString> *AddressListCounty = NULL;
1337         std::map<int, wxString> *AddressListPostCode = NULL;
1338         std::map<int, wxString> *AddressListCountry = NULL;
1339         std::map<int, wxString> *AddressListLabel = NULL;
1340         std::map<int, wxString> *AddressListLang = NULL;                
1341         std::map<int, wxString> *AddressListAltID = NULL;
1342         std::map<int, wxString> *AddressListPID = NULL;
1343         std::map<int, wxString> *AddressListTokens = NULL;
1344         std::map<int, wxString> *AddressListGeo = NULL;
1345         std::map<int, wxString> *AddressListTimezone = NULL;            
1346         std::map<int, wxString> *AddressListType = NULL;
1347         std::map<int, wxString> *AddressListMediatype = NULL;
1348         std::map<int, int> *AddressListPref = NULL;
1350         switch(PropType){
1351                 case PROPERTY_NONE:
1352                         AddressList = &GeneralAddressList;
1353                         AddressListTown = &GeneralAddressListTown;
1354                         AddressListCounty = &GeneralAddressListCounty;
1355                         AddressListPostCode = &GeneralAddressListPostCode;
1356                         AddressListCountry = &GeneralAddressListCountry;
1357                         AddressListLabel = &GeneralAddressListLabel;
1358                         AddressListLang = &GeneralAddressListLang;              
1359                         AddressListAltID = &GeneralAddressListAltID;
1360                         AddressListPID = &GeneralAddressListPID;
1361                         AddressListTokens = &GeneralAddressListTokens;
1362                         AddressListGeo = &GeneralAddressListGeo;
1363                         AddressListTimezone = &GeneralAddressListTimezone;
1364                         AddressListType = &GeneralAddressListType;
1365                         AddressListMediatype = &GeneralAddressListMediatype;
1366                         AddressListPref = &GeneralAddressListPref;              
1367                         break;
1368                 case PROPERTY_HOME:
1369                         AddressList = &HomeAddressList;
1370                         AddressListTown = &HomeAddressListTown;
1371                         AddressListCounty = &HomeAddressListCounty;
1372                         AddressListPostCode = &HomeAddressListPostCode;
1373                         AddressListCountry = &HomeAddressListCountry;
1374                         AddressListLabel = &HomeAddressListLabel;
1375                         AddressListLang = &HomeAddressListLang;         
1376                         AddressListAltID = &HomeAddressListAltID;
1377                         AddressListPID = &HomeAddressListPID;
1378                         AddressListTokens = &HomeAddressListTokens;
1379                         AddressListGeo = &HomeAddressListGeo;
1380                         AddressListTimezone = &HomeAddressListTimezone;
1381                         AddressListType = &HomeAddressListType;
1382                         AddressListMediatype = &HomeAddressListMediatype;
1383                         AddressListPref = &HomeAddressListPref;
1384                         break;
1385                 case PROPERTY_WORK:
1386                         AddressList = &BusinessAddressList;
1387                         AddressListTown = &BusinessAddressListTown;
1388                         AddressListCounty = &BusinessAddressListCounty;
1389                         AddressListPostCode = &BusinessAddressListPostCode;
1390                         AddressListCountry = &BusinessAddressListCountry;
1391                         AddressListLabel = &BusinessAddressListLabel;
1392                         AddressListLang = &BusinessAddressListLang;             
1393                         AddressListAltID = &BusinessAddressListAltID;
1394                         AddressListPID = &BusinessAddressListPID;
1395                         AddressListTokens = &BusinessAddressListTokens;
1396                         AddressListGeo = &BusinessAddressListGeo;
1397                         AddressListTimezone = &BusinessAddressListTimezone;
1398                         AddressListType = &BusinessAddressListType;
1399                         AddressListMediatype = &BusinessAddressListMediatype;
1400                         AddressListPref = &BusinessAddressListPref;
1401                         break;
1402         }
1403         
1404         intPrevValue = 4;
1405         
1406         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1407         intiter != SplitPoints.end(); ++intiter){
1408         
1409                 SLiter = SplitLength.find(intiter->first);
1410         
1411                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1412                 
1413                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1414                 PropertyName = PropertyElement.GetNextToken();                          
1415                 PropertyValue = PropertyElement.GetNextToken();
1416                 
1417                 intPrevValue = intiter->second;
1418                 
1419                 CaptureString(&PropertyValue, FALSE);
1420                 
1421                 // Process properties.
1422                 
1423                 if (PropertyName == wxT("LABEL")){
1424                 
1425                         AddressListLabel->erase(*AddressCount);
1426                         AddressListLabel->insert(std::make_pair(*AddressCount, PropertyValue));
1427                                 
1428                 } else if (PropertyName == wxT("LANGUAGE")){
1429                 
1430                         AddressListLang->erase(*AddressCount);
1431                         AddressListLang->insert(std::make_pair(*AddressCount, PropertyValue));                  
1432                 
1433                 } else if (PropertyName == wxT("ALTID")){
1435                         AddressListAltID->erase(*AddressCount);
1436                         AddressListAltID->insert(std::make_pair(*AddressCount, PropertyValue));
1437                 
1438                 } else if (PropertyName == wxT("PID")){
1440                         AddressListPID->erase(*AddressCount);
1441                         AddressListPID->insert(std::make_pair(*AddressCount, PropertyValue));
1442                 
1443                 } else if (PropertyName == wxT("GEO")){
1444                 
1445                         AddressListGeo->erase(*AddressCount);
1446                         AddressListGeo->insert(std::make_pair(*AddressCount, PropertyValue));
1447                 
1448                 } else if (PropertyName == wxT("TZ")){
1450                         AddressListTimezone->erase(*AddressCount);
1451                         AddressListTimezone->insert(std::make_pair(*AddressCount, PropertyValue));
1452                 
1453                 } else if (PropertyName == wxT("MEDIATYPE")){
1455                         AddressListMediatype->erase(*AddressCount);
1456                         AddressListMediatype->insert(std::make_pair(*AddressCount, PropertyValue));
1457                 
1458                 } else if (PropertyName == wxT("PREF")){
1459                         
1460                         int PriorityNumber = 0;
1461                         bool ValidNumber = TRUE;
1462                         
1463                         try{
1464                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1465                         }
1466                         
1467                         catch(std::invalid_argument &e){
1468                                 ValidNumber = FALSE;
1469                         }
1471                         if (ValidNumber == TRUE){
1473                                 AddressListPref->erase(*AddressCount);
1474                                 AddressListPref->insert(std::make_pair(*AddressCount, PriorityNumber));
1476                         }
1477                 
1478                 } else {
1479                 
1480                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1481                         
1482                                 if (FirstToken == TRUE){
1483                                 
1484                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1485                                         FirstToken = FALSE;
1486                                 
1487                                 } else {
1488                                 
1489                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1490                                 
1491                                 }
1492                         
1493                         }
1494                 
1495                 }
1496         
1497         }                       
1498         
1499         // Split the address. 
1501         //std::map<int, int>::iterator SLiter;
1502         intPropertyLen = PropertySeg2.Len();
1503         SplitPoints.clear();
1504         SplitLength.clear();
1505         intSplitsFound = 0;
1506         intSplitSize = 0;
1507         intPrevValue = 0;
1508         
1509         for (int i = 0; i <= intPropertyLen; i++){
1511                 intSplitSize++;
1512         
1513                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
1514         
1515                         intSplitsFound++;
1516                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
1517                         
1518                         if (intSplitsFound == 6){ 
1519                         
1520                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1521                                 break; 
1522                                 
1523                         } else {
1524                         
1525                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1526                         
1527                         }
1528                         
1529                         intSplitSize = 0;                                       
1530         
1531                 }
1533         }
1534         
1535         // Split the data into several parts.                   
1536         
1537         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1538         intiter != SplitPoints.end(); ++intiter){
1539                         
1540                 if (intiter->first == 1){
1541                 
1542                         // Deal with PO Box.
1543                         
1544                         SLiter = SplitLength.find(1);
1545                                                                 
1546                         //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
1547                         AddressPOBox = PropertySeg2.Mid(0, SLiter->second);
1548                         intPrevValue = intiter->second;
1549                 
1550                 } else if (intiter->first == 2){
1551                 
1552                         // Deal with extended address.
1553                         
1554                         SLiter = SplitLength.find(2);
1555                         
1556                         AddressExtended = PropertySeg2.Mid(intPrevValue, SLiter->second);
1557                         //txtForename->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1558                         intPrevValue = intiter->second;
1559                 
1560                 } else if (intiter->first == 3){
1561                 
1562                         // Deal with street address.
1563                         
1564                         SLiter = SplitLength.find(3);
1565                                                                 
1566                         AddressStreet = PropertySeg2.Mid(intPrevValue, SLiter->second);
1567                         //txtOtherNames->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1568                         intPrevValue = intiter->second;
1569                 
1570                 } else if (intiter->first == 4){
1571                 
1572                         // Deal with locality
1574                         SLiter = SplitLength.find(4);
1575                         
1576                         AddressLocality = PropertySeg2.Mid(intPrevValue, SLiter->second);
1577                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1578                         intPrevValue = intiter->second;
1579                         
1580                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1581                 
1582                 } else if (intiter->first == 5){
1583                 
1584                         // Deal with region.
1586                         SLiter = SplitLength.find(5);
1587                         
1588                         AddressRegion = PropertySeg2.Mid(intPrevValue, SLiter->second);
1589                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1590                         intPrevValue = intiter->second;
1591                         
1592                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1593                 
1594                 } else if (intiter->first == 6){
1595                 
1596                         // Deal with post code.
1598                         SLiter = SplitLength.find(6);
1599                         
1600                         AddressPostalCode = PropertySeg2.Mid(intPrevValue, SLiter->second);
1601                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1602                         intPrevValue = intiter->second;
1603                         
1604                         // Deal with country.
1605                                                 
1606                         AddressCountry = PropertySeg2.Mid(intPrevValue, wxString::npos);
1607                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1608                         
1609                         break;
1610                 
1611                 }
1612         
1613         }       
1614         
1615         // Add the data to the General/Home/Work address variables.
1616         
1617         CaptureString(&AddressStreet, FALSE); 
1618         CaptureString(&AddressLocality, FALSE);
1619         CaptureString(&AddressRegion, FALSE);
1620         CaptureString(&AddressPostalCode, FALSE);
1621         CaptureString(&AddressCountry, FALSE);
1622                 
1623         if (!PropertyTokens.IsEmpty()){
1624         
1625                 AddressListTokens->insert(std::make_pair(*AddressCount, PropertyTokens));
1626         
1627         }
1629         AddressListCountry->insert(std::make_pair(*AddressCount, AddressCountry));      
1630         AddressList->insert(std::make_pair(*AddressCount, AddressStreet));
1631         AddressListTown->insert(std::make_pair(*AddressCount, AddressLocality));
1632         AddressListCounty->insert(std::make_pair(*AddressCount, AddressRegion));
1633         AddressListPostCode->insert(std::make_pair(*AddressCount, AddressPostalCode));
1635         switch(PropType){
1636                 case PROPERTY_NONE:
1637                         AddressListType->insert(std::make_pair(*AddressCount, wxT("")));
1638                         break;
1639                 case PROPERTY_HOME:
1640                         AddressListType->insert(std::make_pair(*AddressCount, wxT("home")));
1641                         break;
1642                 case PROPERTY_WORK:
1643                         AddressListType->insert(std::make_pair(*AddressCount, wxT("work")));    
1644                         break;
1645         }
1646         
1647         AddressListTokens->insert(std::make_pair(*AddressCount, PropertyTokens));
1651 void ContactDataObject::ProcessEmail(wxString PropertySeg1, wxString PropertySeg2, int *EmailCount){
1653         std::map<int, int> SplitPoints;
1654         std::map<int, int> SplitLength;
1656         int intPrevValue = 7;
1657         int intPref = 0;                        
1658         
1659         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1660         
1661         intPrevValue = 6;
1662         
1663         PropertyType PropType = PROPERTY_NONE;
1664                 
1665         // Look for type before continuing.
1666         
1667         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1668         
1669         std::map<int, wxString> *EmailList = NULL;
1670         std::map<int, wxString> *EmailListType = NULL;
1671         std::map<int, wxString> *EmailListAltID = NULL;
1672         std::map<int, wxString> *EmailListPID = NULL;
1673         std::map<int, wxString> *EmailListTokens = NULL;                
1674         std::map<int, int> *EmailListPref = NULL;
1676         switch(PropType){
1677                 case PROPERTY_NONE:
1678                         EmailList = &GeneralEmailList;
1679                         EmailListType = &GeneralEmailListType;
1680                         EmailListAltID = &GeneralEmailListAltID;
1681                         EmailListPID = &GeneralEmailListPID;
1682                         EmailListTokens = &GeneralEmailListTokens;              
1683                         EmailListPref = &GeneralEmailListPref;  
1684                         break;
1685                 case PROPERTY_HOME:
1686                         EmailList = &HomeEmailList;
1687                         EmailListType = &HomeEmailListType;
1688                         EmailListAltID = &HomeEmailListAltID;
1689                         EmailListPID = &HomeEmailListPID;
1690                         EmailListTokens = &HomeEmailListTokens;         
1691                         EmailListPref = &HomeEmailListPref;     
1692                         break;
1693                 case PROPERTY_WORK:
1694                         EmailList = &BusinessEmailList;
1695                         EmailListType = &BusinessEmailListType;
1696                         EmailListAltID = &BusinessEmailListAltID;
1697                         EmailListPID = &BusinessEmailListPID;
1698                         EmailListTokens = &BusinessEmailListTokens;             
1699                         EmailListPref = &BusinessEmailListPref; 
1700                         break;
1701         }
1702         
1703         intPrevValue = 6;
1704         
1705         std::map<int,int>::iterator SLiter;
1706         wxString PropertyData;
1707         wxString PropertyName;
1708         wxString PropertyValue;
1709         wxString PropertyTokens;
1710         bool FirstToken = TRUE;
1711         
1712         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1713         intiter != SplitPoints.end(); ++intiter){
1714         
1715                 SLiter = SplitLength.find(intiter->first);
1716         
1717                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1718                 
1719                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1720                 PropertyName = PropertyElement.GetNextToken();                          
1721                 PropertyValue = PropertyElement.GetNextToken();
1722                 
1723                 intPrevValue = intiter->second;
1724                 
1725                 CaptureString(&PropertyValue, FALSE);
1726                 
1727                 // Process properties.
1728                 
1729                 if (PropertyName == wxT("ALTID")){
1731                         EmailListAltID->erase(*EmailCount);
1732                         EmailListAltID->insert(std::make_pair(*EmailCount, PropertyValue));
1733                 
1734                 } else if (PropertyName == wxT("PID")){
1736                         EmailListPID->erase(*EmailCount);
1737                         EmailListPID->insert(std::make_pair(*EmailCount, PropertyValue));
1738                 
1739                 } else if (PropertyName == wxT("PREF")){
1740                         
1741                         int PriorityNumber = 0;
1742                         bool ValidNumber = TRUE;
1743                         
1744                         try{
1745                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1746                         }
1747                         
1748                         catch(std::invalid_argument &e){
1749                                 ValidNumber = FALSE;
1750                         }
1752                         if (ValidNumber == TRUE){
1754                                 EmailListPref->erase(*EmailCount);
1755                                 EmailListPref->insert(std::make_pair(*EmailCount, PriorityNumber));
1757                         }
1758                 
1759                 } else {
1760                 
1761                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1762                         
1763                                 if (FirstToken == TRUE){
1764                                 
1765                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1766                                         FirstToken = FALSE;
1767                                 
1768                                 } else {
1769                                 
1770                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1771                                 
1772                                 }
1773                         
1774                         }
1775                 
1776                 }
1777         
1778         }
1779         
1780         EmailList->insert(std::make_pair(*EmailCount, PropertySeg2));
1781         
1782         // Add the name token data.
1783         
1784         if (!PropertyTokens.IsEmpty()){
1785         
1786                 EmailListTokens->insert(std::make_pair(*EmailCount, PropertyTokens));
1787         
1788         }       
1793 void ContactDataObject::ProcessIM(wxString PropertySeg1, wxString PropertySeg2, int *IMCount){
1795         std::map<int, int> SplitPoints;
1796         std::map<int, int> SplitLength;
1798         int intPrevValue = 6;
1799         int intPref = 0;                        
1800         
1801         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1802         
1803         intPrevValue = 5;
1804         
1805         PropertyType PropType = PROPERTY_NONE;
1806                 
1807         // Look for type before continuing.
1808         
1809         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1810         
1811         std::map<int, wxString> *IMList = NULL;
1812         std::map<int, wxString> *IMListType = NULL;
1813         std::map<int, wxString> *IMListAltID = NULL;
1814         std::map<int, wxString> *IMListPID = NULL;
1815         std::map<int, wxString> *IMListTokens = NULL;
1816         std::map<int, wxString> *IMListMediatype = NULL;        
1817         std::map<int, int> *IMListPref = NULL;
1819         switch(PropType){
1820                 case PROPERTY_NONE:
1821                         IMList = &GeneralIMList;
1822                         IMListType = &GeneralIMListType;
1823                         IMListAltID = &GeneralIMListAltID;
1824                         IMListPID = &GeneralIMListPID;
1825                         IMListTokens = &GeneralIMListTokens;
1826                         IMListMediatype = &GeneralIMListMediatype;
1827                         IMListPref = &GeneralIMListPref;        
1828                         break;
1829                 case PROPERTY_HOME:
1830                         IMList = &HomeIMList;
1831                         IMListType = &HomeIMListType;
1832                         IMListAltID = &HomeIMListAltID;
1833                         IMListPID = &HomeIMListPID;
1834                         IMListTokens = &HomeIMListTokens;
1835                         IMListMediatype = &HomeIMListMediatype;         
1836                         IMListPref = &HomeIMListPref;   
1837                         break;
1838                 case PROPERTY_WORK:
1839                         IMList = &BusinessIMList;
1840                         IMListType = &BusinessIMListType;
1841                         IMListAltID = &BusinessIMListAltID;
1842                         IMListPID = &BusinessIMListPID;
1843                         IMListTokens = &BusinessIMListTokens;   
1844                         IMListMediatype = &BusinessIMListMediatype;     
1845                         IMListPref = &BusinessIMListPref;       
1846                         break;
1847         }
1848         
1849         intPrevValue = 5;
1850         
1851         std::map<int,int>::iterator SLiter;
1852         wxString PropertyData;
1853         wxString PropertyName;
1854         wxString PropertyValue;
1855         wxString PropertyTokens;
1856         bool FirstToken = TRUE;
1857         
1858         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1859         intiter != SplitPoints.end(); ++intiter){
1860         
1861                 SLiter = SplitLength.find(intiter->first);
1862         
1863                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1864                 
1865                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1866                 PropertyName = PropertyElement.GetNextToken();                          
1867                 PropertyValue = PropertyElement.GetNextToken();
1868                 
1869                 intPrevValue = intiter->second;
1870                 
1871                 CaptureString(&PropertyValue, FALSE);
1872                 
1873                 // Process properties.
1874                 
1875                 if (PropertyName == wxT("ALTID")){
1877                         IMListAltID->erase(*IMCount);
1878                         IMListAltID->insert(std::make_pair(*IMCount, PropertyValue));
1879                 
1880                 } else if (PropertyName == wxT("PID")){
1882                         IMListPID->erase(*IMCount);
1883                         IMListPID->insert(std::make_pair(*IMCount, PropertyValue));
1884                 
1885                 } else if (PropertyName == wxT("MEDIATYPE")){
1887                         IMListMediatype->erase(*IMCount);
1888                         IMListMediatype->insert(std::make_pair(*IMCount, PropertyValue));
1889                 
1890                 } else if (PropertyName == wxT("PREF")){
1891                         
1892                         int PriorityNumber = 0;
1893                         bool ValidNumber = TRUE;
1894                         
1895                         try{
1896                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1897                         }
1898                         
1899                         catch(std::invalid_argument &e){
1900                                 ValidNumber = FALSE;
1901                         }
1903                         if (ValidNumber == TRUE){
1905                                 IMListPref->erase(*IMCount);
1906                                 IMListPref->insert(std::make_pair(*IMCount, PriorityNumber));
1908                         }
1909                 
1910                 } else {
1911                 
1912                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1913                         
1914                                 if (FirstToken == TRUE){
1915                                 
1916                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1917                                         FirstToken = FALSE;
1918                                 
1919                                 } else {
1920                                 
1921                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1922                                 
1923                                 }
1924                         
1925                         }
1926                 
1927                 }
1928         
1929         }
1930                 
1931         IMList->insert(std::make_pair(*IMCount, PropertySeg2));
1932         
1933         // Add the name token data.
1934         
1935         if (!PropertyTokens.IsEmpty()){
1936         
1937                 IMListTokens->insert(std::make_pair(*IMCount, PropertyTokens));
1938         
1939         }       
1943 void SplitValues(wxString *PropertyLine, 
1944         std::map<int,int> *SplitPoints, 
1945         std::map<int,int> *SplitLength, 
1946         int intSize){
1947         
1948         size_t intPropertyLen = PropertyLine->Len();
1949         int intSplitsFound = 0;
1950         int intSplitSize = 0;
1951         int intSplitSeek = 0;
1952         
1953         for (int i = intSize; i <= intPropertyLen; i++){
1955                 intSplitSize++;
1956         
1957                 if (PropertyLine->Mid(i, 1) == wxT(";") &&
1958                     PropertyLine->Mid((i - 1), 1) != wxT("\\")){
1959            
1960                     if (intSplitsFound == 0){
1961             
1962                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
1963           
1964                     } else {
1965            
1966                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1967             
1968                     }
1969             
1970                     SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
1971             
1972                     intSplitsFound++;
1973                     intSplitSeek = i;
1974                     intSplitSize = 0;
1975             
1976                 }
1978         }
1980         if (intSplitsFound == 0){
1982                 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
1983                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1985         } else {
1987                 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
1988                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1990         }
1994 void CheckType(wxString *PropertySeg1, 
1995         std::map<int,int> *SplitPoints, 
1996         std::map<int,int> *SplitLength, 
1997         int *intPrevValue, 
1998         PropertyType *PropType){
1999         
2000         wxString PropertyData;
2001         wxString PropertyName;
2002         wxString PropertyValue;
2003         std::map<int,int>::iterator SLiter;
2004         
2005         for (std::map<int, int>::iterator intiter = SplitPoints->begin(); 
2006         intiter != SplitPoints->end(); ++intiter){
2007         
2008                 SLiter = SplitLength->find(intiter->first);
2009         
2010                 PropertyData = PropertySeg1->Mid(*intPrevValue, (SLiter->second));
2011                 
2012                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2013                 PropertyName = PropertyElement.GetNextToken();                          
2014                 PropertyValue = PropertyElement.GetNextToken();
2015                 
2016                 *intPrevValue = intiter->second;
2017                 
2018                 if (PropertyName == wxT("TYPE")){
2019                                 
2020                         if (PropertyValue == wxT("work")){
2021                         
2022                                 *PropType = PROPERTY_WORK;
2023                                                         
2024                         } else if (PropertyValue == wxT("home")){
2026                                 *PropType = PROPERTY_HOME;
2027                                                         
2028                         } else {
2029                         
2030                                 *PropType = PROPERTY_NONE;
2031                         
2032                         }
2033                 
2034                         return;
2035                 
2036                 }
2037         
2038         }
2039         
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