Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Replaced PREF code in IMPP for ProcessIntegerValue.
[xestiaab/.git] / source / contacteditor / frmContactEditor-LoadEmail.cpp
1 // frmContactEditor-LoadEmail.cpp - frmContactEditor load email subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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;
33         wxString AddressLang;
34         wxString AddressAltID;
35         wxString AddressPID;
36         wxString AddressTokens;
37         wxString AddressGeo;
38         wxString AddressTimezone;
39         wxString AddressType;
40         wxString AddressMediatype;
41         wxString AddressPOBox;
42         wxString AddressExtended;
43         wxString AddressStreet;
44         wxString AddressLocality;
45         wxString AddressCity;
46         wxString AddressRegion;
47         wxString AddressPostalCode;
48         wxString AddressCountry;
49         bool FirstToken = TRUE;
50         int intSplitsFound = 0;
51         int intSplitSize = 0;
52         int intPrevValue = 7;
53         int intPref = 0;                        
54         int intType = 0;
55         long ListCtrlIndex;
56         
57         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
58         
59         intPrevValue = 6;
60         
61         // Look for type before continuing.
62         
63         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
64         intiter != SplitPoints.end(); ++intiter){
65         
66                 SLiter = SplitLength.find(intiter->first);
67         
68                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
69                 
70                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
71                 PropertyName = PropertyElement.GetNextToken();                          
72                 PropertyValue = PropertyElement.GetNextToken();
73                 
74                 intPrevValue = intiter->second;
75                 
76                 if (PropertyName == wxT("TYPE")){
77                 
78                         if (PropertyValue == wxT("work")){
79                         
80                                 intType = 2;                                    
81                         
82                         } else if (PropertyValue == wxT("home")){
84                                 intType = 1;
85                         
86                         } else {
87                         
88                                 intType = 0;
89                         
90                         }
91                 
92                 }
93         
94         }
95         
96         // Setup blank lines for later on.
97         
98         if (intType == 0){
99         
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){
107         
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("")));
113         
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("")));
121         
122         }
123         
124         intPrevValue = 6;                       
125         
126         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
127         intiter != SplitPoints.end(); ++intiter){
128         
129                 SLiter = SplitLength.find(intiter->first);
130         
131                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
132                 
133                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
134                 PropertyName = PropertyElement.GetNextToken();                          
135                 PropertyValue = PropertyElement.GetNextToken();
136                 
137                 intPrevValue = intiter->second;
138                 
139                 ProcessCaptureStrings(&PropertyValue);
140                 
141                 // Process properties.
142                 
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)); }
148                 
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)); }
154                 
155                 } else if (PropertyName == wxT("PREF")){
156                         
157                         intPref = wxAtoi(PropertyValue);
158                         
159                         if (intPref > 0 && intPref < 101){
160                 
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)); }
164                                 
165                         }
166                 
167                 } else {
168                 
169                         // Something else we don't know about so append
170                         // to the tokens variable.
171                         
172                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
173                         
174                                 if (FirstToken == TRUE){
175                                 
176                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
177                                         FirstToken = FALSE;
178                                 
179                                 } else {
180                                 
181                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
182                                 
183                                 }
184                         
185                         }
186                 
187                 }
188         
189         } 
191         //std::map<int, int>::iterator SLiter;
192         intPropertyLen = wxSPropertySeg2.Len();
193         SplitPoints.clear();
194         SplitLength.clear();
195         intSplitsFound = 0;
196         intSplitSize = 0;
197         intPrevValue = 0;       
198         
199         // Add the data to the General/Home/Work email variables.
200         
201         ProcessCaptureStrings(&wxSPropertySeg2);
202         
203         wxListItem coldata;
205         coldata.SetId(intValueSeek);
206         coldata.SetData(intValueSeek);
207         coldata.SetText(wxSPropertySeg2);
208         
209         if (intType == 0){
210         
212         
213                 ListCtrlIndex = lboEmails->InsertItem(coldata);
214                 
215                 if (intPref > 0 && intPref < 101){
216                 
217                         lboEmails->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
218                         
219                 }
220                 
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));
227         
228         } else if (intType == 1){ 
229         
230                 ListCtrlIndex = lboHomeEmails->InsertItem(coldata);
232                 if (intPref > 0 && intPref < 101){
233                 
234                         lboHomeEmails->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
235                         
236                 }
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));
244         
245         } else if (intType == 2){ 
246         
247                 ListCtrlIndex = lboBusinessEmail->InsertItem(coldata);
249                 if (intPref > 0 && intPref < 101){
250                 
251                         lboBusinessEmail->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
252                         
253                 }
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));                           
261         
262         }
263         
264         EmailCount++;
265         intValueSeek++;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy