// frmContactEditor-LoadRelated.cpp - frmContactEditor load related 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::LoadRelated(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *RelatedCount){ size_t intPropertyLen = wxSPropertySeg1.Len(); std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; wxString RelatedType; wxString RelatedTypeOriginal; wxString RelatedName; bool FirstToken = TRUE; int intSplitsFound = 0; int intSplitSize = 0; int intPrevValue = 9; int intPref = 0; long ListCtrlIndex; SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue); intPrevValue = 8; // 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; // Process these. RelatedTypeOriginal = PropertyValue; if (PropertyName == wxT("TYPE")){ if (PropertyValue == wxT("contact")){ RelatedType = _("Contact"); } else if (PropertyValue == wxT("acquaintance")){ RelatedType = _("Acquaintance"); } else if (PropertyValue == wxT("friend")){ RelatedType = _("Friend"); } else if (PropertyValue == wxT("met")){ RelatedType = _("Met"); } else if (PropertyValue == wxT("co-worker")){ RelatedType = _("Co-worker"); } else if (PropertyValue == wxT("colleague")){ RelatedType = _("Colleague"); } else if (PropertyValue == wxT("co-resident")){ RelatedType = _("Co-resident"); } else if (PropertyValue == wxT("neighbor")){ RelatedType = _("Neighbour"); } else if (PropertyValue == wxT("child")){ RelatedType = _("Child"); } else if (PropertyValue == wxT("parent")){ RelatedType = _("Parent"); } else if (PropertyValue == wxT("sibling")){ RelatedType = _("Sibling"); } else if (PropertyValue == wxT("spouse")){ RelatedType = _("Spouse"); } else if (PropertyValue == wxT("kin")){ RelatedType = _("Kin"); } else if (PropertyValue == wxT("muse")){ RelatedType = _("Muse"); } else if (PropertyValue == wxT("crush")){ RelatedType = _("Crush"); } else if (PropertyValue == wxT("date")){ RelatedType = _("Date"); } else if (PropertyValue == wxT("sweetheart")){ RelatedType = _("Sweetheart"); } else if (PropertyValue == wxT("me")){ RelatedType = _("Me"); } else if (PropertyValue == wxT("agent")){ RelatedType = _("Agent"); } else if (PropertyValue == wxT("emergency")){ RelatedType = _("Emergency"); } else { RelatedType = PropertyValue; } } } intPrevValue = 8; 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")){ GeneralRelatedListAltID.erase(intValueSeek); GeneralRelatedListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (PropertyName == wxT("PID")){ GeneralRelatedListPID.erase(intValueSeek); GeneralRelatedListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); if (intPref > 0 && intPref < 101){ GeneralRelatedListPref.erase(intValueSeek); GeneralRelatedListPref.insert(std::make_pair(intValueSeek, intPref)); } } else if (PropertyName == wxT("LANGUAGE")){ GeneralRelatedListLanguage.erase(intValueSeek); GeneralRelatedListLanguage.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); } } } } // Split the address. //std::map::iterator SLiter; intPropertyLen = wxSPropertySeg2.Len(); SplitPoints.clear(); SplitLength.clear(); intSplitsFound = 0; intSplitSize = 0; intPrevValue = 0; // Add the data to the General/Home/Work address variables. wxListItem coldata; coldata.SetId(intValueSeek); coldata.SetData(intValueSeek); coldata.SetText(RelatedType); ProcessCaptureStrings(&wxSPropertySeg2); ListCtrlIndex = lboRelated->InsertItem(coldata); lboRelated->SetItem(ListCtrlIndex, 1, wxSPropertySeg2); if (intPref > 0 && intPref < 101){ lboRelated->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref)); } GeneralRelatedList.erase(intValueSeek); GeneralRelatedListRelType.erase(intValueSeek); GeneralRelatedListType.erase(intValueSeek); GeneralRelatedListTokens.erase(intValueSeek); GeneralRelatedList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); GeneralRelatedListRelType.insert(std::make_pair(intValueSeek, RelatedTypeOriginal)); GeneralRelatedListType.insert(std::make_pair(intValueSeek, RelatedTypeOriginal)); GeneralRelatedListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); RelatedCount++; intValueSeek++; }