author | Lars Persson <lars.persson@embeddev.se> |
Wed, 31 Mar 2010 08:19:35 +0200 | |
changeset 91 | 87cb33beeae2 |
parent 2 | 29cda98b007e |
child 96 | a8538f50e2ba |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB |
|
3 |
* |
|
4 |
* All rights reserved. |
|
5 |
* This component and the accompanying materials are made available |
|
6 |
* under the terms of the License "Eclipse Public License v1.0" |
|
7 |
* which accompanies this distribution, and is available |
|
8 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 |
* |
|
10 |
* Initial Contributors: |
|
11 |
* EmbedDev AB - initial contribution. |
|
12 |
* |
|
13 |
* Contributors: |
|
14 |
* |
|
15 |
* Description: |
|
16 |
* |
|
17 |
*/ |
|
18 |
||
19 |
#include <bautils.h> |
|
20 |
#include <s32file.h> |
|
21 |
#include "SettingsEngine.h" |
|
22 |
#include "SoundEngine.h" |
|
23 |
#include "FeedEngine.h" |
|
24 |
#include "ShowEngine.h" |
|
25 |
||
26 |
const TUid KMainSettingsStoreUid = {0x1000}; |
|
27 |
const TUid KMainSettingsUid = {0x1002}; |
|
28 |
const TUid KExtraSettingsUid = {0x2001}; |
|
29 |
const TInt KMaxParseBuffer = 1024; |
|
30 |
||
31 |
CSettingsEngine::CSettingsEngine(CPodcastModel& aPodcastModel) : iPodcastModel(aPodcastModel) |
|
32 |
{ |
|
33 |
} |
|
34 |
||
35 |
CSettingsEngine::~CSettingsEngine() |
|
36 |
{ |
|
37 |
TRAP_IGNORE(SaveSettingsL()); |
|
38 |
} |
|
39 |
||
40 |
CSettingsEngine* CSettingsEngine::NewL(CPodcastModel& aPodcastModel) |
|
41 |
{ |
|
42 |
CSettingsEngine* self = new (ELeave) CSettingsEngine(aPodcastModel); |
|
43 |
CleanupStack::PushL(self); |
|
44 |
self->ConstructL(); |
|
45 |
CleanupStack::Pop(); |
|
46 |
return self; |
|
47 |
} |
|
48 |
||
49 |
void CSettingsEngine::ConstructL() |
|
50 |
{ |
|
51 |
DP("CSettingsEngine::ConstructL BEGIN"); |
|
52 |
// default values |
|
53 |
iUpdateFeedInterval = KDefaultUpdateFeedInterval; |
|
54 |
iDownloadAutomatically = EFalse; |
|
55 |
iUpdateAutomatically = EAutoUpdateOff; |
|
56 |
iMaxListItems = KDefaultMaxListItems; |
|
57 |
iIap = 0; |
|
58 |
||
59 |
// Check that our basedir exist. Create it otherwise; |
|
60 |
GetDefaultBaseDirL(iBaseDir); |
|
61 |
DP1("Base dir: %S", &iBaseDir); |
|
62 |
||
63 |
// load settings |
|
64 |
TRAPD(loadErr, LoadSettingsL()); |
|
65 |
if (loadErr != KErrNone) |
|
66 |
{ |
|
67 |
DP1("CSettingsEngine::ConstructL\tLoadSettingsL returned error=%d", loadErr); |
|
68 |
DP("CSettingsEngine::ConstructL\tUsing default settings instead"); |
|
69 |
||
70 |
TRAPD(error,SaveSettingsL()); |
|
71 |
if (error != KErrNone) |
|
72 |
{ |
|
73 |
DP1("error saving: %d", error); |
|
74 |
} |
|
75 |
} |
|
76 |
DP("CSettingsEngine::ConstructL END"); |
|
77 |
} |
|
78 |
||
79 |
void CSettingsEngine::GetDefaultBaseDirL(TDes & /*aBaseDir*/) |
|
80 |
{ |
|
81 |
CDesCArray* disks = new(ELeave) CDesCArrayFlat(10); |
|
82 |
CleanupStack::PushL(disks); |
|
83 |
||
84 |
BaflUtils::GetDiskListL(iPodcastModel.FsSession(), *disks); |
|
85 |
||
86 |
#ifdef __WINS__ |
|
87 |
iBaseDir.Copy(KPodcastDir3); |
|
88 |
CleanupStack::PopAndDestroy(disks); |
|
89 |
return; |
|
90 |
#endif |
|
91 |
||
92 |
DP1("Disks count: %u", disks->Count()); |
|
93 |
||
94 |
for (int i=0;i<disks->Count();i++) { |
|
95 |
TPtrC ptr = disks->operator[](i); |
|
96 |
DP2("Disk %u: %S", i, &ptr); |
|
97 |
} |
|
98 |
||
99 |
if (disks->Count() == 1) // if only one drive, use C: |
|
100 |
{ |
|
101 |
iBaseDir.Copy(KPodcastDir3); |
|
102 |
} |
|
103 |
else // else we use the flash drive |
|
104 |
{ |
|
105 |
iBaseDir.Copy(KPodcastDir1); |
|
106 |
DP1("Trying podcast dir '%S'", &iBaseDir); |
|
107 |
||
108 |
TRAPD(err, BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), iBaseDir)); |
|
109 |
||
110 |
if (err != KErrNone) |
|
111 |
{ |
|
112 |
DP("Leave in EnsurePathExistsL"); |
|
113 |
iBaseDir.Copy(KPodcastDir2); |
|
114 |
DP1("Trying podcast dir '%S'", &iBaseDir); |
|
115 |
TRAPD(err, BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), iBaseDir)); |
|
116 |
if (err != KErrNone) |
|
117 |
{ |
|
118 |
DP("Leave in EnsurePathExistsL"); |
|
119 |
iBaseDir.Copy(KPodcastDir3); |
|
120 |
DP1("Trying podcast dir '%S'", &iBaseDir); |
|
121 |
TRAPD(err, BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), iBaseDir)); |
|
122 |
if (err != KErrNone) |
|
123 |
{ |
|
124 |
DP("Leave in EnsurePathExistsL"); |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
CleanupStack::PopAndDestroy(disks); |
|
130 |
} |
|
131 |
||
132 |
void CSettingsEngine::LoadSettingsL() |
|
133 |
{ |
|
134 |
DP("CSettingsEngine::LoadSettingsL\t Trying to load settings"); |
|
135 |
||
136 |
// Create path for the config file |
|
137 |
TFileName configPath; |
|
138 |
configPath.Copy(PrivatePath()); |
|
139 |
configPath.Append(KConfigFile); |
|
140 |
||
141 |
DP1("Checking settings file: %S", &configPath); |
|
142 |
||
143 |
CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(iPodcastModel.FsSession(), configPath, KMainSettingsStoreUid); |
|
144 |
||
145 |
if( store->IsPresentL(KMainSettingsUid) ) |
|
146 |
{ |
|
147 |
RDictionaryReadStream stream; |
|
148 |
stream.OpenLC(*store, KMainSettingsUid); |
|
149 |
||
150 |
TInt len = stream.ReadInt32L(); |
|
151 |
stream.ReadL(iBaseDir, len); |
|
152 |
iUpdateFeedInterval = stream.ReadInt32L(); |
|
153 |
iUpdateAutomatically = static_cast<TAutoUpdateSetting>(stream.ReadInt32L()); |
|
154 |
iDownloadAutomatically = stream.ReadInt32L(); |
|
155 |
||
156 |
||
157 |
iDownloadSuspended = stream.ReadInt32L(); // was iMaxSimultaneousDownloads |
|
158 |
iIap = stream.ReadInt32L(); |
|
159 |
||
160 |
TInt low = stream.ReadInt32L(); |
|
161 |
TInt high = stream.ReadInt32L(); |
|
162 |
iUpdateFeedTime = MAKE_TINT64(high, low); |
|
163 |
TInt dummy; |
|
164 |
dummy = stream.ReadInt32L(); // was iSelectOnlyUnplayed |
|
165 |
dummy = stream.ReadInt32L(); // was iSeekStepTime |
|
166 |
||
167 |
CleanupStack::PopAndDestroy(1); // readStream and iniFile |
|
168 |
DP("CSettingsEngine::LoadSettingsL\t Settings loaded OK"); |
|
169 |
} |
|
170 |
CleanupStack::PopAndDestroy();// close store |
|
171 |
} |
|
172 |
||
173 |
EXPORT_C void CSettingsEngine::SaveSettingsL() |
|
174 |
{ |
|
175 |
DP("CSettingsEngine::SaveSettingsL BEGIN"); |
|
176 |
||
177 |
TFileName configPath; |
|
178 |
configPath.Copy(PrivatePath()); |
|
179 |
configPath.Append(KConfigFile); |
|
180 |
||
181 |
CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(iPodcastModel.FsSession(), configPath, KMainSettingsStoreUid); |
|
182 |
||
183 |
RDictionaryWriteStream stream; |
|
184 |
stream.AssignLC(*store, KMainSettingsUid); |
|
185 |
||
186 |
stream.WriteInt32L(iBaseDir.Length()); |
|
187 |
stream.WriteL(iBaseDir); |
|
188 |
stream.WriteInt32L(iUpdateFeedInterval); |
|
189 |
stream.WriteInt32L(iUpdateAutomatically); |
|
190 |
stream.WriteInt32L(iDownloadAutomatically); |
|
191 |
stream.WriteInt32L(iDownloadSuspended); |
|
192 |
stream.WriteInt32L(iIap); |
|
193 |
||
194 |
stream.WriteInt32L(I64LOW(iUpdateFeedTime.Int64())); |
|
195 |
stream.WriteInt32L(I64HIGH(iUpdateFeedTime.Int64())); |
|
196 |
stream.WriteInt32L(0); // was iSelectOnlyUnplayed |
|
197 |
stream.WriteInt32L(0); // was iSeekStepTime |
|
198 |
||
199 |
stream.CommitL(); |
|
200 |
store->CommitL(); |
|
201 |
CleanupStack::PopAndDestroy(2); // stream and store |
|
202 |
DP("CSettingsEngine::SaveSettingsL END"); |
|
203 |
} |
|
204 |
||
205 |
TFileName CSettingsEngine::DefaultFeedsFileName() |
|
206 |
{ |
|
207 |
TFileName defaultFeeds; |
|
208 |
defaultFeeds.Append(PrivatePath()); |
|
209 |
defaultFeeds.Append(KDefaultFeedsFile); |
|
210 |
DP1("Default feeds file: %S", &defaultFeeds); |
|
211 |
return defaultFeeds; |
|
212 |
} |
|
213 |
||
214 |
TFileName CSettingsEngine::ImportFeedsFileName() |
|
215 |
{ |
|
216 |
TFileName importFeeds; |
|
217 |
importFeeds.Append(BaseDir()); |
|
218 |
importFeeds.Append(KImportFeedsFile); |
|
219 |
return importFeeds; |
|
220 |
} |
|
221 |
||
222 |
||
223 |
TFileName CSettingsEngine::PrivatePath() |
|
224 |
{ |
|
225 |
TFileName privatePath; |
|
91
87cb33beeae2
Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents:
2
diff
changeset
|
226 |
#ifdef __WINS__ |
2 | 227 |
iPodcastModel.FsSession().PrivatePath(privatePath); |
91
87cb33beeae2
Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents:
2
diff
changeset
|
228 |
#else |
87cb33beeae2
Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents:
2
diff
changeset
|
229 |
privatePath = _L("e:\\pod\\"); |
87cb33beeae2
Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents:
2
diff
changeset
|
230 |
#endif |
2 | 231 |
TRAP_IGNORE(BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), privatePath)); |
232 |
return privatePath; |
|
233 |
} |
|
234 |
||
235 |
TInt CSettingsEngine::MaxListItems() |
|
236 |
{ |
|
237 |
return iMaxListItems; |
|
238 |
} |
|
239 |
||
240 |
EXPORT_C TFileName& CSettingsEngine::BaseDir() |
|
241 |
{ |
|
242 |
return iBaseDir; |
|
243 |
} |
|
244 |
||
245 |
EXPORT_C void CSettingsEngine::SetBaseDir(TFileName& aFileName) |
|
246 |
{ |
|
247 |
TInt length = aFileName.Length(); |
|
248 |
if (length > 0) |
|
249 |
{ |
|
250 |
if (aFileName[length-1] != '\\') |
|
251 |
{ |
|
252 |
aFileName.Append(_L("\\")); |
|
253 |
} |
|
254 |
} |
|
255 |
iBaseDir = aFileName; |
|
256 |
} |
|
257 |
||
258 |
EXPORT_C TInt CSettingsEngine::UpdateFeedInterval() |
|
259 |
{ |
|
260 |
return iUpdateFeedInterval; |
|
261 |
} |
|
262 |
||
263 |
EXPORT_C void CSettingsEngine::SetUpdateFeedInterval(TInt aInterval) |
|
264 |
{ |
|
265 |
iUpdateFeedInterval = aInterval; |
|
266 |
iPodcastModel.FeedEngine().RunFeedTimer(); |
|
267 |
} |
|
268 |
||
269 |
EXPORT_C TAutoUpdateSetting CSettingsEngine::UpdateAutomatically() |
|
270 |
{ |
|
271 |
if (iUpdateAutomatically == EAutoUpdateOff || |
|
272 |
iUpdateAutomatically == EAutoUpdatePeriod1 || |
|
273 |
iUpdateAutomatically == EAutoUpdatePeriod2 || |
|
274 |
iUpdateAutomatically == EAutoUpdatePeriod3 || |
|
275 |
iUpdateAutomatically == EAutoUpdatePeriod4) |
|
276 |
return iUpdateAutomatically; |
|
277 |
else |
|
278 |
return EAutoUpdateOff; |
|
279 |
} |
|
280 |
||
281 |
EXPORT_C void CSettingsEngine::SetUpdateAutomatically(TAutoUpdateSetting aAutoSetting) |
|
282 |
{ |
|
283 |
iUpdateAutomatically = aAutoSetting; |
|
284 |
||
285 |
if (aAutoSetting > 0) { |
|
286 |
SetUpdateFeedInterval(aAutoSetting); |
|
287 |
} |
|
288 |
} |
|
289 |
||
290 |
EXPORT_C TBool CSettingsEngine::DownloadAutomatically() |
|
291 |
{ |
|
292 |
return iDownloadAutomatically; |
|
293 |
} |
|
294 |
||
295 |
EXPORT_C void CSettingsEngine::SetDownloadAutomatically(TBool aDownloadAuto) |
|
296 |
{ |
|
297 |
iDownloadAutomatically = aDownloadAuto; |
|
298 |
} |
|
299 |
||
300 |
EXPORT_C TTime CSettingsEngine::UpdateFeedTime() |
|
301 |
{ |
|
302 |
return iUpdateFeedTime; |
|
303 |
} |
|
304 |
||
305 |
EXPORT_C void CSettingsEngine::SetUpdateFeedTime(TTime aUpdateTime) |
|
306 |
{ |
|
307 |
iUpdateFeedTime = aUpdateTime; |
|
308 |
iPodcastModel.FeedEngine().RunFeedTimer(); |
|
309 |
} |
|
310 |
||
311 |
EXPORT_C TInt CSettingsEngine::SpecificIAP() |
|
312 |
{ |
|
313 |
if (iIap == 0 || iIap == -1) { |
|
314 |
return iIap; |
|
315 |
} |
|
316 |
||
317 |
for (int i=0;i<iPodcastModel.IAPIds().Count();i++) { |
|
318 |
if (((TInt)iPodcastModel.IAPIds()[i].iIapId) == (iIap&KUseIAPMask)) { |
|
319 |
return iIap; |
|
320 |
} |
|
321 |
||
322 |
} |
|
323 |
||
324 |
for (int i=0;i<iPodcastModel.SNAPIds().Count();i++) { |
|
325 |
if (((TInt)iPodcastModel.SNAPIds()[i].iIapId) == (iIap&KUseIAPMask)) { |
|
326 |
return iIap; |
|
327 |
} |
|
328 |
||
329 |
} |
|
330 |
||
331 |
return iPodcastModel.IAPIds()[0].iIapId; |
|
332 |
} |
|
333 |
||
334 |
EXPORT_C void CSettingsEngine::SetSpecificIAP(TInt aIap) |
|
335 |
{ |
|
336 |
iIap = aIap; |
|
337 |
} |
|
338 |
||
339 |
EXPORT_C TBool CSettingsEngine::DownloadSuspended() |
|
340 |
{ |
|
341 |
return iDownloadSuspended; |
|
342 |
} |
|
343 |
||
344 |
EXPORT_C void CSettingsEngine::SetDownloadSuspended(TBool aSuspended) |
|
345 |
{ |
|
346 |
DP1("CSettingsEngine::SetDownloadSuspended, aSuspended=%d", aSuspended); |
|
347 |
iDownloadSuspended = aSuspended; |
|
348 |
} |