// frmContactEditor-LoadIM.cpp - frmContactEditor load IM 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::LoadIM(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *IMPPCount){ size_t intPropertyLen = wxSPropertySeg1.Len(); std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; std::map::iterator SPoint; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; wxString IMPPType; wxString IMPPAddress; bool FirstToken = TRUE; int intSplitsFound = 0; int intSplitSize = 0; 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){ GeneralIMList.insert(std::make_pair(intValueSeek, wxT(""))); GeneralIMListAltID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralIMListPID.insert(std::make_pair(intValueSeek, wxT(""))); GeneralIMListPref.insert(std::make_pair(intValueSeek, 0)); GeneralIMListTokens.insert(std::make_pair(intValueSeek, wxT(""))); GeneralIMListMediatype.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 1){ HomeIMList.insert(std::make_pair(intValueSeek, wxT(""))); HomeIMListAltID.insert(std::make_pair(intValueSeek, wxT(""))); HomeIMListPID.insert(std::make_pair(intValueSeek, wxT(""))); HomeIMListPref.insert(std::make_pair(intValueSeek, 0)); HomeIMListTokens.insert(std::make_pair(intValueSeek, wxT(""))); HomeIMListMediatype.insert(std::make_pair(intValueSeek, wxT(""))); } else if (intType == 2){ BusinessIMList.insert(std::make_pair(intValueSeek, wxT(""))); BusinessIMListAltID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessIMListPID.insert(std::make_pair(intValueSeek, wxT(""))); BusinessIMListPref.insert(std::make_pair(intValueSeek, 0)); BusinessIMListTokens.insert(std::make_pair(intValueSeek, wxT(""))); BusinessIMListMediatype.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(); ProcessCaptureStrings(&PropertyValue); intPrevValue = intiter->second; // Process properties. if (PropertyName == wxT("ALTID")){ if (intType == 0){ GeneralIMListAltID.erase(intValueSeek); GeneralIMListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeIMListAltID.erase(intValueSeek); HomeIMListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessIMListAltID.erase(intValueSeek); BusinessIMListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PID")){ if (intType == 0){ GeneralIMListPID.erase(intValueSeek); GeneralIMListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeIMListPID.erase(intValueSeek); HomeIMListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessIMListPID.erase(intValueSeek); BusinessIMListPID.insert(std::make_pair(intValueSeek, PropertyValue)); } } else if (PropertyName == wxT("PREF")){ intPref = wxAtoi(PropertyValue); if (intPref > 0 && intPref < 101){ if (intType == 0){ GeneralIMListPref.erase(intValueSeek); GeneralIMListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 1){ HomeIMListPref.erase(intValueSeek); HomeIMListPref.insert(std::make_pair(intValueSeek, intPref)); } else if (intType == 2){ BusinessIMListPref.erase(intValueSeek); BusinessIMListPref.insert(std::make_pair(intValueSeek, intPref)); } } } else if (PropertyName == wxT("MEDIATYPE")){ if (intType == 0){ GeneralIMListMediatype.erase(intValueSeek); GeneralIMListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 1){ HomeIMListMediatype.erase(intValueSeek); HomeIMListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); } else if (intType == 2){ BusinessIMListMediatype.erase(intValueSeek); BusinessIMListMediatype.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; for (int i = 0; i <= intPropertyLen; i++){ intSplitSize++; if (wxSPropertySeg2.Mid(i, 1) == wxT(":") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){ intSplitsFound++; SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1))); if (intSplitsFound == 1){ SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1))); break; } intSplitSize = 0; } } // Split the data into several parts. for (std::map::iterator intiter = SplitPoints.begin(); intiter != SplitPoints.end(); ++intiter){ if (intiter->first == 1){ // Deal with PO Box. SLiter = SplitLength.find(1); //txtSurname->SetValue(ContactData.Convert(wxSPropertySeg2.Mid(0, SLiter->second), TRUE)); IMPPType = wxSPropertySeg2.Mid(0, SLiter->second); intPrevValue = intiter->second; IMPPAddress = wxSPropertySeg2.Mid(intPrevValue); } } // Check what IM type it is. if (IMPPType == wxT("aim")){ IMPPType = wxT("AIM"); } else if (IMPPType == wxT("gg")){ IMPPType = wxT("Gadu-Gadu"); } else if (IMPPType == wxT("icq")){ IMPPType = wxT("ICQ"); } else if (IMPPType == wxT("skype")){ IMPPType = wxT("Skype"); } else if (IMPPType == wxT("xmpp")){ IMPPType = wxT("XMPP"); } else if (IMPPType == wxT("yahoo")){ IMPPType = wxT("Yahoo"); } else { // Do nothing. } // Add the data to the General/Home/Work address variables. ProcessCaptureStrings(&wxSPropertySeg2); wxListItem coldata; coldata.SetId(intValueSeek); coldata.SetData(intValueSeek); coldata.SetText(IMPPType); if (intType == 0){ ListCtrlIndex = lboIM->InsertItem(coldata); lboIM->SetItem(ListCtrlIndex, 1, IMPPAddress); if (intPref > 0 && intPref < 101){ lboIM->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref)); } GeneralIMList.erase(intValueSeek); GeneralIMListType.erase(intValueSeek); GeneralIMListTokens.erase(intValueSeek); GeneralIMList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); GeneralIMListType.insert(std::make_pair(intValueSeek, wxT(""))); GeneralIMListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } else if (intType == 1){ ListCtrlIndex = lboHomeIM->InsertItem(coldata); lboHomeIM->SetItem(ListCtrlIndex, 1, IMPPAddress); if (intPref > 0 && intPref < 101){ lboHomeIM->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref)); } HomeIMList.erase(intValueSeek); HomeIMListType.erase(intValueSeek); HomeIMListTokens.erase(intValueSeek); HomeIMList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); HomeIMListType.insert(std::make_pair(intValueSeek, wxT("home"))); HomeIMListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } else if (intType == 2){ ListCtrlIndex = lboBusinessIM->InsertItem(coldata); lboBusinessIM->SetItem(ListCtrlIndex, 1, IMPPAddress); if (intPref > 0 && intPref < 101){ lboBusinessIM->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref)); } BusinessIMList.erase(intValueSeek); BusinessIMListType.erase(intValueSeek); BusinessIMListTokens.erase(intValueSeek); BusinessIMList.insert(std::make_pair(intValueSeek, wxSPropertySeg2)); BusinessIMListType.insert(std::make_pair(intValueSeek, wxT("work"))); BusinessIMListTokens.insert(std::make_pair(intValueSeek, PropertyTokens)); } *IMPPCount++; intValueSeek++; }