| 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 | 
 | 
|  |    118 | EXPORT_C void CShowEngine::RemoveAllDownloads()
 | 
|  |    119 | 	{
 | 
|  |    120 | 	if (!iPodcastModel.SettingsEngine().DownloadSuspended())
 | 
|  |    121 | 		{
 | 
|  |    122 | 		SuspendDownloads();
 | 
|  |    123 | 		}
 | 
|  |    124 | 
 | 
|  |    125 | 	DBRemoveAllDownloads();
 | 
|  |    126 | 	}
 | 
|  |    127 | 
 | 
|  |    128 | EXPORT_C TBool CShowEngine::RemoveDownloadL(TUint aUid)
 | 
|  |    129 | 	{
 | 
|  |    130 | 	DP("CShowEngine::RemoveDownload\t Trying to remove download");
 | 
|  |    131 | 
 | 
|  |    132 | 	TBool retVal = EFalse;
 | 
|  |    133 | 	TBool resumeAfterRemove = EFalse;
 | 
|  |    134 | 	// if trying to remove the present download, we first stop it
 | 
|  |    135 | 	if (!iPodcastModel.SettingsEngine().DownloadSuspended() && iShowDownloading != NULL
 | 
|  |    136 | 			&& iShowDownloading->Uid() == aUid)
 | 
|  |    137 | 		{
 | 
|  |    138 | 		DP("CShowEngine::RemoveDownload\t This is the active download, we suspend downloading");
 | 
|  |    139 | 		SuspendDownloads();
 | 
|  |    140 | 		resumeAfterRemove = ETrue;
 | 
|  |    141 | 		}
 | 
|  |    142 | 
 | 
|  |    143 | 	CShowInfo *info = DBGetShowByUidL(aUid);
 | 
|  |    144 | 	if (info != NULL)
 | 
|  |    145 | 		{
 | 
|  |    146 | 		info->SetDownloadState(ENotDownloaded);
 | 
|  |    147 | 		DBUpdateShow(*info);
 | 
|  |    148 | 		delete info;
 | 
|  |    149 | 		}
 | 
|  |    150 | 	DBRemoveDownload(aUid);
 | 
|  |    151 | 
 | 
|  |    152 | 	// partial downloads should be removed
 | 
|  |    153 | 	if (iShowDownloading)
 | 
|  |    154 | 		{
 | 
|  |    155 | 		BaflUtils::DeleteFile(iPodcastModel.FsSession(), iShowDownloading->FileName());
 | 
|  |    156 | 		}
 | 
|  |    157 | 
 | 
|  |    158 | 	NotifyShowDownloadUpdatedL(-1, -1);
 | 
|  |    159 | 	NotifyDownloadQueueUpdatedL();
 | 
|  |    160 | 	
 | 
|  |    161 | 	if (resumeAfterRemove) {
 | 
|  |    162 | 		ResumeDownloadsL();
 | 
|  |    163 | 	}
 | 
|  |    164 | 	
 | 
|  |    165 | 	DownloadNextShowL();
 | 
|  |    166 | 	retVal = ETrue;
 | 
|  |    167 | 
 | 
|  |    168 | 	return retVal;
 | 
|  |    169 | 	}
 | 
|  |    170 | 
 | 
|  |    171 | void CShowEngine::Connected(CHttpClient* /*aClient*/)
 | 
|  |    172 | 	{
 | 
|  |    173 | 
 | 
|  |    174 | 	}
 | 
|  |    175 | 
 | 
|  |    176 | void CShowEngine::Progress(CHttpClient* /*aHttpClient */, TInt aBytes,
 | 
|  |    177 | 		TInt aTotalBytes)
 | 
|  |    178 | 	{	
 | 
|  |    179 | 	iShowDownloading->SetShowSize(aTotalBytes);
 | 
|  |    180 | 	TRAP_IGNORE(NotifyShowDownloadUpdatedL(aBytes, aTotalBytes));
 | 
|  |    181 | 	}
 | 
|  |    182 | 
 | 
|  |    183 | void CShowEngine::Disconnected(CHttpClient* /*aClient */)
 | 
|  |    184 | 	{
 | 
|  |    185 | 	}
 | 
|  |    186 | 
 | 
|  |    187 | void CShowEngine::DownloadInfo(CHttpClient* aHttpClient, TInt aTotalBytes)
 | 
|  |    188 | 	{
 | 
|  |    189 | 	DP1("About to download %d bytes", aTotalBytes);
 | 
|  |    190 | 	if (aHttpClient == iShowClient && iShowDownloading != NULL
 | 
|  |    191 | 			&& aTotalBytes != -1)
 | 
|  |    192 | 		{
 | 
|  |    193 | 		iShowDownloading->SetShowSize(aTotalBytes);
 | 
|  |    194 | 		}
 | 
|  |    195 | 	}
 | 
|  |    196 | 
 | 
|  |    197 | TBool CShowEngine::GetShowL(CShowInfo *info)
 | 
