| author | Brendan Donegan <brendand@symbian.org> | 
| Sat, 06 Mar 2010 10:22:09 +0000 | |
| changeset 35 | 66c5303f3610 | 
| parent 30 | 7bca37ba5fa9 | 
| child 36 | e010fc411ddc | 
| 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 | ||
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 118 | EXPORT_C void CShowEngine::RemoveAllDownloadsL() | 
| 2 | 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); | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 148 | DBUpdateShowL(*info); | 
| 2 | 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 | 		{
 | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 234 | DBAddShowL(aItem); | 
| 2 | 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); | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 302 | DBUpdateShowL(*iShowDownloading); | 
| 2 | 303 | DBRemoveDownload(iShowDownloading->Uid()); | 
| 304 | AddShowToMpxCollection(*iShowDownloading); | |
| 305 | NotifyShowFinishedL(aError); | |
| 15 
93d9f66bf50b
Cleaning description better for second line in search results
 teknolog parents: 
6diff
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); | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 316 | DBUpdateShowL(*iShowDownloading); | 
| 2 | 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); | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 326 | DBUpdateShowL(*iShowDownloading); | 
| 2 | 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); | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 346 | DBUpdateShowL(*iShowDownloading); | 
| 2 | 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 | ||
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 737 | TBool CShowEngine::DBAddShowL(const CShowInfo& aItem) | 
| 2 | 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 | ||
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 807 | TBool CShowEngine::DBUpdateShowL(CShowInfo& aItem) | 
| 2 | 808 | 	{
 | 
| 809 | 	DP1("CShowEngine::DBUpdateShow, title='%S'", &aItem.Title());
 | |
| 810 | ||
| 30 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 811 | HBufC* titleBuf = HBufC::NewLC(KMaxLineLength); | 
| 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 812 | TPtr titlePtr(titleBuf->Des()); | 
| 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 813 | titlePtr.Copy(aItem.Title()); | 
| 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 814 | PodcastUtils::SQLEncode(titlePtr); | 
| 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 815 | |
| 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 816 | HBufC* descBuf = HBufC::NewLC(KMaxLineLength); | 
| 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 817 | TPtr descPtr(descBuf->Des()); | 
| 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 818 | descPtr.Copy(aItem.Description()); | 
| 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 819 | PodcastUtils::SQLEncode(descPtr); | 
| 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 820 | |
| 2 | 821 | _LIT(KSqlStatement, "update shows set url=\"%S\", title=\"%S\", description=\"%S\", filename=\"%S\", position=\"%Lu\"," | 
| 822 | "playtime=\"%u\", playstate=\"%u\", downloadstate=\"%u\", feeduid=\"%u\", showsize=\"%u\", trackno=\"%u\"," | |
| 823 | "pubdate=\"%Lu\", showtype=\"%d\", lasterror=\"%d\" where uid=\"%u\""); | |
| 30 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 824 | iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr, | 
| 2 | 825 | &aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(), | 
| 826 | aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(), | |
| 827 | aItem.ShowSize(), aItem.TrackNo(), aItem.PubDate().Int64(), | |
| 828 | aItem.ShowType(), aItem.LastError(), aItem.Uid()); | |
| 829 | ||
| 30 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 830 | CleanupStack::PopAndDestroy(descBuf); | 
| 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 831 | CleanupStack::PopAndDestroy(titleBuf); | 
| 
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
 teknolog parents: 
