Update contrib.
1 // Copyright (c) 2007-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #include <e32debug.h> //RDebug
24 #include "t_pseudoapputils.h"
26 EXPORT_C void TImportScreenConfig::VerifyFramesPerTraverse(TInt& aFramesPerTraverse, TInt aScreenPixelDimension)
28 if(aFramesPerTraverse <= 0 || aFramesPerTraverse > aScreenPixelDimension)
30 RDebug::Print(_L("Illegal FramesPerTraverse value of %d Value must be between 1 and %d inclusive\n"), aFramesPerTraverse, aScreenPixelDimension);
35 if(aScreenPixelDimension % aFramesPerTraverse)
37 RDebug::Print(_L("Dimension Divisor of %d must be a sub-multiple of the screen pixel dimension %d\n"), aFramesPerTraverse, aScreenPixelDimension);
43 EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, TPtrC& aMemberVar, CIniData* aUtils)
47 if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
49 RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
54 aMemberVar.Set(readInValue);
58 EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam, TPtrC& aMemberVar, CIniData* aUtils)
60 TBuf<KMaxUiBitmapNameLength> temp = tempStore;
61 temp.Append(aIniParam);
62 ReadIni(temp, aMemberVar, aUtils);
65 EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, TInt& aMemberVar, CIniData* aUtils)
69 if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
71 RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
76 aMemberVar = readInValue;
80 EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam, TInt& aMemberVar, CIniData* aUtils)
82 TBuf<KMaxUiBitmapNameLength> temp = tempStore;
83 temp.Append(aIniParam);
84 ReadIni(temp, aMemberVar, aUtils);
87 EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2, TInt& aMemberVar,
88 TInt aValue1, TInt aValue2, CIniData* aUtils)
92 if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
94 RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
99 if(readInValue == aIniValue1)
101 aMemberVar = aValue1;
105 if(readInValue == aIniValue2)
107 aMemberVar = aValue2;
111 RDebug::Print(_L("Invalid %s value from config file\n"), aIniParam.Ptr());
117 EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam, const TPtrC& aIniValue1,
118 const TPtrC& aIniValue2, TInt& aMemberVar, TInt aValue1,
119 TInt aValue2, CIniData* aUtils)
121 TBuf<KMaxUiBitmapNameLength> temp = tempStore;
122 temp.Append(aIniParam);
123 ReadIni(temp, aIniValue1, aIniValue2, aMemberVar, aValue1, aValue2, aUtils);
127 EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2, const TPtrC& aIniValue3,
128 TInt& aMemberVar, TInt aValue1, TInt aValue2, TInt aValue3, CIniData* aUtils)
132 if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
134 RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
139 if(readInValue == aIniValue1)
141 aMemberVar = aValue1;
145 if(readInValue == aIniValue2)
147 aMemberVar = aValue2;
151 if(readInValue == aIniValue3)
153 aMemberVar = aValue3;
157 RDebug::Print(_L("Invalid %s value from config file\n"), aIniParam.Ptr());
164 EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2,
165 const TPtrC& aIniValue3, TInt& aMemberVar, TInt aValue1, TInt aValue2,
166 TInt aValue3, CIniData* aUtils)
168 TBuf<KMaxUiBitmapNameLength> temp = tempStore;
169 temp.Append(aIniParam);
170 ReadIni(temp, aIniValue1, aIniValue2, aIniValue3, aMemberVar, aValue1, aValue2, aValue3, aUtils);
173 EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2, const TPtrC& aIniValue3,
174 const TPtrC& aIniValue4, TInt& aMemberVar, TInt aValue1, TInt aValue2,
175 TInt aValue3, TInt aValue4, CIniData* aUtils)
179 if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
181 RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
186 if(readInValue == aIniValue1)
188 aMemberVar = aValue1;
192 if(readInValue == aIniValue2)
194 aMemberVar = aValue2;
198 if(readInValue == aIniValue3)
200 aMemberVar = aValue3;
204 if(readInValue == aIniValue4)
206 aMemberVar = aValue4;
210 RDebug::Print(_L("Invalid %s value from config file\n"), aIniParam.Ptr());
218 EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2,
219 const TPtrC& aIniValue3, const TPtrC& aIniValue4, TInt& aMemberVar,
220 TInt aValue1, TInt aValue2, TInt aValue3,
221 TInt aValue4, CIniData* aUtils)
223 TBuf<KMaxUiBitmapNameLength> temp = tempStore;
224 temp.Append(aIniParam);
225 ReadIni(temp, aIniValue1, aIniValue2, aIniValue3, aIniValue4, aMemberVar, aValue1, aValue2, aValue3, aValue4, aUtils);
228 EXPORT_C void TImportScreenConfig::ReadIni(const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2, const TPtrC& aIniValue3,
229 const TPtrC& aIniValue4, const TPtrC& aIniValue5, TInt& aMemberVar, TInt aValue1,
230 TInt aValue2, TInt aValue3, TInt aValue4, TInt aValue5, CIniData* aUtils)
234 if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
236 RDebug::Print(_L("Could not read %s value from config file, aborting\n"), aIniParam.Ptr());
241 if(readInValue == aIniValue1)
243 aMemberVar = aValue1;
247 if(readInValue == aIniValue2)
249 aMemberVar = aValue2;
253 if(readInValue == aIniValue3)
255 aMemberVar = aValue3;
259 if(readInValue == aIniValue4)
261 aMemberVar = aValue4;
265 if(readInValue == aIniValue5)
267 aMemberVar = aValue5;
271 RDebug::Print(_L("Invalid %s value from config file\n"), aIniParam.Ptr());
280 EXPORT_C void TImportScreenConfig::ReadIni(const TDesC& tempStore, const TPtrC& aIniParam, const TPtrC& aIniValue1, const TPtrC& aIniValue2,
281 const TPtrC& aIniValue3, const TPtrC& aIniValue4, const TPtrC& aIniValue5, TInt& aMemberVar,
282 TInt aValue1, TInt aValue2, TInt aValue3, TInt aValue4,
283 TInt aValue5, CIniData* aUtils)
285 TBuf<KMaxUiBitmapNameLength> temp = tempStore;
286 temp.Append(aIniParam);
287 ReadIni(temp, aIniValue1, aIniValue2, aIniValue3, aIniValue4, aIniValue5, aMemberVar, aValue1, aValue2, aValue3, aValue4, aValue5, aUtils);
290 EXPORT_C TInt TImportScreenConfig::Numeral(TInt val, TInt& aDigit)
292 if( (val > 47) && (val < 58) )
294 aDigit = val - 48; //ascii to int conversion trick
299 aDigit = -1; //ascii code 45 is a minus sign
306 EXPORT_C TInt TImportScreenConfig::ExtractNumber(const TPtrC& aRectTextString, TInt& aSearchFrom, TInt& aNumber)
313 for(TInt i=aSearchFrom; i<aRectTextString.Length(); i++)
315 if(Numeral(aRectTextString[i], digit) != KErrNotFound)
333 RDebug::Print(_L("Error - cannot read value from string, spurious minus sign\n"));
338 aNumber = aNumber*10 + digit*sign;
359 EXPORT_C TInt TImportScreenConfig::ExtractRect(const TPtrC& aRectTextString, TRect& aRect, const TSize& aScreenSize)
363 TInt pointvalue[4] = {0};
365 for(TInt i=0; i<4; i++)
367 if(ExtractNumber(aRectTextString, searchFrom, number) == KErrNotFound)
369 RDebug::Print(_L("Error - cannot read rectangle dimensions from string, setting to zero size\n"));
370 aRect = TRect(0,0,0,0);
375 pointvalue[i] = number;
379 aRect = TRect(TPoint((pointvalue[0]*aScreenSize.iWidth)/100, (pointvalue[2]*aScreenSize.iHeight)/100)
380 ,TPoint((pointvalue[1]*aScreenSize.iWidth)/100, (pointvalue[3]*aScreenSize.iHeight)/100));
385 EXPORT_C TInt TImportScreenConfig::ExtractAspectRatio(const TPtrC& aRatioString, TSize& aAspectRatio)
389 TInt pointvalue[2] = {0};
391 for(TInt i=0; i<2; i++)
393 if(ExtractNumber(aRatioString, searchFrom, number) == KErrNotFound)
395 RDebug::Print(_L("Error - cannot read aspect ratio dimensions from string\n"));
400 pointvalue[i] = number;
404 aAspectRatio = TSize(pointvalue[0], pointvalue[1]);
408 EXPORT_C TInt TImportScreenConfig::ExtractPoint(const TPtrC& aPointString, TPoint& aPoint)
412 TInt pointvalue[2] = {0};
414 for(TInt i=0; i<2; i++)
416 if(ExtractNumber(aPointString, searchFrom, number) == KErrNotFound)
418 RDebug::Print(_L("Error - cannot read point dimensions from string\n"));
423 pointvalue[i] = number;
427 aPoint = TPoint(pointvalue[0], pointvalue[1]);
431 EXPORT_C TInt TImportScreenConfig::ExtractSize(const TPtrC& aSizeString, TSize& aSize)
435 TInt pointvalue[2] = {0};
437 for(TInt i=0; i<2; i++)
439 if(ExtractNumber(aSizeString, searchFrom, number) == KErrNotFound)
441 RDebug::Print(_L("Error - cannot read size dimensions from string\n"));
446 pointvalue[i] = number;
450 aSize = TSize(pointvalue[0], pointvalue[1]);
454 TInt TImportScreenConfig::ReadIniAllowMissing(const TPtrC& aIniParam, TPtrC& aMemberVar, CIniData* aUtils)
458 if(!aUtils->FindVar(KSimVideoConfigSectionName, aIniParam, readInValue))
460 RDebug::Print(_L("%s value not found in config file\n"), aIniParam.Ptr());
465 aMemberVar.Set(readInValue);
470 TBool TImportScreenConfig::GetShareSurfaceInfoL(TInt aScreenNo, TInt aWindowNo, TInt& aShareScreenNumber, TInt& aShareWindowNumber, CIniData* aUtils)
472 TBuf<KMaxUiBitmapNameLength> tempStore;
473 tempStore.Format(KScreenSurface, aScreenNo, aWindowNo);
474 tempStore.Append(_L("share_surface"));
475 TPtrC shareSurfaceString;
476 TInt res = ReadIniAllowMissing(tempStore, shareSurfaceString, aUtils);
478 if(res == KErrNotFound)
480 RDebug::Print(_L("%s value not found in config file\n"), tempStore.Ptr());
483 else if(res != KErrNone)
485 RDebug::Print(_L("Could not read %s value correctly from config file, aborting\n"), tempStore.Ptr());
489 // Format of aShareSurfaceString should be "screenX_windowY"
491 TInt ret = ExtractNumber(shareSurfaceString, searchFrom, aShareScreenNumber);
494 RDebug::Print(_L("Error - cannot read screen number from shared_surface string\n"));
498 ret = ExtractNumber(shareSurfaceString, searchFrom, aShareWindowNumber);
501 RDebug::Print(_L("Error - cannot read window number from shared_surface string\n"));
505 // Read screen number and window number correctly - surface is shared