|  |    198 | 	{
 | 
|  |    199 | 	CFeedInfo *feedInfo = iPodcastModel.FeedEngine().GetFeedInfoByUid(
 | 
|  |    200 | 			info->FeedUid());
 | 
|  |    201 | 	if (feedInfo == NULL)
 | 
|  |    202 | 		{
 | 
|  |    203 | 		DP("Feed not found for this show!");
 | 
|  |    204 | 		return EFalse;
 | 
|  |    205 | 		}
 | 
|  |    206 | 
 | 
|  |    207 | 	TFileName filePath;
 | 
|  |    208 | 	filePath.Copy(iPodcastModel.SettingsEngine().BaseDir());
 | 
|  |    209 | 	
 | 
|  |    210 | 	TFileName relPath;
 | 
|  |    211 | 	relPath.Copy(feedInfo->Title());
 | 
|  |    212 | 	relPath.Append('\\');
 | 
|  |    213 | 
 | 
|  |    214 | 	TFileName fileName;
 | 
|  |    215 | 	PodcastUtils::FileNameFromUrl(info->Url(), fileName);
 | 
|  |    216 | 	relPath.Append(fileName);
 | 
|  |    217 | 	PodcastUtils::EnsureProperPathName(relPath);
 | 
|  |    218 | 
 | 
|  |    219 | 	// complete file path is base dir + rel path
 | 
|  |    220 | 	filePath.Append(relPath);
 | 
|  |    221 | 	info->SetFileNameL(filePath);
 | 
|  |    222 | 
 | 
|  |    223 | 	return iShowClient->GetL(info->Url(), filePath);
 | 
|  |    224 | 	}
 | 
|  |    225 | 
 | 
|  |    226 | EXPORT_C TBool CShowEngine::AddShowL(const CShowInfo& aItem)
 | 
|  |    227 | 	{
 | 
|  |    228 | 	DP1("CShowEngine::AddShowL, title=%S", &aItem.Title());
 | 
|  |    229 | 	CShowInfo *showInfo = DBGetShowByUidL(aItem.Uid());
 | 
|  |    230 | 
 | 
|  |    231 | 	if (showInfo == NULL)
 | 
|  |    232 | 		{
 | 
|  |    233 | 		DBAddShow(aItem);
 | 
|  |    234 | 		return ETrue;
 | 
|  |    235 | 		}
 | 
|  |    236 | 	else
 | 
|  |    237 | 		{
 | 
|  |    238 | 		delete showInfo;	
 | 
|  |    239 | 		return EFalse;
 | 
|  |    240 | 		}	
 | 
|  |    241 | 	}
 | 
|  |    242 | 
 | 
|  |    243 | EXPORT_C void CShowEngine::AddObserver(MShowEngineObserver *observer)
 | 
|  |    244 | 	{
 | 
|  |    245 | 	iObservers.Append(observer);
 | 
|  |    246 | 	}
 | 
|  |    247 | 
 | 
|  |    248 | EXPORT_C void CShowEngine::RemoveObserver(MShowEngineObserver *observer)
 | 
|  |    249 | 	{
 | 
|  |    250 | 	TInt index = iObservers.Find(observer);
 | 
|  |    251 | 
 | 
|  |    252 | 	if (index > KErrNotFound)
 | 
|  |    253 | 		{
 | 
|  |    254 | 		iObservers.Remove(index);
 | 
|  |    255 | 		}
 | 
|  |    256 | 	}
 | 
|  |    257 | 
 | 
|  |    258 | void CShowEngine::AddShowToMpxCollection(CShowInfo &/*aShowInfo*/)
 | 
|  |    259 | 	{
 | 
|  |    260 | /*	RArray<TInt> contentIDs;
 | 
|  |    261 | 	contentIDs.AppendL( KMPXMediaIdGeneral );
 | 
|  |    262 | 	
 | 
|  |    263 | 	CMPXMedia* media = CMPXMedia::NewL( contentIDs.Array() );
 | 
|  |    264 | 	CleanupStack::PushL( media );
 | 
|  |    265 | 	contentIDs.Close();
 | 
|  |    266 | 	CleanupStack::PopAndDestroy(media);   */
 | 
|  |    267 | 	}
 | 
|  |    268 | 
 | 
|  |    269 | void CShowEngine::CompleteL(CHttpClient* /*aHttpClient*/, TInt aError)
 | 
|  |    270 | 	{
 | 
|  |    271 | 	if (iShowDownloading != NULL)
 | 
|  |    272 | 		{
 | 
|  |    273 | 		DP1("CShowEngine::Complete\tDownload of file: %S is complete", &iShowDownloading->FileName());		
 | 
|  |    274 | 		// decide what kind of file this is		
 | 
|  |    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);
 | 
|  |    302 | 				DBUpdateShow(*iShowDownloading);
 | 
|  |    303 | 				DBRemoveDownload(iShowDownloading->Uid());
 | 
|  |    304 | 				AddShowToMpxCollection(*iShowDownloading);				
 | 
|  |    305 | 				NotifyShowFinishedL(aError);
 | 
|  |    306 | 
 | 
|  |    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);
 | 
|  |    316 | 					DBUpdateShow(*iShowDownloading);
 | 
|  |    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);
 | 
|  |    326 | 					DBUpdateShow(*iShowDownloading);
 | 
|  |    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);
 | 
|  |    346 | 				DBUpdateShow(*iShowDownloading);
 | 
|  |    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 | 
 | 
|  |    737 | TBool CShowEngine::DBAddShow(const CShowInfo& aItem)
 | 
