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::LoadBirthday(wxString *BirthdayData, bool *BirthdayText){
23 if (*BirthdayText == FALSE){
26 wxDateTime::Month DateMonth;
31 if (Birthday.Mid(0, 2) == wxT("--")){
37 DateYear = wxAtoi(BirthdayData->Mid(0,4));
41 DateMonth = (wxDateTime::Month)(wxAtoi(BirthdayData->Mid(4,2)) - 1);
42 DateDay = wxAtoi(BirthdayData->Mid(6,2));
44 wxDateTime BDayDate(DateDay,DateMonth,DateYear);
46 dapBirthday->SetValue(BDayDate);
50 txtBirthday->SetValue(*BirthdayData);
56 void frmContactEditor::LoadAnniversary(wxString *AnniversaryData, bool *AnniversaryText){
58 if (*AnniversaryText == FALSE){
61 wxDateTime::Month DateMonth;
66 if (Anniversary.Mid(0, 2) == wxT("--")){
72 DateYear = wxAtoi(AnniversaryData->Mid(0,4));
76 DateMonth = (wxDateTime::Month)(wxAtoi(AnniversaryData->Mid(4,2)) - 1);
77 DateDay = wxAtoi(AnniversaryData->Mid(6,2));
79 wxDateTime ADayDate(DateDay,DateMonth,DateYear);
81 dapAnniversary->SetValue(ADayDate);
85 txtAnniversary->SetValue(*AnniversaryData);
91 void frmContactEditor::LoadBDay(wxString wxSPropertySeg1, wxString wxSPropertySeg2, bool *BirthdayProcessed){
93 // Process date. Preserve the remainder in the string.
95 std::map<int, int> SplitPoints;
96 std::map<int, int> SplitLength;
97 std::map<int, int>::iterator SLiter;
98 wxString PropertyData;
99 wxString PropertyName;
100 wxString PropertyValue;
101 wxString PropertyTokens;
102 bool BirthdayText = FALSE;
103 int intPrevValue = 6;
105 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
109 // Look for type before continuing.
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 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){
126 ProcessCaptureStrings(&wxSPropertySeg2);
127 txtBirthday->SetValue(wxSPropertySeg2);
128 Birthday = wxSPropertySeg2;
135 // Setup blank lines for later on.
139 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
140 intiter != SplitPoints.end(); ++intiter){
142 SLiter = SplitLength.find(intiter->first);
144 PropertyData = wxSPropertySeg1.Mid(intPrevValue, SLiter->second);
146 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
147 PropertyName = PropertyElement.GetNextToken();
148 PropertyValue = PropertyElement.GetNextToken();
150 intPrevValue = intiter->second;
152 // Process properties.
154 ProcessCaptureStrings(&PropertyValue);
156 size_t intPropertyValueLen = PropertyValue.Len();
158 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
160 PropertyValue.Trim();
161 PropertyValue.RemoveLast();
165 if (PropertyValue.Mid(0, 1) == wxT("\"")){
167 PropertyValue.Remove(0, 1);
171 if (PropertyName == wxT("ALTID")){
173 BirthdayAltID = PropertyValue;
175 } else if (PropertyName == wxT("CALSCALE")){
177 BirthdayCalScale = PropertyValue;
179 } else if (PropertyName != wxT("VALUE")) {
181 // Something else we don't know about so append
182 // to the tokens variable.
184 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
186 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
194 // Add the data to the variables and form.
196 if (BirthdayText == FALSE){
198 Birthday = wxSPropertySeg2;
200 wxDateTime::Month DateMonth;
201 unsigned int DateDay;
205 if (Birthday.Mid(0, 2) == wxT("--")){
211 DateYear = wxAtoi(Birthday.Mid(0,4));
215 DateMonth = (wxDateTime::Month)(wxAtoi(Birthday.Mid(4,2)) - 1);
216 DateDay = wxAtoi(Birthday.Mid(6,2));
218 wxDateTime BDayDate(DateDay,DateMonth,DateYear);
220 /*BDayDate.SetDay(DateDay);
221 BDayDate.SetMonth(wxDateTime::Month::Jan);
222 BDayDate.SetYear(DateYear);*/
224 dapBirthday->SetValue(BDayDate);
228 BirthdayTokens = PropertyTokens;
230 *BirthdayProcessed = TRUE;
234 void frmContactEditor::LoadAnniversary(wxString wxSPropertySeg1, wxString wxSPropertySeg2, bool *AnniversaryProcessed){
236 // Process date. Preserve the remainder in the string.
238 std::map<int, int> SplitPoints;
239 std::map<int, int> SplitLength;
240 std::map<int, int>::iterator SLiter;
241 wxString PropertyData;
242 wxString PropertyName;
243 wxString PropertyValue;
244 wxString PropertyTokens;
245 bool AnniversaryText = FALSE;
246 int intPrevValue = 13;
248 SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
252 // Look for type before continuing.
254 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
255 intiter != SplitPoints.end(); ++intiter){
257 SLiter = SplitLength.find(intiter->first);
259 PropertyData = wxSPropertySeg1.Mid(intPrevValue, SLiter->second);
261 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
262 PropertyName = PropertyElement.GetNextToken();
263 PropertyValue = PropertyElement.GetNextToken();
265 intPrevValue = intiter->second;
267 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){
269 ProcessCaptureStrings(&wxSPropertySeg2);
270 txtAnniversary->SetValue(wxSPropertySeg2);
271 Anniversary = wxSPropertySeg2;
272 AnniversaryText = TRUE;
278 // Setup blank lines for later on.
282 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
283 intiter != SplitPoints.end(); ++intiter){
285 SLiter = SplitLength.find(intiter->first);
287 PropertyData = wxSPropertySeg1.Mid(intPrevValue, SLiter->second);
289 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
290 PropertyName = PropertyElement.GetNextToken();
291 PropertyValue = PropertyElement.GetNextToken();
293 intPrevValue = intiter->second;
295 // Process properties.
297 size_t intPropertyValueLen = PropertyValue.Len();
299 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
301 PropertyValue.Trim();
302 PropertyValue.RemoveLast();
306 if (PropertyValue.Mid(0, 1) == wxT("\"")){
308 PropertyValue.Remove(0, 1);
312 ProcessCaptureStrings(&PropertyValue);
314 if (PropertyName == wxT("ALTID")){
316 AnniversaryAltID = PropertyValue;
318 } else if (PropertyName == wxT("CALSCALE")){
320 AnniversaryCalScale = PropertyValue;
322 } else if (PropertyName != wxT("VALUE")) {
324 // Something else we don't know about so append
325 // to the tokens variable.
327 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
329 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
337 // Add the data to the variables and form.
339 if (AnniversaryText == FALSE){
341 Anniversary = wxSPropertySeg2;
343 wxDateTime::Month DateMonth;
348 if (Anniversary.Mid(0, 2) == wxT("--")){
354 DateYear = wxAtoi(Anniversary.Mid(0,4));
358 DateMonth = (wxDateTime::Month)(wxAtoi(Anniversary.Mid(4,2)) - 1);
359 DateDay = wxAtoi(Anniversary.Mid(6,2));
361 wxDateTime ADayDate(DateDay,DateMonth,DateYear);
363 dapAnniversary->SetValue(ADayDate);
367 AnniversaryTokens = PropertyTokens;
369 *AnniversaryProcessed = TRUE;