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