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