Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed commented out form code from ADR in ContactDataObject.
[xestiaab/.git] / source / contacteditor / frmContactEditor-LoadGeo.cpp
1 // frmContactEditor-LoadGeo.cpp - frmContactEditor load geoposition 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::LoadGeo(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *GeoCount){
23         size_t intPropertyLen = wxSPropertySeg1.Len();
24         std::map<int, int> SplitPoints;
25         std::map<int, int> SplitLength;
26         std::map<int, int>::iterator SLiter;                    
27         wxString PropertyData;
28         wxString PropertyName;
29         wxString PropertyValue;
30         wxString PropertyTokens;
31         wxString GeoType;
32         wxString GeoData;
33         bool FirstToken = TRUE;                 
34         int intSplitsFound = 0;
35         int intSplitSize = 0;
36         int intPrevValue = 5;
37         int intPref = 0;                        
38         int intType = 0;
39         long ListCtrlIndex;
40         
41         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
42         
43         intPrevValue = 4;
44         
45         // Look for type before continuing.
46         
47         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
48         intiter != SplitPoints.end(); ++intiter){
49         
50                 SLiter = SplitLength.find(intiter->first);
51         
52                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
53                 
54                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
55                 PropertyName = PropertyElement.GetNextToken();                          
56                 PropertyValue = PropertyElement.GetNextToken();
57                 
58                 intPrevValue = intiter->second;
59                 
60                 if (PropertyName == wxT("TYPE")){
61                 
62                         if (PropertyValue == wxT("work")){
63                         
64                                 intType = 2;                                    
65                         
66                         } else if (PropertyValue == wxT("home")){
68                                 intType = 1;
69                         
70                         } else {
71                         
72                                 intType = 0;
73                         
74                         }
75                 
76                 }
77         
78         }
79         
80         // Setup blank lines for later on.
81         
82         if (intType == 0){
83         
84                 GeneralGeographyList.insert(std::make_pair(intValueSeek, wxT("")));
85                 GeneralGeographyListAltID.insert(std::make_pair(intValueSeek, wxT("")));
86                 GeneralGeographyListPID.insert(std::make_pair(intValueSeek, wxT("")));
87                 GeneralGeographyListPref.insert(std::make_pair(intValueSeek, 0));
88                 GeneralGeographyListTokens.insert(std::make_pair(intValueSeek, wxT("")));
90         } else if (intType == 1){
91         
92                 HomeGeographyList.insert(std::make_pair(intValueSeek, wxT("")));
93                 HomeGeographyListAltID.insert(std::make_pair(intValueSeek, wxT("")));
94                 HomeGeographyListPID.insert(std::make_pair(intValueSeek, wxT("")));
95                 HomeGeographyListPref.insert(std::make_pair(intValueSeek, 0));
96                 HomeGeographyListTokens.insert(std::make_pair(intValueSeek, wxT("")));
97         
98         } else if (intType == 2){
100                 BusinessGeographyList.insert(std::make_pair(intValueSeek, wxT("")));
101                 BusinessGeographyListAltID.insert(std::make_pair(intValueSeek, wxT("")));
102                 BusinessGeographyListPID.insert(std::make_pair(intValueSeek, wxT("")));
103                 BusinessGeographyListPref.insert(std::make_pair(intValueSeek, 0));
104                 BusinessGeographyListTokens.insert(std::make_pair(intValueSeek, wxT("")));
105         
106         }
107         
108         intPrevValue = 4;                       
109         
110         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
111         intiter != SplitPoints.end(); ++intiter){
112         
113                 SLiter = SplitLength.find(intiter->first);
114         
115                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
116                 
117                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
118                 PropertyName = PropertyElement.GetNextToken();                          
119                 PropertyValue = PropertyElement.GetNextToken();
120                 
121                 intPrevValue = intiter->second;
122                 
123                 // Process properties.
124                 
125                 size_t intPropertyValueLen = PropertyValue.Len();
126                 
127                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
128                         
129                         PropertyValue.Trim();
130                         PropertyValue.RemoveLast();
131                         
132                 }                               
133                 
134                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
135                         
136                         PropertyValue.Remove(0, 1);
137                         
138                 }       
140                 ProcessCaptureStrings(&PropertyValue);
141                 
142                 if (PropertyName == wxT("ALTID")){
144                         if (intType == 0){ GeneralGeographyListAltID.erase(intValueSeek); GeneralGeographyListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
145                         else if (intType == 1){ HomeGeographyListAltID.erase(intValueSeek); HomeGeographyListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
146                         else if (intType == 2){ BusinessGeographyListAltID.erase(intValueSeek); BusinessGeographyListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
147                 
148                 } else if (PropertyName == wxT("PID")){
150                         if (intType == 0){ GeneralGeographyListPID.erase(intValueSeek); GeneralGeographyListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
151                         else if (intType == 1){ HomeGeographyListPID.erase(intValueSeek); HomeGeographyListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
152                         else if (intType == 2){ BusinessGeographyListPID.erase(intValueSeek); BusinessGeographyListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
153                 
154                 } else if (PropertyName == wxT("MEDIATYPE")){
155                 
156                         if (intType == 0){ GeneralGeographyListMediatype.erase(intValueSeek); GeneralGeographyListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
157                         else if (intType == 1){ HomeGeographyListMediatype.erase(intValueSeek); HomeGeographyListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
158                         else if (intType == 2){ BusinessGeographyListMediatype.erase(intValueSeek); BusinessGeographyListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
159                 
160                 } else if (PropertyName == wxT("PREF")){
161                         
162                         intPref = wxAtoi(PropertyValue);
163                 
164                         if (intPref > 0 && intPref < 101){
165                 
166                                 if (intType == 0){ GeneralGeographyListPref.erase(intValueSeek); GeneralGeographyListPref.insert(std::make_pair(intValueSeek, intPref)); }
167                                 else if (intType == 1){ HomeGeographyListPref.erase(intValueSeek); HomeGeographyListPref.insert(std::make_pair(intValueSeek, intPref)); }
168                                 else if (intType == 2){ BusinessGeographyListPref.erase(intValueSeek); BusinessGeographyListPref.insert(std::make_pair(intValueSeek, intPref)); }
169                         
170                         }
171                 
172                 } else {
173                 
174                         // Something else we don't know about so append
175                         // to the tokens variable.
176                 
177                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
178                 
179                                 if (FirstToken == TRUE){
180                         
181                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
182                                         FirstToken = FALSE;
183                         
184                                 } else {
185                         
186                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
187                         
188                                 }
189                 
190                         }
191                 
192                 }
193         
194         }                                       
195         
196         // Split the address. 
198         //std::map<int, int>::iterator SLiter;
199         intPropertyLen = wxSPropertySeg2.Len();
200         SplitPoints.clear();
201         SplitLength.clear();
202         intSplitsFound = 0;
203         intSplitSize = 0;
204         intPrevValue = 0;
205         
206         for (int i = 0; i <= intPropertyLen; i++){
208                 intSplitSize++;
209         
210                 if (wxSPropertySeg2.Mid(i, 1) == wxT(":") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
211         
212                         intSplitsFound++;
213                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
214                         
215                         if (intSplitsFound == 1){ 
216                         
217                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
218                                 break; 
219                                 
220                         }
221                         
222                         intSplitSize = 0;                                       
223         
224                 }
226         }                       
227         
228         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
229         intiter != SplitPoints.end(); ++intiter){
230         
231                 if (intiter->first == 1){
232                 
233                         // Deal with PO Box.
234                         
235                         SLiter = SplitLength.find(1);
236                                                                 
237                         //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
238                         GeoType = wxSPropertySeg2.Mid(0, SLiter->second);
239                         intPrevValue = intiter->second;
240                         
241                         GeoData = wxSPropertySeg2.Mid(intPrevValue);                                    
242                 
243                 }
244         
245         }
246         
247         ProcessCaptureStrings(&wxSPropertySeg2);
248         
249         wxListItem coldata;
251         coldata.SetId(intValueSeek);
252         coldata.SetData(intValueSeek);
254         
255         if (intType == 0){
256         
257                 /*
258         
259                 ListCtrlIndex = lboTimezones->InsertItem(coldata);
260                 
261                 if (intPref > 0 && intPref < 101){
262                 
263                         lboTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
264                         
265                 }
266                 
267                 */
268                 /*
269                 txtGeopositioning->SetValue(GeoData);
270                 */
271                 
272                 GeneralGeographyList.erase(intValueSeek);
273                 GeneralGeographyListType.erase(intValueSeek);
274                 GeneralGeographyListTokens.erase(intValueSeek);
275                 GeneralGeographyList.insert(std::make_pair(intValueSeek, GeoData));
276                 GeneralGeographyListType.insert(std::make_pair(intValueSeek, wxT("")));
277                 GeneralGeographyListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
278                 
279                 CaptureString(&GeoData, FALSE);
280                 coldata.SetText(GeoData);
281                 ListCtrlIndex = lboGeoposition->InsertItem(coldata);
282                 
283                 if (intPref > 0 && intPref < 101){
284                 
285                         lboGeoposition->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
286                         
287                 }
288         
289         } else if (intType == 1){                       
290         
291                 /*
292         
293                 ListCtrlIndex = lboHomeTimezones->InsertItem(coldata);
295                 if (intPref > 0 && intPref < 101){
296                 
297                         lboHomeTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
298                         
299                 }
300                 
301                 */
302                 
303                 /*
304                 txtHomeGeopositioning->SetValue(GeoData);
305                 */
307                 HomeGeographyList.erase(intValueSeek);
308                 HomeGeographyListType.erase(intValueSeek);
309                 HomeGeographyListTokens.erase(intValueSeek);                            
310                 HomeGeographyList.insert(std::make_pair(intValueSeek, GeoData));
311                 HomeGeographyListType.insert(std::make_pair(intValueSeek, wxT("home")));
312                 HomeGeographyListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
313                 
314                 CaptureString(&GeoData, FALSE);
315                 coldata.SetText(GeoData);
316                 ListCtrlIndex = lboHomeGeoposition->InsertItem(coldata);
317                 
318                 if (intPref > 0 && intPref < 101){
319                 
320                         lboHomeGeoposition->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
321                         
322                 }
323         
324         } else if (intType == 2){ 
325         
326                 ListCtrlIndex = lboBusinessGeoposition->InsertItem(coldata);                    
327         
328                 /*
329         
330                 ListCtrlIndex = lboBusinessTimezones->InsertItem(coldata);
332                 if (intPref > 0 && intPref < 101){
333                 
334                         lboBusinessTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
335                         
336                 }
337                 
338                 */
339                 
340                 /*
341                 txtBusinessGeopositioning->SetValue(GeoData);
342                 */
344                 BusinessGeographyList.erase(intValueSeek);
345                 BusinessGeographyListType.erase(intValueSeek);
346                 BusinessGeographyListTokens.erase(intValueSeek);                                
347                 BusinessGeographyList.insert(std::make_pair(intValueSeek, GeoData));
348                 BusinessGeographyListType.insert(std::make_pair(intValueSeek, wxT("work")));
349                 BusinessGeographyListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
350                 
351                 CaptureString(&GeoData, FALSE);
352                 coldata.SetText(GeoData);
353                 ListCtrlIndex = lboBusinessGeoposition->InsertItem(coldata);
354                 
355                 if (intPref > 0 && intPref < 101){
356                 
357                         lboBusinessGeoposition->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
358                         
359                 }
360         
361         }
362         
363         GeoCount++;
364         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