|
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: |
|
15 * Implementation of CCbsUiMsgView. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDES |
|
23 #include <AknUtils.h> //AknTextUtils |
|
24 #include <bldvariant.hrh> // for feature flags |
|
25 #include <featmgr.h> // for feature manager |
|
26 #include <aknappui.h> |
|
27 #include <aknViewAppUi.h> |
|
28 #include <eikmenup.h> |
|
29 #include <avkon.hrh> |
|
30 #include <aknnavide.h> |
|
31 #include <txtrich.h> // CRichText |
|
32 #include <AknProgressDialog.h> |
|
33 #include <eikmenub.h> |
|
34 #include <hlplch.h> |
|
35 #include <avkon.rsg> |
|
36 #include <StringLoader.h> |
|
37 #include <cbsuiApp.rsg> |
|
38 #include <barsread.h> |
|
39 #include <AknQueryDialog.h> |
|
40 #include <eikmop.h> |
|
41 #include <FindItemmenu.rsg> |
|
42 #include <finditemmenu.h> |
|
43 #include <finditemdialog.h> |
|
44 #include <akntitle.h> |
|
45 #include "CCbsUIMsgView.h" |
|
46 #include "Cbsuiapp.hrh" |
|
47 #include "CCbsUIMsgViewContainer.h" |
|
48 #include "CbsUiPanic.h" |
|
49 #include "CbsUiConstants.h" |
|
50 #include "CbsUiUtility.h" |
|
51 #include "CbsUiDebug.h" |
|
52 #include "MCbs.h" |
|
53 #include "CbsUiId.h" //KUidCbsUiappDef |
|
54 |
|
55 |
|
56 |
|
57 // CONSTANTS |
|
58 |
|
59 static const TUid KUidCbsUiappApp = { KUidCbsUiappDef }; |
|
60 const TInt KCbsImmediateMessageIdInt = 313; |
|
61 const TInt KMaxAssumedDateTimeLength = 30; |
|
62 |
|
63 _LIT(KSpace, " "); |
|
64 _LIT(KLineBreak, "\n"); |
|
65 const TInt KMaxSeparatorLenght = 5; |
|
66 const TInt KOneHotMarkedMessage = 1; |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 // ================= MEMBER FUNCTIONS ======================= |
|
73 |
|
74 // C++ default constructor can NOT contain any code, that |
|
75 // might leave. |
|
76 |
|
77 CCbsUiMsgView::CCbsUiMsgView( MCbs& aServer ) |
|
78 : |
|
79 iServer( aServer ) |
|
80 { |
|
81 } |
|
82 |
|
83 // Symbian OS default constructor can leave. |
|
84 void CCbsUiMsgView::ConstructL() |
|
85 { |
|
86 BaseConstructL( R_CBSUI_MSGVIEW ); |
|
87 iFindItemMenu = CFindItemMenu::NewL( ECbsUiCmdFindItem ); |
|
88 iFromOtherApplication = EFalse; |
|
89 |
|
90 CEikStatusPane* statusPane = StatusPane(); |
|
91 |
|
92 iNaviContainer = |
|
93 STATIC_CAST( CAknNavigationControlContainer*, statusPane-> |
|
94 ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) ); |
|
95 |
|
96 } |
|
97 |
|
98 // Two-phased constructor. |
|
99 CCbsUiMsgView* CCbsUiMsgView::NewL( MCbs& aServer ) |
|
100 { |
|
101 CCbsUiMsgView* self = new (ELeave) CCbsUiMsgView( aServer ); |
|
102 |
|
103 CleanupStack::PushL( self ); |
|
104 self->ConstructL(); |
|
105 CleanupStack::Pop(); |
|
106 return self; |
|
107 } |
|
108 |
|
109 // Destructor |
|
110 CCbsUiMsgView::~CCbsUiMsgView() |
|
111 { |
|
112 CloseContextMenu(); |
|
113 |
|
114 if ( iContainer ) |
|
115 { |
|
116 AppUi()->RemoveFromViewStack( *this, iContainer ); |
|
117 } |
|
118 |
|
119 delete iContainer; |
|
120 delete iFindItemMenu; |
|
121 |
|
122 if ( iNaviContainer && iDecoratedLabel ) |
|
123 { |
|
124 iNaviContainer->Pop ( iDecoratedLabel ); |
|
125 delete iDecoratedLabel; |
|
126 } |
|
127 iDecoratedLabel = NULL; |
|
128 |
|
129 if ( iNaviContainer && iPreviousDecoratedLabel ) |
|
130 { |
|
131 iNaviContainer->Pop ( iPreviousDecoratedLabel ); |
|
132 delete iPreviousDecoratedLabel; |
|
133 } |
|
134 iPreviousDecoratedLabel = NULL; |
|
135 |
|
136 delete iMessage; |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------- |
|
140 // CCbsUiMsgView::HandleNaviDecoratorEventL |
|
141 // |
|
142 // |
|
143 // --------------------------------------------------------- |
|
144 // |
|
145 void CCbsUiMsgView::HandleNaviDecoratorEventL( TInt aEventID ) |
|
146 { |
|
147 |
|
148 switch ( aEventID ) |
|
149 { |
|
150 // Left arrow tapped from the navi pane |
|
151 case MAknNaviDecoratorObserver::EAknNaviDecoratorEventLeftTabArrow: |
|
152 { |
|
153 if( AknLayoutUtils::LayoutMirrored() ) |
|
154 { |
|
155 MoveToNextMessageL(); |
|
156 } |
|
157 else |
|
158 { |
|
159 MoveToPreviousMessageL(); |
|
160 } |
|
161 break; |
|
162 } |
|
163 // Right arrow tapped from the navi pane |
|
164 case MAknNaviDecoratorObserver::EAknNaviDecoratorEventRightTabArrow: |
|
165 { |
|
166 if( AknLayoutUtils::LayoutMirrored() ) |
|
167 { |
|
168 MoveToPreviousMessageL(); |
|
169 } |
|
170 else |
|
171 { |
|
172 MoveToNextMessageL(); |
|
173 } |
|
174 break; |
|
175 } |
|
176 default: |
|
177 { |
|
178 break; |
|
179 } |
|
180 } |
|
181 |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------- |
|
185 // CCbsUiMsgView::DynInitMenuPaneL |
|
186 // |
|
187 // |
|
188 // --------------------------------------------------------- |
|
189 // |
|
190 void CCbsUiMsgView::DynInitMenuPaneL( TInt aResourceId, |
|
191 CEikMenuPane* aMenuPane ) |
|
192 { |
|
193 __ASSERT_DEBUG( aMenuPane, CbsUiPanic( EMenuPaneNullError ) ); |
|
194 __ASSERT_DEBUG( iFindItemMenu, CbsUiPanic( EFindItemNullError ) ); |
|
195 |
|
196 switch ( aResourceId ) |
|
197 { |
|
198 case R_CBSUI_MSGVIEW_MENU: |
|
199 { |
|
200 iFindItemMenu->DisplayFindItemMenuItemL( |
|
201 *aMenuPane, |
|
202 ECbsUiappCmdMsgMenuDelete ); |
|
203 |
|
204 if ( CbsUiUtility::IsSavedL(iCurrentHandle, iServer) ) |
|
205 { |
|
206 aMenuPane->DeleteMenuItem( ECbsUiappCmdMsgMenuKeep ); |
|
207 } |
|
208 if( !FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
209 { |
|
210 aMenuPane->DeleteMenuItem( EAknCmdHelp ); |
|
211 } |
|
212 break; |
|
213 } |
|
214 case R_FINDITEMMENU_MENU: |
|
215 { |
|
216 iFindItemMenu->DisplayFindItemCascadeMenuL( *aMenuPane ); |
|
217 break; |
|
218 } |
|
219 default: |
|
220 break; |
|
221 } |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------- |
|
225 // CCbsUiMsgView::ProcessCommandL |
|
226 // |
|
227 // |
|
228 // --------------------------------------------------------- |
|
229 // |
|
230 void CCbsUiMsgView::ProcessCommandL( TInt aCommand ) |
|
231 { |
|
232 if ( iContextMenu ) |
|
233 { |
|
234 iContextMenu->StopDisplayingMenuBar(); |
|
235 CloseContextMenu(); |
|
236 } |
|
237 |
|
238 // Context sensitive menu should be opened when MSK pressed |
|
239 switch ( aCommand ) |
|
240 { |
|
241 case EAknSoftkeyContextOptions: |
|
242 HandleCommandL( EAknSoftkeyContextOptions ); |
|
243 break; |
|
244 default: |
|
245 break; |
|
246 } |
|
247 // Call base class |
|
248 CAknView::ProcessCommandL( aCommand ); |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------- |
|
252 // CCbsUiMsgView::Id |
|
253 // |
|
254 // |
|
255 // --------------------------------------------------------- |
|
256 // |
|
257 TUid CCbsUiMsgView::Id() const |
|
258 { |
|
259 return TUid::Uid( ECbsUiMsgViewId ); |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------- |
|
263 // CCbsUiMsgView::MoveToNextMessage |
|
264 // |
|
265 // |
|
266 // --------------------------------------------------------- |
|
267 // |
|
268 void CCbsUiMsgView::MoveToNextMessageL() |
|
269 { |
|
270 // if a message is class 0, then changing the message |
|
271 // content is not allowed. |
|
272 if ( iIsClass0 ) |
|
273 { |
|
274 return; |
|
275 } |
|
276 |
|
277 if ( SetHandleTo(iCurrentHandle, EToNext) ) |
|
278 { |
|
279 DoLoadMessageL(); |
|
280 } |
|
281 |
|
282 } |
|
283 |
|
284 // --------------------------------------------------------- |
|
285 // CCbsUiMsgView::MoveToPreviousMessage |
|
286 // |
|
287 // |
|
288 // --------------------------------------------------------- |
|
289 // |
|
290 void CCbsUiMsgView::MoveToPreviousMessageL() |
|
291 { |
|
292 // if a message is class 0, then changing the message |
|
293 // content is not allowed. |
|
294 if ( iIsClass0 ) |
|
295 { |
|
296 return; |
|
297 } |
|
298 |
|
299 if ( SetHandleTo(iCurrentHandle, EToPrevious) ) |
|
300 { |
|
301 DoLoadMessageL(); |
|
302 } |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------- |
|
306 // CCbsUiMsgView::HandleCommandL |
|
307 // |
|
308 // |
|
309 // --------------------------------------------------------- |
|
310 // |
|
311 void CCbsUiMsgView::HandleCommandL( TInt aCommand ) |
|
312 { |
|
313 if ( iFindItemMenu && iFindItemMenu->CommandIsValidL( aCommand ) ) |
|
314 { |
|
315 DoSearchL( aCommand ); |
|
316 } |
|
317 |
|
318 TBool exit(EFalse); // program exits if true |
|
319 |
|
320 switch ( aCommand ) |
|
321 { |
|
322 case EAknSoftkeyBack: |
|
323 { |
|
324 ActivateTopicViewL( CurrentTopicNumber(), iCurrentHandle ); |
|
325 break; |
|
326 } |
|
327 case ECbsUiappCmdMsgMenuKeep: |
|
328 { |
|
329 if ( CbsUiUtility::SaveCurrentMessageL(iCurrentHandle, *this) == |
|
330 KErrNone && iIsClass0 ) |
|
331 { |
|
332 exit = ETrue; |
|
333 |
|
334 // show modal note |
|
335 CbsUiUtility::ShowConfirmationNoteL( |
|
336 R_TEXT_NOTE_MSG_KEPT, ETrue); |
|
337 } |
|
338 break; |
|
339 } |
|
340 case ECbsUiCmdCopyToClipboard: |
|
341 { |
|
342 iContainer->CopyToClipboardL(); |
|
343 CbsUiUtility::ShowConfirmationNoteL(R_TEXT_NOTE_MSG_TO_CLIP); |
|
344 break; |
|
345 } |
|
346 case ECbsUiappCmdMsgMenuDelete: |
|
347 { |
|
348 if ( DeleteMessageL(iCurrentHandle) && iIsClass0 ) |
|
349 { |
|
350 exit = ETrue; |
|
351 } |
|
352 break; |
|
353 } |
|
354 case EAknSoftkeyContextOptions: |
|
355 case ECbsUiappCmdOkKey: |
|
356 { |
|
357 LaunchContextMenuL(); |
|
358 break; |
|
359 } |
|
360 case EAknCmdHelp: |
|
361 AppUi()->HandleCommandL(aCommand); |
|
362 break; |
|
363 case EAknSoftkeyExit: // let it run through |
|
364 case EAknCmdExit: |
|
365 { |
|
366 if ( !iFromOtherApplication ) |
|
367 { |
|
368 // if it has been CBSUI then do this |
|
369 ActivateTopicListViewL(); |
|
370 } |
|
371 else |
|
372 { |
|
373 exit = ETrue; |
|
374 } |
|
375 iFromOtherApplication = EFalse; |
|
376 break; |
|
377 } |
|
378 default: |
|
379 break; |
|
380 } |
|
381 |
|
382 if ( exit ) |
|
383 { |
|
384 STATIC_CAST( |
|
385 MEikCommandObserver*, AppUi() )->ProcessCommandL(EAknCmdExit); |
|
386 } |
|
387 } |
|
388 |
|
389 // --------------------------------------------------------- |
|
390 // CCbsUiMsgView::DoActivateL |
|
391 // |
|
392 // |
|
393 // --------------------------------------------------------- |
|
394 // |
|
395 void CCbsUiMsgView::DoActivateL( const TVwsViewId& aPrevViewId, |
|
396 TUid aCustomMessageId, |
|
397 const TDesC8& aCustomMessage ) |
|
398 { |
|
399 iIsClass0 = EFalse; |
|
400 TBool topicListViewActivated(EFalse); |
|
401 |
|
402 switch ( aCustomMessageId.iUid ) |
|
403 { |
|
404 case KCbsUiCustomMessageIdInt: |
|
405 iFromOtherApplication = EFalse; |
|
406 Cba()->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_BACK); |
|
407 SetCurrentMessageHandle(aCustomMessage); |
|
408 break; |
|
409 case KCbsImmediateMessageIdInt: |
|
410 if ( aPrevViewId.iAppUid != KUidCbsUiappApp ) |
|
411 { |
|
412 iFromOtherApplication = ETrue; |
|
413 } |
|
414 SetCurrentMessageHandle(aCustomMessage); |
|
415 Cba()->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_EXIT); |
|
416 Cba()->DrawDeferred(); |
|
417 iIsClass0 = ETrue; |
|
418 break; |
|
419 default: // this should be soft notification |
|
420 iFromOtherApplication = EFalse; |
|
421 Cba()->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_BACK); |
|
422 topicListViewActivated = HandleSoftNotificationL(); |
|
423 break; |
|
424 } |
|
425 |
|
426 if ( !topicListViewActivated ) |
|
427 { |
|
428 if ( !iContainer ) |
|
429 { |
|
430 iContainer = CCbsUiMsgViewContainer::NewL(*this, ClientRect()); |
|
431 AppUi()->AddToViewStackL(*this, iContainer); |
|
432 } |
|
433 |
|
434 TInt err( DoLoadMessageL() ); |
|
435 |
|
436 // if it is class 0 message and some error occurs |
|
437 if ( err != KErrNone && iIsClass0 ) |
|
438 { |
|
439 User::Leave(err); |
|
440 } |
|
441 |
|
442 if ( iMessage ) |
|
443 { |
|
444 iContainer->ActivateL(); |
|
445 } |
|
446 else |
|
447 { |
|
448 // some error occured |
|
449 ActivateTopicViewL( CurrentTopicNumber(), iCurrentHandle ); |
|
450 } |
|
451 } |
|
452 } |
|
453 |
|
454 // --------------------------------------------------------- |
|
455 // CCbsUiMsgView::DoDeactivate() |
|
456 // |
|
457 // |
|
458 // --------------------------------------------------------- |
|
459 // |
|
460 void CCbsUiMsgView::DoDeactivate() |
|
461 { |
|
462 iServer.LockMessage(NULL); |
|
463 |
|
464 CloseContextMenu(); |
|
465 if ( iContainer ) |
|
466 { |
|
467 AppUi()->RemoveFromViewStack( *this, iContainer ); |
|
468 delete iContainer; |
|
469 iContainer = NULL; |
|
470 } |
|
471 |
|
472 delete iDecoratedLabel; |
|
473 iDecoratedLabel = NULL; |
|
474 |
|
475 DeleteOldMessage(); |
|
476 } |
|
477 |
|
478 // --------------------------------------------------------- |
|
479 // CCbsUiMsgView::UpdateNaviPaneL |
|
480 // |
|
481 // |
|
482 // --------------------------------------------------------- |
|
483 // |
|
484 void CCbsUiMsgView::UpdateNaviPaneL() |
|
485 { |
|
486 |
|
487 TInt currentPosition( KCbsErrValue ); |
|
488 TInt totalMessages( KCbsErrValue ); |
|
489 |
|
490 TInt err ( |
|
491 GetMessagePosition( iCurrentHandle, currentPosition, totalMessages ) ); |
|
492 |
|
493 TBool prev( currentPosition != 0 ); |
|
494 TBool next( ( currentPosition + 1 ) < totalMessages ); |
|
495 |
|
496 // If a message is class 0, then the navipane is empty |
|
497 if ( iIsClass0 || err != KErrNone ) |
|
498 { |
|
499 // Delete the existed label before creating a new one |
|
500 // in case of memory leak |
|
501 CAknNavigationDecorator* oldLabel = iDecoratedLabel; |
|
502 iDecoratedLabel = CbsUiUtility::CreateEmptyNavigationPaneL(); |
|
503 delete oldLabel; |
|
504 return; |
|
505 } |
|
506 |
|
507 // Create a new decorator |
|
508 CArrayFixFlat<TInt>* array = new( ELeave ) CArrayFixFlat<TInt>( 2 ); |
|
509 CleanupStack::PushL( array ); |
|
510 array->AppendL( currentPosition + 1 ); |
|
511 array->AppendL( totalMessages ); |
|
512 HBufC* messageLocationInTopic = StringLoader::LoadL( R_MESSAGE_LOCATION_IN_TOPIC, *array, iCoeEnv ); |
|
513 CleanupStack::PopAndDestroy(); // array |
|
514 CleanupStack::PushL( messageLocationInTopic ); |
|
515 |
|
516 CAknNavigationDecorator* newDecoratedLabel = iNaviContainer->CreateNavigationLabelL( *messageLocationInTopic ); |
|
517 CleanupStack::PopAndDestroy(); // messageLocationInTopic |
|
518 |
|
519 CleanupStack::PushL( newDecoratedLabel ); |
|
520 |
|
521 // Set new decorator on top of navi pane's decorator stack |
|
522 // ( topmost decorator is the one to show ) |
|
523 iNaviContainer->PushL( *newDecoratedLabel ); |
|
524 |
|
525 // Remove previous decorator from decorator stack and delete it |
|
526 if ( iPreviousDecoratedLabel ) |
|
527 { |
|
528 iNaviContainer->Pop( iPreviousDecoratedLabel ); |
|
529 delete iPreviousDecoratedLabel; |
|
530 iPreviousDecoratedLabel = NULL; |
|
531 } |
|
532 |
|
533 // Update decorator pointers to new ones |
|
534 iPreviousDecoratedLabel = iDecoratedLabel; |
|
535 iDecoratedLabel = newDecoratedLabel; |
|
536 |
|
537 __ASSERT_DEBUG( iDecoratedLabel, CbsUiPanic( EErrNullPointer ) ); |
|
538 |
|
539 // Set observer for navi pane |
|
540 iDecoratedLabel->SetNaviDecoratorObserver( this ); |
|
541 |
|
542 CleanupStack::Pop( newDecoratedLabel ); |
|
543 |
|
544 iDecoratedLabel->MakeScrollButtonVisible( ETrue ); |
|
545 |
|
546 if( AknLayoutUtils::LayoutMirrored() ) |
|
547 { |
|
548 iDecoratedLabel->SetScrollButtonDimmed( CAknNavigationDecorator::ELeftButton, !next ); |
|
549 iDecoratedLabel->SetScrollButtonDimmed( CAknNavigationDecorator::ERightButton, !prev ); |
|
550 } |
|
551 else |
|
552 { |
|
553 iDecoratedLabel->SetScrollButtonDimmed( CAknNavigationDecorator::ELeftButton, !prev ); |
|
554 iDecoratedLabel->SetScrollButtonDimmed( CAknNavigationDecorator::ERightButton, !next ); |
|
555 } |
|
556 |
|
557 } |
|
558 |
|
559 |
|
560 // --------------------------------------------------------- |
|
561 // CCbsUiMsgView::SaveMessage |
|
562 // |
|
563 // |
|
564 // --------------------------------------------------------- |
|
565 // |
|
566 TInt CCbsUiMsgView::SaveMessage( const TCbsMessageHandle& aHandle ) |
|
567 { |
|
568 return iServer.SaveMessage(aHandle); |
|
569 } |
|
570 |
|
571 // --------------------------------------------------------- |
|
572 // CCbsUiMsgView::DoSearchL |
|
573 // |
|
574 // |
|
575 // --------------------------------------------------------- |
|
576 // |
|
577 void CCbsUiMsgView::DoSearchL( TInt aCommand ) |
|
578 { |
|
579 CFindItemDialog* dialog = CFindItemDialog::NewL( |
|
580 iContainer->GetEditor()->Read(0), |
|
581 iFindItemMenu->SearchCase(aCommand) ); |
|
582 dialog->ExecuteLD(); |
|
583 } |
|
584 |
|
585 // --------------------------------------------------------- |
|
586 // CCbsUiMsgView::TopicListChangedL |
|
587 // |
|
588 // |
|
589 // --------------------------------------------------------- |
|
590 // |
|
591 void CCbsUiMsgView::TopicListChangedL( TCbsTopicListEvent /*aEvent*/, TCbsTopicNumber aTopicNumber ) |
|
592 { |
|
593 if ( iContainer && (CurrentTopicNumber() == aTopicNumber) ) |
|
594 { |
|
595 UpdateNaviPaneL(); |
|
596 } |
|
597 } |
|
598 |
|
599 |
|
600 |
|
601 // --------------------------------------------------------- |
|
602 // CCbsUiMsgView::HandleRectChangeInContainerL |
|
603 // |
|
604 // |
|
605 // --------------------------------------------------------- |
|
606 // |
|
607 void CCbsUiMsgView::HandleRectChangeInContainerL() |
|
608 { |
|
609 if ( iContainer ) |
|
610 { |
|
611 iContainer->SetRect( ClientRect() ); |
|
612 iContainer->UpdateMessageL( *iMessage ); |
|
613 } |
|
614 |
|
615 } |
|
616 |
|
617 // --------------------------------------------------------- |
|
618 // CCbsUiMsgView::CloseContextMenu |
|
619 // |
|
620 // |
|
621 // --------------------------------------------------------- |
|
622 // |
|
623 void CCbsUiMsgView::CloseContextMenu() |
|
624 { |
|
625 if ( iContextMenu ) |
|
626 { |
|
627 AppUi()->RemoveFromViewStack(*this, iContextMenu); |
|
628 delete iContextMenu; |
|
629 iContextMenu = NULL; |
|
630 } |
|
631 } |
|
632 |
|
633 // --------------------------------------------------------- |
|
634 // CCbsUiMsgView::LaunchContextMenuL |
|
635 // |
|
636 // |
|
637 // --------------------------------------------------------- |
|
638 // |
|
639 void CCbsUiMsgView::LaunchContextMenuL() |
|
640 { |
|
641 TInt rssName = R_CBSUI_MSG_KEEP_AND_DELETE_CONTEXT_MENUBAR; |
|
642 |
|
643 if ( CbsUiUtility::IsSavedL(iCurrentHandle, iServer) ) |
|
644 { |
|
645 rssName = R_CBSUI_MSG_DELETE_CONTEXT_MENUBAR; |
|
646 } |
|
647 |
|
648 CloseContextMenu(); |
|
649 |
|
650 __ASSERT_DEBUG( !iContextMenu, CbsUiPanic(EErrAllreadyExists) ); |
|
651 |
|
652 iContextMenu = new (ELeave) CEikMenuBar; |
|
653 iContextMenu->ConstructL( |
|
654 this, |
|
655 0, |
|
656 rssName ); |
|
657 |
|
658 // Set type to context sensitive |
|
659 iContextMenu->SetMenuType( CEikMenuBar::EMenuContext ); |
|
660 |
|
661 AppUi()->AddToViewStackL( |
|
662 *this, |
|
663 iContextMenu, |
|
664 ECoeStackPriorityMenu, |
|
665 ECoeStackFlagRefusesFocus ); |
|
666 |
|
667 iContextMenu->TryDisplayMenuBarL(); |
|
668 } |
|
669 |
|
670 // --------------------------------------------------------- |
|
671 // CCbsUiMsgView::DeleteOldMessage |
|
672 // |
|
673 // |
|
674 // --------------------------------------------------------- |
|
675 // |
|
676 void CCbsUiMsgView::DeleteOldMessage() |
|
677 { |
|
678 delete iMessage; |
|
679 iMessage = NULL; |
|
680 } |
|
681 |
|
682 // --------------------------------------------------------- |
|
683 // CCbsUiMsgView::DoLoadMessageL |
|
684 // |
|
685 // |
|
686 // --------------------------------------------------------- |
|
687 // |
|
688 TInt CCbsUiMsgView::DoLoadMessageL() |
|
689 { |
|
690 TRAPD( err, LoadMessageL() ); |
|
691 |
|
692 switch ( err ) |
|
693 { |
|
694 case KErrNotFound: |
|
695 { |
|
696 // If the message cannot be found |
|
697 // it is not necessary to do anything. |
|
698 // It is just showing some other message (current). |
|
699 break; |
|
700 } |
|
701 case KErrNone: |
|
702 { |
|
703 // normal case |
|
704 __ASSERT_DEBUG( iMessage, CbsUiPanic(EErrNullPointer) ); |
|
705 iContainer->UpdateMessageL(*iMessage); |
|
706 // navi pane has to be updated in all cases; expect when leave |
|
707 UpdateNaviPaneL(); |
|
708 Cba()->SetCommandSetL( R_CBS_SOFTKEYS_OPTIONS_BACK__CONTEXTOPTIONS ); |
|
709 break; |
|
710 } |
|
711 default: |
|
712 User::Leave( err ); |
|
713 break; |
|
714 } |
|
715 |
|
716 return err; |
|
717 } |
|
718 |
|
719 // --------------------------------------------------------- |
|
720 // CCbsUiMsgView::ActivateTopicViewL |
|
721 // |
|
722 // |
|
723 // --------------------------------------------------------- |
|
724 // |
|
725 void CCbsUiMsgView::ActivateTopicViewL( TCbsTopicNumber aTopicNumber, TCbsMessageHandle aHandle ) |
|
726 { |
|
727 TPckgBuf<TCbsUiTopicActivationPckg> message; |
|
728 message().iTopicNumber = aTopicNumber; |
|
729 message().iMessageHandle = aHandle; |
|
730 |
|
731 AppUi()->ActivateLocalViewL( |
|
732 TUid::Uid(ECbsUiTopicViewId), KSetFocusToId, message ); |
|
733 } |
|
734 |
|
735 // --------------------------------------------------------- |
|
736 // CCbsUiMsgView::SetCurrentMessageHandle |
|
737 // |
|
738 // |
|
739 // --------------------------------------------------------- |
|
740 // |
|
741 void CCbsUiMsgView::SetCurrentMessageHandle( const TDesC8& aMessageHandle ) |
|
742 { |
|
743 TPckgBuf<TCbsMessageHandle> pckgMessageHandle; |
|
744 pckgMessageHandle.Copy(aMessageHandle); |
|
745 iCurrentHandle = pckgMessageHandle(); |
|
746 } |
|
747 |
|
748 // --------------------------------------------------------- |
|
749 // CCbsUiMsgView::LoadMessageL |
|
750 // |
|
751 // |
|
752 // --------------------------------------------------------- |
|
753 // |
|
754 void CCbsUiMsgView::LoadMessageL() |
|
755 { |
|
756 User::LeaveIfError( iServer.LockMessage(iCurrentHandle) ); |
|
757 |
|
758 TCbsMessage message; |
|
759 TInt err( iServer.FindMessageByHandle(iCurrentHandle, message) ); |
|
760 __CBSUI_ASSERT( err == KErrNone, CbsUiPanic(EErrMsgHandleNotFound) ); |
|
761 User::LeaveIfError(err); |
|
762 |
|
763 // mark the message as read |
|
764 err = iServer.ReadMessage(iCurrentHandle); |
|
765 User::LeaveIfError(err); |
|
766 |
|
767 DeleteOldMessage(); |
|
768 iMessage = HBufC::NewMaxL(message.iLength); |
|
769 TPtr messageContent = iMessage->Des(); |
|
770 |
|
771 err = iServer.GetMessageContents(iCurrentHandle, messageContent); |
|
772 |
|
773 __CBSUI_ASSERT( err == KErrNone, |
|
774 CbsUiPanic(EMessageContentsError) ); |
|
775 |
|
776 if ( err != KErrNone ) |
|
777 { |
|
778 DeleteOldMessage(); |
|
779 User::Leave(err); |
|
780 } |
|
781 |
|
782 AddDateAndTimeL( |
|
783 message.iDateTime, |
|
784 &iMessage, // address of pointer variable |
|
785 R_CBS_DATE_FORMAT_ARRAY ); |
|
786 } |
|
787 |
|
788 // --------------------------------------------------------- |
|
789 // CCbsUiMsgView::AddDateAndTime |
|
790 // |
|
791 // |
|
792 // --------------------------------------------------------- |
|
793 // |
|
794 void CCbsUiMsgView::AddDateAndTimeL( const TInt64 aTime, HBufC** aMessage, TUint aResourceArrayId ) const |
|
795 { |
|
796 __ASSERT_DEBUG( aTime >= 0, CbsUiPanic(EErrInvalidValue) ); |
|
797 __ASSERT_DEBUG( *aMessage, CbsUiPanic(EErrNullPointer) ); |
|
798 __ASSERT_DEBUG( (*aMessage)->Length() > 0, CbsUiPanic(EErrEmptyDesc) ); |
|
799 __ASSERT_DEBUG( aResourceArrayId > 0, CbsUiPanic(EErrInvalidValue) ); |
|
800 |
|
801 HBufC* timeBuffer = HBufC::NewMaxLC( KMaxAssumedDateTimeLength ); |
|
802 TInt bufLen( 0 ); |
|
803 TTime time( aTime ); |
|
804 |
|
805 // change universal time to local time |
|
806 TLocale locale; |
|
807 time += locale.UniversalTimeOffset(); |
|
808 |
|
809 TPtr des = timeBuffer->Des(); |
|
810 TInt length( ( *aMessage )->Length() ); |
|
811 |
|
812 // for adding date and time to message |
|
813 TResourceReader reader; |
|
814 iCoeEnv->CreateResourceReaderLC( reader, aResourceArrayId ); |
|
815 TInt count( reader.ReadInt16() ); |
|
816 |
|
817 TBuf<KMaxSeparatorLenght> separator( KLineBreak ); |
|
818 TInt separatorsLength( KLineBreak().Length() + KSpace().Length() ); |
|
819 |
|
820 for ( TInt i( 0 ); i < count; i++ ) |
|
821 { |
|
822 TUint resourceId( reader.ReadUint32() ); |
|
823 |
|
824 HBufC* format = iCoeEnv->AllocReadResourceLC( resourceId ); |
|
825 |
|
826 time.FormatL( des, *format ); |
|
827 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( des ); |
|
828 |
|
829 if ( i > 0 ) |
|
830 { |
|
831 separator = KSpace; |
|
832 } |
|
833 |
|
834 bufLen += timeBuffer->Length(); |
|
835 (*aMessage) = (*aMessage)->ReAllocL( |
|
836 length + bufLen + separatorsLength ); |
|
837 |
|
838 // have to get a new pointer after reallocation |
|
839 TPtr ptr2 = ( *aMessage )->Des(); |
|
840 ptr2.Append( separator ); |
|
841 ptr2.Append( *timeBuffer ); |
|
842 |
|
843 CleanupStack::PopAndDestroy(); // format |
|
844 } |
|
845 |
|
846 CleanupStack::PopAndDestroy( 2 ); // timeBuffer, reader |
|
847 } |
|
848 |
|
849 // --------------------------------------------------------- |
|
850 // CCbsUiMsgView::CurrentTopicNumber |
|
851 // |
|
852 // |
|
853 // --------------------------------------------------------- |
|
854 // |
|
855 TCbsTopicNumber CCbsUiMsgView::CurrentTopicNumber() const |
|
856 { |
|
857 return STATIC_CAST( TCbsTopicNumber, (iCurrentHandle >> 16) & 0xFFFF ); |
|
858 } |
|
859 |
|
860 // --------------------------------------------------------- |
|
861 // CCbsUiMsgView::GetMessagePosition |
|
862 // |
|
863 // |
|
864 // --------------------------------------------------------- |
|
865 // |
|
866 TInt CCbsUiMsgView::GetMessagePosition( TCbsMessageHandle aHandle, TInt& aPosition, TInt& aTotal ) |
|
867 { |
|
868 TInt err( iServer.GetMessageIndexByHandle(aHandle, aPosition) ); |
|
869 |
|
870 __CBSUI_ASSERT( err == KErrNone, CbsUiPanic(EErrMsgHandleNotFound) ); |
|
871 __CBSUI_ASSERT( aPosition != KCbsErrValue, CbsUiPanic(EErrInvalidValue) ); |
|
872 |
|
873 if ( err == KErrNone ) |
|
874 { |
|
875 err = iServer.GetMessageCount( CurrentTopicNumber(), aTotal ); |
|
876 } |
|
877 |
|
878 __CBSUI_ASSERT( err == KErrNone, CbsUiPanic(EErrMsgHandleNotFound) ); |
|
879 __CBSUI_ASSERT( aPosition + 1 <= aTotal, CbsUiPanic(EErrMsgImbalance) ); |
|
880 |
|
881 return err; |
|
882 } |
|
883 |
|
884 // --------------------------------------------------------- |
|
885 // CCbsUiMsgView::SetHandleTo |
|
886 // |
|
887 // |
|
888 // --------------------------------------------------------- |
|
889 // |
|
890 TBool CCbsUiMsgView::SetHandleTo( TCbsMessageHandle& aHandle, TMsgViewSetHandle aTo ) |
|
891 { |
|
892 TCbsMessageHandle prev; |
|
893 TCbsMessageHandle next; |
|
894 TInt position(KCbsErrValue); |
|
895 TBool result(EFalse); |
|
896 |
|
897 TInt err( iServer.GetNextAndPrevMessageHandle( |
|
898 aHandle, prev, next, position) ); |
|
899 |
|
900 if ( err == KErrNone ) |
|
901 { |
|
902 __ASSERT_DEBUG( |
|
903 position >= 0 && position <= (ECbsTail | ECbsHead), |
|
904 CbsUiPanic(EErrInvalidValue) ); |
|
905 |
|
906 switch ( aTo ) |
|
907 { |
|
908 case EToPrevious: |
|
909 // if position is head it cannot go thru |
|
910 if ( (position & ECbsHead) == 0 ) |
|
911 { |
|
912 aHandle = prev; |
|
913 result = ETrue; |
|
914 } |
|
915 break; |
|
916 case EToNext: |
|
917 // if position is tail it cannot go thru |
|
918 if ( (position & ECbsTail) == 0 ) |
|
919 { |
|
920 aHandle = next; |
|
921 result = ETrue; |
|
922 } |
|
923 break; |
|
924 default: |
|
925 __ASSERT_DEBUG(0, CbsUiPanic(EErrInvalidValue)); |
|
926 break; |
|
927 } |
|
928 } |
|
929 |
|
930 return result; |
|
931 } |
|
932 |
|
933 // --------------------------------------------------------- |
|
934 // CCbsUiMsgView::DeleteMessageL |
|
935 // |
|
936 // |
|
937 // --------------------------------------------------------- |
|
938 // |
|
939 TBool CCbsUiMsgView::DeleteMessageL( TCbsMessageHandle aHandle ) |
|
940 { |
|
941 TBool result(EFalse); |
|
942 |
|
943 CAknQueryDialog* dlg = CAknQueryDialog::NewL(); |
|
944 |
|
945 if ( dlg->ExecuteLD(R_DELETE_MSG_CONFIRMATION_QUERY) ) |
|
946 { |
|
947 TCbsMessageHandle handleToBeFocused(aHandle); |
|
948 |
|
949 if ( !SetHandleTo(handleToBeFocused, EToNext) ) |
|
950 { |
|
951 if ( !SetHandleTo(handleToBeFocused, EToPrevious) ) |
|
952 { |
|
953 // next or previous could not be set, 0 will unlock message |
|
954 handleToBeFocused = 0; |
|
955 } |
|
956 } |
|
957 |
|
958 // Unlock message to be deleted and lock next message before delete |
|
959 __ASSERT_DEBUG(handleToBeFocused != aHandle, |
|
960 CbsUiPanic(EErrInvalidValue)); |
|
961 |
|
962 iServer.LockMessage(handleToBeFocused); |
|
963 iServer.DeleteMessage(aHandle); |
|
964 |
|
965 // free handleToBeFocused message |
|
966 if ( handleToBeFocused != 0) |
|
967 { |
|
968 iServer.LockMessage(NULL); |
|
969 } |
|
970 |
|
971 // Topic number is still the same even if the message is |
|
972 // deleted. |
|
973 ActivateTopicViewL( CurrentTopicNumber(), handleToBeFocused ); |
|
974 result = ETrue; |
|
975 } |
|
976 |
|
977 return result; |
|
978 } |
|
979 |
|
980 // --------------------------------------------------------- |
|
981 // CCbsUiMsgView::ActivateTopicListViewL |
|
982 // |
|
983 // |
|
984 // --------------------------------------------------------- |
|
985 // |
|
986 void CCbsUiMsgView::ActivateTopicListViewL() const |
|
987 { |
|
988 AppUi()->ActivateLocalViewL( TUid::Uid(ECbsUiTopicListViewId) ); |
|
989 } |
|
990 |
|
991 // --------------------------------------------------------- |
|
992 // CCbsUiMsgView::HandleSoftNotification |
|
993 // |
|
994 // |
|
995 // --------------------------------------------------------- |
|
996 // |
|
997 TBool CCbsUiMsgView::HandleSoftNotificationL() |
|
998 { |
|
999 TCbsTopic topic; |
|
1000 TInt err; |
|
1001 TBool result( EFalse ); |
|
1002 TInt count( iServer.NumberOfUnreadHotmarkedMessages() ); |
|
1003 __ASSERT_DEBUG( |
|
1004 count >= KOneHotMarkedMessage, CbsUiPanic(EErrInvalidValue) ); |
|
1005 |
|
1006 switch ( count ) |
|
1007 { |
|
1008 case KOneHotMarkedMessage: |
|
1009 iServer.GetHotmarkedMessageHandle( iCurrentHandle ); |
|
1010 err = iServer.FindTopicByNumber( CurrentTopicNumber(), topic ); |
|
1011 if ( err == KErrNone ) |
|
1012 { |
|
1013 //Update Title pane |
|
1014 CEikStatusPane* sp = StatusPane(); |
|
1015 CAknTitlePane* title = |
|
1016 STATIC_CAST(CAknTitlePane*, sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle) ) ); |
|
1017 title->SetTextL( topic.iName ); |
|
1018 } |
|
1019 break; |
|
1020 default: // Many hot marked messages |
|
1021 ActivateTopicListViewL(); |
|
1022 result = ETrue; |
|
1023 break; |
|
1024 } |
|
1025 |
|
1026 return result; |
|
1027 } |
|
1028 |
|
1029 |
|
1030 // End of File |