Fix for bug 2780 - we now compare file sizes as well as lastPubDate to tell if a feed is updated RCL_3
authorSebastian Brannstrom <sebastianb@symbian.org>
Sat, 13 Nov 2010 11:50:23 +0000
branchRCL_3
changeset 342 9441fb8fd60d
parent 341 a648d7ca5e27
child 367 4b75876aa85a
Fix for bug 2780 - we now compare file sizes as well as lastPubDate to tell if a feed is updated
engine/inc/FeedEngine.h
engine/inc/FeedInfo.h
engine/inc/FeedParser.h
engine/src/FeedEngine.cpp
engine/src/FeedInfo.cpp
engine/src/FeedParser.cpp
--- a/engine/inc/FeedEngine.h	Sat Nov 13 11:53:11 2010 +0000
+++ b/engine/inc/FeedEngine.h	Sat Nov 13 11:50:23 2010 +0000
@@ -131,7 +131,7 @@
 	TUint DBGetFeedCountL();
 	void DBUpdateFeedL(const CFeedInfo& aItem);
 	void DBGetStatsByFeedL(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed);
-
+	void DBEnsureFileSizeFieldExists();
 		
 private:
 	CHttpClient* iFeedClient;
--- a/engine/inc/FeedInfo.h	Sat Nov 13 11:53:11 2010 +0000
+++ b/engine/inc/FeedInfo.h	Sat Nov 13 11:50:23 2010 +0000
@@ -70,7 +70,10 @@
 		
 		IMPORT_C CFbsBitmap* FeedIcon() const;
 		IMPORT_C void SetFeedIcon(CFbsBitmap* aBitmapToClone);
-		
+
+		IMPORT_C TInt FeedFileSize() const;
+		IMPORT_C void SetFeedFileSize(TInt aSize);
+
 	private:
 		CFeedInfo();
 		void ConstructL();
@@ -88,6 +91,7 @@
 		TBool iCustomTitle;
 		TInt   iLastError;
 		CFbsBitmap* iFeedIcon;	
+		TInt iFeedSize;
 	};
 
 typedef RPointerArray<CFeedInfo> RFeedInfoArray;
--- a/engine/inc/FeedParser.h	Sat Nov 13 11:53:11 2010 +0000
+++ b/engine/inc/FeedParser.h	Sat Nov 13 11:50:23 2010 +0000
@@ -101,6 +101,7 @@
 	TBool iStoppedParsing;
 	TEncoding iEncoding;
 	RFs& iRfs;
+	TInt iFileSize;
 };
 
 #endif
--- a/engine/src/FeedEngine.cpp	Sat Nov 13 11:53:11 2010 +0000
+++ b/engine/src/FeedEngine.cpp	Sat Nov 13 11:50:23 2010 +0000
@@ -53,6 +53,8 @@
 	TInt err = KErrNone;
 	TInt feedCount = 0;
 	
+	DBEnsureFileSizeFieldExists();
+	
 	TRAP(err, feedCount = DBGetFeedCountL());
     if (err == KErrNone && feedCount > 0)
     	{
@@ -410,10 +412,10 @@
 	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, filesize) values (\"%S\",\"%S\", \"%S\", \"%S\", \"%S\", \"%S\", \"%Ld\", \"%Ld\", \"%u\", \"%u\", \"%u\", \"%d\", \"%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());
+			aItem.BuildDate().Int64(), aItem.LastUpdated().Int64(), aItem.Uid(), EAudioPodcast, aItem.CustomTitle(), aItem.LastError(), aItem.FeedFileSize());
 
 	CleanupStack::PopAndDestroy(descBuf);
 	CleanupStack::PopAndDestroy(titleBuf);
@@ -523,11 +525,10 @@
 	TPtr descPtr(descBuf->Des());
 	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\", filesize=\"%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());
+			aItem.BuildDate().Int64(), aItem.LastUpdated().Int64(), EAudioPodcast, aItem.CustomTitle(), aItem.LastError(), aItem.FeedFileSize(), aItem.Uid());
 
 	CleanupStack::PopAndDestroy(descBuf);
 	CleanupStack::PopAndDestroy(titleBuf);
