Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Replaced PREF code for SOURCE with ProcessIntegerValue.
[xestiaab/.git] / source / contacteditor / frmContactEditor-LoadTimeZone.cpp
1 // frmContactEditor-LoadTimeZone.cpp - frmContactEditor load timezone 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"
20                         
21 void frmContactEditor::LoadTimeZone(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *TZCount){
22                         
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                         wxString PropertyData;
28                         wxString PropertyName;
29                         wxString PropertyValue;
30                         wxString PropertyTokens;
31                         bool FirstToken = TRUE;                 
32                         int intSplitsFound = 0;
33                         int intSplitSize = 0;
34                         int intPrevValue = 4;
35                         int intPref = 0;                        
36                         int intType = 0;
37                         long ListCtrlIndex;
38                         
39                         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
40                         
41                         intPrevValue = 3;
42                         
43                         // Look for type before continuing.
44                         
45                         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
46                         intiter != SplitPoints.end(); ++intiter){
47                         
48                                 SLiter = SplitLength.find(intiter->first);
49                         
50                                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
51                                 
52                                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
53                                 PropertyName = PropertyElement.GetNextToken();                          
54                                 PropertyValue = PropertyElement.GetNextToken();
55                                 
56                                 intPrevValue = intiter->second;
57                                 
58                                 if (PropertyName == wxT("TYPE")){
59                                 
60                                         if (PropertyValue == wxT("work")){
61                                         
62                                                 intType = 2;                                    
63                                         
64                                         } else if (PropertyValue == wxT("home")){
66                                                 intType = 1;
67                                         
68                                         } else {
69                                         
70                                                 intType = 0;
71                                         
72                                         }
73                                 
74                                 }
75                         
76                         }
77                         
78                         // Setup blank lines for later on.
79                         
80                         if (intType == 0){
81                         
82                                 GeneralTZList.insert(std::make_pair(intValueSeek, wxT("")));
83                                 GeneralTZListAltID.insert(std::make_pair(intValueSeek, wxT("")));
84                                 GeneralTZListPID.insert(std::make_pair(intValueSeek, wxT("")));
85                                 GeneralTZListPref.insert(std::make_pair(intValueSeek, 0));
86                                 GeneralTZListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
87                                 GeneralTZListTokens.insert(std::make_pair(intValueSeek, wxT("")));
89                         } else if (intType == 1){
90                         
91                                 HomeTZList.insert(std::make_pair(intValueSeek, wxT("")));
92                                 HomeTZListAltID.insert(std::make_pair(intValueSeek, wxT("")));
93                                 HomeTZListPID.insert(std::make_pair(intValueSeek, wxT("")));
94                                 HomeTZListPref.insert(std::make_pair(intValueSeek, 0));
95                                 HomeTZListMediatype.insert(std::make_pair(intValueSeek, wxT("")));                              
96                                 HomeTZListTokens.insert(std::make_pair(intValueSeek, wxT("")));
97                         
98                         } else if (intType == 2){
100                                 BusinessTZList.insert(std::make_pair(intValueSeek, wxT("")));
101                                 BusinessTZListAltID.insert(std::make_pair(intValueSeek, wxT("")));
102                                 BusinessTZListPID.insert(std::make_pair(intValueSeek, wxT("")));
103                                 BusinessTZListPref.insert(std::make_pair(intValueSeek, 0));
104                                 BusinessTZListMediatype.insert(std::make_pair(intValueSeek, wxT("")));                          
105                                 BusinessTZListTokens.insert(std::make_pair(intValueSeek, wxT("")));
106                         
107                         }
108                         
109                         intPrevValue = 3;
110                         
111                         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
112                         intiter != SplitPoints.end(); ++intiter){
113                         
114                                 SLiter = SplitLength.find(intiter->first);
115                         
116                                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
117                                 
118                                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
119                                 PropertyName = PropertyElement.GetNextToken();                          
120                                 PropertyValue = PropertyElement.GetNextToken();
121                                 
122                                 intPrevValue = intiter->second;
123                                 
124                                 size_t intPropertyValueLen = PropertyValue.Len();
125                                 
126                                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
127                                         
128                                         PropertyValue.Trim();
129                                         PropertyValue.RemoveLast();
130                                         
131                                 }                               
132                                 
133                                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
134                                         
135                                         PropertyValue.Remove(0, 1);
136                                         
137                                 }                               
138                                 
139                                 ProcessCaptureStrings(&PropertyValue);
140                                 
141                                 // Process properties.
142                                 
143                                 if (PropertyName == wxT("ALTID")){
145                                         if (intType == 0){ GeneralTZListAltID.erase(intValueSeek); GeneralTZListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
146                                         else if (intType == 1){ HomeTZListAltID.erase(intValueSeek); HomeTZListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
147                                         else if (intType == 2){ BusinessTZListAltID.erase(intValueSeek); BusinessTZListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
148                                 
149                                 } else if (PropertyName == wxT("PID")){
151                                         if (intType == 0){ GeneralTZListPID.erase(intValueSeek); GeneralTZListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
152                                         else if (intType == 1){ HomeTZListPID.erase(intValueSeek); HomeTZListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
153                                         else if (intType == 2){ BusinessTZListPID.erase(intValueSeek); BusinessTZListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
154                                 
155                                 } else if (PropertyName == wxT("MEDIATYPE")){
156                                 
157                                         if (intType == 0){ GeneralTZListMediatype.erase(intValueSeek); GeneralTZListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
158                                         else if (intType == 1){ HomeTZListMediatype.erase(intValueSeek); HomeTZListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
159                                         else if (intType == 2){ BusinessTZListMediatype.erase(intValueSeek); BusinessTZListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
160                                 
161                                 } else if (PropertyName == wxT("PREF")){
162                                         
163                                         intPref = wxAtoi(PropertyValue);
164                                 
165                                         if (intPref > 0 && intPref < 101){
166                                 
167                                                 if (intType == 0){ GeneralTZListPref.erase(intValueSeek); GeneralTZListPref.insert(std::make_pair(intValueSeek, intPref)); }
168                                                 else if (intType == 1){ HomeTZListPref.erase(intValueSeek); HomeTZListPref.insert(std::make_pair(intValueSeek, intPref)); }
169                                                 else if (intType == 2){ BusinessTZListPref.erase(intValueSeek); BusinessTZListPref.insert(std::make_pair(intValueSeek, intPref)); }
170                                         
171                                         }
172                                 
173                                 } else {
174                                 
175                                         // Something else we don't know about so append
176                                         // to the tokens variable.
177                                         
178                                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
179                                         
180                                                 if (FirstToken == TRUE){
181                                                 
182                                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
183                                                         FirstToken = FALSE;
184                                                 
185                                                 } else {
186                                                 
187                                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
188                                                 
189                                                 }
190                                         
191                                         }
192                                 
193                                 }
194                         
195                         }                       
196                         
197                         // Split the address. 
198                 
199                         //std::map<int, int>::iterator SLiter;
200                         intPropertyLen = wxSPropertySeg2.Len();
201                         SplitPoints.clear();
202                         SplitLength.clear();
203                         intSplitsFound = 0;
204                         intSplitSize = 0;
205                         intPrevValue = 0;
206                         
207                         for (int i = 0; i <= intPropertyLen; i++){
208                 
209                                 intSplitSize++;
210                         
211                                 if (wxSPropertySeg2.Mid(i, 1) == wxT(";") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
212                         
213                                         intSplitsFound++;
214                                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
215                                         
216                                         if (intSplitsFound == 6){ 
217                                         
218                                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
219                                                 break; 
220                                                 
221                                         } else {
222                                         
223                                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
224                                         
225                                         }
226                                         
227                                         intSplitSize = 0;                                       
228                         
229                                 }
230                 
231                         }       
232                         
233                         // Add the data to the General/Home/Work address variables.
234                         
235                         ProcessCaptureStrings(&wxSPropertySeg2);                        
236                         
237                         wxListItem coldata;
238                 
239                         coldata.SetId(intValueSeek);
240                         coldata.SetData(intValueSeek);
241                         coldata.SetText(wxSPropertySeg2);
242                         
243                         if (intType == 0){
244                         
245                                 ListCtrlIndex = lboTimezones->InsertItem(coldata);
246                                 
247                                 if (intPref > 0 && intPref < 101){
248                                 
249                                         lboTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
250                                         
251                                 }
252                                 
253                                 GeneralTZList.erase(intValueSeek);
254                                 GeneralTZListType.erase(intValueSeek);
255                                 GeneralTZListTokens.erase(intValueSeek);
256                                 GeneralTZList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
257                                 GeneralTZListType.insert(std::make_pair(intValueSeek, wxT("")));
258                                 GeneralTZListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
259                         
260                         } else if (intType == 1){ 
261                         
262                                 ListCtrlIndex = lboHomeTimezones->InsertItem(coldata);
264                                 if (intPref > 0 && intPref < 101){
265                                 
266                                         lboHomeTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
267                                         
268                                 }
270                                 HomeTZList.erase(intValueSeek);
271                                 HomeTZListType.erase(intValueSeek);
272                                 HomeTZListTokens.erase(intValueSeek);                           
273                                 HomeTZList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
274                                 HomeTZListType.insert(std::make_pair(intValueSeek, wxT("home")));
275                                 HomeTZListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
276                         
277                         } else if (intType == 2){ 
278                         
279                                 ListCtrlIndex = lboBusinessTimezones->InsertItem(coldata);
281                                 if (intPref > 0 && intPref < 101){
282                                 
283                                         lboBusinessTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
284                                         
285                                 }
287                                 BusinessTZList.erase(intValueSeek);
288                                 BusinessTZListType.erase(intValueSeek);
289                                 BusinessTZListTokens.erase(intValueSeek);                               
290                                 BusinessTZList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
291                                 BusinessTZListType.insert(std::make_pair(intValueSeek, wxT("work")));
292                                 BusinessTZListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));                              
293                         
294                         }
295                 
296                         TZCount++;
297                         intValueSeek++; 
298                         
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