// frmContactEditor-LoadCategory.cpp - frmContactEditor load category 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::LoadCategory(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *CategoryCount){ size_t intPropertyLen = wxSPropertySeg1.Len(); std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; wxString PropertyType; bool AfterFirstToken = FALSE; bool FirstToken = TRUE; int intSplitsFound = 0; int intSplitSize = 0; int intPrevValue = 12; int intPref = 0; int intType = 0; int intSplitSeek = 0; long ListCtrlIndex; SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue); intPrevValue = 11; // 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; PropertyType = wxT("work"); } else if (PropertyValue == wxT("home")){ intType = 1; PropertyType = wxT("home"); } else { intType = 0; } } } // Setup blank lines for later on. CategoriesList.insert(std::make_pair(intValueSeek, wxT(""))); CategoriesListAltID.insert(std::make_pair(intValueSeek, wxT(""))); CategoriesListPID.insert(std::make_pair(intValueSeek, wxT(""))); CategoriesListPref.insert(std::make_pair(intValueSeek, 0)); CategoriesListTokens.insert(std::make_pair(intValueSeek, wxT(""))); intPrevValue = 11; 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){ CategoriesListAltID.erase(intValueSeek); CategoriesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ CategoriesListAltID.erase(intValueSeek); CategoriesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ CategoriesListAltID.erase(intValueSeek); CategoriesListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PID")){ if (intType == 0){ CategoriesListPID.erase(intValueSeek); CategoriesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ CategoriesListPID.erase(intValueSeek); CategoriesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ CategoriesListPID.erase(intValueSeek); CategoriesListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); if (intType == 0){ CategoriesListPref.erase(intValueSeek); CategoriesListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 1){ CategoriesListPref.erase(intValueSeek); CategoriesListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 2){ CategoriesListPref.erase(intValueSeek); CategoriesListPref.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); } } } } // Deal with multiple categories. SplitPoints.clear(); SplitLength.clear(); intSplitSize = 0; intSplitsFound = 0; intSplitSeek = 0; intPrevValue = 0; intPropertyLen = wxSPropertySeg2.Len(); for (int i = 0; i <= intPropertyLen; i++){ if (intSplitSize == 0 && wxSPropertySeg2.Mid(i, 1) == wxT(" ")){ continue; } intSplitSize++; if (wxSPropertySeg2.Mid(i, 1) == wxT(",") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){ if (AfterFirstToken == TRUE){ SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1))); SplitLength.insert(std::make_pair(intSplitsFound, intSplitSize)); } else { SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1))); SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1))); AfterFirstToken = TRUE; } intSplitsFound++; intSplitSeek = i; intSplitSize = 0; } } SplitPoints.insert(std::make_pair(intSplitsFound, (intSplitSeek + 1))); SplitLength.insert(std::make_pair(intSplitsFound, intSplitSize)); intPrevValue = 0; for (std::map::iterator intiter = SplitPoints.begin(); intiter != SplitPoints.end(); ++intiter){ SLiter = SplitLength.find(intiter->first); PropertyData = wxSPropertySeg2.Mid(intPrevValue, (SLiter->second + 1)); intPrevValue = intiter->second; // Process properties. /* int intPropertyValueLen = PropertyValue.Len(); if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){ PropertyValue.Trim(); PropertyValue.RemoveLast(); } */ // Add the data to the General/Home/Work address variables. // Trim any whitespace from the start and end. PropertyData = PropertyData.Trim(FALSE); PropertyData = PropertyData.Trim(TRUE); ProcessCaptureStrings(&PropertyData); wxListItem coldata; coldata.SetId(intValueSeek); coldata.SetData(intValueSeek); coldata.SetText(PropertyData); ListCtrlIndex = lboCategories->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboCategories->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } CategoriesList.erase(intValueSeek); CategoriesListType.erase(intValueSeek); CategoriesListTokens.erase(intValueSeek); CategoriesList.insert(std::make_pair(intValueSeek, PropertyData)); CategoriesListType.insert(std::make_pair(intValueSeek, PropertyType)); CategoriesListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); CategoryCount++; intValueSeek++; } } void frmContactEditor::LoadCalFreeBusy(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *FreeBusyCount){ 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. FreeBusyList.insert(std::make_pair(intValueSeek, wxT(""))); FreeBusyListAltID.insert(std::make_pair(intValueSeek, wxT(""))); FreeBusyListPID.insert(std::make_pair(intValueSeek, wxT(""))); FreeBusyListPref.insert(std::make_pair(intValueSeek, 0)); FreeBusyListTokens.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")){ FreeBusyListAltID.erase(intValueSeek); FreeBusyListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (PropertyName == wxT("PID")){ FreeBusyListPID.erase(intValueSeek); FreeBusyListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); FreeBusyListPref.erase(intValueSeek); FreeBusyListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (PropertyName == wxT("MEDIATYPE")){ FreeBusyListMediatype.erase(intValueSeek); FreeBusyListMediatype.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 = lboFreeBusyAddresses->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboFreeBusyAddresses->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref)); } CaptureString(&wxSPropertySeg2, FALSE); FreeBusyList.erase(intValueSeek); FreeBusyListType.erase(intValueSeek); FreeBusyListTokens.erase(intValueSeek); FreeBusyList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); if (intType == 0){ FreeBusyListType.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 1){ FreeBusyListType.insert(std::make_pair(intValueSeek, wxT("home"))); lboFreeBusyAddresses->SetItem(ListCtrlIndex, 1, _("Home"), intPref); } else if (intType == 2){ FreeBusyListType.insert(std::make_pair(intValueSeek, wxT("work"))); lboFreeBusyAddresses->SetItem(ListCtrlIndex, 1, _("Work"), intPref); } FreeBusyListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); FreeBusyCount++; intValueSeek++; }