diff -r 7a313fb652c8 -r b436ab77eac1 engine/src/ShowEngine.cpp --- a/engine/src/ShowEngine.cpp Fri Jun 11 16:24:09 2010 +0100 +++ b/engine/src/ShowEngine.cpp Thu Jul 22 16:33:34 2010 +0100 @@ -176,12 +176,7 @@ void CShowEngine::DownloadInfo(CHttpClient* aHttpClient, TInt aTotalBytes) { - DP1("About to download %d bytes", aTotalBytes); - if (aHttpClient == iShowClient && iShowDownloading != NULL - && aTotalBytes != -1) - { - iShowDownloading->SetShowSize(aTotalBytes); - } + DP1("CShowEngine::DownloadInfo, About to download %d bytes", aTotalBytes); } void CShowEngine::GetShowL(CShowInfo *info) @@ -1020,6 +1015,52 @@ } } +void CShowEngine::DBSwapDownloadsL(TDownload aFirstDL, TDownload aSecondDL) + { + DP("CShowEngine::DBSwapDownloadsL"); + _LIT(KSqlStatement, "update downloads set uid=%u where dl_index=%d"); + + iSqlBuffer.Format(KSqlStatement, aFirstDL.iUid, aSecondDL.iIndex); + sqlite3_stmt *st; + int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, + &st, (const void**) NULL); + + if (rc == SQLITE_OK) + { + Cleanup_sqlite3_finalize_PushL(st); + rc = sqlite3_step(st); + if (rc != SQLITE_DONE) + { + User::Leave(KErrUnknown); + } + CleanupStack::PopAndDestroy(); // st + } + else + { + User::Leave(KErrCorrupt); + } + + iSqlBuffer.Format(KSqlStatement, aSecondDL.iUid, aFirstDL.iIndex); + + rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, + &st, (const void**) NULL); + + if (rc == SQLITE_OK) + { + Cleanup_sqlite3_finalize_PushL(st); + rc = sqlite3_step(st); + if (rc != SQLITE_DONE) + { + User::Leave(KErrUnknown); + } + CleanupStack::PopAndDestroy(); // st + } + else + { + User::Leave(KErrCorrupt); + } + } + EXPORT_C CShowInfo* CShowEngine::GetNextShowByTrackL(CShowInfo* aShowInfo) { CShowInfo* nextShow = NULL; @@ -1382,3 +1423,128 @@ } } +EXPORT_C void CShowEngine::MoveDownloadUpL(TUint aUid) + { + DP("CShowEngine::MoveDownLoadUpL"); + _LIT(KSqlStatement, "select * from downloads"); + iSqlBuffer.Format(KSqlStatement); + + sqlite3_stmt *st; + + int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, + &st, (const void**) NULL); + + if (rc == SQLITE_OK) + { + RArray downloads; + CleanupClosePushL(downloads); + + rc = sqlite3_step(st); + Cleanup_sqlite3_finalize_PushL(st); + + TInt selectedIdx = -1; + while (rc == SQLITE_ROW && selectedIdx == -1) + { + TDownload download; + + download.iIndex = sqlite3_column_int(st, 0); + download.iUid = sqlite3_column_int(st, 1); + + downloads.Append(download); + + if (download.iUid == aUid) + { + selectedIdx = downloads.Count()-1; + } + + rc = sqlite3_step(st); + } + CleanupStack::PopAndDestroy();//st, downloads + + // If the selected download was found in the database + if (selectedIdx != -1) + { + // Swap the specified download with the one above it + TDownload selectedDownload = downloads[selectedIdx]; + TDownload previousDownload = downloads[selectedIdx - 1]; + + // SQL - Update index (with index of selected download) where uid is of previous download + // and update index (with index of previous download) where uid if of selected download + DBSwapDownloadsL(selectedDownload, previousDownload); + } + else + { + User::Leave(KErrNotFound); + } + + CleanupStack::PopAndDestroy(); // downloads + } + else + { + User::Leave(KErrCorrupt); + } + } + +EXPORT_C void CShowEngine::MoveDownloadDownL(TUint aUid) + { + DP("CShowEngine::MoveDownLoadDownL"); + + // An upside-down list will result in the download moving down + _LIT(KSqlStatement, "select * from downloads order by dl_index desc"); + iSqlBuffer.Format(KSqlStatement); + + sqlite3_stmt *st; + + int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, + &st, (const void**) NULL); + + if (rc == SQLITE_OK) + { + RArray downloads; + CleanupClosePushL(downloads); + + rc = sqlite3_step(st); + Cleanup_sqlite3_finalize_PushL(st); + + TInt selectedIdx = -1; + while (rc == SQLITE_ROW && selectedIdx == -1) + { + TDownload download; + + download.iIndex = sqlite3_column_int(st, 0); + download.iUid = sqlite3_column_int(st, 1); + + downloads.Append(download); + + if (download.iUid == aUid) + { + selectedIdx = downloads.Count()-1; + } + + rc = sqlite3_step(st); + } + CleanupStack::PopAndDestroy();//st, downloads + + // If the selected download was found in the database + if (selectedIdx != -1) + { + // Swap the specified download with the one above it + TDownload selectedDownload = downloads[selectedIdx]; + TDownload previousDownload = downloads[selectedIdx - 1]; + + // SQL - Update index (with index of selected download) where uid is of previous download + // and update index (with index of previous download) where uid if of selected download + DBSwapDownloadsL(selectedDownload, previousDownload); + } + else + { + User::Leave(KErrNotFound); + } + + CleanupStack::PopAndDestroy(); // downloads + } + else + { + User::Leave(KErrCorrupt); + } + }