Fix for bug where we always load the feed icon a large number of times
authorteknolog
Wed, 03 Mar 2010 23:56:05 +0000
changeset 32 26a3f2dfba08
parent 31 8a5ead064c4f
child 33 64ed1227e68d
Fix for bug where we always load the feed icon a large number of times
application/inc/PodcastFeedView.h
application/inc/PodcastShowsView.h
application/sis/podcatcher_udeb.sis
application/sis/podcatcher_udeb_signed.sis
application/sis/podcatcher_urel.sis
application/sis/podcatcher_urel_signed.sis
application/src/PodcastFeedView.cpp
application/src/PodcastShowsView.cpp
engine/inc/FeedEngine.h
engine/inc/FeedInfo.h
engine/inc/ImageHandler.h
engine/inc/PodcastModel.h
engine/src/FeedEngine.cpp
engine/src/FeedInfo.cpp
engine/src/ImageHandler.cpp
engine/src/PodcastModel.cpp
--- a/application/inc/PodcastFeedView.h	Wed Mar 03 22:24:42 2010 +0000
+++ b/application/inc/PodcastFeedView.h	Wed Mar 03 23:56:05 2010 +0000
@@ -95,7 +95,7 @@
 		void DialogDismissedL(TInt aButtonId); 
 
 		// from MImageHandlerCallback
-		void ImageOperationCompleteL(TInt aError);
+		void ImageOperationCompleteL(TInt aError, TUint aHandle);
 		
 		void HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation);
 
--- a/application/inc/PodcastShowsView.h	Wed Mar 03 22:24:42 2010 +0000
+++ b/application/inc/PodcastShowsView.h	Wed Mar 03 23:56:05 2010 +0000
@@ -109,7 +109,7 @@
 	 * @param aError Error code given by the CImageHandler or 0 (zero) if the
 	 *   image was loaded successfully.
 	 */
-	virtual void ImageOperationCompleteL(TInt aError);
+	virtual void ImageOperationCompleteL(TInt aError, TUint aHandle);
 	void HandleSetShowPlayed(TBool aPlayed);
 	void HandleDeleteShow();
 	void UpdateViewTitleL();
Binary file application/sis/podcatcher_udeb.sis has changed
Binary file application/sis/podcatcher_udeb_signed.sis has changed
Binary file application/sis/podcatcher_urel.sis has changed
Binary file application/sis/podcatcher_urel_signed.sis has changed
--- a/application/src/PodcastFeedView.cpp	Wed Mar 03 22:24:42 2010 +0000
+++ b/application/src/PodcastFeedView.cpp	Wed Mar 03 23:56:05 2010 +0000
@@ -371,6 +371,11 @@
 				aFeedInfo.LastUpdated().FormatL(updatedDate, KDateFormatShort());
 				}
 			}
+		
+		if(aFeedInfo.LastError() != KErrNone)
+			{
+			GetFeedErrorText(unplayedShows, aFeedInfo.LastError());
+			}
 		}
 	CArrayPtr<CGulIcon>* icons = iListContainer->Listbox()->ItemDrawer()->FormattedCellData()->IconArray();
 	
@@ -395,16 +400,11 @@
 			if(BaflUtils::FileExists(iPodcastModel.FsSession(), aFeedInfo.ImageFileName()))
 			{
 			// If this fails, no reason to worry
-			TRAP_IGNORE(iPodcastModel.ImageHandler().LoadFileAndScaleL(aFeedInfo.FeedIcon(), aFeedInfo.ImageFileName(), TSize(64,56), *this));
+			TRAP_IGNORE(iPodcastModel.ImageHandler().LoadFileAndScaleL(aFeedInfo.FeedIcon(), aFeedInfo.ImageFileName(), TSize(64,56), *this, aFeedInfo.Uid()));
 			}
 		}
 	}
 	
-	if(aFeedInfo.LastError() != KErrNone)
-		{
-		GetFeedErrorText(unplayedShows, aFeedInfo.LastError());
-		}
-		
 	if (unplayedShows.Length() > 0) {
 		unplayedShows.Insert(0,_L(", "));
 	}
@@ -412,10 +412,10 @@
 	iListboxFormatbuffer.Format(KFeedFormat(), iconIndex, &(aFeedInfo.Title()), &updatedDate,  &unplayedShows);
 	}
 
