Fix for bug 3959 - updating new feeds in reverse chronological order symbian1
authorSebastian Brannstrom <sebastianb@symbian.org>
Fri, 19 Nov 2010 01:08:10 +0000
branchsymbian1
changeset 374 f067cee22e48
parent 373 f5de49b27caf
child 375 82f59b3393b3
Fix for bug 3959 - updating new feeds in reverse chronological order
engine/inc/FeedEngine.h
engine/inc/FeedParser.h
engine/inc/FeedParserObserver.h
engine/src/FeedEngine.cpp
engine/src/FeedParser.cpp
--- a/engine/inc/FeedEngine.h	Fri Nov 19 00:16:55 2010 +0000
+++ b/engine/inc/FeedEngine.h	Fri Nov 19 01:08:10 2010 +0000
@@ -97,6 +97,7 @@
 
 	IMPORT_C void OpmlParsingCompleteL(TInt aError, TUint aNumFeedsAdded);
 	void NotifyFeedUpdateComplete(TInt aFeedUid, TInt aError);
+	void ParserShowUpdatedL(CShowInfo& aShow);
 	
 protected:
 	
@@ -154,10 +155,6 @@
 	// observers that will receive callbacks, not owning
     RArray<MFeedEngineObserver*> iObservers;
     
-    // new feeds only add one show to download list when auto downloading
-    TBool newFeed;
-    TUint showsAdded;
-    
     // offline mode detection
     CRepository* iRepository;
     
--- a/engine/inc/FeedParser.h	Fri Nov 19 00:16:55 2010 +0000
+++ b/engine/inc/FeedParser.h	Fri Nov 19 01:08:10 2010 +0000
@@ -94,13 +94,15 @@
 	void OnError(TInt aErrorCode);
 	TAny* GetExtendedInterface(const TInt32 aUid);
 	CFeedInfo& ActiveFeed();
+	
 private:
 	MFeedParserObserver& iCallbacks;
 	TFeedState iFeedState;
 
 	CShowInfo* iActiveShow;
 	CFeedInfo *iActiveFeed;
-
+	CShowInfo *iNewestShow;
+	
 	TBuf<KBufferLength> iBuffer;
 	TUint iUid;
 	TUint iMaxItems;
@@ -111,6 +113,7 @@
 	TInt iFileSize;
 	TFeedDirection iFeedDirection;
 	TTime iPreviousPubDate;
+	TBool iNewFeed;
 };
 
 #endif
--- a/engine/inc/FeedParserObserver.h	Fri Nov 19 00:16:55 2010 +0000
+++ b/engine/inc/FeedParserObserver.h	Fri Nov 19 01:08:10 2010 +0000
@@ -27,6 +27,7 @@
 public:
 	virtual void NewShowL(CShowInfo& item) = 0;
 	virtual void ParsingCompleteL(CFeedInfo *item) = 0;
+	virtual void ParserShowUpdatedL(CShowInfo& item) = 0;
 };
 
 #endif
--- a/engine/src/FeedEngine.cpp	Fri Nov 19 00:16:55 2010 +0000
+++ b/engine/src/FeedEngine.cpp	Fri Nov 19 01:08:10 2010 +0000
@@ -261,15 +261,7 @@
 		}
 	
 	iActiveFeed = GetFeedInfoByUid(aFeedUid);
-	
 	iCancelRequested = EFalse;
-
-	if (iActiveFeed->LastUpdated() == 0)
-		{
-		newFeed = ETrue;	
-		}
-	
-	showsAdded = 0;
 	
 	iActiveFeed->SetLastError(KErrNone);
 	DBUpdateFeedL(*iActiveFeed);
@@ -312,14 +304,6 @@
 	aItem.SetDescriptionL(*description);
 	CleanupStack::PopAndDestroy(description);
 
-	if (newFeed) {
-		// for new feeds, set all shows played
-		aItem.SetPlayState(EPlayed);
-		// except the first one
-		if (showsAdded == 0) {
-			aItem.SetPlayState(ENeverPlayed);	
-		}
-	}
 	
 	TRAPD(err, iPodcastModel.ShowEngine().AddShowL(aItem));
 
@@ -329,7 +313,6 @@
 		iPodcastModel.ShowEngine().AddDownloadL(aItem);
 		}
 	
-	showsAdded++;
 	DP("CFeedEngine::NewShowL END");
 	}
 
@@ -609,10 +592,7 @@
 				{
 				if (!iCancelRequested) {
 					iActiveFeed->SetLastError(aError);
-					TTime time;
-					time.HomeTime();
-					iActiveFeed->SetLastUpdated(time);
-	
+		
 					if( aError == KErrNone)
 						{
 						// Parse the feed. We need to trap this call since it could leave and then
@@ -655,6 +635,9 @@
 						// even if it fails, this will allow us to move on
 						iClientState = EIdle;
 						}
+					TTime time;
+					time.HomeTime();
+					iActiveFeed->SetLastUpdated(time);
 					}
 				iCancelRequested = EFalse;
 				}break;
@@ -1214,3 +1197,8 @@
 		iObservers[i]->OpmlParsingComplete(aError, aNumFeedsAdded);
 		}
 	}
+
+void CFeedEngine::ParserShowUpdatedL(CShowInfo& aShow)
+	{
+	iPodcastModel.ShowEngine().UpdateShowL(aShow);
+	}
--- a/engine/src/FeedParser.cpp	Fri Nov 19 00:16:55 2010 +0000
+++ b/engine/src/FeedParser.cpp	Fri Nov 19 01:08:10 2010 +0000
@@ -54,6 +54,11 @@
 	iMaxItems = aMaxItems;
 	iStoppedParsing = EFalse;
 	iEncoding = ELatin1;
+	if (iNewestShow)
+		delete iNewestShow;
+	iNewestShow = 0;
+	
+	iNewFeed = (iActiveFeed->LastUpdated() == 0) ? ETrue : EFalse;
 
 	TEntry entry;
 	User::LeaveIfError(iRfs.Entry(feedFileName, entry));
@@ -89,6 +94,18 @@
 void CFeedParser::OnEndDocumentL(TInt /*aErrorCode*/)
 	{
 	//DP("OnEndDocumentL()");
+	if (iNewFeed)
+		{
+		// if the feed adds at bottom, this 
+		if (iNewestShow)
+			{
+			iNewestShow->SetPlayState(ENeverPlayed);
+			iCallbacks.ParserShowUpdatedL(*iNewestShow);
+			delete iNewestShow;
+			iNewestShow = 0;
+			}
+		}
+	
 	iCallbacks.ParsingCompleteL(iActiveFeed);
 	}
 
@@ -321,12 +338,25 @@
 					iPreviousPubDate = iActiveShow->PubDate();
 					}
 				
-				
 				if (iUid)
 					{
 					iActiveShow->SetUid(iUid);
 					}
+				
+				if (iNewFeed)
+					{
+					// set all played, except for the newest one
+					iActiveShow->SetPlayState(EPlayed);
+					
+					if (!iNewestShow || iActiveShow->PubDate() > iNewestShow->PubDate())
+						{
+						if (iNewestShow)
+							delete iNewestShow;
 						
+						iNewestShow = new CShowInfo(iActiveShow);
+						}
+					}
+					
 				iCallbacks.NewShowL(*iActiveShow);
 				
 				delete iActiveShow;