author | teknolog |
Sun, 04 Apr 2010 18:14:15 +0100 | |
changeset 79 | 0bd6b9a3f027 |
parent 78 | 12c59f14a031 |
child 82 | d87e984bd8b8 |
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 "ShowEngine.h" |
|
20 |
#include "FeedEngine.h" |
|
21 |
#include "FeedInfo.h" |
|
22 |
#include <bautils.h> |
|
23 |
#include <s32file.h> |
|
24 |
#include "SettingsEngine.h" |
|
25 |
#include <e32hashtab.h> |
|
26 |
#include <httperr.h> |
|
27 |
#include "debug.h" |
|
28 |
#include "PodcastUtils.h" |
|
29 |
||
30 |
//#include <mpxmedia.h> |
|
31 |
//#include <mpxattribute.h> |
|
32 |
//#include <mpxmediageneraldefs.h> |
|
33 |
||
34 |
const TUint KMaxDownloadErrors = 3; |
|
35 |
const TInt KMimeBufLength = 100; |
|
36 |
||
37 |
CShowEngine::CShowEngine(CPodcastModel& aPodcastModel) : |
|
38 |
iPodcastModel(aPodcastModel), |
|
39 |
iDB(*aPodcastModel.DB()) |
|
40 |
{ |
|
41 |
} |
|
42 |
||
43 |
EXPORT_C CShowEngine::~CShowEngine() |
|
44 |
{ |
|
45 |
delete iShowClient; |
|
46 |
iObservers.Close(); |
|
47 |
delete iShowDownloading; |
|
48 |
delete iMetaDataReader; |
|
49 |
iApaSession.Close(); |
|
50 |
} |
|
51 |
||
52 |
EXPORT_C CShowEngine* CShowEngine::NewL(CPodcastModel& aPodcastModel) |
|
53 |
{ |
|
54 |
CShowEngine* self = new (ELeave) CShowEngine(aPodcastModel); |
|
55 |
CleanupStack::PushL(self); |
|
56 |
self->ConstructL(); |
|
57 |
CleanupStack::Pop(self); |
|
58 |
return self; |
|
59 |
} |
|
60 |
||
61 |
EXPORT_C void CShowEngine::GetMimeType(const TDesC& aFileName, TDes& aMimeType) |
|
62 |
{ |
|
63 |
aMimeType.Zero(); |
|
64 |
RFile file; |
|
65 |
if (file.Open(iPodcastModel.FsSession(), aFileName, 0) == KErrNone) |
|
66 |
{ |
|
67 |
if (file.Read(iRecogBuffer) == KErrNone) |
|
68 |
{ |
|
69 |
TDataRecognitionResult result; |
|
70 |
if (iApaSession.RecognizeData(aFileName, iRecogBuffer, result) |
|
71 |
== KErrNone) |
|
72 |
{ |
|
73 |
aMimeType.Copy(result.iDataType.Des()); |
|
74 |
} |
|
75 |
||
76 |
} |
|
77 |
} |
|
78 |
file.Close(); |
|
79 |
} |
|
80 |
||
81 |
void CShowEngine::ConstructL() |
|
82 |
{ |
|
83 |
iShowClient = CHttpClient::NewL(iPodcastModel, *this); |
|
84 |
iShowClient->SetResumeEnabled(ETrue); |
|
85 |
iMetaDataReader = new (ELeave) CMetaDataReader(*this, iPodcastModel.FsSession()); |
|
86 |
iMetaDataReader->ConstructL(); |
|
87 |
User::LeaveIfError(iApaSession.Connect()); |
|
88 |
} |
|
89 |
||
90 |
EXPORT_C void CShowEngine::SuspendDownloads() |
|
91 |
{ |
|
92 |
iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue); |
|
93 |
iShowClient->Stop(); |
|
94 |
} |
|
95 |
||
96 |
EXPORT_C void CShowEngine::ResumeDownloadsL() |
|
97 |
{ |
|
98 |
DP("CShowEngine::ResumeDownloadsL BEGIN"); |
|
99 |
if (iPodcastModel.SettingsEngine().DownloadSuspended()) |
|
100 |
{ |
|
101 |
iPodcastModel.SettingsEngine().SetDownloadSuspended(EFalse); |
|
102 |
iDownloadErrors = 0; |
|
103 |
DownloadNextShowL(); |
|
104 |
} |
|
105 |
DP("CShowEngine::ResumeDownloadsL END"); |
|
106 |
} |
|
107 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
108 |
EXPORT_C void CShowEngine::RemoveAllDownloadsL() |
2 | 109 |
{ |
110 |
if (!iPodcastModel.SettingsEngine().DownloadSuspended()) |
|
111 |
{ |
|
112 |
SuspendDownloads(); |
|
113 |
} |
|
114 |
||
78 | 115 |
DBRemoveAllDownloadsL(); |
22 | 116 |
NotifyDownloadQueueUpdatedL(); |
2 | 117 |
} |
118 |
||
78 | 119 |
EXPORT_C void CShowEngine::RemoveDownloadL(TUint aUid) |
2 | 120 |
{ |
78 | 121 |
DP("CShowEngine::RemoveDownloadL BEGIN"); |
2 | 122 |
|
123 |
TBool resumeAfterRemove = EFalse; |
|
124 |
// if trying to remove the present download, we first stop it |
|
125 |
if (!iPodcastModel.SettingsEngine().DownloadSuspended() && iShowDownloading != NULL |
|
126 |
&& iShowDownloading->Uid() == aUid) |
|
127 |
{ |
|
128 |
DP("CShowEngine::RemoveDownload\t This is the active download, we suspend downloading"); |
|
129 |
SuspendDownloads(); |
|
130 |
resumeAfterRemove = ETrue; |
|
131 |
} |
|
132 |
||
133 |
CShowInfo *info = DBGetShowByUidL(aUid); |
|
134 |
if (info != NULL) |
|
135 |
{ |
|
136 |
info->SetDownloadState(ENotDownloaded); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
137 |
DBUpdateShowL(*info); |
2 | 138 |
delete info; |
139 |
} |
|
78 | 140 |
|
141 |
DBRemoveDownloadL(aUid); |
|
2 | 142 |
|
143 |
// partial downloads should be removed |
|
144 |
if (iShowDownloading) |
|
145 |
{ |
|
146 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(), iShowDownloading->FileName()); |
|
147 |
} |
|
148 |
||
149 |
NotifyShowDownloadUpdatedL(-1, -1); |
|
150 |
NotifyDownloadQueueUpdatedL(); |
|
151 |
||
152 |
if (resumeAfterRemove) { |
|
153 |
ResumeDownloadsL(); |
|
154 |
} |
|
155 |
||
156 |
DownloadNextShowL(); |
|
78 | 157 |
DP("CShowEngine::RemoveDownloadL END"); |
2 | 158 |
} |
159 |
||
160 |
void CShowEngine::Connected(CHttpClient* /*aClient*/) |
|
161 |
{ |
|
162 |
||
163 |
} |
|
164 |
||
165 |
void CShowEngine::Progress(CHttpClient* /*aHttpClient */, TInt aBytes, |
|
166 |
TInt aTotalBytes) |
|
167 |
{ |
|
168 |
iShowDownloading->SetShowSize(aTotalBytes); |
|
169 |
TRAP_IGNORE(NotifyShowDownloadUpdatedL(aBytes, aTotalBytes)); |
|
170 |
} |
|
171 |
||
172 |
void CShowEngine::Disconnected(CHttpClient* /*aClient */) |
|
173 |
{ |
|
174 |
} |
|
175 |
||
176 |
void CShowEngine::DownloadInfo(CHttpClient* aHttpClient, TInt aTotalBytes) |
|
177 |
{ |
|
178 |
DP1("About to download %d bytes", aTotalBytes); |
|
179 |
if (aHttpClient == iShowClient && iShowDownloading != NULL |
|
180 |
&& aTotalBytes != -1) |
|
181 |
{ |
|
182 |
iShowDownloading->SetShowSize(aTotalBytes); |
|
183 |
} |
|
184 |
} |
|
185 |
||
78 | 186 |
void CShowEngine::GetShowL(CShowInfo *info) |
2 | 187 |
{ |
188 |
CFeedInfo *feedInfo = iPodcastModel.FeedEngine().GetFeedInfoByUid( |
|
189 |
info->FeedUid()); |
|
78 | 190 |
|
2 | 191 |
TFileName filePath; |
192 |
filePath.Copy(iPodcastModel.SettingsEngine().BaseDir()); |
|
193 |
||
194 |
TFileName relPath; |
|
195 |
relPath.Copy(feedInfo->Title()); |
|
196 |
relPath.Append('\\'); |
|
197 |
||
198 |
TFileName fileName; |
|
199 |
PodcastUtils::FileNameFromUrl(info->Url(), fileName); |
|
200 |
relPath.Append(fileName); |
|
201 |
PodcastUtils::EnsureProperPathName(relPath); |
|
202 |
||
203 |
// complete file path is base dir + rel path |
|
204 |
filePath.Append(relPath); |
|
205 |
info->SetFileNameL(filePath); |
|
206 |
||
78 | 207 |
User::LeaveIfError(iShowClient->GetL(info->Url(), filePath)); |
2 | 208 |
} |
209 |
||
78 | 210 |
EXPORT_C void CShowEngine::AddShowL(const CShowInfo& aItem) |
2 | 211 |
{ |
212 |
DP1("CShowEngine::AddShowL, title=%S", &aItem.Title()); |
|
213 |
CShowInfo *showInfo = DBGetShowByUidL(aItem.Uid()); |
|
214 |
||
215 |
if (showInfo == NULL) |
|
216 |
{ |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
217 |
DBAddShowL(aItem); |
2 | 218 |
} |
219 |
else |
|
220 |
{ |
|
221 |
delete showInfo; |
|
78 | 222 |
User::Leave(KErrAlreadyExists); |
2 | 223 |
} |
224 |
} |
|
225 |
||
226 |
EXPORT_C void CShowEngine::AddObserver(MShowEngineObserver *observer) |
|
227 |
{ |
|
228 |
iObservers.Append(observer); |
|
229 |
} |
|
230 |
||
231 |
EXPORT_C void CShowEngine::RemoveObserver(MShowEngineObserver *observer) |
|
232 |
{ |
|
233 |
TInt index = iObservers.Find(observer); |
|
234 |
||
235 |
if (index > KErrNotFound) |
|
236 |
{ |
|
237 |
iObservers.Remove(index); |
|
238 |
} |
|
239 |
} |
|
240 |
||
241 |
void CShowEngine::AddShowToMpxCollection(CShowInfo &/*aShowInfo*/) |
|
242 |
{ |
|
243 |
/* RArray<TInt> contentIDs; |
|
244 |
contentIDs.AppendL( KMPXMediaIdGeneral ); |
|
245 |
||
246 |
CMPXMedia* media = CMPXMedia::NewL( contentIDs.Array() ); |
|
247 |
CleanupStack::PushL( media ); |
|
248 |
contentIDs.Close(); |
|
249 |
CleanupStack::PopAndDestroy(media); */ |
|
250 |
} |
|
251 |
||
252 |
void CShowEngine::CompleteL(CHttpClient* /*aHttpClient*/, TInt aError) |
|
253 |
{ |
|
254 |
if (iShowDownloading != NULL) |
|
255 |
{ |
|
256 |
DP1("CShowEngine::Complete\tDownload of file: %S is complete", &iShowDownloading->FileName()); |
|
257 |
if(aError != KErrCouldNotConnect) |
|
258 |
{ |
|
6 | 259 |
if(aError == KErrDisconnected && iPodcastModel.SettingsEngine().DownloadSuspended()) |
260 |
{ |
|
2 | 261 |
// no error if disconnect happened because of suspended downloading |
6 | 262 |
} |
263 |
else |
|
264 |
{ |
|
2 | 265 |
iShowDownloading->SetLastError(aError); |
6 | 266 |
} |
2 | 267 |
|
268 |
if (aError == KErrNone) |
|
269 |
{ |
|
270 |
TBuf<KMimeBufLength> mimeType; |
|
271 |
GetMimeType(iShowDownloading->FileName(), mimeType); |
|
272 |
_LIT(KMimeAudio,"audio"); |
|
273 |
_LIT(KMimeVideo,"video"); |
|
274 |
if (mimeType.Left(5) == KMimeAudio) |
|
275 |
{ |
|
276 |
iShowDownloading->SetShowType(EAudioPodcast); |
|
277 |
} |
|
278 |
else if (mimeType.Left(5) == KMimeVideo) |
|
279 |
{ |
|
280 |
iShowDownloading->SetShowType(EVideoPodcast); |
|
281 |
} |
|
282 |
||
283 |
iShowDownloading->SetDownloadState(EDownloaded); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
284 |
DBUpdateShowL(*iShowDownloading); |
78 | 285 |
DBRemoveDownloadL(iShowDownloading->Uid()); |
2 | 286 |
AddShowToMpxCollection(*iShowDownloading); |
287 |
NotifyShowFinishedL(aError); |
|
15
93d9f66bf50b
Cleaning description better for second line in search results
teknolog
parents:
6
diff
changeset
|
288 |
iDownloadErrors = 0; |
2 | 289 |
delete iShowDownloading; |
290 |
iShowDownloading = NULL; |
|
291 |
} |
|
292 |
else |
|
293 |
{ |
|
294 |
// 400 and 500 series errors are serious errors on which probably another download will fail |
|
295 |
if(aError >= HTTPStatus::EBadRequest && aError <= HTTPStatus::EBadRequest+200) |
|
296 |
{ |
|
297 |
iShowDownloading->SetDownloadState(EFailedDownload); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
298 |
DBUpdateShowL(*iShowDownloading); |
78 | 299 |
DBRemoveDownloadL(iShowDownloading->Uid()); |
2 | 300 |
NotifyShowFinishedL(aError); |
301 |
||
302 |
delete iShowDownloading; |
|
303 |
iShowDownloading = NULL; |
|
304 |
} |
|
305 |
else // other kind of error, missing network etc, reque this show |
|
306 |
{ |
|
307 |
iShowDownloading->SetDownloadState(EQueued); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
308 |
DBUpdateShowL(*iShowDownloading); |
2 | 309 |
} |
310 |
||
311 |
iDownloadErrors++; |
|
312 |
if (iDownloadErrors > KMaxDownloadErrors) |
|
313 |
{ |
|
314 |
DP("Too many downloading errors, suspending downloads"); |
|
315 |
iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue); |
|
316 |
NotifyShowFinishedL(aError); |
|
317 |
} |
|
318 |
} |
|
319 |
DownloadNextShowL(); |
|
320 |
} |
|
321 |
||
322 |
else |
|
323 |
{ |
|
324 |
// Connection error |
|
325 |
if(iShowDownloading) |
|
326 |
{ |
|
327 |
iShowDownloading->SetDownloadState(EQueued); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
328 |
DBUpdateShowL(*iShowDownloading); |
2 | 329 |
} |
330 |
iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue); |
|
331 |
NotifyShowFinishedL(aError); |
|
332 |
} |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
EXPORT_C CShowInfo* CShowEngine::ShowDownloading() |
|
337 |
{ |
|
338 |
return iShowDownloading; |
|
339 |
} |
|
340 |
||
341 |
EXPORT_C CShowInfo* CShowEngine::GetShowByUidL(TUint aShowUid) |
|
342 |
{ |
|
343 |
return DBGetShowByUidL(aShowUid); |
|
344 |
} |
|
345 |
CShowInfo* CShowEngine::DBGetShowByUidL(TUint aUid) |
|
346 |
{ |
|
347 |
DP("CShowEngine::DBGetShowByUid"); |
|
348 |
CShowInfo *showInfo = NULL; |
|
349 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows where uid=%u"); |
|
350 |
iSqlBuffer.Format(KSqlStatement, aUid); |
|
351 |
||
352 |
sqlite3_stmt *st; |
|
353 |
||
354 |
//DP1("SQL: %S", &iSqlBuffer.Left(KSqlDPLen)); |
|
355 |
||
356 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
357 |
&st, (const void**) NULL); |
|
358 |
||
359 |
if (rc == SQLITE_OK) |
|
360 |
{ |
|
361 |
rc = sqlite3_step(st); |
|
362 |
Cleanup_sqlite3_finalize_PushL(st); |
|
363 |
if (rc == SQLITE_ROW) |
|
364 |
{ |
|
365 |
showInfo = CShowInfo::NewLC(); |
|
366 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
367 |
CleanupStack::Pop(showInfo); |
|
368 |
} |
|
369 |
CleanupStack::PopAndDestroy();//st |
|
370 |
} |
|
371 |
||
372 |
return showInfo; |
|
373 |
} |
|
374 |
||
375 |
EXPORT_C CShowInfo* CShowEngine::DBGetShowByFileNameL(TFileName aFileName) |
|
376 |
{ |
|
377 |
DP("CShowEngine::DBGetShowByUid"); |
|
378 |
CShowInfo *showInfo = NULL; |
|
379 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows where filename=\"%S\""); |
|
380 |
iSqlBuffer.Format(KSqlStatement, &aFileName); |
|
381 |
||
382 |
sqlite3_stmt *st; |
|
383 |
||
384 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
385 |
&st, (const void**) NULL); |
|
386 |
||
387 |
if (rc == SQLITE_OK) |
|
388 |
{ |
|
389 |
rc = sqlite3_step(st); |
|
390 |
Cleanup_sqlite3_finalize_PushL(st); |
|
391 |
if (rc == SQLITE_ROW) |
|
392 |
{ |
|
393 |
showInfo = CShowInfo::NewLC(); |
|
394 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
395 |
CleanupStack::Pop(showInfo); |
|
396 |
} |
|
397 |
CleanupStack::PopAndDestroy();//st |
|
398 |
} |
|
399 |
||
400 |
return showInfo; |
|
401 |
} |
|
402 |
||
403 |
void CShowEngine::DBGetAllShowsL(RShowInfoArray& aShowArray) |
|
404 |
{ |
|
405 |
DP("CShowEngine::DBGetAllShows"); |
|
406 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows"); |
|
407 |
iSqlBuffer.Format(KSqlStatement); |
|
408 |
||
409 |
sqlite3_stmt *st; |
|
410 |
||
411 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
412 |
&st, (const void**) NULL); |
|
413 |
||
414 |
if (rc == SQLITE_OK) |
|
415 |
{ |
|
416 |
rc = sqlite3_step(st); |
|
417 |
Cleanup_sqlite3_finalize_PushL(st); |
|
418 |
while (rc == SQLITE_ROW) |
|
419 |
{ |
|
420 |
CShowInfo* showInfo = CShowInfo::NewLC(); |
|
421 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
422 |
aShowArray.Append(showInfo); |
|
423 |
CleanupStack::Pop(showInfo); |
|
424 |
rc = sqlite3_step(st); |
|
425 |
} |
|
426 |
CleanupStack::PopAndDestroy();//st |
|
427 |
} |
|
428 |
||
429 |
} |
|
430 |
||
431 |
void CShowEngine::DBGetAllDownloadsL(RShowInfoArray& aShowArray) |
|
432 |
{ |
|
433 |
DP("CShowEngine::DBGetAllDownloads"); |
|
434 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, shows.uid, showsize, trackno, pubdate, showtype, lasterror from downloads, shows where downloads.uid=shows.uid"); |
|
435 |
iSqlBuffer.Format(KSqlStatement); |
|
436 |
||
437 |
#ifndef DONT_SORT_SQL |
|
438 |
_LIT(KSqlSort, " order by dl_index"); |
|
439 |
iSqlBuffer.Append(KSqlSort); |
|
440 |
#endif |
|
441 |
sqlite3_stmt *st; |
|
442 |
||
443 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
444 |
&st, (const void**) NULL); |
|
445 |
||
446 |
if (rc == SQLITE_OK) |
|
447 |
{ |
|
448 |
rc = sqlite3_step(st); |
|
449 |
Cleanup_sqlite3_finalize_PushL(st); |
|
450 |
while (rc == SQLITE_ROW) |
|
451 |
{ |
|
452 |
CShowInfo* showInfo = CShowInfo::NewLC(); |
|
453 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
454 |
aShowArray.Append(showInfo); |
|
455 |
CleanupStack::Pop(showInfo); |
|
456 |
rc = sqlite3_step(st); |
|
457 |
} |
|
458 |
CleanupStack::PopAndDestroy();//st |
|
459 |
} |
|
78 | 460 |
else |
461 |
{ |
|
462 |
User::Leave(KErrCorrupt); |
|
463 |
} |
|
2 | 464 |
|
465 |
// delete downloads that don't have a show |
|
466 |
||
467 |
_LIT(KSqlStatement2, "delete from downloads where uid not in (select downloads.uid from shows, downloads where shows.uid=downloads.uid)"); |
|
468 |
iSqlBuffer.Format(KSqlStatement2); |
|
469 |
||
470 |
rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, &st, (const void**) NULL); |
|
471 |
||
472 |
if (rc == SQLITE_OK) |
|
473 |
{ |
|
78 | 474 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 475 |
rc = sqlite3_step(st); |
78 | 476 |
CleanupStack::PopAndDestroy(); // st |
477 |
} |
|
478 |
else |
|
479 |
{ |
|
480 |
User::Leave(KErrCorrupt); |
|
2 | 481 |
} |
482 |
} |
|
483 |
||
484 |
CShowInfo* CShowEngine::DBGetNextDownloadL() |
|
485 |
{ |
|
486 |
DP("CShowEngine::DBGetNextDownload"); |
|
487 |
CShowInfo *showInfo = NULL; |
|
488 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, shows.uid, showsize, trackno, pubdate, showtype, lasterror from downloads, shows where downloads.uid=shows.uid"); |
|
489 |
iSqlBuffer.Format(KSqlStatement); |
|
490 |
||
491 |
#ifdef DONT_SORT_SQL |
|
492 |
_LIT(KSqlSort, " limit 1"); |
|
493 |
iSqlBuffer.Append(KSqlSort); |
|
494 |
#else |
|
495 |
_LIT(KSqlNoSort, " order by dl_index limit 1"); |
|
496 |
iSqlBuffer.Append(KSqlNoSort); |
|
497 |
#endif |
|
498 |
||
499 |
sqlite3_stmt *st; |
|
500 |
||
501 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
502 |
&st, (const void**) NULL); |
|
503 |
||
504 |
if (rc == SQLITE_OK) |
|
505 |
{ |
|
506 |
rc = sqlite3_step(st); |
|
507 |
Cleanup_sqlite3_finalize_PushL(st); |
|
508 |
if (rc == SQLITE_ROW) |
|
509 |
{ |
|
510 |
showInfo = CShowInfo::NewLC(); |
|
511 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
512 |
CleanupStack::Pop(showInfo); |
|
513 |
} |
|
78 | 514 |
else |
515 |
{ |
|
516 |
User::Leave(KErrUnknown); |
|
517 |
} |
|
2 | 518 |
CleanupStack::PopAndDestroy();//st |
519 |
} |
|
78 | 520 |
else |
521 |
{ |
|
522 |
User::Leave(KErrCorrupt); |
|
523 |
} |
|
2 | 524 |
|
525 |
return showInfo; |
|
526 |
} |
|
527 |
||
528 |
void CShowEngine::DBGetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid) |
|
529 |
{ |
|
530 |
DP1("CShowEngine::DBGetShowsByFeed BEGIN, feedUid=%u", aFeedUid); |
|
531 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where feeduid=%u"); |
|
532 |
iSqlBuffer.Format(KSqlStatement, aFeedUid); |
|
533 |
||
534 |
#ifndef DONT_SORT_SQL |
|
535 |
_LIT(KSqlOrderByDate, " order by pubdate desc"); |
|
536 |
iSqlBuffer.Append(KSqlOrderByDate); |
|
537 |
#endif |
|
538 |
||
539 |
sqlite3_stmt *st; |
|
540 |
||
541 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
542 |
&st, (const void**) NULL); |
|
543 |
||
544 |
if (rc == SQLITE_OK) |
|
545 |
{ |
|
546 |
rc = sqlite3_step(st); |
|
547 |
Cleanup_sqlite3_finalize_PushL(st); |
|
548 |
while (rc == SQLITE_ROW) |
|
549 |
{ |
|
550 |
CShowInfo* showInfo = CShowInfo::NewLC(); |
|
551 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
552 |
aShowArray.Append(showInfo); |
|
553 |
CleanupStack::Pop(showInfo); |
|
554 |
rc = sqlite3_step(st); |
|
555 |
} |
|
556 |
CleanupStack::PopAndDestroy();//st |
|
557 |
} |
|
78 | 558 |
else |
559 |
{ |
|
560 |
User::Leave(KErrCorrupt); |
|
561 |
} |
|
2 | 562 |
DP("CShowEngine::DBGetShowsByFeed END"); |
563 |
} |
|
564 |
||
78 | 565 |
TUint CShowEngine::DBGetDownloadsCountL() |
2 | 566 |
{ |
567 |
DP("CShowEngine::DBGetDownloadsCount"); |
|
568 |
||
569 |
_LIT(KSqlStatement, "select count(*) from downloads"); |
|
570 |
iSqlBuffer.Format(KSqlStatement); |
|
571 |
||
572 |
sqlite3_stmt *st; |
|
573 |
TUint count = 0; |
|
574 |
||
575 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
576 |
&st, (const void**) NULL); |
|
577 |
||
578 |
if (rc == SQLITE_OK) |
|
579 |
{ |
|
78 | 580 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 581 |
rc = sqlite3_step(st); |
582 |
||
583 |
if (rc == SQLITE_ROW) |
|
584 |
{ |
|
585 |
count = sqlite3_column_int(st, 0); |
|
586 |
} |
|
78 | 587 |
else |
588 |
{ |
|
589 |
User::Leave(KErrUnknown); |
|
590 |
} |
|
591 |
||
592 |
CleanupStack::PopAndDestroy(); //st |
|
593 |
} |
|
594 |
else |
|
595 |
{ |
|
596 |
User::Leave(KErrCorrupt); |
|
2 | 597 |
} |
598 |
return count; |
|
599 |
} |
|
600 |
||
601 |
void CShowEngine::DBGetDownloadedShowsL(RShowInfoArray& aShowArray) |
|
602 |
{ |
|
603 |
DP("CShowEngine::DBGetDownloadedShows"); |
|
604 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where downloadstate=%u"); |
|
605 |
iSqlBuffer.Format(KSqlStatement, EDownloaded); |
|
606 |
||
607 |
#ifndef DONT_SORT_SQL |
|
608 |
_LIT(KSqlSort, " order by title"); |
|
609 |
iSqlBuffer.Append(KSqlSort); |
|
610 |
#endif |
|
611 |
||
612 |
sqlite3_stmt *st; |
|
613 |
||
614 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
615 |
&st, (const void**) NULL); |
|
616 |
||
617 |
if (rc == SQLITE_OK) |
|
618 |
{ |
|
619 |
rc = sqlite3_step(st); |
|
620 |
Cleanup_sqlite3_finalize_PushL(st); |
|
621 |
while (rc == SQLITE_ROW) |
|
622 |
{ |
|
623 |
CShowInfo* showInfo = CShowInfo::NewLC(); |
|
624 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
625 |
aShowArray.Append(showInfo); |
|
626 |
CleanupStack::Pop(showInfo); |
|
627 |
rc = sqlite3_step(st); |
|
628 |
} |
|
629 |
CleanupStack::PopAndDestroy();//st |
|
630 |
} |
|
78 | 631 |
else |
632 |
{ |
|
633 |
User::Leave(KErrCorrupt); |
|
634 |
} |
|
2 | 635 |
} |
636 |
||
637 |
void CShowEngine::DBGetNewShowsL(RShowInfoArray& aShowArray) |
|
638 |
{ |
|
639 |
DP("CShowEngine::DBGetNewShows"); |
|
640 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where playstate=%u"); |
|
641 |
iSqlBuffer.Format(KSqlStatement, ENeverPlayed); |
|
642 |
||
643 |
sqlite3_stmt *st; |
|
644 |
||
645 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
646 |
&st, (const void**) NULL); |
|
647 |
||
648 |
if (rc == SQLITE_OK) |
|
649 |
{ |
|
650 |
rc = sqlite3_step(st); |
|
651 |
Cleanup_sqlite3_finalize_PushL(st); |
|
652 |
while (rc == SQLITE_ROW) |
|
653 |
{ |
|
654 |
CShowInfo* showInfo = CShowInfo::NewLC(); |
|
655 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
656 |
aShowArray.Append(showInfo); |
|
657 |
CleanupStack::Pop(showInfo); |
|
658 |
rc = sqlite3_step(st); |
|
659 |
} |
|
660 |
CleanupStack::PopAndDestroy();//st |
|
661 |
} |
|
78 | 662 |
else |
663 |
{ |
|
664 |
User::Leave(KErrCorrupt); |
|
665 |
} |
|
2 | 666 |
} |
667 |
||
78 | 668 |
void CShowEngine::DBDeleteOldShowsByFeedL(TUint aFeedUid) |
2 | 669 |
{ |
670 |
DP("CShowEngine::DBDeleteOldShows"); |
|
671 |
||
672 |
// what we do: |
|
673 |
// 1. sort shows by pubdate |
|
674 |
// 2. select the first MaxListItems shows |
|
675 |
// 3. delete the rest if downloadstate is ENotDownloaded |
|
676 |
||
677 |
_LIT(KSqlStatement,"delete from shows where feeduid=%u and downloadstate=0 and uid not in " \ |
|
678 |
"(select uid from shows where feeduid=%u order by pubdate desc limit %u)"); |
|
679 |
iSqlBuffer.Format(KSqlStatement, aFeedUid, aFeedUid, iPodcastModel.SettingsEngine().MaxListItems()); |
|
680 |
||
681 |
sqlite3_stmt *st; |
|
682 |
||
683 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
684 |
&st, (const void**) NULL); |
|
685 |
||
686 |
if (rc == SQLITE_OK) |
|
687 |
{ |
|
688 |
rc = sqlite3_step(st); |
|
689 |
sqlite3_finalize(st); |
|
690 |
} |
|
78 | 691 |
else |
692 |
{ |
|
693 |
User::Leave(KErrCorrupt); |
|
694 |
} |
|
2 | 695 |
|
696 |
_LIT(KSqlStatement2, "delete from downloads where uid not in (select downloads.uid from shows, downloads where shows.uid=downloads.uid)"); |
|
697 |
iSqlBuffer.Format(KSqlStatement2); |
|
698 |
||
699 |
rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, &st, (const void**) NULL); |
|
700 |
||
701 |
if (rc == SQLITE_OK) |
|
702 |
{ |
|
703 |
rc = sqlite3_step(st); |
|
704 |
sqlite3_finalize(st); |
|
705 |
} |
|
78 | 706 |
else |
707 |
{ |
|
708 |
User::Leave(KErrCorrupt); |
|
709 |
} |
|
2 | 710 |
} |
711 |
||
712 |
void CShowEngine::DBFillShowInfoFromStmtL(sqlite3_stmt *st, CShowInfo* showInfo) |
|
713 |
{ |
|
714 |
const void *urlz = sqlite3_column_text16(st, 0); |
|
715 |
TPtrC16 url((const TUint16*) urlz); |
|
716 |
showInfo->SetUrlL(url); |
|
717 |
||
718 |
const void *titlez = sqlite3_column_text16(st, 1); |
|
719 |
TPtrC16 title((const TUint16*) titlez); |
|
720 |
showInfo->SetTitleL(title); |
|
721 |
||
722 |
const void *descz = sqlite3_column_text16(st, 2); |
|
723 |
TPtrC16 desc((const TUint16*) descz); |
|
724 |
showInfo->SetDescriptionL(desc); |
|
725 |
||
726 |
const void *filez = sqlite3_column_text16(st, 3); |
|
727 |
TPtrC16 file((const TUint16*) filez); |
|
728 |
showInfo->SetFileNameL(file); |
|
729 |
||
730 |
sqlite3_int64 pos = sqlite3_column_int64(st, 4); |
|
731 |
TTimeIntervalMicroSeconds position(pos); |
|
732 |
showInfo->SetPosition(position); |
|
733 |
||
734 |
TUint playtime = sqlite3_column_int(st, 5); |
|
735 |
showInfo->SetPlayTime(playtime); |
|
736 |
||
737 |
TUint playstate = sqlite3_column_int(st, 6); |
|
738 |
showInfo->SetPlayState((TPlayState) playstate); |
|
739 |
||
740 |
TUint downloadstate = sqlite3_column_int(st, 7); |
|
741 |
showInfo->SetDownloadState((TDownloadState) downloadstate); |
|
742 |
||
743 |
TUint feeduid = sqlite3_column_int(st, 8); |
|
744 |
showInfo->SetFeedUid(feeduid); |
|
745 |
||
746 |
TUint uid = sqlite3_column_int(st, 9); |
|
747 |
showInfo->SetUid(uid); |
|
748 |
||
749 |
TUint showsize = sqlite3_column_int(st, 10); |
|
750 |
showInfo->SetShowSize(showsize); |
|
751 |
||
752 |
TUint trackno = sqlite3_column_int(st, 11); |
|
753 |
showInfo->SetTrackNo((TShowType) trackno); |
|
754 |
||
755 |
sqlite3_int64 pubdate = sqlite3_column_int64(st, 12); |
|
756 |
TTime timepubdate(pubdate); |
|
757 |
showInfo->SetPubDate(timepubdate); |
|
758 |
||
759 |
TUint showtype = sqlite3_column_int(st, 13); |
|
760 |
showInfo->SetShowType((TShowType) showtype); |
|
761 |
||
762 |
TInt lasterror = sqlite3_column_int(st, 14); |
|
763 |
showInfo->SetLastError(lasterror); |
|
764 |
} |
|
765 |
||
78 | 766 |
void CShowEngine::DBAddShowL(const CShowInfo& aItem) |
2 | 767 |
{ |
768 |
DP2("CShowEngine::DBAddShow, title=%S, URL=%S", &aItem.Title(), &aItem.Url()); |
|
769 |
||
21 | 770 |
HBufC* titleBuf = HBufC::NewLC(KMaxLineLength); |
771 |
TPtr titlePtr(titleBuf->Des()); |
|
772 |
titlePtr.Copy(aItem.Title()); |
|
773 |
PodcastUtils::SQLEncode(titlePtr); |
|
774 |
||
775 |
HBufC* descBuf = HBufC::NewLC(KMaxLineLength); |
|
776 |
TPtr descPtr(descBuf->Des()); |
|
777 |
descPtr.Copy(aItem.Description()); |
|
778 |
PodcastUtils::SQLEncode(descPtr); |
|
779 |
||
2 | 780 |
_LIT(KSqlStatement, "insert into shows (url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype)" |
781 |
" values (\"%S\",\"%S\", \"%S\", \"%S\", \"%Lu\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%Lu\", \"%d\")"); |
|
21 | 782 |
|
783 |
iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr, |
|
2 | 784 |
&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(), |
785 |
aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(), |
|
786 |
aItem.Uid(), aItem.ShowSize(), aItem.TrackNo(), |
|
787 |
aItem.PubDate().Int64(), aItem.ShowType()); |
|
788 |
||
21 | 789 |
CleanupStack::PopAndDestroy(descBuf); |
790 |
CleanupStack::PopAndDestroy(titleBuf); |
|
791 |
||
2 | 792 |
sqlite3_stmt *st; |
793 |
||
794 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
795 |
&st, (const void**) NULL); |
|
78 | 796 |
|
2 | 797 |
if (rc == SQLITE_OK) |
798 |
{ |
|
78 | 799 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 800 |
rc = sqlite3_step(st); |
78 | 801 |
if (rc != SQLITE_DONE) |
2 | 802 |
{ |
78 | 803 |
User::Leave(KErrAlreadyExists); |
2 | 804 |
} |
78 | 805 |
CleanupStack::PopAndDestroy(); // st |
2 | 806 |
} |
807 |
else |
|
808 |
{ |
|
78 | 809 |
User::Leave(KErrCorrupt); |
2 | 810 |
} |
811 |
} |
|
812 |
||
78 | 813 |
void CShowEngine::DBAddDownloadL(TUint aUid) |
2 | 814 |
{ |
815 |
DP1("CShowEngine::DBAddDownload, aUid=%u", aUid); |
|
816 |
||
817 |
_LIT(KSqlStatement, "insert into downloads (uid) values (%u)"); |
|
818 |
iSqlBuffer.Format(KSqlStatement, aUid); |
|
819 |
sqlite3_stmt *st; |
|
820 |
||
821 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
822 |
&st, (const void**) NULL); |
|
823 |
||
824 |
if (rc == SQLITE_OK) |
|
825 |
{ |
|
78 | 826 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 827 |
rc = sqlite3_step(st); |
78 | 828 |
if (rc =! SQLITE_DONE) |
829 |
{ |
|
830 |
User::Leave(KErrUnknown); |
|
831 |
} |
|
832 |
CleanupStack::PopAndDestroy(); // st |
|
2 | 833 |
} |
78 | 834 |
else |
835 |
{ |
|
836 |
User::Leave(KErrCorrupt); |
|
837 |
} |
|
2 | 838 |
} |
839 |
||
78 | 840 |
void CShowEngine::DBUpdateShowL(CShowInfo& aItem) |
2 | 841 |
{ |
842 |
DP1("CShowEngine::DBUpdateShow, title='%S'", &aItem.Title()); |
|
843 |
||
30
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
844 |
HBufC* titleBuf = HBufC::NewLC(KMaxLineLength); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
845 |
TPtr titlePtr(titleBuf->Des()); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
846 |
titlePtr.Copy(aItem.Title()); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
847 |
PodcastUtils::SQLEncode(titlePtr); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
848 |
|
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
849 |
HBufC* descBuf = HBufC::NewLC(KMaxLineLength); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
850 |
TPtr descPtr(descBuf->Des()); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
851 |
descPtr.Copy(aItem.Description()); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
852 |
PodcastUtils::SQLEncode(descPtr); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
853 |
|
2 | 854 |
_LIT(KSqlStatement, "update shows set url=\"%S\", title=\"%S\", description=\"%S\", filename=\"%S\", position=\"%Lu\"," |
855 |
"playtime=\"%u\", playstate=\"%u\", downloadstate=\"%u\", feeduid=\"%u\", showsize=\"%u\", trackno=\"%u\"," |
|
856 |
"pubdate=\"%Lu\", showtype=\"%d\", lasterror=\"%d\" where uid=\"%u\""); |
|
30
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
857 |
iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr, |
2 | 858 |
&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(), |
859 |
aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(), |
|
860 |
aItem.ShowSize(), aItem.TrackNo(), aItem.PubDate().Int64(), |
|
861 |
aItem.ShowType(), aItem.LastError(), aItem.Uid()); |
|
862 |
||
30
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
863 |
CleanupStack::PopAndDestroy(descBuf); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
864 |
CleanupStack::PopAndDestroy(titleBuf); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
865 |
|
2 | 866 |
sqlite3_stmt *st; |
867 |
||
868 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
869 |
&st, (const void**) NULL); |
|
870 |
||
871 |
if (rc == SQLITE_OK) |
|
872 |
{ |
|
78 | 873 |
Cleanup_sqlite3_finalize_PushL(st); |
874 |
rc = sqlite3_step(st); |
|
2 | 875 |
|
78 | 876 |
if (rc =! SQLITE_DONE) |
2 | 877 |
{ |
78 | 878 |
User::Leave(KErrUnknown); |
2 | 879 |
} |
78 | 880 |
CleanupStack::PopAndDestroy(); // st |
2 | 881 |
} |
882 |
else |
|
883 |
{ |
|
78 | 884 |
User::Leave(KErrCorrupt); |
2 | 885 |
} |
886 |
} |
|
887 |
||
78 | 888 |
void CShowEngine::DBDeleteShowL(TUint aUid) |
2 | 889 |
{ |
890 |
DP("CShowEngine::DBDeleteShow"); |
|
891 |
||
892 |
_LIT(KSqlStatement, "delete from shows where uid=%u"); |
|
893 |
iSqlBuffer.Format(KSqlStatement, aUid); |
|
894 |
||
895 |
sqlite3_stmt *st; |
|
896 |
||
897 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
898 |
&st, (const void**) NULL); |
|
899 |
||
900 |
if (rc == SQLITE_OK) |
|
901 |
{ |
|
78 | 902 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 903 |
rc = sqlite3_step(st); |
904 |
||
78 | 905 |
if (rc =! SQLITE_DONE) |
2 | 906 |
{ |
78 | 907 |
User::Leave(KErrUnknown); |
2 | 908 |
} |
78 | 909 |
CleanupStack::PopAndDestroy(); // st |
2 | 910 |
} |
911 |
else |
|
912 |
{ |
|
78 | 913 |
User::Leave(KErrCorrupt); |
2 | 914 |
} |
915 |
} |
|
916 |
||
78 | 917 |
void CShowEngine::DBDeleteAllShowsByFeedL(TUint aFeedUid) |
2 | 918 |
{ |
919 |
DP("CShowEngine::DBDeleteAllShowsByFeed"); |
|
920 |
||
921 |
_LIT(KSqlStatement, "delete from shows where feeduid=%u"); |
|
922 |
iSqlBuffer.Format(KSqlStatement, aFeedUid); |
|
923 |
||
924 |
sqlite3_stmt *st; |
|
925 |
||
926 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
927 |
&st, (const void**) NULL); |
|
928 |
||
929 |
if (rc == SQLITE_OK) |
|
930 |
{ |
|
78 | 931 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 932 |
rc = sqlite3_step(st); |
933 |
||
78 | 934 |
if (rc =! SQLITE_DONE) |
2 | 935 |
{ |
78 | 936 |
User::Leave(KErrUnknown); |
2 | 937 |
} |
78 | 938 |
CleanupStack::PopAndDestroy(); // st |
2 | 939 |
} |
940 |
else |
|
941 |
{ |
|
78 | 942 |
User::Leave(KErrCorrupt); |
2 | 943 |
} |
944 |
} |
|
945 |
||
78 | 946 |
void CShowEngine::DBRemoveAllDownloadsL() |
2 | 947 |
{ |
948 |
DP("CShowEngine::DBRemoveAllDownloads"); |
|
949 |
||
950 |
_LIT(KSqlStatement, "delete from downloads"); |
|
951 |
iSqlBuffer.Format(KSqlStatement); |
|
952 |
||
953 |
sqlite3_stmt *st; |
|
954 |
||
955 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
956 |
&st, (const void**) NULL); |
|
957 |
||
958 |
if (rc == SQLITE_OK) |
|
959 |
{ |
|
960 |
rc = sqlite3_step(st); |
|
961 |
sqlite3_finalize(st); |
|
962 |
} |
|
78 | 963 |
else |
964 |
{ |
|
965 |
User::Leave(KErrCorrupt); |
|
966 |
} |
|
2 | 967 |
|
968 |
_LIT(KSqlStatement2, "update shows set downloadstate=0 where downloadstate=1"); |
|
969 |
iSqlBuffer.Format(KSqlStatement2); |
|
970 |
||
971 |
rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, &st, |
|
972 |
(const void**) NULL); |
|
973 |
||
974 |
if (rc == SQLITE_OK) |
|
975 |
{ |
|
78 | 976 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 977 |
rc = sqlite3_step(st); |
78 | 978 |
if (rc =! SQLITE_DONE) |
979 |
{ |
|
980 |
User::Leave(KErrUnknown); |
|
981 |
} |
|
982 |
CleanupStack::PopAndDestroy(); // st |
|
983 |
} |
|
984 |
else |
|
985 |
{ |
|
986 |
User::Leave(KErrCorrupt); |
|
2 | 987 |
} |
988 |
||
989 |
} |
|
990 |
||
78 | 991 |
void CShowEngine::DBRemoveDownloadL(TUint aUid) |
2 | 992 |
{ |
993 |
DP("CShowEngine::DBRemoveDownload"); |
|
994 |
||
995 |
_LIT(KSqlStatement, "delete from downloads where uid=%u"); |
|
996 |
iSqlBuffer.Format(KSqlStatement, aUid); |
|
997 |
||
998 |
sqlite3_stmt *st; |
|
999 |
||
1000 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
1001 |
&st, (const void**) NULL); |
|
1002 |
||
1003 |
if (rc == SQLITE_OK) |
|
1004 |
{ |
|
78 | 1005 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 1006 |
rc = sqlite3_step(st); |
78 | 1007 |
if (rc =! SQLITE_DONE) |
1008 |
{ |
|
1009 |
User::Leave(KErrUnknown); |
|
1010 |
} |
|
1011 |
CleanupStack::PopAndDestroy(); // st |
|
1012 |
} |
|
1013 |
else |
|
1014 |
{ |
|
1015 |
User::Leave(KErrCorrupt); |
|
2 | 1016 |
} |
1017 |
} |
|
1018 |
||
1019 |
EXPORT_C CShowInfo* CShowEngine::GetNextShowByTrackL(CShowInfo* aShowInfo) |
|
1020 |
{ |
|
1021 |
CShowInfo* nextShow = NULL; |
|
1022 |
RShowInfoArray array; |
|
1023 |
DBGetShowsByFeedL(array, aShowInfo->FeedUid()); |
|
1024 |
TUint diff = KMaxTInt; |
|
1025 |
for (TInt loop = 0; loop < array.Count(); loop++) |
|
1026 |
{ |
|
1027 |
if (aShowInfo->TrackNo() < array[loop]->TrackNo()) |
|
1028 |
{ |
|
1029 |
if ((array[loop]->TrackNo() - aShowInfo->TrackNo()) < diff) |
|
1030 |
{ |
|
1031 |
diff = array[loop]->TrackNo() - aShowInfo->TrackNo(); |
|
1032 |
nextShow = array[loop]; |
|
1033 |
} |
|
1034 |
} |
|
1035 |
} |
|
1036 |
array.ResetAndDestroy(); |
|
1037 |
return nextShow; |
|
1038 |
} |
|
1039 |
||
1040 |
TBool CShowEngine::CompareShowsByUid(const CShowInfo &a, const CShowInfo &b) |
|
1041 |
{ |
|
1042 |
return a.Uid() == b.Uid(); |
|
1043 |
} |
|
1044 |
||
1045 |
TInt CShowEngine::CompareShowsByDate(const CShowInfo &a, const CShowInfo &b) |
|
1046 |
{ |
|
1047 |
if (a.PubDate() > b.PubDate()) |
|
1048 |
{ |
|
1049 |
// DP2("Sorting %S less than %S", &a.iTitle, &b.iTitle); |
|
1050 |
return -1; |
|
1051 |
} |
|
1052 |
else if (a.PubDate() == b.PubDate()) |
|
1053 |
{ |
|
1054 |
// DP2("Sorting %S equal to %S", &a.iTitle, &b.iTitle); |
|
1055 |
return 0; |
|
1056 |
} |
|
1057 |
else |
|
1058 |
{ |
|
1059 |
// DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle); |
|
1060 |
return 1; |
|
1061 |
} |
|
1062 |
} |
|
1063 |
||
1064 |
TInt CShowEngine::CompareShowsByTrackNo(const CShowInfo &a, const CShowInfo &b) |
|
1065 |
{ |
|
1066 |
if (a.TrackNo() < b.TrackNo()) |
|
1067 |
{ |
|
1068 |
return -1; |
|
1069 |
} |
|
1070 |
else if (a.TrackNo() == b.TrackNo()) |
|
1071 |
{ |
|
1072 |
return 0; |
|
1073 |
} |
|
1074 |
else |
|
1075 |
{ |
|
1076 |
return 1; |
|
1077 |
} |
|
1078 |
} |
|
1079 |
||
1080 |
TInt CShowEngine::CompareShowsByTitle(const CShowInfo &a, const CShowInfo &b) |
|
1081 |
{ |
|
1082 |
if (a.Title() < b.Title()) |
|
1083 |
{ |
|
1084 |
// DP2("Sorting %S less than %S", &a.iTitle, &b.iTitle); |
|
1085 |
return -1; |
|
1086 |
} |
|
1087 |
else if (a.Title() == b.Title()) |
|
1088 |
{ |
|
1089 |
// DP2("Sorting %S equal to %S", &a.iTitle, &b.iTitle); |
|
1090 |
return 0; |
|
1091 |
} |
|
1092 |
else |
|
1093 |
{ |
|
1094 |
// DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle); |
|
1095 |
return 1; |
|
1096 |
} |
|
1097 |
} |
|
1098 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1099 |
EXPORT_C void CShowEngine::DeletePlayedShowsL(RShowInfoArray &aShowInfoArray) |
2 | 1100 |
{ |
1101 |
for (TInt i = 0; i < aShowInfoArray.Count(); i++) |
|
1102 |
{ |
|
1103 |
if (aShowInfoArray[i]->PlayState() == EPlayed |
|
1104 |
&& aShowInfoArray[i]->FileName().Length() > 0) |
|
1105 |
{ |
|
1106 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(), aShowInfoArray[i]->FileName()); |
|
1107 |
aShowInfoArray[i]->SetDownloadState(ENotDownloaded); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1108 |
DBUpdateShowL(*aShowInfoArray[i]); |
2 | 1109 |
} |
1110 |
} |
|
1111 |
} |
|
1112 |
||
1113 |
EXPORT_C void CShowEngine::DeleteAllShowsByFeedL(TUint aFeedUid, TBool aDeleteFiles) |
|
1114 |
{ |
|
1115 |
RShowInfoArray array; |
|
1116 |
DBGetShowsByFeedL(array, aFeedUid); |
|
1117 |
||
1118 |
const TInt count = array.Count(); |
|
1119 |
||
1120 |
for (TInt i = count - 1; i >= 0; i--) |
|
1121 |
{ |
|
52 | 1122 |
if (iShowDownloading && iShowDownloading->Uid() == array[i]->Uid()) |
1123 |
{ |
|
1124 |
// trying to delete the active download |
|
1125 |
RemoveDownloadL(iShowDownloading->Uid()); |
|
1126 |
} |
|
1127 |
||
1128 |
// delete downloaded file |
|
2 | 1129 |
if (array[i]->FileName().Length() > 0) |
1130 |
{ |
|
1131 |
if (aDeleteFiles) |
|
1132 |
{ |
|
1133 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(), array[i]->FileName()); |
|
1134 |
} |
|
1135 |
} |
|
1136 |
} |
|
1137 |
array.ResetAndDestroy(); |
|
52 | 1138 |
|
1139 |
// delete all shows from DB |
|
78 | 1140 |
DBDeleteAllShowsByFeedL(aFeedUid); |
52 | 1141 |
|
1142 |
// this will clear out deleted shows from the download queue |
|
1143 |
DBGetAllDownloadsL(array); |
|
1144 |
array.ResetAndDestroy(); |
|
1145 |
||
1146 |
NotifyDownloadQueueUpdatedL(); |
|
2 | 1147 |
} |
1148 |
||
78 | 1149 |
EXPORT_C void CShowEngine::DeleteOldShowsByFeedL(TUint aFeedUid) |
2 | 1150 |
{ |
78 | 1151 |
DBDeleteOldShowsByFeedL(aFeedUid); |
2 | 1152 |
} |
1153 |
||
1154 |
EXPORT_C void CShowEngine::DeleteShowL(TUint aShowUid, TBool aRemoveFile) |
|
1155 |
{ |
|
1156 |
||
1157 |
CShowInfo *info = DBGetShowByUidL(aShowUid); |
|
1158 |
||
1159 |
if (info != NULL) |
|
1160 |
{ |
|
1161 |
if (info->FileName().Length() > 0 && aRemoveFile) |
|
1162 |
{ |
|
1163 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(), info->FileName()); |
|
1164 |
} |
|
1165 |
||
1166 |
info->SetDownloadState(ENotDownloaded); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1167 |
DBUpdateShowL(*info); |
2 | 1168 |
delete info; |
1169 |
} |
|
1170 |
} |
|
1171 |
||
1172 |
EXPORT_C void CShowEngine::GetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid) |
|
1173 |
{ |
|
1174 |
DP("CShowEngine::GetShowsByFeed"); |
|
1175 |
DBGetShowsByFeedL(aShowArray, aFeedUid); |
|
1176 |
} |
|
1177 |
||
1178 |
EXPORT_C void CShowEngine::GetAllShowsL(RShowInfoArray &aArray) |
|
1179 |
{ |
|
1180 |
DP("CShowEngine::GetAllShows"); |
|
1181 |
DBGetAllShowsL(aArray); |
|
1182 |
} |
|
1183 |
||
1184 |
EXPORT_C void CShowEngine::GetShowsDownloadedL(RShowInfoArray &aArray) |
|
1185 |
{ |
|
1186 |
DP("CShowEngine::GetShowsDownloaded"); |
|
1187 |
DBGetDownloadedShowsL(aArray); |
|
1188 |
} |
|
1189 |
||
1190 |
EXPORT_C void CShowEngine::GetNewShowsL(RShowInfoArray &aArray) |
|
1191 |
{ |
|
1192 |
DP("CShowEngine::GetNewShows"); |
|
1193 |
DBGetNewShowsL(aArray); |
|
1194 |
} |
|
1195 |
||
1196 |
EXPORT_C void CShowEngine::GetShowsDownloadingL(RShowInfoArray &aArray) |
|
1197 |
{ |
|
1198 |
DP("CShowEngine::GetShowsDownloading"); |
|
1199 |
DBGetAllDownloadsL(aArray); |
|
1200 |
} |
|
1201 |
||
1202 |
EXPORT_C TInt CShowEngine::GetNumDownloadingShows() |
|
1203 |
{ |
|
78 | 1204 |
TUint count; |
1205 |
TRAP_IGNORE(count = DBGetDownloadsCountL()); |
|
1206 |
||
1207 |
return (const TInt) count; |
|
2 | 1208 |
} |
1209 |
||
1210 |
EXPORT_C void CShowEngine::AddDownloadL(CShowInfo& aInfo) |
|
1211 |
{ |
|
1212 |
aInfo.SetDownloadState(EQueued); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1213 |
DBUpdateShowL(aInfo); |
78 | 1214 |
DBAddDownloadL(aInfo.Uid()); |
2 | 1215 |
DownloadNextShowL(); |
1216 |
} |
|
1217 |
||
1218 |
void CShowEngine::DownloadNextShowL() |
|
1219 |
{ |
|
1220 |
DP("CShowEngine::DownloadNextShowL BEGIN"); |
|
1221 |
// Check if we have anything in the download queue |
|
78 | 1222 |
const TInt count = DBGetDownloadsCountL(); |
2 | 1223 |
DP("CShowEngine::DownloadNextShow\tTrying to start new download");DP1("CShowEngine::DownloadNextShow\tShows in download queue %d", count); |
1224 |
||
1225 |
if (count > 0) |
|
1226 |
{ |
|
1227 |
if (iPodcastModel.SettingsEngine().DownloadSuspended()) |
|
1228 |
{ |
|
1229 |
DP("CShowEngine::DownloadNextShow\tDownload process is suspended, ABORTING"); |
|
34 | 1230 |
// Inform the observers |
1231 |
NotifyDownloadQueueUpdatedL(); |
|
2 | 1232 |
return; |
1233 |
} |
|
1234 |
else if (iShowClient->IsActive()) |
|
1235 |
{ |
|
1236 |
DP("CShowEngine::DownloadNextShow\tDownload process is already active."); |
|
34 | 1237 |
// Inform the observers |
1238 |
NotifyDownloadQueueUpdatedL(); |
|
2 | 1239 |
return; |
1240 |
} |
|
1241 |
else |
|
1242 |
{ |
|
1243 |
||
1244 |
// Start the download |
|
1245 |
||
1246 |
CShowInfo *info = DBGetNextDownloadL(); |
|
1247 |
||
1248 |
while(info != NULL) |
|
1249 |
{ |
|
1250 |
DP1("CShowEngine::DownloadNextShow\tDownloading: %S", &(info->Title())); |
|
1251 |
info->SetDownloadState(EDownloading); |
|
1252 |
info->SetLastError(KErrNone); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1253 |
DBUpdateShowL(*info); |
2 | 1254 |
iShowDownloading = info; |
34 | 1255 |
// Inform the observers |
1256 |
// important to do this after we change download state |
|
1257 |
NotifyDownloadQueueUpdatedL(); |
|
1258 |
||
78 | 1259 |
TRAPD(error,GetShowL(info)); |
1260 |
if (error != KErrNone) |
|
2 | 1261 |
{ |
1262 |
info->SetDownloadState(EFailedDownload); |
|
78 | 1263 |
DBRemoveDownloadL(info->Uid()); |
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1264 |
DBUpdateShowL(*info); |
2 | 1265 |
info = DBGetNextDownloadL(); |
1266 |
||
1267 |
if(info == NULL) |
|
1268 |
{ |
|
1269 |
iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue); |
|
1270 |
iShowDownloading = NULL; |
|
1271 |
} |
|
1272 |
} |
|
1273 |
else |
|
1274 |
{ |
|
1275 |
break; |
|
1276 |
} |
|
1277 |
} |
|
1278 |
} |
|
1279 |
} |
|
1280 |
else |
|
1281 |
{ |
|
34 | 1282 |
// Inform the observers |
1283 |
NotifyDownloadQueueUpdatedL(); |
|
2 | 1284 |
iShowDownloading = NULL;DP("CShowEngine::DownloadNextShow\tNothing to download"); |
1285 |
} |
|
1286 |
DP("CShowEngine::DownloadNextShowL END"); |
|
1287 |
} |
|
1288 |
||
1289 |
void CShowEngine::NotifyDownloadQueueUpdatedL() |
|
1290 |
{ |
|
1291 |
const TInt count = iObservers.Count(); |
|
1292 |
for (TInt i = 0; i < count; i++) |
|
1293 |
{ |
|
78 | 1294 |
iObservers[i]->DownloadQueueUpdatedL(1, DBGetDownloadsCountL() - 1); |
2 | 1295 |
} |
1296 |
} |
|
1297 |
||
1298 |
void CShowEngine::NotifyShowDownloadUpdatedL(TInt aBytesOfCurrentDownload, TInt aBytesTotal) |
|
1299 |
{ |
|
1300 |
const TInt count = iObservers.Count(); |
|
1301 |
for (TInt i = 0; i < count; i++) |
|
1302 |
{ |
|
1303 |
iObservers[i]->ShowDownloadUpdatedL(aBytesOfCurrentDownload, aBytesTotal); |
|
1304 |
} |
|
1305 |
} |
|
1306 |
||
1307 |
void CShowEngine::NotifyShowFinishedL(TInt aError) |
|
1308 |
{ |
|
1309 |
const TInt count = iObservers.Count(); |
|
1310 |
for (TInt i = 0; i < count; i++) |
|
1311 |
{ |
|
1312 |
iObservers[i]->ShowDownloadFinishedL(iShowDownloading?iShowDownloading->Uid():0, aError); |
|
1313 |
} |
|
1314 |
} |
|
1315 |
||
1316 |
EXPORT_C void CShowEngine::NotifyShowListUpdatedL() |
|
1317 |
{ |
|
1318 |
for (TInt i = 0; i < iObservers.Count(); i++) |
|
1319 |
{ |
|
1320 |
iObservers[i]->ShowListUpdatedL(); |
|
1321 |
} |
|
1322 |
} |
|
1323 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1324 |
void CShowEngine::ReadMetaDataL(CShowInfo& aShowInfo) |
2 | 1325 |
{ |
1326 |
//DP1("Read %S", &(aShowInfo->Title())); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1327 |
DBUpdateShowL(aShowInfo); |
2 | 1328 |
} |
1329 |
||
1330 |
void CShowEngine::ReadMetaDataCompleteL() |
|
1331 |
{ |
|
1332 |
NotifyShowListUpdatedL(); |
|
1333 |
MetaDataReader().SetIgnoreTrackNo(EFalse); |
|
1334 |
} |
|
1335 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1336 |
EXPORT_C void CShowEngine::UpdateShowL(CShowInfo& aInfo) |
2 | 1337 |
{ |
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1338 |
DBUpdateShowL(aInfo); |
2 | 1339 |
} |
1340 |
||
1341 |
EXPORT_C CMetaDataReader& CShowEngine::MetaDataReader() |
|
1342 |
{ |
|
1343 |
return *iMetaDataReader; |
|
1344 |
} |
|
1345 |
||
1346 |
void CShowEngine::FileError(TUint /*aError*/) |
|
1347 |
{ |
|
1348 |
iDownloadErrors = KMaxDownloadErrors; |
|
1349 |
} |