|  |    738 | 	{
 | 
|  |    739 | 	DP2("CShowEngine::DBAddShow, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
 | 
|  |    740 | 
 | 
|  |    741 | 	_LIT(KSqlStatement, "insert into shows (url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype)"
 | 
|  |    742 | 			" values (\"%S\",\"%S\", \"%S\", \"%S\", \"%Lu\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%Lu\", \"%d\")");
 | 
|  |    743 | 	iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &aItem.Title(), &aItem.Description(),
 | 
|  |    744 | 			&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(),
 | 
|  |    745 | 			aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(),
 | 
|  |    746 | 			aItem.Uid(), aItem.ShowSize(), aItem.TrackNo(),
 | 
|  |    747 | 			aItem.PubDate().Int64(), aItem.ShowType());
 | 
|  |    748 | 
 | 
|  |    749 | 	sqlite3_stmt *st;
 | 
|  |    750 | 
 | 
|  |    751 | 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
 | 
|  |    752 | 			&st, (const void**) NULL);
 | 
|  |    753 | 	if (rc == SQLITE_OK)
 | 
|  |    754 | 		{
 | 
|  |    755 | 		rc = sqlite3_step(st);
 | 
|  |    756 | 		if (rc == SQLITE_DONE)
 | 
|  |    757 | 			{
 | 
|  |    758 | 			sqlite3_finalize(st);
 | 
|  |    759 | 			return ETrue;
 | 
|  |    760 | 			}
 | 
|  |    761 | 		else
 | 
|  |    762 | 			{
 | 
|  |    763 | 			sqlite3_finalize(st);
 | 
|  |    764 | 			}
 | 
|  |    765 | 		}
 | 
|  |    766 | 	else
 | 
|  |    767 | 		{
 | 
|  |    768 | 		DP1("SQLite rc=%d", rc);
 | 
|  |    769 | 		}
 | 
|  |    770 | 
 | 
|  |    771 | 	return EFalse;
 | 
|  |    772 | 	}
 | 
|  |    773 | 
 | 
|  |    774 | void CShowEngine::DBAddDownload(TUint aUid)
 | 
|  |    775 | 	{
 | 
|  |    776 | 	DP1("CShowEngine::DBAddDownload, aUid=%u", aUid);
 | 
|  |    777 | 
 | 
|  |    778 | 	_LIT(KSqlStatement, "insert into downloads (uid) values (%u)");
 | 
|  |    779 | 	iSqlBuffer.Format(KSqlStatement, aUid);
 | 
|  |    780 | 	sqlite3_stmt *st;
 | 
|  |    781 | 
 | 
|  |    782 | 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
 | 
|  |    783 | 			&st, (const void**) NULL);
 | 
|  |    784 | 
 | 
|  |    785 | 	if (rc == SQLITE_OK)
 | 
|  |    786 | 		{
 | 
|  |    787 | 		rc = sqlite3_step(st);
 | 
|  |    788 | 		}
 | 
|  |    789 | 
 | 
|  |    790 | 	sqlite3_finalize(st);
 | 
|  |    791 | 	}
 | 
|  |    792 | 
 | 
|  |    793 | TBool CShowEngine::DBUpdateShow(CShowInfo& aItem)
 | 
|  |    794 | 	{
 | 
|  |    795 | 	DP1("CShowEngine::DBUpdateShow, title='%S'", &aItem.Title());
 | 
|  |    796 | 
 | 
|  |    797 | 	_LIT(KSqlStatement, "update shows set url=\"%S\", title=\"%S\", description=\"%S\", filename=\"%S\", position=\"%Lu\","
 | 
|  |    798 | 			"playtime=\"%u\", playstate=\"%u\", downloadstate=\"%u\", feeduid=\"%u\", showsize=\"%u\", trackno=\"%u\","
 | 
|  |    799 | 			"pubdate=\"%Lu\", showtype=\"%d\", lasterror=\"%d\" where uid=\"%u\"");
 | 
|  |    800 | 	iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &aItem.Title(), &aItem.Description(),
 | 
|  |    801 | 			&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(),
 | 
|  |    802 | 			aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(),
 | 
|  |    803 | 			aItem.ShowSize(), aItem.TrackNo(), aItem.PubDate().Int64(),
 | 
|  |    804 | 			aItem.ShowType(), aItem.LastError(), aItem.Uid());
 | 
|  |    805 | 
 | 
|  |    806 | 	sqlite3_stmt *st;
 | 
|  |    807 | 
 | 
|  |    808 | 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
 | 
|  |    809 | 			&st, (const void**) NULL);
 | 
|  |    810 | 
 | 
|  |    811 | 	if (rc == SQLITE_OK)
 | 
|  |    812 | 		{
 | 
|  |    813 | 		rc = sqlite3_step(st);
 | 
|  |    814 | 
 | 
|  |    815 | 		if (rc == SQLITE_DONE)
 | 
|  |    816 | 			{
 | 
|  |    817 | 			sqlite3_finalize(st);
 | 
|  |    818 | 			return ETrue;
 | 
|  |    819 | 			}
 | 
|  |    820 | 		else
 | 
|  |    821 | 			{
 | 
|  |    822 | 			sqlite3_finalize(st);
 | 
|  |    823 | 			}
 | 
|  |    824 | 		}
 | 
|  |    825 | 	else
 | 
|  |    826 | 		{
 | 
|  |    827 | 		DP1("SQLite rc=%d", rc);
 | 
|  |    828 | 		}
 | 
|  |    829 | 
 | 
