Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source, header and unit tests for TZ vCard property in the ContactDataObject.
[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         wxString ContactLine;
88         wxString PropertyLine;
89         wxString PropertySeg1;
90         wxString PropertySeg2;
91         wxString PropertyNextLine;
92         wxString Property;
93         
94         for (std::map<int,wxString>::iterator iter = ContactFileLines.begin(); 
95          iter != ContactFileLines.end(); ++iter){
97                 ExtraLineSeek = TRUE;
98                 QuoteMode = FALSE;
99                 PropertyFind = TRUE;
100                 ContactLineLen = 0;
101                 QuoteBreakPoint = 0;
102                 ContactLine.Clear();
103                 PropertyLine.Clear();
104                 PropertySeg1.Clear();
105                 PropertySeg2.Clear();
106                 Property.Clear();
107          
108                 ContactLine = iter->second;
109                 
110                 while (ExtraLineSeek == TRUE){
111                 
112                         // Check if there is extra data on the next line 
113                         // (indicated by space or tab at the start) and add data.
114                 
115                         iter++;
116                         
117                         if (iter == ContactFileLines.end()){
118                         
119                                 iter--;
120                                 break;
121                         
122                         }                       
123                 
124                         PropertyNextLine = iter->second;
125                 
126                         if (PropertyNextLine.Mid(0, 1) == wxT(" ") || PropertyNextLine.Mid(0, 1) == wxT("\t")){
127                 
128                                 PropertyNextLine.Remove(0, 1);
129                                 ContactLine.Append(PropertyNextLine);
130                 
131                         } else {
132                         
133                                 iter--;
134                                 ExtraLineSeek = FALSE;
135                         
136                         }
137                 
138                 }
140                 ContactLineLen = ContactLine.Len();
141                 
142                 // Make sure we are not in quotation mode.
143                 // Make sure colon does not have \ or \\ before it.
144                 
145                 for (int i = 0; i <= ContactLineLen; i++){
146                 
147                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
148                         
149                                 PropertyFind = FALSE;
150                         
151                         } else if (PropertyFind == TRUE){
152                         
153                                 Property.Append(ContactLine.Mid(i, 1));
154                         
155                         }               
156                 
157                         if (ContactLine.Mid(i, 1) == wxT("\"")){
158                         
159                                 if (QuoteMode == TRUE){
160                                 
161                                         QuoteMode = FALSE;
162                                 
163                                 } else {
164                         
165                                         QuoteMode = TRUE;
166                                         
167                                 }
168                         
169                         }
170                         
171                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
172                         
173                                 QuoteBreakPoint = i;
174                                 break;
175                         
176                         }
177                 
178                 }
179                 
180                 // Split that line at the point into two variables (ignore the colon).
181                 
182                 PropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
183                 PropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
184                 
185                  if (Property == wxT("KIND") && KindProcessed == FALSE){
186                                 
187                         ProcessKind(PropertySeg2);
188                 
189                 } else if (Property == wxT("MEMBER")){
191                         ProcessMember(PropertySeg1, PropertySeg2, &GroupCount);
192                         GroupCount++;   
193                 
194                 } else if (Property == wxT("FN")){
195                 
196                         ProcessFN(PropertySeg1, PropertySeg2, &FNCount);
197                         FNCount++;
198                 
199                 } else if (Property == wxT("N") && NameProcessed == FALSE){
200                 
201                         ProcessN(PropertySeg1, PropertySeg2);
202                         NameProcessed = TRUE;
203                 
204                 } else if (Property == wxT("NICKNAME")){
205                                                 
206                         ProcessNickname(PropertySeg1, PropertySeg2, &NicknameCount);
207                         NicknameCount++;
208                         
209                 } else if (Property == wxT("GENDER") && GenderProcessed == FALSE){
210                 
211                         ProcessGender(PropertySeg1, PropertySeg2);
212                         GenderProcessed = TRUE;
213                 
214                 } else if (Property == wxT("BDAY") && BirthdayProcessed == FALSE){
215                 
216                         ProcessBirthday(PropertySeg1, PropertySeg2);
217                         BirthdayProcessed = TRUE;
218                 
219                 } else if (Property == wxT("ANNIVERSARY") && AnniversaryProcessed == FALSE){
220                 
221                         ProcessAnniversary(PropertySeg1, PropertySeg2);
222                         AnniversaryProcessed = TRUE;
223                 
224                 } else if (Property == wxT("TZ")){
225                 
226                         ProcessTimeZone(PropertySeg1, PropertySeg2, &TimeZoneCount);
227                         TimeZoneCount++;
228                 
229                 }
230                 
231         }
232         
233         return CONTACTLOAD_OK;
237 void ContactDataObject::ProcessKind(wxString KindType){
239         if (KindType == wxT("individual")){
240                         
241                 ContactKind = CONTACTKIND_INDIVIDUAL;
242                         
243         } else if (KindType == wxT("group")){
244                         
245                 ContactKind = CONTACTKIND_GROUP;
246                         
247         } else if (KindType == wxT("org")){
248                         
249                 ContactKind = CONTACTKIND_ORGANISATION;
250                         
251         } else if (KindType == wxT("location")){
252                         
253                 ContactKind = CONTACTKIND_LOCATION;
254                         
255         } else {
256                         
257                 ContactKind = CONTACTKIND_NONE;                 
258         }
262 void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount){
264         std::map<int, int> SplitPoints;
265         std::map<int, int> SplitLength;
267         int intPrevValue = 8;
268         int intPref = 0;                        
269         int intType = 0;
270         
271         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
273         intPrevValue = 7;
274         
275         wxString PropertyName;
276         wxString PropertyValue;
277         wxString PropertyData;
278         wxString PropertyTokens;
279         std::map<int,int>::iterator SLiter;
280         bool FirstToken = TRUE;
281         
282         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
283         intiter != SplitPoints.end(); ++intiter){
284         
285                 SLiter = SplitLength.find(intiter->first);
286         
287                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
288                 
289                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
290                 PropertyName = PropertyElement.GetNextToken();                          
291                 PropertyValue = PropertyElement.GetNextToken();
292                 
293                 intPrevValue = intiter->second;
294                 
295                 CaptureString(&PropertyValue, FALSE);
296         
297                 if (PropertyName == wxT("ALTID")){
299                         GroupsListAltID.erase(*GroupCount);
300                         GroupsListAltID.insert(std::make_pair(*GroupCount, PropertyValue));
301                 
302                 } else if (PropertyName == wxT("PID")){
304                         GroupsListPID.erase(*GroupCount);
305                         GroupsListPID.insert(std::make_pair(*GroupCount, PropertyValue));
306                 
307                 } else if (PropertyName == wxT("PREF")){
309                         int PriorityNumber = 0;
310                         bool ValidNumber = TRUE;
311                         
312                         try{
313                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
314                         }
315                         
316                         catch(std::invalid_argument &e){
317                                 ValidNumber = FALSE;
318                         }
320                         if (ValidNumber == TRUE){
322                                 GroupsListPref.erase(*GroupCount);
323                                 GroupsListPref.insert(std::make_pair(*GroupCount, PriorityNumber));
324                 
325                         }
326                 
327                 } else if (PropertyName == wxT("MEDIATYPE")){
329                         GroupsListMediaType.erase(*GroupCount);
330                         GroupsListMediaType.insert(std::make_pair(*GroupCount, PropertyValue));
331                 
332                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
333                         
334                         if (FirstToken == TRUE){
335                                 
336                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
337                                 FirstToken = FALSE;
338                                 
339                         } else {
340                         
341                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
342                                 
343                         }
344                         
345                 }
346                 
347         }
349         GroupsList.insert(std::make_pair(*GroupCount, PropertySeg2));
351         if (!PropertyTokens.IsEmpty()){
352         
353                 GroupsListTokens.insert(std::make_pair(*GroupCount, PropertyTokens));
354         
355         }
360 void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount){
362         std::map<int, int> SplitPoints;
363         std::map<int, int> SplitLength;
365         int intPrevValue = 4;
366         int intPref = 0;                        
367         int intType = 0;
368         
369         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
371         intPrevValue = 3;
372         
373         wxString PropertyName;
374         wxString PropertyValue;
375         wxString PropertyData;
376         wxString PropertyTokens;
377         std::map<int,int>::iterator SLiter;
378         bool FirstToken = TRUE;
379         
380         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
381         intiter != SplitPoints.end(); ++intiter){
382         
383                 SLiter = SplitLength.find(intiter->first);
384         
385                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
386                 
387                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
388                 PropertyName = PropertyElement.GetNextToken();                          
389                 PropertyValue = PropertyElement.GetNextToken();
390                 
391                 intPrevValue = intiter->second;
392                 
393                 CaptureString(&PropertyValue, FALSE);
394                 
395                 if (PropertyName == wxT("TYPE")){
397                         if (!PropertyValue.IsEmpty() || PropertyValue == wxT("home") ||
398                                 PropertyValue == wxT("work") ){
400                                 FullNamesListType.erase(*FNCount);
401                                 FullNamesListType.insert(std::make_pair(*FNCount, PropertyValue));
402                 
403                         }
404                 
405                 } else if (PropertyName == wxT("LANGUAGE")){
407                         FullNamesListLanguage.erase(*FNCount);
408                         FullNamesListLanguage.insert(std::make_pair(*FNCount, PropertyValue));
409                 
410                 } else if (PropertyName == wxT("ALTID")){
411                 
412                         FullNamesListAltID.erase(*FNCount);
413                         FullNamesListAltID.insert(std::make_pair(*FNCount, PropertyValue));
414                 
415                 } else if (PropertyName == wxT("PID")){
417                         FullNamesListPID.erase(*FNCount);
418                         FullNamesListPID.insert(std::make_pair(*FNCount, PropertyValue));
419                 
420                 } else if (PropertyName == wxT("PREF")){
422                         int PriorityNumber = 0;
423                         bool ValidNumber = TRUE;
424                         
425                         try{
426                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
427                         }
428                         
429                         catch(std::invalid_argument &e){
430                                 ValidNumber = FALSE;
431                         }
433                         if (ValidNumber == TRUE){
435                                 FullNamesListPref.erase(*FNCount);
436                                 FullNamesListPref.insert(std::make_pair(*FNCount, PriorityNumber));
438                         }
439                 
440                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
441                         
442                         if (FirstToken == TRUE){
443                                 
444                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
445                                 FirstToken = FALSE;
446                                 
447                         } else {
448                         
449                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
450                                 
451                         }
452                         
453                 } 
454         
455         }
457         FullNamesList.insert(std::make_pair(*FNCount, PropertySeg2));
459         if (!PropertyTokens.IsEmpty()){
460         
461                 FullNamesListTokens.insert(std::make_pair(*FNCount, PropertyTokens));
462         
463         }
467 void ContactDataObject::ProcessN(wxString PropertySeg1, wxString PropertySeg2){
469         std::map<int, int> SplitPoints;
470         std::map<int, int> SplitLength;
472         int intPrevValue = 3;
473         int intPref = 0;                        
474         int intType = 0;
475         
476         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
477         
478         intPrevValue = 2;
479         
480         wxString PropertyName;
481         wxString PropertyValue;
482         wxString PropertyData;
483         wxString PropertyTokens;
484         std::map<int,int>::iterator SLiter;
485         bool FirstToken = TRUE;
486         
487         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
488         intiter != SplitPoints.end(); ++intiter){
489         
490                 SLiter = SplitLength.find(intiter->first);
491         
492                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
493                 
494                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
495                 PropertyName = PropertyElement.GetNextToken();                          
496                 PropertyValue = PropertyElement.GetNextToken();
497                 
498                 intPrevValue = intiter->second;
499                 
500                 CaptureString(&PropertyValue, FALSE);
501                 
502                 if (PropertyName == wxT("ALTID")){
504                         NameAltID = PropertyValue;
505                 
506                 } else if (PropertyName == wxT("LANGUAGE")){
507                 
508                         NameLanguage = PropertyValue;
509                 
510                 } else if (PropertyName == wxT("SORT-AS")){
511                 
512                         if (PropertyValue.Left(1) == wxT("\"") && PropertyValue.Right(1) == wxT("\"") &&
513                                 PropertyValue.Len() >= 3){
514                                 NameDisplayAs = PropertyValue.Mid(1, (PropertyValue.Len() - 2));
515                         }
516                 
517                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
518                         
519                         if (FirstToken == TRUE){
520                                 
521                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
522                                 FirstToken = FALSE;
523                                 
524                         } else {
525                         
526                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
527                                 
528                         }
529                         
530                 }
531         
532         }
533         
534         // Split the name data.
535         
536         int intSplitSeek = 0;           
537         int intSplitsFound = 0;
538         int intSplitSize = 0;
539         int intPropertyLen = PropertySeg2.Len();
540         
541         std::map<int,wxString> NameValues;
542         intPrevValue = 0;                                       
543         
544         for (int i = 0; i <= intPropertyLen; i++){
545         
546                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
547                         
548                         NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, intSplitSize)));
549                         
550                         intSplitSeek = i;
551                         intSplitSeek++;
552                         
553                         if (intSplitsFound == 4){
554                         
555                                 NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, wxString::npos)));
556                                 break;
557                         
558                         }
559                         
560                         intSplitSize = 0;
561                         continue;
562         
563                 }
564                 
565                 intSplitSize++;
567         }
568         
569         // Split the data into several parts.
570                         
571         for (std::map<int, wxString>::iterator iter = NameValues.begin(); 
572         iter != NameValues.end(); ++iter){
573         
574                 if (iter->first == 1){
575                 
576                         // Deal with family name.
577                         
578                         NameSurname = iter->second;
579                 
580                 } else if (iter->first == 2){
581                 
582                         // Deal with given names.
583                         
584                         NameForename = iter->second;
585                 
586                 } else if (iter->first == 3){
587                 
588                         // Deal with additional names.
589                         
590                         NameOtherNames = iter->second;
591                 
592                 } else if (iter->first == 4){
593                 
594                         // Deal with honorifix prefixes and suffixes.
596                         NameTitle = iter->second;
597                 
598                         iter++;
599                         
600                         if (iter == NameValues.end()){
601                         
602                                 break;
603                         
604                         }
605                 
606                         NameSuffix = iter->second;
607                 
608                 }
609         
610         }
611         
612         // Add the name token data.
613         
614         if (!PropertyTokens.IsEmpty()){
615         
616                 NameTokens = PropertyTokens;
617         
618         }
622 void ContactDataObject::ProcessNickname(wxString PropertySeg1, wxString PropertySeg2, int *NicknameCount){
624         std::map<int, int> SplitPoints;
625         std::map<int, int> SplitLength;
627         int intPrevValue = 10;
628         int intPref = 0;                        
629         
630         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
631         
632         intPrevValue = 9;
633         
634         PropertyType PropType;
635         
636         // Look for type before continuing.
637         
638         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
639         
640         intPrevValue = 9;
641         
642         std::map<int, wxString> *NicknamesList = NULL;
643         std::map<int, wxString> *NicknamesListType = NULL;
644         std::map<int, wxString> *NicknamesListLanguage = NULL;
645         std::map<int, wxString> *NicknamesListAltID = NULL;
646         std::map<int, wxString> *NicknamesListPID = NULL;
647         std::map<int, wxString> *NicknamesListTokens = NULL;            
648         std::map<int, int> *NicknamesListPref = NULL;
649         
650         switch(PropType){
651                 case PROPERTY_NONE:
652                         NicknamesList = &GeneralNicknamesList;
653                         NicknamesListType = &GeneralNicknamesListType;
654                         NicknamesListLanguage = &GeneralNicknamesListLanguage;
655                         NicknamesListAltID = &GeneralNicknamesListAltID;
656                         NicknamesListPID = &GeneralNicknamesListPID;
657                         NicknamesListTokens = &GeneralNicknamesListTokens;
658                         NicknamesListPref = &GeneralNicknamesListPref;
659                         break;
660                 case PROPERTY_HOME:
661                         NicknamesList = &HomeNicknamesList;
662                         NicknamesListType = &HomeNicknamesListType;
663                         NicknamesListLanguage = &HomeNicknamesListLanguage;
664                         NicknamesListAltID = &HomeNicknamesListAltID;
665                         NicknamesListPID = &HomeNicknamesListPID;
666                         NicknamesListTokens = &HomeNicknamesListTokens;
667                         NicknamesListPref = &HomeNicknamesListPref;
668                         break;
669                 case PROPERTY_WORK:
670                         NicknamesList = &BusinessNicknamesList;
671                         NicknamesListType = &BusinessNicknamesListType;
672                         NicknamesListLanguage = &BusinessNicknamesListLanguage;
673                         NicknamesListAltID = &BusinessNicknamesListAltID;
674                         NicknamesListPID = &BusinessNicknamesListPID;
675                         NicknamesListTokens = &BusinessNicknamesListTokens;
676                         NicknamesListPref = &BusinessNicknamesListPref;
677                         break;
678         }
679         
680         std::map<int, int>::iterator SLiter;    
681         wxString PropertyData;
682         wxString PropertyName;
683         wxString PropertyValue;
684         wxString PropertyTokens;
685         bool FirstToken = TRUE;
686         
687         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
688         intiter != SplitPoints.end(); ++intiter){
689         
690                 SLiter = SplitLength.find(intiter->first);
691         
692                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
693                 
694                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
695                 PropertyName = PropertyElement.GetNextToken();                          
696                 PropertyValue = PropertyElement.GetNextToken();
697                 
698                 intPrevValue = intiter->second;
699                 
700                 CaptureString(&PropertyValue, FALSE);
701                 
702                 if (PropertyName == wxT("ALTID")){
704                         NicknamesListAltID->erase(*NicknameCount);
705                         NicknamesListAltID->insert(std::make_pair(*NicknameCount, PropertyValue));
706                 
707                 } else if (PropertyName == wxT("PID")){
709                         NicknamesListPID->erase(*NicknameCount);
710                         NicknamesListPID->insert(std::make_pair(*NicknameCount, PropertyValue));        
712                 } else if (PropertyName == wxT("PREF")){
714                         int PriorityNumber = 0;
715                         bool ValidNumber = TRUE;
716                         
717                         try{
718                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
719                         }
720                         
721                         catch(std::invalid_argument &e){
722                                 ValidNumber = FALSE;
723                         }
725                         if (ValidNumber == TRUE){
727                                 NicknamesListPref->erase(*NicknameCount);
728                                 NicknamesListPref->insert(std::make_pair(*NicknameCount, PriorityNumber));
730                         }
731                 
732                 } else if (PropertyName == wxT("LANGUAGE")){
734                         NicknamesListLanguage->erase(*NicknameCount);
735                         NicknamesListLanguage->insert(std::make_pair(*NicknameCount, PropertyValue));   
737                 } else {
738                 
739                         // Something else we don't know about so append
740                         // to the tokens variable.
741                 
742                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
743                 
744                                 if (FirstToken == TRUE){
745                         
746                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
747                                         FirstToken = FALSE;
748                         
749                                 } else {
750                         
751                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
752                         
753                                 }
754                 
755                         }
756                 
757                 }
758                 
759         }
760         
761         NicknamesList->insert(std::make_pair(*NicknameCount, PropertySeg2));
762         
763         // Add the name token data.
764         
765         if (!PropertyTokens.IsEmpty()){
766         
767                 NicknamesListTokens->insert(std::make_pair(*NicknameCount, PropertyTokens));
768         
769         }
773 void ContactDataObject::ProcessGender(wxString PropertySeg1, wxString PropertySeg2){
775         std::map<int, int> SplitPoints;
776         std::map<int, int> SplitLength;
777         std::map<int, int>::iterator SLiter;                    
778         wxString PropertyData;
779         wxString PropertyName;
780         wxString PropertyValue;
781         wxString PropertyTokens;
782         bool FirstToken = TRUE;
783         int intPrevValue = 8;
785         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
787         intPrevValue = 7;                       
788         
789         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
790         intiter != SplitPoints.end(); ++intiter){
791         
792                 SLiter = SplitLength.find(intiter->first);
793         
794                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
795                 
796                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
797                 PropertyName = PropertyElement.GetNextToken();                          
798                 PropertyValue = PropertyElement.GetNextToken();
799                 
800                 intPrevValue = intiter->second;
801                 
802                 // Process properties.
803                 
804                 size_t intPropertyValueLen = PropertyValue.Len();
805                 
806                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
807                         
808                         PropertyValue.Trim();
809                         PropertyValue.RemoveLast();
810                         
811                 }                               
812                 
813                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
814                         
815                         PropertyValue.Remove(0, 1);
816                         
817                 }                               
818                 
819                 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
821                         if (FirstToken == TRUE){
822         
823                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
824                                 FirstToken = FALSE;
825         
826                         } else {
827         
828                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
829         
830                         }
832                 }
833         
834         }       
836         wxStringTokenizer GenderData (PropertySeg2, wxT(";"));
837         
838         wxString GenderComponent;
839         
840         if (GenderData.CountTokens() >= 2){
841         
842                 Gender = GenderData.GetNextToken();
843                 GenderDetails = GenderData.GetString();
844         
845                 CaptureString(&GenderDetails, FALSE);
846                                                 
847         } else {
848         
849                 Gender = GenderData.GetNextToken();
850         
851         }
852         
853         if (!PropertyTokens.IsEmpty()){
854         
855                 GenderTokens = PropertyTokens;
856         
857         }
861 void ContactDataObject::ProcessBirthday(wxString PropertySeg1, wxString PropertySeg2){
863         // Process date. Preserve the remainder in the string.
865         std::map<int, int> SplitPoints;
866         std::map<int, int> SplitLength;
867         std::map<int, int>::iterator SLiter;                    
868         wxString PropertyData;
869         wxString PropertyName;
870         wxString PropertyValue;
871         wxString PropertyTokens;
872         bool BirthdayText = FALSE;
873         int intPrevValue = 6;
875         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
877         intPrevValue = 5;
879         // Look for type before continuing.
881         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
882         intiter != SplitPoints.end(); ++intiter){
884                 SLiter = SplitLength.find(intiter->first);
886                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
887         
888                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
889                 PropertyName = PropertyElement.GetNextToken();                          
890                 PropertyValue = PropertyElement.GetNextToken();
891         
892                 intPrevValue = intiter->second;
893         
894                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){
895         
896                         CaptureString(&PropertySeg2, FALSE);
897                         Birthday = PropertySeg2;
898                         BirthdayText = TRUE;
899         
900                 }
902         }
904         // Setup blank lines for later on.
905         
906         intPrevValue = 5;
907         bool FirstToken = TRUE;
909         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
910         intiter != SplitPoints.end(); ++intiter){
912                 SLiter = SplitLength.find(intiter->first);
914                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
915         
916                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
917                 PropertyName = PropertyElement.GetNextToken();                          
918                 PropertyValue = PropertyElement.GetNextToken();
919         
920                 intPrevValue = intiter->second;
921         
922                 // Process properties.
923         
924                 CaptureString(&PropertyValue, FALSE);
925         
926                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
927                 
928                         PropertyValue.Trim();
929                         PropertyValue.RemoveLast();
930                 
931                 }                               
932         
933                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
934                 
935                         PropertyValue.Remove(0, 1);
936                 
937                 }                               
938         
939                 if (PropertyName == wxT("ALTID")){
941                         BirthdayAltID = PropertyValue;
942         
943                 } else if (PropertyName == wxT("CALSCALE")){
944         
945                         BirthdayCalScale = PropertyValue;
946         
947                 } else if (PropertyName != wxT("VALUE")) {
948         
949                         // Something else we don't know about so append
950                         // to the tokens variable.
951                 
952                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
953                 
954                                 if (FirstToken == TRUE){
955         
956                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
957                                         FirstToken = FALSE;
958         
959                                 } else {
960         
961                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
962         
963                                 }
964                                 
965                         }
966                         
967                 }
969         }       
971         // Add the data to the variables and form.
972         
973         if (BirthdayText == FALSE){
974         
975                 Birthday = PropertySeg2;
977         }
978         
979         if (!PropertyTokens.IsEmpty()){
980         
981                 BirthdayTokens = PropertyTokens;
983         }
987 void ContactDataObject::ProcessAnniversary(wxString PropertySeg1, wxString PropertySeg2){
989         // Process date. Preserve the remainder in the string.
991         std::map<int, int> SplitPoints;
992         std::map<int, int> SplitLength;
993         std::map<int, int>::iterator SLiter;                    
994         wxString PropertyData;
995         wxString PropertyName;
996         wxString PropertyValue;
997         wxString PropertyTokens;
998         bool AnniversaryText = FALSE;
999         int intPrevValue = 13;
1001         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1003         intPrevValue = 12;
1005         // Look for type before continuing.
1007         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1008         intiter != SplitPoints.end(); ++intiter){
1010                 SLiter = SplitLength.find(intiter->first);
1012                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1013         
1014                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1015                 PropertyName = PropertyElement.GetNextToken();                          
1016                 PropertyValue = PropertyElement.GetNextToken();
1017         
1018                 intPrevValue = intiter->second;
1019         
1020                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){
1021         
1022                         CaptureString(&PropertySeg2, FALSE);
1023                         Anniversary = PropertySeg2;
1024                         AnniversaryText = TRUE;
1025         
1026                 }
1028         }
1030         // Setup blank lines for later on.
1031         
1032         intPrevValue = 12;
1033         bool FirstToken = TRUE;
1035         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1036         intiter != SplitPoints.end(); ++intiter){
1038                 SLiter = SplitLength.find(intiter->first);
1040                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1041         
1042                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1043                 PropertyName = PropertyElement.GetNextToken();                          
1044                 PropertyValue = PropertyElement.GetNextToken();
1045         
1046                 intPrevValue = intiter->second;
1047         
1048                 // Process properties.
1049         
1050                 CaptureString(&PropertyValue, FALSE);
1051         
1052                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
1053                 
1054                         PropertyValue.Trim();
1055                         PropertyValue.RemoveLast();
1056                 
1057                 }                               
1058         
1059                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
1060                 
1061                         PropertyValue.Remove(0, 1);
1062                 
1063                 }                               
1064         
1065                 if (PropertyName == wxT("ALTID")){
1067                         AnniversaryAltID = PropertyValue;
1068         
1069                 } else if (PropertyName == wxT("CALSCALE")){
1070         
1071                         AnniversaryCalScale = PropertyValue;
1072         
1073                 } else if (PropertyName != wxT("VALUE")) {
1074         
1075                         // Something else we don't know about so append
1076                         // to the tokens variable.
1077                 
1078                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
1079                 
1080                                 if (FirstToken == TRUE){
1081         
1082                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1083                                         FirstToken = FALSE;
1084         
1085                                 } else {
1086         
1087                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1088         
1089                                 }
1090                                 
1091                         }
1092                         
1093                 }
1095         }       
1097         // Add the data to the variables and form.
1098         
1099         if (AnniversaryText == FALSE){
1100         
1101                 Anniversary = PropertySeg2;
1103         }
1104         
1105         if (!PropertyTokens.IsEmpty()){
1106         
1107                 AnniversaryTokens = PropertyTokens;
1109         }
1113 void ContactDataObject::ProcessTimeZone(wxString PropertySeg1, wxString PropertySeg2, int *TimeZoneCount){
1115         std::map<int, int> SplitPoints;
1116         std::map<int, int> SplitLength;
1118         int intPrevValue = 4;
1119         int intPref = 0;                        
1120         
1121         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
1122         
1123         intPrevValue = 3;
1124         
1125         PropertyType PropType;
1126         
1127         // Look for type before continuing.
1128         
1129         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
1130         
1131         intPrevValue = 3;
1132         
1133         std::map<int, wxString> *TZList = NULL;
1134         std::map<int, wxString> *TZListType = NULL;
1135         std::map<int, wxString> *TZListMediatype = NULL;
1136         std::map<int, wxString> *TZListAltID = NULL;
1137         std::map<int, wxString> *TZListPID = NULL;
1138         std::map<int, wxString> *TZListTokens = NULL;           
1139         std::map<int, int> *TZListPref = NULL;
1140         
1141         switch(PropType){
1142                 case PROPERTY_NONE:
1143                         TZList = &GeneralTZList;
1144                         TZListType = &GeneralTZListType;
1145                         TZListMediatype = &GeneralTZListMediatype;
1146                         TZListAltID = &GeneralTZListAltID;
1147                         TZListPID = &GeneralTZListPID;
1148                         TZListTokens = &GeneralTZListTokens;
1149                         TZListPref = &GeneralTZListPref;
1150                         break;
1151                 case PROPERTY_HOME:
1152                         TZList = &HomeTZList;
1153                         TZListType = &HomeTZListType;
1154                         TZListMediatype = &HomeTZListMediatype;
1155                         TZListAltID = &HomeTZListAltID;
1156                         TZListPID = &HomeTZListPID;
1157                         TZListTokens = &HomeTZListTokens;
1158                         TZListPref = &HomeTZListPref;
1159                         break;
1160                 case PROPERTY_WORK:
1161                         TZList = &BusinessTZList;
1162                         TZListType = &BusinessTZListType;
1163                         TZListMediatype = &BusinessTZListMediatype;
1164                         TZListAltID = &BusinessTZListAltID;
1165                         TZListPID = &BusinessTZListPID;
1166                         TZListTokens = &BusinessTZListTokens;
1167                         TZListPref = &BusinessTZListPref;
1168                         break;
1169         }
1170         
1171         std::map<int, int>::iterator SLiter;    
1172         wxString PropertyData;
1173         wxString PropertyName;
1174         wxString PropertyValue;
1175         wxString PropertyTokens;
1176         bool FirstToken = TRUE;
1177         
1178         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1179         intiter != SplitPoints.end(); ++intiter){
1180         
1181                 SLiter = SplitLength.find(intiter->first);
1182         
1183                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
1184                 
1185                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1186                 PropertyName = PropertyElement.GetNextToken();                          
1187                 PropertyValue = PropertyElement.GetNextToken();
1188                 
1189                 intPrevValue = intiter->second;
1190                 
1191                 CaptureString(&PropertyValue, FALSE);
1193                 if (PropertyName == wxT("ALTID")){
1195                         TZListAltID->erase(*TimeZoneCount);
1196                         TZListAltID->insert(std::make_pair(*TimeZoneCount, PropertyValue));
1197                 
1198                 } else if (PropertyName == wxT("PID")){
1200                         TZListPID->erase(*TimeZoneCount);
1201                         TZListPID->insert(std::make_pair(*TimeZoneCount, PropertyValue));       
1203                 } else if (PropertyName == wxT("PREF")){
1205                         int PriorityNumber = 0;
1206                         bool ValidNumber = TRUE;
1207                         
1208                         try{
1209                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
1210                         }
1211                         
1212                         catch(std::invalid_argument &e){
1213                                 ValidNumber = FALSE;
1214                         }
1216                         if (ValidNumber == TRUE){
1218                                 TZListPref->erase(*TimeZoneCount);
1219                                 TZListPref->insert(std::make_pair(*TimeZoneCount, PriorityNumber));
1221                         }
1222                 
1223                 } else if (PropertyName == wxT("MEDIATYPE")){
1225                         TZListMediatype->erase(*TimeZoneCount);
1226                         TZListMediatype->insert(std::make_pair(*TimeZoneCount, PropertyValue)); 
1228                 } else {
1229                 
1230                         // Something else we don't know about so append
1231                         // to the tokens variable.
1232                 
1233                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
1234                 
1235                                 if (FirstToken == TRUE){
1236                         
1237                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1238                                         FirstToken = FALSE;
1239                         
1240                                 } else {
1241                         
1242                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1243                         
1244                                 }
1245                 
1246                         }
1247                 
1248                 }
1249                 
1250         }
1251         
1252         TZList->insert(std::make_pair(*TimeZoneCount, PropertySeg2));
1253         
1254         // Add the name token data.
1255         
1256         if (!PropertyTokens.IsEmpty()){
1257         
1258                 TZListTokens->insert(std::make_pair(*TimeZoneCount, PropertyTokens));
1259         
1260         }
1265 void SplitValues(wxString *PropertyLine, 
1266         std::map<int,int> *SplitPoints, 
1267         std::map<int,int> *SplitLength, 
1268         int intSize){
1269         
1270         size_t intPropertyLen = PropertyLine->Len();
1271         int intSplitsFound = 0;
1272         int intSplitSize = 0;
1273         int intSplitSeek = 0;
1274         
1275         for (int i = intSize; i <= intPropertyLen; i++){
1277                 intSplitSize++;
1278         
1279                 if (PropertyLine->Mid(i, 1) == wxT(";") &&
1280                     PropertyLine->Mid((i - 1), 1) != wxT("\\")){
1281            
1282                     if (intSplitsFound == 0){
1283             
1284                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
1285           
1286                     } else {
1287            
1288                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1289             
1290                     }
1291             
1292                     SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
1293             
1294                     intSplitsFound++;
1295                     intSplitSeek = i;
1296                     intSplitSize = 0;
1297             
1298                 }
1300         }
1302         if (intSplitsFound == 0){
1304                 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
1305                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1307         } else {
1309                 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
1310                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1312         }
1316 void CheckType(wxString *PropertySeg1, 
1317         std::map<int,int> *SplitPoints, 
1318         std::map<int,int> *SplitLength, 
1319         int *intPrevValue, 
1320         PropertyType *PropType){
1321         
1322         wxString PropertyData;
1323         wxString PropertyName;
1324         wxString PropertyValue;
1325         std::map<int,int>::iterator SLiter;
1326         
1327         for (std::map<int, int>::iterator intiter = SplitPoints->begin(); 
1328         intiter != SplitPoints->end(); ++intiter){
1329         
1330                 SLiter = SplitLength->find(intiter->first);
1331         
1332                 PropertyData = PropertySeg1->Mid(*intPrevValue, (SLiter->second));
1333                 
1334                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1335                 PropertyName = PropertyElement.GetNextToken();                          
1336                 PropertyValue = PropertyElement.GetNextToken();
1337                 
1338                 *intPrevValue = intiter->second;
1339                 
1340                 if (PropertyName == wxT("TYPE")){
1341                                 
1342                         if (PropertyValue == wxT("work")){
1343                         
1344                                 *PropType = PROPERTY_WORK;
1345                                                         
1346                         } else if (PropertyValue == wxT("home")){
1348                                 *PropType = PROPERTY_HOME;
1349                                                         
1350                         } else {
1351                         
1352                                 *PropType = PROPERTY_NONE;
1353                         
1354                         }
1355                 
1356                         return;
1357                 
1358                 }
1359         
1360         }
1361         
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