-void CPodcastFeedView::ImageOperationCompleteL(TInt aError)
+void CPodcastFeedView::ImageOperationCompleteL(TInt aError, TUint aHandle)
 	{
 	if (aError == KErrNone) {
-		UpdateListboxItemsL();
+	UpdateFeedInfoStatusL(aHandle, EFalse);
 	}
 	}
 
--- a/application/src/PodcastShowsView.cpp	Wed Mar 03 22:24:42 2010 +0000
+++ b/application/src/PodcastShowsView.cpp	Wed Mar 03 23:56:05 2010 +0000
@@ -619,7 +619,7 @@
 		}
 }
 	
-void CPodcastShowsView::ImageOperationCompleteL(TInt aError)
+void CPodcastShowsView::ImageOperationCompleteL(TInt aError, TUint /*aHandle*/)
 	{
 	iLastImageHandlerError = aError;
 	if(iSetTitlebarImage)
--- a/engine/inc/FeedEngine.h	Wed Mar 03 22:24:42 2010 +0000
+++ b/engine/inc/FeedEngine.h	Wed Mar 03 23:56:05 2010 +0000
@@ -162,6 +162,7 @@
     COpmlParser* iOpmlParser;
 	RFeedInfoArray iSearchResults;
 	TBool iAutoUpdatedInitiator;
+	TBool iCancelRequested;
 };
 #endif /*FEEDENGINE_H_*/
 
--- a/engine/inc/FeedInfo.h	Wed Mar 03 22:24:42 2010 +0000
+++ b/engine/inc/FeedInfo.h	Wed Mar 03 23:56:05 2010 +0000
@@ -76,7 +76,7 @@
 	private:
 		CFeedInfo();
 		void ConstructL();
-		void ImageOperationCompleteL(TInt aError);
+		void ImageOperationCompleteL(TInt aError, TUint aHandle);
 	private:
 		HBufC* iUrl;
 		HBufC* iTitle;
--- a/engine/inc/ImageHandler.h	Wed Mar 03 22:24:42 2010 +0000
+++ b/engine/inc/ImageHandler.h	Wed Mar 03 23:56:05 2010 +0000
@@ -43,7 +43,7 @@
     * @param aError Error code given by the CImageHandler or 0 (zero) if the
     *   image was loaded successfully.
     */
-    virtual void ImageOperationCompleteL(TInt aError) = 0;
+    virtual void ImageOperationCompleteL(TInt aError, TUint aHandle) = 0;
     };
 
 // ============================================================================
@@ -54,6 +54,7 @@
 	TSize iScaledSize;
 	MImageHandlerCallback* iCallBack;
 	TFileName iFileName;
+	TUint iHandle;
 	};
 /**
 *  CImageHandler
@@ -104,6 +105,7 @@
 							   const TFileName& aFileName,
                                const TSize &aSize,
                                MImageHandlerCallback& aCallback,
+                               TUint aHandle,
                                TInt aSelectedFrame = 0);
 
         /**
@@ -176,7 +178,10 @@
 
         /** target size for scaled image */
         TSize                   iSize;
-        RArray<TImageStruct> iCallbackQue;      
+        RArray<TImageStruct> iCallbackQue;  
+        
+        /* Handle passed back to caller */
+        TUint iHandle;
     };
 
 #endif
--- a/engine/inc/PodcastModel.h	Wed Mar 03 22:24:42 2010 +0000
+++ b/engine/inc/PodcastModel.h	Wed Mar 03 23:56:05 2010 +0000
@@ -102,7 +102,7 @@
 	CPodcastModel();
 	void ConstructL();
 	// From ImageHandler
-	void ImageOperationCompleteL(TInt aError);
+	void ImageOperationCompleteL(TInt aError, TUint aHandle);
 private:	
    CShowInfo* iPlayingPodcast;
    
--- a/engine/src/FeedEngine.cpp	Wed Mar 03 22:24:42 2010 +0000
+++ b/engine/src/FeedEngine.cpp	Wed Mar 03 23:56:05 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);
+	DBUpdateFeed(*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;
 			}
 		
