engine/src/FeedEngine.cpp
changeset 36 e010fc411ddc
parent 35 66c5303f3610
parent 32 26a3f2dfba08
child 53 b778853e60a7
child 65 bcd88ba95046
--- a/engine/src/FeedEngine.cpp	Sat Mar 06 10:22:09 2010 +0000
+++ b/engine/src/FeedEngine.cpp	Sat Mar 06 10:28:29 2010 +0000
@@ -158,6 +158,7 @@
 	{
 	if(iClientState != EIdle)
 		{
+		iCancelRequested = ETrue;
 		iFeedsUpdating.Reset();
 		iFeedClient->Stop();
 		}
@@ -199,12 +200,16 @@
 	DP("FeedEngine::UpdateFeedL BEGIN");
 	iActiveFeed = GetFeedInfoByUid(aFeedUid);
 	iCatchupCounter = 0;
+	iCancelRequested = EFalse;
 
 	if (iActiveFeed->LastUpdated() == 0)
 		{
 		iCatchupMode = ETrue;
 		}
-
+	
+	iActiveFeed->SetLastError(KErrNone);
+	DBUpdateFeedL(*iActiveFeed);
+	
 	iUpdatingFeedFileName.Copy (iPodcastModel.SettingsEngine().PrivatePath ());
 	_LIT(KFileNameFormat, "%lu.xml");
 	iUpdatingFeedFileName.AppendFormat(KFileNameFormat, aFeedUid);
@@ -533,49 +538,52 @@
 				break;
 			default:
 				{
-				iActiveFeed->SetLastError(aError);
-				TTime time;
-				time.HomeTime();
-				iActiveFeed->SetLastUpdated(time);
-
-				if( aError == KErrNone)
-					{			
-					TRAPD(parserErr, iParser->ParseFeedL(iUpdatingFeedFileName, iActiveFeed, iPodcastModel.SettingsEngine().MaxListItems()));
-
-					if(parserErr)
-						{
-						// we do not need to any special action on this error.
-						iActiveFeed->SetLastError(parserErr);
-						DP1("CFeedEngine::Complete()\t Failed to parse feed. Leave with error code=%d", parserErr);
-						}
-					else
-						{
-						iPodcastModel.ShowEngine().DeleteOldShowsByFeed(iActiveFeed->Uid());
-						}
-
-					// delete the downloaded XML file as it is no longer needed
-					BaflUtils::DeleteFile(iPodcastModel.FsSession(),iUpdatingFeedFileName);			
-
-					// if the feed has specified a image url. download it if we dont already have it
-					if((iActiveFeed->ImageUrl().Length() > 0))
-						{
-						if ( (iActiveFeed->ImageFileName().Length() == 0) || 
-								(iActiveFeed->ImageFileName().Length() > 0 && 
-										!BaflUtils::FileExists(iPodcastModel.FsSession(), 
-												iActiveFeed->ImageFileName()) )
-						)
+				if (!iCancelRequested) {
+					iActiveFeed->SetLastError(aError);
+					TTime time;
+					time.HomeTime();
+					iActiveFeed->SetLastUpdated(time);
+	
+					if( aError == KErrNone)
+						{			
+						TRAPD(parserErr, iParser->ParseFeedL(iUpdatingFeedFileName, iActiveFeed, iPodcastModel.SettingsEngine().MaxListItems()));
+	
+						if(parserErr)
+							{
+							// we do not need to any special action on this error.
+							iActiveFeed->SetLastError(parserErr);
+							DP1("CFeedEngine::Complete()\t Failed to parse feed. Leave with error code=%d", parserErr);
+							}
+						else
 							{
-							TRAPD(error, GetFeedImageL(iActiveFeed));
-							if (error)
+							iPodcastModel.ShowEngine().DeleteOldShowsByFeed(iActiveFeed->Uid());
+							}
+	
+						// delete the downloaded XML file as it is no longer needed
+						BaflUtils::DeleteFile(iPodcastModel.FsSession(),iUpdatingFeedFileName);			
+	
+						// if the feed has specified a image url. download it if we dont already have it
+						if((iActiveFeed->ImageUrl().Length() > 0))
+							{
+							if ( (iActiveFeed->ImageFileName().Length() == 0) || 
+									(iActiveFeed->ImageFileName().Length() > 0 && 
+											!BaflUtils::FileExists(iPodcastModel.FsSession(), 
+													iActiveFeed->ImageFileName()) )
+							)
 								{
-								// we have failed in a very early stage to fetch the image.
-								// continue with next Feed update	
-								iActiveFeed->SetLastError(parserErr);
-								iClientState = EIdle;							
-								}
-							}	
+								TRAPD(error, GetFeedImageL(iActiveFeed));
+								if (error)
+									{
+									// we have failed in a very early stage to fetch the image.
+									// continue with next Feed update	
+									iActiveFeed->SetLastError(parserErr);
+									iClientState = EIdle;							
+									}
+								}	
+							}
 						}
 					}
+				iCancelRequested = EFalse;
 				}break;
 			}