// frmContactEditor-LoadOrg.cpp - frmContactEditor load organisation 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::LoadOrg(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *OrgCount){ std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; bool FirstToken = TRUE; int intPrevValue = 5; int intPref = 0; int intType = 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")){ 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){ GeneralOrganisationsList.insert(std::make_pair(intValueSeek, wxT(""))); GeneralOrganisationsListAltID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralOrganisationsListPID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralOrganisationsListPref.insert(std::make_pair(intValueSeek, 0)); GeneralOrganisationsListTokens.insert(std::make_pair(intValueSeek, wxT(""))); GeneralOrganisationsListLanguage.insert(std::make_pair(intValueSeek, wxT(""))); GeneralOrganisationsListSortAs.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 1){ HomeOrganisationsList.insert(std::make_pair(intValueSeek, wxT(""))); HomeOrganisationsListAltID.insert(std::make_pair(intValueSeek, wxT(""))); HomeOrganisationsListPID.insert(std::make_pair(intValueSeek, wxT(""))); HomeOrganisationsListPref.insert(std::make_pair(intValueSeek, 0)); HomeOrganisationsListTokens.insert(std::make_pair(intValueSeek, wxT(""))); HomeOrganisationsListLanguage.insert(std::make_pair(intValueSeek, wxT(""))); HomeOrganisationsListSortAs.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 2){ BusinessOrganisationsList.insert(std::make_pair(intValueSeek, wxT(""))); BusinessOrganisationsListAltID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessOrganisationsListPID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessOrganisationsListPref.insert(std::make_pair(intValueSeek, 0)); BusinessOrganisationsListTokens.insert(std::make_pair(intValueSeek, wxT(""))); BusinessOrganisationsListLanguage.insert(std::make_pair(intValueSeek, wxT(""))); BusinessOrganisationsListSortAs.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; // 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){ GeneralOrganisationsListAltID.erase(intValueSeek); GeneralOrganisationsListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeOrganisationsListAltID.erase(intValueSeek); HomeOrganisationsListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessOrganisationsListAltID.erase(intValueSeek); BusinessOrganisationsListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PID")){ if (intType == 0){ GeneralOrganisationsListPID.erase(intValueSeek); GeneralOrganisationsListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeOrganisationsListPID.erase(intValueSeek); HomeOrganisationsListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessOrganisationsListPID.erase(intValueSeek); BusinessOrganisationsListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); if (intType == 0){ GeneralOrganisationsListPref.erase(intValueSeek); GeneralOrganisationsListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 1){ HomeOrganisationsListPref.erase(intValueSeek); HomeOrganisationsListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 2){ BusinessOrganisationsListPref.erase(intValueSeek); BusinessOrganisationsListPref.insert(std::make_pair(intValueSeek, intPref)); } } else if (PropertyName == wxT("LANGUAGE")){ if (intType == 0){ GeneralOrganisationsListLanguage.erase(intValueSeek); GeneralOrganisationsListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeOrganisationsListLanguage.erase(intValueSeek); HomeOrganisationsListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessOrganisationsListLanguage.erase(intValueSeek); BusinessOrganisationsListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("SORT-AS")){ if (intType == 0){ GeneralOrganisationsListSortAs.erase(intValueSeek); GeneralOrganisationsListSortAs.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeOrganisationsListSortAs.erase(intValueSeek); HomeOrganisationsListSortAs.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessOrganisationsListSortAs.erase(intValueSeek); BusinessOrganisationsListSortAs.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; ProcessCaptureStrings(&wxSPropertySeg2); coldata.SetId(intValueSeek); coldata.SetData(intValueSeek); coldata.SetText(wxSPropertySeg2); if (intType == 0){ ListCtrlIndex = lboOrganisations->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboOrganisations->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } GeneralOrganisationsList.erase(intValueSeek); GeneralOrganisationsListType.erase(intValueSeek); GeneralOrganisationsListTokens.erase(intValueSeek); GeneralOrganisationsList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); GeneralOrganisationsListType.insert(std::make_pair(intValueSeek, wxT(""))); GeneralOrganisationsListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } else if (intType == 1){ ListCtrlIndex = lboHomeOrganisations->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboHomeOrganisations->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } HomeOrganisationsList.erase(intValueSeek); HomeOrganisationsListType.erase(intValueSeek); HomeOrganisationsListTokens.erase(intValueSeek); HomeOrganisationsList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); HomeOrganisationsListType.insert(std::make_pair(intValueSeek, wxT("home"))); HomeOrganisationsListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } else if (intType == 2){ ListCtrlIndex = lboBusinessOrganisations->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboBusinessOrganisations->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } BusinessOrganisationsList.erase(intValueSeek); BusinessOrganisationsListType.erase(intValueSeek); BusinessOrganisationsListTokens.erase(intValueSeek); BusinessOrganisationsList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); BusinessOrganisationsListType.insert(std::make_pair(intValueSeek, wxT("work"))); BusinessOrganisationsListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } OrgCount++; intValueSeek++; }