// frmContactEditor-LoadName.cpp - frmContactEditor load name 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::LoadFN(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *FNCount, bool *FNProcessed, vCard *ContactData){ size_t intPropertyLen = wxSPropertySeg1.Len(); std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; bool FirstToken = TRUE; int intSplitsFound = 0; int intSplitSize = 0; int intPrevValue = 4; int intPref = 0; int intType = 0; SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue); intPrevValue = 3; // 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. FullNamesList.insert(std::make_pair(intValueSeek, wxT(""))); FullNamesListAltID.insert(std::make_pair(intValueSeek, wxT(""))); FullNamesListPID.insert(std::make_pair(intValueSeek, wxT(""))); FullNamesListPref.insert(std::make_pair(intValueSeek, 0)); FullNamesListType.insert(std::make_pair(intValueSeek, wxT(""))); FullNamesListLanguage.insert(std::make_pair(intValueSeek, wxT(""))); FullNamesListTokens.insert(std::make_pair(intValueSeek, wxT(""))); intPrevValue = 3; 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(); ProcessCaptureStrings(&PropertyValue); intPrevValue = intiter->second; // Process properties. if (PropertyName == wxT("ALTID")){ FullNamesListAltID.erase(intValueSeek); FullNamesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (PropertyName == wxT("PID")){ FullNamesListPID.erase(intValueSeek); FullNamesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); if (intPref > 0 && intPref < 101){ FullNamesListPref.erase(intValueSeek); FullNamesListPref.insert(std::make_pair(intValueSeek, intPref)); } } else if (PropertyName == wxT("LANG")){ FullNamesListLanguage.erase(intValueSeek); FullNamesListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); } 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; } } // Add the data to the General/Home/Work address variables. /* wxListItem coldata; coldata.SetId(intValueSeek); coldata.SetData(intValueSeek); coldata.SetText(IMPPType); */ //ProcessCaptureStrings(wxsPropertySeg2); ProcessCaptureStrings(&wxSPropertySeg2); FullNamesList.erase(intValueSeek); FullNamesListType.erase(intValueSeek); FullNamesListTokens.erase(intValueSeek); FullNamesList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); FullNamesListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); if (intType == 0){ FullNamesListType.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 1){ FullNamesListType.insert(std::make_pair(intValueSeek, wxT("home"))); } else if (intType == 2){ FullNamesListType.insert(std::make_pair(intValueSeek, wxT("work"))); } if (*FNProcessed == FALSE){ NameDisplayAs = wxSPropertySeg2; cmbDisplayAs->SetValue(ContactData->Convert(wxSPropertySeg2, TRUE)); *FNProcessed = TRUE; } FNCount++; intValueSeek++; } void frmContactEditor::LoadN(wxString wxSPropertySeg1, wxString wxSPropertySeg2, bool *NameProcessed, vCard *ContactData){ size_t intPropertyLen = wxSPropertySeg1.Len(); std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; bool FirstToken = TRUE; int intSplitsFound = 0; int intSplitSize = 0; int intPrevValue = 3; int intSplitSeek = 0; SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue); // Look for type before continuing. intPrevValue = 2; 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; } intPrevValue = 2; 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(); ProcessCaptureStrings(&PropertyValue); intPrevValue = intiter->second; // Process properties. if (PropertyName == wxT("ALTID")){ NameAltID = PropertyValue; } else if (PropertyName == wxT("LANG")){ NameLanguage = PropertyValue; } else if (PropertyName == wxT("SORT-AS")){ NameDisplayAs = PropertyValue; } else { // Something else we don't know about so append // to the tokens variable. if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){ if (FirstToken == TRUE){ PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue); FirstToken = FALSE; } else { PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue); } } } } intPropertyLen = wxSPropertySeg2.Len(); SplitPoints.clear(); SplitLength.clear(); intSplitSeek = 0; 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 == 4){ SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1))); break; } else { SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1))); } intSplitSize = 0; } } // Split the data into several parts. for (std::map::iterator intiter = SplitPoints.begin(); intiter != SplitPoints.end(); ++intiter){ if (intiter->first == 1){ // Deal with family name. SLiter = SplitLength.find(1); txtSurname->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE)); intPrevValue = intiter->second; NameSurname = wxSPropertySeg2.Mid(0, SLiter->second); } else if (intiter->first == 2){ // Deal with given names. SLiter = SplitLength.find(2); txtForename->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE)); intPrevValue = intiter->second; NameForename = wxSPropertySeg2.Mid(intPrevValue, SLiter->second); } else if (intiter->first == 3){ // Deal with additional names. SLiter = SplitLength.find(3); txtOtherNames->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE)); intPrevValue = intiter->second; NameOtherNames = wxSPropertySeg2.Mid(intPrevValue, SLiter->second); } else if (intiter->first == 4){ // Deal with honorifix prefixes and suffixes. SLiter = SplitLength.find(4); txtTitle->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue, SLiter->second), TRUE)); intPrevValue = intiter->second; NameTitle = wxSPropertySeg2.Mid(intPrevValue, SLiter->second); txtSuffix->SetValue(ContactData->Convert(wxSPropertySeg2.Mid(intPrevValue), TRUE)); NameSuffix = wxSPropertySeg2.Mid(intPrevValue); } } NameTokens = PropertyTokens; *NameProcessed = TRUE; }