// frmContactEditor-LoadTimeZone.cpp - frmContactEditor load timezone 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::LoadTimeZone(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *TZCount){
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;
long ListCtrlIndex;
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.
if (intType == 0){
GeneralTZList.insert(std::make_pair(intValueSeek, wxT("")));
GeneralTZListAltID.insert(std::make_pair(intValueSeek, wxT("")));
GeneralTZListPID.insert(std::make_pair(intValueSeek, wxT("")));
GeneralTZListPref.insert(std::make_pair(intValueSeek, 0));
GeneralTZListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
GeneralTZListTokens.insert(std::make_pair(intValueSeek, wxT("")));
} else if (intType == 1){
HomeTZList.insert(std::make_pair(intValueSeek, wxT("")));
HomeTZListAltID.insert(std::make_pair(intValueSeek, wxT("")));
HomeTZListPID.insert(std::make_pair(intValueSeek, wxT("")));
HomeTZListPref.insert(std::make_pair(intValueSeek, 0));
HomeTZListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
HomeTZListTokens.insert(std::make_pair(intValueSeek, wxT("")));
} else if (intType == 2){
BusinessTZList.insert(std::make_pair(intValueSeek, wxT("")));
BusinessTZListAltID.insert(std::make_pair(intValueSeek, wxT("")));
BusinessTZListPID.insert(std::make_pair(intValueSeek, wxT("")));
BusinessTZListPref.insert(std::make_pair(intValueSeek, 0));
BusinessTZListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
BusinessTZListTokens.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();
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){ GeneralTZListAltID.erase(intValueSeek); GeneralTZListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 1){ HomeTZListAltID.erase(intValueSeek); HomeTZListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 2){ BusinessTZListAltID.erase(intValueSeek); BusinessTZListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
} else if (PropertyName == wxT("PID")){
if (intType == 0){ GeneralTZListPID.erase(intValueSeek); GeneralTZListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 1){ HomeTZListPID.erase(intValueSeek); HomeTZListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 2){ BusinessTZListPID.erase(intValueSeek); BusinessTZListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
} else if (PropertyName == wxT("MEDIATYPE")){
if (intType == 0){ GeneralTZListMediatype.erase(intValueSeek); GeneralTZListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 1){ HomeTZListMediatype.erase(intValueSeek); HomeTZListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
else if (intType == 2){ BusinessTZListMediatype.erase(intValueSeek); BusinessTZListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
} else if (PropertyName == wxT("PREF")){
intPref = wxAtoi(PropertyValue);
if (intPref > 0 && intPref < 101){
if (intType == 0){ GeneralTZListPref.erase(intValueSeek); GeneralTZListPref.insert(std::make_pair(intValueSeek, intPref)); }
else if (intType == 1){ HomeTZListPref.erase(intValueSeek); HomeTZListPref.insert(std::make_pair(intValueSeek, intPref)); }
else if (intType == 2){ BusinessTZListPref.erase(intValueSeek); BusinessTZListPref.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 == 6){
SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
break;
} else {
SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
}
intSplitSize = 0;
}
}
// 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 = lboTimezones->InsertItem(coldata);
if (intPref > 0 && intPref < 101){
lboTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
}
GeneralTZList.erase(intValueSeek);
GeneralTZListType.erase(intValueSeek);
GeneralTZListTokens.erase(intValueSeek);
GeneralTZList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
GeneralTZListType.insert(std::make_pair(intValueSeek, wxT("")));
GeneralTZListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
} else if (intType == 1){
ListCtrlIndex = lboHomeTimezones->InsertItem(coldata);
if (intPref > 0 && intPref < 101){
lboHomeTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
}
HomeTZList.erase(intValueSeek);
HomeTZListType.erase(intValueSeek);
HomeTZListTokens.erase(intValueSeek);
HomeTZList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
HomeTZListType.insert(std::make_pair(intValueSeek, wxT("home")));
HomeTZListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
} else if (intType == 2){
ListCtrlIndex = lboBusinessTimezones->InsertItem(coldata);
if (intPref > 0 && intPref < 101){
lboBusinessTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
}
BusinessTZList.erase(intValueSeek);
BusinessTZListType.erase(intValueSeek);
BusinessTZListTokens.erase(intValueSeek);
BusinessTZList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
BusinessTZListType.insert(std::make_pair(intValueSeek, wxT("work")));
BusinessTZListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
}
TZCount++;
intValueSeek++;
}