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(std::map<int, wxString> *GeneralEmailListPtr,
22 std::map<int, int> *GeneralEmailListPrefPtr,
23 std::map<int, wxString> *HomeEmailListPtr,
24 std::map<int, int> *HomeEmailListPrefPtr,
25 std::map<int, wxString> *BusinessEmailListPtr,
26 std::map<int, int> *BusinessEmailListPrefPtr,
29 long ListCtrlIndex = -1;
31 // Deal with the general addresses.
33 for (std::map<int,wxString>::iterator Iter = GeneralEmailListPtr->begin();
34 Iter != GeneralEmailListPtr->end();
39 coldata.SetId(*EmailCount);
40 coldata.SetData(*EmailCount);
41 coldata.SetText(Iter->second);
43 ListCtrlIndex = lboEmails->InsertItem(coldata);
45 if (MapDataExists(EmailCount, GeneralEmailListPrefPtr)){
47 lboEmails->SetItem(ListCtrlIndex, 1, wxString::Format("%i", GeneralEmailListPrefPtr->find(*EmailCount)->second));
55 // Deal with the home addresses.
57 for (std::map<int,wxString>::iterator Iter = HomeEmailListPtr->begin();
58 Iter != HomeEmailListPtr->end();
63 coldata.SetId(*EmailCount);
64 coldata.SetData(*EmailCount);
65 coldata.SetText(Iter->second);
67 ListCtrlIndex = lboHomeEmails->InsertItem(coldata);
69 if (MapDataExists(EmailCount, HomeEmailListPrefPtr)){
71 lboHomeEmails->SetItem(ListCtrlIndex, 1, wxString::Format("%i", HomeEmailListPrefPtr->find(*EmailCount)->second));
79 // Deal with the work addresses.
81 for (std::map<int,wxString>::iterator Iter = BusinessEmailListPtr->begin();
82 Iter != BusinessEmailListPtr->end();
87 coldata.SetId(*EmailCount);
88 coldata.SetData(*EmailCount);
89 coldata.SetText(Iter->second);
91 ListCtrlIndex = lboBusinessEmail->InsertItem(coldata);
93 if (MapDataExists(EmailCount, BusinessEmailListPrefPtr)){
95 lboBusinessEmail->SetItem(ListCtrlIndex, 1, wxString::Format("%i", BusinessEmailListPrefPtr->find(*EmailCount)->second));
105 void frmContactEditor::LoadEmail(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *EmailCount){
107 size_t intPropertyLen = wxSPropertySeg1.Len();
108 std::map<int, int> SplitPoints;
109 std::map<int, int> SplitLength;
110 std::map<int, int>::iterator SLiter;
111 std::map<int, int>::iterator SPoint;
112 wxString PropertyData;
113 wxString PropertyName;
114 wxString PropertyValue;
115 wxString PropertyTokens;
116 wxString AddressLabel;
117 wxString AddressLang;
118 wxString AddressAltID;
120 wxString AddressTokens;
122 wxString AddressTimezone;
123 wxString AddressType;
124 wxString AddressMediatype;
125 wxString AddressPOBox;
126 wxString AddressExtended;
127 wxString AddressStreet;
128 wxString AddressLocality;
129 wxString AddressCity;
130 wxString AddressRegion;
131 wxString AddressPostalCode;
132 wxString AddressCountry;
133 bool FirstToken = TRUE;
134 int intSplitsFound = 0;
135 int intSplitSize = 0;
136 int intPrevValue = 7;
141 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
145 // Look for type before continuing.
147 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
148 intiter != SplitPoints.end(); ++intiter){
150 SLiter = SplitLength.find(intiter->first);
152 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
154 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
155 PropertyName = PropertyElement.GetNextToken();
156 PropertyValue = PropertyElement.GetNextToken();
158 intPrevValue = intiter->second;
160 if (PropertyName == wxT("TYPE")){
162 if (PropertyValue == wxT("work")){
166 } else if (PropertyValue == wxT("home")){
180 // Setup blank lines for later on.
184 GeneralEmailList.insert(std::make_pair(intValueSeek, wxT("")));
185 GeneralEmailListAltID.insert(std::make_pair(intValueSeek, wxT("")));
186 GeneralEmailListPID.insert(std::make_pair(intValueSeek, wxT("")));
187 GeneralEmailListPref.insert(std::make_pair(intValueSeek, 0));
188 GeneralEmailListTokens.insert(std::make_pair(intValueSeek, wxT("")));
190 } else if (intType == 1){
192 HomeEmailList.insert(std::make_pair(intValueSeek, wxT("")));
193 HomeEmailListAltID.insert(std::make_pair(intValueSeek, wxT("")));
194 HomeEmailListPID.insert(std::make_pair(intValueSeek, wxT("")));
195 HomeEmailListPref.insert(std::make_pair(intValueSeek, 0));
196 HomeEmailListTokens.insert(std::make_pair(intValueSeek, wxT("")));
198 } else if (intType == 2){
200 BusinessEmailList.insert(std::make_pair(intValueSeek, wxT("")));
201 BusinessEmailListAltID.insert(std::make_pair(intValueSeek, wxT("")));
202 BusinessEmailListPID.insert(std::make_pair(intValueSeek, wxT("")));
203 BusinessEmailListPref.insert(std::make_pair(intValueSeek, 0));
204 BusinessEmailListTokens.insert(std::make_pair(intValueSeek, wxT("")));
210 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
211 intiter != SplitPoints.end(); ++intiter){
213 SLiter = SplitLength.find(intiter->first);
215 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
217 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
218 PropertyName = PropertyElement.GetNextToken();
219 PropertyValue = PropertyElement.GetNextToken();
221 intPrevValue = intiter->second;
223 ProcessCaptureStrings(&PropertyValue);
225 // Process properties.
227 if (PropertyName == wxT("ALTID")){
229 if (intType == 0){ GeneralEmailListAltID.erase(intValueSeek); GeneralEmailListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
230 else if (intType == 1){ HomeEmailListAltID.erase(intValueSeek); HomeEmailListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
231 else if (intType == 2){ BusinessEmailListAltID.erase(intValueSeek); BusinessEmailListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
233 } else if (PropertyName == wxT("PID")){
235 if (intType == 0){ GeneralEmailListPID.erase(intValueSeek); GeneralEmailListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
236 else if (intType == 1){ HomeEmailListPID.erase(intValueSeek); HomeEmailListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
237 else if (intType == 2){ BusinessEmailListPID.erase(intValueSeek); BusinessEmailListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
239 } else if (PropertyName == wxT("PREF")){
241 intPref = wxAtoi(PropertyValue);
243 if (intPref > 0 && intPref < 101){
245 if (intType == 0){ GeneralEmailListPref.erase(intValueSeek); GeneralEmailListPref.insert(std::make_pair(intValueSeek, intPref)); }
246 else if (intType == 1){ HomeEmailListPref.erase(intValueSeek); HomeEmailListPref.insert(std::make_pair(intValueSeek, intPref)); }
247 else if (intType == 2){ BusinessEmailListPref.erase(intValueSeek); BusinessEmailListPref.insert(std::make_pair(intValueSeek, intPref)); }
253 // Something else we don't know about so append
254 // to the tokens variable.
256 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
258 if (FirstToken == TRUE){
260 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
265 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
275 //std::map<int, int>::iterator SLiter;
276 intPropertyLen = wxSPropertySeg2.Len();
283 // Add the data to the General/Home/Work email variables.
285 ProcessCaptureStrings(&wxSPropertySeg2);
289 coldata.SetId(intValueSeek);
290 coldata.SetData(intValueSeek);
291 coldata.SetText(wxSPropertySeg2);
297 ListCtrlIndex = lboEmails->InsertItem(coldata);
299 if (intPref > 0 && intPref < 101){
301 lboEmails->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
305 GeneralEmailList.erase(intValueSeek);
306 GeneralEmailListType.erase(intValueSeek);
307 GeneralEmailListTokens.erase(intValueSeek);
308 GeneralEmailList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
309 GeneralEmailListType.insert(std::make_pair(intValueSeek, wxT("")));
310 GeneralEmailListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
312 } else if (intType == 1){
314 ListCtrlIndex = lboHomeEmails->InsertItem(coldata);
316 if (intPref > 0 && intPref < 101){
318 lboHomeEmails->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
322 HomeEmailList.erase(intValueSeek);
323 HomeEmailListType.erase(intValueSeek);
324 HomeEmailListTokens.erase(intValueSeek);
325 HomeEmailList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
326 HomeEmailListType.insert(std::make_pair(intValueSeek, wxT("home")));
327 HomeEmailListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
329 } else if (intType == 2){
331 ListCtrlIndex = lboBusinessEmail->InsertItem(coldata);
333 if (intPref > 0 && intPref < 101){
335 lboBusinessEmail->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
339 BusinessEmailList.erase(intValueSeek);
340 BusinessEmailListType.erase(intValueSeek);
341 BusinessEmailListTokens.erase(intValueSeek);
342 BusinessEmailList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
343 BusinessEmailListType.insert(std::make_pair(intValueSeek, wxT("work")));
344 BusinessEmailListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));