1 // frmContactEditor-LoadTimeZone.cpp - frmContactEditor load timezone 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::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,
29 long ListCtrlIndex = -1;
31 // Deal with the general addresses.
33 for (std::map<int,wxString>::iterator Iter = GeneralTZListPtr->begin();
34 Iter != GeneralTZListPtr->end();
39 coldata.SetId(*TZCount);
40 coldata.SetData(*TZCount);
41 coldata.SetText(Iter->second);
43 ListCtrlIndex = lboTimezones->InsertItem(coldata);
45 if (MapDataExists(TZCount, GeneralTZListPrefPtr)){
47 lboTimezones->SetItem(ListCtrlIndex, 1, wxString::Format("%i", GeneralTZListPrefPtr->find(*TZCount)->second));
55 // Deal with the home addresses.
57 for (std::map<int,wxString>::iterator Iter = HomeTZListPtr->begin();
58 Iter != HomeTZListPtr->end();
63 coldata.SetId(*TZCount);
64 coldata.SetData(*TZCount);
65 coldata.SetText(Iter->second);
67 ListCtrlIndex = lboHomeTimezones->InsertItem(coldata);
69 if (MapDataExists(TZCount, HomeTZListPrefPtr)){
71 lboHomeTimezones->SetItem(ListCtrlIndex, 1, wxString::Format("%i", HomeTZListPrefPtr->find(*TZCount)->second));
79 // Deal with the work addresses.
81 for (std::map<int,wxString>::iterator Iter = BusinessTZListPtr->begin();
82 Iter != BusinessTZListPtr->end();
87 coldata.SetId(*TZCount);
88 coldata.SetData(*TZCount);
89 coldata.SetText(Iter->second);
91 ListCtrlIndex = lboBusinessTimezones->InsertItem(coldata);
93 if (MapDataExists(TZCount, BusinessTZListPrefPtr)){
95 lboBusinessTimezones->SetItem(ListCtrlIndex, 1, wxString::Format("%i", BusinessTZListPrefPtr->find(*TZCount)->second));
105 void frmContactEditor::LoadTimeZone(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *TZCount){
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;
123 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
127 // Look for type before continuing.
129 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
130 intiter != SplitPoints.end(); ++intiter){
132 SLiter = SplitLength.find(intiter->first);
134 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
136 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
137 PropertyName = PropertyElement.GetNextToken();
138 PropertyValue = PropertyElement.GetNextToken();
140 intPrevValue = intiter->second;
142 if (PropertyName == wxT("TYPE")){
144 if (PropertyValue == wxT("work")){
148 } else if (PropertyValue == wxT("home")){
162 // Setup blank lines for later on.
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){
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("")));
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("")));
195 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
196 intiter != SplitPoints.end(); ++intiter){
198 SLiter = SplitLength.find(intiter->first);
200 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
202 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
203 PropertyName = PropertyElement.GetNextToken();
204 PropertyValue = PropertyElement.GetNextToken();
206 intPrevValue = intiter->second;
208 size_t intPropertyValueLen = PropertyValue.Len();
210 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
212 PropertyValue.Trim();
213 PropertyValue.RemoveLast();
217 if (PropertyValue.Mid(0, 1) == wxT("\"")){
219 PropertyValue.Remove(0, 1);
223 ProcessCaptureStrings(&PropertyValue);
225 // Process properties.
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)); }
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)); }
239 } else if (PropertyName == wxT("MEDIATYPE")){
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)); }
245 } else if (PropertyName == wxT("PREF")){
247 intPref = wxAtoi(PropertyValue);
249 if (intPref > 0 && intPref < 101){
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)); }
259 // Something else we don't know about so append
260 // to the tokens variable.
262 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
264 if (FirstToken == TRUE){
266 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
271 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
281 // Split the address.
283 //std::map<int, int>::iterator SLiter;
284 intPropertyLen = wxSPropertySeg2.Len();
291 for (int i = 0; i <= intPropertyLen; i++){
295 if (wxSPropertySeg2.Mid(i, 1) == wxT(";") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
298 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
300 if (intSplitsFound == 6){
302 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
307 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
317 // Add the data to the General/Home/Work address variables.
319 ProcessCaptureStrings(&wxSPropertySeg2);
323 coldata.SetId(intValueSeek);
324 coldata.SetData(intValueSeek);
325 coldata.SetText(wxSPropertySeg2);
329 ListCtrlIndex = lboTimezones->InsertItem(coldata);
331 if (intPref > 0 && intPref < 101){
333 lboTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
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));
344 } else if (intType == 1){
346 ListCtrlIndex = lboHomeTimezones->InsertItem(coldata);
348 if (intPref > 0 && intPref < 101){
350 lboHomeTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
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));
361 } else if (intType == 2){
363 ListCtrlIndex = lboBusinessTimezones->InsertItem(coldata);
365 if (intPref > 0 && intPref < 101){
367 lboBusinessTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
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));