--- a/engine/src/FeedInfo.cpp	Wed Mar 03 22:24:42 2010 +0000
+++ b/engine/src/FeedInfo.cpp	Wed Mar 03 23:56:05 2010 +0000
@@ -229,7 +229,7 @@
 	iFeedIcon->Duplicate(aBitmapToClone->Handle());
 	}
 
-void CFeedInfo::ImageOperationCompleteL(TInt /*aError*/)
+void CFeedInfo::ImageOperationCompleteL(TInt /*aError*/, TUint /*aHandle*/)
 	{
 	
 	}
--- a/engine/src/ImageHandler.cpp	Wed Mar 03 22:24:42 2010 +0000
+++ b/engine/src/ImageHandler.cpp	Wed Mar 03 23:56:05 2010 +0000
@@ -17,6 +17,7 @@
 */
 
 #include "ImageHandler.h"
+#include "debug.h"
 
 // =============================================================================
 // CImageHandler, a utility class for loading images.
@@ -121,8 +122,11 @@
 								      const TFileName& aFileName,
                                       const TSize &aSize,
                                       MImageHandlerCallback& aCallback,
+                                      TUint aHandle,
                                       TInt aSelectedFrame)
-    {        
+    {
+    DP1("CImageHandler::LoadFileAndScaleL, iCallbackQueue.Count()=%d", iCallbackQue.Count());
+
     if(!IsActive())
     	{
     	__ASSERT_ALWAYS(!IsActive(),User::Invariant());
@@ -130,16 +134,26 @@
     	iScaledBitmap = aScaledBitmap;
     	iScaledBitmap->Reset();
     	iScaledBitmap->Create(aSize, EColor16M);
-    	iCallback = &aCallback; 
+    	iCallback = &aCallback;
+    	iHandle = aHandle;
     	LoadFileL(aFileName, aSelectedFrame);
     	}
     else
     	{
+    	for (int i=0;i<iCallbackQue.Count();i++)
+    		{
+    		if (iCallbackQue[i].iFileName.Compare(aFileName) == 0)
+    			{
+				User::Leave(KErrAlreadyExists);
+    			}
+    		}
+    	
     	TImageStruct imageStruct;
     	imageStruct.iCallBack = &aCallback;
     	imageStruct.iScaledImage = aScaledBitmap;
     	imageStruct.iScaledSize = aSize;    
     	imageStruct.iFileName = aFileName;
+    	imageStruct.iHandle = aHandle;
     	iCallbackQue.Append(imageStruct);
     	}
     }
@@ -179,6 +193,7 @@
 //
 void CImageHandler::RunL()
     {
+    DP1("CImageHandler::RunL(), iCallbackQueue.Count()=%d", iCallbackQue.Count());
     if ((! iStatus.Int()) && (iSize.iWidth != 0) && (iSize.iHeight != 0))
         {
         ScaleL();
@@ -187,7 +202,7 @@
     else
         {
         // Invoke callback.
-        iCallback->ImageOperationCompleteL(iStatus.Int());        
+        iCallback->ImageOperationCompleteL(iStatus.Int(), iHandle);        
         if(iCallbackQue.Count())
         	{
         	TInt loaderror = KErrNotFound;
@@ -195,7 +210,7 @@
         		{
         		TImageStruct imageStruct= iCallbackQue[0];
         		iCallbackQue.Remove(0);
-        		TRAP(loaderror, LoadFileAndScaleL(imageStruct.iScaledImage, imageStruct.iFileName, imageStruct.iScaledSize, *imageStruct.iCallBack));
+        		TRAP(loaderror, LoadFileAndScaleL(imageStruct.iScaledImage, imageStruct.iFileName, imageStruct.iScaledSize, *imageStruct.iCallBack, imageStruct.iHandle));
         		}
         	}
         }
--- a/engine/src/PodcastModel.cpp	Wed Mar 03 22:24:42 2010 +0000
+++ b/engine/src/PodcastModel.cpp	Wed Mar 03 23:56:05 2010 +0000
@@ -435,7 +435,7 @@
 	}
 
 
-void CPodcastModel::ImageOperationCompleteL(TInt /*aError*/)
+void CPodcastModel::ImageOperationCompleteL(TInt /*aError*/, TUint /*aHandle*/)
 	{
 	
 	}