// frmContactEditor-LoadTitle.cpp - frmContactEditor load title 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::LoadTitle(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *TitleCount){
std::map SplitPoints;
std::map SplitLength;
std::map::iterator SLiter;
wxString PropertyData;
wxString PropertyName;
wxString PropertyValue;
wxString PropertyTokens;
bool FirstToken = TRUE;
int intPrevValue = 7;
int intPref = 0;
int intType = 0;
long ListCtrlIndex;
SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
intPrevValue = 6;
// 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){
GeneralTitleList.insert(std::make_pair(intValueSeek, wxT("")));
GeneralTitleListAltID.insert(std::make_pair(intValueSeek, wxT("")));
GeneralTitleListPID.insert(std::make_pair(intValueSeek, wxT("")));
GeneralTitleListPref.insert(std::make_pair(intValueSeek, 0));
GeneralTitleListTokens.insert(std::make_pair(intValueSeek, wxT("")));
GeneralTitleListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
} else if (intType == 1){
HomeTitleList.insert(std::make_pair(intValueSeek, wxT("")));
HomeTitleListAltID.insert(std::make_pair(intValueSeek, wxT("")));
HomeTitleListPID.insert(std::make_pair(intValueSeek, wxT("")));
HomeTitleListPref.insert(std::make_pair(intValueSeek, 0));
HomeTitleListTokens.insert(std::make_pair(intValueSeek, wxT("")));
HomeTitleListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
} else if (intType == 2){
BusinessTitleList.insert(std::make_pair(intValueSeek, wxT("")));
BusinessTitleListAltID.insert(std::make_pair(intValueSeek, wxT("")));
BusinessTitleListPID.insert(std::make_pair(intValueSeek, wxT("")));
BusinessTitleListPref.insert(std::make_pair(intValueSeek, 0));
BusinessTitleListTokens.insert(std::make_pair(intValueSeek, wxT("")));
BusinessTitleListLanguage.insert(std::make_pair(intValueSeek, wxT("")));
}
intPrevValue = 6;
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){ GeneralTitleListAltID.erase(intValueSeek); GeneralTitleListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 1){ HomeTitleListAltID.erase(intValueSeek); HomeTitleListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 2){ BusinessTitleListAltID.erase(intValueSeek); BusinessTitleListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
} else if (PropertyName == wxT("PID")){
if (intType == 0){ GeneralTitleListPID.erase(intValueSeek); GeneralTitleListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 1){ HomeTitleListPID.erase(intValueSeek); HomeTitleListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 2){ BusinessTitleListPID.erase(intValueSeek); BusinessTitleListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
} else if (PropertyName == wxT("PREF")){
intPref = wxAtoi(PropertyValue);
if (intType == 0){ GeneralTitleListPref.erase(intValueSeek); GeneralTitleListPref.insert(std::make_pair(intValueSeek, intPref)); }
else if (intType == 1){ HomeTitleListPref.erase(intValueSeek); HomeTitleListPref.insert(std::make_pair(intValueSeek, intPref)); }
else if (intType == 2){ BusinessTitleListPref.erase(intValueSeek); BusinessTitleListPref.insert(std::make_pair(intValueSeek, intPref)); }
} else if (PropertyName == wxT("LANGUAGE")){
if (intType == 0){ GeneralTitleListLanguage.erase(intValueSeek); GeneralTitleListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 1){ HomeTitleListLanguage.erase(intValueSeek); HomeTitleListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 2){ BusinessTitleListLanguage.erase(intValueSeek); BusinessTitleListLanguage.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 = lboTitles->InsertItem(coldata);
if (intPref > 0 && intPref < 101){
lboTitles->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
}
GeneralTitleList.erase(intValueSeek);
GeneralTitleListType.erase(intValueSeek);
GeneralTitleListTokens.erase(intValueSeek);
GeneralTitleList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
GeneralTitleListType.insert(std::make_pair(intValueSeek, wxT("")));
GeneralTitleListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
} else if (intType == 1){
ListCtrlIndex = lboHomeTitles->InsertItem(coldata);
if (intPref > 0 && intPref < 101){
lboHomeTitles->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
}
HomeTitleList.erase(intValueSeek);
HomeTitleListType.erase(intValueSeek);
HomeTitleListTokens.erase(intValueSeek);
HomeTitleList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
HomeTitleListType.insert(std::make_pair(intValueSeek, wxT("home")));
HomeTitleListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
} else if (intType == 2){
ListCtrlIndex = lboBusinessTitles->InsertItem(coldata);
if (intPref > 0 && intPref < 101){
lboBusinessTitles->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
}
BusinessTitleList.erase(intValueSeek);
BusinessTitleListType.erase(intValueSeek);
BusinessTitleListTokens.erase(intValueSeek);
BusinessTitleList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
BusinessTitleListType.insert(std::make_pair(intValueSeek, wxT("work")));
BusinessTitleListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
}
TitleCount++;
intValueSeek++;
}