author | larspson |
Wed, 13 Oct 2010 20:14:00 +0200 | |
branch | podcatcher_qt_symbian4 |
changeset 234 | 05075131dd6a |
parent 162 | d15654dbe9b8 |
child 282 | cf3842290671 |
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); |
|
162 |
TInt dummy; |
|
163 |
dummy = stream.ReadInt32L(); // was iSelectOnlyUnplayed |
|
164 |
dummy = stream.ReadInt32L(); // was iSeekStepTime |
|
165 |
||
166 |
CleanupStack::PopAndDestroy(1); // readStream and iniFile |
|
167 |
DP("CSettingsEngine::LoadSettingsL\t Settings loaded OK"); |
|
168 |
} |
|
169 |
CleanupStack::PopAndDestroy();// close store |
|
170 |
} |
|
171 |
||
172 |
EXPORT_C void CSettingsEngine::SaveSettingsL() |
|
173 |
{ |
|
174 |
DP("CSettingsEngine::SaveSettingsL BEGIN"); |
|
175 |
||
176 |
TFileName configPath; |
|
177 |
configPath.Copy(PrivatePath()); |
|
178 |
configPath.Append(KConfigFile); |
|
179 |
||
180 |
CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(iPodcastModel.FsSession(), configPath, KMainSettingsStoreUid); |
|
181 |
||
182 |
RDictionaryWriteStream stream; |
|
183 |
stream.AssignLC(*store, KMainSettingsUid); |
|
184 |
||
185 |
stream.WriteInt32L(iBaseDir.Length()); |
|
186 |
stream.WriteL(iBaseDir); |
|
187 |
stream.WriteInt32L(iUpdateFeedInterval); |
|
188 |
stream.WriteInt32L(iUpdateAutomatically); |
|
189 |
stream.WriteInt32L(iDownloadAutomatically); |
|
190 |
stream.WriteInt32L(iDownloadSuspended); |
|
191 |
stream.WriteInt32L(iIap); |
|
192 |
||
193 |
stream.WriteInt32L(I64LOW(iUpdateFeedTime.Int64())); |
|
194 |
stream.WriteInt32L(I64HIGH(iUpdateFeedTime.Int64())); |
|
195 |
stream.WriteInt32L(0); // was iSelectOnlyUnplayed |
|
196 |
stream.WriteInt32L(0); // was iSeekStepTime |
|
197 |
||
198 |
stream.CommitL(); |
|
199 |
store->CommitL(); |
|
200 |
CleanupStack::PopAndDestroy(2); // stream and store |
|
201 |
DP("CSettingsEngine::SaveSettingsL END"); |
|
202 |
} |
|
203 |
||
204 |
TFileName CSettingsEngine::DefaultFeedsFileName() |
|
205 |
{ |
|
206 |
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
|
207 |
TFileName temp; |
d15654dbe9b8
Fix for bug 3169 - Podcatching failing to open due to missing DB
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
101
diff
changeset
|
208 |
defaultFeeds.Copy(_L("z:")); |
d15654dbe9b8
Fix for bug 3169 - Podcatching failing to open due to missing DB
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
101
diff
changeset
|
209 |
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
|
210 |
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
|
211 |
defaultFeeds.Append(temp); |
2 | 212 |
DP1("Default feeds file: %S", &defaultFeeds); |
213 |
return defaultFeeds; |
|
214 |
} |
|
215 |
||
216 |
TFileName CSettingsEngine::ImportFeedsFileName() |
|
217 |
{ |
|
218 |
TFileName importFeeds; |
|
219 |
importFeeds.Append(BaseDir()); |
|
220 |
importFeeds.Append(KImportFeedsFile); |
|
221 |
return importFeeds; |
|
222 |
} |
|
223 |
||
224 |
||
225 |
TFileName CSettingsEngine::PrivatePath() |
|
226 |
{ |
|
227 |
TFileName privatePath; |
|
228 |
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
|
229 |
|
2 | 230 |
TRAP_IGNORE(BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), privatePath)); |
231 |
return privatePath; |
|
232 |
} |
|
233 |
||
234 |
TInt CSettingsEngine::MaxListItems() |
|
235 |
{ |
|
236 |
return iMaxListItems; |
|
237 |
} |
|
238 |
||
239 |
EXPORT_C TFileName& CSettingsEngine::BaseDir() |
|
240 |
{ |
|
241 |
return iBaseDir; |
|
242 |
} |
|
243 |
||
244 |
EXPORT_C void CSettingsEngine::SetBaseDir(TFileName& aFileName) |
|
245 |
{ |
|
246 |
TInt length = aFileName.Length(); |
|
247 |
if (length > 0) |
|
248 |
{ |
|
249 |
if (aFileName[length-1] != '\\') |
|
250 |
{ |
|
251 |
aFileName.Append(_L("\\")); |
|
252 |
} |
|
253 |
} |
|
254 |
iBaseDir = aFileName; |
|
255 |
} |
|
256 |
||
257 |
EXPORT_C TInt CSettingsEngine::UpdateFeedInterval() |
|
258 |
{ |
|
259 |
return iUpdateFeedInterval; |
|
260 |
} |
|
261 |
||
262 |
EXPORT_C void CSettingsEngine::SetUpdateFeedInterval(TInt aInterval) |
|
263 |
{ |
|
264 |
iUpdateFeedInterval = aInterval; |
|
265 |
iPodcastModel.FeedEngine().RunFeedTimer(); |
|
266 |
} |
|
267 |
||
268 |
EXPORT_C TAutoUpdateSetting CSettingsEngine::UpdateAutomatically() |
|
269 |
{ |
|
270 |
if (iUpdateAutomatically == EAutoUpdateOff || |
|
271 |
iUpdateAutomatically == EAutoUpdatePeriod1 || |
|
272 |
iUpdateAutomatically == EAutoUpdatePeriod2 || |
|
273 |
iUpdateAutomatically == EAutoUpdatePeriod3 || |
|
274 |
iUpdateAutomatically == EAutoUpdatePeriod4) |
|
275 |
return iUpdateAutomatically; |
|
276 |
else |
|
277 |
return EAutoUpdateOff; |
|
278 |
} |
|
279 |
||
280 |
EXPORT_C void CSettingsEngine::SetUpdateAutomatically(TAutoUpdateSetting aAutoSetting) |
|
281 |
{ |
|
282 |
iUpdateAutomatically = aAutoSetting; |
|
283 |
||
284 |
if (aAutoSetting > 0) { |
|
285 |
SetUpdateFeedInterval(aAutoSetting); |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
EXPORT_C TBool CSettingsEngine::DownloadAutomatically() |
|
290 |
{ |
|
291 |
return iDownloadAutomatically; |
|
292 |
} |
|
293 |
||
294 |
EXPORT_C void CSettingsEngine::SetDownloadAutomatically(TBool aDownloadAuto) |
|
295 |
{ |
|
296 |
iDownloadAutomatically = aDownloadAuto; |
|
297 |
} |
|
298 |
||
299 |
EXPORT_C TTime CSettingsEngine::UpdateFeedTime() |
|
300 |
{ |
|
301 |
return iUpdateFeedTime; |
|
302 |
} |
|
303 |
||
304 |
EXPORT_C void CSettingsEngine::SetUpdateFeedTime(TTime aUpdateTime) |
|
305 |
{ |
|
306 |
iUpdateFeedTime = aUpdateTime; |
|
307 |
iPodcastModel.FeedEngine().RunFeedTimer(); |
|
308 |
} |
|
309 |
||
310 |
EXPORT_C TInt CSettingsEngine::SpecificIAP() |
|
311 |
{ |
|
312 |
if (iIap == 0 || iIap == -1) { |
|
313 |
return iIap; |
|
314 |
} |
|
315 |
||
316 |
for (int i=0;i<iPodcastModel.IAPIds().Count();i++) { |
|
317 |
if (((TInt)iPodcastModel.IAPIds()[i].iIapId) == (iIap&KUseIAPMask)) { |
|
318 |
return iIap; |
|
319 |
} |
|
320 |
||
321 |
} |
|
322 |
||
323 |
for (int i=0;i<iPodcastModel.SNAPIds().Count();i++) { |
|
324 |
if (((TInt)iPodcastModel.SNAPIds()[i].iIapId) == (iIap&KUseIAPMask)) { |
|
325 |
return iIap; |
|
326 |
} |
|
327 |
||
328 |
} |
|
329 |
||
330 |
return iPodcastModel.IAPIds()[0].iIapId; |
|
331 |
} |
|
332 |
||
333 |
EXPORT_C void CSettingsEngine::SetSpecificIAP(TInt aIap) |
|
334 |
{ |
|
335 |
iIap = aIap; |
|
336 |
} |
|
337 |
||
338 |
EXPORT_C TBool CSettingsEngine::DownloadSuspended() |
|
339 |
{ |
|
340 |
return iDownloadSuspended; |
|
341 |
} |
|
342 |
||
343 |
EXPORT_C void CSettingsEngine::SetDownloadSuspended(TBool aSuspended) |
|
344 |
{ |
|
345 |
DP1("CSettingsEngine::SetDownloadSuspended, aSuspended=%d", aSuspended); |
|
346 |
iDownloadSuspended = aSuspended; |
|
347 |
} |