Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Using ContactDataObject for N.
[xestiaab/.git] / source / contacteditor / frmContactEditor-LoadName.cpp
1 // frmContactEditor-LoadName.cpp - frmContactEditor load name subroutines.
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 "frmContactEditor.h"
21 void frmContactEditor::LoadFN(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *FNCount, 
22         bool *FNProcessed, vCard *ContactData){
23         
24         size_t intPropertyLen = wxSPropertySeg1.Len();
25         std::map<int, int> SplitPoints;
26         std::map<int, int> SplitLength;
27         std::map<int, int>::iterator SLiter;                    
28         wxString PropertyData;
29         wxString PropertyName;
30         wxString PropertyValue;
31         wxString PropertyTokens;
32         bool FirstToken = TRUE;                 
33         int intSplitsFound = 0;
34         int intSplitSize = 0;
35         int intPrevValue = 4;
36         int intPref = 0;                        
37         int intType = 0;
38         
39         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
40         
41         intPrevValue = 3;
42         
43         // Look for type before continuing.             
44         
45         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
46         intiter != SplitPoints.end(); ++intiter){
47         
48                 SLiter = SplitLength.find(intiter->first);
49         
50                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
51                 
52                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
53                 PropertyName = PropertyElement.GetNextToken();                          
54                 PropertyValue = PropertyElement.GetNextToken();
55                 
56                 intPrevValue = intiter->second;
57                 
58                 if (PropertyName == wxT("TYPE")){
59                 
60                         if (PropertyValue == wxT("work")){
61                         
62                                 intType = 2;                                    
63                         
64                         } else if (PropertyValue == wxT("home")){
66                                 intType = 1;
67                         
68                         } else {
69                         
70                                 intType = 0;
71                         
72                         }
73                 
74                 }
75         
76         }
77         
78         // Setup blank lines for later on.
80         FullNamesList.insert(std::make_pair(intValueSeek, wxT("")));
81         FullNamesListAltID.insert(std::make_pair(intValueSeek, wxT("")));
82         FullNamesListPID.insert(std::make_pair(intValueSeek, wxT("")));
83         FullNamesListPref.insert(std::make_pair(intValueSeek, 0));
84         FullNamesListType.insert(std::make_pair(intValueSeek, wxT("")));
85         FullNamesListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
86         FullNamesListTokens.insert(std::make_pair(intValueSeek, wxT("")));              
87         
88         intPrevValue = 3;
89         
90         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
91         intiter != SplitPoints.end(); ++intiter){
92         
93                 SLiter = SplitLength.find(intiter->first);
94         
95                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
96                 
97                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
98                 PropertyName = PropertyElement.GetNextToken();                          
99                 PropertyValue = PropertyElement.GetNextToken();
100                 
101                 ProcessCaptureStrings(&PropertyValue);
102                 
103                 intPrevValue = intiter->second;
104                 
105                 // Process properties.
106                 
107                 if (PropertyName == wxT("ALTID")){
109                         FullNamesListAltID.erase(intValueSeek); FullNamesListAltID.insert(std::make_pair(intValueSeek, PropertyValue));
110                 
111                 } else if (PropertyName == wxT("PID")){
113                         FullNamesListPID.erase(intValueSeek); FullNamesListPID.insert(std::make_pair(intValueSeek, PropertyValue));
114                 
115                 } else if (PropertyName == wxT("PREF")){
116                         
117                         intPref = wxAtoi(PropertyValue);
118                         
119                         if (intPref > 0 && intPref < 101){
120                 
121                                 FullNamesListPref.erase(intValueSeek); FullNamesListPref.insert(std::make_pair(intValueSeek, intPref));
122                                 
123                         }
124                 
125                 } else if (PropertyName == wxT("LANG")){
127                         FullNamesListLanguage.erase(intValueSeek); FullNamesListLanguage.insert(std::make_pair(intValueSeek, PropertyValue));
128                 
129                 } else {
130                 
131                         // Something else we don't know about so append
132                         // to the tokens variable.
133                         
134                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
135                         
136                                 if (FirstToken == TRUE){
137                                 
138                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
139                                         FirstToken = FALSE;
140                                 
141                                 } else {
142                                 
143                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
144                                 
145                                 }
146                         
147                         }
148                 
149                 }
150         
151         }                       
152         
153         // Split the address.           
155         //std::map<int, int>::iterator SLiter;
156         intPropertyLen = wxSPropertySeg2.Len();
157         SplitPoints.clear();
158         SplitLength.clear();
159         intSplitsFound = 0;
160         intSplitSize = 0;
161         intPrevValue = 0;
162         
163         for (int i = 0; i <= intPropertyLen; i++){
165                 intSplitSize++;
166         
167                 if (wxSPropertySeg2.Mid(i, 1) == wxT(":") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
168         
169                         intSplitsFound++;
170                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
171                         
172                         if (intSplitsFound == 1){ 
173                         
174                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
175                                 break; 
176                                 
177                         }
178                         
179                         intSplitSize = 0;                                       
180         
181                 }
183         }                       
184         
185         // Add the data to the General/Home/Work address variables.
186         
187         /*
188         
189         wxListItem coldata;
191         coldata.SetId(intValueSeek);
192         coldata.SetData(intValueSeek);
193         coldata.SetText(IMPPType);
194         
195         */
196         
197         //ProcessCaptureStrings(wxsPropertySeg2);
198         
199         ProcessCaptureStrings(&wxSPropertySeg2);
200         
201         FullNamesList.erase(intValueSeek);
202         FullNamesListType.erase(intValueSeek);
203         FullNamesListTokens.erase(intValueSeek);
204         FullNamesList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
205         FullNamesListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
206         
207         if (intType == 0){
208         
209                 FullNamesListType.insert(std::make_pair(intValueSeek, wxT("")));
210         
211         } else if (intType == 1){
212         
213                 FullNamesListType.insert(std::make_pair(intValueSeek, wxT("home")));                    
214         
215         } else if (intType == 2){
216         
217                 FullNamesListType.insert(std::make_pair(intValueSeek, wxT("work")));                    
218         
219         }
220         
221         if (*FNProcessed == FALSE){
222         
223                 NameDisplayAs = wxSPropertySeg2;
224                 cmbDisplayAs->SetValue(ContactData->Convert(wxSPropertySeg2, TRUE));
225                 *FNProcessed = TRUE;
226                 
227         }
228         
229         FNCount++;
230         intValueSeek++;
234 void frmContactEditor::LoadName(wxString *NameTitle, wxString *NameForename,
235         wxString *NameSurname, wxString *NameOtherNames, 
236         wxString *NameSuffix){
238         txtTitle->SetValue(*NameTitle); 
239         txtForename->SetValue(*NameForename);
240         txtSurname->SetValue(*NameSurname);
241         txtOtherNames->SetValue(*NameOtherNames);
242         txtSuffix->SetValue(*NameSuffix);
243         
246 void frmContactEditor::LoadN(wxString wxSPropertySeg1, wxString wxSPropertySeg2, bool *NameProcessed, 
247         vCard *ContactData){
249         size_t intPropertyLen = wxSPropertySeg1.Len();
250         std::map<int, int> SplitPoints;
251         std::map<int, int> SplitLength;
252         std::map<int, int>::iterator SLiter;                    
253         wxString PropertyData;
254         wxString PropertyName;
255         wxString PropertyValue;
256         wxString PropertyTokens;
257         bool FirstToken = TRUE;                 
258         int intSplitsFound = 0;
259         int intSplitSize = 0;
260         int intPrevValue = 3;
261         int intSplitSeek = 0;
262         
263         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
264         
265         // Look for type before continuing.             
266         
267         intPrevValue = 2;                       
268         
269         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
270         intiter != SplitPoints.end(); ++intiter){
271         
272                 SLiter = SplitLength.find(intiter->first);
273         
274                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
275                 
276                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
277                 PropertyName = PropertyElement.GetNextToken();                          
278                 PropertyValue = PropertyElement.GetNextToken();
279                 
280                 intPrevValue = intiter->second;
281         
282         }
283         
284         intPrevValue = 2;
285         
286         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
287         intiter != SplitPoints.end(); ++intiter){
288         
289                 SLiter = SplitLength.find(intiter->first);
290         
291                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
292                 
293                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
294                 PropertyName = PropertyElement.GetNextToken();                          
295                 PropertyValue = PropertyElement.GetNextToken();
296                 
297                 ProcessCaptureStrings(&PropertyValue);
298                 
299                 intPrevValue = intiter->second;
300                 
301                 // Process properties.
302                 
303                 if (PropertyName == wxT("ALTID")){
305                         NameAltID = PropertyValue;
306                 
307                 } else if (PropertyName == wxT("LANG")){
309                         NameLanguage = PropertyValue;
310                 
311                 } else if (PropertyName == wxT("SORT-AS")){
312                 
313                         NameDisplayAs = PropertyValue;
314                 
315                 } else {
316                 
317                         // Something else we don't know about so append
318                         // to the tokens variable.
319                         
320                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
321                         
322                                 if (FirstToken == TRUE){
323                                 
324                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
325                                         FirstToken = FALSE;
326                                 
327                                 } else {
328                                 
329                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
330                                 
331                                 }
332                         
333                         }
334                 
335                 }
336         
337         }
338         
339         intPropertyLen = wxSPropertySeg2.Len();
340         SplitPoints.clear();
341         SplitLength.clear();
342         intSplitSeek = 0;               
343         intSplitsFound = 0;
344         intSplitSize = 0;
345         intPrevValue = 0;                                       
346         
347         for (int i = 0; i <= intPropertyLen; i++){
349                 intSplitSize++;
350         
351                 if (wxSPropertySeg2.Mid(i, 1) == wxT(";") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
352         
353                         intSplitsFound++;
354                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
355                         
356                         if (intSplitsFound == 4){ 
357                         
358                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
359                                 break; 
360                                 
361                         } else {
362                         
363                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
364                         
365                         }
366                         
367                         intSplitSize = 0;                                       
368         
369                 }
371         }
372         
373         // Split the data into several parts.
374                         
375         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
376         intiter != SplitPoints.end(); ++intiter){
377         
378                 if (intiter->first == 1){
379                 
380                         // Deal with family name.
381                         
382                         SLiter = SplitLength.find(1);
383                                                                 
384                         txtSurname->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
385                         
386                         intPrevValue = intiter->second;
387                         NameSurname = wxSPropertySeg2.Mid(0, SLiter->second);                                   
388                 
389                 } else if (intiter->first == 2){
390                 
391                         // Deal with given names.
392                         
393                         SLiter = SplitLength.find(2);
394                                                                 
395                         txtForename->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
396                         intPrevValue = intiter->second;
397                         NameForename = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
398                 
399                 } else if (intiter->first == 3){
400                 
401                         // Deal with additional names.
402                         
403                         SLiter = SplitLength.find(3);
404                                                                 
405                         txtOtherNames->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
406                         intPrevValue = intiter->second;
407                         NameOtherNames = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
408                 
409                 } else if (intiter->first == 4){
410                 
411                         // Deal with honorifix prefixes and suffixes.
413                         SLiter = SplitLength.find(4);
414                                                                 
415                         txtTitle->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE));
416                         intPrevValue = intiter->second;
417                         NameTitle = wxSPropertySeg2.Mid(intPrevValue, SLiter->second);
418                 
419                         txtSuffix->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE));
420                         NameSuffix = wxSPropertySeg2.Mid(intPrevValue);
421                 
422                 }
423         
424         }
425         
426         NameTokens = PropertyTokens;
427         *NameProcessed = TRUE;
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