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