85
|
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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "castorage.h"
|
|
19 |
#include "castorageproxy.h"
|
|
20 |
#include "castoragefactory.h"
|
|
21 |
#include "cainnerentry.h"
|
|
22 |
#include "cainnerquery.h"
|
|
23 |
#include "caarraycleanup.inl"
|
|
24 |
#include "calocalizationentry.h"
|
|
25 |
#include "casrvsession.h"
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
// ---------------------------------------------------------------------------
|
|
30 |
//
|
|
31 |
// ---------------------------------------------------------------------------
|
|
32 |
//
|
|
33 |
CCaStorageProxy::CCaStorageProxy()
|
|
34 |
{
|
|
35 |
}
|
|
36 |
|
|
37 |
// ---------------------------------------------------------------------------
|
86
|
38 |
//
|
85
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
void CCaStorageProxy::ConstructL()
|
|
42 |
{
|
|
43 |
iStorage = CaStorageFactory::NewDatabaseL();
|
|
44 |
}
|
|
45 |
|
|
46 |
// ---------------------------------------------------------------------------
|
|
47 |
//
|
|
48 |
// ---------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
CCaStorageProxy* CCaStorageProxy::NewL()
|
|
51 |
{
|
|
52 |
CCaStorageProxy* self = CCaStorageProxy::NewLC();
|
|
53 |
CleanupStack::Pop( self );
|
|
54 |
return self;
|
|
55 |
}
|
|
56 |
|
|
57 |
// ---------------------------------------------------------------------------
|
|
58 |
//
|
|
59 |
// ---------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
CCaStorageProxy* CCaStorageProxy::NewLC()
|
|
62 |
{
|
|
63 |
CCaStorageProxy* self = new ( ELeave ) CCaStorageProxy();
|
|
64 |
CleanupStack::PushL( self );
|
|
65 |
self->ConstructL();
|
|
66 |
return self;
|
|
67 |
}
|
|
68 |
|
|
69 |
// ---------------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
// ---------------------------------------------------------------------------
|
|
72 |
//
|
|
73 |
CCaStorageProxy::~CCaStorageProxy()
|
|
74 |
{
|
|
75 |
delete iStorage;
|
|
76 |
iHandlerNotifier.Close();
|
|
77 |
}
|
|
78 |
|
|
79 |
// ---------------------------------------------------------------------------
|
|
80 |
//
|
|
81 |
// ---------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
EXPORT_C void CCaStorageProxy::GetEntriesL(const CCaInnerQuery* aQuery,
|
|
84 |
RPointerArray<CCaInnerEntry>& aResultContainer )
|
|
85 |
{
|
|
86 |
iStorage->GetEntriesL( aQuery, aResultContainer );
|
|
87 |
}
|
|
88 |
|
86
|
89 |
// ---------------------------------------------------------------------------
|
|
90 |
//
|
|
91 |
// ---------------------------------------------------------------------------
|
85
|
92 |
//
|
|
93 |
EXPORT_C void CCaStorageProxy::GetEntriesIdsL(const CCaInnerQuery* aQuery,
|
|
94 |
RArray<TInt>& aResultIdArray)
|
|
95 |
{
|
|
96 |
iStorage->GetEntriesIdsL( aQuery, aResultIdArray );
|
|
97 |
}
|
|
98 |
|
86
|
99 |
// ---------------------------------------------------------------------------
|
|
100 |
//
|
|
101 |
// ---------------------------------------------------------------------------
|
85
|
102 |
//
|
93
|
103 |
EXPORT_C void CCaStorageProxy::AddL( CCaInnerEntry* aEntry,
|
|
104 |
TBool aUpdate,
|
|
105 |
TItemAppearance aItemAppearanceChange )
|
85
|
106 |
{
|
|
107 |
TChangeType changeType = EAddChangeType;
|
|
108 |
RArray<TInt> parentArray;
|
|
109 |
CleanupClosePushL( parentArray );
|
93
|
110 |
|
85
|
111 |
if( aEntry->GetId() > 0 )
|
|
112 |
{
|
|
113 |
changeType = EUpdateChangeType;
|
|
114 |
RArray<TInt> id;
|
|
115 |
CleanupClosePushL( id );
|
|
116 |
id.AppendL( aEntry->GetId() );
|
|
117 |
iStorage->GetParentsIdsL( id, parentArray );
|
|
118 |
CleanupStack::PopAndDestroy( &id );
|
|
119 |
}
|
93
|
120 |
|
|
121 |
if( aItemAppearanceChange==EItemDisappeared )
|
|
122 |
{
|
|
123 |
changeType = ERemoveChangeType;
|
|
124 |
}
|
|
125 |
else if( aItemAppearanceChange==EItemAppeared )
|
|
126 |
{
|
|
127 |
changeType = EAddChangeType;
|
|
128 |
}
|
|
129 |
|
85
|
130 |
iStorage->AddL( aEntry, aUpdate );
|
|
131 |
for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
|
|
132 |
{
|
|
133 |
iHandlerNotifier[i]->EntryChanged( aEntry, changeType, parentArray );
|
|
134 |
}
|
|
135 |
CleanupStack::PopAndDestroy( &parentArray );
|
|
136 |
}
|
|
137 |
|
86
|
138 |
// ---------------------------------------------------------------------------
|
|
139 |
//
|
|
140 |
// ---------------------------------------------------------------------------
|
85
|
141 |
//
|
|
142 |
EXPORT_C void CCaStorageProxy::RemoveL( const RArray<TInt>& aEntryIds )
|
|
143 |
{
|
|
144 |
CCaInnerQuery* query = CCaInnerQuery::NewLC();
|
|
145 |
query->SetIdsL( aEntryIds );
|
|
146 |
RPointerArray<CCaInnerEntry> resultContainer;
|
|
147 |
CleanupResetAndDestroyPushL( resultContainer );
|
|
148 |
RArray<TInt> parentArray;
|
|
149 |
CleanupClosePushL( parentArray );
|
|
150 |
if( aEntryIds.Count() > 0 )
|
|
151 |
{
|
|
152 |
iStorage->GetEntriesL( query, resultContainer );
|
|
153 |
iStorage->GetParentsIdsL( aEntryIds, parentArray );
|
|
154 |
}
|
|
155 |
iStorage->RemoveL( aEntryIds );
|
|
156 |
for( TInt i( 0 ); i < resultContainer.Count(); i++ )
|
|
157 |
{
|
|
158 |
for( TInt j( 0 ); j < iHandlerNotifier.Count(); j++ )
|
|
159 |
{
|
86
|
160 |
iHandlerNotifier[j]->EntryChanged( resultContainer[i],
|
85
|
161 |
ERemoveChangeType, parentArray );
|
|
162 |
}
|
|
163 |
}
|
|
164 |
CleanupStack::PopAndDestroy( &parentArray );
|
|
165 |
CleanupStack::PopAndDestroy( &resultContainer );
|
|
166 |
CleanupStack::PopAndDestroy( query );
|
|
167 |
}
|
|
168 |
|
86
|
169 |
// ---------------------------------------------------------------------------
|
|
170 |
//
|
|
171 |
// ---------------------------------------------------------------------------
|
85
|
172 |
//
|
|
173 |
EXPORT_C void CCaStorageProxy::OrganizeL( const RArray<TInt>& aEntryIds,
|
|
174 |
TCaOperationParams aParams )
|
|
175 |
{
|
|
176 |
iStorage->OrganizeL( aEntryIds, aParams );
|
|
177 |
RArray<TInt> parentArray;
|
|
178 |
CleanupClosePushL( parentArray );
|
|
179 |
parentArray.AppendL( aParams.iGroupId );
|
|
180 |
iStorage->GetParentsIdsL( parentArray, parentArray );
|
|
181 |
for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
|
|
182 |
{
|
|
183 |
iHandlerNotifier[i]->GroupContentChanged( parentArray );
|
|
184 |
}
|
|
185 |
CleanupStack::PopAndDestroy( &parentArray );
|
|
186 |
}
|
|
187 |
|
86
|
188 |
// ---------------------------------------------------------------------------
|
|
189 |
//
|
|
190 |
// ---------------------------------------------------------------------------
|
85
|
191 |
//
|
|
192 |
EXPORT_C void CCaStorageProxy::TouchL( CCaInnerEntry* aEntry )
|
|
193 |
{
|
|
194 |
CCaInnerQuery* touchQuery = CCaInnerQuery::NewLC();
|
86
|
195 |
|
85
|
196 |
TInt entryId = aEntry->GetId();
|
86
|
197 |
|
85
|
198 |
if ( entryId == 0 && aEntry->GetUid() != 0)
|
|
199 |
{
|
|
200 |
CCaInnerQuery* idQuery = CCaInnerQuery::NewLC();
|
|
201 |
idQuery->SetUid( static_cast<TUint>( aEntry->GetUid()) );
|
86
|
202 |
|
85
|
203 |
RArray<TInt> idArray;
|
|
204 |
CleanupClosePushL( idArray );
|
86
|
205 |
|
85
|
206 |
iStorage->GetEntriesIdsL( idQuery, idArray );
|
86
|
207 |
|
85
|
208 |
if (idArray.Count() == 1 )
|
|
209 |
{
|
|
210 |
entryId = idArray[0];
|
|
211 |
aEntry->SetId( entryId );
|
86
|
212 |
}
|
|
213 |
|
|
214 |
CleanupStack::PopAndDestroy( &idArray );
|
|
215 |
CleanupStack::PopAndDestroy( idQuery );
|
85
|
216 |
}
|
86
|
217 |
|
85
|
218 |
RArray<TInt> id;
|
|
219 |
CleanupClosePushL( id );
|
|
220 |
id.AppendL( entryId );
|
|
221 |
touchQuery->SetIdsL( id );
|
|
222 |
RPointerArray<CCaInnerEntry> resultArray;
|
|
223 |
CleanupResetAndDestroyPushL( resultArray );
|
|
224 |
iStorage->GetEntriesL( touchQuery, resultArray );
|
|
225 |
iStorage->TouchL( entryId );
|
|
226 |
for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
|
|
227 |
{
|
|
228 |
iHandlerNotifier[i]->EntryTouched( entryId );
|
|
229 |
}
|
|
230 |
if( resultArray.Count() > 0 )
|
|
231 |
{
|
|
232 |
if( !( resultArray[0]->GetFlags() & EUsed ) )
|
|
233 |
{
|
|
234 |
RArray<TInt> parentArray;
|
|
235 |
CleanupClosePushL( parentArray );
|
|
236 |
iStorage->GetParentsIdsL( id, parentArray );
|
|
237 |
for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
|
|
238 |
{
|
86
|
239 |
iHandlerNotifier[i]->EntryChanged( resultArray[0],
|
|
240 |
EUpdateChangeType,
|
85
|
241 |
parentArray );
|
|
242 |
}
|
|
243 |
CleanupStack::PopAndDestroy( &parentArray );
|
|
244 |
}
|
|
245 |
}
|
|
246 |
CleanupStack::PopAndDestroy( &resultArray );
|
|
247 |
CleanupStack::PopAndDestroy( &id );
|
|
248 |
CleanupStack::PopAndDestroy( touchQuery );
|
|
249 |
}
|
|
250 |
|
86
|
251 |
// ---------------------------------------------------------------------------
|
|
252 |
//
|
|
253 |
// ---------------------------------------------------------------------------
|
85
|
254 |
//
|
|
255 |
EXPORT_C void CCaStorageProxy::GetLocalizationsL(
|
|
256 |
RPointerArray<CCaLocalizationEntry>& aResultArray )
|
|
257 |
{
|
|
258 |
iStorage->GetLocalizationsL( aResultArray );
|
|
259 |
}
|
|
260 |
|
86
|
261 |
// ---------------------------------------------------------------------------
|
|
262 |
//
|
|
263 |
// ---------------------------------------------------------------------------
|
85
|
264 |
//
|
|
265 |
EXPORT_C void CCaStorageProxy::LocalizeEntryL(
|
|
266 |
CCaLocalizationEntry& aLocalization )
|
|
267 |
{
|
|
268 |
iStorage->LocalizeEntryL( aLocalization );
|
|
269 |
}
|
|
270 |
|
86
|
271 |
// ---------------------------------------------------------------------------
|
|
272 |
//
|
|
273 |
// ---------------------------------------------------------------------------
|
85
|
274 |
//
|
|
275 |
EXPORT_C void CCaStorageProxy::DbPropertyL( const TDesC& aProperty,
|
|
276 |
TDes& aPropertyValue )
|
|
277 |
{
|
|
278 |
iStorage->DbPropertyL( aProperty, aPropertyValue );
|
|
279 |
}
|
|
280 |
|
86
|
281 |
// ---------------------------------------------------------------------------
|
|
282 |
//
|
|
283 |
// ---------------------------------------------------------------------------
|
85
|
284 |
//
|
|
285 |
EXPORT_C void CCaStorageProxy::SetDBPropertyL( const TDesC& aProperty,
|
|
286 |
const TDesC& aPropertyValue )
|
|
287 |
{
|
|
288 |
iStorage->SetDBPropertyL( aProperty, aPropertyValue );
|
|
289 |
}
|
|
290 |
|
86
|
291 |
// ---------------------------------------------------------------------------
|
|
292 |
//
|
|
293 |
// ---------------------------------------------------------------------------
|
85
|
294 |
//
|
|
295 |
EXPORT_C void CCaStorageProxy::CustomSortL( const RArray<TInt>& aEntryIds,
|
|
296 |
const TInt aGroupId )
|
|
297 |
{
|
|
298 |
iStorage->CustomSortL( aEntryIds, aGroupId );
|
86
|
299 |
|
85
|
300 |
RArray<TInt> parentArray;
|
|
301 |
CleanupClosePushL( parentArray );
|
|
302 |
parentArray.AppendL( aGroupId );
|
|
303 |
for( TInt i = 0; i < iHandlerNotifier.Count(); i++ )
|
|
304 |
{
|
|
305 |
iHandlerNotifier[i]->GroupContentChanged( parentArray );
|
|
306 |
}
|
|
307 |
CleanupStack::PopAndDestroy( &parentArray );
|
|
308 |
}
|
|
309 |
|
86
|
310 |
// ---------------------------------------------------------------------------
|
|
311 |
//
|
|
312 |
// ---------------------------------------------------------------------------
|
|
313 |
//
|
|
314 |
EXPORT_C void CCaStorageProxy::LoadDataBaseFromRomL()
|
|
315 |
{
|
|
316 |
iStorage->LoadDataBaseFromRomL();
|
|
317 |
}
|
|
318 |
|
85
|
319 |
// ---------------------------------------------------------
|
86
|
320 |
//
|
85
|
321 |
// ---------------------------------------------------------
|
|
322 |
//
|
|
323 |
void CCaStorageProxy::AddSessionL( MCaSessionNorifier* aHandlerNotifier )
|
|
324 |
{
|
86
|
325 |
__ASSERT_ALWAYS(
|
|
326 |
iHandlerNotifier.Find( aHandlerNotifier ) == KErrNotFound,
|
85
|
327 |
User::Invariant() );
|
|
328 |
iHandlerNotifier.AppendL( aHandlerNotifier );
|
|
329 |
}
|
|
330 |
|
|
331 |
// ---------------------------------------------------------
|
86
|
332 |
//
|
85
|
333 |
// ---------------------------------------------------------
|
|
334 |
//
|
|
335 |
void CCaStorageProxy::RemoveSession( MCaSessionNorifier* aHandlerNotifier )
|
|
336 |
{
|
|
337 |
TInt i = iHandlerNotifier.Find( aHandlerNotifier );
|
|
338 |
if( i != KErrNotFound )
|
|
339 |
{
|
|
340 |
iHandlerNotifier.Remove( i );
|
|
341 |
}
|
|
342 |
}
|