--- a/engine/src/FeedEngine.cpp Wed Jul 07 23:27:49 2010 +0100
+++ b/engine/src/FeedEngine.cpp Fri Jul 09 11:34:00 2010 +0100
@@ -41,7 +41,7 @@
void CFeedEngine::ConstructL()
{
- iParser = new (ELeave) CFeedParser(*this, iPodcastModel.FsSession());
+ iParser = CFeedParser::NewLC(*this, iPodcastModel.FsSession());
iFeedClient = CHttpClient::NewL(iPodcastModel, *this);
iFeedTimer.ConstructL();
@@ -80,11 +80,12 @@
TRAP_IGNORE(ImportFeedsL(importFile));
}
+ CleanupStack::Pop(iParser);
RunFeedTimer();
}
CFeedEngine::CFeedEngine(CPodcastModel& aPodcastModel)
- : iClientState(EIdle),
+ : iEngineState(EIdle),
iFeedTimer(this),
iPodcastModel(aPodcastModel),
iDB(*aPodcastModel.DB())
@@ -107,9 +108,9 @@
/**
* Returns the current internal state of the feed engine4
*/
-EXPORT_C TClientState CFeedEngine::ClientState()
+EXPORT_C TFeedEngineState CFeedEngine::ClientState()
{
- return iClientState;
+ return iEngineState;
}
@@ -144,7 +145,7 @@
EXPORT_C void CFeedEngine::UpdateAllFeedsL(TBool aAutoUpdate)
{
- if (iClientState != EIdle)
+ if (iEngineState != EIdle)
{
User::Leave(KErrInUse);
}
@@ -169,7 +170,7 @@
EXPORT_C void CFeedEngine::CancelUpdateAllFeeds()
{
- if(iClientState != EIdle)
+ if(iEngineState != EIdle)
{
iCancelRequested = ETrue;
iFeedsUpdating.Reset();
@@ -181,7 +182,7 @@
{
DP1("UpdateNextFeed. %d feeds left to update", iFeedsUpdating.Count());
- if (iClientState != EIdle)
+ if (iEngineState != EIdle)
{
User::Leave(KErrInUse);
}
@@ -216,7 +217,7 @@
}
else
{
- iClientState = EIdle;
+ iEngineState = EIdle;
for (TInt i=0;i<iObservers.Count();i++)
{
TRAP_IGNORE(iObservers[i]->FeedUpdateAllCompleteL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate));
@@ -239,10 +240,10 @@
if (iActiveFeed->LastUpdated() == 0)
{
- newFeed = ETrue;
+ iNewFeed = ETrue;
}
- showsAdded = 0;
+ iShowsAdded = 0;
iActiveFeed->SetLastError(KErrNone);
DBUpdateFeedL(*iActiveFeed);
@@ -254,7 +255,7 @@
_LIT(KFileNameFormat, "%lu.xml");
iUpdatingFeedFileName.AppendFormat(KFileNameFormat, aFeedUid);
- iClientState = EUpdatingFeed;
+ iEngineState = EDownloadingFeed;
for (TInt i=0;i<iObservers.Count();i++)
{
@@ -284,24 +285,24 @@
aItem.SetDescriptionL(*description);
CleanupStack::PopAndDestroy(description);
- if (newFeed) {
+ if (iNewFeed) {
// for new feeds, set all shows played
aItem.SetPlayState(EPlayed);
// except the first one
- if (showsAdded == 0) {
+ if (iShowsAdded == 0) {
aItem.SetPlayState(ENeverPlayed);
}
}
TRAPD(err, iPodcastModel.ShowEngine().AddShowL(aItem));
-
+
if (err == KErrNone && aItem.PlayState() == ENeverPlayed &&
iPodcastModel.SettingsEngine().DownloadAutomatically())
{
iPodcastModel.ShowEngine().AddDownloadL(aItem);
+ iShowsAdded++;
}
- showsAdded++;
}
void CFeedEngine::GetFeedImageL(CFeedInfo *aFeedInfo)
@@ -327,7 +328,7 @@
if(iFeedClient->GetL(aFeedInfo->ImageUrl(), filePath, ETrue))
{
- iClientState = EUpdatingImage;
+ iEngineState = EDownloadingImage;
}
}
@@ -527,6 +528,7 @@
TBuf<KMaxLineLength> title;
title.Copy(item->Title());
item->SetTitleL(title); // if this leaves we are out of memory
+ CompleteL(NULL, KErrNone);
}
@@ -555,26 +557,32 @@
void CFeedEngine::CompleteL(CHttpClient* /*aClient*/, TInt aError)
{
- DP2("CFeedEngine::CompleteL BEGIN, iClientState=%d, aSuccessful=%d", iClientState, aError);
+ DP2("CFeedEngine::CompleteL BEGIN, iEngineState=%d, aSuccessful=%d", iEngineState, aError);
- switch(iClientState)
+ switch(iEngineState)
{
- case EUpdatingFeed:
+ case EDownloadingFeed:
{
- iClientState = EIdle;
switch (aError)
{
case KErrCancel:
{
iFeedsUpdating.Reset();
+ iEngineState = EIdle;
}
break;
case KErrCouldNotConnect:
iFeedsUpdating.Reset();
+ iEngineState = EIdle;
break;
default:
{
- if (!iCancelRequested) {
+ if (iCancelRequested)
+ {
+ iEngineState = EIdle;
+ }
+ else
+ {
iActiveFeed->SetLastError(aError);
TTime time;
time.HomeTime();
@@ -585,60 +593,64 @@
// Parse the feed. We need to trap this call since it could leave and then
// the whole update chain will be broken
// change client state
- TRAPD(parserErr, iParser->ParseFeedL(iUpdatingFeedFileName, iActiveFeed, iPodcastModel.SettingsEngine().MaxListItems()));
+ TRAPD(parserErr, iParser->ParseFeedAoL(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);
+ iEngineState = EIdle;
}
-
- // 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))
+ else
{
- if ( (iActiveFeed->ImageFileName().Length() == 0) ||
- (iActiveFeed->ImageFileName().Length() > 0 &&
- !BaflUtils::FileExists(iPodcastModel.FsSession(),
- iActiveFeed->ImageFileName()) )
- )
- {
- 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;
- }
- }
+ iEngineState = EParsingFeed;
}
}
else
{
// even if it fails, this will allow us to move on
- iClientState = EIdle;
+ iEngineState = EIdle;
}
}
- iCancelRequested = EFalse;
}break;
}
- DBUpdateFeedL(*iActiveFeed);
NotifyFeedUpdateComplete(iActiveFeed->Uid(), aError);
-
- // we will wait until the image has been downloaded to start the next feed update.
- if (iClientState == EIdle)
+ }
+ break;
+ case EParsingFeed:
+ {
+ // if the feed has specified a image url. download it if we dont already have it
+ if((iActiveFeed->ImageUrl().Length() > 0))
{
- UpdateNextFeedL();
+ if ( (iActiveFeed->ImageFileName().Length() == 0) ||
+ (iActiveFeed->ImageFileName().Length() > 0 &&
+ !BaflUtils::FileExists(iPodcastModel.FsSession(),
+ iActiveFeed->ImageFileName()) )
+ )
+ {
+ 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(error);
+ iEngineState = EIdle;
+ NotifyFeedUpdateComplete(iActiveFeed->Uid(), error);
+ }
+ }
+ else
+ {
+ iEngineState = EIdle;
+ NotifyFeedUpdateComplete(iActiveFeed->Uid(), aError);
+ }
}
- }break;
- case EUpdatingImage:
+ }
+ break;
+ case EDownloadingImage:
{
// change client state to not updating
- iClientState = EIdle;
+ iEngineState = EIdle;
if(aError == KErrNone)
{
// now the image has been downloaded, so we set it again in the FeedInfo to start
@@ -647,13 +659,11 @@
TRAP_IGNORE(iActiveFeed->SetImageFileNameL(*fileNameCopy, &iPodcastModel));
CleanupStack::PopAndDestroy(fileNameCopy);
}
- DBUpdateFeedL(*iActiveFeed);
NotifyFeedUpdateComplete(iActiveFeed->Uid(), aError);
- UpdateNextFeedL();
}break;
case ESearching:
{
- iClientState = EIdle;
+ iEngineState = EIdle;
DP2("Search complete, results in %S with error %d", &iSearchResultsFileName, aError);
if(aError == KErrNone)
@@ -685,7 +695,16 @@
void CFeedEngine::NotifyFeedUpdateComplete(TInt aFeedUid, TInt aError)
{
- DP("CFeedEngine::NotifyFeedUpdateComplete");
+ DP("CFeedEngine::NotifyFeedUpdateComplete");
+
+ DBUpdateFeedL(*iActiveFeed);
+
+ // we will wait until the image has been downloaded to start the next feed update.
+ if (iEngineState == EIdle)
+ {
+ UpdateNextFeedL();
+ }
+
for (TInt i=0;i<iObservers.Count();i++)
{
TRAP_IGNORE(iObservers[i]->FeedDownloadFinishedL(MFeedEngineObserver::EFeedAutoUpdate, aFeedUid, aError));
@@ -1084,7 +1103,7 @@
{
DP1("FeedEngine::SearchForFeedL BEGIN, aSearchString=%S", &aSearchString);
- if (iClientState != EIdle) {
+ if (iEngineState != EIdle) {
User::Leave(KErrInUse);
}
TBuf<KMaxURLLength> ssBuf;
@@ -1107,11 +1126,11 @@
// run search
if(iFeedClient->GetL(*url, iSearchResultsFileName, iPodcastModel.SettingsEngine().SpecificIAP()))
{
- iClientState = ESearching;
+ iEngineState = ESearching;
}
else
{
- iClientState = EIdle;
+ iEngineState = EIdle;
User::Leave(KErrAbort);
}