author | teknolog |
Wed, 02 Jun 2010 11:39:15 +0100 | |
changeset 102 | ee650bbb958e |
parent 93 | c2f1ea38ec70 |
child 108 | 3402b2e2a66a |
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 "FeedEngine.h" |
|
20 |
#include <f32file.h> |
|
21 |
#include <bautils.h> |
|
22 |
#include <s32file.h> |
|
23 |
#include "SettingsEngine.h" |
|
24 |
#include "ShowEngine.h" |
|
25 |
#include <e32hashtab.h> |
|
26 |
#include "OpmlParser.h" |
|
27 |
#include "PodcastUtils.h" |
|
28 |
#include <utf.h> |
|
81 | 29 |
#include "Podcatcher.pan" |
2 | 30 |
|
75
554d9980157f
Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents:
74
diff
changeset
|
31 |
_LIT(KFeedParseStorePath, "feeds\\"); |
2 | 32 |
|
33 |
CFeedEngine* CFeedEngine::NewL(CPodcastModel& aPodcastModel) |
|
34 |
{ |
|
35 |
CFeedEngine* self = new (ELeave) CFeedEngine(aPodcastModel); |
|
36 |
CleanupStack::PushL(self); |
|
37 |
self->ConstructL(); |
|
38 |
CleanupStack::Pop(self); |
|
39 |
return self; |
|
40 |
} |
|
41 |
||
42 |
void CFeedEngine::ConstructL() |
|
43 |
{ |
|
44 |
iParser = new (ELeave) CFeedParser(*this, iPodcastModel.FsSession()); |
|
45 |
||
46 |
iFeedClient = CHttpClient::NewL(iPodcastModel, *this); |
|
47 |
iFeedTimer.ConstructL(); |
|
48 |
||
76 | 49 |
TInt err = KErrNone; |
50 |
TInt feedCount = 0; |
|
2 | 51 |
|
76 | 52 |
TRAP(err, feedCount = DBGetFeedCountL()); |
53 |
if (err == KErrNone && feedCount > 0) |
|
2 | 54 |
{ |
55 |
DP("Loading feeds from DB"); |
|
76 | 56 |
TRAP(err, DBLoadFeedsL()); |
57 |
} |
|
58 |
||
2 | 59 |
|
76 | 60 |
if (err != KErrNone || iPodcastModel.IsFirstStartup()) { |
2 | 61 |
TFileName defaultFile = iPodcastModel.SettingsEngine().DefaultFeedsFileName(); |
62 |
DP1("Loading default feeds from %S", &defaultFile); |
|
63 |
if (BaflUtils::FileExists(iPodcastModel.FsSession(), defaultFile)) { |
|
64 |
ImportFeedsL(defaultFile); |
|
65 |
} |
|
76 | 66 |
} |
67 |
||
68 |
// clean out feeds temp directory |
|
69 |
TFileName feedTempPath; |
|
70 |
feedTempPath.Copy (iPodcastModel.SettingsEngine().PrivatePath ()); |
|
71 |
feedTempPath.Append(KFeedParseStorePath); |
|
72 |
feedTempPath.Append(_L("*")); |
|
75
554d9980157f
Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents:
74
diff
changeset
|
73 |
|
76 | 74 |
BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), feedTempPath); |
75 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(),feedTempPath); |
|
2 | 76 |
|
77 |
TFileName importFile = iPodcastModel.SettingsEngine().ImportFeedsFileName(); |
|
78 |
if (BaflUtils::FileExists(iPodcastModel.FsSession(), importFile)) { |
|
79 |
DP("Importing feeds"); |
|
76 | 80 |
TRAP_IGNORE(ImportFeedsL(importFile)); |
2 | 81 |
} |
76 | 82 |
|
83 |
RunFeedTimer(); |
|
2 | 84 |
} |
85 |
||
86 |
CFeedEngine::CFeedEngine(CPodcastModel& aPodcastModel) |
|
87 |
: iClientState(EIdle), |
|
88 |
iFeedTimer(this), |
|
89 |
iPodcastModel(aPodcastModel), |
|
90 |
iDB(*aPodcastModel.DB()) |
|
91 |
{ |
|
92 |
} |
|
93 |
||
94 |
CFeedEngine::~CFeedEngine() |
|
95 |
{ |
|
96 |
iObservers.Close(); |
|
97 |
||
98 |
iFeedsUpdating.Close(); |
|
99 |
iSortedFeeds.ResetAndDestroy(); |
|
100 |
iSearchResults.ResetAndDestroy(); |
|
101 |
||
102 |
delete iParser; |
|
103 |
delete iFeedClient; |
|
104 |
delete iOpmlParser; |
|
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
* Returns the current internal state of the feed engine4 |
|
109 |
*/ |
|
110 |
EXPORT_C TClientState CFeedEngine::ClientState() |
|
111 |
{ |
|
112 |
return iClientState; |
|
113 |
} |
|
114 |
||
115 |
||
116 |
/** |
|
117 |
* Returns the current updating client UID if clientstate is != ENotUpdateing |
|
118 |
* @return TUint |
|
119 |
*/ |
|
120 |
EXPORT_C TUint CFeedEngine::ActiveClientUid() |
|
121 |
{ |
|
122 |
if(iActiveFeed != NULL) |
|
123 |
{ |
|
124 |
return iActiveFeed->Uid(); |
|
125 |
} |
|
126 |
return 0; |
|
127 |
} |
|
128 |
||
129 |
void CFeedEngine::RunFeedTimer() |
|
130 |
{ |
|
131 |
iFeedTimer.Cancel(); |
|
132 |
||
133 |
if (iPodcastModel.SettingsEngine().UpdateAutomatically() != EAutoUpdateOff) |
|
134 |
{ |
|
135 |
TInt interval = iPodcastModel.SettingsEngine().UpdateFeedInterval(); |
|
136 |
||
137 |
if (interval != 0) |
|
138 |
{ |
|
139 |
iFeedTimer.SetPeriod(interval); |
|
140 |
iFeedTimer.RunPeriodically(); |
|
141 |
} |
|
142 |
} |
|
143 |
} |
|
144 |
||
145 |
EXPORT_C void CFeedEngine::UpdateAllFeedsL(TBool aAutoUpdate) |
|
146 |
{ |
|
93 | 147 |
if (iClientState != EIdle) |
148 |
{ |
|
149 |
User::Leave(KErrInUse); |
|
150 |
} |
|
151 |
||
2 | 152 |
iAutoUpdatedInitiator = aAutoUpdate; |
153 |
if (iFeedsUpdating.Count() > 0) |
|
154 |
{ |
|
155 |
DP("Cancelling update"); |
|
156 |
iFeedClient->Stop(); |
|
157 |
iFeedsUpdating.Reset(); |
|
158 |
return; |
|
159 |
} |
|
160 |
||
161 |
TInt cnt = iSortedFeeds.Count(); |
|
162 |
for (int i=0;i<cnt;i++) |
|
163 |
{ |
|
69 | 164 |
iFeedsUpdating.Append(iSortedFeeds[i]->Uid()); |
2 | 165 |
} |
166 |
||
167 |
UpdateNextFeedL(); |
|
168 |
} |
|
169 |
||
170 |
EXPORT_C void CFeedEngine::CancelUpdateAllFeeds() |
|
171 |
{ |
|
172 |
if(iClientState != EIdle) |
|
173 |
{ |
|
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
174 |
iCancelRequested = ETrue; |
2 | 175 |
iFeedsUpdating.Reset(); |
176 |
iFeedClient->Stop(); |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
void CFeedEngine::UpdateNextFeedL() |
|
181 |
{ |
|
182 |
DP1("UpdateNextFeed. %d feeds left to update", iFeedsUpdating.Count()); |
|
183 |
||
93 | 184 |
if (iClientState != EIdle) |
185 |
{ |
|
186 |
User::Leave(KErrInUse); |
|
187 |
} |
|
188 |
||
69 | 189 |
// reset active feed, will be set again in UpdateFeedL if needed |
190 |
iActiveFeed = NULL; |
|
191 |
||
2 | 192 |
if (iFeedsUpdating.Count() > 0) |
193 |
{ |
|
69 | 194 |
CFeedInfo *info = GetFeedInfoByUid(iFeedsUpdating[0]); |
2 | 195 |
iFeedsUpdating.Remove(0); |
196 |
||
69 | 197 |
if (info == NULL) |
198 |
{ |
|
199 |
UpdateNextFeedL(); |
|
200 |
} |
|
201 |
else |
|
2 | 202 |
{ |
69 | 203 |
TBool result = EFalse; |
204 |
//DP2("** UpdateNextFeed: %S, ID: %u", &(info->Url()), info->Uid()); |
|
205 |
TRAPD(error, result = UpdateFeedL(info->Uid())); |
|
206 |
||
207 |
if (error != KErrNone || !result) |
|
2 | 208 |
{ |
69 | 209 |
DP("Error while updating all feeds"); |
210 |
for (TInt i=0;i<iObservers.Count();i++) |
|
211 |
{ |
|
212 |
TRAP_IGNORE(iObservers[i]->FeedUpdateAllCompleteL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate)); |
|
213 |
} |
|
2 | 214 |
} |
215 |
} |
|
216 |
} |
|
217 |
else |
|
218 |
{ |
|
219 |
iClientState = EIdle; |
|
220 |
for (TInt i=0;i<iObservers.Count();i++) |
|
221 |
{ |
|
222 |
TRAP_IGNORE(iObservers[i]->FeedUpdateAllCompleteL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate)); |
|
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
||
227 |
EXPORT_C TBool CFeedEngine::UpdateFeedL(TUint aFeedUid) |
|
228 |
{ |
|
229 |
DP("FeedEngine::UpdateFeedL BEGIN"); |
|
69 | 230 |
|
231 |
if (iActiveFeed) |
|
232 |
{ |
|
233 |
User::Leave(KErrInUse); |
|
234 |
} |
|
235 |
||
2 | 236 |
iActiveFeed = GetFeedInfoByUid(aFeedUid); |
73
83752b9e3cb6
Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents:
69
diff
changeset
|
237 |
|
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
238 |
iCancelRequested = EFalse; |
2 | 239 |
|
240 |
if (iActiveFeed->LastUpdated() == 0) |
|
241 |
{ |
|
93 | 242 |
newFeed = ETrue; |
2 | 243 |
} |
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
244 |
|
93 | 245 |
showsAdded = 0; |
246 |
||
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
247 |
iActiveFeed->SetLastError(KErrNone); |
36
e010fc411ddc
Merge, plus minor fix to CFeedEngine
Brendan Donegan <brendand@symbian.org>
diff
changeset
|
248 |
DBUpdateFeedL(*iActiveFeed); |
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
249 |
|
2 | 250 |
iUpdatingFeedFileName.Copy (iPodcastModel.SettingsEngine().PrivatePath ()); |
75
554d9980157f
Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents:
74
diff
changeset
|
251 |
iUpdatingFeedFileName.Append(KFeedParseStorePath); |
554d9980157f
Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents:
74
diff
changeset
|
252 |
BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), iUpdatingFeedFileName); |
554d9980157f
Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents:
74
diff
changeset
|
253 |
|
2 | 254 |
_LIT(KFileNameFormat, "%lu.xml"); |
255 |
iUpdatingFeedFileName.AppendFormat(KFileNameFormat, aFeedUid); |
|
256 |
||
84
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
257 |
iClientState = EUpdatingFeed; |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
258 |
|
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
259 |
for (TInt i=0;i<iObservers.Count();i++) |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
260 |
{ |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
261 |
TRAP_IGNORE(iObservers[i]->FeedDownloadStartedL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate, iActiveFeed->Uid())); |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
262 |
} |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
263 |
|
2 | 264 |
if(iFeedClient->GetL(iActiveFeed->Url(), iUpdatingFeedFileName, iPodcastModel.SettingsEngine().SpecificIAP())) |
265 |
{ |
|
266 |
||
267 |
DP("FeedEngine::UpdateFeedL END, return ETrue"); |
|
268 |
return ETrue; |
|
269 |
} |
|
270 |
else |
|
271 |
{ |
|
272 |
DP("FeedEngine::UpdateFeedL END, return EFalse"); |
|
273 |
return EFalse; |
|
274 |
} |
|
275 |
} |
|
276 |
||
277 |
void CFeedEngine::NewShowL(CShowInfo& aItem) |
|
278 |
{ |
|
279 |
HBufC* description = HBufC::NewLC(KMaxDescriptionLength); |
|
280 |
TPtr ptr(description->Des()); |
|
281 |
ptr.Copy(aItem.Description()); |
|
282 |
PodcastUtils::CleanHtmlL(ptr); |
|
8 | 283 |
|
284 |
aItem.SetDescriptionL(*description); |
|
2 | 285 |
CleanupStack::PopAndDestroy(description); |
286 |
||
93 | 287 |
if (newFeed) { |
288 |
// for new feeds, set all shows played |
|
289 |
aItem.SetPlayState(EPlayed); |
|
290 |
// except the first one |
|
291 |
if (showsAdded == 0) { |
|
292 |
aItem.SetPlayState(ENeverPlayed); |
|
2 | 293 |
} |
294 |
} |
|
295 |
||
78 | 296 |
TRAPD(err, iPodcastModel.ShowEngine().AddShowL(aItem)); |
2 | 297 |
|
78 | 298 |
if (err == KErrNone && aItem.PlayState() == ENeverPlayed && |
299 |
iPodcastModel.SettingsEngine().DownloadAutomatically()) |
|
2 | 300 |
{ |
301 |
iPodcastModel.ShowEngine().AddDownloadL(aItem); |
|
93 | 302 |
} |
303 |
||
304 |
showsAdded++; |
|
2 | 305 |
} |
306 |
||
307 |
void CFeedEngine::GetFeedImageL(CFeedInfo *aFeedInfo) |
|
308 |
{ |
|
309 |
DP("GetFeedImage"); |
|
310 |
||
311 |
TFileName filePath; |
|
312 |
filePath.Copy(iPodcastModel.SettingsEngine().BaseDir()); |
|
313 |
||
314 |
// create relative file name |
|
315 |
TFileName relPath; |
|
316 |
relPath.Copy(aFeedInfo->Title()); |
|
317 |
relPath.Append('\\'); |
|
318 |
||
319 |
TFileName fileName; |
|
320 |
PodcastUtils::FileNameFromUrl(aFeedInfo->ImageUrl(), fileName); |
|
321 |
relPath.Append(fileName); |
|
322 |
PodcastUtils::EnsureProperPathName(relPath); |
|
323 |
||
324 |
// complete file path is base dir + rel path |
|
325 |
filePath.Append(relPath); |
|
67
e0fc52a5df4d
Update to keep features from merge.
Lars Persson <lars.persson@embeddev.se>
parents:
66
diff
changeset
|
326 |
aFeedInfo->SetImageFileNameL(filePath, NULL); |
2 | 327 |
|
328 |
if(iFeedClient->GetL(aFeedInfo->ImageUrl(), filePath, ETrue)) |
|
329 |
{ |
|
330 |
iClientState = EUpdatingImage; |
|
331 |
} |
|
332 |
} |
|
333 |
||
334 |
EXPORT_C TBool CFeedEngine::AddFeedL(const CFeedInfo&aItem) |
|
335 |
{ |
|
336 |
DP2("CFeedEngine::AddFeed, title=%S, URL=%S", &aItem.Title(), &aItem.Url()); |
|
337 |
for (TInt i=0;i<iSortedFeeds.Count();i++) |
|
338 |
{ |
|
339 |
if (iSortedFeeds[i]->Uid() == aItem.Uid()) |
|
340 |
{ |
|
341 |
DP1("Already have feed %S, discarding", &aItem.Url()); |
|
342 |
return EFalse; |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle); |
|
347 |
CFeedInfo* newItem = aItem.CopyL(); |
|
348 |
CleanupStack::PushL(newItem); |
|
349 |
User::LeaveIfError(iSortedFeeds.InsertInOrder(newItem, sortOrder)); |
|
350 |
CleanupStack::Pop(newItem); |
|
351 |
||
352 |
||
353 |
// Save the feeds into DB |
|
354 |
DBAddFeedL(aItem); |
|
355 |
return ETrue; |
|
356 |
} |
|
357 |
||
76 | 358 |
void CFeedEngine::DBAddFeedL(const CFeedInfo& aItem) |
2 | 359 |
{ |
360 |
DP2("CFeedEngine::DBAddFeed, title=%S, URL=%S", &aItem.Title(), &aItem.Url()); |
|
361 |
||
76 | 362 |
CFeedInfo *info; |
363 |
||
83 | 364 |
TRAPD(err, info = DBGetFeedInfoByUidL(aItem.Uid())); |
76 | 365 |
|
366 |
if (err == KErrNone && info) { |
|
2 | 367 |
delete info; |
76 | 368 |
User::Leave(KErrAlreadyExists); |
2 | 369 |
} |
370 |
||
371 |
HBufC* titleBuf = HBufC::NewLC(KMaxLineLength); |
|
372 |
TPtr titlePtr(titleBuf->Des()); |
|
373 |
titlePtr.Copy(aItem.Title()); |
|
374 |
PodcastUtils::SQLEncode(titlePtr); |
|
375 |
||
376 |
HBufC* descBuf = HBufC::NewLC(KMaxLineLength); |
|
377 |
TPtr descPtr(descBuf->Des()); |
|
378 |
descPtr.Copy(aItem.Description()); |
|
379 |
PodcastUtils::SQLEncode(descPtr); |
|
380 |
||
102
ee650bbb958e
Fix for bug 2836 - split string literals causing RVCT compile to fail
teknolog
parents:
93
diff
changeset
|
381 |
_LIT(KSqlStatement, "insert into feeds (url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror) values (\"%S\",\"%S\", \"%S\", \"%S\", \"%S\", \"%S\", \"%Ld\", \"%Ld\", \"%u\", \"%u\", \"%u\", \"%d\")"); |
2 | 382 |
iSqlBuffer.Format(KSqlStatement, |
383 |
&aItem.Url(), titleBuf, descBuf, &aItem.ImageUrl(), &aItem.ImageFileName(), &aItem.Link(), |
|
384 |
aItem.BuildDate().Int64(), aItem.LastUpdated().Int64(), aItem.Uid(), EAudioPodcast, aItem.CustomTitle(), aItem.LastError()); |
|
385 |
||
386 |
CleanupStack::PopAndDestroy(descBuf); |
|
387 |
CleanupStack::PopAndDestroy(titleBuf); |
|
388 |
||
389 |
sqlite3_stmt *st; |
|
390 |
||
391 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &st, (const void**) NULL); |
|
392 |
||
393 |
if (rc==SQLITE_OK) |
|
394 |
{ |
|
76 | 395 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 396 |
rc = sqlite3_step(st); |
397 |
||
76 | 398 |
if (rc != SQLITE_DONE) |
2 | 399 |
{ |
76 | 400 |
User::Leave(KErrCorrupt); |
2 | 401 |
} |
76 | 402 |
CleanupStack::PopAndDestroy(); // st |
2 | 403 |
} |
76 | 404 |
else |
405 |
{ |
|
406 |
User::Leave(KErrCorrupt); |
|
407 |
} |
|
2 | 408 |
} |
409 |
||
410 |
EXPORT_C void CFeedEngine::RemoveFeedL(TUint aUid) |
|
411 |
{ |
|
69 | 412 |
if (iActiveFeed && iActiveFeed->Uid() == aUid) |
413 |
{ |
|
414 |
User::Leave(KErrInUse); |
|
415 |
} |
|
416 |
||
2 | 417 |
for (int i=0;i<iSortedFeeds.Count();i++) |
418 |
{ |
|
419 |
if (iSortedFeeds[i]->Uid() == aUid) |
|
420 |
{ |
|
421 |
iPodcastModel.ShowEngine().DeleteAllShowsByFeedL(aUid); |
|
52 | 422 |
|
2 | 423 |
CFeedInfo* feedToRemove = iSortedFeeds[i]; |
424 |
||
425 |
//delete the image file if it exists |
|
426 |
if ((feedToRemove->ImageFileName().Length() >0) |
|
427 |
&& BaflUtils::FileExists(iPodcastModel.FsSession(), feedToRemove->ImageFileName())) |
|
428 |
{ |
|
429 |
iPodcastModel.FsSession().Delete(feedToRemove->ImageFileName()); |
|
430 |
} |
|
431 |
||
432 |
//delete the folder. It has the same name as the title. |
|
433 |
TFileName filePath; |
|
434 |
filePath.Copy(iPodcastModel.SettingsEngine().BaseDir()); |
|
435 |
filePath.Append(feedToRemove->Title()); |
|
436 |
filePath.Append('\\'); |
|
437 |
iPodcastModel.FsSession().RmDir(filePath); |
|
438 |
||
439 |
iSortedFeeds.Remove(i); |
|
440 |
delete feedToRemove; |
|
441 |
||
442 |
DP("Removed feed from array"); |
|
443 |
||
444 |
// now remove it from DB |
|
76 | 445 |
DBRemoveFeedL(aUid); |
2 | 446 |
} |
447 |
} |
|
448 |
} |
|
449 |
||
450 |
||
76 | 451 |
void CFeedEngine::DBRemoveFeedL(TUint aUid) |
2 | 452 |
{ |
453 |
DP("CFeedEngine::DBRemoveFeed"); |
|
454 |
_LIT(KSqlStatement, "delete from feeds where uid=%u"); |
|
455 |
iSqlBuffer.Format(KSqlStatement, aUid); |
|
456 |
||
457 |
sqlite3_stmt *st; |
|
458 |
||
459 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &st, (const void**) NULL); |
|
460 |
||
461 |
if (rc==SQLITE_OK) |
|
462 |
{ |
|
76 | 463 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 464 |
rc = sqlite3_step(st); |
465 |
||
76 | 466 |
if (rc != SQLITE_DONE) |
2 | 467 |
{ |
76 | 468 |
User::Leave(KErrNotFound); |
2 | 469 |
} |
76 | 470 |
|
471 |
CleanupStack::PopAndDestroy(); //st |
|
2 | 472 |
} |
76 | 473 |
else |
474 |
{ |
|
475 |
User::Leave(KErrCorrupt); |
|
476 |
} |
|
2 | 477 |
} |
478 |
||
76 | 479 |
void CFeedEngine::DBUpdateFeedL(const CFeedInfo &aItem) |
2 | 480 |
{ |
481 |
DP2("CFeedEngine::DBUpdateFeed, title=%S, URL=%S", &aItem.Title(), &aItem.Url()); |
|
482 |
||
483 |
HBufC* titleBuf = HBufC::NewLC(KMaxLineLength); |
|
484 |
TPtr titlePtr(titleBuf->Des()); |
|
485 |
titlePtr.Copy(aItem.Title()); |
|
486 |
PodcastUtils::SQLEncode(titlePtr); |
|
487 |
||
488 |
HBufC* descBuf = HBufC::NewLC(KMaxLineLength); |
|
489 |
TPtr descPtr(descBuf->Des()); |
|
490 |
descPtr.Copy(aItem.Description()); |
|
491 |
PodcastUtils::SQLEncode(descPtr); |
|
492 |
||
102
ee650bbb958e
Fix for bug 2836 - split string literals causing RVCT compile to fail
teknolog
parents:
93
diff
changeset
|
493 |
_LIT(KSqlStatement, "update feeds set url=\"%S\", title=\"%S\", description=\"%S\", imageurl=\"%S\", imagefile=\"%S\", link=\"%S\", built=\"%Lu\", lastupdated=\"%Lu\", feedtype=\"%u\", customtitle=\"%u\", lasterror=\"%d\" where uid=\"%u\""); |
2 | 494 |
iSqlBuffer.Format(KSqlStatement, |
495 |
&aItem.Url(), titleBuf, descBuf, &aItem.ImageUrl(), &aItem.ImageFileName(), &aItem.Link(), |
|
496 |
aItem.BuildDate().Int64(), aItem.LastUpdated().Int64(), EAudioPodcast, aItem.CustomTitle(), aItem.LastError(), aItem.Uid()); |
|
497 |
||
498 |
CleanupStack::PopAndDestroy(descBuf); |
|
499 |
CleanupStack::PopAndDestroy(titleBuf); |
|
500 |
||
501 |
sqlite3_stmt *st; |
|
502 |
||
503 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &st, (const void**) NULL); |
|
504 |
||
505 |
if (rc==SQLITE_OK) |
|
506 |
{ |
|
76 | 507 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 508 |
rc = sqlite3_step(st); |
509 |
||
76 | 510 |
if (rc != SQLITE_DONE) |
2 | 511 |
{ |
76 | 512 |
User::Leave(KErrNotFound); |
2 | 513 |
} |
76 | 514 |
CleanupStack::PopAndDestroy(); //st |
2 | 515 |
} |
516 |
else |
|
517 |
{ |
|
76 | 518 |
User::Leave(KErrCorrupt); |
2 | 519 |
} |
520 |
} |
|
521 |
||
522 |
void CFeedEngine::ParsingCompleteL(CFeedInfo *item) |
|
523 |
{ |
|
524 |
TBuf<KMaxLineLength> title; |
|
525 |
title.Copy(item->Title()); |
|
8 | 526 |
item->SetTitleL(title); // if this leaves we are out of memory |
2 | 527 |
} |
528 |
||
529 |
||
530 |
EXPORT_C void CFeedEngine::AddObserver(MFeedEngineObserver *observer) |
|
531 |
{ |
|
532 |
iObservers.Append(observer); |
|
533 |
} |
|
534 |
||
535 |
EXPORT_C void CFeedEngine::RemoveObserver(MFeedEngineObserver *observer) |
|
536 |
{ |
|
537 |
TInt index = iObservers.Find(observer); |
|
538 |
||
539 |
if (index > KErrNotFound) |
|
540 |
{ |
|
541 |
iObservers.Remove(index); |
|
542 |
} |
|
543 |
} |
|
544 |
||
545 |
void CFeedEngine::Connected(CHttpClient* /*aClient*/) |
|
546 |
{ |
|
547 |
} |
|
548 |
||
549 |
void CFeedEngine::Progress(CHttpClient* /*aHttpClient*/, TInt /*aBytes*/, TInt /*aTotalBytes*/) |
|
550 |
{ |
|
551 |
} |
|
552 |
||
553 |
void CFeedEngine::CompleteL(CHttpClient* /*aClient*/, TInt aError) |
|
554 |
{ |
|
555 |
DP2("CFeedEngine::CompleteL BEGIN, iClientState=%d, aSuccessful=%d", iClientState, aError); |
|
556 |
||
557 |
switch(iClientState) |
|
558 |
{ |
|
559 |
case EUpdatingFeed: |
|
560 |
{ |
|
561 |
iClientState = EIdle; |
|
562 |
switch (aError) |
|
563 |
{ |
|
564 |
case KErrCancel: |
|
565 |
{ |
|
566 |
iFeedsUpdating.Reset(); |
|
567 |
} |
|
568 |
break; |
|
569 |
case KErrCouldNotConnect: |
|
570 |
iFeedsUpdating.Reset(); |
|
571 |
break; |
|
572 |
default: |
|
573 |
{ |
|
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
574 |
if (!iCancelRequested) { |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
575 |
iActiveFeed->SetLastError(aError); |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
576 |
TTime time; |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
577 |
time.HomeTime(); |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
578 |
iActiveFeed->SetLastUpdated(time); |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
579 |
|
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
580 |
if( aError == KErrNone) |
73
83752b9e3cb6
Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents:
69
diff
changeset
|
581 |
{ |
83752b9e3cb6
Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents:
69
diff
changeset
|
582 |
// Parse the feed. We need to trap this call since it could leave and then |
83752b9e3cb6
Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents:
69
diff
changeset
|
583 |
// the whole update chain will be broken |
83752b9e3cb6
Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents:
69
diff
changeset
|
584 |
// change client state |
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
585 |
TRAPD(parserErr, iParser->ParseFeedL(iUpdatingFeedFileName, iActiveFeed, iPodcastModel.SettingsEngine().MaxListItems())); |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
586 |
|
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
587 |
if(parserErr) |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
588 |
{ |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
589 |
// we do not need to any special action on this error. |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
590 |
iActiveFeed->SetLastError(parserErr); |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
591 |
DP1("CFeedEngine::Complete()\t Failed to parse feed. Leave with error code=%d", parserErr); |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
592 |
} |
93 | 593 |
|
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
594 |
// delete the downloaded XML file as it is no longer needed |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
595 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(),iUpdatingFeedFileName); |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
596 |
|
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
597 |
// if the feed has specified a image url. download it if we dont already have it |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
598 |
if((iActiveFeed->ImageUrl().Length() > 0)) |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
599 |
{ |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
600 |
if ( (iActiveFeed->ImageFileName().Length() == 0) || |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
601 |
(iActiveFeed->ImageFileName().Length() > 0 && |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
602 |
!BaflUtils::FileExists(iPodcastModel.FsSession(), |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
603 |
iActiveFeed->ImageFileName()) ) |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
604 |
) |
2 | 605 |
{ |
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
606 |
TRAPD(error, GetFeedImageL(iActiveFeed)); |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
607 |
if (error) |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
608 |
{ |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
609 |
// we have failed in a very early stage to fetch the image. |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
610 |
// continue with next Feed update |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
611 |
iActiveFeed->SetLastError(parserErr); |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
612 |
iClientState = EIdle; |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
613 |
} |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
614 |
} |
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
615 |
} |
2 | 616 |
} |
84
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
617 |
else |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
618 |
{ |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
619 |
// even if it fails, this will allow us to move on |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
620 |
iClientState = EIdle; |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
621 |
} |
2 | 622 |
} |
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
623 |
iCancelRequested = EFalse; |
2 | 624 |
}break; |
625 |
} |
|
74
af6475fdf8d6
Improved error handling; Implemented support for more than 2 flash drives also for import/export feeds
teknolog
parents:
73
diff
changeset
|
626 |
DBUpdateFeedL(*iActiveFeed); |
63 | 627 |
NotifyFeedUpdateComplete(iActiveFeed->Uid(), aError); |
628 |
||
7 | 629 |
// we will wait until the image has been downloaded to start the next feed update. |
630 |
if (iClientState == EIdle) |
|
631 |
{ |
|
632 |
UpdateNextFeedL(); |
|
633 |
} |
|
634 |
}break; |
|
635 |
case EUpdatingImage: |
|
636 |
{ |
|
637 |
// change client state to not updating |
|
638 |
iClientState = EIdle; |
|
58
87cb33beeae2
Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents:
32
diff
changeset
|
639 |
if(aError == KErrNone) |
87cb33beeae2
Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents:
32
diff
changeset
|
640 |
{ |
76 | 641 |
// now the image has been downloaded, so we set it again in the FeedInfo to start |
642 |
// converting it |
|
77
403412eb5292
Added "Reset database" option in settings. Further robustness fixes for Feeds.
teknolog
parents:
76
diff
changeset
|
643 |
HBufC *fileNameCopy = iActiveFeed->ImageFileName().AllocLC(); |
403412eb5292
Added "Reset database" option in settings. Further robustness fixes for Feeds.
teknolog
parents:
76
diff
changeset
|
644 |
TRAP_IGNORE(iActiveFeed->SetImageFileNameL(*fileNameCopy, &iPodcastModel)); |
403412eb5292
Added "Reset database" option in settings. Further robustness fixes for Feeds.
teknolog
parents:
76
diff
changeset
|
645 |
CleanupStack::PopAndDestroy(fileNameCopy); |
58
87cb33beeae2
Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents:
32
diff
changeset
|
646 |
} |
73
83752b9e3cb6
Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents:
69
diff
changeset
|
647 |
DBUpdateFeedL(*iActiveFeed); |
63 | 648 |
NotifyFeedUpdateComplete(iActiveFeed->Uid(), aError); |
7 | 649 |
UpdateNextFeedL(); |
650 |
}break; |
|
651 |
case ESearching: |
|
2 | 652 |
{ |
7 | 653 |
iClientState = EIdle; |
654 |
||
655 |
DP2("Search complete, results in %S with error %d", &iSearchResultsFileName, aError); |
|
656 |
if(aError == KErrNone) |
|
2 | 657 |
{ |
7 | 658 |
if (!iOpmlParser) |
659 |
{ |
|
660 |
iOpmlParser = new COpmlParser(*this, iPodcastModel.FsSession()); |
|
661 |
} |
|
662 |
||
663 |
DP("Parsing OPML"); |
|
664 |
iOpmlParser->ParseOpmlL(iSearchResultsFileName, ETrue); |
|
2 | 665 |
} |
7 | 666 |
else |
667 |
{ |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
8
diff
changeset
|
668 |
NotifyOpmlParsingCompleteL(aError, 0); |
7 | 669 |
} |
670 |
||
671 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(), iSearchResultsFileName); |
|
672 |
}break; |
|
84
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
673 |
case EIdle: |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
674 |
UpdateNextFeedL(); |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
675 |
break; |
69 | 676 |
default: |
81 | 677 |
Panic(EPodcatcherPanicFeedEngineState); |
69 | 678 |
break; |
2 | 679 |
} |
680 |
DP("CFeedEngine::CompleteL END"); |
|
681 |
} |
|
682 |
||
60
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents:
58
diff
changeset
|
683 |
void CFeedEngine::NotifyFeedUpdateComplete(TInt aFeedUid, TInt aError) |
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents:
58
diff
changeset
|
684 |
{ |
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents:
58
diff
changeset
|
685 |
DP("CFeedEngine::NotifyFeedUpdateComplete"); |
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents:
58
diff
changeset
|
686 |
for (TInt i=0;i<iObservers.Count();i++) |
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents:
58
diff
changeset
|
687 |
{ |
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents:
58
diff
changeset
|
688 |
TRAP_IGNORE(iObservers[i]->FeedDownloadFinishedL(MFeedEngineObserver::EFeedAutoUpdate, aFeedUid, aError)); |
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents:
58
diff
changeset
|
689 |
} |
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents:
58
diff
changeset
|
690 |
} |
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents:
58
diff
changeset
|
691 |
|
2 | 692 |
void CFeedEngine::Disconnected(CHttpClient* /*aClient*/) |
693 |
{ |
|
694 |
} |
|
695 |
||
696 |
void CFeedEngine::DownloadInfo(CHttpClient* /*aHttpClient */, int /*aTotalBytes*/) |
|
697 |
{ |
|
698 |
/*DP1("About to download %d bytes", aTotalBytes); |
|
699 |
if(aHttpClient == iShowClient && iShowDownloading != NULL && aTotalBytes != -1) { |
|
700 |
iShowDownloading->iShowSize = aTotalBytes; |
|
701 |
}*/ |
|
702 |
} |
|
703 |
||
704 |
EXPORT_C void CFeedEngine::ImportFeedsL(const TDesC& aFile) |
|
705 |
{ |
|
706 |
TFileName opmlPath; |
|
707 |
opmlPath.Copy(aFile); |
|
708 |
||
709 |
if (!iOpmlParser) { |
|
710 |
iOpmlParser = new COpmlParser(*this, iPodcastModel.FsSession()); |
|
711 |
} |
|
712 |
||
713 |
iOpmlParser->ParseOpmlL(opmlPath, EFalse); |
|
714 |
} |
|
715 |
||
716 |
EXPORT_C TBool CFeedEngine::ExportFeedsL(TFileName& aFile) |
|
717 |
{ |
|
718 |
RFile rfile; |
|
719 |
TFileName privatePath; |
|
720 |
iPodcastModel.FsSession().PrivatePath(privatePath); |
|
721 |
TInt error = rfile.Temp(iPodcastModel.FsSession(), privatePath, aFile, EFileWrite); |
|
722 |
if (error != KErrNone) |
|
723 |
{ |
|
724 |
DP("CFeedEngine::ExportFeedsL()\tFailed to open file"); |
|
725 |
return EFalse; |
|
726 |
} |
|
727 |
CleanupClosePushL(rfile); |
|
728 |
||
729 |
HBufC* templ = HBufC::NewLC(KMaxLineLength); |
|
730 |
templ->Des().Copy(KOpmlFeed()); |
|
731 |
||
732 |
HBufC* line = HBufC::NewLC(KMaxLineLength); |
|
733 |
HBufC* xmlUrl = HBufC::NewLC(KMaxURLLength); |
|
734 |
HBufC* htmlUrl = HBufC::NewLC(KMaxURLLength); |
|
735 |
HBufC* desc = HBufC::NewLC(KMaxDescriptionLength); |
|
736 |
HBufC* title = HBufC::NewLC(KMaxTitleLength); |
|
737 |
||
738 |
HBufC8* utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(KOpmlHeader()); |
|
739 |
||
740 |
rfile.Write(*utf8line); |
|
741 |
delete utf8line; |
|
742 |
||
743 |
for (int i=0; i<iSortedFeeds.Count(); i++) |
|
744 |
{ |
|
745 |
CFeedInfo *info = iSortedFeeds[i]; |
|
746 |
DP1("Exporting feed '%S'", &iSortedFeeds[i]->Title()); |
|
747 |
||
748 |
// XML URL |
|
749 |
TPtr ptrXml(xmlUrl->Des()); |
|
750 |
if (info->Url() != KNullDesC) |
|
751 |
{ |
|
752 |
ptrXml.Copy(info->Url()); |
|
753 |
PodcastUtils::XMLEncode(ptrXml); |
|
754 |
} |
|
755 |
||
756 |
// Description |
|
757 |
TPtr ptrDesc(desc->Des()); |
|
758 |
ptrDesc.Zero(); |
|
759 |
if (info->Description() != KNullDesC) { |
|
760 |
ptrDesc.Copy(info->Description()); |
|
761 |
PodcastUtils::XMLEncode(ptrDesc); |
|
762 |
} |
|
763 |
||
764 |
// Title |
|
765 |
TPtr ptrTitle(title->Des()); |
|
766 |
ptrTitle.Zero(); |
|
767 |
||
768 |
if (info->Title() != KNullDesC) { |
|
769 |
ptrTitle.Copy(info->Title()); |
|
770 |
PodcastUtils::XMLEncode(ptrTitle); |
|
771 |
} |
|
772 |
||
773 |
// HTML URL |
|
774 |
TPtr ptrHtmlUrl(htmlUrl->Des()); |
|
775 |
ptrHtmlUrl.Zero(); |
|
776 |
||
777 |
if (info->Link() != KNullDesC) { |
|
778 |
ptrHtmlUrl.Copy(info->Link()); |
|
779 |
PodcastUtils::XMLEncode(ptrHtmlUrl); |
|
780 |
} |
|
781 |
// Write line to OPML file |
|
782 |
line->Des().Format(*templ, title, desc, xmlUrl, htmlUrl); |
|
783 |
utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(*line); |
|
784 |
rfile.Write(*utf8line); |
|
785 |
delete utf8line; |
|
786 |
} |
|
787 |
||
788 |
utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(KOpmlFooter()); |
|
789 |
rfile.Write(*utf8line); |
|
790 |
delete utf8line; |
|
791 |
||
792 |
CleanupStack::PopAndDestroy(7);//destroy 6 bufs & close rfile |
|
793 |
||
794 |
return ETrue; |
|
795 |
} |
|
796 |
||
797 |
EXPORT_C CFeedInfo* CFeedEngine::GetFeedInfoByUid(TUint aFeedUid) |
|
798 |
{ |
|
799 |
TInt cnt = iSortedFeeds.Count(); |
|
800 |
for (TInt i=0;i<cnt;i++) |
|
801 |
{ |
|
802 |
if (iSortedFeeds[i]->Uid() == aFeedUid) |
|
803 |
{ |
|
804 |
return iSortedFeeds[i]; |
|
805 |
} |
|
806 |
} |
|
807 |
||
808 |
return NULL; |
|
809 |
} |
|
810 |
||
811 |
EXPORT_C const RFeedInfoArray& CFeedEngine::GetSortedFeeds() |
|
812 |
{ |
|
813 |
TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle); |
|
814 |
||
815 |
iSortedFeeds.Sort(sortOrder); |
|
816 |
return iSortedFeeds; |
|
817 |
} |
|
818 |
||
819 |
TInt CFeedEngine::CompareFeedsByTitle(const CFeedInfo &a, const CFeedInfo &b) |
|
820 |
{ |
|
821 |
//DP2("Comparing %S to %S", &a.Title(), &b.Title()); |
|
822 |
return a.Title().CompareF(b.Title()); |
|
823 |
} |
|
824 |
||
76 | 825 |
EXPORT_C void CFeedEngine::GetStatsByFeedL(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed) |
2 | 826 |
{ |
76 | 827 |
//DP1("CFeedEngine::GetStatsByFeed, aFeedUid=%u", aFeedUid); |
828 |
DBGetStatsByFeedL(aFeedUid, aNumShows, aNumUnplayed); |
|
2 | 829 |
} |
830 |
||
76 | 831 |
void CFeedEngine::DBGetStatsByFeedL(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed) |
2 | 832 |
{ |
833 |
//DP1("CFeedEngine::DBGetStatsByFeed, feedUid=%u", aFeedUid); |
|
834 |
_LIT(KSqlStatement, "select count(*) from shows where feeduid=%u"); |
|
835 |
iSqlBuffer.Format(KSqlStatement, aFeedUid); |
|
836 |
||
837 |
sqlite3_stmt *st; |
|
838 |
||
839 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &st, (const void**) NULL); |
|
840 |
||
76 | 841 |
if( rc==SQLITE_OK) |
842 |
{ |
|
843 |
Cleanup_sqlite3_finalize_PushL(st); |
|
2 | 844 |
rc = sqlite3_step(st); |
845 |
||
76 | 846 |
if (rc == SQLITE_ROW) |
847 |
{ |
|
2 | 848 |
aNumShows = sqlite3_column_int(st, 0); |
76 | 849 |
} |
850 |
else |
|
851 |
{ |
|
852 |
User::Leave(KErrNotFound); |
|
853 |
} |
|
854 |
CleanupStack::PopAndDestroy(); // st |
|
855 |
} |
|
856 |
else |
|
857 |
{ |
|
858 |
User::Leave(KErrCorrupt); |
|
859 |
} |
|
2 | 860 |
|
861 |
_LIT(KSqlStatement2, "select count(*) from shows where feeduid=%u and playstate=0"); |
|
862 |
iSqlBuffer.Format(KSqlStatement2, aFeedUid); |
|
863 |
||
864 |
rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &st, (const void**) NULL); |
|
865 |
||
76 | 866 |
if(rc==SQLITE_OK) |
867 |
{ |
|
868 |
Cleanup_sqlite3_finalize_PushL(st); |
|
2 | 869 |
rc = sqlite3_step(st); |
870 |
||
76 | 871 |
if (rc == SQLITE_ROW) |
872 |
{ |
|
2 | 873 |
aNumUnplayed = sqlite3_column_int(st, 0); |
76 | 874 |
} |
875 |
else |
|
876 |
{ |
|
877 |
User::Leave(KErrNotFound); |
|
878 |
} |
|
879 |
CleanupStack::PopAndDestroy(); // st |
|
2 | 880 |
} |
881 |
} |
|
882 |
||
76 | 883 |
TUint CFeedEngine::DBGetFeedCountL() |
2 | 884 |
{ |
76 | 885 |
DP("DBGetFeedCount BEGIN"); |
886 |
sqlite3_stmt *st; |
|
887 |
int rc = sqlite3_prepare_v2(&iDB,"select count(*) from feeds" , -1, &st, (const char**) NULL); |
|
888 |
TUint size = 0; |
|
2 | 889 |
|
76 | 890 |
if( rc==SQLITE_OK ) |
891 |
{ |
|
892 |
Cleanup_sqlite3_finalize_PushL(st); |
|
893 |
rc = sqlite3_step(st); |
|
894 |
||
895 |
if (rc == SQLITE_ROW) |
|
896 |
{ |
|
2 | 897 |
size = sqlite3_column_int(st, 0); |
76 | 898 |
} |
899 |
else |
|
900 |
{ |
|
901 |
User::Leave(KErrCorrupt); |
|
902 |
} |
|
903 |
CleanupStack::PopAndDestroy(); // st |
|
904 |
} |
|
905 |
else |
|
906 |
{ |
|
907 |
User::Leave(KErrCorrupt); |
|
908 |
} |
|
909 |
||
910 |
DP1("DBGetFeedCount END=%d", size); |
|
911 |
return size; |
|
2 | 912 |
} |
913 |
||
914 |
void CFeedEngine::DBLoadFeedsL() |
|
915 |
{ |
|
916 |
DP("DBLoadFeeds BEGIN"); |
|
917 |
iSortedFeeds.Reset(); |
|
918 |
CFeedInfo *feedInfo = NULL; |
|
919 |
||
84
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
920 |
_LIT(KSqlStatement, "select url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror from feeds"); |
2 | 921 |
iSqlBuffer.Format(KSqlStatement); |
922 |
||
923 |
sqlite3_stmt *st; |
|
924 |
||
925 |
TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle); |
|
926 |
||
927 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &st, (const void**) NULL); |
|
928 |
||
76 | 929 |
if (rc==SQLITE_OK) |
930 |
{ |
|
931 |
Cleanup_sqlite3_finalize_PushL(st); |
|
2 | 932 |
rc = sqlite3_step(st); |
76 | 933 |
while(rc == SQLITE_ROW) |
934 |
{ |
|
2 | 935 |
feedInfo = CFeedInfo::NewLC(); |
936 |
||
937 |
const void *urlz = sqlite3_column_text16(st, 0); |
|
938 |
TPtrC16 url((const TUint16*)urlz); |
|
939 |
feedInfo->SetUrlL(url); |
|
940 |
||
941 |
const void *titlez = sqlite3_column_text16(st, 1); |
|
942 |
TPtrC16 title((const TUint16*)titlez); |
|
943 |
feedInfo->SetTitleL(title); |
|
944 |
||
945 |
const void *descz = sqlite3_column_text16(st, 2); |
|
946 |
TPtrC16 desc((const TUint16*)descz); |
|
947 |
feedInfo->SetDescriptionL(desc); |
|
948 |
||
949 |
const void *imagez = sqlite3_column_text16(st, 3); |
|
950 |
TPtrC16 image((const TUint16*)imagez); |
|
951 |
feedInfo->SetImageUrlL(image); |
|
952 |
||
953 |
const void *imagefilez = sqlite3_column_text16(st, 4); |
|
954 |
TPtrC16 imagefile((const TUint16*)imagefilez); |
|
76 | 955 |
if (imagefile.Length() > 0) |
956 |
{ |
|
957 |
feedInfo->SetImageFileNameL(imagefile, &iPodcastModel); |
|
958 |
} |
|
959 |
||
2 | 960 |
const void *linkz = sqlite3_column_text16(st, 5); |
961 |
TPtrC16 link((const TUint16*)linkz); |
|
962 |
feedInfo->SetDescriptionL(link); |
|
963 |
||
964 |
sqlite3_int64 built = sqlite3_column_int64(st, 6); |
|
965 |
TTime buildtime(built); |
|
966 |
feedInfo->SetBuildDate(buildtime); |
|
967 |
||
968 |
sqlite3_int64 lastupdated = sqlite3_column_int64(st, 7); |
|
969 |
TTime lastupdatedtime(lastupdated); |
|
970 |
feedInfo->SetLastUpdated(lastupdatedtime); |
|
971 |
||
972 |
sqlite3_int64 customtitle = sqlite3_column_int64(st, 10); |
|
76 | 973 |
if (customtitle) |
974 |
{ |
|
2 | 975 |
feedInfo->SetCustomTitle(); |
76 | 976 |
} |
2 | 977 |
|
84
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
83
diff
changeset
|
978 |
sqlite3_int64 lasterror = sqlite3_column_int(st, 11); |
2 | 979 |
feedInfo->SetLastError(lasterror); |
980 |
||
981 |
TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle); |
|
982 |
||
983 |
iSortedFeeds.InsertInOrder(feedInfo, sortOrder); |
|
984 |
||
985 |
CleanupStack::Pop(feedInfo); |
|
986 |
||
987 |
rc = sqlite3_step(st); |
|
76 | 988 |
} |
989 |
CleanupStack::PopAndDestroy();//st |
|
2 | 990 |
} |
76 | 991 |
else |
992 |
{ |
|
993 |
User::Leave(KErrCorrupt); |
|
994 |
} |
|
2 | 995 |
|
996 |
DP("DBLoadFeeds END"); |
|
997 |
} |
|
998 |
||
999 |
CFeedInfo* CFeedEngine::DBGetFeedInfoByUidL(TUint aFeedUid) |
|
1000 |
{ |
|
1001 |
DP("CFeedEngine::DBGetFeedInfoByUid"); |
|
1002 |
CFeedInfo *feedInfo = NULL; |
|
1003 |
_LIT(KSqlStatement, "select url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror from feeds where uid=%u"); |
|
1004 |
iSqlBuffer.Format(KSqlStatement, aFeedUid); |
|
1005 |
||
1006 |
sqlite3_stmt *st; |
|
76 | 1007 |
|
2 | 1008 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &st, (const void**) NULL); |
1009 |
||
76 | 1010 |
if (rc==SQLITE_OK) |
1011 |
{ |
|
2 | 1012 |
Cleanup_sqlite3_finalize_PushL(st); |
1013 |
rc = sqlite3_step(st); |
|
76 | 1014 |
if (rc == SQLITE_ROW) |
1015 |
{ |
|
2 | 1016 |
feedInfo = CFeedInfo::NewLC(); |
1017 |
||
1018 |
const void *urlz = sqlite3_column_text16(st, 0); |
|
1019 |
TPtrC16 url((const TUint16*)urlz); |
|
1020 |
feedInfo->SetUrlL(url); |
|
1021 |
||
1022 |
const void *titlez = sqlite3_column_text16(st, 1); |
|
1023 |
TPtrC16 title((const TUint16*)titlez); |
|
1024 |
feedInfo->SetTitleL(title); |
|
1025 |
||
1026 |
const void *descz = sqlite3_column_text16(st, 2); |
|
1027 |
TPtrC16 desc((const TUint16*)descz); |
|
1028 |
feedInfo->SetDescriptionL(desc); |
|
1029 |
||
1030 |
const void *imagez = sqlite3_column_text16(st, 3); |
|
1031 |
TPtrC16 image((const TUint16*)imagez); |
|
1032 |
feedInfo->SetImageUrlL(image); |
|
1033 |
||
1034 |
const void *imagefilez = sqlite3_column_text16(st, 4); |
|
1035 |
TPtrC16 imagefile((const TUint16*)imagefilez); |
|
1036 |
feedInfo->SetDescriptionL(imagefile); |
|
1037 |
||
1038 |
const void *linkz = sqlite3_column_text16(st, 5); |
|
1039 |
TPtrC16 link((const TUint16*)linkz); |
|
1040 |
feedInfo->SetDescriptionL(link); |
|
1041 |
||
1042 |
sqlite3_int64 built = sqlite3_column_int64(st, 6); |
|
1043 |
TTime buildtime(built); |
|
1044 |
feedInfo->SetBuildDate(buildtime); |
|
1045 |
||
1046 |
sqlite3_int64 lastupdated = sqlite3_column_int64(st, 7); |
|
1047 |
TTime lastupdatedtime(lastupdated); |
|
1048 |
feedInfo->SetLastUpdated(lastupdatedtime); |
|
1049 |
||
1050 |
sqlite3_int64 customtitle = sqlite3_column_int64(st, 10); |
|
1051 |
if (customtitle) { |
|
1052 |
feedInfo->SetCustomTitle(); |
|
1053 |
} |
|
1054 |
||
1055 |
TInt lasterror = sqlite3_column_int(st, 11); |
|
1056 |
feedInfo->SetLastError(lasterror); |
|
1057 |
||
1058 |
CleanupStack::Pop(feedInfo); |
|
76 | 1059 |
} |
1060 |
else |
|
1061 |
{ |
|
1062 |
User::Leave(KErrNotFound); |
|
1063 |
} |
|
2 | 1064 |
CleanupStack::PopAndDestroy();//st |
76 | 1065 |
} |
1066 |
else |
|
1067 |
{ |
|
1068 |
User::Leave(KErrNotFound); |
|
1069 |
} |
|
2 | 1070 |
|
1071 |
return feedInfo; |
|
1072 |
} |
|
1073 |
||
69 | 1074 |
EXPORT_C void CFeedEngine::UpdateFeedInfoL(CFeedInfo *aItem) |
2 | 1075 |
{ |
69 | 1076 |
if (iActiveFeed && iActiveFeed->Uid() == aItem->Uid()) |
1077 |
{ |
|
1078 |
User::Leave(KErrInUse); |
|
1079 |
} |
|
1080 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
8
diff
changeset
|
1081 |
DBUpdateFeedL(*aItem); |
2 | 1082 |
} |
1083 |
||
1084 |
EXPORT_C void CFeedEngine::SearchForFeedL(TDesC& aSearchString) |
|
1085 |
{ |
|
1086 |
DP1("FeedEngine::SearchForFeedL BEGIN, aSearchString=%S", &aSearchString); |
|
1087 |
||
1088 |
if (iClientState != EIdle) { |
|
1089 |
User::Leave(KErrInUse); |
|
1090 |
} |
|
1091 |
TBuf<KMaxURLLength> ssBuf; |
|
1092 |
ssBuf.Copy(aSearchString); |
|
1093 |
PodcastUtils::ReplaceString(ssBuf, _L(" "), _L("%20")); |
|
1094 |
// prepare search URL |
|
1095 |
HBufC* templ = HBufC::NewLC(KMaxLineLength); |
|
1096 |
templ->Des().Copy(KSearchUrl()); |
|
1097 |
||
1098 |
HBufC* url = HBufC::NewLC(KMaxURLLength); |
|
1099 |
url->Des().Format(*templ, &ssBuf); |
|
1100 |
||
1101 |
DP1("SearchURL: %S", url); |
|
1102 |
||
1103 |
// crate path to store OPML search results |
|
1104 |
iPodcastModel.FsSession().PrivatePath(iSearchResultsFileName); |
|
1105 |
||
1106 |
iSearchResultsFileName.Append(KSearchResultsFileName); |
|
1107 |
iSearchResults.ResetAndDestroy(); |
|
1108 |
// run search |
|
1109 |
if(iFeedClient->GetL(*url, iSearchResultsFileName, iPodcastModel.SettingsEngine().SpecificIAP())) |
|
1110 |
{ |
|
1111 |
iClientState = ESearching; |
|
1112 |
} |
|
1113 |
else |
|
1114 |
{ |
|
1115 |
iClientState = EIdle; |
|
1116 |
User::Leave(KErrAbort); |
|
1117 |
} |
|
1118 |
||
1119 |
CleanupStack::PopAndDestroy(url); |
|
1120 |
CleanupStack::PopAndDestroy(templ); |
|
1121 |
||
1122 |
DP("FeedEngine::SearchForFeedL END"); |
|
1123 |
} |
|
1124 |
||
1125 |
EXPORT_C void CFeedEngine::AddSearchResultL(CFeedInfo *item) |
|
1126 |
{ |
|
1127 |
DP1("CFeedEngine::AddSearchResultL, item->Title()=%S", &(item->Title())); |
|
1128 |
iSearchResults.AppendL(item); |
|
1129 |
} |
|
1130 |
||
1131 |
EXPORT_C const RFeedInfoArray& CFeedEngine::GetSearchResults() |
|
1132 |
{ |
|
1133 |
return iSearchResults; |
|
1134 |
} |
|
1135 |
||
1136 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
8
diff
changeset
|
1137 |
EXPORT_C void CFeedEngine::OpmlParsingCompleteL(TInt aError, TUint aNumFeedsAdded) |
2 | 1138 |
{ |
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
8
diff
changeset
|
1139 |
NotifyOpmlParsingCompleteL(aError, aNumFeedsAdded); |
2 | 1140 |
} |
1141 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
8
diff
changeset
|
1142 |
void CFeedEngine::NotifyOpmlParsingCompleteL(TInt aError, TUint aNumFeedsAdded) |
2 | 1143 |
{ |
1144 |
for (TInt i=0;i<iObservers.Count();i++) |
|
1145 |
{ |
|
7 | 1146 |
iObservers[i]->OpmlParsingComplete(aError, aNumFeedsAdded); |
2 | 1147 |
} |
1148 |
} |