cbs/cbsui/UiSrc/CCbsUiTopicView.cpp
branchRCL_3
changeset 20 987c9837762f
parent 0 ff3b6d0fd310
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
       
     1 /*
       
     2 * Copyright (c) 2002 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 CCbsUiTopicView.
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDES
       
    22 #include <AknUtils.h>        // AknTextUtils
       
    23 #include <bldvariant.hrh>    // for feature flags
       
    24 #include <featmgr.h>         // for feature manager
       
    25 #include <aknViewAppUi.h>
       
    26 #include <aknnavide.h>
       
    27 #include <calslbs.h>
       
    28 #include <eikclb.h>
       
    29 #include <akntitle.h>
       
    30 #include <eikmenub.h>
       
    31 #include <eikmenup.h>
       
    32 #include <hlplch.h>
       
    33 #include <AknQueryDialog.h>
       
    34 #include <barsread.h>        // TResourceReader
       
    35 #include <cbsuiApp.rsg>
       
    36 #include <e32std.h>
       
    37 #include "CCbsUiTopicView.h"
       
    38 #include "CCbsUiTopicViewContainer.h"
       
    39 #include "Cbsuiapp.hrh"
       
    40 #include "CbsUiPanic.h"
       
    41 #include "CbsUiUtility.h"
       
    42 #include "CbsUiConstants.h"
       
    43 #include "CbsUiDebug.h"
       
    44 #include "MCbs.h"
       
    45 #include <StringLoader.h>
       
    46 #include <AknNaviDecoratorObserver.h>
       
    47 #include <aknnavi.h>
       
    48 
       
    49 
       
    50 
       
    51 // CONSTANTS
       
    52 const TUint KZeroFill = '0';
       
    53 const TUint KCbsMSKControlID = 3;
       
    54 
       
    55 
       
    56 // MODULE DATA STRUCTURES  
       
    57 
       
    58 // buffer to be used to unpack action information
       
    59 typedef TPckgBuf<TCbsUiTopicActivationPckg> TTopicNumberBuf;
       
    60 
       
    61 // index for setting the focus
       
    62 enum TTopicViewFocusIndexes 
       
    63     { 
       
    64     EFirstMessage = 0
       
    65     };
       
    66 
       
    67 
       
    68 
       
    69 //=============================================================================
       
    70 //  MEMBER FUNCTIONS
       
    71 // C++ default constructor can NOT contain any code, that
       
    72 // might leave.
       
    73 //
       
    74 CCbsUiTopicView::CCbsUiTopicView( MCbs& aServer )
       
    75 : iServer( aServer )
       
    76     {
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------
       
    80 // CCbsUiTopicView::ConstructL
       
    81 // 
       
    82 // 
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 void CCbsUiTopicView::ConstructL()
       
    86     {
       
    87     BaseConstructL( R_CBSUI_TOPICVIEW );
       
    88     
       
    89     // Create array for handles.
       
    90     iHandles = new (ELeave) TCbsUiMessageHandleList(
       
    91         KNumberOfTemporaryMessages); 
       
    92     
       
    93     CEikStatusPane* sp = StatusPane();
       
    94  
       
    95     iNaviContainer = 
       
    96         STATIC_CAST( CAknNavigationControlContainer*, sp->
       
    97         ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );    
       
    98     }
       
    99 
       
   100 
       
   101 // Two-phased constructor.
       
   102 CCbsUiTopicView* CCbsUiTopicView::NewL( MCbs& aServer )
       
   103     {
       
   104     __ASSERT_DEBUG( &aServer, CbsUiPanic(EErrNullPointer) );
       
   105     
       
   106     // Normal two phase construction.
       
   107     CCbsUiTopicView* self = 
       
   108         new (ELeave) CCbsUiTopicView(aServer);
       
   109     
       
   110     CleanupStack::PushL( self );
       
   111     self->ConstructL(); 
       
   112     CleanupStack::Pop();
       
   113     
       
   114     return self;
       
   115     }
       
   116 
       
   117 // Destructor
       
   118 CCbsUiTopicView::~CCbsUiTopicView()
       
   119     {	
       
   120     if ( iContainer )
       
   121         {
       
   122         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   123         }
       
   124     
       
   125     delete iContainer;
       
   126     delete iHandles;
       
   127     
       
   128     if ( iNaviContainer && iDecoratedLabel )
       
   129     	{
       
   130     	iNaviContainer->Pop ( iDecoratedLabel );
       
   131         delete iDecoratedLabel;
       
   132     	}
       
   133     iDecoratedLabel = NULL;
       
   134 	
       
   135 	if ( iNaviContainer && iPreviousDecoratedLabel )
       
   136 		{
       
   137     	iNaviContainer->Pop ( iPreviousDecoratedLabel );
       
   138         delete iPreviousDecoratedLabel;
       
   139 		}
       
   140 	iPreviousDecoratedLabel = NULL;
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------
       
   144 // CCbsUiTopicView::ReloadMessagesL
       
   145 // 
       
   146 // 
       
   147 // ---------------------------------------------------------
       
   148 //
       
   149 void CCbsUiTopicView::ReloadMessagesL()
       
   150     {
       
   151     TCbsTopic topic;
       
   152     TInt err( iServer.FindTopicByNumber(iCurrentTopicNumber, topic) );
       
   153     
       
   154     if ( err != KErrNone )
       
   155         {
       
   156         ActivateTopicListViewL(iCurrentTopicNumber);
       
   157         return;
       
   158         }
       
   159     
       
   160     UpdateTitlePaneL(topic);
       
   161     UpdateNaviPaneL(topic);
       
   162     
       
   163     PrepareReloading();
       
   164     LoadAllMessageTitlesL(iCurrentTopicNumber);
       
   165     ActivateListBoxL();
       
   166     
       
   167     // Set the MSK according to message count
       
   168     if ( !iHandles->Count() )
       
   169         {
       
   170         RemoveCommandFromMSK();
       
   171         SetMiddleSoftKeyLabelL( R_TEXT_SOFTKEY_EMPTY, ECbsUiappNullCmd );
       
   172         }
       
   173     else
       
   174         {
       
   175         RemoveCommandFromMSK();
       
   176         SetMiddleSoftKeyLabelL( R_QTN_MSK_OPEN, ECbsUiappCmdTopicMSKRead );
       
   177         }
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------
       
   181 // CCbsUiTopicView::TotalMessages
       
   182 // 
       
   183 // 
       
   184 // ---------------------------------------------------------
       
   185 //
       
   186 TInt CCbsUiTopicView::TotalMessages() const
       
   187     {
       
   188     return iHandles->Count();
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------
       
   192 // CCbsUiTopicView::UpdateTitlePaneL
       
   193 // 
       
   194 // 
       
   195 // ---------------------------------------------------------
       
   196 //
       
   197 void CCbsUiTopicView::UpdateTitlePaneL( const TCbsTopic& aTopic ) const
       
   198     {
       
   199     CEikStatusPane* sp = StatusPane();
       
   200     CAknTitlePane* title = 
       
   201         STATIC_CAST(
       
   202         CAknTitlePane*, sp->ControlL( TUid::Uid(EEikStatusPaneUidTitle) ) );
       
   203     
       
   204     __ASSERT_DEBUG( sp && title, CbsUiPanic(EStatusOrTitlePaneError) );
       
   205     
       
   206     title->SetTextL(aTopic.iName);
       
   207     
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------
       
   211 // CCbsUiTopicView::UpdateNaviPaneL
       
   212 // 
       
   213 // 
       
   214 // ---------------------------------------------------------
       
   215 //
       
   216 void CCbsUiTopicView::UpdateNaviPaneL( const TCbsTopic& aTopic )
       
   217     {   
       
   218     TBool next( EFalse );
       
   219     TBool previous( EFalse );
       
   220     TInt err( CheckIfCanMove( previous, next ) );
       
   221     
       
   222     if ( err != KErrNone )
       
   223         {
       
   224         iDecoratedLabel = CbsUiUtility::CreateEmptyNavigationPaneL();
       
   225         return;
       
   226         }
       
   227     
       
   228     TBuf<EMaxTopicNumberLength> number;
       
   229     TBuf<EMaxTopicNumberLength> buffer;
       
   230     
       
   231     buffer.AppendNum( TInt( aTopic.iNumber ) );
       
   232     number.Justify( buffer, EMaxTopicNumberLength, ERight, KZeroFill );
       
   233     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( number );
       
   234     
       
   235     //  Create a new decorator
       
   236     CAknNavigationDecorator* newDecoratedLabel = 
       
   237     						iNaviContainer->CreateNavigationLabelL ( number );
       
   238     CleanupStack::PushL( newDecoratedLabel );
       
   239     
       
   240     // Set new decorator on top of navi pane's decorator stack 
       
   241     // (topmost decorator is the one to show)
       
   242     iNaviContainer->PushL( *newDecoratedLabel );
       
   243     
       
   244     // remove previous decorator from decorator stack and delete it
       
   245     if ( iPreviousDecoratedLabel )
       
   246     	{
       
   247     	iNaviContainer->Pop( iPreviousDecoratedLabel );
       
   248     	delete iPreviousDecoratedLabel;
       
   249     	iPreviousDecoratedLabel = NULL;
       
   250     	}
       
   251     
       
   252     // update decorator pointers to new ones
       
   253     iPreviousDecoratedLabel = iDecoratedLabel;
       
   254     iDecoratedLabel = newDecoratedLabel;
       
   255     
       
   256     // set observer for navi pane
       
   257     iDecoratedLabel->SetNaviDecoratorObserver( this );
       
   258     
       
   259     CleanupStack::Pop( newDecoratedLabel );
       
   260       
       
   261     iDecoratedLabel->MakeScrollButtonVisible( ETrue );
       
   262 
       
   263     if( AknLayoutUtils::LayoutMirrored() )
       
   264         {
       
   265         // Should be arrows.
       
   266         iDecoratedLabel->SetScrollButtonDimmed( CAknNavigationDecorator::ELeftButton, !next );
       
   267         // And these should also be arrows.
       
   268         iDecoratedLabel->SetScrollButtonDimmed( CAknNavigationDecorator::ERightButton, !previous );
       
   269         }
       
   270     else
       
   271         {
       
   272         // Should be arrows.
       
   273         iDecoratedLabel->SetScrollButtonDimmed( CAknNavigationDecorator::ELeftButton, !previous );
       
   274         // And these should also be arrows.
       
   275         iDecoratedLabel->SetScrollButtonDimmed( CAknNavigationDecorator::ERightButton, !next );
       
   276         }   
       
   277     
       
   278     } 
       
   279 
       
   280 // ---------------------------------------------------------
       
   281 // CCbsUiTopicView::MarkCurrentlyFocusedHandle
       
   282 // 
       
   283 // 
       
   284 // ---------------------------------------------------------
       
   285 //
       
   286 void CCbsUiTopicView::MarkCurrentlyFocusedHandle()
       
   287     {
       
   288     if ( iContainer->CurrentPosition() >= 0 &&          
       
   289         TotalMessages() > iContainer->CurrentPosition() )
       
   290         {
       
   291         iCurrentHandle = iHandles->At( iContainer->CurrentPosition() );
       
   292         }
       
   293     }
       
   294 
       
   295 
       
   296 // ---------------------------------------------------------
       
   297 // CCbsUiTopicView::HandleRectChangeInContainer
       
   298 //
       
   299 //
       
   300 // ---------------------------------------------------------
       
   301 //
       
   302 void CCbsUiTopicView::HandleRectChangeInContainer()
       
   303     {
       
   304     if ( iContainer )
       
   305         {
       
   306         iContainer->SetRect( ClientRect() );
       
   307         }
       
   308     }
       
   309 
       
   310 
       
   311 // ---------------------------------------------------------
       
   312 // CCbsUiTopicView::SetFocusToMessage
       
   313 // 
       
   314 // 
       
   315 // ---------------------------------------------------------
       
   316 //
       
   317 void CCbsUiTopicView::SetFocusToMessage( TInt aIndex )
       
   318     {
       
   319     if ( iContainer && TotalMessages() > 0 )
       
   320         {
       
   321         __ASSERT_DEBUG( aIndex >= 0 && aIndex < TotalMessages(), 
       
   322             CbsUiPanic(EErrIndexOutOfBounds) );
       
   323         // first one in the list is the newest
       
   324         iContainer->SetCurrentItemIndex(aIndex);
       
   325         }
       
   326     }
       
   327 
       
   328 // ---------------------------------------------------------
       
   329 // CCbsUiTopicView::TopicListChangedL
       
   330 // 
       
   331 // 
       
   332 // ---------------------------------------------------------
       
   333 //
       
   334 void CCbsUiTopicView::TopicListChangedL( TCbsTopicListEvent aEvent, TCbsTopicNumber aTopicNumber )
       
   335                                         
       
   336     {
       
   337     if ( iContainer && iCurrentTopicNumber == aTopicNumber )
       
   338         {
       
   339         if ( aEvent == ECbsTopicReceivedNewMessage ) 
       
   340             {
       
   341             ReloadMessagesL();
       
   342             }
       
   343         }
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------
       
   347 // CCbsUiTopicView::SaveMessage
       
   348 // 
       
   349 // 
       
   350 // ---------------------------------------------------------
       
   351 //
       
   352 TInt CCbsUiTopicView::SaveMessage( const TCbsMessageHandle& aHandle )
       
   353     {
       
   354     return iServer.SaveMessage( aHandle );
       
   355     }
       
   356 
       
   357 // ---------------------------------------------------------
       
   358 // CCbsUiTopicView::LockMessage
       
   359 // 
       
   360 // 
       
   361 // ---------------------------------------------------------
       
   362 //
       
   363 TInt CCbsUiTopicView::LockMessage( TCbsMessageHandle aHandle )
       
   364     {
       
   365     return iServer.LockMessage(aHandle);
       
   366     }
       
   367 
       
   368 // ---------------------------------------------------------
       
   369 // CCbsUiTopicView::UnLockMessage
       
   370 // 
       
   371 // 
       
   372 // ---------------------------------------------------------
       
   373 // 
       
   374 void CCbsUiTopicView::UnLockMessage()
       
   375     {
       
   376     if ( iServer.Connected() )
       
   377         {        
       
   378         iServer.LockMessage(NULL);
       
   379         }
       
   380     }
       
   381 
       
   382 // ---------------------------------------------------------
       
   383 // CCbsUiTopicView::ShowMessageL
       
   384 // 
       
   385 // 
       
   386 // ---------------------------------------------------------
       
   387 //
       
   388 void CCbsUiTopicView::ShowMessageL()
       
   389     {
       
   390     if ( TotalMessages() == 0 )
       
   391         {
       
   392         return;
       
   393         }
       
   394     
       
   395     User::LeaveIfError( LockMessage(iCurrentHandle) );
       
   396     
       
   397     ActivateMsgViewL(iCurrentHandle);
       
   398     }
       
   399 
       
   400 // ---------------------------------------------------------
       
   401 // CCbsUiTopicView::DynInitMenuPaneL
       
   402 // 
       
   403 // 
       
   404 // ---------------------------------------------------------
       
   405 //
       
   406 void CCbsUiTopicView::DynInitMenuPaneL( TInt aResourceId,
       
   407                                        CEikMenuPane* aMenuPane )
       
   408     {
       
   409     __ASSERT_DEBUG( aMenuPane, CbsUiPanic(EMenuPaneNullError) );
       
   410     __ASSERT_DEBUG( aResourceId >= 0, CbsUiPanic( EErrInvalidValue) );
       
   411     if ( aResourceId == R_CBSUI_TOPICVIEW_MENU )
       
   412         {      
       
   413         if ( TotalMessages() > 0 )
       
   414             {
       
   415             // for using a right message
       
   416             MarkCurrentlyFocusedHandle();
       
   417             
       
   418             // Lock message that it is not deleted automatically.
       
   419             // If error, close the menu pane
       
   420             User::LeaveIfError( LockMessage(iCurrentHandle) );
       
   421             
       
   422             if( CbsUiUtility::IsSavedL(iCurrentHandle, iServer) )
       
   423                 {
       
   424                 aMenuPane->DeleteMenuItem(ECbsUiappCmdTopicMenuKeep);
       
   425                 }
       
   426             }      
       
   427         else 
       
   428             {
       
   429             // If no messages, then not possible to do anything..
       
   430             aMenuPane->DeleteMenuItem(ECbsUiappCmdTopicMenuRead);
       
   431             aMenuPane->DeleteMenuItem(ECbsUiappCmdTopicMenuKeep);
       
   432             aMenuPane->DeleteMenuItem(ECbsUiappCmdMessageDelete);
       
   433             }
       
   434         if( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   435             {
       
   436             aMenuPane->DeleteMenuItem( EAknCmdHelp );
       
   437             }
       
   438         }
       
   439     }
       
   440 
       
   441 // ---------------------------------------------------------
       
   442 // CCbsUiTopicView::SetEmphasis
       
   443 // 
       
   444 // 
       
   445 // ---------------------------------------------------------
       
   446 //
       
   447 void CCbsUiTopicView::SetEmphasis( CCoeControl* aMenuControl,TBool aEmphasis )
       
   448     {
       
   449     __ASSERT_DEBUG( aMenuControl, CbsUiPanic(EErrNullPointer) );
       
   450     CAknView::SetEmphasis(aMenuControl, aEmphasis);
       
   451     
       
   452     // Checks if the menu pane is showing.
       
   453     if ( !aEmphasis && iCanUnlock )
       
   454         {
       
   455         // Has to be unlocked, because otherwise message could stay as locked
       
   456         // and could not be deleted automatically by the server.
       
   457         UnLockMessage();
       
   458         }
       
   459     }
       
   460 
       
   461 
       
   462 // ---------------------------------------------------------
       
   463 // CCbsUiTopicView::ProcessCommandL
       
   464 // 
       
   465 // 
       
   466 // ---------------------------------------------------------
       
   467 //
       
   468 void CCbsUiTopicView::ProcessCommandL( TInt aCommand )
       
   469     {
       
   470     switch ( aCommand )
       
   471         {
       
   472         case ECbsUiappCmdTopicMenuRead: // same operation
       
   473         case ECbsUiappCmdTopicMSKRead:
       
   474         case ECbsUiappCmdTopicMenuKeep: // cannot unlock current message
       
   475         case ECbsUiappCmdMessageDelete:
       
   476             iCanUnlock = EFalse; // prevents SetEmphasis to unlock message
       
   477             break;
       
   478         default:
       
   479             break;
       
   480         };
       
   481     
       
   482     CAknView::ProcessCommandL(aCommand);
       
   483     
       
   484     switch ( aCommand )
       
   485         {
       
   486         case ECbsUiappCmdTopicMenuKeep: // same operation
       
   487         case ECbsUiappCmdMessageDelete:
       
   488             // Have to unlock message, because in error situation
       
   489             // message would be locked after these two operations.
       
   490             UnLockMessage();
       
   491             break;
       
   492         default:
       
   493             break;
       
   494         };
       
   495     }
       
   496 
       
   497 // ---------------------------------------------------------
       
   498 // CCbsUiTopicView::HandleCommandL
       
   499 // 
       
   500 // 
       
   501 // ---------------------------------------------------------
       
   502 //
       
   503 void CCbsUiTopicView::HandleCommandL( TInt aCommandId )
       
   504     {
       
   505     TTopicViewFocusState focusState = ENoFocusUpdate;
       
   506     
       
   507     switch (aCommandId)
       
   508         {
       
   509         case EAknSoftkeyBack:			    
       
   510             {
       
   511             ActivateTopicListViewL(iCurrentTopicNumber);
       
   512             break;
       
   513             }
       
   514         // MSK
       
   515         case ECbsUiappCmdTopicMSKRead:            
       
   516         case ECbsUiappCmdTopicMenuRead:
       
   517             {
       
   518             // to open a right message
       
   519             MarkCurrentlyFocusedHandle();
       
   520             if ( TotalMessages() > 0 )                     
       
   521                 {
       
   522                 ShowMessageL();
       
   523                 }
       
   524             break;        
       
   525             }
       
   526         case ECbsUiappCmdTopicMenuKeep:
       
   527             {
       
   528             CbsUiUtility::SaveCurrentMessageL(iCurrentHandle, *this);
       
   529             focusState = ESetFocusToCurrentHandle;
       
   530             break;
       
   531             }
       
   532         case ECbsUiappCmdMessageDelete:
       
   533             {           
       
   534             if ( TotalMessages() > 0 )
       
   535                 {                
       
   536                 CAknQueryDialog* dlg = CAknQueryDialog::NewL();            
       
   537                 
       
   538                 if ( dlg->ExecuteLD(R_DELETE_MSG_CONFIRMATION_QUERY) )
       
   539                     {              
       
   540                     // Unlock the message, so that it could be deleted
       
   541                     UnLockMessage();                
       
   542                     
       
   543                     if ( iServer.DeleteMessage(iCurrentHandle) == KErrNone )
       
   544                         {
       
   545                         SetNewCurrentHandle(iCurrentHandle);
       
   546                         }                
       
   547                     }
       
   548                 focusState = ESetFocusToCurrentHandle;
       
   549                 }
       
   550             break;
       
   551             }
       
   552         case ECbsUiappTopicViewCmdGoToPrevTopic:
       
   553             {
       
   554             TBool toPrevious(ETrue);
       
   555             SetCurrentTopicNumber(toPrevious);
       
   556             focusState = ESetFocusToFirstItem;
       
   557             break;
       
   558             }               
       
   559         case ECbsUiappTopicViewCmdGoToNextTopic:
       
   560             {
       
   561             TBool toPrevious(EFalse);
       
   562             SetCurrentTopicNumber(toPrevious);
       
   563             focusState = ESetFocusToFirstItem;
       
   564             break;
       
   565             }
       
   566         case EAknCmdHelp:
       
   567             AppUi()->HandleCommandL(aCommandId);
       
   568             break;
       
   569         case EAknCmdExit:	
       
   570             {
       
   571             ( (MEikCommandObserver*)AppUi() )->
       
   572                 ProcessCommandL(EAknCmdExit);
       
   573             break;
       
   574             }
       
   575         default:
       
   576             {
       
   577             break;
       
   578             }
       
   579         }
       
   580     
       
   581     if ( focusState != ENoFocusUpdate )
       
   582         {
       
   583         ReloadMessagesL();
       
   584         SetFocusAfterReloading(focusState);
       
   585         }
       
   586     
       
   587     }
       
   588 
       
   589 // ---------------------------------------------------------
       
   590 // CCbsUiTopicView::DoActivateL
       
   591 // 
       
   592 // 
       
   593 // ---------------------------------------------------------
       
   594 //
       
   595 void CCbsUiTopicView::DoActivateL( const TVwsViewId& /*aPrevViewId*/, 
       
   596                                   TUid aCustomMessageId,
       
   597                                   const TDesC8& aCustomMessage )
       
   598     {
       
   599     iCanUnlock = ETrue;
       
   600     if ( !iContainer )
       
   601         {
       
   602         iContainer = CCbsUiTopicViewContainer::NewL(*this, ClientRect());
       
   603         AppUi()->AddToViewStackL( *this, iContainer );
       
   604         }
       
   605     
       
   606     SetCurrentTopicNumberAndMessageHandle(aCustomMessage);
       
   607     
       
   608     ReloadMessagesL();    
       
   609                 
       
   610     TTopicViewFocusState focus(ESetFocusToFirstItem);
       
   611     if ( aCustomMessageId == KSetFocusToId )
       
   612         {
       
   613         focus = ESetFocusToCurrentHandle;
       
   614         }
       
   615     
       
   616     SetFocusAfterReloading(focus);
       
   617     
       
   618     // if the list box focus is changed, then container should be activetd
       
   619     // after ReloadMessagesL
       
   620     iContainer->ActivateL();
       
   621     }
       
   622 
       
   623 // ---------------------------------------------------------
       
   624 // CCbsUiTopicView::DoDeactivate
       
   625 // 
       
   626 // 
       
   627 // ---------------------------------------------------------
       
   628 //
       
   629 void CCbsUiTopicView::DoDeactivate()
       
   630     {	
       
   631     if (iContainer)
       
   632         {
       
   633         AppUi()->RemoveFromViewStack(*this, iContainer);
       
   634         delete iContainer;
       
   635         iContainer = NULL;	
       
   636         }
       
   637     }
       
   638 
       
   639 // ---------------------------------------------------------
       
   640 // CCbsUiTopicView::Id
       
   641 // 
       
   642 // 
       
   643 // ---------------------------------------------------------
       
   644 //
       
   645 TUid CCbsUiTopicView::Id() const
       
   646     {
       
   647     return TUid::Uid( ECbsUiTopicViewId );
       
   648     }
       
   649 
       
   650 // ---------------------------------------------------------
       
   651 // CCbsUiTopicView::FindMessageIndexByHandle
       
   652 // 
       
   653 // 
       
   654 // ---------------------------------------------------------
       
   655 //
       
   656 TInt CCbsUiTopicView::FindMessageIndexByHandle( TInt& aIndex,
       
   657                                                const TCbsMessageHandle& aMsgHandle )
       
   658     {
       
   659     __ASSERT_DEBUG( &aIndex, CbsUiPanic(EErrNullPointer) );
       
   660     
       
   661     TInt ret(KErrGeneral);
       
   662     
       
   663     for ( TInt i(0); i < TotalMessages() && ret != KErrNone; i++ )
       
   664         {
       
   665         if ( iHandles->At(i) == aMsgHandle )
       
   666             {
       
   667             ret = KErrNone;
       
   668             aIndex = i;
       
   669             }
       
   670         }
       
   671     
       
   672     return ret;
       
   673     }
       
   674 
       
   675 // ---------------------------------------------------------
       
   676 // CCbsUiTopicView::LoadAllMessageTitlesL
       
   677 // 
       
   678 // 
       
   679 // ---------------------------------------------------------
       
   680 //
       
   681 void CCbsUiTopicView::LoadAllMessageTitlesL( TCbsTopicNumber aTopicNumber )
       
   682     {
       
   683     TBuf<KMaxMessageTitleLength> buffer;
       
   684     TCbsMessage message;
       
   685     iHandles->Reset();
       
   686     
       
   687     // Then take the total amount of messages in the topic.
       
   688     TInt count(0);
       
   689     User::LeaveIfError( iServer.GetMessageCount(aTopicNumber, count) );    
       
   690     
       
   691     for ( TInt index(0); index < count; index++ )
       
   692         {        
       
   693         if ( iServer.GetMessage(aTopicNumber, index, message) == KErrNone )
       
   694             {
       
   695             if ( iContainer )
       
   696                 {
       
   697                 // Add contents.
       
   698                 TInt err = 
       
   699                     iServer.GetMessageContents(message.iHandle, buffer);
       
   700                 
       
   701                 __CBSUI_ASSERT( 
       
   702                     err == KErrNone, CbsUiPanic(EMessageContentsError) );
       
   703                 User::LeaveIfError(err);
       
   704                 
       
   705                 iContainer->ReloadOfferL(message, buffer);
       
   706                 }
       
   707             
       
   708             iHandles->AppendL(message.iHandle);
       
   709             }
       
   710         
       
   711         buffer.Zero();
       
   712         }
       
   713     }
       
   714 
       
   715 // ---------------------------------------------------------
       
   716 // CCbsUiTopicView::PrepareReloading
       
   717 // 
       
   718 // 
       
   719 // ---------------------------------------------------------
       
   720 //
       
   721 void CCbsUiTopicView::PrepareReloading()
       
   722     {
       
   723     if ( iContainer )
       
   724         {
       
   725         iContainer->ReloadStarts();
       
   726         }
       
   727     }
       
   728 
       
   729 // ---------------------------------------------------------
       
   730 // CCbsUiTopicView::SetFocusAfterReloading
       
   731 // 
       
   732 // 
       
   733 // ---------------------------------------------------------
       
   734 //
       
   735 void CCbsUiTopicView::SetFocusAfterReloading( TTopicViewFocusState aFocusState )
       
   736     {
       
   737     TInt focusedItem(KCbsErrValue);
       
   738     
       
   739     // has to find index from the ui side, because in the
       
   740     // server side the index could be an other.
       
   741     TBool setFocusToFirstItem(
       
   742         (aFocusState == ESetFocusToFirstItem) || 
       
   743         (aFocusState == ESetFocusToNewestMessage) ||
       
   744         (FindMessageIndexByHandle(focusedItem, iCurrentHandle) != KErrNone)
       
   745         );
       
   746     
       
   747     if ( setFocusToFirstItem )
       
   748         {
       
   749         focusedItem = EFirstMessage;
       
   750         }
       
   751     
       
   752     __ASSERT_DEBUG( 
       
   753         focusedItem != KCbsErrValue, CbsUiPanic(EErrInvalidValue) );
       
   754     
       
   755     SetFocusToMessage(focusedItem);
       
   756     }
       
   757 
       
   758 // ---------------------------------------------------------
       
   759 // CCbsUiTopicView::SetNewCurrentHandle
       
   760 // 
       
   761 // 
       
   762 // ---------------------------------------------------------
       
   763 //
       
   764 void CCbsUiTopicView::SetNewCurrentHandle( TCbsMessageHandle aDeletedHandle )
       
   765     {
       
   766     
       
   767     TInt messagePosition(KCbsErrValue);
       
   768     TInt err( FindMessageIndexByHandle(messagePosition, aDeletedHandle) );
       
   769     
       
   770     TBool isLastMessage = 
       
   771         ( (messagePosition + 1) == TotalMessages() ) &&
       
   772         (messagePosition >= 0);
       
   773     
       
   774     if ( isLastMessage )
       
   775         {
       
   776         // then previous handle should be focused after deletion
       
   777         messagePosition--;
       
   778         }
       
   779     else
       
   780         {
       
   781         // then the next handle will be focused after deletion
       
   782         messagePosition++;
       
   783         }
       
   784     
       
   785     if ( messagePosition >= TotalMessages() ||
       
   786         messagePosition < 0 || 
       
   787         err != KErrNone )
       
   788         {
       
   789         messagePosition = 0;
       
   790         }
       
   791     
       
   792     __ASSERT_DEBUG( err == KErrNone, CbsUiPanic(EErrMsgNotFound) );
       
   793     
       
   794     iCurrentHandle = iHandles->At(messagePosition);
       
   795     }
       
   796 
       
   797 // ---------------------------------------------------------
       
   798 // CCbsUiTopicView::SetCurrentTopicNumber
       
   799 // 
       
   800 // 
       
   801 // ---------------------------------------------------------
       
   802 //
       
   803 void CCbsUiTopicView::SetCurrentTopicNumber( TBool aToPrev )
       
   804     {
       
   805     TCbsTopicNumber prev;
       
   806     TCbsTopicNumber next;
       
   807     TInt position;
       
   808     
       
   809     TInt err( iServer.GetNextAndPrevTopicNumber(
       
   810         iCurrentTopicNumber, prev, next, position) );
       
   811     
       
   812     if ( err == KErrNone ) // handle exists
       
   813         {        
       
   814         if ( aToPrev )
       
   815             {
       
   816             if ( position != ECbsHead )
       
   817                 {
       
   818                 iCurrentTopicNumber = prev;
       
   819                 }
       
   820             }
       
   821         else 
       
   822             {
       
   823             if ( position != ECbsTail )
       
   824                 {
       
   825                 iCurrentTopicNumber = next;
       
   826                 }
       
   827             }
       
   828         }
       
   829     else 
       
   830         {
       
   831         __CBSUI_ASSERT( 0, CbsUiPanic(EErrTopicNumberNotFound) );
       
   832         }
       
   833     }
       
   834 
       
   835 // ---------------------------------------------------------
       
   836 // CCbsUiTopicView::SetCurrentTopicNumberAndMessageHandle
       
   837 // 
       
   838 // 
       
   839 // ---------------------------------------------------------
       
   840 //
       
   841 void CCbsUiTopicView::SetCurrentTopicNumberAndMessageHandle( const TDesC8& aTopicNumberDes )
       
   842     {
       
   843     TTopicNumberBuf aTopicNumberBuf;
       
   844     aTopicNumberBuf.Copy(aTopicNumberDes);
       
   845     iCurrentTopicNumber = aTopicNumberBuf().iTopicNumber;
       
   846     iCurrentHandle = aTopicNumberBuf().iMessageHandle;
       
   847     }
       
   848 
       
   849 // ---------------------------------------------------------
       
   850 // CCbsUiTopicView::ActivateMsgViewL
       
   851 // 
       
   852 // 
       
   853 // ---------------------------------------------------------
       
   854 //
       
   855 void CCbsUiTopicView::ActivateMsgViewL( TCbsMessageHandle aMsgHandle ) const
       
   856     {
       
   857     TPckgBuf<TCbsMessageHandle> pckgMessageHandle(aMsgHandle);
       
   858     
       
   859     AppUi()->ActivateLocalViewL( 
       
   860         TUid::Uid(ECbsUiMsgViewId), KCbsUiCustomMessageId, pckgMessageHandle);
       
   861     }
       
   862 
       
   863 // ---------------------------------------------------------
       
   864 // CCbsUiTopicView::ActivateTopicListViewL
       
   865 // 
       
   866 // 
       
   867 // ---------------------------------------------------------
       
   868 //
       
   869 void CCbsUiTopicView::ActivateTopicListViewL( TCbsTopicNumber aTopicNumber ) const
       
   870     {
       
   871     TPckgBuf<TCbsTopicNumber> pckgTopicNumber(aTopicNumber);
       
   872     
       
   873     AppUi()->ActivateLocalViewL( 
       
   874         TUid::Uid(ECbsUiTopicListViewId), KSetFocusToId, pckgTopicNumber);
       
   875     }
       
   876 
       
   877 // ---------------------------------------------------------
       
   878 // CCbsUiTopicView::CheckIfCanMove
       
   879 // 
       
   880 // 
       
   881 // ---------------------------------------------------------
       
   882 //
       
   883 TInt CCbsUiTopicView::CheckIfCanMove( TBool& aToPrevious, TBool& aToNext )
       
   884     {
       
   885     TCbsTopicNumber prevDummy; // not used
       
   886     TCbsTopicNumber nextDummy;
       
   887     TInt position;
       
   888     
       
   889     TInt err( iServer.GetNextAndPrevTopicNumber(
       
   890         iCurrentTopicNumber, prevDummy, nextDummy, position) );
       
   891     
       
   892     __CBSUI_ASSERT( err == KErrNone, CbsUiPanic(EErrTopicNumberNotFound) );
       
   893     __CBSUI_ASSERT( 
       
   894         position >= 0 && position <= (ECbsTail | ECbsHead), 
       
   895         CbsUiPanic(EErrInvalidValue) );
       
   896     
       
   897     aToPrevious = EFalse;
       
   898     aToNext = EFalse;
       
   899     
       
   900     if ( err == KErrNone )
       
   901         {
       
   902         if ( !position ) // topic in both sides
       
   903             {
       
   904             aToPrevious = ETrue;
       
   905             aToNext = ETrue;
       
   906             }
       
   907         else if ( position == ECbsTail )
       
   908             {
       
   909             aToPrevious = ETrue;
       
   910             }
       
   911         else if ( position == ECbsHead )
       
   912             {
       
   913             aToNext = ETrue;
       
   914             }
       
   915         else
       
   916             {
       
   917             //Does nothing
       
   918             }
       
   919         }
       
   920     
       
   921     return err;
       
   922     }
       
   923 
       
   924 // ---------------------------------------------------------
       
   925 // CCbsUiTopicView::ActivateListBoxL
       
   926 // 
       
   927 // 
       
   928 // ---------------------------------------------------------
       
   929 //
       
   930 void CCbsUiTopicView::ActivateListBoxL()
       
   931     {
       
   932     iContainer->ReloadEndsL();
       
   933     }
       
   934 
       
   935 // ---------------------------------------------------------
       
   936 // CCbsUiTopicView::SetMiddleSoftKeyLabelL
       
   937 // 
       
   938 // 
       
   939 // ---------------------------------------------------------
       
   940 //
       
   941 void CCbsUiTopicView::SetMiddleSoftKeyLabelL( 
       
   942     const TInt aResourceId, const TInt aCommandId )
       
   943     {
       
   944     CEikButtonGroupContainer* cbaGroup = Cba();
       
   945     if ( cbaGroup )
       
   946         {
       
   947         HBufC* mskText = StringLoader::LoadLC( aResourceId );
       
   948         TPtr mskPtr = mskText->Des();
       
   949         cbaGroup->AddCommandToStackL( 
       
   950             KCbsMSKControlID, 
       
   951             aCommandId, 
       
   952             mskPtr );
       
   953         CleanupStack::PopAndDestroy( mskText );
       
   954         }
       
   955     }
       
   956 
       
   957 // ---------------------------------------------------------
       
   958 // CCbsUiTopicView::RemoveCommandFromMSK
       
   959 // 
       
   960 // 
       
   961 // ---------------------------------------------------------
       
   962 //
       
   963 void CCbsUiTopicView::RemoveCommandFromMSK()
       
   964     {
       
   965     if ( Cba() )
       
   966         {
       
   967         Cba()->RemoveCommandFromStack( KCbsMSKControlID, ECbsUiappCmdTopicMSKRead );
       
   968         Cba()->RemoveCommandFromStack( KCbsMSKControlID, ECbsUiappNullCmd );
       
   969         }
       
   970     }
       
   971 
       
   972 // ---------------------------------------------------------
       
   973 // CCbsUiTopicView::HandleNaviDecoratorEventL
       
   974 // 
       
   975 // 
       
   976 // ---------------------------------------------------------
       
   977 //
       
   978 void CCbsUiTopicView::HandleNaviDecoratorEventL( TInt aEventID )
       
   979 	{
       
   980 	TTopicViewFocusState focusState = ENoFocusUpdate;
       
   981 	
       
   982     switch ( aEventID )
       
   983     	{
       
   984 		case MAknNaviDecoratorObserver::EAknNaviDecoratorEventLeftTabArrow:
       
   985 		    {
       
   986 		    SetCurrentTopicNumber( ETrue );
       
   987 		    focusState = ESetFocusToFirstItem;
       
   988 		    break;
       
   989 		    }               
       
   990 		case MAknNaviDecoratorObserver::EAknNaviDecoratorEventRightTabArrow:
       
   991 		    {
       
   992 		    SetCurrentTopicNumber( EFalse );
       
   993 		    focusState = ESetFocusToFirstItem;
       
   994 		    break;
       
   995 		    }
       
   996 		default:
       
   997 		    {
       
   998 		    break;
       
   999 		    }
       
  1000     	}
       
  1001     
       
  1002 	if ( focusState != ENoFocusUpdate )
       
  1003 		{
       
  1004 		ReloadMessagesL();
       
  1005 		SetFocusAfterReloading( focusState );
       
  1006 		}  
       
  1007 	}
       
  1008     
       
  1009 //  End of File