Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
5275553fef33a7fcb1e5cac575efd8891cd4807c
[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         wxString ContactLine;
87         wxString PropertyLine;
88         wxString PropertySeg1;
89         wxString PropertySeg2;
90         wxString PropertyNextLine;
91         wxString Property;
92         
93         for (std::map<int,wxString>::iterator iter = ContactFileLines.begin(); 
94          iter != ContactFileLines.end(); ++iter){
96                 ExtraLineSeek = TRUE;
97                 QuoteMode = FALSE;
98                 PropertyFind = TRUE;
99                 ContactLineLen = 0;
100                 QuoteBreakPoint = 0;
101                 ContactLine.Clear();
102                 PropertyLine.Clear();
103                 PropertySeg1.Clear();
104                 PropertySeg2.Clear();
105                 Property.Clear();
106          
107                 ContactLine = iter->second;
108                 
109                 while (ExtraLineSeek == TRUE){
110                 
111                         // Check if there is extra data on the next line 
112                         // (indicated by space or tab at the start) and add data.
113                 
114                         iter++;
115                         
116                         if (iter == ContactFileLines.end()){
117                         
118                                 iter--;
119                                 break;
120                         
121                         }                       
122                 
123                         PropertyNextLine = iter->second;
124                 
125                         if (PropertyNextLine.Mid(0, 1) == wxT(" ") || PropertyNextLine.Mid(0, 1) == wxT("\t")){
126                 
127                                 PropertyNextLine.Remove(0, 1);
128                                 ContactLine.Append(PropertyNextLine);
129                 
130                         } else {
131                         
132                                 iter--;
133                                 ExtraLineSeek = FALSE;
134                         
135                         }
136                 
137                 }
139                 ContactLineLen = ContactLine.Len();
140                 
141                 // Make sure we are not in quotation mode.
142                 // Make sure colon does not have \ or \\ before it.
143                 
144                 for (int i = 0; i <= ContactLineLen; i++){
145                 
146                         if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
147                         
148                                 PropertyFind = FALSE;
149                         
150                         } else if (PropertyFind == TRUE){
151                         
152                                 Property.Append(ContactLine.Mid(i, 1));
153                         
154                         }               
155                 
156                         if (ContactLine.Mid(i, 1) == wxT("\"")){
157                         
158                                 if (QuoteMode == TRUE){
159                                 
160                                         QuoteMode = FALSE;
161                                 
162                                 } else {
163                         
164                                         QuoteMode = TRUE;
165                                         
166                                 }
167                         
168                         }
169                         
170                         if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
171                         
172                                 QuoteBreakPoint = i;
173                                 break;
174                         
175                         }
176                 
177                 }
178                 
179                 // Split that line at the point into two variables (ignore the colon).
180                 
181                 PropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
182                 PropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
183                 
184                  if (Property == wxT("KIND") && KindProcessed == FALSE){
185                                 
186                         ProcessKind(PropertySeg2);
187                 
188                 } else if (Property == wxT("MEMBER")){
190                         ProcessMember(PropertySeg1, PropertySeg2, &GroupCount);
191                         GroupCount++;   
192                 
193                 } else if (Property == wxT("FN")){
194                 
195                         ProcessFN(PropertySeg1, PropertySeg2, &FNCount);
196                         FNCount++;
197                 
198                 } else if (Property == wxT("N") && NameProcessed == FALSE){
199                 
200                         ProcessN(PropertySeg1, PropertySeg2);
201                         NameProcessed = TRUE;
202                 
203                 } else if (Property == wxT("NICKNAME")){
204                                                 
205                         ProcessNickname(PropertySeg1, PropertySeg2, &NicknameCount);
206                         NicknameCount++;
207                         
208                 } else if (Property == wxT("GENDER") && GenderProcessed == FALSE){
209                 
210                         ProcessGender(PropertySeg1, PropertySeg2);
211                         GenderProcessed = TRUE;
212                 
213                 } else if (Property == wxT("BDAY") && BirthdayProcessed == FALSE){
214                 
215                         ProcessBirthday(PropertySeg1, PropertySeg2);
216                         BirthdayProcessed = TRUE;
217                 
218                 } else if (Property == wxT("ANNIVERSARY") && AnniversaryProcessed == FALSE){
219                 
220                         ProcessAnniversary(PropertySeg1, PropertySeg2);
221                         AnniversaryProcessed = TRUE;
222                 
223                 }
224                 
225         }
226         
227         return CONTACTLOAD_OK;
231 void ContactDataObject::ProcessKind(wxString KindType){
233         if (KindType == wxT("individual")){
234                         
235                 ContactKind = CONTACTKIND_INDIVIDUAL;
236                         
237         } else if (KindType == wxT("group")){
238                         
239                 ContactKind = CONTACTKIND_GROUP;
240                         
241         } else if (KindType == wxT("org")){
242                         
243                 ContactKind = CONTACTKIND_ORGANISATION;
244                         
245         } else if (KindType == wxT("location")){
246                         
247                 ContactKind = CONTACTKIND_LOCATION;
248                         
249         } else {
250                         
251                 ContactKind = CONTACTKIND_NONE;                 
252         }
256 void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount){
258         std::map<int, int> SplitPoints;
259         std::map<int, int> SplitLength;
261         int intPrevValue = 8;
262         int intPref = 0;                        
263         int intType = 0;
264         
265         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
267         intPrevValue = 7;
268         
269         wxString PropertyName;
270         wxString PropertyValue;
271         wxString PropertyData;
272         wxString PropertyTokens;
273         std::map<int,int>::iterator SLiter;
274         bool FirstToken = TRUE;
275         
276         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
277         intiter != SplitPoints.end(); ++intiter){
278         
279                 SLiter = SplitLength.find(intiter->first);
280         
281                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
282                 
283                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
284                 PropertyName = PropertyElement.GetNextToken();                          
285                 PropertyValue = PropertyElement.GetNextToken();
286                 
287                 intPrevValue = intiter->second;
288                 
289                 CaptureString(&PropertyValue, FALSE);
290         
291                 if (PropertyName == wxT("ALTID")){
293                         GroupsListAltID.erase(*GroupCount);
294                         GroupsListAltID.insert(std::make_pair(*GroupCount, PropertyValue));
295                 
296                 } else if (PropertyName == wxT("PID")){
298                         GroupsListPID.erase(*GroupCount);
299                         GroupsListPID.insert(std::make_pair(*GroupCount, PropertyValue));
300                 
301                 } else if (PropertyName == wxT("PREF")){
303                         int PriorityNumber = 0;
304                         bool ValidNumber = TRUE;
305                         
306                         try{
307                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
308                         }
309                         
310                         catch(std::invalid_argument &e){
311                                 ValidNumber = FALSE;
312                         }
314                         if (ValidNumber == TRUE){
316                                 GroupsListPref.erase(*GroupCount);
317                                 GroupsListPref.insert(std::make_pair(*GroupCount, PriorityNumber));
318                 
319                         }
320                 
321                 } else if (PropertyName == wxT("MEDIATYPE")){
323                         GroupsListMediaType.erase(*GroupCount);
324                         GroupsListMediaType.insert(std::make_pair(*GroupCount, PropertyValue));
325                 
326                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
327                         
328                         if (FirstToken == TRUE){
329                                 
330                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
331                                 FirstToken = FALSE;
332                                 
333                         } else {
334                         
335                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
336                                 
337                         }
338                         
339                 }
340                 
341         }
343         GroupsList.insert(std::make_pair(*GroupCount, PropertySeg2));
345         if (!PropertyTokens.IsEmpty()){
346         
347                 GroupsListTokens.insert(std::make_pair(*GroupCount, PropertyTokens));
348         
349         }
354 void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount){
356         std::map<int, int> SplitPoints;
357         std::map<int, int> SplitLength;
359         int intPrevValue = 4;
360         int intPref = 0;                        
361         int intType = 0;
362         
363         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
365         intPrevValue = 3;
366         
367         wxString PropertyName;
368         wxString PropertyValue;
369         wxString PropertyData;
370         wxString PropertyTokens;
371         std::map<int,int>::iterator SLiter;
372         bool FirstToken = TRUE;
373         
374         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
375         intiter != SplitPoints.end(); ++intiter){
376         
377                 SLiter = SplitLength.find(intiter->first);
378         
379                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
380                 
381                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
382                 PropertyName = PropertyElement.GetNextToken();                          
383                 PropertyValue = PropertyElement.GetNextToken();
384                 
385                 intPrevValue = intiter->second;
386                 
387                 CaptureString(&PropertyValue, FALSE);
388                 
389                 if (PropertyName == wxT("TYPE")){
391                         if (!PropertyValue.IsEmpty() || PropertyValue == wxT("home") ||
392                                 PropertyValue == wxT("work") ){
394                                 FullNamesListType.erase(*FNCount);
395                                 FullNamesListType.insert(std::make_pair(*FNCount, PropertyValue));
396                 
397                         }
398                 
399                 } else if (PropertyName == wxT("LANGUAGE")){
401                         FullNamesListLanguage.erase(*FNCount);
402                         FullNamesListLanguage.insert(std::make_pair(*FNCount, PropertyValue));
403                 
404                 } else if (PropertyName == wxT("ALTID")){
405                 
406                         FullNamesListAltID.erase(*FNCount);
407                         FullNamesListAltID.insert(std::make_pair(*FNCount, PropertyValue));
408                 
409                 } else if (PropertyName == wxT("PID")){
411                         FullNamesListPID.erase(*FNCount);
412                         FullNamesListPID.insert(std::make_pair(*FNCount, PropertyValue));
413                 
414                 } else if (PropertyName == wxT("PREF")){
416                         int PriorityNumber = 0;
417                         bool ValidNumber = TRUE;
418                         
419                         try{
420                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
421                         }
422                         
423                         catch(std::invalid_argument &e){
424                                 ValidNumber = FALSE;
425                         }
427                         if (ValidNumber == TRUE){
429                                 FullNamesListPref.erase(*FNCount);
430                                 FullNamesListPref.insert(std::make_pair(*FNCount, PriorityNumber));
432                         }
433                 
434                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
435                         
436                         if (FirstToken == TRUE){
437                                 
438                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
439                                 FirstToken = FALSE;
440                                 
441                         } else {
442                         
443                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
444                                 
445                         }
446                         
447                 } 
448         
449         }
451         FullNamesList.insert(std::make_pair(*FNCount, PropertySeg2));
453         if (!PropertyTokens.IsEmpty()){
454         
455                 FullNamesListTokens.insert(std::make_pair(*FNCount, PropertyTokens));
456         
457         }
461 void ContactDataObject::ProcessN(wxString PropertySeg1, wxString PropertySeg2){
463         std::map<int, int> SplitPoints;
464         std::map<int, int> SplitLength;
466         int intPrevValue = 3;
467         int intPref = 0;                        
468         int intType = 0;
469         
470         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
471         
472         intPrevValue = 2;
473         
474         wxString PropertyName;
475         wxString PropertyValue;
476         wxString PropertyData;
477         wxString PropertyTokens;
478         std::map<int,int>::iterator SLiter;
479         bool FirstToken = TRUE;
480         
481         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
482         intiter != SplitPoints.end(); ++intiter){
483         
484                 SLiter = SplitLength.find(intiter->first);
485         
486                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
487                 
488                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
489                 PropertyName = PropertyElement.GetNextToken();                          
490                 PropertyValue = PropertyElement.GetNextToken();
491                 
492                 intPrevValue = intiter->second;
493                 
494                 CaptureString(&PropertyValue, FALSE);
495                 
496                 if (PropertyName == wxT("ALTID")){
498                         NameAltID = PropertyValue;
499                 
500                 } else if (PropertyName == wxT("LANGUAGE")){
501                 
502                         NameLanguage = PropertyValue;
503                 
504                 } else if (PropertyName == wxT("SORT-AS")){
505                 
506                         if (PropertyValue.Left(1) == wxT("\"") && PropertyValue.Right(1) == wxT("\"") &&
507                                 PropertyValue.Len() >= 3){
508                                 NameDisplayAs = PropertyValue.Mid(1, (PropertyValue.Len() - 2));
509                         }
510                 
511                 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
512                         
513                         if (FirstToken == TRUE){
514                                 
515                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
516                                 FirstToken = FALSE;
517                                 
518                         } else {
519                         
520                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
521                                 
522                         }
523                         
524                 }
525         
526         }
527         
528         // Split the name data.
529         
530         int intSplitSeek = 0;           
531         int intSplitsFound = 0;
532         int intSplitSize = 0;
533         int intPropertyLen = PropertySeg2.Len();
534         
535         std::map<int,wxString> NameValues;
536         intPrevValue = 0;                                       
537         
538         for (int i = 0; i <= intPropertyLen; i++){
539         
540                 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
541                         
542                         NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, intSplitSize)));
543                         
544                         intSplitSeek = i;
545                         intSplitSeek++;
546                         
547                         if (intSplitsFound == 4){
548                         
549                                 NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, wxString::npos)));
550                                 break;
551                         
552                         }
553                         
554                         intSplitSize = 0;
555                         continue;
556         
557                 }
558                 
559                 intSplitSize++;
561         }
562         
563         // Split the data into several parts.
564                         
565         for (std::map<int, wxString>::iterator iter = NameValues.begin(); 
566         iter != NameValues.end(); ++iter){
567         
568                 if (iter->first == 1){
569                 
570                         // Deal with family name.
571                         
572                         NameSurname = iter->second;
573                 
574                 } else if (iter->first == 2){
575                 
576                         // Deal with given names.
577                         
578                         NameForename = iter->second;
579                 
580                 } else if (iter->first == 3){
581                 
582                         // Deal with additional names.
583                         
584                         NameOtherNames = iter->second;
585                 
586                 } else if (iter->first == 4){
587                 
588                         // Deal with honorifix prefixes and suffixes.
590                         NameTitle = iter->second;
591                 
592                         iter++;
593                         
594                         if (iter == NameValues.end()){
595                         
596                                 break;
597                         
598                         }
599                 
600                         NameSuffix = iter->second;
601                 
602                 }
603         
604         }
605         
606         // Add the name token data.
607         
608         if (!PropertyTokens.IsEmpty()){
609         
610                 NameTokens = PropertyTokens;
611         
612         }
616 void ContactDataObject::ProcessNickname(wxString PropertySeg1, wxString PropertySeg2, int *NicknameCount){
618         std::map<int, int> SplitPoints;
619         std::map<int, int> SplitLength;
621         int intPrevValue = 10;
622         int intPref = 0;                        
623         
624         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
625         
626         intPrevValue = 9;
627         
628         PropertyType PropType;
629         
630         // Look for type before continuing.
631         
632         CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
633         
634         intPrevValue = 9;
635         
636         std::map<int, wxString> *NicknamesList = NULL;
637         std::map<int, wxString> *NicknamesListType = NULL;
638         std::map<int, wxString> *NicknamesListLanguage = NULL;
639         std::map<int, wxString> *NicknamesListAltID = NULL;
640         std::map<int, wxString> *NicknamesListPID = NULL;
641         std::map<int, wxString> *NicknamesListTokens = NULL;            
642         std::map<int, int> *NicknamesListPref = NULL;
643         
644         switch(PropType){
645                 case PROPERTY_NONE:
646                         NicknamesList = &GeneralNicknamesList;
647                         NicknamesListType = &GeneralNicknamesListType;
648                         NicknamesListLanguage = &GeneralNicknamesListLanguage;
649                         NicknamesListAltID = &GeneralNicknamesListAltID;
650                         NicknamesListPID = &GeneralNicknamesListPID;
651                         NicknamesListTokens = &GeneralNicknamesListTokens;
652                         NicknamesListPref = &GeneralNicknamesListPref;
653                         break;
654                 case PROPERTY_HOME:
655                         NicknamesList = &HomeNicknamesList;
656                         NicknamesListType = &HomeNicknamesListType;
657                         NicknamesListLanguage = &HomeNicknamesListLanguage;
658                         NicknamesListAltID = &HomeNicknamesListAltID;
659                         NicknamesListPID = &HomeNicknamesListPID;
660                         NicknamesListTokens = &HomeNicknamesListTokens;
661                         NicknamesListPref = &HomeNicknamesListPref;
662                         break;
663                 case PROPERTY_WORK:
664                         NicknamesList = &BusinessNicknamesList;
665                         NicknamesListType = &BusinessNicknamesListType;
666                         NicknamesListLanguage = &BusinessNicknamesListLanguage;
667                         NicknamesListAltID = &BusinessNicknamesListAltID;
668                         NicknamesListPID = &BusinessNicknamesListPID;
669                         NicknamesListTokens = &BusinessNicknamesListTokens;
670                         NicknamesListPref = &BusinessNicknamesListPref;
671                         break;
672         }
673         
674         std::map<int, int>::iterator SLiter;    
675         wxString PropertyData;
676         wxString PropertyName;
677         wxString PropertyValue;
678         wxString PropertyTokens;
679         bool FirstToken = TRUE;
680         
681         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
682         intiter != SplitPoints.end(); ++intiter){
683         
684                 SLiter = SplitLength.find(intiter->first);
685         
686                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
687                 
688                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
689                 PropertyName = PropertyElement.GetNextToken();                          
690                 PropertyValue = PropertyElement.GetNextToken();
691                 
692                 intPrevValue = intiter->second;
693                 
694                 CaptureString(&PropertyValue, FALSE);
695                 
696                 if (PropertyName == wxT("ALTID")){
698                         NicknamesListAltID->erase(*NicknameCount);
699                         NicknamesListAltID->insert(std::make_pair(*NicknameCount, PropertyValue));
700                 
701                 } else if (PropertyName == wxT("PID")){
703                         NicknamesListPID->erase(*NicknameCount);
704                         NicknamesListPID->insert(std::make_pair(*NicknameCount, PropertyValue));        
706                 } else if (PropertyName == wxT("PREF")){
708                         int PriorityNumber = 0;
709                         bool ValidNumber = TRUE;
710                         
711                         try{
712                                 PriorityNumber = std::stoi(PropertyValue.ToStdString());
713                         }
714                         
715                         catch(std::invalid_argument &e){
716                                 ValidNumber = FALSE;
717                         }
719                         if (ValidNumber == TRUE){
721                                 NicknamesListPref->erase(*NicknameCount);
722                                 NicknamesListPref->insert(std::make_pair(*NicknameCount, PriorityNumber));
724                         }
725                 
726                 } else if (PropertyName == wxT("LANGUAGE")){
728                         NicknamesListLanguage->erase(*NicknameCount);
729                         NicknamesListLanguage->insert(std::make_pair(*NicknameCount, PropertyValue));   
731                 } else {
732                 
733                         // Something else we don't know about so append
734                         // to the tokens variable.
735                 
736                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
737                 
738                                 if (FirstToken == TRUE){
739                         
740                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
741                                         FirstToken = FALSE;
742                         
743                                 } else {
744                         
745                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
746                         
747                                 }
748                 
749                         }
750                 
751                 }
752                 
753         }
754         
755         NicknamesList->insert(std::make_pair(*NicknameCount, PropertySeg2));
756         
757         // Add the name token data.
758         
759         if (!PropertyTokens.IsEmpty()){
760         
761                 NicknamesListTokens->insert(std::make_pair(*NicknameCount, PropertyTokens));
762         
763         }
767 void ContactDataObject::ProcessGender(wxString PropertySeg1, wxString PropertySeg2){
769         std::map<int, int> SplitPoints;
770         std::map<int, int> SplitLength;
771         std::map<int, int>::iterator SLiter;                    
772         wxString PropertyData;
773         wxString PropertyName;
774         wxString PropertyValue;
775         wxString PropertyTokens;
776         bool FirstToken = TRUE;
777         int intPrevValue = 8;
779         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
781         intPrevValue = 7;                       
782         
783         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
784         intiter != SplitPoints.end(); ++intiter){
785         
786                 SLiter = SplitLength.find(intiter->first);
787         
788                 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
789                 
790                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
791                 PropertyName = PropertyElement.GetNextToken();                          
792                 PropertyValue = PropertyElement.GetNextToken();
793                 
794                 intPrevValue = intiter->second;
795                 
796                 // Process properties.
797                 
798                 size_t intPropertyValueLen = PropertyValue.Len();
799                 
800                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
801                         
802                         PropertyValue.Trim();
803                         PropertyValue.RemoveLast();
804                         
805                 }                               
806                 
807                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
808                         
809                         PropertyValue.Remove(0, 1);
810                         
811                 }                               
812                 
813                 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
815                         if (FirstToken == TRUE){
816         
817                                 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
818                                 FirstToken = FALSE;
819         
820                         } else {
821         
822                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
823         
824                         }
826                 }
827         
828         }       
830         wxStringTokenizer GenderData (PropertySeg2, wxT(";"));
831         
832         wxString GenderComponent;
833         
834         if (GenderData.CountTokens() >= 2){
835         
836                 Gender = GenderData.GetNextToken();
837                 GenderDetails = GenderData.GetString();
838         
839                 CaptureString(&GenderDetails, FALSE);
840                                                 
841         } else {
842         
843                 Gender = GenderData.GetNextToken();
844         
845         }
846         
847         if (!PropertyTokens.IsEmpty()){
848         
849                 GenderTokens = PropertyTokens;
850         
851         }
855 void ContactDataObject::ProcessBirthday(wxString PropertySeg1, wxString PropertySeg2){
857         // Process date. Preserve the remainder in the string.
859         std::map<int, int> SplitPoints;
860         std::map<int, int> SplitLength;
861         std::map<int, int>::iterator SLiter;                    
862         wxString PropertyData;
863         wxString PropertyName;
864         wxString PropertyValue;
865         wxString PropertyTokens;
866         bool BirthdayText = FALSE;
867         int intPrevValue = 6;
869         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
871         intPrevValue = 5;
873         // Look for type before continuing.
875         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
876         intiter != SplitPoints.end(); ++intiter){
878                 SLiter = SplitLength.find(intiter->first);
880                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
881         
882                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
883                 PropertyName = PropertyElement.GetNextToken();                          
884                 PropertyValue = PropertyElement.GetNextToken();
885         
886                 intPrevValue = intiter->second;
887         
888                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){
889         
890                         CaptureString(&PropertySeg2, FALSE);
891                         Birthday = PropertySeg2;
892                         BirthdayText = TRUE;
893         
894                 }
896         }
898         // Setup blank lines for later on.
899         
900         intPrevValue = 5;
901         bool FirstToken = TRUE;
903         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
904         intiter != SplitPoints.end(); ++intiter){
906                 SLiter = SplitLength.find(intiter->first);
908                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
909         
910                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
911                 PropertyName = PropertyElement.GetNextToken();                          
912                 PropertyValue = PropertyElement.GetNextToken();
913         
914                 intPrevValue = intiter->second;
915         
916                 // Process properties.
917         
918                 CaptureString(&PropertyValue, FALSE);
919         
920                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
921                 
922                         PropertyValue.Trim();
923                         PropertyValue.RemoveLast();
924                 
925                 }                               
926         
927                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
928                 
929                         PropertyValue.Remove(0, 1);
930                 
931                 }                               
932         
933                 if (PropertyName == wxT("ALTID")){
935                         BirthdayAltID = PropertyValue;
936         
937                 } else if (PropertyName == wxT("CALSCALE")){
938         
939                         BirthdayCalScale = PropertyValue;
940         
941                 } else if (PropertyName != wxT("VALUE")) {
942         
943                         // Something else we don't know about so append
944                         // to the tokens variable.
945                 
946                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
947                 
948                                 if (FirstToken == TRUE){
949         
950                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
951                                         FirstToken = FALSE;
952         
953                                 } else {
954         
955                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
956         
957                                 }
958                                 
959                         }
960                         
961                 }
963         }       
965         // Add the data to the variables and form.
966         
967         if (BirthdayText == FALSE){
968         
969                 Birthday = PropertySeg2;
971         }
972         
973         if (!PropertyTokens.IsEmpty()){
974         
975                 BirthdayTokens = PropertyTokens;
977         }
981 void ContactDataObject::ProcessAnniversary(wxString PropertySeg1, wxString PropertySeg2){
983         // Process date. Preserve the remainder in the string.
985         std::map<int, int> SplitPoints;
986         std::map<int, int> SplitLength;
987         std::map<int, int>::iterator SLiter;                    
988         wxString PropertyData;
989         wxString PropertyName;
990         wxString PropertyValue;
991         wxString PropertyTokens;
992         bool AnniversaryText = FALSE;
993         int intPrevValue = 6;
995         SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
997         intPrevValue = 5;
999         // Look for type before continuing.
1001         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1002         intiter != SplitPoints.end(); ++intiter){
1004                 SLiter = SplitLength.find(intiter->first);
1006                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1007         
1008                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1009                 PropertyName = PropertyElement.GetNextToken();                          
1010                 PropertyValue = PropertyElement.GetNextToken();
1011         
1012                 intPrevValue = intiter->second;
1013         
1014                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){
1015         
1016                         CaptureString(&PropertySeg2, FALSE);
1017                         Anniversary = PropertySeg2;
1018                         AnniversaryText = TRUE;
1019         
1020                 }
1022         }
1024         // Setup blank lines for later on.
1025         
1026         intPrevValue = 5;
1027         bool FirstToken = TRUE;
1029         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
1030         intiter != SplitPoints.end(); ++intiter){
1032                 SLiter = SplitLength.find(intiter->first);
1034                 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1035         
1036                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1037                 PropertyName = PropertyElement.GetNextToken();                          
1038                 PropertyValue = PropertyElement.GetNextToken();
1039         
1040                 intPrevValue = intiter->second;
1041         
1042                 // Process properties.
1043         
1044                 CaptureString(&PropertyValue, FALSE);
1045         
1046                 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
1047                 
1048                         PropertyValue.Trim();
1049                         PropertyValue.RemoveLast();
1050                 
1051                 }                               
1052         
1053                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
1054                 
1055                         PropertyValue.Remove(0, 1);
1056                 
1057                 }                               
1058         
1059                 if (PropertyName == wxT("ALTID")){
1061                         AnniversaryAltID = PropertyValue;
1062         
1063                 } else if (PropertyName == wxT("CALSCALE")){
1064         
1065                         AnniversaryCalScale = PropertyValue;
1066         
1067                 } else if (PropertyName != wxT("VALUE")) {
1068         
1069                         // Something else we don't know about so append
1070                         // to the tokens variable.
1071                 
1072                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
1073                 
1074                                 if (FirstToken == TRUE){
1075         
1076                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1077                                         FirstToken = FALSE;
1078         
1079                                 } else {
1080         
1081                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1082         
1083                                 }
1084                                 
1085                         }
1086                         
1087                 }
1089         }       
1091         // Add the data to the variables and form.
1092         
1093         if (AnniversaryText == FALSE){
1094         
1095                 Anniversary = PropertySeg2;
1097         }
1098         
1099         if (!PropertyTokens.IsEmpty()){
1100         
1101                 AnniversaryTokens = PropertyTokens;
1103         }
1107 void SplitValues(wxString *PropertyLine, 
1108         std::map<int,int> *SplitPoints, 
1109         std::map<int,int> *SplitLength, 
1110         int intSize){
1111         
1112         size_t intPropertyLen = PropertyLine->Len();
1113         int intSplitsFound = 0;
1114         int intSplitSize = 0;
1115         int intSplitSeek = 0;
1116         
1117         for (int i = intSize; i <= intPropertyLen; i++){
1119                 intSplitSize++;
1120         
1121                 if (PropertyLine->Mid(i, 1) == wxT(";") &&
1122                     PropertyLine->Mid((i - 1), 1) != wxT("\\")){
1123            
1124                     if (intSplitsFound == 0){
1125             
1126                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
1127           
1128                     } else {
1129            
1130                         SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1131             
1132                     }
1133             
1134                     SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
1135             
1136                     intSplitsFound++;
1137                     intSplitSeek = i;
1138                     intSplitSize = 0;
1139             
1140                 }
1142         }
1144         if (intSplitsFound == 0){
1146                 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
1147                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1149         } else {
1151                 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
1152                 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1154         }
1158 void CheckType(wxString *PropertySeg1, 
1159         std::map<int,int> *SplitPoints, 
1160         std::map<int,int> *SplitLength, 
1161         int *intPrevValue, 
1162         PropertyType *PropType){
1163         
1164         wxString PropertyData;
1165         wxString PropertyName;
1166         wxString PropertyValue;
1167         std::map<int,int>::iterator SLiter;
1168         
1169         for (std::map<int, int>::iterator intiter = SplitPoints->begin(); 
1170         intiter != SplitPoints->end(); ++intiter){
1171         
1172                 SLiter = SplitLength->find(intiter->first);
1173         
1174                 PropertyData = PropertySeg1->Mid(*intPrevValue, (SLiter->second));
1175                 
1176                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1177                 PropertyName = PropertyElement.GetNextToken();                          
1178                 PropertyValue = PropertyElement.GetNextToken();
1179                 
1180                 *intPrevValue = intiter->second;
1181                 
1182                 if (PropertyName == wxT("TYPE")){
1183                                 
1184                         if (PropertyValue == wxT("work")){
1185                         
1186                                 *PropType = PROPERTY_WORK;
1187                                                         
1188                         } else if (PropertyValue == wxT("home")){
1190                                 *PropType = PROPERTY_HOME;
1191                                                         
1192                         } else {
1193                         
1194                                 *PropType = PROPERTY_NONE;
1195                         
1196                         }
1197                 
1198                         return;
1199                 
1200                 }
1201         
1202         }
1203         
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