|
1 /* |
|
2 * Copyright (c) 2008 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: Base class for the Agenda Model event adapter managers |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // CLASS HEADER |
|
20 #include "cpimeventadaptermanager.h" |
|
21 #include "logger.h" |
|
22 |
|
23 // INTERNAL INCLUDES |
|
24 #include "mpimitem.h" |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // CPIMApptAdapterManager::ConstructL |
|
28 // Symbian 2nd phase constructor can leave. |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 void CPIMEventAdapterManager::ConstructL(const TDesC& aListName) |
|
32 { |
|
33 JELOG2(EPim); |
|
34 iListName = aListName.AllocL(); |
|
35 } |
|
36 |
|
37 // Destructor |
|
38 CPIMEventAdapterManager::~CPIMEventAdapterManager() |
|
39 { |
|
40 JELOG2(EPim); |
|
41 delete iRepeatRuleFieldArray; |
|
42 delete iRepeatRuleFieldArrayEmpty; |
|
43 delete iRepeatRuleIntervalArray; |
|
44 delete iRepeatRuleIntervalArrayEmpty; |
|
45 delete iEventAttributeArray; |
|
46 delete iListName; |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CPIMEventAdapterManager::GetSupportedRepeatRuleFields |
|
51 // Provides the supported repeat rule fields for a given frequency. |
|
52 // Returns: Supported repeat rule fields for \a aFrequency. If no |
|
53 // fields are supported for the frequency, an empty array is returned. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 const CArrayFix<TPIMField>& |
|
57 CPIMEventAdapterManager::GetSupportedRepeatRuleFieldsL( |
|
58 const TPIMRepeatRuleFrequency& aFrequency) |
|
59 { |
|
60 JELOG2(EPim); |
|
61 const CArrayFix<TPIMField>* retVal = NULL; |
|
62 |
|
63 switch (aFrequency) |
|
64 { |
|
65 case EPIMRepeatRuleDaily: |
|
66 case EPIMRepeatRuleMonthly: |
|
67 case EPIMRepeatRuleYearly: |
|
68 { |
|
69 // Return a one item array with the item frequency |
|
70 if (!iRepeatRuleFieldArrayEmpty) |
|
71 { |
|
72 iRepeatRuleFieldArrayEmpty |
|
73 = new(ELeave) CArrayFixFlat<TPIMField> (1); |
|
74 iRepeatRuleFieldArrayEmpty->AppendL(EPIMRepeatRuleFrequency); |
|
75 } |
|
76 retVal = iRepeatRuleFieldArrayEmpty; |
|
77 break; |
|
78 } |
|
79 case EPIMRepeatRuleWeekly: |
|
80 { |
|
81 if (!iRepeatRuleFieldArray) |
|
82 { |
|
83 iRepeatRuleFieldArray |
|
84 = new(ELeave) CArrayFixFlat<TPIMField> (KPIMSupportedRepeatRuleFieldsCount); |
|
85 |
|
86 iRepeatRuleFieldArray->AppendL(KPIMSupportedRepeatRuleFields, |
|
87 KPIMSupportedRepeatRuleFieldsCount); |
|
88 } |
|
89 retVal = iRepeatRuleFieldArray; |
|
90 break; |
|
91 } |
|
92 default: |
|
93 { |
|
94 User::Leave(KErrArgument); // Field was not a valid field |
|
95 } |
|
96 } |
|
97 |
|
98 return *retVal; |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CPIMEventAdapterManager::GetSupportedIntervals |
|
103 // Provides the supported interval values for given frequency. |
|
104 // Returns: Supported interval values for given frequency. If the |
|
105 // interval field is not supported for given frequency, |
|
106 // an empty array is returned. |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 const CArrayFix<TInt>& CPIMEventAdapterManager::GetSupportedIntervalsL( |
|
110 const TPIMRepeatRuleFrequency& aFrequency) |
|
111 { |
|
112 JELOG2(EPim); |
|
113 const CArrayFix<TInt>* retVal = NULL; |
|
114 |
|
115 switch (aFrequency) |
|
116 { |
|
117 case EPIMRepeatRuleDaily: |
|
118 case EPIMRepeatRuleMonthly: |
|
119 case EPIMRepeatRuleYearly: |
|
120 { |
|
121 // Return an empty array indicating no supported fields |
|
122 if (!iRepeatRuleIntervalArrayEmpty) |
|
123 { |
|
124 iRepeatRuleIntervalArrayEmpty |
|
125 = new(ELeave) CArrayFixFlat<TInt> (1); |
|
126 } |
|
127 retVal = iRepeatRuleIntervalArrayEmpty; |
|
128 break; |
|
129 } |
|
130 case EPIMRepeatRuleWeekly: |
|
131 { |
|
132 if (!iRepeatRuleIntervalArray) |
|
133 { |
|
134 iRepeatRuleIntervalArray |
|
135 = new(ELeave) CArrayFixFlat<TPIMField> (KPIMSupportedRepeatRuleIntervalsCount); |
|
136 |
|
137 iRepeatRuleIntervalArray->AppendL(KPIMSupportedRepeatRuleIntervals, |
|
138 KPIMSupportedRepeatRuleIntervalsCount); |
|
139 } |
|
140 retVal = iRepeatRuleIntervalArray; |
|
141 break; |
|
142 } |
|
143 default: |
|
144 { |
|
145 User::Leave(KErrArgument); // Field was not a valid field |
|
146 } |
|
147 } |
|
148 |
|
149 return *retVal; |
|
150 } |
|
151 |
|
152 const TDesC& CPIMEventAdapterManager::ListNameL() |
|
153 { |
|
154 JELOG2(EPim); |
|
155 return *iListName; |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CPIMEventAdapterManager::MaxCategories |
|
160 // Returns: The maximum number of categories that this list can have. |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 |
|
164 TInt CPIMEventAdapterManager::MaxCategories() |
|
165 { |
|
166 JELOG2(EPim); |
|
167 return 0; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CPIMEventAdapterManager::IsSupportedField |
|
172 // Returns: ETrue if supported in this list, EFalse if not supported or invalid. |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 |
|
176 TBool CPIMEventAdapterManager::IsSupportedField(TPIMField aField) // The field to check |
|
177 { |
|
178 JELOG2(EPim); |
|
179 TInt fieldFinder; |
|
180 TInt fetchIndex = 0; |
|
181 TKeyArrayFix key(0, ECmpTInt); |
|
182 fieldFinder = iSupportedFields->Find(aField, key, fetchIndex); |
|
183 if (fieldFinder != 0) // 0 means that the element was found |
|
184 { |
|
185 return EFalse; |
|
186 } |
|
187 return ETrue; |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CPIMEventAdapterManager::GetSupportedFieldsL |
|
192 // Returns: An int array containing all fields supported by this list. |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 |
|
196 const CArrayFix<TPIMField>& CPIMEventAdapterManager::GetSupportedFieldsL() |
|
197 { |
|
198 JELOG2(EPim); |
|
199 return *iSupportedFields; |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CPIMEventAdapterManager::IsSupportedAttribute |
|
204 // Returns: EFalse, as there are no supported attributes in Event list. |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 |
|
208 TBool CPIMEventAdapterManager::IsSupportedAttribute(TPIMField /* aField */, // The field to check the supported attribute from |
|
209 TPIMAttribute /* aAttribute */) // The attribute to check |
|
210 { |
|
211 JELOG2(EPim); |
|
212 return EFalse; |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CPIMEventAdapterManager::GetSupportedAttributesL |
|
217 // Returns: An empty array meaning no supported attributes. |
|
218 // ----------------------------------------------------------------------------- |
|
219 // |
|
220 |
|
221 const CArrayFix<TPIMAttribute>& |
|
222 CPIMEventAdapterManager::GetSupportedAttributesL(TPIMField aField) // The field to check the supported attributes from |
|
223 { |
|
224 JELOG2(EPim); |
|
225 if (!IsSupportedField(aField)) |
|
226 { |
|
227 User::Leave(KErrArgument); // Field was not a valid field |
|
228 } |
|
229 |
|
230 if (!iEventAttributeArray) |
|
231 { |
|
232 iEventAttributeArray = new(ELeave) CArrayFixFlat<TPIMAttribute> (1); |
|
233 } |
|
234 return *iEventAttributeArray; |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CPIMEventAdapterManager::GetSupportedAttributesCombinedL |
|
239 // Returns: An integer holding the combination of all attributes |
|
240 // supported for aField (KPIMAttrNone meaning no supported attributes). |
|
241 // ----------------------------------------------------------------------------- |
|
242 |
|
243 TPIMAttribute CPIMEventAdapterManager::GetSupportedAttributesCombinedL( |
|
244 TPIMField aField) // The field to check the supported attributes from |
|
245 { |
|
246 JELOG2(EPim); |
|
247 if (!IsSupportedField(aField)) |
|
248 { |
|
249 User::Leave(KErrArgument); // Field was not a valid field |
|
250 } |
|
251 |
|
252 return KPIMAttrNone; |
|
253 } |
|
254 |
|
255 TPIMAttribute CPIMEventAdapterManager::GetAllSupportedAttributesCombined() |
|
256 { |
|
257 JELOG2(EPim); |
|
258 return KPIMAttrNone; |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // CPIMEventAdapterManager::IsSupportedArrayElement |
|
263 // Returns: EFalse, as there are no supported array elements in ToDo list. |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 |
|
267 TBool CPIMEventAdapterManager::IsSupportedArrayElement( |
|
268 TPIMField /* aStringArrayField */, // The field where array element belongs |
|
269 TPIMArrayElement /* aArrayElement */) // The array element to check |
|
270 { |
|
271 JELOG2(EPim); |
|
272 return EFalse; |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CPIMEventAdapterManager::GetSupportedArrayElementsL |
|
277 // Returns: An integer array containing all of the supported elements of a |
|
278 // string array for the given field. |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 |
|
282 const CArrayFix<TPIMArrayElement>& |
|
283 CPIMEventAdapterManager::GetSupportedArrayElementsL(TPIMField /* aField */) // The field to check the supported array elements |
|
284 { |
|
285 JELOG2(EPim); |
|
286 User::Leave(KErrArgument); // No array elements in Event list. |
|
287 // Even this method leaves always, the compiler requires it to return an |
|
288 // array. |
|
289 // The next line is only because of that, and actually it is never executed. |
|
290 const CArrayFix<TPIMArrayElement>* temp = NULL; |
|
291 return *temp; |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CPIMEventAdapterManager::MaxValues |
|
296 // Returns: Number of values supported for the field |
|
297 // -1 : The field supports having an unlimited number of values in it. |
|
298 // 0 : The field is not supported by this list. |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 |
|
302 TInt CPIMEventAdapterManager::MaxValues(TPIMField aField) // The field to check for multiple value support |
|
303 { |
|
304 JELOG2(EPim); |
|
305 if (IsSupportedField(aField)) |
|
306 { |
|
307 return 1; // Only one value is supported for any valid Event field |
|
308 } |
|
309 else |
|
310 { |
|
311 return 0; |
|
312 } |
|
313 } |
|
314 |
|
315 // ----------------------------------------------------------------------------- |
|
316 // CPIMEventAdapterManager::StringArraySizeL |
|
317 // Returns: Int the size of the array. |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 |
|
321 TInt CPIMEventAdapterManager::StringArraySizeL(TPIMField /* aStringArrayField */) // The field to check the array size |
|
322 { |
|
323 JELOG2(EPim); |
|
324 User::Leave(KErrArgument); |
|
325 // Even this method leaves always, the compiler requires it to return an |
|
326 // array. |
|
327 // The next line is only because of that, and actually it is never executed. |
|
328 return 0; |
|
329 } |
|
330 |
|
331 // ----------------------------------------------------------------------------- |
|
332 // CPIMEventAdapterManager::ItemOrder |
|
333 // Returns: pointer to a function which implements an algorithm that |
|
334 // determines the order of two items. |
|
335 // ----------------------------------------------------------------------------- |
|
336 // |
|
337 |
|
338 TPIMItemComparisonFunc CPIMEventAdapterManager::ItemOrder() |
|
339 { |
|
340 JELOG2(EPim); |
|
341 return ItemComparisonFunc; |
|
342 } |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CPIMEventAdapterManager::ItemComparisonFunc |
|
346 // Compares two MPIMItemData objects. The comparision is based primarily on the |
|
347 // start times, and secondary on the summary strings (if start times are equal). |
|
348 // Returns: < 0: aFirst < aSecond |
|
349 // 0: aFirst == aSecond |
|
350 // > 0: aFirst > aSecond |
|
351 // ----------------------------------------------------------------------------- |
|
352 // |
|
353 TInt CPIMEventAdapterManager::ItemComparisonFunc(const MPIMItem& aFirst, |
|
354 const MPIMItem& aSecond) |
|
355 { |
|
356 JELOG2(EPim); |
|
357 TInt retVal = 0; |
|
358 TRAPD(err, retVal = ItemComparisonFuncL(aFirst, aSecond)); |
|
359 if (err != KErrNone) |
|
360 { |
|
361 // The comparison function does not actually leave as it is used with |
|
362 // correct PIM field parameters, so this assert here is just for debug |
|
363 __ASSERT_DEBUG(EFalse, User::Panic(KPIMPanicCategory, EPIMPanicGeneral)); |
|
364 } |
|
365 return retVal; |
|
366 } |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CPIMEventAdapterManager::ItemComparisonFuncL |
|
370 // Compares two MPIMItemData objects. The comparision is based primarily on the |
|
371 // start times, and secondary on the summary strings (if start times are equal). |
|
372 // Returns: < 0: aFirst < aSecond |
|
373 // 0: aFirst == aSecond |
|
374 // > 0: aFirst > aSecond |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 TInt CPIMEventAdapterManager::ItemComparisonFuncL(const MPIMItem& aFirst, |
|
378 const MPIMItem& aSecond) |
|
379 { |
|
380 JELOG2(EPim); |
|
381 TInt firstPresent = aFirst.CountValuesL(EPIMEventStart); |
|
382 TInt secondPresent = aSecond.CountValuesL(EPIMEventStart); |
|
383 |
|
384 if ((firstPresent == 0) ^(secondPresent == 0)) |
|
385 // Only one of the fields is present |
|
386 { |
|
387 return secondPresent - firstPresent; |
|
388 } |
|
389 |
|
390 else if (firstPresent > 0 && secondPresent > 0) |
|
391 // Both fields are present |
|
392 { |
|
393 const TPIMDate dateFirst = aFirst.GetDateL(EPIMEventStart, 0); |
|
394 const TPIMDate dateSecond = aSecond.GetDateL(EPIMEventStart, 0); |
|
395 |
|
396 if (dateFirst < dateSecond) |
|
397 { |
|
398 return -1; |
|
399 } |
|
400 else if (dateFirst > dateSecond) |
|
401 { |
|
402 return 1; |
|
403 } |
|
404 } |
|
405 |
|
406 // In this point either none of the items have start time field, or |
|
407 // the other possibility is that the start time fields are exactly equal. |
|
408 // Continue the comparision based on the 2nd criteria, the summary field. |
|
409 firstPresent = aFirst.CountValuesL(EPIMEventSummary); |
|
410 secondPresent = aSecond.CountValuesL(EPIMEventSummary); |
|
411 |
|
412 if ((firstPresent == 0) ^(secondPresent == 0)) // xor |
|
413 { |
|
414 // Only one of the fields is present |
|
415 return secondPresent - firstPresent; |
|
416 } |
|
417 |
|
418 else if (firstPresent > 0 && secondPresent > 0) |
|
419 // Both fields are present |
|
420 { |
|
421 return aFirst.GetStringL(EPIMEventSummary, 0).CompareC( |
|
422 aSecond.GetStringL(EPIMEventSummary, 0)); |
|
423 } |
|
424 |
|
425 // If start time AND summary are missing in both items, they are equal. |
|
426 return 0; |
|
427 } |
|
428 |
|
429 // End of File |