engine/src/FeedParser.cpp
branch3rded
changeset 390 d7abecc9d189
parent 343 9c56bf585696
equal deleted inserted replaced
345:702ba9ffe210 390:d7abecc9d189
    52 	iActiveShow = NULL;
    52 	iActiveShow = NULL;
    53 	iItemsParsed = 0;
    53 	iItemsParsed = 0;
    54 	iMaxItems = aMaxItems;
    54 	iMaxItems = aMaxItems;
    55 	iStoppedParsing = EFalse;
    55 	iStoppedParsing = EFalse;
    56 	iEncoding = ELatin1;
    56 	iEncoding = ELatin1;
       
    57 	if (iNewestShow)
       
    58 		delete iNewestShow;
       
    59 	iNewestShow = 0;
       
    60 	
       
    61 	iNewFeed = (iActiveFeed->LastUpdated() == 0) ? ETrue : EFalse;
    57 
    62 
    58 	TEntry entry;
    63 	TEntry entry;
    59 	User::LeaveIfError(iRfs.Entry(feedFileName, entry));
    64 	User::LeaveIfError(iRfs.Entry(feedFileName, entry));
    60 	iFileSize = entry.iSize;
    65 	iFileSize = entry.iSize;
    61 	
    66 	
    71 	{
    76 	{
    72 	DP("OnStartDocumentL()");
    77 	DP("OnStartDocumentL()");
    73 	HBufC* charset = HBufC::NewLC(KMaxParseBuffer);
    78 	HBufC* charset = HBufC::NewLC(KMaxParseBuffer);
    74 	charset->Des().Copy(aDocParam.CharacterSetName().DesC());
    79 	charset->Des().Copy(aDocParam.CharacterSetName().DesC());
    75 	iEncoding = EUtf8;
    80 	iEncoding = EUtf8;
       
    81 	iFeedDirection = EFeedUnknown;
       
    82 	iPreviousPubDate = 0;
    76 	if (charset->CompareF(_L("utf-8")) == 0) {
    83 	if (charset->CompareF(_L("utf-8")) == 0) {
    77 		DP("setting UTF8");
    84 		DP("setting UTF8");
    78 		iEncoding = EUtf8;
    85 		iEncoding = EUtf8;
    79 	} else if (charset->CompareF(_L("ISO-8859-1")) == 0) {
    86 	} else if (charset->CompareF(_L("ISO-8859-1")) == 0) {
    80 		iEncoding = EUtf8; //Latin1;
    87 		iEncoding = EUtf8; //Latin1;
    85 	}
    92 	}
    86 
    93 
    87 void CFeedParser::OnEndDocumentL(TInt /*aErrorCode*/)
    94 void CFeedParser::OnEndDocumentL(TInt /*aErrorCode*/)
    88 	{
    95 	{
    89 	//DP("OnEndDocumentL()");
    96 	//DP("OnEndDocumentL()");
       
    97 	if (iNewFeed)
       
    98 		{
       
    99 		// if the feed adds at bottom, this 
       
   100 		if (iNewestShow)
       
   101 			{
       
   102 			iNewestShow->SetPlayState(ENeverPlayed);
       
   103 			iCallbacks.ParserShowUpdatedL(*iNewestShow);
       
   104 			delete iNewestShow;
       
   105 			iNewestShow = 0;
       
   106 			}
       
   107 		}
       
   108 	
    90 	iCallbacks.ParsingCompleteL(iActiveFeed);
   109 	iCallbacks.ParsingCompleteL(iActiveFeed);
    91 	}
   110 	}
    92 
   111 
    93 void CFeedParser::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, TInt /*aErrorCode*/)
   112 void CFeedParser::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, TInt /*aErrorCode*/)
    94 	{
   113 	{
   300 					now -= delta;
   319 					now -= delta;
   301 					
   320 					
   302 					iActiveShow->SetPubDate(now);
   321 					iActiveShow->SetPubDate(now);
   303 					}
   322 					}
   304 				
   323 				
       
   324 				if (iFeedDirection == EFeedUnknown)
       
   325 					{
       
   326 					if (iPreviousPubDate.Int64() != 0) {
       
   327 						if (iActiveShow->PubDate() > iPreviousPubDate)
       
   328 							{
       
   329 							DP("Feed adds at bottom");
       
   330 							iFeedDirection = EFeedAddsAtBottom;
       
   331 							}
       
   332 						else
       
   333 							{
       
   334 							DP("Feed adds at top");
       
   335 							iFeedDirection = EFeedAddsAtTop;
       
   336 							}
       
   337 					}
       
   338 					iPreviousPubDate = iActiveShow->PubDate();
       
   339 					}
       
   340 				
   305 				if (iUid)
   341 				if (iUid)
   306 					{
   342 					{
   307 					iActiveShow->SetUid(iUid);
   343 					iActiveShow->SetUid(iUid);
   308 					}
   344 					}
       
   345 				
       
   346 				if (iNewFeed)
       
   347 					{
       
   348 					// set all played, except for the newest one
       
   349 					iActiveShow->SetPlayState(EPlayed);
       
   350 					
       
   351 					if (!iNewestShow || iActiveShow->PubDate() > iNewestShow->PubDate())
       
   352 						{
       
   353 						if (iNewestShow)
       
   354 							delete iNewestShow;
   309 						
   355 						
       
   356 						iNewestShow = new CShowInfo(iActiveShow);
       
   357 						}
       
   358 					}
       
   359 					
   310 				iCallbacks.NewShowL(*iActiveShow);
   360 				iCallbacks.NewShowL(*iActiveShow);
   311 				
   361 				
   312 				delete iActiveShow;				
   362 				delete iActiveShow;				
   313 				
   363 				
   314 				// We should now be finished with the show.
   364 				// We should now be finished with the show.
   315 				iActiveShow = NULL;
   365 				iActiveShow = NULL;
   316 				
   366 				
   317 				iItemsParsed++;
   367 				iItemsParsed++;
   318 				DP2("iItemsParsed: %d, iMaxItems: %d", iItemsParsed, iMaxItems);
   368 				DP2("iItemsParsed: %d, iMaxItems: %d", iItemsParsed, iMaxItems);
   319 				if (iItemsParsed >= iMaxItems) 
   369 				// we stop parsing after iMaxItems, but not if feed builds at bottom
       
   370 				if (iItemsParsed >= iMaxItems && iFeedDirection != EFeedAddsAtBottom) 
   320 					{
   371 					{
   321 					iStoppedParsing = ETrue;
   372 					iStoppedParsing = ETrue;
   322 					DP("*** Too many items, aborting parsing");
   373 					DP("*** Too many items, aborting parsing");
   323 					}
   374 					}
   324 				
   375