|
1 /* |
|
2 * Copyright (c) 2007-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This file contains implementation of iCal parser which parses |
|
15 * the weekly recurring event specific information. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include "AgnParseRRuleWeekly.h" |
|
22 |
|
23 #include "calendarengines_debug.h" |
|
24 #include "ICalValue.h" |
|
25 #include <calrrule.h> |
|
26 |
|
27 /** |
|
28 Constructor |
|
29 @param aAgnImpUtil AgnVersit2Importer utility functions |
|
30 */ |
|
31 CAgnParseRRuleWeekly::CAgnParseRRuleWeekly( MAgnImpUtil& aAgnImpUtil ): |
|
32 CAgnParseRRule( aAgnImpUtil ) |
|
33 { |
|
34 TRACE_ENTRY_POINT; |
|
35 TRACE_EXIT_POINT; |
|
36 } |
|
37 |
|
38 |
|
39 /** |
|
40 Destructor |
|
41 */ |
|
42 CAgnParseRRuleWeekly::~CAgnParseRRuleWeekly() |
|
43 { |
|
44 TRACE_ENTRY_POINT; |
|
45 TRACE_EXIT_POINT; |
|
46 } |
|
47 |
|
48 |
|
49 /** |
|
50 Constructs a new CAgnParseRRuleWeekly and returns it. The object is left on the |
|
51 cleanup stack. |
|
52 @param aAgnImpUtil AgnVersit2Importer utility functions |
|
53 @return a new CAgnParseRRuleWeekly. |
|
54 */ |
|
55 CAgnParseRRule* CAgnParseRRuleWeekly::NewLC( MAgnImpUtil& aAgnImpUtil ) |
|
56 { |
|
57 TRACE_ENTRY_POINT; |
|
58 |
|
59 CAgnParseRRule *self = new (ELeave) CAgnParseRRuleWeekly( aAgnImpUtil ); |
|
60 CleanupStack::PushL( self ); |
|
61 |
|
62 TRACE_EXIT_POINT; |
|
63 return self; |
|
64 } |
|
65 |
|
66 |
|
67 /** |
|
68 Parse the keywords and update RRule |
|
69 @param aSegment recurrence rule value segment. |
|
70 @param aRule recurrence rules |
|
71 @return True if parsed the keyword successfully |
|
72 */ |
|
73 TBool CAgnParseRRuleWeekly::DoParseL( CICalRuleSegment& aSegment, TCalRRule& aRule ) |
|
74 { |
|
75 TRACE_ENTRY_POINT; |
|
76 |
|
77 TBool parsed = ETrue; |
|
78 |
|
79 switch( aSegment.Type() ) |
|
80 { |
|
81 //ESegWkSt |
|
82 case CICalRuleSegment::ESegWkSt : |
|
83 { |
|
84 parsed = SetRRuleWkStL( aSegment, aRule ); |
|
85 break; |
|
86 } |
|
87 |
|
88 //ESegByDay |
|
89 case CICalRuleSegment::ESegByDay : |
|
90 { |
|
91 parsed = SetRRuleByDayL( aSegment, aRule ); |
|
92 break; |
|
93 } |
|
94 default: |
|
95 { |
|
96 parsed = EFalse; |
|
97 } |
|
98 } |
|
99 |
|
100 TRACE_EXIT_POINT; |
|
101 return parsed; |
|
102 } |
|
103 |
|
104 |
|
105 /** |
|
106 Finalize the parsing |
|
107 @param aRule recurrence rules |
|
108 @param aStartTime The DTSTART of the parent component. |
|
109 @return True if finalized parsing successfully |
|
110 */ |
|
111 TBool CAgnParseRRuleWeekly::FinalizeParsingL( TCalRRule& aRule, const TCalTime& aStartTime ) |
|
112 { |
|
113 TRACE_ENTRY_POINT; |
|
114 |
|
115 //Call the parent, to set some common values |
|
116 TBool finalized = CAgnParseRRule::FinalizeParsingL( aRule, aStartTime ); |
|
117 |
|
118 // If we are yearly or weekly we can only handle ByDay, and need to handle it |
|
119 // differently for each. |
|
120 if ( !( iSetSegs & ESegFlagByDay ) ) |
|
121 { |
|
122 RArray<TDay> days; |
|
123 CleanupClosePushL(days); |
|
124 User::LeaveIfError(days.Append(aStartTime.TimeUtcL().DayNoInWeek())); |
|
125 aRule.SetByDay(days); |
|
126 CleanupStack::PopAndDestroy(&days); |
|
127 } |
|
128 |
|
129 TRACE_EXIT_POINT; |
|
130 return finalized; |
|
131 } |
|
132 |
|
133 |
|
134 /** |
|
135 Update TCalRRule with by days |
|
136 @param aSegment recurrence rule value segment. |
|
137 @param aRule recurrence rules |
|
138 @return true if aRule updated successfully |
|
139 */ |
|
140 TBool CAgnParseRRuleWeekly::SetRRuleByDayL( const CICalRuleSegment& aSegment, TCalRRule& aRule ) |
|
141 { |
|
142 TRACE_ENTRY_POINT; |
|
143 |
|
144 TBool parsed = ETrue; |
|
145 |
|
146 RArray<TDay> days; |
|
147 CleanupClosePushL(days); |
|
148 |
|
149 const RPointerArray<CICalValue>& values = aSegment.Values(); |
|
150 TInt valCount = values.Count(); |
|
151 TDay dayval = EMonday; |
|
152 TInt daypos = 0; |
|
153 |
|
154 for (TInt day = 0; day < valCount; ++day) |
|
155 { |
|
156 values[day]->GetDayL(dayval, daypos); |
|
157 |
|
158 if (daypos == 0) |
|
159 { |
|
160 TRACE_EXIT_POINT; |
|
161 User::LeaveIfError(days.Append(dayval)); |
|
162 } |
|
163 else |
|
164 { |
|
165 /* |
|
166 Fix this: |
|
167 |
|
168 We should report an error here |
|
169 */ |
|
170 //return parsed false, which will cause parent class to report an error |
|
171 //parsed = EFalse; |
|
172 //break; |
|
173 } |
|
174 } |
|
175 |
|
176 if( parsed ) |
|
177 { |
|
178 aRule.SetByDay(days); |
|
179 iSetSegs |= ESegFlagByDay; |
|
180 } |
|
181 |
|
182 CleanupStack::PopAndDestroy(&days); |
|
183 |
|
184 TRACE_EXIT_POINT; |
|
185 return parsed; |
|
186 } |