Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
13c869fe301fc338860c85a31cb28f1a03332558
[xestiaab/.git] / source / contacteditor / ContactDataObject.cpp
1 // ContactDataObject.cpp - Client Data Object.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "ContactDataObject.h"
21 ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
22         
23         if (!wxFileExists(Filename)){
24         
25                 return CONTACTLOAD_FILEMISSING;
26         
27         }
28         
29         wxFile ContactFile;
30         
31         if (!ContactFile.Open(Filename, wxFile::read, wxS_DEFAULT)){
32         
33                 return CONTACTLOAD_FILEERROR;
34         
35         }
36         
37         // Check that the vCard is a valid vCard 4.0 file.
39         vCard vCard4FormatCheck;
40         
41         vCard4FormatCheck.LoadFile(Filename);
42         
43         if (vCard4FormatCheck.Get("VERSION") != wxT("4.0")){
44         
45                 return CONTACTLOAD_FILEINVALIDFORMAT;
46         
47         }
49         // Check that the vCard meets the base specification.
50         
51         if (!vCard4FormatCheck.MeetBaseSpecification()){
52         
53                 return CONTACTLOAD_FILEBASESPECFAIL;
54         
55         }
56         
57         wxStringTokenizer wSTContactFileLines(vCard4FormatCheck.WriteString(), wxT("\r\n"));
58         
59         std::map<int, wxString> ContactFileLines;
61         int ContactLineSeek = 0;
63         while (wSTContactFileLines.HasMoreTokens() == TRUE){
65                 wxString ContactLine = wSTContactFileLines.GetNextToken();
66                 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
67                 ContactLineSeek++;              
68         
69         }
70         
71         wxString wxSPropertyNextLine;
72         
73         bool ExtraLineSeek = TRUE;
74         bool QuoteMode = FALSE;
75         bool PropertyFind = TRUE;
76         bool KindProcessed = FALSE;
77         bool NameProcessed = FALSE;
78         bool GenderProcessed = FALSE;
79         bool BirthdayProcessed = FALSE;
80         bool AnniversaryProcessed = FALSE;
81         int ContactLineLen = 0;
82         int QuoteBreakPoint = 0;
83         int GroupCount = 0;
84         int FNCount = 0;
85         int NicknameCount = 0;
86         int TimeZoneCount = 0;
87         int AddressCount = 0;
88         int EmailCount = 0;
89         int IMCount = 0;
90         int TelephoneCount = 0;
91         int LanguageCount = 0;
92         int GeographicCount = 0;
93         int RelatedCount = 0;
94         int URLCount = 0;
95         wxString ContactLine;
96         wxString PropertyLine;
97         wxString PropertySeg1;
98         wxString PropertySeg2;
99         wxString PropertyNextLine;
100         wxString Property;
101         
102         for (std::map<int,wxString>::iterator iter = ContactFileLines.begin(); 
103          iter != ContactFileLines.end(); ++iter){
105                 ExtraLineSeek = TRUE;
106                 QuoteMode = FALSE;
107                 PropertyFind = TRUE;
108                 ContactLineLen = 0;
109                 QuoteBreakPoint = 0;
110                 ContactLine.Clear();
111                 PropertyLine.Clear();
112                 PropertySeg1.Clear();
113                 PropertySeg2.Clear();
114                 Property.Clear();
115          
116                 ContactLine = iter->second;
117                 
118                 while (ExtraLineSeek == TRUE){
119                 
120                         // Check if there is extra data on the next line 
121                         // (indicated by space or tab at the start) and add data.
122                 
123                         iter++;
124                         
125                         if (iter == ContactFileLines.end()){
126                         
127                                 iter--;
128                                 break;
129                         
130                         }                       
131                 
132                         PropertyNextLine = iter->second;
133                 
134                         if (PropertyNextLine.Mid(0, 1) == wxT(" ") || PropertyNextLine.Mid(0, 1) == wxT("\t")){
135                 
136                                 PropertyNextLine.Remove(0, 1);
137                                 ContactLine.Append(PropertyNextLine);
138                 
139                         } else {
140                         
141                                 iter--;
142                                 ExtraLineSeek = FALSE;
143                         
144                         }
145                 
146                 }
148                 ContactLineLen = ContactLine.Len();
149                 
150                 // Make sure we are not in quotation mode.
151                 // Make sure colon does not have \ or \\ before it.
152                 
153                 for (int i = 0; i <= ContactLineLen; i++){
154                 
155                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
156                         
157                                 PropertyFind = FALSE;
158                         
159                         } else if (PropertyFind == TRUE){
160                         
161                                 Property.Append(ContactLine.Mid(i, 1));
162                         
163                         }               
164                 
165                         if (ContactLine.Mid(i, 1) == wxT("\"")){
166                         
167                                 if (QuoteMode == TRUE){
168                                 
169                                         QuoteMode = FALSE;
170                                 
171                                 } else {
172                         
173                                         QuoteMode = TRUE;
174                                         
175                                 }
176                         
177                         }
178                         
179                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
180                         
181                                 QuoteBreakPoint = i;
182                                 break;
183                         
184                         }
185                 
186                 }
187                 
188                 // Split that line at the point into two variables (ignore the colon).
189                 
190                 PropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
191                 PropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
192                 
193                  if (Property == wxT("KIND") && KindProcessed == FALSE){
194                                 
195                         ProcessKind(PropertySeg2);
196                 
197                 } else if (Property == wxT("MEMBER")){
199                         ProcessMember(PropertySeg1, PropertySeg2, &GroupCount);
200                         GroupCount++;   
201                 
202                 } else if (Property == wxT("FN")){
203                 
204                         ProcessFN(PropertySeg1, PropertySeg2, &FNCount);
205                         FNCount++;
206                 
207                 } else if (Property == wxT("N") && NameProcessed == FALSE){
208                 
209                         ProcessN(PropertySeg1, PropertySeg2);
210                         NameProcessed = TRUE;
211                 
212                 } else if (Property == wxT("NICKNAME")){
213                                                 
214                         ProcessNickname(PropertySeg1, PropertySeg2, &NicknameCount);
215                         NicknameCount++;
216                         
217                 } else if (Property == wxT("GENDER") && GenderProcessed == FALSE){
218                 
219                         ProcessGender(PropertySeg1, PropertySeg2);
220                         GenderProcessed = TRUE;
221                 
222                 } else if (Property == wxT("BDAY") && BirthdayProcessed == FALSE){
223                 
224                         ProcessBirthday(PropertySeg1, PropertySeg2);
225                         BirthdayProcessed = TRUE;
226                 
227                 } else if (Property == wxT("ANNIVERSARY") && AnniversaryProcessed == FALSE){
228                 
229                         ProcessAnniversary(PropertySeg1, PropertySeg2);
230                         AnniversaryProcessed = TRUE;
231                 
232                 } else if (Property == wxT("TZ")){
233                 
234                         ProcessTimeZone(PropertySeg1, PropertySeg2, &TimeZoneCount);
235                         TimeZoneCount++;
236                 
237                 } else if (Property == wxT("ADR")){
238                 
239                         ProcessAddress(PropertySeg1, PropertySeg2, &AddressCount);
240                         AddressCount++;
241                 
242                 } else if (Property == wxT("EMAIL")){
243                                         
244                         ProcessEmail(PropertySeg1, PropertySeg2, &EmailCount);  
245                         EmailCount++;
246                 
247                 } else if (Property == wxT("IMPP")){
248                 
249                         ProcessIM(PropertySeg1, PropertySeg2, &IMCount);
250                         IMCount++;
251                         
252                 } else if (Property == wxT("TEL")){
253                                 
254                         ProcessTelephone(PropertySeg1, PropertySeg2, &TelephoneCount);
255                         TelephoneCount++;
256                 
257                 } else if (Property == wxT("LANG")){
258                 
259                         // See frmContactEditor-LoadLanguage.cpp
260                         
261                         ProcessLanguage(PropertySeg1, PropertySeg2, &LanguageCount);
262                         LanguageCount++;
263                 
264                 } else if (Property == wxT("GEO")){
265                 
266                         // See frmContactEditor-LoadGeo.cpp
267                         
268                         ProcessGeographic(PropertySeg1, PropertySeg2, &GeographicCount);        
269                         GeographicCount++;
270                 
271                 } else if (Property == wxT("RELATED")){
272                         
273                         // See fromContactEditor-LoadRelated.cpp
274                         
275                         ProcessRelated(PropertySeg1, PropertySeg2, &RelatedCount);              
276                         RelatedCount++;
277                         
278                 } else if (Property == wxT("URL")){
280                         // See frmContactEditor-LoadURL.cpp
281                 
282                         ProcessURL(PropertySeg1, PropertySeg2, &URLCount);
283                         URLCount++;
284                 
285                 }
286                 
287         }
288         
289         return CONTACTLOAD_OK;
293 void ContactDataObject::ProcessKind(wxString KindType){
295         if (KindType == wxT("individual")){
296                         
297                 ContactKind = CONTACTKIND_INDIVIDUAL;
298                         
299         } else if (KindType == wxT("group")){
300                         
301                 ContactKind = CONTACTKIND_GROUP;
302                         
303         } else if (KindType == wxT("org")){
304                         
305                 ContactKind = CONTACTKIND_ORGANISATION;
306                         
307         } else if (KindType == wxT("location")){
308                         
309                 ContactKind = CONTACTKIND_LOCATION;
310                         
311         } else {
312                         
313                 ContactKind = CONTACTKIND_NONE;                 
314         }
318 void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount){
320         std::map<int, int> SplitPoints;
321         std::map<int, int> SplitLength;
323         int intPrevValue = 8;
324         int intPref = 0;                        
325         int intType = 0;
326         
327         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
329         intPrevValue = 7;
330         
331         wxString PropertyName;
332         wxString PropertyValue;
333         wxString PropertyData;
334         wxString PropertyTokens;
335         std::map<int,int>::iterator SLiter;
336         bool FirstToken = TRUE;
337         
338         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
339         intiter != SplitPoints.end(); ++intiter){
340         
341                 SLiter = SplitLength.find(intiter->first);
342         
343                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
344                 
345                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
346                 PropertyName = PropertyElement.GetNextToken();                          
347                 PropertyValue = PropertyElement.GetNextToken();
348                 
349                 intPrevValue = intiter->second;
350                 
351                 CaptureString(&PropertyValue, FALSE);
352         
353                 if (PropertyName == wxT("ALTID")){
355                         GroupsListAltID.erase(*GroupCount);
356                         GroupsListAltID.insert(std::make_pair(*GroupCount, PropertyValue));
357                 
358                 } else if (PropertyName == wxT("PID")){
360                         GroupsListPID.erase(*GroupCount);
361                         GroupsListPID.insert(std::make_pair(*GroupCount, PropertyValue));
362                 
363                 } else if (PropertyName == wxT("PREF")){
365                         int PriorityNumber = 0;
366                         bool ValidNumber = TRUE;
367                         
368                         try{
369                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
370                         }
371                         
372                         catch(std::invalid_argument &e){
373                                 ValidNumber = FALSE;
374                         }
376                         if (ValidNumber == TRUE){
378                                 GroupsListPref.erase(*GroupCount);
379                                 GroupsListPref.insert(std::make_pair(*GroupCount, PriorityNumber));
380                 
381                         }
382                 
383                 } else if (PropertyName == wxT("MEDIATYPE")){
385                         GroupsListMediaType.erase(*GroupCount);
386                         GroupsListMediaType.insert(std::make_pair(*GroupCount, PropertyValue));
387                 
388                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
389                         
390                         if (FirstToken == TRUE){
391                                 
392                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
393                                 FirstToken = FALSE;
394                                 
395                         } else {
396                         
397                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
398                                 
399                         }
400                         
401                 }
402                 
403         }
405         GroupsList.insert(std::make_pair(*GroupCount, PropertySeg2));
407         if (!PropertyTokens.IsEmpty()){
408         
409                 GroupsListTokens.insert(std::make_pair(*GroupCount, PropertyTokens));
410         
411         }
416 void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount){
418         std::map<int, int> SplitPoints;
419         std::map<int, int> SplitLength;
421         int intPrevValue = 4;
422         int intPref = 0;                        
423         int intType = 0;
424         
425         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
427         intPrevValue = 3;
428         
429         wxString PropertyName;
430         wxString PropertyValue;
431         wxString PropertyData;
432         wxString PropertyTokens;
433         std::map<int,int>::iterator SLiter;
434         bool FirstToken = TRUE;
435         
436         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
437         intiter != SplitPoints.end(); ++intiter){
438         
439                 SLiter = SplitLength.find(intiter->first);
440         
441                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
442                 
443                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
444                 PropertyName = PropertyElement.GetNextToken();                          
445                 PropertyValue = PropertyElement.GetNextToken();
446                 
447                 intPrevValue = intiter->second;
448                 
449                 CaptureString(&PropertyValue, FALSE);
450                 
451                 if (PropertyName == wxT("TYPE")){
453                         if (!PropertyValue.IsEmpty() || PropertyValue == wxT("home") ||
454                                 PropertyValue == wxT("work") ){
456                                 FullNamesListType.erase(*FNCount);
457                                 FullNamesListType.insert(std::make_pair(*FNCount, PropertyValue));
458                 
459                         }
460                 
461                 } else if (PropertyName == wxT("LANGUAGE")){
463                         FullNamesListLanguage.erase(*FNCount);
464                         FullNamesListLanguage.insert(std::make_pair(*FNCount, PropertyValue));
465                 
466                 } else if (PropertyName == wxT("ALTID")){
467                 
468                         FullNamesListAltID.erase(*FNCount);
469                         FullNamesListAltID.insert(std::make_pair(*FNCount, PropertyValue));
470                 
471                 } else if (PropertyName == wxT("PID")){
473                         FullNamesListPID.erase(*FNCount);
474                         FullNamesListPID.insert(std::make_pair(*FNCount, PropertyValue));
475                 
476                 } else if (PropertyName == wxT("PREF")){
478                         int PriorityNumber = 0;
479                         bool ValidNumber = TRUE;
480                         
481                         try{
482                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
483                         }
484                         
485                         catch(std::invalid_argument &e){
486                                 ValidNumber = FALSE;
487                         }
489                         if (ValidNumber == TRUE){
491                                 FullNamesListPref.erase(*FNCount);
492                                 FullNamesListPref.insert(std::make_pair(*FNCount, PriorityNumber));
494                         }
495                 
496                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
497                         
498                         if (FirstToken == TRUE){
499                                 
500                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
501                                 FirstToken = FALSE;
502                                 
503                         } else {
504                         
505                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
506                                 
507                         }
508                         
509                 } 
510         
511         }
513         FullNamesList.insert(std::make_pair(*FNCount, PropertySeg2));
515         if (!PropertyTokens.IsEmpty()){
516         
517                 FullNamesListTokens.insert(std::make_pair(*FNCount, PropertyTokens));
518         
519         }
523 void ContactDataObject::ProcessN(wxString PropertySeg1, wxString PropertySeg2){
525         std::map<int, int> SplitPoints;
526         std::map<int, int> SplitLength;
528         int intPrevValue = 3;
529         int intPref = 0;                        
530         int intType = 0;
531         
532         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
533         
534         intPrevValue = 2;
535         
536         wxString PropertyName;
537         wxString PropertyValue;
538         wxString PropertyData;
539         wxString PropertyTokens;
540         std::map<int,int>::iterator SLiter;
541         bool FirstToken = TRUE;
542         
543         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
544         intiter != SplitPoints.end(); ++intiter){
545         
546                 SLiter = SplitLength.find(intiter->first);
547         
548                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
549                 
550                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
551                 PropertyName = PropertyElement.GetNextToken();                          
552                 PropertyValue = PropertyElement.GetNextToken();
553                 
554                 intPrevValue = intiter->second;
555                 
556                 CaptureString(&PropertyValue, FALSE);
557                 
558                 if (PropertyName == wxT("ALTID")){
560                         NameAltID = PropertyValue;
561                 
562                 } else if (PropertyName == wxT("LANGUAGE")){
563                 
564                         NameLanguage = PropertyValue;
565                 
566                 } else if (PropertyName == wxT("SORT-AS")){
567                 
568                         if (PropertyValue.Left(1) == wxT("\"") && PropertyValue.Right(1) == wxT("\"") &&
569                                 PropertyValue.Len() >= 3){
570                                 NameDisplayAs = PropertyValue.Mid(1, (PropertyValue.Len() - 2));
571                         }
572                 
573                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
574                         
575                         if (FirstToken == TRUE){
576                                 
577                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
578                                 FirstToken = FALSE;
579                                 
580                         } else {
581                         
582                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
583                                 
584                         }
585                         
586                 }
587         
588         }
589         
590         // Split the name data.
591         
592         int intSplitSeek = 0;           
593         int intSplitsFound = 0;
594         int intSplitSize = 0;
595         int intPropertyLen = PropertySeg2.Len();
596         
597         std::map<int,wxString> NameValues;
598         intPrevValue = 0;                                       
599         
600         for (int i = 0; i <= intPropertyLen; i++){
601         
602                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
603                         
604                         NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, intSplitSize)));
605                         
606                         intSplitSeek = i;
607                         intSplitSeek++;
608                         
609                         if (intSplitsFound == 4){
610                         
611                                 NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, wxString::npos)));
612                                 break;
613                         
614                         }
615                         
616                         intSplitSize = 0;
617                         continue;
618         
619                 }
620                 
621                 intSplitSize++;
623         }
624         
625         // Split the data into several parts.
626                         
627         for (std::map<int, wxString>::iterator iter = NameValues.begin(); 
628         iter != NameValues.end(); ++iter){
629         
630                 if (iter->first == 1){
631                 
632                         // Deal with family name.
633                         
634                         NameSurname = iter->second;
635                 
636                 } else if (iter->first == 2){
637                 
638                         // Deal with given names.
639                         
640                         NameForename = iter->second;
641                 
642                 } else if (iter->first == 3){
643                 
644                         // Deal with additional names.
645                         
646                         NameOtherNames = iter->second;
647                 
648                 } else if (iter->first == 4){
649                 
650                         // Deal with honorifix prefixes and suffixes.
652                         NameTitle = iter->second;
653                 
654                         iter++;
655                         
656                         if (iter == NameValues.end()){
657                         
658                                 break;
659                         
660                         }
661                 
662                         NameSuffix = iter->second;
663                 
664                 }
665         
666         }
667         
668         // Add the name token data.
669         
670         if (!PropertyTokens.IsEmpty()){
671         
672                 NameTokens = PropertyTokens;
673         
674         }
678 void ContactDataObject::ProcessNickname(wxString PropertySeg1, wxString PropertySeg2, int *NicknameCount){
680         std::map<int, int> SplitPoints;
681         std::map<int, int> SplitLength;
683         int intPrevValue = 10;
684         int intPref = 0;                        
685         
686         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
687         
688         intPrevValue = 9;
689         
690         PropertyType PropType = PROPERTY_NONE;
691         
692         // Look for type before continuing.
693         
694         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
695         
696         intPrevValue = 9;
697         
698         std::map<int, wxString> *NicknamesList = NULL;
699         std::map<int, wxString> *NicknamesListType = NULL;
700         std::map<int, wxString> *NicknamesListLanguage = NULL;
701         std::map<int, wxString> *NicknamesListAltID = NULL;
702         std::map<int, wxString> *NicknamesListPID = NULL;
703         std::map<int, wxString> *NicknamesListTokens = NULL;            
704         std::map<int, int> *NicknamesListPref = NULL;
705         
706         switch(PropType){
707                 case PROPERTY_NONE:
708                         NicknamesList = &GeneralNicknamesList;
709                         NicknamesListType = &GeneralNicknamesListType;
710                         NicknamesListLanguage = &GeneralNicknamesListLanguage;
711                         NicknamesListAltID = &GeneralNicknamesListAltID;
712                         NicknamesListPID = &GeneralNicknamesListPID;
713                         NicknamesListTokens = &GeneralNicknamesListTokens;
714                         NicknamesListPref = &GeneralNicknamesListPref;
715                         break;
716                 case PROPERTY_HOME:
717                         NicknamesList = &HomeNicknamesList;
718                         NicknamesListType = &HomeNicknamesListType;
719                         NicknamesListLanguage = &HomeNicknamesListLanguage;
720                         NicknamesListAltID = &HomeNicknamesListAltID;
721                         NicknamesListPID = &HomeNicknamesListPID;
722                         NicknamesListTokens = &HomeNicknamesListTokens;
723                         NicknamesListPref = &HomeNicknamesListPref;
724                         break;
725                 case PROPERTY_WORK:
726                         NicknamesList = &BusinessNicknamesList;
727                         NicknamesListType = &BusinessNicknamesListType;
728                         NicknamesListLanguage = &BusinessNicknamesListLanguage;
729                         NicknamesListAltID = &BusinessNicknamesListAltID;
730                         NicknamesListPID = &BusinessNicknamesListPID;
731                         NicknamesListTokens = &BusinessNicknamesListTokens;
732                         NicknamesListPref = &BusinessNicknamesListPref;
733                         break;
734         }
735         
736         std::map<int, int>::iterator SLiter;    
737         wxString PropertyData;
738         wxString PropertyName;
739         wxString PropertyValue;
740         wxString PropertyTokens;
741         bool FirstToken = TRUE;
742         
743         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
744         intiter != SplitPoints.end(); ++intiter){
745         
746                 SLiter = SplitLength.find(intiter->first);
747         
748                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
749                 
750                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
751                 PropertyName = PropertyElement.GetNextToken();                          
752                 PropertyValue = PropertyElement.GetNextToken();
753                 
754                 intPrevValue = intiter->second;
755                 
756                 CaptureString(&PropertyValue, FALSE);
757                 
758                 if (PropertyName == wxT("ALTID")){
760                         NicknamesListAltID->erase(*NicknameCount);
761                         NicknamesListAltID->insert(std::make_pair(*NicknameCount, PropertyValue));
762                 
763                 } else if (PropertyName == wxT("PID")){
765                         NicknamesListPID->erase(*NicknameCount);
766                         NicknamesListPID->insert(std::make_pair(*NicknameCount, PropertyValue));        
768                 } else if (PropertyName == wxT("PREF")){
770                         int PriorityNumber = 0;
771                         bool ValidNumber = TRUE;
772                         
773                         try{
774                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
775                         }
776                         
777                         catch(std::invalid_argument &e){
778                                 ValidNumber = FALSE;
779                         }
781                         if (ValidNumber == TRUE){
783                                 NicknamesListPref->erase(*NicknameCount);
784                                 NicknamesListPref->insert(std::make_pair(*NicknameCount, PriorityNumber));
786                         }
787                 
788                 } else if (PropertyName == wxT("LANGUAGE")){
790                         NicknamesListLanguage->erase(*NicknameCount);
791                         NicknamesListLanguage->insert(std::make_pair(*NicknameCount, PropertyValue));   
793                 } else {
794                 
795                         // Something else we don't know about so append
796                         // to the tokens variable.
797                 
798                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
799                 
800                                 if (FirstToken == TRUE){
801                         
802                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
803                                         FirstToken = FALSE;
804                         
805                                 } else {
806                         
807                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
808                         
809                                 }
810                 
811                         }
812                 
813                 }
814                 
815         }
816         
817         NicknamesList->insert(std::make_pair(*NicknameCount, PropertySeg2));
818         
819         // Add the name token data.
820         
821         if (!PropertyTokens.IsEmpty()){
822         
823                 NicknamesListTokens->insert(std::make_pair(*NicknameCount, PropertyTokens));
824         
825         }
829 void ContactDataObject::ProcessGender(wxString PropertySeg1, wxString PropertySeg2){
831         std::map<int, int> SplitPoints;
832         std::map<int, int> SplitLength;
833         std::map<int, int>::iterator SLiter;                    
834         wxString PropertyData;
835         wxString PropertyName;
836         wxString PropertyValue;
837         wxString PropertyTokens;
838         bool FirstToken = TRUE;
839         int intPrevValue = 8;
841         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
843         intPrevValue = 7;                       
844         
845         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
846         intiter != SplitPoints.end(); ++intiter){
847         
848                 SLiter = SplitLength.find(intiter->first);
849         
850                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
851                 
852                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
853                 PropertyName = PropertyElement.GetNextToken();                          
854                 PropertyValue = PropertyElement.GetNextToken();
855                 
856                 intPrevValue = intiter->second;
857                 
858                 // Process properties.
859                 
860                 size_t intPropertyValueLen = PropertyValue.Len();
861                 
862                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
863                         
864                         PropertyValue.Trim();
865                         PropertyValue.RemoveLast();
866                         
867                 }                               
868                 
869                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
870                         
871                         PropertyValue.Remove(0, 1);
872                         
873                 }                               
874                 
875                 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
877                         if (FirstToken == TRUE){
878         
879                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
880                                 FirstToken = FALSE;
881         
882                         } else {
883         
884                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
885         
886                         }
888                 }
889         
890         }       
892         wxStringTokenizer GenderData (PropertySeg2, wxT(";"));
893         
894         wxString GenderComponent;
895         
896         if (GenderData.CountTokens() >= 2){
897         
898                 Gender = GenderData.GetNextToken();
899                 GenderDetails = GenderData.GetString();
900         
901                 CaptureString(&GenderDetails, FALSE);
902                                                 
903         } else {
904         
905                 Gender = GenderData.GetNextToken();
906         
907         }
908         
909         if (!PropertyTokens.IsEmpty()){
910         
911                 GenderTokens = PropertyTokens;
912         
913         }
917 void ContactDataObject::ProcessBirthday(wxString PropertySeg1, wxString PropertySeg2){
919         // Process date. Preserve the remainder in the string.
921         std::map<int, int> SplitPoints;
922         std::map<int, int> SplitLength;
923         std::map<int, int>::iterator SLiter;                    
924         wxString PropertyData;
925         wxString PropertyName;
926         wxString PropertyValue;
927         wxString PropertyTokens;
928         bool BirthdayText = FALSE;
929         int intPrevValue = 6;
931         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
933         intPrevValue = 5;
935         // Look for type before continuing.
937         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
938         intiter != SplitPoints.end(); ++intiter){
940                 SLiter = SplitLength.find(intiter->first);
942                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
943         
944                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
945                 PropertyName = PropertyElement.GetNextToken();                          
946                 PropertyValue = PropertyElement.GetNextToken();
947         
948                 intPrevValue = intiter->second;
949         
950                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){
951         
952                         CaptureString(&PropertySeg2, FALSE);
953                         Birthday = PropertySeg2;
954                         BirthdayText = TRUE;
955         
956                 }
958         }
960         // Setup blank lines for later on.
961         
962         intPrevValue = 5;
963         bool FirstToken = TRUE;
965         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
966         intiter != SplitPoints.end(); ++intiter){
968                 SLiter = SplitLength.find(intiter->first);
970                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
971         
972                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
973                 PropertyName = PropertyElement.GetNextToken();                          
974                 PropertyValue = PropertyElement.GetNextToken();
975         
976                 intPrevValue = intiter->second;
977         
978                 // Process properties.
979         
980                 CaptureString(&PropertyValue, FALSE);
981         
982                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
983                 
984                         PropertyValue.Trim();
985                         PropertyValue.RemoveLast();
986                 
987                 }                               
988         
989                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
990                 
991                         PropertyValue.Remove(0, 1);
992                 
993                 }                               
994         
995                 if (PropertyName == wxT("ALTID")){
997                         BirthdayAltID = PropertyValue;
998         
999                 } else if (PropertyName == wxT("CALSCALE")){
1000         
1001                         BirthdayCalScale = PropertyValue;
1002         
1003                 } else if (PropertyName != wxT("VALUE")) {
1004         
1005                         // Something else we don't know about so append
1006                         // to the tokens variable.
1007                 
1008                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
1009                 
1010                                 if (FirstToken == TRUE){
1011         
1012                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1013                                         FirstToken = FALSE;
1014         
1015                                 } else {
1016         
1017                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1018         
1019                                 }
1020                                 
1021                         }
1022                         
1023                 }
1025         }       
1027         // Add the data to the variables and form.
1028         
1029         if (BirthdayText == FALSE){
1030         
1031                 Birthday = PropertySeg2;
1033         }
1034         
1035         if (!PropertyTokens.IsEmpty()){
1036         
1037                 BirthdayTokens = PropertyTokens;
1039         }
1043 void ContactDataObject::ProcessAnniversary(wxString PropertySeg1, wxString PropertySeg2){
1045         // Process date. Preserve the remainder in the string.
1047         std::map<int, int> SplitPoints;
1048         std::map<int, int> SplitLength;
1049         std::map<int, int>::iterator SLiter;                    
1050         wxString PropertyData;
1051         wxString PropertyName;
1052         wxString PropertyValue;
1053         wxString PropertyTokens;
1054         bool AnniversaryText = FALSE;
1055         int intPrevValue = 13;
1057         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1059         intPrevValue = 12;
1061         // Look for type before continuing.
1063         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1064         intiter != SplitPoints.end(); ++intiter){
1066                 SLiter = SplitLength.find(intiter->first);
1068                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1069         
1070                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1071                 PropertyName = PropertyElement.GetNextToken();                          
1072                 PropertyValue = PropertyElement.GetNextToken();
1073         
1074                 intPrevValue = intiter->second;
1075         
1076                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){
1077         
1078                         CaptureString(&PropertySeg2, FALSE);
1079                         Anniversary = PropertySeg2;
1080                         AnniversaryText = TRUE;
1081         
1082                 }
1084         }
1086         // Setup blank lines for later on.
1087         
1088         intPrevValue = 12;
1089         bool FirstToken = TRUE;
1091         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1092         intiter != SplitPoints.end(); ++intiter){
1094                 SLiter = SplitLength.find(intiter->first);
1096                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1097         
1098                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1099                 PropertyName = PropertyElement.GetNextToken();                          
1100                 PropertyValue = PropertyElement.GetNextToken();
1101         
1102                 intPrevValue = intiter->second;
1103         
1104                 // Process properties.
1105         
1106                 CaptureString(&PropertyValue, FALSE);
1107         
1108                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
1109                 
1110                         PropertyValue.Trim();
1111                         PropertyValue.RemoveLast();
1112                 
1113                 }                               
1114         
1115                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
1116                 
1117                         PropertyValue.Remove(0, 1);
1118                 
1119                 }                               
1120         
1121                 if (PropertyName == wxT("ALTID")){
1123                         AnniversaryAltID = PropertyValue;
1124         
1125                 } else if (PropertyName == wxT("CALSCALE")){
1126         
1127                         AnniversaryCalScale = PropertyValue;
1128         
1129                 } else if (PropertyName != wxT("VALUE")) {
1130         
1131                         // Something else we don't know about so append
1132                         // to the tokens variable.
1133                 
1134                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
1135                 
1136                                 if (FirstToken == TRUE){
1137         
1138                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1139                                         FirstToken = FALSE;
1140         
1141                                 } else {
1142         
1143                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1144         
1145                                 }
1146                                 
1147                         }
1148                         
1149                 }
1151         }       
1153         // Add the data to the variables and form.
1154         
1155         if (AnniversaryText == FALSE){
1156         
1157                 Anniversary = PropertySeg2;
1159         }
1160         
1161         if (!PropertyTokens.IsEmpty()){
1162         
1163                 AnniversaryTokens = PropertyTokens;
1165         }
1169 void ContactDataObject::ProcessTimeZone(wxString PropertySeg1, wxString PropertySeg2, int *TimeZoneCount){
1171         std::map<int, int> SplitPoints;
1172         std::map<int, int> SplitLength;
1174         int intPrevValue = 4;
1175         int intPref = 0;                        
1176         
1177         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1178         
1179         intPrevValue = 3;
1180         
1181         PropertyType PropType = PROPERTY_NONE;
1182         
1183         // Look for type before continuing.
1184         
1185         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1186         
1187         intPrevValue = 3;
1188         
1189         std::map<int, wxString> *TZList = NULL;
1190         std::map<int, wxString> *TZListType = NULL;
1191         std::map<int, wxString> *TZListMediatype = NULL;
1192         std::map<int, wxString> *TZListAltID = NULL;
1193         std::map<int, wxString> *TZListPID = NULL;
1194         std::map<int, wxString> *TZListTokens = NULL;           
1195         std::map<int, int> *TZListPref = NULL;
1196         
1197         switch(PropType){
1198                 case PROPERTY_NONE:
1199                         TZList = &GeneralTZList;
1200                         TZListType = &GeneralTZListType;
1201                         TZListMediatype = &GeneralTZListMediatype;
1202                         TZListAltID = &GeneralTZListAltID;
1203                         TZListPID = &GeneralTZListPID;
1204                         TZListTokens = &GeneralTZListTokens;
1205                         TZListPref = &GeneralTZListPref;
1206                         break;
1207                 case PROPERTY_HOME:
1208                         TZList = &HomeTZList;
1209                         TZListType = &HomeTZListType;
1210                         TZListMediatype = &HomeTZListMediatype;
1211                         TZListAltID = &HomeTZListAltID;
1212                         TZListPID = &HomeTZListPID;
1213                         TZListTokens = &HomeTZListTokens;
1214                         TZListPref = &HomeTZListPref;
1215                         break;
1216                 case PROPERTY_WORK:
1217                         TZList = &BusinessTZList;
1218                         TZListType = &BusinessTZListType;
1219                         TZListMediatype = &BusinessTZListMediatype;
1220                         TZListAltID = &BusinessTZListAltID;
1221                         TZListPID = &BusinessTZListPID;
1222                         TZListTokens = &BusinessTZListTokens;
1223                         TZListPref = &BusinessTZListPref;
1224                         break;
1225         }
1226         
1227         std::map<int, int>::iterator SLiter;    
1228         wxString PropertyData;
1229         wxString PropertyName;
1230         wxString PropertyValue;
1231         wxString PropertyTokens;
1232         bool FirstToken = TRUE;
1233         
1234         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1235         intiter != SplitPoints.end(); ++intiter){
1236         
1237                 SLiter = SplitLength.find(intiter->first);
1238         
1239                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1240                 
1241                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1242                 PropertyName = PropertyElement.GetNextToken();                          
1243                 PropertyValue = PropertyElement.GetNextToken();
1244                 
1245                 intPrevValue = intiter->second;
1246                 
1247                 CaptureString(&PropertyValue, FALSE);
1249                 if (PropertyName == wxT("ALTID")){
1251                         TZListAltID->erase(*TimeZoneCount);
1252                         TZListAltID->insert(std::make_pair(*TimeZoneCount, PropertyValue));
1253                 
1254                 } else if (PropertyName == wxT("PID")){
1256                         TZListPID->erase(*TimeZoneCount);
1257                         TZListPID->insert(std::make_pair(*TimeZoneCount, PropertyValue));       
1259                 } else if (PropertyName == wxT("PREF")){
1261                         int PriorityNumber = 0;
1262                         bool ValidNumber = TRUE;
1263                         
1264                         try{
1265                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1266                         }
1267                         
1268                         catch(std::invalid_argument &e){
1269                                 ValidNumber = FALSE;
1270                         }
1272                         if (ValidNumber == TRUE){
1274                                 TZListPref->erase(*TimeZoneCount);
1275                                 TZListPref->insert(std::make_pair(*TimeZoneCount, PriorityNumber));
1277                         }
1278                 
1279                 } else if (PropertyName == wxT("MEDIATYPE")){
1281                         TZListMediatype->erase(*TimeZoneCount);
1282                         TZListMediatype->insert(std::make_pair(*TimeZoneCount, PropertyValue)); 
1284                 } else {
1285                 
1286                         // Something else we don't know about so append
1287                         // to the tokens variable.
1288                 
1289                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1290                 
1291                                 if (FirstToken == TRUE){
1292                         
1293                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1294                                         FirstToken = FALSE;
1295                         
1296                                 } else {
1297                         
1298                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1299                         
1300                                 }
1301                 
1302                         }
1303                 
1304                 }
1305                 
1306         }
1307         
1308         TZList->insert(std::make_pair(*TimeZoneCount, PropertySeg2));
1309         
1310         // Add the name token data.
1311         
1312         if (!PropertyTokens.IsEmpty()){
1313         
1314                 TZListTokens->insert(std::make_pair(*TimeZoneCount, PropertyTokens));
1315         
1316         }
1321 void ContactDataObject::ProcessAddress(wxString PropertySeg1, wxString PropertySeg2, int *AddressCount){
1323         size_t intPropertyLen = PropertySeg1.Len();
1324         std::map<int, int> SplitPoints;
1325         std::map<int, int> SplitLength;
1326         std::map<int, int>::iterator SLiter;                    
1327         wxString PropertyData;
1328         wxString PropertyName;
1329         wxString PropertyValue;
1330         wxString PropertyTokens;
1331         wxString AddressLabel;
1332         wxString AddressLang;
1333         wxString AddressAltID;
1334         wxString AddressPID;
1335         wxString AddressTokens;
1336         wxString AddressGeo;
1337         wxString AddressTimezone;
1338         wxString AddressType;
1339         wxString AddressMediatype;
1340         wxString AddressPOBox;
1341         wxString AddressExtended;
1342         wxString AddressStreet;
1343         wxString AddressLocality;
1344         wxString AddressCity;
1345         wxString AddressRegion;
1346         wxString AddressPostalCode;
1347         wxString AddressCountry;
1348         bool FirstToken = TRUE;                 
1349         int intSplitsFound = 0;
1350         int intSplitSize = 0;
1351         int intPrevValue = 5;
1352         int intPref = 0;                        
1353         int intType = 0;
1354         long ListCtrlIndex;
1355         
1356         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1357         
1358         intPrevValue = 4;
1359         
1360         PropertyType PropType = PROPERTY_NONE;
1361                 
1362         // Look for type before continuing.
1363         
1364         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1365         
1366         intPrevValue = 4;
1367         
1368         std::map<int, wxString> *AddressList = NULL;
1369         std::map<int, wxString> *AddressListTown = NULL;
1370         std::map<int, wxString> *AddressListCounty = NULL;
1371         std::map<int, wxString> *AddressListPostCode = NULL;
1372         std::map<int, wxString> *AddressListCountry = NULL;
1373         std::map<int, wxString> *AddressListLabel = NULL;
1374         std::map<int, wxString> *AddressListLang = NULL;                
1375         std::map<int, wxString> *AddressListAltID = NULL;
1376         std::map<int, wxString> *AddressListPID = NULL;
1377         std::map<int, wxString> *AddressListTokens = NULL;
1378         std::map<int, wxString> *AddressListGeo = NULL;
1379         std::map<int, wxString> *AddressListTimezone = NULL;            
1380         std::map<int, wxString> *AddressListType = NULL;
1381         std::map<int, wxString> *AddressListMediatype = NULL;
1382         std::map<int, int> *AddressListPref = NULL;
1384         switch(PropType){
1385                 case PROPERTY_NONE:
1386                         AddressList = &GeneralAddressList;
1387                         AddressListTown = &GeneralAddressListTown;
1388                         AddressListCounty = &GeneralAddressListCounty;
1389                         AddressListPostCode = &GeneralAddressListPostCode;
1390                         AddressListCountry = &GeneralAddressListCountry;
1391                         AddressListLabel = &GeneralAddressListLabel;
1392                         AddressListLang = &GeneralAddressListLang;              
1393                         AddressListAltID = &GeneralAddressListAltID;
1394                         AddressListPID = &GeneralAddressListPID;
1395                         AddressListTokens = &GeneralAddressListTokens;
1396                         AddressListGeo = &GeneralAddressListGeo;
1397                         AddressListTimezone = &GeneralAddressListTimezone;
1398                         AddressListType = &GeneralAddressListType;
1399                         AddressListMediatype = &GeneralAddressListMediatype;
1400                         AddressListPref = &GeneralAddressListPref;              
1401                         break;
1402                 case PROPERTY_HOME:
1403                         AddressList = &HomeAddressList;
1404                         AddressListTown = &HomeAddressListTown;
1405                         AddressListCounty = &HomeAddressListCounty;
1406                         AddressListPostCode = &HomeAddressListPostCode;
1407                         AddressListCountry = &HomeAddressListCountry;
1408                         AddressListLabel = &HomeAddressListLabel;
1409                         AddressListLang = &HomeAddressListLang;         
1410                         AddressListAltID = &HomeAddressListAltID;
1411                         AddressListPID = &HomeAddressListPID;
1412                         AddressListTokens = &HomeAddressListTokens;
1413                         AddressListGeo = &HomeAddressListGeo;
1414                         AddressListTimezone = &HomeAddressListTimezone;
1415                         AddressListType = &HomeAddressListType;
1416                         AddressListMediatype = &HomeAddressListMediatype;
1417                         AddressListPref = &HomeAddressListPref;
1418                         break;
1419                 case PROPERTY_WORK:
1420                         AddressList = &BusinessAddressList;
1421                         AddressListTown = &BusinessAddressListTown;
1422                         AddressListCounty = &BusinessAddressListCounty;
1423                         AddressListPostCode = &BusinessAddressListPostCode;
1424                         AddressListCountry = &BusinessAddressListCountry;
1425                         AddressListLabel = &BusinessAddressListLabel;
1426                         AddressListLang = &BusinessAddressListLang;             
1427                         AddressListAltID = &BusinessAddressListAltID;
1428                         AddressListPID = &BusinessAddressListPID;
1429                         AddressListTokens = &BusinessAddressListTokens;
1430                         AddressListGeo = &BusinessAddressListGeo;
1431                         AddressListTimezone = &BusinessAddressListTimezone;
1432                         AddressListType = &BusinessAddressListType;
1433                         AddressListMediatype = &BusinessAddressListMediatype;
1434                         AddressListPref = &BusinessAddressListPref;
1435                         break;
1436         }
1437         
1438         intPrevValue = 4;
1439         
1440         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1441         intiter != SplitPoints.end(); ++intiter){
1442         
1443                 SLiter = SplitLength.find(intiter->first);
1444         
1445                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1446                 
1447                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1448                 PropertyName = PropertyElement.GetNextToken();                          
1449                 PropertyValue = PropertyElement.GetNextToken();
1450                 
1451                 intPrevValue = intiter->second;
1452                 
1453                 CaptureString(&PropertyValue, FALSE);
1454                 
1455                 // Process properties.
1456                 
1457                 if (PropertyName == wxT("LABEL")){
1458                 
1459                         AddressListLabel->erase(*AddressCount);
1460                         AddressListLabel->insert(std::make_pair(*AddressCount, PropertyValue));
1461                                 
1462                 } else if (PropertyName == wxT("LANGUAGE")){
1463                 
1464                         AddressListLang->erase(*AddressCount);
1465                         AddressListLang->insert(std::make_pair(*AddressCount, PropertyValue));                  
1466                 
1467                 } else if (PropertyName == wxT("ALTID")){
1469                         AddressListAltID->erase(*AddressCount);
1470                         AddressListAltID->insert(std::make_pair(*AddressCount, PropertyValue));
1471                 
1472                 } else if (PropertyName == wxT("PID")){
1474                         AddressListPID->erase(*AddressCount);
1475                         AddressListPID->insert(std::make_pair(*AddressCount, PropertyValue));
1476                 
1477                 } else if (PropertyName == wxT("GEO")){
1478                 
1479                         AddressListGeo->erase(*AddressCount);
1480                         AddressListGeo->insert(std::make_pair(*AddressCount, PropertyValue));
1481                 
1482                 } else if (PropertyName == wxT("TZ")){
1484                         AddressListTimezone->erase(*AddressCount);
1485                         AddressListTimezone->insert(std::make_pair(*AddressCount, PropertyValue));
1486                 
1487                 } else if (PropertyName == wxT("MEDIATYPE")){
1489                         AddressListMediatype->erase(*AddressCount);
1490                         AddressListMediatype->insert(std::make_pair(*AddressCount, PropertyValue));
1491                 
1492                 } else if (PropertyName == wxT("PREF")){
1493                         
1494                         int PriorityNumber = 0;
1495                         bool ValidNumber = TRUE;
1496                         
1497                         try{
1498                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1499                         }
1500                         
1501                         catch(std::invalid_argument &e){
1502                                 ValidNumber = FALSE;
1503                         }
1505                         if (ValidNumber == TRUE){
1507                                 AddressListPref->erase(*AddressCount);
1508                                 AddressListPref->insert(std::make_pair(*AddressCount, PriorityNumber));
1510                         }
1511                 
1512                 } else {
1513                 
1514                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1515                         
1516                                 if (FirstToken == TRUE){
1517                                 
1518                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1519                                         FirstToken = FALSE;
1520                                 
1521                                 } else {
1522                                 
1523                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1524                                 
1525                                 }
1526                         
1527                         }
1528                 
1529                 }
1530         
1531         }                       
1532         
1533         // Split the address. 
1535         //std::map<int, int>::iterator SLiter;
1536         intPropertyLen = PropertySeg2.Len();
1537         SplitPoints.clear();
1538         SplitLength.clear();
1539         intSplitsFound = 0;
1540         intSplitSize = 0;
1541         intPrevValue = 0;
1542         
1543         for (int i = 0; i <= intPropertyLen; i++){
1545                 intSplitSize++;
1546         
1547                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
1548         
1549                         intSplitsFound++;
1550                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
1551                         
1552                         if (intSplitsFound == 6){ 
1553                         
1554                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1555                                 break; 
1556                                 
1557                         } else {
1558                         
1559                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1560                         
1561                         }
1562                         
1563                         intSplitSize = 0;                                       
1564         
1565                 }
1567         }
1568         
1569         // Split the data into several parts.                   
1570         
1571         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1572         intiter != SplitPoints.end(); ++intiter){
1573                         
1574                 if (intiter->first == 1){
1575                 
1576                         // Deal with PO Box.
1577                         
1578                         SLiter = SplitLength.find(1);
1579                                                                 
1580                         //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
1581                         AddressPOBox = PropertySeg2.Mid(0, SLiter->second);
1582                         intPrevValue = intiter->second;
1583                 
1584                 } else if (intiter->first == 2){
1585                 
1586                         // Deal with extended address.
1587                         
1588                         SLiter = SplitLength.find(2);
1589                         
1590                         AddressExtended = PropertySeg2.Mid(intPrevValue, SLiter->second);
1591                         //txtForename->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1592                         intPrevValue = intiter->second;
1593                 
1594                 } else if (intiter->first == 3){
1595                 
1596                         // Deal with street address.
1597                         
1598                         SLiter = SplitLength.find(3);
1599                                                                 
1600                         AddressStreet = PropertySeg2.Mid(intPrevValue, SLiter->second);
1601                         //txtOtherNames->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1602                         intPrevValue = intiter->second;
1603                 
1604                 } else if (intiter->first == 4){
1605                 
1606                         // Deal with locality
1608                         SLiter = SplitLength.find(4);
1609                         
1610                         AddressLocality = PropertySeg2.Mid(intPrevValue, SLiter->second);
1611                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1612                         intPrevValue = intiter->second;
1613                         
1614                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1615                 
1616                 } else if (intiter->first == 5){
1617                 
1618                         // Deal with region.
1620                         SLiter = SplitLength.find(5);
1621                         
1622                         AddressRegion = PropertySeg2.Mid(intPrevValue, SLiter->second);
1623                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1624                         intPrevValue = intiter->second;
1625                         
1626                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1627                 
1628                 } else if (intiter->first == 6){
1629                 
1630                         // Deal with post code.
1632                         SLiter = SplitLength.find(6);
1633                         
1634                         AddressPostalCode = PropertySeg2.Mid(intPrevValue, SLiter->second);
1635                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1636                         intPrevValue = intiter->second;
1637                         
1638                         // Deal with country.
1639                                                 
1640                         AddressCountry = PropertySeg2.Mid(intPrevValue, wxString::npos);
1641                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1642                         
1643                         break;
1644                 
1645                 }
1646         
1647         }       
1648         
1649         // Add the data to the General/Home/Work address variables.
1650         
1651         CaptureString(&AddressStreet, FALSE); 
1652         CaptureString(&AddressLocality, FALSE);
1653         CaptureString(&AddressRegion, FALSE);
1654         CaptureString(&AddressPostalCode, FALSE);
1655         CaptureString(&AddressCountry, FALSE);
1656                 
1657         if (!PropertyTokens.IsEmpty()){
1658         
1659                 AddressListTokens->insert(std::make_pair(*AddressCount, PropertyTokens));
1660         
1661         }
1663         AddressListCountry->insert(std::make_pair(*AddressCount, AddressCountry));      
1664         AddressList->insert(std::make_pair(*AddressCount, AddressStreet));
1665         AddressListTown->insert(std::make_pair(*AddressCount, AddressLocality));
1666         AddressListCounty->insert(std::make_pair(*AddressCount, AddressRegion));
1667         AddressListPostCode->insert(std::make_pair(*AddressCount, AddressPostalCode));
1669         switch(PropType){
1670                 case PROPERTY_NONE:
1671                         AddressListType->insert(std::make_pair(*AddressCount, wxT("")));
1672                         break;
1673                 case PROPERTY_HOME:
1674                         AddressListType->insert(std::make_pair(*AddressCount, wxT("home")));
1675                         break;
1676                 case PROPERTY_WORK:
1677                         AddressListType->insert(std::make_pair(*AddressCount, wxT("work")));    
1678                         break;
1679         }
1680         
1681         AddressListTokens->insert(std::make_pair(*AddressCount, PropertyTokens));
1685 void ContactDataObject::ProcessEmail(wxString PropertySeg1, wxString PropertySeg2, int *EmailCount){
1687         std::map<int, int> SplitPoints;
1688         std::map<int, int> SplitLength;
1690         int intPrevValue = 7;
1691         int intPref = 0;                        
1692         
1693         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1694         
1695         intPrevValue = 6;
1696         
1697         PropertyType PropType = PROPERTY_NONE;
1698                 
1699         // Look for type before continuing.
1700         
1701         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1702         
1703         std::map<int, wxString> *EmailList = NULL;
1704         std::map<int, wxString> *EmailListType = NULL;
1705         std::map<int, wxString> *EmailListAltID = NULL;
1706         std::map<int, wxString> *EmailListPID = NULL;
1707         std::map<int, wxString> *EmailListTokens = NULL;                
1708         std::map<int, int> *EmailListPref = NULL;
1710         switch(PropType){
1711                 case PROPERTY_NONE:
1712                         EmailList = &GeneralEmailList;
1713                         EmailListType = &GeneralEmailListType;
1714                         EmailListAltID = &GeneralEmailListAltID;
1715                         EmailListPID = &GeneralEmailListPID;
1716                         EmailListTokens = &GeneralEmailListTokens;              
1717                         EmailListPref = &GeneralEmailListPref;  
1718                         break;
1719                 case PROPERTY_HOME:
1720                         EmailList = &HomeEmailList;
1721                         EmailListType = &HomeEmailListType;
1722                         EmailListAltID = &HomeEmailListAltID;
1723                         EmailListPID = &HomeEmailListPID;
1724                         EmailListTokens = &HomeEmailListTokens;         
1725                         EmailListPref = &HomeEmailListPref;     
1726                         break;
1727                 case PROPERTY_WORK:
1728                         EmailList = &BusinessEmailList;
1729                         EmailListType = &BusinessEmailListType;
1730                         EmailListAltID = &BusinessEmailListAltID;
1731                         EmailListPID = &BusinessEmailListPID;
1732                         EmailListTokens = &BusinessEmailListTokens;             
1733                         EmailListPref = &BusinessEmailListPref; 
1734                         break;
1735         }
1736         
1737         intPrevValue = 6;
1738         
1739         std::map<int,int>::iterator SLiter;
1740         wxString PropertyData;
1741         wxString PropertyName;
1742         wxString PropertyValue;
1743         wxString PropertyTokens;
1744         bool FirstToken = TRUE;
1745         
1746         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1747         intiter != SplitPoints.end(); ++intiter){
1748         
1749                 SLiter = SplitLength.find(intiter->first);
1750         
1751                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1752                 
1753                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1754                 PropertyName = PropertyElement.GetNextToken();                          
1755                 PropertyValue = PropertyElement.GetNextToken();
1756                 
1757                 intPrevValue = intiter->second;
1758                 
1759                 CaptureString(&PropertyValue, FALSE);
1760                 
1761                 // Process properties.
1762                 
1763                 if (PropertyName == wxT("ALTID")){
1765                         EmailListAltID->erase(*EmailCount);
1766                         EmailListAltID->insert(std::make_pair(*EmailCount, PropertyValue));
1767                 
1768                 } else if (PropertyName == wxT("PID")){
1770                         EmailListPID->erase(*EmailCount);
1771                         EmailListPID->insert(std::make_pair(*EmailCount, PropertyValue));
1772                 
1773                 } else if (PropertyName == wxT("PREF")){
1774                         
1775                         int PriorityNumber = 0;
1776                         bool ValidNumber = TRUE;
1777                         
1778                         try{
1779                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1780                         }
1781                         
1782                         catch(std::invalid_argument &e){
1783                                 ValidNumber = FALSE;
1784                         }
1786                         if (ValidNumber == TRUE){
1788                                 EmailListPref->erase(*EmailCount);
1789                                 EmailListPref->insert(std::make_pair(*EmailCount, PriorityNumber));
1791                         }
1792                 
1793                 } else {
1794                 
1795                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1796                         
1797                                 if (FirstToken == TRUE){
1798                                 
1799                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1800                                         FirstToken = FALSE;
1801                                 
1802                                 } else {
1803                                 
1804                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1805                                 
1806                                 }
1807                         
1808                         }
1809                 
1810                 }
1811         
1812         }
1813         
1814         EmailList->insert(std::make_pair(*EmailCount, PropertySeg2));
1815         
1816         // Add the name token data.
1817         
1818         if (!PropertyTokens.IsEmpty()){
1819         
1820                 EmailListTokens->insert(std::make_pair(*EmailCount, PropertyTokens));
1821         
1822         }       
1827 void ContactDataObject::ProcessIM(wxString PropertySeg1, wxString PropertySeg2, int *IMCount){
1829         std::map<int, int> SplitPoints;
1830         std::map<int, int> SplitLength;
1832         int intPrevValue = 6;
1833         int intPref = 0;                        
1834         
1835         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1836         
1837         intPrevValue = 5;
1838         
1839         PropertyType PropType = PROPERTY_NONE;
1840                 
1841         // Look for type before continuing.
1842         
1843         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1844         
1845         std::map<int, wxString> *IMList = NULL;
1846         std::map<int, wxString> *IMListType = NULL;
1847         std::map<int, wxString> *IMListAltID = NULL;
1848         std::map<int, wxString> *IMListPID = NULL;
1849         std::map<int, wxString> *IMListTokens = NULL;
1850         std::map<int, wxString> *IMListMediatype = NULL;        
1851         std::map<int, int> *IMListPref = NULL;
1853         switch(PropType){
1854                 case PROPERTY_NONE:
1855                         IMList = &GeneralIMList;
1856                         IMListType = &GeneralIMListType;
1857                         IMListAltID = &GeneralIMListAltID;
1858                         IMListPID = &GeneralIMListPID;
1859                         IMListTokens = &GeneralIMListTokens;
1860                         IMListMediatype = &GeneralIMListMediatype;
1861                         IMListPref = &GeneralIMListPref;        
1862                         break;
1863                 case PROPERTY_HOME:
1864                         IMList = &HomeIMList;
1865                         IMListType = &HomeIMListType;
1866                         IMListAltID = &HomeIMListAltID;
1867                         IMListPID = &HomeIMListPID;
1868                         IMListTokens = &HomeIMListTokens;
1869                         IMListMediatype = &HomeIMListMediatype;         
1870                         IMListPref = &HomeIMListPref;   
1871                         break;
1872                 case PROPERTY_WORK:
1873                         IMList = &BusinessIMList;
1874                         IMListType = &BusinessIMListType;
1875                         IMListAltID = &BusinessIMListAltID;
1876                         IMListPID = &BusinessIMListPID;
1877                         IMListTokens = &BusinessIMListTokens;   
1878                         IMListMediatype = &BusinessIMListMediatype;     
1879                         IMListPref = &BusinessIMListPref;       
1880                         break;
1881         }
1882         
1883         intPrevValue = 5;
1884         
1885         std::map<int,int>::iterator SLiter;
1886         wxString PropertyData;
1887         wxString PropertyName;
1888         wxString PropertyValue;
1889         wxString PropertyTokens;
1890         bool FirstToken = TRUE;
1891         
1892         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1893         intiter != SplitPoints.end(); ++intiter){
1894         
1895                 SLiter = SplitLength.find(intiter->first);
1896         
1897                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1898                 
1899                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1900                 PropertyName = PropertyElement.GetNextToken();                          
1901                 PropertyValue = PropertyElement.GetNextToken();
1902                 
1903                 intPrevValue = intiter->second;
1904                 
1905                 CaptureString(&PropertyValue, FALSE);
1906                 
1907                 // Process properties.
1908                 
1909                 if (PropertyName == wxT("ALTID")){
1911                         IMListAltID->erase(*IMCount);
1912                         IMListAltID->insert(std::make_pair(*IMCount, PropertyValue));
1913                 
1914                 } else if (PropertyName == wxT("PID")){
1916                         IMListPID->erase(*IMCount);
1917                         IMListPID->insert(std::make_pair(*IMCount, PropertyValue));
1918                 
1919                 } else if (PropertyName == wxT("MEDIATYPE")){
1921                         IMListMediatype->erase(*IMCount);
1922                         IMListMediatype->insert(std::make_pair(*IMCount, PropertyValue));
1923                 
1924                 } else if (PropertyName == wxT("PREF")){
1925                         
1926                         int PriorityNumber = 0;
1927                         bool ValidNumber = TRUE;
1928                         
1929                         try{
1930                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1931                         }
1932                         
1933                         catch(std::invalid_argument &e){
1934                                 ValidNumber = FALSE;
1935                         }
1937                         if (ValidNumber == TRUE){
1939                                 IMListPref->erase(*IMCount);
1940                                 IMListPref->insert(std::make_pair(*IMCount, PriorityNumber));
1942                         }
1943                 
1944                 } else {
1945                 
1946                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1947                         
1948                                 if (FirstToken == TRUE){
1949                                 
1950                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1951                                         FirstToken = FALSE;
1952                                 
1953                                 } else {
1954                                 
1955                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1956                                 
1957                                 }
1958                         
1959                         }
1960                 
1961                 }
1962         
1963         }
1964                 
1965         IMList->insert(std::make_pair(*IMCount, PropertySeg2));
1966         
1967         // Add the name token data.
1968         
1969         if (!PropertyTokens.IsEmpty()){
1970         
1971                 IMListTokens->insert(std::make_pair(*IMCount, PropertyTokens));
1972         
1973         }
1977 void ContactDataObject::ProcessTelephone(wxString PropertySeg1, wxString PropertySeg2, int *TelephoneCount){
1979         std::map<int, int> SplitPoints;
1980         std::map<int, int> SplitLength;
1981         std::map<int, int>::iterator SLiter;
1982         
1983         int intPref = 0;
1984         
1985         PropertyType PropType = PROPERTY_NONE;
1986                 
1987         // Look for type before continuing.
1988         
1989         wxString TelTypeUI;
1990         wxString TelTypeDetail;
1991         wxString PropertyData;
1992         wxString PropertyName;
1993         wxString PropertyValue;
1994         wxString PropertyTokens;
1995         
1996         std::map<int,int> TypeSplitPoints;
1997         std::map<int,int> TypeSplitLength;
1998         std::map<int,int>::iterator TSLiter;
1999         
2000         int intSplitSize = 0;
2001         int intSplitsFound = 0;
2002         int intSplitPoint = 0;
2003         int intType = 0;
2004         int intPrevValue = 5;
2005                 
2006         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
2007         
2008         intPrevValue = 4;
2009         
2010         // Look for type before continuing.
2011         
2012         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
2013         intiter != SplitPoints.end(); ++intiter){
2014         
2015                 SLiter = SplitLength.find(intiter->first);
2016         
2017                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2018                 
2019                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2020                 PropertyName = PropertyElement.GetNextToken();                          
2021                 PropertyValue = PropertyElement.GetNextToken();
2022                 
2023                 intPrevValue = intiter->second;
2025                 if (PropertyName == wxT("TYPE")){
2026                 
2027                         // Process each value in type and translate each
2028                         // part.
2029                 
2030                         // Strip out the quotes if they are there.
2031                 
2032                         size_t intPropertyValueLen = PropertyValue.Len();
2033                 
2034                         if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
2035                         
2036                                 PropertyValue.Trim();
2037                                 PropertyValue.RemoveLast();
2038                         
2039                         }                               
2040                 
2041                         if (PropertyValue.Mid(0, 1) == wxT("\"")){
2042                         
2043                                 PropertyValue.Remove(0, 1);
2044                         
2045                         }
2046                         
2047                         TelTypeDetail = PropertyValue;
2048                         
2049                         intSplitSize = 0;
2050                         intSplitsFound = 0;
2051                         intSplitPoint = 0;
2052                         
2053                         for (int i = 0; i <= intPropertyValueLen; i++){
2054         
2055                                 intSplitSize++;
2056         
2057                                 if (PropertyValue.Mid(i, 1) == wxT(",") && PropertyValue.Mid((i - 1), 1) != wxT("\\")){
2058         
2059                                         if (intSplitsFound == 0){
2061                                                 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
2062                                                 TypeSplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
2063                         
2064                                         } else {
2065                         
2066                                                 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
2067                                                 TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
2068                         
2069                                         }                       
2071                                         intSplitsFound++;
2072                                         i++;
2073                                         intSplitPoint = i;
2074                                         intSplitSize = 0;
2075         
2076                                 }
2077         
2078                         }
2079                         
2080                         TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
2081                         TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));                                                           
2082                 
2083                         int intTypeSeek = 0;
2084                 
2085                         for (std::map<int, int>::iterator typeiter = TypeSplitPoints.begin(); 
2086                         typeiter != TypeSplitPoints.end(); ++typeiter){
2087                         
2088                                 wxString TypePropertyName;
2089                                 
2090                                 TSLiter = TypeSplitLength.find(typeiter->first);
2091                                 
2092                                 TypePropertyName = PropertyValue.Mid(typeiter->second, TSLiter->second);
2093                                 
2094                                 if (intTypeSeek == 0){
2095                                 
2096                                 
2097                                 } else {
2098                                                                                 
2099                                         TelTypeUI.Append(wxT(","));                                                     
2100                                 
2101                                 }
2102                         
2103                                 if (TypePropertyName == wxT("home")){
2104                                 
2105                                         PropType = PROPERTY_HOME;
2106                                 
2107                                 } else if (TypePropertyName == wxT("work")){
2108                                 
2109                                         PropType = PROPERTY_WORK;
2110                                                                         
2111                                 }
2112                                 
2113                                 
2114                                 if (TypePropertyName == wxT("text")){
2115                                 
2116                                         TelTypeUI.Append(_("text"));
2117                                         intTypeSeek++;
2118                                 
2119                                 } else if (TypePropertyName == wxT("voice")){
2120                                 
2121                                         TelTypeUI.Append(_("voice"));
2122                                         intTypeSeek++;
2123                                 
2124                                 } else if (TypePropertyName == wxT("fax")){
2125                                 
2126                                         TelTypeUI.Append(_("fax"));
2127                                         intTypeSeek++;
2128                                 
2129                                 } else if (TypePropertyName == wxT("cell")){
2130                                 
2131                                         TelTypeUI.Append(_("mobile"));
2132                                         intTypeSeek++;
2133                                 
2134                                 } else if (TypePropertyName == wxT("video")){
2135                                 
2136                                         TelTypeUI.Append(_("video"));
2137                                         intTypeSeek++;
2138                                 
2139                                 } else if (TypePropertyName == wxT("pager")){
2140                                 
2141                                         TelTypeUI.Append(_("pager"));
2142                                         intTypeSeek++;
2143                                 
2144                                 } else if (TypePropertyName == wxT("textphone")){
2145                                 
2146                                         TelTypeUI.Append(_("textphone"));
2147                                         intTypeSeek++;
2148                                 
2149                                 }
2150                         
2151                         }
2152                 
2153                 }
2154                 
2155         }
2156         
2157         std::map<int, wxString> *TelephoneList = NULL;
2158         std::map<int, wxString> *TelephoneListType = NULL;
2159         std::map<int, wxString> *TelephoneListAltID = NULL;
2160         std::map<int, wxString> *TelephoneListPID = NULL;
2161         std::map<int, wxString> *TelephoneListTokens = NULL;
2162         std::map<int, wxString> *TelephoneListTypeInfo = NULL;  
2163         std::map<int, int> *TelephoneListPref = NULL;
2165         switch(PropType){
2166                 case PROPERTY_NONE:
2167                         TelephoneList = &GeneralTelephoneList;
2168                         TelephoneListType = &GeneralTelephoneListType;
2169                         TelephoneListAltID = &GeneralTelephoneListAltID;
2170                         TelephoneListPID = &GeneralTelephoneListPID;
2171                         TelephoneListTokens = &GeneralTelephoneListTokens;
2172                         TelephoneListTypeInfo = &GeneralTelephoneListTypeInfo;
2173                         TelephoneListPref = &GeneralTelephoneListPref;  
2174                         break;
2175                 case PROPERTY_HOME:
2176                         TelephoneList = &HomeTelephoneList;
2177                         TelephoneListType = &HomeTelephoneListType;
2178                         TelephoneListAltID = &HomeTelephoneListAltID;
2179                         TelephoneListPID = &HomeTelephoneListPID;
2180                         TelephoneListTokens = &HomeTelephoneListTokens;
2181                         TelephoneListTypeInfo = &HomeTelephoneListTypeInfo;     
2182                         TelephoneListPref = &HomeTelephoneListPref;     
2183                         break;
2184                 case PROPERTY_WORK:
2185                         TelephoneList = &BusinessTelephoneList;
2186                         TelephoneListType = &BusinessTelephoneListType;
2187                         TelephoneListAltID = &BusinessTelephoneListAltID;
2188                         TelephoneListPID = &BusinessTelephoneListPID;
2189                         TelephoneListTokens = &BusinessTelephoneListTokens;     
2190                         TelephoneListTypeInfo = &BusinessTelephoneListTypeInfo; 
2191                         TelephoneListPref = &BusinessTelephoneListPref; 
2192                         break;
2193         }
2194                 
2195         // Process the properties.
2196         
2197         bool FirstToken = TRUE;
2198         
2199         intPrevValue = 5;
2200         SplitPoints.clear();
2201         SplitLength.clear();
2203         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
2205         intPrevValue = 4;
2206         
2207         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
2208         intiter != SplitPoints.end(); ++intiter){
2209         
2210                 SLiter = SplitLength.find(intiter->first);
2211         
2212                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2213                 
2214                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2215                 PropertyName = PropertyElement.GetNextToken();                          
2216                 PropertyValue = PropertyElement.GetNextToken();
2217                 
2218                 intPrevValue = intiter->second;
2219                 
2220                 CaptureString(&PropertyValue, FALSE);
2221                 
2222                 // Process properties.
2223                 
2224                 if (PropertyName == wxT("ALTID")){
2226                         TelephoneListAltID->erase(*TelephoneCount);
2227                         TelephoneListAltID->insert(std::make_pair(*TelephoneCount, PropertyValue));
2228                 
2229                 } else if (PropertyName == wxT("PID")){
2231                         TelephoneListPID->erase(*TelephoneCount);
2232                         TelephoneListPID->insert(std::make_pair(*TelephoneCount, PropertyValue));
2233                 
2234                 } else if (PropertyName == wxT("PREF")){
2235                         
2236                         int PriorityNumber = 0;
2237                         bool ValidNumber = TRUE;
2238                         
2239                         try{
2240                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
2241                         }
2242                         
2243                         catch(std::invalid_argument &e){
2244                                 ValidNumber = FALSE;
2245                         }
2247                         if (ValidNumber == TRUE){
2249                                 TelephoneListPref->erase(*TelephoneCount);
2250                                 TelephoneListPref->insert(std::make_pair(*TelephoneCount, PriorityNumber));
2252                         }
2253                 
2254                 } else {
2255                 
2256                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
2257                         
2258                                 if (FirstToken == TRUE){
2259                                 
2260                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
2261                                         FirstToken = FALSE;
2262                                 
2263                                 } else {
2264                                 
2265                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
2266                                 
2267                                 }
2268                         
2269                         }
2270                 
2271                 }
2272         
2273         }
2274                 
2275         TelephoneList->insert(std::make_pair(*TelephoneCount, PropertySeg2));
2276         TelephoneListTypeInfo->insert(std::make_pair(*TelephoneCount, TelTypeUI));
2277         
2278         // Add the name token data.
2279         
2280         if (!PropertyTokens.IsEmpty()){
2281         
2282                 TelephoneListTokens->insert(std::make_pair(*TelephoneCount, PropertyTokens));
2283         
2284         }
2288 void ContactDataObject::ProcessLanguage(wxString PropertySeg1, wxString PropertySeg2, int *LanguageCount){
2290         std::map<int, int> SplitPoints;
2291         std::map<int, int> SplitLength;
2293         int intPrevValue = 6;
2294         int intPref = 0;                        
2295         
2296         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
2297         
2298         intPrevValue = 5;
2299         
2300         PropertyType PropType = PROPERTY_NONE;
2301                 
2302         // Look for type before continuing.
2303         
2304         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
2305         
2306         std::map<int, wxString> *LanguageList = NULL;
2307         std::map<int, wxString> *LanguageListType = NULL;
2308         std::map<int, wxString> *LanguageListAltID = NULL;
2309         std::map<int, wxString> *LanguageListPID = NULL;
2310         std::map<int, wxString> *LanguageListTokens = NULL;
2311         std::map<int, int> *LanguageListPref = NULL;
2313         switch(PropType){
2314                 case PROPERTY_NONE:
2315                         LanguageList = &GeneralLanguageList;
2316                         LanguageListType = &GeneralLanguageListType;
2317                         LanguageListAltID = &GeneralLanguageListAltID;
2318                         LanguageListPID = &GeneralLanguageListPID;
2319                         LanguageListTokens = &GeneralLanguageListTokens;
2320                         LanguageListPref = &GeneralLanguageListPref;    
2321                         break;
2322                 case PROPERTY_HOME:
2323                         LanguageList = &HomeLanguageList;
2324                         LanguageListType = &HomeLanguageListType;
2325                         LanguageListAltID = &HomeLanguageListAltID;
2326                         LanguageListPID = &HomeLanguageListPID;
2327                         LanguageListTokens = &HomeLanguageListTokens;   
2328                         LanguageListPref = &HomeLanguageListPref;       
2329                         break;
2330                 case PROPERTY_WORK:
2331                         LanguageList = &BusinessLanguageList;
2332                         LanguageListType = &BusinessLanguageListType;
2333                         LanguageListAltID = &BusinessLanguageListAltID;
2334                         LanguageListPID = &BusinessLanguageListPID;
2335                         LanguageListTokens = &BusinessLanguageListTokens;       
2336                         LanguageListPref = &BusinessLanguageListPref;
2337                         break;
2338         }
2339         
2340         intPrevValue = 5;
2341         
2342         std::map<int,int>::iterator SLiter;
2343         wxString PropertyData;
2344         wxString PropertyName;
2345         wxString PropertyValue;
2346         wxString PropertyTokens;
2347         bool FirstToken = TRUE;
2348         
2349         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
2350         intiter != SplitPoints.end(); ++intiter){
2351         
2352                 SLiter = SplitLength.find(intiter->first);
2353         
2354                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2355                 
2356                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2357                 PropertyName = PropertyElement.GetNextToken();                          
2358                 PropertyValue = PropertyElement.GetNextToken();
2359                 
2360                 intPrevValue = intiter->second;
2361                 
2362                 CaptureString(&PropertyValue, FALSE);
2363                 
2364                 // Process properties.
2365                 
2366                 if (PropertyName == wxT("ALTID")){
2368                         LanguageListAltID->erase(*LanguageCount);
2369                         LanguageListAltID->insert(std::make_pair(*LanguageCount, PropertyValue));
2370                 
2371                 } else if (PropertyName == wxT("PID")){
2373                         LanguageListPID->erase(*LanguageCount);
2374                         LanguageListPID->insert(std::make_pair(*LanguageCount, PropertyValue));
2375                 
2376                 } else if (PropertyName == wxT("PREF")){
2377                         
2378                         int PriorityNumber = 0;
2379                         bool ValidNumber = TRUE;
2380                         
2381                         try{
2382                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
2383                         }
2384                         
2385                         catch(std::invalid_argument &e){
2386                                 ValidNumber = FALSE;
2387                         }
2389                         if (ValidNumber == TRUE){
2391                                 LanguageListPref->erase(*LanguageCount);
2392                                 LanguageListPref->insert(std::make_pair(*LanguageCount, PriorityNumber));
2394                         }
2395                 
2396                 } else {
2397                 
2398                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
2399                         
2400                                 if (FirstToken == TRUE){
2401                                 
2402                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
2403                                         FirstToken = FALSE;
2404                                 
2405                                 } else {
2406                                 
2407                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
2408                                 
2409                                 }
2410                         
2411                         }
2412                 
2413                 }
2414         
2415         }
2416                 
2417         LanguageList->insert(std::make_pair(*LanguageCount, PropertySeg2));
2418         
2419         // Add the name token data.
2420         
2421         if (!PropertyTokens.IsEmpty()){
2422         
2423                 LanguageListTokens->insert(std::make_pair(*LanguageCount, PropertyTokens));
2424         
2425         }
2429 void ContactDataObject::ProcessGeographic(wxString PropertySeg1, wxString PropertySeg2, int *GeographicCount){
2431         std::map<int, int> SplitPoints;
2432         std::map<int, int> SplitLength;
2434         int intPrevValue = 5;
2435         int intPref = 0;                        
2436         
2437         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
2438         
2439         intPrevValue = 4;
2440         
2441         PropertyType PropType = PROPERTY_NONE;
2442                 
2443         // Look for type before continuing.
2444         
2445         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
2446         
2447         std::map<int, wxString> *GeopositionList = NULL;
2448         std::map<int, wxString> *GeopositionListType = NULL;
2449         std::map<int, wxString> *GeopositionListAltID = NULL;
2450         std::map<int, wxString> *GeopositionListPID = NULL;
2451         std::map<int, wxString> *GeopositionListTokens = NULL;
2452         std::map<int, wxString> *GeopositionListMediatype = NULL;
2453         std::map<int, int> *GeopositionListPref = NULL;
2455         switch(PropType){
2456                 case PROPERTY_NONE:
2457                         GeopositionList = &GeneralGeographyList;
2458                         GeopositionListType = &GeneralGeographyListType;
2459                         GeopositionListAltID = &GeneralGeographyListAltID;
2460                         GeopositionListPID = &GeneralGeographyListPID;
2461                         GeopositionListTokens = &GeneralGeographyListTokens;
2462                         GeopositionListMediatype = &GeneralGeographyListMediatype;
2463                         GeopositionListPref = &GeneralGeographyListPref;        
2464                         break;
2465                 case PROPERTY_HOME:
2466                         GeopositionList = &HomeGeographyList;
2467                         GeopositionListType = &HomeGeographyListType;
2468                         GeopositionListAltID = &HomeGeographyListAltID;
2469                         GeopositionListPID = &HomeGeographyListPID;
2470                         GeopositionListTokens = &HomeGeographyListTokens;
2471                         GeopositionListMediatype = &HomeGeographyListMediatype;
2472                         GeopositionListPref = &HomeGeographyListPref;   
2473                         break;
2474                 case PROPERTY_WORK:
2475                         GeopositionList = &BusinessGeographyList;
2476                         GeopositionListType = &BusinessGeographyListType;
2477                         GeopositionListAltID = &BusinessGeographyListAltID;
2478                         GeopositionListPID = &BusinessGeographyListPID;
2479                         GeopositionListTokens = &BusinessGeographyListTokens;
2480                         GeopositionListMediatype = &BusinessGeographyListMediatype;     
2481                         GeopositionListPref = &BusinessGeographyListPref;
2482                         break;
2483         }
2484         
2485         intPrevValue = 4;
2486         
2487         std::map<int,int>::iterator SLiter;
2488         wxString PropertyData;
2489         wxString PropertyName;
2490         wxString PropertyValue;
2491         wxString PropertyTokens;
2492         bool FirstToken = TRUE;
2493         
2494         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
2495         intiter != SplitPoints.end(); ++intiter){
2496         
2497                 SLiter = SplitLength.find(intiter->first);
2498         
2499                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2500                 
2501                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2502                 PropertyName = PropertyElement.GetNextToken();                          
2503                 PropertyValue = PropertyElement.GetNextToken();
2504                 
2505                 intPrevValue = intiter->second;
2506                 
2507                 CaptureString(&PropertyValue, FALSE);
2508                 
2509                 // Process properties.
2510                 
2511                 if (PropertyName == wxT("ALTID")){
2513                         GeopositionListAltID->erase(*GeographicCount);
2514                         GeopositionListAltID->insert(std::make_pair(*GeographicCount, PropertyValue));
2515                 
2516                 } else if (PropertyName == wxT("PID")){
2518                         GeopositionListPID->erase(*GeographicCount);
2519                         GeopositionListPID->insert(std::make_pair(*GeographicCount, PropertyValue));
2520                 
2521                 } else if (PropertyName == wxT("MEDIATYPE")){
2523                         GeopositionListMediatype->erase(*GeographicCount);
2524                         GeopositionListMediatype->insert(std::make_pair(*GeographicCount, PropertyValue));
2525                 
2526                 } else if (PropertyName == wxT("PREF")){
2527                         
2528                         int PriorityNumber = 0;
2529                         bool ValidNumber = TRUE;
2530                         
2531                         try{
2532                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
2533                         }
2534                         
2535                         catch(std::invalid_argument &e){
2536                                 ValidNumber = FALSE;
2537                         }
2539                         if (ValidNumber == TRUE){
2541                                 GeopositionListPref->erase(*GeographicCount);
2542                                 GeopositionListPref->insert(std::make_pair(*GeographicCount, PriorityNumber));
2544                         }
2545                 
2546                 } else {
2547                 
2548                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
2549                         
2550                                 if (FirstToken == TRUE){
2551                                 
2552                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
2553                                         FirstToken = FALSE;
2554                                 
2555                                 } else {
2556                                 
2557                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
2558                                 
2559                                 }
2560                         
2561                         }
2562                 
2563                 }
2564         
2565         }
2566                 
2567         GeopositionList->insert(std::make_pair(*GeographicCount, PropertySeg2));
2568         
2569         // Add the name token data.
2570         
2571         if (!PropertyTokens.IsEmpty()){
2572         
2573                 GeopositionListTokens->insert(std::make_pair(*GeographicCount, PropertyTokens));
2574         
2575         }
2579 void ContactDataObject::ProcessRelated(wxString PropertySeg1, wxString PropertySeg2, int *RelatedCount){
2581         size_t intPropertyLen = PropertySeg1.Len();
2582         std::map<int, int> SplitPoints;
2583         std::map<int, int> SplitLength;
2584         std::map<int, int>::iterator SLiter;                    
2585         wxString PropertyData;
2586         wxString PropertyName;
2587         wxString PropertyValue;
2588         wxString PropertyTokens;
2589         wxString RelatedType;
2590         wxString RelatedTypeOriginal;                   
2591         wxString RelatedName;
2592         bool FirstToken = TRUE;                 
2593         int intSplitsFound = 0;
2594         int intSplitSize = 0;
2595         int intPrevValue = 9;
2596         int intPref = 0;
2597         long ListCtrlIndex;
2598         
2599         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
2600         
2601         intPrevValue = 8;
2602         
2603         // Look for type before continuing.
2604         
2605         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
2606         intiter != SplitPoints.end(); ++intiter){
2607         
2608                 SLiter = SplitLength.find(intiter->first);
2609         
2610                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2611                 
2612                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2613                 PropertyName = PropertyElement.GetNextToken();                          
2614                 PropertyValue = PropertyElement.GetNextToken();
2615                 
2616                 intPrevValue = intiter->second;
2617                 
2618                 // Process these.
2619                 
2620                 RelatedTypeOriginal = PropertyValue;
2621                 
2622                 if (PropertyName == wxT("TYPE")){
2623                 
2624                         if (PropertyValue == wxT("contact")){
2626                                 RelatedType = _("Contact");
2628                         } else if (PropertyValue == wxT("acquaintance")){
2630                                 RelatedType = _("Acquaintance");
2632                         } else if (PropertyValue == wxT("friend")){
2634                                 RelatedType = _("Friend");
2636                         } else if (PropertyValue == wxT("met")){
2638                                 RelatedType = _("Met");
2640                         } else if (PropertyValue == wxT("co-worker")){
2642                                 RelatedType = _("Co-worker");
2644                         } else if (PropertyValue == wxT("colleague")){
2646                                 RelatedType = _("Colleague");
2648                         } else if (PropertyValue == wxT("co-resident")){
2650                                 RelatedType = _("Co-resident");
2652                         } else if (PropertyValue == wxT("neighbor")){
2654                                 RelatedType = _("Neighbour");
2656                         } else if (PropertyValue == wxT("child")){
2658                                 RelatedType = _("Child");
2660                         } else if (PropertyValue == wxT("parent")){
2662                                 RelatedType = _("Parent");
2664                         } else if (PropertyValue == wxT("sibling")){
2666                                 RelatedType = _("Sibling");
2668                         } else if (PropertyValue == wxT("spouse")){
2670                                 RelatedType = _("Spouse");
2672                         } else if (PropertyValue == wxT("kin")){
2674                                 RelatedType = _("Kin");
2676                         } else if (PropertyValue == wxT("muse")){
2678                                 RelatedType = _("Muse");
2680                         } else if (PropertyValue == wxT("crush")){
2682                                 RelatedType = _("Crush");
2684                         } else if (PropertyValue == wxT("date")){
2686                                 RelatedType = _("Date");
2688                         } else if (PropertyValue == wxT("sweetheart")){
2690                                 RelatedType = _("Sweetheart");
2692                         } else if (PropertyValue == wxT("me")){
2694                                 RelatedType = _("Me");
2696                         } else if (PropertyValue == wxT("agent")){
2698                                 RelatedType = _("Agent");
2700                         } else if (PropertyValue == wxT("emergency")){
2702                                 RelatedType = _("Emergency");
2704                         } else {
2706                                 RelatedType = PropertyValue;
2708                         }
2709                 
2710                 }
2711         
2712         }
2713         
2714         intPrevValue = 8;                       
2715         
2716         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
2717         intiter != SplitPoints.end(); ++intiter){
2718         
2719                 SLiter = SplitLength.find(intiter->first);
2720         
2721                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2722                 
2723                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2724                 PropertyName = PropertyElement.GetNextToken();                          
2725                 PropertyValue = PropertyElement.GetNextToken();
2726                 
2727                 intPrevValue = intiter->second;
2728                 
2729                 // Process properties.
2730                 
2731                 size_t intPropertyValueLen = PropertyValue.Len();
2732                 
2733                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
2734                         
2735                         PropertyValue.Trim();
2736                         PropertyValue.RemoveLast();
2737                         
2738                 }                               
2739                 
2740                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
2741                         
2742                         PropertyValue.Remove(0, 1);
2743                         
2744                 }
2745                 
2746                 CaptureString(&PropertyValue, FALSE);
2747                         
2748                 if (PropertyName == wxT("ALTID")){
2750                         GeneralRelatedListAltID.erase(*RelatedCount);
2751                         GeneralRelatedListAltID.insert(std::make_pair(*RelatedCount, PropertyValue));
2752                 
2753                 } else if (PropertyName == wxT("PID")){
2755                         GeneralRelatedListPID.erase(*RelatedCount);
2756                         GeneralRelatedListPID.insert(std::make_pair(*RelatedCount, PropertyValue));
2757                 
2758                 } else if (PropertyName == wxT("PREF")){
2759                         
2760                         intPref = wxAtoi(PropertyValue);
2761                 
2762                         if (intPref > 0 && intPref < 101){
2763                 
2764                                 GeneralRelatedListPref.erase(*RelatedCount);
2765                                 GeneralRelatedListPref.insert(std::make_pair(*RelatedCount, intPref));
2767                         
2768                         }
2769                 
2770                 } else if (PropertyName == wxT("LANGUAGE")){
2771                 
2772                         GeneralRelatedListLanguage.erase(*RelatedCount);
2773                         GeneralRelatedListLanguage.insert(std::make_pair(*RelatedCount, PropertyValue));
2774                 
2775                 } else if (PropertyName != wxT("TYPE")) {
2776                 
2777                         // Something else we don't know about so append
2778                         // to the tokens variable.
2779                 
2780                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
2781                 
2782                                 if (FirstToken == TRUE){
2783                         
2784                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
2785                                         FirstToken = FALSE;
2786                         
2787                                 } else {
2788                         
2789                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
2790                         
2791                                 }
2792                 
2793                         }
2794                 
2795                 }
2796         
2797         }                                       
2798         
2799         // Add the data to the General/Home/Work address variables.
2800                                 
2801         GeneralRelatedList.erase(*RelatedCount);
2802         GeneralRelatedListRelType.erase(*RelatedCount);
2803         GeneralRelatedListType.erase(*RelatedCount);
2804         GeneralRelatedListTokens.erase(*RelatedCount);
2805         GeneralRelatedList.insert(std::make_pair(*RelatedCount, PropertySeg2));
2806         GeneralRelatedListRelType.insert(std::make_pair(*RelatedCount, RelatedType));                   
2807         GeneralRelatedListType.insert(std::make_pair(*RelatedCount, RelatedType));
2808         GeneralRelatedListTokens.insert(std::make_pair(*RelatedCount, PropertyTokens));
2812 void ContactDataObject::ProcessURL(wxString PropertySeg1, wxString PropertySeg2, int *URLCount){
2814         std::map<int, int> SplitPoints;
2815         std::map<int, int> SplitLength;
2816         std::map<int, int>::iterator SLiter;                    
2817         wxString PropertyData;
2818         wxString PropertyName;
2819         wxString PropertyValue;
2820         wxString PropertyTokens;
2821         bool FirstToken = TRUE;
2822         int intPrevValue = 5;
2823         int intPref = 0;                        
2824         int intType = 0;
2825         long ListCtrlIndex;
2826         
2827         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
2828         
2829         intPrevValue = 4;
2830         
2831         PropertyType PropType = PROPERTY_NONE;
2832                 
2833         // Look for type before continuing.
2834         
2835         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
2836         
2837         // Setup the pointers.
2838         
2839         std::map<int, wxString> *WebsiteList = NULL;
2840         std::map<int, wxString> *WebsiteListAltID = NULL;
2841         std::map<int, wxString> *WebsiteListPID = NULL;
2842         std::map<int, wxString> *WebsiteListType = NULL;
2843         std::map<int, wxString> *WebsiteListTokens = NULL;
2844         std::map<int, wxString> *WebsiteListMediatype = NULL;
2845         std::map<int, int> *WebsiteListPref = NULL;
2846         
2847         // Setup blank lines for later on.
2848         
2849         switch(PropType){
2850                 case PROPERTY_NONE:
2851                         WebsiteList = &GeneralWebsiteList;
2852                         WebsiteListType = &GeneralWebsiteListType;
2853                         WebsiteListAltID = &GeneralWebsiteListAltID;
2854                         WebsiteListPID = &GeneralWebsiteListPID;
2855                         WebsiteListTokens = &GeneralWebsiteListTokens;
2856                         WebsiteListMediatype = &GeneralWebsiteListMediatype;
2857                         WebsiteListPref = &GeneralWebsiteListPref;      
2858                         break;
2859                 case PROPERTY_HOME:
2860                         WebsiteList = &HomeWebsiteList;
2861                         WebsiteListType = &HomeWebsiteListType;
2862                         WebsiteListAltID = &HomeWebsiteListAltID;
2863                         WebsiteListPID = &HomeWebsiteListPID;
2864                         WebsiteListTokens = &HomeWebsiteListTokens;
2865                         WebsiteListMediatype = &HomeWebsiteListMediatype;
2866                         WebsiteListPref = &HomeWebsiteListPref; 
2867                         break;
2868                 case PROPERTY_WORK:
2869                         WebsiteList = &BusinessWebsiteList;
2870                         WebsiteListType = &BusinessWebsiteListType;
2871                         WebsiteListAltID = &BusinessWebsiteListAltID;
2872                         WebsiteListPID = &BusinessWebsiteListPID;
2873                         WebsiteListTokens = &BusinessWebsiteListTokens;
2874                         WebsiteListMediatype = &BusinessWebsiteListMediatype;   
2875                         WebsiteListPref = &BusinessWebsiteListPref;
2876                         break;
2877         }
2878         
2879         intPrevValue = 4;
2880         
2881         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
2882         intiter != SplitPoints.end(); ++intiter){
2883         
2884                 SLiter = SplitLength.find(intiter->first);
2885         
2886                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2887                 
2888                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2889                 PropertyName = PropertyElement.GetNextToken();                          
2890                 PropertyValue = PropertyElement.GetNextToken();
2891                 
2892                 intPrevValue = intiter->second;
2893                 
2894                 // Process properties.
2895                 
2896                 size_t intPropertyValueLen = PropertyValue.Len();
2897                 
2898                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
2899                         
2900                         PropertyValue.Trim();
2901                         PropertyValue.RemoveLast();
2902                         
2903                 }                               
2904                 
2905                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
2906                         
2907                         PropertyValue.Remove(0, 1);
2908                         
2909                 }
2910                 
2911                 CaptureString(&PropertyValue, FALSE);
2912                 
2913                 if (PropertyName == wxT("ALTID")){
2915                         WebsiteListAltID->erase(*URLCount);
2916                         WebsiteListAltID->insert(std::make_pair(*URLCount, PropertyValue));
2917                 
2918                 } else if (PropertyName == wxT("PID")){
2920                         WebsiteListPID->erase(*URLCount);
2921                         WebsiteListPID->insert(std::make_pair(*URLCount, PropertyValue));
2922                         
2923                 } else if (PropertyName == wxT("PREF")){
2924                         
2925                         int PriorityNumber = 0;
2926                         bool ValidNumber = TRUE;
2927                         
2928                         try{
2929                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
2930                         }
2931                         
2932                         catch(std::invalid_argument &e){
2933                                 ValidNumber = FALSE;
2934                         }
2936                         if (ValidNumber == TRUE){
2938                                 WebsiteListPref->erase(*URLCount);
2939                                 WebsiteListPref->insert(std::make_pair(*URLCount, PriorityNumber));
2941                         }
2942                                         
2943                 } else if (PropertyName == wxT("MEDIATYPE")){
2944                 
2945                         WebsiteListMediatype->erase(*URLCount);
2946                         WebsiteListMediatype->insert(std::make_pair(*URLCount, PropertyValue));
2947                 
2948                 } else {
2949                 
2950                         // Something else we don't know about so append
2951                         // to the tokens variable.
2952                 
2953                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
2954                 
2955                                 if (FirstToken == TRUE){
2956                         
2957                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
2958                                         FirstToken = FALSE;
2959                         
2960                                 } else {
2961                         
2962                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
2963                         
2964                                 }
2965                 
2966                         }
2967                 
2968                 }
2969         
2970         }
2971         
2972         // Add the data to the General/Home/Work address variables.
2973         
2974         CaptureString(&PropertySeg2, FALSE);
2975                         
2976         WebsiteList->insert(std::make_pair(*URLCount, PropertySeg2));
2977         
2978         if (!PropertyTokens.IsEmpty()){
2979         
2980                 WebsiteListTokens->insert(std::make_pair(*URLCount, PropertyTokens));
2981                         
2982         }
2983         
2986 void SplitValues(wxString *PropertyLine, 
2987         std::map<int,int> *SplitPoints, 
2988         std::map<int,int> *SplitLength, 
2989         int intSize){
2990         
2991         size_t intPropertyLen = PropertyLine->Len();
2992         int intSplitsFound = 0;
2993         int intSplitSize = 0;
2994         int intSplitSeek = 0;
2995         
2996         for (int i = intSize; i <= intPropertyLen; i++){
2998                 intSplitSize++;
2999         
3000                 if (PropertyLine->Mid(i, 1) == wxT(";") &&
3001                     PropertyLine->Mid((i - 1), 1) != wxT("\\")){
3002            
3003                     if (intSplitsFound == 0){
3004             
3005                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
3006           
3007                     } else {
3008            
3009                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
3010             
3011                     }
3012             
3013                     SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
3014             
3015                     intSplitsFound++;
3016                     intSplitSeek = i;
3017                     intSplitSize = 0;
3018             
3019                 }
3021         }
3023         if (intSplitsFound == 0){
3025                 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
3026                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
3028         } else {
3030                 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
3031                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
3033         }
3037 void CheckType(wxString *PropertySeg1, 
3038         std::map<int,int> *SplitPoints, 
3039         std::map<int,int> *SplitLength, 
3040         int *intPrevValue, 
3041         PropertyType *PropType){
3042         
3043         wxString PropertyData;
3044         wxString PropertyName;
3045         wxString PropertyValue;
3046         std::map<int,int>::iterator SLiter;
3047         
3048         for (std::map<int, int>::iterator intiter = SplitPoints->begin(); 
3049         intiter != SplitPoints->end(); ++intiter){
3050         
3051                 SLiter = SplitLength->find(intiter->first);
3052         
3053                 PropertyData = PropertySeg1->Mid(*intPrevValue, (SLiter->second));
3054                 
3055                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
3056                 PropertyName = PropertyElement.GetNextToken();                          
3057                 PropertyValue = PropertyElement.GetNextToken();
3058                 
3059                 *intPrevValue = intiter->second;
3060                 
3061                 if (PropertyName == wxT("TYPE")){
3062                                 
3063                         if (PropertyValue == wxT("work")){
3064                         
3065                                 *PropType = PROPERTY_WORK;
3066                                                         
3067                         } else if (PropertyValue == wxT("home")){
3069                                 *PropType = PROPERTY_HOME;
3070                                                         
3071                         } else {
3072                         
3073                                 *PropType = PROPERTY_NONE;
3074                         
3075                         }
3076                 
3077                         return;
3078                 
3079                 }
3080         
3081         }
3082         
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