1 // frmContactEditor-LoadCalendar.cpp - frmContactEditor load calendar 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::LoadCalURI(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *CalAdrCount){
23 std::map<int, int> SplitPoints;
24 std::map<int, int> SplitLength;
25 std::map<int, int>::iterator SLiter;
26 wxString PropertyData;
27 wxString PropertyName;
28 wxString PropertyValue;
29 wxString PropertyTokens;
30 bool FirstToken = TRUE;
36 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
40 // Look for type before continuing.
42 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
43 intiter != SplitPoints.end(); ++intiter){
45 SLiter = SplitLength.find(intiter->first);
47 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
49 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
50 PropertyName = PropertyElement.GetNextToken();
51 PropertyValue = PropertyElement.GetNextToken();
53 intPrevValue = intiter->second;
55 if (PropertyName == wxT("TYPE")){
57 if (PropertyValue == wxT("work")){
61 } else if (PropertyValue == wxT("home")){
75 // Setup blank lines for later on.
77 CalendarList.insert(std::make_pair(intValueSeek, wxT("")));
78 CalendarListAltID.insert(std::make_pair(intValueSeek, wxT("")));
79 CalendarListPID.insert(std::make_pair(intValueSeek, wxT("")));
80 CalendarListPref.insert(std::make_pair(intValueSeek, 0));
81 CalendarListTokens.insert(std::make_pair(intValueSeek, wxT("")));
85 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
86 intiter != SplitPoints.end(); ++intiter){
88 SLiter = SplitLength.find(intiter->first);
90 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
92 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
93 PropertyName = PropertyElement.GetNextToken();
94 PropertyValue = PropertyElement.GetNextToken();
96 intPrevValue = intiter->second;
98 // Process properties.
100 size_t intPropertyValueLen = PropertyValue.Len();
102 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
104 PropertyValue.Trim();
105 PropertyValue.RemoveLast();
109 if (PropertyValue.Mid(0, 1) == wxT("\"")){
111 PropertyValue.Remove(0, 1);
115 if (PropertyName == wxT("ALTID")){
117 CalendarListAltID.erase(intValueSeek); CalendarListAltID.insert(std::make_pair(intValueSeek, PropertyValue));
119 } else if (PropertyName == wxT("PID")){
121 CalendarListPID.erase(intValueSeek); CalendarListPID.insert(std::make_pair(intValueSeek, PropertyValue));
123 } else if (PropertyName == wxT("PREF")){
125 intPref = wxAtoi(PropertyValue);
127 CalendarListPref.erase(intValueSeek); CalendarListPref.insert(std::make_pair(intValueSeek, intPref));
129 } else if (PropertyName == wxT("MEDIATYPE")){
131 CalendarListMediatype.erase(intValueSeek); CalendarListMediatype.insert(std::make_pair(intValueSeek, PropertyValue));
135 // Something else we don't know about so append
136 // to the tokens variable.
138 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
140 if (FirstToken == TRUE){
142 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
147 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
157 // Add the data to the General/Home/Work address variables.
161 coldata.SetId(intValueSeek);
162 coldata.SetData(intValueSeek);
163 coldata.SetText(wxSPropertySeg2);
165 ListCtrlIndex = lboCalendarAddresses->InsertItem(coldata);
167 if (intPref > 0 && intPref < 101){
169 lboCalendarAddresses->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
173 CaptureString(&wxSPropertySeg2, FALSE);
175 CalendarList.erase(intValueSeek);
176 CalendarListType.erase(intValueSeek);
177 CalendarListTokens.erase(intValueSeek);
178 CalendarList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
182 CalendarListType.insert(std::make_pair(intValueSeek, wxT("")));
184 } else if (intType == 1){
186 CalendarListType.insert(std::make_pair(intValueSeek, wxT("home")));
187 lboCalendarAddresses->SetItem(ListCtrlIndex, 1, _("Home"), intPref);
189 } else if (intType == 2){
191 CalendarListType.insert(std::make_pair(intValueSeek, wxT("work")));
192 lboCalendarAddresses->SetItem(ListCtrlIndex, 1, _("Work"), intPref);
196 CalendarListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));
203 void frmContactEditor::LoadCalAdrURI(wxString wxSPropertySeg1, wxString wxSPropertySeg2, int *CalReqAdrCount){
205 std::map<int, int> SplitPoints;
206 std::map<int, int> SplitLength;
207 std::map<int, int>::iterator SLiter;
208 wxString PropertyData;
209 wxString PropertyName;
210 wxString PropertyValue;
211 wxString PropertyTokens;
212 bool FirstToken = TRUE;
213 int intPrevValue = 11;
218 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
222 // Look for type before continuing.
226 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
227 intiter != SplitPoints.end(); ++intiter){
229 SLiter = SplitLength.find(intiter->first);
231 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
233 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
234 PropertyName = PropertyElement.GetNextToken();
235 PropertyValue = PropertyElement.GetNextToken();
237 intPrevValue = intiter->second;
239 if (PropertyName == wxT("TYPE")){
241 if (PropertyValue == wxT("work")){
245 } else if (PropertyValue == wxT("home")){
259 // Setup blank lines for later on.
261 CalendarRequestList.insert(std::make_pair(intValueSeek, wxT("")));
262 CalendarRequestListAltID.insert(std::make_pair(intValueSeek, wxT("")));
263 CalendarRequestListPID.insert(std::make_pair(intValueSeek, wxT("")));
264 CalendarRequestListPref.insert(std::make_pair(intValueSeek, 0));
265 CalendarRequestListTokens.insert(std::make_pair(intValueSeek, wxT("")));
269 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
270 intiter != SplitPoints.end(); ++intiter){
272 SLiter = SplitLength.find(intiter->first);
274 PropertyData = wxSPropertySeg1.Mid(intPrevValue, (SLiter->second));
276 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
277 PropertyName = PropertyElement.GetNextToken();
278 PropertyValue = PropertyElement.GetNextToken();
280 intPrevValue = intiter->second;
282 // Process properties.
284 size_t intPropertyValueLen = PropertyValue.Len();
286 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
288 PropertyValue.Trim();
289 PropertyValue.RemoveLast();
293 if (PropertyValue.Mid(0, 1) == wxT("\"")){
295 PropertyValue.Remove(0, 1);
299 if (PropertyName == wxT("ALTID")){
301 CalendarRequestListAltID.erase(intValueSeek); CalendarRequestListAltID.insert(std::make_pair(intValueSeek, PropertyValue));
303 } else if (PropertyName == wxT("PID")){
305 CalendarRequestListPID.erase(intValueSeek); CalendarRequestListPID.insert(std::make_pair(intValueSeek, PropertyValue));
307 } else if (PropertyName == wxT("PREF")){
309 intPref = wxAtoi(PropertyValue);
311 CalendarRequestListPref.erase(intValueSeek); CalendarRequestListPref.insert(std::make_pair(intValueSeek, intPref));
313 } else if (PropertyName == wxT("MEDIATYPE")){
315 CalendarRequestListMediatype.erase(intValueSeek); CalendarRequestListMediatype.insert(std::make_pair(intValueSeek, PropertyValue));
319 // Something else we don't know about so append
320 // to the tokens variable.
322 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
324 if (FirstToken == TRUE){
326 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
331 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
341 // Add the data to the General/Home/Work address variables.
345 coldata.SetId(intValueSeek);
346 coldata.SetData(intValueSeek);
347 coldata.SetText(wxSPropertySeg2);
349 ListCtrlIndex = lboCalendarRequestAddress->InsertItem(coldata);
351 if (intPref > 0 && intPref < 101){
353 lboCalendarRequestAddress->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), intPref));
357 CaptureString(&wxSPropertySeg2, FALSE);
359 CalendarRequestList.erase(intValueSeek);
360 CalendarRequestListType.erase(intValueSeek);
361 CalendarRequestListTokens.erase(intValueSeek);
362 CalendarRequestList.insert(std::make_pair(intValueSeek, wxSPropertySeg2));
366 CalendarRequestListType.insert(std::make_pair(intValueSeek, wxT("")));
368 } else if (intType == 1){
370 CalendarRequestListType.insert(std::make_pair(intValueSeek, wxT("home")));
371 lboCalendarRequestAddress->SetItem(ListCtrlIndex, 1, _("Home"), intPref);
373 } else if (intType == 2){
375 CalendarRequestListType.insert(std::make_pair(intValueSeek, wxT("work")));
376 lboCalendarRequestAddress->SetItem(ListCtrlIndex, 1, _("Work"), intPref);
380 CalendarRequestListTokens.insert(std::make_pair(intValueSeek, PropertyTokens));