branch | RCL_3 |
changeset 368 | b131f7696342 |
parent 332 | 88a24b8b97d8 |
child 369 | c683165bec63 |
367:4b75876aa85a | 368:b131f7696342 |
---|---|
41 { |
41 { |
42 } |
42 } |
43 |
43 |
44 EXPORT_C CShowEngine::~CShowEngine() |
44 EXPORT_C CShowEngine::~CShowEngine() |
45 { |
45 { |
46 DP("CShowEngine::~CShowEngine BEGIN"); |
|
46 delete iShowClient; |
47 delete iShowClient; |
47 iObservers.Close(); |
48 iObservers.Close(); |
48 delete iShowDownloading; |
49 delete iShowDownloading; |
49 delete iMetaDataReader; |
50 delete iMetaDataReader; |
50 iApaSession.Close(); |
51 iApaSession.Close(); |
52 if (iCollectionHelper) |
53 if (iCollectionHelper) |
53 { |
54 { |
54 iCollectionHelper->Close(); |
55 iCollectionHelper->Close(); |
55 } |
56 } |
56 #endif |
57 #endif |
58 DP("CShowEngine::~CShowEngine END"); |
|
57 } |
59 } |
58 |
60 |
59 EXPORT_C CShowEngine* CShowEngine::NewL(CPodcastModel& aPodcastModel) |
61 EXPORT_C CShowEngine* CShowEngine::NewL(CPodcastModel& aPodcastModel) |
60 { |
62 { |
61 CShowEngine* self = new (ELeave) CShowEngine(aPodcastModel); |
63 CShowEngine* self = new (ELeave) CShowEngine(aPodcastModel); |
393 |
395 |
394 EXPORT_C CShowInfo* CShowEngine::GetShowByUidL(TUint aShowUid) |
396 EXPORT_C CShowInfo* CShowEngine::GetShowByUidL(TUint aShowUid) |
395 { |
397 { |
396 return DBGetShowByUidL(aShowUid); |
398 return DBGetShowByUidL(aShowUid); |
397 } |
399 } |
400 |
|
398 CShowInfo* CShowEngine::DBGetShowByUidL(TUint aUid) |
401 CShowInfo* CShowEngine::DBGetShowByUidL(TUint aUid) |
399 { |
402 { |
400 DP("CShowEngine::DBGetShowByUid"); |
403 DP("CShowEngine::DBGetShowByUid"); |
401 CShowInfo *showInfo = NULL; |
404 CShowInfo *showInfo = NULL; |
402 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows where uid=%u"); |
405 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, deletedate from shows where uid=%u"); |
403 iSqlBuffer.Format(KSqlStatement, aUid); |
406 iSqlBuffer.Format(KSqlStatement, aUid); |
404 |
407 |
405 sqlite3_stmt *st; |
408 sqlite3_stmt *st; |
406 |
409 |
407 //DP1("SQL: %S", &iSqlBuffer.Left(KSqlDPLen)); |
410 //DP1("SQL: %S", &iSqlBuffer.Left(KSqlDPLen)); |
427 |
430 |
428 EXPORT_C CShowInfo* CShowEngine::DBGetShowByFileNameL(TFileName aFileName) |
431 EXPORT_C CShowInfo* CShowEngine::DBGetShowByFileNameL(TFileName aFileName) |
429 { |
432 { |
430 DP("CShowEngine::DBGetShowByUid"); |
433 DP("CShowEngine::DBGetShowByUid"); |
431 CShowInfo *showInfo = NULL; |
434 CShowInfo *showInfo = NULL; |
432 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows where filename=\"%S\""); |
435 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror, deletedate from shows where filename=\"%S\""); |
433 iSqlBuffer.Format(KSqlStatement, &aFileName); |
436 iSqlBuffer.Format(KSqlStatement, &aFileName); |
434 |
437 |
435 sqlite3_stmt *st; |
438 sqlite3_stmt *st; |
436 |
439 |
437 int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
440 int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
454 } |
457 } |
455 |
458 |
456 void CShowEngine::DBGetAllShowsL(RShowInfoArray& aShowArray) |
459 void CShowEngine::DBGetAllShowsL(RShowInfoArray& aShowArray) |
457 { |
460 { |
458 DP("CShowEngine::DBGetAllShows"); |
461 DP("CShowEngine::DBGetAllShows"); |
459 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows"); |
462 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror, deletedate from shows"); |
460 iSqlBuffer.Format(KSqlStatement); |
463 iSqlBuffer.Format(KSqlStatement); |
461 |
464 |
462 sqlite3_stmt *st; |
465 sqlite3_stmt *st; |
463 |
466 |
464 int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
467 int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
482 } |
485 } |
483 |
486 |
484 void CShowEngine::DBGetAllDownloadsL(RShowInfoArray& aShowArray) |
487 void CShowEngine::DBGetAllDownloadsL(RShowInfoArray& aShowArray) |
485 { |
488 { |
486 DP("CShowEngine::DBGetAllDownloads"); |
489 DP("CShowEngine::DBGetAllDownloads"); |
487 _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"); |
490 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, shows.uid, showsize, trackno, pubdate, showtype, lasterror, deletedate from downloads, shows where downloads.uid=shows.uid"); |
488 iSqlBuffer.Format(KSqlStatement); |
491 iSqlBuffer.Format(KSqlStatement); |
489 |
492 |
490 #ifndef DONT_SORT_SQL |
493 #ifndef DONT_SORT_SQL |
491 _LIT(KSqlSort, " order by dl_index"); |
494 _LIT(KSqlSort, " order by dl_index"); |
492 iSqlBuffer.Append(KSqlSort); |
495 iSqlBuffer.Append(KSqlSort); |
532 { |
535 { |
533 User::Leave(KErrCorrupt); |
536 User::Leave(KErrCorrupt); |
534 } |
537 } |
535 } |
538 } |
536 |
539 |
540 void CShowEngine::DBGetOldShowsL(RShowInfoArray& aShowArray) |
|
541 { |
|
542 DP("CShowEngine::DBGetOldShowsL BEGIN"); |
|
543 TTime now; |
|
544 now.HomeTime(); |
|
545 // TTimeIntervalYears years(5); |
|
546 // now += years; |
|
547 |
|
548 _LIT(KSqlStatement, "select filename from shows where downloadstate=%d and deletedate < \"%Ld\""); |
|
549 iSqlBuffer.Format(KSqlStatement, EDownloaded, now.Int64()); |
|
550 |
|
551 sqlite3_stmt *st; |
|
552 |
|
553 int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
554 &st, (const void**) NULL); |
|
555 |
|
556 if (rc == SQLITE_OK) |
|
557 { |
|
558 rc = sqlite3_step(st); |
|
559 Cleanup_sqlite3_finalize_PushL(st); |
|
560 while (rc == SQLITE_ROW) |
|
561 { |
|
562 CShowInfo* showInfo = CShowInfo::NewLC(); |
|
563 |
|
564 const void *filez = sqlite3_column_text16(st, 0); |
|
565 TPtrC16 file((const TUint16*) filez); |
|
566 showInfo->SetFileNameL(file); |
|
567 |
|
568 aShowArray.Append(showInfo); |
|
569 CleanupStack::Pop(showInfo); |
|
570 rc = sqlite3_step(st); |
|
571 } |
|
572 CleanupStack::PopAndDestroy();//st |
|
573 } |
|
574 else |
|
575 { |
|
576 User::Leave(KErrCorrupt); |
|
577 } |
|
578 DP("CShowEngine::DBGetOldShowsL END"); |
|
579 } |
|
580 |
|
537 CShowInfo* CShowEngine::DBGetNextDownloadL() |
581 CShowInfo* CShowEngine::DBGetNextDownloadL() |
538 { |
582 { |
539 DP("CShowEngine::DBGetNextDownload"); |
583 DP("CShowEngine::DBGetNextDownload"); |
540 CShowInfo *showInfo = NULL; |
584 CShowInfo *showInfo = NULL; |
541 _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"); |
585 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, shows.uid, showsize, trackno, pubdate, showtype, lasterror, deletedate from downloads, shows where downloads.uid=shows.uid"); |
542 iSqlBuffer.Format(KSqlStatement); |
586 iSqlBuffer.Format(KSqlStatement); |
543 |
587 |
544 #ifdef DONT_SORT_SQL |
588 #ifdef DONT_SORT_SQL |
545 _LIT(KSqlSort, " limit 1"); |
589 _LIT(KSqlSort, " limit 1"); |
546 iSqlBuffer.Append(KSqlSort); |
590 iSqlBuffer.Append(KSqlSort); |
579 } |
623 } |
580 |
624 |
581 void CShowEngine::DBGetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid) |
625 void CShowEngine::DBGetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid) |
582 { |
626 { |
583 DP1("CShowEngine::DBGetShowsByFeed BEGIN, feedUid=%u", aFeedUid); |
627 DP1("CShowEngine::DBGetShowsByFeed BEGIN, feedUid=%u", aFeedUid); |
584 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where feeduid=%u"); |
628 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror, deletedate from shows where feeduid=%u"); |
585 iSqlBuffer.Format(KSqlStatement, aFeedUid); |
629 iSqlBuffer.Format(KSqlStatement, aFeedUid); |
586 |
630 |
587 #ifndef DONT_SORT_SQL |
631 #ifndef DONT_SORT_SQL |
588 _LIT(KSqlOrderByDate, " order by pubdate desc"); |
632 _LIT(KSqlOrderByDate, " order by pubdate desc"); |
589 iSqlBuffer.Append(KSqlOrderByDate); |
633 iSqlBuffer.Append(KSqlOrderByDate); |
590 #endif |
634 #endif |
591 |
635 |
652 } |
696 } |
653 |
697 |
654 void CShowEngine::DBGetDownloadedShowsL(RShowInfoArray& aShowArray) |
698 void CShowEngine::DBGetDownloadedShowsL(RShowInfoArray& aShowArray) |
655 { |
699 { |
656 DP("CShowEngine::DBGetDownloadedShows"); |
700 DP("CShowEngine::DBGetDownloadedShows"); |
657 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where downloadstate=%u"); |
701 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror, deletedate from shows where downloadstate=%u"); |
658 iSqlBuffer.Format(KSqlStatement, EDownloaded); |
702 iSqlBuffer.Format(KSqlStatement, EDownloaded); |
659 |
703 |
660 #ifndef DONT_SORT_SQL |
704 #ifndef DONT_SORT_SQL |
661 _LIT(KSqlSort, " order by title"); |
705 _LIT(KSqlSort, " order by title"); |
662 iSqlBuffer.Append(KSqlSort); |
706 iSqlBuffer.Append(KSqlSort); |
688 } |
732 } |
689 |
733 |
690 void CShowEngine::DBGetNewShowsL(RShowInfoArray& aShowArray) |
734 void CShowEngine::DBGetNewShowsL(RShowInfoArray& aShowArray) |
691 { |
735 { |
692 DP("CShowEngine::DBGetNewShows"); |
736 DP("CShowEngine::DBGetNewShows"); |
693 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where playstate=%u"); |
737 _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where playstate=%u order by pubdate desc"); |
738 |
|
694 iSqlBuffer.Format(KSqlStatement, ENeverPlayed); |
739 iSqlBuffer.Format(KSqlStatement, ENeverPlayed); |
695 |
740 |
696 sqlite3_stmt *st; |
741 sqlite3_stmt *st; |
697 |
742 |
698 int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
743 int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
811 TUint showtype = sqlite3_column_int(st, 13); |
856 TUint showtype = sqlite3_column_int(st, 13); |
812 showInfo->SetShowType((TShowType) showtype); |
857 showInfo->SetShowType((TShowType) showtype); |
813 |
858 |
814 TInt lasterror = sqlite3_column_int(st, 14); |
859 TInt lasterror = sqlite3_column_int(st, 14); |
815 showInfo->SetLastError(lasterror); |
860 showInfo->SetLastError(lasterror); |
861 |
|
862 sqlite3_int64 deletedate = sqlite3_column_int64(st, 15); |
|
863 TTime timedeletedate(deletedate); |
|
864 showInfo->SetDeleteDate(timedeletedate); |
|
816 } |
865 } |
817 |
866 |
818 void CShowEngine::DBAddShowL(const CShowInfo& aItem) |
867 void CShowEngine::DBAddShowL(const CShowInfo& aItem) |
819 { |
868 { |
820 DP2("CShowEngine::DBAddShow, title=%S, URL=%S", &aItem.Title(), &aItem.Url()); |
869 DP2("CShowEngine::DBAddShow, title=%S, URL=%S", &aItem.Title(), &aItem.Url()); |
827 HBufC* descBuf = HBufC::NewLC(KMaxLineLength); |
876 HBufC* descBuf = HBufC::NewLC(KMaxLineLength); |
828 TPtr descPtr(descBuf->Des()); |
877 TPtr descPtr(descBuf->Des()); |
829 descPtr.Copy(aItem.Description()); |
878 descPtr.Copy(aItem.Description()); |
830 PodcastUtils::SQLEncode(descPtr); |
879 PodcastUtils::SQLEncode(descPtr); |
831 |
880 |
832 _LIT(KSqlStatement, "insert into shows (url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype) values (\"%S\",\"%S\", \"%S\", \"%S\", \"%Lu\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%Lu\", \"%d\")"); |
881 _LIT(KSqlStatement, "insert into shows (url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, deletedate) values (\"%S\",\"%S\", \"%S\", \"%S\", \"%Lu\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%Lu\", \"%d\", \"%Lu\")"); |
833 |
882 |
834 iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr, |
883 iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr, |
835 &aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(), |
884 &aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(), |
836 aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(), |
885 aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(), |
837 aItem.Uid(), aItem.ShowSize(), aItem.TrackNo(), |
886 aItem.Uid(), aItem.ShowSize(), aItem.TrackNo(), |
838 aItem.PubDate().Int64(), aItem.ShowType()); |
887 aItem.PubDate().Int64(), aItem.ShowType(), aItem.DeleteDate().Int64()); |
839 |
888 |
840 CleanupStack::PopAndDestroy(descBuf); |
889 CleanupStack::PopAndDestroy(descBuf); |
841 CleanupStack::PopAndDestroy(titleBuf); |
890 CleanupStack::PopAndDestroy(titleBuf); |
842 |
891 |
843 sqlite3_stmt *st; |
892 sqlite3_stmt *st; |
900 HBufC* descBuf = HBufC::NewLC(KMaxLineLength); |
949 HBufC* descBuf = HBufC::NewLC(KMaxLineLength); |
901 TPtr descPtr(descBuf->Des()); |
950 TPtr descPtr(descBuf->Des()); |
902 descPtr.Copy(aItem.Description()); |
951 descPtr.Copy(aItem.Description()); |
903 PodcastUtils::SQLEncode(descPtr); |
952 PodcastUtils::SQLEncode(descPtr); |
904 |
953 |
905 _LIT(KSqlStatement, "update shows set url=\"%S\", title=\"%S\", description=\"%S\", filename=\"%S\", position=\"%Lu\", playtime=\"%u\", playstate=\"%u\", downloadstate=\"%u\", feeduid=\"%u\", showsize=\"%u\", trackno=\"%u\",pubdate=\"%Lu\", showtype=\"%d\", lasterror=\"%d\" where uid=\"%u\""); |
954 _LIT(KSqlStatement, "update shows set url=\"%S\", title=\"%S\", description=\"%S\", filename=\"%S\", position=\"%Lu\", playtime=\"%u\", playstate=\"%u\", downloadstate=\"%u\", feeduid=\"%u\", showsize=\"%u\", trackno=\"%u\",pubdate=\"%Lu\", showtype=\"%d\", lasterror=\"%d\", deletedate=\"%Lu\" where uid=\"%u\""); |
906 iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr, |
955 iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr, |
907 &aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(), |
956 &aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(), |
908 aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(), |
957 aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(), |
909 aItem.ShowSize(), aItem.TrackNo(), aItem.PubDate().Int64(), |
958 aItem.ShowSize(), aItem.TrackNo(), aItem.PubDate().Int64(), |
910 aItem.ShowType(), aItem.LastError(), aItem.Uid()); |
959 aItem.ShowType(), aItem.LastError(), aItem.DeleteDate().Int64(), aItem.Uid()); |
911 |
960 |
912 CleanupStack::PopAndDestroy(descBuf); |
961 CleanupStack::PopAndDestroy(descBuf); |
913 CleanupStack::PopAndDestroy(titleBuf); |
962 CleanupStack::PopAndDestroy(titleBuf); |
914 |
963 |
915 sqlite3_stmt *st; |
964 sqlite3_stmt *st; |
1442 void CShowEngine::FileError(TUint /*aError*/) |
1491 void CShowEngine::FileError(TUint /*aError*/) |
1443 { |
1492 { |
1444 iDownloadErrors = KMaxDownloadErrors; |
1493 iDownloadErrors = KMaxDownloadErrors; |
1445 } |
1494 } |
1446 |
1495 |
1496 EXPORT_C void CShowEngine::ExpireOldShows() |
|
1497 { |
|
1498 DP("CShowEngine::ExpireOldShows BEGIN"); |
|
1499 RShowInfoArray oldShowsArray; |
|
1500 |
|
1501 TRAPD(err, DBGetOldShowsL(oldShowsArray)); |
|
1502 |
|
1503 if (err == KErrNone) |
|
1504 { |
|
1505 for (int i=0;i<oldShowsArray.Count();i++) |
|
1506 { |
|
1507 DP1(" deleting %S", &oldShowsArray[i]->FileName()); |
|
1508 BaflUtils::DeleteFile(iPodcastModel.FsSession(), oldShowsArray[i]->FileName()); |
|
1509 } |
|
1510 } |
|
1511 DP("CShowEngine::ExpireOldShows END"); |
|
1512 } |
|
1513 |
|
1447 EXPORT_C void CShowEngine::CheckForDeletedShows(TUint aFeedUid) |
1514 EXPORT_C void CShowEngine::CheckForDeletedShows(TUint aFeedUid) |
1448 { |
1515 { |
1449 RShowInfoArray shows; |
1516 RShowInfoArray shows; |
1450 |
1517 |
1451 TRAPD(err, DBGetShowsByFeedL(shows, aFeedUid)); |
1518 TRAPD(err, DBGetShowsByFeedL(shows, aFeedUid)); |
1596 else |
1663 else |
1597 { |
1664 { |
1598 User::Leave(KErrCorrupt); |
1665 User::Leave(KErrCorrupt); |
1599 } |
1666 } |
1600 } |
1667 } |
1668 |
|
1669 EXPORT_C void CShowEngine::PostPlayHandling(CShowInfo *aShow) |
|
1670 { |
|
1671 DP("CShowEngine::PostPlayHandling BEGIN"); |
|
1672 if (!aShow) |
|
1673 return; |
|
1674 |
|
1675 aShow->SetPlayState(EPlayed); |
|
1676 |
|
1677 TAutoDeleteSetting deleteSetting = iPodcastModel.SettingsEngine().DeleteAutomatically(); |
|
1678 TTimeIntervalDays daysAhead; |
|
1679 |
|
1680 switch (deleteSetting) |
|
1681 { |
|
1682 case EAutoDeleteOff: |
|
1683 break; |
|
1684 case EAutoDeleteAfter1Day: |
|
1685 daysAhead = 1; |
|
1686 break; |
|
1687 case EAutoDeleteAfter7Days: |
|
1688 daysAhead = 7; |
|
1689 break; |
|
1690 } |
|
1691 |
|
1692 TTime deleteDate; |
|
1693 deleteDate.HomeTime(); |
|
1694 deleteDate += daysAhead; |
|
1695 aShow->SetDeleteDate(deleteDate); |
|
1696 |
|
1697 UpdateShowL(*aShow); |
|
1698 DP("CShowEngine::PostPlayHandling END"); |
|
1699 } |