// frmContactEditor-LoadTelephone.cpp - frmContactEditor load telephone 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::LoadTelephone(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *TelCount){
// Check TEL and make sure it is functioning properly.
size_t intPropertyLen = wxSPropertySeg1.Len();
std::map SplitPoints;
std::map SplitLength;
std::map TypeSplitPoints;
std::map TypeSplitLength;
std::map::iterator SLiter;
std::map::iterator SPoint;
std::map::iterator TSLiter;
std::map::iterator TSPoint;
wxString PropertyData;
wxString PropertyName;
wxString PropertyValue;
wxString PropertyTokens;
wxString TelType;
wxString TelNumber;
wxString TelTypeUI;
wxString TelTypeDetail;
bool FirstToken = TRUE;
int intSplitsFound = 0;
int intSplitSize = 0;
int intPrevValue = 5;
int intPref = 0;
int intType = 0;
int intSplitPoint = 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")){
// Process each value in type and translate each
// part.
// Strip out the quotes if they are there.
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);
}
TelTypeDetail = PropertyValue;
intSplitSize = 0;
intSplitsFound = 0;
intSplitPoint = 0;
for (int i = 0; i <= intPropertyValueLen; i++){
intSplitSize++;
if (PropertyValue.Mid(i, 1) == wxT(",") && PropertyValue.Mid((i - 1), 1) != wxT("\\")){
if (intSplitsFound == 0){
TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
TypeSplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
} else {
TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
}
intSplitsFound++;
i++;
intSplitPoint = i;
intSplitSize = 0;
}
}
TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
int intTypeSeek = 0;
for (std::map::iterator typeiter = TypeSplitPoints.begin();
typeiter != TypeSplitPoints.end(); ++typeiter){
wxString TypePropertyName;
TSLiter = TypeSplitLength.find(typeiter->first);
TypePropertyName = PropertyValue.Mid(typeiter->second, TSLiter->second);
if (intTypeSeek == 0){
} else {
TelTypeUI.Append(wxT(","));
}
if (TypePropertyName == wxT("home")){
intType = 1;
} else if (TypePropertyName == wxT("work")){
intType = 2;
}
if (TypePropertyName == wxT("text")){
TelTypeUI.Append(_("text"));
intTypeSeek++;
} else if (TypePropertyName == wxT("voice")){
TelTypeUI.Append(_("voice"));
intTypeSeek++;
} else if (TypePropertyName == wxT("fax")){
TelTypeUI.Append(_("fax"));
intTypeSeek++;
} else if (TypePropertyName == wxT("cell")){
TelTypeUI.Append(_("mobile"));
intTypeSeek++;
} else if (TypePropertyName == wxT("video")){
TelTypeUI.Append(_("video"));
intTypeSeek++;
} else if (TypePropertyName == wxT("pager")){
TelTypeUI.Append(_("pager"));
intTypeSeek++;
} else if (TypePropertyName == wxT("textphone")){
TelTypeUI.Append(_("textphone"));
intTypeSeek++;
}
}
}
}
// Setup blank lines for later on.
if (intType == 0){
GeneralTelephoneList.insert(std::make_pair(intValueSeek, wxT("")));
GeneralTelephoneListAltID.insert(std::make_pair(intValueSeek, wxT("")));
GeneralTelephoneListPID.insert(std::make_pair(intValueSeek, wxT("")));
GeneralTelephoneListPref.insert(std::make_pair(intValueSeek, 0));
GeneralTelephoneListTokens.insert(std::make_pair(intValueSeek, wxT("")));
} else if (intType == 1){
HomeTelephoneList.insert(std::make_pair(intValueSeek, wxT("")));
HomeTelephoneListAltID.insert(std::make_pair(intValueSeek, wxT("")));
HomeTelephoneListPID.insert(std::make_pair(intValueSeek, wxT("")));
HomeTelephoneListPref.insert(std::make_pair(intValueSeek, 0));
HomeTelephoneListTokens.insert(std::make_pair(intValueSeek, wxT("")));
} else if (intType == 2){
BusinessTelephoneList.insert(std::make_pair(intValueSeek, wxT("")));
BusinessTelephoneListAltID.insert(std::make_pair(intValueSeek, wxT("")));
BusinessTelephoneListPID.insert(std::make_pair(intValueSeek, wxT("")));
BusinessTelephoneListPref.insert(std::make_pair(intValueSeek, 0));
BusinessTelephoneListTokens.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;
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);
// Process properties.
if (PropertyName == wxT("ALTID")){
if (intType == 0){ GeneralTelephoneListAltID.erase(intValueSeek); GeneralTelephoneListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 1){ HomeTelephoneListAltID.erase(intValueSeek); HomeTelephoneListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 2){ BusinessTelephoneListAltID.erase(intValueSeek); BusinessTelephoneListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
} else if (PropertyName == wxT("PID")){
if (intType == 0){ GeneralTelephoneListPID.erase(intValueSeek); GeneralTelephoneListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 1){ HomeTelephoneListPID.erase(intValueSeek); HomeTelephoneListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 2){ BusinessTelephoneListPID.erase(intValueSeek); BusinessTelephoneListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
} else if (PropertyName == wxT("PREF")){
intPref = wxAtoi(PropertyValue);
if (intPref > 0 && intPref < 101){
if (intType == 0){ GeneralTelephoneListPref.erase(intValueSeek); GeneralTelephoneListPref.insert(std::make_pair(intValueSeek, intPref)); }
else if (intType == 1){ HomeTelephoneListPref.erase(intValueSeek); HomeTelephoneListPref.insert(std::make_pair(intValueSeek, intPref)); }
else if (intType == 2){ BusinessTelephoneListPref.erase(intValueSeek); BusinessTelephoneListPref.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;
}
}
// Split the data into several parts.
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));
TelType = wxSPropertySeg2.Mid(0, SLiter->second);
intPrevValue = intiter->second;
TelNumber = wxSPropertySeg2.Mid(intPrevValue);
}
}
// Add the data to the General/Home/Work address variables.
ProcessCaptureStrings(&PropertyValue);
wxListItem coldata;
coldata.SetId(intValueSeek);
coldata.SetData(intValueSeek);
coldata.SetText(TelNumber);
if (intType == 0){
ListCtrlIndex = lboTelephone->InsertItem(coldata);
lboTelephone->SetItem(ListCtrlIndex, 1, TelTypeUI);
if (intPref > 0 && intPref < 101){
lboTelephone->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
}
GeneralTelephoneList.erase(intValueSeek);
GeneralTelephoneListType.erase(intValueSeek);
GeneralTelephoneListTokens.erase(intValueSeek);
GeneralTelephoneList.insert(std::make_pair(intValueSeek, TelNumber));
GeneralTelephoneListType.insert(std::make_pair(intValueSeek, TelTypeDetail));
GeneralTelephoneListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
} else if (intType == 1){
ListCtrlIndex = lboHomeTelephone->InsertItem(coldata);
lboHomeTelephone->SetItem(ListCtrlIndex, 1, TelTypeUI);
if (intPref > 0 && intPref < 101){
lboHomeTelephone->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
}
HomeTelephoneList.erase(intValueSeek);
HomeTelephoneListType.erase(intValueSeek);
HomeTelephoneListTokens.erase(intValueSeek);
HomeTelephoneList.insert(std::make_pair(intValueSeek, TelNumber));
HomeTelephoneListType.insert(std::make_pair(intValueSeek, TelTypeDetail));
HomeTelephoneListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
} else if (intType == 2){
ListCtrlIndex = lboBusinessTelephone->InsertItem(coldata);
lboBusinessTelephone->SetItem(ListCtrlIndex, 1, TelTypeUI);
if (intPref > 0 && intPref < 101){
lboBusinessTelephone->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
}
BusinessTelephoneList.erase(intValueSeek);
BusinessTelephoneListType.erase(intValueSeek);
BusinessTelephoneListTokens.erase(intValueSeek);
BusinessTelephoneList.insert(std::make_pair(intValueSeek, TelNumber));
BusinessTelephoneListType.insert(std::make_pair(intValueSeek, TelTypeDetail));
BusinessTelephoneListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
}
TelCount++;
intValueSeek++;
}