engine/src/FeedEngine.cpp
changeset 69 04c6ccce8e7e
parent 67 e0fc52a5df4d
child 73 83752b9e3cb6
equal deleted inserted replaced
68:867fc277ffea 69:04c6ccce8e7e
   146 		}
   146 		}
   147 
   147 
   148 	TInt cnt = iSortedFeeds.Count();
   148 	TInt cnt = iSortedFeeds.Count();
   149 	for (int i=0;i<cnt;i++)
   149 	for (int i=0;i<cnt;i++)
   150 		{
   150 		{
   151 		iFeedsUpdating.Append(iSortedFeeds[i]);
   151 		iFeedsUpdating.Append(iSortedFeeds[i]->Uid());
   152 		}
   152 		}
   153 
   153 
   154 	UpdateNextFeedL();
   154 	UpdateNextFeedL();
   155 	}
   155 	}
   156 
   156 
   166 
   166 
   167 void CFeedEngine::UpdateNextFeedL()
   167 void CFeedEngine::UpdateNextFeedL()
   168 	{
   168 	{
   169 	DP1("UpdateNextFeed. %d feeds left to update", iFeedsUpdating.Count());
   169 	DP1("UpdateNextFeed. %d feeds left to update", iFeedsUpdating.Count());
   170 	
   170 	
       
   171 	// reset active feed, will be set again in UpdateFeedL if needed
       
   172 	iActiveFeed = NULL;
       
   173 	
   171 	if (iFeedsUpdating.Count() > 0)
   174 	if (iFeedsUpdating.Count() > 0)
   172 		{
   175 		{
   173 		CFeedInfo *info = iFeedsUpdating[0];
   176 		CFeedInfo *info = GetFeedInfoByUid(iFeedsUpdating[0]);
   174 		iFeedsUpdating.Remove(0);
   177 		iFeedsUpdating.Remove(0);
   175 		TBool result = EFalse;
   178 		
   176 		//DP2("** UpdateNextFeed: %S, ID: %u", &(info->Url()), info->Uid());
   179 		if (info == NULL)
   177 		TRAPD(error, result = UpdateFeedL(info->Uid()));
   180 			{
   178 		
   181 			UpdateNextFeedL();
   179 		if (error != KErrNone || !result)
   182 			}
   180 			{
   183 		else
   181 			DP("Error while updating all feeds");
   184 			{
   182 			for (TInt i=0;i<iObservers.Count();i++) 
   185 			TBool result = EFalse;
       
   186 			//DP2("** UpdateNextFeed: %S, ID: %u", &(info->Url()), info->Uid());
       
   187 			TRAPD(error, result = UpdateFeedL(info->Uid()));
       
   188 			
       
   189 			if (error != KErrNone || !result)
   183 				{
   190 				{
   184 				TRAP_IGNORE(iObservers[i]->FeedUpdateAllCompleteL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate));
   191 				DP("Error while updating all feeds");
       
   192 				for (TInt i=0;i<iObservers.Count();i++) 
       
   193 					{
       
   194 					TRAP_IGNORE(iObservers[i]->FeedUpdateAllCompleteL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate));
       
   195 					}
   185 				}
   196 				}
   186 			}
   197 			}
   187 		}
   198 		}
   188 	else
   199 	else
   189 		{
   200 		{
   196 	}
   207 	}
   197 
   208 
   198 EXPORT_C TBool CFeedEngine::UpdateFeedL(TUint aFeedUid)
   209 EXPORT_C TBool CFeedEngine::UpdateFeedL(TUint aFeedUid)
   199 	{
   210 	{
   200 	DP("FeedEngine::UpdateFeedL BEGIN");
   211 	DP("FeedEngine::UpdateFeedL BEGIN");
       
   212 	
       
   213 	if (iActiveFeed)
       
   214 		{
       
   215 		User::Leave(KErrInUse);
       
   216 		}
       
   217 	
   201 	iActiveFeed = GetFeedInfoByUid(aFeedUid);
   218 	iActiveFeed = GetFeedInfoByUid(aFeedUid);
   202 	iCatchupCounter = 0;
   219 	iCatchupCounter = 0;
   203 	iCancelRequested = EFalse;
   220 	iCancelRequested = EFalse;
   204 
   221 
   205 	if (iActiveFeed->LastUpdated() == 0)
   222 	if (iActiveFeed->LastUpdated() == 0)
   361 	return EFalse;
   378 	return EFalse;
   362 	}
   379 	}
   363 
   380 
   364 EXPORT_C void CFeedEngine::RemoveFeedL(TUint aUid) 
   381 EXPORT_C void CFeedEngine::RemoveFeedL(TUint aUid) 
   365 	{
   382 	{
       
   383 	if (iActiveFeed && iActiveFeed->Uid() == aUid)
       
   384 		{
       
   385 		User::Leave(KErrInUse);
       
   386 		}
       
   387 	
   366 	for (int i=0;i<iSortedFeeds.Count();i++) 
   388 	for (int i=0;i<iSortedFeeds.Count();i++) 
   367 		{
   389 		{
   368 		if (iSortedFeeds[i]->Uid() == aUid) 
   390 		if (iSortedFeeds[i]->Uid() == aUid) 
   369 			{
   391 			{
   370 			iPodcastModel.ShowEngine().DeleteAllShowsByFeedL(aUid);
   392 			iPodcastModel.ShowEngine().DeleteAllShowsByFeedL(aUid);
   508 	{
   530 	{
   509 	DP2("CFeedEngine::CompleteL BEGIN, iClientState=%d, aSuccessful=%d", iClientState, aError);
   531 	DP2("CFeedEngine::CompleteL BEGIN, iClientState=%d, aSuccessful=%d", iClientState, aError);
   510 
   532 
   511 	switch(iClientState)
   533 	switch(iClientState)
   512 		{		
   534 		{		
   513 		default:
       
   514 			if(iActiveFeed != NULL)
       
   515 				{
       
   516 				TTime time;
       
   517 				time.HomeTime();
       
   518 				iActiveFeed->SetLastUpdated(time);
       
   519 				iActiveFeed->SetLastError(aError);
       
   520 				NotifyFeedUpdateComplete(iActiveFeed->Uid(), aError);
       
   521 				}
       
   522 			break;
       
   523 		case EUpdatingFeed: 
   535 		case EUpdatingFeed: 
   524 		{
   536 		{
   525 		// Parse the feed. We need to trap this call since it could leave and then
   537 		// Parse the feed. We need to trap this call since it could leave and then
   526 		// the whole update chain will be broken
   538 		// the whole update chain will be broken
   527 		// change client state
   539 		// change client state
   631 				NotifyOpmlParsingCompleteL(aError, 0);
   643 				NotifyOpmlParsingCompleteL(aError, 0);
   632 				}
   644 				}
   633 			
   645 			
   634 			BaflUtils::DeleteFile(iPodcastModel.FsSession(), iSearchResultsFileName);
   646 			BaflUtils::DeleteFile(iPodcastModel.FsSession(), iSearchResultsFileName);
   635 			}break;
   647 			}break;
       
   648 		default:
       
   649 			User::Panic(_L("FeedEngine"), KErrUnknown);
       
   650 			break;
   636 		}
   651 		}
   637 	DP("CFeedEngine::CompleteL END");
   652 	DP("CFeedEngine::CompleteL END");
   638 	}
   653 	}
   639 
   654 
   640 void CFeedEngine::NotifyFeedUpdateComplete(TInt aFeedUid, TInt aError)
   655 void CFeedEngine::NotifyFeedUpdateComplete(TInt aFeedUid, TInt aError)
  1018 	}
  1033 	}
  1019 	
  1034 	
  1020 	return feedInfo;
  1035 	return feedInfo;
  1021 }
  1036 }
  1022 
  1037 
  1023 EXPORT_C void CFeedEngine::UpdateFeedL(CFeedInfo *aItem)
  1038 EXPORT_C void CFeedEngine::UpdateFeedInfoL(CFeedInfo *aItem)
  1024 	{
  1039 	{
       
  1040 	if (iActiveFeed && iActiveFeed->Uid() == aItem->Uid())
       
  1041 		{
       
  1042 		User::Leave(KErrInUse);
       
  1043 		}
       
  1044 	
  1025 	DBUpdateFeedL(*aItem);
  1045 	DBUpdateFeedL(*aItem);
  1026 	}
  1046 	}
  1027 
  1047 
  1028 EXPORT_C void CFeedEngine::SearchForFeedL(TDesC& aSearchString)
  1048 EXPORT_C void CFeedEngine::SearchForFeedL(TDesC& aSearchString)
  1029 	{
  1049 	{