@@ -731,6 +732,25 @@
 
 void CFeedEngine::DownloadInfo(CHttpClient* /*aHttpClient */, int /*aTotalBytes*/)
 	{	
+	
+	}
+
+void CFeedEngine::DBEnsureFileSizeFieldExists()
+	{
+	DP("DBEnsureFileSizeFieldExists BEGIN");
+	sqlite3_stmt *st;
+	int rc = sqlite3_prepare_v2(&iDB,"alter table feeds add column filesize int" , -1, &st, (const char**) NULL);
+	DP1("    rc=%d", rc);
+	 
+	if( rc==SQLITE_OK )
+		{
+		Cleanup_sqlite3_finalize_PushL(st);
+		rc = sqlite3_step(st);
+		DP1("    rc=%d", rc);
+		CleanupStack::PopAndDestroy(); // st
+		}
+
+	DP("DBEnsureFileSizeFieldExists END");
 	}
 
 EXPORT_C void CFeedEngine::ImportFeedsL(const TDesC& aFile)
@@ -949,7 +969,7 @@
 	iSortedFeeds.Reset();
 	CFeedInfo *feedInfo = NULL;
 	
-	_LIT(KSqlStatement, "select url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror from feeds");
+	_LIT(KSqlStatement, "select url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror, filesize from feeds");
 	iSqlBuffer.Format(KSqlStatement);
 
 	sqlite3_stmt *st;
@@ -1009,7 +1029,10 @@
 			
 			sqlite3_int64 lasterror = sqlite3_column_int(st, 11);
 			feedInfo->SetLastError(lasterror);
-			
+		
+			TInt filesize = sqlite3_column_int(st, 12);
+			feedInfo->SetFeedFileSize(filesize);
+
 			TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
 
 			iSortedFeeds.InsertInOrder(feedInfo, sortOrder);
@@ -1032,7 +1055,7 @@
 	{
 	DP("CFeedEngine::DBGetFeedInfoByUid BEGIN");
 	CFeedInfo *feedInfo = NULL;
-	_LIT(KSqlStatement, "select url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror from feeds where uid=%u");
+	_LIT(KSqlStatement, "select url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror, filesize from feeds where uid=%u");
 	iSqlBuffer.Format(KSqlStatement, aFeedUid);
 
 	sqlite3_stmt *st;
@@ -1086,7 +1109,10 @@
 			
 			TInt lasterror = sqlite3_column_int(st, 11);
 			feedInfo->SetLastError(lasterror);
-						
+	
+			TInt filesize = sqlite3_column_int(st, 12);
+			feedInfo->SetFeedFileSize(filesize);
+		
 			CleanupStack::Pop(feedInfo);
 			}
 		else
--- a/engine/src/FeedInfo.cpp	Sat Nov 13 11:53:11 2010 +0000
+++ b/engine/src/FeedInfo.cpp	Sat Nov 13 11:50:23 2010 +0000
@@ -279,3 +279,15 @@
 		aPodcastModel.FeedEngine().NotifyFeedUpdateComplete(this->iUid, KErrNone);
 		}
 	}
+
+
+EXPORT_C TInt CFeedInfo::FeedFileSize() const
+	{
+	return iFeedSize;
+	}
+
+EXPORT_C void CFeedInfo::SetFeedFileSize(TInt aSize)
+	{
+	iFeedSize = aSize;
+	}
+
--- a/engine/src/FeedParser.cpp	Sat Nov 13 11:53:11 2010 +0000
+++ b/engine/src/FeedParser.cpp	Sat Nov 13 11:50:23 2010 +0000
@@ -55,6 +55,10 @@
 	iStoppedParsing = EFalse;
 	iEncoding = ELatin1;
 
+	TEntry entry;
+	User::LeaveIfError(iRfs.Entry(feedFileName, entry));
+	iFileSize = entry.iSize;
+	
 	ParseL(*parser, iRfs, feedFileName);
 
 	CleanupStack::PopAndDestroy(parser);	
@@ -250,18 +254,21 @@
 			TBuf8<128> temp;
 			temp.Copy(iBuffer);
 					
+			DP2("iFileSize=%d, iActiveFeed->FeedFileSize()=%d", iFileSize, iActiveFeed->FeedFileSize());
+					
 			TRAPD(parseError, internetDate.SetDateL(temp));
 			if(parseError == KErrNone) {				
 				if (TTime(internetDate.DateTime()) > iActiveFeed->BuildDate()) {
 					DP("Successfully parsed build date");
 					iActiveFeed->SetBuildDate(TTime(internetDate.DateTime()));
-				} else {
+				} else if (iFileSize == iActiveFeed->FeedFileSize()){
 					DP("*** Nothing new, aborting parsing");
 					iStoppedParsing = ETrue;
 				}
 			} else {
 				DP("Failed to parse last build date");
 			}
+			iActiveFeed->SetFeedFileSize(iFileSize);
 			iFeedState = EStateChannel;
 			}
 			break;