1 /* |
|
2 * Copyright (c) 2008 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: This module contains the implementation of |
|
15 * : CSsServiceHandlerVoip class |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cssservicehandlervoip.h" |
|
22 #include "cssconnectionhandler.h" |
|
23 #include "cssuiutilities.h" |
|
24 #include "cssserviceutilities.h" |
|
25 #include "csssettingshandler.h" |
|
26 #include "cssbshandler.h" |
|
27 #include "csslogger.h" |
|
28 #include <serviceselector.rsg> |
|
29 #include <spdefinitions.h> |
|
30 #include <spsettingsvoiputils.h> |
|
31 #include <data_caging_path_literals.hrh> |
|
32 #include <eikenv.h> |
|
33 |
|
34 |
|
35 // CONSTANTS |
|
36 // Selection list array granularity |
|
37 const TInt KSsArrayGranularity = 2; |
|
38 // CS service id |
|
39 const TInt KGSMServiceId = 1; |
|
40 // List item array size |
|
41 const TInt KSsLbxItemsArraySize = 3; |
|
42 // Format of the selection list query. |
|
43 _LIT( KQueryItemFormat, "%d\t%S" ); |
|
44 // Branding id |
|
45 const TInt KSsBrandingIdLength = 512; |
|
46 // Integer length |
|
47 const TInt KSsIntegerLength = 10; |
|
48 |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================================= |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CSsServiceHandlerVoip::CSsServiceHandlerVoip |
|
54 // C++ constructor can NOT contain any code, that |
|
55 // might leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CSsServiceHandlerVoip::CSsServiceHandlerVoip |
|
59 ( |
|
60 // None. |
|
61 ) |
|
62 { |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CSsServiceHandlerVoip::ConstructL |
|
67 // Symbian 2nd phase constructor can leave. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CSsServiceHandlerVoip::ConstructL() |
|
71 { |
|
72 iConnectionHandler = CSsConnectionHandler::NewL(); |
|
73 iVoipUtils = CSPSettingsVoIPUtils::NewL(); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CSsServiceHandlerVoip::NewL |
|
78 // Two-phased constructor. |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CSsServiceHandlerVoip* CSsServiceHandlerVoip::NewL |
|
82 ( |
|
83 // None. |
|
84 ) |
|
85 { |
|
86 CSsServiceHandlerVoip* self = new ( ELeave ) CSsServiceHandlerVoip(); |
|
87 CleanupStack::PushL( self ); |
|
88 self->ConstructL(); |
|
89 CleanupStack::Pop( self ); |
|
90 return self; |
|
91 } |
|
92 |
|
93 // Destructor |
|
94 CSsServiceHandlerVoip::~CSsServiceHandlerVoip |
|
95 ( |
|
96 // None. |
|
97 ) |
|
98 { |
|
99 delete iVoipUtils; |
|
100 delete iConnectionHandler; |
|
101 delete iUiUtils; |
|
102 delete iSettings; |
|
103 delete iBsHandler; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CSsServiceHandlerVoip::ExecuteServiceSelectionL |
|
108 // Gets the calling service by current call type and service id. |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 void CSsServiceHandlerVoip::ExecuteServiceSelectionL |
|
112 ( |
|
113 CConvergedServiceSelector::TSsResult& aResult, |
|
114 CConvergedServiceSelector::TSsCallType /*aCallType*/, |
|
115 TUint aServiceId, |
|
116 TBool aSendKey, |
|
117 const TDesC& aString |
|
118 ) |
|
119 { |
|
120 CSSLOGSTRING("CSSelector::ExecuteVoip"); |
|
121 |
|
122 if ( 0 != aServiceId && KGSMServiceId != aServiceId ) |
|
123 { |
|
124 // Service id is known, just set correct calltype |
|
125 // and registration status. |
|
126 GetServiceByServiceId( aResult, aServiceId, aSendKey, aString ); |
|
127 } |
|
128 else |
|
129 { |
|
130 // Service id is not known or CS service |
|
131 // so we have to choce from available voip services. |
|
132 GetCallingServiceL( aResult ); |
|
133 } |
|
134 |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CSsServiceHandlerVoip::GetServiceByServiceId |
|
139 // Gets calling service by known service id. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 void CSsServiceHandlerVoip::GetServiceByServiceId |
|
143 ( |
|
144 CConvergedServiceSelector::TSsResult& aResult, |
|
145 TUint aServiceId, |
|
146 TBool aSendKey, |
|
147 const TDesC& aString |
|
148 ) const |
|
149 { |
|
150 if ( aSendKey && ChangeTypeAsCsVoice( aServiceId, aString ) ) |
|
151 { |
|
152 // Set (CS)voice call parameters |
|
153 // CallType, Service id and GSM service is always "enabled" |
|
154 SsServiceUtilities::SetServiceResult( |
|
155 aResult, |
|
156 CConvergedServiceSelector::ESsVoiceCall, |
|
157 KGSMServiceId, |
|
158 ETrue ); |
|
159 } |
|
160 else |
|
161 { |
|
162 // Get current registration status for the service. |
|
163 // This may be unnecessary at the moment because we don't show |
|
164 // "Register now?" note anymore and currently clients don't use the |
|
165 // registration status for anything. |
|
166 TBool registered( iConnectionHandler->IsVoipServiceRegistered( |
|
167 aServiceId ) ); |
|
168 |
|
169 // Set results |
|
170 SsServiceUtilities::SetServiceResult( |
|
171 aResult, |
|
172 CConvergedServiceSelector::ESsVoipCall, |
|
173 aServiceId, |
|
174 registered ); |
|
175 } |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CSsServiceHandlerVoip::GetCallingServiceL |
|
180 // Gets calling service without service id. |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CSsServiceHandlerVoip::GetCallingServiceL |
|
184 ( |
|
185 CConvergedServiceSelector::TSsResult& aResult |
|
186 ) |
|
187 { |
|
188 TInt error( KErrNone ); |
|
189 TBool registered( EFalse ); |
|
190 RArray<TUint> services; |
|
191 CleanupClosePushL( services ); |
|
192 |
|
193 // First try to find registered services to be used if not any available |
|
194 // then try to find unregistered services. |
|
195 error = SettingsHandlerL().GetRegisteredServices( |
|
196 *iConnectionHandler, services ); |
|
197 |
|
198 if ( KErrNone != error ) |
|
199 { |
|
200 error = SettingsHandlerL().GetAllServices( services ); |
|
201 } |
|
202 else |
|
203 { |
|
204 registered = ETrue; |
|
205 } |
|
206 |
|
207 CSSLOGSTRING2("CSSelector::Service error:%d", error); |
|
208 if ( KErrNone != error ) |
|
209 { |
|
210 CSSLOGSTRING("CSSelector::Services not available"); |
|
211 if ( KErrNoMemory == error ) |
|
212 { |
|
213 User::Leave( error ); |
|
214 } |
|
215 // No voip services available/configured. |
|
216 // Launch information note and leave. |
|
217 UiUtilitiesL().ShowInformationNoteL( R_NO_SERVICE_AVAILABLE ); |
|
218 User::Leave( KErrNotFound ); |
|
219 } |
|
220 |
|
221 |
|
222 // Select service. Show list query |
|
223 // if more than one services available. |
|
224 SelectServiceL( aResult, |
|
225 services, |
|
226 registered ); |
|
227 |
|
228 CleanupStack::PopAndDestroy( &services ); |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CSsServiceHandlerVoip::SelectServiceL |
|
233 // Makes service selection. |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CSsServiceHandlerVoip::SelectServiceL |
|
237 ( |
|
238 CConvergedServiceSelector::TSsResult& aResult, |
|
239 RArray<TUint>& aServices, |
|
240 TBool aRegistered |
|
241 ) |
|
242 { |
|
243 CSSLOGSTRING2("CSSelector::Service count:%d",aServices.Count()); |
|
244 if ( 0 == aServices.Count() ) |
|
245 { |
|
246 // Empty array, leave |
|
247 User::Leave( KErrNotFound ); |
|
248 } |
|
249 |
|
250 TUint serviceId( 0 ); |
|
251 if ( 1 < aServices.Count() ) |
|
252 { |
|
253 // Because more than one service available we have to |
|
254 // make selection list for the user. |
|
255 TInt index( KErrNotFound ); |
|
256 |
|
257 CDesCArrayFlat* lbxItems = |
|
258 new (ELeave) CDesCArrayFlat( KSsLbxItemsArraySize ); |
|
259 CleanupStack::PushL( lbxItems ); |
|
260 CArrayPtr<CGulIcon>* icons = |
|
261 new (ELeave) CAknIconArray( KSsLbxItemsArraySize ); |
|
262 CleanupStack::PushL( icons ); |
|
263 |
|
264 GetListBoxItemsAndIconsL( aServices, |
|
265 lbxItems, |
|
266 icons ); |
|
267 |
|
268 // List query takes ownership for icon array |
|
269 CleanupStack::Pop( icons ); |
|
270 |
|
271 // Select service by list query |
|
272 TBool ret = UiUtilitiesL().ShowListQueryL( |
|
273 index, R_PHONE_VOIP_CALL_TYPE_QUERY, lbxItems, icons ); |
|
274 |
|
275 CSSLOGSTRING2("CSSelector::Service list ret:%d", ret); |
|
276 CSSLOGSTRING2("CSSelector::Service list index:%d", index); |
|
277 |
|
278 |
|
279 // Make sure that the index is on the correct range and user has |
|
280 // not canceled the list query. |
|
281 if ( !ret || ( index < 0 || index >= aServices.Count() ) ) |
|
282 { |
|
283 // User cancels the query -> leave |
|
284 User::Leave( KErrCancel ); |
|
285 } |
|
286 |
|
287 CleanupStack::PopAndDestroy( lbxItems ); |
|
288 |
|
289 // Use the selected service. |
|
290 serviceId = aServices[index]; |
|
291 } |
|
292 else |
|
293 { |
|
294 // One service available, use it. |
|
295 serviceId = aServices[0]; |
|
296 } |
|
297 |
|
298 |
|
299 // Set results |
|
300 SsServiceUtilities::SetServiceResult( |
|
301 aResult, |
|
302 CConvergedServiceSelector::ESsVoipCall, |
|
303 serviceId, |
|
304 aRegistered ); |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // CSsServiceHandlerVoip::UiUtilitiesL |
|
309 // Returns uiutilities reference. |
|
310 // ----------------------------------------------------------------------------- |
|
311 // |
|
312 CSsUiUtilities& CSsServiceHandlerVoip::UiUtilitiesL() |
|
313 { |
|
314 if ( !iUiUtils ) |
|
315 { |
|
316 // Create uiutils for ui dialogs. |
|
317 // UiUtils is created only for the real need. |
|
318 iUiUtils = CSsUiUtilities::NewL(); |
|
319 } |
|
320 |
|
321 return *iUiUtils; |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CSsServiceHandlerVoip::SettingsHandlerL |
|
326 // Returns settings handler reference. |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 CSsSettingsHandler& CSsServiceHandlerVoip::SettingsHandlerL() |
|
330 { |
|
331 if ( !iSettings ) |
|
332 { |
|
333 // Create settings handler |
|
334 iSettings = CSsSettingsHandler::NewL(); |
|
335 } |
|
336 |
|
337 return *iSettings; |
|
338 } |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 // CSsServiceHandlerVoip::BrandingHandlerL |
|
342 // Returns settings handler reference. |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 CSsBsHandler& CSsServiceHandlerVoip::BrandingHandlerL() |
|
346 { |
|
347 if ( !iBsHandler ) |
|
348 { |
|
349 // Create settings handler |
|
350 iBsHandler = CSsBsHandler::NewL(); |
|
351 } |
|
352 |
|
353 return *iBsHandler; |
|
354 } |
|
355 |
|
356 // ----------------------------------------------------------------------------- |
|
357 // CSsServiceHandlerVoip::ChangeTypeAsCsVoice |
|
358 // Checks should voip call type be changed as cs voice. |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 TBool CSsServiceHandlerVoip::ChangeTypeAsCsVoice |
|
362 ( |
|
363 TUint aServiceId, |
|
364 const TDesC& aString |
|
365 ) const |
|
366 { |
|
367 TBool csCall( EFalse ); |
|
368 TUint prefService( 0 ); |
|
369 |
|
370 if ( SsServiceUtilities::IsValidCsNumber( aString ) && |
|
371 iVoipUtils->IsPreferredTelephonyVoIP() && |
|
372 KErrNone == iVoipUtils->GetPreferredService( prefService ) ) |
|
373 { |
|
374 csCall = prefService == aServiceId && |
|
375 !iConnectionHandler->IsVoipServiceRegistered( aServiceId ); |
|
376 |
|
377 } |
|
378 |
|
379 return csCall; |
|
380 } |
|
381 |
|
382 // ----------------------------------------------------------------------------- |
|
383 // CSsServiceHandlerVoip::AddBrandIconL |
|
384 // |
|
385 // ----------------------------------------------------------------------------- |
|
386 // |
|
387 void CSsServiceHandlerVoip::AddBrandIconL |
|
388 ( |
|
389 CArrayPtr<CGulIcon>* aIcons, |
|
390 TUint aServiceId, |
|
391 TInt& aIconId |
|
392 ) |
|
393 { |
|
394 CFbsBitmap* brandedBitmap = NULL; |
|
395 CFbsBitmap* brandedBitmapMask = NULL; |
|
396 |
|
397 // Get branded bitmap |
|
398 TRAPD( err, GetBrandIconL( aServiceId, |
|
399 brandedBitmap, |
|
400 brandedBitmapMask ) ); |
|
401 |
|
402 if ( KErrNone == err ) |
|
403 { |
|
404 // The count of list icons(before adding branding icon to the list) |
|
405 // must be the branded icon list id |
|
406 aIconId = aIcons->Count(); |
|
407 // Create new icon and add it to the icon list |
|
408 CGulIcon* icon = CGulIcon::NewL( brandedBitmap, brandedBitmapMask ); |
|
409 CleanupStack::PushL( icon ); |
|
410 aIcons->AppendL( icon ); |
|
411 CleanupStack::Pop( icon ); |
|
412 } |
|
413 else |
|
414 { |
|
415 // Use default icon for this service |
|
416 aIconId = 0; |
|
417 } |
|
418 } |
|
419 |
|
420 // ----------------------------------------------------------------------------- |
|
421 // CSsServiceHandlerVoip::GetListBoxItemsAndIconsL |
|
422 // |
|
423 // ----------------------------------------------------------------------------- |
|
424 // |
|
425 void CSsServiceHandlerVoip::GetListBoxItemsAndIconsL |
|
426 ( |
|
427 RArray<TUint>& aServices, |
|
428 CDesCArrayFlat* aLbxItems, |
|
429 CArrayPtr<CGulIcon>* aIcons |
|
430 ) |
|
431 { |
|
432 CDesCArray* names = new(ELeave) CDesCArrayFlat( KSsArrayGranularity ); |
|
433 CleanupStack::PushL( names ); |
|
434 |
|
435 // Load default listbox icon |
|
436 UiUtilitiesL().LoadDefaultIconL( *aIcons ); |
|
437 |
|
438 // Get service names by service id array |
|
439 SettingsHandlerL().GetServiceNamesL( aServices, *names ); |
|
440 |
|
441 for ( TInt i=0; i< aServices.Count() && |
|
442 names->MdcaCount() == aServices.Count(); i++ ) |
|
443 { |
|
444 RBuf16 buf; |
|
445 CleanupClosePushL( buf ); |
|
446 TInt iconId( KErrNotFound ); |
|
447 |
|
448 // Add brand icon. Default is used if brand icon not found |
|
449 AddBrandIconL( aIcons, aServices[ i ], iconId ); |
|
450 |
|
451 HBufC* name = HBufC::NewLC( names->MdcaPoint(i).Length() ); |
|
452 name->Des().Copy( names->MdcaPoint(i) ); |
|
453 |
|
454 buf.CreateL( names->MdcaPoint(i).Length() + |
|
455 KQueryItemFormat().Length() + |
|
456 KSsIntegerLength ); |
|
457 |
|
458 // Create final list box item data. |
|
459 buf.Format( KQueryItemFormat, iconId, name ); |
|
460 |
|
461 //Append text to the item array. |
|
462 aLbxItems->AppendL( buf ); |
|
463 |
|
464 CleanupStack::PopAndDestroy( name ); |
|
465 CleanupStack::PopAndDestroy( &buf ); |
|
466 } |
|
467 |
|
468 CleanupStack::PopAndDestroy( names ); |
|
469 } |
|
470 |
|
471 // ----------------------------------------------------------------------------- |
|
472 // CSsServiceHandlerVoip::GetBrandIconL |
|
473 // |
|
474 // ----------------------------------------------------------------------------- |
|
475 // |
|
476 void CSsServiceHandlerVoip::GetBrandIconL |
|
477 ( |
|
478 TUint aServiceId, |
|
479 CFbsBitmap*& aBrandedBitmap, |
|
480 CFbsBitmap*& aBrandedBitmapMask |
|
481 ) |
|
482 { |
|
483 TBuf8<KSsBrandingIdLength> brandId( KNullDesC8 ); |
|
484 |
|
485 SettingsHandlerL().BrandIdL( aServiceId, brandId ); |
|
486 |
|
487 // Get branded bitmap |
|
488 BrandingHandlerL().GetBrandedIconL( brandId, |
|
489 aBrandedBitmap, |
|
490 aBrandedBitmapMask ); |
|
491 } |
|
492 |
|
493 |
|
494 // ================= OTHER EXPORTED FUNCTIONS =============================== |
|
495 |
|
496 // End of File |
|