63
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2007 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: The virtual phonebook store implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDES
|
|
20 |
#include "CContactStore.h"
|
|
21 |
|
|
22 |
#include "CContactView.h"
|
|
23 |
#include "CContact.h"
|
|
24 |
#include "CRemoteStore.h"
|
|
25 |
#include "CFieldTypeMappings.h"
|
|
26 |
#include "CContactStoreDomain.h"
|
|
27 |
#include "CCommitContactsOperation.h"
|
|
28 |
#include "CDeleteContactsOperation.h"
|
|
29 |
#include "CMatchPhoneNumberOperation.h"
|
|
30 |
#include "CFindOperation.h"
|
|
31 |
#include "CFindWithParserOperation.h"
|
|
32 |
#include "CContactRetriever.h"
|
|
33 |
#include "CSupportedFieldTypes.h"
|
|
34 |
#include "CContactLink.h"
|
|
35 |
#include "CContactOperationCallback.h"
|
|
36 |
#include "CContactStoreInfo.h"
|
|
37 |
|
|
38 |
#include "VPbkSimStoreError.h"
|
|
39 |
#include "VPbkStoreUriLiterals.h"
|
|
40 |
|
|
41 |
#include <CVPbkContactStoreUri.h>
|
|
42 |
#include <TVPbkContactStoreUriPtr.h>
|
|
43 |
#include <MVPbkContactStoreObserver.h>
|
|
44 |
#include <CVPbkSimContact.h>
|
|
45 |
#include <TVPbkSimStoreProperty.h>
|
|
46 |
#include <CVPbkContactStoreProperties.h>
|
|
47 |
#include <VPbkError.h>
|
|
48 |
#include <VPbkSimStoreTemplateFunctions.h>
|
|
49 |
#include <CVPbkAsyncCallback.h>
|
|
50 |
|
|
51 |
#include <featmgr.h>
|
|
52 |
namespace VPbkSimStore {
|
|
53 |
|
|
54 |
// LOCAL
|
|
55 |
namespace {
|
|
56 |
|
|
57 |
// CONSTANTS
|
|
58 |
|
|
59 |
// ============================= LOCAL FUNCTIONS ===============================
|
|
60 |
|
|
61 |
// -----------------------------------------------------------------------------
|
|
62 |
// GetStoreIdentifier
|
|
63 |
// Converts Virtual phonebook store name to sim store identifier
|
|
64 |
// -----------------------------------------------------------------------------
|
|
65 |
//
|
|
66 |
TVPbkSimStoreIdentifier GetStoreIdentifier( const TDesC& aStoreName )
|
|
67 |
{
|
|
68 |
TVPbkSimStoreIdentifier identifier = EVPbkSimAdnGlobalStore;
|
|
69 |
if ( aStoreName.Compare( KVPbkSimGlobalAdnURI ) == 0 )
|
|
70 |
{
|
|
71 |
identifier = EVPbkSimAdnGlobalStore;
|
|
72 |
}
|
|
73 |
else if ( aStoreName.Compare( KVPbkSimGlobalSdnURI ) == 0 )
|
|
74 |
{
|
|
75 |
identifier = EVPbkSimSdnGlobalStore;
|
|
76 |
}
|
|
77 |
else if ( aStoreName.Compare( KVPbkSimGlobalFdnURI ) == 0 )
|
|
78 |
{
|
|
79 |
identifier = EVPbkSimFdnGlobalStore;
|
|
80 |
}
|
|
81 |
else if ( aStoreName.Compare( KVPbkSimGlobalOwnNumberURI ) == 0 )
|
|
82 |
{
|
|
83 |
identifier = EVPbkSimONStore;
|
|
84 |
}
|
|
85 |
else
|
|
86 |
{
|
|
87 |
VPbkSimStore::Panic( VPbkSimStore::EStoreNameMappingFailed );
|
|
88 |
}
|
|
89 |
return identifier;
|
|
90 |
}
|
|
91 |
} // unnamed namespace
|
|
92 |
|
|
93 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
94 |
|
|
95 |
// -----------------------------------------------------------------------------
|
|
96 |
// CContactStore::CContactStore
|
|
97 |
// C++ default constructor can NOT contain any code, that
|
|
98 |
// might leave.
|
|
99 |
// -----------------------------------------------------------------------------
|
|
100 |
//
|
|
101 |
inline CContactStore::CContactStore( CContactStoreDomain& aStoreDomain )
|
|
102 |
: iStoreDomain( aStoreDomain ),
|
|
103 |
iStoreState( EStoreNotOpen )
|
|
104 |
{
|
|
105 |
}
|
|
106 |
|
|
107 |
// -----------------------------------------------------------------------------
|
|
108 |
// CContactStore::ConstructL
|
|
109 |
// Symbian 2nd phase constructor can leave.
|
|
110 |
// -----------------------------------------------------------------------------
|
|
111 |
//
|
|
112 |
inline void CContactStore::ConstructL( const TVPbkContactStoreUriPtr& aURI )
|
|
113 |
{
|
|
114 |
iProperties = CVPbkContactStoreProperties::NewL();
|
|
115 |
iStoreURI = CVPbkContactStoreUri::NewL( aURI );
|
|
116 |
iProperties->SetName( iStoreURI->Uri() );
|
|
117 |
iAsyncOpenOp =
|
|
118 |
CVPbkAsyncObjectOperation<MVPbkContactStoreObserver>::NewL();
|
|
119 |
|
|
120 |
iStoreInfo = CContactStoreInfo::NewL( *this );
|
|
121 |
iNativeStore = CRemoteStore::NewL( GetStoreIdentifier(
|
|
122 |
iStoreURI->Uri().UriDes() ) );
|
|
123 |
}
|
|
124 |
|
|
125 |
// -----------------------------------------------------------------------------
|
|
126 |
// CContactStore::NewL
|
|
127 |
// Two-phased constructor.
|
|
128 |
// -----------------------------------------------------------------------------
|
|
129 |
//
|
|
130 |
CContactStore* CContactStore::NewL( const TVPbkContactStoreUriPtr& aURI,
|
|
131 |
CContactStoreDomain& aStoreDomain )
|
|
132 |
{
|
|
133 |
CContactStore* self = new ( ELeave ) CContactStore( aStoreDomain );
|
|
134 |
CleanupStack::PushL( self );
|
|
135 |
self->ConstructL( aURI );
|
|
136 |
CleanupStack::Pop( self );
|
|
137 |
return self;
|
|
138 |
}
|
|
139 |
|
|
140 |
// Destructor
|
|
141 |
CContactStore::~CContactStore()
|
|
142 |
{
|
|
143 |
iStoreObservers.Close();
|
|
144 |
delete iStoreInfo;
|
|
145 |
delete iSupportedFieldTypes;
|
|
146 |
delete iAsyncOpenOp;
|
|
147 |
delete iStoreURI;
|
|
148 |
if ( iNativeStore )
|
|
149 |
{
|
|
150 |
iNativeStore->Close( *this );
|
|
151 |
delete iNativeStore;
|
|
152 |
}
|
|
153 |
delete iProperties;
|
|
154 |
}
|
|
155 |
|
|
156 |
// -----------------------------------------------------------------------------
|
|
157 |
// CContactStore::FieldTypeMappings
|
|
158 |
// -----------------------------------------------------------------------------
|
|
159 |
//
|
|
160 |
CFieldTypeMappings& CContactStore::FieldTypeMappings()
|
|
161 |
{
|
|
162 |
return iStoreDomain.FieldTypeMappings();
|
|
163 |
}
|
|
164 |
|
|
165 |
// -----------------------------------------------------------------------------
|
|
166 |
// CContactStore::MasterFieldTypeList
|
|
167 |
// -----------------------------------------------------------------------------
|
|
168 |
//
|
|
169 |
const MVPbkFieldTypeList& CContactStore::MasterFieldTypeList() const
|
|
170 |
{
|
|
171 |
return iStoreDomain.MasterFieldTypeList();
|
|
172 |
}
|
|
173 |
|
|
174 |
// -----------------------------------------------------------------------------
|
|
175 |
// CContactStore::NativeStore
|
|
176 |
// -----------------------------------------------------------------------------
|
|
177 |
//
|
|
178 |
MVPbkSimCntStore& CContactStore::NativeStore()
|
|
179 |
{
|
|
180 |
return *iNativeStore;
|
|
181 |
}
|
|
182 |
|
|
183 |
// -----------------------------------------------------------------------------
|
|
184 |
// CContactStore::CreateLinkLC
|
|
185 |
// -----------------------------------------------------------------------------
|
|
186 |
//
|
|
187 |
MVPbkContactLink* CContactStore::CreateLinkLC( TInt aSimIndex ) const
|
|
188 |
{
|
|
189 |
MVPbkContactLink* ret = NULL;
|
|
190 |
if ( aSimIndex != KVPbkSimStoreFirstFreeIndex )
|
|
191 |
{
|
|
192 |
// Contact store constness casted away, no reason to be const
|
|
193 |
ret = CContactLink::NewLC( const_cast<CContactStore&>(*this), aSimIndex );
|
|
194 |
}
|
|
195 |
return ret;
|
|
196 |
}
|
|
197 |
|
|
198 |
// -----------------------------------------------------------------------------
|
|
199 |
// CContactStore::ReadContactL
|
|
200 |
// -----------------------------------------------------------------------------
|
|
201 |
//
|
|
202 |
CContact* CContactStore::ReadContactL( TInt aSimIndex )
|
|
203 |
{
|
|
204 |
__ASSERT_DEBUG( iStoreState != EStoreNotOpen,
|
|
205 |
VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
|
|
206 |
|
|
207 |
// Read sim contact synchronously
|
|
208 |
const TDesC8* etelCnt = iNativeStore->AtL( aSimIndex );
|
|
209 |
if( !etelCnt )
|
|
210 |
{
|
|
211 |
User::Leave( KErrNotFound );
|
|
212 |
}
|
|
213 |
CVPbkSimContact* simCnt =
|
|
214 |
CVPbkSimContact::NewLC( *etelCnt, *iNativeStore );
|
|
215 |
// Create vpbk contact
|
|
216 |
CContact* cnt = CContact::NewL( *this, simCnt );
|
|
217 |
CleanupStack::Pop( simCnt );
|
|
218 |
return cnt;
|
|
219 |
}
|
|
220 |
|
|
221 |
// -----------------------------------------------------------------------------
|
|
222 |
// CContactStore::MatchContactStore
|
|
223 |
// -----------------------------------------------------------------------------
|
|
224 |
//
|
|
225 |
TBool CContactStore::MatchContactStore( const TDesC& aContactStoreUri ) const
|
|
226 |
{
|
|
227 |
if ( iStoreURI->Uri().Compare(
|
|
228 |
TVPbkContactStoreUriPtr( aContactStoreUri ),
|
|
229 |
TVPbkContactStoreUriPtr::EContactStoreUriAllComponents ) == 0 )
|
|
230 |
{
|
|
231 |
return ETrue;
|
|
232 |
}
|
|
233 |
return EFalse;
|
|
234 |
}
|
|
235 |
|
|
236 |
// -----------------------------------------------------------------------------
|
|
237 |
// CContactStore::MatchContactStoreDomain
|
|
238 |
// -----------------------------------------------------------------------------
|
|
239 |
//
|
|
240 |
TBool CContactStore::MatchContactStoreDomain(
|
|
241 |
const TDesC& aContactStoreDomain ) const
|
|
242 |
{
|
|
243 |
if ( iStoreURI->Uri().Compare(
|
|
244 |
aContactStoreDomain,
|
|
245 |
TVPbkContactStoreUriPtr::EContactStoreUriStoreType ) == 0 )
|
|
246 |
{
|
|
247 |
return ETrue;
|
|
248 |
}
|
|
249 |
return EFalse;
|
|
250 |
}
|
|
251 |
|
|
252 |
// -----------------------------------------------------------------------------
|
|
253 |
// CContactStore::CreateBookmarkLC
|
|
254 |
// -----------------------------------------------------------------------------
|
|
255 |
//
|
|
256 |
MVPbkContactBookmark* CContactStore::CreateBookmarkLC( TInt aSimIndex ) const
|
|
257 |
{
|
|
258 |
__ASSERT_DEBUG( iStoreState != EStoreNotOpen,
|
|
259 |
VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
|
|
260 |
// Bookmark is implemented as a link in this store
|
|
261 |
// Contact store constness casted away, no reason to be const
|
|
262 |
return CContactLink::NewLC( const_cast<CContactStore&>(*this), aSimIndex );
|
|
263 |
}
|
|
264 |
|
|
265 |
// -----------------------------------------------------------------------------
|
|
266 |
// CContactStore::CreateCommitContactsOperationL
|
|
267 |
// -----------------------------------------------------------------------------
|
|
268 |
//
|
|
269 |
MVPbkContactOperation* CContactStore::CreateCommitContactsOperationL(
|
|
270 |
const TArray<MVPbkStoreContact*>& aContacts,
|
|
271 |
MVPbkBatchOperationObserver& aObserver )
|
|
272 |
{
|
|
273 |
|
|
274 |
RArray<MVPbkStoreContact*> simContacts;
|
|
275 |
CleanupClosePushL( simContacts );
|
|
276 |
const TInt count = aContacts.Count();
|
|
277 |
for ( TInt i = 0; i < count; ++i )
|
|
278 |
{
|
|
279 |
if ( &aContacts[i]->ParentStore() == this )
|
|
280 |
{
|
|
281 |
simContacts.AppendL( aContacts[i] );
|
|
282 |
}
|
|
283 |
}
|
|
284 |
|
|
285 |
CCommitContactsOperation* cntOp = NULL;
|
|
286 |
if ( simContacts.Count() > 0 )
|
|
287 |
{
|
|
288 |
__ASSERT_DEBUG( iStoreState != EStoreNotOpen,
|
|
289 |
VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
|
|
290 |
if (iStoreState == EStoreOpen )
|
|
291 |
{
|
|
292 |
cntOp = CCommitContactsOperation::NewL( *this, aObserver,
|
|
293 |
simContacts.Array() );
|
|
294 |
}
|
|
295 |
|
|
296 |
}
|
|
297 |
CleanupStack::PopAndDestroy(); // simContacts
|
|
298 |
return cntOp;
|
|
299 |
}
|
|
300 |
|
|
301 |
// -----------------------------------------------------------------------------
|
|
302 |
// CContactStore::CreateContactRetrieverL
|
|
303 |
// -----------------------------------------------------------------------------
|
|
304 |
//
|
|
305 |
MVPbkContactOperation* CContactStore::CreateContactRetrieverL(
|
|
306 |
const MVPbkContactLink& aLink,
|
|
307 |
MVPbkSingleContactOperationObserver& aObserver )
|
|
308 |
{
|
|
309 |
|
|
310 |
if ( CContactLink::IsValid( *this, aLink ) )
|
|
311 |
{
|
|
312 |
__ASSERT_DEBUG( iStoreState != EStoreNotOpen,
|
|
313 |
VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
|
|
314 |
if ( iStoreState == EStoreOpen )
|
|
315 |
{
|
|
316 |
const CContactLink& link = static_cast<const CContactLink&>( aLink );
|
|
317 |
return CContactRetriever::NewL( *this, link.SimIndex(), aObserver );
|
|
318 |
}
|
|
319 |
}
|
|
320 |
return NULL;
|
|
321 |
}
|
|
322 |
|
|
323 |
// -----------------------------------------------------------------------------
|
|
324 |
// CContactStore::CreateDeleteContactsOperationL
|
|
325 |
// -----------------------------------------------------------------------------
|
|
326 |
//
|
|
327 |
MVPbkContactOperation* CContactStore::CreateDeleteContactsOperationL(
|
|
328 |
const MVPbkContactLinkArray& aContactLinks,
|
|
329 |
MVPbkBatchOperationObserver& aObserver )
|
|
330 |
{
|
|
331 |
|
|
332 |
MVPbkContactOperation* operation = NULL;
|
|
333 |
if ( !iProperties->ReadOnly() )
|
|
334 |
{
|
|
335 |
const TInt count = aContactLinks.Count();
|
|
336 |
const TInt granularity = 20;
|
|
337 |
RArray<TInt> indexes( granularity );
|
|
338 |
CleanupClosePushL( indexes );
|
|
339 |
for ( TInt i = 0; i < count; ++i )
|
|
340 |
{
|
|
341 |
if ( &aContactLinks.At(i).ContactStore() == this )
|
|
342 |
{
|
|
343 |
const CContactLink& link =
|
|
344 |
static_cast<const CContactLink&>( aContactLinks.At(i) );
|
|
345 |
indexes.AppendL( link.SimIndex() );
|
|
346 |
}
|
|
347 |
|
|
348 |
}
|
|
349 |
|
|
350 |
if ( indexes.Count() > 0 )
|
|
351 |
{
|
|
352 |
__ASSERT_DEBUG( iStoreState != EStoreNotOpen,
|
|
353 |
VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
|
|
354 |
if ( iStoreState == EStoreOpen )
|
|
355 |
{
|
|
356 |
operation = CDeleteContactsOperation::NewL( *this, aObserver,
|
|
357 |
indexes.Array() );
|
|
358 |
}
|
|
359 |
}
|
|
360 |
CleanupStack::PopAndDestroy(); // indexes
|
|
361 |
}
|
|
362 |
return operation;
|
|
363 |
}
|
|
364 |
|
|
365 |
// -----------------------------------------------------------------------------
|
|
366 |
// CContactStore::CreateMatchPhoneNumberOperationL
|
|
367 |
// -----------------------------------------------------------------------------
|
|
368 |
//
|
|
369 |
MVPbkContactOperation* CContactStore::CreateMatchPhoneNumberOperationL(
|
|
370 |
const TDesC& aPhoneNumber, TInt aMaxMatchDigits,
|
|
371 |
MVPbkContactFindObserver& aObserver )
|
|
372 |
{
|
|
373 |
|
|
374 |
if ( iStoreState == EStoreOpen )
|
|
375 |
{
|
|
376 |
return CMatchPhoneNumberOperation::NewL( aPhoneNumber,
|
|
377 |
aMaxMatchDigits, aObserver, *this );
|
|
378 |
}
|
|
379 |
return NULL;
|
|
380 |
}
|
|
381 |
|
|
382 |
// -----------------------------------------------------------------------------
|
|
383 |
// CContactStore::CreateFindOperationL
|
|
384 |
// -----------------------------------------------------------------------------
|
|
385 |
//
|
|
386 |
MVPbkContactOperation* CContactStore::CreateFindOperationL(
|
|
387 |
const TDesC& aSearchString,
|
|
388 |
const MVPbkFieldTypeList& aFieldTypes,
|
|
389 |
MVPbkContactFindObserver& aObserver)
|
|
390 |
{
|
|
391 |
|
|
392 |
if ( iStoreState == EStoreOpen )
|
|
393 |
{
|
|
394 |
return CFindOperation::NewL( *this, aObserver, aSearchString,
|
|
395 |
aFieldTypes );
|
|
396 |
}
|
|
397 |
return NULL;
|
|
398 |
}
|
|
399 |
|
|
400 |
// -----------------------------------------------------------------------------
|
|
401 |
// CContactStore::CreateFindOperationL
|
|
402 |
// -----------------------------------------------------------------------------
|
|
403 |
//
|
|
404 |
MVPbkContactOperation* CContactStore::CreateFindOperationL(
|
|
405 |
const MDesC16Array& aSearchStrings,
|
|
406 |
const MVPbkFieldTypeList& aFieldTypes,
|
|
407 |
MVPbkContactFindFromStoresObserver& aObserver,
|
|
408 |
const TCallBack& aWordParserCallBack )
|
|
409 |
{
|
|
410 |
|
|
411 |
if ( iStoreState == EStoreOpen )
|
|
412 |
{
|
|
413 |
return CFindWithParserOperation::NewL( *this, aSearchStrings,
|
|
414 |
aFieldTypes, aObserver, aWordParserCallBack );
|
|
415 |
}
|
|
416 |
return NULL;
|
|
417 |
}
|
|
418 |
|
|
419 |
// -----------------------------------------------------------------------------
|
|
420 |
// CContactStore::CreateCompressStoresOperationL
|
|
421 |
// -----------------------------------------------------------------------------
|
|
422 |
//
|
|
423 |
MVPbkContactOperation* CContactStore::CreateCompressStoresOperationL(
|
|
424 |
MVPbkBatchOperationObserver& /*aObserver*/)
|
|
425 |
{
|
|
426 |
return NULL;
|
|
427 |
}
|
|
428 |
|
|
429 |
// -----------------------------------------------------------------------------
|
|
430 |
// CContactStore::StoreProperties
|
|
431 |
// -----------------------------------------------------------------------------
|
|
432 |
//
|
|
433 |
const MVPbkContactStoreProperties& CContactStore::StoreProperties() const
|
|
434 |
{
|
|
435 |
return *iProperties;
|
|
436 |
}
|
|
437 |
|
|
438 |
// -----------------------------------------------------------------------------
|
|
439 |
// CContactStore::OpenL
|
|
440 |
// -----------------------------------------------------------------------------
|
|
441 |
//
|
|
442 |
void CContactStore::OpenL( MVPbkContactStoreObserver& aObserver )
|
|
443 |
{
|
|
444 |
switch ( iStoreState )
|
|
445 |
{
|
|
446 |
case EStoreNotOpen:
|
|
447 |
{
|
|
448 |
// Close first to ensure that store doesn't register twice.
|
|
449 |
iNativeStore->Close( *this );
|
|
450 |
iNativeStore->OpenL( iStoreDomain.SecurityInformation(), *this );
|
|
451 |
break;
|
|
452 |
}
|
|
453 |
case EStoreOpen:
|
|
454 |
case EStoreNotAvailable:
|
|
455 |
default:
|
|
456 |
{
|
|
457 |
CVPbkAsyncObjectCallback<MVPbkContactStoreObserver>* callback =
|
|
458 |
VPbkEngUtils::CreateAsyncObjectCallbackLC(
|
|
459 |
*this,
|
|
460 |
&CContactStore::DoOpenL,
|
|
461 |
&CContactStore::DoOpenError,
|
|
462 |
aObserver);
|
|
463 |
iAsyncOpenOp->CallbackL( callback );
|
|
464 |
CleanupStack::Pop( callback );
|
|
465 |
break;
|
|
466 |
}
|
|
467 |
}
|
|
468 |
|
|
469 |
// adds aObserver to list of observers if it isn't there already, thus
|
|
470 |
// avoids clients registering multiple times
|
|
471 |
if ( iStoreObservers.Find(&aObserver) == KErrNotFound )
|
|
472 |
{
|
|
473 |
iStoreObservers.AppendL( &aObserver );
|
|
474 |
}
|
|
475 |
}
|
|
476 |
|
|
477 |
// -----------------------------------------------------------------------------
|
|
478 |
// CContactStore::ReplaceL
|
|
479 |
// -----------------------------------------------------------------------------
|
|
480 |
//
|
|
481 |
void CContactStore::ReplaceL(MVPbkContactStoreObserver& aObserver)
|
|
482 |
{
|
|
483 |
OpenL( aObserver );
|
|
484 |
}
|
|
485 |
|
|
486 |
// -----------------------------------------------------------------------------
|
|
487 |
// CContactStore::Close
|
|
488 |
// -----------------------------------------------------------------------------
|
|
489 |
//
|
|
490 |
void CContactStore::Close(MVPbkContactStoreObserver& aObserver)
|
|
491 |
{
|
|
492 |
iAsyncOpenOp->CancelCallback( &aObserver );
|
|
493 |
|
|
494 |
const TInt pos = iStoreObservers.Find( &aObserver );
|
|
495 |
if ( pos != KErrNotFound )
|
|
496 |
{
|
|
497 |
iStoreObservers.Remove( pos );
|
|
498 |
}
|
|
499 |
|
|
500 |
if ( iStoreObservers.Count() == 0 )
|
|
501 |
{
|
|
502 |
iNativeStore->Close( *this );
|
|
503 |
iAsyncOpenOp->Purge();
|
|
504 |
iStoreState = EStoreNotOpen;
|
|
505 |
}
|
|
506 |
}
|
|
507 |
|
|
508 |
// -----------------------------------------------------------------------------
|
|
509 |
// CContactStore::CreateNewContactLC
|
|
510 |
// -----------------------------------------------------------------------------
|
|
511 |
//
|
|
512 |
MVPbkStoreContact* CContactStore::CreateNewContactLC()
|
|
513 |
{
|
|
514 |
__ASSERT_DEBUG( iStoreState != EStoreNotOpen,
|
|
515 |
VPbkError::Panic( VPbkError::EAccessOfUnopenedStore ) );
|
|
516 |
|
|
517 |
CVPbkSimContact* simCnt = CVPbkSimContact::NewLC( *iNativeStore );
|
|
518 |
CContact* cnt = CContact::NewL( *this, simCnt, ETrue );
|
|
519 |
CleanupStack::Pop( simCnt );
|
|
520 |
CleanupStack::PushL( cnt );
|
|
521 |
return cnt;
|
|
522 |
}
|
|
523 |
|
|
524 |
// -----------------------------------------------------------------------------
|
|
525 |
// CContactStore::CreateNewContactGroupLC
|
|
526 |
// -----------------------------------------------------------------------------
|
|
527 |
//
|
|
528 |
MVPbkContactGroup* CContactStore::CreateNewContactGroupLC()
|
|
529 |
{
|
|
530 |
User::Leave(KErrNotSupported);
|
|
531 |
return NULL;
|
|
532 |
}
|
|
533 |
|
|
534 |
// -----------------------------------------------------------------------------
|
|
535 |
// CContactStore::CreateViewLC
|
|
536 |
// -----------------------------------------------------------------------------
|
|
537 |
//
|
|
538 |
MVPbkContactView* CContactStore::CreateViewLC(
|
|
539 |
const CVPbkContactViewDefinition& aViewDefinition,
|
|
540 |
MVPbkContactViewObserver& aObserver,
|
|
541 |
const MVPbkFieldTypeList& aSortOrder )
|
|
542 |
{
|
|
543 |
return CContactView::NewLC( aObserver, *this, aSortOrder, aViewDefinition );
|
|
544 |
}
|
|
545 |
|
|
546 |
// -----------------------------------------------------------------------------
|
|
547 |
// CContactStore::ContactGroupsLC
|
|
548 |
// -----------------------------------------------------------------------------
|
|
549 |
//
|
|
550 |
MVPbkContactLinkArray* CContactStore::ContactGroupsLC() const
|
|
551 |
{
|
|
552 |
return CVPbkContactLinkArray::NewLC();
|
|
553 |
}
|
|
554 |
|
|
555 |
// -----------------------------------------------------------------------------
|
|
556 |
// CContactStore::StoreInfo
|
|
557 |
// -----------------------------------------------------------------------------
|
|
558 |
//
|
|
559 |
const MVPbkContactStoreInfo& CContactStore::StoreInfo() const
|
|
560 |
{
|
|
561 |
return *iStoreInfo;
|
|
562 |
}
|
|
563 |
|
|
564 |
// -----------------------------------------------------------------------------
|
|
565 |
// CContactStore::CreateLinkFromInternalsLC
|
|
566 |
// -----------------------------------------------------------------------------
|
|
567 |
//
|
|
568 |
MVPbkContactLink* CContactStore::CreateLinkFromInternalsLC(
|
|
569 |
RReadStream& aStream) const
|
|
570 |
{
|
|
571 |
// Contact store constness casted away, no reason to be const
|
|
572 |
return CContactLink::NewLC( const_cast<CContactStore&>(*this), aStream );
|
|
573 |
}
|
|
574 |
|
|
575 |
|
|
576 |
|
|
577 |
// -----------------------------------------------------------------------------
|
|
578 |
// CContactStore::StoreReady
|
|
579 |
// -----------------------------------------------------------------------------
|
|
580 |
//
|
|
581 |
void CContactStore::StoreReady( MVPbkSimCntStore& /*aStore*/ )
|
|
582 |
{
|
|
583 |
TVPbkGsmStoreProperty gsmProperties;
|
|
584 |
TInt res = KErrNone;
|
|
585 |
if( !FeatureManager::FeatureSupported( KFeatureIdFfTdClmcontactreplicationfromphonebooktousimcard ) )
|
|
586 |
{
|
|
587 |
res= iNativeStore->GetGsmStoreProperties( gsmProperties );
|
|
588 |
if ( res == KErrNone )
|
|
589 |
{
|
|
590 |
delete iSupportedFieldTypes;
|
|
591 |
iSupportedFieldTypes = NULL;
|
|
592 |
TRAP( res, iSupportedFieldTypes = CSupportedFieldTypes::NewL(
|
|
593 |
iStoreDomain.FieldTypeMappings(), gsmProperties ) );
|
|
594 |
iSimStoreCapabilities = gsmProperties.iCaps;
|
|
595 |
}
|
|
596 |
}
|
|
597 |
else // if contact replication from phonebook to usim card.
|
|
598 |
{
|
|
599 |
TInt resGsm = iNativeStore->GetGsmStoreProperties( gsmProperties );
|
|
600 |
TVPbkUSimStoreProperty usimProperties;
|
|
601 |
TInt resUsim = iNativeStore->GetUSimStoreProperties( usimProperties );
|
|
602 |
if( resGsm == KErrNone && resUsim == KErrNone )
|
|
603 |
{
|
|
604 |
delete iSupportedFieldTypes;
|
|
605 |
iSupportedFieldTypes = NULL;
|
|
606 |
TRAP( res, iSupportedFieldTypes = CSupportedFieldTypes::NewL(
|
|
607 |
iStoreDomain.FieldTypeMappings(), gsmProperties, usimProperties ) );
|
|
608 |
iSimStoreCapabilities = gsmProperties.iCaps;
|
|
609 |
}
|
|
610 |
else
|
|
611 |
{
|
|
612 |
res = ( resGsm != KErrNone ? resGsm : resUsim );
|
|
613 |
}
|
|
614 |
}
|
|
615 |
|
|
616 |
if ( res != KErrNone )
|
|
617 |
{
|
|
618 |
iStoreState = EStoreNotAvailable;
|
|
619 |
VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
|
|
620 |
&MVPbkContactStoreObserver::StoreUnavailable, *this, res );
|
|
621 |
}
|
|
622 |
else
|
|
623 |
{
|
|
624 |
iProperties->SetSupportedFields( *iSupportedFieldTypes );
|
|
625 |
// After sim store is opened get read-only information and set properties
|
|
626 |
SetStaticProperties( gsmProperties );
|
|
627 |
iStoreState = EStoreOpen;
|
|
628 |
VPbkSimStoreImpl::SendObserverMessageR( iStoreObservers,
|
|
629 |
&MVPbkContactStoreObserver::StoreReady, *this );
|
|
630 |
}
|
|
631 |
}
|
|
632 |
|
|
633 |
// -----------------------------------------------------------------------------
|
|
634 |
// CContactStore::StoreReady
|
|
635 |
// -----------------------------------------------------------------------------
|
|
636 |
//
|
|
637 |
void CContactStore::StoreError( MVPbkSimCntStore& /*aStore*/, TInt aError )
|
|
638 |
{
|
|
639 |
iStoreState = EStoreNotAvailable;
|
|
640 |
VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
|
|
641 |
&MVPbkContactStoreObserver::StoreUnavailable, *this, aError );
|
|
642 |
}
|
|
643 |
|
|
644 |
// -----------------------------------------------------------------------------
|
|
645 |
// CContactStore::StoreNotAvailable
|
|
646 |
// -----------------------------------------------------------------------------
|
|
647 |
//
|
|
648 |
void CContactStore::StoreNotAvailable( MVPbkSimCntStore& /*aStore*/ )
|
|
649 |
{
|
|
650 |
iStoreState = EStoreNotAvailable;
|
|
651 |
VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
|
|
652 |
&MVPbkContactStoreObserver::StoreUnavailable, *this,
|
|
653 |
KErrNotSupported );
|
|
654 |
}
|
|
655 |
|
|
656 |
// -----------------------------------------------------------------------------
|
|
657 |
// CContactStore::StoreContactEvent
|
|
658 |
// -----------------------------------------------------------------------------
|
|
659 |
//
|
|
660 |
void CContactStore::StoreContactEvent( TEvent aEvent, TInt aSimIndex )
|
|
661 |
{
|
|
662 |
CContactLink* link = NULL;
|
|
663 |
TRAPD( result,
|
|
664 |
{
|
|
665 |
link = CContactLink::NewLC( *this, aSimIndex );
|
|
666 |
CleanupStack::Pop( link );
|
|
667 |
});
|
|
668 |
if ( result != KErrNone )
|
|
669 |
{
|
|
670 |
// First param not used in StoreError()
|
|
671 |
StoreError( *iNativeStore, result );
|
|
672 |
return;
|
|
673 |
}
|
|
674 |
|
|
675 |
switch ( aEvent )
|
|
676 |
{
|
|
677 |
case EContactAdded:
|
|
678 |
{
|
|
679 |
TVPbkContactStoreEvent event(TVPbkContactStoreEvent::EContactAdded, link);
|
|
680 |
VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
|
|
681 |
&MVPbkContactStoreObserver::HandleStoreEventL, *this, event);
|
|
682 |
break;
|
|
683 |
}
|
|
684 |
case EContactDeleted:
|
|
685 |
{
|
|
686 |
TVPbkContactStoreEvent event(TVPbkContactStoreEvent::EContactDeleted, link);
|
|
687 |
VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
|
|
688 |
&MVPbkContactStoreObserver::HandleStoreEventL, *this, event);
|
|
689 |
break;
|
|
690 |
}
|
|
691 |
case EContactChanged:
|
|
692 |
{
|
|
693 |
TVPbkContactStoreEvent event(TVPbkContactStoreEvent::EContactChanged, link);
|
|
694 |
VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
|
|
695 |
&MVPbkContactStoreObserver::HandleStoreEventL, *this, event);
|
|
696 |
break;
|
|
697 |
}
|
|
698 |
default:
|
|
699 |
{
|
|
700 |
__ASSERT_DEBUG( EFalse,
|
|
701 |
VPbkSimStore::Panic( VPbkSimStore::EUnknownSimStoreEvent ) );
|
|
702 |
VPbkSimStoreImpl::SendObserverMessageRV( iStoreObservers,
|
|
703 |
&MVPbkContactStoreObserver::StoreUnavailable, *this,
|
|
704 |
KErrUnknown );
|
|
705 |
break;
|
|
706 |
}
|
|
707 |
}
|
|
708 |
|
|
709 |
delete link;
|
|
710 |
}
|
|
711 |
|
|
712 |
// -----------------------------------------------------------------------------
|
|
713 |
// CContactStore::DoOpenL
|
|
714 |
// -----------------------------------------------------------------------------
|
|
715 |
//
|
|
716 |
void CContactStore::DoOpenL( MVPbkContactStoreObserver& aObserver )
|
|
717 |
{
|
|
718 |
if ( iStoreState == EStoreOpen )
|
|
719 |
{
|
|
720 |
aObserver.StoreReady( *this );
|
|
721 |
}
|
|
722 |
else
|
|
723 |
{
|
|
724 |
aObserver.StoreUnavailable( *this, KErrNotSupported );
|
|
725 |
}
|
|
726 |
}
|
|
727 |
|
|
728 |
// -----------------------------------------------------------------------------
|
|
729 |
// CContactStore::DoOpenError
|
|
730 |
// -----------------------------------------------------------------------------
|
|
731 |
//
|
|
732 |
void CContactStore::DoOpenError( MVPbkContactStoreObserver& aObserver,
|
|
733 |
TInt aError )
|
|
734 |
{
|
|
735 |
aObserver.StoreUnavailable( *this, aError );
|
|
736 |
}
|
|
737 |
|
|
738 |
// -----------------------------------------------------------------------------
|
|
739 |
// CContactStore::SetStaticProperties
|
|
740 |
// -----------------------------------------------------------------------------
|
|
741 |
//
|
|
742 |
void CContactStore::SetStaticProperties( TVPbkGsmStoreProperty& aProperties )
|
|
743 |
{
|
|
744 |
// SIM resides in device -> local store
|
|
745 |
iProperties->SetBooleanProperty(
|
|
746 |
CVPbkContactStoreProperties::EPropertyLocal, ETrue );
|
|
747 |
// In some devices SIM can be also removed from the device run time
|
|
748 |
// -> removable store
|
|
749 |
iProperties->SetBooleanProperty(
|
|
750 |
CVPbkContactStoreProperties::EPropertyRemovable, ETrue );
|
|
751 |
// If client changes the SIM store the changes are saved persistently
|
|
752 |
// -> persistent store.
|
|
753 |
iProperties->SetBooleanProperty(
|
|
754 |
CVPbkContactStoreProperties::EPropertyPersistent, ETrue );
|
|
755 |
|
|
756 |
if ( !( aProperties.iCaps & VPbkSimStoreImpl::KWriteAccess ) )
|
|
757 |
{
|
|
758 |
iProperties->SetBooleanProperty(
|
|
759 |
CVPbkContactStoreProperties::EPropertyReadOnly, ETrue );
|
|
760 |
}
|
|
761 |
}
|
|
762 |
|
|
763 |
// --------------------------------------------------------------------------
|
|
764 |
// CContactStore::ContactStoreDomainFsSession
|
|
765 |
// --------------------------------------------------------------------------
|
|
766 |
//
|
|
767 |
RFs& CContactStore::ContactStoreDomainFsSession()
|
|
768 |
{
|
|
769 |
return iStoreDomain.FsSession();
|
|
770 |
}
|
|
771 |
|
|
772 |
} // namespace VPbkSimStore
|
|
773 |
|