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: Definition of the class CPbkxRclServiceUiContext |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CPBKXRCLSERVICEUICONTEXTIMPL_H |
|
19 #define CPBKXRCLSERVICEUICONTEXTIMPL_H |
|
20 |
|
21 #include "cpbkxremotecontactlookupserviceuicontext.h" |
|
22 #include "tpbkxremotecontactlookupprotocolaccountid.h" |
|
23 #include "mpbkxremotecontactlookupprotocolsessionobserver.h" |
|
24 #include "mpbkxrclcontactretrieval.h" |
|
25 #include "cpbkxrcleventscheduler.h" |
|
26 |
|
27 #include <AknWaitDialog.h> |
|
28 |
|
29 class CPbkxRclSearchResultDlg; |
|
30 class CPbkxRclResultInfoDlg; |
|
31 class CPbkxRemoteContactLookupProtocolSession; |
|
32 class CCoeEnv; |
|
33 class CPbkContactEngine; |
|
34 class CPbkxRemoteContactLookupProtocolAdapter; |
|
35 class CPbkxRclProtocolEnvImpl; |
|
36 class CPbkxRemoteContactLookupProtocolAccount; |
|
37 class CPbkxRclActionServiceWrapper; |
|
38 |
|
39 /** |
|
40 * Implementation class of service ui context. |
|
41 * |
|
42 * This class implements the RCL search logic and UI flow. |
|
43 * |
|
44 * @lib pbkxrclengine.lib |
|
45 * @since S60 3.1 |
|
46 */ |
|
47 |
|
48 class CPbkxRclServiceUiContextImpl : |
|
49 public CPbkxRemoteContactLookupServiceUiContext, |
|
50 public MPbkxRemoteContactLookupProtocolSessionObserver, |
|
51 public MPbkxRclContactRetrieval, |
|
52 public MPbkxRclEventHandler, |
|
53 public MEikCommandObserver, |
|
54 public MProgressDialogCallback |
|
55 { |
|
56 |
|
57 public: // constructors and destructor |
|
58 |
|
59 /** |
|
60 * Constructs new object. |
|
61 * |
|
62 * @param aId Acccount id. |
|
63 * @param aMode Mode in which context operates. |
|
64 * @return Created object. |
|
65 */ |
|
66 |
|
67 static CPbkxRclServiceUiContextImpl* NewL( |
|
68 TPbkxRemoteContactLookupProtocolAccountId aId, |
|
69 TMode aMode ); |
|
70 |
|
71 /** |
|
72 * Constructs new object. |
|
73 * |
|
74 * Constructed object is leaved in cleanup stack. |
|
75 * |
|
76 * @param aId Acccount id. |
|
77 * @param aMode Mode in which context operates. |
|
78 * @return Created object. |
|
79 */ |
|
80 static CPbkxRclServiceUiContextImpl* NewLC( |
|
81 TPbkxRemoteContactLookupProtocolAccountId aId, |
|
82 TMode aMode ); |
|
83 |
|
84 |
|
85 /** |
|
86 * Destructor. |
|
87 */ |
|
88 virtual ~CPbkxRclServiceUiContextImpl(); |
|
89 |
|
90 |
|
91 public: // methods from CPbkxRemoteContactLookupServiceUiContext |
|
92 |
|
93 /** |
|
94 * Execute UI flow. |
|
95 * |
|
96 * @param aQueryText loose query text |
|
97 * @param aResult remote lookup results |
|
98 */ |
|
99 virtual void ExecuteL( const TDesC& aQueryText, TResult& aResult ); |
|
100 |
|
101 |
|
102 public: // from MPbkxRemoteContactLookupProtocolSessionObserver |
|
103 |
|
104 /** |
|
105 * Notifies that the loose search has been completed. |
|
106 * |
|
107 * @param aStatus error code that tells how search went |
|
108 * @param aResults search results, ownership is moved to the caller of the |
|
109 * loose search. |
|
110 */ |
|
111 |
|
112 virtual void LooseSearchCompleted( |
|
113 TInt aStatus, |
|
114 RPointerArray<CPbkxRemoteContactLookupProtocolResult>& aResults ); |
|
115 |
|
116 /** |
|
117 * Notifies that the contact fields retrieval has been completed. |
|
118 * |
|
119 * @param aStatus error code that tells how retrieval went |
|
120 */ |
|
121 |
|
122 virtual void ContactFieldsRetrievalCompleted( TInt aStatus ); |
|
123 |
|
124 public: // from MPbkxRclContactRetrieval |
|
125 |
|
126 /** |
|
127 * Retrieves details of the contact with given index. |
|
128 * |
|
129 * @param aContactIndex Index of the contact for which details are retrieved. |
|
130 * @param aWaitNoteText Text shown in wait note. |
|
131 * @return ContactCard with details retrieved or NULL. NULL is returned |
|
132 * when either contact retrieval failed or user cancelled |
|
133 * contact retrieval. |
|
134 */ |
|
135 |
|
136 virtual CContactCard* RetrieveDetailsL( |
|
137 TInt aContactIndex, |
|
138 const TDesC& aWaitNoteText ); |
|
139 |
|
140 /** |
|
141 * Returns the number of contacts. |
|
142 * |
|
143 * @return The number of contacts. |
|
144 */ |
|
145 |
|
146 virtual TInt ContactCount() const; |
|
147 |
|
148 /** |
|
149 * Sets the index of currently selected contact. |
|
150 * |
|
151 * @param aIndex Index of the currently selected contact. |
|
152 */ |
|
153 |
|
154 virtual void SetSelectedContactL( TInt aIndex ); |
|
155 |
|
156 public: // from MPbkxRclEventHandler |
|
157 |
|
158 /** |
|
159 * Callback method from event scheduler. |
|
160 * |
|
161 * Operation is executed each time this method is called. |
|
162 */ |
|
163 |
|
164 virtual void EventTriggered(); |
|
165 |
|
166 public: // methods from MEikCommandObserver |
|
167 |
|
168 /** |
|
169 * Processes command from search result view or result information view. |
|
170 * |
|
171 * @param aCommand Command id. |
|
172 */ |
|
173 |
|
174 virtual void ProcessCommandL( TInt aCommandId ); |
|
175 |
|
176 public: // from MProgressDialogCallback |
|
177 |
|
178 /** |
|
179 * This method is called when wait note closed by either user pressing |
|
180 * cancel or dialog closed by code. |
|
181 */ |
|
182 virtual void DialogDismissedL( TInt aButtonId ); |
|
183 |
|
184 private: // enumerations used internally |
|
185 |
|
186 |
|
187 // Possible operations for context. |
|
188 |
|
189 enum TOperation |
|
190 { |
|
191 ENoOperation, // No operation |
|
192 EOpenSearchResultDlg, // Opens search result dialog |
|
193 EOpenResultInfoDlg, // Opens result info dialog |
|
194 ECloseSearchResultDlg, // Closes search result dialog |
|
195 ECloseResultInfoDlg, // Closes result info dialog |
|
196 EOpenSearchQueryDefault, // Opens default search query |
|
197 EOpenSearchQueryEmpty, // Opens empty search query |
|
198 EExecuteSearchWithNoQuery, // Executes search without prompting query |
|
199 EExit // Stop context execution |
|
200 }; |
|
201 |
|
202 // Possible state values for context. |
|
203 |
|
204 enum TState |
|
205 { |
|
206 EInitial = 0x1, // Initial state |
|
207 EResultDlgOnTop = 0x2, // Result dialog topmost |
|
208 EInfoDlgOnTop = 0x4, // Info dialog topmost |
|
209 EResultSelected = 0x8, // Result is selected |
|
210 EReturnToCaller = 0x10 // Return to the calling application |
|
211 }; |
|
212 |
|
213 |
|
214 // Wait object indexes. |
|
215 |
|
216 enum TWaitObjectIndex |
|
217 { |
|
218 EMainWait = 0, // Main wait loop. |
|
219 EContactRetrievalWait = 1 // Contact retrieval wait loop |
|
220 }; |
|
221 |
|
222 private: // methods used internally |
|
223 |
|
224 /** |
|
225 * Executes search. |
|
226 * |
|
227 * @param aShowQueryDialog Flag indicating whether search query dialog is |
|
228 * shown. |
|
229 * @param aQueryText Default value for query text. |
|
230 */ |
|
231 |
|
232 void ExecuteSearchL( TBool aShowQueryDialog, const TDesC& aQueryText ); |
|
233 |
|
234 /** |
|
235 * Displays wait dialog. |
|
236 * |
|
237 * @param aDialogResourceId Dialog resource id. |
|
238 * @param aText Text shown in wait dialog. |
|
239 */ |
|
240 |
|
241 void DisplayWaitDialogL( TInt aDialogResourceId, const TDesC& aText ); |
|
242 |
|
243 /** |
|
244 * Displays note dialog. |
|
245 * |
|
246 * @param aDialogResourceId Dialog resource id. |
|
247 * @param aText Text shown in dialog. |
|
248 * @param aTimeout Flag indicating whether note has timeout. |
|
249 * @return Possible return value from note. |
|
250 */ |
|
251 |
|
252 TBool DisplayNoteDialogL( |
|
253 TInt aDialogResourceId, |
|
254 const TDesC& aText, |
|
255 TBool aTimeout = EFalse ); |
|
256 |
|
257 /** |
|
258 * Displays query dialog. |
|
259 * |
|
260 * @param aDialogResourceId Dialog resource id. |
|
261 * @param aText Text shown in dialog. |
|
262 * @return Possible return value from note. |
|
263 */ |
|
264 //Fix for: EASV-7KFGG3 |
|
265 TBool DisplayQueryDialogL( |
|
266 TInt aDialogResourceId, |
|
267 const TDesC& aText ); |
|
268 |
|
269 /** |
|
270 * Closes wait dialog. |
|
271 */ |
|
272 |
|
273 void CloseWaitDialogL(); |
|
274 |
|
275 /** |
|
276 * Displays search result dialog. |
|
277 */ |
|
278 |
|
279 void DisplaySearchResultDialogL(); |
|
280 |
|
281 /** |
|
282 * Displays result info dialog. |
|
283 */ |
|
284 |
|
285 void DisplayResultInfoDialogL(); |
|
286 |
|
287 |
|
288 /** |
|
289 * Creates contact card array. |
|
290 * |
|
291 * Contact items are casted to contact cards. |
|
292 */ |
|
293 |
|
294 void CreateContactCardArray(); |
|
295 |
|
296 /** |
|
297 * Does actions after loose search has been completed. |
|
298 * |
|
299 * @param aStatus Status returned from adapter. |
|
300 * @param aResults Search results. |
|
301 */ |
|
302 |
|
303 void DoLooseSearchCompletedL( |
|
304 TInt aStatus, |
|
305 RPointerArray<CPbkxRemoteContactLookupProtocolResult>& aResults ); |
|
306 |
|
307 |
|
308 /** |
|
309 * Does actions after contact field retrieval has been completed. |
|
310 * |
|
311 * @param aStatus Status received from adapter. |
|
312 */ |
|
313 |
|
314 void DoContactFieldsRetrievalCompletedL( TInt aStatus ); |
|
315 |
|
316 |
|
317 /** |
|
318 * Executes operation. |
|
319 */ |
|
320 |
|
321 void DoHandleOperationL(); |
|
322 |
|
323 |
|
324 |
|
325 /** |
|
326 * Handles actions after search result dialog is closed based |
|
327 * on state of the context. |
|
328 */ |
|
329 |
|
330 void HandleSearchResultDialogExitL(); |
|
331 |
|
332 |
|
333 /** |
|
334 * This method is called when we are about to exit the context. |
|
335 * |
|
336 * Exit reason is set and possible error note is shown. |
|
337 */ |
|
338 |
|
339 void HandleContextExitL(); |
|
340 |
|
341 |
|
342 /** |
|
343 * Creates new contact item of the selected contact item. |
|
344 * |
|
345 * Ownership is transferred. |
|
346 * |
|
347 * @return Selected contact item. |
|
348 */ |
|
349 |
|
350 CContactItem* GetSelectedContactL(); |
|
351 |
|
352 |
|
353 /** |
|
354 * Searches for a result which corresponding contact item has given index. |
|
355 * |
|
356 * This method is needed because contact items are sorted and they are |
|
357 * in different order as results. So we must find a result which contains |
|
358 * the contact item with given index. |
|
359 * |
|
360 * Ownership is not transferred. |
|
361 * |
|
362 * @param aIndex Index of the contact item which result is searched. |
|
363 * @return Protocol result. |
|
364 */ |
|
365 |
|
366 CPbkxRemoteContactLookupProtocolResult* GetResultByIndex( TInt aIndex ); |
|
367 |
|
368 /** |
|
369 * Starts active wait. |
|
370 * |
|
371 * Execution is halted until corresponding stop is called. |
|
372 * |
|
373 * @param aIndex Index of the wait object to be started. |
|
374 */ |
|
375 |
|
376 void StartActiveWaitL( TWaitObjectIndex aIndex ); |
|
377 |
|
378 |
|
379 /** |
|
380 * Stops active wait with given index. |
|
381 * |
|
382 * @param aIndex Index of the wait object to be stopped. |
|
383 */ |
|
384 |
|
385 void StopActiveWait( TWaitObjectIndex aIndex ); |
|
386 |
|
387 |
|
388 /** |
|
389 * Changes the state of the context. |
|
390 * |
|
391 * @param aState The state in which context is set. |
|
392 */ |
|
393 |
|
394 void SetState( TState aState ); |
|
395 |
|
396 |
|
397 /** |
|
398 * Unsets state. |
|
399 * |
|
400 * @param aState State to be unset. |
|
401 */ |
|
402 |
|
403 void UnsetState( TState aState ); |
|
404 |
|
405 |
|
406 /** |
|
407 * Returns ETrue if given state is set. |
|
408 * |
|
409 * @param aState State which status is checked. |
|
410 * @return ETrue if context is in given state, EFalse otherwise. |
|
411 */ |
|
412 |
|
413 TBool IsStateSet( TState aState ); |
|
414 |
|
415 |
|
416 /** |
|
417 * Resets all state flags of context. |
|
418 */ |
|
419 |
|
420 void ResetState(); |
|
421 |
|
422 /** |
|
423 * Adds new operation to be executed. |
|
424 * |
|
425 * @param aOperation Operation to be added. |
|
426 */ |
|
427 |
|
428 void AddOperation( TOperation aOperation ); |
|
429 |
|
430 |
|
431 /** |
|
432 * Handles fatal error based on current state. |
|
433 * |
|
434 * @param aError Occurred error. |
|
435 */ |
|
436 |
|
437 void HandleError( TInt aError ); |
|
438 |
|
439 |
|
440 /** |
|
441 * Sorts contacts based on last name. |
|
442 */ |
|
443 |
|
444 static TInt Sort( const CContactCard& aFirst, const CContactCard& aSecond ); |
|
445 |
|
446 /** |
|
447 * Static callback for CPeriodic timer |
|
448 */ |
|
449 static TInt TimerCallBack(TAny* aAny); |
|
450 |
|
451 /** |
|
452 * This method is called in TimerCallBack() when time is out |
|
453 */ |
|
454 void TimeOut(); |
|
455 |
|
456 private: // constructors |
|
457 |
|
458 /** |
|
459 * Constructors. |
|
460 * |
|
461 * @param aId Protocol account id. |
|
462 * @param aMode Mode. |
|
463 */ |
|
464 |
|
465 CPbkxRclServiceUiContextImpl( |
|
466 TPbkxRemoteContactLookupProtocolAccountId aId, |
|
467 TMode aMode ); |
|
468 |
|
469 /** |
|
470 * Second-phase constructor. |
|
471 */ |
|
472 |
|
473 void ConstructL(); |
|
474 |
|
475 private: // data structure used internally |
|
476 |
|
477 class TOperationQueue |
|
478 { |
|
479 public: // constructor |
|
480 |
|
481 /** |
|
482 * Constructor. |
|
483 */ |
|
484 |
|
485 TOperationQueue(); |
|
486 |
|
487 public: // new methods |
|
488 |
|
489 /** |
|
490 * Adds new operation to queue. |
|
491 * |
|
492 * @param aOperation Operation to be added. |
|
493 */ |
|
494 |
|
495 void Add( TOperation aOperation ); |
|
496 |
|
497 /** |
|
498 * Pops operation to be executed from the queue. |
|
499 * |
|
500 * @return Operation to be executed. |
|
501 */ |
|
502 |
|
503 TOperation Pop(); |
|
504 |
|
505 |
|
506 /** |
|
507 * Returns number of the operations in the queue. |
|
508 */ |
|
509 |
|
510 TInt Count() const; |
|
511 |
|
512 private: // data |
|
513 |
|
514 // Maximum number of operations. |
|
515 static const TInt KMaxOperations = 10; |
|
516 |
|
517 // Current operation index. |
|
518 TInt iCurrent; |
|
519 |
|
520 // Count of operations. |
|
521 TInt iCount; |
|
522 |
|
523 // Fixed size operation array. |
|
524 TOperation iOperations[KMaxOperations]; |
|
525 }; |
|
526 |
|
527 |
|
528 private: // data |
|
529 |
|
530 // Account id. |
|
531 TPbkxRemoteContactLookupProtocolAccountId iAccountId; |
|
532 |
|
533 // State in which context is in. |
|
534 TInt iState; |
|
535 |
|
536 // Resource file offset. |
|
537 TInt iResourceFileOffset; |
|
538 |
|
539 // Original query criteria given to context. Owned. |
|
540 RBuf iQueryCriteria; |
|
541 |
|
542 // Query text given to execute. Owned. |
|
543 RBuf iQueryText; |
|
544 |
|
545 // Search mode. |
|
546 TMode iMode; |
|
547 |
|
548 // Selected contact index. |
|
549 TInt iSelectedIndex; |
|
550 |
|
551 // For waiting asynchronous operations to finish. Owned. |
|
552 RPointerArray<CActiveSchedulerWait> iWaitObjects; |
|
553 |
|
554 // Wait dialog. Owned. |
|
555 CAknWaitDialog* iWaitDialog; |
|
556 |
|
557 // Search result dialog. Owned. |
|
558 CPbkxRclSearchResultDlg* iSearchResultDialog; |
|
559 |
|
560 // Result information dialog. Owned. |
|
561 CPbkxRclResultInfoDlg* iResultInfoDialog; |
|
562 |
|
563 // Remote contact query results. Owned. |
|
564 RPointerArray<CPbkxRemoteContactLookupProtocolResult> iSearchResults; |
|
565 |
|
566 // Contact cards from the results. Not owned. |
|
567 RPointerArray<CContactCard> iContactCards; |
|
568 |
|
569 // Adapter used in searches. Owned. |
|
570 CPbkxRemoteContactLookupProtocolAdapter* iAdapter; |
|
571 |
|
572 // Session used to execute remote searches. Owned. |
|
573 CPbkxRemoteContactLookupProtocolSession* iSession; |
|
574 |
|
575 // Protocol environment given to adapter. Owned. |
|
576 CPbkxRclProtocolEnvImpl* iEnvImpl; |
|
577 |
|
578 // Account which is used. Owned. |
|
579 CPbkxRemoteContactLookupProtocolAccount* iAccount; |
|
580 |
|
581 // Search result. Not owned. |
|
582 TResult* iResult; |
|
583 |
|
584 // Contact engine used to help create phone book contact items. Owned. |
|
585 CPbkContactEngine* iContactEngine; |
|
586 |
|
587 // Action service wrapper used by search result dialog and |
|
588 // result information dialog. Owned. |
|
589 CPbkxRclActionServiceWrapper* iActionServiceWrapper; |
|
590 |
|
591 // For generating timed events. Owned. |
|
592 CPbkxRclEventScheduler* iEventScheduler; |
|
593 |
|
594 // Operation queue. |
|
595 TOperationQueue iOperations; |
|
596 |
|
597 // Context exit code. If something goes wrong, this code is set. |
|
598 TInt iExitCode; |
|
599 |
|
600 // Timer for generating time out event |
|
601 CPeriodic* iTimer; |
|
602 }; |
|
603 |
|
604 #endif |
|