|
1 /* |
|
2 * Copyright (c) 1997-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cntcurrentitemmap.h" |
|
20 #include <s32stor.h> |
|
21 #include <s32file.h> |
|
22 |
|
23 const TInt KCntCurrentItemMapGranularity = 3; |
|
24 |
|
25 |
|
26 CCntServerCurrentItemMap::CCntServerCurrentItemMap() : iCurrentItemMap(KCntCurrentItemMapGranularity) |
|
27 { |
|
28 } |
|
29 |
|
30 CCntServerCurrentItemMap::~CCntServerCurrentItemMap() |
|
31 { |
|
32 iCurrentItemMap.ResetAndDestroy(); |
|
33 iCurrentItemMap.Close(); |
|
34 } |
|
35 |
|
36 TContactItemId CCntServerCurrentItemMap::CurrentItem(const TDesC& aDatabaseFile) const |
|
37 { |
|
38 TInt index = KErrNotFound; |
|
39 if (EntryAvailable(aDatabaseFile, index)) |
|
40 return iCurrentItemMap[index]->ContactId(); |
|
41 return KNullContactId; |
|
42 } |
|
43 |
|
44 TBool CCntServerCurrentItemMap::EntryAvailable(const TDesC& aDatabaseFile, TInt& aIndex) const |
|
45 { |
|
46 const TInt count = iCurrentItemMap.Count(); |
|
47 for(aIndex = 0; aIndex < count; aIndex++) |
|
48 { |
|
49 if (FileNamesIdentical(iCurrentItemMap[aIndex]->DatabaseFile(),aDatabaseFile)) |
|
50 return ETrue; |
|
51 } |
|
52 aIndex = KErrNotFound; |
|
53 return EFalse; |
|
54 } |
|
55 |
|
56 |
|
57 void CCntServerCurrentItemMap::UpdateEntryL(TInt aIndex, TContactItemId aId) |
|
58 { |
|
59 __ASSERT_ALWAYS(aIndex >= 0 && aIndex < iCurrentItemMap.Count(), User::Leave(KErrOverflow)); |
|
60 iCurrentItemMap[aIndex]->SetContactId(aId); |
|
61 } |
|
62 |
|
63 |
|
64 void CCntServerCurrentItemMap::AddEntryL(const TDesC& aDatabaseFile, TContactItemId aId) |
|
65 { |
|
66 CCntCurrentItemMapEntry* entry = new(ELeave) CCntCurrentItemMapEntry(); |
|
67 CleanupStack::PushL(entry); |
|
68 entry->ConstructL(aDatabaseFile, aId); |
|
69 User::LeaveIfError(iCurrentItemMap.Append(entry)); |
|
70 CleanupStack::Pop(); // entry |
|
71 } |
|
72 |
|
73 |
|
74 |
|
75 void CCntServerCurrentItemMap::StoreL(CDictionaryFileStore& aStore) const |
|
76 { |
|
77 RDictionaryWriteStream stream; |
|
78 stream.AssignLC(aStore, KUidCntCurrentItemStream); |
|
79 |
|
80 const TInt count = iCurrentItemMap.Count(); |
|
81 stream.WriteInt32L(count); |
|
82 for(TInt i=0; i<count; i++) |
|
83 { |
|
84 const CCntCurrentItemMapEntry* entry = iCurrentItemMap[i]; |
|
85 stream << *entry; |
|
86 } |
|
87 |
|
88 stream.CommitL(); |
|
89 CleanupStack::PopAndDestroy(); // stream |
|
90 } |
|
91 |
|
92 |
|
93 void CCntServerCurrentItemMap::RestoreL(CDictionaryFileStore& aStore) |
|
94 { |
|
95 if (aStore.IsPresentL(KUidCntCurrentItemStream)) |
|
96 { |
|
97 RDictionaryReadStream stream; |
|
98 stream.OpenLC(aStore, KUidCntCurrentItemStream); |
|
99 |
|
100 const TInt count = stream.ReadInt32L(); |
|
101 for(TInt i=0; i<count; i++) |
|
102 { |
|
103 CCntCurrentItemMapEntry* entry = new(ELeave) CCntCurrentItemMapEntry(); |
|
104 CleanupStack::PushL(entry); |
|
105 stream >> *entry; |
|
106 User::LeaveIfError(iCurrentItemMap.Append(entry)); |
|
107 CleanupStack::Pop(); // entry |
|
108 } |
|
109 |
|
110 CleanupStack::PopAndDestroy(); // stream |
|
111 } |
|
112 } |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 CCntServerCurrentItemMap::CCntCurrentItemMapEntry::CCntCurrentItemMapEntry() |
|
121 { |
|
122 } |
|
123 |
|
124 |
|
125 CCntServerCurrentItemMap::CCntCurrentItemMapEntry::~CCntCurrentItemMapEntry() |
|
126 { |
|
127 delete iDatabaseFile; |
|
128 } |
|
129 |
|
130 |
|
131 void CCntServerCurrentItemMap::CCntCurrentItemMapEntry::ConstructL(const TDesC& aFileName, TContactItemId aContactId) |
|
132 { |
|
133 iDatabaseFile = aFileName.AllocL(); |
|
134 iContactId = aContactId; |
|
135 } |
|
136 |
|
137 |
|
138 void CCntServerCurrentItemMap::CCntCurrentItemMapEntry::InternalizeL(RReadStream& aStream) |
|
139 { |
|
140 iDatabaseFile = HBufC::NewL(aStream, KMaxTInt); |
|
141 iContactId = aStream.ReadInt32L(); |
|
142 } |
|
143 |
|
144 |
|
145 void CCntServerCurrentItemMap::CCntCurrentItemMapEntry::ExternalizeL(RWriteStream& aStream) const |
|
146 { |
|
147 aStream << *iDatabaseFile; |
|
148 aStream.WriteInt32L(iContactId); |
|
149 } |
|
150 |
|
151 |
|
152 |
|
153 |