|
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 server app contact data assign phase. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2SingleAssignDataPhase.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "MPbk2ServicePhaseObserver.h" |
|
23 #include "CPbk2ServerAppAppUi.h" |
|
24 #include "MPbk2ContactAssigner.h" |
|
25 #include "Pbk2ContactAssignerFactory.h" |
|
26 #include "CPbk2ContactEditorOperator.h" |
|
27 #include "MPbk2SelectFieldProperty.h" |
|
28 #include "TPbk2AssignNoteService.h" |
|
29 #include "Pbk2ServerApp.hrh" |
|
30 #include <MPbk2DialogEliminator.h> |
|
31 #include <TPbk2DestructionIndicator.h> |
|
32 #include <CPbk2StoreConfiguration.h> |
|
33 #include <MPbk2ApplicationServices.h> |
|
34 #include <Pbk2UIControls.rsg> |
|
35 #include <Pbk2ServerApp.rsg> |
|
36 |
|
37 // Virtual Phonebook |
|
38 #include <MVPbkContactLink.h> |
|
39 #include <CVPbkContactLinkArray.h> |
|
40 #include <MVPbkContactOperationBase.h> |
|
41 #include <MVPbkStoreContact.h> |
|
42 #include <MVPbkContactStore.h> |
|
43 #include <CVPbkContactManager.h> |
|
44 #include <MVPbkContactStoreProperties.h> |
|
45 #include <VPbkContactStoreUris.h> |
|
46 #include <CVPbkContactStoreUriArray.h> |
|
47 |
|
48 // System includes |
|
49 #include <AiwContactAssignDataTypes.h> |
|
50 |
|
51 using namespace AiwContactAssign; |
|
52 |
|
53 // -------------------------------------------------------------------------- |
|
54 // CPbk2SingleAssignDataPhase::CPbk2SingleAssignDataPhase |
|
55 // -------------------------------------------------------------------------- |
|
56 // |
|
57 CPbk2SingleAssignDataPhase::CPbk2SingleAssignDataPhase |
|
58 ( MPbk2ServicePhaseObserver& aObserver, |
|
59 MVPbkStoreContact* aStoreContact, |
|
60 MPbk2SelectFieldProperty* aSelectedFieldProperty, |
|
61 TInt aSelectedFieldIndex, HBufC* aDataBuffer, TInt aMimeType, |
|
62 TCoeHelpContext aHelpContext, |
|
63 TUint aAssignFlags, TUint aNoteFlags ) : |
|
64 iObserver( aObserver ), |
|
65 iStoreContact( aStoreContact ), |
|
66 iSelectedFieldIndex( aSelectedFieldIndex ), |
|
67 iSelectedFieldProperty( aSelectedFieldProperty ), |
|
68 iDataBuffer( aDataBuffer ), |
|
69 iMimeType( aMimeType ), |
|
70 iHelpContext( aHelpContext ), |
|
71 iAssignFlags( aAssignFlags ), |
|
72 iNoteFlags( aNoteFlags ), |
|
73 iEikEnv( CEikonEnv::Static() ) |
|
74 { |
|
75 } |
|
76 |
|
77 // -------------------------------------------------------------------------- |
|
78 // CPbk2SingleAssignDataPhase::~CPbk2SingleAssignDataPhase |
|
79 // -------------------------------------------------------------------------- |
|
80 // |
|
81 CPbk2SingleAssignDataPhase::~CPbk2SingleAssignDataPhase() |
|
82 { |
|
83 if ( iContactEditorEliminator ) |
|
84 { |
|
85 iContactEditorEliminator->ForceExit(); |
|
86 } |
|
87 delete iResults; |
|
88 delete iContactDataAssigner; |
|
89 delete iStoreContact; |
|
90 |
|
91 if ( iDestroyedPtr ) |
|
92 { |
|
93 *iDestroyedPtr = ETrue; |
|
94 } |
|
95 } |
|
96 |
|
97 // -------------------------------------------------------------------------- |
|
98 // CPbk2SingleAssignDataPhase::NewL |
|
99 // -------------------------------------------------------------------------- |
|
100 // |
|
101 CPbk2SingleAssignDataPhase* CPbk2SingleAssignDataPhase::NewL |
|
102 ( MPbk2ServicePhaseObserver& aObserver, |
|
103 MVPbkStoreContact* aStoreContact, |
|
104 MPbk2SelectFieldProperty* aSelectedFieldProperty, |
|
105 TInt aSelectedFieldIndex, HBufC* aDataBuffer, TInt aMimeType, |
|
106 TCoeHelpContext aHelpContext, |
|
107 TUint aAssignFlags, TUint aNoteFlags ) |
|
108 { |
|
109 CPbk2SingleAssignDataPhase* self = |
|
110 new ( ELeave ) CPbk2SingleAssignDataPhase |
|
111 ( aObserver, aStoreContact, aSelectedFieldProperty, |
|
112 aSelectedFieldIndex, aDataBuffer, aMimeType, aHelpContext, |
|
113 aAssignFlags, aNoteFlags ); |
|
114 return self; |
|
115 } |
|
116 |
|
117 // -------------------------------------------------------------------------- |
|
118 // CPbk2SingleAssignDataPhase::LaunchServicePhaseL |
|
119 // -------------------------------------------------------------------------- |
|
120 // |
|
121 void CPbk2SingleAssignDataPhase::LaunchServicePhaseL() |
|
122 { |
|
123 DoAssignDataL(); |
|
124 } |
|
125 |
|
126 // -------------------------------------------------------------------------- |
|
127 // CPbk2SingleAssignDataPhase::CancelServicePhase |
|
128 // -------------------------------------------------------------------------- |
|
129 // |
|
130 void CPbk2SingleAssignDataPhase::CancelServicePhase() |
|
131 { |
|
132 if ( iContactEditorEliminator ) |
|
133 { |
|
134 // Changes won't be saved here. |
|
135 iContactEditorEliminator->ForceExit(); |
|
136 } |
|
137 // Notify observer to complete its message. |
|
138 iObserver.PhaseCanceled( *this ); |
|
139 } |
|
140 |
|
141 // -------------------------------------------------------------------------- |
|
142 // CPbk2SingleAssignDataPhase::RequestCancelL |
|
143 // -------------------------------------------------------------------------- |
|
144 // |
|
145 void CPbk2SingleAssignDataPhase::RequestCancelL( TInt aExitCommandId ) |
|
146 { |
|
147 if ( iContactEditorEliminator ) |
|
148 { |
|
149 // Do not notify observer about abortion here, we must let |
|
150 // contact editor to do it. Otherwise the changes would not be saved. |
|
151 iContactEditorEliminator->RequestExitL( aExitCommandId ); |
|
152 } |
|
153 else |
|
154 { |
|
155 if ( aExitCommandId == EEikBidCancel ) |
|
156 { |
|
157 iObserver.PhaseAborted( *this ); |
|
158 } |
|
159 else |
|
160 { |
|
161 iObserver.PhaseCanceled( *this ); |
|
162 } |
|
163 } |
|
164 } |
|
165 |
|
166 // -------------------------------------------------------------------------- |
|
167 // CPbk2SingleAssignDataPhase::AcceptDelayed |
|
168 // -------------------------------------------------------------------------- |
|
169 // |
|
170 void CPbk2SingleAssignDataPhase::AcceptDelayedL |
|
171 ( const TDesC8& /*aContactLinkBuffer*/ ) |
|
172 { |
|
173 // Nothing to do |
|
174 } |
|
175 |
|
176 // -------------------------------------------------------------------------- |
|
177 // CPbk2SingleAssignDataPhase::Results |
|
178 // -------------------------------------------------------------------------- |
|
179 // |
|
180 MVPbkContactLinkArray* CPbk2SingleAssignDataPhase::Results() const |
|
181 { |
|
182 return iResults; |
|
183 } |
|
184 |
|
185 // -------------------------------------------------------------------------- |
|
186 // CPbk2SingleAssignDataPhase::ExtraResultData |
|
187 // -------------------------------------------------------------------------- |
|
188 // |
|
189 TInt CPbk2SingleAssignDataPhase::ExtraResultData() const |
|
190 { |
|
191 return iSelectedFieldIndex; |
|
192 } |
|
193 |
|
194 // -------------------------------------------------------------------------- |
|
195 // CPbk2SingleAssignDataPhase::TakeStoreContact |
|
196 // -------------------------------------------------------------------------- |
|
197 // |
|
198 MVPbkStoreContact* CPbk2SingleAssignDataPhase::TakeStoreContact() |
|
199 { |
|
200 MVPbkStoreContact* contact = iStoreContact; |
|
201 iStoreContact = NULL; |
|
202 return contact; |
|
203 } |
|
204 |
|
205 // -------------------------------------------------------------------------- |
|
206 // CPbk2SingleAssignDataPhase::FieldContent |
|
207 // -------------------------------------------------------------------------- |
|
208 // |
|
209 HBufC* CPbk2SingleAssignDataPhase::FieldContent() const |
|
210 { |
|
211 return NULL; |
|
212 } |
|
213 |
|
214 // -------------------------------------------------------------------------- |
|
215 // CPbk2SingleAssignDataPhase::AssignComplete |
|
216 // -------------------------------------------------------------------------- |
|
217 // |
|
218 void CPbk2SingleAssignDataPhase::AssignComplete |
|
219 ( MPbk2ContactAssigner& /*aAssigner*/, TInt aIndex ) |
|
220 { |
|
221 // aIndex is KErrNotSupported from CPbk2ContactEmptyDataAssigner |
|
222 // but iSelectedFieldIndex may still be set previously. |
|
223 if (aIndex == KErrNotSupported) |
|
224 { |
|
225 aIndex = iSelectedFieldIndex; |
|
226 } |
|
227 |
|
228 TRAPD( err, HandleContactDataAssignedL( aIndex ) ); |
|
229 if ( err != KErrNone ) |
|
230 { |
|
231 // HandleContactDataAssignedL will leave with KErrDied if |
|
232 // this was destroyed, then we will not inform observer |
|
233 // since iObserver is no more. Syslib's CBaActiveScheduler leaves |
|
234 // with KLeaveExit (in certain situations, e.g. pressing End key |
|
235 // with delete-dialog open when assigning empty contact. |
|
236 if ( err != KErrDied && err != KLeaveExit ) |
|
237 { |
|
238 iObserver.PhaseError( *this, err ); |
|
239 } |
|
240 } |
|
241 } |
|
242 |
|
243 // -------------------------------------------------------------------------- |
|
244 // CPbk2SingleAssignDataPhase::AssignFailed |
|
245 // -------------------------------------------------------------------------- |
|
246 // |
|
247 void CPbk2SingleAssignDataPhase::AssignFailed |
|
248 ( MPbk2ContactAssigner& /*aAssigner*/, TInt aErrorCode ) |
|
249 { |
|
250 iObserver.PhaseError( *this, aErrorCode ); |
|
251 } |
|
252 |
|
253 // -------------------------------------------------------------------------- |
|
254 // CPbk2SingleAssignDataPhase::ContactOperationCompleted |
|
255 // -------------------------------------------------------------------------- |
|
256 // |
|
257 void CPbk2SingleAssignDataPhase::ContactOperationCompleted |
|
258 ( TContactOpResult aResult ) |
|
259 { |
|
260 TInt err = KErrNone; |
|
261 |
|
262 if ( aResult.iOpCode == EContactLock ) |
|
263 { |
|
264 TRAP( err, DoAssignDataL() ); |
|
265 } |
|
266 else if ( aResult.iOpCode == EContactCommit ) |
|
267 { |
|
268 TRAP( err, FinalizeL( iStoreContact ) ); |
|
269 } |
|
270 |
|
271 if ( err != KErrNone ) |
|
272 { |
|
273 iObserver.PhaseError( *this, err ); |
|
274 } |
|
275 } |
|
276 |
|
277 // -------------------------------------------------------------------------- |
|
278 // CPbk2SingleAssignDataPhase::ContactOperationFailed |
|
279 // -------------------------------------------------------------------------- |
|
280 // |
|
281 void CPbk2SingleAssignDataPhase::ContactOperationFailed |
|
282 ( TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/ ) |
|
283 { |
|
284 // Locking or committing the contact failed |
|
285 iObserver.PhaseError( *this, aErrorCode ); |
|
286 } |
|
287 |
|
288 // -------------------------------------------------------------------------- |
|
289 // CPbk2SingleAssignDataPhase::ContactEditingComplete |
|
290 // -------------------------------------------------------------------------- |
|
291 // |
|
292 void CPbk2SingleAssignDataPhase::ContactEditingComplete |
|
293 ( MVPbkStoreContact* aEditedContact ) |
|
294 { |
|
295 delete iStoreContact; |
|
296 iStoreContact = aEditedContact; |
|
297 |
|
298 TRAPD( err, FinalizeL( iStoreContact ) ); |
|
299 |
|
300 if ( err != KErrNone ) |
|
301 { |
|
302 iObserver.PhaseError( *this, err ); |
|
303 } |
|
304 } |
|
305 |
|
306 // -------------------------------------------------------------------------- |
|
307 // CPbk2SingleAssignDataPhase::ContactEditingDeletedContact |
|
308 // -------------------------------------------------------------------------- |
|
309 // |
|
310 void CPbk2SingleAssignDataPhase::ContactEditingDeletedContact |
|
311 ( MVPbkStoreContact* aEditedContact ) |
|
312 { |
|
313 delete iStoreContact; |
|
314 iStoreContact = aEditedContact; |
|
315 |
|
316 // Reset note flags |
|
317 iNoteFlags |= KPbk2NoteFlagContactDeleted; |
|
318 |
|
319 // Finalize, but with no results to append |
|
320 TRAPD( err, FinalizeL( NULL ) ); |
|
321 |
|
322 if ( err != KErrNone ) |
|
323 { |
|
324 iObserver.PhaseError( *this, err ); |
|
325 } |
|
326 } |
|
327 |
|
328 // -------------------------------------------------------------------------- |
|
329 // CPbk2SingleAssignDataPhase::ContactEditingAborted |
|
330 // -------------------------------------------------------------------------- |
|
331 // |
|
332 void CPbk2SingleAssignDataPhase::ContactEditingAborted() |
|
333 { |
|
334 iObserver.PhaseAborted( *this ); |
|
335 } |
|
336 |
|
337 // -------------------------------------------------------------------------- |
|
338 // CPbk2SingleAssignDataPhase::OkToExitL |
|
339 // -------------------------------------------------------------------------- |
|
340 // |
|
341 TBool CPbk2SingleAssignDataPhase::OkToExitL( TInt aCommandId ) |
|
342 { |
|
343 return iObserver.PhaseOkToExit( *this, aCommandId ); |
|
344 } |
|
345 |
|
346 // -------------------------------------------------------------------------- |
|
347 // CPbk2SingleAssignDataPhase::DoAssignDataL |
|
348 // -------------------------------------------------------------------------- |
|
349 // |
|
350 void CPbk2SingleAssignDataPhase::DoAssignDataL() |
|
351 { |
|
352 const MVPbkFieldType* fieldType = NULL; |
|
353 MVPbkStoreContactField* field = NULL; |
|
354 if ( iSelectedFieldProperty ) |
|
355 { |
|
356 fieldType = iSelectedFieldProperty->SelectedFieldType(); |
|
357 if ( iSelectedFieldIndex >= KErrNone ) |
|
358 { |
|
359 field = &iStoreContact->Fields().FieldAt( iSelectedFieldIndex ); |
|
360 } |
|
361 } |
|
362 |
|
363 CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&> |
|
364 ( *iEikEnv->EikAppUi() ); |
|
365 |
|
366 delete iContactDataAssigner; |
|
367 iContactDataAssigner = NULL; |
|
368 iContactDataAssigner = |
|
369 Pbk2ContactAssignerFactory::CreateContactDataAssignerL |
|
370 ( *this, iMimeType, fieldType, |
|
371 appUi.ApplicationServices().ContactManager(), |
|
372 appUi.ApplicationServices().FieldProperties() ); |
|
373 |
|
374 iContactDataAssigner->AssignDataL |
|
375 ( *iStoreContact, field, fieldType, iDataBuffer ); |
|
376 } |
|
377 |
|
378 // -------------------------------------------------------------------------- |
|
379 // CPbk2SingleAssignDataPhase::HandleContactDataAssignedL |
|
380 // -------------------------------------------------------------------------- |
|
381 // |
|
382 void CPbk2SingleAssignDataPhase::HandleContactDataAssignedL( TInt aIndex ) |
|
383 { |
|
384 TInt index = aIndex; |
|
385 |
|
386 // If desired, open editor |
|
387 if ( !( iAssignFlags & EDoNotOpenEditor ) ) |
|
388 { |
|
389 if ( iAssignFlags & ECreateNewContact ) |
|
390 { |
|
391 // If we created a new contact, set focus to first field |
|
392 index = KErrNotFound; |
|
393 } |
|
394 |
|
395 TBool thisDestroyed = EFalse; |
|
396 iDestroyedPtr = &thisDestroyed; |
|
397 TPbk2DestructionIndicator indicator |
|
398 ( &thisDestroyed, iDestroyedPtr ); |
|
399 |
|
400 CPbk2ContactEditorOperator* editorOperator = |
|
401 CPbk2ContactEditorOperator::NewLC( *this, *this ); |
|
402 iContactEditorEliminator = editorOperator; |
|
403 iContactEditorEliminator->ResetWhenDestroyed |
|
404 ( &iContactEditorEliminator ); |
|
405 |
|
406 editorOperator->OpenEditorL( |
|
407 iStoreContact, index, iAssignFlags, iHelpContext ); |
|
408 |
|
409 // index is updated when editor is closed. |
|
410 iSelectedFieldIndex = index; |
|
411 |
|
412 CleanupStack::PopAndDestroy(); // operator |
|
413 |
|
414 if ( thisDestroyed ) |
|
415 { |
|
416 // The calling code excepts us to leave with KErrDied if |
|
417 // this was destroyed |
|
418 User::Leave( KErrDied ); |
|
419 } |
|
420 } |
|
421 else |
|
422 { |
|
423 iStoreContact->CommitL( *this ); |
|
424 } |
|
425 } |
|
426 |
|
427 // -------------------------------------------------------------------------- |
|
428 // CPbk2SingleAssignDataPhase::AppendResultL |
|
429 // -------------------------------------------------------------------------- |
|
430 // |
|
431 void CPbk2SingleAssignDataPhase::AppendResultL |
|
432 ( const MVPbkStoreContact* aStoreContact ) |
|
433 { |
|
434 if ( aStoreContact ) |
|
435 { |
|
436 // Add the contact link to the result array |
|
437 MVPbkContactLink* link = aStoreContact->CreateLinkLC(); |
|
438 if ( link ) |
|
439 { |
|
440 if ( !iResults ) |
|
441 { |
|
442 iResults = CVPbkContactLinkArray::NewL(); |
|
443 } |
|
444 |
|
445 CleanupStack::Pop(); // aStoreContact->CreateLinkLC() |
|
446 |
|
447 iResults->AppendL( link ); |
|
448 } |
|
449 } |
|
450 } |
|
451 |
|
452 // -------------------------------------------------------------------------- |
|
453 // CPbk2SingleAssignDataPhase::DisplayNotesL |
|
454 // -------------------------------------------------------------------------- |
|
455 // |
|
456 void CPbk2SingleAssignDataPhase::DisplayNotesL() |
|
457 { |
|
458 TPbk2AssignNoteService noteService; |
|
459 |
|
460 CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&> |
|
461 ( *iEikEnv->EikAppUi() ); |
|
462 |
|
463 if ( !(iNoteFlags & KPbk2NoteFlagContactDeleted) |
|
464 &&!(iAssignFlags & EskipInfoNotes) ) |
|
465 { |
|
466 // Show note if new contact was created |
|
467 if ( iNoteFlags & KPbk2NoteFlagOneContactCreated ) |
|
468 { |
|
469 if ( IsContactInSelectedMemoryL( *iStoreContact ) ) |
|
470 { |
|
471 noteService.ShowInformationNoteL |
|
472 ( R_QTN_PHOB_NOTE_CONTACT_CREATED ); |
|
473 } |
|
474 else |
|
475 { |
|
476 TVPbkContactStoreUriPtr contactUri = |
|
477 iStoreContact->ParentStore().StoreProperties().Uri(); |
|
478 |
|
479 CPbk2StorePropertyArray& array = |
|
480 appUi.ApplicationServices().StoreProperties(); |
|
481 noteService.ShowInformationNoteL |
|
482 ( R_QTN_PHOB_NOTE_CONTACT_HIDDEN, contactUri, array ); |
|
483 } |
|
484 } |
|
485 // Show note if existing contact was updated |
|
486 else |
|
487 { |
|
488 if ( iNoteFlags & KPbk2NoteFlagOneContactRelocated ) |
|
489 { |
|
490 CPbk2StorePropertyArray& array = |
|
491 appUi.ApplicationServices().StoreProperties(); |
|
492 TVPbkContactStoreUriPtr store |
|
493 ( VPbkContactStoreUris::DefaultCntDbUri() ); |
|
494 |
|
495 noteService.ShowInformationNoteL |
|
496 ( R_QTN_PHOB_NOTE_CONTACT_HIDDEN, store, array ); |
|
497 } |
|
498 else |
|
499 { |
|
500 noteService.ShowInformationNoteL |
|
501 ( R_QTN_PHOB_NOTE_CONTACT_UPDATED ); |
|
502 } |
|
503 } |
|
504 } |
|
505 } |
|
506 |
|
507 // -------------------------------------------------------------------------- |
|
508 // CPbk2SingleAssignDataPhase::IsContactInSelectedMemoryL |
|
509 // -------------------------------------------------------------------------- |
|
510 // |
|
511 TBool CPbk2SingleAssignDataPhase::IsContactInSelectedMemoryL |
|
512 ( MVPbkStoreContact& aContact ) |
|
513 { |
|
514 TBool result( EFalse ); |
|
515 |
|
516 TVPbkContactStoreUriPtr contactUri = |
|
517 aContact.ParentStore().StoreProperties().Uri(); |
|
518 |
|
519 CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&> |
|
520 ( *iEikEnv->EikAppUi() ); |
|
521 |
|
522 CVPbkContactStoreUriArray* currentConfig = |
|
523 appUi.ApplicationServices().StoreConfiguration(). |
|
524 CurrentConfigurationL(); |
|
525 CleanupStack::PushL( currentConfig ); |
|
526 |
|
527 if ( currentConfig->IsIncluded( contactUri ) ) |
|
528 { |
|
529 result = ETrue; |
|
530 } |
|
531 |
|
532 CleanupStack::PopAndDestroy( currentConfig ); |
|
533 return result; |
|
534 } |
|
535 |
|
536 // -------------------------------------------------------------------------- |
|
537 // CPbk2SingleAssignDataPhase::FinalizeL |
|
538 // -------------------------------------------------------------------------- |
|
539 // |
|
540 void CPbk2SingleAssignDataPhase::FinalizeL |
|
541 ( const MVPbkStoreContact* aStoreContact ) |
|
542 { |
|
543 AppendResultL( aStoreContact ); |
|
544 DisplayNotesL(); |
|
545 iObserver.NextPhase( *this ); |
|
546 } |
|
547 |
|
548 // End of File |