|
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 type selector. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPbk2CallTypeSelector.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include <MPbk2ContactUiControl.h> |
|
24 #include <Pbk2Commands.hrh> |
|
25 #include <Pbk2UIControls.rsg> |
|
26 #include <TPbk2StoreContactAnalyzer.h> |
|
27 |
|
28 // Virtual Phonebook |
|
29 #include <CVPbkFieldTypeSelector.h> |
|
30 #include <MVPbkBaseContactField.h> |
|
31 #include <MVPbkStoreContact.h> |
|
32 #include <MVPbkFieldType.h> |
|
33 #include <CVPbkDefaultAttribute.h> |
|
34 #include <CVPbkContactManager.h> |
|
35 #include <RVPbkContactFieldDefaultPriorities.h> |
|
36 |
|
37 // System includes |
|
38 #include <coemain.h> |
|
39 #include <centralrepository.h> |
|
40 #include <AiwServiceHandler.h> |
|
41 #include <AiwPoCParameters.hrh> |
|
42 #include <featmgr.h> |
|
43 |
|
44 // -------------------------------------------------------------------------- |
|
45 // CPbk2CallTypeSelector::CPbk2CallTypeSelector |
|
46 // -------------------------------------------------------------------------- |
|
47 // |
|
48 CPbk2CallTypeSelector::CPbk2CallTypeSelector |
|
49 ( CVPbkContactManager& aContactManager ) : |
|
50 iContactManager( aContactManager ) |
|
51 { |
|
52 } |
|
53 |
|
54 // -------------------------------------------------------------------------- |
|
55 // CPbk2CallTypeSelector::~CPbk2CallTypeSelector |
|
56 // -------------------------------------------------------------------------- |
|
57 // |
|
58 CPbk2CallTypeSelector::~CPbk2CallTypeSelector() |
|
59 { |
|
60 FeatureManager::UnInitializeLib(); |
|
61 } |
|
62 |
|
63 // -------------------------------------------------------------------------- |
|
64 // CPbk2CallTypeSelector::NewL |
|
65 // -------------------------------------------------------------------------- |
|
66 // |
|
67 CPbk2CallTypeSelector* CPbk2CallTypeSelector::NewL |
|
68 ( CVPbkContactManager& aContactManager ) |
|
69 { |
|
70 CPbk2CallTypeSelector* self = |
|
71 new ( ELeave ) CPbk2CallTypeSelector( aContactManager ); |
|
72 CleanupStack::PushL( self ); |
|
73 self->ConstructL(); |
|
74 CleanupStack::Pop( self ); |
|
75 return self; |
|
76 } |
|
77 |
|
78 // -------------------------------------------------------------------------- |
|
79 // CPbk2CallTypeSelector::ConstructL |
|
80 // -------------------------------------------------------------------------- |
|
81 // |
|
82 void CPbk2CallTypeSelector::ConstructL() |
|
83 { |
|
84 FeatureManager::InitializeLibL(); |
|
85 } |
|
86 |
|
87 // -------------------------------------------------------------------------- |
|
88 // CPbk2CallTypeSelector::SelectCallTypeL |
|
89 // -------------------------------------------------------------------------- |
|
90 // |
|
91 CAiwDialData::TCallType CPbk2CallTypeSelector::SelectCallTypeL |
|
92 ( const TInt aCommandId, MVPbkStoreContact& aContact, |
|
93 const MVPbkBaseContactField* aFocusedField, |
|
94 const MVPbkBaseContactField& aSelectedField ) const |
|
95 { |
|
96 // Default to voice call |
|
97 CAiwDialData::TCallType ret = CAiwDialData::EAIWVoice; |
|
98 |
|
99 // If the command was launched via Call UI menu we do not |
|
100 // need to apply our own logic for call type selection. |
|
101 // But if the command was not launched via menu but via the send key |
|
102 // (which is the case when aCommandId is EPbk2CmdCall), we |
|
103 // need to deduct what kind of a call to launch. |
|
104 if ( aCommandId == EPbk2CmdCall ) |
|
105 { |
|
106 if ( !aFocusedField ) |
|
107 { |
|
108 // If there was no focused field, the call was |
|
109 // launched from names list |
|
110 ret = SelectCallTypeL( aContact, aSelectedField ); |
|
111 } |
|
112 else |
|
113 { |
|
114 // There was a focused field, so the |
|
115 // call was launched from info view |
|
116 ret = SelectCallTypeL( aSelectedField ); |
|
117 } |
|
118 } |
|
119 |
|
120 return ret; |
|
121 } |
|
122 |
|
123 // -------------------------------------------------------------------------- |
|
124 // CPbk2CallTypeSelector::OkToLaunchTelephonyCallL |
|
125 // -------------------------------------------------------------------------- |
|
126 // |
|
127 TBool CPbk2CallTypeSelector::OkToLaunchTelephonyCallL |
|
128 ( const MVPbkBaseContactField* aSelectedField ) const |
|
129 { |
|
130 // Default to yes |
|
131 TBool ret = ETrue; |
|
132 |
|
133 if ( aSelectedField ) |
|
134 { |
|
135 TPbk2StoreContactAnalyzer analyzer( iContactManager, NULL ); |
|
136 |
|
137 if ( analyzer.IsFieldTypeIncludedL( *aSelectedField, |
|
138 R_PHONEBOOK2_PTT_SELECTOR ) ) |
|
139 { |
|
140 // In case of PTT field, a POC call is to be launched |
|
141 ret = EFalse; |
|
142 } |
|
143 } |
|
144 |
|
145 return ret; |
|
146 } |
|
147 |
|
148 // -------------------------------------------------------------------------- |
|
149 // CPbk2CallTypeSelector::SelectPocCallType |
|
150 // -------------------------------------------------------------------------- |
|
151 // |
|
152 TInt CPbk2CallTypeSelector::SelectPocCallType |
|
153 ( const MPbk2ContactUiControl& aControl ) const |
|
154 { |
|
155 TInt ret = 0; |
|
156 |
|
157 // Check are we in a contact info field (which has focused field) |
|
158 if ( !aControl.FocusedField() ) |
|
159 { |
|
160 ret |= EAiwPoCCmdTalkMany; |
|
161 } |
|
162 |
|
163 if ( !aControl.ContactsMarked() ) |
|
164 { |
|
165 ret |= EAiwPoCCmdTalk1to1 | EAiwPoCCmdSendCallBackRequest; |
|
166 } |
|
167 |
|
168 return ret; |
|
169 } |
|
170 |
|
171 // -------------------------------------------------------------------------- |
|
172 // CPbk2CallTypeSelector::SelectPocCallTypeForPocKeyPress |
|
173 // -------------------------------------------------------------------------- |
|
174 // |
|
175 TInt CPbk2CallTypeSelector::SelectPocCallTypeForPocKeyPress |
|
176 ( const MPbk2ContactUiControl& aControl ) const |
|
177 { |
|
178 TInt all = SelectPocCallType( aControl ); |
|
179 TInt ret = all; |
|
180 |
|
181 // There is no specified logic for selecting a type. |
|
182 // So just define some priority for the call types. |
|
183 if ( all & EAiwPoCCmdTalkGroup ) |
|
184 { |
|
185 ret = EAiwPoCCmdTalkGroup; |
|
186 } |
|
187 else if (all & EAiwPoCCmdTalk1to1) |
|
188 { |
|
189 ret = EAiwPoCCmdTalk1to1; |
|
190 } |
|
191 else if (all & EAiwPoCCmdTalkMany) |
|
192 { |
|
193 ret = EAiwPoCCmdTalkMany; |
|
194 } |
|
195 else if (all & EAiwPoCCmdSendCallBackRequest) |
|
196 { |
|
197 ret = EAiwPoCCmdSendCallBackRequest; |
|
198 } |
|
199 |
|
200 return ret; |
|
201 } |
|
202 |
|
203 // -------------------------------------------------------------------------- |
|
204 // CPbk2CallTypeSelector::SetDefaultPrioritiesLC |
|
205 // -------------------------------------------------------------------------- |
|
206 // |
|
207 void CPbk2CallTypeSelector::SetDefaultPrioritiesLC |
|
208 ( RVPbkContactFieldDefaultPriorities& aDefaults, |
|
209 MVPbkStoreContact& aContact ) const |
|
210 { |
|
211 CleanupClosePushL( aDefaults ); |
|
212 |
|
213 if ( HasContactAttributeL( EVPbkDefaultTypePhoneNumber, aContact ) ) |
|
214 { |
|
215 // Voice overrides everything else |
|
216 User::LeaveIfError( aDefaults.Append( EVPbkDefaultTypePhoneNumber ) ); |
|
217 } |
|
218 else if ( HasContactAttributeL( EVPbkDefaultTypeVoIP, aContact ) ) |
|
219 { |
|
220 // VoIP overrides everything but voice |
|
221 User::LeaveIfError( aDefaults.Append( EVPbkDefaultTypeVoIP ) ); |
|
222 } |
|
223 else if ( HasContactAttributeL( EVPbkDefaultTypeVideoNumber, aContact ) ) |
|
224 { |
|
225 // Video overrides POC |
|
226 User::LeaveIfError( aDefaults.Append( EVPbkDefaultTypeVideoNumber ) ); |
|
227 } |
|
228 else if ( HasContactAttributeL( EVPbkDefaultTypePOC, aContact ) ) |
|
229 { |
|
230 // Only POC default exists, lets use it |
|
231 User::LeaveIfError( aDefaults.Append( EVPbkDefaultTypePOC ) ); |
|
232 } |
|
233 } |
|
234 |
|
235 // -------------------------------------------------------------------------- |
|
236 // CPbk2CallTypeSelector::SelectCallTypeL |
|
237 // Selects call type based on selected field and |
|
238 // contacts default information. |
|
239 // -------------------------------------------------------------------------- |
|
240 // |
|
241 inline CAiwDialData::TCallType CPbk2CallTypeSelector::SelectCallTypeL |
|
242 ( MVPbkStoreContact& aContact, |
|
243 const MVPbkBaseContactField& aSelectedField ) const |
|
244 { |
|
245 // Default to voice call |
|
246 CAiwDialData::TCallType ret = CAiwDialData::EAIWVoice; |
|
247 |
|
248 if ( HasContactAttributeL( EVPbkDefaultTypePhoneNumber, aContact ) ) |
|
249 { |
|
250 ret = CAiwDialData::EAIWVoice; |
|
251 } |
|
252 else if ( ( HasContactAttributeL( EVPbkDefaultTypeVoIP, aContact ) ) && |
|
253 ( FeatureManager::FeatureSupported( KFeatureIdCommonVoip ) ) ) |
|
254 { |
|
255 ret = CAiwDialData::EAIWVoiP; |
|
256 } |
|
257 else if ( HasContactAttributeL( EVPbkDefaultTypeVideoNumber, aContact ) ) |
|
258 { |
|
259 ret = CAiwDialData::EAIWForcedVideo; |
|
260 } |
|
261 else |
|
262 { |
|
263 // No defaults, so select based on selected field type only |
|
264 ret = SelectCallTypeBasedOnFieldTypeL( aSelectedField ); |
|
265 } |
|
266 |
|
267 return ret; |
|
268 } |
|
269 |
|
270 // -------------------------------------------------------------------------- |
|
271 // CPbk2CallTypeSelector::SelectCallTypeL |
|
272 // Select call type based on field type, the preferred telephony |
|
273 // information setting is taken in consideration also. |
|
274 // -------------------------------------------------------------------------- |
|
275 // |
|
276 inline CAiwDialData::TCallType CPbk2CallTypeSelector::SelectCallTypeL |
|
277 ( const MVPbkBaseContactField& aSelectedField ) const |
|
278 { |
|
279 // When there is clearly a selected field, the call type |
|
280 // of course depends on the type of the field |
|
281 return SelectCallTypeBasedOnFieldTypeL( aSelectedField ); |
|
282 } |
|
283 |
|
284 // -------------------------------------------------------------------------- |
|
285 // CPbk2CallTypeSelector::SelectCallTypeBasedOnFieldTypeL |
|
286 // This function selects the call type by the type of passed |
|
287 // aSelectedField alone. |
|
288 // -------------------------------------------------------------------------- |
|
289 // |
|
290 inline CAiwDialData::TCallType |
|
291 CPbk2CallTypeSelector::SelectCallTypeBasedOnFieldTypeL |
|
292 ( const MVPbkBaseContactField& aSelectedField ) const |
|
293 { |
|
294 // Default to voice call |
|
295 CAiwDialData::TCallType ret = CAiwDialData::EAIWVoice; |
|
296 |
|
297 TPbk2StoreContactAnalyzer analyzer( iContactManager, NULL ); |
|
298 |
|
299 if ( analyzer.IsFieldTypeIncludedL( aSelectedField, |
|
300 R_PHONEBOOK2_SIP_SELECTOR ) ) |
|
301 { |
|
302 ret = CAiwDialData::EAIWVoiP; |
|
303 } |
|
304 else if ( analyzer.IsFieldTypeIncludedL( aSelectedField, |
|
305 R_PHONEBOOK2_VIDEO_SELECTOR ) ) |
|
306 { |
|
307 ret = CAiwDialData::EAIWForcedVideo; |
|
308 } |
|
309 |
|
310 return ret; |
|
311 } |
|
312 |
|
313 // -------------------------------------------------------------------------- |
|
314 // CPbk2CallTypeSelector::HasContactAttributeL |
|
315 // Checks if aContact has default attribute of given type. |
|
316 // -------------------------------------------------------------------------- |
|
317 // |
|
318 TBool CPbk2CallTypeSelector::HasContactAttributeL |
|
319 ( TVPbkDefaultType aType, MVPbkStoreContact& aContact ) const |
|
320 { |
|
321 TBool retval = EFalse; |
|
322 |
|
323 CVPbkDefaultAttribute* attr = CVPbkDefaultAttribute::NewL( aType ); |
|
324 CleanupStack::PushL( attr ); |
|
325 MVPbkContactAttributeManager& attrManager = |
|
326 iContactManager.ContactAttributeManagerL(); |
|
327 retval = attrManager.HasContactAttributeL( *attr, aContact ); |
|
328 CleanupStack::PopAndDestroy( attr ); |
|
329 |
|
330 return retval; |
|
331 } |
|
332 |
|
333 // -------------------------------------------------------------------------- |
|
334 // CPbk2CallTypeSelector::SetDefaultPrioritiesLC |
|
335 // -------------------------------------------------------------------------- |
|
336 // |
|
337 void CPbk2CallTypeSelector::SetDefaultPrioritiesLC |
|
338 ( RVPbkContactFieldDefaultPriorities& aDefaults, |
|
339 MVPbkStoreContact& aContact, |
|
340 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelector ) const |
|
341 { |
|
342 CleanupClosePushL( aDefaults ); |
|
343 |
|
344 switch( aSelector ) |
|
345 { |
|
346 case VPbkFieldTypeSelectorFactory::EVoiceCallSelector : |
|
347 if ( HasContactAttributeL( EVPbkDefaultTypePhoneNumber, aContact ) ) |
|
348 { |
|
349 User::LeaveIfError( aDefaults.Append( EVPbkDefaultTypePhoneNumber ) ); |
|
350 } |
|
351 break; |
|
352 case VPbkFieldTypeSelectorFactory::EVOIPCallSelector : |
|
353 if ( HasContactAttributeL( EVPbkDefaultTypeVoIP, aContact ) ) |
|
354 { |
|
355 User::LeaveIfError( aDefaults.Append( EVPbkDefaultTypeVoIP ) ); |
|
356 } |
|
357 break; |
|
358 case VPbkFieldTypeSelectorFactory::EVideoCallSelector : |
|
359 if ( HasContactAttributeL( EVPbkDefaultTypeVideoNumber, aContact ) ) |
|
360 { |
|
361 User::LeaveIfError( aDefaults.Append( EVPbkDefaultTypeVideoNumber ) ); |
|
362 } |
|
363 break; |
|
364 case VPbkFieldTypeSelectorFactory::EPocSelector : |
|
365 if ( HasContactAttributeL( EVPbkDefaultTypePOC, aContact ) ) |
|
366 { |
|
367 User::LeaveIfError( aDefaults.Append( EVPbkDefaultTypePOC ) ); |
|
368 } |
|
369 break; |
|
370 default: |
|
371 break; |
|
372 } |
|
373 } |
|
374 |
|
375 // -------------------------------------------------------------------------- |
|
376 // CPbk2CallTypeSelector::SelectVoipCallTypeL |
|
377 // -------------------------------------------------------------------------- |
|
378 // |
|
379 CAiwDialData::TCallType CPbk2CallTypeSelector::SelectVoipCallTypeL( |
|
380 const MVPbkBaseContactField* aSelectedField ) const |
|
381 { |
|
382 // Default to CAiwDialData::EAIWVoiP |
|
383 CAiwDialData::TCallType ret = CAiwDialData::EAIWVoiP; |
|
384 |
|
385 TPbk2StoreContactAnalyzer analyzer( iContactManager, NULL ); |
|
386 |
|
387 // Call type should be set CAiwDialData::EAIWVoice |
|
388 // if mobile field (or other CS field) is selected |
|
389 if ( analyzer.IsFieldTypeIncludedL( *aSelectedField, |
|
390 R_PHONEBOOK2_VOIP_CALL_OUT_SELECTOR ) ) |
|
391 { |
|
392 ret = CAiwDialData::EAIWVoice ; |
|
393 } |
|
394 |
|
395 return ret; |
|
396 } |
|
397 |
|
398 // End of File |