|
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 PoC AIW interest item. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2AiwInterestItemPoc.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPbk2CallTypeSelector.h" |
|
23 #include "CPbk2PocCmd.h" |
|
24 #include <TPbk2StoreContactAnalyzer.h> |
|
25 #include <MPbk2Command.h> |
|
26 #include <Pbk2UIControls.rsg> |
|
27 #include <Pbk2Commands.rsg> |
|
28 #include <MPbk2ContactUiControl.h> |
|
29 #include <Pbk2UID.h> |
|
30 #include <MPbk2ApplicationServices.h> |
|
31 #include <MPbk2AppUi.h> |
|
32 #include "cpbk2storestatechecker.h" |
|
33 |
|
34 // Virtual Phonebook |
|
35 #include <CVPbkContactManager.h> |
|
36 #include <MVPbkStoreContact.h> |
|
37 #include <MVPbkContactLink.h> |
|
38 #include <MVPbkContactOperationBase.h> |
|
39 |
|
40 // System includes |
|
41 #include <AiwServiceHandler.h> |
|
42 #include <eikmenup.h> |
|
43 #include <eikenv.h> |
|
44 #include <AiwPoCParameters.h> |
|
45 #include <AiwPoCParameters.hrh> |
|
46 |
|
47 /// Unnamed namespace for local definitions |
|
48 namespace { |
|
49 |
|
50 /** |
|
51 * Standard error handling. |
|
52 * |
|
53 * @param aError Error code. |
|
54 */ |
|
55 void HandleError( const TInt aError ) |
|
56 { |
|
57 if (aError != KErrNone) |
|
58 { |
|
59 // Get UIKON environment |
|
60 CEikonEnv* eikEnv = CEikonEnv::Static(); |
|
61 if (eikEnv) |
|
62 { |
|
63 // Display standard error message |
|
64 eikEnv->HandleError(aError); |
|
65 } |
|
66 } |
|
67 } |
|
68 |
|
69 #ifdef _DEBUG |
|
70 enum TPanicCode |
|
71 { |
|
72 EPanicPreCond_ExecuteCommandL = 1, |
|
73 EPanicPreCond_ReadContactL, |
|
74 EPanicLogic_UnknownState |
|
75 }; |
|
76 |
|
77 void Panic(TPanicCode aReason) |
|
78 { |
|
79 _LIT( KPanicText, "CPbk2AiwInterestItemPoc" ); |
|
80 User::Panic( KPanicText, aReason ); |
|
81 } |
|
82 #endif // _DEBUG |
|
83 |
|
84 |
|
85 } /// namespace |
|
86 |
|
87 |
|
88 // -------------------------------------------------------------------------- |
|
89 // CPbk2AiwInterestItemPoc::CPbk2AiwInterestItemPoc |
|
90 // -------------------------------------------------------------------------- |
|
91 // |
|
92 inline CPbk2AiwInterestItemPoc::CPbk2AiwInterestItemPoc |
|
93 ( TInt aInterestId, CAiwServiceHandler& aServiceHandler ) : |
|
94 CPbk2AiwInterestItemBase( aInterestId, aServiceHandler ) |
|
95 { |
|
96 CActiveScheduler::Add( this ); |
|
97 } |
|
98 |
|
99 // -------------------------------------------------------------------------- |
|
100 // CPbk2AiwInterestItemPoc::~CPbk2AiwInterestItemPoc |
|
101 // -------------------------------------------------------------------------- |
|
102 // |
|
103 CPbk2AiwInterestItemPoc::~CPbk2AiwInterestItemPoc() |
|
104 { |
|
105 Cancel(); |
|
106 delete iStoreStateChecker; |
|
107 delete iContactLink; |
|
108 delete iStoreContact; |
|
109 delete iSelector; |
|
110 delete iRetriever; |
|
111 } |
|
112 |
|
113 // -------------------------------------------------------------------------- |
|
114 // CPbk2AiwInterestItemPoc::ConstructL |
|
115 // -------------------------------------------------------------------------- |
|
116 // |
|
117 inline void CPbk2AiwInterestItemPoc::ConstructL() |
|
118 { |
|
119 iFieldPropertyArray = |
|
120 &Phonebook2::Pbk2AppUi()->ApplicationServices().FieldProperties(); |
|
121 iSelector = CPbk2CallTypeSelector::NewL |
|
122 ( Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager() ); |
|
123 } |
|
124 |
|
125 // -------------------------------------------------------------------------- |
|
126 // CPbk2AiwInterestItemPoc::NewL |
|
127 // -------------------------------------------------------------------------- |
|
128 // |
|
129 CPbk2AiwInterestItemPoc* CPbk2AiwInterestItemPoc::NewL |
|
130 ( TInt aInterestId, CAiwServiceHandler& aServiceHandler ) |
|
131 { |
|
132 CPbk2AiwInterestItemPoc* self = |
|
133 new (ELeave) CPbk2AiwInterestItemPoc( aInterestId, aServiceHandler ); |
|
134 CleanupStack::PushL( self ); |
|
135 self->ConstructL(); |
|
136 CleanupStack::Pop( self ); |
|
137 return self; |
|
138 } |
|
139 |
|
140 // -------------------------------------------------------------------------- |
|
141 // CPbk2AiwInterestItemPoc::DynInitMenuPaneL |
|
142 // -------------------------------------------------------------------------- |
|
143 // |
|
144 TBool CPbk2AiwInterestItemPoc::DynInitMenuPaneL |
|
145 ( const TInt aResourceId, CEikMenuPane& aMenuPane, |
|
146 const MPbk2ContactUiControl& aControl ) |
|
147 { |
|
148 TBool ret = EFalse; |
|
149 |
|
150 switch ( aResourceId ) |
|
151 { |
|
152 case R_PHONEBOOK2_GROUPVIEWS_POC_MENU: |
|
153 { |
|
154 ret = ETrue; |
|
155 |
|
156 if ( aControl.NumberOfContacts() > 0 ) |
|
157 { |
|
158 DoInitMenuPaneL( aResourceId, aMenuPane, aControl, |
|
159 EAiwPoCCmdTalkGroup ); |
|
160 } |
|
161 else |
|
162 { |
|
163 aMenuPane.SetItemDimmed( KAiwCmdPoC, ETrue ); |
|
164 } |
|
165 break; |
|
166 } |
|
167 case R_PHONEBOOK2_POC_MENU: |
|
168 { |
|
169 ret = ETrue; |
|
170 TBool noPTTField = EFalse; |
|
171 |
|
172 // In contact info view, the PoC menu must be filtered |
|
173 // away if there are no PoC fields |
|
174 const MVPbkStoreContact* storeContact = |
|
175 aControl.FocusedStoreContact(); |
|
176 |
|
177 // Store contact is not available if we are not in contact |
|
178 // info view |
|
179 if ( storeContact ) |
|
180 { |
|
181 TPbk2StoreContactAnalyzer analyzer |
|
182 ( Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
183 ContactManager(), storeContact ); |
|
184 |
|
185 if ( analyzer.HasFieldL |
|
186 ( R_PHONEBOOK2_SIP_MSISDN_SELECTOR ) < 0 ) |
|
187 { |
|
188 noPTTField = ETrue; |
|
189 } |
|
190 } |
|
191 |
|
192 // If the list is empty hide PoC option. |
|
193 // In contact info view, the contact must also have |
|
194 // a PTT field available. |
|
195 if ( aControl.NumberOfContacts() > 0 && !noPTTField ) |
|
196 { |
|
197 DoInitMenuPaneL( aResourceId, aMenuPane, aControl ); |
|
198 } |
|
199 else |
|
200 { |
|
201 aMenuPane.SetItemDimmed( KAiwCmdPoC, ETrue ); |
|
202 } |
|
203 break; |
|
204 } |
|
205 case R_PHONEBOOK2_POC_CONTEXT_MENU: |
|
206 { |
|
207 ret = ETrue; |
|
208 |
|
209 // Hide the item by default |
|
210 aMenuPane.SetItemDimmed( KAiwCmdPoC, ETrue ); |
|
211 |
|
212 // Get the focused field |
|
213 const MVPbkBaseContactField* field = |
|
214 aControl.FocusedField(); |
|
215 |
|
216 if ( field ) |
|
217 { |
|
218 TInt tmp( KErrNotFound ); |
|
219 |
|
220 TPbk2StoreContactAnalyzer analyzer |
|
221 ( Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
222 ContactManager(), NULL ); |
|
223 |
|
224 // Pager field is part of SIP_MSISDN selector |
|
225 // so exclude it from the menu here first |
|
226 if ( analyzer.IsFieldTypeIncludedL( |
|
227 *field, R_PHONEBOOK2_PAGER_SELECTOR ) && |
|
228 aMenuPane.MenuItemExists( KAiwCmdPoC, tmp ) ) |
|
229 { |
|
230 // If we are in pager field let the item be dimmed |
|
231 } |
|
232 |
|
233 // Check are we dealing with a PTT field |
|
234 else if ( analyzer.IsFieldTypeIncludedL( |
|
235 *field, R_PHONEBOOK2_SIP_MSISDN_SELECTOR ) ) |
|
236 { |
|
237 aMenuPane.SetItemDimmed( KAiwCmdPoC, EFalse ); |
|
238 DoInitMenuPaneL( aResourceId, aMenuPane, aControl ); |
|
239 } |
|
240 } |
|
241 break; |
|
242 } |
|
243 |
|
244 default: |
|
245 { |
|
246 // Do nothing |
|
247 break; |
|
248 } |
|
249 }; |
|
250 return ret; |
|
251 } |
|
252 |
|
253 // -------------------------------------------------------------------------- |
|
254 // CPbk2AiwInterestItemPoc::HandleCommandL |
|
255 // -------------------------------------------------------------------------- |
|
256 // |
|
257 TBool CPbk2AiwInterestItemPoc::HandleCommandL |
|
258 ( const TInt aMenuCommandId, MPbk2ContactUiControl& aControl, |
|
259 TInt aServiceCommandId ) |
|
260 { |
|
261 TBool ret = EFalse; |
|
262 // Only handle this command if service command is talk |
|
263 if ( aServiceCommandId == KAiwCmdPoC ) |
|
264 { |
|
265 ret = ETrue; |
|
266 iMenuCommandId = aMenuCommandId; |
|
267 iControl = &aControl; |
|
268 |
|
269 // Retrieve store contact if needed |
|
270 MVPbkStoreContact* storeContact = const_cast<MVPbkStoreContact*>( |
|
271 aControl.FocusedStoreContact() ); |
|
272 if ( !storeContact ) |
|
273 { |
|
274 // No need to check store state, store always available |
|
275 // if cmd is invoked from nameslist |
|
276 IssueNextAction( ERetrieveContact ); |
|
277 } |
|
278 else |
|
279 { |
|
280 // Check store availability |
|
281 CPbk2StoreStateChecker* temp = |
|
282 CPbk2StoreStateChecker::NewL( |
|
283 storeContact->ParentStore(), *this ); |
|
284 delete iStoreStateChecker; |
|
285 iStoreStateChecker = temp; |
|
286 } |
|
287 } |
|
288 |
|
289 return ret; |
|
290 } |
|
291 |
|
292 // -------------------------------------------------------------------------- |
|
293 // CPbk2AiwInterestItemPoc::VPbkSingleContactOperationComplete |
|
294 // -------------------------------------------------------------------------- |
|
295 // |
|
296 void CPbk2AiwInterestItemPoc::VPbkSingleContactOperationComplete( |
|
297 MVPbkContactOperationBase& aOperation, |
|
298 MVPbkStoreContact* aContact ) |
|
299 { |
|
300 if ( &aOperation == iRetriever ) |
|
301 { |
|
302 delete iStoreContact; |
|
303 iStoreContact = aContact; |
|
304 |
|
305 IssueNextAction( EExecutePoc ); |
|
306 } |
|
307 } |
|
308 |
|
309 // -------------------------------------------------------------------------- |
|
310 // CPbk2AiwInterestItemPoc::VPbkSingleContactOperationFailed |
|
311 // -------------------------------------------------------------------------- |
|
312 // |
|
313 void CPbk2AiwInterestItemPoc::VPbkSingleContactOperationFailed( |
|
314 MVPbkContactOperationBase& aOperation, |
|
315 TInt aError ) |
|
316 { |
|
317 if ( &aOperation == iRetriever ) |
|
318 { |
|
319 HandleError( aError ); |
|
320 } |
|
321 } |
|
322 |
|
323 // -------------------------------------------------------------------------- |
|
324 // CPbk2AiwInterestItemPoc::StoreState |
|
325 // -------------------------------------------------------------------------- |
|
326 // |
|
327 void CPbk2AiwInterestItemPoc::StoreState |
|
328 ( MPbk2StoreStateCheckerObserver::TState aState ) |
|
329 { |
|
330 if ( aState == MPbk2StoreStateCheckerObserver::EStoreAvailable ) |
|
331 { |
|
332 IssueNextAction( EExecutePoc ); |
|
333 } |
|
334 else |
|
335 { |
|
336 IssueNextAction( EShowUnavailableNote ); |
|
337 } |
|
338 } |
|
339 |
|
340 // -------------------------------------------------------------------------- |
|
341 // CPbk2AiwInterestItemPoc::DoCancel |
|
342 // -------------------------------------------------------------------------- |
|
343 // |
|
344 void CPbk2AiwInterestItemPoc::DoCancel() |
|
345 { |
|
346 // Do nothing |
|
347 } |
|
348 |
|
349 // -------------------------------------------------------------------------- |
|
350 // CPbk2AiwInterestItemPoc::RunL |
|
351 // -------------------------------------------------------------------------- |
|
352 // |
|
353 void CPbk2AiwInterestItemPoc::RunL() |
|
354 { |
|
355 switch ( iState ) |
|
356 { |
|
357 case ERetrieveContact: |
|
358 { |
|
359 RetrieveContactL(); |
|
360 break; |
|
361 } |
|
362 case EExecutePoc: |
|
363 { |
|
364 MVPbkStoreContact* storeContact = const_cast<MVPbkStoreContact*>( |
|
365 iControl->FocusedStoreContact() ); |
|
366 if ( !storeContact ) |
|
367 { |
|
368 storeContact = iStoreContact; |
|
369 } |
|
370 ExecuteCommandL( *storeContact ); |
|
371 break; |
|
372 } |
|
373 case EShowUnavailableNote: |
|
374 { |
|
375 if ( iStoreStateChecker ) |
|
376 { |
|
377 iStoreStateChecker->ShowUnavailableNoteL(); |
|
378 } |
|
379 break; |
|
380 } |
|
381 default: |
|
382 { |
|
383 __ASSERT_DEBUG(iControl, Panic( EPanicLogic_UnknownState ) ); |
|
384 break; |
|
385 } |
|
386 } |
|
387 } |
|
388 |
|
389 // -------------------------------------------------------------------------- |
|
390 // CPbk2AiwInterestItemPoc::ExecuteCommandL |
|
391 // -------------------------------------------------------------------------- |
|
392 // |
|
393 void CPbk2AiwInterestItemPoc::ExecuteCommandL |
|
394 ( MVPbkStoreContact& aStoreContact ) |
|
395 { |
|
396 __ASSERT_DEBUG(iControl, Panic( EPanicPreCond_ExecuteCommandL ) ); |
|
397 |
|
398 // Execute the command |
|
399 MPbk2Command* cmd = CreatePocCmdObjectL |
|
400 ( iMenuCommandId, *iControl, aStoreContact ); |
|
401 cmd->ExecuteLD(); |
|
402 } |
|
403 |
|
404 // -------------------------------------------------------------------------- |
|
405 // CPbk2AiwInterestItemPoc::RetrieveContactL |
|
406 // -------------------------------------------------------------------------- |
|
407 // |
|
408 void CPbk2AiwInterestItemPoc::RetrieveContactL() |
|
409 { |
|
410 delete iContactLink; |
|
411 iContactLink = NULL; |
|
412 iContactLink = iControl->FocusedContactL()->CreateLinkLC(); |
|
413 CleanupStack::Pop(); // iContactLink |
|
414 |
|
415 delete iRetriever; |
|
416 iRetriever = NULL; |
|
417 iRetriever = Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
418 ContactManager().RetrieveContactL( *iContactLink, *this ); |
|
419 } |
|
420 |
|
421 // -------------------------------------------------------------------------- |
|
422 // CPbk2AiwInterestItemPoc::IssueRetrieveRequest |
|
423 // -------------------------------------------------------------------------- |
|
424 // |
|
425 void CPbk2AiwInterestItemPoc::IssueNextAction( TNextAction aState ) |
|
426 { |
|
427 if ( !IsActive() ) |
|
428 { |
|
429 iState = aState; |
|
430 TRequestStatus* status = &iStatus; |
|
431 User::RequestComplete( status, KErrNone ); |
|
432 SetActive(); |
|
433 } |
|
434 } |
|
435 |
|
436 // -------------------------------------------------------------------------- |
|
437 // CPbk2AiwInterestItemPoc::DoInitMenuPaneL |
|
438 // -------------------------------------------------------------------------- |
|
439 // |
|
440 void CPbk2AiwInterestItemPoc::DoInitMenuPaneL |
|
441 ( const TInt aResourceId, CEikMenuPane& aMenuPane, |
|
442 const MPbk2ContactUiControl& aControl, |
|
443 TUint aPreferredMenu /*= 0*/ ) const |
|
444 { |
|
445 CAiwGenericParamList& params = iServiceHandler.InParamListL(); |
|
446 TAiwPocParameterData pocParameter; |
|
447 pocParameter.iConsumerAppUid = TUid::Uid( KPbk2UID3 ); |
|
448 pocParameter.iConsumerWindowGroup = |
|
449 CCoeEnv::Static()->RootWin().Identifier(); |
|
450 pocParameter.iCommandId = 0; // not used in menu construct |
|
451 |
|
452 if ( aPreferredMenu != 0 ) |
|
453 { |
|
454 // Select POC call type |
|
455 pocParameter.iPreferredMenu = EAiwPoCCmdTalkGroup; |
|
456 } |
|
457 else |
|
458 { |
|
459 pocParameter.iPreferredMenu = |
|
460 iSelector->SelectPocCallType( aControl ); |
|
461 } |
|
462 |
|
463 // PoC parameter data always included |
|
464 TAiwGenericParam param = TAiwGenericParam( EGenericParamPoCData, |
|
465 TAiwVariant( TAiwPocParameterDataPckg( pocParameter ) ) ); |
|
466 params.AppendL( param ); |
|
467 |
|
468 // Let provider add its menu items to the menu |
|
469 iServiceHandler.InitializeMenuPaneL( aMenuPane, aResourceId, |
|
470 KAiwCmdPoC, params); |
|
471 } |
|
472 |
|
473 // -------------------------------------------------------------------------- |
|
474 // CPbk2AiwInterestItemPoc::CreatePocCmdObjectL |
|
475 // -------------------------------------------------------------------------- |
|
476 // |
|
477 MPbk2Command* CPbk2AiwInterestItemPoc::CreatePocCmdObjectL( |
|
478 const TInt aMenuCommandId, |
|
479 MPbk2ContactUiControl& aControl, |
|
480 MVPbkStoreContact& aStoreContact ) |
|
481 { |
|
482 MPbk2Command* cmd = NULL; |
|
483 |
|
484 cmd = CPbk2PocCmd::NewL( aMenuCommandId, iServiceHandler, |
|
485 *iSelector, aControl, aStoreContact, NULL ); |
|
486 |
|
487 return cmd; |
|
488 } |
|
489 |
|
490 // End of File |