os/mm/mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteapp/src/MVSConfigAudioFormatDialog.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 
    18 #include "MVSConfigAudioFormatDialog.h"
    19 #include "MVSApp.hrh"
    20 #include <badesca.h>
    21 
    22 
    23 #include "MVSAppUI.h" 
    24 
    25 void CMVSConfigAudioFormatDialog::SetupDialogLD(CMVSAppUi* aAppUi,TUid aControllerId,CSettingsManager* aSettingsManager)
    26 	{
    27     CMVSConfigAudioFormatDialog* dialog = new (ELeave) CMVSConfigAudioFormatDialog(aAppUi,aControllerId); 
    28     CleanupStack::PushL(dialog);
    29     dialog->ConstructL();
    30     aSettingsManager->ReadAudioDataL(dialog,aControllerId);
    31     CleanupStack::Pop(dialog);
    32     dialog->ExecuteLD(R_MVS_DIALOG_CONFIGUREDATAFORMAT);
    33     }
    34 
    35 
    36 void CMVSConfigAudioFormatDialog::ConstructL() 
    37 	{
    38 	iArrBitRates = new(ELeave) CDesCArrayFlat(8);	
    39 	iArrSampleRates = new(ELeave) CDesCArrayFlat(8);	
    40 	iArrChannels = new(ELeave) CDesCArrayFlat(8);	
    41 	iArrCodecs = new(ELeave) CDesCArrayFlat(8);	
    42 	}
    43 
    44 
    45 void CMVSConfigAudioFormatDialog::PreLayoutDynInitL()
    46 	{
    47 	// Get a downcasted pointer to each of the controls
    48 	CEikChoiceList* bitrateList = static_cast<CEikChoiceList*>(Control(EMVSSetBitrate));
    49 	 
    50 	CEikChoiceList* codecList = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectCodec));
    51 
    52 	CEikChoiceList* channelsList = static_cast<CEikChoiceList*>(Control(EMVSSetNoOfChannels));
    53 
    54 	CEikChoiceList* sampleratesList = static_cast<CEikChoiceList*>(Control(EMVSSetSamplerate));
    55     
    56     CEikCheckBox* restoresettings = static_cast<CEikCheckBox*>(Control(EMVSRestoreAudioSettings));	
    57 	iSettings = restoresettings;
    58 	TBuf<10> td;
    59 	TInt err = 0;
    60 	CDesCArray*	tempArray = NULL;
    61 	if(restoresettings)
    62 		{
    63 		restoresettings->SetObserver(this); 
    64 		}
    65 	if(bitrateList)
    66 		{
    67 		bitrateList->SetArrayL(iArrBitRates);
    68 		bitrateList->SetArrayExternalOwnership(ETrue);
    69 		tempArray = bitrateList->DesCArray(); 	   		
    70 		//get supported bit rates
    71 		TRAP(err,iAppUi->GetSupportedBitRatesL(iBitRatesArray));	
    72 		if(err == KErrNotSupported)	
    73 			{
    74 			_LIT(KBitRateSupport, "Bitrates not supported");
    75 			User::InfoPrint(KBitRateSupport);
    76 			iBitRateIdx = -1;			
    77 			}
    78 		else
    79 			{
    80 			//copy from array to  CDescCArray 
    81 		    for(TInt i = 0; i < iBitRatesArray.Count();i++) 
    82 			    {
    83 				td.Num(iBitRatesArray[i]);
    84 				tempArray->AppendL(td);
    85 			    }
    86 			}	
    87 		}
    88 	
    89     if(sampleratesList)
    90 	    {
    91 	    sampleratesList->SetArrayL(iArrSampleRates);
    92 	    sampleratesList->SetArrayExternalOwnership(ETrue);
    93 	    tempArray = sampleratesList->DesCArray();
    94 		//get supported sample rates
    95 		TRAP(err,iAppUi->GetSupportedSampleRatesArrayL(iSampleRatesArray));
    96 		if(err == KErrNotSupported)
    97 			{
    98 			_LIT(KSampleRateSupport, "Samplerates not supported");
    99 			User::InfoPrint(KSampleRateSupport);			
   100 			iSampleRateIdx = -1;
   101 			}
   102 		else
   103 			{
   104 			//copy from array to  CDescCArray 
   105 		    for(TInt i = 0; i < iSampleRatesArray.Count();i++) 
   106 		    	{
   107 		    	td.Num(iSampleRatesArray[i]);
   108 		    	tempArray->AppendL(td);
   109 		    	}
   110 			}	
   111 	    }
   112     
   113     if(channelsList)
   114 	    {
   115 	    channelsList->SetArrayL(iArrChannels);
   116 	    channelsList->SetArrayExternalOwnership(ETrue);
   117 	    tempArray = channelsList->DesCArray();
   118 	    //get supported channels 	
   119 		TRAP(err,iAppUi->GetSupportedNoChannelsArrayL(iChannelsArray));
   120 		if(err==KErrNotSupported)
   121 			{
   122 			_LIT(KChannelSupport, "Channels not supported");
   123 			User::InfoPrint(KChannelSupport);			
   124 			iChannelListIdx = -1;
   125 			}
   126 		else
   127 			{
   128 			//copy from array to  CDescCArray
   129 			for(TInt i = 0; i < iChannelsArray.Count();i++) 
   130 		    	{
   131 		    	td.Num(iChannelsArray[i]);
   132 		    	tempArray->AppendL(td);
   133 		    	}
   134 			}	
   135 	    }
   136     
   137 	if(codecList)
   138 		{
   139 		codecList->SetArrayL(iArrCodecs);	
   140 		codecList->SetArrayExternalOwnership(ETrue);
   141 		tempArray = codecList->DesCArray();
   142 		
   143 		//get supported codecs
   144 		char *pch = NULL;
   145 		TUint32 unValue;
   146 		TRAP(err,iAppUi->GetSupportedCodecsArrayL(iCodecsArray));
   147 		if(err==KErrNotSupported)
   148 			{
   149 			_LIT(KCodecSupport, "Codecs not supported");
   150 			User::InfoPrint(KCodecSupport);			
   151 			iCodecListIdx = -1;
   152 			}
   153 		else
   154 			{
   155 			tempArray->Reset();
   156 			//copy from array to  CDescCArray 
   157 		    for(TInt i = 0; i < iCodecsArray.Count(); i++)
   158 		    	{
   159 		    	unValue = iCodecsArray[i].FourCC();
   160 		    	pch =reinterpret_cast<char*>(&unValue);
   161 		    	td.Zero();
   162 		    	td.Append(pch[0]);
   163 		    	td.Append(pch[1]);
   164 		    	td.Append(pch[2]);
   165 		    	td.Append(pch[3]);
   166 		    	tempArray->AppendL(td);
   167 		    	}
   168 			}	
   169 		}
   170 	//Seed the controls with their appropriate value.
   171     if(iBitRateIdx >= 0)
   172     	{
   173     	bitrateList->SetCurrentItem(iBitRateIdx);
   174     	}
   175     if(iSampleRateIdx >= 0)
   176     	{
   177     	sampleratesList->SetCurrentItem(iSampleRateIdx);	
   178     	}
   179     if(iChannelListIdx >= 0)
   180     	{
   181     	channelsList->SetCurrentItem(iChannelListIdx);
   182     	}
   183     if(iCodecListIdx >= 0)
   184     	{
   185     	codecList->SetCurrentItem(iCodecListIdx);
   186     	}
   187     }
   188 
   189 
   190 
   191 CMVSConfigAudioFormatDialog::CMVSConfigAudioFormatDialog(CMVSAppUi* aAppUi,TUid aControllerId)
   192 	:iContollerUid(aControllerId) , iAppUi(aAppUi)
   193      {
   194      }
   195 
   196 
   197 
   198 TBool CMVSConfigAudioFormatDialog::OkToExitL(TInt aButtonId)
   199      {
   200      if(aButtonId == EMVSButtonCancel)
   201      	{
   202      	return ETrue;
   203      	}
   204 	 //the values have to go to store
   205  	 // Get a downcasted pointer to each of the controls
   206      CEikChoiceList* bitrateList = static_cast<CEikChoiceList*>(Control(EMVSSetBitrate));
   207      
   208      CEikChoiceList* codecList = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectCodec));
   209 
   210      CEikChoiceList* channelsList = static_cast<CEikChoiceList*>(Control(EMVSSetNoOfChannels));
   211 
   212      CEikChoiceList* sampleratesList = static_cast<CEikChoiceList*>(Control(EMVSSetSamplerate));
   213      
   214      if(bitrateList && codecList && channelsList && sampleratesList)
   215 	     {
   216 	     if(iBitRateIdx != -1)
   217 	     	{
   218 	     	iBitRateIdx	= bitrateList->CurrentItem();	
   219 	     	}
   220 	     if(iSampleRateIdx != -1)
   221 	     	{
   222 	     	iSampleRateIdx = sampleratesList->CurrentItem();	
   223 	     	}
   224 	     if(iChannelListIdx != -1)
   225 	     	{
   226 	     	iChannelListIdx = channelsList->CurrentItem();	
   227 	     	}
   228 	     if(iCodecListIdx != -1)
   229 	     	{
   230 	     	iCodecListIdx	= codecList->CurrentItem();	
   231 	     	}
   232 	     iAppUi->WriteAudioDataL(this,iContollerUid);
   233 	 	 if(aButtonId == EMVSButtonUpdate)
   234 		 	{
   235 		 	if(iBitRateIdx >= 0)
   236 		 		{
   237 		 	 	iAppUi->SetBitRateL(iBitRatesArray[iBitRateIdx]);	
   238 		 	 	}
   239 		 	if(iSampleRateIdx >= 0) 	 
   240 			 	{
   241 			 	iAppUi->SetSampleRateL(iSampleRatesArray[iSampleRateIdx]);	
   242 			 	}
   243 		 	if(iChannelListIdx >= 0)
   244 			 	{
   245 			 	iAppUi->SetChannelsL(iChannelsArray[iChannelListIdx]);		
   246 			 	}
   247 			if(iCodecListIdx >= 0)
   248 			 	{
   249 				iAppUi->SetCodecsL(iCodecsArray[iCodecListIdx]);			
   250 				}
   251 		 	}	
   252 	     }
   253 	 return ETrue;
   254      }
   255 
   256 
   257 TKeyResponse CMVSConfigAudioFormatDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
   258 	{
   259 	if(aKeyEvent.iCode == EKeyEnter && aType == EEventKeyDown)
   260 		{
   261 		OkToExitL(EMVSButtonUpdate);
   262 		}
   263 	return CEikDialog::OfferKeyEventL(aKeyEvent,aType);
   264 	}
   265 
   266 
   267 
   268 void CMVSConfigAudioFormatDialog::ExternalizeL(RWriteStream& aStream)
   269 	{
   270 	aStream.WriteInt8L(iBitRateIdx);
   271 	aStream.WriteInt8L(iSampleRateIdx);
   272 	aStream.WriteInt8L(iChannelListIdx);
   273 	aStream.WriteInt8L(iCodecListIdx);
   274 	}
   275 
   276 
   277 void CMVSConfigAudioFormatDialog::InternalizeL(RReadStream& aStream)
   278 	{
   279 	iBitRateIdx = aStream.ReadInt8L();
   280     iSampleRateIdx = aStream.ReadInt8L();
   281     iChannelListIdx = aStream.ReadInt8L();
   282     iCodecListIdx = aStream.ReadInt8L();
   283 	}
   284 
   285 
   286 void CMVSConfigAudioFormatDialog::HandleControlEventL(CCoeControl *aControl, TCoeEvent aEventType)
   287 	{
   288 	CEikChoiceList* bitrateList = static_cast<CEikChoiceList*>(Control(EMVSSetBitrate));
   289 	 
   290 	CEikChoiceList* codecList = static_cast<CEikChoiceList*>(Control(EMVSCmdSelectCodec));
   291 
   292 	CEikChoiceList* channelsList = static_cast<CEikChoiceList*>(Control(EMVSSetNoOfChannels));
   293 
   294 	CEikChoiceList* sampleratesList = static_cast<CEikChoiceList*>(Control(EMVSSetSamplerate));
   295     
   296 	CEikDialog::HandleControlEventL(aControl,aEventType);
   297 	if(bitrateList && codecList && channelsList && sampleratesList)
   298 		{
   299 		if(iSettings == aControl && aEventType == EEventStateChanged)
   300 			{
   301 			if(iRestoreSettings == EFalse)
   302 				{
   303 				iRestoreSettings=ETrue;
   304 				}
   305 			else
   306 				{
   307 				iRestoreSettings=EFalse;	
   308 				}
   309 			if(iRestoreSettings)
   310 				{
   311 				if(iBitRateIdx >= 0)
   312 					{
   313 					bitrateList->SetCurrentItem(iBitRateIdx);
   314 	    			bitrateList->DrawDeferred();
   315 					}
   316 	    	
   317 	    		if(iSampleRateIdx >= 0)
   318 	    			{
   319 	    			sampleratesList->SetCurrentItem(iSampleRateIdx);	
   320 	    			sampleratesList->DrawDeferred();
   321 	    			}
   322 	    		
   323 	       		if(iChannelListIdx >= 0)
   324 	       			{
   325 	       			channelsList->SetCurrentItem(iChannelListIdx);
   326 	       			channelsList->DrawDeferred();
   327 	       			}
   328 	    		
   329 	    		if(iCodecListIdx >= 0)
   330 	    			{
   331 	    			codecList->SetCurrentItem(iCodecListIdx);
   332 	    			codecList->DrawDeferred();
   333 	    			}	
   334 				}
   335 			else
   336 				{
   337 				if(iBitRateIdx >= 0)
   338 					{
   339 					bitrateList->SetCurrentItem(0);
   340 	    			bitrateList->DrawDeferred();
   341 					}
   342 	    	
   343 	    		if(iSampleRateIdx >= 0)
   344 	    			{
   345 	    			sampleratesList->SetCurrentItem(0);	
   346 	    			sampleratesList->DrawDeferred();
   347 	    			}
   348 	    		
   349 	       		if(iChannelListIdx >= 0)
   350 	       			{
   351 	       			channelsList->SetCurrentItem(0);
   352 	       			channelsList->DrawDeferred();
   353 	       			}
   354 	    		
   355 	    		if(iCodecListIdx >= 0)
   356 	    			{
   357 	    			codecList->SetCurrentItem(0);
   358 	    			codecList->DrawDeferred();
   359 	    			}
   360 				}
   361 	    	return;
   362 			}	
   363 		}
   364 	}
   365 
   366 
   367 CMVSConfigAudioFormatDialog::~CMVSConfigAudioFormatDialog()
   368 	{
   369 	iBitRatesArray.Close();
   370 	iSampleRatesArray.Close();
   371 	iChannelsArray.Close();
   372 	iCodecsArray.Close();
   373 	delete iArrSampleRates; 	  	          
   374 	delete iArrBitRates;
   375 	delete iArrChannels;
   376 	delete iArrCodecs;
   377 	}