|
1 /* |
|
2 * Copyright (c) 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 : Util api for getting next available offset value |
|
15 * |
|
16 */ |
|
17 |
|
18 //Includes |
|
19 #include "calendarui_debug.h" |
|
20 |
|
21 #include <centralrepository.h> |
|
22 #include <calenmulticalutil.h> |
|
23 #include <CalendarInternalCRKeys.h> |
|
24 |
|
25 //Constants |
|
26 const TUint KCalendarOffSet = 0x000186A0; //50000*2 |
|
27 const TInt KOffsetLength = 16; |
|
28 // Default Calendar database path |
|
29 _LIT( KCalendarDatabaseFilePath, "c:calendar" ); |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CCalenMultiCalUtil::GetNextAvailableOffsetL |
|
33 // Gets the next available calendar unique value |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 EXPORT_C TUint CCalenMultiCalUtil::GetNextAvailableOffsetL() |
|
37 { |
|
38 TRACE_ENTRY_POINT |
|
39 |
|
40 TBuf<KOffsetLength> offSetBuf; |
|
41 |
|
42 CRepository* cenRep = CRepository::NewLC(KCRUidCalendar); |
|
43 User::LeaveIfError(cenRep->Get(KCalendarAvailableValue, offSetBuf)); |
|
44 |
|
45 TUint availableOffsetValue = 0; |
|
46 TLex lex(offSetBuf); |
|
47 lex.Val(availableOffsetValue, EDecimal); |
|
48 |
|
49 TUint nextAvailableOffset = availableOffsetValue + KCalendarOffSet; |
|
50 |
|
51 offSetBuf.Zero(); //Reset |
|
52 offSetBuf.AppendFormat(_L("%u"), nextAvailableOffset); |
|
53 |
|
54 User::LeaveIfError(cenRep->Set(KCalendarAvailableValue, offSetBuf)); |
|
55 |
|
56 CleanupStack::PopAndDestroy(cenRep); |
|
57 TRACE_EXIT_POINT |
|
58 return availableOffsetValue; |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CCalenMultiCalUtil::GetNextAvailableCalFileL |
|
63 // Gets the next available calendar filename |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 EXPORT_C HBufC* CCalenMultiCalUtil::GetNextAvailableCalFileL() |
|
67 { |
|
68 TRACE_ENTRY_POINT; |
|
69 |
|
70 TInt nextAvailableCalNumber(0); |
|
71 // get the next available calendar value from cenrep and |
|
72 // append it to c:calendar |
|
73 CRepository* cenRep = CRepository::NewL(KCRUidCalendar); |
|
74 CleanupStack::PushL(cenRep); |
|
75 User::LeaveIfError(cenRep->Get(KCalendarFileNumber, |
|
76 nextAvailableCalNumber)); |
|
77 nextAvailableCalNumber++; |
|
78 User::LeaveIfError(cenRep->Set(KCalendarFileNumber, |
|
79 nextAvailableCalNumber)); |
|
80 CleanupStack::PopAndDestroy(cenRep); |
|
81 |
|
82 HBufC* calFileName = HBufC::NewL(KMaxFileName); |
|
83 TPtr fileNameptr(calFileName->Des()); |
|
84 fileNameptr.Append(KCalendarDatabaseFilePath); |
|
85 fileNameptr.AppendNum(nextAvailableCalNumber); |
|
86 |
|
87 TRACE_EXIT_POINT; |
|
88 // ownership of calFileName is transferred to the caller |
|
89 return calFileName; |
|
90 } |
|
91 |
|
92 // EOF |