// frmContactEditor-LoadNote.cpp - frmContactEditor load note 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::LoadNote(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *NoteCount){ std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; bool FirstToken = TRUE; int intPrevValue = 6; int intPref = 0; int intType = 0; long ListCtrlIndex; SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue); intPrevValue = 5; // 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){ GeneralNoteList.insert(std::make_pair(intValueSeek, wxT(""))); GeneralNoteListAltID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralNoteListPID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralNoteListPref.insert(std::make_pair(intValueSeek, 0)); GeneralNoteListTokens.insert(std::make_pair(intValueSeek, wxT(""))); GeneralNoteListLanguage.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 1){ HomeNoteList.insert(std::make_pair(intValueSeek, wxT(""))); HomeNoteListAltID.insert(std::make_pair(intValueSeek, wxT(""))); HomeNoteListPID.insert(std::make_pair(intValueSeek, wxT(""))); HomeNoteListPref.insert(std::make_pair(intValueSeek, 0)); HomeNoteListTokens.insert(std::make_pair(intValueSeek, wxT(""))); HomeNoteListLanguage.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 2){ BusinessNoteList.insert(std::make_pair(intValueSeek, wxT(""))); BusinessNoteListAltID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessNoteListPID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessNoteListPref.insert(std::make_pair(intValueSeek, 0)); BusinessNoteListTokens.insert(std::make_pair(intValueSeek, wxT(""))); BusinessNoteListLanguage.insert(std::make_pair(intValueSeek, wxT(""))); } intPrevValue = 5; 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){ GeneralNoteListAltID.erase(intValueSeek); GeneralNoteListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeNoteListAltID.erase(intValueSeek); HomeNoteListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessNoteListAltID.erase(intValueSeek); BusinessNoteListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PID")){ if (intType == 0){ GeneralNoteListPID.erase(intValueSeek); GeneralNoteListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeNoteListPID.erase(intValueSeek); HomeNoteListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessNoteListPID.erase(intValueSeek); BusinessNoteListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); if (intType == 0){ GeneralNoteListPref.erase(intValueSeek); GeneralNoteListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 1){ HomeNoteListPref.erase(intValueSeek); HomeNoteListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 2){ BusinessNoteListPref.erase(intValueSeek); BusinessNoteListPref.insert(std::make_pair(intValueSeek, intPref)); } } else if (PropertyName == wxT("LANGUAGE")){ if (intType == 0){ GeneralNoteListLanguage.erase(intValueSeek); GeneralNoteListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeNoteListLanguage.erase(intValueSeek); HomeNoteListLanguage.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessNoteListLanguage.erase(intValueSeek); BusinessNoteListLanguage.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. ProcessCaptureStrings(&wxSPropertySeg2); wxListItem coldata; coldata.SetId(intValueSeek); coldata.SetData(intValueSeek); if (intType == 0){ GeneralNoteList.erase(intValueSeek); GeneralNoteListType.erase(intValueSeek); GeneralNoteListTokens.erase(intValueSeek); GeneralNoteList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); GeneralNoteListType.insert(std::make_pair(intValueSeek, wxT(""))); GeneralNoteListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); //CaptureString(&wxSPropertySeg2, FALSE); coldata.SetText(wxSPropertySeg2); ListCtrlIndex = lboNotes->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboNotes->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } } else if (intType == 1){ HomeNoteList.erase(intValueSeek); HomeNoteListType.erase(intValueSeek); HomeNoteListTokens.erase(intValueSeek); HomeNoteList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); HomeNoteListType.insert(std::make_pair(intValueSeek, wxT("home"))); HomeNoteListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); CaptureString(&wxSPropertySeg2, FALSE); coldata.SetText(wxSPropertySeg2); ListCtrlIndex = lboHomeNotes->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboHomeNotes->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } } else if (intType == 2){ BusinessNoteList.erase(intValueSeek); BusinessNoteListType.erase(intValueSeek); BusinessNoteListTokens.erase(intValueSeek); BusinessNoteList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); BusinessNoteListType.insert(std::make_pair(intValueSeek, wxT("work"))); BusinessNoteListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); CaptureString(&wxSPropertySeg2, FALSE); coldata.SetText(wxSPropertySeg2); ListCtrlIndex = lboBusinessNotes->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboBusinessNotes->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } } NoteCount++; intValueSeek++; }