engine/src/FeedParser.cpp
author Sebastian Brannstrom <sebastianb@symbian.org>
Sun, 31 Oct 2010 14:15:37 +0000
branchRCL_3
changeset 321 7a0fb290f9c6
parent 258 f02d87cb8d1f
child 330 4cf89a7d3476
permissions -rw-r--r--
Re-enabled max items parsed, because disabling this causes shows to turn up as new multiple times. This again breaks feeds that add new shows at the bottom, so we need to solve this properly.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     1
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     2
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     3
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     4
* All rights reserved.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     5
* This component and the accompanying materials are made available
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     6
* under the terms of the License "Eclipse Public License v1.0"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     7
* which accompanies this distribution, and is available
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     8
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     9
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    10
* Initial Contributors:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    11
* EmbedDev AB - initial contribution.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    12
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    13
* Contributors:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    14
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    15
* Description:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    16
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    17
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    18
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    19
#include "FeedParser.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    20
#include <f32file.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    21
#include <bautils.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    22
#include <s32file.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
#include <charconv.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
#include <xml/stringdictionarycollection.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    25
#include <utf.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    26
#include <tinternetdate.h>
258
f02d87cb8d1f Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 255
diff changeset
    27
#include <e32hashtab.h>
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    28
#include "debug.h"
123
50edf2be6f0d Crude video file detection implemented
teknolog
parents: 2
diff changeset
    29
