1 // frmContactEditor-LoadEmail.cpp - frmContactEditor load email subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmContactEditor.h"
21 void frmContactEditor::LoadEmail(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *EmailCount){
23 size_t intPropertyLen = wxSPropertySeg1.Len();
24 std::map<int, int> SplitPoints;
25 std::map<int, int> SplitLength;
26 std::map<int, int>::iterator SLiter;
27 std::map<int, int>::iterator SPoint;
28 wxString PropertyData;
29 wxString PropertyName;
30 wxString PropertyValue;
31 wxString PropertyTokens;
32 wxString AddressLabel;
34 wxString AddressAltID;
36 wxString AddressTokens;
38 wxString AddressTimezone;
40 wxString AddressMediatype;
41 wxString AddressPOBox;
42 wxString AddressExtended;
43 wxString AddressStreet;
44 wxString AddressLocality;
46 wxString AddressRegion;
47 wxString AddressPostalCode;
48 wxString AddressCountry;
49 bool FirstToken = TRUE;
50 int intSplitsFound = 0;
57 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
61 // Look for type before continuing.
63 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
64 intiter != SplitPoints.end(); ++intiter){
66 SLiter = SplitLength.find(intiter->first);
68 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
70 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
71 PropertyName = PropertyElement.GetNextToken();
72 PropertyValue = PropertyElement.GetNextToken();
74 intPrevValue = intiter->second;
76 if (PropertyName == wxT("TYPE")){
78 if (PropertyValue == wxT("work")){
82 } else if (PropertyValue == wxT("home")){
96 // Setup blank lines for later on.
100 GeneralEmailList.insert(std::make_pair(intValueSeek, wxT("")));
101 GeneralEmailListAltID.insert(std::make_pair(intValueSeek, wxT("")));
102 GeneralEmailListPID.insert(std::make_pair(intValueSeek, wxT("")));
103 GeneralEmailListPref.insert(std::make_pair(intValueSeek, 0));
104 GeneralEmailListTokens.insert(std::make_pair(intValueSeek, wxT("")));
106 } else if (intType == 1){
108 HomeEmailList.insert(std::make_pair(intValueSeek, wxT("")));
109 HomeEmailListAltID.insert(std::make_pair(intValueSeek, wxT("")));
110 HomeEmailListPID.insert(std::make_pair(intValueSeek, wxT("")));
111 HomeEmailListPref.insert(std::make_pair(intValueSeek, 0));
112 HomeEmailListTokens.insert(std::make_pair(intValueSeek, wxT("")));
114 } else if (intType == 2){
116 BusinessEmailList.insert(std::make_pair(intValueSeek, wxT("")));
117 BusinessEmailListAltID.insert(std::make_pair(intValueSeek, wxT("")));
118 BusinessEmailListPID.insert(std::make_pair(intValueSeek, wxT("")));
119 BusinessEmailListPref.insert(std::make_pair(intValueSeek, 0));
120 BusinessEmailListTokens.insert(std::make_pair(intValueSeek, wxT("")));
126 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
127 intiter != SplitPoints.end(); ++intiter){
129 SLiter = SplitLength.find(intiter->first);
131 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
133 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
134 PropertyName = PropertyElement.GetNextToken();
135 PropertyValue = PropertyElement.GetNextToken();
137 intPrevValue = intiter->second;
139 ProcessCaptureStrings(&PropertyValue);
141 // Process properties.
143 if (PropertyName == wxT("ALTID")){
145 if (intType == 0){ GeneralEmailListAltID.erase(intValueSeek); GeneralEmailListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
146 else if (intType == 1){ HomeEmailListAltID.erase(intValueSeek); HomeEmailListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
147 else if (intType == 2){ BusinessEmailListAltID.erase(intValueSeek); BusinessEmailListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
149 } else if (PropertyName == wxT("PID")){
151 if (intType == 0){ GeneralEmailListPID.erase(intValueSeek); GeneralEmailListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
152 else if (intType == 1){ HomeEmailListPID.erase(intValueSeek); HomeEmailListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
153 else if (intType == 2){ BusinessEmailListPID.erase(intValueSeek); BusinessEmailListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
155 } else if (PropertyName == wxT("PREF")){
157 intPref = wxAtoi(PropertyValue);
159 if (intPref > 0 && intPref < 101){
161 if (intType == 0){ GeneralEmailListPref.erase(intValueSeek); GeneralEmailListPref.insert(std::make_pair(intValueSeek, intPref)); }
162 else if (intType == 1){ HomeEmailListPref.erase(intValueSeek); HomeEmailListPref.insert(std::make_pair(intValueSeek, intPref)); }
163 else if (intType == 2){ BusinessEmailListPref.erase(intValueSeek); BusinessEmailListPref.insert(std::make_pair(intValueSeek, intPref)); }
169 // Something else we don't know about so append
170 // to the tokens variable.
172 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
174 if (FirstToken == TRUE){
176 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
181 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
191 //std::map<int, int>::iterator SLiter;
192 intPropertyLen = wxSPropertySeg2.Len();
199 // Add the data to the General/Home/Work email variables.
201 ProcessCaptureStrings(&wxSPropertySeg2);
205 coldata.SetId(intValueSeek);
206 coldata.SetData(intValueSeek);
207 coldata.SetText(wxSPropertySeg2);
213 ListCtrlIndex = lboEmails->InsertItem(coldata);
215 if (intPref > 0 && intPref < 101){
217 lboEmails->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
221 GeneralEmailList.erase(intValueSeek);
222 GeneralEmailListType.erase(intValueSeek);
223 GeneralEmailListTokens.erase(intValueSeek);
224 GeneralEmailList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
225 GeneralEmailListType.insert(std::make_pair(intValueSeek, wxT("")));
226 GeneralEmailListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
228 } else if (intType == 1){
230 ListCtrlIndex = lboHomeEmails->InsertItem(coldata);
232 if (intPref > 0 && intPref < 101){
234 lboHomeEmails->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
238 HomeEmailList.erase(intValueSeek);
239 HomeEmailListType.erase(intValueSeek);
240 HomeEmailListTokens.erase(intValueSeek);
241 HomeEmailList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
242 HomeEmailListType.insert(std::make_pair(intValueSeek, wxT("home")));
243 HomeEmailListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
245 } else if (intType == 2){
247 ListCtrlIndex = lboBusinessEmail->InsertItem(coldata);
249 if (intPref > 0 && intPref < 101){
251 lboBusinessEmail->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
255 BusinessEmailList.erase(intValueSeek);
256 BusinessEmailListType.erase(intValueSeek);
257 BusinessEmailListTokens.erase(intValueSeek);
258 BusinessEmailList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
259 BusinessEmailListType.insert(std::make_pair(intValueSeek, wxT("work")));
260 BusinessEmailListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));