Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Implemented loading for TZ using ContactDataObject.
[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"
21 void frmContactEditor::LoadTimeZone(std::map<int, wxString> *GeneralTZListPtr,
22                 std::map<int, int> *GeneralTZListPrefPtr,
23                 std::map<int, wxString> *HomeTZListPtr,
24                 std::map<int, int> *HomeTZListPrefPtr,
25                 std::map<int, wxString> *BusinessTZListPtr,
26                 std::map<int, int> *BusinessTZListPrefPtr,
27                 int *TZCount){
29         long ListCtrlIndex = -1;
31         // Deal with the general addresses.
32         
33         for (std::map<int,wxString>::iterator Iter = GeneralTZListPtr->begin();
34                 Iter != GeneralTZListPtr->end();
35                 Iter++){
36         
37                 wxListItem coldata;
39                 coldata.SetId(*TZCount);
40                 coldata.SetData(*TZCount);
41                 coldata.SetText(Iter->second);
42                 
43                 ListCtrlIndex = lboTimezones->InsertItem(coldata);
45                 if (MapDataExists(TZCount, GeneralTZListPrefPtr)){
46                 
47                         lboTimezones->SetItem(ListCtrlIndex, 1, wxString::Format("%i", GeneralTZListPrefPtr->find(*TZCount)->second));
48                 
49                 }
50         
51                 (*TZCount)++;
52         
53         }
54         
55         // Deal with the home addresses.
56         
57         for (std::map<int,wxString>::iterator Iter = HomeTZListPtr->begin();
58                 Iter != HomeTZListPtr->end();
59                 Iter++){
60         
61                 wxListItem coldata;
63                 coldata.SetId(*TZCount);
64                 coldata.SetData(*TZCount);
65                 coldata.SetText(Iter->second);
66                 
67                 ListCtrlIndex = lboHomeTimezones->InsertItem(coldata);
69                 if (MapDataExists(TZCount, HomeTZListPrefPtr)){
70                 
71                         lboHomeTimezones->SetItem(ListCtrlIndex, 1, wxString::Format("%i", HomeTZListPrefPtr->find(*TZCount)->second));
72                 
73                 }
74         
75                 (*TZCount)++;
76         
77         }
78         
79         // Deal with the work addresses.
80         
81         for (std::map<int,wxString>::iterator Iter = BusinessTZListPtr->begin();
82                 Iter != BusinessTZListPtr->end();
83                 Iter++){
84         
85                 wxListItem coldata;
87                 coldata.SetId(*TZCount);
88                 coldata.SetData(*TZCount);
89                 coldata.SetText(Iter->second);
90                 
91                 ListCtrlIndex = lboBusinessTimezones->InsertItem(coldata);
92                                 
93                 if (MapDataExists(TZCount, BusinessTZListPrefPtr)){
94                 
95                         lboBusinessTimezones->SetItem(ListCtrlIndex, 1, wxString::Format("%i", BusinessTZListPrefPtr->find(*TZCount)->second));
96                 
97                 }
98         
99                 (*TZCount)++;
100         
101         }
102                 
105 void frmContactEditor::LoadTimeZone(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *TZCount){
106                         
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                         wxString PropertyData;
112                         wxString PropertyName;
113                         wxString PropertyValue;
114                         wxString PropertyTokens;
115                         bool FirstToken = TRUE;                 
116                         int intSplitsFound = 0;
117                         int intSplitSize = 0;
118                         int intPrevValue = 4;
119                         int intPref = 0;                        
120                         int intType = 0;
121                         long ListCtrlIndex;
122                         
123                         SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
124                         
125                         intPrevValue = 3;
126                         
127                         // Look for type before continuing.
128                         
129                         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
130                         intiter != SplitPoints.end(); ++intiter){
131                         
132                                 SLiter = SplitLength.find(intiter->first);
133                         
134                                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
135                                 
136                                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
137                                 PropertyName = PropertyElement.GetNextToken();                          
138                                 PropertyValue = PropertyElement.GetNextToken();
139                                 
140                                 intPrevValue = intiter->second;
141                                 
142                                 if (PropertyName == wxT("TYPE")){
143                                 
144                                         if (PropertyValue == wxT("work")){
145                                         
146                                                 intType = 2;                                    
147                                         
148                                         } else if (PropertyValue == wxT("home")){
150                                                 intType = 1;
151                                         
152                                         } else {
153                                         
154                                                 intType = 0;
155                                         
156                                         }
157                                 
158                                 }
159                         
160                         }
161                         
162                         // Setup blank lines for later on.
163                         
164                         if (intType == 0){
165                         
166                                 GeneralTZList.insert(std::make_pair(intValueSeek, wxT("")));
167                                 GeneralTZListAltID.insert(std::make_pair(intValueSeek, wxT("")));
168                                 GeneralTZListPID.insert(std::make_pair(intValueSeek, wxT("")));
169                                 GeneralTZListPref.insert(std::make_pair(intValueSeek, 0));
170                                 GeneralTZListMediatype.insert(std::make_pair(intValueSeek, wxT("")));
171                                 GeneralTZListTokens.insert(std::make_pair(intValueSeek, wxT("")));
173                         } else if (intType == 1){
174                         
175                                 HomeTZList.insert(std::make_pair(intValueSeek, wxT("")));
176                                 HomeTZListAltID.insert(std::make_pair(intValueSeek, wxT("")));
177                                 HomeTZListPID.insert(std::make_pair(intValueSeek, wxT("")));
178                                 HomeTZListPref.insert(std::make_pair(intValueSeek, 0));
179                                 HomeTZListMediatype.insert(std::make_pair(intValueSeek, wxT("")));                              
180                                 HomeTZListTokens.insert(std::make_pair(intValueSeek, wxT("")));
181                         
182                         } else if (intType == 2){
184                                 BusinessTZList.insert(std::make_pair(intValueSeek, wxT("")));
185                                 BusinessTZListAltID.insert(std::make_pair(intValueSeek, wxT("")));
186                                 BusinessTZListPID.insert(std::make_pair(intValueSeek, wxT("")));
187                                 BusinessTZListPref.insert(std::make_pair(intValueSeek, 0));
188                                 BusinessTZListMediatype.insert(std::make_pair(intValueSeek, wxT("")));                          
189                                 BusinessTZListTokens.insert(std::make_pair(intValueSeek, wxT("")));
190                         
191                         }
192                         
193                         intPrevValue = 3;
194                         
195                         for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
196                         intiter != SplitPoints.end(); ++intiter){
197                         
198                                 SLiter = SplitLength.find(intiter->first);
199                         
200                                 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
201                                 
202                                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
203                                 PropertyName = PropertyElement.GetNextToken();                          
204                                 PropertyValue = PropertyElement.GetNextToken();
205                                 
206                                 intPrevValue = intiter->second;
207                                 
208                                 size_t intPropertyValueLen = PropertyValue.Len();
209                                 
210                                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
211                                         
212                                         PropertyValue.Trim();
213                                         PropertyValue.RemoveLast();
214                                         
215                                 }                               
216                                 
217                                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
218                                         
219                                         PropertyValue.Remove(0, 1);
220                                         
221                                 }                               
222                                 
223                                 ProcessCaptureStrings(&PropertyValue);
224                                 
225                                 // Process properties.
226                                 
227                                 if (PropertyName == wxT("ALTID")){
229                                         if (intType == 0){ GeneralTZListAltID.erase(intValueSeek); GeneralTZListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
230                                         else if (intType == 1){ HomeTZListAltID.erase(intValueSeek); HomeTZListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
231                                         else if (intType == 2){ BusinessTZListAltID.erase(intValueSeek); BusinessTZListAltID.insert(std::make_pair(intValueSeek, PropertyValue)); }
232                                 
233                                 } else if (PropertyName == wxT("PID")){
235                                         if (intType == 0){ GeneralTZListPID.erase(intValueSeek); GeneralTZListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
236                                         else if (intType == 1){ HomeTZListPID.erase(intValueSeek); HomeTZListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
237                                         else if (intType == 2){ BusinessTZListPID.erase(intValueSeek); BusinessTZListPID.insert(std::make_pair(intValueSeek, PropertyValue)); }
238                                 
239                                 } else if (PropertyName == wxT("MEDIATYPE")){
240                                 
241                                         if (intType == 0){ GeneralTZListMediatype.erase(intValueSeek); GeneralTZListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
242                                         else if (intType == 1){ HomeTZListMediatype.erase(intValueSeek); HomeTZListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
243                                         else if (intType == 2){ BusinessTZListMediatype.erase(intValueSeek); BusinessTZListMediatype.insert(std::make_pair(intValueSeek, PropertyValue)); }
244                                 
245                                 } else if (PropertyName == wxT("PREF")){
246                                         
247                                         intPref = wxAtoi(PropertyValue);
248                                 
249                                         if (intPref > 0 && intPref < 101){
250                                 
251                                                 if (intType == 0){ GeneralTZListPref.erase(intValueSeek); GeneralTZListPref.insert(std::make_pair(intValueSeek, intPref)); }
252                                                 else if (intType == 1){ HomeTZListPref.erase(intValueSeek); HomeTZListPref.insert(std::make_pair(intValueSeek, intPref)); }
253                                                 else if (intType == 2){ BusinessTZListPref.erase(intValueSeek); BusinessTZListPref.insert(std::make_pair(intValueSeek, intPref)); }
254                                         
255                                         }
256                                 
257                                 } else {
258                                 
259                                         // Something else we don't know about so append
260                                         // to the tokens variable.
261                                         
262                                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
263                                         
264                                                 if (FirstToken == TRUE){
265                                                 
266                                                         PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
267                                                         FirstToken = FALSE;
268                                                 
269                                                 } else {
270                                                 
271                                                         PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
272                                                 
273                                                 }
274                                         
275                                         }
276                                 
277                                 }
278                         
279                         }                       
280                         
281                         // Split the address. 
282                 
283                         //std::map<int, int>::iterator SLiter;
284                         intPropertyLen = wxSPropertySeg2.Len();
285                         SplitPoints.clear();
286                         SplitLength.clear();
287                         intSplitsFound = 0;
288                         intSplitSize = 0;
289                         intPrevValue = 0;
290                         
291                         for (int i = 0; i <= intPropertyLen; i++){
292                 
293                                 intSplitSize++;
294                         
295                                 if (wxSPropertySeg2.Mid(i, 1) == wxT(";") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
296                         
297                                         intSplitsFound++;
298                                         SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
299                                         
300                                         if (intSplitsFound == 6){ 
301                                         
302                                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
303                                                 break; 
304                                                 
305                                         } else {
306                                         
307                                                 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
308                                         
309                                         }
310                                         
311                                         intSplitSize = 0;                                       
312                         
313                                 }
314                 
315                         }       
316                         
317                         // Add the data to the General/Home/Work address variables.
318                         
319                         ProcessCaptureStrings(&wxSPropertySeg2);                        
320                         
321                         wxListItem coldata;
322                 
323                         coldata.SetId(intValueSeek);
324                         coldata.SetData(intValueSeek);
325                         coldata.SetText(wxSPropertySeg2);
326                         
327                         if (intType == 0){
328                         
329                                 ListCtrlIndex = lboTimezones->InsertItem(coldata);
330                                 
331                                 if (intPref > 0 && intPref < 101){
332                                 
333                                         lboTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
334                                         
335                                 }
336                                 
337                                 GeneralTZList.erase(intValueSeek);
338                                 GeneralTZListType.erase(intValueSeek);
339                                 GeneralTZListTokens.erase(intValueSeek);
340                                 GeneralTZList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
341                                 GeneralTZListType.insert(std::make_pair(intValueSeek, wxT("")));
342                                 GeneralTZListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
343                         
344                         } else if (intType == 1){ 
345                         
346                                 ListCtrlIndex = lboHomeTimezones->InsertItem(coldata);
348                                 if (intPref > 0 && intPref < 101){
349                                 
350                                         lboHomeTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
351                                         
352                                 }
354                                 HomeTZList.erase(intValueSeek);
355                                 HomeTZListType.erase(intValueSeek);
356                                 HomeTZListTokens.erase(intValueSeek);                           
357                                 HomeTZList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
358                                 HomeTZListType.insert(std::make_pair(intValueSeek, wxT("home")));
359                                 HomeTZListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
360                         
361                         } else if (intType == 2){ 
362                         
363                                 ListCtrlIndex = lboBusinessTimezones->InsertItem(coldata);
365                                 if (intPref > 0 && intPref < 101){
366                                 
367                                         lboBusinessTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
368                                         
369                                 }
371                                 BusinessTZList.erase(intValueSeek);
372                                 BusinessTZListType.erase(intValueSeek);
373                                 BusinessTZListTokens.erase(intValueSeek);                               
374                                 BusinessTZList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
375                                 BusinessTZListType.insert(std::make_pair(intValueSeek, wxT("work")));
376                                 BusinessTZListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));                              
377                         
378                         }
379                 
380                         TZCount++;
381                         intValueSeek++; 
382                         
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