|  |    830 | 	return EFalse;
 | 
|  |    831 | 	}
 | 
|  |    832 | 
 | 
|  |    833 | TBool CShowEngine::DBDeleteShow(TUint aUid)
 | 
|  |    834 | 	{
 | 
|  |    835 | 	DP("CShowEngine::DBDeleteShow");
 | 
|  |    836 | 
 | 
|  |    837 | 	_LIT(KSqlStatement, "delete from shows where uid=%u");
 | 
|  |    838 | 	iSqlBuffer.Format(KSqlStatement, aUid);
 | 
|  |    839 | 
 | 
|  |    840 | 	sqlite3_stmt *st;
 | 
|  |    841 | 
 | 
|  |    842 | 	//DP1("SQL: %S", &iSqlBuffer.Left(KSqlDPLen));
 | 
|  |    843 | 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
 | 
|  |    844 | 			&st, (const void**) NULL);
 | 
|  |    845 | 
 | 
|  |    846 | 	if (rc == SQLITE_OK)
 | 
|  |    847 | 		{
 | 
|  |    848 | 		rc = sqlite3_step(st);
 | 
|  |    849 | 
 | 
|  |    850 | 		if (rc == SQLITE_DONE)
 | 
|  |    851 | 			{
 | 
|  |    852 | 			sqlite3_finalize(st);
 | 
|  |    853 | 			return ETrue;
 | 
|  |    854 | 			}
 | 
|  |    855 | 		else
 | 
|  |    856 | 			{
 | 
|  |    857 | 			sqlite3_finalize(st);
 | 
|  |    858 | 			}
 | 
|  |    859 | 		}
 | 
|  |    860 | 	else
 | 
|  |    861 | 		{
 | 
|  |    862 | 		DP1("SQLite rc=%d", rc);
 | 
|  |    863 | 		}
 | 
|  |    864 | 
 | 
|  |    865 | 	return EFalse;
 | 
|  |    866 | 	}
 | 
|  |    867 | 
 | 
|  |    868 | TBool CShowEngine::DBDeleteAllShowsByFeed(TUint aFeedUid)
 | 
|  |    869 | 	{
 | 
|  |    870 | 	DP("CShowEngine::DBDeleteAllShowsByFeed");
 | 
|  |    871 | 
 | 
|  |    872 | 	_LIT(KSqlStatement, "delete from shows where feeduid=%u");
 | 
|  |    873 | 	iSqlBuffer.Format(KSqlStatement, aFeedUid);
 | 
|  |    874 | 
 | 
|  |    875 | 	sqlite3_stmt *st;
 | 
|  |    876 | 
 | 
|  |    877 | 	//DP1("SQL: %S", &iSqlBuffer.Left(KSqlDPLen));
 | 
|  |    878 | 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
 | 
|  |    879 | 			&st, (const void**) NULL);
 | 
|  |    880 | 
 | 
|  |    881 | 	if (rc == SQLITE_OK)
 | 
|  |    882 | 		{
 | 
|  |    883 | 		rc = sqlite3_step(st);
 | 
|  |    884 | 
 | 
|  |    885 | 		if (rc == SQLITE_DONE)
 | 
|  |    886 | 			{
 | 
|  |    887 | 			sqlite3_finalize(st);
 | 
|  |    888 | 			return ETrue;
 | 
|  |    889 | 			}
 | 
|  |    890 | 		else
 | 
|  |    891 | 			{
 | 
|  |    892 | 			sqlite3_finalize(st);
 | 
|  |    893 | 			}
 | 
|  |    894 | 		}
 | 
|  |    895 | 	else
 | 
|  |    896 | 		{
 | 
|  |    897 | 		DP1("SQLite rc=%d", rc);
 | 
|  |    898 | 		}
 | 
|  |    899 | 
 | 
|  |    900 | 	return EFalse;
 | 
|  |    901 | 	}
 | 
|  |    902 | 
 | 
|  |    903 | void CShowEngine::DBRemoveAllDownloads()
 | 
|  |    904 | 	{
 | 
|  |    905 | 	DP("CShowEngine::DBRemoveAllDownloads");
 | 
|  |    906 | 
 | 
|  |    907 | 	_LIT(KSqlStatement, "delete from downloads");
 | 
|  |    908 | 	iSqlBuffer.Format(KSqlStatement);
 | 
|  |    909 | 
 | 
|  |    910 | 	sqlite3_stmt *st;
 | 
|  |    911 | 
 | 
|  |    912 | 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
 | 
|  |    913 | 			&st, (const void**) NULL);
 | 
|  |    914 | 
 | 
|  |    915 | 	if (rc == SQLITE_OK)
 | 
|  |    916 | 		{
 | 
|  |    917 | 		rc = sqlite3_step(st);
 | 
|  |    918 | 		sqlite3_finalize(st);
 | 
|  |    919 | 		}
 | 
|  |    920 | 
 | 
|  |    921 | 	_LIT(KSqlStatement2, "update shows set downloadstate=0 where downloadstate=1");
 | 
|  |    922 | 	iSqlBuffer.Format(KSqlStatement2);
 | 
|  |    923 | 
 | 
|  |    924 | 	rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, &st,
 | 
|  |    925 | 			(const void**) NULL);
 | 
|  |    926 | 
 | 
|  |    927 | 	if (rc == SQLITE_OK)
 | 
