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