os/mm/mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteapp/src/MVSConfigAudioFormatDialog.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteapp/src/MVSConfigAudioFormatDialog.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,377 @@
     1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Part of the MVS Application for TechView
    1.18 +//
    1.19 +
    1.20 +
    1.21 +#include "MVSConfigAudioFormatDialog.h"
    1.22 +#include "MVSApp.hrh"
    1.23 +#include <badesca.h>
    1.24 +
    1.25 +
    1.26 +#include "MVSAppUI.h" 
    1.27 +
    1.28 +void CMVSConfigAudioFormatDialog::SetupDialogLD(CMVSAppUi* aAppUi,TUid aControllerId,CSettingsManager* aSettingsManager)
    1.29 +	{
    1.30 +    CMVSConfigAudioFormatDialog* dialog = new (ELeave) CMVSConfigAudioFormatDialog(aAppUi,aControllerId); 
    1.31 +    CleanupStack::PushL(dialog);
    1.32 +    dialog->ConstructL();
    1.33 +    aSettingsManager->ReadAudioDataL(dialog,aControllerId);
    1.34 +    CleanupStack::Pop(dialog);
    1.35 +    dialog->ExecuteLD(R_MVS_DIALOG_CONFIGUREDATAFORMAT);
    1.36 +    }
    1.37 +
    1.38 +
    1.39 +void CMVSConfigAudioFormatDialog::ConstructL() 
    1.40 +	{
    1.41 +	iArrBitRates = new(ELeave) CDesCArrayFlat(8);	
    1.42 +	iArrSampleRates = new(ELeave) CDesCArrayFlat(8);	
    1.43 +	iArrChannels = new(ELeave) CDesCArrayFlat(8);	
    1.44 +	iArrCodecs = new(ELeave) CDesCArrayFlat(8);	
    1.45 +	}
    1.46 +
    1.47 +
    1.48 +void CMVSConfigAudioFormatDialog::PreLayoutDynInitL()
    1.49 +	{
    1.50 +	// Get a downcasted pointer to each of the controls
    1.51 +	CEikChoiceList* bitrateList = static_cast<CEikChoiceList*>(Control(EMVSSetBitrate));
    1.52 +	 
    1.53 +	CEikChoiceList* codecList = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectCodec));
    1.54 +
    1.55 +	CEikChoiceList* channelsList = static_cast<CEikChoiceList*>(Control(EMVSSetNoOfChannels));
    1.56 +
    1.57 +	CEikChoiceList* sampleratesList = static_cast<CEikChoiceList*>(Control(EMVSSetSamplerate));
    1.58 +    
    1.59 +    CEikCheckBox* restoresettings = static_cast<CEikCheckBox*>(Control(EMVSRestoreAudioSettings));	
    1.60 +	iSettings = restoresettings;
    1.61 +	TBuf<10> td;
    1.62 +	TInt err = 0;
    1.63 +	CDesCArray*	tempArray = NULL;
    1.64 +	if(restoresettings)
    1.65 +		{
    1.66 +		restoresettings->SetObserver(this); 
    1.67 +		}
    1.68 +	if(bitrateList)
    1.69 +		{
    1.70 +		bitrateList->SetArrayL(iArrBitRates);
    1.71 +		bitrateList->SetArrayExternalOwnership(ETrue);
    1.72 +		tempArray = bitrateList->DesCArray(); 	   		
    1.73 +		//get supported bit rates
    1.74 +		TRAP(err,iAppUi->GetSupportedBitRatesL(iBitRatesArray));	
    1.75 +		if(err == KErrNotSupported)	
    1.76 +			{
    1.77 +			_LIT(KBitRateSupport, "Bitrates not supported");
    1.78 +			User::InfoPrint(KBitRateSupport);
    1.79 +			iBitRateIdx = -1;			
    1.80 +			}
    1.81 +		else
    1.82 +			{
    1.83 +			//copy from array to  CDescCArray 
    1.84 +		    for(TInt i = 0; i < iBitRatesArray.Count();i++) 
    1.85 +			    {
    1.86 +				td.Num(iBitRatesArray[i]);
    1.87 +				tempArray->AppendL(td);
    1.88 +			    }
    1.89 +			}	
    1.90 +		}
    1.91 +	
    1.92 +    if(sampleratesList)
    1.93 +	    {
    1.94 +	    sampleratesList->SetArrayL(iArrSampleRates);
    1.95 +	    sampleratesList->SetArrayExternalOwnership(ETrue);
    1.96 +	    tempArray = sampleratesList->DesCArray();
    1.97 +		//get supported sample rates
    1.98 +		TRAP(err,iAppUi->GetSupportedSampleRatesArrayL(iSampleRatesArray));
    1.99 +		if(err == KErrNotSupported)
   1.100 +			{
   1.101 +			_LIT(KSampleRateSupport, "Samplerates not supported");
   1.102 +			User::InfoPrint(KSampleRateSupport);			
   1.103 +			iSampleRateIdx = -1;
   1.104 +			}
   1.105 +		else
   1.106 +			{
   1.107 +			//copy from array to  CDescCArray 
   1.108 +		    for(TInt i = 0; i < iSampleRatesArray.Count();i++) 
   1.109 +		    	{
   1.110 +		    	td.Num(iSampleRatesArray[i]);
   1.111 +		    	tempArray->AppendL(td);
   1.112 +		    	}
   1.113 +			}	
   1.114 +	    }
   1.115 +    
   1.116 +    if(channelsList)
   1.117 +	    {
   1.118 +	    channelsList->SetArrayL(iArrChannels);
   1.119 +	    channelsList->SetArrayExternalOwnership(ETrue);
   1.120 +	    tempArray = channelsList->DesCArray();
   1.121 +	    //get supported channels 	
   1.122 +		TRAP(err,iAppUi->GetSupportedNoChannelsArrayL(iChannelsArray));
   1.123 +		if(err==KErrNotSupported)
   1.124 +			{
   1.125 +			_LIT(KChannelSupport, "Channels not supported");
   1.126 +			User::InfoPrint(KChannelSupport);			
   1.127 +			iChannelListIdx = -1;
   1.128 +			}
   1.129 +		else
   1.130 +			{
   1.131 +			//copy from array to  CDescCArray
   1.132 +			for(TInt i = 0; i < iChannelsArray.Count();i++) 
   1.133 +		    	{
   1.134 +		    	td.Num(iChannelsArray[i]);
   1.135 +		    	tempArray->AppendL(td);
   1.136 +		    	}
   1.137 +			}	
   1.138 +	    }
   1.139 +    
   1.140 +	if(codecList)
   1.141 +		{
   1.142 +		codecList->SetArrayL(iArrCodecs);	
   1.143 +		codecList->SetArrayExternalOwnership(ETrue);
   1.144 +		tempArray = codecList->DesCArray();
   1.145 +		
   1.146 +		//get supported codecs
   1.147 +		char *pch = NULL;
   1.148 +		TUint32 unValue;
   1.149 +		TRAP(err,iAppUi->GetSupportedCodecsArrayL(iCodecsArray));
   1.150 +		if(err==KErrNotSupported)
   1.151 +			{
   1.152 +			_LIT(KCodecSupport, "Codecs not supported");
   1.153 +			User::InfoPrint(KCodecSupport);			
   1.154 +			iCodecListIdx = -1;
   1.155 +			}
   1.156 +		else
   1.157 +			{
   1.158 +			tempArray->Reset();
   1.159 +			//copy from array to  CDescCArray 
   1.160 +		    for(TInt i = 0; i < iCodecsArray.Count(); i++)
   1.161 +		    	{
   1.162 +		    	unValue = iCodecsArray[i].FourCC();
   1.163 +		    	pch =reinterpret_cast<char*>(&unValue);
   1.164 +		    	td.Zero();
   1.165 +		    	td.Append(pch[0]);
   1.166 +		    	td.Append(pch[1]);
   1.167 +		    	td.Append(pch[2]);
   1.168 +		    	td.Append(pch[3]);
   1.169 +		    	tempArray->AppendL(td);
   1.170 +		    	}
   1.171 +			}	
   1.172 +		}
   1.173 +	//Seed the controls with their appropriate value.
   1.174 +    if(iBitRateIdx >= 0)
   1.175 +    	{
   1.176 +    	bitrateList->SetCurrentItem(iBitRateIdx);
   1.177 +    	}
   1.178 +    if(iSampleRateIdx >= 0)
   1.179 +    	{
   1.180 +    	sampleratesList->SetCurrentItem(iSampleRateIdx);	
   1.181 +    	}
   1.182 +    if(iChannelListIdx >= 0)
   1.183 +    	{
   1.184 +    	channelsList->SetCurrentItem(iChannelListIdx);
   1.185 +    	}
   1.186 +    if(iCodecListIdx >= 0)
   1.187 +    	{
   1.188 +    	codecList->SetCurrentItem(iCodecListIdx);
   1.189 +    	}
   1.190 +    }
   1.191 +
   1.192 +
   1.193 +
   1.194 +CMVSConfigAudioFormatDialog::CMVSConfigAudioFormatDialog(CMVSAppUi* aAppUi,TUid aControllerId)
   1.195 +	:iContollerUid(aControllerId) , iAppUi(aAppUi)
   1.196 +     {
   1.197 +     }
   1.198 +
   1.199 +
   1.200 +
   1.201 +TBool CMVSConfigAudioFormatDialog::OkToExitL(TInt aButtonId)
   1.202 +     {
   1.203 +     if(aButtonId == EMVSButtonCancel)
   1.204 +     	{
   1.205 +     	return ETrue;
   1.206 +     	}
   1.207 +	 //the values have to go to store
   1.208 + 	 // Get a downcasted pointer to each of the controls
   1.209 +     CEikChoiceList* bitrateList = static_cast<CEikChoiceList*>(Control(EMVSSetBitrate));
   1.210 +     
   1.211 +     CEikChoiceList* codecList = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectCodec));
   1.212 +
   1.213 +     CEikChoiceList* channelsList = static_cast<CEikChoiceList*>(Control(EMVSSetNoOfChannels));
   1.214 +
   1.215 +     CEikChoiceList* sampleratesList = static_cast<CEikChoiceList*>(Control(EMVSSetSamplerate));
   1.216 +     
   1.217 +     if(bitrateList && codecList && channelsList && sampleratesList)
   1.218 +	     {
   1.219 +	     if(iBitRateIdx != -1)
   1.220 +	     	{
   1.221 +	     	iBitRateIdx	= bitrateList->CurrentItem();	
   1.222 +	     	}
   1.223 +	     if(iSampleRateIdx != -1)
   1.224 +	     	{
   1.225 +	     	iSampleRateIdx = sampleratesList->CurrentItem();	
   1.226 +	     	}
   1.227 +	     if(iChannelListIdx != -1)
   1.228 +	     	{
   1.229 +	     	iChannelListIdx = channelsList->CurrentItem();	
   1.230 +	     	}
   1.231 +	     if(iCodecListIdx != -1)
   1.232 +	     	{
   1.233 +	     	iCodecListIdx	= codecList->CurrentItem();	
   1.234 +	     	}
   1.235 +	     iAppUi->WriteAudioDataL(this,iContollerUid);
   1.236 +	 	 if(aButtonId == EMVSButtonUpdate)
   1.237 +		 	{
   1.238 +		 	if(iBitRateIdx >= 0)
   1.239 +		 		{
   1.240 +		 	 	iAppUi->SetBitRateL(iBitRatesArray[iBitRateIdx]);	
   1.241 +		 	 	}
   1.242 +		 	if(iSampleRateIdx >= 0) 	 
   1.243 +			 	{
   1.244 +			 	iAppUi->SetSampleRateL(iSampleRatesArray[iSampleRateIdx]);	
   1.245 +			 	}
   1.246 +		 	if(iChannelListIdx >= 0)
   1.247 +			 	{
   1.248 +			 	iAppUi->SetChannelsL(iChannelsArray[iChannelListIdx]);		
   1.249 +			 	}
   1.250 +			if(iCodecListIdx >= 0)
   1.251 +			 	{
   1.252 +				iAppUi->SetCodecsL(iCodecsArray[iCodecListIdx]);			
   1.253 +				}
   1.254 +		 	}	
   1.255 +	     }
   1.256 +	 return ETrue;
   1.257 +     }
   1.258 +
   1.259 +
   1.260 +TKeyResponse CMVSConfigAudioFormatDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
   1.261 +	{
   1.262 +	if(aKeyEvent.iCode == EKeyEnter && aType == EEventKeyDown)
   1.263 +		{
   1.264 +		OkToExitL(EMVSButtonUpdate);
   1.265 +		}
   1.266 +	return CEikDialog::OfferKeyEventL(aKeyEvent,aType);
   1.267 +	}
   1.268 +
   1.269 +
   1.270 +
   1.271 +void CMVSConfigAudioFormatDialog::ExternalizeL(RWriteStream& aStream)
   1.272 +	{
   1.273 +	aStream.WriteInt8L(iBitRateIdx);
   1.274 +	aStream.WriteInt8L(iSampleRateIdx);
   1.275 +	aStream.WriteInt8L(iChannelListIdx);
   1.276 +	aStream.WriteInt8L(iCodecListIdx);
   1.277 +	}
   1.278 +
   1.279 +
   1.280 +void CMVSConfigAudioFormatDialog::InternalizeL(RReadStream& aStream)
   1.281 +	{
   1.282 +	iBitRateIdx = aStream.ReadInt8L();
   1.283 +    iSampleRateIdx = aStream.ReadInt8L();
   1.284 +    iChannelListIdx = aStream.ReadInt8L();
   1.285 +    iCodecListIdx = aStream.ReadInt8L();
   1.286 +	}
   1.287 +
   1.288 +
   1.289 +void CMVSConfigAudioFormatDialog::HandleControlEventL(CCoeControl *aControl, TCoeEvent aEventType)
   1.290 +	{
   1.291 +	CEikChoiceList* bitrateList = static_cast<CEikChoiceList*>(Control(EMVSSetBitrate));
   1.292 +	 
   1.293 +	CEikChoiceList* codecList = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectCodec));
   1.294 +
   1.295 +	CEikChoiceList* channelsList = static_cast<CEikChoiceList*>(Control(EMVSSetNoOfChannels));
   1.296 +
   1.297 +	CEikChoiceList* sampleratesList = static_cast<CEikChoiceList*>(Control(EMVSSetSamplerate));
   1.298 +    
   1.299 +	CEikDialog::HandleControlEventL(aControl,aEventType);
   1.300 +	if(bitrateList && codecList && channelsList && sampleratesList)
   1.301 +		{
   1.302 +		if(iSettings == aControl && aEventType == EEventStateChanged)
   1.303 +			{
   1.304 +			if(iRestoreSettings == EFalse)
   1.305 +				{
   1.306 +				iRestoreSettings=ETrue;
   1.307 +				}
   1.308 +			else
   1.309 +				{
   1.310 +				iRestoreSettings=EFalse;	
   1.311 +				}
   1.312 +			if(iRestoreSettings)
   1.313 +				{
   1.314 +				if(iBitRateIdx >= 0)
   1.315 +					{
   1.316 +					bitrateList->SetCurrentItem(iBitRateIdx);
   1.317 +	    			bitrateList->DrawDeferred();
   1.318 +					}
   1.319 +	    	
   1.320 +	    		if(iSampleRateIdx >= 0)
   1.321 +	    			{
   1.322 +	    			sampleratesList->SetCurrentItem(iSampleRateIdx);	
   1.323 +	    			sampleratesList->DrawDeferred();
   1.324 +	    			}
   1.325 +	    		
   1.326 +	       		if(iChannelListIdx >= 0)
   1.327 +	       			{
   1.328 +	       			channelsList->SetCurrentItem(iChannelListIdx);
   1.329 +	       			channelsList->DrawDeferred();
   1.330 +	       			}
   1.331 +	    		
   1.332 +	    		if(iCodecListIdx >= 0)
   1.333 +	    			{
   1.334 +	    			codecList->SetCurrentItem(iCodecListIdx);
   1.335 +	    			codecList->DrawDeferred();
   1.336 +	    			}	
   1.337 +				}
   1.338 +			else
   1.339 +				{
   1.340 +				if(iBitRateIdx >= 0)
   1.341 +					{
   1.342 +					bitrateList->SetCurrentItem(0);
   1.343 +	    			bitrateList->DrawDeferred();
   1.344 +					}
   1.345 +	    	
   1.346 +	    		if(iSampleRateIdx >= 0)
   1.347 +	    			{
   1.348 +	    			sampleratesList->SetCurrentItem(0);	
   1.349 +	    			sampleratesList->DrawDeferred();
   1.350 +	    			}
   1.351 +	    		
   1.352 +	       		if(iChannelListIdx >= 0)
   1.353 +	       			{
   1.354 +	       			channelsList->SetCurrentItem(0);
   1.355 +	       			channelsList->DrawDeferred();
   1.356 +	       			}
   1.357 +	    		
   1.358 +	    		if(iCodecListIdx >= 0)
   1.359 +	    			{
   1.360 +	    			codecList->SetCurrentItem(0);
   1.361 +	    			codecList->DrawDeferred();
   1.362 +	    			}
   1.363 +				}
   1.364 +	    	return;
   1.365 +			}	
   1.366 +		}
   1.367 +	}
   1.368 +
   1.369 +
   1.370 +CMVSConfigAudioFormatDialog::~CMVSConfigAudioFormatDialog()
   1.371 +	{
   1.372 +	iBitRatesArray.Close();
   1.373 +	iSampleRatesArray.Close();
   1.374 +	iChannelsArray.Close();
   1.375 +	iCodecsArray.Close();
   1.376 +	delete iArrSampleRates; 	  	          
   1.377 +	delete iArrBitRates;
   1.378 +	delete iArrChannels;
   1.379 +	delete iArrCodecs;
   1.380 +	}