|  |    928 | 		{
 | 
|  |    929 | 		rc = sqlite3_step(st);
 | 
|  |    930 | 		sqlite3_finalize(st);
 | 
|  |    931 | 		}
 | 
|  |    932 | 
 | 
|  |    933 | 	}
 | 
|  |    934 | 
 | 
|  |    935 | void CShowEngine::DBRemoveDownload(TUint aUid)
 | 
|  |    936 | 	{
 | 
|  |    937 | 	DP("CShowEngine::DBRemoveDownload");
 | 
|  |    938 | 
 | 
|  |    939 | 	_LIT(KSqlStatement, "delete from downloads where uid=%u");
 | 
|  |    940 | 	iSqlBuffer.Format(KSqlStatement, aUid);
 | 
|  |    941 | 
 | 
|  |    942 | 	sqlite3_stmt *st;
 | 
|  |    943 | 
 | 
|  |    944 | 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
 | 
|  |    945 | 			&st, (const void**) NULL);
 | 
|  |    946 | 
 | 
|  |    947 | 	if (rc == SQLITE_OK)
 | 
|  |    948 | 		{
 | 
|  |    949 | 		rc = sqlite3_step(st);
 | 
|  |    950 | 		sqlite3_finalize(st);
 | 
|  |    951 | 		}
 | 
|  |    952 | 	}
 | 
|  |    953 | 
 | 
|  |    954 | EXPORT_C CShowInfo* CShowEngine::GetNextShowByTrackL(CShowInfo* aShowInfo)
 | 
|  |    955 | 	{
 | 
|  |    956 | 	CShowInfo* nextShow = NULL;
 | 
|  |    957 | 	RShowInfoArray array;
 | 
|  |    958 | 	DBGetShowsByFeedL(array, aShowInfo->FeedUid());
 | 
|  |    959 | 	TUint diff = KMaxTInt;
 | 
|  |    960 | 	for (TInt loop = 0; loop < array.Count(); loop++)
 | 
|  |    961 | 		{
 | 
|  |    962 | 		if (aShowInfo->TrackNo() < array[loop]->TrackNo())
 | 
|  |    963 | 			{
 | 
|  |    964 | 			if ((array[loop]->TrackNo() - aShowInfo->TrackNo()) < diff)
 | 
|  |    965 | 				{
 | 
|  |    966 | 				diff = array[loop]->TrackNo() - aShowInfo->TrackNo();
 | 
|  |    967 | 				nextShow = array[loop];
 | 
|  |    968 | 				}
 | 
|  |    969 | 			}
 | 
|  |    970 | 		}
 | 
|  |    971 | 	array.ResetAndDestroy();
 | 
|  |    972 | 	return nextShow;
 | 
|  |    973 | 	}
 | 
|  |    974 | 
 | 
|  |    975 | TBool CShowEngine::CompareShowsByUid(const CShowInfo &a, const CShowInfo &b)
 | 
|  |    976 | 	{
 | 
|  |    977 | 	return a.Uid() == b.Uid();
 | 
|  |    978 | 	}
 | 
|  |    979 | 
 | 
|  |    980 | TInt CShowEngine::CompareShowsByDate(const CShowInfo &a, const CShowInfo &b)
 | 
|  |    981 | 	{
 | 
|  |    982 | 	if (a.PubDate() > b.PubDate())
 | 
|  |    983 | 		{
 | 
|  |    984 | 		//		DP2("Sorting %S less than %S", &a.iTitle, &b.iTitle);
 | 
|  |    985 | 		return -1;
 | 
|  |    986 | 		}
 | 
|  |    987 | 	else if (a.PubDate() == b.PubDate())
 | 
|  |    988 | 		{
 | 
|  |    989 | 		//		DP2("Sorting %S equal to %S", &a.iTitle, &b.iTitle);
 | 
|  |    990 | 		return 0;
 | 
|  |    991 | 		}
 | 
|  |    992 | 	else
 | 
|  |    993 | 		{
 | 
|  |    994 | 		//		DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle);
 | 
|  |    995 | 		return 1;
 | 
|  |    996 | 		}
 | 
|  |    997 | 	}
 | 
|  |    998 | 
 | 
|  |    999 | TInt CShowEngine::CompareShowsByTrackNo(const CShowInfo &a, const CShowInfo &b)
 | 
|  |   1000 | 	{
 | 
|  |   1001 | 	if (a.TrackNo() < b.TrackNo())
 | 
|  |   1002 | 		{
 | 
|  |   1003 | 		return -1;
 | 
|  |   1004 | 		}
 | 
|  |   1005 | 	else if (a.TrackNo() == b.TrackNo())
 | 
|  |   1006 | 		{
 | 
|  |   1007 | 		return 0;
 | 
|  |   1008 | 		}
 | 
|  |   1009 | 	else
 | 
|  |   1010 | 		{
 | 
|  |   1011 | 		return 1;
 | 
|  |   1012 | 		}
 | 
|  |   1013 | 	}
 | 
|  |   1014 | 
 | 
|  |   1015 | TInt CShowEngine::CompareShowsByTitle(const CShowInfo &a, const CShowInfo &b)
 | 
