libraries/ltkutils/tsrc/tsettings.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // tsettings.cpp
       
     2 // 
       
     3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include <fshell/ioutils.h>
       
    14 #include <fshell/settings.h>
       
    15 
       
    16 using namespace IoUtils;
       
    17 using namespace LtkUtils;
       
    18 
       
    19 class CCmdTSettings : public CCommandBase
       
    20 	{
       
    21 public:
       
    22 	static CCommandBase* NewLC();
       
    23 	~CCmdTSettings();
       
    24 private:
       
    25 	CCmdTSettings();
       
    26 private: // From CCommandBase.
       
    27 	virtual const TDesC& Name() const;
       
    28 	virtual const TDesC& Description() const;
       
    29 	virtual void DoRunL();
       
    30 	virtual void ArgumentsL(RCommandArgumentList& aArguments);
       
    31 	virtual void OptionsL(RCommandOptionList& aOptions);
       
    32 private:
       
    33 	enum 
       
    34 		{
       
    35 		ERead,
       
    36 		EValidate,
       
    37 		ERewrite,
       
    38 		} iTest;
       
    39 	TFileName2 iFilename;
       
    40 	
       
    41 	CIniReader* iReader;
       
    42 	CIniFile* iValidator;
       
    43 	};
       
    44 
       
    45 _LIT(KTests, "read,validate,rewrite");
       
    46 
       
    47 
       
    48 CCommandBase* CCmdTSettings::NewLC()
       
    49 	{
       
    50 	CCmdTSettings* self = new(ELeave) CCmdTSettings();
       
    51 	CleanupStack::PushL(self);
       
    52 	self->BaseConstructL();
       
    53 	return self;
       
    54 	}
       
    55 
       
    56 CCmdTSettings::~CCmdTSettings()
       
    57 	{
       
    58 	delete iReader;
       
    59 	delete iValidator;
       
    60 	}
       
    61 
       
    62 CCmdTSettings::CCmdTSettings()
       
    63 	{
       
    64 	}
       
    65 
       
    66 const TDesC& CCmdTSettings::Name() const
       
    67 	{
       
    68 	_LIT(KName, "tsettings");	
       
    69 	return KName;
       
    70 	}
       
    71 
       
    72 const TDesC& CCmdTSettings::Description() const
       
    73 	{
       
    74 	_LIT(KDescription, "Test command for LTK utils settings classes.");
       
    75 	return KDescription;
       
    76 	}
       
    77 
       
    78 void CCmdTSettings::DoRunL()
       
    79 	{
       
    80 	switch (iTest)
       
    81 		{
       
    82 	case ERead:
       
    83 		{
       
    84 		iReader = CIniReader::NewL(iFilename);
       
    85 		RPointerArray<CValue> values;
       
    86 		CleanupClosePushL(values);
       
    87 		iReader->GetValuesL(values);
       
    88 		for (TInt i=0; i<values.Count(); ++i)
       
    89 			{
       
    90 			Printf(_L("%S=%S\n"), &values[i]->Id(), &values[i]->Value());
       
    91 			}		
       
    92 		CleanupStack::PopAndDestroy(&values);
       
    93 		break;
       
    94 		}
       
    95 	case EValidate:
       
    96 		{
       
    97 		iValidator = CIniFile::NewL(iFilename);
       
    98 		RPointerArray<CValue> values;
       
    99 		CleanupClosePushL(values);
       
   100 		iValidator->GetValuesL(values);
       
   101 		for (TInt i=0; i<values.Count(); ++i)
       
   102 			{
       
   103 			Printf(_L("%S=%S\n"), &values[i]->Id(), &values[i]->Value());
       
   104 			}		
       
   105 		CleanupStack::PopAndDestroy(&values);
       
   106 		break;
       
   107 		}
       
   108 	case ERewrite:
       
   109 		{
       
   110 		iReader = CIniReader::NewL(iFilename);
       
   111 		WriteIniFileL(iFilename, *iReader);
       
   112 		break;
       
   113 		}
       
   114 		};
       
   115 	}
       
   116 
       
   117 void CCmdTSettings::ArgumentsL(RCommandArgumentList& aArguments)
       
   118 	{
       
   119 	_LIT(KTest, "test");
       
   120 	_LIT(KTestDescription, "Test to perform");
       
   121 	aArguments.AppendEnumL((TInt&)iTest, KTest, KTestDescription, KTests);
       
   122 	
       
   123 	_LIT(KIniFile, "inifile");
       
   124 	_LIT(KIniFileDescription, "The .ini file to test with");
       
   125 	aArguments.AppendFileNameL(iFilename, KIniFile, KIniFileDescription);
       
   126 	}
       
   127 
       
   128 void CCmdTSettings::OptionsL(RCommandOptionList& /*aOptions*/)
       
   129 	{
       
   130 	}
       
   131 
       
   132 
       
   133 EXE_BOILER_PLATE(CCmdTSettings)
       
   134