// frmContactEditor-LoadCalendar.cpp - frmContactEditor load calendar 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::LoadCalURI(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *CalAdrCount){ std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; bool FirstToken = TRUE; int intPrevValue = 8; int intPref = 0; int intType = 0; long ListCtrlIndex; SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue); intPrevValue = 7; // 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. CalendarList.insert(std::make_pair(intValueSeek, wxT(""))); CalendarListAltID.insert(std::make_pair(intValueSeek, wxT(""))); CalendarListPID.insert(std::make_pair(intValueSeek, wxT(""))); CalendarListPref.insert(std::make_pair(intValueSeek, 0)); CalendarListTokens.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); } if (PropertyName == wxT("ALTID")){ CalendarListAltID.erase(intValueSeek); CalendarListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (PropertyName == wxT("PID")){ CalendarListPID.erase(intValueSeek); CalendarListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); CalendarListPref.erase(intValueSeek); CalendarListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (PropertyName == wxT("MEDIATYPE")){ CalendarListMediatype.erase(intValueSeek); CalendarListMediatype.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. wxListItem coldata; coldata.SetId(intValueSeek); coldata.SetData(intValueSeek); coldata.SetText(wxSPropertySeg2); ListCtrlIndex = lboCalendarAddresses->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboCalendarAddresses->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref)); } CaptureString(&wxSPropertySeg2, FALSE); CalendarList.erase(intValueSeek); CalendarListType.erase(intValueSeek); CalendarListTokens.erase(intValueSeek); CalendarList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); if (intType == 0){ CalendarListType.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 1){ CalendarListType.insert(std::make_pair(intValueSeek, wxT("home"))); lboCalendarAddresses->SetItem(ListCtrlIndex, 1, _("Home"), intPref); } else if (intType == 2){ CalendarListType.insert(std::make_pair(intValueSeek, wxT("work"))); lboCalendarAddresses->SetItem(ListCtrlIndex, 1, _("Work"), intPref); } CalendarListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); CalAdrCount++; intValueSeek++; } void frmContactEditor::LoadCalAdrURI(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *CalReqAdrCount){ std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; bool FirstToken = TRUE; int intPrevValue = 11; int intPref = 0; int intType = 0; long ListCtrlIndex; SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue); intPrevValue = 10; // 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. CalendarRequestList.insert(std::make_pair(intValueSeek, wxT(""))); CalendarRequestListAltID.insert(std::make_pair(intValueSeek, wxT(""))); CalendarRequestListPID.insert(std::make_pair(intValueSeek, wxT(""))); CalendarRequestListPref.insert(std::make_pair(intValueSeek, 0)); CalendarRequestListTokens.insert(std::make_pair(intValueSeek, wxT(""))); intPrevValue = 10; 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); } if (PropertyName == wxT("ALTID")){ CalendarRequestListAltID.erase(intValueSeek); CalendarRequestListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (PropertyName == wxT("PID")){ CalendarRequestListPID.erase(intValueSeek); CalendarRequestListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); CalendarRequestListPref.erase(intValueSeek); CalendarRequestListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (PropertyName == wxT("MEDIATYPE")){ CalendarRequestListMediatype.erase(intValueSeek); CalendarRequestListMediatype.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. wxListItem coldata; coldata.SetId(intValueSeek); coldata.SetData(intValueSeek); coldata.SetText(wxSPropertySeg2); ListCtrlIndex = lboCalendarRequestAddress->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboCalendarRequestAddress->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref)); } CaptureString(&wxSPropertySeg2, FALSE); CalendarRequestList.erase(intValueSeek); CalendarRequestListType.erase(intValueSeek); CalendarRequestListTokens.erase(intValueSeek); CalendarRequestList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); if (intType == 0){ CalendarRequestListType.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 1){ CalendarRequestListType.insert(std::make_pair(intValueSeek, wxT("home"))); lboCalendarRequestAddress->SetItem(ListCtrlIndex, 1, _("Home"), intPref); } else if (intType == 2){ CalendarRequestListType.insert(std::make_pair(intValueSeek, wxT("work"))); lboCalendarRequestAddress->SetItem(ListCtrlIndex, 1, _("Work"), intPref); } CalendarRequestListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); CalReqAdrCount++; intValueSeek++; }