Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Split frmContactEditor-Load.cpp into 24 files to make it more manageable.
[xestiaab/.git] / source / contacteditor / frmContactEditor-LoadTelephone.cpp
1 #include "frmContactEditor.h"
3 void frmContactEditor::LoadTelephone(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *TelCount){
5         // Check TEL and make sure it is functioning properly.
7         size_t intPropertyLen = wxSPropertySeg1.Len();
8         std::map<int, int> SplitPoints;
9         std::map<int, int> SplitLength;
10         std::map<int, int> TypeSplitPoints;
11         std::map<int, int> TypeSplitLength;
12         std::map<int, int>::iterator SLiter;
13         std::map<int, int>::iterator SPoint;                    
14         std::map<int, int>::iterator TSLiter;
15         std::map<int, int>::iterator TSPoint;
16         wxString PropertyData;
17         wxString PropertyName;
18         wxString PropertyValue;
19         wxString PropertyTokens;
20         wxString TelType;
21         wxString TelNumber;
22         wxString TelTypeUI;
23         wxString TelTypeDetail;
24         bool FirstToken = TRUE;
25         int intSplitsFound = 0;
26         int intSplitSize = 0;
27         int intPrevValue = 5;
28         int intPref = 0;                        
29         int intType = 0;
30         int intSplitPoint = 0;
31         long ListCtrlIndex;
32         
33         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
34         
35         intPrevValue = 4;
36         
37         // Look for type before continuing.
38         
39         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
40         intiter != SplitPoints.end(); ++intiter){
41         
42                 SLiter = SplitLength.find(intiter->first);
43         
44                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
45                 
46                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
47                 PropertyName = PropertyElement.GetNextToken();                          
48                 PropertyValue = PropertyElement.GetNextToken();
49                 
50                 intPrevValue = intiter->second;
51                 
52                 if (PropertyName == wxT("TYPE")){
53                 
54                         // Process each value in type and translate each
55                         // part.
56                 
57                         // Strip out the quotes if they are there.
58                 
59                         size_t intPropertyValueLen = PropertyValue.Len();
60                 
61                         if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
62                         
63                                 PropertyValue.Trim();
64                                 PropertyValue.RemoveLast();
65                         
66                         }                               
67                 
68                         if (PropertyValue.Mid(0, 1) == wxT("\"")){
69                         
70                                 PropertyValue.Remove(0, 1);
71                         
72                         }
73                         
74                         TelTypeDetail = PropertyValue;
75                         
76                         intSplitSize = 0;
77                         intSplitsFound = 0;
78                         intSplitPoint = 0;
79                         
80                         for (int i = 0; i <= intPropertyValueLen; i++){
81         
82                                 intSplitSize++;
83         
84                                 if (PropertyValue.Mid(i, 1) == wxT(",") && PropertyValue.Mid((i - 1), 1) != wxT("\\")){
85         
86                                         if (intSplitsFound == 0){
88                                                 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
89                                                 TypeSplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
90                         
91                                         } else {
92                         
93                                                 TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
94                                                 TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
95                         
96                                         }                       
98                                         intSplitsFound++;
99                                         i++;
100                                         intSplitPoint = i;
101                                         intSplitSize = 0;
102         
103                                 }
104         
105                         }
106                         
107                         TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
108                         TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));                                                           
109                 
110                         int intTypeSeek = 0;
111                 
112                         for (std::map<int, int>::iterator typeiter = TypeSplitPoints.begin(); 
113                         typeiter != TypeSplitPoints.end(); ++typeiter){
114                         
115                                 wxString TypePropertyName;
116                                 
117                                 TSLiter = TypeSplitLength.find(typeiter->first);
118                                 
119                                 TypePropertyName = PropertyValue.Mid(typeiter->second, TSLiter->second);
120                                 
121                                 if (intTypeSeek == 0){
122                                 
123                                 
124                                 } else {
125                                                                                 
126                                         TelTypeUI.Append(wxT(","));                                                     
127                                 
128                                 }
129                         
130                                 if (TypePropertyName == wxT("home")){
131                                 
132                                         intType = 1;
133                                 
134                                 } else if (TypePropertyName == wxT("work")){
135                                 
136                                         intType = 2;
137                                 
138                                 }
139                                 
140                                 
141                                 if (TypePropertyName == wxT("text")){
142                                 
143                                         TelTypeUI.Append(_("text"));
144                                         intTypeSeek++;
145                                 
146                                 } else if (TypePropertyName == wxT("voice")){
147                                 
148                                         TelTypeUI.Append(_("voice"));
149                                         intTypeSeek++;
150                                 
151                                 } else if (TypePropertyName == wxT("fax")){
152                                 
153                                         TelTypeUI.Append(_("fax"));
154                                         intTypeSeek++;
155                                 
156                                 } else if (TypePropertyName == wxT("cell")){
157                                 
158                                         TelTypeUI.Append(_("mobile"));
159                                         intTypeSeek++;
160                                 
161                                 } else if (TypePropertyName == wxT("video")){
162                                 
163                                         TelTypeUI.Append(_("video"));
164                                         intTypeSeek++;
165                                 
166                                 } else if (TypePropertyName == wxT("pager")){
167                                 
168                                         TelTypeUI.Append(_("pager"));
169                                         intTypeSeek++;
170                                 
171                                 } else if (TypePropertyName == wxT("textphone")){
172                                 
173                                         TelTypeUI.Append(_("textphone"));
174                                         intTypeSeek++;
175                                 
176                                 }
177                         
178                         }
179                 
180                 }
181                 
182                 
183         
184         }
185         
186         // Setup blank lines for later on.
187         
188         if (intType == 0){
189         
190                 GeneralTelephoneList.insert(std::make_pair(intValueSeek, wxT("")));
191                 GeneralTelephoneListAltID.insert(std::make_pair(intValueSeek, wxT("")));
192                 GeneralTelephoneListPID.insert(std::make_pair(intValueSeek, wxT("")));
193                 GeneralTelephoneListPref.insert(std::make_pair(intValueSeek, 0));
194                 GeneralTelephoneListTokens.insert(std::make_pair(intValueSeek, wxT("")));
196         } else if (intType == 1){
197         
198                 HomeTelephoneList.insert(std::make_pair(intValueSeek, wxT("")));
199                 HomeTelephoneListAltID.insert(std::make_pair(intValueSeek, wxT("")));
200                 HomeTelephoneListPID.insert(std::make_pair(intValueSeek, wxT("")));
201                 HomeTelephoneListPref.insert(std::make_pair(intValueSeek, 0));
202                 HomeTelephoneListTokens.insert(std::make_pair(intValueSeek, wxT("")));
203         
204         } else if (intType == 2){
206                 BusinessTelephoneList.insert(std::make_pair(intValueSeek, wxT("")));
207                 BusinessTelephoneListAltID.insert(std::make_pair(intValueSeek, wxT("")));
208                 BusinessTelephoneListPID.insert(std::make_pair(intValueSeek, wxT("")));
209                 BusinessTelephoneListPref.insert(std::make_pair(intValueSeek, 0));
210                 BusinessTelephoneListTokens.insert(std::make_pair(intValueSeek, wxT("")));
211         
212         }
213         
214         intPrevValue = 4;
215         
216         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
217         intiter != SplitPoints.end(); ++intiter){
218         
219                 SLiter = SplitLength.find(intiter->first);
220         
221                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
222                 
223                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
224                 PropertyName = PropertyElement.GetNextToken();                          
225                 PropertyValue = PropertyElement.GetNextToken();
226                 
227                 intPrevValue = intiter->second;
228                 
229                 size_t intPropertyValueLen = PropertyValue.Len();
230                 
231                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
232                         
233                         PropertyValue.Trim();
234                         PropertyValue.RemoveLast();
235                         
236                 }                               
237                 
238                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
239                         
240                         PropertyValue.Remove(0, 1);
241                         
242                 }                               
243                 
244                 ProcessCaptureStrings(&PropertyValue);
245                 
246                 // Process properties.
247                 
248                 if (PropertyName == wxT("ALTID")){
250                         if (intType == 0){ GeneralTelephoneListAltID.erase(intValueSeek); GeneralTelephoneListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
251                         else if (intType == 1){ HomeTelephoneListAltID.erase(intValueSeek); HomeTelephoneListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
252                         else if (intType == 2){ BusinessTelephoneListAltID.erase(intValueSeek); BusinessTelephoneListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
253                 
254                 } else if (PropertyName == wxT("PID")){
256                         if (intType == 0){ GeneralTelephoneListPID.erase(intValueSeek); GeneralTelephoneListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
257                         else if (intType == 1){ HomeTelephoneListPID.erase(intValueSeek); HomeTelephoneListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
258                         else if (intType == 2){ BusinessTelephoneListPID.erase(intValueSeek); BusinessTelephoneListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
259                 
260                 } else if (PropertyName == wxT("PREF")){
261                         
262                         intPref = wxAtoi(PropertyValue);
263                         
264                         if (intPref > 0 && intPref < 101){
265                 
266                                 if (intType == 0){ GeneralTelephoneListPref.erase(intValueSeek); GeneralTelephoneListPref.insert(std::make_pair(intValueSeek, intPref)); }
267                                 else if (intType == 1){ HomeTelephoneListPref.erase(intValueSeek); HomeTelephoneListPref.insert(std::make_pair(intValueSeek, intPref)); }
268                                 else if (intType == 2){ BusinessTelephoneListPref.erase(intValueSeek); BusinessTelephoneListPref.insert(std::make_pair(intValueSeek, intPref)); }
269                                 
270                         }
271                 
272                 } else {
273                 
274                         // Something else we don't know about so append
275                         // to the tokens variable.
276                         
277                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
278                         
279                                 if (FirstToken == TRUE){
280                                 
281                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
282                                         FirstToken = FALSE;
283                                 
284                                 } else {
285                                 
286                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
287                                 
288                                 }
289                         
290                         }
291                 
292                 }
293         
294         }                       
295         
296         // Split the address. 
298         //std::map<int, int>::iterator SLiter;
299         intPropertyLen = wxSPropertySeg2.Len();
300         SplitPoints.clear();
301         SplitLength.clear();
302         intSplitsFound = 0;
303         intSplitSize = 0;
304         intPrevValue = 0;
305         
306         for (int i = 0; i <= intPropertyLen; i++){
308                 intSplitSize++;
309         
310                 if (wxSPropertySeg2.Mid(i, 1) == wxT(":") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
311         
312                         intSplitsFound++;
313                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
314                         
315                         if (intSplitsFound == 1){ 
316                         
317                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
318                                 break; 
319                                 
320                         }
321                         
322                         intSplitSize = 0;                                       
323         
324                 }
326         }
327         
328         // Split the data into several parts.                   
329         
330         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
331         intiter != SplitPoints.end(); ++intiter){
332         
333                 if (intiter->first == 1){
334                 
335                         // Deal with PO Box.
336                         
337                         SLiter = SplitLength.find(1);
338                                                                 
339                         //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
340                         TelType = wxSPropertySeg2.Mid(0, SLiter->second);
341                         intPrevValue = intiter->second;
342                         
343                         TelNumber = wxSPropertySeg2.Mid(intPrevValue);                                  
344                 
345                 }
346         
347         }                       
348         
349         // Add the data to the General/Home/Work address variables.
350         
351         ProcessCaptureStrings(&PropertyValue);
352         wxListItem coldata;
354         coldata.SetId(intValueSeek);
355         coldata.SetData(intValueSeek);
356         coldata.SetText(TelNumber);
357         
358         if (intType == 0){
359         
360                 ListCtrlIndex = lboTelephone->InsertItem(coldata);
361                 
362                 lboTelephone->SetItem(ListCtrlIndex, 1, TelTypeUI);
363                 
364                 if (intPref > 0 && intPref < 101){
365                 
366                         lboTelephone->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
367                         
368                 }                               
369                 
370                 GeneralTelephoneList.erase(intValueSeek);
371                 GeneralTelephoneListType.erase(intValueSeek);
372                 GeneralTelephoneListTokens.erase(intValueSeek);
373                 GeneralTelephoneList.insert(std::make_pair(intValueSeek, TelNumber));
374                 GeneralTelephoneListType.insert(std::make_pair(intValueSeek, TelTypeDetail));
375                 GeneralTelephoneListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
376         
377         } else if (intType == 1){ 
378         
379                 ListCtrlIndex = lboHomeTelephone->InsertItem(coldata);
381                 lboHomeTelephone->SetItem(ListCtrlIndex, 1, TelTypeUI);
383                 if (intPref > 0 && intPref < 101){
384                 
385                         lboHomeTelephone->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
386                         
387                 }
389                 HomeTelephoneList.erase(intValueSeek);
390                 HomeTelephoneListType.erase(intValueSeek);
391                 HomeTelephoneListTokens.erase(intValueSeek);                            
392                 HomeTelephoneList.insert(std::make_pair(intValueSeek, TelNumber));
393                 HomeTelephoneListType.insert(std::make_pair(intValueSeek, TelTypeDetail));
394                 HomeTelephoneListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
395         
396         } else if (intType == 2){ 
397         
398                 ListCtrlIndex = lboBusinessTelephone->InsertItem(coldata);
400                 lboBusinessTelephone->SetItem(ListCtrlIndex, 1, TelTypeUI);
402                 if (intPref > 0 && intPref < 101){
403                 
404                         lboBusinessTelephone->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
405                         
406                 }
408                 BusinessTelephoneList.erase(intValueSeek);
409                 BusinessTelephoneListType.erase(intValueSeek);
410                 BusinessTelephoneListTokens.erase(intValueSeek);                                
411                 BusinessTelephoneList.insert(std::make_pair(intValueSeek, TelNumber));
412                 BusinessTelephoneListType.insert(std::make_pair(intValueSeek, TelTypeDetail));
413                 BusinessTelephoneListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));                               
414         
415         }
416         
417         TelCount++;
418         intValueSeek++;
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