63
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-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: An operation for importing and updating contacts to the store
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "CVPbkImportToContactsMergeOperation.h"
|
|
20 |
#include "VPbkVCardEngError.h"
|
|
21 |
#include "CVPbkVCardImporter.h"
|
|
22 |
#include "CVPbkDefaultAttribute.h"
|
|
23 |
#include "CVPbkLocalVariationManager.h"
|
|
24 |
|
|
25 |
// Virtual Phonebook
|
|
26 |
#include <MVPbkStoreContact.h>
|
|
27 |
#include <MVPbkContactStore.h>
|
|
28 |
#include <MVPbkContactLink.h>
|
|
29 |
#include <CVPbkVCardEng.h>
|
|
30 |
#include <CVPbkContactManager.h>
|
|
31 |
#include <MVPbkFieldType.h>
|
|
32 |
#include <MVPbkContactFieldData.h>
|
|
33 |
#include <MVPbkContactFieldUriData.h>
|
|
34 |
#include <MVPbkContactFieldTextData.h>
|
|
35 |
#include <MVPbkSingleContactOperationObserver.h>
|
|
36 |
const TInt KGranularity = 4;
|
|
37 |
|
|
38 |
namespace{
|
|
39 |
#ifdef _DEBUG
|
|
40 |
|
|
41 |
enum TPanic
|
|
42 |
{
|
|
43 |
EPanicInvalidState = 1,
|
|
44 |
EPanicInvalidToRetrieve,
|
|
45 |
EPanicInvalidToLock,
|
|
46 |
EPanicInvalidToCommit,
|
|
47 |
EPanicInvalidToUpdate,
|
|
48 |
};
|
|
49 |
|
|
50 |
void Panic(TPanic aPanic)
|
|
51 |
{
|
|
52 |
_LIT(KPanicCat, "CVPbkImportToContactsMergeOperation");
|
|
53 |
User::Panic(KPanicCat, aPanic);
|
|
54 |
}
|
|
55 |
|
|
56 |
#endif // _DEBUG
|
|
57 |
} //namespace
|
|
58 |
|
|
59 |
// ---------------------------------------------------------------------------
|
|
60 |
// CVPbkImportToContactsMergeOperation::CVPbkImportToContactsMergeOperation
|
|
61 |
// ---------------------------------------------------------------------------
|
|
62 |
//
|
|
63 |
CVPbkImportToContactsMergeOperation::CVPbkImportToContactsMergeOperation(
|
|
64 |
const MVPbkContactLink& aReplaceContact,
|
|
65 |
MVPbkSingleContactOperationObserver& aObserver,
|
|
66 |
MVPbkContactStore& aTargetStore,
|
|
67 |
CVPbkVCardData& aData
|
|
68 |
)
|
|
69 |
: CActive( EPriorityStandard ),
|
|
70 |
iState ( EImport ),
|
|
71 |
iTargetStore( aTargetStore ),
|
|
72 |
iReplaceContact( aReplaceContact ),
|
|
73 |
iObserver( aObserver ),
|
|
74 |
iData(aData)
|
|
75 |
{
|
|
76 |
CActiveScheduler::Add(this);
|
|
77 |
iGroupcardHandler = NULL;
|
|
78 |
iOperationImpl = NULL;
|
|
79 |
iVPbkOperation = NULL;
|
|
80 |
}
|
|
81 |
|
|
82 |
|
|
83 |
// ---------------------------------------------------------------------------
|
|
84 |
// CVPbkImportToContactsMergeOperation::ConstructL
|
|
85 |
// ---------------------------------------------------------------------------
|
|
86 |
//
|
|
87 |
void CVPbkImportToContactsMergeOperation::ConstructL( TVPbkImportCardType aType, RReadStream& aSourceStream)
|
|
88 |
{
|
|
89 |
|
|
90 |
if ( aType == EVCard )
|
|
91 |
{
|
|
92 |
iOperationImpl = CVPbkVCardImporter::NewL(iImportedContacts, aSourceStream, iTargetStore, iData );
|
|
93 |
}
|
|
94 |
else
|
|
95 |
{
|
|
96 |
User::Leave( KErrArgument );
|
|
97 |
}
|
|
98 |
iGroupcardHandler = CVPbkGroupCardHandler::NewL(iData);
|
|
99 |
}
|
|
100 |
|
|
101 |
// ---------------------------------------------------------------------------
|
|
102 |
// CVPbkImportToContactsMergeOperation::NewL
|
|
103 |
// ---------------------------------------------------------------------------
|
|
104 |
//
|
|
105 |
CVPbkImportToContactsMergeOperation * CVPbkImportToContactsMergeOperation::NewL(
|
|
106 |
TVPbkImportCardType aType,
|
|
107 |
CVPbkVCardData& aData,
|
|
108 |
const MVPbkContactLink& aReplaceContact,
|
|
109 |
MVPbkContactStore& aTargetStore,
|
|
110 |
RReadStream& aSourceStream,
|
|
111 |
MVPbkSingleContactOperationObserver& aObserver )
|
|
112 |
{
|
|
113 |
CVPbkImportToContactsMergeOperation* self =
|
|
114 |
new( ELeave ) CVPbkImportToContactsMergeOperation( aReplaceContact,aObserver, aTargetStore, aData);
|
|
115 |
CleanupStack::PushL( self );
|
|
116 |
self->ConstructL( aType, aSourceStream);
|
|
117 |
CleanupStack::Pop( self );
|
|
118 |
return self;
|
|
119 |
|
|
120 |
}
|
|
121 |
|
|
122 |
|
|
123 |
// ---------------------------------------------------------------------------
|
|
124 |
// CVPbkImportToContactsMergeOperation::~CVPbkImportToContactsMergeOperation
|
|
125 |
// ---------------------------------------------------------------------------
|
|
126 |
//
|
|
127 |
CVPbkImportToContactsMergeOperation::~CVPbkImportToContactsMergeOperation()
|
|
128 |
{
|
|
129 |
|
|
130 |
if(iOperationImpl)
|
|
131 |
{
|
|
132 |
delete iOperationImpl;
|
|
133 |
iOperationImpl = NULL;
|
|
134 |
}
|
|
135 |
if (iGroupcardHandler)
|
|
136 |
{
|
|
137 |
delete iGroupcardHandler;
|
|
138 |
iGroupcardHandler = NULL;
|
|
139 |
}
|
|
140 |
if(iVPbkOperation)
|
|
141 |
delete iVPbkOperation;
|
|
142 |
if( iSetAttributeOperation )
|
|
143 |
{
|
|
144 |
delete iSetAttributeOperation;
|
|
145 |
iSetAttributeOperation = NULL;
|
|
146 |
}
|
|
147 |
if( iDefaultAttributes )
|
|
148 |
{
|
|
149 |
delete iDefaultAttributes;
|
|
150 |
iDefaultAttributes = NULL;
|
|
151 |
}
|
|
152 |
iImportedContacts.ResetAndDestroy();
|
|
153 |
|
|
154 |
CActive::Cancel();
|
|
155 |
}
|
|
156 |
|
|
157 |
void CVPbkImportToContactsMergeOperation::StartL()
|
|
158 |
{
|
|
159 |
__ASSERT_DEBUG( iOperationImpl, VPbkVCardEngError::Panic(
|
|
160 |
VPbkVCardEngError::EPreCond_CVPbkImportToStoreOperation_StartL ) );
|
|
161 |
|
|
162 |
iOperationImpl->SetObserver( *this );
|
|
163 |
iOperationImpl->StartL();
|
|
164 |
}
|
|
165 |
|
|
166 |
// ---------------------------------------------------------------------------
|
|
167 |
// From class MVPbkContactOperation
|
|
168 |
// CVPbkImportToStoreOperation::Cancel
|
|
169 |
// ---------------------------------------------------------------------------
|
|
170 |
//
|
|
171 |
|
|
172 |
void CVPbkImportToContactsMergeOperation::Cancel()
|
|
173 |
{
|
|
174 |
if(iOperationImpl)
|
|
175 |
delete iOperationImpl;
|
|
176 |
iOperationImpl = NULL;
|
|
177 |
}
|
|
178 |
|
|
179 |
// ---------------------------------------------------------------------------
|
|
180 |
// CVPbkImportToContactsMergeOperation::RunL
|
|
181 |
// from CActive
|
|
182 |
// ---------------------------------------------------------------------------
|
|
183 |
//
|
|
184 |
void CVPbkImportToContactsMergeOperation::RunL()
|
|
185 |
{
|
|
186 |
if ( iStatus == KErrNone)
|
|
187 |
{
|
|
188 |
switch( iState )
|
|
189 |
{
|
|
190 |
case ERetrieve:
|
|
191 |
{
|
|
192 |
RetrieveContactL();
|
|
193 |
break;
|
|
194 |
}
|
|
195 |
case ELock:
|
|
196 |
{
|
|
197 |
LockContactL();
|
|
198 |
break;
|
|
199 |
}
|
|
200 |
case EUpdateContact:
|
|
201 |
{
|
|
202 |
UpdateContactL();
|
|
203 |
break;
|
|
204 |
}
|
|
205 |
case EReplaceFields:
|
|
206 |
{
|
|
207 |
ReplaceFieldL( *(iImportedContacts[0]), *iContact );
|
|
208 |
break;
|
|
209 |
}
|
|
210 |
case ESetAttributes:
|
|
211 |
{
|
|
212 |
SetNextL();
|
|
213 |
break;
|
|
214 |
}
|
|
215 |
case ECommit:
|
|
216 |
{
|
|
217 |
CommitContactL();
|
|
218 |
break;
|
|
219 |
}
|
|
220 |
case EReRetrieve:
|
|
221 |
{
|
|
222 |
ReRetrieveContactL();
|
|
223 |
break;
|
|
224 |
}
|
|
225 |
case EComplete:
|
|
226 |
{
|
|
227 |
TBool isGroupCard = ((CVPbkVCardImporter *)iOperationImpl)->IsGroupcard();
|
|
228 |
if(iGroupcardHandler && isGroupCard)
|
|
229 |
{
|
|
230 |
iGroupcardHandler->BuildContactGroupsHashMapL(iContact->ParentStore());
|
|
231 |
const MVPbkContactLink* contact = iContact->CreateLinkLC();
|
|
232 |
iGroupcardHandler->GetContactGroupStoreL(*contact);
|
|
233 |
CleanupStack::PopAndDestroy(); // For contact
|
|
234 |
iGroupcardHandler->DecodeContactGroupInVCardL(((CVPbkVCardImporter *)iOperationImpl)->GetGroupcardvalue());
|
|
235 |
}
|
|
236 |
|
|
237 |
CVPbkLocalVariationManager* lvm = CVPbkLocalVariationManager::NewL();
|
|
238 |
TBool supportSyncGroupVcard = lvm->LocallyVariatedFeatureEnabled( EVPbkLVSyncGroupEnabled );
|
|
239 |
delete lvm;
|
|
240 |
if (supportSyncGroupVcard && iGroupcardHandler && !isGroupCard)
|
|
241 |
{
|
|
242 |
iGroupcardHandler->BuildContactGroupsHashMapL(iContact->ParentStore());
|
|
243 |
const MVPbkContactLink *aContact = iContact->CreateLinkLC();
|
|
244 |
iGroupcardHandler->GetContactGroupStoreL(*aContact);
|
|
245 |
CleanupStack::PopAndDestroy();
|
|
246 |
iGroupcardHandler->DeleteContactFromGroupsL();
|
|
247 |
}
|
|
248 |
|
|
249 |
iObserver.VPbkSingleContactOperationComplete( *this, iContact );
|
|
250 |
iContact = NULL;
|
|
251 |
break;
|
|
252 |
}
|
|
253 |
default:
|
|
254 |
__ASSERT_DEBUG( EFalse, Panic(EPanicInvalidState) );
|
|
255 |
}
|
|
256 |
}
|
|
257 |
}
|
|
258 |
|
|
259 |
// ---------------------------------------------------------------------------
|
|
260 |
// CVPbkImportToContactsMergeOperation::RunError
|
|
261 |
// from CActive
|
|
262 |
// ---------------------------------------------------------------------------
|
|
263 |
//
|
|
264 |
TInt CVPbkImportToContactsMergeOperation::RunError( TInt aError )
|
|
265 |
{
|
|
266 |
HandleError( aError );
|
|
267 |
return KErrNone;
|
|
268 |
}
|
|
269 |
|
|
270 |
// ---------------------------------------------------------------------------
|
|
271 |
// CVPbkImportToContactsMergeOperation::DoCancel
|
|
272 |
// from CActive
|
|
273 |
// ---------------------------------------------------------------------------
|
|
274 |
//
|
|
275 |
void CVPbkImportToContactsMergeOperation::DoCancel()
|
|
276 |
{
|
|
277 |
delete iOperationImpl;
|
|
278 |
iOperationImpl = NULL;
|
|
279 |
}
|
|
280 |
|
|
281 |
// ---------------------------------------------------------------------------
|
|
282 |
// From class MVPbkImportOperationObserver
|
|
283 |
// CVPbkImportToStoreOperation::ContactsImported
|
|
284 |
// ---------------------------------------------------------------------------
|
|
285 |
//
|
|
286 |
void CVPbkImportToContactsMergeOperation::ContactsImported()
|
|
287 |
{
|
|
288 |
if (iVPbkOperation)
|
|
289 |
delete iVPbkOperation;
|
|
290 |
iVPbkOperation = NULL;
|
|
291 |
|
|
292 |
//At the Start of contact replace,aContact will be Null, it will be retrived later
|
|
293 |
HandleContactReplacing(NULL);
|
|
294 |
}
|
|
295 |
|
|
296 |
// ---------------------------------------------------------------------------
|
|
297 |
// From class MVPbkImportOperationObserver
|
|
298 |
// CVPbkImportToStoreOperation::ContactsImportedCompleted
|
|
299 |
// ---------------------------------------------------------------------------
|
|
300 |
//
|
|
301 |
void CVPbkImportToContactsMergeOperation::ContactsImportingCompleted()
|
|
302 |
{
|
|
303 |
//not used
|
|
304 |
}
|
|
305 |
|
|
306 |
// ---------------------------------------------------------------------------
|
|
307 |
// From class MVPbkImportOperationObserver
|
|
308 |
// CVPbkImportToStoreOperation::ContactImportingFailed
|
|
309 |
// ---------------------------------------------------------------------------
|
|
310 |
//
|
|
311 |
void CVPbkImportToContactsMergeOperation::ContactImportingFailed( TInt aError )
|
|
312 |
{
|
|
313 |
if(iVPbkOperation)
|
|
314 |
delete iVPbkOperation;
|
|
315 |
iVPbkOperation = NULL;
|
|
316 |
|
|
317 |
HandleError( aError );
|
|
318 |
}
|
|
319 |
|
|
320 |
// ---------------------------------------------------------------------------
|
|
321 |
// CVPbkImportToContactsMergeOperation::HandleContactReplacing
|
|
322 |
// To initiate and start contact replacing
|
|
323 |
// ---------------------------------------------------------------------------
|
|
324 |
//
|
|
325 |
void CVPbkImportToContactsMergeOperation::HandleContactReplacing(MVPbkStoreContact* aContact)
|
|
326 |
{
|
|
327 |
switch( iState )
|
|
328 |
{
|
|
329 |
case EImport:
|
|
330 |
{
|
|
331 |
// initiate contact replacing
|
|
332 |
if ( iImportedContacts.Count() == 1 )
|
|
333 |
{
|
|
334 |
NextState( ERetrieve );
|
|
335 |
}
|
|
336 |
else
|
|
337 |
{
|
|
338 |
// invalid arguments
|
|
339 |
HandleError( KErrArgument );
|
|
340 |
}
|
|
341 |
break;
|
|
342 |
}
|
|
343 |
case ERetrieve:
|
|
344 |
{
|
|
345 |
delete iContact;
|
|
346 |
iContact = aContact;
|
|
347 |
NextState( ELock );
|
|
348 |
break;
|
|
349 |
}
|
|
350 |
case EReRetrieve:
|
|
351 |
{
|
|
352 |
delete iContact;
|
|
353 |
iContact = aContact;
|
|
354 |
NextState( EComplete );
|
|
355 |
break;
|
|
356 |
}
|
|
357 |
default:
|
|
358 |
__ASSERT_DEBUG( EFalse, Panic(EPanicInvalidState) );
|
|
359 |
HandleError( KErrGeneral );
|
|
360 |
}
|
|
361 |
}
|
|
362 |
// ---------------------------------------------------------------------------
|
|
363 |
// CVPbkImportToContactsMergeOperation::VPbkSingleContactOperationComplete
|
|
364 |
// from class MVPbkSingleContactOperationObserver
|
|
365 |
// ---------------------------------------------------------------------------
|
|
366 |
//
|
|
367 |
void CVPbkImportToContactsMergeOperation::VPbkSingleContactOperationComplete(
|
|
368 |
MVPbkContactOperationBase& /*aOperation*/,
|
|
369 |
MVPbkStoreContact* aContact )
|
|
370 |
{
|
|
371 |
if (iVPbkOperation)
|
|
372 |
delete iVPbkOperation;
|
|
373 |
iVPbkOperation = NULL;
|
|
374 |
|
|
375 |
HandleContactReplacing(aContact);
|
|
376 |
}
|
|
377 |
|
|
378 |
// ---------------------------------------------------------------------------
|
|
379 |
// CVPbkImportToContactsMergeOperation::VPbkSingleContactOperationFailed
|
|
380 |
// from class MVPbkSingleContactOperationObserver
|
|
381 |
// ---------------------------------------------------------------------------
|
|
382 |
//
|
|
383 |
void CVPbkImportToContactsMergeOperation::VPbkSingleContactOperationFailed(
|
|
384 |
MVPbkContactOperationBase& /*aOperation*/,
|
|
385 |
TInt aError )
|
|
386 |
{
|
|
387 |
delete iVPbkOperation;
|
|
388 |
iVPbkOperation = NULL;
|
|
389 |
|
|
390 |
HandleError( aError );
|
|
391 |
}
|
|
392 |
|
|
393 |
// ---------------------------------------------------------------------------
|
|
394 |
// CVPbkImportToContactsMergeOperation::ContactOperationCompleted
|
|
395 |
// from class MVPbkContactObserver
|
|
396 |
// ---------------------------------------------------------------------------
|
|
397 |
//
|
|
398 |
void CVPbkImportToContactsMergeOperation::ContactOperationCompleted(
|
|
399 |
TContactOpResult aResult)
|
|
400 |
{
|
|
401 |
delete aResult.iStoreContact;
|
|
402 |
switch( iState )
|
|
403 |
{
|
|
404 |
case ELock:
|
|
405 |
{
|
|
406 |
NextState( EUpdateContact );
|
|
407 |
break;
|
|
408 |
}
|
|
409 |
case ECommit:
|
|
410 |
{
|
|
411 |
NextState( EReRetrieve );
|
|
412 |
break;
|
|
413 |
}
|
|
414 |
default:
|
|
415 |
__ASSERT_DEBUG( EFalse, Panic(EPanicInvalidState) );
|
|
416 |
}
|
|
417 |
}
|
|
418 |
|
|
419 |
// ---------------------------------------------------------------------------
|
|
420 |
// CVPbkImportToContactsMergeOperation::ContactOperationFailed
|
|
421 |
// from class MVPbkContactObserver
|
|
422 |
// ---------------------------------------------------------------------------
|
|
423 |
//
|
|
424 |
void CVPbkImportToContactsMergeOperation::ContactOperationFailed(
|
|
425 |
TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/)
|
|
426 |
{
|
|
427 |
HandleError( aErrorCode );
|
|
428 |
}
|
|
429 |
|
|
430 |
// ---------------------------------------------------------------------------
|
|
431 |
// CVPbkImportToContactsMergeOperation::HandleError
|
|
432 |
// ---------------------------------------------------------------------------
|
|
433 |
//
|
|
434 |
void CVPbkImportToContactsMergeOperation::HandleError(TInt aError)
|
|
435 |
{
|
|
436 |
iObserver.VPbkSingleContactOperationFailed( *this, aError );
|
|
437 |
}
|
|
438 |
|
|
439 |
// ---------------------------------------------------------------------------
|
|
440 |
// CVPbkImportToContactsMergeOperation::RetrieveContactL
|
|
441 |
// ---------------------------------------------------------------------------
|
|
442 |
//
|
|
443 |
inline void CVPbkImportToContactsMergeOperation::RetrieveContactL()
|
|
444 |
{
|
|
445 |
iVPbkOperation = iData.GetContactManager().RetrieveContactL(iReplaceContact,*this );
|
|
446 |
}
|
|
447 |
|
|
448 |
// ---------------------------------------------------------------------------
|
|
449 |
// CVPbkImportToContactsMergeOperation::ReRetrieveContactL
|
|
450 |
// ---------------------------------------------------------------------------
|
|
451 |
//
|
|
452 |
inline void CVPbkImportToContactsMergeOperation::ReRetrieveContactL()
|
|
453 |
{
|
|
454 |
__ASSERT_DEBUG( iContact, Panic(EPanicInvalidToRetrieve) );
|
|
455 |
|
|
456 |
MVPbkContactLink* link = iContact->CreateLinkLC();
|
|
457 |
iVPbkOperation = iData.GetContactManager().RetrieveContactL( *link, *this );
|
|
458 |
CleanupStack::PopAndDestroy();
|
|
459 |
}
|
|
460 |
|
|
461 |
// ---------------------------------------------------------------------------
|
|
462 |
// CVPbkImportToContactsMergeOperation::LockContactL
|
|
463 |
// ---------------------------------------------------------------------------
|
|
464 |
//
|
|
465 |
inline void CVPbkImportToContactsMergeOperation::LockContactL()
|
|
466 |
{
|
|
467 |
__ASSERT_DEBUG( iContact, Panic(EPanicInvalidToLock) );
|
|
468 |
iContact->LockL( *this );
|
|
469 |
}
|
|
470 |
|
|
471 |
// ---------------------------------------------------------------------------
|
|
472 |
// CVPbkImportToContactsMergeOperation::CommitContactL
|
|
473 |
// ---------------------------------------------------------------------------
|
|
474 |
//
|
|
475 |
inline void CVPbkImportToContactsMergeOperation::CommitContactL()
|
|
476 |
{
|
|
477 |
__ASSERT_DEBUG( iContact, Panic(EPanicInvalidToCommit) );
|
|
478 |
|
|
479 |
iContact->CommitL( *this );
|
|
480 |
}
|
|
481 |
|
|
482 |
// ---------------------------------------------------------------------------
|
|
483 |
// CVPbkImportToContactsMergeOperation::UpdateContactL
|
|
484 |
// ---------------------------------------------------------------------------
|
|
485 |
//
|
|
486 |
inline void CVPbkImportToContactsMergeOperation::UpdateContactL()
|
|
487 |
{
|
|
488 |
__ASSERT_DEBUG( iContact, Panic(EPanicInvalidToUpdate) );
|
|
489 |
__ASSERT_DEBUG( iImportedContacts.Count()>0, Panic(EPanicInvalidToUpdate) );
|
|
490 |
__ASSERT_DEBUG( iImportedContacts[0], Panic(EPanicInvalidToUpdate) );
|
|
491 |
iContact->RemoveAllFields();
|
|
492 |
iCurrentFieldIndex = 0;
|
|
493 |
iFieldCount = iImportedContacts[0]->Fields().FieldCount();
|
|
494 |
|
|
495 |
ReplaceFieldL( *(iImportedContacts[0]), *iContact );
|
|
496 |
}
|
|
497 |
|
|
498 |
// ---------------------------------------------------------------------------
|
|
499 |
// From class MVPbkImportOperationObserver
|
|
500 |
// ---------------------------------------------------------------------------
|
|
501 |
//
|
|
502 |
void CVPbkImportToContactsMergeOperation::ReplaceFieldL(
|
|
503 |
const MVPbkStoreContact& aSrc,
|
|
504 |
MVPbkStoreContact& aTarget )
|
|
505 |
{
|
|
506 |
if( iCurrentFieldIndex < iFieldCount )
|
|
507 |
{
|
|
508 |
const MVPbkStoreContactFieldCollection& sourceFields = aSrc.Fields();
|
|
509 |
const MVPbkFieldType* type = sourceFields.FieldAt(iCurrentFieldIndex).BestMatchingFieldType();
|
|
510 |
if ( type )
|
|
511 |
{
|
|
512 |
TRAPD( err,
|
|
513 |
CopyFieldL( sourceFields.FieldAt(iCurrentFieldIndex), *type, aTarget );
|
|
514 |
// Check whether the sorce field has attribute,
|
|
515 |
// If the sorce field has attribute, set attribute to the target contact's field
|
|
516 |
TInt type = EVPbkDefaultTypeUndefined + 1;
|
|
517 |
if( iData.AttributeManagerL().HasFieldAttributeL( CVPbkDefaultAttribute::Uid(),
|
|
518 |
sourceFields.FieldAt(iCurrentFieldIndex) ) )
|
|
519 |
{
|
|
520 |
GetDefaultAttributsL( sourceFields.FieldAt(iCurrentFieldIndex) );
|
|
521 |
if( iDefaultAttributes && iDefaultAttributes->Count() > 0 )
|
|
522 |
{
|
|
523 |
SetNextL();
|
|
524 |
}
|
|
525 |
}
|
|
526 |
else
|
|
527 |
{
|
|
528 |
if( ++iCurrentFieldIndex < iFieldCount )
|
|
529 |
{
|
|
530 |
ReplaceFieldL(aSrc, aTarget);
|
|
531 |
}
|
|
532 |
else
|
|
533 |
{
|
|
534 |
delete iImportedContacts[0];
|
|
535 |
iImportedContacts.Remove(0);
|
|
536 |
NextState( ECommit );
|
|
537 |
}
|
|
538 |
}
|
|
539 |
);
|
|
540 |
if( err != KErrNone )
|
|
541 |
{
|
|
542 |
delete iImportedContacts[0];
|
|
543 |
iImportedContacts.Remove(0);
|
|
544 |
HandleError( err );
|
|
545 |
}
|
|
546 |
}
|
|
547 |
}
|
|
548 |
else
|
|
549 |
{
|
|
550 |
delete iImportedContacts[0];
|
|
551 |
iImportedContacts.Remove(0);
|
|
552 |
NextState( ECommit );
|
|
553 |
}
|
|
554 |
}
|
|
555 |
|
|
556 |
// ---------------------------------------------------------------------------
|
|
557 |
// CVPbkImportToContactsMergeOperation::CopyFieldL
|
|
558 |
// ---------------------------------------------------------------------------
|
|
559 |
//
|
|
560 |
inline void CVPbkImportToContactsMergeOperation::CopyFieldL(
|
|
561 |
const MVPbkStoreContactField& aSourceField,
|
|
562 |
const MVPbkFieldType& aType,
|
|
563 |
MVPbkStoreContact& aTargetContact )
|
|
564 |
{
|
|
565 |
MVPbkStoreContactField* newField = aTargetContact.CreateFieldLC( aType );
|
|
566 |
if ( newField->SupportsLabel() )
|
|
567 |
{
|
|
568 |
TPtrC fieldLabel = aSourceField.FieldLabel();
|
|
569 |
if (fieldLabel.Length() > 0)
|
|
570 |
{
|
|
571 |
newField->SetFieldLabelL(fieldLabel);
|
|
572 |
}
|
|
573 |
}
|
|
574 |
newField->FieldData().CopyL(aSourceField.FieldData());
|
|
575 |
aTargetContact.AddFieldL(newField);
|
|
576 |
CleanupStack::Pop(); // newField
|
|
577 |
}
|
|
578 |
|
|
579 |
// --------------------------------------------------------------------------
|
|
580 |
// CVPbkImportToContactsMergeOperation::GetDefaultAttributsL
|
|
581 |
// Gets the attributes from aField.
|
|
582 |
// --------------------------------------------------------------------------
|
|
583 |
//
|
|
584 |
void CVPbkImportToContactsMergeOperation::GetDefaultAttributsL( const MVPbkStoreContactField& aField )
|
|
585 |
{
|
|
586 |
delete iDefaultAttributes;
|
|
587 |
iDefaultAttributes = NULL;
|
|
588 |
iDefaultAttributes = new( ELeave ) CArrayFixFlat<TVPbkDefaultType>( KGranularity );
|
|
589 |
TInt type = EVPbkDefaultTypeUndefined + 1;
|
|
590 |
while( EVPbkLastDefaultType != type )
|
|
591 |
{
|
|
592 |
CVPbkDefaultAttribute* attr = CVPbkDefaultAttribute::NewL( (TVPbkDefaultType)type );
|
|
593 |
CleanupStack::PushL( attr );
|
|
594 |
|
|
595 |
if( iData.AttributeManagerL().HasFieldAttributeL( *attr, aField ) )
|
|
596 |
{
|
|
597 |
iDefaultAttributes->AppendL( (TVPbkDefaultType)type );
|
|
598 |
}
|
|
599 |
|
|
600 |
CleanupStack::PopAndDestroy( attr );
|
|
601 |
type++;
|
|
602 |
}
|
|
603 |
}
|
|
604 |
|
|
605 |
// --------------------------------------------------------------------------
|
|
606 |
// CVPbkImportToContactsMergeOperation::NextAttribute
|
|
607 |
// Gets next attribute from the array. The array is processed backwards.
|
|
608 |
// --------------------------------------------------------------------------
|
|
609 |
//
|
|
610 |
inline TVPbkDefaultType CVPbkImportToContactsMergeOperation::NextAttribute()
|
|
611 |
{
|
|
612 |
TVPbkDefaultType attribute = EVPbkDefaultTypeUndefined;
|
|
613 |
TInt count = 0;
|
|
614 |
if ( iDefaultAttributes )
|
|
615 |
{
|
|
616 |
count = iDefaultAttributes->Count();
|
|
617 |
}
|
|
618 |
|
|
619 |
if ( count > 0 )
|
|
620 |
{
|
|
621 |
attribute = iDefaultAttributes->At( count - 1 ); // zero-based
|
|
622 |
iDefaultAttributes->Delete( count -1 ); // zero-based
|
|
623 |
}
|
|
624 |
return attribute;
|
|
625 |
}
|
|
626 |
|
|
627 |
// --------------------------------------------------------------------------
|
|
628 |
// CPbk2DefaultAttributeProcess::SetNextL
|
|
629 |
// --------------------------------------------------------------------------
|
|
630 |
//
|
|
631 |
void CVPbkImportToContactsMergeOperation::SetNextL()
|
|
632 |
{
|
|
633 |
TVPbkDefaultType attributeType = NextAttribute();
|
|
634 |
if ( attributeType != EVPbkDefaultTypeUndefined )
|
|
635 |
{
|
|
636 |
delete iSetAttributeOperation;
|
|
637 |
iSetAttributeOperation = NULL;
|
|
638 |
CVPbkDefaultAttribute* attr = CVPbkDefaultAttribute::NewL( attributeType );
|
|
639 |
CleanupStack::PushL( attr );
|
|
640 |
iSetAttributeOperation = iData.AttributeManagerL().SetFieldAttributeL(iContact->Fields().FieldAt(iCurrentFieldIndex), *attr, *this);
|
|
641 |
CleanupStack::PopAndDestroy( attr );
|
|
642 |
}
|
|
643 |
else
|
|
644 |
{
|
|
645 |
// Finished
|
|
646 |
++iCurrentFieldIndex;
|
|
647 |
NextState( EReplaceFields );
|
|
648 |
}
|
|
649 |
}
|
|
650 |
|
|
651 |
// ---------------------------------------------------------------------------
|
|
652 |
// CVPbkImportToContactsMergeOperation::NextState
|
|
653 |
// ---------------------------------------------------------------------------
|
|
654 |
//
|
|
655 |
void CVPbkImportToContactsMergeOperation::NextState( TState aNextState )
|
|
656 |
{
|
|
657 |
iState = aNextState;
|
|
658 |
TRequestStatus* status = &iStatus;
|
|
659 |
User::RequestComplete( status, KErrNone );
|
|
660 |
SetActive();
|
|
661 |
}
|
|
662 |
|
|
663 |
// --------------------------------------------------------------------------
|
|
664 |
// CVPbkImportToContactsMergeOperation::AttributeOperationComplete
|
|
665 |
// --------------------------------------------------------------------------
|
|
666 |
//
|
|
667 |
void CVPbkImportToContactsMergeOperation::AttributeOperationComplete( MVPbkContactOperationBase& aOperation )
|
|
668 |
{
|
|
669 |
if( &aOperation == iSetAttributeOperation )
|
|
670 |
{
|
|
671 |
NextState( ESetAttributes );
|
|
672 |
}
|
|
673 |
}
|
|
674 |
|
|
675 |
// --------------------------------------------------------------------------
|
|
676 |
// CVPbkImportToContactsMergeOperation::AttributeOperationFailed
|
|
677 |
// --------------------------------------------------------------------------
|
|
678 |
//
|
|
679 |
void CVPbkImportToContactsMergeOperation::AttributeOperationFailed(
|
|
680 |
MVPbkContactOperationBase& aOperation,
|
|
681 |
TInt aError )
|
|
682 |
{
|
|
683 |
if( &aOperation == iSetAttributeOperation )
|
|
684 |
{
|
|
685 |
delete iImportedContacts[0];
|
|
686 |
iImportedContacts.Remove(0);
|
|
687 |
HandleError( aError );
|
|
688 |
}
|
|
689 |
}
|
|
690 |
|
|
691 |
// End of file
|