// frmContactEditor-LoadNickname.cpp - frmContactEditor load nickname 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::LoadNickname(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *NicknameCount, vCard *ContactData){ std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; bool FirstToken = TRUE; int intPrevValue = 10; int intPref = 0; int intType = 0; long ListCtrlIndex; SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue); intPrevValue = 9; 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){ GeneralNicknamesList.insert(std::make_pair(intValueSeek, wxT(""))); GeneralNicknamesListAltID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralNicknamesListPID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralNicknamesListPref.insert(std::make_pair(intValueSeek, 0)); GeneralNicknamesListTokens.insert(std::make_pair(intValueSeek, wxT(""))); GeneralNicknamesListLanguage.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 1){ HomeNicknamesList.insert(std::make_pair(intValueSeek, wxT(""))); HomeNicknamesListAltID.insert(std::make_pair(intValueSeek, wxT(""))); HomeNicknamesListPID.insert(std::make_pair(intValueSeek, wxT(""))); HomeNicknamesListPref.insert(std::make_pair(intValueSeek, 0)); HomeNicknamesListTokens.insert(std::make_pair(intValueSeek, wxT(""))); HomeNicknamesListLanguage.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 2){ BusinessNicknamesList.insert(std::make_pair(intValueSeek, wxT(""))); BusinessNicknamesListAltID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessNicknamesListPID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessNicknamesListPref.insert(std::make_pair(intValueSeek, 0)); BusinessNicknamesListTokens.insert(std::make_pair(intValueSeek, wxT(""))); BusinessNicknamesListLanguage.insert(std::make_pair(intValueSeek, wxT(""))); } intPrevValue = 9; 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; ProcessCaptureStrings(&PropertyValue); // 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); } if (PropertyName == wxT("ALTID")){ if (intType == 0){ GeneralNicknamesListAltID.erase(intValueSeek); GeneralNicknamesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeNicknamesListAltID.erase(intValueSeek); HomeNicknamesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessNicknamesListAltID.erase(intValueSeek); BusinessNicknamesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PID")){ if (intType == 0){ GeneralNicknamesListPID.erase(intValueSeek); GeneralNicknamesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeNicknamesListPID.erase(intValueSeek); HomeNicknamesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessNicknamesListPID.erase(intValueSeek); BusinessNicknamesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); if (intType == 0){ GeneralNicknamesListPref.erase(intValueSeek); GeneralNicknamesListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 1){ HomeNicknamesListPref.erase(intValueSeek); HomeNicknamesListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 2){ BusinessNicknamesListPref.erase(intValueSeek); BusinessNicknamesListPref.insert(std::make_pair(intValueSeek, intPref)); } } else if (PropertyName == wxT("LANGUAGE")){ if (intType == 0){ GeneralNicknamesListLanguage.erase(intValueSeek); GeneralNicknamesListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeNicknamesListLanguage.erase(intValueSeek); HomeNicknamesListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessNicknamesListLanguage.erase(intValueSeek); BusinessNicknamesListLanguage.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); } } } } // Add the data to the General/Home/Work address variables. ProcessCaptureStrings(&wxSPropertySeg2); wxListItem coldata; coldata.SetId(intValueSeek); coldata.SetData(intValueSeek); coldata.SetText(wxSPropertySeg2); if (intType == 0){ ListCtrlIndex = lboNicknames->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboNicknames->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } GeneralNicknamesList.erase(intValueSeek); GeneralNicknamesListType.erase(intValueSeek); GeneralNicknamesListTokens.erase(intValueSeek); GeneralNicknamesList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); GeneralNicknamesListType.insert(std::make_pair(intValueSeek, wxT(""))); GeneralNicknamesListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } else if (intType == 1){ ListCtrlIndex = lboHomeNicknames->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboHomeNicknames->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } HomeNicknamesList.erase(intValueSeek); HomeNicknamesListType.erase(intValueSeek); HomeNicknamesListTokens.erase(intValueSeek); HomeNicknamesList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); HomeNicknamesListType.insert(std::make_pair(intValueSeek, wxT("home"))); HomeNicknamesListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } else if (intType == 2){ ListCtrlIndex = lboBusinessNicknames->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboBusinessNicknames->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } BusinessNicknamesList.erase(intValueSeek); BusinessNicknamesListType.erase(intValueSeek); BusinessNicknamesListTokens.erase(intValueSeek); BusinessNicknamesList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); BusinessNicknamesListType.insert(std::make_pair(intValueSeek, wxT("work"))); BusinessNicknamesListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } NicknameCount++; intValueSeek++; }