author | Sebastian Brannstrom <sebastianb@symbian.org> |
Fri, 19 Nov 2010 01:08:10 +0000 | |
branch | symbian1 |
changeset 374 | f067cee22e48 |
parent 349 | 4538abb763e4 |
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 "FeedEngine.h" |
|
23 |
#include "ShowEngine.h" |
|
24 |
||
25 |
const TUid KMainSettingsStoreUid = {0x1000}; |
|
26 |
const TUid KMainSettingsUid = {0x1002}; |
|
27 |
const TUid KExtraSettingsUid = {0x2001}; |
|
28 |
const TInt KMaxParseBuffer = 1024; |
|
29 |
||
30 |
CSettingsEngine::CSettingsEngine(CPodcastModel& aPodcastModel) : iPodcastModel(aPodcastModel) |
|
31 |
{ |
|
32 |
} |
|
33 |
||
34 |
CSettingsEngine::~CSettingsEngine() |
|
35 |
{ |
|
36 |
TRAP_IGNORE(SaveSettingsL()); |
|
37 |
} |
|
38 |
||
39 |
CSettingsEngine* CSettingsEngine::NewL(CPodcastModel& aPodcastModel) |
|
40 |
{ |
|
41 |
CSettingsEngine* self = new (ELeave) CSettingsEngine(aPodcastModel); |
|
42 |
CleanupStack::PushL(self); |
|
43 |
self->ConstructL(); |
|
44 |
CleanupStack::Pop(); |
|
45 |
return self; |
|
46 |
} |
|
47 |
||
48 |
void CSettingsEngine::ConstructL() |
|
49 |
{ |
|
50 |
DP("CSettingsEngine::ConstructL BEGIN"); |
|
51 |
// default values |
|
52 |
iUpdateFeedInterval = KDefaultUpdateFeedInterval; |
|
53 |
iDownloadAutomatically = EFalse; |
|
54 |
iUpdateAutomatically = EAutoUpdateOff; |
|
55 |
iMaxListItems = KDefaultMaxListItems; |
|
56 |
iIap = 0; |
|
57 |
||
58 |
// Check that our basedir exist. Create it otherwise; |
|
59 |
GetDefaultBaseDirL(iBaseDir); |
|
60 |
DP1("Base dir: %S", &iBaseDir); |
|
61 |
||
62 |
// load settings |
|
63 |
TRAPD(loadErr, LoadSettingsL()); |
|
64 |
if (loadErr != KErrNone) |
|
65 |
{ |
|
66 |
DP1("CSettingsEngine::ConstructL\tLoadSettingsL returned error=%d", loadErr); |
|
67 |
DP("CSettingsEngine::ConstructL\tUsing default settings instead"); |
|
68 |
||
69 |
TRAPD(error,SaveSettingsL()); |
|
70 |
if (error != KErrNone) |
|
71 |
{ |
|
72 |
DP1("error saving: %d", error); |
|
73 |
} |
|
74 |
} |
|
75 |
DP("CSettingsEngine::ConstructL END"); |
|
76 |
} |
|
77 |
||
78 |
void CSettingsEngine::GetDefaultBaseDirL(TDes & /*aBaseDir*/) |
|
79 |
{ |
|
80 |
CDesCArray* disks = new(ELeave) CDesCArrayFlat(10); |
|
81 |
CleanupStack::PushL(disks); |
|
82 |
||
83 |
BaflUtils::GetDiskListL(iPodcastModel.FsSession(), *disks); |
|
84 |
||
85 |
#ifdef __WINS__ |
|
86 |
iBaseDir.Copy(KPodcastDir3); |
|
87 |
CleanupStack::PopAndDestroy(disks); |
|
88 |
return; |
|
89 |
#endif |
|
90 |
||
91 |
DP1("Disks count: %u", disks->Count()); |
|
92 |
||
93 |
for (int i=0;i<disks->Count();i++) { |
|
94 |
TPtrC ptr = disks->operator[](i); |
|
95 |
DP2("Disk %u: %S", i, &ptr); |
|
96 |
} |
|
97 |
||
98 |
if (disks->Count() == 1) // if only one drive, use C: |
|
99 |
{ |
|
100 |
iBaseDir.Copy(KPodcastDir3); |
|
101 |
} |
|
102 |
else // else we use the flash drive |
|
103 |
{ |
|
104 |
iBaseDir.Copy(KPodcastDir1); |
|
105 |
DP1("Trying podcast dir '%S'", &iBaseDir); |
|
106 |
||
107 |
TRAPD(err, BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), iBaseDir)); |
|
108 |
||
109 |
if (err != KErrNone) |
|
110 |
{ |
|
111 |
DP("Leave in EnsurePathExistsL"); |
|
112 |
iBaseDir.Copy(KPodcastDir2); |
|
113 |
DP1("Trying podcast dir '%S'", &iBaseDir); |
|
114 |
TRAPD(err, BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), iBaseDir)); |
|
115 |
if (err != KErrNone) |
|
116 |
{ |
|
117 |
DP("Leave in EnsurePathExistsL"); |
|
118 |
iBaseDir.Copy(KPodcastDir3); |
|
119 |
DP1("Trying podcast dir '%S'", &iBaseDir); |
|
120 |
TRAPD(err, BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), iBaseDir)); |
|
121 |
if (err != KErrNone) |
|
122 |
{ |
|
123 |
DP("Leave in EnsurePathExistsL"); |
|
124 |
} |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
CleanupStack::PopAndDestroy(disks); |
|
129 |
} |
|
130 |
||
131 |
void CSettingsEngine::LoadSettingsL() |
|
132 |
{ |
|
133 |
DP("CSettingsEngine::LoadSettingsL\t Trying to load settings"); |
|
134 |
||
135 |
// Create path for the config file |
|
136 |
TFileName configPath; |
|
137 |
configPath.Copy(PrivatePath()); |
|
138 |
configPath.Append(KConfigFile); |
|
139 |
||
140 |
DP1("Checking settings file: %S", &configPath); |
|
141 |
||
142 |
CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(iPodcastModel.FsSession(), configPath, KMainSettingsStoreUid); |
|
143 |
||
144 |
if( store->IsPresentL(KMainSettingsUid) ) |
|
145 |
{ |
|
146 |
RDictionaryReadStream stream; |
|
147 |
stream.OpenLC(*store, KMainSettingsUid); |
|
148 |
||
149 |
TInt len = stream.ReadInt32L(); |
|
150 |
stream.ReadL(iBaseDir, len); |
|
151 |
iUpdateFeedInterval = stream.ReadInt32L(); |
|
152 |
iUpdateAutomatically = static_cast<TAutoUpdateSetting>(stream.ReadInt32L()); |
|
153 |
iDownloadAutomatically = stream.ReadInt32L(); |
|
154 |
||
155 |
||
156 |
iDownloadSuspended = stream.ReadInt32L(); // was iMaxSimultaneousDownloads |
|
157 |
iIap = stream.ReadInt32L(); |
|
158 |
||
159 |
TInt low = stream.ReadInt32L(); |
|
160 |
TInt high = stream.ReadInt32L(); |
|
161 |
iUpdateFeedTime = MAKE_TINT64(high, low); |
|
349
4538abb763e4
Added auto delete feature
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
65
diff
changeset
|
162 |
|
4538abb763e4
Added auto delete feature
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
65
diff
changeset
|
163 |
iDeleteAutomatically = (TAutoDeleteSetting) stream.ReadInt32L(); |
2 | 164 |
TInt dummy; |
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())); |
|
349
4538abb763e4
Added auto delete feature
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
65
diff
changeset
|
196 |
stream.WriteInt32L(iDeleteAutomatically); |
2 | 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; |
|
226 |
iPodcastModel.FsSession().PrivatePath(privatePath); |
|
60 | 227 |
|
2 | 228 |
TRAP_IGNORE(BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), privatePath)); |
229 |
return privatePath; |
|
230 |
} |
|
231 |
||
232 |
TInt CSettingsEngine::MaxListItems() |
|
233 |
{ |
|
234 |
return iMaxListItems; |
|
235 |
} |
|
236 |
||
237 |
EXPORT_C TFileName& CSettingsEngine::BaseDir() |
|
238 |
{ |
|
239 |
return iBaseDir; |
|
240 |
} |
|
241 |
||
242 |
EXPORT_C void CSettingsEngine::SetBaseDir(TFileName& aFileName) |
|
243 |
{ |
|
244 |
TInt length = aFileName.Length(); |
|
245 |
if (length > 0) |
|
246 |
{ |
|
247 |
if (aFileName[length-1] != '\\') |
|
248 |
{ |
|
249 |
aFileName.Append(_L("\\")); |
|
250 |
} |
|
251 |
} |
|
252 |
iBaseDir = aFileName; |
|
253 |
} |
|
254 |
||
255 |
EXPORT_C TInt CSettingsEngine::UpdateFeedInterval() |
|
256 |
{ |
|
257 |
return iUpdateFeedInterval; |
|
258 |
} |
|
259 |
||
260 |
EXPORT_C void CSettingsEngine::SetUpdateFeedInterval(TInt aInterval) |
|
261 |
{ |
|
262 |
iUpdateFeedInterval = aInterval; |
|
263 |
iPodcastModel.FeedEngine().RunFeedTimer(); |
|
264 |
} |
|
265 |
||
266 |
EXPORT_C TAutoUpdateSetting CSettingsEngine::UpdateAutomatically() |
|
267 |
{ |
|
268 |
if (iUpdateAutomatically == EAutoUpdateOff || |
|
269 |
iUpdateAutomatically == EAutoUpdatePeriod1 || |
|
270 |
iUpdateAutomatically == EAutoUpdatePeriod2 || |
|
271 |
iUpdateAutomatically == EAutoUpdatePeriod3 || |
|
272 |
iUpdateAutomatically == EAutoUpdatePeriod4) |
|
273 |
return iUpdateAutomatically; |
|
274 |
else |
|
275 |
return EAutoUpdateOff; |
|
276 |
} |
|
277 |
||
278 |
EXPORT_C void CSettingsEngine::SetUpdateAutomatically(TAutoUpdateSetting aAutoSetting) |
|
279 |
{ |
|
280 |
iUpdateAutomatically = aAutoSetting; |
|
281 |
||
282 |
if (aAutoSetting > 0) { |
|
283 |
SetUpdateFeedInterval(aAutoSetting); |
|
284 |
} |
|
285 |
} |
|
286 |
||
287 |
EXPORT_C TBool CSettingsEngine::DownloadAutomatically() |
|
288 |
{ |
|
289 |
return iDownloadAutomatically; |
|
290 |
} |
|
291 |
||
292 |
EXPORT_C void CSettingsEngine::SetDownloadAutomatically(TBool aDownloadAuto) |
|
293 |
{ |
|
294 |
iDownloadAutomatically = aDownloadAuto; |
|
295 |
} |
|
296 |
||
297 |
EXPORT_C TTime CSettingsEngine::UpdateFeedTime() |
|
298 |
{ |
|
299 |
return iUpdateFeedTime; |
|
300 |
} |
|
301 |
||
302 |
EXPORT_C void CSettingsEngine::SetUpdateFeedTime(TTime aUpdateTime) |
|
303 |
{ |
|
304 |
iUpdateFeedTime = aUpdateTime; |
|
305 |
iPodcastModel.FeedEngine().RunFeedTimer(); |
|
306 |
} |
|
307 |
||
308 |
EXPORT_C TInt CSettingsEngine::SpecificIAP() |
|
309 |
{ |
|
310 |
if (iIap == 0 || iIap == -1) { |
|
311 |
return iIap; |
|
312 |
} |
|
313 |
||
314 |
for (int i=0;i<iPodcastModel.IAPIds().Count();i++) { |
|
315 |
if (((TInt)iPodcastModel.IAPIds()[i].iIapId) == (iIap&KUseIAPMask)) { |
|
316 |
return iIap; |
|
317 |
} |
|
318 |
||
319 |
} |
|
320 |
||
321 |
for (int i=0;i<iPodcastModel.SNAPIds().Count();i++) { |
|
322 |
if (((TInt)iPodcastModel.SNAPIds()[i].iIapId) == (iIap&KUseIAPMask)) { |
|
323 |
return iIap; |
|
324 |
} |
|
325 |
||
326 |
} |
|
327 |
||
328 |
return iPodcastModel.IAPIds()[0].iIapId; |
|
329 |
} |
|
330 |
||
331 |
EXPORT_C void CSettingsEngine::SetSpecificIAP(TInt aIap) |
|
332 |
{ |
|
333 |
iIap = aIap; |
|
334 |
} |
|
335 |
||
336 |
EXPORT_C TBool CSettingsEngine::DownloadSuspended() |
|
337 |
{ |
|
338 |
return iDownloadSuspended; |
|
339 |
} |
|
340 |
||
341 |
EXPORT_C void CSettingsEngine::SetDownloadSuspended(TBool aSuspended) |
|
342 |
{ |
|
343 |
DP1("CSettingsEngine::SetDownloadSuspended, aSuspended=%d", aSuspended); |
|
344 |
iDownloadSuspended = aSuspended; |
|
345 |
} |
|
349
4538abb763e4
Added auto delete feature
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
65
diff
changeset
|
346 |
|
4538abb763e4
Added auto delete feature
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
65
diff
changeset
|
347 |
EXPORT_C TAutoDeleteSetting CSettingsEngine::DeleteAutomatically() |
4538abb763e4
Added auto delete feature
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
65
diff
changeset
|
348 |
{ |
4538abb763e4
Added auto delete feature
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
65
diff
changeset
|
349 |
return iDeleteAutomatically; |
4538abb763e4
Added auto delete feature
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
65
diff
changeset
|
350 |
} |
4538abb763e4
Added auto delete feature
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
65
diff
changeset
|
351 |
|
4538abb763e4
Added auto delete feature
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
65
diff
changeset
|
352 |
EXPORT_C void CSettingsEngine::SetDeleteAutomatically(TAutoDeleteSetting aDeleteAuto) |
4538abb763e4
Added auto delete feature
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
65
diff
changeset
|
353 |
{ |
4538abb763e4
Added auto delete feature
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
65
diff
changeset
|
354 |
iDeleteAutomatically = aDeleteAuto; |
4538abb763e4
Added auto delete feature
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
65
diff
changeset
|
355 |
} |