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