|
1 /* |
|
2 * Copyright (c) 2007-2009 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 implements class CESMRAgnRRuleImporter. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include "cesmragnrruleimporter.h" |
|
21 |
|
22 //<cmail> |
|
23 |
|
24 // Agenda includes. |
|
25 #include <calrrule.h> // For CCalRRule |
|
26 |
|
27 // Versit includes. |
|
28 #include "esmricalkeywords.h" // for cesmricalkeywords |
|
29 #include "cesmricalproperty.h" // for cesmricalproperty |
|
30 #include "cesmricalvalue.h" // for cesmricalvalue |
|
31 //</cmail> |
|
32 |
|
33 |
|
34 #include "esmrcleanuppointerarray.h" // For TCleanupPointerArray |
|
35 |
|
36 // RRule Parser includes |
|
37 #include "cesmragnparserruleyearly.h" // For CESMRAgnParseRRuleYearly |
|
38 #include "cesmragnparserrulemonthly.h" // For CESMRAgnParseRRuleMonthly |
|
39 #include "cesmragnparserruleweekly.h" // For CESMRAgnParseRRuleWeekly |
|
40 #include "cesmragnparserruledaily.h" // For CESMRAgnParseRRuleDaily |
|
41 |
|
42 // ======== MEMBER FUNCTIONS ======== |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CESMRAgnRRuleImporter::CESMRAgnRRuleImporter |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CESMRAgnRRuleImporter::CESMRAgnRRuleImporter( MESMRAgnImpUtil& aAgnImpUtil ): iAgnImpUtil( aAgnImpUtil ) |
|
49 { |
|
50 FUNC_LOG; |
|
51 //do nothing |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // CESMRAgnRRuleImporter::~CESMRAgnRRuleImporter |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CESMRAgnRRuleImporter::~CESMRAgnRRuleImporter() |
|
59 { |
|
60 FUNC_LOG; |
|
61 //do nothing |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // CESMRAgnRRuleImporter::NewL |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 CESMRAgnRRuleImporter* CESMRAgnRRuleImporter::NewL( MESMRAgnImpUtil& aAgnImpUtil ) |
|
69 { |
|
70 FUNC_LOG; |
|
71 CESMRAgnRRuleImporter *self = CESMRAgnRRuleImporter::NewLC( aAgnImpUtil ); |
|
72 CleanupStack::Pop(self); |
|
73 |
|
74 return self; |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CESMRAgnRRuleImporter::NewLC |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 CESMRAgnRRuleImporter* CESMRAgnRRuleImporter::NewLC( MESMRAgnImpUtil& aAgnImpUtil ) |
|
82 { |
|
83 FUNC_LOG; |
|
84 |
|
85 CESMRAgnRRuleImporter *self = new (ELeave)CESMRAgnRRuleImporter( aAgnImpUtil ); |
|
86 CleanupStack::PushL(self); |
|
87 self->ConstructL(); |
|
88 |
|
89 return self; |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CESMRAgnRRuleImporter::ConstructL |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CESMRAgnRRuleImporter::ConstructL() |
|
97 { |
|
98 FUNC_LOG; |
|
99 //do nothing |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CESMRAgnRRuleImporter::ImportL |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 TBool CESMRAgnRRuleImporter::ImportL( const CESMRICalProperty& aProperty, CCalEntry& aEntry, const TCalTime& aStartTime ) |
|
107 { |
|
108 FUNC_LOG; |
|
109 |
|
110 //=============================== |
|
111 //Frequency and recurrency rules |
|
112 //=============================== |
|
113 const RPointerArray<CESMRICalValue>& rulevalues = aProperty.Values(); |
|
114 |
|
115 // There should never be less than 1 value. |
|
116 if (rulevalues.Count() < 1) |
|
117 { |
|
118 // We can't continue so abort. |
|
119 iAgnImpUtil.ReportErrorL(MESMRAgnImportObserver::EImpErrorMissingData, aEntry.UidL(), KICalRRule, EFalse); |
|
120 } |
|
121 |
|
122 CESMRICalRuleSegment::TFreq freq = CESMRICalRuleSegment::EFreqDaily; |
|
123 RPointerArray<CESMRICalRuleSegment> recRules; |
|
124 CleanupPointerArrayPushL(recRules); |
|
125 |
|
126 // At this point we take ownership of the things which rules contains: |
|
127 rulevalues[0]->GetRecurrenceRuleL(recRules); |
|
128 |
|
129 // An RRule must have a frequency. |
|
130 TInt pos = iAgnImpUtil.FindRuleSegment(recRules, CESMRICalRuleSegment::ESegFreq); |
|
131 |
|
132 if (pos != KErrNotFound) |
|
133 { |
|
134 ASSERT(recRules.Count() >= pos + 1); |
|
135 freq = recRules[pos]->FreqL(); |
|
136 } |
|
137 else |
|
138 { |
|
139 iAgnImpUtil.ReportErrorL(MESMRAgnImportObserver::EImpErrorMissingData, aEntry.UidL(), rulevalues[0]->TextL()); |
|
140 // On continue, EFreqDaily will be used. |
|
141 } |
|
142 |
|
143 //=================================== |
|
144 // Create Parser and parse the rrule |
|
145 //=================================== |
|
146 TBool parsed = EFalse; |
|
147 TCalRRule rule; |
|
148 |
|
149 //Create parser and parse the recurrency rule |
|
150 CESMRAgnParseRRule* parser = CreateParserLC( freq, rule ); |
|
151 |
|
152 if( parser ) |
|
153 { |
|
154 //if parser returns true the RRule was parsed successfully |
|
155 parsed = parser->ParseL( rule, recRules, aStartTime, aEntry.UidL(), rulevalues ); |
|
156 CleanupStack::PopAndDestroy( parser ); |
|
157 } |
|
158 else |
|
159 { |
|
160 parsed = EFalse; |
|
161 iAgnImpUtil.ReportErrorL(MESMRAgnImportObserver::EImpErrorNotSupported, aEntry.UidL(), rulevalues[0]->TextL()); |
|
162 } |
|
163 |
|
164 //================================= |
|
165 // Update aEntry if parsed is true |
|
166 //================================= |
|
167 if ( parsed ) |
|
168 { |
|
169 aEntry.SetRRuleL(rule); |
|
170 } |
|
171 |
|
172 CleanupStack::PopAndDestroy(&recRules); |
|
173 |
|
174 return parsed; |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // CESMRAgnRRuleImporter::CreateParserLC |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 /** |
|
182 Factory method to create the RRule parser |
|
183 @param aFreq The RRULE frequency |
|
184 @param aRule rule to add the frequency to |
|
185 @return returns NULL if parser for CESMRICalRuleSegment::TFreq type not found, otherwise parser |
|
186 */ |
|
187 CESMRAgnParseRRule* CESMRAgnRRuleImporter::CreateParserLC( const CESMRICalRuleSegment::TFreq aFreq, TCalRRule& aRule ) |
|
188 { |
|
189 FUNC_LOG; |
|
190 |
|
191 CESMRAgnParseRRule* parser; |
|
192 |
|
193 switch ( aFreq ) |
|
194 { |
|
195 //Daily |
|
196 case CESMRICalRuleSegment::EFreqDaily : |
|
197 { |
|
198 aRule.SetType(TCalRRule::EDaily); |
|
199 parser = CESMRAgnParseRRuleDaily::NewLC( iAgnImpUtil ); |
|
200 break; |
|
201 } |
|
202 //Weekly |
|
203 case CESMRICalRuleSegment::EFreqWeekly : |
|
204 { |
|
205 aRule.SetType(TCalRRule::EWeekly); |
|
206 parser = CESMRAgnParseRRuleWeekly::NewLC( iAgnImpUtil ); |
|
207 break; |
|
208 } |
|
209 //Monthly |
|
210 case CESMRICalRuleSegment::EFreqMonthly : |
|
211 { |
|
212 aRule.SetType(TCalRRule::EMonthly); |
|
213 parser = CESMRAgnParseRRuleMonthly::NewLC( iAgnImpUtil ); |
|
214 break; |
|
215 } |
|
216 //Yearly |
|
217 case CESMRICalRuleSegment::EFreqYearly : |
|
218 { |
|
219 aRule.SetType(TCalRRule::EYearly); |
|
220 parser = CESMRAgnParseRRuleYearly::NewLC( iAgnImpUtil ); |
|
221 break; |
|
222 } |
|
223 //Not supported |
|
224 case CESMRICalRuleSegment::EFreqSecondly : // Not supported, fall through... |
|
225 case CESMRICalRuleSegment::EFreqMinutely : // Not supported, fall through... |
|
226 case CESMRICalRuleSegment::EFreqHourly : // Not supported, fall through... |
|
227 default : |
|
228 { |
|
229 parser = NULL; |
|
230 } |
|
231 |
|
232 } |
|
233 |
|
234 return parser; |
|
235 } |
|
236 |