author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:54:53 +0300 | |
branch | RCL_3 |
changeset 21 | 9da50d567e3c |
parent 20 | f4a778e096c2 |
permissions | -rw-r--r-- |
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 add to top contacts launcher command |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
// INCLUDE FILES |
|
20 |
#include "CPbk2NlxAddToTopContactsCmd.h" |
|
21 |
||
22 |
#include <StringLoader.h> |
|
23 |
#include <aknnotewrappers.h> |
|
21
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
24 |
#include <pbk2uicontrols.rsg> |
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
25 |
#include <pbk2commonui.rsg> |
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
26 |
#include <pbk2cmdextres.rsg> |
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
27 |
#include <pbk2commands.rsg> |
20 | 28 |
|
29 |
#include <Pbk2ProcessDecoratorFactory.h> |
|
30 |
#include <CPbk2NamesListControl.h> |
|
31 |
#include <MPbk2CommandObserver.h> |
|
32 |
#include <MPbk2ContactUiControl.h> |
|
33 |
#include <CPbk2AppUiBase.h> |
|
34 |
#include <MPbk2ApplicationServices.h> |
|
35 |
#include <CVPbkContactManager.h> |
|
36 |
#include <VPbkContactStoreUris.h> |
|
37 |
#include <MVPbkContactStore.h> |
|
38 |
#include <MVPbkContactStoreProperties.h> |
|
39 |
#include <MVPbkContactOperationBase.h> |
|
40 |
#include <MVPbkContactLink.h> |
|
41 |
#include <MVPbkStoreContact.h> |
|
21
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
42 |
#include <pbk2exnameslistres.rsg> |
20 | 43 |
#include <Phonebook2PrivateCRKeys.h> |
44 |
#include <centralrepository.h> |
|
45 |
#include <CVPbkTopContactManager.h> |
|
46 |
#include <CPbk2FetchDlg.h> |
|
47 |
#include <MPbk2ContactViewSupplier.h> |
|
48 |
#include <MPbk2ContactViewSupplier2.h> |
|
49 |
#include <CPbk2ContactViewBuilder.h> |
|
50 |
#include <MVPbkContactViewBase.h> |
|
51 |
#include <CPbk2StoreConfiguration.h> |
|
52 |
#include <CVPbkContactStoreUriArray.h> |
|
53 |
#include <CPbk2StorePropertyArray.h> |
|
54 |
#include <CPbk2StoreProperty.h> |
|
55 |
#include <Pbk2StoreProperty.hrh> |
|
56 |
#include <CVPbkFilteredContactView.h> |
|
57 |
#include <CPbk2ContactRelocator.h> |
|
58 |
#include "TPbk2ContactIterator.h" |
|
59 |
||
60 |
// Debugging headers |
|
61 |
#include <Pbk2Debug.h> |
|
62 |
#include <Pbk2Profile.h> |
|
63 |
||
64 |
/// Unnamed namespace for local definitions |
|
65 |
namespace { |
|
66 |
||
67 |
enum TNlxPanicCodes |
|
68 |
{ |
|
69 |
ENlxAtcCommandObserverMissing, |
|
70 |
ENlxAtcSingleContactRelocation, |
|
71 |
ENlxAtcSingleContactRelocation2, |
|
72 |
ENlxAtcSingleTopContactOperation, |
|
73 |
ENlxAtcWronglyActivated, |
|
74 |
ENlxAtcDuplicateCallToExecuteLD, |
|
75 |
ENlxUnexpectedFailurePath, |
|
76 |
ENlxNoHighlightedContact, |
|
77 |
ENlxViewsAlreadyCreated, |
|
78 |
ENlxMergePrecond, |
|
79 |
ENlxRemoveSimPrecond, |
|
80 |
ENlxNoteActive |
|
81 |
}; |
|
82 |
||
83 |
void Panic(TNlxPanicCodes aReason) |
|
84 |
{ |
|
85 |
_LIT( KPanicText, "CPbk2_nlx_AddToTC" ); |
|
86 |
User::Panic(KPanicText,aReason); |
|
87 |
} |
|
88 |
||
89 |
CVPbkContactLinkArray* CloneL( |
|
90 |
const MVPbkContactLinkArray& aArray ) |
|
91 |
{ |
|
92 |
CVPbkContactLinkArray* newArray = CVPbkContactLinkArray::NewLC(); |
|
93 |
const TInt count = aArray.Count(); |
|
94 |
for ( TInt n = 0; n < count; ++n ) |
|
95 |
{ |
|
96 |
MVPbkContactLink* link = aArray.At(n).CloneLC(); |
|
97 |
newArray->AppendL( link ); |
|
98 |
CleanupStack::Pop(); // link |
|
99 |
} |
|
100 |
CleanupStack::Pop( newArray ); |
|
101 |
return newArray; |
|
102 |
} |
|
103 |
||
104 |
} /// namespace |
|
105 |
||
106 |
||
107 |
// -------------------------------------------------------------------------- |
|
108 |
// CPbk2NlxAddToTopContactsCmd::CPbk2NlxAddToTopContactsCmd |
|
109 |
// -------------------------------------------------------------------------- |
|
110 |
// |
|
111 |
CPbk2NlxAddToTopContactsCmd::CPbk2NlxAddToTopContactsCmd( |
|
112 |
MPbk2ContactUiControl& aUiControl, |
|
113 |
TBool aAddFavourites ) : |
|
114 |
CActive( EPriorityStandard ), |
|
115 |
iNextPhase( EPhaseNone ), |
|
116 |
iUiControl( &aUiControl ), |
|
117 |
iAddFavourites( aAddFavourites ) |
|
118 |
{ |
|
119 |
CActiveScheduler::Add( this ); |
|
120 |
} |
|
121 |
||
122 |
// -------------------------------------------------------------------------- |
|
123 |
// CPbk2NlxAddToTopContactsCmd::~CPbk2NlxAddToTopContactsCmd |
|
124 |
// -------------------------------------------------------------------------- |
|
125 |
// |
|
126 |
CPbk2NlxAddToTopContactsCmd::~CPbk2NlxAddToTopContactsCmd() |
|
127 |
{ |
|
128 |
PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
129 |
("CPbk2NlxAddToTopContactsCmd(%x)::~CPbk2NlxAddToTopContactsCmd()"), |
|
130 |
this); |
|
131 |
||
132 |
Cancel(); |
|
133 |
if (iUiControl) |
|
134 |
{ |
|
135 |
iUiControl->RegisterCommand( NULL ); |
|
136 |
} |
|
137 |
||
138 |
CleanAfterFetching(); |
|
139 |
delete iRelocatedContacts; |
|
140 |
delete iMarkedEntries; |
|
141 |
delete iContactIterator; |
|
142 |
delete iContactOperation; //Cancels request if pending |
|
143 |
delete iDelayedWaitNote; |
|
144 |
delete iVPbkTopContactManager; |
|
145 |
delete iContactRelocator; |
|
146 |
} |
|
147 |
||
148 |
// -------------------------------------------------------------------------- |
|
149 |
// CPbk2NlxAddToTopContactsCmd::NewL |
|
150 |
// -------------------------------------------------------------------------- |
|
151 |
// |
|
152 |
CPbk2NlxAddToTopContactsCmd* CPbk2NlxAddToTopContactsCmd::NewL( |
|
153 |
MPbk2ContactUiControl& aUiControl, TBool aAddFavourites ) |
|
154 |
{ |
|
155 |
CPbk2NlxAddToTopContactsCmd* self = |
|
156 |
new ( ELeave ) CPbk2NlxAddToTopContactsCmd( |
|
157 |
aUiControl, aAddFavourites ); |
|
158 |
CleanupStack::PushL( self ); |
|
159 |
self->ConstructL(); |
|
160 |
CleanupStack::Pop( self ); |
|
161 |
return self; |
|
162 |
} |
|
163 |
||
164 |
// -------------------------------------------------------------------------- |
|
165 |
// CPbk2NlxAddToTopContactsCmd::ConstructL |
|
166 |
// -------------------------------------------------------------------------- |
|
167 |
// |
|
168 |
void CPbk2NlxAddToTopContactsCmd::ConstructL() |
|
169 |
{ |
|
170 |
if( iUiControl ) |
|
171 |
{ |
|
172 |
iUiControl->RegisterCommand( this ); |
|
173 |
} |
|
174 |
||
175 |
iContactManager = |
|
176 |
&Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager(); |
|
177 |
||
178 |
// For performance optimization, get the top contacts view |
|
179 |
// from pbk2 applications services and provide to top contact |
|
180 |
// manager if the view is available |
|
181 |
||
182 |
MPbk2ContactViewSupplier2* viewSupplierExtension = |
|
183 |
reinterpret_cast<MPbk2ContactViewSupplier2*>( |
|
184 |
Phonebook2::Pbk2AppUi()->ApplicationServices().ViewSupplier(). |
|
185 |
MPbk2ContactViewSupplierExtension( |
|
186 |
KMPbk2ContactViewSupplierExtension2Uid )); |
|
187 |
||
188 |
MVPbkContactViewBase* topContactsView = viewSupplierExtension->TopContactsViewL(); |
|
189 |
if ( topContactsView ) |
|
190 |
{ |
|
191 |
iVPbkTopContactManager = CVPbkTopContactManager::NewL( *iContactManager, |
|
192 |
*topContactsView); |
|
193 |
} |
|
194 |
else |
|
195 |
{ |
|
196 |
iVPbkTopContactManager = CVPbkTopContactManager::NewL( *iContactManager ); |
|
197 |
} |
|
198 |
||
199 |
} |
|
200 |
||
201 |
// -------------------------------------------------------------------------- |
|
202 |
// CPbk2NlxAddToTopContactsCmd::ExecuteLD |
|
203 |
// -------------------------------------------------------------------------- |
|
204 |
// |
|
205 |
void CPbk2NlxAddToTopContactsCmd::ExecuteLD() |
|
206 |
{ |
|
207 |
__ASSERT_ALWAYS( iCommandObserver, Panic( ENlxAtcCommandObserverMissing )); |
|
208 |
__ASSERT_ALWAYS( !IsActive(), Panic( ENlxAtcWronglyActivated )); |
|
209 |
__ASSERT_ALWAYS( iNextPhase == EPhaseNone, Panic( ENlxAtcDuplicateCallToExecuteLD )); |
|
210 |
||
211 |
if( iUiControl ) |
|
212 |
{ |
|
213 |
iUiControl->SetBlank( ETrue ); |
|
214 |
} |
|
215 |
||
216 |
if ( iAddFavourites ) |
|
217 |
{ |
|
218 |
// The user has started the "Add favorites" namesList command. |
|
219 |
// Launch Fetch dialog asynchronously. |
|
220 |
GetSelectionWithFetchUiL(); |
|
221 |
// The Fetch dialog will inform fetch completion with a callback. |
|
222 |
} |
|
223 |
else |
|
224 |
{ |
|
225 |
// The user has selected "Set as favorite" from options menu. |
|
226 |
GetUiControlSelectionL(); |
|
227 |
} |
|
228 |
||
229 |
//This can be deleted only when callback of operation is done. |
|
230 |
//Ownership of this object is in caller (i.e. CPbk2CommandActivator) |
|
231 |
//No push and pop to cleanupstack in this function must be done. |
|
232 |
} |
|
233 |
||
234 |
// -------------------------------------------------------------------------- |
|
235 |
// CPbk2NlxAddToTopContactsCmd::ResetUiControl |
|
236 |
// -------------------------------------------------------------------------- |
|
237 |
// |
|
238 |
void CPbk2NlxAddToTopContactsCmd::ResetUiControl( |
|
239 |
MPbk2ContactUiControl& aUiControl ) |
|
240 |
{ |
|
241 |
if ( iUiControl == &aUiControl ) |
|
242 |
{ |
|
243 |
iUiControl = NULL; |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
// -------------------------------------------------------------------------- |
|
248 |
// CPbk2NlxAddToTopContactsCmd::AddObserver |
|
249 |
// -------------------------------------------------------------------------- |
|
250 |
// |
|
251 |
void CPbk2NlxAddToTopContactsCmd::AddObserver( |
|
252 |
MPbk2CommandObserver& aObserver ) |
|
253 |
{ |
|
254 |
iCommandObserver = &aObserver; |
|
255 |
} |
|
256 |
||
257 |
||
258 |
// -------------------------------------------------------------------------- |
|
259 |
// CPbk2NlxAddToTopContactsCmd::RunL |
|
260 |
// -------------------------------------------------------------------------- |
|
261 |
// |
|
262 |
void CPbk2NlxAddToTopContactsCmd::RunL() |
|
263 |
{ |
|
264 |
if( !iUiControl ) |
|
265 |
{ |
|
266 |
//UiControl reseted, so cancel all processing |
|
267 |
iNextPhase = EFinish ; |
|
268 |
} |
|
269 |
||
270 |
switch( iNextPhase ) |
|
271 |
{ |
|
272 |
case ERelocate: |
|
273 |
{ |
|
274 |
CleanAfterFetching(); |
|
275 |
const TInt numberOfSimContacts = CountSimContacts(); |
|
276 |
if ( numberOfSimContacts > 0 ) |
|
277 |
{ |
|
278 |
StartSimContactsRelocationL(); |
|
279 |
iNextPhase = ESetAsTopContact; |
|
280 |
} |
|
281 |
else |
|
282 |
{ |
|
283 |
StartNext(ESetAsTopContact); |
|
284 |
} |
|
285 |
ShowDelayedWaitNoteL(); |
|
286 |
} |
|
287 |
break; |
|
288 |
case ESetAsTopContact: |
|
289 |
{ |
|
290 |
// prepare iMarkedEntries |
|
291 |
ReplaceSimContactsL(); |
|
292 |
// set as top |
|
293 |
iContactOperation = iVPbkTopContactManager->AddToTopL( |
|
294 |
*iMarkedEntries, |
|
295 |
*this, |
|
296 |
*this ); |
|
297 |
} |
|
298 |
break; |
|
299 |
case EFinish: |
|
300 |
{ |
|
301 |
if (iUiControl) |
|
302 |
{ |
|
303 |
iUiControl->SetBlank(EFalse); |
|
304 |
iUiControl->UpdateAfterCommandExecution(); |
|
305 |
} |
|
306 |
if ( iCommandObserver ) |
|
307 |
{ |
|
308 |
iCommandObserver->CommandFinished( *this ); |
|
309 |
} |
|
310 |
} |
|
311 |
break; |
|
312 |
default: |
|
313 |
Panic( ENlxAtcWronglyActivated ); |
|
314 |
break; |
|
315 |
} |
|
316 |
} |
|
317 |
||
318 |
// -------------------------------------------------------------------------- |
|
319 |
// CPbk2NlxAddToTopContactsCmd::RunError |
|
320 |
// -------------------------------------------------------------------------- |
|
321 |
// |
|
322 |
TInt CPbk2NlxAddToTopContactsCmd::RunError(TInt aError) |
|
323 |
{ |
|
324 |
Finish( aError ); |
|
325 |
return KErrNone; |
|
326 |
} |
|
327 |
||
328 |
// -------------------------------------------------------------------------- |
|
329 |
// CPbk2NlxAddToTopContactsCmd::DoCancel |
|
330 |
// -------------------------------------------------------------------------- |
|
331 |
// |
|
332 |
void CPbk2NlxAddToTopContactsCmd::DoCancel() |
|
333 |
{ |
|
334 |
} |
|
335 |
||
336 |
MPbk2FetchDlgObserver::TPbk2FetchAcceptSelection CPbk2NlxAddToTopContactsCmd::AcceptFetchSelectionL( |
|
337 |
TInt /*aNumMarkedEntries*/, |
|
338 |
MVPbkContactLink& /*aLastSelection*/ ) |
|
339 |
{ |
|
340 |
return MPbk2FetchDlgObserver::EFetchYes; |
|
341 |
} |
|
342 |
||
343 |
void CPbk2NlxAddToTopContactsCmd::FetchCompletedL( |
|
344 |
MVPbkContactLinkArray* aMarkedEntries ) |
|
345 |
{ |
|
346 |
// Don't take ownership of aMarkedEntries! |
|
347 |
||
348 |
// If nothing was marked, then aMarkedEntries can be NULL |
|
349 |
if ( aMarkedEntries ) |
|
350 |
{ |
|
351 |
// Yes, something was selected by user. |
|
352 |
iMarkedEntries = CloneL( *aMarkedEntries ); |
|
353 |
TPbk2ContactIterator* iterator = new (ELeave) TPbk2ContactIterator; |
|
354 |
iterator->SetLinkArray( *iMarkedEntries ); |
|
355 |
delete iContactIterator; |
|
356 |
iContactIterator = iterator; // takes ownership |
|
357 |
||
358 |
StartNext(); // Goes to RunL() |
|
359 |
} |
|
360 |
else |
|
361 |
{ |
|
362 |
// Nothing was selected by user. |
|
363 |
Finish( KErrNone ); |
|
364 |
} |
|
365 |
} |
|
366 |
||
367 |
void CPbk2NlxAddToTopContactsCmd::FetchCanceled() |
|
368 |
{ |
|
369 |
Finish( KErrCancel ); |
|
370 |
} |
|
371 |
||
372 |
void CPbk2NlxAddToTopContactsCmd::FetchAborted() |
|
373 |
{ |
|
374 |
Finish( KErrCancel ); |
|
375 |
} |
|
376 |
||
377 |
TBool CPbk2NlxAddToTopContactsCmd::FetchOkToExit() |
|
378 |
{ |
|
379 |
return ETrue; |
|
380 |
} |
|
381 |
||
382 |
void CPbk2NlxAddToTopContactsCmd::GetSelectionWithFetchUiL() |
|
383 |
{ |
|
384 |
__ASSERT_DEBUG( !iNonEmptyGroupsView, Panic( ENlxViewsAlreadyCreated )); |
|
385 |
__ASSERT_DEBUG( !iAllContactsView, Panic( ENlxViewsAlreadyCreated )); |
|
386 |
||
387 |
CPbk2FetchDlg::TParams params; |
|
388 |
params.iResId = R_PBK2_MULTIPLE_ENTRY_FETCH_DLG; |
|
389 |
||
390 |
CPbk2StorePropertyArray& storeProperties = |
|
391 |
Phonebook2::Pbk2AppUi()->ApplicationServices().StoreProperties(); |
|
392 |
CPbk2ContactViewBuilder* viewBuilder = CPbk2ContactViewBuilder::NewLC |
|
393 |
( *iContactManager, |
|
394 |
storeProperties ); |
|
395 |
||
396 |
// Fetch dlg uses this view instead of AllNameslistView |
|
397 |
iStoreUris = |
|
398 |
Phonebook2::Pbk2AppUi()->ApplicationServices().StoreConfiguration().CurrentConfigurationL(); |
|
399 |
TBool createNewView = EFalse; |
|
400 |
for ( TInt i = iStoreUris->Count()-1; i >= 0; --i ) |
|
401 |
{ |
|
402 |
const CPbk2StoreProperty* storeProperty = |
|
403 |
storeProperties.FindProperty( (*iStoreUris)[i] ); |
|
404 |
if ( !( storeProperty->Flags() & KPbk2DefaultSavingStorageItem ) ) |
|
405 |
{ |
|
406 |
// Remove read only URI from the array |
|
407 |
iStoreUris->Remove( (*iStoreUris)[i] ); |
|
408 |
createNewView = ETrue; |
|
409 |
} |
|
410 |
} |
|
411 |
||
412 |
if ( createNewView ) |
|
413 |
{ |
|
414 |
iAllContactsView = CVPbkFilteredContactView::NewL |
|
415 |
( *Phonebook2::Pbk2AppUi()->ApplicationServices().ViewSupplier(). |
|
416 |
AllContactsViewL(), *this, *this, |
|
417 |
iContactManager->FieldTypes() ); |
|
418 |
||
419 |
params.iNamesListView = iAllContactsView; |
|
420 |
} |
|
421 |
else |
|
422 |
{ |
|
423 |
params.iNamesListView = |
|
424 |
Phonebook2::Pbk2AppUi()->ApplicationServices().ViewSupplier().AllContactsViewL(); |
|
425 |
} |
|
426 |
||
427 |
// create group view without empty groups |
|
428 |
||
429 |
//use ready sort order from normal AllGroups view |
|
430 |
const MVPbkFieldTypeList& sortOrder = |
|
431 |
Phonebook2::Pbk2AppUi()->ApplicationServices().ViewSupplier().AllGroupsViewL()->SortOrder(); |
|
432 |
iNonEmptyGroupsView = viewBuilder->CreateGroupViewForStoresLC |
|
433 |
( *iStoreUris, *this, sortOrder, |
|
434 |
NULL, // no view filtering |
|
435 |
EVPbkExcludeEmptyGroups ); |
|
436 |
CleanupStack::Pop(); // iNonEmptyGroupsView |
|
437 |
||
438 |
CleanupStack::PopAndDestroy( viewBuilder ); |
|
439 |
//CleanupStack::PopAndDestroy( storeUris ); |
|
440 |
||
441 |
params.iGroupsListView = iNonEmptyGroupsView; |
|
442 |
params.iFlags = CPbk2FetchDlg::EFetchMultiple; |
|
443 |
||
444 |
CPbk2FetchDlg* dlg = CPbk2FetchDlg::NewL( params, *this ); |
|
445 |
iFetchDlgEliminator = dlg; |
|
446 |
iFetchDlgEliminator->ResetWhenDestroyed( &iFetchDlgEliminator ); |
|
447 |
||
448 |
// The ExecuteLD is asyncrhonous. |
|
449 |
dlg->ExecuteLD(); // Completion is signalled with a callback. |
|
450 |
||
451 |
iNextPhase = ERelocate; |
|
452 |
} |
|
453 |
||
454 |
TBool CPbk2NlxAddToTopContactsCmd::IsContactIncluded |
|
455 |
( const MVPbkBaseContact& aContact ) |
|
456 |
{ |
|
457 |
for ( TInt i = iStoreUris->Count()-1; i >= 0; --i ) |
|
458 |
{ |
|
459 |
if ( aContact.MatchContactStore((*iStoreUris)[i].UriDes()) ) |
|
460 |
{ |
|
461 |
return ETrue; |
|
462 |
} |
|
463 |
} |
|
464 |
||
465 |
return EFalse; |
|
466 |
} |
|
467 |
||
468 |
// insure the fetch dlg is deleted and destroy resources used by it |
|
469 |
void CPbk2NlxAddToTopContactsCmd::CleanAfterFetching() |
|
470 |
{ |
|
471 |
if ( iFetchDlgEliminator ) |
|
472 |
{ |
|
473 |
iFetchDlgEliminator->ForceExit(); |
|
474 |
} |
|
475 |
delete iNonEmptyGroupsView; |
|
476 |
iNonEmptyGroupsView = NULL; |
|
477 |
delete iAllContactsView; |
|
478 |
iAllContactsView = NULL; |
|
479 |
delete iStoreUris; |
|
480 |
iStoreUris = NULL; |
|
481 |
} |
|
482 |
||
483 |
void CPbk2NlxAddToTopContactsCmd::GetUiControlSelectionL() |
|
484 |
{ |
|
485 |
// First delete any previous iterator. |
|
486 |
if ( iUiControl ) |
|
487 |
{ |
|
488 |
delete iContactIterator; |
|
489 |
iContactIterator = NULL; |
|
490 |
||
491 |
// Take the selection from the UI control. |
|
492 |
const MVPbkBaseContact* contact = NULL; |
|
493 |
iContactIterator = iUiControl->SelectedContactsIteratorL(); |
|
494 |
if ( !iContactIterator ) |
|
495 |
{ |
|
496 |
// Nothing was marked. Use the highlighted contact. |
|
497 |
delete iMarkedEntries; |
|
498 |
iMarkedEntries = NULL; |
|
499 |
contact = iUiControl->FocusedContactL(); |
|
500 |
if (contact) |
|
501 |
{ |
|
502 |
MVPbkContactLink* link = contact->CreateLinkLC(); |
|
503 |
CVPbkContactLinkArray* array = CVPbkContactLinkArray::NewL(); |
|
504 |
iMarkedEntries = array; // take ownership here |
|
505 |
array->AppendL( link ); |
|
506 |
CleanupStack::Pop(); // link |
|
507 |
// Create an iterator for the link array. |
|
508 |
TPbk2ContactIterator* iterator = new (ELeave) TPbk2ContactIterator; |
|
509 |
iterator->SetLinkArray( *iMarkedEntries ); |
|
510 |
iContactIterator = iterator; |
|
511 |
} |
|
512 |
} |
|
513 |
if (contact) |
|
514 |
{ |
|
515 |
StartNext(ERelocate); |
|
516 |
} |
|
517 |
else |
|
518 |
{ |
|
519 |
Finish(KErrNone); |
|
520 |
} |
|
521 |
} |
|
522 |
} |
|
523 |
||
524 |
TInt CPbk2NlxAddToTopContactsCmd::CountSimContacts() const |
|
525 |
{ |
|
526 |
TInt result = 0; |
|
527 |
||
528 |
const TInt markedCount = iMarkedEntries->Count(); |
|
529 |
for (TInt i = 0; i < markedCount; ++i) |
|
530 |
{ |
|
531 |
if ( !iMarkedEntries->At(i).ContactStore().StoreProperties().Uri().Compare( |
|
532 |
VPbkContactStoreUris::SimGlobalAdnUri(), |
|
533 |
TVPbkContactStoreUriPtr::EContactStoreUriAllComponents)) |
|
534 |
{ |
|
535 |
++result; |
|
536 |
} |
|
537 |
} |
|
538 |
||
539 |
return result; |
|
540 |
} |
|
541 |
||
542 |
CVPbkContactLinkArray* CPbk2NlxAddToTopContactsCmd::CreateSimContactsArrayLC() const |
|
543 |
{ |
|
544 |
CVPbkContactLinkArray* result = CVPbkContactLinkArray::NewLC(); |
|
545 |
iContactIterator->SetToFirst(); |
|
546 |
while( iContactIterator->HasNext() ) |
|
547 |
{ |
|
548 |
MVPbkContactLink* link = iContactIterator->NextL(); |
|
549 |
CleanupDeletePushL( link ); |
|
550 |
||
551 |
if ( !link->ContactStore().StoreProperties().Uri().Compare( |
|
552 |
VPbkContactStoreUris::SimGlobalAdnUri(), |
|
553 |
TVPbkContactStoreUriPtr::EContactStoreUriAllComponents)) |
|
554 |
{ |
|
555 |
result->AppendL(link); |
|
556 |
CleanupStack::Pop(); // link |
|
557 |
} |
|
558 |
else |
|
559 |
{ |
|
560 |
CleanupStack::PopAndDestroy(); // link |
|
561 |
} |
|
562 |
} |
|
563 |
||
564 |
return result; |
|
565 |
} |
|
566 |
||
567 |
// Replace or remove sim contact links from iMarkedEntries |
|
568 |
void CPbk2NlxAddToTopContactsCmd::ReplaceSimContactsL() |
|
569 |
{ |
|
570 |
__ASSERT_DEBUG( iMarkedEntries, Panic(ENlxMergePrecond) ); |
|
571 |
||
572 |
for (TInt i = iMarkedEntries->Count()-1; i >= 0; --i) |
|
573 |
{ |
|
574 |
if ( !iMarkedEntries->At(i).ContactStore().StoreProperties().Uri().Compare( |
|
575 |
VPbkContactStoreUris::SimGlobalAdnUri(), |
|
576 |
TVPbkContactStoreUriPtr::EContactStoreUriAllComponents)) |
|
577 |
{ |
|
578 |
// replace link with relocated contact link if there are any, |
|
579 |
// otherwise just delete it |
|
580 |
iMarkedEntries->Delete(i); |
|
581 |
if ( iRelocatedContacts && iRelocatedContacts->Count() > 0 ) |
|
582 |
{ |
|
583 |
const TInt lastLinkIndex = iRelocatedContacts->Count()-1; |
|
584 |
MVPbkContactLink* link = iRelocatedContacts->At(lastLinkIndex).CloneLC(); |
|
585 |
iMarkedEntries->InsertL( link, i ); |
|
586 |
CleanupStack::Pop();//link |
|
587 |
iRelocatedContacts->Delete(lastLinkIndex); |
|
588 |
} |
|
589 |
} |
|
590 |
} |
|
591 |
} |
|
592 |
||
593 |
void CPbk2NlxAddToTopContactsCmd::StartSimContactsRelocationL() |
|
594 |
{ |
|
595 |
if( !iContactRelocator ) |
|
596 |
{ |
|
597 |
iContactRelocator = CPbk2ContactRelocator::NewL(); |
|
598 |
} |
|
599 |
CVPbkContactLinkArray* simContacts = CreateSimContactsArrayLC(); |
|
600 |
iContactRelocator->RelocateContactsL( |
|
601 |
simContacts, |
|
602 |
*this, |
|
603 |
Pbk2ContactRelocator::EPbk2DisplayNoQueries ); |
|
604 |
//Relocator took ownership |
|
605 |
CleanupStack::Pop(); //simContacts |
|
606 |
} |
|
607 |
||
608 |
// --------------------------------------------------------------------------- |
|
609 |
// CPbk2NlxAddToTopContactsCmd::Finish |
|
610 |
// --------------------------------------------------------------------------- |
|
611 |
// |
|
612 |
void CPbk2NlxAddToTopContactsCmd::Finish( TInt aReason ) |
|
613 |
{ |
|
614 |
if ( aReason != KErrNone && aReason != KErrCancel ) |
|
615 |
{ |
|
616 |
CCoeEnv::Static()->HandleError( aReason ); |
|
617 |
} |
|
618 |
||
619 |
if ( iDelayedWaitNote ) |
|
620 |
{ |
|
621 |
// wait for callback from the wait note and finish then |
|
622 |
iDelayedWaitNote->Stop(); |
|
623 |
} |
|
624 |
else |
|
625 |
{ |
|
626 |
StartNext( EFinish ); |
|
627 |
} |
|
628 |
} |
|
629 |
||
630 |
// --------------------------------------------------------------------------- |
|
631 |
// CPbk2NlxAddToTopContactsCmd::StartNext |
|
632 |
// --------------------------------------------------------------------------- |
|
633 |
// |
|
634 |
void CPbk2NlxAddToTopContactsCmd::StartNext( TPhase aPhase ) |
|
635 |
{ |
|
636 |
__ASSERT_DEBUG( !IsActive(), Panic( ENlxAtcWronglyActivated )); |
|
637 |
iNextPhase = aPhase; |
|
638 |
TRequestStatus* status = &iStatus; |
|
639 |
User::RequestComplete(status, KErrNone); |
|
640 |
SetActive(); |
|
641 |
} |
|
642 |
||
643 |
// --------------------------------------------------------------------------- |
|
644 |
// CPbk2NlxAddToTopContactsCmd::StartNext |
|
645 |
// --------------------------------------------------------------------------- |
|
646 |
// |
|
647 |
void CPbk2NlxAddToTopContactsCmd::StartNext() |
|
648 |
{ |
|
649 |
__ASSERT_DEBUG( !IsActive(), Panic( ENlxAtcWronglyActivated )); |
|
650 |
TRequestStatus* status = &iStatus; |
|
651 |
User::RequestComplete(status, KErrNone); |
|
652 |
SetActive(); |
|
653 |
} |
|
654 |
||
655 |
// --------------------------------------------------------------------------- |
|
656 |
// CPbk2NlxAddToTopContactsCmd::ShowDelayedWaitNoteL |
|
657 |
// --------------------------------------------------------------------------- |
|
658 |
// |
|
659 |
void CPbk2NlxAddToTopContactsCmd::ShowDelayedWaitNoteL() |
|
660 |
{ |
|
661 |
if ( !iDelayedWaitNote ) |
|
662 |
{ |
|
663 |
iDelayedWaitNote = CPbk2DelayedWaitNote::NewL(*this, R_QTN_GEN_NOTE_SAVING_WAIT); |
|
664 |
iDelayedWaitNote->Start(); |
|
665 |
} |
|
666 |
} |
|
667 |
||
668 |
// --------------------------------------------------------------------------- |
|
669 |
// CPbk2NlxAddToTopContactsCmd::ProcessDismissed |
|
670 |
// --------------------------------------------------------------------------- |
|
671 |
// |
|
672 |
void CPbk2NlxAddToTopContactsCmd::ProcessDismissed( TInt /*aCancelCode*/ ) |
|
673 |
{ |
|
674 |
StartNext( EFinish ); |
|
675 |
} |
|
676 |
||
677 |
////////////////////////////// CALLBACKS ///////////////////////////////////// |
|
678 |
||
679 |
// --------------------------------------------------------------------------- |
|
680 |
// CPbk2NlxAddToTopContactsCmd::ContactRelocatedL |
|
681 |
// --------------------------------------------------------------------------- |
|
682 |
// |
|
683 |
void CPbk2NlxAddToTopContactsCmd::ContactRelocatedL( |
|
684 |
MVPbkStoreContact* aRelocatedContact ) |
|
685 |
{ |
|
686 |
__ASSERT_DEBUG( iNextPhase == ESetAsTopContact, |
|
687 |
Panic( ENlxAtcSingleContactRelocation )); |
|
688 |
||
689 |
if ( !iRelocatedContacts ) |
|
690 |
{ |
|
691 |
iRelocatedContacts = CVPbkContactLinkArray::NewL(); |
|
692 |
} |
|
693 |
||
694 |
MVPbkContactLink* link = aRelocatedContact->CreateLinkLC(); |
|
695 |
iRelocatedContacts->AppendL( link ); |
|
696 |
CleanupStack::Pop(); //link |
|
697 |
||
698 |
// top contact manager needs links, delete store contacts |
|
699 |
delete aRelocatedContact; |
|
700 |
} |
|
701 |
||
702 |
// --------------------------------------------------------------------------- |
|
703 |
// CPbk2NlxAddToTopContactsCmd::ContactRelocationFailed |
|
704 |
// --------------------------------------------------------------------------- |
|
705 |
// |
|
706 |
void CPbk2NlxAddToTopContactsCmd::ContactRelocationFailed( |
|
707 |
TInt /* aReason */, |
|
708 |
MVPbkStoreContact* /* aContact */ ) |
|
709 |
{ |
|
710 |
if ( iDelayedWaitNote ) |
|
711 |
{ |
|
712 |
// wait for callback from the wait note and finish then |
|
713 |
iDelayedWaitNote->Stop(); |
|
714 |
} |
|
715 |
else |
|
716 |
{ |
|
717 |
StartNext( EFinish ); |
|
718 |
} |
|
719 |
} |
|
720 |
||
721 |
// --------------------------------------------------------------------------- |
|
722 |
// CPbk2NlxAddToTopContactsCmd::ContactsRelocationFailed |
|
723 |
// --------------------------------------------------------------------------- |
|
724 |
// |
|
725 |
void CPbk2NlxAddToTopContactsCmd::ContactsRelocationFailed( |
|
726 |
TInt aReason, |
|
727 |
CVPbkContactLinkArray* aContacts ) |
|
728 |
{ |
|
729 |
delete aContacts; |
|
730 |
CCoeEnv::Static()->HandleError( aReason ); |
|
731 |
} |
|
732 |
||
733 |
||
734 |
// --------------------------------------------------------------------------- |
|
735 |
// CPbk2NlxAddToTopContactsCmd::RelocationProcessComplete |
|
736 |
// --------------------------------------------------------------------------- |
|
737 |
// |
|
738 |
void CPbk2NlxAddToTopContactsCmd::RelocationProcessComplete() |
|
739 |
{ |
|
740 |
__ASSERT_DEBUG( iNextPhase == ESetAsTopContact, |
|
741 |
Panic( ENlxAtcSingleContactRelocation2 )); |
|
742 |
||
743 |
if ( iRelocatedContacts && iRelocatedContacts->Count() > 0 ) |
|
744 |
{ |
|
745 |
// All is OK. |
|
746 |
StartNext(); |
|
747 |
} |
|
748 |
else |
|
749 |
{ |
|
750 |
// Some error has occured. The error has already been handled |
|
751 |
// in ContactRelocationFailed(). |
|
752 |
Finish( KErrNone ); |
|
753 |
} |
|
754 |
} |
|
755 |
||
756 |
// --------------------------------------------------------------------------- |
|
757 |
// CPbk2NlxAddToTopContactsCmd::TopOperationCompleted |
|
758 |
// --------------------------------------------------------------------------- |
|
759 |
// |
|
760 |
void CPbk2NlxAddToTopContactsCmd::VPbkOperationCompleted( |
|
761 |
MVPbkContactOperationBase*) |
|
762 |
{ |
|
763 |
// This is a callback for CVPbkTopContactManager::AddToTopL() |
|
764 |
__ASSERT_DEBUG( iNextPhase == ESetAsTopContact, |
|
765 |
Panic( ENlxAtcSingleTopContactOperation )); |
|
766 |
Finish( KErrNone ); |
|
767 |
} |
|
768 |
||
769 |
// --------------------------------------------------------------------------- |
|
770 |
// CPbk2NlxAddToTopContactsCmd::TopErrorOccured |
|
771 |
// --------------------------------------------------------------------------- |
|
772 |
// |
|
773 |
void CPbk2NlxAddToTopContactsCmd::VPbkOperationFailed( |
|
774 |
MVPbkContactOperationBase*,TInt aError ) |
|
775 |
{ |
|
776 |
__ASSERT_DEBUG( iNextPhase == ESetAsTopContact, |
|
777 |
Panic( ENlxAtcSingleTopContactOperation )); |
|
778 |
Finish( aError ); |
|
779 |
} |
|
780 |
||
781 |
// -------------------------------------------------------------------------- |
|
782 |
// CPbk2NlxAddToTopContactsCmd::ContactViewReady |
|
783 |
// -------------------------------------------------------------------------- |
|
784 |
// |
|
785 |
void CPbk2NlxAddToTopContactsCmd::ContactViewReady |
|
786 |
( MVPbkContactViewBase& /*aView*/ ) |
|
787 |
{ |
|
788 |
// Do nothing |
|
789 |
} |
|
790 |
||
791 |
// -------------------------------------------------------------------------- |
|
792 |
// CPbk2NlxAddToTopContactsCmd::ContactViewUnavailable |
|
793 |
// -------------------------------------------------------------------------- |
|
794 |
// |
|
795 |
void CPbk2NlxAddToTopContactsCmd::ContactViewUnavailable |
|
796 |
( MVPbkContactViewBase& /*aView*/ ) |
|
797 |
{ |
|
798 |
// Do nothing |
|
799 |
} |
|
800 |
||
801 |
// -------------------------------------------------------------------------- |
|
802 |
// CPbk2NlxAddToTopContactsCmd::ContactAddedToView |
|
803 |
// -------------------------------------------------------------------------- |
|
804 |
// |
|
805 |
void CPbk2NlxAddToTopContactsCmd::ContactAddedToView |
|
806 |
( MVPbkContactViewBase& /*aView*/, TInt /*aIndex*/, |
|
807 |
const MVPbkContactLink& /*aContactLink*/ ) |
|
808 |
{ |
|
809 |
// Do nothing |
|
810 |
} |
|
811 |
||
812 |
// -------------------------------------------------------------------------- |
|
813 |
// CPbk2NlxAddToTopContactsCmd::ContactRemovedFromView |
|
814 |
// -------------------------------------------------------------------------- |
|
815 |
// |
|
816 |
void CPbk2NlxAddToTopContactsCmd::ContactRemovedFromView |
|
817 |
( MVPbkContactViewBase& /*aView*/, TInt /*aIndex*/, |
|
818 |
const MVPbkContactLink& /*aContactLink*/ ) |
|
819 |
{ |
|
820 |
// Do nothing |
|
821 |
} |
|
822 |
||
823 |
// -------------------------------------------------------------------------- |
|
824 |
// CPbk2NlxAddToTopContactsCmd::ContactViewError |
|
825 |
// -------------------------------------------------------------------------- |
|
826 |
// |
|
827 |
void CPbk2NlxAddToTopContactsCmd::ContactViewError |
|
828 |
( MVPbkContactViewBase& /*aView*/, TInt /*aError*/, |
|
829 |
TBool /*aErrorNotified*/ ) |
|
830 |
{ |
|
831 |
// Do nothing |
|
832 |
} |
|
833 |
||
834 |
// End of File |