engine/src/FeedEngine.cpp
branch3rded
changeset 390 d7abecc9d189
parent 343 9c56bf585696
equal deleted inserted replaced
345:702ba9ffe210 390:d7abecc9d189
   259 		{
   259 		{
   260 		User::Leave(KErrInUse);
   260 		User::Leave(KErrInUse);
   261 		}
   261 		}
   262 	
   262 	
   263 	iActiveFeed = GetFeedInfoByUid(aFeedUid);
   263 	iActiveFeed = GetFeedInfoByUid(aFeedUid);
   264 	
       
   265 	iCancelRequested = EFalse;
   264 	iCancelRequested = EFalse;
   266 
       
   267 	if (iActiveFeed->LastUpdated() == 0)
       
   268 		{
       
   269 		newFeed = ETrue;	
       
   270 		}
       
   271 	
       
   272 	showsAdded = 0;
       
   273 	
   265 	
   274 	iActiveFeed->SetLastError(KErrNone);
   266 	iActiveFeed->SetLastError(KErrNone);
   275 	DBUpdateFeedL(*iActiveFeed);
   267 	DBUpdateFeedL(*iActiveFeed);
   276 	
   268 	
   277 	iUpdatingFeedFileName.Copy (iPodcastModel.SettingsEngine().PrivatePath ());
   269 	iUpdatingFeedFileName.Copy (iPodcastModel.SettingsEngine().PrivatePath ());
   310 	PodcastUtils::CleanHtmlL(ptr);
   302 	PodcastUtils::CleanHtmlL(ptr);
   311 
   303 
   312 	aItem.SetDescriptionL(*description);
   304 	aItem.SetDescriptionL(*description);
   313 	CleanupStack::PopAndDestroy(description);
   305 	CleanupStack::PopAndDestroy(description);
   314 
   306 
   315 	if (newFeed) {
       
   316 		// for new feeds, set all shows played
       
   317 		aItem.SetPlayState(EPlayed);
       
   318 		// except the first one
       
   319 		if (showsAdded == 0) {
       
   320 			aItem.SetPlayState(ENeverPlayed);	
       
   321 		}
       
   322 	}
       
   323 	
   307 	
   324 	TRAPD(err, iPodcastModel.ShowEngine().AddShowL(aItem));
   308 	TRAPD(err, iPodcastModel.ShowEngine().AddShowL(aItem));
   325 
   309 
   326 	if (err == KErrNone && aItem.PlayState() == ENeverPlayed && 
   310 	if (err == KErrNone && aItem.PlayState() == ENeverPlayed && 
   327 			iPodcastModel.SettingsEngine().DownloadAutomatically()) 
   311 			iPodcastModel.SettingsEngine().DownloadAutomatically()) 
   328 		{
   312 		{
   329 		iPodcastModel.ShowEngine().AddDownloadL(aItem);
   313 		iPodcastModel.ShowEngine().AddDownloadL(aItem);
   330 		}
   314 		}
   331 	
   315 	
   332 	showsAdded++;
       
   333 	DP("CFeedEngine::NewShowL END");
   316 	DP("CFeedEngine::NewShowL END");
   334 	}
   317 	}
   335 
   318 
   336 void CFeedEngine::GetFeedImageL(CFeedInfo *aFeedInfo)
   319 void CFeedEngine::GetFeedImageL(CFeedInfo *aFeedInfo)
   337 	{
   320 	{
   391 
   374 
   392 void CFeedEngine::DBAddFeedL(const CFeedInfo& aItem)
   375 void CFeedEngine::DBAddFeedL(const CFeedInfo& aItem)
   393 	{
   376 	{
   394 	DP2("CFeedEngine::DBAddFeed BEGIN, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
   377 	DP2("CFeedEngine::DBAddFeed BEGIN, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
   395 	
   378 	
   396 	CFeedInfo *info;
   379 	CFeedInfo *info = NULL;
   397 	
   380 	
   398 	TRAPD(err, info = DBGetFeedInfoByUidL(aItem.Uid()));
   381 	TRAPD(err, info = DBGetFeedInfoByUidL(aItem.Uid()));
   399 	
   382 	
   400 	if (err == KErrNone && info) {
   383 	if (err == KErrNone && info) {
   401 		delete info;
   384 		delete info;
   607 				break;
   590 				break;
   608 			default:
   591 			default:
   609 				{
   592 				{
   610 				if (!iCancelRequested) {
   593 				if (!iCancelRequested) {
   611 					iActiveFeed->SetLastError(aError);
   594 					iActiveFeed->SetLastError(aError);
   612 					TTime time;
   595 		
   613 					time.HomeTime();
       
   614 					iActiveFeed->SetLastUpdated(time);
       
   615 	
       
   616 					if( aError == KErrNone)
   596 					if( aError == KErrNone)
   617 						{
   597 						{
   618 						// Parse the feed. We need to trap this call since it could leave and then
   598 						// Parse the feed. We need to trap this call since it could leave and then
   619 						// the whole update chain will be broken
   599 						// the whole update chain will be broken
   620 						// change client state
   600 						// change client state
   653 					else
   633 					else
   654 						{
   634 						{
   655 						// even if it fails, this will allow us to move on
   635 						// even if it fails, this will allow us to move on
   656 						iClientState = EIdle;
   636 						iClientState = EIdle;
   657 						}
   637 						}
       
   638 					TTime time;
       
   639 					time.HomeTime();
       
   640 					iActiveFeed->SetLastUpdated(time);
   658 					}
   641 					}
   659 				iCancelRequested = EFalse;
   642 				iCancelRequested = EFalse;
   660 				}break;
   643 				}break;
   661 			}
   644 			}
   662 			DBUpdateFeedL(*iActiveFeed);
   645 			DBUpdateFeedL(*iActiveFeed);
   747 		rc = sqlite3_step(st);
   730 		rc = sqlite3_step(st);
   748 		DP1("    rc=%d", rc);
   731 		DP1("    rc=%d", rc);
   749 		CleanupStack::PopAndDestroy(); // st
   732 		CleanupStack::PopAndDestroy(); // st
   750 		}
   733 		}
   751 
   734 
       
   735 	rc = sqlite3_prepare_v2(&iDB,"alter table shows add column deletedate int" , -1, &st, (const char**) NULL);
       
   736 	DP1("    rc=%d", rc);
       
   737 	 
       
   738 	if( rc==SQLITE_OK )
       
   739 		{
       
   740 		Cleanup_sqlite3_finalize_PushL(st);
       
   741 		rc = sqlite3_step(st);
       
   742 		DP1("    rc=%d", rc);
       
   743 		CleanupStack::PopAndDestroy(); // st
       
   744 		}
       
   745 	
   752 	DP("DBEnsureFileSizeFieldExists END");
   746 	DP("DBEnsureFileSizeFieldExists END");
   753 	}
   747 	}
   754 
   748 
   755 EXPORT_C void CFeedEngine::ImportFeedsL(const TDesC& aFile)
   749 EXPORT_C void CFeedEngine::ImportFeedsL(const TDesC& aFile)
   756 	{
   750 	{
  1201 	for (TInt i=0;i<iObservers.Count();i++) 
  1195 	for (TInt i=0;i<iObservers.Count();i++) 
  1202 		{
  1196 		{
  1203 		iObservers[i]->OpmlParsingComplete(aError, aNumFeedsAdded);
  1197 		iObservers[i]->OpmlParsingComplete(aError, aNumFeedsAdded);
  1204 		}
  1198 		}
  1205 	}
  1199 	}
       
  1200 
       
  1201 void CFeedEngine::ParserShowUpdatedL(CShowInfo& aShow)
       
  1202 	{
       
  1203 	iPodcastModel.ShowEngine().UpdateShowL(aShow);
       
  1204 	if (aShow.PlayState() == ENeverPlayed && 
       
  1205 				iPodcastModel.SettingsEngine().DownloadAutomatically()) 
       
  1206 			{
       
  1207 			iPodcastModel.ShowEngine().AddDownloadL(aShow);
       
  1208 			}
       
  1209 	}