|  |   1016 | 	{
 | 
|  |   1017 | 	if (a.Title() < b.Title())
 | 
|  |   1018 | 		{
 | 
|  |   1019 | 		//		DP2("Sorting %S less than %S", &a.iTitle, &b.iTitle);
 | 
|  |   1020 | 		return -1;
 | 
|  |   1021 | 		}
 | 
|  |   1022 | 	else if (a.Title() == b.Title())
 | 
|  |   1023 | 		{
 | 
|  |   1024 | 		//		DP2("Sorting %S equal to %S", &a.iTitle, &b.iTitle);
 | 
|  |   1025 | 		return 0;
 | 
|  |   1026 | 		}
 | 
|  |   1027 | 	else
 | 
|  |   1028 | 		{
 | 
|  |   1029 | 		//		DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle);
 | 
|  |   1030 | 		return 1;
 | 
|  |   1031 | 		}
 | 
|  |   1032 | 	}
 | 
|  |   1033 | 
 | 
|  |   1034 | EXPORT_C void CShowEngine::DeletePlayedShows(RShowInfoArray &aShowInfoArray)
 | 
|  |   1035 | 	{
 | 
|  |   1036 | 	for (TInt i = 0; i < aShowInfoArray.Count(); i++)
 | 
|  |   1037 | 		{
 | 
|  |   1038 | 		if (aShowInfoArray[i]->PlayState() == EPlayed
 | 
|  |   1039 | 				&& aShowInfoArray[i]->FileName().Length() > 0)
 | 
|  |   1040 | 			{
 | 
|  |   1041 | 			if (CompareShowsByUid(*(iPodcastModel.PlayingPodcast()), *(aShowInfoArray[i]))
 | 
|  |   1042 | 					&& iPodcastModel.SoundEngine().State() != ESoundEngineNotInitialized)
 | 
|  |   1043 | 				{
 | 
|  |   1044 | 				iPodcastModel.SoundEngine().Stop();
 | 
|  |   1045 | 				}
 | 
|  |   1046 | 			BaflUtils::DeleteFile(iPodcastModel.FsSession(), aShowInfoArray[i]->FileName());
 | 
|  |   1047 | 			aShowInfoArray[i]->SetDownloadState(ENotDownloaded);
 | 
|  |   1048 | 			DBUpdateShow(*aShowInfoArray[i]);
 | 
|  |   1049 | 			}
 | 
|  |   1050 | 		}
 | 
|  |   1051 | 	}
 | 
|  |   1052 | 
 | 
|  |   1053 | EXPORT_C void CShowEngine::DeleteAllShowsByFeedL(TUint aFeedUid, TBool aDeleteFiles)
 | 
|  |   1054 | 	{
 | 
|  |   1055 | 	RShowInfoArray array;
 | 
|  |   1056 | 	DBGetShowsByFeedL(array, aFeedUid);
 | 
|  |   1057 | 
 | 
|  |   1058 | 	const TInt count = array.Count();
 | 
|  |   1059 | 
 | 
|  |   1060 | 	for (TInt i = count - 1; i >= 0; i--)
 | 
|  |   1061 | 		{
 | 
|  |   1062 | 		if (array[i]->FileName().Length() > 0)
 | 
|  |   1063 | 			{
 | 
|  |   1064 | 			if (aDeleteFiles)
 | 
|  |   1065 | 				{
 | 
|  |   1066 | 				BaflUtils::DeleteFile(iPodcastModel.FsSession(), array[i]->FileName());
 | 
|  |   1067 | 				}
 | 
|  |   1068 | 			}
 | 
|  |   1069 | 		}
 | 
|  |   1070 | 	array.ResetAndDestroy();
 | 
|  |   1071 | 	DBDeleteAllShowsByFeed(aFeedUid);
 | 
|  |   1072 | 	}
 | 
|  |   1073 | 
 | 
|  |   1074 | EXPORT_C void CShowEngine::DeleteOldShowsByFeed(TUint aFeedUid)
 | 
|  |   1075 | 	{
 | 
|  |   1076 | 		DBDeleteOldShowsByFeed(aFeedUid);
 | 
|  |   1077 | 	}
 | 
|  |   1078 | 
 | 
|  |   1079 | EXPORT_C void CShowEngine::DeleteShowL(TUint aShowUid, TBool aRemoveFile)
 | 
|  |   1080 | 	{
 | 
|  |   1081 | 
 | 
|  |   1082 | 	CShowInfo *info = DBGetShowByUidL(aShowUid);
 | 
|  |   1083 | 
 | 
|  |   1084 | 	if (info != NULL)
 | 
|  |   1085 | 		{
 | 
|  |   1086 | 		if (info->FileName().Length() > 0 && aRemoveFile)
 | 
|  |   1087 | 			{
 | 
|  |   1088 | 			BaflUtils::DeleteFile(iPodcastModel.FsSession(), info->FileName());
 | 
|  |   1089 | 			}
 | 
|  |   1090 | 		
 | 
|  |   1091 | 		info->SetDownloadState(ENotDownloaded);
 | 
|  |   1092 | 		DBUpdateShow(*info);
 | 
|  |   1093 | 		delete info;
 | 
|  |   1094 | 		}
 | 
|  |   1095 | 	}
 | 
|  |   1096 | 
 | 
|  |   1097 | EXPORT_C void CShowEngine::GetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid)
 | 
|  |   1098 | 	{
 | 
|  |   1099 | 	DP("CShowEngine::GetShowsByFeed");
 | 
|  |   1100 | 	DBGetShowsByFeedL(aShowArray, aFeedUid);
 | 
|  |   1101 | 	}
 | 
|  |   1102 | 
 | 
|  |   1103 | EXPORT_C void CShowEngine::GetAllShowsL(RShowInfoArray &aArray)
 | 
|  |   1104 | 	{
 | 
|  |   1105 | 	DP("CShowEngine::GetAllShows");
 | 
|  |   1106 | 	DBGetAllShowsL(aArray);
 | 
|  |   1107 | 	}
 | 
|  |   1108 | 
 | 
|  |   1109 | EXPORT_C void CShowEngine::GetShowsDownloadedL(RShowInfoArray &aArray)
 | 
|  |   1110 | 	{
 | 
|  |   1111 | 	DP("CShowEngine::GetShowsDownloaded");
 | 
|  |   1112 | 	DBGetDownloadedShowsL(aArray);
 | 
|  |   1113 | 	}
 | 
|  |   1114 | 
 | 
|  |   1115 | EXPORT_C void CShowEngine::GetNewShowsL(RShowInfoArray &aArray)
 | 
|  |   1116 | 	{
 | 
|  |   1117 | 	DP("CShowEngine::GetNewShows");
 | 
|  |   1118 | 	DBGetNewShowsL(aArray);
 | 
|  |   1119 | 	}
 | 
|  |   1120 | 
 | 
|  |   1121 | EXPORT_C void CShowEngine::GetShowsDownloadingL(RShowInfoArray &aArray)
 | 
|  |   1122 | 	{
 | 
|  |   1123 | 	DP("CShowEngine::GetShowsDownloading");
 | 
|  |   1124 | 	DBGetAllDownloadsL(aArray);
 | 
|  |   1125 | 	}
 | 
|  |   1126 | 
 | 
|  |   1127 | EXPORT_C TInt CShowEngine::GetNumDownloadingShows()
 | 
|  |   1128 | 	{
 | 
|  |   1129 | 	return (const TInt) DBGetDownloadsCount();
 | 
|  |   1130 | 	}
 | 
|  |   1131 | 
 | 
|  |   1132 | EXPORT_C void CShowEngine::AddDownloadL(CShowInfo& aInfo)
 | 
|  |   1133 | 	{
 | 
|  |   1134 | 	aInfo.SetDownloadState(EQueued);
 | 
|  |   1135 | 	DBUpdateShow(aInfo);
 | 
|  |   1136 | 	DBAddDownload(aInfo.Uid());
 | 
|  |   1137 | 	DownloadNextShowL();
 | 
|  |   1138 | 	}
 | 
|  |   1139 | 
 | 
|  |   1140 | void CShowEngine::DownloadNextShowL()
 | 
|  |   1141 | 	{
 | 
|  |   1142 | 	DP("CShowEngine::DownloadNextShowL BEGIN");
 | 
|  |   1143 | 	// Check if we have anything in the download queue
 | 
|  |   1144 | 	const TInt count = DBGetDownloadsCount();
 | 
|  |   1145 | 	DP("CShowEngine::DownloadNextShow\tTrying to start new download");DP1("CShowEngine::DownloadNextShow\tShows in download queue %d", count);
 | 
|  |   1146 | 
 | 
|  |   1147 | 	// Inform the observers
 | 
|  |   1148 | 	NotifyDownloadQueueUpdatedL();
 | 
|  |   1149 | 
 | 
|  |   1150 | 	if (count > 0)
 | 
|  |   1151 | 		{
 | 
|  |   1152 | 		if (iPodcastModel.SettingsEngine().DownloadSuspended())
 | 
|  |   1153 | 			{
 | 
|  |   1154 | 			DP("CShowEngine::DownloadNextShow\tDownload process is suspended, ABORTING");
 | 
|  |   1155 | 			return;
 | 
|  |   1156 | 			}
 | 
|  |   1157 | 		else if (iShowClient->IsActive())
 | 
|  |   1158 | 			{
 | 
|  |   1159 | 			DP("CShowEngine::DownloadNextShow\tDownload process is already active.");
 | 
|  |   1160 | 			return;
 | 
|  |   1161 | 			}
 | 
|  |   1162 | 		else
 | 
|  |   1163 | 			{
 | 
|  |   1164 | 
 | 
|  |   1165 | 			// Start the download
 | 
|  |   1166 | 			
 | 
|  |   1167 | 			CShowInfo *info = DBGetNextDownloadL();
 | 
|  |   1168 | 			
 | 
|  |   1169 | 			while(info != NULL)
 | 
|  |   1170 | 				{
 | 
|  |   1171 | 				TBool getOk = EFalse;
 | 
|  |   1172 | 				DP1("CShowEngine::DownloadNextShow\tDownloading: %S", &(info->Title()));
 | 
|  |   1173 | 				info->SetDownloadState(EDownloading);
 | 
|  |   1174 | 				info->SetLastError(KErrNone);
 | 
|  |   1175 | 				DBUpdateShow(*info);
 | 
|  |   1176 | 				iShowDownloading = info;
 | 
|  |   1177 | 				TRAPD(error,getOk = GetShowL(info));
 | 
|  |   1178 | 				if (error != KErrNone || !getOk)
 | 
|  |   1179 | 					{
 | 
|  |   1180 | 					info->SetDownloadState(EFailedDownload);
 | 
|  |   1181 | 					DBRemoveDownload(info->Uid());
 | 
|  |   1182 | 					DBUpdateShow(*info);
 | 
|  |   1183 | 					info = DBGetNextDownloadL();
 | 
|  |   1184 | 					
 | 
|  |   1185 | 					if(info == NULL)
 | 
|  |   1186 | 						{
 | 
|  |   1187 | 						iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue);
 | 
|  |   1188 | 						iShowDownloading = NULL;
 | 
|  |   1189 | 						}
 | 
|  |   1190 | 					}				
 | 
|  |   1191 | 				else
 | 
|  |   1192 | 					{
 | 
|  |   1193 | 					break;
 | 
|  |   1194 | 					}
 | 
|  |   1195 | 				}
 | 
|  |   1196 | 			}
 | 
|  |   1197 | 		}
 | 
|  |   1198 | 	else
 | 
|  |   1199 | 		{
 | 
|  |   1200 | 		iShowDownloading = NULL;DP("CShowEngine::DownloadNextShow\tNothing to download");
 | 
|  |   1201 | 		}
 | 
|  |   1202 | 	DP("CShowEngine::DownloadNextShowL END");
 | 
|  |   1203 | 	}
 | 
|  |   1204 | 
 | 
|  |   1205 | void CShowEngine::NotifyDownloadQueueUpdatedL()
 | 
|  |   1206 | 	{
 | 
|  |   1207 | 	const TInt count = iObservers.Count();
 | 
|  |   1208 | 	for (TInt i = 0; i < count; i++)
 | 
|  |   1209 | 		{
 | 
|  |   1210 | 		iObservers[i]->DownloadQueueUpdatedL(1, DBGetDownloadsCount() - 1);
 | 
|  |   1211 | 		}
 | 
|  |   1212 | 	}
 | 
|  |   1213 | 
 | 
|  |   1214 | void CShowEngine::NotifyShowDownloadUpdatedL(TInt aBytesOfCurrentDownload, TInt aBytesTotal)
 | 
|  |   1215 | 	{
 | 
|  |   1216 | 	const TInt count = iObservers.Count();
 | 
|  |   1217 | 	for (TInt i = 0; i < count; i++)
 | 
|  |   1218 | 		{
 | 
|  |   1219 | 			iObservers[i]->ShowDownloadUpdatedL(aBytesOfCurrentDownload, aBytesTotal);
 | 
|  |   1220 | 		}
 | 
|  |   1221 | 	}
 | 
|  |   1222 | 
 | 
|  |   1223 | void CShowEngine::NotifyShowFinishedL(TInt aError)
 | 
|  |   1224 | 	{
 | 
|  |   1225 | 	const TInt count = iObservers.Count();
 | 
|  |   1226 | 		for (TInt i = 0; i < count; i++)
 | 
|  |   1227 | 			{
 | 
|  |   1228 | 				iObservers[i]->ShowDownloadFinishedL(iShowDownloading?iShowDownloading->Uid():0, aError);
 | 
|  |   1229 | 			}
 | 
|  |   1230 | 	}
 | 
|  |   1231 | 
 | 
|  |   1232 | EXPORT_C void CShowEngine::NotifyShowListUpdatedL()
 | 
|  |   1233 | 	{
 | 
|  |   1234 | 	for (TInt i = 0; i < iObservers.Count(); i++)
 | 
|  |   1235 | 		{
 | 
|  |   1236 | 		iObservers[i]->ShowListUpdatedL();
 | 
|  |   1237 | 		}
 | 
|  |   1238 | 	}
 | 
|  |   1239 | 
 | 
|  |   1240 | void CShowEngine::ReadMetaData(CShowInfo& aShowInfo)
 | 
|  |   1241 | 	{
 | 
|  |   1242 | 	//DP1("Read %S", &(aShowInfo->Title()));
 | 
|  |   1243 | 	DBUpdateShow(aShowInfo);
 | 
|  |   1244 | 	}
 | 
|  |   1245 | 
 | 
|  |   1246 | void CShowEngine::ReadMetaDataCompleteL()
 | 
|  |   1247 | 	{
 | 
|  |   1248 | 	NotifyShowListUpdatedL();
 | 
|  |   1249 | 	MetaDataReader().SetIgnoreTrackNo(EFalse);
 | 
|  |   1250 | 	}
 | 
|  |   1251 | 
 | 
|  |   1252 | EXPORT_C void CShowEngine::UpdateShow(CShowInfo& aInfo)
 | 
|  |   1253 | 	{
 | 
|  |   1254 | 	DBUpdateShow(aInfo);
 | 
|  |   1255 | 	}
 | 
|  |   1256 | 
 | 
|  |   1257 | EXPORT_C CMetaDataReader& CShowEngine::MetaDataReader()
 | 
|  |   1258 | 	{
 | 
|  |   1259 | 	return *iMetaDataReader;
 | 
|  |   1260 | 	}
 | 
|  |   1261 | 
 | 
|  |   1262 | void CShowEngine::FileError(TUint /*aError*/)
 | 
|  |   1263 | 	{
 | 
|  |   1264 | 	//TODO: Error dialog
 | 
|  |   1265 | 	//StopDownloads();
 | 
|  |   1266 | 	iDownloadErrors = KMaxDownloadErrors;
 | 
|  |   1267 | 	}
 |