|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <bautils.h> |
|
20 #include <coemain.h> |
|
21 #include <ConeResLoader.h> |
|
22 #include <f32file.h> |
|
23 #include <data_caging_path_literals.hrh> |
|
24 |
|
25 // User includes |
|
26 #include "cradiosettingsimp.h" |
|
27 #include "cradioapplicationsettings.h" |
|
28 #include "cradioenginesettings.h" |
|
29 #include "cradiorepositorymanager.h" |
|
30 #include "radioengineutils.h" |
|
31 #include "radioengineutils.h" |
|
32 #include "cradioenginelogger.h" |
|
33 |
|
34 // The name of the radio settings resource file. |
|
35 _LIT( KRadioSettingsResourceFile, "radioenginesettings.rsc" ); |
|
36 |
|
37 // The granularity of the repository manager array. |
|
38 const TInt KRadioSettingsRepositoryManagerGranularity = 8; |
|
39 |
|
40 // ======== MEMBER FUNCTIONS ======== |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CRadioSettingsImp* CRadioSettingsImp::NewL( CCoeEnv* aCoeEnv ) |
|
47 { |
|
48 CRadioSettingsImp* self = new (ELeave) CRadioSettingsImp; |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL( aCoeEnv ); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 void CRadioSettingsImp::ConstructL( CCoeEnv* aCoeEnv ) |
|
60 { |
|
61 RadioEngineUtils::InitializeL( aCoeEnv ); |
|
62 LoadResourcesL(); |
|
63 |
|
64 iRepositoryManager = CRadioRepositoryManager::NewL( KRadioSettingsRepositoryManagerGranularity ); |
|
65 |
|
66 // Constructs the implementors of the interfaces. |
|
67 iApplicationSettings = CRadioApplicationSettings::NewL( *iRepositoryManager, *RadioEngineUtils::Env() ); |
|
68 iEngineSettings = CRadioEngineSettings::NewL( *iRepositoryManager, *RadioEngineUtils::Env() ); |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CRadioSettingsImp::CRadioSettingsImp() |
|
76 { |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 CRadioSettingsImp::~CRadioSettingsImp() |
|
84 { |
|
85 delete iApplicationSettings; |
|
86 delete iEngineSettings; |
|
87 delete iRepositoryManager; |
|
88 |
|
89 if ( iResourceLoader ) |
|
90 { |
|
91 iResourceLoader->Close(); |
|
92 } |
|
93 delete iResourceLoader; |
|
94 RadioEngineUtils::Release(); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // Determines if region is allowed. |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 TBool CRadioSettingsImp::IsRegionAllowed( TRadioRegion aRegionId ) const |
|
102 { |
|
103 return iEngineSettings->IsRegionAllowed( aRegionId ); |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // Returns the application settings interface. |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 MRadioApplicationSettings& CRadioSettingsImp::ApplicationSettings() const |
|
111 { |
|
112 return *iApplicationSettings; |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // Returns the radio settings interface. |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 MRadioEngineSettings& CRadioSettingsImp::EngineSettings() const |
|
120 { |
|
121 return *iEngineSettings; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // Returns the radio settings setter interface. |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 MRadioSettingsSetter& CRadioSettingsImp::RadioSetter() const |
|
129 { |
|
130 return *iEngineSettings; |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // Returns the underlying repository. |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 CRadioRepositoryManager& CRadioSettingsImp::Repository() const |
|
138 { |
|
139 return *iRepositoryManager; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // Static version of ResolveDriveL. |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CRadioSettingsImp::ResolveDriveL( TFileName& aFileName, const TDesC& aPath ) |
|
147 { |
|
148 LOG_FORMAT( "CRadioSettingsImp::ResolveDriveL( aFileName = %S, aPath = %S )", &aFileName, &aPath ); |
|
149 |
|
150 RFs& fsSession = RadioEngineUtils::FsSession(); |
|
151 TFileName fileName; |
|
152 TFileName baseResource; |
|
153 TFindFile finder( fsSession ); |
|
154 TLanguage language( ELangNone ); |
|
155 |
|
156 _LIT( resourceFileExt, ".rsc" ); |
|
157 _LIT( resourceFileWildExt, ".r*" ); |
|
158 |
|
159 TParsePtrC parse( aFileName ); |
|
160 TBool isResourceFile = ( parse.Ext() == resourceFileExt() ); |
|
161 |
|
162 TInt err = KErrUnknown; |
|
163 if ( isResourceFile ) |
|
164 { |
|
165 CDir* entries = NULL; |
|
166 fileName.Copy( parse.Name() ); |
|
167 fileName.Append( resourceFileWildExt() ); |
|
168 err = finder.FindWildByDir( fileName, aPath, entries ); |
|
169 delete entries; |
|
170 } |
|
171 else |
|
172 { |
|
173 // TFindFile applies search order that is from |
|
174 // drive Y to A, then Z |
|
175 err = finder.FindByDir( aFileName, aPath ); |
|
176 } |
|
177 |
|
178 LOG_FORMAT( "CRadioSettingsImp::ResolveDriveL - err = %d", err ); |
|
179 TBool found = EFalse; |
|
180 if ( !isResourceFile && err == KErrNone ) |
|
181 { |
|
182 found = ETrue; |
|
183 aFileName.Zero(); |
|
184 aFileName.Append( finder.File() ); |
|
185 } |
|
186 |
|
187 while ( !found && err == KErrNone && isResourceFile ) |
|
188 { |
|
189 // Found file |
|
190 fileName.Zero(); |
|
191 TParsePtrC foundPath( finder.File() ); |
|
192 fileName.Copy( foundPath.DriveAndPath() ); |
|
193 fileName.Append( aFileName ); |
|
194 BaflUtils::NearestLanguageFile( fsSession, fileName, language ); |
|
195 if ( language != ELangNone && BaflUtils::FileExists( fsSession, fileName ) ) |
|
196 { |
|
197 found = ETrue; |
|
198 aFileName.Zero(); |
|
199 aFileName.Copy( fileName ); |
|
200 } |
|
201 else |
|
202 { |
|
203 if ( language == ELangNone && |
|
204 !baseResource.Compare( KNullDesC ) && |
|
205 BaflUtils::FileExists( fsSession, fileName ) ) |
|
206 { |
|
207 baseResource.Copy( fileName ); |
|
208 } |
|
209 CDir* entries = NULL; |
|
210 err = finder.FindWild( entries ); |
|
211 delete entries; |
|
212 } |
|
213 } |
|
214 |
|
215 if ( !found && baseResource.Compare( KNullDesC ) ) |
|
216 { |
|
217 // If we found *.rsc then better to use that than nothing |
|
218 if ( BaflUtils::FileExists( fsSession, baseResource ) ) |
|
219 { |
|
220 found = ETrue; |
|
221 aFileName.Zero(); |
|
222 aFileName.Append( baseResource ); |
|
223 } |
|
224 } |
|
225 |
|
226 if ( !found ) |
|
227 { |
|
228 LOG_FORMAT( "CRadioSettingsImp::ResolveDriveL - File %S not found ( err = %d )!", &aFileName, err ); |
|
229 User::Leave( KErrNotFound ); |
|
230 } |
|
231 |
|
232 LOG_FORMAT( "CRadioSettingsImp::ResolveDriveL( aFileName = %S )", &aFileName ); |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------------------------- |
|
236 // Loads the required resources. |
|
237 // --------------------------------------------------------------------------- |
|
238 // |
|
239 void CRadioSettingsImp::LoadResourcesL() |
|
240 { |
|
241 // Allocated in heap only so that the resource loader header doesn't need to be |
|
242 // included in the header of this class. This is because this will be included |
|
243 // by a QT component that should not depend on CONE |
|
244 iResourceLoader = new (ELeave) RConeResourceLoader( *RadioEngineUtils::Env() ); |
|
245 |
|
246 TFileName resourceFileName; |
|
247 resourceFileName.Append( KRadioSettingsResourceFile ); |
|
248 |
|
249 ResolveDriveL( resourceFileName, KDC_RESOURCE_FILES_DIR ); |
|
250 |
|
251 iResourceLoader->OpenL( resourceFileName ); |
|
252 } |
|
253 |