|
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 // Debugging headers |
|
52 #include <Pbk2Debug.h> |
|
53 |
|
54 /// Unnamed namespace for local definitions |
|
55 namespace { |
|
56 |
|
57 #ifdef _DEBUG |
|
58 enum TPanicCode |
|
59 { |
|
60 EPanicPreCond_ExecuteLD = 1 |
|
61 }; |
|
62 |
|
63 void Panic(TPanicCode aReason) |
|
64 { |
|
65 _LIT(KPanicText, "CPbk2CallCmd"); |
|
66 User::Panic(KPanicText,aReason); |
|
67 } |
|
68 #endif // _DEBUG |
|
69 |
|
70 /** |
|
71 * Field type matcher. |
|
72 * |
|
73 * @param aFieldTypeList List of field types. |
|
74 * @param aFieldType Field type to search for. |
|
75 * @param aResourceId Field type selector resources. |
|
76 * @return ETrue if match was found. |
|
77 */ |
|
78 TBool MatchesFieldTypeL |
|
79 ( const MVPbkFieldTypeList& aFieldTypeList, |
|
80 const MVPbkFieldType& aFieldType, |
|
81 TInt aResourceId ) |
|
82 { |
|
83 TResourceReader reader; |
|
84 CCoeEnv::Static()->CreateResourceReaderLC( reader, aResourceId ); |
|
85 |
|
86 CVPbkFieldTypeSelector* selector = CVPbkFieldTypeSelector::NewL |
|
87 ( reader, aFieldTypeList ); |
|
88 |
|
89 // Check if the field type is the one needed |
|
90 TBool ret = selector->IsFieldTypeIncluded(aFieldType); |
|
91 CleanupStack::PopAndDestroy(); // resource buffer |
|
92 delete selector; |
|
93 return ret; |
|
94 } |
|
95 |
|
96 /** |
|
97 * Sets a phone number to AIW dial data. |
|
98 * |
|
99 * @param aDialData Dial data to modify. |
|
100 * @param aContact Contact containing the number. |
|
101 */ |
|
102 void SetDialDataNumberL |
|
103 ( CAiwDialDataExt& aDialData, const MVPbkStoreContact& aContact ) |
|
104 { |
|
105 const MVPbkFieldTypeList& fieldTypeList = |
|
106 aContact.ParentStore().StoreProperties().SupportedFields(); |
|
107 const MVPbkStoreContactFieldCollection& fieldCollection = |
|
108 aContact.Fields(); |
|
109 TInt fieldCount( fieldCollection.FieldCount() ); |
|
110 for ( TInt i = 0; i < fieldCount; ++i ) |
|
111 { |
|
112 const MVPbkStoreContactField& field = fieldCollection.FieldAt( i ); |
|
113 const MVPbkFieldType* fieldType = field.BestMatchingFieldType(); |
|
114 if( MatchesFieldTypeL( fieldTypeList, *fieldType, |
|
115 R_PHONEBOOK2_PHONENUMBER_SELECTOR ) ) |
|
116 { |
|
117 const MVPbkContactFieldTextData* textData = |
|
118 &MVPbkContactFieldTextData::Cast |
|
119 ( field.FieldData() ); |
|
120 const TDesC& phoneNumber( textData->Text().Left |
|
121 ( AIWDialData::KMaximumPhoneNumberLength ) ); |
|
122 aDialData.SetPhoneNumberL( phoneNumber ); |
|
123 } |
|
124 } |
|
125 } |
|
126 |
|
127 /** |
|
128 * Sets a phone number to AIW dial data. |
|
129 * |
|
130 * @param aDialData Dial data to modify. |
|
131 * @param aField Contact field containing the number. |
|
132 */ |
|
133 void SetDialDataNumberL |
|
134 ( CAiwDialDataExt& aDialData, const MVPbkStoreContactField& aField ) |
|
135 { |
|
136 TVPbkFieldStorageType dataType = aField.FieldData().DataType(); |
|
137 |
|
138 if ( dataType == EVPbkFieldStorageTypeText ) |
|
139 { |
|
140 const MVPbkContactFieldTextData* textData = |
|
141 &MVPbkContactFieldTextData::Cast( aField.FieldData() ); |
|
142 const TDesC& phoneNumber( textData->Text().Left |
|
143 ( AIWDialData::KMaximumPhoneNumberLength ) ); |
|
144 aDialData.SetPhoneNumberL( phoneNumber ); |
|
145 } |
|
146 |
|
147 if ( dataType == EVPbkFieldStorageTypeUri ) |
|
148 { |
|
149 const MVPbkContactFieldUriData* textData = |
|
150 &MVPbkContactFieldUriData::Cast( aField.FieldData() ); |
|
151 const TDesC& phoneNumber( textData->Text().Left |
|
152 ( AIWDialData::KMaximumPhoneNumberLength ) ); |
|
153 aDialData.SetPhoneNumberL( phoneNumber ); |
|
154 } |
|
155 } |
|
156 } /// namespace |
|
157 |
|
158 // -------------------------------------------------------------------------- |
|
159 // CPbk2CallCmd::CPbk2CallCmd |
|
160 // -------------------------------------------------------------------------- |
|
161 // |
|
162 CPbk2CallCmd::CPbk2CallCmd( MVPbkStoreContact*& aContact, |
|
163 MVPbkStoreContactField* aSelectedField, |
|
164 MPbk2ContactUiControl& aControl, |
|
165 const TInt aCommandId, CAiwServiceHandler& aServiceHandler, |
|
166 CPbk2CallTypeSelector& aSelector, |
|
167 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aActionSelector ) : |
|
168 iContact( aContact ), |
|
169 iSelectedField( aSelectedField ), |
|
170 iControl( &aControl ), |
|
171 iCommandId( aCommandId ), |
|
172 iServiceHandler( aServiceHandler ), |
|
173 iSelector( aSelector ), |
|
174 iActionSelector( aActionSelector ) |
|
175 |
|
176 { |
|
177 PBK2_DEBUG_PRINT |
|
178 (PBK2_DEBUG_STRING("CPbk2CallCmd::CPbk2CallCmd(0x%x)"), this); |
|
179 |
|
180 iControl->RegisterCommand( this ); |
|
181 } |
|
182 |
|
183 // -------------------------------------------------------------------------- |
|
184 // CPbk2CallCmd::~CPbk2CallCmd |
|
185 // -------------------------------------------------------------------------- |
|
186 // |
|
187 CPbk2CallCmd::~CPbk2CallCmd() |
|
188 { |
|
189 PBK2_DEBUG_PRINT |
|
190 (PBK2_DEBUG_STRING("CPbk2CallCmd::~CPbk2CallCmd(0x%x)"), this); |
|
191 |
|
192 delete iSelectedField; |
|
193 if( iControl ) |
|
194 { |
|
195 iControl->RegisterCommand( NULL ); |
|
196 } |
|
197 } |
|
198 |
|
199 // -------------------------------------------------------------------------- |
|
200 // CPbk2CallCmd::NewL |
|
201 // -------------------------------------------------------------------------- |
|
202 // |
|
203 CPbk2CallCmd* CPbk2CallCmd::NewL( MVPbkStoreContact*& aContact, |
|
204 MVPbkStoreContactField* aSelectedField, |
|
205 MPbk2ContactUiControl& aControl, |
|
206 const TInt aCommandId, CAiwServiceHandler& aServiceHandler, |
|
207 CPbk2CallTypeSelector& aSelector ) |
|
208 { |
|
209 CPbk2CallCmd* self = new (ELeave ) CPbk2CallCmd |
|
210 ( aContact, aSelectedField, aControl, aCommandId, |
|
211 aServiceHandler, aSelector, VPbkFieldTypeSelectorFactory::EEmptySelector ); |
|
212 return self; |
|
213 } |
|
214 |
|
215 // -------------------------------------------------------------------------- |
|
216 // CPbk2CallCmd::NewL |
|
217 // -------------------------------------------------------------------------- |
|
218 // |
|
219 CPbk2CallCmd* CPbk2CallCmd::NewL( MVPbkStoreContact*& aContact, |
|
220 MVPbkStoreContactField* aSelectedField, |
|
221 MPbk2ContactUiControl& aControl, |
|
222 const TInt aCommandId, CAiwServiceHandler& aServiceHandler, |
|
223 CPbk2CallTypeSelector& aSelector, |
|
224 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aActionSelector ) |
|
225 { |
|
226 CPbk2CallCmd* self = new (ELeave ) CPbk2CallCmd |
|
227 ( aContact, aSelectedField, aControl, aCommandId, |
|
228 aServiceHandler, aSelector, aActionSelector ); |
|
229 return self; |
|
230 } |
|
231 |
|
232 // -------------------------------------------------------------------------- |
|
233 // CPbk2CallCmd::ExecuteLD |
|
234 // -------------------------------------------------------------------------- |
|
235 // |
|
236 void CPbk2CallCmd::ExecuteLD() |
|
237 { |
|
238 PBK2_DEBUG_PRINT |
|
239 (PBK2_DEBUG_STRING("CPbk2CallCmd::ExecuteLD(0x%x)"), this); |
|
240 |
|
241 CleanupStack::PushL( this ); |
|
242 |
|
243 // Setup dial data |
|
244 CAiwDialDataExt* dialData = CAiwDialDataExt::NewLC(); |
|
245 dialData->SetWindowGroup |
|
246 ( CCoeEnv::Static()->RootWin().Identifier() ); |
|
247 |
|
248 // If there is a default service, use the service |
|
249 TUint serviceId; |
|
250 CSPSettingsVoIPUtils* sPSettings = CSPSettingsVoIPUtils::NewLC(); |
|
251 if ( !sPSettings->GetPreferredService( serviceId ) ) |
|
252 { |
|
253 dialData->SetServiceId( serviceId ); |
|
254 } |
|
255 CleanupStack::PopAndDestroy( sPSettings ); |
|
256 |
|
257 MVPbkContactLink* contactLink = NULL; |
|
258 |
|
259 if ( iCommandId == EPbk2CmdCall ) |
|
260 { |
|
261 // Call was launched with send key, which means |
|
262 // Phonebook has performed address select by itself |
|
263 // and there is selected field instance |
|
264 __ASSERT_DEBUG( iSelectedField && |
|
265 ( iSelectedField->FieldData().DataType() == |
|
266 EVPbkFieldStorageTypeText || |
|
267 iSelectedField->FieldData().DataType() == |
|
268 EVPbkFieldStorageTypeUri ), |
|
269 Panic( EPanicPreCond_ExecuteLD ) ); |
|
270 |
|
271 // Create field link |
|
272 contactLink = iSelectedField->CreateLinkLC(); |
|
273 |
|
274 // Set number |
|
275 SetDialDataNumberL( *dialData, *iSelectedField ); |
|
276 |
|
277 // We also have select call type by ourselves |
|
278 SetCallTypeL( *dialData ); |
|
279 } |
|
280 else |
|
281 { |
|
282 if ( iSelectedField ) |
|
283 { |
|
284 // If selected field is set create field link from it. |
|
285 contactLink = iSelectedField->CreateLinkLC(); |
|
286 } |
|
287 else |
|
288 { |
|
289 // Otherwise use contact |
|
290 contactLink = iContact->CreateLinkLC(); |
|
291 } |
|
292 |
|
293 if ( !contactLink ) |
|
294 { |
|
295 // Temporary contact, set number here |
|
296 SetDialDataNumberL( *dialData, *iContact ); |
|
297 } |
|
298 } |
|
299 |
|
300 if ( contactLink ) |
|
301 { |
|
302 HBufC8* linkBuffer = contactLink->PackLC(); |
|
303 dialData->SetContactLinkL( *linkBuffer ); |
|
304 } |
|
305 else |
|
306 { |
|
307 CPbk2ApplicationServices* appServices = CPbk2ApplicationServices::InstanceLC(); |
|
308 MPbk2ContactNameFormatter& nameFormatter = |
|
309 appServices->NameFormatter(); |
|
310 const MVPbkStoreContactFieldCollection& fieldCollection = |
|
311 iContact->Fields(); |
|
312 HBufC* title = nameFormatter.GetContactTitleOrNullL( |
|
313 fieldCollection, |
|
314 MPbk2ContactNameFormatter::EPreserveLeadingSpaces ); |
|
315 CleanupStack::PopAndDestroy(); |
|
316 CleanupStack::PushL( title ); |
|
317 |
|
318 if ( title ) |
|
319 { |
|
320 dialData->SetNameL( *title ); |
|
321 } |
|
322 } |
|
323 |
|
324 // Get an empty in param list.. |
|
325 CAiwGenericParamList& inParamList = iServiceHandler.InParamListL(); |
|
326 // ..and pass it to dial data in order for it to fill it |
|
327 dialData->FillInParamListL( inParamList ); |
|
328 |
|
329 if ( contactLink ) |
|
330 { |
|
331 CleanupStack::PopAndDestroy( 3 ); // linkBuffer, contactLink, dialData |
|
332 } |
|
333 else |
|
334 { |
|
335 CleanupStack::PopAndDestroy( 2 ); // title, dialData |
|
336 } |
|
337 |
|
338 |
|
339 // If the command id is EPbk2CmdCall it means the call was launched |
|
340 // with send key and we therefore must use different AIW command |
|
341 // than when the call was selected from the menu |
|
342 if ( iCommandId == EPbk2CmdCall ) |
|
343 { |
|
344 iServiceHandler.ExecuteServiceCmdL( |
|
345 KAiwCmdCall, |
|
346 inParamList, |
|
347 iServiceHandler.OutParamListL(), |
|
348 0, // No options used. |
|
349 NULL); // No need for callback |
|
350 } |
|
351 else // the call was launched from menu |
|
352 { |
|
353 // Relay the command to AIW for handling |
|
354 iServiceHandler.ExecuteMenuCmdL( |
|
355 iCommandId, |
|
356 inParamList, |
|
357 iServiceHandler.OutParamListL(), |
|
358 0, // No options used. |
|
359 NULL); // No need for callback |
|
360 } |
|
361 |
|
362 // Update UI control |
|
363 if( iControl ) |
|
364 { |
|
365 TInt fieldIndex = iControl->FocusedFieldIndex(); |
|
366 iControl->ResetFindL(); |
|
367 if( iContact ) |
|
368 { |
|
369 iControl->SetFocusedContactL( *iContact ); |
|
370 } |
|
371 iControl->SetFocusedFieldIndex( fieldIndex ); |
|
372 } |
|
373 |
|
374 // Destroy itself as promised |
|
375 CleanupStack::PopAndDestroy(); // this |
|
376 } |
|
377 |
|
378 // -------------------------------------------------------------------------- |
|
379 // CPbk2CallCmd::ResetUiControl |
|
380 // -------------------------------------------------------------------------- |
|
381 // |
|
382 void CPbk2CallCmd::ResetUiControl( MPbk2ContactUiControl& aUiControl ) |
|
383 { |
|
384 if( iControl == &aUiControl ) |
|
385 { |
|
386 iControl = NULL; |
|
387 } |
|
388 } |
|
389 |
|
390 // -------------------------------------------------------------------------- |
|
391 // CPbk2CallCmd::AddObserver |
|
392 // -------------------------------------------------------------------------- |
|
393 // |
|
394 void CPbk2CallCmd::AddObserver( MPbk2CommandObserver& /*aObserver*/ ) |
|
395 { |
|
396 // Do nothing |
|
397 } |
|
398 |
|
399 // -------------------------------------------------------------------------- |
|
400 // CPbk2CallCmd::SetCallTypeL |
|
401 // -------------------------------------------------------------------------- |
|
402 // |
|
403 void CPbk2CallCmd::SetCallTypeL( CAiwDialDataExt& dialData ) |
|
404 { |
|
405 switch( iActionSelector ) |
|
406 { |
|
407 CAiwDialData::TCallType callType; |
|
408 case VPbkFieldTypeSelectorFactory::EEmptySelector: |
|
409 callType = iSelector.SelectCallTypeL |
|
410 ( iCommandId, *iContact, iControl->FocusedField(), *iSelectedField ); |
|
411 dialData.SetCallType( callType ); |
|
412 break; |
|
413 case VPbkFieldTypeSelectorFactory::EVoiceCallSelector: |
|
414 dialData.SetCallType( CAiwDialData::EAIWForcedCS ); |
|
415 break; |
|
416 case VPbkFieldTypeSelectorFactory::EVOIPCallSelector: |
|
417 callType = iSelector.SelectVoipCallTypeL( iSelectedField ); |
|
418 dialData.SetCallType( callType ); |
|
419 break; |
|
420 case VPbkFieldTypeSelectorFactory::EVideoCallSelector: |
|
421 dialData.SetCallType( CAiwDialData::EAIWForcedVideo ); |
|
422 break; |
|
423 default: |
|
424 dialData.SetCallType ( CAiwDialData::EAIWForcedCS); |
|
425 break; |
|
426 } |
|
427 } |
|
428 |
|
429 // End of File |