multimediacommsengine/tsrc/MCETestUI/src/CMCETestUISessionView.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2009 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 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "MCETestUI.hrh"
       
    21 #include "CMCETestUISessionView.h"
       
    22 #include "CMCETestUIAppUi.h"
       
    23 #include "CMCETestUIEngineOutSession.h"
       
    24 #include "CMCETestUIENgineInSession.h"
       
    25 
       
    26 #include <e32def.h>
       
    27 #include <barsread.h>
       
    28 #include <AknNoteWrappers.h>
       
    29 #include <aknviewappui.h>
       
    30 #include <eikbtgpc.h>
       
    31 #include <akntitle.h>   // for CAknTitlePane
       
    32 #include <aknnavi.h>    // for CAknNavigationControlContainer
       
    33 #include <aknnavide.h>  // for CAknNavigationDecorator
       
    34 
       
    35 // CONSTANTS
       
    36 
       
    37 
       
    38 CMCETestUISessionView* CMCETestUISessionView::NewL( CMCETestUIEngine& aEngine )
       
    39 	{
       
    40 	CMCETestUISessionView* self = new(ELeave) CMCETestUISessionView( aEngine );
       
    41 	CleanupStack::PushL(self);
       
    42 	self->ConstructL();
       
    43 	CleanupStack::Pop(self);
       
    44 	return self;
       
    45 	}
       
    46 
       
    47 CMCETestUISessionView::CMCETestUISessionView( CMCETestUIEngine& aEngine )
       
    48     : iEngine( aEngine )
       
    49 	{
       
    50 	}
       
    51 
       
    52 //
       
    53 // Destructor for the view.
       
    54 //
       
    55 CMCETestUISessionView::~CMCETestUISessionView()
       
    56 	{
       
    57 	if (iContainer)
       
    58 		{
       
    59 		AppUi()->RemoveFromViewStack( *this, iContainer);
       
    60 		delete iContainer;
       
    61 		iContainer = NULL;
       
    62 		}
       
    63 	}
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CMCETestUISessionView::EngineStateChangedL()
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void CMCETestUISessionView::EngineStateChangedL()
       
    70     {
       
    71     if ( iContainer )
       
    72         {
       
    73         iContainer->ConstructModelL();
       
    74         iContainer->DrawNow();
       
    75         
       
    76         ConstructStatusPaneL();
       
    77         }
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CMCETestUISessionView::ChangeToMainViewL()
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CMCETestUISessionView::ChangeToMainViewL()
       
    85     {
       
    86     TUid viewId = TUid::Uid( EMCETestUIAppViewId );
       
    87     TRAPD( err, AppUi()->ActivateLocalViewL( viewId ) );
       
    88     if ( err != KErrNone )
       
    89         {
       
    90         User::InfoPrint( _L("Error") );
       
    91         }
       
    92         
       
    93     }
       
    94 
       
    95 /**
       
    96 * Called by the framework
       
    97 * @return The Uid for this view
       
    98 */
       
    99 TUid CMCETestUISessionView::Id() const 
       
   100     {
       
   101     return TUid::Uid( EMCETestUISessionViewId );
       
   102     }
       
   103 
       
   104 
       
   105 /**
       
   106 * From CEikAppUi, takes care of command handling for this view.
       
   107 *
       
   108 * @param aCommand command to be handled
       
   109 */
       
   110 void CMCETestUISessionView::HandleCommandL( TInt aCommand )
       
   111     {
       
   112     switch ( aCommand )
       
   113         {
       
   114         case EAknSoftkeyBack:
       
   115             {
       
   116             ChangeToMainViewL();
       
   117             break;
       
   118             }
       
   119         case EAknSoftkeyOptions:
       
   120             {
       
   121             if ( iContainer ){
       
   122                 iContainer->DoShowMenuL();
       
   123                 }
       
   124             break;
       
   125             }
       
   126         default:
       
   127             {
       
   128             }
       
   129         }
       
   130 	}
       
   131 
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CMCETestUISessionView::DoActivateL
       
   135 //
       
   136 // Called by the framework when the view is activated.  Constructs the 
       
   137 // container if necessary, setting this view as its MOP parent, and 
       
   138 // adding it to the control stack.
       
   139 //
       
   140 // -----------------------------------------------------------------------------
       
   141 
       
   142 void CMCETestUISessionView::DoActivateL(
       
   143         const TVwsViewId& /*aPrevViewId*/,
       
   144         TUid /*aCustomMessageId*/,
       
   145         const TDesC8& aCustomMessage )
       
   146     {
       
   147 	if (!iContainer)
       
   148 		{
       
   149 		// Solve session to be shown
       
   150 		TLex8 lex( aCustomMessage );
       
   151 	    TInt sessionIndex = -1; 
       
   152         User::LeaveIfError( lex.Val( sessionIndex ) );
       
   153         
       
   154         const RPointerArray<CMCETestUIEngineOutSession>& outSessions = 
       
   155                     iEngine.OutSessions();               
       
   156                     
       
   157         const RPointerArray<CMCETestUIEngineInSession>& inSessions = 
       
   158                     iEngine.InSessions(); 
       
   159         
       
   160         if ( sessionIndex < outSessions.Count() )
       
   161             {
       
   162             iSession = outSessions[sessionIndex];
       
   163             iTitlePaneText.Copy(KOutSession);
       
   164             iTitlePaneText.Append(KLeftParenthesis);
       
   165             iTitlePaneText.AppendNum(iSession->Id());
       
   166             iTitlePaneText.Append(KRightParenthesis);
       
   167             }
       
   168         else
       
   169             {
       
   170             sessionIndex -= outSessions.Count();
       
   171             if ( sessionIndex < inSessions.Count() )
       
   172                 {  
       
   173                 iSession = inSessions[sessionIndex];
       
   174                 iTitlePaneText.Copy(KInSession);
       
   175 	            iTitlePaneText.Append(KLeftParenthesis);
       
   176 	            iTitlePaneText.AppendNum(iSession->Id());
       
   177 	            iTitlePaneText.Append(KRightParenthesis);
       
   178                 }
       
   179             else
       
   180                 {
       
   181                 User::Leave( KErrArgument );
       
   182                 }
       
   183             }
       
   184 		
       
   185 		iContainer = CMCETestUISessionViewContainer::NewL(
       
   186 		    AppUi()->ClientRect(), *this, iEngine, *iSession );
       
   187 		iContainer->SetMopParent(this);
       
   188 		//iContainer->ConstructL(AppUi()->ClientRect());
       
   189 		AppUi()->AddToViewStackL( *this, iContainer );
       
   190 		}
       
   191     
       
   192          
       
   193 	Cba()->SetCommandSetL( R_AVKON_SOFTKEYS_OPTIONS_BACK );  
       
   194 	Cba()->DrawNow();  
       
   195     
       
   196     ConstructStatusPaneL();    
       
   197     			  
       
   198     }
       
   199 
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CMCETestUISessionView::DoDeactivate
       
   203 //
       
   204 // Called by the framework when the view is deactivated.  
       
   205 // Removes the container from the control stack and deletes it.
       
   206 //
       
   207 // -----------------------------------------------------------------------------
       
   208 void CMCETestUISessionView::DoDeactivate()
       
   209     {
       
   210 	if (iContainer)
       
   211 		{
       
   212 		// TODO: This should not leave
       
   213         CAknNavigationControlContainer* navi = 
       
   214             static_cast<CAknNavigationControlContainer*>
       
   215                 (StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ));
       
   216         navi->Pop( iNaviLabel );
       
   217         delete iNaviLabel;
       
   218         iNaviLabel = NULL;	
       
   219         	
       
   220 		AppUi()->RemoveFromViewStack( *this, iContainer );
       
   221 		delete iContainer;
       
   222 		iContainer = NULL;
       
   223 		}
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CMCETestUISessionView::ConstructStatusPaneL
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 void CMCETestUISessionView::ConstructStatusPaneL()
       
   231     {
       
   232     CAknTitlePane* titlePane = static_cast<CAknTitlePane*>
       
   233         (StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ));
       
   234     titlePane->SetTextL( iTitlePaneText );
       
   235     
       
   236     CAknNavigationControlContainer* navi = 
       
   237             static_cast<CAknNavigationControlContainer*>
       
   238                 (StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ));
       
   239     navi->Pop( iNaviLabel );
       
   240     delete iNaviLabel;
       
   241     iNaviLabel = NULL;
       
   242     iNaviLabel = navi->CreateNavigationLabelL( iSession->State() );
       
   243     navi->PushL( *iNaviLabel );    
       
   244     }
       
   245     
       
   246 // -----------------------------------------------------------------------------
       
   247 // CMCETestUISessionView::ConstructL
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 void CMCETestUISessionView::ConstructL()
       
   251     {
       
   252     BaseConstructL(); 
       
   253 	}
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CMCETestUISessionView::ChangeToStreamViewL
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 void CMCETestUISessionView::ChangeToStreamViewL( TInt aStreamIndex )
       
   260     {
       
   261     TUid viewId = TUid::Uid( EMCETestUIStreamViewId );
       
   262     TUid customMessageId = TUid::Uid( EMCETestUIStreamId );
       
   263     
       
   264     TBuf8<10> streamIndex; 
       
   265     streamIndex.AppendNum( aStreamIndex );
       
   266     TRAPD( err, AppUi()->ActivateLocalViewL( viewId, 
       
   267                                              customMessageId, 
       
   268                                              streamIndex ) );
       
   269     if ( err != KErrNone )
       
   270         {
       
   271         User::InfoPrint( _L("Error") );
       
   272         }   
       
   273     }