multimediacommsengine/tsrc/MCETestUI/src/CMCETestUIStreamViewContainer.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 // INCLUDE FILES
       
    19 #include "CMCETestUIAppUi.h"
       
    20 #include "CMCETestUIStreamViewContainer.h"
       
    21 #include "CMCETestUIStreamViewModel.h"
       
    22 #include "CMCETestUIEngine.h"
       
    23 #include "CMCETestUIEngineProfile.h"
       
    24 #include "CMCETestUIEngineSession.h"
       
    25 #include "CMCETestUIEngineAudioStream.h"
       
    26 #include "CMCETestUIEngineVideoStream.h"
       
    27 #include "TMCETestUIEngineCmdBase.h"
       
    28 #include <MCEMediaSink.h>
       
    29 #include <MCERtpSink.h>
       
    30 #include <MCEDisplaySink.h>
       
    31 #include <MCESpeakerSink.h>
       
    32 #include <MCEMicSource.h>
       
    33 #include <MCEFileSource.h>
       
    34 #include <MCEcameraSource.h>
       
    35 #include <MCEMediaSource.h>
       
    36 #include "CMCETestUIEngineSink.h"
       
    37 #include "CMCETestUIEngineSource.h"
       
    38 #include "CMCETestUIEngineVideoSource.h"
       
    39 #include "CMCETestUIEngineVideoSink.h"
       
    40 #include "createAudioCodecdialog.h"
       
    41 #include "createVideoCodecdialog.h"
       
    42 #include "createRtpSinkdialog.h"
       
    43 #include "createSpeakerSinkdialog.h"
       
    44 #include "createMicSourcedialog.h"
       
    45 #include "createCameraSourcedialog.h"
       
    46 #include "createFileSourcedialog.h"
       
    47 #include "createDisplaySinkDialog.h"
       
    48 #include <aknview.h>
       
    49 #include <aknpopup.h>
       
    50 #include <MCETestUI.rsg>
       
    51 
       
    52 
       
    53 // CONSTANTS
       
    54 
       
    55 
       
    56 // ================= MEMBER FUNCTIONS ==========================================
       
    57 
       
    58 CMCETestUIStreamViewContainer* CMCETestUIStreamViewContainer::NewL(
       
    59         const TRect& aRect,
       
    60         CAknView& aOwningView,
       
    61         CMCETestUIEngine& aEngine,
       
    62         CMCETestUIEngineAudioStream& aStream )
       
    63     {
       
    64 	CMCETestUIStreamViewContainer* self = 
       
    65 	        new(ELeave) CMCETestUIStreamViewContainer( 
       
    66 	                        aOwningView, 
       
    67 	                        aEngine, 
       
    68 	                        aStream );
       
    69 	CleanupStack::PushL(self);
       
    70 	self->ConstructL( aRect );
       
    71 	CleanupStack::Pop(self);
       
    72 	return self;    
       
    73     }
       
    74 
       
    75 CMCETestUIStreamViewContainer::CMCETestUIStreamViewContainer( 
       
    76         CAknView& aOwningView, 
       
    77         CMCETestUIEngine& aEngine, 
       
    78         CMCETestUIEngineAudioStream& aStream )
       
    79     :iOwningView( aOwningView ),
       
    80     iEngine( aEngine ),
       
    81     iStream( aStream ),
       
    82     iContextMenuAlreadyShown( EFalse )
       
    83     {
       
    84     }
       
    85     
       
    86 // -----------------------------------------------------------------------------
       
    87 // CMCETestUIStreamViewContainer::ConstructL(const TRect& aRect)
       
    88 // EPOC two phased constructor
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CMCETestUIStreamViewContainer::ConstructL(const TRect& aRect)
       
    92     {
       
    93     CreateWindowL();
       
    94     //Window().SetShadowDisabled(EFalse);
       
    95 
       
    96 	iListBox = new (ELeave) CAknDoubleStyleListBox(); 
       
    97    
       
    98 	iListBox->SetContainerWindowL(*this);
       
    99 	iListBox->ConstructL( this, 
       
   100 	                      EAknListBoxSelectionList | EAknListBoxLoopScrolling);
       
   101 	iListBox->SetListBoxObserver(this);
       
   102 	iListBox->SetMopParent(this);
       
   103 
       
   104     iListBoxModel = CMCETestUIStreamViewModel::NewL( iEngine , iStream);   
       
   105 
       
   106     iListBox->Model()->SetItemTextArray( iListBoxModel );      
       
   107 	
       
   108     SetRect(aRect);
       
   109 
       
   110     iListBox->SetRect(Rect());
       
   111 
       
   112 	//Set up the listbox to use a scroll bar
       
   113 	iListBox->CreateScrollBarFrameL(ETrue);
       
   114 	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   115 	    CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   116 
       
   117     ConstructModelL();
       
   118     
       
   119     ActivateL(); 
       
   120    
       
   121     //iListBox->HandleItemAdditionL();   
       
   122 
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CMCETestUISessionViewContainer::~CMCETestUISessionViewContainer()
       
   127 // Destructor
       
   128 // Frees reserved resources
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 CMCETestUIStreamViewContainer::~CMCETestUIStreamViewContainer()
       
   132     {
       
   133     delete iListBox;
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CMCETestUIStreamViewContainer::~CMCETestUIStreamViewContainer()
       
   138 // Destructor
       
   139 // Frees reserved resources
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 void CMCETestUIStreamViewContainer::ConstructModelL()
       
   143     {
       
   144     iListBoxModel = CMCETestUIStreamViewModel::NewL( iEngine, iStream );   
       
   145 
       
   146     iListBox->Model()->SetItemTextArray( iListBoxModel ); 
       
   147     
       
   148     iListBox->Reset();      
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CMCETestUIStreamViewContainer::SizeChanged()
       
   153 // Called by framework when the view size is changed
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CMCETestUIStreamViewContainer::SizeChanged()
       
   157     {
       
   158     TInt error;
       
   159     
       
   160     // TRAP methods that can leave.
       
   161     TRAP(error, SizeChangedL());
       
   162     if(error != KErrNone)
       
   163         {
       
   164         User::Panic( KNullDesC16, 0 );
       
   165         }   
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CMCETestUISessionViewContainer::SizeChangedL()
       
   170 // Methods that can leave and are needed by SizeChanged
       
   171 // are collected into this method.
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 void CMCETestUIStreamViewContainer::SizeChangedL()
       
   175     {
       
   176   
       
   177     }
       
   178 
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CMCETestUIStreamViewContainer::CountComponentControls() const
       
   182 // Note! Output window must be ignored.
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 TInt CMCETestUIStreamViewContainer::CountComponentControls() const
       
   186     {
       
   187     if ( iListBox ) 
       
   188         return 1;
       
   189     return 0;
       
   190     }
       
   191 
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CMCETestUIStreamViewContainer::ComponentControl()
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 CCoeControl* CMCETestUIStreamViewContainer::ComponentControl(TInt /*aIndex*/) const
       
   198     {
       
   199     return iListBox;
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CMCETestUIMainViewContainer::HandleListBoxEventL()
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void CMCETestUIStreamViewContainer::HandleListBoxEventL( 
       
   207                 CEikListBox* aListBox, 
       
   208                 TListBoxEvent aEventType )
       
   209     {
       
   210     TInt selectedIndex = iListBox->CurrentItemIndex();
       
   211     iContextMenuAlreadyShown = EFalse;
       
   212     
       
   213     if ( aListBox == iListBox )
       
   214         {
       
   215         if ( aEventType == EEventEnterKeyPressed || aEventType == EEventItemDoubleClicked )
       
   216             {
       
   217             if ( iListBoxModel->IsAudioSourceSelected( selectedIndex ) )
       
   218                 {
       
   219                 // Change to manager view 
       
   220                 const RPointerArray<CMCETestUIEngineSource>& sources = 
       
   221             										iStream.SourcesL();
       
   222             	if(sources[selectedIndex]->Type() == KMceMicSource)
       
   223             		{
       
   224             		CCreateMicSourceDialog* dialog = new ( ELeave )
       
   225                 					 CCreateMicSourceDialog(iStream, selectedIndex );
       
   226     				if (dialog->ExecuteLD( R_MCE_STREAM_MICSOURCE_DIALOG ) == EAknSoftkeyOk)
       
   227 	    				{
       
   228 	    				iContextMenuAlreadyShown = ETrue;
       
   229 	    				}
       
   230             		}
       
   231                  else if(sources[selectedIndex]->Type() == KMceFileSource)
       
   232             		{
       
   233             		CCreateAudioFileSourceDialog* dialog = new ( ELeave )
       
   234                 					 CCreateAudioFileSourceDialog(iStream, selectedIndex );
       
   235     				if (dialog->ExecuteLD( R_MCE_STREAM_FILESOURCE_AUDIO_DIALOG ) == EAknSoftkeyOk)
       
   236 	    				{
       
   237 	    				iContextMenuAlreadyShown = ETrue;
       
   238 	    				}
       
   239             		}           	
       
   240                 }
       
   241             else if ( iListBoxModel->SelectedAudioSinkIndex(selectedIndex) >= 0 )
       
   242                 {
       
   243                 const RPointerArray<CMCETestUIEngineSink>& sinks = 
       
   244             										iStream.SinksL();
       
   245             	if(sinks[iListBoxModel->SelectedAudioSinkIndex(selectedIndex)]->Type() == KMceSpeakerSink)
       
   246                 	{
       
   247                 	CCreateSpeakerSinkDialog* dialog = new ( ELeave )
       
   248                 					 CCreateSpeakerSinkDialog(iStream, iListBoxModel->SelectedAudioSinkIndex(selectedIndex) );
       
   249     				if (dialog->ExecuteLD( R_MCE_STREAM_SPEAKERSINK_DIALOG ) == EAknSoftkeyOk)
       
   250 	    				{
       
   251 	    				iContextMenuAlreadyShown = ETrue;
       
   252 	    				}
       
   253                 	}
       
   254           /*      else if(sinks[iListBoxModel->SelectedAudioSinkIndex(selectedIndex)]->Type() == KMCERTPSink)
       
   255                 	{
       
   256                 	CCreateRtpSinkDialog* dialog = new ( ELeave )
       
   257                 					 CCreateRtpSinkDialog(iStream, iListBoxModel->SelectedAudioSinkIndex(selectedIndex) );
       
   258     				if (dialog->ExecuteLD( R_MCE_STREAM_RTPSINK_DIALOG ) == EAknSoftkeyOk)
       
   259 	    				{
       
   260 	    				iContextMenuAlreadyShown = ETrue;
       
   261 	    				}
       
   262                 	}
       
   263             */    
       
   264                 }
       
   265             else if ( iListBoxModel->SelectedAudioCodecIndex(selectedIndex) >= 0 )
       
   266                 {
       
   267                 CCreateAudioCodecDialog* dialog = new ( ELeave )
       
   268                 					 CCreateAudioCodecDialog(iStream, iListBoxModel->SelectedAudioCodecIndex(selectedIndex) );
       
   269     			if (dialog->ExecuteLD( R_MCE_STREAM_AUDIOCODEC_DIALOG ) == EAknSoftkeyOk)
       
   270     				{
       
   271     				iContextMenuAlreadyShown = ETrue;
       
   272     				}
       
   273                 }
       
   274                 
       
   275             // TODO: Add changes to event and refer views
       
   276             }
       
   277         }
       
   278    }
       
   279 
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CMCETestUIStreamViewContainer::Draw(const TRect& aRect) const
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 void CMCETestUIStreamViewContainer::Draw(const TRect& aRect ) const
       
   286 {
       
   287     CWindowGc& gc = SystemGc();
       
   288     gc.Clear( aRect );    
       
   289 }
       
   290 
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // CMCETestUISessionViewContainer::HandleControlEventL(
       
   294 //     CCoeControl* aControl,TCoeEvent aEventType)
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 void CMCETestUIStreamViewContainer::HandleControlEventL(
       
   298         CCoeControl* /*aControl*/,
       
   299         TCoeEvent /*aEventType*/)
       
   300 {
       
   301     // TODO: Add your control event handler code here
       
   302 }
       
   303 
       
   304 
       
   305 // -----------------------------------------------------------------------------
       
   306 // CMCETestUISessionViewContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
   307 //                                    TEventCode aType)
       
   308 // Handle key event. Only up and down key arrow events are
       
   309 // consumed in order to enable scrolling in output window.
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 TKeyResponse CMCETestUIStreamViewContainer::OfferKeyEventL(
       
   313         const TKeyEvent& aKeyEvent,
       
   314         TEventCode aType)
       
   315     {    
       
   316     if ( aType == EEventKeyUp )
       
   317         {
       
   318         
       
   319         if ( aKeyEvent.iCode == 0 && aKeyEvent.iScanCode == 164 ) // EAknSoftkeyOptions?
       
   320             {
       
   321             DoShowMenuL();
       
   322 
       
   323             return EKeyWasConsumed;
       
   324             }
       
   325         }
       
   326     return iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   327    
       
   328     }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // 
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 void CMCETestUIStreamViewContainer::DoShowMenuL()
       
   335     {
       
   336     if ( iContextMenuAlreadyShown )
       
   337         {
       
   338         iContextMenuAlreadyShown = EFalse;
       
   339         return;
       
   340         }
       
   341         
       
   342     // Get command provider
       
   343     MMCETestUIEngineCmdProvider& cmdProvider = 
       
   344         iListBoxModel->CmdProvider( iListBox->CurrentItemIndex() );
       
   345     
       
   346     // Get commands    
       
   347     const RPointerArray<TMCETestUIEngineCmdBase>& commands = 
       
   348         cmdProvider.GetCommandsL();
       
   349         
       
   350     if(commands.Count() == 0)
       
   351         {
       
   352         return;    
       
   353         }
       
   354       
       
   355 
       
   356     // Generate list
       
   357     CAknSinglePopupMenuStyleListBox* listBox = 
       
   358             new (ELeave) CAknSinglePopupMenuStyleListBox;   
       
   359     CleanupStack::PushL( listBox );
       
   360     
       
   361     CAknPopupList* popup = CAknPopupList::NewL( 
       
   362             listBox, 
       
   363             R_AVKON_SOFTKEYS_MENU_LIST,
       
   364             AknPopupLayouts::EPopupSNotePopupWindow );
       
   365     CleanupStack::PushL( popup );
       
   366     popup->SetTitleL( _L("Available commands") );
       
   367     
       
   368     listBox->ConstructL( popup, 
       
   369         EAknListBoxSelectionList | EAknListBoxLoopScrolling);
       
   370     
       
   371     listBox->CreateScrollBarFrameL( ETrue );
       
   372     listBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   373         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   374     
       
   375     CDesCArray* array = new (ELeave) CDesCArrayFlat( 1 );
       
   376     CleanupStack::PushL( array );
       
   377     
       
   378     for ( TInt i = 0; i < commands.Count(); ++i )
       
   379         {
       
   380         TInt itemLength = commands[i]->Caption().Length() + 
       
   381                           KTab().Length();
       
   382         HBufC* item = HBufC::NewLC( itemLength );
       
   383         TPtr itemPtr = item->Des();
       
   384         itemPtr.Append( commands[i]->Caption() );
       
   385         itemPtr.Append( KTab );
       
   386 
       
   387         array->AppendL( *item );
       
   388 
       
   389         CleanupStack::PopAndDestroy( item );
       
   390         item = NULL;
       
   391         }
       
   392            
       
   393     CleanupStack::Pop( array );
       
   394     listBox->Model()->SetItemTextArray( array );            
       
   395     
       
   396     CleanupStack::Pop( popup ); 
       
   397     TInt selectedCommand = -1;             
       
   398     if ( popup->ExecuteLD() )
       
   399         {
       
   400         iContextMenuAlreadyShown = ETrue;
       
   401         selectedCommand = listBox->CurrentItemIndex();
       
   402         }
       
   403 
       
   404     CleanupStack::PopAndDestroy( listBox );
       
   405 
       
   406     if ( selectedCommand != -1 )
       
   407         {
       
   408         // This will not work...
       
   409         TRAPD( err, commands[ selectedCommand ]->ExecuteL() );
       
   410         if ( err != KErrNone )
       
   411             {
       
   412             CEikonEnv* eikonEnv = CEikonEnv::Static();
       
   413             CMCETestUIAppUi* tempUiPtr = (CMCETestUIAppUi*)eikonEnv->AppUi();
       
   414             TInt errorLength = KLeaveMessage().Length() + 10;
       
   415             HBufC* error = HBufC::NewL( errorLength );
       
   416             TPtr errorPtr = error->Des();
       
   417             errorPtr.Append( KLeaveMessage );
       
   418             errorPtr.AppendNum( err );
       
   419            // User::InfoPrint( *error );
       
   420             tempUiPtr->NotifyUser(*error);
       
   421             delete error;
       
   422             }
       
   423                           
       
   424         }
       
   425     }
       
   426 
       
   427 // ================= MEMBER FUNCTIONS ==========================================
       
   428 
       
   429 CMCETestUIVideoStreamViewContainer* CMCETestUIVideoStreamViewContainer::NewL(
       
   430         const TRect& aRect,
       
   431         CAknView& aOwningView,
       
   432         CMCETestUIEngine& aEngine,
       
   433         CMCETestUIEngineVideoStream& aStream )
       
   434     {
       
   435 	CMCETestUIVideoStreamViewContainer* self = 
       
   436 	        new(ELeave) CMCETestUIVideoStreamViewContainer( 
       
   437 	                        aOwningView, 
       
   438 	                        aEngine, 
       
   439 	                        aStream );
       
   440 	CleanupStack::PushL(self);
       
   441 	self->ConstructL( aRect );
       
   442 	CleanupStack::Pop(self);
       
   443 	return self;    
       
   444     }
       
   445 
       
   446 CMCETestUIVideoStreamViewContainer::CMCETestUIVideoStreamViewContainer( 
       
   447         CAknView& aOwningView, 
       
   448         CMCETestUIEngine& aEngine, 
       
   449         CMCETestUIEngineVideoStream& aStream )
       
   450     :iOwningView( aOwningView ),
       
   451     iEngine( aEngine ),
       
   452     iStream( aStream ),
       
   453     iContextMenuAlreadyShown( EFalse )
       
   454     {
       
   455     }
       
   456     
       
   457 // -----------------------------------------------------------------------------
       
   458 // CMCETestUIVideoStreamViewContainer::ConstructL(const TRect& aRect)
       
   459 // EPOC two phased constructor
       
   460 // -----------------------------------------------------------------------------
       
   461 //
       
   462 void CMCETestUIVideoStreamViewContainer::ConstructL(const TRect& aRect)
       
   463     {
       
   464     CreateWindowL();
       
   465     //Window().SetShadowDisabled(EFalse);
       
   466 
       
   467 	iListBox = new (ELeave) CAknDoubleStyleListBox(); 
       
   468    
       
   469 	iListBox->SetContainerWindowL(*this);
       
   470 	iListBox->ConstructL( this, 
       
   471 	                      EAknListBoxSelectionList | EAknListBoxLoopScrolling);
       
   472 	iListBox->SetListBoxObserver(this);
       
   473 	iListBox->SetMopParent(this);
       
   474 
       
   475     iListBoxModel = CMCETestUIVideoStreamViewModel::NewL( iEngine , iStream);   
       
   476 
       
   477     iListBox->Model()->SetItemTextArray( iListBoxModel );      
       
   478 	
       
   479     SetRect(aRect);
       
   480 
       
   481     iListBox->SetRect(Rect());
       
   482 
       
   483 	//Set up the listbox to use a scroll bar
       
   484 	iListBox->CreateScrollBarFrameL(ETrue);
       
   485 	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   486 	    CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   487 
       
   488     ConstructModelL();
       
   489     
       
   490     ActivateL(); 
       
   491    
       
   492     //iListBox->HandleItemAdditionL();   
       
   493     }
       
   494 
       
   495 // -----------------------------------------------------------------------------
       
   496 // CMCETestUIVideoStreamViewContainer::~CMCETestUIVideoStreamViewContainer()
       
   497 // Destructor
       
   498 // Frees reserved resources
       
   499 // -----------------------------------------------------------------------------
       
   500 //
       
   501 CMCETestUIVideoStreamViewContainer::~CMCETestUIVideoStreamViewContainer()
       
   502     { 
       
   503     delete iListBox;
       
   504     }
       
   505 
       
   506 // -----------------------------------------------------------------------------
       
   507 // CMCETestUIVideoStreamViewContainer::~CMCETestUIStreamViewContainer()
       
   508 // Destructor
       
   509 // Frees reserved resources
       
   510 // -----------------------------------------------------------------------------
       
   511 //
       
   512 void CMCETestUIVideoStreamViewContainer::ConstructModelL()
       
   513     {
       
   514     iListBoxModel = CMCETestUIVideoStreamViewModel::NewL( iEngine, iStream );   
       
   515 
       
   516     iListBox->Model()->SetItemTextArray( iListBoxModel ); 
       
   517     
       
   518     iListBox->Reset();      
       
   519     }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CMCETestUIVideoStreamViewContainer::SizeChanged()
       
   523 // Called by framework when the view size is changed
       
   524 // -----------------------------------------------------------------------------
       
   525 //
       
   526 void CMCETestUIVideoStreamViewContainer::SizeChanged()
       
   527     {
       
   528     TInt error;
       
   529     
       
   530     // TRAP methods that can leave.
       
   531     TRAP(error, SizeChangedL());
       
   532     if(error != KErrNone)
       
   533         {
       
   534         User::Panic( KNullDesC16, 0 );
       
   535         }   
       
   536     }
       
   537 
       
   538 // -----------------------------------------------------------------------------
       
   539 // CMCETestUISessionViewContainer::SizeChangedL()
       
   540 // Methods that can leave and are needed by SizeChanged
       
   541 // are collected into this method.
       
   542 // -----------------------------------------------------------------------------
       
   543 //
       
   544 void CMCETestUIVideoStreamViewContainer::SizeChangedL()
       
   545     {
       
   546   
       
   547     }
       
   548 
       
   549 
       
   550 // -----------------------------------------------------------------------------
       
   551 // CMCETestUIVideoStreamViewContainer::CountComponentControls() const
       
   552 // Note! Output window must be ignored.
       
   553 // -----------------------------------------------------------------------------
       
   554 //
       
   555 TInt CMCETestUIVideoStreamViewContainer::CountComponentControls() const
       
   556     {
       
   557     if ( iListBox ) 
       
   558         return 1;
       
   559     return 0;
       
   560     }
       
   561 
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CMCETestUIVideoStreamViewContainer::ComponentControl()
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 CCoeControl* CMCETestUIVideoStreamViewContainer::ComponentControl(TInt /*aIndex*/) const
       
   568     {
       
   569     return iListBox;
       
   570     }
       
   571 
       
   572 // -----------------------------------------------------------------------------
       
   573 // CMCETestUIVideoStreamViewContainer::HandleListBoxEventL()
       
   574 // -----------------------------------------------------------------------------
       
   575 //
       
   576 void CMCETestUIVideoStreamViewContainer::HandleListBoxEventL( 
       
   577                 CEikListBox* aListBox, 
       
   578                 TListBoxEvent aEventType )
       
   579     {
       
   580     TInt selectedIndex = iListBox->CurrentItemIndex();
       
   581     iContextMenuAlreadyShown = EFalse;
       
   582     
       
   583     if ( aListBox == iListBox )
       
   584         {
       
   585         if ( aEventType == EEventEnterKeyPressed || aEventType == EEventItemDoubleClicked )
       
   586             {
       
   587             if ( iListBoxModel->IsVideoSourceSelected( selectedIndex ) )
       
   588                 {
       
   589                 // Change to manager view 
       
   590                    const RPointerArray<CMCETestUIEngineVideoSource>& sources = 
       
   591             										iStream.SourcesL();
       
   592             	if(sources[selectedIndex]->Type() == KMceCameraSource)
       
   593             		{
       
   594             		CCreateCameraSourceDialog* dialog = new ( ELeave )
       
   595                 					 CCreateCameraSourceDialog(iStream, selectedIndex );
       
   596     				if (dialog->ExecuteLD( R_MCE_STREAM_CAMERASOURCE_DIALOG ) == EAknSoftkeyOk)
       
   597 	    				{
       
   598 	    				iContextMenuAlreadyShown = ETrue;
       
   599 	    				}
       
   600             		}
       
   601             	else if(sources[selectedIndex]->Type() == KMceFileSource)
       
   602             		{
       
   603             		CCreateVideoFileSourceDialog* dialog = new ( ELeave )
       
   604                 					 CCreateVideoFileSourceDialog(iStream, selectedIndex );
       
   605     				if (dialog->ExecuteLD( R_MCE_STREAM_FILESOURCE_VIDEO_DIALOG ) == EAknSoftkeyOk)
       
   606 	    				{
       
   607 	    				iContextMenuAlreadyShown = ETrue;
       
   608 	    				}
       
   609             		}    
       
   610                 }
       
   611             else if ( iListBoxModel->SelectedVideoSinkIndex(selectedIndex) >= 0 )
       
   612                 {
       
   613                 const RPointerArray<CMCETestUIEngineVideoSink>& sinks = 
       
   614             										iStream.SinksL();
       
   615             	if(sinks[iListBoxModel->SelectedVideoSinkIndex(selectedIndex)]->Type() == KMceSpeakerSink)
       
   616                 	{
       
   617                 /*	CCreateSpeakerSinkDialog* dialog = new ( ELeave )
       
   618                 					 CCreateSpeakerSinkDialog(iStream, iListBoxModel->SelectedAudioSinkIndex(selectedIndex) );
       
   619     				if (dialog->ExecuteLD( R_MCE_STREAM_SPEAKERSINK_DIALOG ) == EAknSoftkeyOk)
       
   620 	    				{
       
   621 	    				iContextMenuAlreadyShown = ETrue;
       
   622 	    				}*/
       
   623                 	}
       
   624                 else if((sinks[iListBoxModel->SelectedVideoSinkIndex(selectedIndex)]->Type() == KMceDisplaySink))
       
   625                 	{
       
   626                 	CCreateDisplaySinkDialog* dialog = new ( ELeave )
       
   627                 					 CCreateDisplaySinkDialog(iStream, iListBoxModel->SelectedVideoSinkIndex(selectedIndex) );
       
   628     				if (dialog->ExecuteLD( R_MCE_STREAM_DISPLAYSINK_VIDEO_DIALOG ) == EAknSoftkeyOk)
       
   629 	    				{
       
   630 	    				iContextMenuAlreadyShown = ETrue;
       
   631 	    				}
       
   632                 	}
       
   633           
       
   634                 }
       
   635             else if ( iListBoxModel->SelectedVideoCodecIndex(selectedIndex) >= 0 )
       
   636                 {
       
   637                 CCreateVideoCodecDialog* dialog = new ( ELeave )
       
   638                 					 CCreateVideoCodecDialog(iStream, iListBoxModel->SelectedVideoCodecIndex(selectedIndex) );
       
   639     			if (dialog->ExecuteLD( R_MCE_STREAM_VIDEOCODEC_DIALOG ) == EAknSoftkeyOk)
       
   640     				{
       
   641     				iContextMenuAlreadyShown = ETrue;
       
   642     				}
       
   643                 }
       
   644                 
       
   645             // TODO: Add changes to event and refer views
       
   646             }
       
   647         }
       
   648    }
       
   649 
       
   650 
       
   651 // -----------------------------------------------------------------------------
       
   652 // CMCETestUIVideoStreamViewContainer::Draw(const TRect& aRect) const
       
   653 // -----------------------------------------------------------------------------
       
   654 //
       
   655 void CMCETestUIVideoStreamViewContainer::Draw(const TRect& aRect ) const
       
   656 {
       
   657     CWindowGc& gc = SystemGc();
       
   658     gc.Clear( aRect );    
       
   659 }
       
   660 
       
   661 
       
   662 // -----------------------------------------------------------------------------
       
   663 // CMCETestUISessionViewContainer::HandleControlEventL(
       
   664 //     CCoeControl* aControl,TCoeEvent aEventType)
       
   665 // -----------------------------------------------------------------------------
       
   666 //
       
   667 void CMCETestUIVideoStreamViewContainer::HandleControlEventL(
       
   668         CCoeControl* /*aControl*/,
       
   669         TCoeEvent /*aEventType*/)
       
   670 {
       
   671     // TODO: Add your control event handler code here
       
   672 }
       
   673 
       
   674 
       
   675 // -----------------------------------------------------------------------------
       
   676 // CMCETestUIVideoStreamViewContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
   677 //                                    TEventCode aType)
       
   678 // Handle key event. Only up and down key arrow events are
       
   679 // consumed in order to enable scrolling in output window.
       
   680 // -----------------------------------------------------------------------------
       
   681 //
       
   682 TKeyResponse CMCETestUIVideoStreamViewContainer::OfferKeyEventL(
       
   683         const TKeyEvent& aKeyEvent,
       
   684         TEventCode aType)
       
   685     {    
       
   686     if ( aType == EEventKeyUp )
       
   687         {
       
   688         
       
   689         if ( aKeyEvent.iCode == 0 && aKeyEvent.iScanCode == 164 ) // EAknSoftkeyOptions?
       
   690             {
       
   691             DoShowMenuL();
       
   692             
       
   693             return EKeyWasConsumed;
       
   694             }
       
   695         }
       
   696     return iListBox->OfferKeyEventL( aKeyEvent, aType );   
       
   697     }
       
   698 
       
   699 // -----------------------------------------------------------------------------
       
   700 // 
       
   701 // -----------------------------------------------------------------------------
       
   702 //
       
   703 void CMCETestUIVideoStreamViewContainer::DoShowMenuL()
       
   704     {
       
   705     if ( iContextMenuAlreadyShown )
       
   706         {
       
   707         iContextMenuAlreadyShown = EFalse;
       
   708         return;
       
   709         }
       
   710         
       
   711     // Get command provider
       
   712     MMCETestUIEngineCmdProvider& cmdProvider = 
       
   713         iListBoxModel->CmdProvider( iListBox->CurrentItemIndex() );
       
   714     
       
   715     // Get commands    
       
   716     const RPointerArray<TMCETestUIEngineCmdBase>& commands = 
       
   717         cmdProvider.GetCommandsL();
       
   718         
       
   719     if(commands.Count() == 0)
       
   720         {
       
   721         return;    
       
   722         }
       
   723       
       
   724     
       
   725     // Generate list
       
   726     CAknSinglePopupMenuStyleListBox* listBox = 
       
   727             new (ELeave) CAknSinglePopupMenuStyleListBox;   
       
   728     CleanupStack::PushL( listBox );
       
   729     
       
   730     CAknPopupList* popup = CAknPopupList::NewL( 
       
   731             listBox, 
       
   732             R_AVKON_SOFTKEYS_MENU_LIST,
       
   733             AknPopupLayouts::EPopupSNotePopupWindow );
       
   734     CleanupStack::PushL( popup );
       
   735     popup->SetTitleL( _L("Available commands") );
       
   736     
       
   737     listBox->ConstructL( popup, 
       
   738         EAknListBoxSelectionList | EAknListBoxLoopScrolling);
       
   739     
       
   740     listBox->CreateScrollBarFrameL( ETrue );
       
   741     listBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   742         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   743     
       
   744     CDesCArray* array = new (ELeave) CDesCArrayFlat( 1 );
       
   745     CleanupStack::PushL( array );
       
   746     
       
   747     for ( TInt i = 0; i < commands.Count(); ++i )
       
   748         {
       
   749         TInt itemLength = commands[i]->Caption().Length() + 
       
   750                           KTab().Length();
       
   751         HBufC* item = HBufC::NewLC( itemLength );
       
   752         TPtr itemPtr = item->Des();
       
   753         itemPtr.Append( commands[i]->Caption() );
       
   754         itemPtr.Append( KTab );
       
   755     
       
   756         array->AppendL( *item );
       
   757     
       
   758         CleanupStack::PopAndDestroy( item );
       
   759         item = NULL;
       
   760         }
       
   761            
       
   762     CleanupStack::Pop( array );
       
   763     listBox->Model()->SetItemTextArray( array );            
       
   764     
       
   765     CleanupStack::Pop( popup ); 
       
   766     TInt selectedCommand = -1;             
       
   767     if ( popup->ExecuteLD() )
       
   768         {
       
   769         iContextMenuAlreadyShown = ETrue;
       
   770         selectedCommand = listBox->CurrentItemIndex();
       
   771         }
       
   772     
       
   773     CleanupStack::PopAndDestroy( listBox );
       
   774     
       
   775     if ( selectedCommand != -1 )
       
   776         {
       
   777         // This will not work...
       
   778         TRAPD( err, commands[ selectedCommand ]->ExecuteL() );
       
   779         if ( err != KErrNone )
       
   780             {
       
   781             CEikonEnv* eikonEnv = CEikonEnv::Static();
       
   782             CMCETestUIAppUi* tempUiPtr = (CMCETestUIAppUi*)eikonEnv->AppUi();
       
   783             TInt errorLength = KLeaveMessage().Length() + 10;
       
   784             HBufC* error = HBufC::NewL( errorLength );
       
   785             TPtr errorPtr = error->Des();
       
   786             errorPtr.Append( KLeaveMessage );
       
   787             errorPtr.AppendNum( err );
       
   788            // User::InfoPrint( *error );
       
   789             tempUiPtr->NotifyUser(*error);
       
   790             delete error;
       
   791             }
       
   792                           
       
   793         }
       
   794     }
       
   795 
       
   796 // End of File