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