Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source code, headers and unit testing for the TEL vCard Property for ContactDat...
[xestiaab/.git] / source / contacteditor / ContactDataObject.cpp
1 // ContactDataObject.cpp - Client Data Object.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "ContactDataObject.h"
21 ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
22         
23         if (!wxFileExists(Filename)){
24         
25                 return CONTACTLOAD_FILEMISSING;
26         
27         }
28         
29         wxFile ContactFile;
30         
31         if (!ContactFile.Open(Filename, wxFile::read, wxS_DEFAULT)){
32         
33                 return CONTACTLOAD_FILEERROR;
34         
35         }
36         
37         // Check that the vCard is a valid vCard 4.0 file.
39         vCard vCard4FormatCheck;
40         
41         vCard4FormatCheck.LoadFile(Filename);
42         
43         if (vCard4FormatCheck.Get("VERSION") != wxT("4.0")){
44         
45                 return CONTACTLOAD_FILEINVALIDFORMAT;
46         
47         }
49         // Check that the vCard meets the base specification.
50         
51         if (!vCard4FormatCheck.MeetBaseSpecification()){
52         
53                 return CONTACTLOAD_FILEBASESPECFAIL;
54         
55         }
56         
57         wxStringTokenizer wSTContactFileLines(vCard4FormatCheck.WriteString(), wxT("\r\n"));
58         
59         std::map<int, wxString> ContactFileLines;
61         int ContactLineSeek = 0;
63         while (wSTContactFileLines.HasMoreTokens() == TRUE){
65                 wxString ContactLine = wSTContactFileLines.GetNextToken();
66                 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
67                 ContactLineSeek++;              
68         
69         }
70         
71         wxString wxSPropertyNextLine;
72         
73         bool ExtraLineSeek = TRUE;
74         bool QuoteMode = FALSE;
75         bool PropertyFind = TRUE;
76         bool KindProcessed = FALSE;
77         bool NameProcessed = FALSE;
78         bool GenderProcessed = FALSE;
79         bool BirthdayProcessed = FALSE;
80         bool AnniversaryProcessed = FALSE;
81         int ContactLineLen = 0;
82         int QuoteBreakPoint = 0;
83         int GroupCount = 0;
84         int FNCount = 0;
85         int NicknameCount = 0;
86         int TimeZoneCount = 0;
87         int AddressCount = 0;
88         int EmailCount = 0;
89         int IMCount = 0;
90         int TelephoneCount = 0;
91         wxString ContactLine;
92         wxString PropertyLine;
93         wxString PropertySeg1;
94         wxString PropertySeg2;
95         wxString PropertyNextLine;
96         wxString Property;
97         
98         for (std::map<int,wxString>::iterator iter = ContactFileLines.begin(); 
99          iter != ContactFileLines.end(); ++iter){
101                 ExtraLineSeek = TRUE;
102                 QuoteMode = FALSE;
103                 PropertyFind = TRUE;
104                 ContactLineLen = 0;
105                 QuoteBreakPoint = 0;
106                 ContactLine.Clear();
107                 PropertyLine.Clear();
108                 PropertySeg1.Clear();
109                 PropertySeg2.Clear();
110                 Property.Clear();
111          
112                 ContactLine = iter->second;
113                 
114                 while (ExtraLineSeek == TRUE){
115                 
116                         // Check if there is extra data on the next line 
117                         // (indicated by space or tab at the start) and add data.
118                 
119                         iter++;
120                         
121                         if (iter == ContactFileLines.end()){
122                         
123                                 iter--;
124                                 break;
125                         
126                         }                       
127                 
128                         PropertyNextLine = iter->second;
129                 
130                         if (PropertyNextLine.Mid(0, 1) == wxT(" ") || PropertyNextLine.Mid(0, 1) == wxT("\t")){
131                 
132                                 PropertyNextLine.Remove(0, 1);
133                                 ContactLine.Append(PropertyNextLine);
134                 
135                         } else {
136                         
137                                 iter--;
138                                 ExtraLineSeek = FALSE;
139                         
140                         }
141                 
142                 }
144                 ContactLineLen = ContactLine.Len();
145                 
146                 // Make sure we are not in quotation mode.
147                 // Make sure colon does not have \ or \\ before it.
148                 
149                 for (int i = 0; i <= ContactLineLen; i++){
150                 
151                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
152                         
153                                 PropertyFind = FALSE;
154                         
155                         } else if (PropertyFind == TRUE){
156                         
157                                 Property.Append(ContactLine.Mid(i, 1));
158                         
159                         }               
160                 
161                         if (ContactLine.Mid(i, 1) == wxT("\"")){
162                         
163                                 if (QuoteMode == TRUE){
164                                 
165                                         QuoteMode = FALSE;
166                                 
167                                 } else {
168                         
169                                         QuoteMode = TRUE;
170                                         
171                                 }
172                         
173                         }
174                         
175                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
176                         
177                                 QuoteBreakPoint = i;
178                                 break;
179                         
180                         }
181                 
182                 }
183                 
184                 // Split that line at the point into two variables (ignore the colon).
185                 
186                 PropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
187                 PropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
188                 
189                  if (Property == wxT("KIND") && KindProcessed == FALSE){
190                                 
191                         ProcessKind(PropertySeg2);
192                 
193                 } else if (Property == wxT("MEMBER")){
195                         ProcessMember(PropertySeg1, PropertySeg2, &GroupCount);
196                         GroupCount++;   
197                 
198                 } else if (Property == wxT("FN")){
199                 
200                         ProcessFN(PropertySeg1, PropertySeg2, &FNCount);
201                         FNCount++;
202                 
203                 } else if (Property == wxT("N") && NameProcessed == FALSE){
204                 
205                         ProcessN(PropertySeg1, PropertySeg2);
206                         NameProcessed = TRUE;
207                 
208                 } else if (Property == wxT("NICKNAME")){
209                                                 
210                         ProcessNickname(PropertySeg1, PropertySeg2, &NicknameCount);
211                         NicknameCount++;
212                         
213                 } else if (Property == wxT("GENDER") && GenderProcessed == FALSE){
214                 
215                         ProcessGender(PropertySeg1, PropertySeg2);
216                         GenderProcessed = TRUE;
217                 
218                 } else if (Property == wxT("BDAY") && BirthdayProcessed == FALSE){
219                 
220                         ProcessBirthday(PropertySeg1, PropertySeg2);
221                         BirthdayProcessed = TRUE;
222                 
223                 } else if (Property == wxT("ANNIVERSARY") && AnniversaryProcessed == FALSE){
224                 
225                         ProcessAnniversary(PropertySeg1, PropertySeg2);
226                         AnniversaryProcessed = TRUE;
227                 
228                 } else if (Property == wxT("TZ")){
229                 
230                         ProcessTimeZone(PropertySeg1, PropertySeg2, &TimeZoneCount);
231                         TimeZoneCount++;
232                 
233                 } else if (Property == wxT("ADR")){
234                 
235                         ProcessAddress(PropertySeg1, PropertySeg2, &AddressCount);
236                         AddressCount++;
237                 
238                 } else if (Property == wxT("EMAIL")){
239                                         
240                         ProcessEmail(PropertySeg1, PropertySeg2, &EmailCount);  
241                         EmailCount++;
242                 
243                 } else if (Property == wxT("IMPP")){
244                 
245                         ProcessIM(PropertySeg1, PropertySeg2, &IMCount);
246                         IMCount++;
247                         
248                 } else if (Property == wxT("TEL")){
249                                 
250                         ProcessTelephone(PropertySeg1, PropertySeg2, &TelephoneCount);
251                         TelephoneCount++;
252                 
253                 }
254                 
255         }
256         
257         return CONTACTLOAD_OK;
261 void ContactDataObject::ProcessKind(wxString KindType){
263         if (KindType == wxT("individual")){
264                         
265                 ContactKind = CONTACTKIND_INDIVIDUAL;
266                         
267         } else if (KindType == wxT("group")){
268                         
269                 ContactKind = CONTACTKIND_GROUP;
270                         
271         } else if (KindType == wxT("org")){
272                         
273                 ContactKind = CONTACTKIND_ORGANISATION;
274                         
275         } else if (KindType == wxT("location")){
276                         
277                 ContactKind = CONTACTKIND_LOCATION;
278                         
279         } else {
280                         
281                 ContactKind = CONTACTKIND_NONE;                 
282         }
286 void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount){
288         std::map<int, int> SplitPoints;
289         std::map<int, int> SplitLength;
291         int intPrevValue = 8;
292         int intPref = 0;                        
293         int intType = 0;
294         
295         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
297         intPrevValue = 7;
298         
299         wxString PropertyName;
300         wxString PropertyValue;
301         wxString PropertyData;
302         wxString PropertyTokens;
303         std::map<int,int>::iterator SLiter;
304         bool FirstToken = TRUE;
305         
306         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
307         intiter != SplitPoints.end(); ++intiter){
308         
309                 SLiter = SplitLength.find(intiter->first);
310         
311                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
312                 
313                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
314                 PropertyName = PropertyElement.GetNextToken();                          
315                 PropertyValue = PropertyElement.GetNextToken();
316                 
317                 intPrevValue = intiter->second;
318                 
319                 CaptureString(&PropertyValue, FALSE);
320         
321                 if (PropertyName == wxT("ALTID")){
323                         GroupsListAltID.erase(*GroupCount);
324                         GroupsListAltID.insert(std::make_pair(*GroupCount, PropertyValue));
325                 
326                 } else if (PropertyName == wxT("PID")){
328                         GroupsListPID.erase(*GroupCount);
329                         GroupsListPID.insert(std::make_pair(*GroupCount, PropertyValue));
330                 
331                 } else if (PropertyName == wxT("PREF")){
333                         int PriorityNumber = 0;
334                         bool ValidNumber = TRUE;
335                         
336                         try{
337                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
338                         }
339                         
340                         catch(std::invalid_argument &e){
341                                 ValidNumber = FALSE;
342                         }
344                         if (ValidNumber == TRUE){
346                                 GroupsListPref.erase(*GroupCount);
347                                 GroupsListPref.insert(std::make_pair(*GroupCount, PriorityNumber));
348                 
349                         }
350                 
351                 } else if (PropertyName == wxT("MEDIATYPE")){
353                         GroupsListMediaType.erase(*GroupCount);
354                         GroupsListMediaType.insert(std::make_pair(*GroupCount, PropertyValue));
355                 
356                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
357                         
358                         if (FirstToken == TRUE){
359                                 
360                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
361                                 FirstToken = FALSE;
362                                 
363                         } else {
364                         
365                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
366                                 
367                         }
368                         
369                 }
370                 
371         }
373         GroupsList.insert(std::make_pair(*GroupCount, PropertySeg2));
375         if (!PropertyTokens.IsEmpty()){
376         
377                 GroupsListTokens.insert(std::make_pair(*GroupCount, PropertyTokens));
378         
379         }
384 void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount){
386         std::map<int, int> SplitPoints;
387         std::map<int, int> SplitLength;
389         int intPrevValue = 4;
390         int intPref = 0;                        
391         int intType = 0;
392         
393         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
395         intPrevValue = 3;
396         
397         wxString PropertyName;
398         wxString PropertyValue;
399         wxString PropertyData;
400         wxString PropertyTokens;
401         std::map<int,int>::iterator SLiter;
402         bool FirstToken = TRUE;
403         
404         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
405         intiter != SplitPoints.end(); ++intiter){
406         
407                 SLiter = SplitLength.find(intiter->first);
408         
409                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
410                 
411                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
412                 PropertyName = PropertyElement.GetNextToken();                          
413                 PropertyValue = PropertyElement.GetNextToken();
414                 
415                 intPrevValue = intiter->second;
416                 
417                 CaptureString(&PropertyValue, FALSE);
418                 
419                 if (PropertyName == wxT("TYPE")){
421                         if (!PropertyValue.IsEmpty() || PropertyValue == wxT("home") ||
422                                 PropertyValue == wxT("work") ){
424                                 FullNamesListType.erase(*FNCount);
425                                 FullNamesListType.insert(std::make_pair(*FNCount, PropertyValue));
426                 
427                         }
428                 
429                 } else if (PropertyName == wxT("LANGUAGE")){
431                         FullNamesListLanguage.erase(*FNCount);
432                         FullNamesListLanguage.insert(std::make_pair(*FNCount, PropertyValue));
433                 
434                 } else if (PropertyName == wxT("ALTID")){
435                 
436                         FullNamesListAltID.erase(*FNCount);
437                         FullNamesListAltID.insert(std::make_pair(*FNCount, PropertyValue));
438                 
439                 } else if (PropertyName == wxT("PID")){
441                         FullNamesListPID.erase(*FNCount);
442                         FullNamesListPID.insert(std::make_pair(*FNCount, PropertyValue));
443                 
444                 } else if (PropertyName == wxT("PREF")){
446                         int PriorityNumber = 0;
447                         bool ValidNumber = TRUE;
448                         
449                         try{
450                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
451                         }
452                         
453                         catch(std::invalid_argument &e){
454                                 ValidNumber = FALSE;
455                         }
457                         if (ValidNumber == TRUE){
459                                 FullNamesListPref.erase(*FNCount);
460                                 FullNamesListPref.insert(std::make_pair(*FNCount, PriorityNumber));
462                         }
463                 
464                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
465                         
466                         if (FirstToken == TRUE){
467                                 
468                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
469                                 FirstToken = FALSE;
470                                 
471                         } else {
472                         
473                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
474                                 
475                         }
476                         
477                 } 
478         
479         }
481         FullNamesList.insert(std::make_pair(*FNCount, PropertySeg2));
483         if (!PropertyTokens.IsEmpty()){
484         
485                 FullNamesListTokens.insert(std::make_pair(*FNCount, PropertyTokens));
486         
487         }
491 void ContactDataObject::ProcessN(wxString PropertySeg1, wxString PropertySeg2){
493         std::map<int, int> SplitPoints;
494         std::map<int, int> SplitLength;
496         int intPrevValue = 3;
497         int intPref = 0;                        
498         int intType = 0;
499         
500         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
501         
502         intPrevValue = 2;
503         
504         wxString PropertyName;
505         wxString PropertyValue;
506         wxString PropertyData;
507         wxString PropertyTokens;
508         std::map<int,int>::iterator SLiter;
509         bool FirstToken = TRUE;
510         
511         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
512         intiter != SplitPoints.end(); ++intiter){
513         
514                 SLiter = SplitLength.find(intiter->first);
515         
516                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
517                 
518                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
519                 PropertyName = PropertyElement.GetNextToken();                          
520                 PropertyValue = PropertyElement.GetNextToken();
521                 
522                 intPrevValue = intiter->second;
523                 
524                 CaptureString(&PropertyValue, FALSE);
525                 
526                 if (PropertyName == wxT("ALTID")){
528                         NameAltID = PropertyValue;
529                 
530                 } else if (PropertyName == wxT("LANGUAGE")){
531                 
532                         NameLanguage = PropertyValue;
533                 
534                 } else if (PropertyName == wxT("SORT-AS")){
535                 
536                         if (PropertyValue.Left(1) == wxT("\"") && PropertyValue.Right(1) == wxT("\"") &&
537                                 PropertyValue.Len() >= 3){
538                                 NameDisplayAs = PropertyValue.Mid(1, (PropertyValue.Len() - 2));
539                         }
540                 
541                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
542                         
543                         if (FirstToken == TRUE){
544                                 
545                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
546                                 FirstToken = FALSE;
547                                 
548                         } else {
549                         
550                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
551                                 
552                         }
553                         
554                 }
555         
556         }
557         
558         // Split the name data.
559         
560         int intSplitSeek = 0;           
561         int intSplitsFound = 0;
562         int intSplitSize = 0;
563         int intPropertyLen = PropertySeg2.Len();
564         
565         std::map<int,wxString> NameValues;
566         intPrevValue = 0;                                       
567         
568         for (int i = 0; i <= intPropertyLen; i++){
569         
570                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
571                         
572                         NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, intSplitSize)));
573                         
574                         intSplitSeek = i;
575                         intSplitSeek++;
576                         
577                         if (intSplitsFound == 4){
578                         
579                                 NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, wxString::npos)));
580                                 break;
581                         
582                         }
583                         
584                         intSplitSize = 0;
585                         continue;
586         
587                 }
588                 
589                 intSplitSize++;
591         }
592         
593         // Split the data into several parts.
594                         
595         for (std::map<int, wxString>::iterator iter = NameValues.begin(); 
596         iter != NameValues.end(); ++iter){
597         
598                 if (iter->first == 1){
599                 
600                         // Deal with family name.
601                         
602                         NameSurname = iter->second;
603                 
604                 } else if (iter->first == 2){
605                 
606                         // Deal with given names.
607                         
608                         NameForename = iter->second;
609                 
610                 } else if (iter->first == 3){
611                 
612                         // Deal with additional names.
613                         
614                         NameOtherNames = iter->second;
615                 
616                 } else if (iter->first == 4){
617                 
618                         // Deal with honorifix prefixes and suffixes.
620                         NameTitle = iter->second;
621                 
622                         iter++;
623                         
624                         if (iter == NameValues.end()){
625                         
626                                 break;
627                         
628                         }
629                 
630                         NameSuffix = iter->second;
631                 
632                 }
633         
634         }
635         
636         // Add the name token data.
637         
638         if (!PropertyTokens.IsEmpty()){
639         
640                 NameTokens = PropertyTokens;
641         
642         }
646 void ContactDataObject::ProcessNickname(wxString PropertySeg1, wxString PropertySeg2, int *NicknameCount){
648         std::map<int, int> SplitPoints;
649         std::map<int, int> SplitLength;
651         int intPrevValue = 10;
652         int intPref = 0;                        
653         
654         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
655         
656         intPrevValue = 9;
657         
658         PropertyType PropType = PROPERTY_NONE;
659         
660         // Look for type before continuing.
661         
662         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
663         
664         intPrevValue = 9;
665         
666         std::map<int, wxString> *NicknamesList = NULL;
667         std::map<int, wxString> *NicknamesListType = NULL;
668         std::map<int, wxString> *NicknamesListLanguage = NULL;
669         std::map<int, wxString> *NicknamesListAltID = NULL;
670         std::map<int, wxString> *NicknamesListPID = NULL;
671         std::map<int, wxString> *NicknamesListTokens = NULL;            
672         std::map<int, int> *NicknamesListPref = NULL;
673         
674         switch(PropType){
675                 case PROPERTY_NONE:
676                         NicknamesList = &GeneralNicknamesList;
677                         NicknamesListType = &GeneralNicknamesListType;
678                         NicknamesListLanguage = &GeneralNicknamesListLanguage;
679                         NicknamesListAltID = &GeneralNicknamesListAltID;
680                         NicknamesListPID = &GeneralNicknamesListPID;
681                         NicknamesListTokens = &GeneralNicknamesListTokens;
682                         NicknamesListPref = &GeneralNicknamesListPref;
683                         break;
684                 case PROPERTY_HOME:
685                         NicknamesList = &HomeNicknamesList;
686                         NicknamesListType = &HomeNicknamesListType;
687                         NicknamesListLanguage = &HomeNicknamesListLanguage;
688                         NicknamesListAltID = &HomeNicknamesListAltID;
689                         NicknamesListPID = &HomeNicknamesListPID;
690                         NicknamesListTokens = &HomeNicknamesListTokens;
691                         NicknamesListPref = &HomeNicknamesListPref;
692                         break;
693                 case PROPERTY_WORK:
694                         NicknamesList = &BusinessNicknamesList;
695                         NicknamesListType = &BusinessNicknamesListType;
696                         NicknamesListLanguage = &BusinessNicknamesListLanguage;
697                         NicknamesListAltID = &BusinessNicknamesListAltID;
698                         NicknamesListPID = &BusinessNicknamesListPID;
699                         NicknamesListTokens = &BusinessNicknamesListTokens;
700                         NicknamesListPref = &BusinessNicknamesListPref;
701                         break;
702         }
703         
704         std::map<int, int>::iterator SLiter;    
705         wxString PropertyData;
706         wxString PropertyName;
707         wxString PropertyValue;
708         wxString PropertyTokens;
709         bool FirstToken = TRUE;
710         
711         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
712         intiter != SplitPoints.end(); ++intiter){
713         
714                 SLiter = SplitLength.find(intiter->first);
715         
716                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
717                 
718                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
719                 PropertyName = PropertyElement.GetNextToken();                          
720                 PropertyValue = PropertyElement.GetNextToken();
721                 
722                 intPrevValue = intiter->second;
723                 
724                 CaptureString(&PropertyValue, FALSE);
725                 
726                 if (PropertyName == wxT("ALTID")){
728                         NicknamesListAltID->erase(*NicknameCount);
729                         NicknamesListAltID->insert(std::make_pair(*NicknameCount, PropertyValue));
730                 
731                 } else if (PropertyName == wxT("PID")){
733                         NicknamesListPID->erase(*NicknameCount);
734                         NicknamesListPID->insert(std::make_pair(*NicknameCount, PropertyValue));        
736                 } else if (PropertyName == wxT("PREF")){
738                         int PriorityNumber = 0;
739                         bool ValidNumber = TRUE;
740                         
741                         try{
742                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
743                         }
744                         
745                         catch(std::invalid_argument &e){
746                                 ValidNumber = FALSE;
747                         }
749                         if (ValidNumber == TRUE){
751                                 NicknamesListPref->erase(*NicknameCount);
752                                 NicknamesListPref->insert(std::make_pair(*NicknameCount, PriorityNumber));
754                         }
755                 
756                 } else if (PropertyName == wxT("LANGUAGE")){
758                         NicknamesListLanguage->erase(*NicknameCount);
759                         NicknamesListLanguage->insert(std::make_pair(*NicknameCount, PropertyValue));   
761                 } else {
762                 
763                         // Something else we don't know about so append
764                         // to the tokens variable.
765                 
766                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
767                 
768                                 if (FirstToken == TRUE){
769                         
770                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
771                                         FirstToken = FALSE;
772                         
773                                 } else {
774                         
775                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
776                         
777                                 }
778                 
779                         }
780                 
781                 }
782                 
783         }
784         
785         NicknamesList->insert(std::make_pair(*NicknameCount, PropertySeg2));
786         
787         // Add the name token data.
788         
789         if (!PropertyTokens.IsEmpty()){
790         
791                 NicknamesListTokens->insert(std::make_pair(*NicknameCount, PropertyTokens));
792         
793         }
797 void ContactDataObject::ProcessGender(wxString PropertySeg1, wxString PropertySeg2){
799         std::map<int, int> SplitPoints;
800         std::map<int, int> SplitLength;
801         std::map<int, int>::iterator SLiter;                    
802         wxString PropertyData;
803         wxString PropertyName;
804         wxString PropertyValue;
805         wxString PropertyTokens;
806         bool FirstToken = TRUE;
807         int intPrevValue = 8;
809         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
811         intPrevValue = 7;                       
812         
813         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
814         intiter != SplitPoints.end(); ++intiter){
815         
816                 SLiter = SplitLength.find(intiter->first);
817         
818                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
819                 
820                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
821                 PropertyName = PropertyElement.GetNextToken();                          
822                 PropertyValue = PropertyElement.GetNextToken();
823                 
824                 intPrevValue = intiter->second;
825                 
826                 // Process properties.
827                 
828                 size_t intPropertyValueLen = PropertyValue.Len();
829                 
830                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
831                         
832                         PropertyValue.Trim();
833                         PropertyValue.RemoveLast();
834                         
835                 }                               
836                 
837                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
838                         
839                         PropertyValue.Remove(0, 1);
840                         
841                 }                               
842                 
843                 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
845                         if (FirstToken == TRUE){
846         
847                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
848                                 FirstToken = FALSE;
849         
850                         } else {
851         
852                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
853         
854                         }
856                 }
857         
858         }       
860         wxStringTokenizer GenderData (PropertySeg2, wxT(";"));
861         
862         wxString GenderComponent;
863         
864         if (GenderData.CountTokens() >= 2){
865         
866                 Gender = GenderData.GetNextToken();
867                 GenderDetails = GenderData.GetString();
868         
869                 CaptureString(&GenderDetails, FALSE);
870                                                 
871         } else {
872         
873                 Gender = GenderData.GetNextToken();
874         
875         }
876         
877         if (!PropertyTokens.IsEmpty()){
878         
879                 GenderTokens = PropertyTokens;
880         
881         }
885 void ContactDataObject::ProcessBirthday(wxString PropertySeg1, wxString PropertySeg2){
887         // Process date. Preserve the remainder in the string.
889         std::map<int, int> SplitPoints;
890         std::map<int, int> SplitLength;
891         std::map<int, int>::iterator SLiter;                    
892         wxString PropertyData;
893         wxString PropertyName;
894         wxString PropertyValue;
895         wxString PropertyTokens;
896         bool BirthdayText = FALSE;
897         int intPrevValue = 6;
899         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
901         intPrevValue = 5;
903         // Look for type before continuing.
905         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
906         intiter != SplitPoints.end(); ++intiter){
908                 SLiter = SplitLength.find(intiter->first);
910                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
911         
912                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
913                 PropertyName = PropertyElement.GetNextToken();                          
914                 PropertyValue = PropertyElement.GetNextToken();
915         
916                 intPrevValue = intiter->second;
917         
918                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){
919         
920                         CaptureString(&PropertySeg2, FALSE);
921                         Birthday = PropertySeg2;
922                         BirthdayText = TRUE;
923         
924                 }
926         }
928         // Setup blank lines for later on.
929         
930         intPrevValue = 5;
931         bool FirstToken = TRUE;
933         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
934         intiter != SplitPoints.end(); ++intiter){
936                 SLiter = SplitLength.find(intiter->first);
938                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
939         
940                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
941                 PropertyName = PropertyElement.GetNextToken();                          
942                 PropertyValue = PropertyElement.GetNextToken();
943         
944                 intPrevValue = intiter->second;
945         
946                 // Process properties.
947         
948                 CaptureString(&PropertyValue, FALSE);
949         
950                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
951                 
952                         PropertyValue.Trim();
953                         PropertyValue.RemoveLast();
954                 
955                 }                               
956         
957                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
958                 
959                         PropertyValue.Remove(0, 1);
960                 
961                 }                               
962         
963                 if (PropertyName == wxT("ALTID")){
965                         BirthdayAltID = PropertyValue;
966         
967                 } else if (PropertyName == wxT("CALSCALE")){
968         
969                         BirthdayCalScale = PropertyValue;
970         
971                 } else if (PropertyName != wxT("VALUE")) {
972         
973                         // Something else we don't know about so append
974                         // to the tokens variable.
975                 
976                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
977                 
978                                 if (FirstToken == TRUE){
979         
980                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
981                                         FirstToken = FALSE;
982         
983                                 } else {
984         
985                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
986         
987                                 }
988                                 
989                         }
990                         
991                 }
993         }       
995         // Add the data to the variables and form.
996         
997         if (BirthdayText == FALSE){
998         
999                 Birthday = PropertySeg2;
1001         }
1002         
1003         if (!PropertyTokens.IsEmpty()){
1004         
1005                 BirthdayTokens = PropertyTokens;
1007         }
1011 void ContactDataObject::ProcessAnniversary(wxString PropertySeg1, wxString PropertySeg2){
1013         // Process date. Preserve the remainder in the string.
1015         std::map<int, int> SplitPoints;
1016         std::map<int, int> SplitLength;
1017         std::map<int, int>::iterator SLiter;                    
1018         wxString PropertyData;
1019         wxString PropertyName;
1020         wxString PropertyValue;
1021         wxString PropertyTokens;
1022         bool AnniversaryText = FALSE;
1023         int intPrevValue = 13;
1025         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1027         intPrevValue = 12;
1029         // Look for type before continuing.
1031         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1032         intiter != SplitPoints.end(); ++intiter){
1034                 SLiter = SplitLength.find(intiter->first);
1036                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1037         
1038                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1039                 PropertyName = PropertyElement.GetNextToken();                          
1040                 PropertyValue = PropertyElement.GetNextToken();
1041         
1042                 intPrevValue = intiter->second;
1043         
1044                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){
1045         
1046                         CaptureString(&PropertySeg2, FALSE);
1047                         Anniversary = PropertySeg2;
1048                         AnniversaryText = TRUE;
1049         
1050                 }
1052         }
1054         // Setup blank lines for later on.
1055         
1056         intPrevValue = 12;
1057         bool FirstToken = TRUE;
1059         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1060         intiter != SplitPoints.end(); ++intiter){
1062                 SLiter = SplitLength.find(intiter->first);
1064                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1065         
1066                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1067                 PropertyName = PropertyElement.GetNextToken();                          
1068                 PropertyValue = PropertyElement.GetNextToken();
1069         
1070                 intPrevValue = intiter->second;
1071         
1072                 // Process properties.
1073         
1074                 CaptureString(&PropertyValue, FALSE);
1075         
1076                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
1077                 
1078                         PropertyValue.Trim();
1079                         PropertyValue.RemoveLast();
1080                 
1081                 }                               
1082         
1083                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
1084                 
1085                         PropertyValue.Remove(0, 1);
1086                 
1087                 }                               
1088         
1089                 if (PropertyName == wxT("ALTID")){
1091                         AnniversaryAltID = PropertyValue;
1092         
1093                 } else if (PropertyName == wxT("CALSCALE")){
1094         
1095                         AnniversaryCalScale = PropertyValue;
1096         
1097                 } else if (PropertyName != wxT("VALUE")) {
1098         
1099                         // Something else we don't know about so append
1100                         // to the tokens variable.
1101                 
1102                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
1103                 
1104                                 if (FirstToken == TRUE){
1105         
1106                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1107                                         FirstToken = FALSE;
1108         
1109                                 } else {
1110         
1111                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1112         
1113                                 }
1114                                 
1115                         }
1116                         
1117                 }
1119         }       
1121         // Add the data to the variables and form.
1122         
1123         if (AnniversaryText == FALSE){
1124         
1125                 Anniversary = PropertySeg2;
1127         }
1128         
1129         if (!PropertyTokens.IsEmpty()){
1130         
1131                 AnniversaryTokens = PropertyTokens;
1133         }
1137 void ContactDataObject::ProcessTimeZone(wxString PropertySeg1, wxString PropertySeg2, int *TimeZoneCount){
1139         std::map<int, int> SplitPoints;
1140         std::map<int, int> SplitLength;
1142         int intPrevValue = 4;
1143         int intPref = 0;                        
1144         
1145         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1146         
1147         intPrevValue = 3;
1148         
1149         PropertyType PropType = PROPERTY_NONE;
1150         
1151         // Look for type before continuing.
1152         
1153         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1154         
1155         intPrevValue = 3;
1156         
1157         std::map<int, wxString> *TZList = NULL;
1158         std::map<int, wxString> *TZListType = NULL;
1159         std::map<int, wxString> *TZListMediatype = NULL;
1160         std::map<int, wxString> *TZListAltID = NULL;
1161         std::map<int, wxString> *TZListPID = NULL;
1162         std::map<int, wxString> *TZListTokens = NULL;           
1163         std::map<int, int> *TZListPref = NULL;
1164         
1165         switch(PropType){
1166                 case PROPERTY_NONE:
1167                         TZList = &GeneralTZList;
1168                         TZListType = &GeneralTZListType;
1169                         TZListMediatype = &GeneralTZListMediatype;
1170                         TZListAltID = &GeneralTZListAltID;
1171                         TZListPID = &GeneralTZListPID;
1172                         TZListTokens = &GeneralTZListTokens;
1173                         TZListPref = &GeneralTZListPref;
1174                         break;
1175                 case PROPERTY_HOME:
1176                         TZList = &HomeTZList;
1177                         TZListType = &HomeTZListType;
1178                         TZListMediatype = &HomeTZListMediatype;
1179                         TZListAltID = &HomeTZListAltID;
1180                         TZListPID = &HomeTZListPID;
1181                         TZListTokens = &HomeTZListTokens;
1182                         TZListPref = &HomeTZListPref;
1183                         break;
1184                 case PROPERTY_WORK:
1185                         TZList = &BusinessTZList;
1186                         TZListType = &BusinessTZListType;
1187                         TZListMediatype = &BusinessTZListMediatype;
1188                         TZListAltID = &BusinessTZListAltID;
1189                         TZListPID = &BusinessTZListPID;
1190                         TZListTokens = &BusinessTZListTokens;
1191                         TZListPref = &BusinessTZListPref;
1192                         break;
1193         }
1194         
1195         std::map<int, int>::iterator SLiter;    
1196         wxString PropertyData;
1197         wxString PropertyName;
1198         wxString PropertyValue;
1199         wxString PropertyTokens;
1200         bool FirstToken = TRUE;
1201         
1202         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1203         intiter != SplitPoints.end(); ++intiter){
1204         
1205                 SLiter = SplitLength.find(intiter->first);
1206         
1207                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1208                 
1209                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1210                 PropertyName = PropertyElement.GetNextToken();                          
1211                 PropertyValue = PropertyElement.GetNextToken();
1212                 
1213                 intPrevValue = intiter->second;
1214                 
1215                 CaptureString(&PropertyValue, FALSE);
1217                 if (PropertyName == wxT("ALTID")){
1219                         TZListAltID->erase(*TimeZoneCount);
1220                         TZListAltID->insert(std::make_pair(*TimeZoneCount, PropertyValue));
1221                 
1222                 } else if (PropertyName == wxT("PID")){
1224                         TZListPID->erase(*TimeZoneCount);
1225                         TZListPID->insert(std::make_pair(*TimeZoneCount, PropertyValue));       
1227                 } else if (PropertyName == wxT("PREF")){
1229                         int PriorityNumber = 0;
1230                         bool ValidNumber = TRUE;
1231                         
1232                         try{
1233                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1234                         }
1235                         
1236                         catch(std::invalid_argument &e){
1237                                 ValidNumber = FALSE;
1238                         }
1240                         if (ValidNumber == TRUE){
1242                                 TZListPref->erase(*TimeZoneCount);
1243                                 TZListPref->insert(std::make_pair(*TimeZoneCount, PriorityNumber));
1245                         }
1246                 
1247                 } else if (PropertyName == wxT("MEDIATYPE")){
1249                         TZListMediatype->erase(*TimeZoneCount);
1250                         TZListMediatype->insert(std::make_pair(*TimeZoneCount, PropertyValue)); 
1252                 } else {
1253                 
1254                         // Something else we don't know about so append
1255                         // to the tokens variable.
1256                 
1257                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1258                 
1259                                 if (FirstToken == TRUE){
1260                         
1261                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1262                                         FirstToken = FALSE;
1263                         
1264                                 } else {
1265                         
1266                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1267                         
1268                                 }
1269                 
1270                         }
1271                 
1272                 }
1273                 
1274         }
1275         
1276         TZList->insert(std::make_pair(*TimeZoneCount, PropertySeg2));
1277         
1278         // Add the name token data.
1279         
1280         if (!PropertyTokens.IsEmpty()){
1281         
1282                 TZListTokens->insert(std::make_pair(*TimeZoneCount, PropertyTokens));
1283         
1284         }
1289 void ContactDataObject::ProcessAddress(wxString PropertySeg1, wxString PropertySeg2, int *AddressCount){
1291         size_t intPropertyLen = PropertySeg1.Len();
1292         std::map<int, int> SplitPoints;
1293         std::map<int, int> SplitLength;
1294         std::map<int, int>::iterator SLiter;                    
1295         wxString PropertyData;
1296         wxString PropertyName;
1297         wxString PropertyValue;
1298         wxString PropertyTokens;
1299         wxString AddressLabel;
1300         wxString AddressLang;
1301         wxString AddressAltID;
1302         wxString AddressPID;
1303         wxString AddressTokens;
1304         wxString AddressGeo;
1305         wxString AddressTimezone;
1306         wxString AddressType;
1307         wxString AddressMediatype;
1308         wxString AddressPOBox;
1309         wxString AddressExtended;
1310         wxString AddressStreet;
1311         wxString AddressLocality;
1312         wxString AddressCity;
1313         wxString AddressRegion;
1314         wxString AddressPostalCode;
1315         wxString AddressCountry;
1316         bool FirstToken = TRUE;                 
1317         int intSplitsFound = 0;
1318         int intSplitSize = 0;
1319         int intPrevValue = 5;
1320         int intPref = 0;                        
1321         int intType = 0;
1322         long ListCtrlIndex;
1323         
1324         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1325         
1326         intPrevValue = 4;
1327         
1328         PropertyType PropType = PROPERTY_NONE;
1329                 
1330         // Look for type before continuing.
1331         
1332         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1333         
1334         intPrevValue = 4;
1335         
1336         std::map<int, wxString> *AddressList = NULL;
1337         std::map<int, wxString> *AddressListTown = NULL;
1338         std::map<int, wxString> *AddressListCounty = NULL;
1339         std::map<int, wxString> *AddressListPostCode = NULL;
1340         std::map<int, wxString> *AddressListCountry = NULL;
1341         std::map<int, wxString> *AddressListLabel = NULL;
1342         std::map<int, wxString> *AddressListLang = NULL;                
1343         std::map<int, wxString> *AddressListAltID = NULL;
1344         std::map<int, wxString> *AddressListPID = NULL;
1345         std::map<int, wxString> *AddressListTokens = NULL;
1346         std::map<int, wxString> *AddressListGeo = NULL;
1347         std::map<int, wxString> *AddressListTimezone = NULL;            
1348         std::map<int, wxString> *AddressListType = NULL;
1349         std::map<int, wxString> *AddressListMediatype = NULL;
1350         std::map<int, int> *AddressListPref = NULL;
1352         switch(PropType){
1353                 case PROPERTY_NONE:
1354                         AddressList = &GeneralAddressList;
1355                         AddressListTown = &GeneralAddressListTown;
1356                         AddressListCounty = &GeneralAddressListCounty;
1357                         AddressListPostCode = &GeneralAddressListPostCode;
1358                         AddressListCountry = &GeneralAddressListCountry;
1359                         AddressListLabel = &GeneralAddressListLabel;
1360                         AddressListLang = &GeneralAddressListLang;              
1361                         AddressListAltID = &GeneralAddressListAltID;
1362                         AddressListPID = &GeneralAddressListPID;
1363                         AddressListTokens = &GeneralAddressListTokens;
1364                         AddressListGeo = &GeneralAddressListGeo;
1365                         AddressListTimezone = &GeneralAddressListTimezone;
1366                         AddressListType = &GeneralAddressListType;
1367                         AddressListMediatype = &GeneralAddressListMediatype;
1368                         AddressListPref = &GeneralAddressListPref;              
1369                         break;
1370                 case PROPERTY_HOME:
1371                         AddressList = &HomeAddressList;
1372                         AddressListTown = &HomeAddressListTown;
1373                         AddressListCounty = &HomeAddressListCounty;
1374                         AddressListPostCode = &HomeAddressListPostCode;
1375                         AddressListCountry = &HomeAddressListCountry;
1376                         AddressListLabel = &HomeAddressListLabel;
1377                         AddressListLang = &HomeAddressListLang;         
1378                         AddressListAltID = &HomeAddressListAltID;
1379                         AddressListPID = &HomeAddressListPID;
1380                         AddressListTokens = &HomeAddressListTokens;
1381                         AddressListGeo = &HomeAddressListGeo;
1382                         AddressListTimezone = &HomeAddressListTimezone;
1383                         AddressListType = &HomeAddressListType;
1384                         AddressListMediatype = &HomeAddressListMediatype;
1385                         AddressListPref = &HomeAddressListPref;
1386                         break;
1387                 case PROPERTY_WORK:
1388                         AddressList = &BusinessAddressList;
1389                         AddressListTown = &BusinessAddressListTown;
1390                         AddressListCounty = &BusinessAddressListCounty;
1391                         AddressListPostCode = &BusinessAddressListPostCode;
1392                         AddressListCountry = &BusinessAddressListCountry;
1393                         AddressListLabel = &BusinessAddressListLabel;
1394                         AddressListLang = &BusinessAddressListLang;             
1395                         AddressListAltID = &BusinessAddressListAltID;
1396                         AddressListPID = &BusinessAddressListPID;
1397                         AddressListTokens = &BusinessAddressListTokens;
1398                         AddressListGeo = &BusinessAddressListGeo;
1399                         AddressListTimezone = &BusinessAddressListTimezone;
1400                         AddressListType = &BusinessAddressListType;
1401                         AddressListMediatype = &BusinessAddressListMediatype;
1402                         AddressListPref = &BusinessAddressListPref;
1403                         break;
1404         }
1405         
1406         intPrevValue = 4;
1407         
1408         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1409         intiter != SplitPoints.end(); ++intiter){
1410         
1411                 SLiter = SplitLength.find(intiter->first);
1412         
1413                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1414                 
1415                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1416                 PropertyName = PropertyElement.GetNextToken();                          
1417                 PropertyValue = PropertyElement.GetNextToken();
1418                 
1419                 intPrevValue = intiter->second;
1420                 
1421                 CaptureString(&PropertyValue, FALSE);
1422                 
1423                 // Process properties.
1424                 
1425                 if (PropertyName == wxT("LABEL")){
1426                 
1427                         AddressListLabel->erase(*AddressCount);
1428                         AddressListLabel->insert(std::make_pair(*AddressCount, PropertyValue));
1429                                 
1430                 } else if (PropertyName == wxT("LANGUAGE")){
1431                 
1432                         AddressListLang->erase(*AddressCount);
1433                         AddressListLang->insert(std::make_pair(*AddressCount, PropertyValue));                  
1434                 
1435                 } else if (PropertyName == wxT("ALTID")){
1437                         AddressListAltID->erase(*AddressCount);
1438                         AddressListAltID->insert(std::make_pair(*AddressCount, PropertyValue));
1439                 
1440                 } else if (PropertyName == wxT("PID")){
1442                         AddressListPID->erase(*AddressCount);
1443                         AddressListPID->insert(std::make_pair(*AddressCount, PropertyValue));
1444                 
1445                 } else if (PropertyName == wxT("GEO")){
1446                 
1447                         AddressListGeo->erase(*AddressCount);
1448                         AddressListGeo->insert(std::make_pair(*AddressCount, PropertyValue));
1449                 
1450                 } else if (PropertyName == wxT("TZ")){
1452                         AddressListTimezone->erase(*AddressCount);
1453                         AddressListTimezone->insert(std::make_pair(*AddressCount, PropertyValue));
1454                 
1455                 } else if (PropertyName == wxT("MEDIATYPE")){
1457                         AddressListMediatype->erase(*AddressCount);
1458                         AddressListMediatype->insert(std::make_pair(*AddressCount, PropertyValue));
1459                 
1460                 } else if (PropertyName == wxT("PREF")){
1461                         
1462                         int PriorityNumber = 0;
1463                         bool ValidNumber = TRUE;
1464                         
1465                         try{
1466                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1467                         }
1468                         
1469                         catch(std::invalid_argument &e){
1470                                 ValidNumber = FALSE;
1471                         }
1473                         if (ValidNumber == TRUE){
1475                                 AddressListPref->erase(*AddressCount);
1476                                 AddressListPref->insert(std::make_pair(*AddressCount, PriorityNumber));
1478                         }
1479                 
1480                 } else {
1481                 
1482                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1483                         
1484                                 if (FirstToken == TRUE){
1485                                 
1486                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1487                                         FirstToken = FALSE;
1488                                 
1489                                 } else {
1490                                 
1491                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1492                                 
1493                                 }
1494                         
1495                         }
1496                 
1497                 }
1498         
1499         }                       
1500         
1501         // Split the address. 
1503         //std::map<int, int>::iterator SLiter;
1504         intPropertyLen = PropertySeg2.Len();
1505         SplitPoints.clear();
1506         SplitLength.clear();
1507         intSplitsFound = 0;
1508         intSplitSize = 0;
1509         intPrevValue = 0;
1510         
1511         for (int i = 0; i <= intPropertyLen; i++){
1513                 intSplitSize++;
1514         
1515                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
1516         
1517                         intSplitsFound++;
1518                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
1519                         
1520                         if (intSplitsFound == 6){ 
1521                         
1522                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1523                                 break; 
1524                                 
1525                         } else {
1526                         
1527                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1528                         
1529                         }
1530                         
1531                         intSplitSize = 0;                                       
1532         
1533                 }
1535         }
1536         
1537         // Split the data into several parts.                   
1538         
1539         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1540         intiter != SplitPoints.end(); ++intiter){
1541                         
1542                 if (intiter->first == 1){
1543                 
1544                         // Deal with PO Box.
1545                         
1546                         SLiter = SplitLength.find(1);
1547                                                                 
1548                         //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
1549                         AddressPOBox = PropertySeg2.Mid(0, SLiter->second);
1550                         intPrevValue = intiter->second;
1551                 
1552                 } else if (intiter->first == 2){
1553                 
1554                         // Deal with extended address.
1555                         
1556                         SLiter = SplitLength.find(2);
1557                         
1558                         AddressExtended = PropertySeg2.Mid(intPrevValue, SLiter->second);
1559                         //txtForename->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1560                         intPrevValue = intiter->second;
1561                 
1562                 } else if (intiter->first == 3){
1563                 
1564                         // Deal with street address.
1565                         
1566                         SLiter = SplitLength.find(3);
1567                                                                 
1568                         AddressStreet = PropertySeg2.Mid(intPrevValue, SLiter->second);
1569                         //txtOtherNames->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1570                         intPrevValue = intiter->second;
1571                 
1572                 } else if (intiter->first == 4){
1573                 
1574                         // Deal with locality
1576                         SLiter = SplitLength.find(4);
1577                         
1578                         AddressLocality = PropertySeg2.Mid(intPrevValue, SLiter->second);
1579                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1580                         intPrevValue = intiter->second;
1581                         
1582                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1583                 
1584                 } else if (intiter->first == 5){
1585                 
1586                         // Deal with region.
1588                         SLiter = SplitLength.find(5);
1589                         
1590                         AddressRegion = PropertySeg2.Mid(intPrevValue, SLiter->second);
1591                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1592                         intPrevValue = intiter->second;
1593                         
1594                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1595                 
1596                 } else if (intiter->first == 6){
1597                 
1598                         // Deal with post code.
1600                         SLiter = SplitLength.find(6);
1601                         
1602                         AddressPostalCode = PropertySeg2.Mid(intPrevValue, SLiter->second);
1603                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1604                         intPrevValue = intiter->second;
1605                         
1606                         // Deal with country.
1607                                                 
1608                         AddressCountry = PropertySeg2.Mid(intPrevValue, wxString::npos);
1609                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1610                         
1611                         break;
1612                 
1613                 }
1614         
1615         }       
1616         
1617         // Add the data to the General/Home/Work address variables.
1618         
1619         CaptureString(&AddressStreet, FALSE); 
1620         CaptureString(&AddressLocality, FALSE);
1621         CaptureString(&AddressRegion, FALSE);
1622         CaptureString(&AddressPostalCode, FALSE);
1623         CaptureString(&AddressCountry, FALSE);
1624                 
1625         if (!PropertyTokens.IsEmpty()){
1626         
1627                 AddressListTokens->insert(std::make_pair(*AddressCount, PropertyTokens));
1628         
1629         }
1631         AddressListCountry->insert(std::make_pair(*AddressCount, AddressCountry));      
1632         AddressList->insert(std::make_pair(*AddressCount, AddressStreet));
1633         AddressListTown->insert(std::make_pair(*AddressCount, AddressLocality));
1634         AddressListCounty->insert(std::make_pair(*AddressCount, AddressRegion));
1635         AddressListPostCode->insert(std::make_pair(*AddressCount, AddressPostalCode));
1637         switch(PropType){
1638                 case PROPERTY_NONE:
1639                         AddressListType->insert(std::make_pair(*AddressCount, wxT("")));
1640                         break;
1641                 case PROPERTY_HOME:
1642                         AddressListType->insert(std::make_pair(*AddressCount, wxT("home")));
1643                         break;
1644                 case PROPERTY_WORK:
1645                         AddressListType->insert(std::make_pair(*AddressCount, wxT("work")));    
1646                         break;
1647         }
1648         
1649         AddressListTokens->insert(std::make_pair(*AddressCount, PropertyTokens));
1653 void ContactDataObject::ProcessEmail(wxString PropertySeg1, wxString PropertySeg2, int *EmailCount){
1655         std::map<int, int> SplitPoints;
1656         std::map<int, int> SplitLength;
1658         int intPrevValue = 7;
1659         int intPref = 0;                        
1660         
1661         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1662         
1663         intPrevValue = 6;
1664         
1665         PropertyType PropType = PROPERTY_NONE;
1666                 
1667         // Look for type before continuing.
1668         
1669         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1670         
1671         std::map<int, wxString> *EmailList = NULL;
1672         std::map<int, wxString> *EmailListType = NULL;
1673         std::map<int, wxString> *EmailListAltID = NULL;
1674         std::map<int, wxString> *EmailListPID = NULL;
1675         std::map<int, wxString> *EmailListTokens = NULL;                
1676         std::map<int, int> *EmailListPref = NULL;
1678         switch(PropType){
1679                 case PROPERTY_NONE:
1680                         EmailList = &GeneralEmailList;
1681                         EmailListType = &GeneralEmailListType;
1682                         EmailListAltID = &GeneralEmailListAltID;
1683                         EmailListPID = &GeneralEmailListPID;
1684                         EmailListTokens = &GeneralEmailListTokens;              
1685                         EmailListPref = &GeneralEmailListPref;  
1686                         break;
1687                 case PROPERTY_HOME:
1688                         EmailList = &HomeEmailList;
1689                         EmailListType = &HomeEmailListType;
1690                         EmailListAltID = &HomeEmailListAltID;
1691                         EmailListPID = &HomeEmailListPID;
1692                         EmailListTokens = &HomeEmailListTokens;         
1693                         EmailListPref = &HomeEmailListPref;     
1694                         break;
1695                 case PROPERTY_WORK:
1696                         EmailList = &BusinessEmailList;
1697                         EmailListType = &BusinessEmailListType;
1698                         EmailListAltID = &BusinessEmailListAltID;
1699                         EmailListPID = &BusinessEmailListPID;
1700                         EmailListTokens = &BusinessEmailListTokens;             
1701                         EmailListPref = &BusinessEmailListPref; 
1702                         break;
1703         }
1704         
1705         intPrevValue = 6;
1706         
1707         std::map<int,int>::iterator SLiter;
1708         wxString PropertyData;
1709         wxString PropertyName;
1710         wxString PropertyValue;
1711         wxString PropertyTokens;
1712         bool FirstToken = TRUE;
1713         
1714         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1715         intiter != SplitPoints.end(); ++intiter){
1716         
1717                 SLiter = SplitLength.find(intiter->first);
1718         
1719                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1720                 
1721                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1722                 PropertyName = PropertyElement.GetNextToken();                          
1723                 PropertyValue = PropertyElement.GetNextToken();
1724                 
1725                 intPrevValue = intiter->second;
1726                 
1727                 CaptureString(&PropertyValue, FALSE);
1728                 
1729                 // Process properties.
1730                 
1731                 if (PropertyName == wxT("ALTID")){
1733                         EmailListAltID->erase(*EmailCount);
1734                         EmailListAltID->insert(std::make_pair(*EmailCount, PropertyValue));
1735                 
1736                 } else if (PropertyName == wxT("PID")){
1738                         EmailListPID->erase(*EmailCount);
1739                         EmailListPID->insert(std::make_pair(*EmailCount, PropertyValue));
1740                 
1741                 } else if (PropertyName == wxT("PREF")){
1742                         
1743                         int PriorityNumber = 0;
1744                         bool ValidNumber = TRUE;
1745                         
1746                         try{
1747                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1748                         }
1749                         
1750                         catch(std::invalid_argument &e){
1751                                 ValidNumber = FALSE;
1752                         }
1754                         if (ValidNumber == TRUE){
1756                                 EmailListPref->erase(*EmailCount);
1757                                 EmailListPref->insert(std::make_pair(*EmailCount, PriorityNumber));
1759                         }
1760                 
1761                 } else {
1762                 
1763                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1764                         
1765                                 if (FirstToken == TRUE){
1766                                 
1767                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1768                                         FirstToken = FALSE;
1769                                 
1770                                 } else {
1771                                 
1772                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1773                                 
1774                                 }
1775                         
1776                         }
1777                 
1778                 }
1779         
1780         }
1781         
1782         EmailList->insert(std::make_pair(*EmailCount, PropertySeg2));
1783         
1784         // Add the name token data.
1785         
1786         if (!PropertyTokens.IsEmpty()){
1787         
1788                 EmailListTokens->insert(std::make_pair(*EmailCount, PropertyTokens));
1789         
1790         }       
1795 void ContactDataObject::ProcessIM(wxString PropertySeg1, wxString PropertySeg2, int *IMCount){
1797         std::map<int, int> SplitPoints;
1798         std::map<int, int> SplitLength;
1800         int intPrevValue = 6;
1801         int intPref = 0;                        
1802         
1803         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1804         
1805         intPrevValue = 5;
1806         
1807         PropertyType PropType = PROPERTY_NONE;
1808                 
1809         // Look for type before continuing.
1810         
1811         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1812         
1813         std::map<int, wxString> *IMList = NULL;
1814         std::map<int, wxString> *IMListType = NULL;
1815         std::map<int, wxString> *IMListAltID = NULL;
1816         std::map<int, wxString> *IMListPID = NULL;
1817         std::map<int, wxString> *IMListTokens = NULL;
1818         std::map<int, wxString> *IMListMediatype = NULL;        
1819         std::map<int, int> *IMListPref = NULL;
1821         switch(PropType){
1822                 case PROPERTY_NONE:
1823                         IMList = &GeneralIMList;
1824                         IMListType = &GeneralIMListType;
1825                         IMListAltID = &GeneralIMListAltID;
1826                         IMListPID = &GeneralIMListPID;
1827                         IMListTokens = &GeneralIMListTokens;
1828                         IMListMediatype = &GeneralIMListMediatype;
1829                         IMListPref = &GeneralIMListPref;        
1830                         break;
1831                 case PROPERTY_HOME:
1832                         IMList = &HomeIMList;
1833                         IMListType = &HomeIMListType;
1834                         IMListAltID = &HomeIMListAltID;
1835                         IMListPID = &HomeIMListPID;
1836                         IMListTokens = &HomeIMListTokens;
1837                         IMListMediatype = &HomeIMListMediatype;         
1838                         IMListPref = &HomeIMListPref;   
1839                         break;
1840                 case PROPERTY_WORK:
1841                         IMList = &BusinessIMList;
1842                         IMListType = &BusinessIMListType;
1843                         IMListAltID = &BusinessIMListAltID;
1844                         IMListPID = &BusinessIMListPID;
1845                         IMListTokens = &BusinessIMListTokens;   
1846                         IMListMediatype = &BusinessIMListMediatype;     
1847                         IMListPref = &BusinessIMListPref;       
1848                         break;
1849         }
1850         
1851         intPrevValue = 5;
1852         
1853         std::map<int,int>::iterator SLiter;
1854         wxString PropertyData;
1855         wxString PropertyName;
1856         wxString PropertyValue;
1857         wxString PropertyTokens;
1858         bool FirstToken = TRUE;
1859         
1860         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1861         intiter != SplitPoints.end(); ++intiter){
1862         
1863                 SLiter = SplitLength.find(intiter->first);
1864         
1865                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1866                 
1867                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1868                 PropertyName = PropertyElement.GetNextToken();                          
1869                 PropertyValue = PropertyElement.GetNextToken();
1870                 
1871                 intPrevValue = intiter->second;
1872                 
1873                 CaptureString(&PropertyValue, FALSE);
1874                 
1875                 // Process properties.
1876                 
1877                 if (PropertyName == wxT("ALTID")){
1879                         IMListAltID->erase(*IMCount);
1880                         IMListAltID->insert(std::make_pair(*IMCount, PropertyValue));
1881                 
1882                 } else if (PropertyName == wxT("PID")){
1884                         IMListPID->erase(*IMCount);
1885                         IMListPID->insert(std::make_pair(*IMCount, PropertyValue));
1886                 
1887                 } else if (PropertyName == wxT("MEDIATYPE")){
1889                         IMListMediatype->erase(*IMCount);
1890                         IMListMediatype->insert(std::make_pair(*IMCount, PropertyValue));
1891                 
1892                 } else if (PropertyName == wxT("PREF")){
1893                         
1894                         int PriorityNumber = 0;
1895                         bool ValidNumber = TRUE;
1896                         
1897                         try{
1898                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1899                         }
1900                         
1901                         catch(std::invalid_argument &e){
1902                                 ValidNumber = FALSE;
1903                         }
1905                         if (ValidNumber == TRUE){
1907                                 IMListPref->erase(*IMCount);
1908                                 IMListPref->insert(std::make_pair(*IMCount, PriorityNumber));
1910                         }
1911                 
1912                 } else {
1913                 
1914                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1915                         
1916                                 if (FirstToken == TRUE){
1917                                 
1918                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1919                                         FirstToken = FALSE;
1920                                 
1921                                 } else {
1922                                 
1923                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1924                                 
1925                                 }
1926                         
1927                         }
1928                 
1929                 }
1930         
1931         }
1932                 
1933         IMList->insert(std::make_pair(*IMCount, PropertySeg2));
1934         
1935         // Add the name token data.
1936         
1937         if (!PropertyTokens.IsEmpty()){
1938         
1939                 IMListTokens->insert(std::make_pair(*IMCount, PropertyTokens));
1940         
1941         }       
1945 void ContactDataObject::ProcessTelephone(wxString PropertySeg1, wxString PropertySeg2, int *TelephoneCount){
1947         std::map<int, int> SplitPoints;
1948         std::map<int, int> SplitLength;
1949         std::map<int, int>::iterator SLiter;
1950         
1951         int intPref = 0;
1952         
1953         PropertyType PropType = PROPERTY_NONE;
1954                 
1955         // Look for type before continuing.
1956         
1957         wxString TelTypeUI;
1958         wxString TelTypeDetail;
1959         wxString PropertyData;
1960         wxString PropertyName;
1961         wxString PropertyValue;
1962         wxString PropertyTokens;
1963         
1964         std::map<int,int> TypeSplitPoints;
1965         std::map<int,int> TypeSplitLength;
1966         std::map<int,int>::iterator TSLiter;
1967         
1968         int intSplitSize = 0;
1969         int intSplitsFound = 0;
1970         int intSplitPoint = 0;
1971         int intType = 0;
1972         int intPrevValue = 5;
1973                 
1974         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1975         
1976         intPrevValue = 4;
1977         
1978         // Look for type before continuing.
1979         
1980         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1981         intiter != SplitPoints.end(); ++intiter){
1982         
1983                 SLiter = SplitLength.find(intiter->first);
1984         
1985                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1986                 
1987                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1988                 PropertyName = PropertyElement.GetNextToken();                          
1989                 PropertyValue = PropertyElement.GetNextToken();
1990                 
1991                 intPrevValue = intiter->second;
1993                 if (PropertyName == wxT("TYPE")){
1994                 
1995                         // Process each value in type and translate each
1996                         // part.
1997                 
1998                         // Strip out the quotes if they are there.
1999                 
2000                         size_t intPropertyValueLen = PropertyValue.Len();
2001                 
2002                         if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
2003                         
2004                                 PropertyValue.Trim();
2005                                 PropertyValue.RemoveLast();
2006                         
2007                         }                               
2008                 
2009                         if (PropertyValue.Mid(0, 1) == wxT("\"")){
2010                         
2011                                 PropertyValue.Remove(0, 1);
2012                         
2013                         }
2014                         
2015                         TelTypeDetail = PropertyValue;
2016                         
2017                         intSplitSize = 0;
2018                         intSplitsFound = 0;
2019                         intSplitPoint = 0;
2020                         
2021                         for (int i = 0; i <= intPropertyValueLen; i++){
2022         
2023                                 intSplitSize++;
2024         
2025                                 if (PropertyValue.Mid(i, 1) == wxT(",") && PropertyValue.Mid((i - 1), 1) != wxT("\\")){
2026         
2027                                         if (intSplitsFound == 0){
2029                                                 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
2030                                                 TypeSplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
2031                         
2032                                         } else {
2033                         
2034                                                 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
2035                                                 TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
2036                         
2037                                         }                       
2039                                         intSplitsFound++;
2040                                         i++;
2041                                         intSplitPoint = i;
2042                                         intSplitSize = 0;
2043         
2044                                 }
2045         
2046                         }
2047                         
2048                         TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
2049                         TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));                                                           
2050                 
2051                         int intTypeSeek = 0;
2052                 
2053                         for (std::map<int, int>::iterator typeiter = TypeSplitPoints.begin(); 
2054                         typeiter != TypeSplitPoints.end(); ++typeiter){
2055                         
2056                                 wxString TypePropertyName;
2057                                 
2058                                 TSLiter = TypeSplitLength.find(typeiter->first);
2059                                 
2060                                 TypePropertyName = PropertyValue.Mid(typeiter->second, TSLiter->second);
2061                                 
2062                                 if (intTypeSeek == 0){
2063                                 
2064                                 
2065                                 } else {
2066                                                                                 
2067                                         TelTypeUI.Append(wxT(","));                                                     
2068                                 
2069                                 }
2070                         
2071                                 if (TypePropertyName == wxT("home")){
2072                                 
2073                                         PropType = PROPERTY_HOME;
2074                                 
2075                                 } else if (TypePropertyName == wxT("work")){
2076                                 
2077                                         PropType = PROPERTY_WORK;
2078                                                                         
2079                                 }
2080                                 
2081                                 
2082                                 if (TypePropertyName == wxT("text")){
2083                                 
2084                                         TelTypeUI.Append(_("text"));
2085                                         intTypeSeek++;
2086                                 
2087                                 } else if (TypePropertyName == wxT("voice")){
2088                                 
2089                                         TelTypeUI.Append(_("voice"));
2090                                         intTypeSeek++;
2091                                 
2092                                 } else if (TypePropertyName == wxT("fax")){
2093                                 
2094                                         TelTypeUI.Append(_("fax"));
2095                                         intTypeSeek++;
2096                                 
2097                                 } else if (TypePropertyName == wxT("cell")){
2098                                 
2099                                         TelTypeUI.Append(_("mobile"));
2100                                         intTypeSeek++;
2101                                 
2102                                 } else if (TypePropertyName == wxT("video")){
2103                                 
2104                                         TelTypeUI.Append(_("video"));
2105                                         intTypeSeek++;
2106                                 
2107                                 } else if (TypePropertyName == wxT("pager")){
2108                                 
2109                                         TelTypeUI.Append(_("pager"));
2110                                         intTypeSeek++;
2111                                 
2112                                 } else if (TypePropertyName == wxT("textphone")){
2113                                 
2114                                         TelTypeUI.Append(_("textphone"));
2115                                         intTypeSeek++;
2116                                 
2117                                 }
2118                         
2119                         }
2120                 
2121                 }
2122                 
2123         }
2124         
2125         std::map<int, wxString> *TelephoneList = NULL;
2126         std::map<int, wxString> *TelephoneListType = NULL;
2127         std::map<int, wxString> *TelephoneListAltID = NULL;
2128         std::map<int, wxString> *TelephoneListPID = NULL;
2129         std::map<int, wxString> *TelephoneListTokens = NULL;
2130         std::map<int, wxString> *TelephoneListTypeInfo = NULL;  
2131         std::map<int, int> *TelephoneListPref = NULL;
2133         switch(PropType){
2134                 case PROPERTY_NONE:
2135                         TelephoneList = &GeneralTelephoneList;
2136                         TelephoneListType = &GeneralTelephoneListType;
2137                         TelephoneListAltID = &GeneralTelephoneListAltID;
2138                         TelephoneListPID = &GeneralTelephoneListPID;
2139                         TelephoneListTokens = &GeneralTelephoneListTokens;
2140                         TelephoneListTypeInfo = &GeneralTelephoneListTypeInfo;
2141                         TelephoneListPref = &GeneralTelephoneListPref;  
2142                         break;
2143                 case PROPERTY_HOME:
2144                         TelephoneList = &HomeTelephoneList;
2145                         TelephoneListType = &HomeTelephoneListType;
2146                         TelephoneListAltID = &HomeTelephoneListAltID;
2147                         TelephoneListPID = &HomeTelephoneListPID;
2148                         TelephoneListTokens = &HomeTelephoneListTokens;
2149                         TelephoneListTypeInfo = &HomeTelephoneListTypeInfo;     
2150                         TelephoneListPref = &HomeTelephoneListPref;     
2151                         break;
2152                 case PROPERTY_WORK:
2153                         TelephoneList = &BusinessTelephoneList;
2154                         TelephoneListType = &BusinessTelephoneListType;
2155                         TelephoneListAltID = &BusinessTelephoneListAltID;
2156                         TelephoneListPID = &BusinessTelephoneListPID;
2157                         TelephoneListTokens = &BusinessTelephoneListTokens;     
2158                         TelephoneListTypeInfo = &BusinessTelephoneListTypeInfo; 
2159                         TelephoneListPref = &BusinessTelephoneListPref; 
2160                         break;
2161         }
2162                 
2163         // Process the properties.
2164         
2165         bool FirstToken = TRUE;
2166         
2167         intPrevValue = 5;
2168         SplitPoints.clear();
2169         SplitLength.clear();
2171         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
2173         intPrevValue = 4;
2174         
2175         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
2176         intiter != SplitPoints.end(); ++intiter){
2177         
2178                 SLiter = SplitLength.find(intiter->first);
2179         
2180                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2181                 
2182                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2183                 PropertyName = PropertyElement.GetNextToken();                          
2184                 PropertyValue = PropertyElement.GetNextToken();
2185                 
2186                 intPrevValue = intiter->second;
2187                 
2188                 CaptureString(&PropertyValue, FALSE);
2189                 
2190                 // Process properties.
2191                 
2192                 if (PropertyName == wxT("ALTID")){
2194                         TelephoneListAltID->erase(*TelephoneCount);
2195                         TelephoneListAltID->insert(std::make_pair(*TelephoneCount, PropertyValue));
2196                 
2197                 } else if (PropertyName == wxT("PID")){
2199                         TelephoneListPID->erase(*TelephoneCount);
2200                         TelephoneListPID->insert(std::make_pair(*TelephoneCount, PropertyValue));
2201                 
2202                 } else if (PropertyName == wxT("PREF")){
2203                         
2204                         int PriorityNumber = 0;
2205                         bool ValidNumber = TRUE;
2206                         
2207                         try{
2208                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
2209                         }
2210                         
2211                         catch(std::invalid_argument &e){
2212                                 ValidNumber = FALSE;
2213                         }
2215                         if (ValidNumber == TRUE){
2217                                 TelephoneListPref->erase(*TelephoneCount);
2218                                 TelephoneListPref->insert(std::make_pair(*TelephoneCount, PriorityNumber));
2220                         }
2221                 
2222                 } else {
2223                 
2224                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
2225                         
2226                                 if (FirstToken == TRUE){
2227                                 
2228                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
2229                                         FirstToken = FALSE;
2230                                 
2231                                 } else {
2232                                 
2233                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
2234                                 
2235                                 }
2236                         
2237                         }
2238                 
2239                 }
2240         
2241         }
2242                 
2243         TelephoneList->insert(std::make_pair(*TelephoneCount, PropertySeg2));
2244         TelephoneListTypeInfo->insert(std::make_pair(*TelephoneCount, TelTypeUI));
2245         
2246         // Add the name token data.
2247         
2248         if (!PropertyTokens.IsEmpty()){
2249         
2250                 TelephoneListTokens->insert(std::make_pair(*TelephoneCount, PropertyTokens));
2251         
2252         }
2256 void SplitValues(wxString *PropertyLine, 
2257         std::map<int,int> *SplitPoints, 
2258         std::map<int,int> *SplitLength, 
2259         int intSize){
2260         
2261         size_t intPropertyLen = PropertyLine->Len();
2262         int intSplitsFound = 0;
2263         int intSplitSize = 0;
2264         int intSplitSeek = 0;
2265         
2266         for (int i = intSize; i <= intPropertyLen; i++){
2268                 intSplitSize++;
2269         
2270                 if (PropertyLine->Mid(i, 1) == wxT(";") &&
2271                     PropertyLine->Mid((i - 1), 1) != wxT("\\")){
2272            
2273                     if (intSplitsFound == 0){
2274             
2275                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
2276           
2277                     } else {
2278            
2279                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
2280             
2281                     }
2282             
2283                     SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
2284             
2285                     intSplitsFound++;
2286                     intSplitSeek = i;
2287                     intSplitSize = 0;
2288             
2289                 }
2291         }
2293         if (intSplitsFound == 0){
2295                 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
2296                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
2298         } else {
2300                 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
2301                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
2303         }
2307 void CheckType(wxString *PropertySeg1, 
2308         std::map<int,int> *SplitPoints, 
2309         std::map<int,int> *SplitLength, 
2310         int *intPrevValue, 
2311         PropertyType *PropType){
2312         
2313         wxString PropertyData;
2314         wxString PropertyName;
2315         wxString PropertyValue;
2316         std::map<int,int>::iterator SLiter;
2317         
2318         for (std::map<int, int>::iterator intiter = SplitPoints->begin(); 
2319         intiter != SplitPoints->end(); ++intiter){
2320         
2321                 SLiter = SplitLength->find(intiter->first);
2322         
2323                 PropertyData = PropertySeg1->Mid(*intPrevValue, (SLiter->second));
2324                 
2325                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2326                 PropertyName = PropertyElement.GetNextToken();                          
2327                 PropertyValue = PropertyElement.GetNextToken();
2328                 
2329                 *intPrevValue = intiter->second;
2330                 
2331                 if (PropertyName == wxT("TYPE")){
2332                                 
2333                         if (PropertyValue == wxT("work")){
2334                         
2335                                 *PropType = PROPERTY_WORK;
2336                                                         
2337                         } else if (PropertyValue == wxT("home")){
2339                                 *PropType = PROPERTY_HOME;
2340                                                         
2341                         } else {
2342                         
2343                                 *PropType = PROPERTY_NONE;
2344                         
2345                         }
2346                 
2347                         return;
2348                 
2349                 }
2350         
2351         }
2352         
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