author | Sebastian Brannstrom <sebastianb@symbian.org> |
Tue, 16 Nov 2010 18:02:18 +0000 | |
branch | RCL_3 |
changeset 370 | 83825edad8e1 |
parent 368 | b131f7696342 |
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" |
|
299
56d23cf60795
Fixes for issues using #define with raptor
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
282
diff
changeset
|
24 |
#include "defines.h" |
2 | 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); |
|
368
b131f7696342
Catch up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
299
diff
changeset
|
163 |
|
b131f7696342
Catch up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
299
diff
changeset
|
164 |
iDeleteAutomatically = (TAutoDeleteSetting) stream.ReadInt32L(); |
2 | 165 |
TInt dummy; |
166 |
dummy = stream.ReadInt32L(); // was iSeekStepTime |
|
167 |
||
168 |
CleanupStack::PopAndDestroy(1); // readStream and iniFile |
|
169 |
DP("CSettingsEngine::LoadSettingsL\t Settings loaded OK"); |
|
170 |
} |
|
171 |
CleanupStack::PopAndDestroy();// close store |
|
172 |
} |
|
173 |
||
174 |
EXPORT_C void CSettingsEngine::SaveSettingsL() |
|
175 |
{ |
|
176 |
DP("CSettingsEngine::SaveSettingsL BEGIN"); |
|
177 |
||
178 |
TFileName configPath; |
|
179 |
configPath.Copy(PrivatePath()); |
|
180 |
configPath.Append(KConfigFile); |
|
181 |
||
182 |
CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(iPodcastModel.FsSession(), configPath, KMainSettingsStoreUid); |
|
183 |
||
184 |
RDictionaryWriteStream stream; |
|
185 |
stream.AssignLC(*store, KMainSettingsUid); |
|
186 |
||
187 |
stream.WriteInt32L(iBaseDir.Length()); |
|
188 |
stream.WriteL(iBaseDir); |
|
189 |
stream.WriteInt32L(iUpdateFeedInterval); |
|
190 |
stream.WriteInt32L(iUpdateAutomatically); |
|
191 |
stream.WriteInt32L(iDownloadAutomatically); |
|
192 |
stream.WriteInt32L(iDownloadSuspended); |
|
193 |
stream.WriteInt32L(iIap); |
|
194 |
||
195 |
stream.WriteInt32L(I64LOW(iUpdateFeedTime.Int64())); |
|
196 |
stream.WriteInt32L(I64HIGH(iUpdateFeedTime.Int64())); |
|
368
b131f7696342
Catch up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
299
diff
changeset
|
197 |
stream.WriteInt32L(iDeleteAutomatically); |
2 | 198 |
stream.WriteInt32L(0); // was iSeekStepTime |
199 |
||
200 |
stream.CommitL(); |
|
201 |
store->CommitL(); |
|
202 |
CleanupStack::PopAndDestroy(2); // stream and store |
|
203 |
DP("CSettingsEngine::SaveSettingsL END"); |
|
204 |
} |
|
205 |
||
206 |
TFileName CSettingsEngine::DefaultFeedsFileName() |
|
207 |
{ |
|
208 |
TFileName defaultFeeds; |
|
162
d15654dbe9b8
Fix for bug 3169 - Podcatching failing to open due to missing DB
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
101
diff
changeset
|
209 |
TFileName temp; |
282
cf3842290671
Fix for startup bug in Symbian 3 version; new SIS v 1.00.6
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
162
diff
changeset
|
210 |
#ifdef ENABLE_MPX_INTEGRATION |
162
d15654dbe9b8
Fix for bug 3169 - Podcatching failing to open due to missing DB
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
101
diff
changeset
|
211 |
defaultFeeds.Copy(_L("z:")); |
282
cf3842290671
Fix for startup bug in Symbian 3 version; new SIS v 1.00.6
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
162
diff
changeset
|
212 |
#endif |
162
d15654dbe9b8
Fix for bug 3169 - Podcatching failing to open due to missing DB
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
101
diff
changeset
|
213 |
temp.Append(PrivatePath()); |
d15654dbe9b8
Fix for bug 3169 - Podcatching failing to open due to missing DB
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
101
diff
changeset
|
214 |
temp.Append(KDefaultFeedsFile); |
d15654dbe9b8
Fix for bug 3169 - Podcatching failing to open due to missing DB
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
101
diff
changeset
|
215 |
defaultFeeds.Append(temp); |
2 | 216 |
DP1("Default feeds file: %S", &defaultFeeds); |
217 |
return defaultFeeds; |
|
218 |
} |
|
219 |
||
220 |
TFileName CSettingsEngine::ImportFeedsFileName() |
|
221 |
{ |
|
222 |
TFileName importFeeds; |
|
223 |
importFeeds.Append(BaseDir()); |
|
224 |
importFeeds.Append(KImportFeedsFile); |
|
225 |
return importFeeds; |
|
226 |
} |
|
227 |
||
228 |
||
229 |
TFileName CSettingsEngine::PrivatePath() |
|
230 |
{ |
|
231 |
TFileName privatePath; |
|
232 |
iPodcastModel.FsSession().PrivatePath(privatePath); |
|
101
867fc277ffea
Removed debug code that place the DB in the wrong place; Fix for DL queue not updating show icon correctly when moving to next download.
teknolog
parents:
96
diff
changeset
|
233 |
|
2 | 234 |
TRAP_IGNORE(BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), privatePath)); |
235 |
return privatePath; |
|
236 |
} |
|
237 |
||
238 |
TInt CSettingsEngine::MaxListItems() |
|
239 |
{ |
|
240 |
return iMaxListItems; |
|
241 |
} |
|
242 |
||
243 |
EXPORT_C TFileName& CSettingsEngine::BaseDir() |
|
244 |
{ |
|
245 |
return iBaseDir; |
|
246 |
} |
|
247 |
||
248 |
EXPORT_C void CSettingsEngine::SetBaseDir(TFileName& aFileName) |
|
249 |
{ |
|
250 |
TInt length = aFileName.Length(); |
|
251 |
if (length > 0) |
|
252 |
{ |
|
253 |
if (aFileName[length-1] != '\\') |
|
254 |
{ |
|
255 |
aFileName.Append(_L("\\")); |
|
256 |
} |
|
257 |
} |
|
258 |
iBaseDir = aFileName; |
|
259 |
} |
|
260 |
||
261 |
EXPORT_C TInt CSettingsEngine::UpdateFeedInterval() |
|
262 |
{ |
|
263 |
return iUpdateFeedInterval; |
|
264 |
} |
|
265 |
||
266 |
EXPORT_C void CSettingsEngine::SetUpdateFeedInterval(TInt aInterval) |
|
267 |
{ |
|
268 |
iUpdateFeedInterval = aInterval; |
|
269 |
iPodcastModel.FeedEngine().RunFeedTimer(); |
|
270 |
} |
|
271 |
||
272 |
EXPORT_C TAutoUpdateSetting CSettingsEngine::UpdateAutomatically() |
|
273 |
{ |
|
274 |
if (iUpdateAutomatically == EAutoUpdateOff || |
|
275 |
iUpdateAutomatically == EAutoUpdatePeriod1 || |
|
276 |
iUpdateAutomatically == EAutoUpdatePeriod2 || |
|
277 |
iUpdateAutomatically == EAutoUpdatePeriod3 || |
|
278 |
iUpdateAutomatically == EAutoUpdatePeriod4) |
|
279 |
return iUpdateAutomatically; |
|
280 |
else |
|
281 |
return EAutoUpdateOff; |
|
282 |
} |
|
283 |
||
284 |
EXPORT_C void CSettingsEngine::SetUpdateAutomatically(TAutoUpdateSetting aAutoSetting) |
|
285 |
{ |
|
286 |
iUpdateAutomatically = aAutoSetting; |
|
287 |
||
288 |
if (aAutoSetting > 0) { |
|
289 |
SetUpdateFeedInterval(aAutoSetting); |
|
290 |
} |
|
291 |
} |
|
292 |
||
293 |
EXPORT_C TBool CSettingsEngine::DownloadAutomatically() |
|
294 |
{ |
|
295 |
return iDownloadAutomatically; |
|
296 |
} |
|
297 |
||
298 |
EXPORT_C void CSettingsEngine::SetDownloadAutomatically(TBool aDownloadAuto) |
|
299 |
{ |
|
300 |
iDownloadAutomatically = aDownloadAuto; |
|
301 |
} |
|
302 |
||
303 |
EXPORT_C TTime CSettingsEngine::UpdateFeedTime() |
|
304 |
{ |
|
305 |
return iUpdateFeedTime; |
|
306 |
} |
|
307 |
||
308 |
EXPORT_C void CSettingsEngine::SetUpdateFeedTime(TTime aUpdateTime) |
|
309 |
{ |
|
310 |
iUpdateFeedTime = aUpdateTime; |
|
311 |
iPodcastModel.FeedEngine().RunFeedTimer(); |
|
312 |
} |
|
313 |
||
314 |
EXPORT_C TInt CSettingsEngine::SpecificIAP() |
|
315 |
{ |
|
316 |
if (iIap == 0 || iIap == -1) { |
|
317 |
return iIap; |
|
318 |
} |
|
319 |
||
320 |
for (int i=0;i<iPodcastModel.IAPIds().Count();i++) { |
|
321 |
if (((TInt)iPodcastModel.IAPIds()[i].iIapId) == (iIap&KUseIAPMask)) { |
|
322 |
return iIap; |
|
323 |
} |
|
324 |
||
325 |
} |
|
326 |
||
327 |
for (int i=0;i<iPodcastModel.SNAPIds().Count();i++) { |
|
328 |
if (((TInt)iPodcastModel.SNAPIds()[i].iIapId) == (iIap&KUseIAPMask)) { |
|
329 |
return iIap; |
|
330 |
} |
|
331 |
||
332 |
} |
|
333 |
||
334 |
return iPodcastModel.IAPIds()[0].iIapId; |
|
335 |
} |
|
336 |
||
337 |
EXPORT_C void CSettingsEngine::SetSpecificIAP(TInt aIap) |
|
338 |
{ |
|
339 |
iIap = aIap; |
|
340 |
} |
|
341 |
||
342 |
EXPORT_C TBool CSettingsEngine::DownloadSuspended() |
|
343 |
{ |
|
344 |
return iDownloadSuspended; |
|
345 |
} |
|
346 |
||
347 |
EXPORT_C void CSettingsEngine::SetDownloadSuspended(TBool aSuspended) |
|
348 |
{ |
|
349 |
DP1("CSettingsEngine::SetDownloadSuspended, aSuspended=%d", aSuspended); |
|
350 |
iDownloadSuspended = aSuspended; |
|
351 |
} |
|
368
b131f7696342
Catch up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
299
diff
changeset
|
352 |
|
b131f7696342
Catch up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
299
diff
changeset
|
353 |
EXPORT_C TAutoDeleteSetting CSettingsEngine::DeleteAutomatically() |
b131f7696342
Catch up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
299
diff
changeset
|
354 |
{ |
b131f7696342
Catch up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
299
diff
changeset
|
355 |
return iDeleteAutomatically; |
b131f7696342
Catch up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
299
diff
changeset
|
356 |
} |
b131f7696342
Catch up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
299
diff
changeset
|
357 |
|
b131f7696342
Catch up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
299
diff
changeset
|
358 |
EXPORT_C void CSettingsEngine::SetDeleteAutomatically(TAutoDeleteSetting aDeleteAuto) |
b131f7696342
Catch up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
299
diff
changeset
|
359 |
{ |
b131f7696342
Catch up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
299
diff
changeset
|
360 |
iDeleteAutomatically = aDeleteAuto; |
b131f7696342
Catch up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
299
diff
changeset
|
361 |
} |