|
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 application server fetch service. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2FetchService.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPbk2EntryFetcher.h" |
|
23 #include "CPbk2ItemFetcher.h" |
|
24 |
|
25 // Virtual Phonebook |
|
26 #include <MVPbkContactLinkArray.h> |
|
27 |
|
28 // System includes |
|
29 #include <AiwContactSelectionDataTypes.h> |
|
30 #include <eikappui.h> |
|
31 #include <eikenv.h> |
|
32 #include <avkon.hrh> |
|
33 |
|
34 // Debug |
|
35 #include <Pbk2Debug.h> |
|
36 |
|
37 /// Unnamed namespace for local definitions |
|
38 namespace { |
|
39 |
|
40 _LIT(KPanicText, "CPbk2FetchService"); |
|
41 |
|
42 enum TPanicCode |
|
43 { |
|
44 EInvalidRequest, |
|
45 EInvalidSelectionType |
|
46 }; |
|
47 |
|
48 // RMessage IPC-argument slot order |
|
49 const TInt KResponseSlot = 0; |
|
50 const TInt KPackedResultsSlot = 0; |
|
51 const TInt KExtraResultsSlot = 1; |
|
52 const TInt KFieldContentSlot = 2; |
|
53 const TInt KResultArraySizeSlot = 0; |
|
54 const TInt KResultFieldSizeSlot = 1; |
|
55 const TInt KFetchInstructionsSlot = 1; |
|
56 |
|
57 const TInt KAcceptServiceSlot = 0; // acception protocol |
|
58 const TInt KMarkedEntriesCountSlot = 0; // acception protocol |
|
59 const TInt KSelectedLinksSlot = 1; // acception protocol |
|
60 const TInt KSelectedContactSlot = 1; // acception protocol |
|
61 |
|
62 const TInt KExitAcceptedSlot = 0; // ok to exit protocol |
|
63 const TInt KExitCommandIdSlot = 1; // ok to exit protocol |
|
64 const TInt KCompleteExitCommandIdSlot = 0; // ok to exit protocol |
|
65 |
|
66 } /// namespace |
|
67 |
|
68 |
|
69 // -------------------------------------------------------------------------- |
|
70 // CPbk2FetchService::CPbk2FetchService |
|
71 // -------------------------------------------------------------------------- |
|
72 // |
|
73 CPbk2FetchService::CPbk2FetchService |
|
74 ( const RMessage2& aExitMsg, const RMessage2& aAcceptMsg ) : |
|
75 iExitMsg( aExitMsg), iAcceptMsg( aAcceptMsg ) |
|
76 { |
|
77 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
78 ("CPbk2FetchService::CPbk2FetchService()") ); |
|
79 } |
|
80 |
|
81 // -------------------------------------------------------------------------- |
|
82 // CPbk2FetchService::~CPbk2FetchService |
|
83 // -------------------------------------------------------------------------- |
|
84 // |
|
85 CPbk2FetchService::~CPbk2FetchService() |
|
86 { |
|
87 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
88 ("CPbk2FetchService::~CPbk2FetchService()") ); |
|
89 |
|
90 if ( !iFetchCompleteMsg.IsNull() ) |
|
91 { |
|
92 iFetchCompleteMsg.Complete( KErrServerTerminated ); |
|
93 } |
|
94 |
|
95 delete iUiService; |
|
96 } |
|
97 |
|
98 // -------------------------------------------------------------------------- |
|
99 // CPbk2FetchService::NewL |
|
100 // -------------------------------------------------------------------------- |
|
101 // |
|
102 CPbk2FetchService* CPbk2FetchService::NewL |
|
103 ( const RMessage2& aExitMsg, const RMessage2& aAcceptMsg ) |
|
104 { |
|
105 CPbk2FetchService* self = |
|
106 new ( ELeave ) CPbk2FetchService( aExitMsg, aAcceptMsg ); |
|
107 return self; |
|
108 } |
|
109 |
|
110 // -------------------------------------------------------------------------- |
|
111 // CPbk2FetchService::LaunchServiceL |
|
112 // -------------------------------------------------------------------------- |
|
113 // |
|
114 void CPbk2FetchService::LaunchServiceL( const RMessage2& aMessage ) |
|
115 { |
|
116 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
117 ("CPbk2FetchService::LaunchServiceL()") ); |
|
118 |
|
119 if ( ( iFetchCompleteMsg.Handle() != KNullHandle ) && |
|
120 ( iAcceptMsg.Handle() == KNullHandle ) ) |
|
121 { |
|
122 aMessage.Panic( KPanicText(), EInvalidRequest ); |
|
123 } |
|
124 |
|
125 TPbk2FetchType fetchType = FetchTypeL( aMessage ); |
|
126 |
|
127 switch ( fetchType ) |
|
128 { |
|
129 case EItemFetch: // FALLTHROUGH |
|
130 case ECallItemFetch: |
|
131 case EMultipleItemFetch: |
|
132 { |
|
133 LaunchItemFetchL( aMessage, fetchType ); |
|
134 break; |
|
135 } |
|
136 case EEntryFetch: // FALLTHROUGH |
|
137 case EMultipleEntryFetch: |
|
138 { |
|
139 LaunchEntryFetchL( aMessage, fetchType ); |
|
140 break; |
|
141 } |
|
142 default: |
|
143 { |
|
144 aMessage.Panic( KPanicText(), EInvalidRequest ); |
|
145 break; |
|
146 } |
|
147 } |
|
148 } |
|
149 |
|
150 // -------------------------------------------------------------------------- |
|
151 // CPbk2FetchService::CancelService |
|
152 // -------------------------------------------------------------------------- |
|
153 // |
|
154 void CPbk2FetchService::CancelService( const RMessage2& aMessage ) |
|
155 { |
|
156 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
157 ("CPbk2FetchService::CancelService()") ); |
|
158 |
|
159 // If iFetchCompleteMsg is already completed do nothing. |
|
160 if ( !iFetchCompleteMsg.IsNull() ) |
|
161 { |
|
162 iUiService->CancelService(); |
|
163 } |
|
164 aMessage.Complete( KErrNone ); |
|
165 } |
|
166 |
|
167 // -------------------------------------------------------------------------- |
|
168 // CPbk2FetchService::GetResultsL |
|
169 // -------------------------------------------------------------------------- |
|
170 // |
|
171 void CPbk2FetchService::GetResultsL( const RMessage2& aMessage ) |
|
172 { |
|
173 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
174 ("CPbk2FetchService::GetResultsL()") ); |
|
175 |
|
176 if ( iUiService ) |
|
177 { |
|
178 MPbk2UiService::TServiceResults results; |
|
179 iUiService->ServiceResults(&results); |
|
180 if ( results.iLinkArray ) |
|
181 { |
|
182 HBufC8* packedResults = results.iLinkArray->PackLC(); |
|
183 TPckg<TInt> extraData(results.iExtraData); |
|
184 TRAP_IGNORE( |
|
185 aMessage.WriteL(KPackedResultsSlot, *packedResults ); |
|
186 aMessage.WriteL(KExtraResultsSlot, extraData ); |
|
187 ); |
|
188 CleanupStack::PopAndDestroy(); // packedResults |
|
189 } |
|
190 |
|
191 if ( results.iFieldContent != NULL ) |
|
192 { |
|
193 TRAP_IGNORE( |
|
194 aMessage.WriteL( KFieldContentSlot, *results.iFieldContent ); |
|
195 ); |
|
196 } |
|
197 } |
|
198 aMessage.Complete( KErrNone ); |
|
199 } |
|
200 |
|
201 // -------------------------------------------------------------------------- |
|
202 // CPbk2FetchService::GetResultSizeL |
|
203 // -------------------------------------------------------------------------- |
|
204 // |
|
205 void CPbk2FetchService::GetResultSizeL( const RMessage2& aMessage ) |
|
206 { |
|
207 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
208 ("CPbk2FetchService::GetResultSizeL()") ); |
|
209 |
|
210 if ( iUiService ) |
|
211 { |
|
212 MPbk2UiService::TServiceResults results; |
|
213 iUiService->ServiceResults(&results); |
|
214 if ( results.iLinkArray ) |
|
215 { |
|
216 HBufC8* packedResults = results.iLinkArray->PackLC(); |
|
217 TPtr8 ptr = packedResults->Des(); |
|
218 TPckg<TInt> buffer( ptr.Size() ); |
|
219 TRAP_IGNORE( aMessage.WriteL( |
|
220 KResultArraySizeSlot, buffer ) ); |
|
221 CleanupStack::PopAndDestroy(); // packedResults |
|
222 } |
|
223 |
|
224 if ( results.iFieldContent != NULL ) |
|
225 { |
|
226 TPckg<TInt> buffer( results.iFieldContent->Des().Length() ); |
|
227 TRAP_IGNORE( aMessage.WriteL( |
|
228 KResultFieldSizeSlot, buffer ) ); |
|
229 } |
|
230 else |
|
231 { |
|
232 TPckg<TInt> buffer( 0 ); |
|
233 TRAP_IGNORE( aMessage.WriteL( |
|
234 KResultFieldSizeSlot, buffer ) ); |
|
235 } |
|
236 } |
|
237 aMessage.Complete( KErrNone ); |
|
238 } |
|
239 |
|
240 // -------------------------------------------------------------------------- |
|
241 // CPbk2FetchService::TryExitServiceL |
|
242 // -------------------------------------------------------------------------- |
|
243 // |
|
244 void CPbk2FetchService::TryExitServiceL( const RMessage2& aMessage ) |
|
245 { |
|
246 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
247 ("CPbk2FetchService::TryExitServiceL()") ); |
|
248 |
|
249 TBool okToExit = EFalse; |
|
250 TPckg<TBool> exitPkg( okToExit ); |
|
251 aMessage.ReadL( KExitAcceptedSlot, exitPkg ); |
|
252 |
|
253 if ( iUiService && okToExit ) |
|
254 { |
|
255 TInt exitId = KErrNotFound; |
|
256 TPckg<TInt> commandIdPkg( exitId ); |
|
257 aMessage.ReadL( KExitCommandIdSlot, commandIdPkg ); |
|
258 |
|
259 |
|
260 iUiService->ExitServiceL( exitId ); |
|
261 } |
|
262 |
|
263 aMessage.Complete( KErrNone ); |
|
264 } |
|
265 |
|
266 // -------------------------------------------------------------------------- |
|
267 // CPbk2FetchService::TryAcceptServiceL |
|
268 // -------------------------------------------------------------------------- |
|
269 // |
|
270 void CPbk2FetchService::TryAcceptServiceL( const RMessage2& aMessage ) |
|
271 { |
|
272 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
273 ("CPbk2FetchService::TryAcceptServiceL()") ); |
|
274 |
|
275 TBool accepted = EFalse; |
|
276 TPckg<TBool> acceptedPkg( accepted ); |
|
277 aMessage.ReadL( KAcceptServiceSlot, acceptedPkg ); |
|
278 |
|
279 if ( iUiService ) |
|
280 { |
|
281 HBufC8* buffer = HBufC8::NewLC( |
|
282 aMessage.GetDesMaxLengthL( KSelectedContactSlot ) ); |
|
283 TPtr8 ptr = buffer->Des(); |
|
284 aMessage.ReadL( KSelectedContactSlot, ptr ); |
|
285 |
|
286 // If client accepts selected contact, call AcceptDelayedContacts |
|
287 // Otherwise call DenyDelayedContactsL |
|
288 if( accepted ) |
|
289 { |
|
290 iUiService->AcceptDelayedContactsL( *buffer ); |
|
291 } |
|
292 else |
|
293 { |
|
294 iUiService->DenyDelayedContactsL( *buffer ); |
|
295 } |
|
296 CleanupStack::PopAndDestroy(); // buffer |
|
297 } |
|
298 |
|
299 aMessage.Complete( KErrNone ); |
|
300 } |
|
301 |
|
302 // -------------------------------------------------------------------------- |
|
303 // CPbk2FetchService::ServiceComplete |
|
304 // -------------------------------------------------------------------------- |
|
305 // |
|
306 void CPbk2FetchService::ServiceComplete() |
|
307 { |
|
308 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
309 ("CPbk2FetchService::ServiceComplete()") ); |
|
310 |
|
311 if ( !iFetchCompleteMsg.IsNull() ) |
|
312 { |
|
313 TPckg<TBool> complete( EFalse ); |
|
314 TRAP_IGNORE( iFetchCompleteMsg.WriteL( KResponseSlot, complete ) ); |
|
315 iFetchCompleteMsg.Complete( KErrNone ); |
|
316 } |
|
317 } |
|
318 |
|
319 // -------------------------------------------------------------------------- |
|
320 // CPbk2FetchService::ServiceCanceled |
|
321 // -------------------------------------------------------------------------- |
|
322 // |
|
323 void CPbk2FetchService::ServiceCanceled() |
|
324 { |
|
325 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
326 ("CPbk2FetchService::ServiceCanceled()") ); |
|
327 |
|
328 if ( !iFetchCompleteMsg.IsNull() ) |
|
329 { |
|
330 TPckg<TBool> cancel( ETrue ); |
|
331 TRAP_IGNORE( iFetchCompleteMsg.WriteL( KResponseSlot, cancel ) ); |
|
332 iFetchCompleteMsg.Complete( KErrCancel ); |
|
333 } |
|
334 } |
|
335 |
|
336 // -------------------------------------------------------------------------- |
|
337 // CPbk2FetchService::ServiceAborted |
|
338 // -------------------------------------------------------------------------- |
|
339 // |
|
340 void CPbk2FetchService::ServiceAborted() |
|
341 { |
|
342 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
343 ("CPbk2FetchService::ServiceAborted()") ); |
|
344 |
|
345 if ( !iFetchCompleteMsg.IsNull() ) |
|
346 { |
|
347 iFetchCompleteMsg.Complete( KErrAbort ); |
|
348 |
|
349 // Exit application |
|
350 CEikonEnv* eikonEnv = CEikonEnv::Static(); |
|
351 if ( eikonEnv ) |
|
352 { |
|
353 CEikAppUi* appUi = eikonEnv->EikAppUi(); |
|
354 MEikCommandObserver* cmdObs = |
|
355 static_cast<MEikCommandObserver*>( appUi ); |
|
356 |
|
357 // Dialog is closed so there is nothing to do if |
|
358 // ProcessCommandL leaves. Of course it shouldn't leave in |
|
359 // practice because it's exit command. |
|
360 TRAP_IGNORE( cmdObs->ProcessCommandL( EAknCmdExit ) ); |
|
361 } |
|
362 } |
|
363 } |
|
364 |
|
365 // -------------------------------------------------------------------------- |
|
366 // CPbk2FetchService::ServiceError |
|
367 // -------------------------------------------------------------------------- |
|
368 // |
|
369 void CPbk2FetchService::ServiceError( TInt aErrorCode ) |
|
370 { |
|
371 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
372 ("CPbk2FetchService::ServiceError(%d)"), aErrorCode ); |
|
373 |
|
374 TPckg<TInt> error( aErrorCode ); |
|
375 TRAP_IGNORE( iFetchCompleteMsg.WriteL( KResponseSlot, error ) ); |
|
376 iFetchCompleteMsg.Complete( aErrorCode ); |
|
377 } |
|
378 |
|
379 // -------------------------------------------------------------------------- |
|
380 // CPbk2FetchService::CompleteExitMessage |
|
381 // -------------------------------------------------------------------------- |
|
382 // |
|
383 void CPbk2FetchService::CompleteExitMessage( TInt aExitCommandId ) |
|
384 { |
|
385 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
386 ("CPbk2FetchService::CompleteExitMessage()") ); |
|
387 |
|
388 TPckg<TInt> exitCommandId( aExitCommandId ); |
|
389 if ( iUiService && iExitMsg.Handle() != KNullHandle ) |
|
390 { |
|
391 TRAP_IGNORE( iExitMsg.WriteL( |
|
392 KCompleteExitCommandIdSlot, exitCommandId ) ); |
|
393 iExitMsg.Complete( KErrNone ); |
|
394 } |
|
395 } |
|
396 |
|
397 // -------------------------------------------------------------------------- |
|
398 // CPbk2FetchService::CompleteAcceptMsg |
|
399 // -------------------------------------------------------------------------- |
|
400 // |
|
401 void CPbk2FetchService::CompleteAcceptMsg |
|
402 ( const TDesC8& aMarkedEntries, const TDesC8& aLinkData ) |
|
403 { |
|
404 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING |
|
405 ("CPbk2FetchService::CompleteAcceptMsg()") ); |
|
406 |
|
407 if ( iUiService && iAcceptMsg.Handle() != KNullHandle ) |
|
408 { |
|
409 // Verify that we have enough room in the buffer |
|
410 TInt maxSize = 0; |
|
411 TRAP_IGNORE( |
|
412 maxSize = iAcceptMsg.GetDesMaxLengthL( KSelectedLinksSlot ) ); |
|
413 TInt bufferSize = aLinkData.Size(); |
|
414 |
|
415 if ( bufferSize > maxSize ) |
|
416 { |
|
417 iAcceptMsg.Complete( KErrOverflow ); |
|
418 } |
|
419 else |
|
420 { |
|
421 TRAP_IGNORE( |
|
422 { |
|
423 iAcceptMsg.WriteL( KMarkedEntriesCountSlot, aMarkedEntries ); |
|
424 iAcceptMsg.WriteL( KSelectedLinksSlot, aLinkData ); |
|
425 }); |
|
426 iAcceptMsg.Complete( KErrNone ); |
|
427 } |
|
428 } |
|
429 } |
|
430 |
|
431 // -------------------------------------------------------------------------- |
|
432 // CPbk2FetchService::LaunchEntryFetchL |
|
433 // -------------------------------------------------------------------------- |
|
434 // |
|
435 void CPbk2FetchService::LaunchEntryFetchL |
|
436 ( const RMessage2& aMessage, TPbk2FetchType aFetchType ) |
|
437 { |
|
438 delete iUiService; |
|
439 iUiService = NULL; |
|
440 iUiService = CPbk2EntryFetcher::NewL( aMessage, *this, aFetchType ); |
|
441 iUiService->LaunchServiceL(); |
|
442 |
|
443 iFetchCompleteMsg = aMessage; |
|
444 } |
|
445 |
|
446 // -------------------------------------------------------------------------- |
|
447 // CPbk2FetchService::LaunchItemFetchL |
|
448 // -------------------------------------------------------------------------- |
|
449 // |
|
450 void CPbk2FetchService::LaunchItemFetchL |
|
451 ( const RMessage2& aMessage, TPbk2FetchType aFetchType ) |
|
452 { |
|
453 delete iUiService; |
|
454 iUiService = NULL; |
|
455 iUiService = CPbk2ItemFetcher::NewL( aMessage, *this, aFetchType ); |
|
456 iUiService->LaunchServiceL(); |
|
457 |
|
458 iFetchCompleteMsg = aMessage; |
|
459 } |
|
460 |
|
461 // -------------------------------------------------------------------------- |
|
462 // CPbk2FetchService::FetchTypeL |
|
463 // -------------------------------------------------------------------------- |
|
464 // |
|
465 TPbk2FetchType CPbk2FetchService::FetchTypeL( const RMessage2& aMessage ) |
|
466 { |
|
467 TPbk2FetchType result = EInvalidType; |
|
468 |
|
469 TInt length = aMessage.GetDesLengthL( KFetchInstructionsSlot ); |
|
470 if ( length > 0 ) |
|
471 { |
|
472 HBufC8* dataBuf = HBufC8::NewLC( length ); |
|
473 TPtr8 ptr = dataBuf->Des(); |
|
474 aMessage.ReadL( KFetchInstructionsSlot, ptr ); |
|
475 |
|
476 TAiwContactSelectionDataType dataType = |
|
477 TAiwContactSelectionDataBase::SelectionDataTypeFromBuffer( ptr ); |
|
478 |
|
479 switch ( dataType ) |
|
480 { |
|
481 case EAiwSingleEntrySelectionV1: // FALLTHROUGH |
|
482 case EAiwSingleEntrySelectionV2: |
|
483 { |
|
484 result = EEntryFetch; |
|
485 break; |
|
486 } |
|
487 case EAiwMultipleEntrySelectionV1: // FALLTHROUGH |
|
488 case EAiwMultipleEntrySelectionV2: |
|
489 { |
|
490 result = EMultipleEntryFetch; |
|
491 break; |
|
492 } |
|
493 case EAiwSingleItemSelectionV1: |
|
494 { |
|
495 TAiwSingleItemSelectionDataV1Pckg data; |
|
496 data.Copy( ptr ); |
|
497 result = EItemFetch; |
|
498 |
|
499 TAiwAddressSelectType addressSelectType = |
|
500 data().AddressSelectType(); |
|
501 if ( addressSelectType == EAiwCallItemSelect |
|
502 || addressSelectType == EAiwVoIPItemSelect ) |
|
503 { |
|
504 result = ECallItemFetch; |
|
505 } |
|
506 break; |
|
507 } |
|
508 case EAiwSingleItemSelectionV2: |
|
509 { |
|
510 result = EItemFetch; |
|
511 break; |
|
512 } |
|
513 case EAiwSingleItemSelectionV3: |
|
514 { |
|
515 TAiwSingleItemSelectionDataV3Pckg data; |
|
516 data.Copy( ptr ); |
|
517 result = EItemFetch; |
|
518 |
|
519 TAiwAddressSelectType addressSelectType = |
|
520 data().AddressSelectType(); |
|
521 if ( addressSelectType == EAiwCallItemSelect |
|
522 || addressSelectType == EAiwVoIPItemSelect ) |
|
523 { |
|
524 result = ECallItemFetch; |
|
525 } |
|
526 break; |
|
527 } |
|
528 case EAiwMultipleItemSelectionV1: |
|
529 { |
|
530 result = EMultipleItemFetch; |
|
531 break; |
|
532 } |
|
533 default: |
|
534 { |
|
535 aMessage.Panic( KPanicText, EInvalidSelectionType ); |
|
536 break; |
|
537 } |
|
538 } |
|
539 CleanupStack::PopAndDestroy( dataBuf ); |
|
540 } |
|
541 else |
|
542 { |
|
543 aMessage.Panic( KPanicText, EInvalidSelectionType ); |
|
544 } |
|
545 |
|
546 return result; |
|
547 } |
|
548 |
|
549 // End of File |