// frmContactEditor-LoadBADays.cpp - frmContactEditor load birthday/anniversary subroutines. // // (c) 2012-2015 Xestia Software Development. // // This file is part of Xestia Address Book. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Address Book. If not, see #include "frmContactEditor.h" void frmContactEditor::LoadBDay(wxString wxSPropertySeg1, wxString wxSPropertySeg2, bool *BirthdayProcessed){ // Process date. Preserve the remainder in the string. std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; bool BirthdayText = FALSE; int intPrevValue = 6; SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue); intPrevValue = 5; // Look for type before continuing. for (std::map::iterator intiter = SplitPoints.begin(); intiter != SplitPoints.end(); ++intiter){ SLiter = SplitLength.find(intiter->first); PropertyData = wxSPropertySeg1.Mid(intPrevValue, SLiter->second); wxStringTokenizer PropertyElement (PropertyData, wxT("=")); PropertyName = PropertyElement.GetNextToken(); PropertyValue = PropertyElement.GetNextToken(); intPrevValue = intiter->second; if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){ ProcessCaptureStrings(&wxSPropertySeg2); txtBirthday->SetValue(wxSPropertySeg2); Birthday = wxSPropertySeg2; BirthdayText = TRUE; } } // Setup blank lines for later on. intPrevValue = 5; for (std::map::iterator intiter = SplitPoints.begin(); intiter != SplitPoints.end(); ++intiter){ SLiter = SplitLength.find(intiter->first); PropertyData = wxSPropertySeg1.Mid(intPrevValue, SLiter->second); wxStringTokenizer PropertyElement (PropertyData, wxT("=")); PropertyName = PropertyElement.GetNextToken(); PropertyValue = PropertyElement.GetNextToken(); intPrevValue = intiter->second; // Process properties. ProcessCaptureStrings(&PropertyValue); size_t intPropertyValueLen = PropertyValue.Len(); if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){ PropertyValue.Trim(); PropertyValue.RemoveLast(); } if (PropertyValue.Mid(0, 1) == wxT("\"")){ PropertyValue.Remove(0, 1); } if (PropertyName == wxT("ALTID")){ BirthdayAltID = PropertyValue; } else if (PropertyName == wxT("CALSCALE")){ BirthdayCalScale = PropertyValue; } else if (PropertyName != wxT("VALUE")) { // Something else we don't know about so append // to the tokens variable. if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){ PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue); } } } // Add the data to the variables and form. if (BirthdayText == FALSE){ Birthday = wxSPropertySeg2; int DateYear = 0; wxDateTime::Month DateMonth; unsigned int DateDay; wxString wxSData; if (Birthday.Mid(0, 2) == wxT("--")){ // Skip year. } else { DateYear = wxAtoi(Birthday.Mid(0,4)); } DateMonth = (wxDateTime::Month)(wxAtoi(Birthday.Mid(4,2)) - 1); DateDay = wxAtoi(Birthday.Mid(6,2)); wxDateTime BDayDate(DateDay,DateMonth,DateYear); /*BDayDate.SetDay(DateDay); BDayDate.SetMonth(wxDateTime::Month::Jan); BDayDate.SetYear(DateYear);*/ dapBirthday->SetValue(BDayDate); } BirthdayTokens = PropertyTokens; *BirthdayProcessed = TRUE; } void frmContactEditor::LoadAnniversary(wxString wxSPropertySeg1, wxString wxSPropertySeg2, bool *AnniversaryProcessed){ // Process date. Preserve the remainder in the string. std::map SplitPoints; std::map SplitLength; std::map::iterator SLiter; wxString PropertyData; wxString PropertyName; wxString PropertyValue; wxString PropertyTokens; bool AnniversaryText = FALSE; int intPrevValue = 13; SplitValues(&wxSPropertySeg1, &SplitPoints, &SplitLength, intPrevValue); intPrevValue = 12; // Look for type before continuing. for (std::map::iterator intiter = SplitPoints.begin(); intiter != SplitPoints.end(); ++intiter){ SLiter = SplitLength.find(intiter->first); PropertyData = wxSPropertySeg1.Mid(intPrevValue, SLiter->second); wxStringTokenizer PropertyElement (PropertyData, wxT("=")); PropertyName = PropertyElement.GetNextToken(); PropertyValue = PropertyElement.GetNextToken(); intPrevValue = intiter->second; if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){ ProcessCaptureStrings(&wxSPropertySeg2); txtAnniversary->SetValue(wxSPropertySeg2); Anniversary = wxSPropertySeg2; AnniversaryText = TRUE; } } // Setup blank lines for later on. intPrevValue = 12; for (std::map::iterator intiter = SplitPoints.begin(); intiter != SplitPoints.end(); ++intiter){ SLiter = SplitLength.find(intiter->first); PropertyData = wxSPropertySeg1.Mid(intPrevValue, SLiter->second); wxStringTokenizer PropertyElement (PropertyData, wxT("=")); PropertyName = PropertyElement.GetNextToken(); PropertyValue = PropertyElement.GetNextToken(); intPrevValue = intiter->second; // Process properties. size_t intPropertyValueLen = PropertyValue.Len(); if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){ PropertyValue.Trim(); PropertyValue.RemoveLast(); } if (PropertyValue.Mid(0, 1) == wxT("\"")){ PropertyValue.Remove(0, 1); } ProcessCaptureStrings(&PropertyValue); if (PropertyName == wxT("ALTID")){ AnniversaryAltID = PropertyValue; } else if (PropertyName == wxT("CALSCALE")){ AnniversaryCalScale = PropertyValue; } else if (PropertyName != wxT("VALUE")) { // Something else we don't know about so append // to the tokens variable. if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){ PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue); } } } // Add the data to the variables and form. if (AnniversaryText == FALSE){ Anniversary = wxSPropertySeg2; int DateYear = 0; wxDateTime::Month DateMonth; int DateDay; wxString wxSData; if (Anniversary.Mid(0, 2) == wxT("--")){ // Skip year. } else { DateYear = wxAtoi(Anniversary.Mid(0,4)); } DateMonth = (wxDateTime::Month)(wxAtoi(Anniversary.Mid(4,2)) - 1); DateDay = wxAtoi(Anniversary.Mid(6,2)); wxDateTime ADayDate(DateDay,DateMonth,DateYear); dapAnniversary->SetValue(ADayDate); } AnniversaryTokens = PropertyTokens; *AnniversaryProcessed = TRUE; }