1 // frmContactEditor-LoadBADays.cpp - frmContactEditor load birthday/anniversary 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::LoadBDay(wxString wxSPropertySeg1, wxString wxSPropertySeg2, bool *BirthdayProcessed){
23 // Process date. Preserve the remainder in the string.
25 std::map<int, int> SplitPoints;
26 std::map<int, int> SplitLength;
27 std::map<int, int>::iterator SLiter;
28 wxString PropertyData;
29 wxString PropertyName;
30 wxString PropertyValue;
31 wxString PropertyTokens;
32 bool BirthdayText = FALSE;
35 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
39 // Look for type before continuing.
41 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
42 intiter != SplitPoints.end(); ++intiter){
44 SLiter = SplitLength.find(intiter->first);
46 PropertyData = wxSPropertySeg1.Mid(intPrevValue, SLiter->second);
48 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
49 PropertyName = PropertyElement.GetNextToken();
50 PropertyValue = PropertyElement.GetNextToken();
52 intPrevValue = intiter->second;
54 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){
56 ProcessCaptureStrings(&wxSPropertySeg2);
57 txtBirthday->SetValue(wxSPropertySeg2);
58 Birthday = wxSPropertySeg2;
65 // Setup blank lines for later on.
69 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
70 intiter != SplitPoints.end(); ++intiter){
72 SLiter = SplitLength.find(intiter->first);
74 PropertyData = wxSPropertySeg1.Mid(intPrevValue, SLiter->second);
76 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
77 PropertyName = PropertyElement.GetNextToken();
78 PropertyValue = PropertyElement.GetNextToken();
80 intPrevValue = intiter->second;
82 // Process properties.
84 ProcessCaptureStrings(&PropertyValue);
86 size_t intPropertyValueLen = PropertyValue.Len();
88 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
91 PropertyValue.RemoveLast();
95 if (PropertyValue.Mid(0, 1) == wxT("\"")){
97 PropertyValue.Remove(0, 1);
101 if (PropertyName == wxT("ALTID")){
103 BirthdayAltID = PropertyValue;
105 } else if (PropertyName == wxT("CALSCALE")){
107 BirthdayCalScale = PropertyValue;
109 } else if (PropertyName != wxT("VALUE")) {
111 // Something else we don't know about so append
112 // to the tokens variable.
114 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
116 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
124 // Add the data to the variables and form.
126 if (BirthdayText == FALSE){
128 Birthday = wxSPropertySeg2;
130 wxDateTime::Month DateMonth;
131 unsigned int DateDay;
135 if (Birthday.Mid(0, 2) == wxT("--")){
141 DateYear = wxAtoi(Birthday.Mid(0,4));
145 DateMonth = (wxDateTime::Month)(wxAtoi(Birthday.Mid(4,2)) - 1);
146 DateDay = wxAtoi(Birthday.Mid(6,2));
148 wxDateTime BDayDate(DateDay,DateMonth,DateYear);
150 /*BDayDate.SetDay(DateDay);
151 BDayDate.SetMonth(wxDateTime::Month::Jan);
152 BDayDate.SetYear(DateYear);*/
154 dapBirthday->SetValue(BDayDate);
158 BirthdayTokens = PropertyTokens;
160 *BirthdayProcessed = TRUE;
164 void frmContactEditor::LoadAnniversary(wxString wxSPropertySeg1, wxString wxSPropertySeg2, bool *AnniversaryProcessed){
166 // Process date. Preserve the remainder in the string.
168 std::map<int, int> SplitPoints;
169 std::map<int, int> SplitLength;
170 std::map<int, int>::iterator SLiter;
171 wxString PropertyData;
172 wxString PropertyName;
173 wxString PropertyValue;
174 wxString PropertyTokens;
175 bool AnniversaryText = FALSE;
176 int intPrevValue = 13;
178 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
182 // Look for type before continuing.
184 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
185 intiter != SplitPoints.end(); ++intiter){
187 SLiter = SplitLength.find(intiter->first);
189 PropertyData = wxSPropertySeg1.Mid(intPrevValue, SLiter->second);
191 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
192 PropertyName = PropertyElement.GetNextToken();
193 PropertyValue = PropertyElement.GetNextToken();
195 intPrevValue = intiter->second;
197 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){
199 ProcessCaptureStrings(&wxSPropertySeg2);
200 txtAnniversary->SetValue(wxSPropertySeg2);
201 Anniversary = wxSPropertySeg2;
202 AnniversaryText = TRUE;
208 // Setup blank lines for later on.
212 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
213 intiter != SplitPoints.end(); ++intiter){
215 SLiter = SplitLength.find(intiter->first);
217 PropertyData = wxSPropertySeg1.Mid(intPrevValue, SLiter->second);
219 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
220 PropertyName = PropertyElement.GetNextToken();
221 PropertyValue = PropertyElement.GetNextToken();
223 intPrevValue = intiter->second;
225 // Process properties.
227 size_t intPropertyValueLen = PropertyValue.Len();
229 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
231 PropertyValue.Trim();
232 PropertyValue.RemoveLast();
236 if (PropertyValue.Mid(0, 1) == wxT("\"")){
238 PropertyValue.Remove(0, 1);
242 ProcessCaptureStrings(&PropertyValue);
244 if (PropertyName == wxT("ALTID")){
246 AnniversaryAltID = PropertyValue;
248 } else if (PropertyName == wxT("CALSCALE")){
250 AnniversaryCalScale = PropertyValue;
252 } else if (PropertyName != wxT("VALUE")) {
254 // Something else we don't know about so append
255 // to the tokens variable.
257 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
259 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
267 // Add the data to the variables and form.
269 if (AnniversaryText == FALSE){
271 Anniversary = wxSPropertySeg2;
273 wxDateTime::Month DateMonth;
278 if (Anniversary.Mid(0, 2) == wxT("--")){
284 DateYear = wxAtoi(Anniversary.Mid(0,4));
288 DateMonth = (wxDateTime::Month)(wxAtoi(Anniversary.Mid(4,2)) - 1);
289 DateDay = wxAtoi(Anniversary.Mid(6,2));
291 wxDateTime ADayDate(DateDay,DateMonth,DateYear);
293 dapAnniversary->SetValue(ADayDate);
297 AnniversaryTokens = PropertyTokens;
299 *AnniversaryProcessed = TRUE;