author | Sebastian Brannstrom <sebastianb@symbian.org> |
Wed, 14 Jul 2010 14:53:21 +0100 | |
branch | symbian1 |
changeset 181 | d0200555f97b |
parent 167 | 4bfc2fcec5f6 |
child 171 | cc1be3797632 |
child 189 | d1539f926e3e |
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 |
{ |
164
000f9fc147b2
Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
130
diff
changeset
|
360 |
DP2("CFeedEngine::DBAddFeed BEGIN, title=%S, URL=%S", &aItem.Title(), &aItem.Url()); |
2 | 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 |
||
164
000f9fc147b2
Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
130
diff
changeset
|
381 |
_LIT(KSqlStatement, "insert into feeds (url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror) values (\"%S\",\"%S\", \"%S\", \"%S\", \"%S\", \"%S\", \"%Ld\", \"%Ld\", \"%u\", \"%u\", \"%u\", \"%d\")"); |
2 | 382 |
iSqlBuffer.Format(KSqlStatement, |
383 |
&aItem.Url(), titleBuf, descBuf, &aItem.ImageUrl(), &aItem.ImageFileName(), &aItem.Link(), |
|
384 |
aItem.BuildDate().Int64(), aItem.LastUpdated().Int64(), aItem.Uid(), EAudioPodcast, aItem.CustomTitle(), aItem.LastError()); |
|
385 |
||
386 |
CleanupStack::PopAndDestroy(descBuf); |
|
387 |
CleanupStack::PopAndDestroy(titleBuf); |
|
388 |
||
389 |
sqlite3_stmt *st; |
|
390 |
||
391 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &st, (const void**) NULL); |
|
392 |
||
393 |
if (rc==SQLITE_OK) |
|
394 |
{ |
|
60 | 395 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 396 |
rc = sqlite3_step(st); |
397 |
||
60 | 398 |
if (rc != SQLITE_DONE) |
2 | 399 |
{ |
60 | 400 |
User::Leave(KErrCorrupt); |
2 | 401 |
} |
60 | 402 |
CleanupStack::PopAndDestroy(); // st |
2 | 403 |
} |
60 | 404 |
else |
405 |
{ |
|
406 |
User::Leave(KErrCorrupt); |
|
407 |
} |
|
164
000f9fc147b2
Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
130
diff
changeset
|
408 |
DP("CFeedEngine::DBAddFeed END"); |
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 |
{ |
164
000f9fc147b2
Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
130
diff
changeset
|
454 |
DP("CFeedEngine::DBRemoveFeed BEGIN"); |
2 | 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 |
} |
|
164
000f9fc147b2
Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
130
diff
changeset
|
478 |
DP("CFeedEngine::DBRemoveFeed END"); |
2 | 479 |
} |
480 |
||
60 | 481 |
void CFeedEngine::DBUpdateFeedL(const CFeedInfo &aItem) |
2 | 482 |
{ |
164
000f9fc147b2
Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
130
diff
changeset
|
483 |
DP2("CFeedEngine::DBUpdateFeed BEGIN, title=%S, URL=%S", &aItem.Title(), &aItem.Url()); |
2 | 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 |
||
164
000f9fc147b2
Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
130
diff
changeset
|
495 |
_LIT(KSqlStatement, "update feeds set url=\"%S\", title=\"%S\", description=\"%S\", imageurl=\"%S\", imagefile=\"%S\", link=\"%S\", built=\"%Lu\", lastupdated=\"%Lu\", feedtype=\"%u\", customtitle=\"%u\", lasterror=\"%d\" where uid=\"%u\""); |
2 | 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 |
} |
164
000f9fc147b2
Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
130
diff
changeset
|
522 |
DP("CFeedEngine::DBUpdateFeed END"); |
2 | 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 |
} |
|
702 |
||
703 |
EXPORT_C void CFeedEngine::ImportFeedsL(const TDesC& aFile) |
|
704 |
{ |
|
705 |
TFileName opmlPath; |
|
706 |
opmlPath.Copy(aFile); |
|
707 |
||
708 |
if (!iOpmlParser) { |
|
709 |
iOpmlParser = new COpmlParser(*this, iPodcastModel.FsSession()); |
|
710 |
} |
|
711 |
||
712 |
iOpmlParser->ParseOpmlL(opmlPath, EFalse); |
|
713 |
} |
|
714 |
||
715 |
EXPORT_C TBool CFeedEngine::ExportFeedsL(TFileName& aFile) |
|
716 |
{ |
|
717 |
RFile rfile; |
|
718 |
TFileName privatePath; |
|
719 |
iPodcastModel.FsSession().PrivatePath(privatePath); |
|
720 |
TInt error = rfile.Temp(iPodcastModel.FsSession(), privatePath, aFile, EFileWrite); |
|
721 |
if (error != KErrNone) |
|
722 |
{ |
|
723 |
DP("CFeedEngine::ExportFeedsL()\tFailed to open file"); |
|
724 |
return EFalse; |
|
725 |
} |
|
726 |
CleanupClosePushL(rfile); |
|
727 |
||
728 |
HBufC* templ = HBufC::NewLC(KMaxLineLength); |
|
729 |
templ->Des().Copy(KOpmlFeed()); |
|
730 |
||
731 |
HBufC* line = HBufC::NewLC(KMaxLineLength); |
|
732 |
HBufC* xmlUrl = HBufC::NewLC(KMaxURLLength); |
|
733 |
HBufC* htmlUrl = HBufC::NewLC(KMaxURLLength); |
|
734 |
HBufC* desc = HBufC::NewLC(KMaxDescriptionLength); |
|
735 |
HBufC* title = HBufC::NewLC(KMaxTitleLength); |
|
736 |
||
737 |
HBufC8* utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(KOpmlHeader()); |
|
738 |
||
739 |
rfile.Write(*utf8line); |
|
740 |
delete utf8line; |
|
741 |
||
742 |
for (int i=0; i<iSortedFeeds.Count(); i++) |
|
743 |
{ |
|
744 |
CFeedInfo *info = iSortedFeeds[i]; |
|
745 |
DP1("Exporting feed '%S'", &iSortedFeeds[i]->Title()); |
|
746 |
||
747 |
// XML URL |
|
748 |
TPtr ptrXml(xmlUrl->Des()); |
|
749 |
if (info->Url() != KNullDesC) |
|
750 |
{ |
|
751 |
ptrXml.Copy(info->Url()); |
|
752 |
PodcastUtils::XMLEncode(ptrXml); |
|
753 |
} |
|
754 |
||
755 |
// Description |
|
756 |
TPtr ptrDesc(desc->Des()); |
|
757 |
ptrDesc.Zero(); |
|
758 |
if (info->Description() != KNullDesC) { |
|
759 |
ptrDesc.Copy(info->Description()); |
|
760 |
PodcastUtils::XMLEncode(ptrDesc); |
|
761 |
} |
|
762 |
||
763 |
// Title |
|
764 |
TPtr ptrTitle(title->Des()); |
|
765 |
ptrTitle.Zero(); |
|
766 |
||
767 |
if (info->Title() != KNullDesC) { |
|
768 |
ptrTitle.Copy(info->Title()); |
|
769 |
PodcastUtils::XMLEncode(ptrTitle); |
|
770 |
} |
|
771 |
||
772 |
// HTML URL |
|
773 |
TPtr ptrHtmlUrl(htmlUrl->Des()); |
|
774 |
ptrHtmlUrl.Zero(); |
|
775 |
||
776 |
if (info->Link() != KNullDesC) { |
|
777 |
ptrHtmlUrl.Copy(info->Link()); |
|
778 |
PodcastUtils::XMLEncode(ptrHtmlUrl); |
|
779 |
} |
|
780 |
// Write line to OPML file |
|
781 |
line->Des().Format(*templ, title, desc, xmlUrl, htmlUrl); |
|
782 |
utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(*line); |
|
783 |
rfile.Write(*utf8line); |
|
784 |
delete utf8line; |
|
785 |
} |
|
786 |
||
787 |
utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(KOpmlFooter()); |
|
788 |
rfile.Write(*utf8line); |
|
789 |
delete utf8line; |
|
790 |
||
791 |
CleanupStack::PopAndDestroy(7);//destroy 6 bufs & close rfile |
|
792 |
||
793 |
return ETrue; |
|
794 |
} |
|
795 |
||
796 |
EXPORT_C CFeedInfo* CFeedEngine::GetFeedInfoByUid(TUint aFeedUid) |
|
797 |
{ |
|
798 |
TInt cnt = iSortedFeeds.Count(); |
|
799 |
for (TInt i=0;i<cnt;i++) |
|
800 |
{ |
|
801 |
if (iSortedFeeds[i]->Uid() == aFeedUid) |
|
802 |
{ |
|
803 |
return iSortedFeeds[i]; |
|
804 |
} |
|
805 |
} |
|
806 |
||
807 |
return NULL; |
|
808 |
} |
|
809 |
||
810 |
EXPORT_C const RFeedInfoArray& CFeedEngine::GetSortedFeeds() |
|
811 |
{ |
|
812 |
TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle); |
|
813 |
||
814 |
iSortedFeeds.Sort(sortOrder); |
|
815 |
return iSortedFeeds; |
|
816 |
} |
|
817 |
||
818 |
TInt CFeedEngine::CompareFeedsByTitle(const CFeedInfo &a, const CFeedInfo &b) |
|
819 |
{ |
|
820 |
//DP2("Comparing %S to %S", &a.Title(), &b.Title()); |
|
821 |
return a.Title().CompareF(b.Title()); |
|
822 |
} |
|
823 |
||
60 | 824 |
EXPORT_C void CFeedEngine::GetStatsByFeedL(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed) |
2 | 825 |
{ |
60 | 826 |
//DP1("CFeedEngine::GetStatsByFeed, aFeedUid=%u", aFeedUid); |
827 |
DBGetStatsByFeedL(aFeedUid, aNumShows, aNumUnplayed); |
|
2 | 828 |
} |
829 |
||
60 | 830 |
void CFeedEngine::DBGetStatsByFeedL(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed) |
2 | 831 |
{ |
832 |
//DP1("CFeedEngine::DBGetStatsByFeed, feedUid=%u", aFeedUid); |
|
833 |
_LIT(KSqlStatement, "select count(*) from shows where feeduid=%u"); |
|
834 |
iSqlBuffer.Format(KSqlStatement, aFeedUid); |
|
835 |
||
836 |
sqlite3_stmt *st; |
|
837 |
||
838 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &st, (const void**) NULL); |
|
839 |
||
60 | 840 |
if( rc==SQLITE_OK) |
841 |
{ |
|
842 |
Cleanup_sqlite3_finalize_PushL(st); |
|
2 | 843 |
rc = sqlite3_step(st); |
844 |
||
60 | 845 |
if (rc == SQLITE_ROW) |
846 |
{ |
|
2 | 847 |
aNumShows = sqlite3_column_int(st, 0); |
60 | 848 |
} |
849 |
else |
|
850 |
{ |
|
851 |
User::Leave(KErrNotFound); |
|
852 |
} |
|
853 |
CleanupStack::PopAndDestroy(); // st |
|
854 |
} |
|
855 |
else |
|
856 |
{ |
|
857 |
User::Leave(KErrCorrupt); |
|
858 |
} |
|
2 | 859 |
|
860 |
_LIT(KSqlStatement2, "select count(*) from shows where feeduid=%u and playstate=0"); |
|
861 |
iSqlBuffer.Format(KSqlStatement2, aFeedUid); |
|
862 |
||
863 |
rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &st, (const void**) NULL); |
|
864 |
||
60 | 865 |
if(rc==SQLITE_OK) |
866 |
{ |
|
867 |
Cleanup_sqlite3_finalize_PushL(st); |
|
2 | 868 |
rc = sqlite3_step(st); |
869 |
||
60 | 870 |
if (rc == SQLITE_ROW) |
871 |
{ |
|
2 | 872 |
aNumUnplayed = sqlite3_column_int(st, 0); |
60 | 873 |
} |
874 |
else |
|
875 |
{ |
|
876 |
User::Leave(KErrNotFound); |
|
877 |
} |
|
878 |
CleanupStack::PopAndDestroy(); // st |
|
2 | 879 |
} |
880 |
} |
|
881 |
||
60 | 882 |
TUint CFeedEngine::DBGetFeedCountL() |
2 | 883 |
{ |
60 | 884 |
DP("DBGetFeedCount BEGIN"); |
885 |
sqlite3_stmt *st; |
|
886 |
int rc = sqlite3_prepare_v2(&iDB,"select count(*) from feeds" , -1, &st, (const char**) NULL); |
|
887 |
TUint size = 0; |
|
2 | 888 |
|
60 | 889 |
if( rc==SQLITE_OK ) |
890 |
{ |
|
891 |
Cleanup_sqlite3_finalize_PushL(st); |
|
892 |
rc = sqlite3_step(st); |
|
893 |
||
894 |
if (rc == SQLITE_ROW) |
|
895 |
{ |
|
2 | 896 |
size = sqlite3_column_int(st, 0); |
60 | 897 |
} |
898 |
else |
|
899 |
{ |
|
900 |
User::Leave(KErrCorrupt); |
|
901 |
} |
|
902 |
CleanupStack::PopAndDestroy(); // st |
|
903 |
} |
|
904 |
else |
|
905 |
{ |
|
906 |
User::Leave(KErrCorrupt); |
|
907 |
} |
|
908 |
||
909 |
DP1("DBGetFeedCount END=%d", size); |
|
910 |
return size; |
|
2 | 911 |
} |
912 |
||
913 |
void CFeedEngine::DBLoadFeedsL() |
|
914 |
{ |
|
915 |
DP("DBLoadFeeds BEGIN"); |
|
916 |
iSortedFeeds.Reset(); |
|
917 |
CFeedInfo *feedInfo = NULL; |
|
918 |
||
60 | 919 |
_LIT(KSqlStatement, "select url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror from feeds"); |
2 | 920 |
iSqlBuffer.Format(KSqlStatement); |
921 |
||
922 |
sqlite3_stmt *st; |
|
923 |
||
924 |
TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle); |
|
925 |
||
926 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &st, (const void**) NULL); |
|
927 |
||
60 | 928 |
if (rc==SQLITE_OK) |
929 |
{ |
|
930 |
Cleanup_sqlite3_finalize_PushL(st); |
|
2 | 931 |
rc = sqlite3_step(st); |
60 | 932 |
while(rc == SQLITE_ROW) |
933 |
{ |
|
2 | 934 |
feedInfo = CFeedInfo::NewLC(); |
935 |
||
936 |
const void *urlz = sqlite3_column_text16(st, 0); |
|
937 |
TPtrC16 url((const TUint16*)urlz); |
|
938 |
feedInfo->SetUrlL(url); |
|
939 |
||
940 |
const void *titlez = sqlite3_column_text16(st, 1); |
|
941 |
TPtrC16 title((const TUint16*)titlez); |
|
942 |
feedInfo->SetTitleL(title); |
|
943 |
||
944 |
const void *descz = sqlite3_column_text16(st, 2); |
|
945 |
TPtrC16 desc((const TUint16*)descz); |
|
946 |
feedInfo->SetDescriptionL(desc); |
|
947 |
||
948 |
const void *imagez = sqlite3_column_text16(st, 3); |
|
949 |
TPtrC16 image((const TUint16*)imagez); |
|
950 |
feedInfo->SetImageUrlL(image); |
|
951 |
||
952 |
const void *imagefilez = sqlite3_column_text16(st, 4); |
|
953 |
TPtrC16 imagefile((const TUint16*)imagefilez); |
|
60 | 954 |
if (imagefile.Length() > 0) |
955 |
{ |
|
956 |
feedInfo->SetImageFileNameL(imagefile, &iPodcastModel); |
|
957 |
} |
|
958 |
||
2 | 959 |
const void *linkz = sqlite3_column_text16(st, 5); |
960 |
TPtrC16 link((const TUint16*)linkz); |
|
961 |
feedInfo->SetDescriptionL(link); |
|
962 |
||
963 |
sqlite3_int64 built = sqlite3_column_int64(st, 6); |
|
964 |
TTime buildtime(built); |
|
965 |
feedInfo->SetBuildDate(buildtime); |
|
966 |
||
967 |
sqlite3_int64 lastupdated = sqlite3_column_int64(st, 7); |
|
968 |
TTime lastupdatedtime(lastupdated); |
|
969 |
feedInfo->SetLastUpdated(lastupdatedtime); |
|
970 |
||
971 |
sqlite3_int64 customtitle = sqlite3_column_int64(st, 10); |
|
60 | 972 |
if (customtitle) |
973 |
{ |
|
2 | 974 |
feedInfo->SetCustomTitle(); |
60 | 975 |
} |
2 | 976 |
|
60 | 977 |
sqlite3_int64 lasterror = sqlite3_column_int(st, 11); |
2 | 978 |
feedInfo->SetLastError(lasterror); |
979 |
||
980 |
TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle); |
|
981 |
||
982 |
iSortedFeeds.InsertInOrder(feedInfo, sortOrder); |
|
983 |
||
984 |
CleanupStack::Pop(feedInfo); |
|
985 |
||
986 |
rc = sqlite3_step(st); |
|
60 | 987 |
} |
988 |
CleanupStack::PopAndDestroy();//st |
|
2 | 989 |
} |
60 | 990 |
else |
991 |
{ |
|
992 |
User::Leave(KErrCorrupt); |
|
993 |
} |
|
2 | 994 |
|
995 |
DP("DBLoadFeeds END"); |
|
996 |
} |
|
997 |
||
998 |
CFeedInfo* CFeedEngine::DBGetFeedInfoByUidL(TUint aFeedUid) |
|
999 |
{ |
|
164
000f9fc147b2
Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
130
diff
changeset
|
1000 |
DP("CFeedEngine::DBGetFeedInfoByUid BEGIN"); |
2 | 1001 |
CFeedInfo *feedInfo = NULL; |
1002 |
_LIT(KSqlStatement, "select url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror from feeds where uid=%u"); |
|
1003 |
iSqlBuffer.Format(KSqlStatement, aFeedUid); |
|
1004 |
||
1005 |
sqlite3_stmt *st; |
|
60 | 1006 |
|
2 | 1007 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &st, (const void**) NULL); |
1008 |
||
60 | 1009 |
if (rc==SQLITE_OK) |
1010 |
{ |
|
2 | 1011 |
Cleanup_sqlite3_finalize_PushL(st); |
1012 |
rc = sqlite3_step(st); |
|
60 | 1013 |
if (rc == SQLITE_ROW) |
1014 |
{ |
|
2 | 1015 |
feedInfo = CFeedInfo::NewLC(); |
1016 |
||
1017 |
const void *urlz = sqlite3_column_text16(st, 0); |
|
1018 |
TPtrC16 url((const TUint16*)urlz); |
|
1019 |
feedInfo->SetUrlL(url); |
|
1020 |
||
1021 |
const void *titlez = sqlite3_column_text16(st, 1); |
|
1022 |
TPtrC16 title((const TUint16*)titlez); |
|
1023 |
feedInfo->SetTitleL(title); |
|
1024 |
||
1025 |
const void *descz = sqlite3_column_text16(st, 2); |
|
1026 |
TPtrC16 desc((const TUint16*)descz); |
|
1027 |
feedInfo->SetDescriptionL(desc); |
|
1028 |
||
1029 |
const void *imagez = sqlite3_column_text16(st, 3); |
|
1030 |
TPtrC16 image((const TUint16*)imagez); |
|
1031 |
feedInfo->SetImageUrlL(image); |
|
1032 |
||
1033 |
const void *imagefilez = sqlite3_column_text16(st, 4); |
|
1034 |
TPtrC16 imagefile((const TUint16*)imagefilez); |
|
1035 |
feedInfo->SetDescriptionL(imagefile); |
|
1036 |
||
1037 |
const void *linkz = sqlite3_column_text16(st, 5); |
|
1038 |
TPtrC16 link((const TUint16*)linkz); |
|
1039 |
feedInfo->SetDescriptionL(link); |
|
1040 |
||
1041 |
sqlite3_int64 built = sqlite3_column_int64(st, 6); |
|
1042 |
TTime buildtime(built); |
|
1043 |
feedInfo->SetBuildDate(buildtime); |
|
1044 |
||
1045 |
sqlite3_int64 lastupdated = sqlite3_column_int64(st, 7); |
|
1046 |
TTime lastupdatedtime(lastupdated); |
|
1047 |
feedInfo->SetLastUpdated(lastupdatedtime); |
|
1048 |
||
1049 |
sqlite3_int64 customtitle = sqlite3_column_int64(st, 10); |
|
1050 |
if (customtitle) { |
|
1051 |
feedInfo->SetCustomTitle(); |
|
1052 |
} |
|
1053 |
||
1054 |
TInt lasterror = sqlite3_column_int(st, 11); |
|
1055 |
feedInfo->SetLastError(lasterror); |
|
1056 |
||
1057 |
CleanupStack::Pop(feedInfo); |
|
60 | 1058 |
} |
1059 |
else |
|
1060 |
{ |
|
1061 |
User::Leave(KErrNotFound); |
|
1062 |
} |
|
2 | 1063 |
CleanupStack::PopAndDestroy();//st |
60 | 1064 |
} |
1065 |
else |
|
1066 |
{ |
|
1067 |
User::Leave(KErrNotFound); |
|
1068 |
} |
|
164
000f9fc147b2
Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
130
diff
changeset
|
1069 |
DP("CFeedEngine::DBGetFeedInfoByUid END"); |
2 | 1070 |
return feedInfo; |
1071 |
} |
|
1072 |
||
60 | 1073 |
EXPORT_C void CFeedEngine::UpdateFeedInfoL(CFeedInfo *aItem) |
2 | 1074 |
{ |
60 | 1075 |
if (iActiveFeed && iActiveFeed->Uid() == aItem->Uid()) |
1076 |
{ |
|
1077 |
User::Leave(KErrInUse); |
|
1078 |
} |
|
1079 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
8
diff
changeset
|
1080 |
DBUpdateFeedL(*aItem); |
2 | 1081 |
} |
1082 |
||
1083 |
EXPORT_C void CFeedEngine::SearchForFeedL(TDesC& aSearchString) |
|
1084 |
{ |
|
1085 |
DP1("FeedEngine::SearchForFeedL BEGIN, aSearchString=%S", &aSearchString); |
|
1086 |
||
1087 |
if (iClientState != EIdle) { |
|
1088 |
User::Leave(KErrInUse); |
|
1089 |
} |
|
1090 |
TBuf<KMaxURLLength> ssBuf; |
|
1091 |
ssBuf.Copy(aSearchString); |
|
1092 |
PodcastUtils::ReplaceString(ssBuf, _L(" "), _L("%20")); |
|
1093 |
// prepare search URL |
|
1094 |
HBufC* templ = HBufC::NewLC(KMaxLineLength); |
|
1095 |
templ->Des().Copy(KSearchUrl()); |
|
1096 |
||
1097 |
HBufC* url = HBufC::NewLC(KMaxURLLength); |
|
1098 |
url->Des().Format(*templ, &ssBuf); |
|
1099 |
||
1100 |
DP1("SearchURL: %S", url); |
|
1101 |
||
1102 |
// crate path to store OPML search results |
|
1103 |
iPodcastModel.FsSession().PrivatePath(iSearchResultsFileName); |
|
1104 |
||
1105 |
iSearchResultsFileName.Append(KSearchResultsFileName); |
|
1106 |
iSearchResults.ResetAndDestroy(); |
|
1107 |
// run search |
|
1108 |
if(iFeedClient->GetL(*url, iSearchResultsFileName, iPodcastModel.SettingsEngine().SpecificIAP())) |
|
1109 |
{ |
|
1110 |
iClientState = ESearching; |
|
1111 |
} |
|
1112 |
else |
|
1113 |
{ |
|
1114 |
iClientState = EIdle; |
|
1115 |
User::Leave(KErrAbort); |
|
1116 |
} |
|
1117 |
||
1118 |
CleanupStack::PopAndDestroy(url); |
|
1119 |
CleanupStack::PopAndDestroy(templ); |
|
1120 |
||
1121 |
DP("FeedEngine::SearchForFeedL END"); |
|
1122 |
} |
|
1123 |
||
1124 |
EXPORT_C void CFeedEngine::AddSearchResultL(CFeedInfo *item) |
|
1125 |
{ |
|
1126 |
DP1("CFeedEngine::AddSearchResultL, item->Title()=%S", &(item->Title())); |
|
1127 |
iSearchResults.AppendL(item); |
|
1128 |
} |
|
1129 |
||
1130 |
EXPORT_C const RFeedInfoArray& CFeedEngine::GetSearchResults() |
|
1131 |
{ |
|
1132 |
return iSearchResults; |
|
1133 |
} |
|
1134 |
||
1135 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
8
diff
changeset
|
1136 |
EXPORT_C void CFeedEngine::OpmlParsingCompleteL(TInt aError, TUint aNumFeedsAdded) |
2 | 1137 |
{ |
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
8
diff
changeset
|
1138 |
NotifyOpmlParsingCompleteL(aError, aNumFeedsAdded); |
2 | 1139 |
} |
1140 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
8
diff
changeset
|
1141 |
void CFeedEngine::NotifyOpmlParsingCompleteL(TInt aError, TUint aNumFeedsAdded) |
2 | 1142 |
{ |
1143 |
for (TInt i=0;i<iObservers.Count();i++) |
|
1144 |
{ |
|
7 | 1145 |
iObservers[i]->OpmlParsingComplete(aError, aNumFeedsAdded); |
2 | 1146 |
} |
1147 |
} |