|
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: PIM item repeat rule implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cpimrepeatrule.h" |
|
21 #include "pimrepeatruleconverter.h" |
|
22 #include "pimjnitools.h" |
|
23 #include "pimutils.h" |
|
24 #include "s60commonutils.h" |
|
25 #include "logger.h" |
|
26 |
|
27 // CONSTANTS |
|
28 namespace |
|
29 { |
|
30 const TInt KPIMRepeatRuleMaskWeekInMonth = 1023; // All week bits set |
|
31 const TInt KPIMRepeatRuleMaskDayInWeek = 131071; // All day bits set |
|
32 const TInt KPIMRepeatRuleMaskMonthInYear = 536870911; // All month bits set |
|
33 } |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CPIMRepeatRule::CPIMRepeatRule |
|
39 // C++ default constructor can NOT contain any code, that |
|
40 // might leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CPIMRepeatRule::CPIMRepeatRule() : |
|
44 iRepeatRuleFrequency(0), iRepeatRuleInterval(0), iRepeatRuleEndDate( |
|
45 Time::NullTTime()), iRepeatRuleDayInMonth(0), iRepeatRuleDayInWeek(0), |
|
46 iRepeatRuleDayInYear(0), iRepeatRuleMonthInYear(0), |
|
47 iRepeatRuleWeekInMonth(0), iRepeatRuleCount(0) |
|
48 { |
|
49 JELOG2(EPim); |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CPIMRepeatRule::ConstructL |
|
54 // Symbian 2nd phase constructor can leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 void CPIMRepeatRule::ConstructL() |
|
58 { |
|
59 JELOG2(EPim); |
|
60 iExceptDates = new(ELeave) CArrayFixFlat<TPIMDate> (1); |
|
61 // Create here also the array to store the original exception dates |
|
62 iOriginalExceptDates = new(ELeave) CArrayFixFlat<TPIMDate> (1); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CPIMRepeatRule::NewL |
|
67 // Two-phased constructor. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CPIMRepeatRule* CPIMRepeatRule::NewL() |
|
71 { |
|
72 JELOG2(EPim); |
|
73 CPIMRepeatRule* self = new(ELeave) CPIMRepeatRule; |
|
74 |
|
75 CleanupStack::PushL(self); |
|
76 self->ConstructL(); |
|
77 CleanupStack::Pop(self); |
|
78 |
|
79 return self; |
|
80 } |
|
81 |
|
82 pimbaserepeatrule* pimbaserepeatrule::getInstance() |
|
83 { |
|
84 JELOG2(EPim); |
|
85 CPIMRepeatRule* repeatRule = NULL; |
|
86 TInt error = KErrNone; |
|
87 TRAP(error, repeatRule = CPIMRepeatRule::NewL()); |
|
88 if (error != KErrNone) |
|
89 throw KErrGeneral; |
|
90 return repeatRule; |
|
91 } |
|
92 |
|
93 // Destructor |
|
94 CPIMRepeatRule::~CPIMRepeatRule() |
|
95 { |
|
96 JELOG2(EPim); |
|
97 delete iExceptDates; |
|
98 delete iOriginalExceptDates; |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CPIMRepeatRule::DatesL |
|
103 // Returns the repeat dates. |
|
104 // Returns: An array of repeat dates without the exception dates. |
|
105 // The ownership of the array is transferred to the caller. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 CArrayFixFlat<TPIMDate>* CPIMRepeatRule::DatesL(const TPIMDate& aStartDate, |
|
109 const TPIMDate& aSubsetBeginning, const TPIMDate& aSubsetEnding) const |
|
110 { |
|
111 JELOG2(EPim); |
|
112 return PIMRepeatRuleConverter::DatesL(*this, aStartDate, aSubsetBeginning, |
|
113 aSubsetEnding, *iExceptDates, iRepeatRuleEndDate, iRepeatRuleCount); |
|
114 } |
|
115 |
|
116 jintArray CPIMRepeatRule::dates(jlong aStartDate, jlong aSubsetBeginning, |
|
117 jlong aSubsetEnding, JNIEnv* aJniEnv) |
|
118 { |
|
119 JELOG2(EPim); |
|
120 CArrayFix<TPIMDate>* repeatDates = NULL; |
|
121 |
|
122 TPIMDate nativeStartDate(java::util::S60CommonUtils::JavaTimeToTTime( |
|
123 aStartDate)); |
|
124 TPIMDate nativeSubsetBeginning(java::util::S60CommonUtils::JavaTimeToTTime( |
|
125 aSubsetBeginning)); |
|
126 TPIMDate nativeSubsetEnding(java::util::S60CommonUtils::JavaTimeToTTime( |
|
127 aSubsetEnding)); |
|
128 TInt error = KErrNone; |
|
129 TRAP(error, repeatDates = DatesL(nativeStartDate, nativeSubsetBeginning, |
|
130 nativeSubsetEnding)); |
|
131 |
|
132 if (error != KErrNone || repeatDates == NULL) |
|
133 { |
|
134 // major error |
|
135 return NULL; |
|
136 } |
|
137 |
|
138 jintArray repeatDatesIntArray = NativeDatesToJavaInts(*aJniEnv, |
|
139 *repeatDates); |
|
140 |
|
141 delete repeatDates; |
|
142 return repeatDatesIntArray; |
|
143 |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CPIMRepeatRule::AddExceptDateL |
|
148 // Adds an exception date into the repeat rule. |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void CPIMRepeatRule::AddExceptDateL(TPIMDate aDate) |
|
152 { |
|
153 JELOG2(EPim); |
|
154 TInt exceptionDateFinder; |
|
155 TInt fetchIndex = 0; |
|
156 TKeyArrayFix key(0, ECmpTInt64); |
|
157 exceptionDateFinder = iExceptDates->Find(aDate, key, fetchIndex); |
|
158 if (exceptionDateFinder != 0) // 0 would mean that the element was found |
|
159 { |
|
160 iExceptDates->AppendL(aDate); |
|
161 } |
|
162 } |
|
163 |
|
164 void CPIMRepeatRule::addExceptDate(jlong aValue) |
|
165 { |
|
166 JELOG2(EPim); |
|
167 TPIMDate nativeValue(java::util::S60CommonUtils::JavaTimeToTTime(aValue)); |
|
168 TInt error = KErrNone; |
|
169 TRAP(error, AddExceptDateL(nativeValue)); |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CPIMRepeatRule::RemoveExceptDate |
|
174 // Removes an exception date given as a parameter. |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 void CPIMRepeatRule::RemoveExceptDate(TPIMDate aDate) |
|
178 { |
|
179 JELOG2(EPim); |
|
180 TInt exceptionDateFinder; |
|
181 TInt fetchIndex = 0; |
|
182 TKeyArrayFix key(0, ECmpTInt64); |
|
183 exceptionDateFinder = iExceptDates->Find(aDate, key, fetchIndex); |
|
184 if (exceptionDateFinder == 0) // 0 means that the element was found |
|
185 { |
|
186 iExceptDates->Delete(fetchIndex); |
|
187 // Deleting elements from the array does not cause the |
|
188 // array buffer to be automatically compressed. |
|
189 // Compress() method returns excess space to the heap. |
|
190 iExceptDates->Compress(); |
|
191 } |
|
192 } |
|
193 |
|
194 void CPIMRepeatRule::removeExceptDate(jlong aValue) |
|
195 { |
|
196 JELOG2(EPim); |
|
197 TPIMDate nativeValue(java::util::S60CommonUtils::JavaTimeToTTime(aValue)); |
|
198 RemoveExceptDate(nativeValue); |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CPIMRepeatRule::GetExceptDatesL |
|
203 // Returns the exception dates. |
|
204 // Returns: An array of exceptiond dates. |
|
205 // The ownership of the array stays with the repeat rule. |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 const CArrayFix<TPIMDate>& CPIMRepeatRule::GetExceptDatesL() const |
|
209 { |
|
210 JELOG2(EPim); |
|
211 return *iExceptDates; |
|
212 } |
|
213 |
|
214 jintArray CPIMRepeatRule::getExceptDates(JNIEnv* aJniEnv) |
|
215 { |
|
216 JELOG2(EPim); |
|
217 // The ownership of the except dates array stays with the repeat rule. |
|
218 const CArrayFix<TPIMDate>* exceptDates = NULL; |
|
219 TInt error = KErrNone; |
|
220 TRAP(error, exceptDates = &(GetExceptDatesL())); |
|
221 if (error != KErrNone || exceptDates == NULL) |
|
222 { |
|
223 // major error |
|
224 return NULL; |
|
225 } |
|
226 jintArray exceptDatesIntArray = NativeDatesToJavaInts(*aJniEnv, |
|
227 *exceptDates); |
|
228 return exceptDatesIntArray; |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CPIMRepeatRule::GetIntL |
|
233 // Returns an integer value. |
|
234 // Returns: An integer value based on the parameter field. |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 TInt CPIMRepeatRule::GetIntL(TPIMField aField) const |
|
238 { |
|
239 JELOG2(EPim); |
|
240 switch (aField) |
|
241 { |
|
242 // First the two supported repeat rule int fields |
|
243 case EPIMRepeatRuleFrequency: |
|
244 { |
|
245 if (iRepeatRuleFrequency == 0) |
|
246 { |
|
247 User::Leave(KErrNotFound); |
|
248 } |
|
249 return iRepeatRuleFrequency; |
|
250 } |
|
251 case EPIMRepeatRuleInterval: |
|
252 { |
|
253 if (iRepeatRuleInterval == 0) |
|
254 { |
|
255 User::Leave(KErrNotFound); |
|
256 } |
|
257 return iRepeatRuleInterval; |
|
258 } |
|
259 |
|
260 // Then the rest of the repeat rule fields (not supported by Nokia.) |
|
261 case EPIMRepeatRuleDayInMonth: |
|
262 { |
|
263 if (iRepeatRuleDayInMonth == 0) |
|
264 { |
|
265 User::Leave(KErrNotFound); |
|
266 } |
|
267 return iRepeatRuleDayInMonth; |
|
268 } |
|
269 case EPIMRepeatRuleDayInWeek: |
|
270 { |
|
271 if (iRepeatRuleDayInWeek == 0) |
|
272 { |
|
273 User::Leave(KErrNotFound); |
|
274 } |
|
275 return iRepeatRuleDayInWeek; |
|
276 } |
|
277 case EPIMRepeatRuleDayInYear: |
|
278 { |
|
279 if (iRepeatRuleDayInYear == 0) |
|
280 { |
|
281 User::Leave(KErrNotFound); |
|
282 } |
|
283 return iRepeatRuleDayInYear; |
|
284 } |
|
285 case EPIMRepeatRuleMonthInYear: |
|
286 { |
|
287 if (iRepeatRuleMonthInYear == 0) |
|
288 { |
|
289 User::Leave(KErrNotFound); |
|
290 } |
|
291 return iRepeatRuleMonthInYear; |
|
292 } |
|
293 case EPIMRepeatRuleWeekInMonth: |
|
294 { |
|
295 if (iRepeatRuleWeekInMonth == 0) |
|
296 { |
|
297 User::Leave(KErrNotFound); |
|
298 } |
|
299 return iRepeatRuleWeekInMonth; |
|
300 } |
|
301 case EPIMRepeatRuleCount: |
|
302 { |
|
303 if (iRepeatRuleCount == 0) |
|
304 { |
|
305 User::Leave(KErrNotFound); |
|
306 } |
|
307 return iRepeatRuleCount; |
|
308 } |
|
309 default: |
|
310 { |
|
311 User::Leave(KErrArgument); |
|
312 // Even the method leaves here, the compiler requires it to return |
|
313 // an integer value. The next line is only because of that. |
|
314 return 0; |
|
315 } |
|
316 } |
|
317 } |
|
318 |
|
319 int CPIMRepeatRule::getRepeatInt(TPIMField aField) |
|
320 { |
|
321 JELOG2(EPim); |
|
322 TInt error = KErrNone; |
|
323 int retVal = 0; |
|
324 TRAP(error, retVal = GetIntL(aField)); |
|
325 if (error != KErrNone) |
|
326 throw error; |
|
327 return retVal; |
|
328 } |
|
329 |
|
330 // ----------------------------------------------------------------------------- |
|
331 // CPIMRepeatRule::SetIntL |
|
332 // Sets an integer value for the given field. |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 void CPIMRepeatRule::SetIntL(TPIMField aField, TInt aValue) |
|
336 { |
|
337 JELOG2(EPim); |
|
338 switch (aField) |
|
339 { |
|
340 // First the two supported repeat rule int fields |
|
341 case EPIMRepeatRuleFrequency: |
|
342 { |
|
343 if (aValue == EPIMRepeatRuleDaily || aValue == EPIMRepeatRuleWeekly |
|
344 || aValue == EPIMRepeatRuleMonthly || aValue |
|
345 == EPIMRepeatRuleYearly) |
|
346 { |
|
347 iRepeatRuleFrequency = aValue; |
|
348 } |
|
349 else |
|
350 { |
|
351 User::Leave(KErrTooBig); |
|
352 } |
|
353 break; |
|
354 } |
|
355 case EPIMRepeatRuleInterval: |
|
356 { |
|
357 if (aValue > 0) |
|
358 { |
|
359 iRepeatRuleInterval = aValue; |
|
360 } |
|
361 else |
|
362 { |
|
363 User::Leave(KErrTooBig); |
|
364 } |
|
365 break; |
|
366 } |
|
367 |
|
368 // Then the rest of the repeat rule fields (not supported by Nokia.) |
|
369 case EPIMRepeatRuleDayInMonth: |
|
370 { |
|
371 if (0 < aValue && aValue < 32) // Valid values are 1-31 |
|
372 { |
|
373 iRepeatRuleDayInMonth = aValue; |
|
374 } |
|
375 else |
|
376 { |
|
377 User::Leave(KErrTooBig); |
|
378 } |
|
379 break; |
|
380 } |
|
381 case EPIMRepeatRuleDayInWeek: |
|
382 { |
|
383 if (aValue > 0 && aValue <= KPIMRepeatRuleMaskDayInWeek && (aValue |
|
384 & KPIMRepeatRuleMaskWeekInMonth) == 0) |
|
385 { |
|
386 // Value does consist of 1 or more weekdays only |
|
387 iRepeatRuleDayInWeek = aValue; |
|
388 } |
|
389 else |
|
390 { |
|
391 User::Leave(KErrTooBig); |
|
392 } |
|
393 break; |
|
394 } |
|
395 case EPIMRepeatRuleDayInYear: |
|
396 { |
|
397 if (0 < aValue && aValue < 367) // Valid values are 1-366 |
|
398 { |
|
399 iRepeatRuleDayInYear = aValue; |
|
400 } |
|
401 else |
|
402 { |
|
403 User::Leave(KErrTooBig); |
|
404 } |
|
405 break; |
|
406 } |
|
407 case EPIMRepeatRuleMonthInYear: |
|
408 { |
|
409 if (aValue > 0 && aValue <= KPIMRepeatRuleMaskMonthInYear && (aValue |
|
410 & KPIMRepeatRuleMaskDayInWeek) == 0) |
|
411 { |
|
412 // Value does consist of 1 or more months only |
|
413 iRepeatRuleMonthInYear = aValue; |
|
414 } |
|
415 else |
|
416 { |
|
417 User::Leave(KErrTooBig); |
|
418 } |
|
419 break; |
|
420 } |
|
421 case EPIMRepeatRuleWeekInMonth: |
|
422 { |
|
423 if (aValue > 0 && aValue <= KPIMRepeatRuleMaskWeekInMonth) |
|
424 { |
|
425 // Value does consist of 1 or more weeks in month only |
|
426 iRepeatRuleWeekInMonth = aValue; |
|
427 } |
|
428 else |
|
429 { |
|
430 User::Leave(KErrTooBig); |
|
431 } |
|
432 break; |
|
433 } |
|
434 case EPIMRepeatRuleCount: |
|
435 { |
|
436 if (aValue > 0) |
|
437 { |
|
438 iRepeatRuleCount = aValue; |
|
439 } |
|
440 else |
|
441 { |
|
442 User::Leave(KErrTooBig); |
|
443 } |
|
444 break; |
|
445 } |
|
446 default: |
|
447 { |
|
448 User::Leave(KErrArgument); |
|
449 } |
|
450 } |
|
451 } |
|
452 |
|
453 void CPIMRepeatRule::setRepeatInt(TPIMField aField, int aValue) |
|
454 { |
|
455 JELOG2(EPim); |
|
456 TInt error = KErrNone; |
|
457 TRAP(error, SetIntL(aField, aValue)); |
|
458 if (error != KErrNone) |
|
459 throw error; |
|
460 |
|
461 } |
|
462 |
|
463 // ----------------------------------------------------------------------------- |
|
464 // CPIMRepeatRule::GetDateL |
|
465 // Returns a date value. |
|
466 // Returns: A date value based on the parameter field. |
|
467 // ----------------------------------------------------------------------------- |
|
468 // |
|
469 TPIMDate CPIMRepeatRule::GetDateL(TPIMField aField) const |
|
470 { |
|
471 JELOG2(EPim); |
|
472 if (aField != EPIMRepeatRuleEnd) |
|
473 { |
|
474 User::Leave(KErrArgument); |
|
475 } |
|
476 |
|
477 if (iRepeatRuleEndDate == Time::NullTTime()) |
|
478 { |
|
479 User::Leave(KErrNotFound); |
|
480 } |
|
481 |
|
482 return iRepeatRuleEndDate; |
|
483 } |
|
484 |
|
485 jlong CPIMRepeatRule::getRepeatDate(TPIMField aField) |
|
486 { |
|
487 JELOG2(EPim); |
|
488 TInt error = KErrNone; |
|
489 TPIMDate value; |
|
490 TRAP(error, value = GetDateL(aField)); |
|
491 if (error != KErrNone) |
|
492 throw error; |
|
493 jlong retVal = java::util::S60CommonUtils::TTimeToJavaTime(value); |
|
494 return retVal; |
|
495 } |
|
496 |
|
497 // ----------------------------------------------------------------------------- |
|
498 // CPIMRepeatRule::SetDateL |
|
499 // Sets a date value for the given field. |
|
500 // ----------------------------------------------------------------------------- |
|
501 // |
|
502 void CPIMRepeatRule::SetDateL(TPIMField aField, TPIMDate aDate) |
|
503 { |
|
504 JELOG2(EPim); |
|
505 if (aField == EPIMRepeatRuleEnd) |
|
506 { |
|
507 if (!PIMRepeatRuleConverter::IsValidAgendaDate(aDate)) |
|
508 { |
|
509 User::Leave(KErrTooBig); |
|
510 } |
|
511 iRepeatRuleEndDate = aDate; |
|
512 } |
|
513 else |
|
514 { |
|
515 User::Leave(KErrArgument); |
|
516 } |
|
517 } |
|
518 |
|
519 void CPIMRepeatRule::setDate(TPIMField aField, jlong aValue) |
|
520 { |
|
521 JELOG2(EPim); |
|
522 TPIMDate nativeValue(java::util::S60CommonUtils::JavaTimeToTTime(aValue)); |
|
523 TInt error = KErrNone; |
|
524 TRAP(error, SetDateL(aField, nativeValue)); |
|
525 if (error != KErrNone) |
|
526 throw error; |
|
527 } |
|
528 |
|
529 // ----------------------------------------------------------------------------- |
|
530 // CPIMRepeatRule::GetFieldsL |
|
531 // Returns the fields that are in use. |
|
532 // Returns: An array of repeat rule fields that are in use. |
|
533 // The ownership of the array is transferred to the caller. |
|
534 // ----------------------------------------------------------------------------- |
|
535 // |
|
536 CArrayFix<TPIMField>* CPIMRepeatRule::GetFieldsL() const |
|
537 { |
|
538 JELOG2(EPim); |
|
539 CArrayFixFlat<TPIMField>* repeatRuleFields = new(ELeave) CArrayFixFlat< |
|
540 TPIMField> (1); |
|
541 CleanupStack::PushL(repeatRuleFields); |
|
542 |
|
543 // First the three supported repeat rule fields |
|
544 if (iRepeatRuleFrequency != 0) |
|
545 { |
|
546 repeatRuleFields->AppendL(EPIMRepeatRuleFrequency); |
|
547 } |
|
548 if (iRepeatRuleInterval != 0) |
|
549 { |
|
550 repeatRuleFields->AppendL(EPIMRepeatRuleInterval); |
|
551 } |
|
552 if (iRepeatRuleEndDate != Time::NullTTime()) |
|
553 { |
|
554 repeatRuleFields->AppendL(EPIMRepeatRuleEnd); |
|
555 } |
|
556 |
|
557 // Then the rest of the repeat rule fields (not supported by Nokia.) |
|
558 if (iRepeatRuleDayInMonth != 0) |
|
559 { |
|
560 repeatRuleFields->AppendL(EPIMRepeatRuleDayInMonth); |
|
561 } |
|
562 if (iRepeatRuleDayInWeek != 0) |
|
563 { |
|
564 repeatRuleFields->AppendL(EPIMRepeatRuleDayInWeek); |
|
565 } |
|
566 if (iRepeatRuleDayInYear != 0) |
|
567 { |
|
568 repeatRuleFields->AppendL(EPIMRepeatRuleDayInYear); |
|
569 } |
|
570 if (iRepeatRuleMonthInYear != 0) |
|
571 { |
|
572 repeatRuleFields->AppendL(EPIMRepeatRuleMonthInYear); |
|
573 } |
|
574 if (iRepeatRuleWeekInMonth != 0) |
|
575 { |
|
576 repeatRuleFields->AppendL(EPIMRepeatRuleWeekInMonth); |
|
577 } |
|
578 if (iRepeatRuleCount != 0) |
|
579 { |
|
580 repeatRuleFields->AppendL(EPIMRepeatRuleCount); |
|
581 } |
|
582 |
|
583 CleanupStack::Pop(repeatRuleFields); |
|
584 return repeatRuleFields; |
|
585 } |
|
586 |
|
587 jintArray CPIMRepeatRule::getFields(JNIEnv* aJniEnv) |
|
588 { |
|
589 JELOG2(EPim); |
|
590 CArrayFix<TPIMField>* fields = NULL; |
|
591 TInt error = KErrNone; |
|
592 TRAP(error, fields = GetFieldsL()); |
|
593 // We now own the field array |
|
594 |
|
595 if (error != KErrNone || fields == NULL) |
|
596 { |
|
597 delete fields; |
|
598 return NULL; |
|
599 } |
|
600 |
|
601 const TInt numFields = fields->Count(); |
|
602 |
|
603 jintArray javaFields = aJniEnv->NewIntArray(numFields); |
|
604 |
|
605 if (javaFields == NULL) |
|
606 { |
|
607 delete fields; |
|
608 return NULL; |
|
609 } |
|
610 |
|
611 if (numFields > 0) |
|
612 { |
|
613 aJniEnv->SetIntArrayRegion(javaFields, 0, numFields, fields->Back(0)); |
|
614 } |
|
615 |
|
616 delete fields; |
|
617 return javaFields; |
|
618 } |
|
619 |
|
620 // ----------------------------------------------------------------------------- |
|
621 // CPIMRepeatRule::ClearFieldL |
|
622 // Clears the value of the field given as a parameter. |
|
623 // ----------------------------------------------------------------------------- |
|
624 // |
|
625 void CPIMRepeatRule::ClearFieldL(TPIMField aField) |
|
626 { |
|
627 JELOG2(EPim); |
|
628 switch (aField) |
|
629 { |
|
630 // First the three supported repeat rule fields |
|
631 case EPIMRepeatRuleFrequency: |
|
632 { |
|
633 iRepeatRuleFrequency = 0; |
|
634 break; |
|
635 } |
|
636 case EPIMRepeatRuleInterval: |
|
637 { |
|
638 iRepeatRuleInterval = 0; |
|
639 break; |
|
640 } |
|
641 case EPIMRepeatRuleEnd: |
|
642 { |
|
643 iRepeatRuleEndDate = Time::NullTTime(); |
|
644 break; |
|
645 } |
|
646 |
|
647 // Then the rest of the repeat rule fields (not supported by Nokia.) |
|
648 case EPIMRepeatRuleDayInMonth: |
|
649 { |
|
650 iRepeatRuleDayInMonth = 0; |
|
651 break; |
|
652 } |
|
653 case EPIMRepeatRuleDayInWeek: |
|
654 { |
|
655 iRepeatRuleDayInWeek = 0; |
|
656 break; |
|
657 } |
|
658 case EPIMRepeatRuleDayInYear: |
|
659 { |
|
660 iRepeatRuleDayInYear = 0; |
|
661 break; |
|
662 } |
|
663 case EPIMRepeatRuleMonthInYear: |
|
664 { |
|
665 iRepeatRuleMonthInYear = 0; |
|
666 break; |
|
667 } |
|
668 case EPIMRepeatRuleWeekInMonth: |
|
669 { |
|
670 iRepeatRuleWeekInMonth = 0; |
|
671 break; |
|
672 } |
|
673 case EPIMRepeatRuleCount: |
|
674 { |
|
675 iRepeatRuleCount = 0; |
|
676 break; |
|
677 } |
|
678 default: |
|
679 { |
|
680 User::Leave(KErrArgument); |
|
681 } |
|
682 } |
|
683 } |
|
684 |
|
685 // ----------------------------------------------------------------------------- |
|
686 // CPIMRepeatRule::Clear |
|
687 // Clears all values of the repeat rule. |
|
688 // ----------------------------------------------------------------------------- |
|
689 // |
|
690 void CPIMRepeatRule::clear() |
|
691 { |
|
692 JELOG2(EPim); |
|
693 iExceptDates->Reset(); |
|
694 iRepeatRuleFrequency = 0; |
|
695 iRepeatRuleInterval = 0; |
|
696 iRepeatRuleEndDate = Time::NullTTime(); |
|
697 iRepeatRuleDayInMonth = 0; |
|
698 iRepeatRuleDayInWeek = 0; |
|
699 iRepeatRuleDayInYear = 0; |
|
700 iRepeatRuleMonthInYear = 0; |
|
701 iRepeatRuleWeekInMonth = 0; |
|
702 iRepeatRuleCount = 0; |
|
703 } |
|
704 |
|
705 // ----------------------------------------------------------------------------- |
|
706 // CPIMRepeatRule::BackupRepeatL |
|
707 // Copies all the fields from the Agenda model's Repeat definition. |
|
708 // ----------------------------------------------------------------------------- |
|
709 // |
|
710 void CPIMRepeatRule::BackupRepeatL() |
|
711 { |
|
712 JELOG2(EPim); |
|
713 for (TInt i = 0; i < iExceptDates->Count(); i++) |
|
714 { |
|
715 iOriginalExceptDates->AppendL(iExceptDates->At(i)); |
|
716 } |
|
717 iOriginalRepeatRuleFrequency = iRepeatRuleFrequency; |
|
718 iOriginalRepeatRuleInterval = iRepeatRuleInterval; |
|
719 iOriginalRepeatRuleEndDate = iRepeatRuleEndDate; |
|
720 iOriginalRepeatRuleDayInMonth = iRepeatRuleDayInMonth; |
|
721 iOriginalRepeatRuleDayInWeek = iRepeatRuleDayInWeek; |
|
722 iOriginalRepeatRuleDayInYear = iRepeatRuleDayInYear; |
|
723 iOriginalRepeatRuleMonthInYear = iRepeatRuleMonthInYear; |
|
724 iOriginalRepeatRuleWeekInMonth = iRepeatRuleWeekInMonth; |
|
725 iOriginalRepeatRuleCount = iRepeatRuleCount; |
|
726 } |
|
727 |
|
728 // ----------------------------------------------------------------------------- |
|
729 // CPIMRepeatRule::IsModified |
|
730 // Checks if the repeat rule has been changed or not. |
|
731 // ----------------------------------------------------------------------------- |
|
732 // |
|
733 TBool CPIMRepeatRule::IsModified() const |
|
734 { |
|
735 JELOG2(EPim); |
|
736 // First check that has the exception dates amount changed |
|
737 if (iExceptDates->Count() != iOriginalExceptDates->Count()) |
|
738 { |
|
739 return ETrue; |
|
740 } |
|
741 |
|
742 // If original repeat had same amount of exception dates, compare all dates |
|
743 if (iExceptDates->Count() > 0 && iOriginalExceptDates->Count() > 0) |
|
744 { |
|
745 TInt exceptionDateFinder; |
|
746 TInt fetchIndex = 0; |
|
747 TKeyArrayFix key(0, ECmpTInt64); |
|
748 for (TInt i = 0; i < iExceptDates->Count(); i++) |
|
749 { |
|
750 const TPIMDate& exceptDate = iExceptDates->At(i); |
|
751 exceptionDateFinder = iOriginalExceptDates->Find(exceptDate, key, |
|
752 fetchIndex); |
|
753 if (exceptionDateFinder != 0) // 0 would mean that date was found |
|
754 { |
|
755 return ETrue; |
|
756 } |
|
757 } |
|
758 } |
|
759 |
|
760 // Exception dates comparison passed, continue with the rest of the fields |
|
761 if (iOriginalRepeatRuleFrequency == iRepeatRuleFrequency |
|
762 && iOriginalRepeatRuleInterval == iRepeatRuleInterval |
|
763 && iOriginalRepeatRuleEndDate == iRepeatRuleEndDate |
|
764 && iOriginalRepeatRuleDayInMonth == iRepeatRuleDayInMonth |
|
765 && iOriginalRepeatRuleDayInWeek == iRepeatRuleDayInWeek |
|
766 && iOriginalRepeatRuleDayInYear == iRepeatRuleDayInYear |
|
767 && iOriginalRepeatRuleMonthInYear == iRepeatRuleMonthInYear |
|
768 && iOriginalRepeatRuleWeekInMonth == iRepeatRuleWeekInMonth |
|
769 && iOriginalRepeatRuleCount == iRepeatRuleCount) |
|
770 { |
|
771 // All the fields are identical, the repeat has not been changed |
|
772 return EFalse; |
|
773 } |
|
774 else |
|
775 { |
|
776 // At least one of the fields was different, the repeat has been changed |
|
777 return ETrue; |
|
778 } |
|
779 } |
|
780 |
|
781 // End of File |