#include "podcastutils.h"
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
using namespace Xml;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
const TInt KMaxParseBuffer = 1024;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
const TInt KMaxStringBuffer = 100;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
CFeedParser::CFeedParser(MFeedParserObserver& aCallbacks, RFs& aFs) : 	iCallbacks(aCallbacks), iRfs(aFs)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
CFeedParser::~CFeedParser()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    41
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
void CFeedParser::ParseFeedL(const TFileName &feedFileName, CFeedInfo *info, TUint aMaxItems)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
	//DP1("ParseFeedL BEGIN: %S", &feedFileName);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
	_LIT8(KXmlMimeType, "text/xml");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
	// Contruct the parser object
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
	CParser* parser = CParser::NewLC(KXmlMimeType, *this);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
	iActiveFeed = info;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
	iFeedState = EStateRoot;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
	iActiveShow = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
	iItemsParsed = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    54
	iMaxItems = aMaxItems;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
	iStoppedParsing = EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
	iEncoding = ELatin1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
	ParseL(*parser, iRfs, feedFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    60
	CleanupStack::PopAndDestroy(parser);	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    61
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
	//DP("ParseFeedL END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
// from MContentHandler
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
void CFeedParser::OnStartDocumentL(const RDocumentParameters& aDocParam, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
	DP("OnStartDocumentL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    69
	HBufC* charset = HBufC::NewLC(KMaxParseBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    70
	charset->Des().Copy(aDocParam.CharacterSetName().DesC());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    71
	iEncoding = EUtf8;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    72
	if (charset->CompareF(_L("utf-8")) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    73
		DP("setting UTF8");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    74
		iEncoding = EUtf8;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    75
	} else if (charset->CompareF(_L("ISO-8859-1")) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    76
		iEncoding = EUtf8; //Latin1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
	} else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
		DP1("unknown charset: %S", &charset);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
	CleanupStack::PopAndDestroy(charset);//buffer
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
void CFeedParser::OnEndDocumentL(TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    84
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
	//DP("OnEndDocumentL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
	iCallbacks.ParsingCompleteL(iActiveFeed);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
void CFeedParser::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
	if (iStoppedParsing) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
		iActiveShow = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
		return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
	TBuf<KMaxStringBuffer> str;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
	str.Copy(aElement.LocalName().DesC());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
	//DP2("OnStartElementL START state=%d, element=%S", iFeedState, &str);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
	iBuffer.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
	switch (iFeedState) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
	case EStateRoot:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
		// <channel>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
		if (str.CompareF(KTagChannel) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
			iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
		break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
	case EStateChannel:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
		// <channel> <item>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
		if(str.CompareF(KTagItem) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
			//DP("New item");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
			iFeedState=EStateItem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
			iActiveShow = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
			iActiveShow = CShowInfo::NewL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
			if (iActiveShow == NULL) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
				DP("Out of memory!");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
				iStoppedParsing = ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
				return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   120
			iActiveShow->SetFeedUid(iActiveFeed->Uid());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   121
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   122
		// <channel> <lastBuildDate>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   123
		} else if (str.CompareF(KTagLastBuildDate) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
			DP("LastBuildDate BEGIN");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   125
			iFeedState=EStateChannelLastBuildDate;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   126
		// <channel> <link>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   127
		}else if (str.CompareF(KTagTitle) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
			iFeedState=EStateChannelTitle;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   129
		// <channel> <link>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   130
		} else if (str.CompareF(KTagLink) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
			iFeedState = EStateChannelLink;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
		// <channel> <description>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   133
		} else if (str.CompareF(KTagDescription) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   134
			iFeedState=EStateChannelDescription;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
		// <channel> <image>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
		} else if (str.CompareF(KTagImage) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   137
			for (int i=0;i<aAttributes.Count();i++) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
				RAttribute attr = aAttributes[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
				TBuf<KMaxStringBuffer> attr16;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   140
				attr16.Copy(attr.Attribute().LocalName().DesC().Left(KMaxStringBuffer));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   141
				HBufC* val16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L(attr.Value().DesC().Left(KMaxParseBuffer));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
				CleanupStack::PushL(val16);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
						
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
				// href=...
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   145
				if (attr16.Compare(KTagHref) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   146
					iActiveFeed->SetImageUrlL(*val16);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   148
				CleanupStack::PopAndDestroy(val16);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   149
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
			iFeedState=EStateChannelImage;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   152
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
		break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
	case EStateChannelImage:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
		// <channel> <image> <url>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
		if (str.CompareF(KTagUrl) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   157
			iFeedState=EStateChannelImageUrl;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
		} else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   159
			iFeedState=EStateChannelImage;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   160
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   161
		break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
	case EStateItem:
258
f02d87cb8d1f Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 255
diff changeset
   163
		iUid = 0;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   164
		// <channel> <item> <title>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   165
		if (str.CompareF(KTagTitle) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   166
			iFeedState=EStateItemTitle;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
		// <channel> <item> <link>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   168
		} else if (str.CompareF(KTagLink) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
			iFeedState=EStateItemLink;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   170
		// <channel> <item> <enclosure ...>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   171
		} else if (str.CompareF(KTagEnclosure) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
			//DP("Enclosure START");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
			for (int i=0;i<aAttributes.Count();i++) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
				RAttribute attr = aAttributes[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
				TBuf<KMaxStringBuffer> attr16;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
				attr16.Copy(attr.Attribute().LocalName().DesC());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
				// url=...
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   178
				if (attr16.Compare(KTagUrl) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
					HBufC* val16 = HBufC::NewLC(KMaxParseBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
					val16->Des().Copy(attr.Value().DesC());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
					iActiveShow->SetUrlL(*val16);
123
50edf2be6f0d Crude video file detection implemented
teknolog
parents: 2
diff changeset
   182
					
50edf2be6f0d Crude video file detection implemented
teknolog
parents: 2
diff changeset
   183
					if (PodcastUtils::IsVideoShow(*val16)) {
50edf2be6f0d Crude video file detection implemented
teknolog
parents: 2
diff changeset
   184
						iActiveShow->SetShowType(EVideoPodcast);
50edf2be6f0d Crude video file detection implemented
teknolog
parents: 2
diff changeset
   185
					}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   186
					CleanupStack::PopAndDestroy(val16);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   187
				// length=...
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   188
				} else if (attr16.Compare(KTagLength) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   189
					TLex8 lex(attr.Value().DesC());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   190
					TUint size = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
					lex.Val(size, EDecimal);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
					iActiveShow->SetShowSize(size);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   195
		// <channel> <item> <description>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
		} else if (str.CompareF(KTagDescription) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
			iFeedState=EStateItemDescription;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   198
		// <channel> <item> <pubdate>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   199
		} else if (str.CompareF(KTagPubDate) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   200
			//DP("LastBuildDate BEGIN");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
			iFeedState = EStateItemPubDate;
258
f02d87cb8d1f Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 255
diff changeset
   202
		// <channel> <item> <guid>
f02d87cb8d1f Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 255
diff changeset
   203
		} else if (str.CompareF(KTagGuid) == 0) {
f02d87cb8d1f Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 255
diff changeset
   204
			iFeedState = EStateItemGuid;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   205
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
		break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   207
	default:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
		//DP2("Ignoring tag %S when in state %d", &str, iFeedState);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
		break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   210
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   211
//	DP1("OnStartElementL END state=%d", iFeedState);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   212
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
void CFeedParser::OnEndElementL(const RTagInfo& aElement, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   217
	if (iStoppedParsing) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   218
		return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
	iBuffer.Trim();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   222
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   223
	TDesC8 lName = aElement.LocalName().DesC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   224
	TBuf<KMaxStringBuffer> str;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   225
	str.Copy(aElement.LocalName().DesC());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   226
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
	//DP2("OnEndElementL START state=%d, element=%S", iFeedState, &str);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
	switch (iFeedState) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
		case EStateChannelTitle:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
			if(str.CompareF(KTagTitle) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
				if (iActiveFeed->CustomTitle() == EFalse) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
					iActiveFeed->SetTitleL(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
				iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   236
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
		case EStateChannelLink:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
			iActiveFeed->SetLinkL(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
			iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
		case EStateChannelDescription:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
			iActiveFeed->SetDescriptionL(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
			iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
		case EStateChannelLastBuildDate:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
			//DP("LastBuildDate END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
			TInternetDate internetDate;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
			TBuf8<128> temp;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
			temp.Copy(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
			TRAPD(parseError, internetDate.SetDateL(temp));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   254
			if(parseError == KErrNone) {				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
				if (TTime(internetDate.DateTime()) > iActiveFeed->BuildDate()) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
					DP("Successfully parsed build date");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
					iActiveFeed->SetBuildDate(TTime(internetDate.DateTime()));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   258
				} else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
					DP("*** Nothing new, aborting parsing");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
					iStoppedParsing = ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
			} else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   263
				DP("Failed to parse last build date");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   264
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
			iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   267
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   268
		case EStateChannelImageUrl:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
			//DP1("Image url: %S", &iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
			iActiveFeed->SetImageUrlL(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
			iFeedState = EStateChannelImage;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
		case EStateChannelImage:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
			if(str.CompareF(KTagImage) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
				iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
		case EStateItem:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
			if (str.CompareF(KTagItem) == 0) 
254
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   280
				{
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   281
				// check if we have a valid pubdate
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   282
				if (iActiveShow->PubDate().Int64() == 0)
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   283
					{
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   284
					// set pubDate to present time
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   285
					TTime now;
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   286
					now.UniversalTime();
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   287
					
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   288
					// but we want reverse sorting, so let's do a little trick...
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   289
					TTimeIntervalHours delta;
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   290
					delta = iItemsParsed;
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   291
					
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   292
					// ... remove an hour per show we've parsed so far
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   293
					now -= delta;
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   294
					
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   295
					iActiveShow->SetPubDate(now);
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   296
					}
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   297
				
258
f02d87cb8d1f Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 255
diff changeset
   298
				if (iUid)
f02d87cb8d1f Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 255
diff changeset
   299
					{
f02d87cb8d1f Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 255
diff changeset
   300
					iActiveShow->SetUid(iUid);
f02d87cb8d1f Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 255
diff changeset
   301
					}
254
042bb9038b32 Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   302
						
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
				iCallbacks.NewShowL(*iActiveShow);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
				delete iActiveShow;				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   306
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   307
				// We should now be finished with the show.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   308
				iActiveShow = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   309
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   310
				iItemsParsed++;
126
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 123
diff changeset
   311
				DP2("iItemsParsed: %d, iMaxItems: %d", iItemsParsed, iMaxItems);
321
7a0fb290f9c6 Re-enabled max items parsed, because disabling this causes shows to turn up as new multiple times. This again breaks feeds that add new shows at the bottom, so we need to solve this properly.
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 258
diff changeset
   312
				if (iItemsParsed >= iMaxItems) 
7a0fb290f9c6 Re-enabled max items parsed, because disabling this causes shows to turn up as new multiple times. This again breaks feeds that add new shows at the bottom, so we need to solve this properly.
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 258
diff changeset
   313
					{
7a0fb290f9c6 Re-enabled max items parsed, because disabling this causes shows to turn up as new multiple times. This again breaks feeds that add new shows at the bottom, so we need to solve this properly.
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 258
diff changeset
   314
					iStoppedParsing = ETrue;
7a0fb290f9c6 Re-enabled max items parsed, because disabling this causes shows to turn up as new multiple times. This again breaks feeds that add new shows at the bottom, so we need to solve this properly.
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 258
diff changeset
   315
					DP("*** Too many items, aborting parsing");
7a0fb290f9c6 Re-enabled max items parsed, because disabling this causes shows to turn up as new multiple times. This again breaks feeds that add new shows at the bottom, so we need to solve this properly.
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 258
diff changeset
   316
					}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   317
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   318
				iFeedState=EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   319
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   320
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   321
		case EStateItemPubDate:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   322
			DP1("PubDate END: iBuffer='%S'", &iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   323
			if (str.CompareF(KTagPubDate) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   324
				// hack for feeds that don't always write day as two digits
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   325
				TChar five(iBuffer[5]);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   326
				TChar six(iBuffer[6]);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   327
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   328
				if (five.IsDigit() && !six.IsDigit()) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   329
					TBuf<KMaxStringBuffer> fix;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   330
					fix.Copy(iBuffer.Left(4));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   331
					fix.Append(_L(" 0"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   332
					fix.Append(iBuffer.Mid(5));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   333
					iBuffer.Copy(fix);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   334
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   335
				// end hack
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   336
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   337
				// hack for feeds that write out months in full
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   338
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   339
				if (iBuffer[11] != ' ') {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   340
					TPtrC midPtr = iBuffer.Mid(8);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   341
					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   342
					int spacePos = midPtr.Find(_L(" "));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   343
					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   344
					if (spacePos != KErrNotFound) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   345
						//DP1("Month: %S", &midPtr.Left(spacePos));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   346
						
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   347
						TBuf16<KBufferLength> newBuffer;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   348
						newBuffer.Copy(iBuffer.Left(11));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   349
						newBuffer.Append(_L(" "));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   350
						newBuffer.Append(iBuffer.Mid(11+spacePos));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   351
						//DP1("newBuffer: %S", &newBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   352
						iBuffer.Copy(newBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   353
					}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   354
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   355
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   356
				// hack for feeds that write days and months as UPPERCASE
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   357
				TChar one(iBuffer[1]);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   358
				TChar two(iBuffer[2]);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   359
				TChar nine(iBuffer[9]);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   360
				TChar ten(iBuffer[10]);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   361
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   362
				one.LowerCase();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   363
				two.LowerCase();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   364
				nine.LowerCase();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   365
				ten.LowerCase();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   366
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   367
				iBuffer[1] = one;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   368
				iBuffer[2] = two;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   369
				iBuffer[9] = nine;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   370
				iBuffer[10] = ten;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   371
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   372
				TBuf8<128> temp;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   373
				temp.Copy(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   374
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   375
				TInternetDate internetDate;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   376
				TRAPD(parseError, internetDate.SetDateL(temp));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   377
				if(parseError == KErrNone) {				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   378
					//DP1("PubDate parse success: '%S'", &iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   379
					iActiveShow->SetPubDate(TTime(internetDate.DateTime()));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   380
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   381
					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   382
					DP6("Successfully parsed pubdate %d/%d/%d %d:%d:%d",
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   383
							iActiveShow->PubDate().DateTime().Year(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   384
							iActiveShow->PubDate().DateTime().Month(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   385
							iActiveShow->PubDate().DateTime().Day(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   386
							iActiveShow->PubDate().DateTime().Hour(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   387
							iActiveShow->PubDate().DateTime().Minute(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   388
							iActiveShow->PubDate().DateTime().Second());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   389
							
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   390
				} else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   391
					DP2("Pubdate parse error: '%S', error=%d", &iBuffer, parseError);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   392
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   393
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   394
			iFeedState=EStateItem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   395
			break;
258
f02d87cb8d1f Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 255
diff changeset
   396
		case EStateItemGuid:
f02d87cb8d1f Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 255
diff changeset
   397
			iUid = DefaultHash::Des16(iBuffer);
f02d87cb8d1f Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 255
diff changeset
   398
			iFeedState=EStateItem;
f02d87cb8d1f Fix for bug 3420 - we now use GUID if it's provided by the feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 255
diff changeset
   399
			break;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   400
		case EStateItemTitle:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   401
			//DP1("title: %S", &iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   402
			iActiveShow->SetTitleL(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   403
			iFeedState = EStateItem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   404
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   405
		case EStateItemLink:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   406
			if (iActiveShow->Url().Length() == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   407
				iActiveShow->SetUrlL(iBuffer);
123
50edf2be6f0d Crude video file detection implemented
teknolog
parents: 2
diff changeset
   408
				
50edf2be6f0d Crude video file detection implemented
teknolog
parents: 2
diff changeset
   409
				if (PodcastUtils::IsVideoShow(iBuffer)) {
50edf2be6f0d Crude video file detection implemented
teknolog
parents: 2
diff changeset
   410
					iActiveShow->SetShowType(EVideoPodcast);
50edf2be6f0d Crude video file detection implemented
teknolog
parents: 2
diff changeset
   411
				}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   412
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   413
			iFeedState = EStateItem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   414
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   415
		case EStateItemDescription:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   416
			iActiveShow->SetDescriptionL(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   417
			iFeedState = EStateItem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   418
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   419
		default:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   420
			// fall back to channel level when in doubt
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   421
			iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   422
			//DP2("Don't know how to handle end tag %S when in state %d", &str, iFeedState);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   423
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   424
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   425
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   426
	//DP1("OnEndElementL END state=%d", iFeedState);	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   427
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   428
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   429
void CFeedParser::OnContentL(const TDesC8& aBytes, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   430
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   431
	TBuf<KBufferLength> temp;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   432
	if (iEncoding == EUtf8) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   433
		CnvUtfConverter::ConvertToUnicodeFromUtf8(temp, aBytes);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   434
	} else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   435
		temp.Copy(aBytes);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   436
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   437
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   438
	if(temp.Length() + iBuffer.Length() < KBufferLength) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   439
		iBuffer.Append(temp);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   440
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   441
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   442
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   443
void CFeedParser::OnStartPrefixMappingL(const RString& /*aPrefix*/, const RString& /*aUri*/, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   444
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   445
	DP("OnStartPrefixMappingL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   446
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   447
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   448
void CFeedParser::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   449
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   450
	DP("OnEndPrefixMappingL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   451
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   452
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   453
void CFeedParser::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   454
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   455
	DP("OnIgnorableWhiteSpaceL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   456
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   457
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   458
void CFeedParser::OnSkippedEntityL(const RString& /*aName*/, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   459
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   460
	DP("OnSkippedEntityL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   461
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   462
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   463
void CFeedParser::OnProcessingInstructionL(const TDesC8& /*aTarget*/, const TDesC8& /*aData*/, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   464
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   465
	DP("OnProcessingInstructionL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   466
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   467
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   468
void CFeedParser::OnError(TInt aErrorCode)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   469
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   470
	DP1("CFeedParser::OnError %d", aErrorCode);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   471
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   472
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   473
TAny* CFeedParser::GetExtendedInterface(const TInt32 /*aUid*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   474
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   475
	DP("GetExtendedInterface()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   476
	return NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   477
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   478
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   479
CFeedInfo& CFeedParser::ActiveFeed()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   480
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   481
		return *iActiveFeed;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   482
	}