// frmContactEditor-LoadURL.cpp - frmContactEditor load URL 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::LoadURL(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *URLCount){ 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){ GeneralWebsiteList.insert(std::make_pair(intValueSeek, wxT(""))); GeneralWebsiteListAltID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralWebsiteListPID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralWebsiteListPref.insert(std::make_pair(intValueSeek, 0)); GeneralWebsiteListTokens.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 1){ HomeWebsiteList.insert(std::make_pair(intValueSeek, wxT(""))); HomeWebsiteListAltID.insert(std::make_pair(intValueSeek, wxT(""))); HomeWebsiteListPID.insert(std::make_pair(intValueSeek, wxT(""))); HomeWebsiteListPref.insert(std::make_pair(intValueSeek, 0)); HomeWebsiteListTokens.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 2){ BusinessWebsiteList.insert(std::make_pair(intValueSeek, wxT(""))); BusinessWebsiteListAltID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessWebsiteListPID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessWebsiteListPref.insert(std::make_pair(intValueSeek, 0)); BusinessWebsiteListTokens.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){ GeneralWebsiteListAltID.erase(intValueSeek); GeneralWebsiteListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeWebsiteListAltID.erase(intValueSeek); HomeWebsiteListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessWebsiteListAltID.erase(intValueSeek); BusinessWebsiteListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PID")){ if (intType == 0){ GeneralWebsiteListPID.erase(intValueSeek); GeneralWebsiteListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeWebsiteListPID.erase(intValueSeek); HomeWebsiteListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessWebsiteListPID.erase(intValueSeek); BusinessWebsiteListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); if (intType == 0){ GeneralWebsiteListPref.erase(intValueSeek); GeneralWebsiteListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 1){ HomeWebsiteListPref.erase(intValueSeek); HomeWebsiteListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 2){ BusinessWebsiteListPref.erase(intValueSeek); BusinessWebsiteListPref.insert(std::make_pair(intValueSeek, intPref)); } } else if (PropertyName == wxT("MEDIATYPE")){ if (intType == 0){ GeneralWebsiteListMediatype.erase(intValueSeek); GeneralWebsiteListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeWebsiteListMediatype.erase(intValueSeek); HomeWebsiteListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessWebsiteListMediatype.erase(intValueSeek); BusinessWebsiteListMediatype.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); coldata.SetText(wxSPropertySeg2); if (intType == 0){ ListCtrlIndex = lboWebsites->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboWebsites->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } GeneralWebsiteList.erase(intValueSeek); GeneralWebsiteListType.erase(intValueSeek); GeneralWebsiteListTokens.erase(intValueSeek); GeneralWebsiteList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); GeneralWebsiteListType.insert(std::make_pair(intValueSeek, wxT(""))); GeneralWebsiteListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } else if (intType == 1){ ListCtrlIndex = lboHomeWebsites->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboHomeWebsites->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } HomeWebsiteList.erase(intValueSeek); HomeWebsiteListType.erase(intValueSeek); HomeWebsiteListTokens.erase(intValueSeek); HomeWebsiteList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); HomeWebsiteListType.insert(std::make_pair(intValueSeek, wxT("home"))); HomeWebsiteListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } else if (intType == 2){ ListCtrlIndex = lboBusinessWebsites->InsertItem(coldata); if (intPref > 0 && intPref < 101){ lboBusinessWebsites->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref)); } BusinessWebsiteList.erase(intValueSeek); BusinessWebsiteListType.erase(intValueSeek); BusinessWebsiteListTokens.erase(intValueSeek); BusinessWebsiteList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); BusinessWebsiteListType.insert(std::make_pair(intValueSeek, wxT("work"))); BusinessWebsiteListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } URLCount++; intValueSeek++; }