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