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