|
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: Provides static information about todo lists and creates |
|
15 * todo list adapters. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // CLASS HEADER |
|
21 #include "cpimtodoadaptermanager.h" |
|
22 |
|
23 // INTERNAL INCLUDES |
|
24 #include "mpimitem.h" |
|
25 #include "cpimtodolistadapter.h" |
|
26 #include "pimlocalizationids.h" |
|
27 #include "logger.h" |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CPIMToDoAdapterManager::CPIMToDoAdapterManager |
|
31 // C++ default constructor can NOT contain any code, that |
|
32 // might leave. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CPIMToDoAdapterManager::CPIMToDoAdapterManager() |
|
36 { |
|
37 JELOG2(EPim); |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CPIMToDoAdapterManager::ConstructL |
|
42 // Symbian 2nd phase constructor can leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 void CPIMToDoAdapterManager::ConstructL(const TDesC& aListName) |
|
46 { |
|
47 JELOG2(EPim); |
|
48 iListName = aListName.AllocL(); |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CPIMToDoAdapterManager::NewL |
|
53 // Two-phased constructor. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CPIMToDoAdapterManager* CPIMToDoAdapterManager::NewL(const TDesC& aListName) |
|
57 { |
|
58 JELOG2(EPim); |
|
59 CPIMToDoAdapterManager* self = new(ELeave) CPIMToDoAdapterManager; |
|
60 |
|
61 CleanupStack::PushL(self); |
|
62 self->ConstructL(aListName); |
|
63 CleanupStack::Pop(self); |
|
64 |
|
65 return self; |
|
66 } |
|
67 |
|
68 // Destructor |
|
69 CPIMToDoAdapterManager::~CPIMToDoAdapterManager() |
|
70 { |
|
71 JELOG2(EPim); |
|
72 delete iSupportedToDoFields; |
|
73 delete iEmptyToDoAttributeArray; |
|
74 delete iListName; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CPIMToDoAdapterManager::GetAdapterManager |
|
79 // Provides access to the MPIMAdapterManager representation of this object. |
|
80 // Returns: MPIMAdapterManager representation of this object. |
|
81 // ----------------------------------------------------------------------------- |
|
82 MPIMAdapterManager* CPIMToDoAdapterManager::GetAdapterManager() |
|
83 { |
|
84 JELOG2(EPim); |
|
85 return this; |
|
86 } |
|
87 |
|
88 const TDesC& CPIMToDoAdapterManager::ListNameL() |
|
89 { |
|
90 JELOG2(EPim); |
|
91 return *iListName; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CPIMToDoAdapterManager::MaxCategories |
|
96 // Returns: The maximum number of categories that this list can have. |
|
97 // 0 indicates no category support, |
|
98 // -1 indicates there is no limit on the number of categories that this |
|
99 // list can have |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 |
|
103 TInt CPIMToDoAdapterManager::MaxCategories() |
|
104 { |
|
105 JELOG2(EPim); |
|
106 return 0; |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CPIMToDoAdapterManager::IsSupportedField |
|
111 // Returns: ETrue if supported in this list, EFalse otherwise. Invalid fields |
|
112 // return false. |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 |
|
116 TBool CPIMToDoAdapterManager::IsSupportedField(TPIMField aField) |
|
117 { |
|
118 JELOG2(EPim); |
|
119 for (TInt index = 0; index < KPIMSupportedToDoFieldsCount; index++) |
|
120 { |
|
121 if (aField == KPIMSupportedToDoFields[index]) |
|
122 { |
|
123 return ETrue; |
|
124 } |
|
125 } |
|
126 return EFalse; |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CPIMToDoAdapterManager::GetSupportedFieldsL |
|
131 // Returns: An int array containing all fields supported by this list. |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 |
|
135 const CArrayFix<TPIMField>& CPIMToDoAdapterManager::GetSupportedFieldsL() |
|
136 { |
|
137 JELOG2(EPim); |
|
138 if (!iSupportedToDoFields) |
|
139 { |
|
140 iSupportedToDoFields |
|
141 = new(ELeave) CArrayFixFlat<TPIMField> (KPIMSupportedToDoFieldsCount); // codescanner::leave |
|
142 |
|
143 iSupportedToDoFields->AppendL(KPIMSupportedToDoFields, // codescanner::leave |
|
144 KPIMSupportedToDoFieldsCount); |
|
145 } |
|
146 return *iSupportedToDoFields; |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CPIMToDoAdapterManager::IsSupportedAttribute |
|
151 // Returns: EFalse for every other attribute than KPIMAttrNone |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 |
|
155 TBool CPIMToDoAdapterManager::IsSupportedAttribute(TPIMField /* aField */, |
|
156 TPIMAttribute /* aAttribute */) |
|
157 { |
|
158 JELOG2(EPim); |
|
159 return EFalse; // No attributes supported |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CPIMToDoAdapterManager::GetSupportedAttributesL |
|
164 // Returns: An empty array meaning no supported attributes. |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 |
|
168 const CArrayFix<TPIMAttribute>& |
|
169 CPIMToDoAdapterManager::GetSupportedAttributesL(TPIMField aField) |
|
170 { |
|
171 JELOG2(EPim); |
|
172 if (!IsSupportedField(aField)) |
|
173 { |
|
174 User::Leave(KErrArgument); |
|
175 } |
|
176 |
|
177 if (!iEmptyToDoAttributeArray) |
|
178 { |
|
179 iEmptyToDoAttributeArray |
|
180 = new(ELeave) CArrayFixFlat<TPIMAttribute> (1); |
|
181 } |
|
182 return *iEmptyToDoAttributeArray; |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CPIMToDoAdapterManager::GetSupportedAttributesCombinedL |
|
187 // Returns: KPIMAttrNone meaning no supported attributes. |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 |
|
191 TPIMAttribute CPIMToDoAdapterManager::GetSupportedAttributesCombinedL( |
|
192 TPIMField aField) // The field to check the supported attributes from |
|
193 { |
|
194 JELOG2(EPim); |
|
195 if (!IsSupportedField(aField)) |
|
196 { |
|
197 User::Leave(KErrArgument); // Field was not a valid field |
|
198 } |
|
199 return KPIMAttrNone; |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CPIMToDoAdapterManager::GetAllSupportedAttributesCombined |
|
204 // Returns: KPIMAttrNone meaning no supported attributes. |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 |
|
208 TPIMAttribute CPIMToDoAdapterManager::GetAllSupportedAttributesCombined() |
|
209 { |
|
210 JELOG2(EPim); |
|
211 return KPIMAttrNone; |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CPIMToDoAdapterManager::IsSupportedArrayElement |
|
216 // Returns: EFalse, as there are no supported array elements in ToDo list. |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 |
|
220 TBool CPIMToDoAdapterManager::IsSupportedArrayElement( |
|
221 TPIMField /* aStringArrayField */, TPIMArrayElement /* aArrayElement */) |
|
222 { |
|
223 JELOG2(EPim); |
|
224 return EFalse; // No attributes supported |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CPIMToDoAdapterManager::GetSupportedArrayElementsL |
|
229 // Returns: An integer array containing all of the supported elements of a |
|
230 // string array for the given field. |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 |
|
234 const CArrayFix<TPIMArrayElement>& |
|
235 CPIMToDoAdapterManager::GetSupportedArrayElementsL(TPIMField /* aField */) // The field to check for supported array elements |
|
236 { |
|
237 JELOG2(EPim); |
|
238 User::Leave(KErrArgument); // No array elements in ToDo list. |
|
239 |
|
240 // satisfy the compiler |
|
241 const CArrayFix<TPIMArrayElement>* temp = NULL; |
|
242 return *temp; |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CPIMToDoAdapterManager::MaxValues |
|
247 // Returns: Number of values supported for the field |
|
248 // -1 : The field supports having an unlimited number of values in it. |
|
249 // 0 : The field is not supported by this list. |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 |
|
253 TInt CPIMToDoAdapterManager::MaxValues(TPIMField aField) // The field to check for multiple value support |
|
254 { |
|
255 JELOG2(EPim); |
|
256 if (IsSupportedField(aField)) |
|
257 { |
|
258 return 1; // Only one value is supported for any valid ToDo field |
|
259 } |
|
260 else |
|
261 { |
|
262 return 0; |
|
263 } |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CPIMToDoAdapterManager::StringArraySizeL |
|
268 // Returns: Int the size of the array of a single data instance of a string |
|
269 // array field. |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 |
|
273 TInt CPIMToDoAdapterManager::StringArraySizeL(TPIMField /* aStringArrayField */) |
|
274 { |
|
275 JELOG2(EPim); |
|
276 User::Leave(KErrArgument); // no string array fields |
|
277 |
|
278 // satisfy the compiler |
|
279 return 0; |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CPIMToDoAdapterManager::ItemOrder |
|
284 // Returns: pointer to a function which implements an algorithm that |
|
285 // determines the order of two items. |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 |
|
289 TPIMItemComparisonFunc CPIMToDoAdapterManager::ItemOrder() |
|
290 { |
|
291 JELOG2(EPim); |
|
292 return ItemComparisonFunc; |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CPIMToDoAdapterManager::ItemComparisonFuncL |
|
297 // Compares two MPIMItemData objects. The comparision is based primarily on the |
|
298 // completion of the item, secondly on the due date of the item, and thirdly |
|
299 // on the priority of the item. |
|
300 // Returns: < 0: aFirst < aSecond |
|
301 // 0: aFirst == aSecond |
|
302 // > 0: aFirst > aSecond |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 TInt CPIMToDoAdapterManager::ItemComparisonFunc(const MPIMItem& aFirst, |
|
306 const MPIMItem& aSecond) |
|
307 { |
|
308 JELOG2(EPim); |
|
309 TInt retVal = 0; |
|
310 TRAPD(err, retVal = ItemComparisonFuncL(aFirst, aSecond)); |
|
311 if (err != KErrNone) |
|
312 { |
|
313 // The comparison function does not actually leave as it is used with |
|
314 // correct PIM field parameters, so this assert here is just for debug |
|
315 __ASSERT_DEBUG(EFalse, User::Panic(KPIMPanicCategory, EPIMPanicGeneral)); |
|
316 } |
|
317 return retVal; |
|
318 } |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // CPIMToDoAdapterManager::ItemComparisonFuncL |
|
322 // Compares two MPIMItemData objects. The comparision is based primarily on the |
|
323 // completion of the item, secondly on the due date of the item, and thirdly |
|
324 // on the priority of the item. |
|
325 // Returns: < 0: aFirst < aSecond |
|
326 // 0: aFirst == aSecond |
|
327 // > 0: aFirst > aSecond |
|
328 // ----------------------------------------------------------------------------- |
|
329 // |
|
330 TInt CPIMToDoAdapterManager::ItemComparisonFuncL(const MPIMItem& aFirst, |
|
331 const MPIMItem& aSecond) |
|
332 { |
|
333 JELOG2(EPim); |
|
334 TInt firstPresent = aFirst.CountValuesL(EPIMToDoCompleted); |
|
335 TInt secondPresent = aSecond.CountValuesL(EPIMToDoCompleted); |
|
336 |
|
337 if ((firstPresent == 0) ^(secondPresent == 0)) |
|
338 // Only one of the fields is present |
|
339 { |
|
340 return firstPresent - secondPresent; |
|
341 } |
|
342 |
|
343 else if (firstPresent > 0 && secondPresent > 0) |
|
344 // Both fields are present |
|
345 { |
|
346 TBool completedFirst = aFirst.GetBooleanL(EPIMToDoCompleted, 0); |
|
347 TBool completedSecond = aSecond.GetBooleanL(EPIMToDoCompleted, 0); |
|
348 |
|
349 if (!completedFirst && completedSecond) |
|
350 { |
|
351 return 1; |
|
352 } |
|
353 else if (completedFirst && !completedSecond) |
|
354 { |
|
355 return -1; |
|
356 } |
|
357 } |
|
358 |
|
359 // In this point either none of the items have the completed field, |
|
360 // or both of the items have the field and also have the same value in it. |
|
361 // Continue the comparision based on the 2nd criteria, the due date field. |
|
362 firstPresent = aFirst.CountValuesL(EPIMToDoDue); |
|
363 secondPresent = aSecond.CountValuesL(EPIMToDoDue); |
|
364 |
|
365 if ((firstPresent == 0) ^(secondPresent == 0)) // xor |
|
366 // Only one of the fields is present |
|
367 { |
|
368 return secondPresent - firstPresent; |
|
369 } |
|
370 |
|
371 else if (firstPresent > 0 && secondPresent > 0) |
|
372 // Both fields are present |
|
373 { |
|
374 const TPIMDate dateFirst = aFirst.GetDateL(EPIMToDoDue, 0); |
|
375 const TPIMDate dateSecond = aSecond.GetDateL(EPIMToDoDue, 0); |
|
376 |
|
377 if (dateFirst < dateSecond) |
|
378 { |
|
379 return -1; |
|
380 } |
|
381 else if (dateFirst > dateSecond) |
|
382 { |
|
383 return 1; |
|
384 } |
|
385 } |
|
386 |
|
387 // In this point either none of the items have due date field, or |
|
388 // the other possibility is that the due date fields are exactly equal. |
|
389 // Continue the comparision based on the 3rd criteria, the priority field. |
|
390 firstPresent = aFirst.CountValuesL(EPIMToDoPriority); |
|
391 secondPresent = aSecond.CountValuesL(EPIMToDoPriority); |
|
392 |
|
393 if ((firstPresent == 0) ^(secondPresent == 0)) // xor |
|
394 // Only one of the fields is present |
|
395 { |
|
396 return secondPresent - firstPresent; |
|
397 } |
|
398 |
|
399 else if (firstPresent > 0 && secondPresent > 0) |
|
400 // Both fields are present |
|
401 { |
|
402 TInt priorityFirst = aFirst.getInt(EPIMToDoPriority, 0); |
|
403 TInt prioritySecond = aSecond.getInt(EPIMToDoPriority, 0); |
|
404 if (priorityFirst < prioritySecond) |
|
405 { |
|
406 return -1; |
|
407 } |
|
408 if (priorityFirst > prioritySecond) |
|
409 { |
|
410 return 1; |
|
411 } |
|
412 // The third option is that the priorities are equal as well : return 0 |
|
413 return 0; |
|
414 } |
|
415 |
|
416 // If all 3 comparision fields are missing in both items, they are equal |
|
417 return 0; |
|
418 } |
|
419 |
|
420 // End of File |