Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source code, headers and unit testing for the GEO vCard property for ContactDat...
[xestiaab/.git] / source / contacteditor / ContactDataObject.cpp
1 // ContactDataObject.cpp - Client Data Object.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "ContactDataObject.h"
21 ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
22         
23         if (!wxFileExists(Filename)){
24         
25                 return CONTACTLOAD_FILEMISSING;
26         
27         }
28         
29         wxFile ContactFile;
30         
31         if (!ContactFile.Open(Filename, wxFile::read, wxS_DEFAULT)){
32         
33                 return CONTACTLOAD_FILEERROR;
34         
35         }
36         
37         // Check that the vCard is a valid vCard 4.0 file.
39         vCard vCard4FormatCheck;
40         
41         vCard4FormatCheck.LoadFile(Filename);
42         
43         if (vCard4FormatCheck.Get("VERSION") != wxT("4.0")){
44         
45                 return CONTACTLOAD_FILEINVALIDFORMAT;
46         
47         }
49         // Check that the vCard meets the base specification.
50         
51         if (!vCard4FormatCheck.MeetBaseSpecification()){
52         
53                 return CONTACTLOAD_FILEBASESPECFAIL;
54         
55         }
56         
57         wxStringTokenizer wSTContactFileLines(vCard4FormatCheck.WriteString(), wxT("\r\n"));
58         
59         std::map<int, wxString> ContactFileLines;
61         int ContactLineSeek = 0;
63         while (wSTContactFileLines.HasMoreTokens() == TRUE){
65                 wxString ContactLine = wSTContactFileLines.GetNextToken();
66                 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
67                 ContactLineSeek++;              
68         
69         }
70         
71         wxString wxSPropertyNextLine;
72         
73         bool ExtraLineSeek = TRUE;
74         bool QuoteMode = FALSE;
75         bool PropertyFind = TRUE;
76         bool KindProcessed = FALSE;
77         bool NameProcessed = FALSE;
78         bool GenderProcessed = FALSE;
79         bool BirthdayProcessed = FALSE;
80         bool AnniversaryProcessed = FALSE;
81         int ContactLineLen = 0;
82         int QuoteBreakPoint = 0;
83         int GroupCount = 0;
84         int FNCount = 0;
85         int NicknameCount = 0;
86         int TimeZoneCount = 0;
87         int AddressCount = 0;
88         int EmailCount = 0;
89         int IMCount = 0;
90         int TelephoneCount = 0;
91         int LanguageCount = 0;
92         int GeographicCount = 0;
93         wxString ContactLine;
94         wxString PropertyLine;
95         wxString PropertySeg1;
96         wxString PropertySeg2;
97         wxString PropertyNextLine;
98         wxString Property;
99         
100         for (std::map<int,wxString>::iterator iter = ContactFileLines.begin(); 
101          iter != ContactFileLines.end(); ++iter){
103                 ExtraLineSeek = TRUE;
104                 QuoteMode = FALSE;
105                 PropertyFind = TRUE;
106                 ContactLineLen = 0;
107                 QuoteBreakPoint = 0;
108                 ContactLine.Clear();
109                 PropertyLine.Clear();
110                 PropertySeg1.Clear();
111                 PropertySeg2.Clear();
112                 Property.Clear();
113          
114                 ContactLine = iter->second;
115                 
116                 while (ExtraLineSeek == TRUE){
117                 
118                         // Check if there is extra data on the next line 
119                         // (indicated by space or tab at the start) and add data.
120                 
121                         iter++;
122                         
123                         if (iter == ContactFileLines.end()){
124                         
125                                 iter--;
126                                 break;
127                         
128                         }                       
129                 
130                         PropertyNextLine = iter->second;
131                 
132                         if (PropertyNextLine.Mid(0, 1) == wxT(" ") || PropertyNextLine.Mid(0, 1) == wxT("\t")){
133                 
134                                 PropertyNextLine.Remove(0, 1);
135                                 ContactLine.Append(PropertyNextLine);
136                 
137                         } else {
138                         
139                                 iter--;
140                                 ExtraLineSeek = FALSE;
141                         
142                         }
143                 
144                 }
146                 ContactLineLen = ContactLine.Len();
147                 
148                 // Make sure we are not in quotation mode.
149                 // Make sure colon does not have \ or \\ before it.
150                 
151                 for (int i = 0; i <= ContactLineLen; i++){
152                 
153                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
154                         
155                                 PropertyFind = FALSE;
156                         
157                         } else if (PropertyFind == TRUE){
158                         
159                                 Property.Append(ContactLine.Mid(i, 1));
160                         
161                         }               
162                 
163                         if (ContactLine.Mid(i, 1) == wxT("\"")){
164                         
165                                 if (QuoteMode == TRUE){
166                                 
167                                         QuoteMode = FALSE;
168                                 
169                                 } else {
170                         
171                                         QuoteMode = TRUE;
172                                         
173                                 }
174                         
175                         }
176                         
177                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
178                         
179                                 QuoteBreakPoint = i;
180                                 break;
181                         
182                         }
183                 
184                 }
185                 
186                 // Split that line at the point into two variables (ignore the colon).
187                 
188                 PropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
189                 PropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
190                 
191                  if (Property == wxT("KIND") && KindProcessed == FALSE){
192                                 
193                         ProcessKind(PropertySeg2);
194                 
195                 } else if (Property == wxT("MEMBER")){
197                         ProcessMember(PropertySeg1, PropertySeg2, &GroupCount);
198                         GroupCount++;   
199                 
200                 } else if (Property == wxT("FN")){
201                 
202                         ProcessFN(PropertySeg1, PropertySeg2, &FNCount);
203                         FNCount++;
204                 
205                 } else if (Property == wxT("N") && NameProcessed == FALSE){
206                 
207                         ProcessN(PropertySeg1, PropertySeg2);
208                         NameProcessed = TRUE;
209                 
210                 } else if (Property == wxT("NICKNAME")){
211                                                 
212                         ProcessNickname(PropertySeg1, PropertySeg2, &NicknameCount);
213                         NicknameCount++;
214                         
215                 } else if (Property == wxT("GENDER") && GenderProcessed == FALSE){
216                 
217                         ProcessGender(PropertySeg1, PropertySeg2);
218                         GenderProcessed = TRUE;
219                 
220                 } else if (Property == wxT("BDAY") && BirthdayProcessed == FALSE){
221                 
222                         ProcessBirthday(PropertySeg1, PropertySeg2);
223                         BirthdayProcessed = TRUE;
224                 
225                 } else if (Property == wxT("ANNIVERSARY") && AnniversaryProcessed == FALSE){
226                 
227                         ProcessAnniversary(PropertySeg1, PropertySeg2);
228                         AnniversaryProcessed = TRUE;
229                 
230                 } else if (Property == wxT("TZ")){
231                 
232                         ProcessTimeZone(PropertySeg1, PropertySeg2, &TimeZoneCount);
233                         TimeZoneCount++;
234                 
235                 } else if (Property == wxT("ADR")){
236                 
237                         ProcessAddress(PropertySeg1, PropertySeg2, &AddressCount);
238                         AddressCount++;
239                 
240                 } else if (Property == wxT("EMAIL")){
241                                         
242                         ProcessEmail(PropertySeg1, PropertySeg2, &EmailCount);  
243                         EmailCount++;
244                 
245                 } else if (Property == wxT("IMPP")){
246                 
247                         ProcessIM(PropertySeg1, PropertySeg2, &IMCount);
248                         IMCount++;
249                         
250                 } else if (Property == wxT("TEL")){
251                                 
252                         ProcessTelephone(PropertySeg1, PropertySeg2, &TelephoneCount);
253                         TelephoneCount++;
254                 
255                 } else if (Property == wxT("LANG")){
256                 
257                         // See frmContactEditor-LoadLanguage.cpp
258                         
259                         ProcessLanguage(PropertySeg1, PropertySeg2, &LanguageCount);
260                         LanguageCount++;
261                 
262                 } else if (Property == wxT("GEO")){
263                 
264                         // See frmContactEditor-LoadGeo.cpp
265                         
266                         ProcessGeographic(PropertySeg1, PropertySeg2, &GeographicCount);        
267                         GeographicCount++;
268                 
269                 }
270                 
271         }
272         
273         return CONTACTLOAD_OK;
277 void ContactDataObject::ProcessKind(wxString KindType){
279         if (KindType == wxT("individual")){
280                         
281                 ContactKind = CONTACTKIND_INDIVIDUAL;
282                         
283         } else if (KindType == wxT("group")){
284                         
285                 ContactKind = CONTACTKIND_GROUP;
286                         
287         } else if (KindType == wxT("org")){
288                         
289                 ContactKind = CONTACTKIND_ORGANISATION;
290                         
291         } else if (KindType == wxT("location")){
292                         
293                 ContactKind = CONTACTKIND_LOCATION;
294                         
295         } else {
296                         
297                 ContactKind = CONTACTKIND_NONE;                 
298         }
302 void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount){
304         std::map<int, int> SplitPoints;
305         std::map<int, int> SplitLength;
307         int intPrevValue = 8;
308         int intPref = 0;                        
309         int intType = 0;
310         
311         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
313         intPrevValue = 7;
314         
315         wxString PropertyName;
316         wxString PropertyValue;
317         wxString PropertyData;
318         wxString PropertyTokens;
319         std::map<int,int>::iterator SLiter;
320         bool FirstToken = TRUE;
321         
322         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
323         intiter != SplitPoints.end(); ++intiter){
324         
325                 SLiter = SplitLength.find(intiter->first);
326         
327                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
328                 
329                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
330                 PropertyName = PropertyElement.GetNextToken();                          
331                 PropertyValue = PropertyElement.GetNextToken();
332                 
333                 intPrevValue = intiter->second;
334                 
335                 CaptureString(&PropertyValue, FALSE);
336         
337                 if (PropertyName == wxT("ALTID")){
339                         GroupsListAltID.erase(*GroupCount);
340                         GroupsListAltID.insert(std::make_pair(*GroupCount, PropertyValue));
341                 
342                 } else if (PropertyName == wxT("PID")){
344                         GroupsListPID.erase(*GroupCount);
345                         GroupsListPID.insert(std::make_pair(*GroupCount, PropertyValue));
346                 
347                 } else if (PropertyName == wxT("PREF")){
349                         int PriorityNumber = 0;
350                         bool ValidNumber = TRUE;
351                         
352                         try{
353                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
354                         }
355                         
356                         catch(std::invalid_argument &e){
357                                 ValidNumber = FALSE;
358                         }
360                         if (ValidNumber == TRUE){
362                                 GroupsListPref.erase(*GroupCount);
363                                 GroupsListPref.insert(std::make_pair(*GroupCount, PriorityNumber));
364                 
365                         }
366                 
367                 } else if (PropertyName == wxT("MEDIATYPE")){
369                         GroupsListMediaType.erase(*GroupCount);
370                         GroupsListMediaType.insert(std::make_pair(*GroupCount, PropertyValue));
371                 
372                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
373                         
374                         if (FirstToken == TRUE){
375                                 
376                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
377                                 FirstToken = FALSE;
378                                 
379                         } else {
380                         
381                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
382                                 
383                         }
384                         
385                 }
386                 
387         }
389         GroupsList.insert(std::make_pair(*GroupCount, PropertySeg2));
391         if (!PropertyTokens.IsEmpty()){
392         
393                 GroupsListTokens.insert(std::make_pair(*GroupCount, PropertyTokens));
394         
395         }
400 void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount){
402         std::map<int, int> SplitPoints;
403         std::map<int, int> SplitLength;
405         int intPrevValue = 4;
406         int intPref = 0;                        
407         int intType = 0;
408         
409         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
411         intPrevValue = 3;
412         
413         wxString PropertyName;
414         wxString PropertyValue;
415         wxString PropertyData;
416         wxString PropertyTokens;
417         std::map<int,int>::iterator SLiter;
418         bool FirstToken = TRUE;
419         
420         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
421         intiter != SplitPoints.end(); ++intiter){
422         
423                 SLiter = SplitLength.find(intiter->first);
424         
425                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
426                 
427                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
428                 PropertyName = PropertyElement.GetNextToken();                          
429                 PropertyValue = PropertyElement.GetNextToken();
430                 
431                 intPrevValue = intiter->second;
432                 
433                 CaptureString(&PropertyValue, FALSE);
434                 
435                 if (PropertyName == wxT("TYPE")){
437                         if (!PropertyValue.IsEmpty() || PropertyValue == wxT("home") ||
438                                 PropertyValue == wxT("work") ){
440                                 FullNamesListType.erase(*FNCount);
441                                 FullNamesListType.insert(std::make_pair(*FNCount, PropertyValue));
442                 
443                         }
444                 
445                 } else if (PropertyName == wxT("LANGUAGE")){
447                         FullNamesListLanguage.erase(*FNCount);
448                         FullNamesListLanguage.insert(std::make_pair(*FNCount, PropertyValue));
449                 
450                 } else if (PropertyName == wxT("ALTID")){
451                 
452                         FullNamesListAltID.erase(*FNCount);
453                         FullNamesListAltID.insert(std::make_pair(*FNCount, PropertyValue));
454                 
455                 } else if (PropertyName == wxT("PID")){
457                         FullNamesListPID.erase(*FNCount);
458                         FullNamesListPID.insert(std::make_pair(*FNCount, PropertyValue));
459                 
460                 } else if (PropertyName == wxT("PREF")){
462                         int PriorityNumber = 0;
463                         bool ValidNumber = TRUE;
464                         
465                         try{
466                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
467                         }
468                         
469                         catch(std::invalid_argument &e){
470                                 ValidNumber = FALSE;
471                         }
473                         if (ValidNumber == TRUE){
475                                 FullNamesListPref.erase(*FNCount);
476                                 FullNamesListPref.insert(std::make_pair(*FNCount, PriorityNumber));
478                         }
479                 
480                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
481                         
482                         if (FirstToken == TRUE){
483                                 
484                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
485                                 FirstToken = FALSE;
486                                 
487                         } else {
488                         
489                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
490                                 
491                         }
492                         
493                 } 
494         
495         }
497         FullNamesList.insert(std::make_pair(*FNCount, PropertySeg2));
499         if (!PropertyTokens.IsEmpty()){
500         
501                 FullNamesListTokens.insert(std::make_pair(*FNCount, PropertyTokens));
502         
503         }
507 void ContactDataObject::ProcessN(wxString PropertySeg1, wxString PropertySeg2){
509         std::map<int, int> SplitPoints;
510         std::map<int, int> SplitLength;
512         int intPrevValue = 3;
513         int intPref = 0;                        
514         int intType = 0;
515         
516         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
517         
518         intPrevValue = 2;
519         
520         wxString PropertyName;
521         wxString PropertyValue;
522         wxString PropertyData;
523         wxString PropertyTokens;
524         std::map<int,int>::iterator SLiter;
525         bool FirstToken = TRUE;
526         
527         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
528         intiter != SplitPoints.end(); ++intiter){
529         
530                 SLiter = SplitLength.find(intiter->first);
531         
532                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
533                 
534                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
535                 PropertyName = PropertyElement.GetNextToken();                          
536                 PropertyValue = PropertyElement.GetNextToken();
537                 
538                 intPrevValue = intiter->second;
539                 
540                 CaptureString(&PropertyValue, FALSE);
541                 
542                 if (PropertyName == wxT("ALTID")){
544                         NameAltID = PropertyValue;
545                 
546                 } else if (PropertyName == wxT("LANGUAGE")){
547                 
548                         NameLanguage = PropertyValue;
549                 
550                 } else if (PropertyName == wxT("SORT-AS")){
551                 
552                         if (PropertyValue.Left(1) == wxT("\"") && PropertyValue.Right(1) == wxT("\"") &&
553                                 PropertyValue.Len() >= 3){
554                                 NameDisplayAs = PropertyValue.Mid(1, (PropertyValue.Len() - 2));
555                         }
556                 
557                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
558                         
559                         if (FirstToken == TRUE){
560                                 
561                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
562                                 FirstToken = FALSE;
563                                 
564                         } else {
565                         
566                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
567                                 
568                         }
569                         
570                 }
571         
572         }
573         
574         // Split the name data.
575         
576         int intSplitSeek = 0;           
577         int intSplitsFound = 0;
578         int intSplitSize = 0;
579         int intPropertyLen = PropertySeg2.Len();
580         
581         std::map<int,wxString> NameValues;
582         intPrevValue = 0;                                       
583         
584         for (int i = 0; i <= intPropertyLen; i++){
585         
586                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
587                         
588                         NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, intSplitSize)));
589                         
590                         intSplitSeek = i;
591                         intSplitSeek++;
592                         
593                         if (intSplitsFound == 4){
594                         
595                                 NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, wxString::npos)));
596                                 break;
597                         
598                         }
599                         
600                         intSplitSize = 0;
601                         continue;
602         
603                 }
604                 
605                 intSplitSize++;
607         }
608         
609         // Split the data into several parts.
610                         
611         for (std::map<int, wxString>::iterator iter = NameValues.begin(); 
612         iter != NameValues.end(); ++iter){
613         
614                 if (iter->first == 1){
615                 
616                         // Deal with family name.
617                         
618                         NameSurname = iter->second;
619                 
620                 } else if (iter->first == 2){
621                 
622                         // Deal with given names.
623                         
624                         NameForename = iter->second;
625                 
626                 } else if (iter->first == 3){
627                 
628                         // Deal with additional names.
629                         
630                         NameOtherNames = iter->second;
631                 
632                 } else if (iter->first == 4){
633                 
634                         // Deal with honorifix prefixes and suffixes.
636                         NameTitle = iter->second;
637                 
638                         iter++;
639                         
640                         if (iter == NameValues.end()){
641                         
642                                 break;
643                         
644                         }
645                 
646                         NameSuffix = iter->second;
647                 
648                 }
649         
650         }
651         
652         // Add the name token data.
653         
654         if (!PropertyTokens.IsEmpty()){
655         
656                 NameTokens = PropertyTokens;
657         
658         }
662 void ContactDataObject::ProcessNickname(wxString PropertySeg1, wxString PropertySeg2, int *NicknameCount){
664         std::map<int, int> SplitPoints;
665         std::map<int, int> SplitLength;
667         int intPrevValue = 10;
668         int intPref = 0;                        
669         
670         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
671         
672         intPrevValue = 9;
673         
674         PropertyType PropType = PROPERTY_NONE;
675         
676         // Look for type before continuing.
677         
678         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
679         
680         intPrevValue = 9;
681         
682         std::map<int, wxString> *NicknamesList = NULL;
683         std::map<int, wxString> *NicknamesListType = NULL;
684         std::map<int, wxString> *NicknamesListLanguage = NULL;
685         std::map<int, wxString> *NicknamesListAltID = NULL;
686         std::map<int, wxString> *NicknamesListPID = NULL;
687         std::map<int, wxString> *NicknamesListTokens = NULL;            
688         std::map<int, int> *NicknamesListPref = NULL;
689         
690         switch(PropType){
691                 case PROPERTY_NONE:
692                         NicknamesList = &GeneralNicknamesList;
693                         NicknamesListType = &GeneralNicknamesListType;
694                         NicknamesListLanguage = &GeneralNicknamesListLanguage;
695                         NicknamesListAltID = &GeneralNicknamesListAltID;
696                         NicknamesListPID = &GeneralNicknamesListPID;
697                         NicknamesListTokens = &GeneralNicknamesListTokens;
698                         NicknamesListPref = &GeneralNicknamesListPref;
699                         break;
700                 case PROPERTY_HOME:
701                         NicknamesList = &HomeNicknamesList;
702                         NicknamesListType = &HomeNicknamesListType;
703                         NicknamesListLanguage = &HomeNicknamesListLanguage;
704                         NicknamesListAltID = &HomeNicknamesListAltID;
705                         NicknamesListPID = &HomeNicknamesListPID;
706                         NicknamesListTokens = &HomeNicknamesListTokens;
707                         NicknamesListPref = &HomeNicknamesListPref;
708                         break;
709                 case PROPERTY_WORK:
710                         NicknamesList = &BusinessNicknamesList;
711                         NicknamesListType = &BusinessNicknamesListType;
712                         NicknamesListLanguage = &BusinessNicknamesListLanguage;
713                         NicknamesListAltID = &BusinessNicknamesListAltID;
714                         NicknamesListPID = &BusinessNicknamesListPID;
715                         NicknamesListTokens = &BusinessNicknamesListTokens;
716                         NicknamesListPref = &BusinessNicknamesListPref;
717                         break;
718         }
719         
720         std::map<int, int>::iterator SLiter;    
721         wxString PropertyData;
722         wxString PropertyName;
723         wxString PropertyValue;
724         wxString PropertyTokens;
725         bool FirstToken = TRUE;
726         
727         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
728         intiter != SplitPoints.end(); ++intiter){
729         
730                 SLiter = SplitLength.find(intiter->first);
731         
732                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
733                 
734                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
735                 PropertyName = PropertyElement.GetNextToken();                          
736                 PropertyValue = PropertyElement.GetNextToken();
737                 
738                 intPrevValue = intiter->second;
739                 
740                 CaptureString(&PropertyValue, FALSE);
741                 
742                 if (PropertyName == wxT("ALTID")){
744                         NicknamesListAltID->erase(*NicknameCount);
745                         NicknamesListAltID->insert(std::make_pair(*NicknameCount, PropertyValue));
746                 
747                 } else if (PropertyName == wxT("PID")){
749                         NicknamesListPID->erase(*NicknameCount);
750                         NicknamesListPID->insert(std::make_pair(*NicknameCount, PropertyValue));        
752                 } else if (PropertyName == wxT("PREF")){
754                         int PriorityNumber = 0;
755                         bool ValidNumber = TRUE;
756                         
757                         try{
758                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
759                         }
760                         
761                         catch(std::invalid_argument &e){
762                                 ValidNumber = FALSE;
763                         }
765                         if (ValidNumber == TRUE){
767                                 NicknamesListPref->erase(*NicknameCount);
768                                 NicknamesListPref->insert(std::make_pair(*NicknameCount, PriorityNumber));
770                         }
771                 
772                 } else if (PropertyName == wxT("LANGUAGE")){
774                         NicknamesListLanguage->erase(*NicknameCount);
775                         NicknamesListLanguage->insert(std::make_pair(*NicknameCount, PropertyValue));   
777                 } else {
778                 
779                         // Something else we don't know about so append
780                         // to the tokens variable.
781                 
782                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
783                 
784                                 if (FirstToken == TRUE){
785                         
786                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
787                                         FirstToken = FALSE;
788                         
789                                 } else {
790                         
791                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
792                         
793                                 }
794                 
795                         }
796                 
797                 }
798                 
799         }
800         
801         NicknamesList->insert(std::make_pair(*NicknameCount, PropertySeg2));
802         
803         // Add the name token data.
804         
805         if (!PropertyTokens.IsEmpty()){
806         
807                 NicknamesListTokens->insert(std::make_pair(*NicknameCount, PropertyTokens));
808         
809         }
813 void ContactDataObject::ProcessGender(wxString PropertySeg1, wxString PropertySeg2){
815         std::map<int, int> SplitPoints;
816         std::map<int, int> SplitLength;
817         std::map<int, int>::iterator SLiter;                    
818         wxString PropertyData;
819         wxString PropertyName;
820         wxString PropertyValue;
821         wxString PropertyTokens;
822         bool FirstToken = TRUE;
823         int intPrevValue = 8;
825         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
827         intPrevValue = 7;                       
828         
829         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
830         intiter != SplitPoints.end(); ++intiter){
831         
832                 SLiter = SplitLength.find(intiter->first);
833         
834                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
835                 
836                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
837                 PropertyName = PropertyElement.GetNextToken();                          
838                 PropertyValue = PropertyElement.GetNextToken();
839                 
840                 intPrevValue = intiter->second;
841                 
842                 // Process properties.
843                 
844                 size_t intPropertyValueLen = PropertyValue.Len();
845                 
846                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
847                         
848                         PropertyValue.Trim();
849                         PropertyValue.RemoveLast();
850                         
851                 }                               
852                 
853                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
854                         
855                         PropertyValue.Remove(0, 1);
856                         
857                 }                               
858                 
859                 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
861                         if (FirstToken == TRUE){
862         
863                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
864                                 FirstToken = FALSE;
865         
866                         } else {
867         
868                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
869         
870                         }
872                 }
873         
874         }       
876         wxStringTokenizer GenderData (PropertySeg2, wxT(";"));
877         
878         wxString GenderComponent;
879         
880         if (GenderData.CountTokens() >= 2){
881         
882                 Gender = GenderData.GetNextToken();
883                 GenderDetails = GenderData.GetString();
884         
885                 CaptureString(&GenderDetails, FALSE);
886                                                 
887         } else {
888         
889                 Gender = GenderData.GetNextToken();
890         
891         }
892         
893         if (!PropertyTokens.IsEmpty()){
894         
895                 GenderTokens = PropertyTokens;
896         
897         }
901 void ContactDataObject::ProcessBirthday(wxString PropertySeg1, wxString PropertySeg2){
903         // Process date. Preserve the remainder in the string.
905         std::map<int, int> SplitPoints;
906         std::map<int, int> SplitLength;
907         std::map<int, int>::iterator SLiter;                    
908         wxString PropertyData;
909         wxString PropertyName;
910         wxString PropertyValue;
911         wxString PropertyTokens;
912         bool BirthdayText = FALSE;
913         int intPrevValue = 6;
915         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
917         intPrevValue = 5;
919         // Look for type before continuing.
921         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
922         intiter != SplitPoints.end(); ++intiter){
924                 SLiter = SplitLength.find(intiter->first);
926                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
927         
928                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
929                 PropertyName = PropertyElement.GetNextToken();                          
930                 PropertyValue = PropertyElement.GetNextToken();
931         
932                 intPrevValue = intiter->second;
933         
934                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){
935         
936                         CaptureString(&PropertySeg2, FALSE);
937                         Birthday = PropertySeg2;
938                         BirthdayText = TRUE;
939         
940                 }
942         }
944         // Setup blank lines for later on.
945         
946         intPrevValue = 5;
947         bool FirstToken = TRUE;
949         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
950         intiter != SplitPoints.end(); ++intiter){
952                 SLiter = SplitLength.find(intiter->first);
954                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
955         
956                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
957                 PropertyName = PropertyElement.GetNextToken();                          
958                 PropertyValue = PropertyElement.GetNextToken();
959         
960                 intPrevValue = intiter->second;
961         
962                 // Process properties.
963         
964                 CaptureString(&PropertyValue, FALSE);
965         
966                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
967                 
968                         PropertyValue.Trim();
969                         PropertyValue.RemoveLast();
970                 
971                 }                               
972         
973                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
974                 
975                         PropertyValue.Remove(0, 1);
976                 
977                 }                               
978         
979                 if (PropertyName == wxT("ALTID")){
981                         BirthdayAltID = PropertyValue;
982         
983                 } else if (PropertyName == wxT("CALSCALE")){
984         
985                         BirthdayCalScale = PropertyValue;
986         
987                 } else if (PropertyName != wxT("VALUE")) {
988         
989                         // Something else we don't know about so append
990                         // to the tokens variable.
991                 
992                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
993                 
994                                 if (FirstToken == TRUE){
995         
996                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
997                                         FirstToken = FALSE;
998         
999                                 } else {
1000         
1001                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1002         
1003                                 }
1004                                 
1005                         }
1006                         
1007                 }
1009         }       
1011         // Add the data to the variables and form.
1012         
1013         if (BirthdayText == FALSE){
1014         
1015                 Birthday = PropertySeg2;
1017         }
1018         
1019         if (!PropertyTokens.IsEmpty()){
1020         
1021                 BirthdayTokens = PropertyTokens;
1023         }
1027 void ContactDataObject::ProcessAnniversary(wxString PropertySeg1, wxString PropertySeg2){
1029         // Process date. Preserve the remainder in the string.
1031         std::map<int, int> SplitPoints;
1032         std::map<int, int> SplitLength;
1033         std::map<int, int>::iterator SLiter;                    
1034         wxString PropertyData;
1035         wxString PropertyName;
1036         wxString PropertyValue;
1037         wxString PropertyTokens;
1038         bool AnniversaryText = FALSE;
1039         int intPrevValue = 13;
1041         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1043         intPrevValue = 12;
1045         // Look for type before continuing.
1047         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1048         intiter != SplitPoints.end(); ++intiter){
1050                 SLiter = SplitLength.find(intiter->first);
1052                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1053         
1054                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1055                 PropertyName = PropertyElement.GetNextToken();                          
1056                 PropertyValue = PropertyElement.GetNextToken();
1057         
1058                 intPrevValue = intiter->second;
1059         
1060                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){
1061         
1062                         CaptureString(&PropertySeg2, FALSE);
1063                         Anniversary = PropertySeg2;
1064                         AnniversaryText = TRUE;
1065         
1066                 }
1068         }
1070         // Setup blank lines for later on.
1071         
1072         intPrevValue = 12;
1073         bool FirstToken = TRUE;
1075         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1076         intiter != SplitPoints.end(); ++intiter){
1078                 SLiter = SplitLength.find(intiter->first);
1080                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1081         
1082                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1083                 PropertyName = PropertyElement.GetNextToken();                          
1084                 PropertyValue = PropertyElement.GetNextToken();
1085         
1086                 intPrevValue = intiter->second;
1087         
1088                 // Process properties.
1089         
1090                 CaptureString(&PropertyValue, FALSE);
1091         
1092                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
1093                 
1094                         PropertyValue.Trim();
1095                         PropertyValue.RemoveLast();
1096                 
1097                 }                               
1098         
1099                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
1100                 
1101                         PropertyValue.Remove(0, 1);
1102                 
1103                 }                               
1104         
1105                 if (PropertyName == wxT("ALTID")){
1107                         AnniversaryAltID = PropertyValue;
1108         
1109                 } else if (PropertyName == wxT("CALSCALE")){
1110         
1111                         AnniversaryCalScale = PropertyValue;
1112         
1113                 } else if (PropertyName != wxT("VALUE")) {
1114         
1115                         // Something else we don't know about so append
1116                         // to the tokens variable.
1117                 
1118                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
1119                 
1120                                 if (FirstToken == TRUE){
1121         
1122                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1123                                         FirstToken = FALSE;
1124         
1125                                 } else {
1126         
1127                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1128         
1129                                 }
1130                                 
1131                         }
1132                         
1133                 }
1135         }       
1137         // Add the data to the variables and form.
1138         
1139         if (AnniversaryText == FALSE){
1140         
1141                 Anniversary = PropertySeg2;
1143         }
1144         
1145         if (!PropertyTokens.IsEmpty()){
1146         
1147                 AnniversaryTokens = PropertyTokens;
1149         }
1153 void ContactDataObject::ProcessTimeZone(wxString PropertySeg1, wxString PropertySeg2, int *TimeZoneCount){
1155         std::map<int, int> SplitPoints;
1156         std::map<int, int> SplitLength;
1158         int intPrevValue = 4;
1159         int intPref = 0;                        
1160         
1161         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1162         
1163         intPrevValue = 3;
1164         
1165         PropertyType PropType = PROPERTY_NONE;
1166         
1167         // Look for type before continuing.
1168         
1169         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1170         
1171         intPrevValue = 3;
1172         
1173         std::map<int, wxString> *TZList = NULL;
1174         std::map<int, wxString> *TZListType = NULL;
1175         std::map<int, wxString> *TZListMediatype = NULL;
1176         std::map<int, wxString> *TZListAltID = NULL;
1177         std::map<int, wxString> *TZListPID = NULL;
1178         std::map<int, wxString> *TZListTokens = NULL;           
1179         std::map<int, int> *TZListPref = NULL;
1180         
1181         switch(PropType){
1182                 case PROPERTY_NONE:
1183                         TZList = &GeneralTZList;
1184                         TZListType = &GeneralTZListType;
1185                         TZListMediatype = &GeneralTZListMediatype;
1186                         TZListAltID = &GeneralTZListAltID;
1187                         TZListPID = &GeneralTZListPID;
1188                         TZListTokens = &GeneralTZListTokens;
1189                         TZListPref = &GeneralTZListPref;
1190                         break;
1191                 case PROPERTY_HOME:
1192                         TZList = &HomeTZList;
1193                         TZListType = &HomeTZListType;
1194                         TZListMediatype = &HomeTZListMediatype;
1195                         TZListAltID = &HomeTZListAltID;
1196                         TZListPID = &HomeTZListPID;
1197                         TZListTokens = &HomeTZListTokens;
1198                         TZListPref = &HomeTZListPref;
1199                         break;
1200                 case PROPERTY_WORK:
1201                         TZList = &BusinessTZList;
1202                         TZListType = &BusinessTZListType;
1203                         TZListMediatype = &BusinessTZListMediatype;
1204                         TZListAltID = &BusinessTZListAltID;
1205                         TZListPID = &BusinessTZListPID;
1206                         TZListTokens = &BusinessTZListTokens;
1207                         TZListPref = &BusinessTZListPref;
1208                         break;
1209         }
1210         
1211         std::map<int, int>::iterator SLiter;    
1212         wxString PropertyData;
1213         wxString PropertyName;
1214         wxString PropertyValue;
1215         wxString PropertyTokens;
1216         bool FirstToken = TRUE;
1217         
1218         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1219         intiter != SplitPoints.end(); ++intiter){
1220         
1221                 SLiter = SplitLength.find(intiter->first);
1222         
1223                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1224                 
1225                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1226                 PropertyName = PropertyElement.GetNextToken();                          
1227                 PropertyValue = PropertyElement.GetNextToken();
1228                 
1229                 intPrevValue = intiter->second;
1230                 
1231                 CaptureString(&PropertyValue, FALSE);
1233                 if (PropertyName == wxT("ALTID")){
1235                         TZListAltID->erase(*TimeZoneCount);
1236                         TZListAltID->insert(std::make_pair(*TimeZoneCount, PropertyValue));
1237                 
1238                 } else if (PropertyName == wxT("PID")){
1240                         TZListPID->erase(*TimeZoneCount);
1241                         TZListPID->insert(std::make_pair(*TimeZoneCount, PropertyValue));       
1243                 } else if (PropertyName == wxT("PREF")){
1245                         int PriorityNumber = 0;
1246                         bool ValidNumber = TRUE;
1247                         
1248                         try{
1249                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1250                         }
1251                         
1252                         catch(std::invalid_argument &e){
1253                                 ValidNumber = FALSE;
1254                         }
1256                         if (ValidNumber == TRUE){
1258                                 TZListPref->erase(*TimeZoneCount);
1259                                 TZListPref->insert(std::make_pair(*TimeZoneCount, PriorityNumber));
1261                         }
1262                 
1263                 } else if (PropertyName == wxT("MEDIATYPE")){
1265                         TZListMediatype->erase(*TimeZoneCount);
1266                         TZListMediatype->insert(std::make_pair(*TimeZoneCount, PropertyValue)); 
1268                 } else {
1269                 
1270                         // Something else we don't know about so append
1271                         // to the tokens variable.
1272                 
1273                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1274                 
1275                                 if (FirstToken == TRUE){
1276                         
1277                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1278                                         FirstToken = FALSE;
1279                         
1280                                 } else {
1281                         
1282                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1283                         
1284                                 }
1285                 
1286                         }
1287                 
1288                 }
1289                 
1290         }
1291         
1292         TZList->insert(std::make_pair(*TimeZoneCount, PropertySeg2));
1293         
1294         // Add the name token data.
1295         
1296         if (!PropertyTokens.IsEmpty()){
1297         
1298                 TZListTokens->insert(std::make_pair(*TimeZoneCount, PropertyTokens));
1299         
1300         }
1305 void ContactDataObject::ProcessAddress(wxString PropertySeg1, wxString PropertySeg2, int *AddressCount){
1307         size_t intPropertyLen = PropertySeg1.Len();
1308         std::map<int, int> SplitPoints;
1309         std::map<int, int> SplitLength;
1310         std::map<int, int>::iterator SLiter;                    
1311         wxString PropertyData;
1312         wxString PropertyName;
1313         wxString PropertyValue;
1314         wxString PropertyTokens;
1315         wxString AddressLabel;
1316         wxString AddressLang;
1317         wxString AddressAltID;
1318         wxString AddressPID;
1319         wxString AddressTokens;
1320         wxString AddressGeo;
1321         wxString AddressTimezone;
1322         wxString AddressType;
1323         wxString AddressMediatype;
1324         wxString AddressPOBox;
1325         wxString AddressExtended;
1326         wxString AddressStreet;
1327         wxString AddressLocality;
1328         wxString AddressCity;
1329         wxString AddressRegion;
1330         wxString AddressPostalCode;
1331         wxString AddressCountry;
1332         bool FirstToken = TRUE;                 
1333         int intSplitsFound = 0;
1334         int intSplitSize = 0;
1335         int intPrevValue = 5;
1336         int intPref = 0;                        
1337         int intType = 0;
1338         long ListCtrlIndex;
1339         
1340         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1341         
1342         intPrevValue = 4;
1343         
1344         PropertyType PropType = PROPERTY_NONE;
1345                 
1346         // Look for type before continuing.
1347         
1348         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1349         
1350         intPrevValue = 4;
1351         
1352         std::map<int, wxString> *AddressList = NULL;
1353         std::map<int, wxString> *AddressListTown = NULL;
1354         std::map<int, wxString> *AddressListCounty = NULL;
1355         std::map<int, wxString> *AddressListPostCode = NULL;
1356         std::map<int, wxString> *AddressListCountry = NULL;
1357         std::map<int, wxString> *AddressListLabel = NULL;
1358         std::map<int, wxString> *AddressListLang = NULL;                
1359         std::map<int, wxString> *AddressListAltID = NULL;
1360         std::map<int, wxString> *AddressListPID = NULL;
1361         std::map<int, wxString> *AddressListTokens = NULL;
1362         std::map<int, wxString> *AddressListGeo = NULL;
1363         std::map<int, wxString> *AddressListTimezone = NULL;            
1364         std::map<int, wxString> *AddressListType = NULL;
1365         std::map<int, wxString> *AddressListMediatype = NULL;
1366         std::map<int, int> *AddressListPref = NULL;
1368         switch(PropType){
1369                 case PROPERTY_NONE:
1370                         AddressList = &GeneralAddressList;
1371                         AddressListTown = &GeneralAddressListTown;
1372                         AddressListCounty = &GeneralAddressListCounty;
1373                         AddressListPostCode = &GeneralAddressListPostCode;
1374                         AddressListCountry = &GeneralAddressListCountry;
1375                         AddressListLabel = &GeneralAddressListLabel;
1376                         AddressListLang = &GeneralAddressListLang;              
1377                         AddressListAltID = &GeneralAddressListAltID;
1378                         AddressListPID = &GeneralAddressListPID;
1379                         AddressListTokens = &GeneralAddressListTokens;
1380                         AddressListGeo = &GeneralAddressListGeo;
1381                         AddressListTimezone = &GeneralAddressListTimezone;
1382                         AddressListType = &GeneralAddressListType;
1383                         AddressListMediatype = &GeneralAddressListMediatype;
1384                         AddressListPref = &GeneralAddressListPref;              
1385                         break;
1386                 case PROPERTY_HOME:
1387                         AddressList = &HomeAddressList;
1388                         AddressListTown = &HomeAddressListTown;
1389                         AddressListCounty = &HomeAddressListCounty;
1390                         AddressListPostCode = &HomeAddressListPostCode;
1391                         AddressListCountry = &HomeAddressListCountry;
1392                         AddressListLabel = &HomeAddressListLabel;
1393                         AddressListLang = &HomeAddressListLang;         
1394                         AddressListAltID = &HomeAddressListAltID;
1395                         AddressListPID = &HomeAddressListPID;
1396                         AddressListTokens = &HomeAddressListTokens;
1397                         AddressListGeo = &HomeAddressListGeo;
1398                         AddressListTimezone = &HomeAddressListTimezone;
1399                         AddressListType = &HomeAddressListType;
1400                         AddressListMediatype = &HomeAddressListMediatype;
1401                         AddressListPref = &HomeAddressListPref;
1402                         break;
1403                 case PROPERTY_WORK:
1404                         AddressList = &BusinessAddressList;
1405                         AddressListTown = &BusinessAddressListTown;
1406                         AddressListCounty = &BusinessAddressListCounty;
1407                         AddressListPostCode = &BusinessAddressListPostCode;
1408                         AddressListCountry = &BusinessAddressListCountry;
1409                         AddressListLabel = &BusinessAddressListLabel;
1410                         AddressListLang = &BusinessAddressListLang;             
1411                         AddressListAltID = &BusinessAddressListAltID;
1412                         AddressListPID = &BusinessAddressListPID;
1413                         AddressListTokens = &BusinessAddressListTokens;
1414                         AddressListGeo = &BusinessAddressListGeo;
1415                         AddressListTimezone = &BusinessAddressListTimezone;
1416                         AddressListType = &BusinessAddressListType;
1417                         AddressListMediatype = &BusinessAddressListMediatype;
1418                         AddressListPref = &BusinessAddressListPref;
1419                         break;
1420         }
1421         
1422         intPrevValue = 4;
1423         
1424         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1425         intiter != SplitPoints.end(); ++intiter){
1426         
1427                 SLiter = SplitLength.find(intiter->first);
1428         
1429                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1430                 
1431                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1432                 PropertyName = PropertyElement.GetNextToken();                          
1433                 PropertyValue = PropertyElement.GetNextToken();
1434                 
1435                 intPrevValue = intiter->second;
1436                 
1437                 CaptureString(&PropertyValue, FALSE);
1438                 
1439                 // Process properties.
1440                 
1441                 if (PropertyName == wxT("LABEL")){
1442                 
1443                         AddressListLabel->erase(*AddressCount);
1444                         AddressListLabel->insert(std::make_pair(*AddressCount, PropertyValue));
1445                                 
1446                 } else if (PropertyName == wxT("LANGUAGE")){
1447                 
1448                         AddressListLang->erase(*AddressCount);
1449                         AddressListLang->insert(std::make_pair(*AddressCount, PropertyValue));                  
1450                 
1451                 } else if (PropertyName == wxT("ALTID")){
1453                         AddressListAltID->erase(*AddressCount);
1454                         AddressListAltID->insert(std::make_pair(*AddressCount, PropertyValue));
1455                 
1456                 } else if (PropertyName == wxT("PID")){
1458                         AddressListPID->erase(*AddressCount);
1459                         AddressListPID->insert(std::make_pair(*AddressCount, PropertyValue));
1460                 
1461                 } else if (PropertyName == wxT("GEO")){
1462                 
1463                         AddressListGeo->erase(*AddressCount);
1464                         AddressListGeo->insert(std::make_pair(*AddressCount, PropertyValue));
1465                 
1466                 } else if (PropertyName == wxT("TZ")){
1468                         AddressListTimezone->erase(*AddressCount);
1469                         AddressListTimezone->insert(std::make_pair(*AddressCount, PropertyValue));
1470                 
1471                 } else if (PropertyName == wxT("MEDIATYPE")){
1473                         AddressListMediatype->erase(*AddressCount);
1474                         AddressListMediatype->insert(std::make_pair(*AddressCount, PropertyValue));
1475                 
1476                 } else if (PropertyName == wxT("PREF")){
1477                         
1478                         int PriorityNumber = 0;
1479                         bool ValidNumber = TRUE;
1480                         
1481                         try{
1482                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1483                         }
1484                         
1485                         catch(std::invalid_argument &e){
1486                                 ValidNumber = FALSE;
1487                         }
1489                         if (ValidNumber == TRUE){
1491                                 AddressListPref->erase(*AddressCount);
1492                                 AddressListPref->insert(std::make_pair(*AddressCount, PriorityNumber));
1494                         }
1495                 
1496                 } else {
1497                 
1498                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1499                         
1500                                 if (FirstToken == TRUE){
1501                                 
1502                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1503                                         FirstToken = FALSE;
1504                                 
1505                                 } else {
1506                                 
1507                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1508                                 
1509                                 }
1510                         
1511                         }
1512                 
1513                 }
1514         
1515         }                       
1516         
1517         // Split the address. 
1519         //std::map<int, int>::iterator SLiter;
1520         intPropertyLen = PropertySeg2.Len();
1521         SplitPoints.clear();
1522         SplitLength.clear();
1523         intSplitsFound = 0;
1524         intSplitSize = 0;
1525         intPrevValue = 0;
1526         
1527         for (int i = 0; i <= intPropertyLen; i++){
1529                 intSplitSize++;
1530         
1531                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
1532         
1533                         intSplitsFound++;
1534                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
1535                         
1536                         if (intSplitsFound == 6){ 
1537                         
1538                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1539                                 break; 
1540                                 
1541                         } else {
1542                         
1543                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1544                         
1545                         }
1546                         
1547                         intSplitSize = 0;                                       
1548         
1549                 }
1551         }
1552         
1553         // Split the data into several parts.                   
1554         
1555         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1556         intiter != SplitPoints.end(); ++intiter){
1557                         
1558                 if (intiter->first == 1){
1559                 
1560                         // Deal with PO Box.
1561                         
1562                         SLiter = SplitLength.find(1);
1563                                                                 
1564                         //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
1565                         AddressPOBox = PropertySeg2.Mid(0, SLiter->second);
1566                         intPrevValue = intiter->second;
1567                 
1568                 } else if (intiter->first == 2){
1569                 
1570                         // Deal with extended address.
1571                         
1572                         SLiter = SplitLength.find(2);
1573                         
1574                         AddressExtended = PropertySeg2.Mid(intPrevValue, SLiter->second);
1575                         //txtForename->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1576                         intPrevValue = intiter->second;
1577                 
1578                 } else if (intiter->first == 3){
1579                 
1580                         // Deal with street address.
1581                         
1582                         SLiter = SplitLength.find(3);
1583                                                                 
1584                         AddressStreet = PropertySeg2.Mid(intPrevValue, SLiter->second);
1585                         //txtOtherNames->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1586                         intPrevValue = intiter->second;
1587                 
1588                 } else if (intiter->first == 4){
1589                 
1590                         // Deal with locality
1592                         SLiter = SplitLength.find(4);
1593                         
1594                         AddressLocality = PropertySeg2.Mid(intPrevValue, SLiter->second);
1595                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1596                         intPrevValue = intiter->second;
1597                         
1598                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1599                 
1600                 } else if (intiter->first == 5){
1601                 
1602                         // Deal with region.
1604                         SLiter = SplitLength.find(5);
1605                         
1606                         AddressRegion = PropertySeg2.Mid(intPrevValue, SLiter->second);
1607                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1608                         intPrevValue = intiter->second;
1609                         
1610                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1611                 
1612                 } else if (intiter->first == 6){
1613                 
1614                         // Deal with post code.
1616                         SLiter = SplitLength.find(6);
1617                         
1618                         AddressPostalCode = PropertySeg2.Mid(intPrevValue, SLiter->second);
1619                         //txtTitle->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
1620                         intPrevValue = intiter->second;
1621                         
1622                         // Deal with country.
1623                                                 
1624                         AddressCountry = PropertySeg2.Mid(intPrevValue, wxString::npos);
1625                         //txtSuffix->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
1626                         
1627                         break;
1628                 
1629                 }
1630         
1631         }       
1632         
1633         // Add the data to the General/Home/Work address variables.
1634         
1635         CaptureString(&AddressStreet, FALSE); 
1636         CaptureString(&AddressLocality, FALSE);
1637         CaptureString(&AddressRegion, FALSE);
1638         CaptureString(&AddressPostalCode, FALSE);
1639         CaptureString(&AddressCountry, FALSE);
1640                 
1641         if (!PropertyTokens.IsEmpty()){
1642         
1643                 AddressListTokens->insert(std::make_pair(*AddressCount, PropertyTokens));
1644         
1645         }
1647         AddressListCountry->insert(std::make_pair(*AddressCount, AddressCountry));      
1648         AddressList->insert(std::make_pair(*AddressCount, AddressStreet));
1649         AddressListTown->insert(std::make_pair(*AddressCount, AddressLocality));
1650         AddressListCounty->insert(std::make_pair(*AddressCount, AddressRegion));
1651         AddressListPostCode->insert(std::make_pair(*AddressCount, AddressPostalCode));
1653         switch(PropType){
1654                 case PROPERTY_NONE:
1655                         AddressListType->insert(std::make_pair(*AddressCount, wxT("")));
1656                         break;
1657                 case PROPERTY_HOME:
1658                         AddressListType->insert(std::make_pair(*AddressCount, wxT("home")));
1659                         break;
1660                 case PROPERTY_WORK:
1661                         AddressListType->insert(std::make_pair(*AddressCount, wxT("work")));    
1662                         break;
1663         }
1664         
1665         AddressListTokens->insert(std::make_pair(*AddressCount, PropertyTokens));
1669 void ContactDataObject::ProcessEmail(wxString PropertySeg1, wxString PropertySeg2, int *EmailCount){
1671         std::map<int, int> SplitPoints;
1672         std::map<int, int> SplitLength;
1674         int intPrevValue = 7;
1675         int intPref = 0;                        
1676         
1677         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1678         
1679         intPrevValue = 6;
1680         
1681         PropertyType PropType = PROPERTY_NONE;
1682                 
1683         // Look for type before continuing.
1684         
1685         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1686         
1687         std::map<int, wxString> *EmailList = NULL;
1688         std::map<int, wxString> *EmailListType = NULL;
1689         std::map<int, wxString> *EmailListAltID = NULL;
1690         std::map<int, wxString> *EmailListPID = NULL;
1691         std::map<int, wxString> *EmailListTokens = NULL;                
1692         std::map<int, int> *EmailListPref = NULL;
1694         switch(PropType){
1695                 case PROPERTY_NONE:
1696                         EmailList = &GeneralEmailList;
1697                         EmailListType = &GeneralEmailListType;
1698                         EmailListAltID = &GeneralEmailListAltID;
1699                         EmailListPID = &GeneralEmailListPID;
1700                         EmailListTokens = &GeneralEmailListTokens;              
1701                         EmailListPref = &GeneralEmailListPref;  
1702                         break;
1703                 case PROPERTY_HOME:
1704                         EmailList = &HomeEmailList;
1705                         EmailListType = &HomeEmailListType;
1706                         EmailListAltID = &HomeEmailListAltID;
1707                         EmailListPID = &HomeEmailListPID;
1708                         EmailListTokens = &HomeEmailListTokens;         
1709                         EmailListPref = &HomeEmailListPref;     
1710                         break;
1711                 case PROPERTY_WORK:
1712                         EmailList = &BusinessEmailList;
1713                         EmailListType = &BusinessEmailListType;
1714                         EmailListAltID = &BusinessEmailListAltID;
1715                         EmailListPID = &BusinessEmailListPID;
1716                         EmailListTokens = &BusinessEmailListTokens;             
1717                         EmailListPref = &BusinessEmailListPref; 
1718                         break;
1719         }
1720         
1721         intPrevValue = 6;
1722         
1723         std::map<int,int>::iterator SLiter;
1724         wxString PropertyData;
1725         wxString PropertyName;
1726         wxString PropertyValue;
1727         wxString PropertyTokens;
1728         bool FirstToken = TRUE;
1729         
1730         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1731         intiter != SplitPoints.end(); ++intiter){
1732         
1733                 SLiter = SplitLength.find(intiter->first);
1734         
1735                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1736                 
1737                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1738                 PropertyName = PropertyElement.GetNextToken();                          
1739                 PropertyValue = PropertyElement.GetNextToken();
1740                 
1741                 intPrevValue = intiter->second;
1742                 
1743                 CaptureString(&PropertyValue, FALSE);
1744                 
1745                 // Process properties.
1746                 
1747                 if (PropertyName == wxT("ALTID")){
1749                         EmailListAltID->erase(*EmailCount);
1750                         EmailListAltID->insert(std::make_pair(*EmailCount, PropertyValue));
1751                 
1752                 } else if (PropertyName == wxT("PID")){
1754                         EmailListPID->erase(*EmailCount);
1755                         EmailListPID->insert(std::make_pair(*EmailCount, PropertyValue));
1756                 
1757                 } else if (PropertyName == wxT("PREF")){
1758                         
1759                         int PriorityNumber = 0;
1760                         bool ValidNumber = TRUE;
1761                         
1762                         try{
1763                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1764                         }
1765                         
1766                         catch(std::invalid_argument &e){
1767                                 ValidNumber = FALSE;
1768                         }
1770                         if (ValidNumber == TRUE){
1772                                 EmailListPref->erase(*EmailCount);
1773                                 EmailListPref->insert(std::make_pair(*EmailCount, PriorityNumber));
1775                         }
1776                 
1777                 } else {
1778                 
1779                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1780                         
1781                                 if (FirstToken == TRUE){
1782                                 
1783                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1784                                         FirstToken = FALSE;
1785                                 
1786                                 } else {
1787                                 
1788                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1789                                 
1790                                 }
1791                         
1792                         }
1793                 
1794                 }
1795         
1796         }
1797         
1798         EmailList->insert(std::make_pair(*EmailCount, PropertySeg2));
1799         
1800         // Add the name token data.
1801         
1802         if (!PropertyTokens.IsEmpty()){
1803         
1804                 EmailListTokens->insert(std::make_pair(*EmailCount, PropertyTokens));
1805         
1806         }       
1811 void ContactDataObject::ProcessIM(wxString PropertySeg1, wxString PropertySeg2, int *IMCount){
1813         std::map<int, int> SplitPoints;
1814         std::map<int, int> SplitLength;
1816         int intPrevValue = 6;
1817         int intPref = 0;                        
1818         
1819         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1820         
1821         intPrevValue = 5;
1822         
1823         PropertyType PropType = PROPERTY_NONE;
1824                 
1825         // Look for type before continuing.
1826         
1827         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1828         
1829         std::map<int, wxString> *IMList = NULL;
1830         std::map<int, wxString> *IMListType = NULL;
1831         std::map<int, wxString> *IMListAltID = NULL;
1832         std::map<int, wxString> *IMListPID = NULL;
1833         std::map<int, wxString> *IMListTokens = NULL;
1834         std::map<int, wxString> *IMListMediatype = NULL;        
1835         std::map<int, int> *IMListPref = NULL;
1837         switch(PropType){
1838                 case PROPERTY_NONE:
1839                         IMList = &GeneralIMList;
1840                         IMListType = &GeneralIMListType;
1841                         IMListAltID = &GeneralIMListAltID;
1842                         IMListPID = &GeneralIMListPID;
1843                         IMListTokens = &GeneralIMListTokens;
1844                         IMListMediatype = &GeneralIMListMediatype;
1845                         IMListPref = &GeneralIMListPref;        
1846                         break;
1847                 case PROPERTY_HOME:
1848                         IMList = &HomeIMList;
1849                         IMListType = &HomeIMListType;
1850                         IMListAltID = &HomeIMListAltID;
1851                         IMListPID = &HomeIMListPID;
1852                         IMListTokens = &HomeIMListTokens;
1853                         IMListMediatype = &HomeIMListMediatype;         
1854                         IMListPref = &HomeIMListPref;   
1855                         break;
1856                 case PROPERTY_WORK:
1857                         IMList = &BusinessIMList;
1858                         IMListType = &BusinessIMListType;
1859                         IMListAltID = &BusinessIMListAltID;
1860                         IMListPID = &BusinessIMListPID;
1861                         IMListTokens = &BusinessIMListTokens;   
1862                         IMListMediatype = &BusinessIMListMediatype;     
1863                         IMListPref = &BusinessIMListPref;       
1864                         break;
1865         }
1866         
1867         intPrevValue = 5;
1868         
1869         std::map<int,int>::iterator SLiter;
1870         wxString PropertyData;
1871         wxString PropertyName;
1872         wxString PropertyValue;
1873         wxString PropertyTokens;
1874         bool FirstToken = TRUE;
1875         
1876         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1877         intiter != SplitPoints.end(); ++intiter){
1878         
1879                 SLiter = SplitLength.find(intiter->first);
1880         
1881                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1882                 
1883                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1884                 PropertyName = PropertyElement.GetNextToken();                          
1885                 PropertyValue = PropertyElement.GetNextToken();
1886                 
1887                 intPrevValue = intiter->second;
1888                 
1889                 CaptureString(&PropertyValue, FALSE);
1890                 
1891                 // Process properties.
1892                 
1893                 if (PropertyName == wxT("ALTID")){
1895                         IMListAltID->erase(*IMCount);
1896                         IMListAltID->insert(std::make_pair(*IMCount, PropertyValue));
1897                 
1898                 } else if (PropertyName == wxT("PID")){
1900                         IMListPID->erase(*IMCount);
1901                         IMListPID->insert(std::make_pair(*IMCount, PropertyValue));
1902                 
1903                 } else if (PropertyName == wxT("MEDIATYPE")){
1905                         IMListMediatype->erase(*IMCount);
1906                         IMListMediatype->insert(std::make_pair(*IMCount, PropertyValue));
1907                 
1908                 } else if (PropertyName == wxT("PREF")){
1909                         
1910                         int PriorityNumber = 0;
1911                         bool ValidNumber = TRUE;
1912                         
1913                         try{
1914                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1915                         }
1916                         
1917                         catch(std::invalid_argument &e){
1918                                 ValidNumber = FALSE;
1919                         }
1921                         if (ValidNumber == TRUE){
1923                                 IMListPref->erase(*IMCount);
1924                                 IMListPref->insert(std::make_pair(*IMCount, PriorityNumber));
1926                         }
1927                 
1928                 } else {
1929                 
1930                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1931                         
1932                                 if (FirstToken == TRUE){
1933                                 
1934                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1935                                         FirstToken = FALSE;
1936                                 
1937                                 } else {
1938                                 
1939                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1940                                 
1941                                 }
1942                         
1943                         }
1944                 
1945                 }
1946         
1947         }
1948                 
1949         IMList->insert(std::make_pair(*IMCount, PropertySeg2));
1950         
1951         // Add the name token data.
1952         
1953         if (!PropertyTokens.IsEmpty()){
1954         
1955                 IMListTokens->insert(std::make_pair(*IMCount, PropertyTokens));
1956         
1957         }
1961 void ContactDataObject::ProcessTelephone(wxString PropertySeg1, wxString PropertySeg2, int *TelephoneCount){
1963         std::map<int, int> SplitPoints;
1964         std::map<int, int> SplitLength;
1965         std::map<int, int>::iterator SLiter;
1966         
1967         int intPref = 0;
1968         
1969         PropertyType PropType = PROPERTY_NONE;
1970                 
1971         // Look for type before continuing.
1972         
1973         wxString TelTypeUI;
1974         wxString TelTypeDetail;
1975         wxString PropertyData;
1976         wxString PropertyName;
1977         wxString PropertyValue;
1978         wxString PropertyTokens;
1979         
1980         std::map<int,int> TypeSplitPoints;
1981         std::map<int,int> TypeSplitLength;
1982         std::map<int,int>::iterator TSLiter;
1983         
1984         int intSplitSize = 0;
1985         int intSplitsFound = 0;
1986         int intSplitPoint = 0;
1987         int intType = 0;
1988         int intPrevValue = 5;
1989                 
1990         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1991         
1992         intPrevValue = 4;
1993         
1994         // Look for type before continuing.
1995         
1996         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1997         intiter != SplitPoints.end(); ++intiter){
1998         
1999                 SLiter = SplitLength.find(intiter->first);
2000         
2001                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2002                 
2003                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2004                 PropertyName = PropertyElement.GetNextToken();                          
2005                 PropertyValue = PropertyElement.GetNextToken();
2006                 
2007                 intPrevValue = intiter->second;
2009                 if (PropertyName == wxT("TYPE")){
2010                 
2011                         // Process each value in type and translate each
2012                         // part.
2013                 
2014                         // Strip out the quotes if they are there.
2015                 
2016                         size_t intPropertyValueLen = PropertyValue.Len();
2017                 
2018                         if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
2019                         
2020                                 PropertyValue.Trim();
2021                                 PropertyValue.RemoveLast();
2022                         
2023                         }                               
2024                 
2025                         if (PropertyValue.Mid(0, 1) == wxT("\"")){
2026                         
2027                                 PropertyValue.Remove(0, 1);
2028                         
2029                         }
2030                         
2031                         TelTypeDetail = PropertyValue;
2032                         
2033                         intSplitSize = 0;
2034                         intSplitsFound = 0;
2035                         intSplitPoint = 0;
2036                         
2037                         for (int i = 0; i <= intPropertyValueLen; i++){
2038         
2039                                 intSplitSize++;
2040         
2041                                 if (PropertyValue.Mid(i, 1) == wxT(",") && PropertyValue.Mid((i - 1), 1) != wxT("\\")){
2042         
2043                                         if (intSplitsFound == 0){
2045                                                 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
2046                                                 TypeSplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
2047                         
2048                                         } else {
2049                         
2050                                                 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
2051                                                 TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
2052                         
2053                                         }                       
2055                                         intSplitsFound++;
2056                                         i++;
2057                                         intSplitPoint = i;
2058                                         intSplitSize = 0;
2059         
2060                                 }
2061         
2062                         }
2063                         
2064                         TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
2065                         TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));                                                           
2066                 
2067                         int intTypeSeek = 0;
2068                 
2069                         for (std::map<int, int>::iterator typeiter = TypeSplitPoints.begin(); 
2070                         typeiter != TypeSplitPoints.end(); ++typeiter){
2071                         
2072                                 wxString TypePropertyName;
2073                                 
2074                                 TSLiter = TypeSplitLength.find(typeiter->first);
2075                                 
2076                                 TypePropertyName = PropertyValue.Mid(typeiter->second, TSLiter->second);
2077                                 
2078                                 if (intTypeSeek == 0){
2079                                 
2080                                 
2081                                 } else {
2082                                                                                 
2083                                         TelTypeUI.Append(wxT(","));                                                     
2084                                 
2085                                 }
2086                         
2087                                 if (TypePropertyName == wxT("home")){
2088                                 
2089                                         PropType = PROPERTY_HOME;
2090                                 
2091                                 } else if (TypePropertyName == wxT("work")){
2092                                 
2093                                         PropType = PROPERTY_WORK;
2094                                                                         
2095                                 }
2096                                 
2097                                 
2098                                 if (TypePropertyName == wxT("text")){
2099                                 
2100                                         TelTypeUI.Append(_("text"));
2101                                         intTypeSeek++;
2102                                 
2103                                 } else if (TypePropertyName == wxT("voice")){
2104                                 
2105                                         TelTypeUI.Append(_("voice"));
2106                                         intTypeSeek++;
2107                                 
2108                                 } else if (TypePropertyName == wxT("fax")){
2109                                 
2110                                         TelTypeUI.Append(_("fax"));
2111                                         intTypeSeek++;
2112                                 
2113                                 } else if (TypePropertyName == wxT("cell")){
2114                                 
2115                                         TelTypeUI.Append(_("mobile"));
2116                                         intTypeSeek++;
2117                                 
2118                                 } else if (TypePropertyName == wxT("video")){
2119                                 
2120                                         TelTypeUI.Append(_("video"));
2121                                         intTypeSeek++;
2122                                 
2123                                 } else if (TypePropertyName == wxT("pager")){
2124                                 
2125                                         TelTypeUI.Append(_("pager"));
2126                                         intTypeSeek++;
2127                                 
2128                                 } else if (TypePropertyName == wxT("textphone")){
2129                                 
2130                                         TelTypeUI.Append(_("textphone"));
2131                                         intTypeSeek++;
2132                                 
2133                                 }
2134                         
2135                         }
2136                 
2137                 }
2138                 
2139         }
2140         
2141         std::map<int, wxString> *TelephoneList = NULL;
2142         std::map<int, wxString> *TelephoneListType = NULL;
2143         std::map<int, wxString> *TelephoneListAltID = NULL;
2144         std::map<int, wxString> *TelephoneListPID = NULL;
2145         std::map<int, wxString> *TelephoneListTokens = NULL;
2146         std::map<int, wxString> *TelephoneListTypeInfo = NULL;  
2147         std::map<int, int> *TelephoneListPref = NULL;
2149         switch(PropType){
2150                 case PROPERTY_NONE:
2151                         TelephoneList = &GeneralTelephoneList;
2152                         TelephoneListType = &GeneralTelephoneListType;
2153                         TelephoneListAltID = &GeneralTelephoneListAltID;
2154                         TelephoneListPID = &GeneralTelephoneListPID;
2155                         TelephoneListTokens = &GeneralTelephoneListTokens;
2156                         TelephoneListTypeInfo = &GeneralTelephoneListTypeInfo;
2157                         TelephoneListPref = &GeneralTelephoneListPref;  
2158                         break;
2159                 case PROPERTY_HOME:
2160                         TelephoneList = &HomeTelephoneList;
2161                         TelephoneListType = &HomeTelephoneListType;
2162                         TelephoneListAltID = &HomeTelephoneListAltID;
2163                         TelephoneListPID = &HomeTelephoneListPID;
2164                         TelephoneListTokens = &HomeTelephoneListTokens;
2165                         TelephoneListTypeInfo = &HomeTelephoneListTypeInfo;     
2166                         TelephoneListPref = &HomeTelephoneListPref;     
2167                         break;
2168                 case PROPERTY_WORK:
2169                         TelephoneList = &BusinessTelephoneList;
2170                         TelephoneListType = &BusinessTelephoneListType;
2171                         TelephoneListAltID = &BusinessTelephoneListAltID;
2172                         TelephoneListPID = &BusinessTelephoneListPID;
2173                         TelephoneListTokens = &BusinessTelephoneListTokens;     
2174                         TelephoneListTypeInfo = &BusinessTelephoneListTypeInfo; 
2175                         TelephoneListPref = &BusinessTelephoneListPref; 
2176                         break;
2177         }
2178                 
2179         // Process the properties.
2180         
2181         bool FirstToken = TRUE;
2182         
2183         intPrevValue = 5;
2184         SplitPoints.clear();
2185         SplitLength.clear();
2187         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
2189         intPrevValue = 4;
2190         
2191         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
2192         intiter != SplitPoints.end(); ++intiter){
2193         
2194                 SLiter = SplitLength.find(intiter->first);
2195         
2196                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2197                 
2198                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2199                 PropertyName = PropertyElement.GetNextToken();                          
2200                 PropertyValue = PropertyElement.GetNextToken();
2201                 
2202                 intPrevValue = intiter->second;
2203                 
2204                 CaptureString(&PropertyValue, FALSE);
2205                 
2206                 // Process properties.
2207                 
2208                 if (PropertyName == wxT("ALTID")){
2210                         TelephoneListAltID->erase(*TelephoneCount);
2211                         TelephoneListAltID->insert(std::make_pair(*TelephoneCount, PropertyValue));
2212                 
2213                 } else if (PropertyName == wxT("PID")){
2215                         TelephoneListPID->erase(*TelephoneCount);
2216                         TelephoneListPID->insert(std::make_pair(*TelephoneCount, PropertyValue));
2217                 
2218                 } else if (PropertyName == wxT("PREF")){
2219                         
2220                         int PriorityNumber = 0;
2221                         bool ValidNumber = TRUE;
2222                         
2223                         try{
2224                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
2225                         }
2226                         
2227                         catch(std::invalid_argument &e){
2228                                 ValidNumber = FALSE;
2229                         }
2231                         if (ValidNumber == TRUE){
2233                                 TelephoneListPref->erase(*TelephoneCount);
2234                                 TelephoneListPref->insert(std::make_pair(*TelephoneCount, PriorityNumber));
2236                         }
2237                 
2238                 } else {
2239                 
2240                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
2241                         
2242                                 if (FirstToken == TRUE){
2243                                 
2244                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
2245                                         FirstToken = FALSE;
2246                                 
2247                                 } else {
2248                                 
2249                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
2250                                 
2251                                 }
2252                         
2253                         }
2254                 
2255                 }
2256         
2257         }
2258                 
2259         TelephoneList->insert(std::make_pair(*TelephoneCount, PropertySeg2));
2260         TelephoneListTypeInfo->insert(std::make_pair(*TelephoneCount, TelTypeUI));
2261         
2262         // Add the name token data.
2263         
2264         if (!PropertyTokens.IsEmpty()){
2265         
2266                 TelephoneListTokens->insert(std::make_pair(*TelephoneCount, PropertyTokens));
2267         
2268         }
2272 void ContactDataObject::ProcessLanguage(wxString PropertySeg1, wxString PropertySeg2, int *LanguageCount){
2274         std::map<int, int> SplitPoints;
2275         std::map<int, int> SplitLength;
2277         int intPrevValue = 6;
2278         int intPref = 0;                        
2279         
2280         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
2281         
2282         intPrevValue = 5;
2283         
2284         PropertyType PropType = PROPERTY_NONE;
2285                 
2286         // Look for type before continuing.
2287         
2288         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
2289         
2290         std::map<int, wxString> *LanguageList = NULL;
2291         std::map<int, wxString> *LanguageListType = NULL;
2292         std::map<int, wxString> *LanguageListAltID = NULL;
2293         std::map<int, wxString> *LanguageListPID = NULL;
2294         std::map<int, wxString> *LanguageListTokens = NULL;
2295         std::map<int, int> *LanguageListPref = NULL;
2297         switch(PropType){
2298                 case PROPERTY_NONE:
2299                         LanguageList = &GeneralLanguageList;
2300                         LanguageListType = &GeneralLanguageListType;
2301                         LanguageListAltID = &GeneralLanguageListAltID;
2302                         LanguageListPID = &GeneralLanguageListPID;
2303                         LanguageListTokens = &GeneralLanguageListTokens;
2304                         LanguageListPref = &GeneralLanguageListPref;    
2305                         break;
2306                 case PROPERTY_HOME:
2307                         LanguageList = &HomeLanguageList;
2308                         LanguageListType = &HomeLanguageListType;
2309                         LanguageListAltID = &HomeLanguageListAltID;
2310                         LanguageListPID = &HomeLanguageListPID;
2311                         LanguageListTokens = &HomeLanguageListTokens;   
2312                         LanguageListPref = &HomeLanguageListPref;       
2313                         break;
2314                 case PROPERTY_WORK:
2315                         LanguageList = &BusinessLanguageList;
2316                         LanguageListType = &BusinessLanguageListType;
2317                         LanguageListAltID = &BusinessLanguageListAltID;
2318                         LanguageListPID = &BusinessLanguageListPID;
2319                         LanguageListTokens = &BusinessLanguageListTokens;       
2320                         LanguageListPref = &BusinessLanguageListPref;
2321                         break;
2322         }
2323         
2324         intPrevValue = 5;
2325         
2326         std::map<int,int>::iterator SLiter;
2327         wxString PropertyData;
2328         wxString PropertyName;
2329         wxString PropertyValue;
2330         wxString PropertyTokens;
2331         bool FirstToken = TRUE;
2332         
2333         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
2334         intiter != SplitPoints.end(); ++intiter){
2335         
2336                 SLiter = SplitLength.find(intiter->first);
2337         
2338                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2339                 
2340                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2341                 PropertyName = PropertyElement.GetNextToken();                          
2342                 PropertyValue = PropertyElement.GetNextToken();
2343                 
2344                 intPrevValue = intiter->second;
2345                 
2346                 CaptureString(&PropertyValue, FALSE);
2347                 
2348                 // Process properties.
2349                 
2350                 if (PropertyName == wxT("ALTID")){
2352                         LanguageListAltID->erase(*LanguageCount);
2353                         LanguageListAltID->insert(std::make_pair(*LanguageCount, PropertyValue));
2354                 
2355                 } else if (PropertyName == wxT("PID")){
2357                         LanguageListPID->erase(*LanguageCount);
2358                         LanguageListPID->insert(std::make_pair(*LanguageCount, PropertyValue));
2359                 
2360                 } else if (PropertyName == wxT("PREF")){
2361                         
2362                         int PriorityNumber = 0;
2363                         bool ValidNumber = TRUE;
2364                         
2365                         try{
2366                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
2367                         }
2368                         
2369                         catch(std::invalid_argument &e){
2370                                 ValidNumber = FALSE;
2371                         }
2373                         if (ValidNumber == TRUE){
2375                                 LanguageListPref->erase(*LanguageCount);
2376                                 LanguageListPref->insert(std::make_pair(*LanguageCount, PriorityNumber));
2378                         }
2379                 
2380                 } else {
2381                 
2382                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
2383                         
2384                                 if (FirstToken == TRUE){
2385                                 
2386                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
2387                                         FirstToken = FALSE;
2388                                 
2389                                 } else {
2390                                 
2391                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
2392                                 
2393                                 }
2394                         
2395                         }
2396                 
2397                 }
2398         
2399         }
2400                 
2401         LanguageList->insert(std::make_pair(*LanguageCount, PropertySeg2));
2402         
2403         // Add the name token data.
2404         
2405         if (!PropertyTokens.IsEmpty()){
2406         
2407                 LanguageListTokens->insert(std::make_pair(*LanguageCount, PropertyTokens));
2408         
2409         }
2413 void ContactDataObject::ProcessGeographic(wxString PropertySeg1, wxString PropertySeg2, int *GeographicCount){
2415         std::map<int, int> SplitPoints;
2416         std::map<int, int> SplitLength;
2418         int intPrevValue = 5;
2419         int intPref = 0;                        
2420         
2421         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
2422         
2423         intPrevValue = 4;
2424         
2425         PropertyType PropType = PROPERTY_NONE;
2426                 
2427         // Look for type before continuing.
2428         
2429         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
2430         
2431         std::map<int, wxString> *GeopositionList = NULL;
2432         std::map<int, wxString> *GeopositionListType = NULL;
2433         std::map<int, wxString> *GeopositionListAltID = NULL;
2434         std::map<int, wxString> *GeopositionListPID = NULL;
2435         std::map<int, wxString> *GeopositionListTokens = NULL;
2436         std::map<int, wxString> *GeopositionListMediatype = NULL;
2437         std::map<int, int> *GeopositionListPref = NULL;
2439         switch(PropType){
2440                 case PROPERTY_NONE:
2441                         GeopositionList = &GeneralGeographyList;
2442                         GeopositionListType = &GeneralGeographyListType;
2443                         GeopositionListAltID = &GeneralGeographyListAltID;
2444                         GeopositionListPID = &GeneralGeographyListPID;
2445                         GeopositionListTokens = &GeneralGeographyListTokens;
2446                         GeopositionListMediatype = &GeneralGeographyListMediatype;
2447                         GeopositionListPref = &GeneralGeographyListPref;        
2448                         break;
2449                 case PROPERTY_HOME:
2450                         GeopositionList = &HomeGeographyList;
2451                         GeopositionListType = &HomeGeographyListType;
2452                         GeopositionListAltID = &HomeGeographyListAltID;
2453                         GeopositionListPID = &HomeGeographyListPID;
2454                         GeopositionListTokens = &HomeGeographyListTokens;
2455                         GeopositionListMediatype = &HomeGeographyListMediatype;
2456                         GeopositionListPref = &HomeGeographyListPref;   
2457                         break;
2458                 case PROPERTY_WORK:
2459                         GeopositionList = &BusinessGeographyList;
2460                         GeopositionListType = &BusinessGeographyListType;
2461                         GeopositionListAltID = &BusinessGeographyListAltID;
2462                         GeopositionListPID = &BusinessGeographyListPID;
2463                         GeopositionListTokens = &BusinessGeographyListTokens;
2464                         GeopositionListMediatype = &BusinessGeographyListMediatype;     
2465                         GeopositionListPref = &BusinessGeographyListPref;
2466                         break;
2467         }
2468         
2469         intPrevValue = 4;
2470         
2471         std::map<int,int>::iterator SLiter;
2472         wxString PropertyData;
2473         wxString PropertyName;
2474         wxString PropertyValue;
2475         wxString PropertyTokens;
2476         bool FirstToken = TRUE;
2477         
2478         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
2479         intiter != SplitPoints.end(); ++intiter){
2480         
2481                 SLiter = SplitLength.find(intiter->first);
2482         
2483                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
2484                 
2485                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2486                 PropertyName = PropertyElement.GetNextToken();                          
2487                 PropertyValue = PropertyElement.GetNextToken();
2488                 
2489                 intPrevValue = intiter->second;
2490                 
2491                 CaptureString(&PropertyValue, FALSE);
2492                 
2493                 // Process properties.
2494                 
2495                 if (PropertyName == wxT("ALTID")){
2497                         GeopositionListAltID->erase(*GeographicCount);
2498                         GeopositionListAltID->insert(std::make_pair(*GeographicCount, PropertyValue));
2499                 
2500                 } else if (PropertyName == wxT("PID")){
2502                         GeopositionListPID->erase(*GeographicCount);
2503                         GeopositionListPID->insert(std::make_pair(*GeographicCount, PropertyValue));
2504                 
2505                 } else if (PropertyName == wxT("MEDIATYPE")){
2507                         GeopositionListMediatype->erase(*GeographicCount);
2508                         GeopositionListMediatype->insert(std::make_pair(*GeographicCount, PropertyValue));
2509                 
2510                 } else if (PropertyName == wxT("PREF")){
2511                         
2512                         int PriorityNumber = 0;
2513                         bool ValidNumber = TRUE;
2514                         
2515                         try{
2516                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
2517                         }
2518                         
2519                         catch(std::invalid_argument &e){
2520                                 ValidNumber = FALSE;
2521                         }
2523                         if (ValidNumber == TRUE){
2525                                 GeopositionListPref->erase(*GeographicCount);
2526                                 GeopositionListPref->insert(std::make_pair(*GeographicCount, PriorityNumber));
2528                         }
2529                 
2530                 } else {
2531                 
2532                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
2533                         
2534                                 if (FirstToken == TRUE){
2535                                 
2536                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
2537                                         FirstToken = FALSE;
2538                                 
2539                                 } else {
2540                                 
2541                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
2542                                 
2543                                 }
2544                         
2545                         }
2546                 
2547                 }
2548         
2549         }
2550                 
2551         GeopositionList->insert(std::make_pair(*GeographicCount, PropertySeg2));
2552         
2553         // Add the name token data.
2554         
2555         if (!PropertyTokens.IsEmpty()){
2556         
2557                 GeopositionListTokens->insert(std::make_pair(*GeographicCount, PropertyTokens));
2558         
2559         }
2563 void SplitValues(wxString *PropertyLine, 
2564         std::map<int,int> *SplitPoints, 
2565         std::map<int,int> *SplitLength, 
2566         int intSize){
2567         
2568         size_t intPropertyLen = PropertyLine->Len();
2569         int intSplitsFound = 0;
2570         int intSplitSize = 0;
2571         int intSplitSeek = 0;
2572         
2573         for (int i = intSize; i <= intPropertyLen; i++){
2575                 intSplitSize++;
2576         
2577                 if (PropertyLine->Mid(i, 1) == wxT(";") &&
2578                     PropertyLine->Mid((i - 1), 1) != wxT("\\")){
2579            
2580                     if (intSplitsFound == 0){
2581             
2582                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
2583           
2584                     } else {
2585            
2586                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
2587             
2588                     }
2589             
2590                     SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
2591             
2592                     intSplitsFound++;
2593                     intSplitSeek = i;
2594                     intSplitSize = 0;
2595             
2596                 }
2598         }
2600         if (intSplitsFound == 0){
2602                 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
2603                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
2605         } else {
2607                 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
2608                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
2610         }
2614 void CheckType(wxString *PropertySeg1, 
2615         std::map<int,int> *SplitPoints, 
2616         std::map<int,int> *SplitLength, 
2617         int *intPrevValue, 
2618         PropertyType *PropType){
2619         
2620         wxString PropertyData;
2621         wxString PropertyName;
2622         wxString PropertyValue;
2623         std::map<int,int>::iterator SLiter;
2624         
2625         for (std::map<int, int>::iterator intiter = SplitPoints->begin(); 
2626         intiter != SplitPoints->end(); ++intiter){
2627         
2628                 SLiter = SplitLength->find(intiter->first);
2629         
2630                 PropertyData = PropertySeg1->Mid(*intPrevValue, (SLiter->second));
2631                 
2632                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
2633                 PropertyName = PropertyElement.GetNextToken();                          
2634                 PropertyValue = PropertyElement.GetNextToken();
2635                 
2636                 *intPrevValue = intiter->second;
2637                 
2638                 if (PropertyName == wxT("TYPE")){
2639                                 
2640                         if (PropertyValue == wxT("work")){
2641                         
2642                                 *PropType = PROPERTY_WORK;
2643                                                         
2644                         } else if (PropertyValue == wxT("home")){
2646                                 *PropType = PROPERTY_HOME;
2647                                                         
2648                         } else {
2649                         
2650                                 *PropType = PROPERTY_NONE;
2651                         
2652                         }
2653                 
2654                         return;
2655                 
2656                 }
2657         
2658         }
2659         
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