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