1 // frmContactEditor-LoadGeo.cpp - frmContactEditor load geoposition subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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;
33 bool FirstToken = TRUE;
34 int intSplitsFound = 0;
41 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
45 // Look for type before continuing.
47 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
48 intiter != SplitPoints.end(); ++intiter){
50 SLiter = SplitLength.find(intiter->first);
52 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
54 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
55 PropertyName = PropertyElement.GetNextToken();
56 PropertyValue = PropertyElement.GetNextToken();
58 intPrevValue = intiter->second;
60 if (PropertyName == wxT("TYPE")){
62 if (PropertyValue == wxT("work")){
66 } else if (PropertyValue == wxT("home")){
80 // Setup blank lines for later on.
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){
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("")));
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("")));
110 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
111 intiter != SplitPoints.end(); ++intiter){
113 SLiter = SplitLength.find(intiter->first);
115 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
117 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
118 PropertyName = PropertyElement.GetNextToken();
119 PropertyValue = PropertyElement.GetNextToken();
121 intPrevValue = intiter->second;
123 // Process properties.
125 size_t intPropertyValueLen = PropertyValue.Len();
127 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
129 PropertyValue.Trim();
130 PropertyValue.RemoveLast();
134 if (PropertyValue.Mid(0, 1) == wxT("\"")){
136 PropertyValue.Remove(0, 1);
140 ProcessCaptureStrings(&PropertyValue);
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)); }
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)); }
154 } else if (PropertyName == wxT("MEDIATYPE")){
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)); }
160 } else if (PropertyName == wxT("PREF")){
162 intPref = wxAtoi(PropertyValue);
164 if (intPref > 0 && intPref < 101){
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)); }
174 // Something else we don't know about so append
175 // to the tokens variable.
177 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
179 if (FirstToken == TRUE){
181 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
186 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
196 // Split the address.
198 //std::map<int, int>::iterator SLiter;
199 intPropertyLen = wxSPropertySeg2.Len();
206 for (int i = 0; i <= intPropertyLen; i++){
210 if (wxSPropertySeg2.Mid(i, 1) == wxT(":") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
213 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
215 if (intSplitsFound == 1){
217 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
228 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
229 intiter != SplitPoints.end(); ++intiter){
231 if (intiter->first == 1){
235 SLiter = SplitLength.find(1);
237 //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE));
238 GeoType = wxSPropertySeg2.Mid(0, SLiter->second);
239 intPrevValue = intiter->second;
241 GeoData = wxSPropertySeg2.Mid(intPrevValue);
247 ProcessCaptureStrings(&wxSPropertySeg2);
251 coldata.SetId(intValueSeek);
252 coldata.SetData(intValueSeek);
259 ListCtrlIndex = lboTimezones->InsertItem(coldata);
261 if (intPref > 0 && intPref < 101){
263 lboTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
269 txtGeopositioning->SetValue(GeoData);
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));
279 CaptureString(&GeoData, FALSE);
280 coldata.SetText(GeoData);
281 ListCtrlIndex = lboGeoposition->InsertItem(coldata);
283 if (intPref > 0 && intPref < 101){
285 lboGeoposition->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
289 } else if (intType == 1){
293 ListCtrlIndex = lboHomeTimezones->InsertItem(coldata);
295 if (intPref > 0 && intPref < 101){
297 lboHomeTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
304 txtHomeGeopositioning->SetValue(GeoData);
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));
314 CaptureString(&GeoData, FALSE);
315 coldata.SetText(GeoData);
316 ListCtrlIndex = lboHomeGeoposition->InsertItem(coldata);
318 if (intPref > 0 && intPref < 101){
320 lboHomeGeoposition->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
324 } else if (intType == 2){
326 ListCtrlIndex = lboBusinessGeoposition->InsertItem(coldata);
330 ListCtrlIndex = lboBusinessTimezones->InsertItem(coldata);
332 if (intPref > 0 && intPref < 101){
334 lboBusinessTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
341 txtBusinessGeopositioning->SetValue(GeoData);
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));
351 CaptureString(&GeoData, FALSE);
352 coldata.SetText(GeoData);
353 ListCtrlIndex = lboBusinessGeoposition->InsertItem(coldata);
355 if (intPref > 0 && intPref < 101){
357 lboBusinessGeoposition->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));