|
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 call command object. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPbk2CallCmd.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include "CPbk2CallTypeSelector.h" |
|
24 #include <Pbk2Commands.hrh> |
|
25 #include <MPbk2ContactNameFormatter.h> |
|
26 #include <MPbk2ContactUiControl.h> |
|
27 #include <MPbk2ApplicationServices.h> |
|
28 #include <MPbk2AppUi.h> |
|
29 #include <CPbk2ApplicationServices.h> |
|
30 |
|
31 // Virtual Phonebook |
|
32 #include <MVPbkStoreContact.h> |
|
33 #include <MVPbkStoreContactField.h> |
|
34 #include <MVPbkContactFieldData.h> |
|
35 #include <MVPbkContactFieldTextData.h> |
|
36 #include <MVPbkContactLink.h> |
|
37 #include <CVPbkFieldTypeSelector.h> |
|
38 #include <MVPbkFieldType.h> |
|
39 #include <MVPbkContactStore.h> |
|
40 #include <MVPbkContactStoreProperties.h> |
|
41 #include <Pbk2UIControls.rsg> |
|
42 #include <MVPbkContactFieldUriData.h> |
|
43 |
|
44 // System includes |
|
45 #include <coemain.h> |
|
46 #include <AiwServiceHandler.h> |
|
47 #include <AiwCommon.hrh> |
|
48 #include <aiwdialdataext.h> |
|
49 #include <spsettingsvoiputils.h> |
|
50 |
|
51 //SPSettings |
|
52 #include <spsettings.h> |
|
53 #include <spproperty.h> |
|
54 |
|
55 // Debugging headers |
|
56 #include <Pbk2Debug.h> |
|
57 |
|
58 /// Unnamed namespace for local definitions |
|
59 namespace { |
|
60 |
|
61 #ifdef _DEBUG |
|
62 enum TPanicCode |
|
63 { |
|
64 EPanicPreCond_ExecuteLD = 1 |
|
65 }; |
|
66 |
|
67 void Panic(TPanicCode aReason) |
|
68 { |
|
69 _LIT(KPanicText, "CPbk2CallCmd"); |
|
70 User::Panic(KPanicText,aReason); |
|
71 } |
|
72 #endif // _DEBUG |
|
73 |
|
74 /** |
|
75 * Field type matcher. |
|
76 * |
|
77 * @param aFieldTypeList List of field types. |
|
78 * @param aFieldType Field type to search for. |
|
79 * @param aResourceId Field type selector resources. |
|
80 * @return ETrue if match was found. |
|
81 */ |
|
82 TBool MatchesFieldTypeL |
|
83 ( const MVPbkFieldTypeList& aFieldTypeList, |
|
84 const MVPbkFieldType& aFieldType, |
|
85 TInt aResourceId ) |
|
86 { |
|
87 TResourceReader reader; |
|
88 CCoeEnv::Static()->CreateResourceReaderLC( reader, aResourceId ); |
|
89 |
|
90 CVPbkFieldTypeSelector* selector = CVPbkFieldTypeSelector::NewL |
|
91 ( reader, aFieldTypeList ); |
|
92 |
|
93 // Check if the field type is the one needed |
|
94 TBool ret = selector->IsFieldTypeIncluded(aFieldType); |
|
95 CleanupStack::PopAndDestroy(); // resource buffer |
|
96 delete selector; |
|
97 return ret; |
|
98 } |
|
99 |
|
100 /** |
|
101 * Sets a phone number to AIW dial data. |
|
102 * |
|
103 * @param aDialData Dial data to modify. |
|
104 * @param aContact Contact containing the number. |
|
105 */ |
|
106 void SetDialDataNumberL |
|
107 ( CAiwDialDataExt& aDialData, const MVPbkStoreContact& aContact ) |
|
108 { |
|
109 const MVPbkFieldTypeList& fieldTypeList = |
|
110 aContact.ParentStore().StoreProperties().SupportedFields(); |
|
111 const MVPbkStoreContactFieldCollection& fieldCollection = |
|
112 aContact.Fields(); |
|
113 TInt fieldCount( fieldCollection.FieldCount() ); |
|
114 for ( TInt i = 0; i < fieldCount; ++i ) |
|
115 { |
|
116 const MVPbkStoreContactField& field = fieldCollection.FieldAt( i ); |
|
117 const MVPbkFieldType* fieldType = field.BestMatchingFieldType(); |
|
118 if( MatchesFieldTypeL( fieldTypeList, *fieldType, |
|
119 R_PHONEBOOK2_PHONENUMBER_SELECTOR ) ) |
|
120 { |
|
121 const MVPbkContactFieldTextData* textData = |
|
122 &MVPbkContactFieldTextData::Cast |
|
123 ( field.FieldData() ); |
|
124 const TDesC& phoneNumber( textData->Text().Left |
|
125 ( AIWDialData::KMaximumPhoneNumberLength ) ); |
|
126 aDialData.SetPhoneNumberL( phoneNumber ); |
|
127 } |
|
128 } |
|
129 } |
|
130 |
|
131 /** |
|
132 * Sets a phone number to AIW dial data. |
|
133 * |
|
134 * @param aDialData Dial data to modify. |
|
135 * @param aField Contact field containing the number. |
|
136 */ |
|
137 void SetDialDataNumberL |
|
138 ( CAiwDialDataExt& aDialData, const MVPbkStoreContactField& aField ) |
|
139 { |
|
140 TVPbkFieldStorageType dataType = aField.FieldData().DataType(); |
|
141 |
|
142 if ( dataType == EVPbkFieldStorageTypeText ) |
|
143 { |
|
144 const MVPbkContactFieldTextData* textData = |
|
145 &MVPbkContactFieldTextData::Cast( aField.FieldData() ); |
|
146 const TDesC& phoneNumber( textData->Text().Left |
|
147 ( AIWDialData::KMaximumPhoneNumberLength ) ); |
|
148 aDialData.SetPhoneNumberL( phoneNumber ); |
|
149 } |
|
150 |
|
151 if ( dataType == EVPbkFieldStorageTypeUri ) |
|
152 { |
|
153 const MVPbkContactFieldUriData* textData = |
|
154 &MVPbkContactFieldUriData::Cast( aField.FieldData() ); |
|
155 const TDesC& phoneNumber( textData->Text().Left |
|
156 ( AIWDialData::KMaximumPhoneNumberLength ) ); |
|
157 aDialData.SetPhoneNumberL( phoneNumber ); |
|
158 } |
|
159 } |
|
160 } /// namespace |
|
161 |
|
162 // -------------------------------------------------------------------------- |
|
163 // CPbk2CallCmd::CPbk2CallCmd |
|
164 // -------------------------------------------------------------------------- |
|
165 // |
|
166 CPbk2CallCmd::CPbk2CallCmd( MVPbkStoreContact*& aContact, |
|
167 MVPbkStoreContactField* aSelectedField, |
|
168 MPbk2ContactUiControl& aControl, |
|
169 const TInt aCommandId, CAiwServiceHandler& aServiceHandler, |
|
170 CPbk2CallTypeSelector& aSelector, |
|
171 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aActionSelector ) : |
|
172 iContact( aContact ), |
|
173 iSelectedField( aSelectedField ), |
|
174 iControl( &aControl ), |
|
175 iCommandId( aCommandId ), |
|
176 iServiceHandler( aServiceHandler ), |
|
177 iSelector( aSelector ), |
|
178 iActionSelector( aActionSelector ) |
|
179 |
|
180 { |
|
181 PBK2_DEBUG_PRINT |
|
182 (PBK2_DEBUG_STRING("CPbk2CallCmd::CPbk2CallCmd(0x%x)"), this); |
|
183 |
|
184 iControl->RegisterCommand( this ); |
|
185 } |
|
186 |
|
187 // -------------------------------------------------------------------------- |
|
188 // CPbk2CallCmd::~CPbk2CallCmd |
|
189 // -------------------------------------------------------------------------- |
|
190 // |
|
191 CPbk2CallCmd::~CPbk2CallCmd() |
|
192 { |
|
193 PBK2_DEBUG_PRINT |
|
194 (PBK2_DEBUG_STRING("CPbk2CallCmd::~CPbk2CallCmd(0x%x)"), this); |
|
195 |
|
196 delete iSelectedField; |
|
197 if( iControl ) |
|
198 { |
|
199 iControl->RegisterCommand( NULL ); |
|
200 } |
|
201 } |
|
202 |
|
203 // -------------------------------------------------------------------------- |
|
204 // CPbk2CallCmd::NewL |
|
205 // -------------------------------------------------------------------------- |
|
206 // |
|
207 CPbk2CallCmd* CPbk2CallCmd::NewL( MVPbkStoreContact*& aContact, |
|
208 MVPbkStoreContactField* aSelectedField, |
|
209 MPbk2ContactUiControl& aControl, |
|
210 const TInt aCommandId, CAiwServiceHandler& aServiceHandler, |
|
211 CPbk2CallTypeSelector& aSelector ) |
|
212 { |
|
213 CPbk2CallCmd* self = new (ELeave ) CPbk2CallCmd |
|
214 ( aContact, aSelectedField, aControl, aCommandId, |
|
215 aServiceHandler, aSelector, VPbkFieldTypeSelectorFactory::EEmptySelector ); |
|
216 return self; |
|
217 } |
|
218 |
|
219 // -------------------------------------------------------------------------- |
|
220 // CPbk2CallCmd::NewL |
|
221 // -------------------------------------------------------------------------- |
|
222 // |
|
223 CPbk2CallCmd* CPbk2CallCmd::NewL( MVPbkStoreContact*& aContact, |
|
224 MVPbkStoreContactField* aSelectedField, |
|
225 MPbk2ContactUiControl& aControl, |
|
226 const TInt aCommandId, CAiwServiceHandler& aServiceHandler, |
|
227 CPbk2CallTypeSelector& aSelector, |
|
228 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aActionSelector ) |
|
229 { |
|
230 CPbk2CallCmd* self = new (ELeave ) CPbk2CallCmd |
|
231 ( aContact, aSelectedField, aControl, aCommandId, |
|
232 aServiceHandler, aSelector, aActionSelector ); |
|
233 return self; |
|
234 } |
|
235 |
|
236 // -------------------------------------------------------------------------- |
|
237 // CPbk2CallCmd::ExecuteLD |
|
238 // -------------------------------------------------------------------------- |
|
239 // |
|
240 void CPbk2CallCmd::ExecuteLD() |
|
241 { |
|
242 PBK2_DEBUG_PRINT |
|
243 (PBK2_DEBUG_STRING("CPbk2CallCmd::ExecuteLD(0x%x)"), this); |
|
244 |
|
245 CleanupStack::PushL( this ); |
|
246 |
|
247 // Setup dial data |
|
248 CAiwDialDataExt* dialData = CAiwDialDataExt::NewLC(); |
|
249 dialData->SetWindowGroup |
|
250 ( CCoeEnv::Static()->RootWin().Identifier() ); |
|
251 |
|
252 // If there is a default service, use the service |
|
253 TUint serviceId; |
|
254 CSPSettingsVoIPUtils* sPSettings = CSPSettingsVoIPUtils::NewLC(); |
|
255 if ( !sPSettings->GetPreferredService( serviceId ) ) |
|
256 { |
|
257 dialData->SetServiceId( serviceId ); |
|
258 } |
|
259 CleanupStack::PopAndDestroy( sPSettings ); |
|
260 |
|
261 MVPbkContactLink* contactLink = NULL; |
|
262 |
|
263 if ( iCommandId == EPbk2CmdCall ) |
|
264 { |
|
265 // Call was launched with send key, which means |
|
266 // Phonebook has performed address select by itself |
|
267 // and there is selected field instance |
|
268 __ASSERT_DEBUG( iSelectedField && |
|
269 ( iSelectedField->FieldData().DataType() == |
|
270 EVPbkFieldStorageTypeText || |
|
271 iSelectedField->FieldData().DataType() == |
|
272 EVPbkFieldStorageTypeUri ), |
|
273 Panic( EPanicPreCond_ExecuteLD ) ); |
|
274 |
|
275 // Create field link |
|
276 contactLink = iSelectedField->CreateLinkLC(); |
|
277 |
|
278 // Set number |
|
279 SetDialDataNumberL( *dialData, *iSelectedField ); |
|
280 |
|
281 // We also have select call type by ourselves |
|
282 SetCallTypeL( *dialData ); |
|
283 |
|
284 // If field data has service prefix, extract it and find matched service id |
|
285 // from SP setting, then set the matched service id to daildata. |
|
286 // Service prefix from field data has higher priority over preferred service |
|
287 TPtrC xspId; |
|
288 if ( ExtractXspId( iSelectedField, xspId ) ) |
|
289 { |
|
290 TUint srcId = GetMatchedServiceIdL( xspId ); |
|
291 |
|
292 if ( srcId != (TUint)KErrNotFound ) |
|
293 { |
|
294 dialData->SetServiceId( srcId ); |
|
295 } |
|
296 } |
|
297 } |
|
298 else |
|
299 { |
|
300 if ( iSelectedField ) |
|
301 { |
|
302 // If selected field is set create field link from it. |
|
303 contactLink = iSelectedField->CreateLinkLC(); |
|
304 } |
|
305 else |
|
306 { |
|
307 // Otherwise use contact |
|
308 contactLink = iContact->CreateLinkLC(); |
|
309 } |
|
310 |
|
311 if ( !contactLink ) |
|
312 { |
|
313 // Temporary contact, set number here |
|
314 SetDialDataNumberL( *dialData, *iContact ); |
|
315 } |
|
316 } |
|
317 |
|
318 if ( contactLink ) |
|
319 { |
|
320 HBufC8* linkBuffer = contactLink->PackLC(); |
|
321 dialData->SetContactLinkL( *linkBuffer ); |
|
322 } |
|
323 else |
|
324 { |
|
325 CPbk2ApplicationServices* appServices = CPbk2ApplicationServices::InstanceLC(); |
|
326 MPbk2ContactNameFormatter& nameFormatter = |
|
327 appServices->NameFormatter(); |
|
328 const MVPbkStoreContactFieldCollection& fieldCollection = |
|
329 iContact->Fields(); |
|
330 HBufC* title = nameFormatter.GetContactTitleOrNullL( |
|
331 fieldCollection, |
|
332 MPbk2ContactNameFormatter::EPreserveLeadingSpaces ); |
|
333 CleanupStack::PopAndDestroy(); |
|
334 CleanupStack::PushL( title ); |
|
335 |
|
336 if ( title ) |
|
337 { |
|
338 dialData->SetNameL( *title ); |
|
339 } |
|
340 } |
|
341 |
|
342 // Get an empty in param list.. |
|
343 CAiwGenericParamList& inParamList = iServiceHandler.InParamListL(); |
|
344 // ..and pass it to dial data in order for it to fill it |
|
345 dialData->FillInParamListL( inParamList ); |
|
346 |
|
347 if ( contactLink ) |
|
348 { |
|
349 CleanupStack::PopAndDestroy( 3 ); // linkBuffer, contactLink, dialData |
|
350 } |
|
351 else |
|
352 { |
|
353 CleanupStack::PopAndDestroy( 2 ); // title, dialData |
|
354 } |
|
355 |
|
356 |
|
357 // If the command id is EPbk2CmdCall it means the call was launched |
|
358 // with send key and we therefore must use different AIW command |
|
359 // than when the call was selected from the menu |
|
360 if ( iCommandId == EPbk2CmdCall ) |
|
361 { |
|
362 iServiceHandler.ExecuteServiceCmdL( |
|
363 KAiwCmdCall, |
|
364 inParamList, |
|
365 iServiceHandler.OutParamListL(), |
|
366 0, // No options used. |
|
367 NULL); // No need for callback |
|
368 } |
|
369 else // the call was launched from menu |
|
370 { |
|
371 // Relay the command to AIW for handling |
|
372 iServiceHandler.ExecuteMenuCmdL( |
|
373 iCommandId, |
|
374 inParamList, |
|
375 iServiceHandler.OutParamListL(), |
|
376 0, // No options used. |
|
377 NULL); // No need for callback |
|
378 } |
|
379 |
|
380 // Update UI control |
|
381 if( iControl ) |
|
382 { |
|
383 TInt fieldIndex = iControl->FocusedFieldIndex(); |
|
384 iControl->ResetFindL(); |
|
385 if( iContact ) |
|
386 { |
|
387 iControl->SetFocusedContactL( *iContact ); |
|
388 } |
|
389 iControl->SetFocusedFieldIndex( fieldIndex ); |
|
390 } |
|
391 |
|
392 // Destroy itself as promised |
|
393 CleanupStack::PopAndDestroy(); // this |
|
394 } |
|
395 |
|
396 // -------------------------------------------------------------------------- |
|
397 // CPbk2CallCmd::ResetUiControl |
|
398 // -------------------------------------------------------------------------- |
|
399 // |
|
400 void CPbk2CallCmd::ResetUiControl( MPbk2ContactUiControl& aUiControl ) |
|
401 { |
|
402 if( iControl == &aUiControl ) |
|
403 { |
|
404 iControl = NULL; |
|
405 } |
|
406 } |
|
407 |
|
408 // -------------------------------------------------------------------------- |
|
409 // CPbk2CallCmd::AddObserver |
|
410 // -------------------------------------------------------------------------- |
|
411 // |
|
412 void CPbk2CallCmd::AddObserver( MPbk2CommandObserver& /*aObserver*/ ) |
|
413 { |
|
414 // Do nothing |
|
415 } |
|
416 |
|
417 // -------------------------------------------------------------------------- |
|
418 // CPbk2CallCmd::SetCallTypeL |
|
419 // -------------------------------------------------------------------------- |
|
420 // |
|
421 void CPbk2CallCmd::SetCallTypeL( CAiwDialDataExt& dialData ) |
|
422 { |
|
423 switch( iActionSelector ) |
|
424 { |
|
425 CAiwDialData::TCallType callType; |
|
426 case VPbkFieldTypeSelectorFactory::EEmptySelector: |
|
427 callType = iSelector.SelectCallTypeL |
|
428 ( iCommandId, *iContact, iControl->FocusedField(), *iSelectedField ); |
|
429 dialData.SetCallType( callType ); |
|
430 break; |
|
431 case VPbkFieldTypeSelectorFactory::EVoiceCallSelector: |
|
432 dialData.SetCallType( CAiwDialData::EAIWForcedCS ); |
|
433 break; |
|
434 case VPbkFieldTypeSelectorFactory::EVOIPCallSelector: |
|
435 callType = iSelector.SelectVoipCallTypeL( iSelectedField ); |
|
436 dialData.SetCallType( callType ); |
|
437 break; |
|
438 case VPbkFieldTypeSelectorFactory::EVideoCallSelector: |
|
439 dialData.SetCallType( CAiwDialData::EAIWForcedVideo ); |
|
440 break; |
|
441 default: |
|
442 dialData.SetCallType ( CAiwDialData::EAIWForcedCS); |
|
443 break; |
|
444 } |
|
445 } |
|
446 |
|
447 // -------------------------------------------------------------------------- |
|
448 // CPbk2CallCmd::ExtractXspId |
|
449 // -------------------------------------------------------------------------- |
|
450 // |
|
451 TBool CPbk2CallCmd::ExtractXspId( |
|
452 const MVPbkStoreContactField* aSelectedField, TPtrC& aXSPId ) const |
|
453 { |
|
454 TBool found = EFalse; |
|
455 _LIT( KColon, ":" ); |
|
456 |
|
457 const MVPbkContactFieldData& fieldData = aSelectedField->FieldData(); |
|
458 TPtrC data = GetFieldData( fieldData ); |
|
459 TInt pos = data.Find( KColon ); |
|
460 |
|
461 if ( pos > 0 ) |
|
462 { |
|
463 aXSPId.Set( data.Left( pos ) ); |
|
464 found = ETrue; |
|
465 } |
|
466 |
|
467 return found; |
|
468 } |
|
469 |
|
470 // -------------------------------------------------------------------------- |
|
471 // CPbk2CallCmd::GetMatchedServiceIdL |
|
472 // -------------------------------------------------------------------------- |
|
473 // |
|
474 TServiceId CPbk2CallCmd::GetMatchedServiceIdL( const TDesC& aXSPId ) |
|
475 { |
|
476 TUint ret = ( TUint )KErrNotFound; |
|
477 CDesCArrayFlat* nameArray = NULL; |
|
478 |
|
479 RIdArray ids; |
|
480 CleanupClosePushL( ids ); |
|
481 |
|
482 nameArray = new (ELeave) CDesCArrayFlat( 2 ); |
|
483 CleanupStack::PushL( nameArray ); |
|
484 |
|
485 CSPSettings* settings = CSPSettings::NewLC(); |
|
486 |
|
487 settings->FindServiceIdsL( ids ); |
|
488 settings->FindServiceNamesL( ids, *nameArray ); |
|
489 |
|
490 const TInt count = nameArray->MdcaCount(); |
|
491 for ( TInt i=0; i < count; i++ ) |
|
492 { |
|
493 // Find the mathched service |
|
494 TPtrC name = nameArray->MdcaPoint( i ); |
|
495 if ( !name.CompareF( aXSPId ) ) |
|
496 { |
|
497 // Service found |
|
498 ret = ids[i]; |
|
499 break; |
|
500 } |
|
501 } |
|
502 CleanupStack::PopAndDestroy( 3 ); // ids, nameArray, settings |
|
503 |
|
504 return ret; |
|
505 } |
|
506 |
|
507 // -------------------------------------------------------------------------- |
|
508 // CPbk2CallCmd::GetFieldData |
|
509 // -------------------------------------------------------------------------- |
|
510 // |
|
511 TPtrC CPbk2CallCmd::GetFieldData( const MVPbkContactFieldData& aFieldData ) const |
|
512 { |
|
513 TPtrC text ( KNullDesC() ); |
|
514 |
|
515 switch ( aFieldData.DataType() ) |
|
516 { |
|
517 // Text storage type |
|
518 case EVPbkFieldStorageTypeText: |
|
519 { |
|
520 const MVPbkContactFieldTextData& textData = MVPbkContactFieldTextData::Cast( aFieldData ); |
|
521 text.Set( textData.Text() ); |
|
522 break; |
|
523 } |
|
524 // URI storage type |
|
525 case EVPbkFieldStorageTypeUri: |
|
526 { |
|
527 const MVPbkContactFieldUriData& textData = MVPbkContactFieldUriData::Cast( aFieldData ); |
|
528 text.Set( textData.Text() ); |
|
529 break; |
|
530 } |
|
531 } |
|
532 |
|
533 return text; |
|
534 } |
|
535 |
|
536 // End of File |