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