// frmContactEditor-LoadGeo.cpp - frmContactEditor load geoposition subroutines. // // (c) 2012-2015 Xestia Software Development. // // This file is part of Xestia Address Book. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Address Book. If not, see #include "frmContactEditor.h" void frmContactEditor::LoadGeo(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *GeoCount){ size_t intPropertyLen = wxSPropertySeg1.Len(); std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; wxString GeoType; wxString GeoData; bool FirstToken = TRUE; int intSplitsFound = 0; int intSplitSize = 0; int intPrevValue = 5; int intPref = 0; int intType = 0; long ListCtrlIndex; SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue); intPrevValue = 4; // Look for type before continuing. for (std::map::iterator intiter = SplitPoints.begin(); intiter != SplitPoints.end(); ++intiter){ SLiter = SplitLength.find(intiter->first); PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second)); wxStringTokenizer PropertyElement (PropertyData, wxT("=")); PropertyName = PropertyElement.GetNextToken(); PropertyValue = PropertyElement.GetNextToken(); intPrevValue = intiter->second; if (PropertyName == wxT("TYPE")){ if (PropertyValue == wxT("work")){ intType = 2; } else if (PropertyValue == wxT("home")){ intType = 1; } else { intType = 0; } } } // Setup blank lines for later on. if (intType == 0){ GeneralGeographyList.insert(std::make_pair(intValueSeek, wxT(""))); GeneralGeographyListAltID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralGeographyListPID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralGeographyListPref.insert(std::make_pair(intValueSeek, 0)); GeneralGeographyListTokens.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 1){ HomeGeographyList.insert(std::make_pair(intValueSeek, wxT(""))); HomeGeographyListAltID.insert(std::make_pair(intValueSeek, wxT(""))); HomeGeographyListPID.insert(std::make_pair(intValueSeek, wxT(""))); HomeGeographyListPref.insert(std::make_pair(intValueSeek, 0)); HomeGeographyListTokens.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 2){ BusinessGeographyList.insert(std::make_pair(intValueSeek, wxT(""))); BusinessGeographyListAltID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessGeographyListPID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessGeographyListPref.insert(std::make_pair(intValueSeek, 0)); BusinessGeographyListTokens.insert(std::make_pair(intValueSeek, wxT(""))); } intPrevValue = 4; for (std::map::iterator intiter = SplitPoints.begin(); intiter != SplitPoints.end(); ++intiter){ SLiter = SplitLength.find(intiter->first); PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second)); wxStringTokenizer PropertyElement (PropertyData, wxT("=")); PropertyName = PropertyElement.GetNextToken(); PropertyValue = PropertyElement.GetNextToken(); intPrevValue = intiter->second; // Process properties. size_t intPropertyValueLen = PropertyValue.Len(); if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){ PropertyValue.Trim(); PropertyValue.RemoveLast(); } if (PropertyValue.Mid(0, 1) == wxT("\"")){ PropertyValue.Remove(0, 1); } ProcessCaptureStrings(&PropertyValue); if (PropertyName == wxT("ALTID")){ if (intType == 0){ GeneralGeographyListAltID.erase(intValueSeek); GeneralGeographyListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeGeographyListAltID.erase(intValueSeek); HomeGeographyListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessGeographyListAltID.erase(intValueSeek); BusinessGeographyListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PID")){ if (intType == 0){ GeneralGeographyListPID.erase(intValueSeek); GeneralGeographyListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeGeographyListPID.erase(intValueSeek); HomeGeographyListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessGeographyListPID.erase(intValueSeek); BusinessGeographyListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("MEDIATYPE")){ if (intType == 0){ GeneralGeographyListMediatype.erase(intValueSeek); GeneralGeographyListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeGeographyListMediatype.erase(intValueSeek); HomeGeographyListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessGeographyListMediatype.erase(intValueSeek); BusinessGeographyListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); if (intPref > 0 && intPref < 101){ if (intType == 0){ GeneralGeographyListPref.erase(intValueSeek); GeneralGeographyListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 1){ HomeGeographyListPref.erase(intValueSeek); HomeGeographyListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 2){ BusinessGeographyListPref.erase(intValueSeek); BusinessGeographyListPref.insert(std::make_pair(intValueSeek, intPref)); } } } else { // Something else we don't know about so append // to the tokens variable. if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){ if (FirstToken == TRUE){ PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue); FirstToken = FALSE; } else { PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue); } } } } // Split the address. //std::map::iterator SLiter; intPropertyLen = wxSPropertySeg2.Len(); SplitPoints.clear(); SplitLength.clear(); intSplitsFound = 0; intSplitSize = 0; intPrevValue = 0; for (int i = 0; i <= intPropertyLen; i++){ intSplitSize++; if (wxSPropertySeg2.Mid(i, 1) == wxT(":") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){ intSplitsFound++; SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1))); if (intSplitsFound == 1){ SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1))); break; } intSplitSize = 0; } } for (std::map::iterator intiter = SplitPoints.begin(); intiter != SplitPoints.end(); ++intiter){ if (intiter->first == 1){ // Deal with PO Box. SLiter = SplitLength.find(1); //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE)); GeoType = wxSPropertySeg2.Mid(0, SLiter->second); intPrevValue = intiter->second; GeoData = wxSPropertySeg2.Mid(intPrevValue); } } ProcessCaptureStrings(&wxSPropertySeg2); wxListItem coldata; coldata.SetId(intValueSeek); coldata.SetData(intValueSeek); if (intType == 0){ /* ListCtrlIndex = lboTimezones->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } */ /* txtGeopositioning->SetValue(GeoData); */ GeneralGeographyList.erase(intValueSeek); GeneralGeographyListType.erase(intValueSeek); GeneralGeographyListTokens.erase(intValueSeek); GeneralGeographyList.insert(std::make_pair(intValueSeek, GeoData)); GeneralGeographyListType.insert(std::make_pair(intValueSeek, wxT(""))); GeneralGeographyListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); CaptureString(&GeoData, FALSE); coldata.SetText(GeoData); ListCtrlIndex = lboGeoposition->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboGeoposition->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } } else if (intType == 1){ /* ListCtrlIndex = lboHomeTimezones->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboHomeTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } */ /* txtHomeGeopositioning->SetValue(GeoData); */ HomeGeographyList.erase(intValueSeek); HomeGeographyListType.erase(intValueSeek); HomeGeographyListTokens.erase(intValueSeek); HomeGeographyList.insert(std::make_pair(intValueSeek, GeoData)); HomeGeographyListType.insert(std::make_pair(intValueSeek, wxT("home"))); HomeGeographyListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); CaptureString(&GeoData, FALSE); coldata.SetText(GeoData); ListCtrlIndex = lboHomeGeoposition->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboHomeGeoposition->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } } else if (intType == 2){ ListCtrlIndex = lboBusinessGeoposition->InsertItem(coldata); /* ListCtrlIndex = lboBusinessTimezones->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboBusinessTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } */ /* txtBusinessGeopositioning->SetValue(GeoData); */ BusinessGeographyList.erase(intValueSeek); BusinessGeographyListType.erase(intValueSeek); BusinessGeographyListTokens.erase(intValueSeek); BusinessGeographyList.insert(std::make_pair(intValueSeek, GeoData)); BusinessGeographyListType.insert(std::make_pair(intValueSeek, wxT("work"))); BusinessGeographyListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); CaptureString(&GeoData, FALSE); coldata.SetText(GeoData); ListCtrlIndex = lboBusinessGeoposition->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboBusinessGeoposition->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } } GeoCount++; intValueSeek++; }