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: A contact adapter between VPbk framework and VPbkSimStoreImpl
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDES
|
|
20 |
#include "CContact.h"
|
|
21 |
|
|
22 |
#include "CContactStore.h"
|
|
23 |
#include "CFieldTypeMappings.h"
|
|
24 |
#include "CViewContact.h"
|
|
25 |
#include "MVPbkContactObserver.h"
|
|
26 |
#include "CSupportedFieldTypes.h"
|
|
27 |
#include "CContactOperationCallback.h"
|
|
28 |
#include "VPbkSimStoreError.h"
|
|
29 |
|
|
30 |
#include <CVPbkAsyncOperation.h>
|
|
31 |
#include <CVPbkContactLinkArray.h>
|
|
32 |
#include <CVPbkSimContact.h>
|
|
33 |
#include <CVPbkSimCntField.h>
|
|
34 |
#include <featmgr.h>
|
|
35 |
#include <MVPbkSimCntStore.h>
|
|
36 |
#include <MVPbkContactViewBase.h>
|
|
37 |
#include <MVPbkContactStoreProperties.h>
|
|
38 |
#include <RVPbkStreamedIntArray.h>
|
|
39 |
#include <TVPbkSimStoreProperty.h>
|
|
40 |
#include <VPbkSimCntFieldTypes.hrh>
|
|
41 |
#include <MVPbkSimStoreOperation.h>
|
|
42 |
#include <VPbkError.h>
|
|
43 |
#include <MVPbkStoreContactProperties.h>
|
|
44 |
|
|
45 |
namespace {
|
|
46 |
|
|
47 |
// MODULE DATA STRUCTURES
|
|
48 |
enum TContactFlags
|
|
49 |
{
|
|
50 |
KNewContact = 1
|
|
51 |
};
|
|
52 |
|
|
53 |
const TInt KDefinedAnrFieldTypeCount = 3; // count of defined additional number types
|
|
54 |
|
|
55 |
// ============================= LOCAL FUNCTIONS ===============================
|
|
56 |
|
|
57 |
MVPbkContactObserver::TContactOp ConvertContactOperation(
|
|
58 |
MVPbkSimContactObserver::TEvent aEvent )
|
|
59 |
{
|
|
60 |
MVPbkContactObserver::TContactOp op =
|
|
61 |
MVPbkContactObserver::EContactOperationUnknown;
|
|
62 |
switch ( aEvent )
|
|
63 |
{
|
|
64 |
case MVPbkSimContactObserver::EDelete:
|
|
65 |
{
|
|
66 |
op = MVPbkContactObserver::EContactDelete;
|
|
67 |
break;
|
|
68 |
}
|
|
69 |
case MVPbkSimContactObserver::ESave:
|
|
70 |
{
|
|
71 |
op = MVPbkContactObserver::EContactCommit;
|
|
72 |
break;
|
|
73 |
}
|
|
74 |
default:
|
|
75 |
{
|
|
76 |
op = MVPbkContactObserver::EContactOperationUnknown;
|
|
77 |
break;
|
|
78 |
}
|
|
79 |
}
|
|
80 |
return op;
|
|
81 |
}
|
|
82 |
|
|
83 |
TInt MaxNumberOfFieldsInContact( TVPbkSimCntFieldType aType,
|
|
84 |
TVPbkUSimStoreProperty& aUsimProp )
|
|
85 |
{
|
|
86 |
TInt result = 0;
|
|
87 |
switch ( aType )
|
|
88 |
{
|
|
89 |
case EVPbkSimReading: // FALLTHROUGH
|
|
90 |
case EVPbkSimNickName: // FALLTHROUGH
|
|
91 |
case EVPbkSimName:
|
|
92 |
{
|
|
93 |
++result; // only one name field can exist
|
|
94 |
break;
|
|
95 |
}
|
|
96 |
case EVPbkSimEMailAddress:
|
|
97 |
{
|
|
98 |
if (aUsimProp.iMaxNumOfEmails != KVPbkSimStorePropertyUndefined)
|
|
99 |
{
|
|
100 |
result = aUsimProp.iMaxNumOfEmails;
|
|
101 |
}
|
|
102 |
break;
|
|
103 |
}
|
|
104 |
case EVPbkSimGsmNumber: // FALLTHROUGH
|
|
105 |
case EVPbkSimAdditionalNumberLast: // the EVPbkSimAdditionalNumber
|
|
106 |
{
|
|
107 |
++result; // always at least one number
|
|
108 |
if ( aUsimProp.iMaxNumOfAnrs != KVPbkSimStorePropertyUndefined )
|
|
109 |
{
|
|
110 |
if ( !FeatureManager::FeatureSupported(
|
|
111 |
KFeatureIdFfTdClmcontactreplicationfromphonebooktousimcard ) )
|
|
112 |
{
|
|
113 |
result += aUsimProp.iMaxNumOfAnrs;
|
|
114 |
}
|
|
115 |
else
|
|
116 |
{
|
|
117 |
if ( aUsimProp.iMaxNumOfAnrs - KDefinedAnrFieldTypeCount > 0 )
|
|
118 |
{
|
|
119 |
result += (aUsimProp.iMaxNumOfAnrs - KDefinedAnrFieldTypeCount);
|
|
120 |
}
|
|
121 |
}
|
|
122 |
}
|
|
123 |
break;
|
|
124 |
}
|
|
125 |
case EVPbkSimAdditionalNumber1:
|
|
126 |
result = aUsimProp.iMaxNumOfAnrs >= 1 ? 1 : 0; // according the max number of anrs.
|
|
127 |
break;
|
|
128 |
case EVPbkSimAdditionalNumber2:
|
|
129 |
result = aUsimProp.iMaxNumOfAnrs >= 2 ? 1 : 0;
|
|
130 |
break;
|
|
131 |
case EVPbkSimAdditionalNumber3:
|
|
132 |
result = aUsimProp.iMaxNumOfAnrs >= 3 ? 1 : 0;
|
|
133 |
break;
|
|
134 |
default:
|
|
135 |
{
|
|
136 |
// Do nothing
|
|
137 |
break;
|
|
138 |
}
|
|
139 |
}
|
|
140 |
return result;
|
|
141 |
}
|
|
142 |
}
|
|
143 |
|
|
144 |
namespace VPbkSimStore {
|
|
145 |
|
|
146 |
_LIT( KEmptyData, "+" ); //the empty data, modifiy this string to keep its a special string.
|
|
147 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
148 |
|
|
149 |
// -----------------------------------------------------------------------------
|
|
150 |
// CContact::CContact
|
|
151 |
// C++ default constructor can NOT contain any code, that
|
|
152 |
// might leave.
|
|
153 |
// -----------------------------------------------------------------------------
|
|
154 |
//
|
|
155 |
inline CContact::CContact( CContactStore& aParentStore )
|
|
156 |
: iParentStore( aParentStore )
|
|
157 |
{
|
|
158 |
}
|
|
159 |
|
|
160 |
// -----------------------------------------------------------------------------
|
|
161 |
// CContact::ConstructL
|
|
162 |
// Symbian 2nd phase constructor can leave.
|
|
163 |
// -----------------------------------------------------------------------------
|
|
164 |
//
|
|
165 |
inline void CContact::ConstructL( CVPbkSimContact& aSimContact,
|
|
166 |
TBool aIsNewContact )
|
|
167 |
{
|
|
168 |
if ( aIsNewContact )
|
|
169 |
{
|
|
170 |
iFlags.Set( KNewContact );
|
|
171 |
}
|
|
172 |
if( FeatureManager::FeatureSupported(
|
|
173 |
KFeatureIdFfTdClmcontactreplicationfromphonebooktousimcard ) )
|
|
174 |
{
|
|
175 |
RemoveAllEmptyFields( aSimContact ); // remove the empty contacts where added before save.
|
|
176 |
}
|
|
177 |
iFields.SetContact( *this, aSimContact );
|
|
178 |
iAsyncOp = new( ELeave ) VPbkEngUtils::CVPbkAsyncOperation;
|
|
179 |
}
|
|
180 |
|
|
181 |
// -----------------------------------------------------------------------------
|
|
182 |
// CContact::NewL
|
|
183 |
// Two-phased constructor.
|
|
184 |
// -----------------------------------------------------------------------------
|
|
185 |
//
|
|
186 |
CContact* CContact::NewL( CContactStore& aParentStore,
|
|
187 |
CVPbkSimContact* aSimContact, TBool aIsNewContact )
|
|
188 |
{
|
|
189 |
CContact* self = new ( ELeave ) CContact( aParentStore );
|
|
190 |
CleanupStack::PushL(self);
|
|
191 |
self->ConstructL( *aSimContact, aIsNewContact );
|
|
192 |
CleanupStack::Pop( self );
|
|
193 |
// Take ownership after construction
|
|
194 |
self->iSimContact = aSimContact;
|
|
195 |
return self;
|
|
196 |
}
|
|
197 |
|
|
198 |
// Destructor
|
|
199 |
CContact::~CContact()
|
|
200 |
{
|
|
201 |
delete iStoreOperation;
|
|
202 |
delete iAsyncOp;
|
|
203 |
delete iSimContact;
|
|
204 |
}
|
|
205 |
|
|
206 |
// -----------------------------------------------------------------------------
|
|
207 |
// CContact::RemoveAllEmptyFields
|
|
208 |
// -----------------------------------------------------------------------------
|
|
209 |
//
|
|
210 |
void CContact::RemoveAllEmptyFields( CVPbkSimContact& aSimContact )
|
|
211 |
{
|
|
212 |
TInt i = aSimContact.FieldCount() - 1 ;
|
|
213 |
while( i >= 0 )
|
|
214 |
{
|
|
215 |
CVPbkSimCntField& cntField = aSimContact.FieldAt( i );
|
|
216 |
TVPbkSimCntFieldType simCntType = cntField.Type();
|
|
217 |
if( simCntType == EVPbkSimGsmNumber
|
|
218 |
|| simCntType == EVPbkSimAdditionalNumber1
|
|
219 |
|| simCntType == EVPbkSimAdditionalNumber2
|
|
220 |
|| simCntType == EVPbkSimAdditionalNumber3
|
|
221 |
|| simCntType == EVPbkSimAdditionalNumberLast )
|
|
222 |
{
|
|
223 |
if( cntField. Data().Compare( KEmptyData ) == 0 )
|
|
224 |
{
|
|
225 |
aSimContact.DeleteField( i );
|
|
226 |
}
|
|
227 |
}
|
|
228 |
i --;
|
|
229 |
}
|
|
230 |
}
|
|
231 |
|
|
232 |
// -----------------------------------------------------------------------------
|
|
233 |
// CContact::FillWithEmptyFieldsL
|
|
234 |
// -----------------------------------------------------------------------------
|
|
235 |
//
|
|
236 |
void CContact::FillWithEmptyFieldsL() const
|
|
237 |
{
|
|
238 |
RPointerArray<CVPbkSimCntField> & contactFieldArray = iSimContact->FieldArray();
|
|
239 |
TInt i = contactFieldArray.Count() - 1 ;
|
|
240 |
while( i >= 0 ) // remove all empty content.
|
|
241 |
{
|
|
242 |
CVPbkSimCntField& cntField = iSimContact->FieldAt( i );
|
|
243 |
TVPbkSimCntFieldType type = cntField.Type();
|
|
244 |
if( cntField. Data().Length() == 0 )
|
|
245 |
{
|
|
246 |
iSimContact->DeleteField( i );
|
|
247 |
}
|
|
248 |
i --;
|
|
249 |
}
|
|
250 |
|
|
251 |
if( contactFieldArray.Count() == 0 ) // no un-empty fields.
|
|
252 |
{
|
|
253 |
return;
|
|
254 |
}
|
|
255 |
CVPbkSimContact::TFieldLookup lookupAdnNumber =
|
|
256 |
iSimContact->FindField( EVPbkSimAdditionalNumber );
|
|
257 |
if( lookupAdnNumber.EndOfLookup()) // if there is no additional number in the contact then no need to add placeholder
|
|
258 |
{
|
|
259 |
return;
|
|
260 |
}
|
|
261 |
RPointerArray<CVPbkSimCntField> tempFieldArray;
|
|
262 |
CleanupClosePushL( tempFieldArray );
|
|
263 |
// mappings
|
|
264 |
CFieldTypeMappings & mappings = iParentStore.FieldTypeMappings();
|
|
265 |
// supported types.
|
|
266 |
const CSupportedFieldTypes& supportedTypes = iParentStore.SupportedFieldTypes();
|
|
267 |
|
|
268 |
// check all supported field types in the fields list. If not exist created new.
|
|
269 |
// if data length is 0, set data to empty data.
|
|
270 |
for( int i = 0; i < supportedTypes.FieldTypeCount(); i ++ )
|
|
271 |
{
|
|
272 |
const MVPbkFieldType& fieldType = supportedTypes.FieldTypeAt( i );
|
|
273 |
TVPbkSimCntFieldType simCntType = mappings.Match( fieldType );
|
|
274 |
if( simCntType == EVPbkSimGsmNumber
|
|
275 |
|| simCntType == EVPbkSimAdditionalNumber1
|
|
276 |
|| simCntType == EVPbkSimAdditionalNumber2
|
|
277 |
|| simCntType == EVPbkSimAdditionalNumber3
|
|
278 |
|| simCntType == EVPbkSimAdditionalNumberLast )
|
|
279 |
{
|
|
280 |
CVPbkSimCntField * field = NULL;
|
|
281 |
CVPbkSimContact::TFieldLookup lookup =
|
|
282 |
iSimContact->FindField( simCntType );
|
|
283 |
|
|
284 |
if( lookup.EndOfLookup() )
|
|
285 |
{
|
|
286 |
field= iSimContact->CreateFieldLC( simCntType );
|
|
287 |
field->SetDataL( KEmptyData );
|
|
288 |
tempFieldArray.Append( field );
|
|
289 |
CleanupStack::Pop();
|
|
290 |
}
|
|
291 |
else
|
|
292 |
{
|
|
293 |
field = contactFieldArray[lookup.Index()];
|
|
294 |
if( field->Data().Length() == 0 )
|
|
295 |
{
|
|
296 |
field->SetDataL( KEmptyData );
|
|
297 |
}
|
|
298 |
if( simCntType == EVPbkSimAdditionalNumber1
|
|
299 |
|| simCntType == EVPbkSimAdditionalNumber2
|
|
300 |
|| simCntType == EVPbkSimAdditionalNumber3 )
|
|
301 |
{
|
|
302 |
contactFieldArray.Remove( lookup.Index() );
|
|
303 |
tempFieldArray.AppendL( field );
|
|
304 |
}
|
|
305 |
}
|
|
306 |
}
|
|
307 |
}
|
|
308 |
TInt j = contactFieldArray.Count() - 1;
|
|
309 |
while( j >= 0 ) // EVPbkSimAdditionalNumberLast type field will append at last.
|
|
310 |
{
|
|
311 |
if( contactFieldArray[j]->Type() == EVPbkSimAdditionalNumberLast )
|
|
312 |
{
|
|
313 |
tempFieldArray.AppendL( contactFieldArray[ j ] );
|
|
314 |
contactFieldArray.Remove( j );
|
|
315 |
}
|
|
316 |
j --;
|
|
317 |
}
|
|
318 |
for( int i = 0; i < tempFieldArray.Count(); i ++ )
|
|
319 |
{
|
|
320 |
contactFieldArray.AppendL( tempFieldArray[i]);
|
|
321 |
}
|
|
322 |
tempFieldArray.Reset();
|
|
323 |
CleanupStack::Pop();
|
|
324 |
}
|
|
325 |
|
|
326 |
// -----------------------------------------------------------------------------
|
|
327 |
// CContact::ParentObject
|
|
328 |
// -----------------------------------------------------------------------------
|
|
329 |
//
|
|
330 |
MVPbkObjectHierarchy& CContact::ParentObject() const
|
|
331 |
{
|
|
332 |
return iParentStore;
|
|
333 |
}
|
|
334 |
|
|
335 |
// -----------------------------------------------------------------------------
|
|
336 |
// CContact::ConstFields
|
|
337 |
// -----------------------------------------------------------------------------
|
|
338 |
//
|
|
339 |
const MVPbkStoreContactFieldCollection& CContact::Fields() const
|
|
340 |
{
|
|
341 |
return iFields;
|
|
342 |
}
|
|
343 |
|
|
344 |
// -----------------------------------------------------------------------------
|
|
345 |
// CContact::IsSame
|
|
346 |
// -----------------------------------------------------------------------------
|
|
347 |
//
|
|
348 |
TBool CContact::IsSame( const MVPbkStoreContact& aOtherContact ) const
|
|
349 |
{
|
|
350 |
if ( &ParentStore() == &aOtherContact.ParentStore() )
|
|
351 |
{
|
|
352 |
const CContact& otherCnt = static_cast<const CContact&>( aOtherContact );
|
|
353 |
return otherCnt.SimContact().SimIndex() == iSimContact->SimIndex();
|
|
354 |
}
|
|
355 |
return EFalse;
|
|
356 |
}
|
|
357 |
|
|
358 |
// -----------------------------------------------------------------------------
|
|
359 |
// CContact::CreateLinkLC
|
|
360 |
// -----------------------------------------------------------------------------
|
|
361 |
//
|
|
362 |
MVPbkContactLink* CContact::CreateLinkLC() const
|
|
363 |
{
|
|
364 |
return iParentStore.CreateLinkLC( iSimContact->SimIndex() );
|
|
365 |
}
|
|
366 |
|
|
367 |
// -----------------------------------------------------------------------------
|
|
368 |
// CContact::DeleteL
|
|
369 |
// -----------------------------------------------------------------------------
|
|
370 |
//
|
|
371 |
void CContact::DeleteL( MVPbkContactObserver& aObserver ) const
|
|
372 |
{
|
|
373 |
if ( iStoreOperation )
|
|
374 |
{
|
|
375 |
User::Leave( KErrInUse );
|
|
376 |
}
|
|
377 |
|
|
378 |
// From the client point of view the MVPbkStoreContact is constant but
|
|
379 |
// implementation needs a non const contact.
|
|
380 |
RVPbkStreamedIntArray indexArray;
|
|
381 |
CleanupClosePushL( indexArray );
|
|
382 |
indexArray.AppendIntL(iSimContact->SimIndex() );
|
|
383 |
iStoreOperation = iParentStore.NativeStore().DeleteL( indexArray,
|
|
384 |
const_cast<CContact&>(*this));
|
|
385 |
iObserver = &aObserver;
|
|
386 |
CleanupStack::PopAndDestroy(); // indexArray
|
|
387 |
}
|
|
388 |
|
|
389 |
// -----------------------------------------------------------------------------
|
|
390 |
// CContact::MatchContactStore
|
|
391 |
// -----------------------------------------------------------------------------
|
|
392 |
//
|
|
393 |
TBool CContact::MatchContactStore(const TDesC& aContactStoreUri) const
|
|
394 |
{
|
|
395 |
return iParentStore.MatchContactStore(aContactStoreUri);
|
|
396 |
}
|
|
397 |
|
|
398 |
// -----------------------------------------------------------------------------
|
|
399 |
// CContact::MatchContactStoreDomain
|
|
400 |
// -----------------------------------------------------------------------------
|
|
401 |
//
|
|
402 |
TBool CContact::MatchContactStoreDomain(const TDesC& aContactStoreDomain) const
|
|
403 |
{
|
|
404 |
return iParentStore.MatchContactStoreDomain(aContactStoreDomain);
|
|
405 |
}
|
|
406 |
|
|
407 |
// -----------------------------------------------------------------------------
|
|
408 |
// CContact::CreateBookmarkLC
|
|
409 |
// -----------------------------------------------------------------------------
|
|
410 |
//
|
|
411 |
MVPbkContactBookmark* CContact::CreateBookmarkLC() const
|
|
412 |
{
|
|
413 |
return iParentStore.CreateBookmarkLC( iSimContact->SimIndex() );
|
|
414 |
}
|
|
415 |
|
|
416 |
// -----------------------------------------------------------------------------
|
|
417 |
// CContact::ParentStore
|
|
418 |
// -----------------------------------------------------------------------------
|
|
419 |
//
|
|
420 |
MVPbkContactStore& CContact::ParentStore() const
|
|
421 |
{
|
|
422 |
return iParentStore;
|
|
423 |
}
|
|
424 |
|
|
425 |
// -----------------------------------------------------------------------------
|
|
426 |
// CContact::Fields
|
|
427 |
// -----------------------------------------------------------------------------
|
|
428 |
//
|
|
429 |
MVPbkStoreContactFieldCollection& CContact::Fields()
|
|
430 |
{
|
|
431 |
return iFields;
|
|
432 |
}
|
|
433 |
|
|
434 |
// -----------------------------------------------------------------------------
|
|
435 |
// CContact::CreateFieldLC
|
|
436 |
// -----------------------------------------------------------------------------
|
|
437 |
//
|
|
438 |
MVPbkStoreContactField* CContact::CreateFieldLC(
|
|
439 |
const MVPbkFieldType& aFieldType ) const
|
|
440 |
{
|
|
441 |
if ( !iParentStore.SupportedFieldTypes().ContainsSame( aFieldType ) )
|
|
442 |
{
|
|
443 |
// According to contact API the function must leave if
|
|
444 |
// the type is invalid
|
|
445 |
User::Leave( KErrNotSupported );
|
|
446 |
}
|
|
447 |
TVPbkSimCntFieldType simType =
|
|
448 |
iParentStore.FieldTypeMappings().Match( aFieldType );
|
|
449 |
|
|
450 |
__ASSERT_DEBUG( simType != EVPbkSimUnknownType,
|
|
451 |
VPbkSimStore::Panic( ESimFieldTypeNotFound ) );
|
|
452 |
|
|
453 |
if ( simType == EVPbkSimGsmNumber ||
|
|
454 |
simType == EVPbkSimAdditionalNumberLast ) //the same field type as EVPbkSimGsmNumber
|
|
455 |
{
|
|
456 |
// EVPbkSimGsmNumber and EVPbkSimAdditionalNumber maps to same
|
|
457 |
// VPbk field type. A sim contact can have only one EVPbkSimGsmNumber
|
|
458 |
// field type and possibly many EVPbkSimAdditionalNumber types
|
|
459 |
// depending on the USIM store.
|
|
460 |
// However, if SIM card doesn't support additional number it is allowed
|
|
461 |
// to create as many EVPbkSimGsmNumber fields as client wants. This
|
|
462 |
// is needed to enable temporary contacts that holds multiple numbers.
|
|
463 |
CVPbkSimContact::TFieldLookup lookup =
|
|
464 |
iSimContact->FindField( EVPbkSimGsmNumber );
|
|
465 |
if ( lookup.EndOfLookup() ||
|
|
466 |
!( iParentStore.SimStoreCapabilities() &
|
|
467 |
VPbkSimStoreImpl::KAdditionalNumUsed ))
|
|
468 |
{
|
|
469 |
simType = EVPbkSimGsmNumber;
|
|
470 |
}
|
|
471 |
else
|
|
472 |
{
|
|
473 |
simType = EVPbkSimAdditionalNumberLast;
|
|
474 |
}
|
|
475 |
}
|
|
476 |
|
|
477 |
CVPbkSimCntField* field = iSimContact->CreateFieldLC( simType );
|
|
478 |
TContactNewField* fieldWrapper = new( ELeave ) TContactNewField( field );
|
|
479 |
fieldWrapper->SetParentContact( const_cast<CContact&>( *this ) );
|
|
480 |
CleanupStack::Pop( field );
|
|
481 |
CleanupDeletePushL( fieldWrapper );
|
|
482 |
return fieldWrapper;
|
|
483 |
}
|
|
484 |
|
|
485 |
// -----------------------------------------------------------------------------
|
|
486 |
// CContact::AddFieldL
|
|
487 |
// -----------------------------------------------------------------------------
|
|
488 |
//
|
|
489 |
TInt CContact::AddFieldL( MVPbkStoreContactField* aField )
|
|
490 |
{
|
|
491 |
__ASSERT_ALWAYS( aField, VPbkError::Panic( VPbkError::ENullContactField ) );
|
|
492 |
// Test that the client gives this contact's field and doesn't pass
|
|
493 |
// an existing field of this contact as a new one
|
|
494 |
__ASSERT_ALWAYS( &aField->ParentContact() == this &&
|
|
495 |
aField != iFields.FieldPointer(),
|
|
496 |
VPbkError::Panic( VPbkError::EInvalidContactField ) );
|
|
497 |
|
|
498 |
// Now the wrapper is casted back
|
|
499 |
TContactNewField* fieldWrapper = static_cast<TContactNewField*>( aField );
|
|
500 |
// Takes ownership of the field from the wrapper
|
|
501 |
CVPbkSimCntField* field = fieldWrapper->SimField();
|
|
502 |
CleanupStack::PushL( field );
|
|
503 |
// Add sim field to sim contact. Contact owns the field now.
|
|
504 |
iSimContact->AddFieldL( field );
|
|
505 |
CleanupStack::Pop( field );
|
|
506 |
// After this the function must not leave because client has created
|
|
507 |
// the fieldWrapper with CreateFieldLC and it's in the CleanupStack
|
|
508 |
// Client pops the fieldWrapper after this function
|
|
509 |
delete fieldWrapper;
|
|
510 |
// The field is appended to the array -> return the last field index.
|
|
511 |
return iSimContact->FieldCount() - 1;
|
|
512 |
}
|
|
513 |
|
|
514 |
// -----------------------------------------------------------------------------
|
|
515 |
// CContact::RemoveField
|
|
516 |
// -----------------------------------------------------------------------------
|
|
517 |
//
|
|
518 |
void CContact::RemoveField( TInt aIndex )
|
|
519 |
{
|
|
520 |
__ASSERT_ALWAYS( aIndex >= 0 && aIndex < iFields.FieldCount(),
|
|
521 |
VPbkError::Panic(VPbkError::EInvalidFieldIndex) );
|
|
522 |
__ASSERT_ALWAYS( !iParentStore.StoreProperties().ReadOnly(),
|
|
523 |
VPbkError::Panic(VPbkError::EInvalidAccessToReadOnlyContact ) );
|
|
524 |
|
|
525 |
iSimContact->DeleteField( aIndex );
|
|
526 |
}
|
|
527 |
|
|
528 |
// -----------------------------------------------------------------------------
|
|
529 |
// CContact::RemoveAllFields
|
|
530 |
// -----------------------------------------------------------------------------
|
|
531 |
//
|
|
532 |
void CContact::RemoveAllFields()
|
|
533 |
{
|
|
534 |
__ASSERT_ALWAYS( !iParentStore.StoreProperties().ReadOnly(),
|
|
535 |
VPbkError::Panic(VPbkError::EInvalidAccessToReadOnlyContact ) );
|
|
536 |
|
|
537 |
iSimContact->DeleteAllFields();
|
|
538 |
}
|
|
539 |
|
|
540 |
// -----------------------------------------------------------------------------
|
|
541 |
// CContact::LockL
|
|
542 |
// -----------------------------------------------------------------------------
|
|
543 |
//
|
|
544 |
void CContact::LockL( MVPbkContactObserver& aObserver ) const
|
|
545 |
{
|
|
546 |
MVPbkContactObserver::TContactOpResult opResult;
|
|
547 |
opResult.iExtension = NULL;
|
|
548 |
opResult.iOpCode = MVPbkContactObserver::EContactLock;
|
|
549 |
opResult.iStoreContact = NULL;
|
|
550 |
|
|
551 |
CContactOperationCallback* callBack =
|
|
552 |
new( ELeave ) CContactOperationCallback( opResult, aObserver,
|
|
553 |
KErrNone );
|
|
554 |
CleanupStack::PushL( callBack );
|
|
555 |
iAsyncOp->CallbackL( callBack );
|
|
556 |
CleanupStack::Pop( callBack );
|
|
557 |
iLocked = ETrue;
|
|
558 |
}
|
|
559 |
|
|
560 |
// -----------------------------------------------------------------------------
|
|
561 |
// CContact::CommitL
|
|
562 |
// -----------------------------------------------------------------------------
|
|
563 |
//
|
|
564 |
void CContact::CommitL( MVPbkContactObserver& aObserver ) const
|
|
565 |
{
|
|
566 |
if ( iLocked || iFlags.IsSet( KNewContact ))
|
|
567 |
{
|
|
568 |
if ( iStoreOperation )
|
|
569 |
{
|
|
570 |
User::Leave( KErrInUse );
|
|
571 |
}
|
|
572 |
// From the client point of view the MVPbkStoreContact is constant but
|
|
573 |
// implementation needs a non const contact.
|
|
574 |
if( FeatureManager::FeatureSupported( KFeatureIdFfTdClmcontactreplicationfromphonebooktousimcard ) )
|
|
575 |
{
|
|
576 |
FillWithEmptyFieldsL();
|
|
577 |
}
|
|
578 |
iStoreOperation = iSimContact->SaveL( const_cast<CContact&>( *this ));
|
|
579 |
iObserver = &aObserver;
|
|
580 |
}
|
|
581 |
else
|
|
582 |
{
|
|
583 |
// Virtual Phonebook API demands that contact must be locked before
|
|
584 |
// CommitL. Sim Store has to behave according to that and
|
|
585 |
// complete with KErrAccessDenied.
|
|
586 |
MVPbkContactObserver::TContactOpResult opResult;
|
|
587 |
opResult.iExtension = NULL;
|
|
588 |
opResult.iOpCode = MVPbkContactObserver::EContactCommit;
|
|
589 |
opResult.iStoreContact = NULL;
|
|
590 |
CContactOperationCallback* callBack =
|
|
591 |
new( ELeave ) CContactOperationCallback(
|
|
592 |
opResult, aObserver, KErrAccessDenied );
|
|
593 |
CleanupStack::PushL( callBack );
|
|
594 |
iAsyncOp->CallbackL( callBack );
|
|
595 |
CleanupStack::Pop( callBack );
|
|
596 |
}
|
|
597 |
}
|
|
598 |
|
|
599 |
// -----------------------------------------------------------------------------
|
|
600 |
// CContact::GroupsJoinedLC
|
|
601 |
// -----------------------------------------------------------------------------
|
|
602 |
//
|
|
603 |
MVPbkContactLinkArray* CContact::GroupsJoinedLC() const
|
|
604 |
{
|
|
605 |
return CVPbkContactLinkArray::NewLC();
|
|
606 |
}
|
|
607 |
|
|
608 |
// -----------------------------------------------------------------------------
|
|
609 |
// CContact::Group
|
|
610 |
// -----------------------------------------------------------------------------
|
|
611 |
//
|
|
612 |
MVPbkContactGroup* CContact::Group()
|
|
613 |
{
|
|
614 |
return NULL;
|
|
615 |
}
|
|
616 |
|
|
617 |
// -----------------------------------------------------------------------------
|
|
618 |
// CContact::MaxNumberOfFieldL
|
|
619 |
// -----------------------------------------------------------------------------
|
|
620 |
//
|
|
621 |
TInt CContact::MaxNumberOfFieldL( const MVPbkFieldType& aType ) const
|
|
622 |
{
|
|
623 |
TInt res = 0;
|
|
624 |
TVPbkSimCntFieldType nativeType =
|
|
625 |
iParentStore.FieldTypeMappings().Match( aType );
|
|
626 |
if ( nativeType != EVPbkSimUnknownType )
|
|
627 |
{
|
|
628 |
TVPbkUSimStoreProperty usimProp;
|
|
629 |
User::LeaveIfError(iParentStore.NativeStore().GetUSimStoreProperties(
|
|
630 |
usimProp ));
|
|
631 |
res = MaxNumberOfFieldsInContact( nativeType, usimProp );
|
|
632 |
}
|
|
633 |
return res;
|
|
634 |
}
|
|
635 |
|
|
636 |
// -----------------------------------------------------------------------------
|
|
637 |
// CContact::ContactEventComplete
|
|
638 |
// -----------------------------------------------------------------------------
|
|
639 |
//
|
|
640 |
void CContact::ContactEventComplete( TEvent aEvent,
|
|
641 |
CVPbkSimContact* /*aContact*/ )
|
|
642 |
{
|
|
643 |
__ASSERT_DEBUG( iObserver, Panic(EPreCond_CContact_ContactEventComplete));
|
|
644 |
|
|
645 |
delete iStoreOperation;
|
|
646 |
iStoreOperation = NULL;
|
|
647 |
|
|
648 |
MVPbkContactObserver::TContactOpResult vpbkOpResult;
|
|
649 |
vpbkOpResult.iStoreContact = NULL;
|
|
650 |
vpbkOpResult.iExtension = NULL;
|
|
651 |
vpbkOpResult.iOpCode = ConvertContactOperation( aEvent );
|
|
652 |
|
|
653 |
MVPbkContactObserver* observer = iObserver;
|
|
654 |
ResetContactOperationState();
|
|
655 |
|
|
656 |
// remove filled placeholder fields.
|
|
657 |
if( vpbkOpResult.iOpCode == MVPbkContactObserver::EContactCommit )
|
|
658 |
{
|
|
659 |
RemoveAllEmptyFields( *iSimContact );
|
|
660 |
}
|
|
661 |
observer->ContactOperationCompleted( vpbkOpResult );
|
|
662 |
}
|
|
663 |
|
|
664 |
// -----------------------------------------------------------------------------
|
|
665 |
// CContact::ContactEventError
|
|
666 |
// -----------------------------------------------------------------------------
|
|
667 |
//
|
|
668 |
void CContact::ContactEventError( TEvent aEvent,
|
|
669 |
CVPbkSimContact* /*aContact*/, TInt aError )
|
|
670 |
{
|
|
671 |
__ASSERT_DEBUG( iObserver, Panic(EPreCond_CContact_ContactEventError));
|
|
672 |
|
|
673 |
delete iStoreOperation;
|
|
674 |
iStoreOperation = NULL;
|
|
675 |
|
|
676 |
MVPbkContactObserver* observer = iObserver;
|
|
677 |
ResetContactOperationState();
|
|
678 |
MVPbkContactObserver::TContactOp op = ConvertContactOperation( aEvent );
|
|
679 |
|
|
680 |
// remove filled placeholder fields.
|
|
681 |
if( op == MVPbkContactObserver::EContactCommit )
|
|
682 |
{
|
|
683 |
RemoveAllEmptyFields( *iSimContact );
|
|
684 |
}
|
|
685 |
observer->ContactOperationFailed( op, aError, EFalse );
|
|
686 |
}
|
|
687 |
|
|
688 |
// -----------------------------------------------------------------------------
|
|
689 |
// CContact::ResetContactOperationState
|
|
690 |
// -----------------------------------------------------------------------------
|
|
691 |
//
|
|
692 |
void CContact::ResetContactOperationState()
|
|
693 |
{
|
|
694 |
iObserver = NULL;
|
|
695 |
}
|
|
696 |
|
|
697 |
TAny* CContact::StoreContactExtension(TUid aExtensionUid)
|
|
698 |
{
|
|
699 |
|
|
700 |
if( aExtensionUid == KMVPbkStoreContactExtension2Uid )
|
|
701 |
return static_cast<MVPbkStoreContact2*>( this );
|
|
702 |
return NULL;
|
|
703 |
}
|
|
704 |
|
|
705 |
|
|
706 |
|
|
707 |
MVPbkStoreContactProperties* CContact::PropertiesL() const
|
|
708 |
{
|
|
709 |
//sim store doesn't support any of MVPbkStoreContactProperties functions
|
|
710 |
return NULL;
|
|
711 |
}
|
|
712 |
|
|
713 |
void CContact::SetAsOwnL( MVPbkContactObserver& /*aObserver*/ ) const
|
|
714 |
{
|
|
715 |
// own link is not supported in sim store
|
|
716 |
User::Leave( KErrNotSupported );
|
|
717 |
}
|
|
718 |
|
|
719 |
} // namespace VPbkSimStore
|
|
720 |
|
|
721 |
// end of file
|
|
722 |
|