|
1 /* |
|
2 * Copyright (c) 2002-2004 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 CESMRICalRuleSegment. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Class include. |
|
20 #include "emailtrace.h" |
|
21 #include "cesmricalrulesegment.h" // CESMRICalRuleSegment |
|
22 |
|
23 //debug |
|
24 |
|
25 // User includes. |
|
26 #include "esmricalkeywords.h" // Literals |
|
27 #include "esmricalerrors.h" // Error codes |
|
28 #include "cesmricalvalue.h" // CESMRICalValue |
|
29 |
|
30 /** |
|
31 Static factory construction. Not exported as this class is only provided as a |
|
32 utility for breaking down recurrence rules into segments - it is only ever |
|
33 created by the CESMRICalValue class. |
|
34 @param aSource TDesC containing the rule segment information |
|
35 @return A new rule segment |
|
36 @internalTechnology |
|
37 */ |
|
38 CESMRICalRuleSegment* CESMRICalRuleSegment::NewL(const TDesC& aSource) |
|
39 { |
|
40 FUNC_LOG; |
|
41 |
|
42 CESMRICalRuleSegment* self = CESMRICalRuleSegment::NewLC(aSource); |
|
43 CleanupStack::Pop(self); |
|
44 |
|
45 return self; |
|
46 } |
|
47 |
|
48 /** |
|
49 Static factory construction. Not exported as this class is only provided as a |
|
50 utility for breaking down recurrence rules into segments - it is only ever |
|
51 created by the CESMRICalValue class. |
|
52 @param aSource TDesC containing the rule segment information |
|
53 @return A new rule segment |
|
54 @internalTechnology |
|
55 */ |
|
56 CESMRICalRuleSegment* CESMRICalRuleSegment::NewLC(const TDesC& aSource) |
|
57 { |
|
58 FUNC_LOG; |
|
59 |
|
60 CESMRICalRuleSegment* self = new (ELeave) CESMRICalRuleSegment; |
|
61 CleanupStack::PushL(self); |
|
62 self->ConstructL(aSource); |
|
63 |
|
64 return self; |
|
65 } |
|
66 |
|
67 /** |
|
68 Destructor |
|
69 @internalTechnology |
|
70 */ |
|
71 CESMRICalRuleSegment::~CESMRICalRuleSegment() |
|
72 { |
|
73 FUNC_LOG; |
|
74 |
|
75 iValues.ResetAndDestroy(); |
|
76 delete iTypeString; |
|
77 } |
|
78 |
|
79 /** |
|
80 Access method for the segment type as a descriptor. |
|
81 @return The segment type as a descriptor or an empty descriptor if no type is |
|
82 set. |
|
83 @publishedPartner |
|
84 */ |
|
85 EXPORT_C const TDesC& CESMRICalRuleSegment::TypeName() const |
|
86 { |
|
87 FUNC_LOG; |
|
88 |
|
89 if (iTypeString) |
|
90 { |
|
91 return *iTypeString; |
|
92 } |
|
93 |
|
94 // Else type is not set due to SetTypeL() leaving. |
|
95 return KNullDesC; |
|
96 } |
|
97 |
|
98 /** |
|
99 Access method for the value array. |
|
100 @return The value array. |
|
101 @publishedPartner |
|
102 */ |
|
103 EXPORT_C const RPointerArray<CESMRICalValue>& CESMRICalRuleSegment::Values() const |
|
104 { |
|
105 return iValues; |
|
106 } |
|
107 |
|
108 /** |
|
109 Access method for the segment type as an enumeration. |
|
110 @return The segment type as an enumeration. |
|
111 @publishedPartner |
|
112 */ |
|
113 EXPORT_C CESMRICalRuleSegment::TSegmentType CESMRICalRuleSegment::Type() const |
|
114 { |
|
115 FUNC_LOG; |
|
116 return iType; |
|
117 } |
|
118 |
|
119 /** |
|
120 Access method for the segment value as a frequency enumeration. Only the first |
|
121 value is used. |
|
122 @return The segment value as a frequency. |
|
123 @leave Leaves with KErrRuleTypeNotFrequency if this rule segment does not |
|
124 contain a frequency. |
|
125 @leave Leaves with KErrRuleFrequencyUnknown if the frequency cannot be |
|
126 determined. |
|
127 @publishedPartner |
|
128 */ |
|
129 EXPORT_C CESMRICalRuleSegment::TFreq CESMRICalRuleSegment::FreqL() const |
|
130 { |
|
131 FUNC_LOG; |
|
132 |
|
133 // Type MUST be frequency if this method is called. |
|
134 |
|
135 if (iType != ESegFreq) |
|
136 { |
|
137 User::Leave(KErrRuleTypeNotFrequency); |
|
138 } |
|
139 |
|
140 // The rule must have at least one value. |
|
141 // If it has more than one then the first value is taken (for recoverability). |
|
142 if (iValues.Count() == 0) |
|
143 { |
|
144 User::Leave(KErrRuleFrequencyUnknown); |
|
145 } |
|
146 |
|
147 // Compare the first value. |
|
148 const TDesC& firstValue = iValues[0]->TextL(); |
|
149 |
|
150 if (firstValue.CompareF(KICalYearly) == 0) |
|
151 { |
|
152 return EFreqYearly; |
|
153 } |
|
154 else if (firstValue.CompareF(KICalMonthly) == 0) |
|
155 { |
|
156 return EFreqMonthly; |
|
157 } |
|
158 else if (firstValue.CompareF(KICalWeekly) == 0) |
|
159 { |
|
160 return EFreqWeekly; |
|
161 } |
|
162 else if (firstValue.CompareF(KICalDaily) == 0) |
|
163 { |
|
164 return EFreqDaily; |
|
165 } |
|
166 else if (firstValue.CompareF(KICalHourly) == 0) |
|
167 { |
|
168 return EFreqHourly; |
|
169 } |
|
170 else if (firstValue.CompareF(KICalMinutely) == 0) |
|
171 { |
|
172 return EFreqMinutely; |
|
173 } |
|
174 else if (firstValue.CompareF(KICalSecondly) == 0) |
|
175 { |
|
176 return EFreqSecondly; |
|
177 } |
|
178 |
|
179 // Else... |
|
180 User::Leave(KErrRuleFrequencyUnknown); |
|
181 |
|
182 return EFreqDaily; // Never reached. |
|
183 } |
|
184 |
|
185 /** |
|
186 Constructor |
|
187 @internalTechnology |
|
188 */ |
|
189 CESMRICalRuleSegment::CESMRICalRuleSegment() |
|
190 { |
|
191 FUNC_LOG; |
|
192 } |
|
193 |
|
194 /** |
|
195 Internal construction. |
|
196 @param aSource Descriptor containing details of the segment. |
|
197 @leave Leaves with KErrInvalidRuleSegment if the rule segment has no "type". |
|
198 @leave Leaves with KErrRuleSegmentHasNoValue if the rule segment has no value. |
|
199 @leave Leaves if there is an error adding a value to this rule segment. |
|
200 @internalTechnology |
|
201 */ |
|
202 void CESMRICalRuleSegment::ConstructL(const TDesC& aSource) |
|
203 { |
|
204 FUNC_LOG; |
|
205 |
|
206 // We've been passed a descriptor containing the type string followed |
|
207 // by an equals sign followed by (one or more) comma separated values. |
|
208 // All escaping is assumed to have been previously removed. |
|
209 |
|
210 // Get the position of the equals sign. |
|
211 const TInt equalsSignPos = aSource.Locate(KICalEqualsChar); |
|
212 |
|
213 if (equalsSignPos < 1) // "Type" must be at least one character long. |
|
214 { |
|
215 User::Leave(KErrInvalidRuleSegment); |
|
216 } |
|
217 |
|
218 if ((equalsSignPos + 1) >= aSource.Length()) // Value must be at least one character long. |
|
219 { |
|
220 User::Leave(KErrRuleSegmentHasNoValue); |
|
221 } |
|
222 |
|
223 // Any text before this point is the type string. |
|
224 SetTypeL(aSource.Left(equalsSignPos)); |
|
225 |
|
226 // Any text after this point contains value information |
|
227 TPtrC aRemainder(aSource.Mid(equalsSignPos + 1)); |
|
228 |
|
229 while (aRemainder.Length() > 0) |
|
230 { |
|
231 // Find the next comma. |
|
232 TInt endOfValue(aRemainder.Locate(KICalCommaChar)); |
|
233 |
|
234 if (endOfValue == KErrNotFound) |
|
235 { |
|
236 endOfValue = aRemainder.Length(); |
|
237 } |
|
238 |
|
239 // Add value. |
|
240 if (endOfValue > 0) |
|
241 { |
|
242 CESMRICalValue* val = CESMRICalValue::NewLC(); |
|
243 val->SetTextL(aRemainder.Left(endOfValue)); |
|
244 User::LeaveIfError(iValues.Append(val)); |
|
245 CleanupStack::Pop(val); |
|
246 } |
|
247 |
|
248 // Set the remainder. |
|
249 if (endOfValue < (aRemainder.Length() - 1)) // Value must be at least one character long. |
|
250 { |
|
251 aRemainder.Set(aRemainder.Mid(endOfValue + 1)); |
|
252 } |
|
253 else |
|
254 { |
|
255 break; |
|
256 } |
|
257 } |
|
258 |
|
259 } |
|
260 |
|
261 /** |
|
262 Sets the type of a rule segment. |
|
263 @param aType The type as a descriptor. |
|
264 @internalTechnology |
|
265 */ |
|
266 void CESMRICalRuleSegment::SetTypeL(const TDesC& aType) |
|
267 { |
|
268 FUNC_LOG; |
|
269 |
|
270 // Set the type. |
|
271 |
|
272 if (aType.CompareF(KICalFreq) == 0) |
|
273 { |
|
274 iType = ESegFreq; |
|
275 } |
|
276 else if (aType.CompareF(KICalUntil) == 0) |
|
277 { |
|
278 iType = ESegUntil; |
|
279 } |
|
280 else if (aType.CompareF(KICalCount) == 0) |
|
281 { |
|
282 iType = ESegCount; |
|
283 } |
|
284 else if (aType.CompareF(KICalInterval) == 0) |
|
285 { |
|
286 iType = ESegInterval; |
|
287 } |
|
288 else if (aType.CompareF(KICalBySecond) == 0) |
|
289 { |
|
290 iType = ESegBySecond; |
|
291 } |
|
292 else if (aType.CompareF(KICalByMinute) == 0) |
|
293 { |
|
294 iType = ESegByMinute; |
|
295 } |
|
296 else if (aType.CompareF(KICalByHour) == 0) |
|
297 { |
|
298 iType = ESegByHour; |
|
299 } |
|
300 else if (aType.CompareF(KICalByDay) == 0) |
|
301 { |
|
302 iType = ESegByDay; |
|
303 } |
|
304 else if (aType.CompareF(KICalByMonthDay) == 0) |
|
305 { |
|
306 iType = ESegByMonthDay; |
|
307 } |
|
308 else if (aType.CompareF(KICalByYearDay) == 0) |
|
309 { |
|
310 iType = ESegByYearDay; |
|
311 } |
|
312 else if (aType.CompareF(KICalByWeekNo) == 0) |
|
313 { |
|
314 iType = ESegByWeekNo; |
|
315 } |
|
316 else if (aType.CompareF(KICalByMonth) == 0) |
|
317 { |
|
318 iType = ESegByMonth; |
|
319 } |
|
320 else if (aType.CompareF(KICalBySetPos) == 0) |
|
321 { |
|
322 iType = ESegByPos; |
|
323 } |
|
324 else if (aType.CompareF(KICalWkSt) == 0) |
|
325 { |
|
326 iType = ESegWkSt; |
|
327 } |
|
328 else |
|
329 { |
|
330 iType = ESegExtension; |
|
331 } |
|
332 |
|
333 // Set the type string. |
|
334 delete iTypeString; |
|
335 iTypeString = NULL; |
|
336 iTypeString = aType.AllocL(); |
|
337 |
|
338 } |
|
339 |
|
340 // End of File |
|
341 |