os/mm/mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteapp/src/MVSConfigVideoFormatDialog.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Part of the MVS Application for TechView
    15 //
    16 
    17 #include "MVSConfigVideoFormatDialog.h"
    18 #include "MVSApp.hrh"
    19 #include <badesca.h>
    20 
    21 #include "MVSAppUI.h" 
    22 
    23 void CMVSConfigVideoFormatDialog::SetupDialogLD(CMVSAppUi* aAppUi,TUid aControllerId,CSettingsManager* aSettingsManager)
    24 	{
    25 	CMVSConfigVideoFormatDialog* dialog = new (ELeave) CMVSConfigVideoFormatDialog(aAppUi,aControllerId); 
    26     CleanupStack::PushL(dialog);
    27     dialog->ConstructL();
    28     aSettingsManager->ReadVideoDataL(dialog,aControllerId);
    29     CleanupStack::Pop(dialog);
    30     dialog->ExecuteLD(R_MVS_DIALOG_VIDEOPLUGINS);
    31     }
    32 
    33 
    34 void CMVSConfigVideoFormatDialog::ConstructL() 
    35 	{
    36 	iMimeTypeArray = new(ELeave) CDesC8ArrayFlat(8);
    37 	iArrFrameRate = new(ELeave) CDesCArrayFlat(8);	
    38 	iArrFrameSize = new(ELeave) CDesCArrayFlat(8);
    39 	iArrVideoMimeType = new(ELeave) CDesCArrayFlat(8);	
    40  	}
    41 
    42 void CMVSConfigVideoFormatDialog::PreLayoutDynInitL()
    43     {
    44    	CEikChoiceList* frameRateCtl = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectVideoFrameRate));	
    45 	 
    46 	CEikChoiceList* frameSizeCtl = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectVideoFrameSize));	
    47 	
    48 	CEikChoiceList* mimeTypeCtl = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectVideoMimeCodec));	
    49 		  		
    50     CEikCheckBox* restoresettings = static_cast<CEikCheckBox*>(Control(EMVSRestoreVideoSettings));	
    51     
    52     CEikCheckBox* audioenable = static_cast<CEikCheckBox*>(Control(EMVSEnableAudio));	
    53     
    54     TBuf<10> td;
    55     TBuf<20> sd;
    56  	TInt err = 0;
    57 	CDesCArray*	tempArray = NULL;
    58 	if(frameRateCtl)
    59 		{
    60 		frameRateCtl->SetArrayL(iArrFrameRate);
    61 		frameRateCtl->SetArrayExternalOwnership(ETrue);
    62 		tempArray = frameRateCtl->DesCArray(); 	   		
    63 		//get supported frame rates
    64 		TRAP(err,iAppUi->GetSupportedFrameRatesL(iFrameRateArray));	
    65 		if(err == KErrNotSupported)	
    66 			{
    67 			_LIT(KFrameRateSupport, "Frame Rates not supported");
    68 			User::InfoPrint(KFrameRateSupport);			
    69 			iFrameRateIdx = -1;
    70 			}
    71 		else
    72 			{
    73 			//copy from array to  CDescCArray 
    74 		    iFrameRateIdx = 0;
    75 		    for(TInt i = 0; i < iFrameRateArray.Count();i++) 
    76 			    {
    77 				td.Num(iFrameRateArray[i]);
    78 				tempArray->AppendL(td);
    79 			    }
    80 			}	
    81 		}
    82 		
    83 	if(frameSizeCtl)
    84 	    {
    85 	    _LIT(comma,",");
    86 	    frameSizeCtl->SetArrayL(iArrFrameSize);
    87 	    frameSizeCtl->SetArrayExternalOwnership(ETrue);
    88 	    tempArray = frameSizeCtl->DesCArray();
    89 		//get supported sample rates
    90 		TRAP(err,iAppUi->GetSupportedFrameSizeArrayL(iFrameSizeArray));
    91 		if(err == KErrNotSupported)
    92 			{
    93 			_LIT(KSampleRateSupport, "Sample rates not supported");
    94 			User::InfoPrint(KSampleRateSupport);			
    95 			iFrameSizeIdx = -1;
    96 			}
    97 		else
    98 			{
    99 			//copy from array to  CDescCArray
   100 			iFrameSizeIdx = 0; 
   101 		    for(TInt i = 0; i < iFrameSizeArray.Count();i++) 
   102 		    	{
   103 		    	//code to append both TWidth and THeight into single cell of the Array
   104 		    	TSize temp=iFrameSizeArray[i];
   105 		    	TInt width=temp.iWidth;
   106 		    	TInt height=temp.iHeight;
   107 		    	td.Num(width);
   108 		    	TInt8 size=td.Length()+1;
   109 		    	sd.Insert(0,td);
   110 		    	sd.Append(comma);
   111 		    	td.Num(height);
   112 		    	sd.Append(td);
   113 		    	tempArray->AppendL(sd);
   114 		    	td.Delete(0,size+5);//the Delete()function adjusts this value to ensure that no data
   115 		    	sd.Delete(0,size+5);//beyond the end of the descriptor data area is deleted.
   116 		     	}
   117 			}	
   118 	    }
   119 	    
   120     if(mimeTypeCtl)
   121 		{
   122 	  	//get supported frame rates
   123 		mimeTypeCtl->SetArrayL(iArrVideoMimeType);
   124 		mimeTypeCtl->SetArrayExternalOwnership(ETrue);
   125 		TRAP(err,iAppUi->GetSupportedVideoTypesL(*iMimeTypeArray));	
   126 		TInt counter=iMimeTypeArray->Count();
   127 		for(TInt i=0; i<counter; i++)
   128 			{
   129 			TBuf16<16> temp;
   130 			temp.Copy(iMimeTypeArray->MdcaPoint(i)); 		
   131 			iArrVideoMimeType->AppendL(temp);
   132 			}
   133 		if(err == KErrNotSupported)	
   134 			{
   135 			_LIT(KFrameRateSupport, "Frame Rates not supported");
   136 			User::InfoPrint(KFrameRateSupport);			
   137 			}
   138 		}
   139 
   140     if(restoresettings)
   141     	{
   142     	iSettings = restoresettings;
   143     	restoresettings->SetObserver(this);	
   144     	}
   145     if(audioenable)
   146     	{
   147     	iAudioEnableCtl = audioenable;
   148     	iAudioEnable = EFalse;
   149     	audioenable->SetObserver(this);
   150     	}
   151     }
   152 
   153 
   154 CMVSConfigVideoFormatDialog::CMVSConfigVideoFormatDialog(CMVSAppUi* aAppUi,TUid aControllerId)
   155 	:iContollerUid(aControllerId) , iAppUi(aAppUi)
   156     {
   157     } 
   158 
   159 
   160 TKeyResponse CMVSConfigVideoFormatDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
   161 	{
   162 	if(aKeyEvent.iCode == EKeyEnter && aType == EEventKeyDown)
   163 		{
   164 		OkToExitL(EMVSButtonUpdate);
   165 		}
   166 	return CEikDialog::OfferKeyEventL(aKeyEvent,aType);
   167 	}
   168 
   169 
   170 TBool CMVSConfigVideoFormatDialog::OkToExitL(TInt aButtonId)
   171     {
   172     if(aButtonId == EMVSButtonCancel)
   173     	{
   174     	return ETrue;
   175     	}   
   176     CEikChoiceList* frameRateCtl = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectVideoFrameRate));	
   177 	 
   178 	CEikChoiceList* frameSizeCtl = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectVideoFrameSize));
   179 	
   180 	CEikChoiceList* mimeTypeCtl = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectVideoMimeCodec));
   181 
   182 	if(frameRateCtl && frameSizeCtl && mimeTypeCtl)
   183 		{
   184 		if(iFrameRateIdx != -1)
   185 			{
   186 			iFrameRateIdx = frameRateCtl->CurrentItem();	
   187 			}
   188 		if(iFrameSizeIdx != -1)
   189 			{
   190 			iFrameSizeIdx = frameSizeCtl->CurrentItem();	
   191 			}
   192 	    iMimeTypeIdx = mimeTypeCtl->CurrentItem();
   193 		iAppUi->WriteVideoDataL(this,iContollerUid);	
   194 		}
   195 	if(aButtonId == EMVSButtonUpdate)
   196 		{
   197 		if(iFrameRateIdx >= 0)
   198 			{
   199 		 	iAppUi->SetVideoFrameRateL(iFrameRateArray[iFrameRateIdx]);	
   200 		 	}
   201 		if(iFrameSizeIdx >= 0) 	 
   202 			{
   203 		 	iAppUi->SetVideoFrameSizeL(iFrameSizeArray[iFrameSizeIdx]);	
   204 		 	}
   205 		if(iAudioEnable)
   206 			{
   207 			iAppUi->SetAudioEnabledL(iAudioEnable);
   208 			}
   209 		if(iMimeTypeIdx)
   210 			{
   211 			iAppUi->SetVideoTypeL((*iMimeTypeArray)[iMimeTypeIdx]);
   212 			}
   213 		}
   214 	return ETrue;
   215     }
   216 
   217 
   218 void CMVSConfigVideoFormatDialog::InternalizeL(RReadStream& aStream)
   219 	{
   220 	iFrameRateIdx = aStream.ReadInt8L();
   221     iFrameSizeIdx = aStream.ReadInt8L();
   222 	}
   223 
   224 
   225 void CMVSConfigVideoFormatDialog::ExternalizeL(RWriteStream& aStream)
   226 	{
   227 	aStream.WriteInt8L(iFrameRateIdx);
   228 	aStream.WriteInt8L(iFrameSizeIdx);	
   229 	}
   230 
   231 void CMVSConfigVideoFormatDialog::HandleControlEventL(CCoeControl *aControl, TCoeEvent aEventType)
   232 	{
   233 	CEikChoiceList* frameRateCtl = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectVideoFrameRate));	
   234 	 
   235 	CEikChoiceList* frameSizeCtl = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectVideoFrameSize));	
   236 	    
   237 	CEikDialog::HandleControlEventL(aControl,aEventType);
   238 	if(frameRateCtl && frameSizeCtl)
   239 		{
   240 		if(iSettings == aControl && aEventType == EEventStateChanged)
   241 			{
   242 			if(iRestoreSettings == EFalse)
   243 				{
   244 				iRestoreSettings = ETrue;
   245 				}
   246 			else
   247 				{
   248 				iRestoreSettings = EFalse;	
   249 				}
   250 			if(iRestoreSettings)
   251 				{
   252 				if(iFrameRateIdx>0)
   253 					{
   254 					frameRateCtl->SetCurrentItem(iFrameRateIdx);
   255 					frameRateCtl->DrawDeferred();
   256 					}
   257 				if(iFrameSizeIdx>0)
   258 					{
   259 					frameSizeCtl->SetCurrentItem(iFrameSizeIdx);	
   260 					frameSizeCtl->DrawDeferred();
   261 					}
   262 				}
   263 			else
   264 				{
   265 				if(iFrameRateIdx >= 0)
   266 					{
   267 					frameRateCtl->SetCurrentItem(0);
   268 	    			frameRateCtl->DrawDeferred();
   269 					}
   270 	    	
   271 	    		if(iFrameSizeIdx >= 0)
   272 	    			{
   273 	    			frameSizeCtl->SetCurrentItem(0);	
   274 	    			frameSizeCtl->DrawDeferred();
   275 	    			}
   276 				}
   277 			return;
   278 	    	}
   279 	    if(iAudioEnableCtl == aControl && aEventType == EEventStateChanged)
   280 	    	{
   281 	    	if(iAudioEnable == EFalse)
   282 	    		{
   283 	    		iAudioEnable = ETrue;
   284 	    		}
   285 	    	else
   286 	    		{
   287 	    		iAudioEnable = EFalse;
   288 	    		}
   289 	    	return;
   290 	    	}
   291 		}
   292 	}
   293 
   294 
   295 CMVSConfigVideoFormatDialog::~CMVSConfigVideoFormatDialog()
   296 	{
   297 	iFrameRateArray.Close();
   298 	iFrameSizeArray.Close();
   299 	delete iArrFrameRate; 	  	          
   300 	delete iArrFrameSize;
   301 	delete iMimeTypeArray;
   302 	delete iArrVideoMimeType;
   303 	}