20
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-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: Phonebook 2 USIM UI Extension copy to SIM command.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include "CPsu2CopyToSimCmd.h"
|
|
21 |
|
|
22 |
// Phonebook 2
|
|
23 |
#include "CPsu2CopyToSimFieldInfoArray.h"
|
|
24 |
#include "CPsu2SimContactProcessor.h"
|
|
25 |
#include "TPsu2SimCopyResults.h"
|
|
26 |
#include "CPsu2ContactCopyInspector.h"
|
|
27 |
#include <MPbk2ContactUiControl.h>
|
|
28 |
#include <CPbk2FieldPropertyArray.h>
|
|
29 |
#include <MPbk2ContactNameFormatter.h>
|
|
30 |
#include <MPbk2CommandObserver.h>
|
|
31 |
#include <Pbk2ProcessDecoratorFactory.h>
|
|
32 |
#include <Pbk2USimUIRes.rsg>
|
|
33 |
#include <CPbk2StorePropertyArray.h>
|
|
34 |
#include <CPbk2StoreProperty.h>
|
|
35 |
#include <CPbk2ApplicationServices.h>
|
|
36 |
#include <MPbk2AppUi.h>
|
|
37 |
#include <Pbk2CommonUi.rsg>
|
|
38 |
|
|
39 |
// Virtual Phonebook
|
|
40 |
#include <MVPbkContactStoreProperties.h>
|
|
41 |
#include <CVPbkContactManager.h>
|
|
42 |
#include <MVPbkContactStore.h>
|
|
43 |
#include <MVPbkStoreContact.h>
|
|
44 |
#include <MVPbkContactLink.h>
|
|
45 |
#include <MVPbkContactOperationBase.h>
|
|
46 |
#include <CVPbkContactLinkArray.h>
|
|
47 |
#include <CVPbkFieldTypeRefsList.h>
|
|
48 |
#include <MVPbkContactStoreInfo.h>
|
|
49 |
|
|
50 |
// System includes
|
|
51 |
#include <avkon.hrh>
|
|
52 |
#include <exterror.h>
|
|
53 |
#include <coemain.h>
|
|
54 |
#include <StringLoader.h>
|
|
55 |
#include <aknnotewrappers.h>
|
|
56 |
|
|
57 |
// debug
|
|
58 |
#include <Pbk2Debug.h>
|
|
59 |
|
|
60 |
/// Unnamed namespace for local definitions
|
|
61 |
namespace {
|
|
62 |
|
|
63 |
const TInt KZero = 0;
|
|
64 |
const TInt KOne = 1;
|
|
65 |
|
|
66 |
enum TNextTask
|
|
67 |
{
|
|
68 |
EStartCommand,
|
|
69 |
ERetrieveSourceContact,
|
|
70 |
ECreateSimContacts,
|
|
71 |
EStartCopy,
|
|
72 |
ECopyContact,
|
|
73 |
EShowResultsAndComplete,
|
|
74 |
EComplete
|
|
75 |
};
|
|
76 |
|
|
77 |
enum TTargetStoreStatus
|
|
78 |
{
|
|
79 |
EStoreNotOpen,
|
|
80 |
EStoreOpen,
|
|
81 |
EStoreNotAvailable
|
|
82 |
};
|
|
83 |
#ifdef _DEBUG
|
|
84 |
enum TPanicCode
|
|
85 |
{
|
|
86 |
ECopyToSimMenuItemMustNotBeInMenu,
|
|
87 |
EPreCond_CopyCurrentContactL,
|
|
88 |
};
|
|
89 |
|
|
90 |
void Panic(TInt aReason)
|
|
91 |
{
|
|
92 |
_LIT(KPanicText, "CPsu2CopyToSimCmd");
|
|
93 |
User::Panic(KPanicText, aReason);
|
|
94 |
}
|
|
95 |
#endif // _DEBUG
|
|
96 |
|
|
97 |
} /// namespace
|
|
98 |
|
|
99 |
// --------------------------------------------------------------------------
|
|
100 |
// CPsu2CopyToSimCmd::CPsu2CopyToSimCmd
|
|
101 |
// --------------------------------------------------------------------------
|
|
102 |
//
|
|
103 |
CPsu2CopyToSimCmd::CPsu2CopyToSimCmd( MPbk2ContactUiControl& aUiControl,
|
|
104 |
MVPbkContactStore& aTargetStore ) :
|
|
105 |
CActive( EPriorityStandard ),
|
|
106 |
iUiControl( &aUiControl ),
|
|
107 |
iTargetStore( aTargetStore ),
|
|
108 |
iUpdateControl( ETrue ),
|
|
109 |
iIsCopiedCompletely( ETrue ),
|
|
110 |
iIsLastCopyFailedForSimIsFull( EFalse )
|
|
111 |
{
|
|
112 |
}
|
|
113 |
|
|
114 |
// --------------------------------------------------------------------------
|
|
115 |
// CPsu2CopyToSimCmd::~CPsu2CopyToSimCmd
|
|
116 |
// --------------------------------------------------------------------------
|
|
117 |
//
|
|
118 |
CPsu2CopyToSimCmd::~CPsu2CopyToSimCmd()
|
|
119 |
{
|
|
120 |
Cancel();
|
|
121 |
delete iContactInspector;
|
|
122 |
delete iDecorator;
|
|
123 |
delete iSimContactProcessor;
|
|
124 |
delete iCopyToSimTypeInfos;
|
|
125 |
delete iContactRetriever;
|
|
126 |
delete iLinkArray;
|
|
127 |
delete iCurrentSourceContact;
|
|
128 |
delete iCurrentSimContact;
|
|
129 |
iSimContacts.ResetAndDestroy();
|
|
130 |
// Deregister the observer to the target store.
|
|
131 |
iTargetStore.Close( *this );
|
|
132 |
|
|
133 |
Release( iAppServices );
|
|
134 |
}
|
|
135 |
|
|
136 |
// --------------------------------------------------------------------------
|
|
137 |
// CPsu2CopyToSimCmd::NewL
|
|
138 |
// --------------------------------------------------------------------------
|
|
139 |
//
|
|
140 |
CPsu2CopyToSimCmd* CPsu2CopyToSimCmd::NewL(
|
|
141 |
MPbk2ContactUiControl& aUiControl,
|
|
142 |
MVPbkContactStore& aTargetStore)
|
|
143 |
{
|
|
144 |
CPsu2CopyToSimCmd* self =
|
|
145 |
new( ELeave ) CPsu2CopyToSimCmd(aUiControl, aTargetStore);
|
|
146 |
CleanupStack::PushL( self );
|
|
147 |
self->ConstructL();
|
|
148 |
CleanupStack::Pop( self );
|
|
149 |
return self;
|
|
150 |
}
|
|
151 |
|
|
152 |
// --------------------------------------------------------------------------
|
|
153 |
// CPsu2CopyToSimCmd::ConstructL
|
|
154 |
// --------------------------------------------------------------------------
|
|
155 |
//
|
|
156 |
void CPsu2CopyToSimCmd::ConstructL()
|
|
157 |
{
|
|
158 |
iAppServices = CPbk2ApplicationServices::InstanceL();
|
|
159 |
|
|
160 |
CActiveScheduler::Add(this);
|
|
161 |
|
|
162 |
iLinkArray = CVPbkContactLinkArray::NewL();
|
|
163 |
iContactInspector = CPsu2ContactCopyInspector::NewL
|
|
164 |
( iAppServices->NameFormatter() );
|
|
165 |
|
|
166 |
// The command can be called from the generic Copy starter
|
|
167 |
// or straight using Copy To SIM menu command
|
|
168 |
// -> iUiControl can be name list control or
|
|
169 |
// it can be a store list control
|
|
170 |
// safe since reference in contructor
|
|
171 |
iNameListUiControl = iUiControl->ParentControl();
|
|
172 |
if (!iNameListUiControl)
|
|
173 |
{
|
|
174 |
iNameListUiControl = iUiControl;
|
|
175 |
}
|
|
176 |
|
|
177 |
iNameListUiControl->RegisterCommand( this );
|
|
178 |
|
|
179 |
MVPbkContactLinkArray* linkArray =
|
|
180 |
iNameListUiControl->SelectedContactsOrFocusedContactL();
|
|
181 |
// There must be at least one item in the array, otherwise the menu
|
|
182 |
// item shouldn't be there
|
|
183 |
__ASSERT_DEBUG( linkArray && linkArray->Count() > 0,
|
|
184 |
Panic( ECopyToSimMenuItemMustNotBeInMenu ) );
|
|
185 |
|
|
186 |
CleanupDeletePushL( linkArray );
|
|
187 |
// Copy links that belongs to the target store
|
|
188 |
TVPbkContactStoreUriPtr targetUri = iTargetStore.StoreProperties().Uri();
|
|
189 |
const TInt count = linkArray->Count();
|
|
190 |
for (TInt i = 0; i < count; ++i)
|
|
191 |
{
|
|
192 |
TVPbkContactStoreUriPtr uri =
|
|
193 |
(*linkArray)[i].ContactStore().StoreProperties().Uri();
|
|
194 |
if ( targetUri.Compare(uri,
|
|
195 |
TVPbkContactStoreUriPtr::EContactStoreUriAllComponents) != 0)
|
|
196 |
{
|
|
197 |
iLinkArray->AppendL( (*linkArray)[i].CloneLC() );
|
|
198 |
CleanupStack::Pop(); // created link
|
|
199 |
}
|
|
200 |
}
|
|
201 |
CleanupStack::PopAndDestroy(); // linkArray
|
|
202 |
|
|
203 |
// Create source to SIM field type mapping infos
|
|
204 |
iCopyToSimTypeInfos = CPsu2CopyToSimFieldInfoArray::NewL(
|
|
205 |
iAppServices->ContactManager().FieldTypes(),
|
|
206 |
iAppServices->ContactManager().FsSession() );
|
|
207 |
|
|
208 |
// Create a processor that knows how to build and split contacts
|
|
209 |
iSimContactProcessor = CPsu2SimContactProcessor::NewL(
|
|
210 |
iTargetStore,
|
|
211 |
*iCopyToSimTypeInfos,
|
|
212 |
iAppServices->NameFormatter(),
|
|
213 |
iAppServices->ContactManager().FieldTypes(),
|
|
214 |
iAppServices->ContactManager().FsSession() );
|
|
215 |
|
|
216 |
iDecorator = Pbk2ProcessDecoratorFactory::CreateProgressDialogDecoratorL(
|
|
217 |
R_PSU2_COPY_PROGRESS_NOTE, ETrue );
|
|
218 |
iDecorator->SetObserver( *this );
|
|
219 |
|
|
220 |
iTargetStoreStatus = EStoreNotOpen;
|
|
221 |
// Register as an observer of the store, to make sure could get the store state
|
|
222 |
// change notification.
|
|
223 |
iTargetStore.OpenL( *this );
|
|
224 |
}
|
|
225 |
|
|
226 |
// --------------------------------------------------------------------------
|
|
227 |
// CPsu2CopyToSimCmd::RunL
|
|
228 |
// --------------------------------------------------------------------------
|
|
229 |
//
|
|
230 |
void CPsu2CopyToSimCmd::RunL()
|
|
231 |
{
|
|
232 |
switch (iNextTask)
|
|
233 |
{
|
|
234 |
case EStartCommand:
|
|
235 |
{
|
|
236 |
StartL();
|
|
237 |
break;
|
|
238 |
}
|
|
239 |
case ERetrieveSourceContact:
|
|
240 |
{
|
|
241 |
RetrieveSourceContactL();
|
|
242 |
break;
|
|
243 |
}
|
|
244 |
case ECreateSimContacts:
|
|
245 |
{
|
|
246 |
CreateSimContactsL();
|
|
247 |
break;
|
|
248 |
}
|
|
249 |
case EStartCopy:
|
|
250 |
{
|
|
251 |
StartCopyL();
|
|
252 |
break;
|
|
253 |
}
|
|
254 |
case ECopyContact:
|
|
255 |
{
|
|
256 |
CopyCurrentContactL();
|
|
257 |
break;
|
|
258 |
}
|
|
259 |
case EShowResultsAndComplete:
|
|
260 |
{
|
|
261 |
// If can't get the sim space here, and the former
|
|
262 |
// copy is failed, just show that sim is full
|
|
263 |
if ( (GetSimSpaceStatusL() == ESimSpaceUnknown) &&
|
|
264 |
iIsLastCopyFailedForSimIsFull )
|
|
265 |
{
|
|
266 |
ShowSimIsFullNoteL();
|
|
267 |
}
|
|
268 |
else
|
|
269 |
{
|
|
270 |
ShowResultsNoteL();
|
|
271 |
}
|
|
272 |
|
|
273 |
CompleteL();
|
|
274 |
break;
|
|
275 |
}
|
|
276 |
case EComplete: // FALLTHROUGH
|
|
277 |
default:
|
|
278 |
{
|
|
279 |
CompleteL();
|
|
280 |
break;
|
|
281 |
}
|
|
282 |
}
|
|
283 |
}
|
|
284 |
|
|
285 |
// --------------------------------------------------------------------------
|
|
286 |
// CPsu2CopyToSimCmd::DoCancel
|
|
287 |
// --------------------------------------------------------------------------
|
|
288 |
//
|
|
289 |
void CPsu2CopyToSimCmd::DoCancel()
|
|
290 |
{
|
|
291 |
}
|
|
292 |
|
|
293 |
// --------------------------------------------------------------------------
|
|
294 |
// CPsu2CopyToSimCmd::RunError
|
|
295 |
// --------------------------------------------------------------------------
|
|
296 |
//
|
|
297 |
TInt CPsu2CopyToSimCmd::RunError(TInt aError)
|
|
298 |
{
|
|
299 |
PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
|
|
300 |
( "CPsu2CopyToSimCmd::RunError %d" ), aError );
|
|
301 |
CCoeEnv::Static()->HandleError(aError);
|
|
302 |
|
|
303 |
// If the copy operation is cancelled due to error occurred, update the
|
|
304 |
// ui control and reset the command pointer before it is destructed.
|
|
305 |
if ( iNameListUiControl )
|
|
306 |
{
|
|
307 |
iNameListUiControl->UpdateAfterCommandExecution();
|
|
308 |
}
|
|
309 |
if ( iCommandObserver )
|
|
310 |
{
|
|
311 |
iCommandObserver->CommandFinished(*this);
|
|
312 |
}
|
|
313 |
return KErrNone;
|
|
314 |
}
|
|
315 |
|
|
316 |
// --------------------------------------------------------------------------
|
|
317 |
// CPsu2CopyToSimCmd::ExecuteLD
|
|
318 |
// --------------------------------------------------------------------------
|
|
319 |
//
|
|
320 |
void CPsu2CopyToSimCmd::ExecuteLD()
|
|
321 |
{
|
|
322 |
iNextTask = EStartCommand;
|
|
323 |
IssueRequest();
|
|
324 |
}
|
|
325 |
|
|
326 |
// --------------------------------------------------------------------------
|
|
327 |
// CPsu2CopyToSimCmd::AddObserver
|
|
328 |
// --------------------------------------------------------------------------
|
|
329 |
//
|
|
330 |
void CPsu2CopyToSimCmd::AddObserver(MPbk2CommandObserver& aObserver)
|
|
331 |
{
|
|
332 |
iCommandObserver = &aObserver;
|
|
333 |
}
|
|
334 |
|
|
335 |
// --------------------------------------------------------------------------
|
|
336 |
// CPsu2CopyToSimCmd::ResetUiControl
|
|
337 |
// --------------------------------------------------------------------------
|
|
338 |
//
|
|
339 |
void CPsu2CopyToSimCmd::ResetUiControl(
|
|
340 |
MPbk2ContactUiControl& aUiControl)
|
|
341 |
{
|
|
342 |
if (iNameListUiControl == & aUiControl)
|
|
343 |
{
|
|
344 |
iUiControl = NULL;
|
|
345 |
iNameListUiControl = NULL;
|
|
346 |
}
|
|
347 |
}
|
|
348 |
|
|
349 |
// --------------------------------------------------------------------------
|
|
350 |
// CPsu2CopyToSimCmd::StoreReady
|
|
351 |
// --------------------------------------------------------------------------
|
|
352 |
//
|
|
353 |
void CPsu2CopyToSimCmd::StoreReady( MVPbkContactStore& /*aContactStore*/ )
|
|
354 |
{
|
|
355 |
iTargetStoreStatus = EStoreOpen;
|
|
356 |
}
|
|
357 |
|
|
358 |
// --------------------------------------------------------------------------
|
|
359 |
// CPsu2CopyToSimCmd::StoreUnavailable
|
|
360 |
// --------------------------------------------------------------------------
|
|
361 |
//
|
|
362 |
void CPsu2CopyToSimCmd::StoreUnavailable( MVPbkContactStore& /*aContactStore*/,
|
|
363 |
TInt /*aReason*/ )
|
|
364 |
{
|
|
365 |
iTargetStoreStatus = EStoreNotAvailable;
|
|
366 |
}
|
|
367 |
|
|
368 |
// --------------------------------------------------------------------------
|
|
369 |
// CPsu2CopyToSimCmd::HandleStoreEventL
|
|
370 |
// --------------------------------------------------------------------------
|
|
371 |
//
|
|
372 |
void CPsu2CopyToSimCmd::HandleStoreEventL(
|
|
373 |
MVPbkContactStore& /*aContactStore*/,
|
|
374 |
TVPbkContactStoreEvent /*aStoreEvent*/ )
|
|
375 |
{
|
|
376 |
// do nothing.
|
|
377 |
}
|
|
378 |
|
|
379 |
// --------------------------------------------------------------------------
|
|
380 |
// CPsu2CopyToSimCmd::VPbkSingleContactOperationComplete
|
|
381 |
// --------------------------------------------------------------------------
|
|
382 |
//
|
|
383 |
void CPsu2CopyToSimCmd::VPbkSingleContactOperationComplete(
|
|
384 |
MVPbkContactOperationBase& /*aOperation*/,
|
|
385 |
MVPbkStoreContact* aContact)
|
|
386 |
{
|
|
387 |
PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
|
|
388 |
( "CPsu2CopyToSimCmd::VPbkSingleContactOperationComplete 0x%x" ),
|
|
389 |
this );
|
|
390 |
// This is called when a new source contact is loaded
|
|
391 |
|
|
392 |
delete iCurrentSourceContact;
|
|
393 |
iCurrentSourceContact = aContact;
|
|
394 |
|
|
395 |
// Create SIM contacts from the source next
|
|
396 |
iNextTask = ECreateSimContacts;
|
|
397 |
IssueRequest();
|
|
398 |
}
|
|
399 |
|
|
400 |
// --------------------------------------------------------------------------
|
|
401 |
// CPsu2CopyToSimCmd::VPbkSingleContactOperationFailed
|
|
402 |
// --------------------------------------------------------------------------
|
|
403 |
//
|
|
404 |
void CPsu2CopyToSimCmd::VPbkSingleContactOperationFailed(
|
|
405 |
MVPbkContactOperationBase& /*aOperation*/, TInt aError)
|
|
406 |
{
|
|
407 |
PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
|
|
408 |
( "CPsu2CopyToSimCmd::VPbkSingleContactOperationFailed 0x%x" ),
|
|
409 |
this );
|
|
410 |
// This is called when a new source contact loading failed
|
|
411 |
iDecorator->ProcessAdvance(KOne);
|
|
412 |
HandleError(aError);
|
|
413 |
}
|
|
414 |
|
|
415 |
// --------------------------------------------------------------------------
|
|
416 |
// CPsu2CopyToSimCmd::ContactOperationCompleted
|
|
417 |
// --------------------------------------------------------------------------
|
|
418 |
//
|
|
419 |
void CPsu2CopyToSimCmd::ContactOperationCompleted
|
|
420 |
(TContactOpResult /*aResult*/)
|
|
421 |
{
|
|
422 |
PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
|
|
423 |
( "CPsu2CopyToSimCmd::ContactOperationCompleted 0x%x" ),
|
|
424 |
this );
|
|
425 |
// This called when one SIM contact has been copied
|
|
426 |
// ( or deleted in additional number full case )
|
|
427 |
iIsLastCopyFailedForSimIsFull = ETrue;
|
|
428 |
if (iSimContacts.Count() == 0)
|
|
429 |
{
|
|
430 |
// The source contact has been successfully copied
|
|
431 |
++iCopied;
|
|
432 |
MoveToNextContact();
|
|
433 |
}
|
|
434 |
else
|
|
435 |
{
|
|
436 |
// The source contact was splitted and all splitted sim contacts
|
|
437 |
// are not yet copied
|
|
438 |
CopyNextSimContact();
|
|
439 |
}
|
|
440 |
}
|
|
441 |
|
|
442 |
// --------------------------------------------------------------------------
|
|
443 |
// CPsu2CopyToSimCmd::ContactOperationFailed
|
|
444 |
// --------------------------------------------------------------------------
|
|
445 |
//
|
|
446 |
void CPsu2CopyToSimCmd::ContactOperationFailed
|
|
447 |
(TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/)
|
|
448 |
{
|
|
449 |
PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
|
|
450 |
( "CPsu2CopyToSimCmd::ContactOperationFailed 0x%x ERROR: %d" ),
|
|
451 |
this, aErrorCode );
|
|
452 |
|
|
453 |
// This called when copying of a SIM contact failed
|
|
454 |
TInt res = KErrNone;
|
|
455 |
TInt currentSimContactDeleted( EFalse );
|
|
456 |
iIsLastCopyFailedForSimIsFull = ETrue;
|
|
457 |
if (iSimContactProcessor->HandleSimError(aErrorCode ))
|
|
458 |
{
|
|
459 |
// If the error was handled it means that the SIM contact
|
|
460 |
// must be splitted and resulted contacts must be copied.
|
|
461 |
TRAP(res, iSimContactProcessor->CreateFixedSimContactsL(
|
|
462 |
*iCurrentSimContact, iSimContacts));
|
|
463 |
|
|
464 |
if ( res == KErrNone && iIsCopiedCompletely )
|
|
465 |
{
|
|
466 |
iIsCopiedCompletely = !iSimContactProcessor->DetailsDropped();
|
|
467 |
if ( iIsCopiedCompletely )
|
|
468 |
{
|
|
469 |
// Inspect that contact was copied completely
|
|
470 |
// if sim contacts has created.
|
|
471 |
if ( iIsCopiedCompletely && iSimContacts.Count() > 0 )
|
|
472 |
{
|
|
473 |
iIsCopiedCompletely = iContactInspector->IsCopiedCompletelyL
|
|
474 |
( *iCurrentSimContact, iSimContacts );
|
|
475 |
}
|
|
476 |
}
|
|
477 |
}
|
|
478 |
|
|
479 |
if ( res == KErrNone )
|
|
480 |
{
|
|
481 |
// Current contact is partially saved so delete it
|
|
482 |
// to prevent duplicate data
|
|
483 |
TRAP( res, iCurrentSimContact->DeleteL( *this ) );
|
|
484 |
currentSimContactDeleted = ETrue;
|
|
485 |
}
|
|
486 |
}
|
|
487 |
else
|
|
488 |
{
|
|
489 |
res = aErrorCode;
|
|
490 |
}
|
|
491 |
|
|
492 |
if (res != KErrNone)
|
|
493 |
{
|
|
494 |
// Stop command or move to next contact depending on the error
|
|
495 |
HandleError(res);
|
|
496 |
}
|
|
497 |
else if (iSimContacts.Count() > 0)
|
|
498 |
{
|
|
499 |
// if delete contact is on, this will continue in
|
|
500 |
// MVPbkContactObserver callback
|
|
501 |
if ( !currentSimContactDeleted )
|
|
502 |
{
|
|
503 |
// There are still SIM contacts to copy
|
|
504 |
CopyNextSimContact();
|
|
505 |
}
|
|
506 |
}
|
|
507 |
else
|
|
508 |
{
|
|
509 |
// Current contact has been handled, move to next contact
|
|
510 |
MoveToNextContact();
|
|
511 |
}
|
|
512 |
|
|
513 |
PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
|
|
514 |
"CPsu2CopyToSimCmd::ContactOperationFailed 0x%x IsCopiedCompletely: %d" ),
|
|
515 |
this, iIsCopiedCompletely );
|
|
516 |
}
|
|
517 |
|
|
518 |
// --------------------------------------------------------------------------
|
|
519 |
// CPsu2CopyToSimCmd::ProcessDismissed
|
|
520 |
// --------------------------------------------------------------------------
|
|
521 |
//
|
|
522 |
void CPsu2CopyToSimCmd::ProcessDismissed(TInt aCancelCode)
|
|
523 |
{
|
|
524 |
if ( iNameListUiControl )
|
|
525 |
{
|
|
526 |
iNameListUiControl->SetBlank( EFalse );
|
|
527 |
}
|
|
528 |
|
|
529 |
if ( aCancelCode == KErrCancel || aCancelCode == EEikBidCancel )
|
|
530 |
{
|
|
531 |
Cancel();
|
|
532 |
HandleCanceling();
|
|
533 |
iNextTask = EShowResultsAndComplete;
|
|
534 |
}
|
|
535 |
IssueRequest();
|
|
536 |
}
|
|
537 |
|
|
538 |
// --------------------------------------------------------------------------
|
|
539 |
// CPsu2CopyToSimCmd::IssueRequest
|
|
540 |
// --------------------------------------------------------------------------
|
|
541 |
//
|
|
542 |
void CPsu2CopyToSimCmd::IssueRequest()
|
|
543 |
{
|
|
544 |
if ( !IsActive() )
|
|
545 |
{
|
|
546 |
TRequestStatus* status = &iStatus;
|
|
547 |
User::RequestComplete(status, KErrNone);
|
|
548 |
SetActive();
|
|
549 |
}
|
|
550 |
}
|
|
551 |
|
|
552 |
// --------------------------------------------------------------------------
|
|
553 |
// CPsu2CopyToSimCmd::StartL
|
|
554 |
// --------------------------------------------------------------------------
|
|
555 |
//
|
|
556 |
void CPsu2CopyToSimCmd::StartL()
|
|
557 |
{
|
|
558 |
if ( GetSimSpaceStatusL() == ESimSpaceIsFull )
|
|
559 |
{
|
|
560 |
ShowSimIsFullNoteL();
|
|
561 |
iNextTask = EComplete;
|
|
562 |
IssueRequest();
|
|
563 |
}
|
|
564 |
else
|
|
565 |
{
|
|
566 |
iCurrentIndex = 0;
|
|
567 |
TInt contactCount = iLinkArray->Count();
|
|
568 |
switch ( contactCount )
|
|
569 |
{
|
|
570 |
case KZero:
|
|
571 |
{
|
|
572 |
CompleteWithResults();
|
|
573 |
break;
|
|
574 |
}
|
|
575 |
default:
|
|
576 |
{
|
|
577 |
iDecorator->ProcessStartedL( contactCount );
|
|
578 |
iNextTask = ERetrieveSourceContact;
|
|
579 |
IssueRequest();
|
|
580 |
break;
|
|
581 |
}
|
|
582 |
}
|
|
583 |
}
|
|
584 |
}
|
|
585 |
|
|
586 |
// --------------------------------------------------------------------------
|
|
587 |
// CPsu2CopyToSimCmd::HandleCanceling
|
|
588 |
// --------------------------------------------------------------------------
|
|
589 |
//
|
|
590 |
void CPsu2CopyToSimCmd::HandleCanceling()
|
|
591 |
{
|
|
592 |
delete iContactRetriever;
|
|
593 |
iContactRetriever = NULL;
|
|
594 |
delete iCurrentSimContact;
|
|
595 |
iCurrentSimContact = NULL;
|
|
596 |
iSimContacts.ResetAndDestroy();
|
|
597 |
}
|
|
598 |
|
|
599 |
// --------------------------------------------------------------------------
|
|
600 |
// CPsu2CopyToSimCmd::RetrieveSourceContactL
|
|
601 |
// --------------------------------------------------------------------------
|
|
602 |
//
|
|
603 |
void CPsu2CopyToSimCmd::RetrieveSourceContactL()
|
|
604 |
{
|
|
605 |
if (iCurrentIndex >= iLinkArray->Count())
|
|
606 |
{
|
|
607 |
// End copying if all contacts have been read
|
|
608 |
CompleteWithResults();
|
|
609 |
}
|
|
610 |
else
|
|
611 |
{
|
|
612 |
delete iContactRetriever;
|
|
613 |
iContactRetriever = NULL;
|
|
614 |
|
|
615 |
iContactRetriever = iAppServices->ContactManager().RetrieveContactL(
|
|
616 |
(*iLinkArray)[iCurrentIndex], *this);
|
|
617 |
}
|
|
618 |
}
|
|
619 |
|
|
620 |
// --------------------------------------------------------------------------
|
|
621 |
// CPsu2CopyToSimCmd::CreateSimContactsL
|
|
622 |
// --------------------------------------------------------------------------
|
|
623 |
//
|
|
624 |
void CPsu2CopyToSimCmd::CreateSimContactsL()
|
|
625 |
{
|
|
626 |
iSimContacts.ResetAndDestroy();
|
|
627 |
iSimContactProcessor->CreateSimContactsL(
|
|
628 |
*iCurrentSourceContact, iSimContacts );
|
|
629 |
// Inspect that contact was copied completely
|
|
630 |
// if sim contacts has created.
|
|
631 |
if ( iIsCopiedCompletely && iSimContacts.Count() > 0 )
|
|
632 |
{
|
|
633 |
iIsCopiedCompletely = iContactInspector->IsCopiedCompletelyL
|
|
634 |
( *iCurrentSourceContact, iSimContacts );
|
|
635 |
}
|
|
636 |
if ( iSimContacts.Count() == 0 )
|
|
637 |
{
|
|
638 |
MoveToNextContact();
|
|
639 |
}
|
|
640 |
else
|
|
641 |
{
|
|
642 |
iNextTask = EStartCopy;
|
|
643 |
IssueRequest();
|
|
644 |
}
|
|
645 |
}
|
|
646 |
|
|
647 |
// --------------------------------------------------------------------------
|
|
648 |
// CPsu2CopyToSimCmd::StartCopyL()
|
|
649 |
// --------------------------------------------------------------------------
|
|
650 |
//
|
|
651 |
void CPsu2CopyToSimCmd::StartCopyL()
|
|
652 |
{
|
|
653 |
if ( iNameListUiControl )
|
|
654 |
{
|
|
655 |
// Blank UI control to avoid names list view refreshing
|
|
656 |
iNameListUiControl->SetBlank( ETrue );
|
|
657 |
}
|
|
658 |
|
|
659 |
CopyNextSimContact();
|
|
660 |
}
|
|
661 |
|
|
662 |
// --------------------------------------------------------------------------
|
|
663 |
// CPsu2CopyToSimCmd::CopyCurrentContactL
|
|
664 |
// --------------------------------------------------------------------------
|
|
665 |
//
|
|
666 |
void CPsu2CopyToSimCmd::CopyCurrentContactL()
|
|
667 |
{
|
|
668 |
delete iCurrentSimContact;
|
|
669 |
iCurrentSimContact = NextSimContact();
|
|
670 |
|
|
671 |
__ASSERT_DEBUG(iCurrentSimContact, Panic(EPreCond_CopyCurrentContactL));
|
|
672 |
// If the store is not open, just complete the copy process.
|
|
673 |
if( iTargetStoreStatus != EStoreOpen )
|
|
674 |
{
|
|
675 |
CompleteWithResults();
|
|
676 |
}
|
|
677 |
else
|
|
678 |
{
|
|
679 |
iCurrentSimContact->CommitL(*this);
|
|
680 |
}
|
|
681 |
}
|
|
682 |
|
|
683 |
// --------------------------------------------------------------------------
|
|
684 |
// CPsu2CopyToSimCmd::ShowResultsNoteL
|
|
685 |
// --------------------------------------------------------------------------
|
|
686 |
//
|
|
687 |
void CPsu2CopyToSimCmd::ShowResultsNoteL()
|
|
688 |
{
|
|
689 |
if (iLinkArray->Count() == KOne)
|
|
690 |
{
|
|
691 |
if (iCurrentSourceContact)
|
|
692 |
{
|
|
693 |
HBufC* title = iAppServices->NameFormatter().
|
|
694 |
GetContactTitleL(iCurrentSourceContact->Fields(),
|
|
695 |
MPbk2ContactNameFormatter::EPreserveLeadingSpaces);
|
|
696 |
CleanupStack::PushL(title);
|
|
697 |
TPsu2SimCopyResults results(iCopied, *title);
|
|
698 |
// Show partly copied note if necessary
|
|
699 |
if ( !iIsCopiedCompletely )
|
|
700 |
{
|
|
701 |
results.ShowPartlyCopiedNoteL();
|
|
702 |
}
|
|
703 |
else
|
|
704 |
{
|
|
705 |
results.ShowNoteL();
|
|
706 |
}
|
|
707 |
CleanupStack::PopAndDestroy(title);
|
|
708 |
}
|
|
709 |
else
|
|
710 |
{
|
|
711 |
TPsu2SimCopyResults results;
|
|
712 |
results.ShowErrorNoteL();
|
|
713 |
}
|
|
714 |
}
|
|
715 |
else
|
|
716 |
{
|
|
717 |
TPsu2SimCopyResults results(iCopied, iLinkArray->Count());
|
|
718 |
results.ShowNoteL();
|
|
719 |
// Show partly copied note if necessary
|
|
720 |
if ( !iIsCopiedCompletely )
|
|
721 |
{
|
|
722 |
results.ShowPartlyCopiedNoteL();
|
|
723 |
}
|
|
724 |
}
|
|
725 |
}
|
|
726 |
|
|
727 |
// --------------------------------------------------------------------------
|
|
728 |
// CPsu2CopyToSimCmd::CompleteL
|
|
729 |
// --------------------------------------------------------------------------
|
|
730 |
//
|
|
731 |
void CPsu2CopyToSimCmd::CompleteL()
|
|
732 |
{
|
|
733 |
if ( iUpdateControl && iNameListUiControl )
|
|
734 |
{
|
|
735 |
iNameListUiControl->SetBlank( EFalse );
|
|
736 |
// Reset find due to case that if contact was not really copied
|
|
737 |
// (=the target contact had already all the same fields) then
|
|
738 |
// UI control doesn't receive any events and find text is not
|
|
739 |
// reset by the UI control.
|
|
740 |
iNameListUiControl->ResetFindL();
|
|
741 |
if ( iCurrentSourceContact )
|
|
742 |
{
|
|
743 |
// Maintain NamesList focus on the source contact
|
|
744 |
iNameListUiControl->SetFocusedContactL( *iCurrentSourceContact );
|
|
745 |
}
|
|
746 |
// If the copy has been cancelled we don't want to update control.
|
|
747 |
// Markings are not removed after cancel.
|
|
748 |
iNameListUiControl->UpdateAfterCommandExecution();
|
|
749 |
}
|
|
750 |
if ( iCommandObserver )
|
|
751 |
{
|
|
752 |
iCommandObserver->CommandFinished(*this);
|
|
753 |
}
|
|
754 |
}
|
|
755 |
|
|
756 |
// --------------------------------------------------------------------------
|
|
757 |
// CPsu2CopyToSimCmd::NextSimContact
|
|
758 |
// --------------------------------------------------------------------------
|
|
759 |
//
|
|
760 |
MVPbkStoreContact* CPsu2CopyToSimCmd::NextSimContact()
|
|
761 |
{
|
|
762 |
if (iSimContacts.Count() > 0)
|
|
763 |
{
|
|
764 |
const TInt firstPos = 0;
|
|
765 |
MVPbkStoreContact* contact = iSimContacts[firstPos];
|
|
766 |
iSimContacts.Remove(firstPos);
|
|
767 |
return contact;
|
|
768 |
}
|
|
769 |
return NULL;
|
|
770 |
}
|
|
771 |
|
|
772 |
// --------------------------------------------------------------------------
|
|
773 |
// CPsu2CopyToSimCmd::HandleError
|
|
774 |
// --------------------------------------------------------------------------
|
|
775 |
//
|
|
776 |
void CPsu2CopyToSimCmd::HandleError(TInt aError)
|
|
777 |
{
|
|
778 |
switch (aError)
|
|
779 |
{
|
|
780 |
// Errors that can be ignored
|
|
781 |
case KErrGsm0707InvalidCharsInTextString: // FALLTHROUGH
|
|
782 |
case KErrGsm0707TextStringTooLong: // FALLTHROUGH
|
|
783 |
case KErrGsm0707DialStringTooLong: // FALLTHROUGH
|
|
784 |
case KErrGsmCCUnassignedNumber:
|
|
785 |
{
|
|
786 |
MoveToNextContact();
|
|
787 |
break;
|
|
788 |
}
|
|
789 |
default:
|
|
790 |
{
|
|
791 |
// If the copy was failed for memory full
|
|
792 |
if (aError == KErrGsm0707MemoryFull)
|
|
793 |
{
|
|
794 |
iIsLastCopyFailedForSimIsFull = ETrue;
|
|
795 |
}
|
|
796 |
CompleteWithResults();
|
|
797 |
CCoeEnv::Static()->HandleError(aError);
|
|
798 |
break;
|
|
799 |
}
|
|
800 |
}
|
|
801 |
}
|
|
802 |
|
|
803 |
// --------------------------------------------------------------------------
|
|
804 |
// CPsu2CopyToSimCmd::MoveToNextContact
|
|
805 |
// --------------------------------------------------------------------------
|
|
806 |
//
|
|
807 |
void CPsu2CopyToSimCmd::MoveToNextContact()
|
|
808 |
{
|
|
809 |
iDecorator->ProcessAdvance(KOne);
|
|
810 |
++iCurrentIndex;
|
|
811 |
iNextTask = ERetrieveSourceContact;
|
|
812 |
IssueRequest();
|
|
813 |
}
|
|
814 |
|
|
815 |
// --------------------------------------------------------------------------
|
|
816 |
// CPsu2CopyToSimCmd::CopyNextSimContact
|
|
817 |
// --------------------------------------------------------------------------
|
|
818 |
//
|
|
819 |
void CPsu2CopyToSimCmd::CopyNextSimContact()
|
|
820 |
{
|
|
821 |
CPsu2CopyToSimCmd::TSimSpaceStatus simSpaceStatus = ESimSpaceUnknown;
|
|
822 |
|
|
823 |
// Check always before copying that there is space for a new contact
|
|
824 |
TRAPD( res, simSpaceStatus = GetSimSpaceStatusL() )
|
|
825 |
if ( res != KErrNone )
|
|
826 |
{
|
|
827 |
HandleError( res );
|
|
828 |
}
|
|
829 |
else
|
|
830 |
{
|
|
831 |
iNextTask = ECopyContact;
|
|
832 |
if ( simSpaceStatus == ESimSpaceIsFull )
|
|
833 |
{
|
|
834 |
CompleteWithResults();
|
|
835 |
}
|
|
836 |
else
|
|
837 |
{
|
|
838 |
IssueRequest();
|
|
839 |
}
|
|
840 |
}
|
|
841 |
}
|
|
842 |
|
|
843 |
// --------------------------------------------------------------------------
|
|
844 |
// CPsu2CopyToSimCmd::CompleteWithResults
|
|
845 |
// --------------------------------------------------------------------------
|
|
846 |
//
|
|
847 |
void CPsu2CopyToSimCmd::CompleteWithResults()
|
|
848 |
{
|
|
849 |
iNextTask = EShowResultsAndComplete;
|
|
850 |
if ( iDecorator )
|
|
851 |
{
|
|
852 |
// This will cause a callback to ProcessDismissed
|
|
853 |
iDecorator->ProcessStopped();
|
|
854 |
}
|
|
855 |
else
|
|
856 |
{
|
|
857 |
IssueRequest();
|
|
858 |
}
|
|
859 |
}
|
|
860 |
|
|
861 |
// --------------------------------------------------------------------------
|
|
862 |
// CPsu2CopyToSimCmd::ShowNoteIfSimIsFullL
|
|
863 |
// --------------------------------------------------------------------------
|
|
864 |
//
|
|
865 |
CPsu2CopyToSimCmd::TSimSpaceStatus CPsu2CopyToSimCmd::GetSimSpaceStatusL()
|
|
866 |
{
|
|
867 |
const MVPbkContactStoreInfo& info = iTargetStore.StoreInfo();
|
|
868 |
|
|
869 |
if ( info.MaxNumberOfContactsL() <= 0 )
|
|
870 |
{
|
|
871 |
return ESimSpaceUnknown;
|
|
872 |
}
|
|
873 |
else if ( info.MaxNumberOfContactsL() == info.NumberOfContactsL() )
|
|
874 |
{
|
|
875 |
return ESimSpaceIsFull;
|
|
876 |
}
|
|
877 |
|
|
878 |
return ESimSpaceIsNotFull;
|
|
879 |
}
|
|
880 |
|
|
881 |
// --------------------------------------------------------------------------
|
|
882 |
// CPsu2CopyToSimCmd::ShowSimIsFullNoteL
|
|
883 |
// --------------------------------------------------------------------------
|
|
884 |
//
|
|
885 |
void CPsu2CopyToSimCmd::ShowSimIsFullNoteL()
|
|
886 |
{
|
|
887 |
const CPbk2StoreProperty* storeProperty =
|
|
888 |
iAppServices->StoreProperties().FindProperty(
|
|
889 |
iTargetStore.StoreProperties().Uri() );
|
|
890 |
|
|
891 |
// R_QTN_PHOB_NOTE_STORE_FULL is from Pbk2Commands and it's
|
|
892 |
// safe to use because commands resources are loaded in core pbk2
|
|
893 |
HBufC* fullText = StringLoader::LoadLC(
|
|
894 |
R_QTN_PHOB_NOTE_STORE_FULL,
|
|
895 |
storeProperty->StoreName() );
|
|
896 |
|
|
897 |
CAknInformationNote* noteDlg =
|
|
898 |
new(ELeave) CAknInformationNote( ETrue );
|
|
899 |
noteDlg->ExecuteLD( *fullText );
|
|
900 |
CleanupStack::PopAndDestroy( fullText );
|
|
901 |
}
|
|
902 |
|
|
903 |
// End of File
|