// frmContactEditor-LoadLanguages.cpp - frmContactEditor load languages 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::LoadLanguage(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *LangCount){
std::map SplitPoints;
std::map SplitLength;
std::map::iterator SLiter;
wxString PropertyData;
wxString PropertyName;
wxString PropertyValue;
wxString PropertyTokens;
bool FirstToken = TRUE;
int intPrevValue = 6;
int intPref = 0;
int intType = 0;
long ListCtrlIndex;
SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
intPrevValue = 5;
// 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){
GeneralLanguageList.insert(std::make_pair(intValueSeek, wxT("")));
GeneralLanguageListAltID.insert(std::make_pair(intValueSeek, wxT("")));
GeneralLanguageListPID.insert(std::make_pair(intValueSeek, wxT("")));
GeneralLanguageListPref.insert(std::make_pair(intValueSeek, 0));
GeneralLanguageListTokens.insert(std::make_pair(intValueSeek, wxT("")));
} else if (intType == 1){
HomeLanguageList.insert(std::make_pair(intValueSeek, wxT("")));
HomeLanguageListAltID.insert(std::make_pair(intValueSeek, wxT("")));
HomeLanguageListPID.insert(std::make_pair(intValueSeek, wxT("")));
HomeLanguageListPref.insert(std::make_pair(intValueSeek, 0));
HomeLanguageListTokens.insert(std::make_pair(intValueSeek, wxT("")));
} else if (intType == 2){
BusinessLanguageList.insert(std::make_pair(intValueSeek, wxT("")));
BusinessLanguageListAltID.insert(std::make_pair(intValueSeek, wxT("")));
BusinessLanguageListPID.insert(std::make_pair(intValueSeek, wxT("")));
BusinessLanguageListPref.insert(std::make_pair(intValueSeek, 0));
BusinessLanguageListTokens.insert(std::make_pair(intValueSeek, wxT("")));
}
intPrevValue = 5;
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){ GeneralLanguageListAltID.erase(intValueSeek); GeneralLanguageListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 1){ HomeLanguageListAltID.erase(intValueSeek); HomeLanguageListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 2){ BusinessLanguageListAltID.erase(intValueSeek); BusinessLanguageListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
} else if (PropertyName == wxT("PID")){
if (intType == 0){ GeneralLanguageListPID.erase(intValueSeek); GeneralLanguageListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 1){ HomeLanguageListPID.erase(intValueSeek); HomeLanguageListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 2){ BusinessLanguageListPID.erase(intValueSeek); BusinessLanguageListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
} else if (PropertyName == wxT("PREF")){
intPref = wxAtoi(PropertyValue);
if (intType == 0){ GeneralLanguageListPref.erase(intValueSeek); GeneralLanguageListPref.insert(std::make_pair(intValueSeek, intPref)); }
else if (intType == 1){ HomeLanguageListPref.erase(intValueSeek); HomeLanguageListPref.insert(std::make_pair(intValueSeek, intPref)); }
else if (intType == 2){ BusinessLanguageListPref.erase(intValueSeek); BusinessLanguageListPref.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);
}
}
}
}
// 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 = lboLanguages->InsertItem(coldata);
if (intPref > 0 && intPref < 101){
lboLanguages->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
}
GeneralLanguageList.erase(intValueSeek);
GeneralLanguageListType.erase(intValueSeek);
GeneralLanguageListTokens.erase(intValueSeek);
GeneralLanguageList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
GeneralLanguageListType.insert(std::make_pair(intValueSeek, wxT("")));
GeneralLanguageListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
} else if (intType == 1){
ListCtrlIndex = lboHomeLanguages->InsertItem(coldata);
if (intPref > 0 && intPref < 101){
lboHomeLanguages->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
}
HomeLanguageList.erase(intValueSeek);
HomeLanguageListType.erase(intValueSeek);
HomeLanguageListTokens.erase(intValueSeek);
HomeLanguageList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
HomeLanguageListType.insert(std::make_pair(intValueSeek, wxT("home")));
HomeLanguageListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
} else if (intType == 2){
ListCtrlIndex = lboBusinessLanguages->InsertItem(coldata);
if (intPref > 0 && intPref < 101){
lboBusinessLanguages->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
}
BusinessLanguageList.erase(intValueSeek);
BusinessLanguageListType.erase(intValueSeek);
BusinessLanguageListTokens.erase(intValueSeek);
BusinessLanguageList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
BusinessLanguageListType.insert(std::make_pair(intValueSeek, wxT("work")));
BusinessLanguageListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
}
LangCount++;
intValueSeek++;
}