|
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 multiple contact data assigner. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2MultiContactDataAssigner.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPbk2ServerAppAppUi.h" |
|
23 #include "MPbk2UiServiceObserver.h" |
|
24 #include "CPbk2SelectMultiplePropertyPhase.h" |
|
25 #include "CPbk2ContactFetchPhase.h" |
|
26 #include "CPbk2MultiAssignDataPhase.h" |
|
27 #include "CPbk2PrepareMultipleAssignPhase.h" |
|
28 #include "TPbk2TitlePaneOperator.h" |
|
29 #include "TPbk2ServerMessageDataRetriever.h" |
|
30 #include "CPbk2ServerAppStoreManager.h" |
|
31 #include "MPbk2SelectFieldProperty.h" |
|
32 #include <CPbk2FetchDlg.h> |
|
33 #include <MPbk2ApplicationServices.h> |
|
34 #include <Pbk2UIControls.rsg> |
|
35 #include <Pbk2ServerApp.rsg> |
|
36 |
|
37 // Virtual Phonebook |
|
38 #include <CVPbkContactManager.h> |
|
39 #include <CVPbkContactStoreUriArray.h> |
|
40 #include <MVPbkContactLink.h> |
|
41 #include <CVPbkFieldTypeSelector.h> |
|
42 |
|
43 // System includes |
|
44 #include <AiwContactAssignDataTypes.h> |
|
45 |
|
46 using namespace AiwContactAssign; |
|
47 |
|
48 /// Unnamed namespace for local definitions |
|
49 namespace { |
|
50 |
|
51 #ifdef _DEBUG |
|
52 |
|
53 enum TPanicCode |
|
54 { |
|
55 EPanicLogicPhaseCompletion |
|
56 }; |
|
57 |
|
58 void Panic(TPanicCode aReason) |
|
59 { |
|
60 _LIT(KPanicText, "CPbk2MultiContactDataAssigner"); |
|
61 User::Panic(KPanicText,aReason); |
|
62 } |
|
63 |
|
64 #endif // _DEBUG |
|
65 |
|
66 /** |
|
67 * Sets title pane. |
|
68 * |
|
69 * @param aDataRetriever Server message data retriever. |
|
70 * @param aFlags Assign flags. |
|
71 * @param aMessage Server message. |
|
72 */ |
|
73 void SetTitlePaneL |
|
74 ( TPbk2ServerMessageDataRetriever& aDataRetriever, TUint aFlags, |
|
75 const RMessage2& aMessage ) |
|
76 { |
|
77 HBufC* titlePaneText = NULL; |
|
78 if ( !( aFlags & AiwContactAssign::EUseProviderTitle ) ) |
|
79 { |
|
80 titlePaneText = aDataRetriever.GetTitlePaneTextL( aMessage ); |
|
81 } |
|
82 TPbk2TitlePaneOperator titlePaneOperator; |
|
83 titlePaneOperator.SetTitlePaneL( titlePaneText ); // takes ownership |
|
84 } |
|
85 |
|
86 } /// namespace |
|
87 |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CPbk2MultiContactDataAssigner::CPbk2MultiContactDataAssigner |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 CPbk2MultiContactDataAssigner::CPbk2MultiContactDataAssigner |
|
94 ( MPbk2UiServiceObserver& aObserver ) : |
|
95 iObserver( aObserver ) |
|
96 { |
|
97 } |
|
98 |
|
99 // -------------------------------------------------------------------------- |
|
100 // CPbk2MultiContactDataAssigner::~CPbk2MultiContactDataAssigner |
|
101 // -------------------------------------------------------------------------- |
|
102 // |
|
103 CPbk2MultiContactDataAssigner::~CPbk2MultiContactDataAssigner() |
|
104 { |
|
105 delete iSelectPropertyPhase; |
|
106 delete iFetchPhase; |
|
107 delete iPrepareAssignPhase; |
|
108 delete iAssignDataPhase; |
|
109 delete iStoreUris; |
|
110 delete iDataBuffer; |
|
111 delete iAddressSelectFilterBuffer; |
|
112 delete iPreselectedContacts; |
|
113 delete iSelectFieldProperty; |
|
114 delete iContactViewFilter; |
|
115 delete iStoreManager; |
|
116 } |
|
117 |
|
118 // -------------------------------------------------------------------------- |
|
119 // CPbk2MultiContactDataAssigner::NewL |
|
120 // -------------------------------------------------------------------------- |
|
121 // |
|
122 CPbk2MultiContactDataAssigner* CPbk2MultiContactDataAssigner::NewL( |
|
123 const RMessage2& aFetchCompleteMessage, |
|
124 MPbk2UiServiceObserver& aObserver ) |
|
125 { |
|
126 CPbk2MultiContactDataAssigner* self = |
|
127 new ( ELeave ) CPbk2MultiContactDataAssigner( aObserver ); |
|
128 CleanupStack::PushL( self ); |
|
129 self->ConstructL( aFetchCompleteMessage ); |
|
130 CleanupStack::Pop( self ); |
|
131 return self; |
|
132 } |
|
133 |
|
134 // -------------------------------------------------------------------------- |
|
135 // CPbk2MultiContactDataAssigner::ConstructL |
|
136 // -------------------------------------------------------------------------- |
|
137 // |
|
138 void CPbk2MultiContactDataAssigner::ConstructL( const RMessage2& aMessage ) |
|
139 { |
|
140 // Retrieve data from the client-server message |
|
141 TPbk2ServerMessageDataRetriever dataRetriever; |
|
142 TUint flags = dataRetriever.MultipleContactAssignFlagsL( aMessage ); |
|
143 |
|
144 // Set title pane |
|
145 SetTitlePaneL( dataRetriever, flags, aMessage ); |
|
146 |
|
147 CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&> |
|
148 ( *CEikonEnv::Static()->EikAppUi() ); |
|
149 |
|
150 iPreselectedContacts = dataRetriever.GetPreselectedContactLinksL |
|
151 ( aMessage, appUi.ApplicationServices().ContactManager() ); |
|
152 iStoreUris = dataRetriever.GetContactStoreUriArrayL |
|
153 ( aMessage, appUi.ApplicationServices().StoreConfiguration(), |
|
154 iPreselectedContacts, iUseDeviceConfig ); |
|
155 iAddressSelectFilterBuffer = |
|
156 dataRetriever.GetAddressSelectFilterBufferL( aMessage ); |
|
157 iDataBuffer = dataRetriever.GetDataBufferL( aMessage ); |
|
158 iMimeType = dataRetriever.GetMimeTypeL( aMessage ); |
|
159 |
|
160 // check if the client has special orientation setting to make sure keeping |
|
161 // the same orientation with the client. |
|
162 TInt clientOrientationType = dataRetriever.GetOrietationTypeL( aMessage ); |
|
163 if( clientOrientationType == CAknAppUi::EAppUiOrientationLandscape ) |
|
164 { |
|
165 appUi.SetOrientationL( CAknAppUi::EAppUiOrientationLandscape ); |
|
166 } |
|
167 else if( clientOrientationType == CAknAppUi::EAppUiOrientationPortrait ) |
|
168 { |
|
169 appUi.SetOrientationL( CAknAppUi::EAppUiOrientationPortrait ); |
|
170 } |
|
171 |
|
172 // Drop all non-writable stores |
|
173 iStoreManager = CPbk2ServerAppStoreManager::NewL |
|
174 ( appUi.StoreManager(), |
|
175 appUi.ApplicationServices().ContactManager() ); |
|
176 iStoreManager->RemoveReadOnlyStoreUris |
|
177 ( *iStoreUris, appUi.ApplicationServices().StoreProperties() ); |
|
178 |
|
179 // Retrieve view filter |
|
180 iContactViewFilter = |
|
181 dataRetriever.GetContactViewFilterForAttributeAssignL |
|
182 ( aMessage, |
|
183 appUi.ApplicationServices().ContactManager().FieldTypes() ); |
|
184 } |
|
185 |
|
186 // -------------------------------------------------------------------------- |
|
187 // CPbk2MultiContactDataAssigner::LaunchServiceL |
|
188 // -------------------------------------------------------------------------- |
|
189 // |
|
190 void CPbk2MultiContactDataAssigner::LaunchServiceL() |
|
191 { |
|
192 // Open stores |
|
193 iStoreManager->LoadAndOpenContactStoresL( *iStoreUris, *this, ETrue ); |
|
194 } |
|
195 |
|
196 // -------------------------------------------------------------------------- |
|
197 // CPbk2MultiContactDataAssigner::CancelService |
|
198 // -------------------------------------------------------------------------- |
|
199 // |
|
200 void CPbk2MultiContactDataAssigner::CancelService() |
|
201 { |
|
202 if ( iAssignDataPhase ) |
|
203 { |
|
204 iAssignDataPhase->CancelServicePhase(); |
|
205 } |
|
206 |
|
207 if ( iPrepareAssignPhase ) |
|
208 { |
|
209 iPrepareAssignPhase->CancelServicePhase(); |
|
210 } |
|
211 |
|
212 if ( iSelectPropertyPhase ) |
|
213 { |
|
214 iSelectPropertyPhase->CancelServicePhase(); |
|
215 } |
|
216 |
|
217 if ( iFetchPhase ) |
|
218 { |
|
219 iFetchPhase->CancelServicePhase(); |
|
220 } |
|
221 } |
|
222 |
|
223 // -------------------------------------------------------------------------- |
|
224 // CPbk2MultiContactDataAssigner::AcceptDelayedContactsL |
|
225 // -------------------------------------------------------------------------- |
|
226 // |
|
227 void CPbk2MultiContactDataAssigner::AcceptDelayedContactsL |
|
228 ( const TDesC8& /*aContactLinkBuffer*/ ) |
|
229 { |
|
230 // Do nothing |
|
231 } |
|
232 |
|
233 // -------------------------------------------------------------------------- |
|
234 // CPbk2MultiContactDataAssigner::ExitServiceL |
|
235 // -------------------------------------------------------------------------- |
|
236 // |
|
237 void CPbk2MultiContactDataAssigner::ExitServiceL( TInt aExitCommandId ) |
|
238 { |
|
239 if ( iAssignDataPhase ) |
|
240 { |
|
241 iAssignDataPhase->RequestCancelL( aExitCommandId ); |
|
242 } |
|
243 |
|
244 if ( iPrepareAssignPhase ) |
|
245 { |
|
246 iPrepareAssignPhase->RequestCancelL( aExitCommandId ); |
|
247 } |
|
248 |
|
249 if ( iSelectPropertyPhase ) |
|
250 { |
|
251 iSelectPropertyPhase->RequestCancelL( aExitCommandId ); |
|
252 } |
|
253 |
|
254 if ( iFetchPhase ) |
|
255 { |
|
256 iFetchPhase->RequestCancelL( aExitCommandId ); |
|
257 } |
|
258 } |
|
259 |
|
260 // -------------------------------------------------------------------------- |
|
261 // CPbk2MultiContactDataAssigner::ServiceResults |
|
262 // -------------------------------------------------------------------------- |
|
263 // |
|
264 void CPbk2MultiContactDataAssigner::ServiceResults(TServiceResults* aResults) const |
|
265 { |
|
266 if ( iAssignDataPhase ) |
|
267 { |
|
268 aResults->iLinkArray = iAssignDataPhase->Results(); |
|
269 aResults->iExtraData = iAssignDataPhase->ExtraResultData(); |
|
270 aResults->iFieldContent = iAssignDataPhase->FieldContent(); |
|
271 } |
|
272 } |
|
273 |
|
274 // -------------------------------------------------------------------------- |
|
275 // CPbk2MultiContactDataAssigner::NextPhase |
|
276 // -------------------------------------------------------------------------- |
|
277 // |
|
278 void CPbk2MultiContactDataAssigner::NextPhase |
|
279 ( MPbk2ServicePhase& aPhase ) |
|
280 { |
|
281 TInt err = KErrNone; |
|
282 |
|
283 if ( &aPhase == iFetchPhase ) |
|
284 { |
|
285 MVPbkContactLinkArray* fetchResults = iFetchPhase->Results(); |
|
286 __ASSERT_DEBUG( fetchResults && fetchResults->Count() > 0, |
|
287 Panic( EPanicLogicPhaseCompletion ) ); |
|
288 |
|
289 TRAP( err, LaunchSelectMultiPropertyPhaseL( fetchResults ) ); |
|
290 } |
|
291 else if ( &aPhase == iSelectPropertyPhase ) |
|
292 { |
|
293 MVPbkContactLinkArray* selectPropertyResults |
|
294 = iSelectPropertyPhase->Results(); |
|
295 __ASSERT_DEBUG( selectPropertyResults && |
|
296 selectPropertyResults->Count() > 0, |
|
297 Panic( EPanicLogicPhaseCompletion ) ); |
|
298 |
|
299 TRAP( err, LaunchPrepareMultiAssignPhaseL( selectPropertyResults ) ); |
|
300 } |
|
301 else if ( &aPhase == iPrepareAssignPhase ) |
|
302 { |
|
303 MVPbkContactLinkArray* prepareResults |
|
304 = iPrepareAssignPhase->Results(); |
|
305 __ASSERT_DEBUG( prepareResults && |
|
306 prepareResults->Count() > 0, |
|
307 Panic( EPanicLogicPhaseCompletion ) ); |
|
308 |
|
309 TRAP( err, LaunchAssignPhaseL( prepareResults ) ); |
|
310 } |
|
311 else if ( &aPhase == iAssignDataPhase ) |
|
312 { |
|
313 iObserver.ServiceComplete(); |
|
314 } |
|
315 else |
|
316 { |
|
317 __ASSERT_DEBUG( EFalse, Panic( EPanicLogicPhaseCompletion ) ); |
|
318 } |
|
319 |
|
320 if ( err != KErrNone ) |
|
321 { |
|
322 iObserver.ServiceError( err ); |
|
323 } |
|
324 } |
|
325 |
|
326 // -------------------------------------------------------------------------- |
|
327 // CPbk2MultiContactDataAssigner::PreviousPhase |
|
328 // -------------------------------------------------------------------------- |
|
329 // |
|
330 void CPbk2MultiContactDataAssigner::PreviousPhase |
|
331 ( MPbk2ServicePhase& /*aPhase*/ ) |
|
332 { |
|
333 // Not supported in multiple assign |
|
334 } |
|
335 |
|
336 // -------------------------------------------------------------------------- |
|
337 // CPbk2MultiContactDataAssigner::PhaseCanceled |
|
338 // -------------------------------------------------------------------------- |
|
339 // |
|
340 void CPbk2MultiContactDataAssigner::PhaseCanceled |
|
341 ( MPbk2ServicePhase& /*aPhase*/ ) |
|
342 { |
|
343 iObserver.ServiceCanceled(); |
|
344 } |
|
345 |
|
346 // -------------------------------------------------------------------------- |
|
347 // CPbk2MultiContactDataAssigner::PhaseAborted |
|
348 // -------------------------------------------------------------------------- |
|
349 // |
|
350 void CPbk2MultiContactDataAssigner::PhaseAborted |
|
351 ( MPbk2ServicePhase& /*aPhase*/ ) |
|
352 { |
|
353 iObserver.ServiceAborted(); |
|
354 } |
|
355 |
|
356 // -------------------------------------------------------------------------- |
|
357 // CPbk2MultiContactDataAssigner::PhaseError |
|
358 // -------------------------------------------------------------------------- |
|
359 // |
|
360 void CPbk2MultiContactDataAssigner::PhaseError |
|
361 ( MPbk2ServicePhase& /*aPhase*/, TInt aErrorCode ) |
|
362 { |
|
363 iObserver.ServiceError( aErrorCode ); |
|
364 } |
|
365 |
|
366 // -------------------------------------------------------------------------- |
|
367 // CPbk2MultiContactDataAssigner::PhaseOkToExit |
|
368 // -------------------------------------------------------------------------- |
|
369 // |
|
370 TBool CPbk2MultiContactDataAssigner::PhaseOkToExit |
|
371 ( MPbk2ServicePhase& /*aPhase*/, TInt aCommandId ) |
|
372 { |
|
373 // Deny exit and pass an asynchronous query to the consumer, |
|
374 // which may later approve exit |
|
375 iObserver.CompleteExitMessage( aCommandId ); |
|
376 return EFalse; |
|
377 } |
|
378 |
|
379 // -------------------------------------------------------------------------- |
|
380 // CPbk2MultiContactDataAssigner::PhaseAccept |
|
381 // -------------------------------------------------------------------------- |
|
382 // |
|
383 void CPbk2MultiContactDataAssigner::PhaseAccept |
|
384 ( MPbk2ServicePhase& /*aPhase*/, const TDesC8& /*aMarkedEntries*/, |
|
385 const TDesC8& /*aLinkData*/ ) |
|
386 { |
|
387 // Not supported in assign |
|
388 } |
|
389 |
|
390 // -------------------------------------------------------------------------- |
|
391 // CPbk2MultiContactDataAssigner::ContactUiReadyL |
|
392 // -------------------------------------------------------------------------- |
|
393 // |
|
394 void CPbk2MultiContactDataAssigner::ContactUiReadyL |
|
395 ( MPbk2StartupMonitor& aStartupMonitor ) |
|
396 { |
|
397 aStartupMonitor.DeregisterEvents( *this ); |
|
398 if ( iPreselectedContacts && iPreselectedContacts->Count() > 0 ) |
|
399 { |
|
400 if ( iStoreManager->ContactsAvailableL( *iPreselectedContacts ) ) |
|
401 { |
|
402 LaunchSelectMultiPropertyPhaseL( iPreselectedContacts ); |
|
403 } |
|
404 else |
|
405 { |
|
406 iObserver.ServiceError( KErrNotSupported ); |
|
407 } |
|
408 } |
|
409 else |
|
410 { |
|
411 LaunchFetchPhaseL(); |
|
412 } |
|
413 } |
|
414 |
|
415 // -------------------------------------------------------------------------- |
|
416 // CPbk2MultiContactDataAssigner::StartupCanceled |
|
417 // -------------------------------------------------------------------------- |
|
418 // |
|
419 void CPbk2MultiContactDataAssigner::StartupCanceled( TInt aErrorCode ) |
|
420 { |
|
421 if ( aErrorCode == KErrCancel ) |
|
422 { |
|
423 iObserver.ServiceCanceled(); |
|
424 } |
|
425 else |
|
426 { |
|
427 iObserver.ServiceError( aErrorCode ); |
|
428 } |
|
429 } |
|
430 |
|
431 // -------------------------------------------------------------------------- |
|
432 // CPbk2MultiContactDataAssigner::LaunchFetchPhaseL |
|
433 // -------------------------------------------------------------------------- |
|
434 // |
|
435 void CPbk2MultiContactDataAssigner::LaunchFetchPhaseL() |
|
436 { |
|
437 CPbk2FetchDlg::TParams params; |
|
438 params.iResId = R_PBK2_MULTIPLE_ENTRY_FETCH_DLG; |
|
439 params.iFlags = CPbk2FetchDlg::EFetchMultiple; |
|
440 |
|
441 delete iFetchPhase; |
|
442 iFetchPhase = NULL; |
|
443 iFetchPhase = CPbk2ContactFetchPhase::NewL |
|
444 ( *this, *iStoreManager, params, ETrue, |
|
445 MPbk2FetchDlgObserver::EFetchYes, iContactViewFilter, |
|
446 iUseDeviceConfig, iStoreUris ); |
|
447 |
|
448 CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&> |
|
449 ( *CEikonEnv::Static()->EikAppUi() ); |
|
450 |
|
451 // Change layout to fetch's layout |
|
452 appUi.ChangeStatuspaneLayoutL( |
|
453 CPbk2ServerAppAppUi::EStatusPaneLayoutUsual ); |
|
454 |
|
455 iFetchPhase->LaunchServicePhaseL(); |
|
456 } |
|
457 |
|
458 // -------------------------------------------------------------------------- |
|
459 // CPbk2MultiContactDataAssigner::LaunchSelectMultiPropertyPhaseL |
|
460 // -------------------------------------------------------------------------- |
|
461 // |
|
462 void CPbk2MultiContactDataAssigner::LaunchSelectMultiPropertyPhaseL |
|
463 ( MVPbkContactLinkArray* aContactLinks ) |
|
464 { |
|
465 delete iSelectPropertyPhase; |
|
466 iSelectPropertyPhase = NULL; |
|
467 |
|
468 // Prepare parameters by reseting them |
|
469 delete iSelectFieldProperty; |
|
470 iSelectFieldProperty = NULL; |
|
471 |
|
472 iSelectPropertyPhase = CPbk2SelectMultiplePropertyPhase::NewL |
|
473 ( *this, aContactLinks, *iAddressSelectFilterBuffer, |
|
474 iSelectFieldProperty ); |
|
475 |
|
476 CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&> |
|
477 ( *CEikonEnv::Static()->EikAppUi() ); |
|
478 |
|
479 // Change layout back to regular layout after fetch |
|
480 appUi.ChangeStatuspaneLayoutL( |
|
481 CPbk2ServerAppAppUi::EStatusPaneLayoutEmpty ); |
|
482 |
|
483 iSelectPropertyPhase->LaunchServicePhaseL(); |
|
484 } |
|
485 |
|
486 // -------------------------------------------------------------------------- |
|
487 // CPbk2MultiContactDataAssigner::LaunchPrepareMultiAssignPhaseL |
|
488 // -------------------------------------------------------------------------- |
|
489 // |
|
490 void CPbk2MultiContactDataAssigner::LaunchPrepareMultiAssignPhaseL |
|
491 ( MVPbkContactLinkArray* aContactLinks ) |
|
492 { |
|
493 delete iPrepareAssignPhase; |
|
494 iPrepareAssignPhase = NULL; |
|
495 |
|
496 iPrepareAssignPhase = CPbk2PrepareMultipleAssignPhase::NewL |
|
497 ( *this, aContactLinks, iSelectFieldProperty, |
|
498 iInformationNoteFlags ); |
|
499 |
|
500 iPrepareAssignPhase->LaunchServicePhaseL(); |
|
501 } |
|
502 |
|
503 // -------------------------------------------------------------------------- |
|
504 // CPbk2MultiContactDataAssigner::LaunchAssignPhaseL |
|
505 // -------------------------------------------------------------------------- |
|
506 // |
|
507 void CPbk2MultiContactDataAssigner::LaunchAssignPhaseL |
|
508 ( MVPbkContactLinkArray* aContactLinks ) |
|
509 { |
|
510 delete iAssignDataPhase; |
|
511 iAssignDataPhase = NULL; |
|
512 |
|
513 iAssignDataPhase = CPbk2MultiAssignDataPhase::NewL |
|
514 ( *this, aContactLinks, iSelectFieldProperty, |
|
515 iDataBuffer, iMimeType, iInformationNoteFlags ); |
|
516 |
|
517 // In case of the assign phase it is important to delete the |
|
518 // previous phases so that exit and cancel methods work correctly |
|
519 delete iPrepareAssignPhase; |
|
520 iPrepareAssignPhase = NULL; |
|
521 delete iSelectPropertyPhase; |
|
522 iSelectPropertyPhase = NULL; |
|
523 delete iFetchPhase; |
|
524 iFetchPhase = NULL; |
|
525 |
|
526 iAssignDataPhase->LaunchServicePhaseL(); |
|
527 } |
|
528 |
|
529 // End of File |