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(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *TZCount){
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;
39 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
43 // Look for type before continuing.
45 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
46 intiter != SplitPoints.end(); ++intiter){
48 SLiter = SplitLength.find(intiter->first);
50 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
52 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
53 PropertyName = PropertyElement.GetNextToken();
54 PropertyValue = PropertyElement.GetNextToken();
56 intPrevValue = intiter->second;
58 if (PropertyName == wxT("TYPE")){
60 if (PropertyValue == wxT("work")){
64 } else if (PropertyValue == wxT("home")){
78 // Setup blank lines for later on.
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){
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("")));
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("")));
111 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
112 intiter != SplitPoints.end(); ++intiter){
114 SLiter = SplitLength.find(intiter->first);
116 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
118 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
119 PropertyName = PropertyElement.GetNextToken();
120 PropertyValue = PropertyElement.GetNextToken();
122 intPrevValue = intiter->second;
124 size_t intPropertyValueLen = PropertyValue.Len();
126 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
128 PropertyValue.Trim();
129 PropertyValue.RemoveLast();
133 if (PropertyValue.Mid(0, 1) == wxT("\"")){
135 PropertyValue.Remove(0, 1);
139 ProcessCaptureStrings(&PropertyValue);
141 // Process properties.
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)); }
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)); }
155 } else if (PropertyName == wxT("MEDIATYPE")){
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)); }
161 } else if (PropertyName == wxT("PREF")){
163 intPref = wxAtoi(PropertyValue);
165 if (intPref > 0 && intPref < 101){
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)); }
175 // Something else we don't know about so append
176 // to the tokens variable.
178 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
180 if (FirstToken == TRUE){
182 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
187 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
197 // Split the address.
199 //std::map<int, int>::iterator SLiter;
200 intPropertyLen = wxSPropertySeg2.Len();
207 for (int i = 0; i <= intPropertyLen; i++){
211 if (wxSPropertySeg2.Mid(i, 1) == wxT(";") && wxSPropertySeg2.Mid((i - 1), 1) != wxT("\\")){
214 SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
216 if (intSplitsFound == 6){
218 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
223 SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
233 // Add the data to the General/Home/Work address variables.
235 ProcessCaptureStrings(&wxSPropertySeg2);
239 coldata.SetId(intValueSeek);
240 coldata.SetData(intValueSeek);
241 coldata.SetText(wxSPropertySeg2);
245 ListCtrlIndex = lboTimezones->InsertItem(coldata);
247 if (intPref > 0 && intPref < 101){
249 lboTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
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));
260 } else if (intType == 1){
262 ListCtrlIndex = lboHomeTimezones->InsertItem(coldata);
264 if (intPref > 0 && intPref < 101){
266 lboHomeTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
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));
277 } else if (intType == 2){
279 ListCtrlIndex = lboBusinessTimezones->InsertItem(coldata);
281 if (intPref > 0 && intPref < 101){
283 lboBusinessTimezones->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), intPref));
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));