22diff
changeset | 832 | |
| 2 | 833 | sqlite3_stmt *st; | 
| 834 | ||
| 835 | int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, | |
| 836 | &st, (const void**) NULL); | |
| 837 | ||
| 838 | if (rc == SQLITE_OK) | |
| 839 | 		{
 | |
| 840 | rc = sqlite3_step(st); | |
| 841 | ||
| 842 | if (rc == SQLITE_DONE) | |
| 843 | 			{
 | |
| 844 | sqlite3_finalize(st); | |
| 845 | return ETrue; | |
| 846 | } | |
| 847 | else | |
| 848 | 			{
 | |
| 849 | sqlite3_finalize(st); | |
| 850 | } | |
| 851 | } | |
| 852 | else | |
| 853 | 		{
 | |
| 854 | 		DP1("SQLite rc=%d", rc);
 | |
| 855 | } | |
| 856 | ||
| 857 | return EFalse; | |
| 858 | } | |
| 859 | ||
| 860 | TBool CShowEngine::DBDeleteShow(TUint aUid) | |
| 861 | 	{
 | |
| 862 | 	DP("CShowEngine::DBDeleteShow");
 | |
| 863 | ||
| 864 | _LIT(KSqlStatement, "delete from shows where uid=%u"); | |
| 865 | iSqlBuffer.Format(KSqlStatement, aUid); | |
| 866 | ||
| 867 | sqlite3_stmt *st; | |
| 868 | ||
| 869 | 	//DP1("SQL: %S", &iSqlBuffer.Left(KSqlDPLen));
 | |
| 870 | int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, | |
| 871 | &st, (const void**) NULL); | |
| 872 | ||
| 873 | if (rc == SQLITE_OK) | |
| 874 | 		{
 | |
| 875 | rc = sqlite3_step(st); | |
| 876 | ||
| 877 | if (rc == SQLITE_DONE) | |
| 878 | 			{
 | |
| 879 | sqlite3_finalize(st); | |
| 880 | return ETrue; | |
| 881 | } | |
| 882 | else | |
| 883 | 			{
 | |
| 884 | sqlite3_finalize(st); | |
| 885 | } | |
| 886 | } | |
| 887 | else | |
| 888 | 		{
 | |
| 889 | 		DP1("SQLite rc=%d", rc);
 | |
| 890 | } | |
| 891 | ||
| 892 | return EFalse; | |
| 893 | } | |
| 894 | ||
| 895 | TBool CShowEngine::DBDeleteAllShowsByFeed(TUint aFeedUid) | |
| 896 | 	{
 | |
| 897 | 	DP("CShowEngine::DBDeleteAllShowsByFeed");
 | |
| 898 | ||
| 899 | _LIT(KSqlStatement, "delete from shows where feeduid=%u"); | |
| 900 | iSqlBuffer.Format(KSqlStatement, aFeedUid); | |
| 901 | ||
| 902 | sqlite3_stmt *st; | |
| 903 | ||
| 904 | 	//DP1("SQL: %S", &iSqlBuffer.Left(KSqlDPLen));
 | |
| 905 | int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, | |
| 906 | &st, (const void**) NULL); | |
| 907 | ||
| 908 | if (rc == SQLITE_OK) | |
| 909 | 		{
 | |
| 910 | rc = sqlite3_step(st); | |
| 911 | ||
| 912 | if (rc == SQLITE_DONE) | |
| 913 | 			{
 | |
| 914 | sqlite3_finalize(st); | |
| 915 | return ETrue; | |
| 916 | } | |
| 917 | else | |
| 918 | 			{
 | |
| 919 | sqlite3_finalize(st); | |
| 920 | } | |
| 921 | } | |
| 922 | else | |
| 923 | 		{
 | |
| 924 | 		DP1("SQLite rc=%d", rc);
 | |
| 925 | } | |
| 926 | ||
| 927 | return EFalse; | |
| 928 | } | |
| 929 | ||
| 930 | void CShowEngine::DBRemoveAllDownloads() | |
| 931 | 	{
 | |
| 932 | 	DP("CShowEngine::DBRemoveAllDownloads");
 | |
| 933 | ||
| 934 | _LIT(KSqlStatement, "delete from downloads"); | |
| 935 | iSqlBuffer.Format(KSqlStatement); | |
| 936 | ||
| 937 | sqlite3_stmt *st; | |
| 938 | ||
| 939 | int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, | |
| 940 | &st, (const void**) NULL); | |
| 941 | ||
| 942 | if (rc == SQLITE_OK) | |
| 943 | 		{
 | |
| 944 | rc = sqlite3_step(st); | |
| 945 | sqlite3_finalize(st); | |
| 946 | } | |
| 947 | ||
| 948 | _LIT(KSqlStatement2, "update shows set downloadstate=0 where downloadstate=1"); | |
| 949 | iSqlBuffer.Format(KSqlStatement2); | |
| 950 | ||
| 951 | rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, &st, | |
| 952 | (const void**) NULL); | |
| 953 | ||
| 954 | if (rc == SQLITE_OK) | |
| 955 | 		{
 | |
| 956 | rc = sqlite3_step(st); | |
| 957 | sqlite3_finalize(st); | |
| 958 | } | |
| 959 | ||
| 960 | } | |
| 961 | ||
| 962 | void CShowEngine::DBRemoveDownload(TUint aUid) | |
| 963 | 	{
 | |
| 964 | 	DP("CShowEngine::DBRemoveDownload");
 | |
| 965 | ||
| 966 | _LIT(KSqlStatement, "delete from downloads where uid=%u"); | |
| 967 | iSqlBuffer.Format(KSqlStatement, aUid); | |
| 968 | ||
| 969 | sqlite3_stmt *st; | |
| 970 | ||
| 971 | int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, | |
| 972 | &st, (const void**) NULL); | |
| 973 | ||
| 974 | if (rc == SQLITE_OK) | |
| 975 | 		{
 | |
| 976 | rc = sqlite3_step(st); | |
| 977 | sqlite3_finalize(st); | |
| 978 | } | |
| 979 | } | |
| 980 | ||
| 981 | EXPORT_C CShowInfo* CShowEngine::GetNextShowByTrackL(CShowInfo* aShowInfo) | |
| 982 | 	{
 | |
| 983 | CShowInfo* nextShow = NULL; | |
| 984 | RShowInfoArray array; | |
| 985 | DBGetShowsByFeedL(array, aShowInfo->FeedUid()); | |
| 986 | TUint diff = KMaxTInt; | |
| 987 | for (TInt loop = 0; loop < array.Count(); loop++) | |
| 988 | 		{
 | |
| 989 | if (aShowInfo->TrackNo() < array[loop]->TrackNo()) | |
| 990 | 			{
 | |
| 991 | if ((array[loop]->TrackNo() - aShowInfo->TrackNo()) < diff) | |
| 992 | 				{
 | |
| 993 | diff = array[loop]->TrackNo() - aShowInfo->TrackNo(); | |
| 994 | nextShow = array[loop]; | |
| 995 | } | |
| 996 | } | |
| 997 | } | |
| 998 | array.ResetAndDestroy(); | |
| 999 | return nextShow; | |
| 1000 | } | |
| 1001 | ||
| 1002 | TBool CShowEngine::CompareShowsByUid(const CShowInfo &a, const CShowInfo &b) | |
| 1003 | 	{
 | |
| 1004 | return a.Uid() == b.Uid(); | |
| 1005 | } | |
| 1006 | ||
| 1007 | TInt CShowEngine::CompareShowsByDate(const CShowInfo &a, const CShowInfo &b) | |
| 1008 | 	{
 | |
| 1009 | if (a.PubDate() > b.PubDate()) | |
| 1010 | 		{
 | |
| 1011 | 		//		DP2("Sorting %S less than %S", &a.iTitle, &b.iTitle);
 | |
| 1012 | return -1; | |
| 1013 | } | |
| 1014 | else if (a.PubDate() == b.PubDate()) | |
| 1015 | 		{
 | |
| 1016 | 		//		DP2("Sorting %S equal to %S", &a.iTitle, &b.iTitle);
 | |
| 1017 | return 0; | |
| 1018 | } | |
| 1019 | else | |
| 1020 | 		{
 | |
| 1021 | 		//		DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle);
 | |
| 1022 | return 1; | |
| 1023 | } | |
| 1024 | } | |
| 1025 | ||
| 1026 | TInt CShowEngine::CompareShowsByTrackNo(const CShowInfo &a, const CShowInfo &b) | |
| 1027 | 	{
 | |
| 1028 | if (a.TrackNo() < b.TrackNo()) | |
| 1029 | 		{
 | |
| 1030 | return -1; | |
| 1031 | } | |
| 1032 | else if (a.TrackNo() == b.TrackNo()) | |
| 1033 | 		{
 | |
| 1034 | return 0; | |
| 1035 | } | |
| 1036 | else | |
| 1037 | 		{
 | |
| 1038 | return 1; | |
| 1039 | } | |
| 1040 | } | |
| 1041 | ||
| 1042 | TInt CShowEngine::CompareShowsByTitle(const CShowInfo &a, const CShowInfo &b) | |
| 1043 | 	{
 | |
| 1044 | if (a.Title() < b.Title()) | |
| 1045 | 		{
 | |
| 1046 | 		//		DP2("Sorting %S less than %S", &a.iTitle, &b.iTitle);
 | |
| 1047 | return -1; | |
| 1048 | } | |
| 1049 | else if (a.Title() == b.Title()) | |
| 1050 | 		{
 | |
| 1051 | 		//		DP2("Sorting %S equal to %S", &a.iTitle, &b.iTitle);
 | |
| 1052 | return 0; | |
| 1053 | } | |
| 1054 | else | |
| 1055 | 		{
 | |
| 1056 | 		//		DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle);
 | |
| 1057 | return 1; | |
| 1058 | } | |
| 1059 | } | |
| 1060 | ||
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 1061 | EXPORT_C void CShowEngine::DeletePlayedShowsL(RShowInfoArray &aShowInfoArray) | 
| 2 | 1062 | 	{
 | 
| 1063 | for (TInt i = 0; i < aShowInfoArray.Count(); i++) | |
| 1064 | 		{
 | |
| 1065 | if (aShowInfoArray[i]->PlayState() == EPlayed | |
| 1066 | && aShowInfoArray[i]->FileName().Length() > 0) | |
| 1067 | 			{
 | |
| 1068 | if (CompareShowsByUid(*(iPodcastModel.PlayingPodcast()), *(aShowInfoArray[i])) | |
| 1069 | && iPodcastModel.SoundEngine().State() != ESoundEngineNotInitialized) | |
| 1070 | 				{
 | |
| 1071 | iPodcastModel.SoundEngine().Stop(); | |
| 1072 | } | |
| 1073 | BaflUtils::DeleteFile(iPodcastModel.FsSession(), aShowInfoArray[i]->FileName()); | |
| 1074 | aShowInfoArray[i]->SetDownloadState(ENotDownloaded); | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 1075 | DBUpdateShowL(*aShowInfoArray[i]); | 
| 2 | 1076 | } | 
| 1077 | } | |
| 1078 | } | |
| 1079 | ||
| 1080 | EXPORT_C void CShowEngine::DeleteAllShowsByFeedL(TUint aFeedUid, TBool aDeleteFiles) | |
| 1081 | 	{
 | |
| 1082 | RShowInfoArray array; | |
| 1083 | DBGetShowsByFeedL(array, aFeedUid); | |
| 1084 | ||
| 1085 | const TInt count = array.Count(); | |
| 1086 | ||
| 1087 | for (TInt i = count - 1; i >= 0; i--) | |
| 1088 | 		{
 | |
| 1089 | if (array[i]->FileName().Length() > 0) | |
| 1090 | 			{
 | |
| 1091 | if (aDeleteFiles) | |
| 1092 | 				{
 | |
| 1093 | BaflUtils::DeleteFile(iPodcastModel.FsSession(), array[i]->FileName()); | |
| 1094 | } | |
| 1095 | } | |
| 1096 | } | |
| 1097 | array.ResetAndDestroy(); | |
| 1098 | DBDeleteAllShowsByFeed(aFeedUid); | |
| 1099 | } | |
| 1100 | ||
| 1101 | EXPORT_C void CShowEngine::DeleteOldShowsByFeed(TUint aFeedUid) | |
| 1102 | 	{
 | |
| 1103 | DBDeleteOldShowsByFeed(aFeedUid); | |
| 1104 | } | |
| 1105 | ||
| 1106 | EXPORT_C void CShowEngine::DeleteShowL(TUint aShowUid, TBool aRemoveFile) | |
| 1107 | 	{
 | |
| 1108 | ||
| 1109 | CShowInfo *info = DBGetShowByUidL(aShowUid); | |
| 1110 | ||
| 1111 | if (info != NULL) | |
| 1112 | 		{
 | |
| 1113 | if (info->FileName().Length() > 0 && aRemoveFile) | |
| 1114 | 			{
 | |
| 1115 | BaflUtils::DeleteFile(iPodcastModel.FsSession(), info->FileName()); | |
| 1116 | } | |
| 1117 | ||
| 1118 | info->SetDownloadState(ENotDownloaded); | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 1119 | DBUpdateShowL(*info); | 
| 2 | 1120 | delete info; | 
| 1121 | } | |
| 1122 | } | |
| 1123 | ||
| 1124 | EXPORT_C void CShowEngine::GetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid) | |
| 1125 | 	{
 | |
| 1126 | 	DP("CShowEngine::GetShowsByFeed");
 | |
| 1127 | DBGetShowsByFeedL(aShowArray, aFeedUid); | |
| 1128 | } | |
| 1129 | ||
| 1130 | EXPORT_C void CShowEngine::GetAllShowsL(RShowInfoArray &aArray) | |
| 1131 | 	{
 | |
| 1132 | 	DP("CShowEngine::GetAllShows");
 | |
| 1133 | DBGetAllShowsL(aArray); | |
| 1134 | } | |
| 1135 | ||
| 1136 | EXPORT_C void CShowEngine::GetShowsDownloadedL(RShowInfoArray &aArray) | |
| 1137 | 	{
 | |
| 1138 | 	DP("CShowEngine::GetShowsDownloaded");
 | |
| 1139 | DBGetDownloadedShowsL(aArray); | |
| 1140 | } | |
| 1141 | ||
| 1142 | EXPORT_C void CShowEngine::GetNewShowsL(RShowInfoArray &aArray) | |
| 1143 | 	{
 | |
| 1144 | 	DP("CShowEngine::GetNewShows");
 | |
| 1145 | DBGetNewShowsL(aArray); | |
| 1146 | } | |
| 1147 | ||
| 1148 | EXPORT_C void CShowEngine::GetShowsDownloadingL(RShowInfoArray &aArray) | |
| 1149 | 	{
 | |
| 1150 | 	DP("CShowEngine::GetShowsDownloading");
 | |
| 1151 | DBGetAllDownloadsL(aArray); | |
| 1152 | } | |
| 1153 | ||
| 1154 | EXPORT_C TInt CShowEngine::GetNumDownloadingShows() | |
| 1155 | 	{
 | |
| 1156 | return (const TInt) DBGetDownloadsCount(); | |
| 1157 | } | |
| 1158 | ||
| 1159 | EXPORT_C void CShowEngine::AddDownloadL(CShowInfo& aInfo) | |
| 1160 | 	{
 | |
| 1161 | aInfo.SetDownloadState(EQueued); | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 1162 | DBUpdateShowL(aInfo); | 
| 2 | 1163 | DBAddDownload(aInfo.Uid()); | 
| 1164 | DownloadNextShowL(); | |
| 1165 | } | |
| 1166 | ||
| 1167 | void CShowEngine::DownloadNextShowL() | |
| 1168 | 	{
 | |
| 1169 | 	DP("CShowEngine::DownloadNextShowL BEGIN");
 | |
| 1170 | // Check if we have anything in the download queue | |
| 1171 | const TInt count = DBGetDownloadsCount(); | |
| 1172 | 	DP("CShowEngine::DownloadNextShow\tTrying to start new download");DP1("CShowEngine::DownloadNextShow\tShows in download queue %d", count);
 | |
| 1173 | ||
| 1174 | // Inform the observers | |
| 1175 | NotifyDownloadQueueUpdatedL(); | |
| 1176 | ||
| 1177 | if (count > 0) | |
| 1178 | 		{
 | |
| 1179 | if (iPodcastModel.SettingsEngine().DownloadSuspended()) | |
| 1180 | 			{
 | |
| 1181 | 			DP("CShowEngine::DownloadNextShow\tDownload process is suspended, ABORTING");
 | |
| 1182 | return; | |
| 1183 | } | |
| 1184 | else if (iShowClient->IsActive()) | |
| 1185 | 			{
 | |
| 1186 | 			DP("CShowEngine::DownloadNextShow\tDownload process is already active.");
 | |
| 1187 | return; | |
| 1188 | } | |
| 1189 | else | |
| 1190 | 			{
 | |
| 1191 | ||
| 1192 | // Start the download | |
| 1193 | ||
| 1194 | CShowInfo *info = DBGetNextDownloadL(); | |
| 1195 | ||
| 1196 | while(info != NULL) | |
| 1197 | 				{
 | |
| 1198 | TBool getOk = EFalse; | |
| 1199 | 				DP1("CShowEngine::DownloadNextShow\tDownloading: %S", &(info->Title()));
 | |
| 1200 | info->SetDownloadState(EDownloading); | |
| 1201 | info->SetLastError(KErrNone); | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 1202 | DBUpdateShowL(*info); | 
| 2 | 1203 | iShowDownloading = info; | 
| 1204 | TRAPD(error,getOk = GetShowL(info)); | |
| 1205 | if (error != KErrNone || !getOk) | |
| 1206 | 					{
 | |
| 1207 | info->SetDownloadState(EFailedDownload); | |
| 1208 | DBRemoveDownload(info->Uid()); | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 1209 | DBUpdateShowL(*info); | 
| 2 | 1210 | info = DBGetNextDownloadL(); | 
| 1211 | ||
| 1212 | if(info == NULL) | |
| 1213 | 						{
 | |
| 1214 | iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue); | |
| 1215 | iShowDownloading = NULL; | |
| 1216 | } | |
| 1217 | } | |
| 1218 | else | |
| 1219 | 					{
 | |
| 1220 | break; | |
| 1221 | } | |
| 1222 | } | |
| 1223 | } | |
| 1224 | } | |
| 1225 | else | |
| 1226 | 		{
 | |
| 1227 | 		iShowDownloading = NULL;DP("CShowEngine::DownloadNextShow\tNothing to download");
 | |
| 1228 | } | |
| 1229 | 	DP("CShowEngine::DownloadNextShowL END");
 | |
