multimediacommsengine/tsrc/MCETestUI/src/CMCETestUISessionViewModel.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 // INCLUDE FILES
       
    20 
       
    21 #include "CMCETestUISessionViewModel.h"
       
    22 #include "CMCETestUIEngine.h"
       
    23 #include "CMCETestUIEngineSession.h"
       
    24 #include "MMCETestUIEngineCmdProvider.h"
       
    25 #include "CMceTestUIEngineAudioStream.h"
       
    26 #include "CMceTestUIEngineVideoStream.h"
       
    27 #include "mcetestuiengineconstants.h"
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 
       
    32 // ================= MEMBER FUNCTIONS ==========================================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CMCETestUISessionViewModel::NewL
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CMCETestUISessionViewModel* CMCETestUISessionViewModel::NewL(
       
    39         CMCETestUIEngine& aEngine,
       
    40         CMCETestUIEngineSession& aSession )
       
    41     {
       
    42 	CMCETestUISessionViewModel* self = 
       
    43 	    new(ELeave) CMCETestUISessionViewModel( aEngine, aSession );
       
    44 	CleanupStack::PushL(self);
       
    45 	self->ConstructL();
       
    46 	CleanupStack::Pop(self);
       
    47 	return self;    
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CMCETestUISessionViewModel::CMCETestUISessionViewModel
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CMCETestUISessionViewModel::CMCETestUISessionViewModel(
       
    55         CMCETestUIEngine& aEngine,
       
    56         CMCETestUIEngineSession& aSession )
       
    57     :iEngine( aEngine ),
       
    58      iSession( aSession ),
       
    59      audioStreamsSuppressed(EFalse)
       
    60     {
       
    61     }
       
    62     
       
    63 // -----------------------------------------------------------------------------
       
    64 // CMCETestUISessionViewModel::ConstructL()
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 void CMCETestUISessionViewModel::ConstructL()
       
    68     {
       
    69     iArray = new (ELeave) CDesCArrayFlat( 1 );
       
    70 
       
    71     PopulateStreamsL();
       
    72     PopulateVideoStreamsL();
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CMCETestUISessionViewModel::~CMCETestUISessionViewModel()
       
    77 // Destructor
       
    78 // Frees reserved resources
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CMCETestUISessionViewModel::~CMCETestUISessionViewModel()
       
    82     {
       
    83     delete iArray;
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CMCETestUISessionViewModel::MdcaCount() const
       
    88 // 
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 TInt CMCETestUISessionViewModel::MdcaCount() const
       
    92     {
       
    93     return iArray->MdcaCount();
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CMCETestUISessionViewModel::MdcaPoint() const
       
    98 // 
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 TPtrC CMCETestUISessionViewModel::MdcaPoint( TInt aIndex ) const
       
   102     {
       
   103     return iArray->MdcaPoint( aIndex );
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CMCETestUISessionViewModel::CmdProvider()
       
   108 // 
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 MMCETestUIEngineCmdProvider& CMCETestUISessionViewModel::CmdProvider( 
       
   112         TInt aIndex )
       
   113     {
       
   114     const RPointerArray<CMCETestUIEngineAudioStream>& audioStreams = 
       
   115             iSession.AudioStreamsL();
       
   116             
       
   117     const RPointerArray<CMCETestUIEngineVideoStream>& videoStreams = 
       
   118             iSession.VideoStreamsL();
       
   119     
       
   120     
       
   121     if ( audioStreamsSuppressed )
       
   122         {
       
   123         aIndex += audioStreams.Count();
       
   124         }
       
   125 
       
   126     if ( aIndex < audioStreams.Count() )
       
   127         {
       
   128         return *(audioStreams[aIndex]);
       
   129         }
       
   130     
       
   131     aIndex -= audioStreams.Count(); // Selected is not a audio stream
       
   132     
       
   133     if ( aIndex < videoStreams.Count() )
       
   134         {
       
   135         return *(videoStreams[aIndex]);
       
   136         }        
       
   137 /*    if ( aIndex < audioStreams.Count() )
       
   138         {
       
   139         return *(audioStreams[aIndex]);
       
   140         }
       
   141   */      
       
   142     return iEngine;   // default         
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CMCETestUISessionViewModel::SelectedAudioStreamIndex() const
       
   147 // 
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 TInt CMCETestUISessionViewModel::SelectedAudioStreamIndex( TInt aIndex ) const
       
   151     {
       
   152 
       
   153     const RPointerArray<CMCETestUIEngineAudioStream>& audioStreams = 
       
   154             iSession.AudioStreamsL();
       
   155             
       
   156     if ( audioStreamsSuppressed )
       
   157         {
       
   158         aIndex += audioStreams.Count();
       
   159         }
       
   160 
       
   161     if ( aIndex < audioStreams.Count() )
       
   162         {
       
   163         return aIndex;
       
   164         }
       
   165     
       
   166     return KErrNotFound;    
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CMCETestUISessionViewModel::SelectedVideoStreamIndex() const
       
   171 // 
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 TInt CMCETestUISessionViewModel::SelectedVideoStreamIndex( TInt aIndex ) const
       
   175     {
       
   176 
       
   177     const RPointerArray<CMCETestUIEngineAudioStream>& audioStreams = 
       
   178             iSession.AudioStreamsL();
       
   179 
       
   180     const RPointerArray<CMCETestUIEngineVideoStream>& videoStreams = 
       
   181             iSession.VideoStreamsL();           
       
   182                 
       
   183     
       
   184     // Next does not work correctly
       
   185                     
       
   186     
       
   187     if ( audioStreamsSuppressed )
       
   188         {
       
   189         aIndex += audioStreams.Count();
       
   190         }
       
   191 
       
   192     if ( aIndex < audioStreams.Count() )
       
   193         {
       
   194         return KErrNotFound;
       
   195         }
       
   196     
       
   197     aIndex -= audioStreams.Count(); // Selected is not a audio sink
       
   198     
       
   199     if ( aIndex < videoStreams.Count()  )
       
   200         {
       
   201         return aIndex;
       
   202         }
       
   203         
       
   204     return KErrNotFound;   // default      
       
   205     }
       
   206     
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CMCETestUISessionViewModel::PopulateStreamsL
       
   210 // Populate streams of a session
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 void CMCETestUISessionViewModel::PopulateStreamsL()
       
   214     {
       
   215     const RPointerArray<CMCETestUIEngineAudioStream>& audioStreams = 
       
   216             iSession.AudioStreamsL();
       
   217 
       
   218     for ( TInt i = 0; i < audioStreams.Count(); ++i )
       
   219         {
       
   220                               
       
   221         TInt itemLength = KAudioStream().Length() + 
       
   222                           KLeftParenthesis().Length() +
       
   223                           audioStreams[i]->TextualDirection().Length() +
       
   224                           KRightParenthesis().Length() +
       
   225                           audioStreams[i]->State().Length() +
       
   226                           KLeftParenthesis().Length() +
       
   227                           audioStreams[i]->StreamState().Length() +
       
   228                           KRightParenthesis().Length() +
       
   229                           KTab().Length() * 3;
       
   230                       
       
   231         HBufC16* item = HBufC16::NewLC( itemLength );
       
   232         TPtr16 itemPtr = item->Des();
       
   233         itemPtr.Append( KTab );
       
   234         itemPtr.Append( KAudioStream );
       
   235         itemPtr.Append( KLeftParenthesis() );
       
   236         itemPtr.Append( audioStreams[i]->TextualDirection() );
       
   237         itemPtr.Append( KRightParenthesis() );
       
   238         itemPtr.Append( KTab );
       
   239         itemPtr.Append( audioStreams[i]->State() );
       
   240         itemPtr.Append( KLeftParenthesis() );
       
   241         itemPtr.Append( audioStreams[i]->StreamState() );
       
   242         itemPtr.Append( KRightParenthesis() );
       
   243         itemPtr.Append( KTab );
       
   244     
       
   245         iArray->AppendL( *item );
       
   246         
       
   247         CleanupStack::PopAndDestroy( item );
       
   248         item = NULL;
       
   249         }
       
   250     }
       
   251 // -----------------------------------------------------------------------------
       
   252 // CMCETestUISessionViewModel::PopulateVideoStreamsL
       
   253 // Populate videostreams of a session
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 void CMCETestUISessionViewModel::PopulateVideoStreamsL()
       
   257     {
       
   258     const RPointerArray<CMCETestUIEngineVideoStream>& videoStreams = 
       
   259             iSession.VideoStreamsL();
       
   260 
       
   261     for ( TInt i = 0; i < videoStreams.Count(); ++i )
       
   262         {
       
   263                               
       
   264         TInt itemLength = KVideoStream().Length() + 
       
   265                           KLeftParenthesis().Length() +
       
   266                           videoStreams[i]->TextualVideoDirection().Length() +
       
   267                           KRightParenthesis().Length() +
       
   268                           videoStreams[i]->State().Length() +
       
   269                           KLeftParenthesis().Length() +
       
   270                           videoStreams[i]->StreamState().Length() +
       
   271                           KRightParenthesis().Length() +
       
   272                           KTab().Length() * 3;
       
   273                       
       
   274         HBufC16* item = HBufC16::NewLC( itemLength );
       
   275         TPtr16 itemPtr = item->Des();
       
   276         itemPtr.Append( KTab );
       
   277         itemPtr.Append( KVideoStream );
       
   278         itemPtr.Append( KLeftParenthesis() );
       
   279         itemPtr.Append( videoStreams[i]->TextualVideoDirection() );
       
   280         itemPtr.Append( KRightParenthesis() );
       
   281         itemPtr.Append( KTab );
       
   282         itemPtr.Append( videoStreams[i]->State() );
       
   283         itemPtr.Append( KLeftParenthesis() );
       
   284         itemPtr.Append( videoStreams[i]->StreamState() );
       
   285         itemPtr.Append( KRightParenthesis() );
       
   286         itemPtr.Append( KTab );
       
   287     
       
   288         iArray->AppendL( *item );
       
   289         
       
   290         CleanupStack::PopAndDestroy( item );
       
   291         item = NULL;
       
   292         }
       
   293     }
       
   294 
       
   295 // End of File