sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: /**
sl@0:  @file
sl@0:  @test
sl@0:  @internalComponent
sl@0: */
sl@0: 
sl@0: #include <e32debug.h> //RDebug
sl@0: 
sl@0: #include "t_pseudoapputils.h"
sl@0: 
sl@0: EXPORT_C void TImportScreenConfig::VerifyFramesPerTraverse(TInt& aFramesPerTraverse, TInt aScreenPixelDimension)
sl@0: 	{
sl@0: 	if(aFramesPerTraverse <= 0 || aFramesPerTraverse > aScreenPixelDimension)
sl@0: 		{
sl@0: 		RDebug::Print(_L("Illegal FramesPerTraverse value of %d Value must be between 1 and %d inclusive\n"), aFramesPerTraverse, aScreenPixelDimension);
sl@0: 		User::Exit(0);
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		if(aScreenPixelDimension % aFramesPerTraverse)
sl@0: 			{
sl@0: 			RDebug::Print(_L("Dimension Divisor of %d must be a sub-multiple of the screen pixel dimension %d\n"), aFramesPerTraverse, aScreenPixelDimension);
sl@0: 			User::Exit(0);
sl@0: 			}
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, TPtrC& aMemberVar, CIniData* aUtils)
sl@0: 	{
sl@0: 	TPtrC readInValue;
sl@0: 
sl@0: 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
sl@0: 		{
sl@0: 		RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
sl@0: 		User::Exit(0);
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		aMemberVar.Set(readInValue);
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam, TPtrC& aMemberVar, CIniData* aUtils)
sl@0: 	{
sl@0: 	TBuf<KMaxUiBitmapNameLength> temp = tempStore;
sl@0: 	temp.Append(aIniParam);
sl@0: 	ReadIni(temp, aMemberVar, aUtils);
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, TInt& aMemberVar, CIniData* aUtils)
sl@0: 	{
sl@0: 	TInt readInValue;
sl@0: 
sl@0: 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
sl@0: 		{
sl@0: 		RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
sl@0: 		User::Exit(0);
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		aMemberVar = readInValue;
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam, TInt& aMemberVar, CIniData* aUtils)
sl@0: 	{
sl@0: 	TBuf<KMaxUiBitmapNameLength> temp = tempStore;
sl@0: 	temp.Append(aIniParam);
sl@0: 	ReadIni(temp, aMemberVar, aUtils);
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2, TInt& aMemberVar,
sl@0:                                            TInt aValue1, TInt aValue2, CIniData* aUtils)
sl@0: 	{
sl@0: 	TPtrC readInValue;
sl@0: 
sl@0: 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
sl@0: 		{
sl@0: 		RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
sl@0: 		User::Exit(0);
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		if(readInValue == aIniValue1)
sl@0: 			{
sl@0: 			aMemberVar = aValue1;
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			if(readInValue == aIniValue2)
sl@0: 				{
sl@0: 				aMemberVar = aValue2;
sl@0: 				}
sl@0: 			else
sl@0: 				{
sl@0: 				RDebug::Print(_L("Invalid %s value from config file\n"), aIniParam.Ptr());
sl@0: 				}
sl@0: 			}
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam,  const TPtrC& aIniValue1,
sl@0:                                            const TPtrC& aIniValue2, TInt& aMemberVar, TInt aValue1,
sl@0:                                            TInt aValue2, CIniData* aUtils)
sl@0: 	{
sl@0: 	TBuf<KMaxUiBitmapNameLength> temp = tempStore;
sl@0: 	temp.Append(aIniParam);
sl@0: 	ReadIni(temp, aIniValue1, aIniValue2, aMemberVar, aValue1, aValue2, aUtils);
sl@0: 	}
sl@0: 
sl@0: 
sl@0: EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam,  const TPtrC& aIniValue1, const TPtrC& aIniValue2, const TPtrC& aIniValue3,
sl@0:                                            TInt& aMemberVar, TInt aValue1, TInt aValue2, TInt aValue3, CIniData* aUtils)
sl@0: 	{
sl@0: 	TPtrC readInValue;
sl@0: 
sl@0: 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
sl@0: 		{
sl@0: 		RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
sl@0: 		User::Exit(0);
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		if(readInValue == aIniValue1)
sl@0: 			{
sl@0: 			aMemberVar = aValue1;
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			if(readInValue == aIniValue2)
sl@0: 				{
sl@0: 				aMemberVar = aValue2;
sl@0: 				}
sl@0: 			else
sl@0: 				{
sl@0: 				if(readInValue == aIniValue3)
sl@0: 					{
sl@0: 					aMemberVar = aValue3;
sl@0: 					}
sl@0: 				else
sl@0: 					{
sl@0: 					RDebug::Print(_L("Invalid %s value from config file\n"), aIniParam.Ptr());
sl@0: 					}
sl@0: 				}
sl@0: 			}
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2,
sl@0:                                            const TPtrC& aIniValue3, TInt& aMemberVar, TInt aValue1, TInt aValue2,
sl@0:                                            TInt aValue3, CIniData* aUtils)
sl@0: 	{
sl@0: 	TBuf<KMaxUiBitmapNameLength> temp = tempStore;
sl@0: 	temp.Append(aIniParam);
sl@0: 	ReadIni(temp, aIniValue1, aIniValue2, aIniValue3, aMemberVar, aValue1, aValue2, aValue3, aUtils);
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2, const TPtrC& aIniValue3,
sl@0:                                            const TPtrC& aIniValue4, TInt& aMemberVar, TInt aValue1, TInt aValue2,
sl@0:                                            TInt aValue3, TInt aValue4, CIniData* aUtils)
sl@0: 	{
sl@0: 	TPtrC readInValue;
sl@0: 
sl@0: 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
sl@0: 		{
sl@0: 		RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
sl@0: 		User::Exit(0);
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		if(readInValue == aIniValue1)
sl@0: 			{
sl@0: 			aMemberVar = aValue1;
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			if(readInValue == aIniValue2)
sl@0: 				{
sl@0: 				aMemberVar = aValue2;
sl@0: 				}
sl@0: 			else
sl@0: 				{
sl@0: 				if(readInValue == aIniValue3)
sl@0: 					{
sl@0: 					aMemberVar = aValue3;
sl@0: 					}
sl@0: 				else
sl@0: 					{
sl@0: 					if(readInValue == aIniValue4)
sl@0: 						{
sl@0: 						aMemberVar = aValue4;
sl@0: 						}
sl@0: 					else
sl@0: 						{
sl@0: 						RDebug::Print(_L("Invalid %s value from config file\n"), aIniParam.Ptr());
sl@0: 						}
sl@0: 					}
sl@0: 				}
sl@0: 			}
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam,  const TPtrC& aIniValue1, const TPtrC& aIniValue2,
sl@0:                                            const TPtrC& aIniValue3, const TPtrC& aIniValue4, TInt& aMemberVar,
sl@0:                                            TInt aValue1, TInt aValue2, TInt aValue3,
sl@0:                                            TInt aValue4, CIniData* aUtils)
sl@0: 	{
sl@0: 	TBuf<KMaxUiBitmapNameLength> temp = tempStore;
sl@0: 	temp.Append(aIniParam);
sl@0: 	ReadIni(temp, aIniValue1, aIniValue2, aIniValue3, aIniValue4, aMemberVar, aValue1, aValue2, aValue3, aValue4, aUtils);
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2, const TPtrC& aIniValue3,
sl@0:                                            const TPtrC& aIniValue4, const TPtrC& aIniValue5, TInt& aMemberVar, TInt aValue1,
sl@0:                                            TInt aValue2, TInt aValue3, TInt aValue4, TInt aValue5, CIniData* aUtils)
sl@0: 	{
sl@0: 	TPtrC readInValue;
sl@0: 
sl@0: 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
sl@0: 		{
sl@0: 		RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
sl@0: 		User::Exit(0);
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		if(readInValue == aIniValue1)
sl@0: 			{
sl@0: 			aMemberVar = aValue1;
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			if(readInValue == aIniValue2)
sl@0: 				{
sl@0: 				aMemberVar = aValue2;
sl@0: 				}
sl@0: 			else
sl@0: 				{
sl@0: 				if(readInValue == aIniValue3)
sl@0: 					{
sl@0: 					aMemberVar = aValue3;
sl@0: 					}
sl@0: 				else
sl@0: 					{
sl@0: 					if(readInValue == aIniValue4)
sl@0: 						{
sl@0: 						aMemberVar = aValue4;
sl@0: 						}
sl@0: 					else
sl@0: 						{
sl@0: 						if(readInValue == aIniValue5)
sl@0: 							{
sl@0: 							aMemberVar = aValue5;
sl@0: 							}
sl@0: 						else
sl@0: 							{
sl@0: 							RDebug::Print(_L("Invalid %s value from config file\n"), aIniParam.Ptr());
sl@0: 							}
sl@0: 						}
sl@0: 					}
sl@0: 				}
sl@0: 			}
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam,  const TPtrC& aIniValue1, const TPtrC& aIniValue2,
sl@0:                                            const TPtrC& aIniValue3, const TPtrC& aIniValue4, const TPtrC& aIniValue5, TInt& aMemberVar,
sl@0:                                            TInt aValue1, TInt aValue2, TInt aValue3, TInt aValue4,
sl@0:                                            TInt aValue5, CIniData* aUtils)
sl@0: 	{
sl@0: 	TBuf<KMaxUiBitmapNameLength> temp = tempStore;
sl@0: 	temp.Append(aIniParam);
sl@0: 	ReadIni(temp, aIniValue1, aIniValue2, aIniValue3, aIniValue4, aIniValue5, aMemberVar, aValue1, aValue2, aValue3, aValue4, aValue5, aUtils);
sl@0: 	}
sl@0: 
sl@0: EXPORT_C TInt TImportScreenConfig::Numeral(TInt val, TInt& aDigit)
sl@0: 	{
sl@0: 	if( (val > 47) && (val < 58) )
sl@0: 		{
sl@0: 		aDigit = val - 48; //ascii to int conversion trick
sl@0: 		return KErrNone;
sl@0: 		}
sl@0: 	else if(val == 45)
sl@0: 		{
sl@0: 		aDigit = -1;       //ascii code 45 is a minus sign
sl@0: 		return KErrNone;
sl@0: 		}
sl@0: 
sl@0: 	return KErrNotFound;
sl@0: 	}
sl@0: 
sl@0: EXPORT_C TInt TImportScreenConfig::ExtractNumber(const TPtrC& aRectTextString, TInt& aSearchFrom, TInt& aNumber)
sl@0: 	{
sl@0: 	TInt initFlag = 0;
sl@0: 	TInt digit;
sl@0: 	aNumber = 0;
sl@0: 	TInt sign = 1;
sl@0: 
sl@0: 	for(TInt i=aSearchFrom; i<aRectTextString.Length(); i++)
sl@0: 		{
sl@0: 		if(Numeral(aRectTextString[i], digit) != KErrNotFound)
sl@0: 			{
sl@0: 			if(initFlag == 0)
sl@0: 				{
sl@0: 				initFlag = 1;
sl@0: 				if(digit == -1)
sl@0: 					{
sl@0: 					sign = digit;
sl@0: 					}
sl@0: 				else
sl@0: 					{
sl@0: 					aNumber = digit;
sl@0: 					}
sl@0: 				}
sl@0: 			else
sl@0: 				{
sl@0: 				if(digit == -1)
sl@0: 					{
sl@0: 					RDebug::Print(_L("Error - cannot read value from string, spurious minus sign\n"));
sl@0: 					return KErrNotFound;
sl@0: 					}
sl@0: 				else
sl@0: 					{
sl@0: 					aNumber = aNumber*10 + digit*sign;
sl@0: 					}
sl@0: 				}
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			if(initFlag == 1)
sl@0: 				{
sl@0: 				aSearchFrom = i + 1;
sl@0: 				return KErrNone;
sl@0: 				}
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	if(initFlag == 1)
sl@0: 		{
sl@0: 		return KErrNone;
sl@0: 		}
sl@0: 	return KErrNotFound;
sl@0: 	}
sl@0: 
sl@0: EXPORT_C TInt TImportScreenConfig::ExtractRect(const TPtrC& aRectTextString, TRect& aRect, const TSize& aScreenSize)
sl@0: 	{
sl@0: 	TInt searchFrom = 0;
sl@0: 	TInt number = 0;
sl@0: 	TInt pointvalue[4] = {0};
sl@0: 
sl@0: 	for(TInt i=0; i<4; i++)
sl@0: 		{
sl@0: 		if(ExtractNumber(aRectTextString, searchFrom, number) == KErrNotFound)
sl@0: 			{
sl@0: 			RDebug::Print(_L("Error - cannot read rectangle dimensions from string, setting to zero size\n"));
sl@0: 			aRect = TRect(0,0,0,0);
sl@0: 			return KErrNotFound;
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			pointvalue[i] = number;
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	aRect = TRect(TPoint((pointvalue[0]*aScreenSize.iWidth)/100, (pointvalue[2]*aScreenSize.iHeight)/100)
sl@0: 	             ,TPoint((pointvalue[1]*aScreenSize.iWidth)/100, (pointvalue[3]*aScreenSize.iHeight)/100));
sl@0: 
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: EXPORT_C TInt TImportScreenConfig::ExtractAspectRatio(const TPtrC& aRatioString, TSize& aAspectRatio)
sl@0: 	{
sl@0: 	TInt searchFrom = 0;
sl@0: 	TInt number = 0;
sl@0: 	TInt pointvalue[2] = {0};
sl@0: 
sl@0: 	for(TInt i=0; i<2; i++)
sl@0: 		{
sl@0: 		if(ExtractNumber(aRatioString, searchFrom, number) == KErrNotFound)
sl@0: 			{
sl@0: 			RDebug::Print(_L("Error - cannot read aspect ratio dimensions from string\n"));
sl@0: 			return KErrNotFound;
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			pointvalue[i] = number;
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	aAspectRatio = TSize(pointvalue[0], pointvalue[1]);
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: EXPORT_C TInt TImportScreenConfig::ExtractPoint(const TPtrC& aPointString, TPoint& aPoint)
sl@0: 	{
sl@0: 	TInt searchFrom = 0;
sl@0: 	TInt number = 0;
sl@0: 	TInt pointvalue[2] = {0};
sl@0: 
sl@0: 	for(TInt i=0; i<2; i++)
sl@0: 		{
sl@0: 		if(ExtractNumber(aPointString, searchFrom, number) == KErrNotFound)
sl@0: 			{
sl@0: 			RDebug::Print(_L("Error - cannot read point dimensions from string\n"));
sl@0: 			return KErrNotFound;
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			pointvalue[i] = number;
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	aPoint = TPoint(pointvalue[0], pointvalue[1]);
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: EXPORT_C TInt TImportScreenConfig::ExtractSize(const TPtrC& aSizeString, TSize& aSize)
sl@0: 	{
sl@0: 	TInt searchFrom = 0;
sl@0: 	TInt number = 0;
sl@0: 	TInt pointvalue[2] = {0};
sl@0: 
sl@0: 	for(TInt i=0; i<2; i++)
sl@0: 		{
sl@0: 		if(ExtractNumber(aSizeString, searchFrom, number) == KErrNotFound)
sl@0: 			{
sl@0: 			RDebug::Print(_L("Error - cannot read size dimensions from string\n"));
sl@0: 			return KErrNotFound;
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			pointvalue[i] = number;
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	aSize = TSize(pointvalue[0], pointvalue[1]);
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: TInt TImportScreenConfig::ReadIniAllowMissing(const TPtrC& aIniParam, TPtrC& aMemberVar, CIniData* aUtils)
sl@0: 	{
sl@0: 	TPtrC readInValue;
sl@0: 
sl@0: 	if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
sl@0: 		{
sl@0: 		RDebug::Print(_L("%s value not found in config file\n"), aIniParam.Ptr());
sl@0: 		return KErrNotFound;
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		aMemberVar.Set(readInValue);
sl@0: 		return KErrNone;
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: TBool TImportScreenConfig::GetShareSurfaceInfoL(TInt aScreenNo, TInt aWindowNo, TInt& aShareScreenNumber, TInt& aShareWindowNumber, CIniData* aUtils)
sl@0: 	{
sl@0: 	TBuf<KMaxUiBitmapNameLength> tempStore;
sl@0: 	tempStore.Format(KScreenSurface, aScreenNo, aWindowNo);
sl@0: 	tempStore.Append(_L("share_surface"));
sl@0: 	TPtrC shareSurfaceString;
sl@0: 	TInt res = ReadIniAllowMissing(tempStore, shareSurfaceString, aUtils);
sl@0: 
sl@0: 	if(res == KErrNotFound)
sl@0: 		{
sl@0: 		RDebug::Print(_L("%s value not found in config file\n"), tempStore.Ptr());
sl@0: 		return EFalse;
sl@0: 		}
sl@0: 	else if(res != KErrNone)
sl@0: 		{
sl@0: 		RDebug::Print(_L("Could not read %s value correctly from config file, aborting\n"), tempStore.Ptr());
sl@0: 		User::Exit(0);
sl@0: 		}
sl@0: 	
sl@0: 	// Format of aShareSurfaceString should be "screenX_windowY"
sl@0: 	TInt searchFrom = 5;
sl@0: 	TInt ret = ExtractNumber(shareSurfaceString, searchFrom, aShareScreenNumber);
sl@0: 	if(KErrNone != ret)
sl@0: 		{
sl@0: 		RDebug::Print(_L("Error - cannot read screen number from shared_surface string\n"));
sl@0: 		User::Exit(0);
sl@0: 		}
sl@0: 
sl@0: 	ret = ExtractNumber(shareSurfaceString, searchFrom, aShareWindowNumber);
sl@0: 	if(KErrNone != ret)
sl@0: 		{
sl@0: 		RDebug::Print(_L("Error - cannot read window number from shared_surface string\n"));
sl@0: 		User::Exit(0);
sl@0: 		}
sl@0: 
sl@0: 	// Read screen number and window number correctly - surface is shared
sl@0: 	return ETrue;
sl@0: 	}