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