diff -r 4b75876aa85a -r b131f7696342 engine/src/ShowEngine.cpp --- a/engine/src/ShowEngine.cpp Sun Nov 14 13:05:37 2010 +0000 +++ b/engine/src/ShowEngine.cpp Tue Nov 16 10:26:34 2010 +0000 @@ -43,6 +43,7 @@ EXPORT_C CShowEngine::~CShowEngine() { + DP("CShowEngine::~CShowEngine BEGIN"); delete iShowClient; iObservers.Close(); delete iShowDownloading; @@ -54,6 +55,7 @@ iCollectionHelper->Close(); } #endif + DP("CShowEngine::~CShowEngine END"); } EXPORT_C CShowEngine* CShowEngine::NewL(CPodcastModel& aPodcastModel) @@ -395,11 +397,12 @@ { return DBGetShowByUidL(aShowUid); } + CShowInfo* CShowEngine::DBGetShowByUidL(TUint aUid) { DP("CShowEngine::DBGetShowByUid"); CShowInfo *showInfo = NULL; - _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows where uid=%u"); + _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, deletedate from shows where uid=%u"); iSqlBuffer.Format(KSqlStatement, aUid); sqlite3_stmt *st; @@ -429,7 +432,7 @@ { DP("CShowEngine::DBGetShowByUid"); CShowInfo *showInfo = NULL; - _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows where filename=\"%S\""); + _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror, deletedate from shows where filename=\"%S\""); iSqlBuffer.Format(KSqlStatement, &aFileName); sqlite3_stmt *st; @@ -456,7 +459,7 @@ void CShowEngine::DBGetAllShowsL(RShowInfoArray& aShowArray) { DP("CShowEngine::DBGetAllShows"); - _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows"); + _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror, deletedate from shows"); iSqlBuffer.Format(KSqlStatement); sqlite3_stmt *st; @@ -484,7 +487,7 @@ void CShowEngine::DBGetAllDownloadsL(RShowInfoArray& aShowArray) { DP("CShowEngine::DBGetAllDownloads"); - _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"); + _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"); iSqlBuffer.Format(KSqlStatement); #ifndef DONT_SORT_SQL @@ -534,11 +537,52 @@ } } +void CShowEngine::DBGetOldShowsL(RShowInfoArray& aShowArray) + { + DP("CShowEngine::DBGetOldShowsL BEGIN"); + TTime now; + now.HomeTime(); +// TTimeIntervalYears years(5); +// now += years; + + _LIT(KSqlStatement, "select filename from shows where downloadstate=%d and deletedate < \"%Ld\""); + iSqlBuffer.Format(KSqlStatement, EDownloaded, now.Int64()); + + sqlite3_stmt *st; + + int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, + &st, (const void**) NULL); + + if (rc == SQLITE_OK) + { + rc = sqlite3_step(st); + Cleanup_sqlite3_finalize_PushL(st); + while (rc == SQLITE_ROW) + { + CShowInfo* showInfo = CShowInfo::NewLC(); + + const void *filez = sqlite3_column_text16(st, 0); + TPtrC16 file((const TUint16*) filez); + showInfo->SetFileNameL(file); + + aShowArray.Append(showInfo); + CleanupStack::Pop(showInfo); + rc = sqlite3_step(st); + } + CleanupStack::PopAndDestroy();//st + } + else + { + User::Leave(KErrCorrupt); + } + DP("CShowEngine::DBGetOldShowsL END"); + } + CShowInfo* CShowEngine::DBGetNextDownloadL() { DP("CShowEngine::DBGetNextDownload"); CShowInfo *showInfo = NULL; - _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"); + _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"); iSqlBuffer.Format(KSqlStatement); #ifdef DONT_SORT_SQL @@ -581,9 +625,9 @@ void CShowEngine::DBGetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid) { DP1("CShowEngine::DBGetShowsByFeed BEGIN, feedUid=%u", aFeedUid); - _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where feeduid=%u"); + _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror, deletedate from shows where feeduid=%u"); iSqlBuffer.Format(KSqlStatement, aFeedUid); - + #ifndef DONT_SORT_SQL _LIT(KSqlOrderByDate, " order by pubdate desc"); iSqlBuffer.Append(KSqlOrderByDate); @@ -654,7 +698,7 @@ void CShowEngine::DBGetDownloadedShowsL(RShowInfoArray& aShowArray) { DP("CShowEngine::DBGetDownloadedShows"); - _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where downloadstate=%u"); + _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror, deletedate from shows where downloadstate=%u"); iSqlBuffer.Format(KSqlStatement, EDownloaded); #ifndef DONT_SORT_SQL @@ -690,7 +734,8 @@ void CShowEngine::DBGetNewShowsL(RShowInfoArray& aShowArray) { DP("CShowEngine::DBGetNewShows"); - _LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where playstate=%u"); + _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"); + iSqlBuffer.Format(KSqlStatement, ENeverPlayed); sqlite3_stmt *st; @@ -813,6 +858,10 @@ TInt lasterror = sqlite3_column_int(st, 14); showInfo->SetLastError(lasterror); + + sqlite3_int64 deletedate = sqlite3_column_int64(st, 15); + TTime timedeletedate(deletedate); + showInfo->SetDeleteDate(timedeletedate); } void CShowEngine::DBAddShowL(const CShowInfo& aItem) @@ -829,13 +878,13 @@ descPtr.Copy(aItem.Description()); PodcastUtils::SQLEncode(descPtr); - _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\")"); + _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\")"); iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr, &aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(), aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(), aItem.Uid(), aItem.ShowSize(), aItem.TrackNo(), - aItem.PubDate().Int64(), aItem.ShowType()); + aItem.PubDate().Int64(), aItem.ShowType(), aItem.DeleteDate().Int64()); CleanupStack::PopAndDestroy(descBuf); CleanupStack::PopAndDestroy(titleBuf); @@ -902,12 +951,12 @@ descPtr.Copy(aItem.Description()); PodcastUtils::SQLEncode(descPtr); - _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\""); + _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\""); iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr, &aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(), aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(), aItem.ShowSize(), aItem.TrackNo(), aItem.PubDate().Int64(), - aItem.ShowType(), aItem.LastError(), aItem.Uid()); + aItem.ShowType(), aItem.LastError(), aItem.DeleteDate().Int64(), aItem.Uid()); CleanupStack::PopAndDestroy(descBuf); CleanupStack::PopAndDestroy(titleBuf); @@ -1444,6 +1493,24 @@ iDownloadErrors = KMaxDownloadErrors; } +EXPORT_C void CShowEngine::ExpireOldShows() + { + DP("CShowEngine::ExpireOldShows BEGIN"); + RShowInfoArray oldShowsArray; + + TRAPD(err, DBGetOldShowsL(oldShowsArray)); + + if (err == KErrNone) + { + for (int i=0;iFileName()); + BaflUtils::DeleteFile(iPodcastModel.FsSession(), oldShowsArray[i]->FileName()); + } + } + DP("CShowEngine::ExpireOldShows END"); + } + EXPORT_C void CShowEngine::CheckForDeletedShows(TUint aFeedUid) { RShowInfoArray shows; @@ -1598,3 +1665,35 @@ User::Leave(KErrCorrupt); } } + +EXPORT_C void CShowEngine::PostPlayHandling(CShowInfo *aShow) + { + DP("CShowEngine::PostPlayHandling BEGIN"); + if (!aShow) + return; + + aShow->SetPlayState(EPlayed); + + TAutoDeleteSetting deleteSetting = iPodcastModel.SettingsEngine().DeleteAutomatically(); + TTimeIntervalDays daysAhead; + + switch (deleteSetting) + { + case EAutoDeleteOff: + break; + case EAutoDeleteAfter1Day: + daysAhead = 1; + break; + case EAutoDeleteAfter7Days: + daysAhead = 7; + break; + } + + TTime deleteDate; + deleteDate.HomeTime(); + deleteDate += daysAhead; + aShow->SetDeleteDate(deleteDate); + + UpdateShowL(*aShow); + DP("CShowEngine::PostPlayHandling END"); + }