Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Introduced simplified LoadBirthday and LoadAnniversary.
[xestiaab/.git] / source / contacteditor / frmContactEditor-LoadBADays.cpp
1 // frmContactEditor-LoadBADays.cpp - frmContactEditor load birthday/anniversary subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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){
24         
25                 int DateYear = 0;
26                 wxDateTime::Month DateMonth;
27                 unsigned int DateDay;
28                 
29                 wxString wxSData;
30                 
31                 if (Birthday.Mid(0, 2) == wxT("--")){
32                 
33                         // Skip year.
34                 
35                 } else {
36                 
37                         DateYear = wxAtoi(BirthdayData->Mid(0,4));
38                 
39                 }
40                 
41                 DateMonth = (wxDateTime::Month)(wxAtoi(BirthdayData->Mid(4,2)) - 1);
42                 DateDay = wxAtoi(BirthdayData->Mid(6,2));
43         
44                 wxDateTime BDayDate(DateDay,DateMonth,DateYear);
45         
46                 dapBirthday->SetValue(BDayDate);                                
47         
48         } else {
49         
50                 txtBirthday->SetValue(*BirthdayData);
51         
52         }
54 }
56 void frmContactEditor::LoadAnniversary(wxString *AnniversaryData, bool *AnniversaryText){
58         if (*AnniversaryText == FALSE){
59         
60                 int DateYear = 0;
61                 wxDateTime::Month DateMonth;
62                 int DateDay;
63                 
64                 wxString wxSData;
65                 
66                 if (Anniversary.Mid(0, 2) == wxT("--")){
67                 
68                         // Skip year.
69                 
70                 } else {
71                 
72                         DateYear = wxAtoi(AnniversaryData->Mid(0,4));
73                 
74                 }
75                 
76                 DateMonth = (wxDateTime::Month)(wxAtoi(AnniversaryData->Mid(4,2)) - 1);
77                 DateDay = wxAtoi(AnniversaryData->Mid(6,2));                                    
78         
79                 wxDateTime ADayDate(DateDay,DateMonth,DateYear);
80         
81                 dapAnniversary->SetValue(ADayDate);
82         
83         } else {
84         
85                 txtAnniversary->SetValue(*AnniversaryData);
86         
87         }
89 }
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);
107         intPrevValue = 5;
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);
117         
118                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
119                 PropertyName = PropertyElement.GetNextToken();                          
120                 PropertyValue = PropertyElement.GetNextToken();
121         
122                 intPrevValue = intiter->second;
123         
124                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){
125         
126                         ProcessCaptureStrings(&wxSPropertySeg2);
127                         txtBirthday->SetValue(wxSPropertySeg2);
128                         Birthday = wxSPropertySeg2;
129                         BirthdayText = TRUE;
130         
131                 }
133         }
135         // Setup blank lines for later on.
136         
137         intPrevValue = 5;
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);
145         
146                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
147                 PropertyName = PropertyElement.GetNextToken();                          
148                 PropertyValue = PropertyElement.GetNextToken();
149         
150                 intPrevValue = intiter->second;
151         
152                 // Process properties.
153         
154                 ProcessCaptureStrings(&PropertyValue);
155         
156                 size_t intPropertyValueLen = PropertyValue.Len();
157         
158                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
159                 
160                         PropertyValue.Trim();
161                         PropertyValue.RemoveLast();
162                 
163                 }                               
164         
165                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
166                 
167                         PropertyValue.Remove(0, 1);
168                 
169                 }                               
170         
171                 if (PropertyName == wxT("ALTID")){
173                         BirthdayAltID = PropertyValue;
174         
175                 } else if (PropertyName == wxT("CALSCALE")){
176         
177                         BirthdayCalScale = PropertyValue;
178         
179                 } else if (PropertyName != wxT("VALUE")) {
180         
181                         // Something else we don't know about so append
182                         // to the tokens variable.
183                 
184                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
185                 
186                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
187                                 
188                         }
189                         
190                 }
192         }       
194         // Add the data to the variables and form.
195         
196         if (BirthdayText == FALSE){
197         
198                 Birthday = wxSPropertySeg2;
199                 int DateYear = 0;
200                 wxDateTime::Month DateMonth;
201                 unsigned int DateDay;
202                 
203                 wxString wxSData;
204                 
205                 if (Birthday.Mid(0, 2) == wxT("--")){
206                 
207                         // Skip year.
208                 
209                 } else {
210                 
211                         DateYear = wxAtoi(Birthday.Mid(0,4));
212                 
213                 }
214                 
215                 DateMonth = (wxDateTime::Month)(wxAtoi(Birthday.Mid(4,2)) - 1);
216                 DateDay = wxAtoi(Birthday.Mid(6,2));
217         
218                 wxDateTime BDayDate(DateDay,DateMonth,DateYear);
219         
220                 /*BDayDate.SetDay(DateDay);
221                 BDayDate.SetMonth(wxDateTime::Month::Jan);
222                 BDayDate.SetYear(DateYear);*/
223         
224                 dapBirthday->SetValue(BDayDate);                                
225         
226         }
227         
228         BirthdayTokens = PropertyTokens;
229         
230         *BirthdayProcessed = TRUE;
234 void frmContactEditor::LoadAnniversary(wxString wxSPropertySeg1, wxString wxSPropertySeg2, bool *AnniversaryProcessed){
236         // Process date. Preserve the remainder in the string.
237                 
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);
250         intPrevValue = 12;
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);
260         
261                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
262                 PropertyName = PropertyElement.GetNextToken();                          
263                 PropertyValue = PropertyElement.GetNextToken();
264         
265                 intPrevValue = intiter->second;
266         
267                 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){
268         
269                         ProcessCaptureStrings(&wxSPropertySeg2);
270                         txtAnniversary->SetValue(wxSPropertySeg2);
271                         Anniversary = wxSPropertySeg2;
272                         AnniversaryText = TRUE;
273         
274                 }
276         }
278         // Setup blank lines for later on.
280         intPrevValue = 12;
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);
288         
289                 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
290                 PropertyName = PropertyElement.GetNextToken();                          
291                 PropertyValue = PropertyElement.GetNextToken();
292         
293                 intPrevValue = intiter->second;
294         
295                 // Process properties.
296         
297                 size_t intPropertyValueLen = PropertyValue.Len();
298         
299                 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
300                 
301                         PropertyValue.Trim();
302                         PropertyValue.RemoveLast();
303                 
304                 }                               
305         
306                 if (PropertyValue.Mid(0, 1) == wxT("\"")){
307                 
308                         PropertyValue.Remove(0, 1);
309                 
310                 }
311                 
312                 ProcessCaptureStrings(&PropertyValue);          
313         
314                 if (PropertyName == wxT("ALTID")){
316                         AnniversaryAltID = PropertyValue;
317         
318                 } else if (PropertyName == wxT("CALSCALE")){
319         
320                         AnniversaryCalScale = PropertyValue;
321         
322                 } else if (PropertyName != wxT("VALUE")) {
323         
324                         // Something else we don't know about so append
325                         // to the tokens variable.
326                         
327                         if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
328                 
329                                 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
330                                 
331                         }
332         
333                 }
335         }       
337         // Add the data to the variables and form.
338         
339         if (AnniversaryText == FALSE){
340         
341                 Anniversary = wxSPropertySeg2;
342                 int DateYear = 0;
343                 wxDateTime::Month DateMonth;
344                 int DateDay;
345                 
346                 wxString wxSData;
347                 
348                 if (Anniversary.Mid(0, 2) == wxT("--")){
349                 
350                         // Skip year.
351                 
352                 } else {
353                 
354                         DateYear = wxAtoi(Anniversary.Mid(0,4));
355                 
356                 }
357                 
358                 DateMonth = (wxDateTime::Month)(wxAtoi(Anniversary.Mid(4,2)) - 1);
359                 DateDay = wxAtoi(Anniversary.Mid(6,2));                                 
360         
361                 wxDateTime ADayDate(DateDay,DateMonth,DateYear);
362         
363                 dapAnniversary->SetValue(ADayDate);
364         
365         }
366         
367         AnniversaryTokens = PropertyTokens;
368         
369         *AnniversaryProcessed = TRUE;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy