engine/src/ShowEngine.cpp
changeset 93 c2f1ea38ec70
parent 89 dd31cab34e27
child 99 46baf9a7cadd
equal deleted inserted replaced
92:70749e2f572d 93:c2f1ea38ec70
    24 #include "SettingsEngine.h"
    24 #include "SettingsEngine.h"
    25 #include <e32hashtab.h>
    25 #include <e32hashtab.h>
    26 #include <httperr.h>
    26 #include <httperr.h>
    27 #include "debug.h"
    27 #include "debug.h"
    28 #include "PodcastUtils.h"
    28 #include "PodcastUtils.h"
    29 
    29 #include <mpxcollectionhelperfactory.h>
    30 //#include <mpxmedia.h>
       
    31 //#include <mpxattribute.h>
       
    32 //#include <mpxmediageneraldefs.h>
       
    33 
    30 
    34 const TUint KMaxDownloadErrors = 3;
    31 const TUint KMaxDownloadErrors = 3;
    35 const TInt KMimeBufLength = 100;
    32 const TInt KMimeBufLength = 100;
    36 
    33 
    37 CShowEngine::CShowEngine(CPodcastModel& aPodcastModel) :
    34 CShowEngine::CShowEngine(CPodcastModel& aPodcastModel) :
    45 	delete iShowClient;
    42 	delete iShowClient;
    46 	iObservers.Close();
    43 	iObservers.Close();
    47 	delete iShowDownloading;
    44 	delete iShowDownloading;
    48 	delete iMetaDataReader;
    45 	delete iMetaDataReader;
    49 	iApaSession.Close();
    46 	iApaSession.Close();
       
    47 	
       
    48 	if (iCollectionHelper)
       
    49 		delete iCollectionHelper;
    50 	}
    50 	}
    51 
    51 
    52 EXPORT_C CShowEngine* CShowEngine::NewL(CPodcastModel& aPodcastModel)
    52 EXPORT_C CShowEngine* CShowEngine::NewL(CPodcastModel& aPodcastModel)
    53 	{
    53 	{
    54 	CShowEngine* self = new (ELeave) CShowEngine(aPodcastModel);
    54 	CShowEngine* self = new (ELeave) CShowEngine(aPodcastModel);
   237 		{
   237 		{
   238 		iObservers.Remove(index);
   238 		iObservers.Remove(index);
   239 		}
   239 		}
   240 	}
   240 	}
   241 
   241 
   242 void CShowEngine::AddShowToMpxCollection(CShowInfo &/*aShowInfo*/)
   242 void CShowEngine::AddShowToMpxCollection(CShowInfo &aShowInfo)
   243 	{
   243 	{
   244 /*	RArray<TInt> contentIDs;
   244 	if (!iCollectionHelper)
   245 	contentIDs.AppendL( KMPXMediaIdGeneral );
   245 		iCollectionHelper = CMPXCollectionHelperFactory::NewCollectionHelperL();
   246 	
   246 	
   247 	CMPXMedia* media = CMPXMedia::NewL( contentIDs.Array() );
   247 	// if this leaves, not much we can do anyway
   248 	CleanupStack::PushL( media );
   248 	TRAP_IGNORE(iCollectionHelper->AddL(aShowInfo.FileName(), this));
   249 	contentIDs.Close();
   249 
   250 	CleanupStack::PopAndDestroy(media);   */
       
   251 	}
   250 	}
   252 
   251 
   253 void CShowEngine::CompleteL(CHttpClient* /*aHttpClient*/, TInt aError)
   252 void CShowEngine::CompleteL(CHttpClient* /*aHttpClient*/, TInt aError)
   254 	{
   253 	{
   255 	if (iShowDownloading != NULL)
   254 	if (iShowDownloading != NULL)
   681 	// what we do:
   680 	// what we do:
   682 	// 1. sort shows by pubdate
   681 	// 1. sort shows by pubdate
   683 	// 2. select the first MaxListItems shows
   682 	// 2. select the first MaxListItems shows
   684 	// 3. delete the rest if downloadstate is ENotDownloaded
   683 	// 3. delete the rest if downloadstate is ENotDownloaded
   685 	
   684 	
   686 	_LIT(KSqlStatement,"delete from shows where feeduid=%u and downloadstate=0 and uid not in " \
   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)");
   687 			"(select uid from shows where feeduid=%u order by pubdate desc limit %u)");
       
   688 	iSqlBuffer.Format(KSqlStatement, aFeedUid, aFeedUid, iPodcastModel.SettingsEngine().MaxListItems());
   686 	iSqlBuffer.Format(KSqlStatement, aFeedUid, aFeedUid, iPodcastModel.SettingsEngine().MaxListItems());
   689 
   687 
   690 	sqlite3_stmt *st;
   688 	sqlite3_stmt *st;
   691 
   689 
   692 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
   690 	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
   784 	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
   782 	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
   785 	TPtr descPtr(descBuf->Des());
   783 	TPtr descPtr(descBuf->Des());
   786 	descPtr.Copy(aItem.Description());
   784 	descPtr.Copy(aItem.Description());
   787 	PodcastUtils::SQLEncode(descPtr);
   785 	PodcastUtils::SQLEncode(descPtr);
   788 	
   786 	
   789 	_LIT(KSqlStatement, "insert into shows (url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype)"
   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\")");
   790 			" values (\"%S\",\"%S\", \"%S\", \"%S\", \"%Lu\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%Lu\", \"%d\")");
       
   791 	
   788 	
   792 	iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr,
   789 	iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr,
   793 			&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(),
   790 			&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(),
   794 			aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(),
   791 			aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(),
   795 			aItem.Uid(), aItem.ShowSize(), aItem.TrackNo(),
   792 			aItem.Uid(), aItem.ShowSize(), aItem.TrackNo(),
   858 	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
   855 	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
   859 	TPtr descPtr(descBuf->Des());
   856 	TPtr descPtr(descBuf->Des());
   860 	descPtr.Copy(aItem.Description());
   857 	descPtr.Copy(aItem.Description());
   861 	PodcastUtils::SQLEncode(descPtr);
   858 	PodcastUtils::SQLEncode(descPtr);
   862 
   859 
   863 	_LIT(KSqlStatement, "update shows set url=\"%S\", title=\"%S\", description=\"%S\", filename=\"%S\", position=\"%Lu\","
   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\"");
   864 			"playtime=\"%u\", playstate=\"%u\", downloadstate=\"%u\", feeduid=\"%u\", showsize=\"%u\", trackno=\"%u\","
       
   865 			"pubdate=\"%Lu\", showtype=\"%d\", lasterror=\"%d\" where uid=\"%u\"");
       
   866 	iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr,
   861 	iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr,
   867 			&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(),
   862 			&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(),
   868 			aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(),
   863 			aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(),
   869 			aItem.ShowSize(), aItem.TrackNo(), aItem.PubDate().Int64(),
   864 			aItem.ShowSize(), aItem.TrackNo(), aItem.PubDate().Int64(),
   870 			aItem.ShowType(), aItem.LastError(), aItem.Uid());
   865 			aItem.ShowType(), aItem.LastError(), aItem.Uid());