|
1 /* |
|
2 * Copyright (c) 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: Class for handling service logic. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <s32mem.h> |
|
20 |
|
21 #include "ccacontactorserviceheaders.h" |
|
22 |
|
23 // ================= MEMBER FUNCTIONS ======================= |
|
24 // |
|
25 |
|
26 // -------------------------------------------------------------------------- |
|
27 // CCCAContactorServiceOperator::NewLC |
|
28 // -------------------------------------------------------------------------- |
|
29 // |
|
30 CCCAContactorServiceOperator* CCCAContactorServiceOperator::NewLC() |
|
31 { |
|
32 CCCAContactorServiceOperator* self = new (ELeave) CCCAContactorServiceOperator(); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 return self; |
|
36 } |
|
37 |
|
38 // -------------------------------------------------------------------------- |
|
39 // CCCAContactorServiceOperator::NewL |
|
40 // -------------------------------------------------------------------------- |
|
41 // |
|
42 CCCAContactorServiceOperator* CCCAContactorServiceOperator::NewL() |
|
43 { |
|
44 CCCAContactorServiceOperator* self = CCCAContactorServiceOperator::NewLC(); |
|
45 CleanupStack::Pop(self); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // -------------------------------------------------------------------------- |
|
50 // CCCAContactorServiceOperator::~CCCAContactorServiceOperator |
|
51 // -------------------------------------------------------------------------- |
|
52 // |
|
53 CCCAContactorServiceOperator::~CCCAContactorServiceOperator() |
|
54 { |
|
55 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::~CCCAContactorServiceOperator")); |
|
56 |
|
57 delete iPopupHandler; |
|
58 } |
|
59 |
|
60 // -------------------------------------------------------------------------- |
|
61 // CCCAContactorServiceOperator::Execute |
|
62 // -------------------------------------------------------------------------- |
|
63 // |
|
64 void CCCAContactorServiceOperator::Execute( |
|
65 const CCAContactorService::TCSParameter& aParameter) |
|
66 { |
|
67 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::Execute")); |
|
68 |
|
69 iParameter = &aParameter; |
|
70 |
|
71 /** |
|
72 * LOGIC: |
|
73 * 1. Launch AIW popup |
|
74 * 2. Special cases: Find out serviceid for voip |
|
75 * 3. Launch communication service |
|
76 * |
|
77 * All actions are trapped here. |
|
78 */ |
|
79 TDesC* result = NULL; |
|
80 TInt err( KErrNone ); |
|
81 TBool hasSelectedField( EFalse ); |
|
82 |
|
83 // Check use field control flag |
|
84 if (CCAContactorService::TCSParameter::EUseFieldParam & |
|
85 iParameter->iControlFlag) |
|
86 { |
|
87 hasSelectedField = ETrue; |
|
88 } |
|
89 |
|
90 if ( !hasSelectedField ) |
|
91 { |
|
92 TBool useDefaults = EFalse; |
|
93 |
|
94 // Check default control flag |
|
95 if (CCAContactorService::TCSParameter::EEnableDefaults & |
|
96 iParameter->iControlFlag) |
|
97 { |
|
98 useDefaults = ETrue; |
|
99 } |
|
100 |
|
101 // Launch popup |
|
102 TRAP(err, result = &iPopupHandler->LaunchPopupL( |
|
103 iParameter->iContactLinkArray, |
|
104 CommunicationEnumMapper(iParameter->iCommTypeSelector), |
|
105 useDefaults)); |
|
106 |
|
107 if (result != NULL) |
|
108 { |
|
109 isSelected = ETrue; |
|
110 } |
|
111 |
|
112 if (KErrNone != err) |
|
113 { |
|
114 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExecuteL: LaunchPopupL: Leaves %d."), err); |
|
115 return; |
|
116 } |
|
117 } |
|
118 else |
|
119 { |
|
120 __ASSERT_ALWAYS (NULL != iParameter->iSelectedField, User::Leave (KErrArgument)); |
|
121 __ASSERT_ALWAYS (0 < iParameter->iSelectedField->Size(), User::Leave (KErrArgument)); |
|
122 result = iParameter->iSelectedField; |
|
123 } |
|
124 |
|
125 // Resolve special cases |
|
126 TRAP(err, ResolveSpecialCasesL(*result)); |
|
127 |
|
128 if (KErrNone != err) |
|
129 { |
|
130 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExecuteL: ResolveSpecialCasesL: Leaves %d."), err); |
|
131 return; |
|
132 } |
|
133 |
|
134 // Launch communication service |
|
135 TRAP(err, LaunchCommunicationMethodL(*result)); |
|
136 |
|
137 if (KErrNone != err) |
|
138 { |
|
139 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExecuteL: LaunchCommunicationMethodL: Leaves %d."), err); |
|
140 return; |
|
141 } |
|
142 |
|
143 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::Execute: Done.")); |
|
144 } |
|
145 |
|
146 |
|
147 TBool CCCAContactorServiceOperator::IsSelected() |
|
148 { |
|
149 return isSelected; |
|
150 } |
|
151 // -------------------------------------------------------------------------- |
|
152 // CCCAContactorServiceOperator::CCCAContactorServiceOperator |
|
153 // -------------------------------------------------------------------------- |
|
154 // |
|
155 CCCAContactorServiceOperator::CCCAContactorServiceOperator(): |
|
156 iServiceId((TUint32)KErrNotFound), |
|
157 isSelected(EFalse) |
|
158 { |
|
159 } |
|
160 |
|
161 // -------------------------------------------------------------------------- |
|
162 // CCCAContactorServiceOperator::ConstructL |
|
163 // -------------------------------------------------------------------------- |
|
164 // |
|
165 void CCCAContactorServiceOperator::ConstructL() |
|
166 { |
|
167 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ConstructL")); |
|
168 |
|
169 iPopupHandler = CCCAContactorPopupHandler::NewL(); |
|
170 |
|
171 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ConstructL: Done.")); |
|
172 } |
|
173 |
|
174 // -------------------------------------------------------------------------- |
|
175 // CCCAContactorServiceOperator::ResolveSpecialCasesL |
|
176 // -------------------------------------------------------------------------- |
|
177 // |
|
178 void CCCAContactorServiceOperator::ResolveSpecialCasesL(const TDesC& aFieldData) |
|
179 { |
|
180 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveSpecialCasesL")); |
|
181 |
|
182 /* |
|
183 * Currently only VOIP ServiceId is needed to find out. |
|
184 */ |
|
185 switch(iParameter->iCommTypeSelector) |
|
186 { |
|
187 case VPbkFieldTypeSelectorFactory::EVOIPCallSelector: |
|
188 iServiceId = ResolveServiceIdL(aFieldData); |
|
189 break; |
|
190 } |
|
191 |
|
192 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveSpecialCasesL: Done.")); |
|
193 } |
|
194 |
|
195 // -------------------------------------------------------------------------- |
|
196 // CCCAContactorServiceOperator::ResolveServiceIdL |
|
197 // -------------------------------------------------------------------------- |
|
198 // |
|
199 TUint32 CCCAContactorServiceOperator::ResolveServiceIdL(const TDesC& aFieldData) |
|
200 { |
|
201 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveServiceIdL")); |
|
202 |
|
203 __ASSERT_ALWAYS (NULL != &aFieldData, User::Leave (KErrArgument)); |
|
204 __ASSERT_ALWAYS (0 < aFieldData.Size(), User::Leave (KErrArgument)); |
|
205 |
|
206 TUint32 ret = (TUint32)KErrNotFound; |
|
207 |
|
208 //LOGIC: |
|
209 /* |
|
210 * 1. Find out is there xSP prefix |
|
211 * 2. If there is, search service id |
|
212 * 3. If not, find out how many services support msisdn |
|
213 * 4. If only one, find use that service id |
|
214 * 5. If more than one, do not use service id. |
|
215 */ |
|
216 |
|
217 TPtrC result; |
|
218 |
|
219 // 1. Find out is there xSP prefix |
|
220 if (ExtractServiceL(aFieldData, result)) |
|
221 { |
|
222 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveServiceIdL: ExtractServiceL found.")); |
|
223 |
|
224 // 2. If there is, search service id |
|
225 ret = SearchServiceIdL(result); |
|
226 } |
|
227 else |
|
228 { |
|
229 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveServiceIdL: ExtractServiceL not found.")); |
|
230 |
|
231 // 3. If not, find out how many services support msisdn |
|
232 ret = ResolveMSISDNAddressingSupportedL(); |
|
233 if ((TUint32)KErrNotFound != ret) |
|
234 { |
|
235 // 4. If only one, find use that service id |
|
236 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveServiceIdL: ResolveMSISDNAddressingSupportedL only one service.")); |
|
237 |
|
238 } |
|
239 else |
|
240 { |
|
241 // 5. If more than one or none found, do not use service id. |
|
242 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveServiceIdL: ResolveMSISDNAddressingSupportedL more than one service.")); |
|
243 |
|
244 } |
|
245 } |
|
246 |
|
247 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveServiceIdL: Done.")); |
|
248 |
|
249 return ret; |
|
250 } |
|
251 |
|
252 // -------------------------------------------------------------------------- |
|
253 // CCCAContactorServiceOperator::ExtractServiceL |
|
254 // -------------------------------------------------------------------------- |
|
255 // |
|
256 TBool CCCAContactorServiceOperator::ExtractServiceL( |
|
257 const TDesC& aFieldData, TPtrC& aXSPId) |
|
258 { |
|
259 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExtractServiceL")); |
|
260 |
|
261 TBool found = EFalse; |
|
262 |
|
263 TInt pos = aFieldData.Find(KColon); |
|
264 if (pos >= 0) |
|
265 { |
|
266 // ok input |
|
267 aXSPId.Set(aFieldData.Left(pos)); |
|
268 found = ETrue; |
|
269 } |
|
270 |
|
271 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExtractServiceL: Done.")); |
|
272 |
|
273 return found; |
|
274 } |
|
275 |
|
276 // -------------------------------------------------------------------------- |
|
277 // CCCAContactorServiceOperator::SearchServiceIdL |
|
278 // -------------------------------------------------------------------------- |
|
279 // |
|
280 TUint32 CCCAContactorServiceOperator::SearchServiceIdL(const TDesC& aFieldData) |
|
281 { |
|
282 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::SearchServiceIdL")); |
|
283 |
|
284 TUint32 ret = (TUint32)KErrNotFound; |
|
285 TInt err = KErrNone; |
|
286 CDesCArrayFlat* nameArray = NULL; |
|
287 |
|
288 RIdArray ids; |
|
289 CleanupClosePushL(ids); |
|
290 |
|
291 nameArray = new (ELeave) CDesCArrayFlat(2); |
|
292 CleanupStack::PushL(nameArray); |
|
293 |
|
294 CSPSettings* settings = CSPSettings::NewLC(); |
|
295 |
|
296 err = settings->FindServiceIdsL(ids); |
|
297 User::LeaveIfError(err); |
|
298 err = settings->FindServiceNamesL(ids, *nameArray); |
|
299 User::LeaveIfError(err); |
|
300 |
|
301 TInt count = nameArray->MdcaCount(); |
|
302 for (TInt i(0); i < count; i++) |
|
303 { |
|
304 // search the mathching service name |
|
305 TPtrC p = nameArray->MdcaPoint(i); |
|
306 if (!p.CompareF(aFieldData)) |
|
307 { |
|
308 // Service found |
|
309 ret = ids[i]; |
|
310 |
|
311 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::SearchServiceIdL: Service found.")); |
|
312 break; |
|
313 } |
|
314 } |
|
315 CleanupStack::PopAndDestroy(3); // ids, nameArray, settings |
|
316 |
|
317 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::SearchServiceIdL: Done.")); |
|
318 |
|
319 return ret; |
|
320 } |
|
321 |
|
322 // -------------------------------------------------------------------------- |
|
323 // CCCAContactorServiceOperator::ResolveMSISDNAddressingSupportedL |
|
324 // -------------------------------------------------------------------------- |
|
325 // |
|
326 TUint32 CCCAContactorServiceOperator::ResolveMSISDNAddressingSupportedL() |
|
327 { |
|
328 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveMSISDNAddressingSupportedL")); |
|
329 |
|
330 /* |
|
331 * LOGIC: |
|
332 * -Find out services |
|
333 * -If only 1 service, return the serviceid |
|
334 * -If services are more than 1, then do not use serviceid. |
|
335 */ |
|
336 |
|
337 TInt err = KErrNone; |
|
338 TInt foundNo = 0; |
|
339 TUint32 ret = (TUint32)KErrNotFound; |
|
340 |
|
341 RIdArray ids; |
|
342 CleanupClosePushL(ids); |
|
343 |
|
344 CSPSettings* settings = CSPSettings::NewLC(); |
|
345 |
|
346 err = settings->FindServiceIdsL(ids); |
|
347 User::LeaveIfError(err); |
|
348 |
|
349 TInt count = ids.Count(); |
|
350 for (TInt i(0); i < count; i++) |
|
351 { |
|
352 CSPProperty* property = CSPProperty::NewLC(); |
|
353 |
|
354 // Find out property |
|
355 err = settings->FindPropertyL(ids[i], |
|
356 EPropertyServiceAttributeMask, *property); |
|
357 |
|
358 // If service have property |
|
359 if (KErrNone == err) |
|
360 { |
|
361 // read the value of mask property |
|
362 TInt mask = 0; |
|
363 err = property->GetValue(mask); |
|
364 if (KErrNone == err) |
|
365 { |
|
366 if ((mask & ESupportsMSISDNAddressing) && |
|
367 (mask & ESupportsInternetCall)) |
|
368 { |
|
369 // Found one. |
|
370 ret = ids[i]; |
|
371 foundNo++; |
|
372 |
|
373 }// if mask |
|
374 }// if err |
|
375 }// if err |
|
376 |
|
377 CleanupStack::PopAndDestroy(property); |
|
378 }// for |
|
379 |
|
380 // If more than 1 service, do not use serviceid |
|
381 |
|
382 if (1 < foundNo) |
|
383 { |
|
384 ret = (TUint32)KErrNotFound; |
|
385 } |
|
386 |
|
387 CleanupStack::PopAndDestroy(2); // ids, settings |
|
388 |
|
389 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ResolveMSISDNAddressingSupportedL: Done.")); |
|
390 return ret; |
|
391 } |
|
392 |
|
393 // -------------------------------------------------------------------------- |
|
394 // CCCAContactorServiceOperator::LaunchCommunicationMethodL |
|
395 // -------------------------------------------------------------------------- |
|
396 // |
|
397 void CCCAContactorServiceOperator::LaunchCommunicationMethodL( |
|
398 const TDesC& aFieldData) |
|
399 { |
|
400 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::LaunchCommunicationMethodL")); |
|
401 |
|
402 __ASSERT_ALWAYS (NULL != &iParameter->iFullName, User::Leave (KErrArgument)); |
|
403 |
|
404 // If serviceid found, use it. |
|
405 if ((TUint32)KErrNotFound != iServiceId) |
|
406 { |
|
407 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExecuteL: ExecuteServiceL with serviceid")); |
|
408 CCAContactor::ExecuteServiceL( |
|
409 iParameter->iCommTypeSelector, |
|
410 aFieldData, |
|
411 iParameter->iFullName, |
|
412 iParameter->iContactLinkArray, |
|
413 iServiceId |
|
414 ); |
|
415 } |
|
416 else |
|
417 { |
|
418 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::ExecuteL: ExecuteServiceL without serviceid")); |
|
419 CCAContactor::ExecuteServiceL( |
|
420 iParameter->iCommTypeSelector, |
|
421 aFieldData, |
|
422 iParameter->iFullName, |
|
423 iParameter->iContactLinkArray); |
|
424 } |
|
425 |
|
426 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::LaunchCommunicationMethodL: Done.")); |
|
427 } |
|
428 |
|
429 // -------------------------------------------------------------------------- |
|
430 // CCCAContactorServiceOperator::CommunicationEnumMapper |
|
431 // -------------------------------------------------------------------------- |
|
432 // |
|
433 TAiwCommAddressSelectType CCCAContactorServiceOperator::CommunicationEnumMapper( |
|
434 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aCommTypeSelector) |
|
435 { |
|
436 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::CommunicationEnumMapper")); |
|
437 |
|
438 TAiwCommAddressSelectType type; |
|
439 |
|
440 switch(aCommTypeSelector) |
|
441 { |
|
442 case VPbkFieldTypeSelectorFactory::EEmptySelector: |
|
443 type = EAiwCommEmpty; |
|
444 break; |
|
445 |
|
446 case VPbkFieldTypeSelectorFactory::EVoiceCallSelector: |
|
447 type = EAiwCommVoiceCall; |
|
448 break; |
|
449 |
|
450 case VPbkFieldTypeSelectorFactory::EUniEditorSelector: |
|
451 type = EAiwCommUniEditor; |
|
452 break; |
|
453 |
|
454 case VPbkFieldTypeSelectorFactory::EEmailEditorSelector: |
|
455 type = EAiwCommEmailEditor; |
|
456 break; |
|
457 |
|
458 case VPbkFieldTypeSelectorFactory::EInstantMessagingSelector: |
|
459 type = EAiwCommInstantMessaging; |
|
460 break; |
|
461 |
|
462 case VPbkFieldTypeSelectorFactory::EVOIPCallSelector: |
|
463 type = EAiwCommVOIPCall; |
|
464 break; |
|
465 |
|
466 case VPbkFieldTypeSelectorFactory::EURLSelector: |
|
467 type = EAiwCommURL; |
|
468 break; |
|
469 |
|
470 case VPbkFieldTypeSelectorFactory::EVideoCallSelector: |
|
471 type = EAiwCommVideoCall; |
|
472 break; |
|
473 |
|
474 default: |
|
475 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::CommunicationEnumMapper: default -> Empty mapped.")); |
|
476 type = EAiwCommEmpty; |
|
477 break; |
|
478 } |
|
479 |
|
480 CCA_DP(KCCAContactorServiceLoggerFile, CCA_L("CCCAContactorServiceOperator::CommunicationEnumMapper: Done.")); |
|
481 |
|
482 return type; |
|
483 } |
|
484 |
|
485 // End of file |