| 1230 | } | |
| 1231 | ||
| 1232 | void CShowEngine::NotifyDownloadQueueUpdatedL() | |
| 1233 | 	{
 | |
| 1234 | const TInt count = iObservers.Count(); | |
| 1235 | for (TInt i = 0; i < count; i++) | |
| 1236 | 		{
 | |
| 1237 | iObservers[i]->DownloadQueueUpdatedL(1, DBGetDownloadsCount() - 1); | |
| 1238 | } | |
| 1239 | } | |
| 1240 | ||
| 1241 | void CShowEngine::NotifyShowDownloadUpdatedL(TInt aBytesOfCurrentDownload, TInt aBytesTotal) | |
| 1242 | 	{
 | |
| 1243 | const TInt count = iObservers.Count(); | |
| 1244 | for (TInt i = 0; i < count; i++) | |
| 1245 | 		{
 | |
| 1246 | iObservers[i]->ShowDownloadUpdatedL(aBytesOfCurrentDownload, aBytesTotal); | |
| 1247 | } | |
| 1248 | } | |
| 1249 | ||
| 1250 | void CShowEngine::NotifyShowFinishedL(TInt aError) | |
| 1251 | 	{
 | |
| 1252 | const TInt count = iObservers.Count(); | |
| 1253 | for (TInt i = 0; i < count; i++) | |
| 1254 | 			{
 | |
| 1255 | iObservers[i]->ShowDownloadFinishedL(iShowDownloading?iShowDownloading->Uid():0, aError); | |
| 1256 | } | |
| 1257 | } | |
| 1258 | ||
| 1259 | EXPORT_C void CShowEngine::NotifyShowListUpdatedL() | |
| 1260 | 	{
 | |
| 1261 | for (TInt i = 0; i < iObservers.Count(); i++) | |
| 1262 | 		{
 | |
| 1263 | iObservers[i]->ShowListUpdatedL(); | |
| 1264 | } | |
| 1265 | } | |
| 1266 | ||
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 1267 | void CShowEngine::ReadMetaDataL(CShowInfo& aShowInfo) | 
| 2 | 1268 | 	{
 | 
| 1269 | 	//DP1("Read %S", &(aShowInfo->Title()));
 | |
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 1270 | DBUpdateShowL(aShowInfo); | 
| 2 | 1271 | } | 
| 1272 | ||
| 1273 | void CShowEngine::ReadMetaDataCompleteL() | |
| 1274 | 	{
 | |
| 1275 | NotifyShowListUpdatedL(); | |
| 1276 | MetaDataReader().SetIgnoreTrackNo(EFalse); | |
| 1277 | } | |
| 1278 | ||
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 1279 | EXPORT_C void CShowEngine::UpdateShowL(CShowInfo& aInfo) | 
| 2 | 1280 | 	{
 | 
| 35 
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
 Brendan Donegan <brendand@symbian.org> parents: 
30diff
changeset | 1281 | DBUpdateShowL(aInfo); | 
| 2 | 1282 | } | 
| 1283 | ||
| 1284 | EXPORT_C CMetaDataReader& CShowEngine::MetaDataReader() | |
| 1285 | 	{
 | |
| 1286 | return *iMetaDataReader; | |
| 1287 | } | |
| 1288 | ||
| 1289 | void CShowEngine::FileError(TUint /*aError*/) | |
| 1290 | 	{
 | |
| 1291 | //TODO: Error dialog | |
| 1292 | //StopDownloads(); | |
| 1293 | iDownloadErrors = KMaxDownloadErrors; | |
| 1294 | } |