756
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Symbian Foundation License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: The class handles IMPS Setting file reading.
|
|
15 |
*
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include <e32std.h>
|
|
22 |
#ifdef _DEBUG
|
|
23 |
#include <flogger.h>
|
|
24 |
#endif
|
|
25 |
#include "ParserUtils.h"
|
|
26 |
|
|
27 |
// ================= MEMBER FUNCTIONS =======================
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
//**********************************
|
|
32 |
// CImpsSettingFile
|
|
33 |
//**********************************
|
|
34 |
|
|
35 |
CImpsSettingFile* CImpsSettingFile::NewL(
|
|
36 |
RFs& aFs )
|
|
37 |
{
|
|
38 |
CImpsSettingFile* self = new ( ELeave ) CImpsSettingFile( aFs );
|
|
39 |
return self;
|
|
40 |
}
|
|
41 |
|
|
42 |
CImpsSettingFile::~CImpsSettingFile()
|
|
43 |
{
|
|
44 |
if ( iOpen )
|
|
45 |
{
|
|
46 |
iReader.Close();
|
|
47 |
}
|
|
48 |
iOpen = EFalse;
|
|
49 |
}
|
|
50 |
|
|
51 |
CImpsSettingFile::CImpsSettingFile( RFs& aFs )
|
|
52 |
: iFs( aFs ),
|
|
53 |
iOpen( EFalse )
|
|
54 |
{
|
|
55 |
|
|
56 |
}
|
|
57 |
|
|
58 |
void CImpsSettingFile::OpenL( TDesC& aResFile )
|
|
59 |
{
|
|
60 |
// open a file
|
|
61 |
iFileName = aResFile;
|
|
62 |
|
|
63 |
TInt myError = iReader.Open( iFs,
|
|
64 |
iFileName,
|
|
65 |
EFileShareReadersOnly );
|
|
66 |
|
|
67 |
User::LeaveIfError( myError );
|
|
68 |
iOpen = ETrue;
|
|
69 |
|
|
70 |
}
|
|
71 |
|
|
72 |
TPtrC8 CImpsSettingFile::KeyValueL( const TDesC8& aKey )
|
|
73 |
{
|
|
74 |
|
|
75 |
TPtrC8 myKey;
|
|
76 |
TPtrC8 myValue;
|
|
77 |
TBool getIt( EFalse );
|
|
78 |
TInt err = 0;
|
|
79 |
|
|
80 |
// Reset the reader
|
|
81 |
OpenL( iFileName );
|
|
82 |
|
|
83 |
// Start to search
|
|
84 |
while ( !getIt )
|
|
85 |
{
|
|
86 |
TRAP ( err, ReadRowL( myKey, myValue ) );
|
|
87 |
if ( err != KErrNone )
|
|
88 |
{
|
|
89 |
User::Leave( KErrNotFound );
|
|
90 |
}
|
|
91 |
if ( !myKey.CompareF( aKey ) )
|
|
92 |
{
|
|
93 |
return myValue;
|
|
94 |
}
|
|
95 |
}
|
|
96 |
return TPtrC8();
|
|
97 |
}
|
|
98 |
|
|
99 |
void CImpsSettingFile::ReadRowL( TPtrC8& aKey, TPtrC8& aValue )
|
|
100 |
{
|
|
101 |
// READ ONE ROW
|
|
102 |
TChar delim( 10 );
|
|
103 |
iReader.ReadL( iRowBuffer, delim );
|
|
104 |
TInt length = iRowBuffer.Length();
|
|
105 |
if ( length > 2 )
|
|
106 |
{
|
|
107 |
// DROP CR+LF FROM THE END OF LINE
|
|
108 |
iRowBuffer.Delete( length - 2, 2 );
|
|
109 |
|
|
110 |
TInt pos = 0;
|
|
111 |
pos = iRowBuffer.Find( _L8( "=" ) );
|
|
112 |
if ( pos > 0 )
|
|
113 |
{
|
|
114 |
aKey.Set( iRowBuffer.Left( pos ) );
|
|
115 |
// Cut off separator
|
|
116 |
aValue.Set( iRowBuffer.Mid( pos + 1 ) );
|
|
117 |
}
|
|
118 |
}
|
|
119 |
}
|
|
120 |
|
|
121 |
// End of File
|
|
122 |
|