Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
authorteknolog
Wed, 05 May 2010 10:50:52 +0100
changeset 84 fbb6c20a24b5
parent 82 c70a6524a236
child 89 9d854792013a
Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
engine/inc/FeedEngine.h
engine/inc/ShowEngine.h
engine/src/FeedEngine.cpp
--- a/engine/inc/FeedEngine.h	Mon May 03 16:09:50 2010 +0100
+++ b/engine/inc/FeedEngine.h	Wed May 05 10:50:52 2010 +0100
@@ -151,8 +151,9 @@
 	// observers that will receive callbacks, not owning
     RArray<MFeedEngineObserver*> iObservers;
     
-    TBool iCatchupMode;
-    TUint iCatchupCounter;
+    // new feeds only add one show to download list when auto downloading
+    TBool newFeed;
+    TUint showsAdded;
     
     sqlite3& iDB;
     
--- a/engine/inc/ShowEngine.h	Mon May 03 16:09:50 2010 +0100
+++ b/engine/inc/ShowEngine.h	Wed May 05 10:50:52 2010 +0100
@@ -88,7 +88,7 @@
 	void ReadMetaDataL(CShowInfo& aShowInfo);
 	void ReadMetaDataCompleteL();
 	// from MMPXCollectionHelperObserver
-    void HandleAddFileCompleteL( TInt aErr ) {}  
+    void HandleAddFileCompleteL( TInt /*aErr*/ ) {}  
 
 private:
 	CShowEngine(CPodcastModel& aPodcastModel);
--- a/engine/src/FeedEngine.cpp	Mon May 03 16:09:50 2010 +0100
+++ b/engine/src/FeedEngine.cpp	Wed May 05 10:50:52 2010 +0100
@@ -144,6 +144,11 @@
 
 EXPORT_C void CFeedEngine::UpdateAllFeedsL(TBool aAutoUpdate)
 	{
+	if (iClientState != EIdle)
+		{
+		User::Leave(KErrInUse);
+		}
+
 	iAutoUpdatedInitiator = aAutoUpdate;
 	if (iFeedsUpdating.Count() > 0)
 		{
@@ -176,6 +181,11 @@
 	{
 	DP1("UpdateNextFeed. %d feeds left to update", iFeedsUpdating.Count());
 	
+	if (iClientState != EIdle)
+		{
+		User::Leave(KErrInUse);
+		}
+	
 	// reset active feed, will be set again in UpdateFeedL if needed
 	iActiveFeed = NULL;
 	
@@ -229,10 +239,11 @@
 
 	if (iActiveFeed->LastUpdated() == 0)
 		{
-		iCatchupMode = ETrue;
-		iCatchupCounter = 0;
+		newFeed = ETrue;	
 		}
 	
+	showsAdded = 0;
+	
 	iActiveFeed->SetLastError(KErrNone);
 	DBUpdateFeedL(*iActiveFeed);
 	
@@ -273,10 +284,12 @@
 	aItem.SetDescriptionL(*description);
 	CleanupStack::PopAndDestroy(description);
 
-	if (iCatchupMode) {
-		// in catchup mode, we let one show be unplayed
-		if (++iCatchupCounter > 1) {
-			aItem.SetPlayState(EPlayed);
+	if (newFeed) {
+		// for new feeds, set all shows played
+		aItem.SetPlayState(EPlayed);
+		// except the first one
+		if (showsAdded == 0) {
+			aItem.SetPlayState(ENeverPlayed);	
 		}
 	}
 	
@@ -286,7 +299,9 @@
 			iPodcastModel.SettingsEngine().DownloadAutomatically()) 
 		{
 		iPodcastModel.ShowEngine().AddDownloadL(aItem);
-		}	
+		}
+	
+	showsAdded++;
 	}
 
 void CFeedEngine::GetFeedImageL(CFeedInfo *aFeedInfo)
@@ -363,7 +378,8 @@
 	descPtr.Copy(aItem.Description());
 	PodcastUtils::SQLEncode(descPtr);
 	
-	_LIT(KSqlStatement, "insert into feeds (url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror) values (\"%S\",\"%S\", \"%S\", \"%S\", \"%S\", \"%S\", \"%Ld\", \"%Ld\", \"%u\", \"%u\", \"%u\", \"%d\")");
+	_LIT(KSqlStatement, "insert into feeds (url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror)"
+			" values (\"%S\",\"%S\", \"%S\", \"%S\", \"%S\", \"%S\", \"%Ld\", \"%Ld\", \"%u\", \"%u\", \"%u\", \"%d\")");
 	iSqlBuffer.Format(KSqlStatement,
 			&aItem.Url(), titleBuf, descBuf, &aItem.ImageUrl(), &aItem.ImageFileName(), &aItem.Link(),
 			aItem.BuildDate().Int64(), aItem.LastUpdated().Int64(), aItem.Uid(), EAudioPodcast, aItem.CustomTitle(), aItem.LastError());
@@ -475,7 +491,8 @@
 	descPtr.Copy(aItem.Description());
 	PodcastUtils::SQLEncode(descPtr);
 	
-	_LIT(KSqlStatement, "update feeds set url=\"%S\", title=\"%S\", description=\"%S\", imageurl=\"%S\", imagefile=\"%S\",link=\"%S\", built=\"%Lu\", lastupdated=\"%Lu\", feedtype=\"%u\", customtitle=\"%u\", lasterror=\"%d\" where uid=\"%u\"");
+	_LIT(KSqlStatement, "update feeds set url=\"%S\", title=\"%S\", description=\"%S\", imageurl=\"%S\", imagefile=\"%S\"," \
+			"link=\"%S\", built=\"%Lu\", lastupdated=\"%Lu\", feedtype=\"%u\", customtitle=\"%u\", lasterror=\"%d\" where uid=\"%u\"");
 	iSqlBuffer.Format(KSqlStatement,
 			&aItem.Url(), titleBuf, descBuf, &aItem.ImageUrl(), &aItem.ImageFileName(), &aItem.Link(),
 			aItem.BuildDate().Int64(), aItem.LastUpdated().Int64(), EAudioPodcast, aItem.CustomTitle(), aItem.LastError(), aItem.Uid());