|
1 /* |
|
2 * Copyright (c) 2004-2006 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 "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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This class reads the resource file and provides access to the |
|
15 * information read from the resource file. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <f32file.h> |
|
22 #include <bautils.h> |
|
23 #include <barsc.h> |
|
24 #include <barsread.h> |
|
25 #include "ttspluginresourcehandler.h" |
|
26 #include <ttspluginsettings.rsg> |
|
27 |
|
28 // LOCAL CONSTANTS AND MACROS |
|
29 _LIT( KResourceFileName, "\\ttspluginsettings.rsc" ); |
|
30 _LIT( KResourceDir, "\\resource" ); |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CTtsPluginResourceHandler::CTtsPluginResourceHandler |
|
36 // C++ default constructor can NOT contain any code, that |
|
37 // might leave. |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CTtsPluginResourceHandler::CTtsPluginResourceHandler() |
|
41 { |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CTtsPluginResourceHandler::ConstructL |
|
46 // Symbian 2nd phase constructor can leave. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 void CTtsPluginResourceHandler::ConstructL( RFs& aFs ) |
|
50 { |
|
51 ReadResourceFileL( aFs ); |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CTtsPluginResourceHandler::NewL |
|
56 // Two-phased constructor. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CTtsPluginResourceHandler* CTtsPluginResourceHandler::NewL( RFs& aFs ) |
|
60 { |
|
61 CTtsPluginResourceHandler* self = new ( ELeave ) CTtsPluginResourceHandler(); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL( aFs ); |
|
64 CleanupStack::Pop( self ); |
|
65 return self; |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CTtsPluginResourceHandler::~CTtsPluginResourceHandler |
|
70 // Destructor. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CTtsPluginResourceHandler::~CTtsPluginResourceHandler() |
|
74 { |
|
75 delete iTtpGeneralFilename; |
|
76 delete iTtpLanguangeFilename; |
|
77 delete iTtpFilenamePostfix; |
|
78 delete iTtsFilename; |
|
79 delete iTtsFilenamePostfix; |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CTtsPluginResourceHandler::ReadResourceFileL |
|
84 // Reads the data from the resource file. |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 void CTtsPluginResourceHandler::ReadResourceFileL( RFs& aFs ) |
|
88 { |
|
89 // letters for drives in search order |
|
90 const TBuf<2> KResourceDrivers = _L("cz"); |
|
91 |
|
92 // load resources |
|
93 RResourceFile resourceFile; |
|
94 |
|
95 TFileName name; |
|
96 TInt i( 0 ); |
|
97 // try to find from the first driver |
|
98 name.Append( KResourceDrivers[i] ); |
|
99 name.Append( ':' ); |
|
100 name.Append( KResourceDir ); |
|
101 name.Append( KResourceFileName ); |
|
102 TBool found( EFalse ); |
|
103 |
|
104 while ( !found && i < KResourceDrivers.Length() ) |
|
105 { |
|
106 name[0] = KResourceDrivers[i++]; |
|
107 |
|
108 if ( BaflUtils::FileExists( aFs, name ) ) |
|
109 { |
|
110 // open resource |
|
111 resourceFile.OpenL( aFs, name ); |
|
112 CleanupClosePushL( resourceFile ); |
|
113 found = ETrue; |
|
114 } |
|
115 } |
|
116 |
|
117 if ( !found ) |
|
118 { |
|
119 User::Leave( KErrNotFound ); |
|
120 } |
|
121 |
|
122 HBufC8* res = resourceFile.AllocReadLC( TTSPLUGININFO ); |
|
123 |
|
124 TResourceReader theReader; |
|
125 theReader.SetBuffer( res ); |
|
126 |
|
127 iTtpGeneralFilename = theReader.ReadHBufCL(); |
|
128 iTtpLanguangeFilename = theReader.ReadHBufCL(); |
|
129 iTtpFilenamePostfix = theReader.ReadHBufCL(); |
|
130 iTtsFilename = theReader.ReadHBufCL(); |
|
131 iTtsFilenamePostfix = theReader.ReadHBufCL(); |
|
132 |
|
133 CleanupStack::PopAndDestroy( res ); |
|
134 CleanupStack::PopAndDestroy( &resourceFile ); |
|
135 } |
|
136 |
|
137 // End of File |