author | larspson |
Wed, 13 Oct 2010 20:12:52 +0200 | |
branch | podcatcher_qt_symbian4 |
changeset 233 | e78b6d7efcb2 |
parent 228 | c553fa9dcbe5 |
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 "ShowEngine.h" |
|
20 |
#include "FeedEngine.h" |
|
21 |
#include "FeedInfo.h" |
|
22 |
#include <bautils.h> |
|
23 |
#include <s32file.h> |
|
24 |
#include "SettingsEngine.h" |
|
25 |
#include <e32hashtab.h> |
|
26 |
#include <httperr.h> |
|
228 | 27 |
#include "podcatcher_debug.h" |
2 | 28 |
#include "PodcastUtils.h" |
202
e1dedb07817d
Tweaks to capabilities in DLL to enable self signing; Opening RCL_3 branch.
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
200
diff
changeset
|
29 |
|
e1dedb07817d
Tweaks to capabilities in DLL to enable self signing; Opening RCL_3 branch.
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
200
diff
changeset
|
30 |
#ifdef ENABLE_MPX_INTEGRATION |
126 | 31 |
#include <mpxcollectionhelperfactory.h> |
202
e1dedb07817d
Tweaks to capabilities in DLL to enable self signing; Opening RCL_3 branch.
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
200
diff
changeset
|
32 |
#endif |
2 | 33 |
|
34 |
const TUint KMaxDownloadErrors = 3; |
|
35 |
const TInt KMimeBufLength = 100; |
|
36 |
||
37 |
CShowEngine::CShowEngine(CPodcastModel& aPodcastModel) : |
|
38 |
iPodcastModel(aPodcastModel), |
|
39 |
iDB(*aPodcastModel.DB()) |
|
40 |
{ |
|
41 |
} |
|
42 |
||
43 |
EXPORT_C CShowEngine::~CShowEngine() |
|
44 |
{ |
|
45 |
delete iShowClient; |
|
46 |
iObservers.Close(); |
|
47 |
delete iShowDownloading; |
|
48 |
delete iMetaDataReader; |
|
49 |
iApaSession.Close(); |
|
200
79076725bab9
Added #define to enable/disable MPX integration, since it requires capabilities that can't be granted when self signed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
50 |
#ifdef ENABLE_MPX_INTEGRATION |
126 | 51 |
if (iCollectionHelper) |
52 |
delete iCollectionHelper; |
|
200
79076725bab9
Added #define to enable/disable MPX integration, since it requires capabilities that can't be granted when self signed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
53 |
#endif |
2 | 54 |
} |
55 |
||
56 |
EXPORT_C CShowEngine* CShowEngine::NewL(CPodcastModel& aPodcastModel) |
|
57 |
{ |
|
58 |
CShowEngine* self = new (ELeave) CShowEngine(aPodcastModel); |
|
59 |
CleanupStack::PushL(self); |
|
60 |
self->ConstructL(); |
|
61 |
CleanupStack::Pop(self); |
|
62 |
return self; |
|
63 |
} |
|
64 |
||
65 |
EXPORT_C void CShowEngine::GetMimeType(const TDesC& aFileName, TDes& aMimeType) |
|
66 |
{ |
|
67 |
aMimeType.Zero(); |
|
68 |
RFile file; |
|
69 |
if (file.Open(iPodcastModel.FsSession(), aFileName, 0) == KErrNone) |
|
70 |
{ |
|
71 |
if (file.Read(iRecogBuffer) == KErrNone) |
|
72 |
{ |
|
73 |
TDataRecognitionResult result; |
|
74 |
if (iApaSession.RecognizeData(aFileName, iRecogBuffer, result) |
|
75 |
== KErrNone) |
|
76 |
{ |
|
77 |
aMimeType.Copy(result.iDataType.Des()); |
|
78 |
} |
|
79 |
||
80 |
} |
|
81 |
} |
|
82 |
file.Close(); |
|
83 |
} |
|
84 |
||
85 |
void CShowEngine::ConstructL() |
|
86 |
{ |
|
87 |
iShowClient = CHttpClient::NewL(iPodcastModel, *this); |
|
88 |
iShowClient->SetResumeEnabled(ETrue); |
|
89 |
iMetaDataReader = new (ELeave) CMetaDataReader(*this, iPodcastModel.FsSession()); |
|
90 |
iMetaDataReader->ConstructL(); |
|
91 |
User::LeaveIfError(iApaSession.Connect()); |
|
92 |
} |
|
93 |
||
94 |
EXPORT_C void CShowEngine::SuspendDownloads() |
|
95 |
{ |
|
96 |
iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue); |
|
97 |
iShowClient->Stop(); |
|
98 |
} |
|
99 |
||
100 |
EXPORT_C void CShowEngine::ResumeDownloadsL() |
|
101 |
{ |
|
102 |
DP("CShowEngine::ResumeDownloadsL BEGIN"); |
|
103 |
if (iPodcastModel.SettingsEngine().DownloadSuspended()) |
|
104 |
{ |
|
105 |
iPodcastModel.SettingsEngine().SetDownloadSuspended(EFalse); |
|
106 |
iDownloadErrors = 0; |
|
107 |
DownloadNextShowL(); |
|
108 |
} |
|
109 |
DP("CShowEngine::ResumeDownloadsL END"); |
|
110 |
} |
|
111 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
112 |
EXPORT_C void CShowEngine::RemoveAllDownloadsL() |
2 | 113 |
{ |
114 |
if (!iPodcastModel.SettingsEngine().DownloadSuspended()) |
|
115 |
{ |
|
116 |
SuspendDownloads(); |
|
117 |
} |
|
118 |
||
111 | 119 |
DBRemoveAllDownloadsL(); |
22 | 120 |
NotifyDownloadQueueUpdatedL(); |
2 | 121 |
} |
122 |
||
111 | 123 |
EXPORT_C void CShowEngine::RemoveDownloadL(TUint aUid) |
2 | 124 |
{ |
111 | 125 |
DP("CShowEngine::RemoveDownloadL BEGIN"); |
2 | 126 |
|
127 |
TBool resumeAfterRemove = EFalse; |
|
128 |
// if trying to remove the present download, we first stop it |
|
129 |
if (!iPodcastModel.SettingsEngine().DownloadSuspended() && iShowDownloading != NULL |
|
130 |
&& iShowDownloading->Uid() == aUid) |
|
131 |
{ |
|
132 |
DP("CShowEngine::RemoveDownload\t This is the active download, we suspend downloading"); |
|
133 |
SuspendDownloads(); |
|
122 | 134 |
|
135 |
// partial downloads should be removed |
|
136 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(), iShowDownloading->FileName()); |
|
137 |
||
2 | 138 |
resumeAfterRemove = ETrue; |
139 |
} |
|
140 |
||
141 |
CShowInfo *info = DBGetShowByUidL(aUid); |
|
142 |
if (info != NULL) |
|
143 |
{ |
|
144 |
info->SetDownloadState(ENotDownloaded); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
145 |
DBUpdateShowL(*info); |
2 | 146 |
delete info; |
147 |
} |
|
111 | 148 |
|
149 |
DBRemoveDownloadL(aUid); |
|
2 | 150 |
|
116 | 151 |
if (resumeAfterRemove) |
152 |
{ |
|
2 | 153 |
ResumeDownloadsL(); |
116 | 154 |
} |
155 |
else |
|
156 |
{ |
|
157 |
NotifyShowDownloadUpdatedL(-1, -1); |
|
158 |
NotifyDownloadQueueUpdatedL(); |
|
159 |
} |
|
2 | 160 |
|
161 |
DownloadNextShowL(); |
|
111 | 162 |
DP("CShowEngine::RemoveDownloadL END"); |
2 | 163 |
} |
164 |
||
165 |
void CShowEngine::Connected(CHttpClient* /*aClient*/) |
|
166 |
{ |
|
167 |
||
168 |
} |
|
169 |
||
170 |
void CShowEngine::Progress(CHttpClient* /*aHttpClient */, TInt aBytes, |
|
171 |
TInt aTotalBytes) |
|
172 |
{ |
|
173 |
iShowDownloading->SetShowSize(aTotalBytes); |
|
174 |
TRAP_IGNORE(NotifyShowDownloadUpdatedL(aBytes, aTotalBytes)); |
|
175 |
} |
|
176 |
||
177 |
void CShowEngine::Disconnected(CHttpClient* /*aClient */) |
|
178 |
{ |
|
179 |
} |
|
180 |
||
181 |
void CShowEngine::DownloadInfo(CHttpClient* aHttpClient, TInt aTotalBytes) |
|
182 |
{ |
|
172
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
165
diff
changeset
|
183 |
DP1("CShowEngine::DownloadInfo, About to download %d bytes", aTotalBytes); |
2 | 184 |
} |
185 |
||
111 | 186 |
void CShowEngine::GetShowL(CShowInfo *info) |
2 | 187 |
{ |
188 |
CFeedInfo *feedInfo = iPodcastModel.FeedEngine().GetFeedInfoByUid( |
|
189 |
info->FeedUid()); |
|
111 | 190 |
|
2 | 191 |
TFileName filePath; |
192 |
filePath.Copy(iPodcastModel.SettingsEngine().BaseDir()); |
|
193 |
||
194 |
TFileName relPath; |
|
195 |
relPath.Copy(feedInfo->Title()); |
|
196 |
relPath.Append('\\'); |
|
197 |
||
198 |
TFileName fileName; |
|
199 |
PodcastUtils::FileNameFromUrl(info->Url(), fileName); |
|
200 |
relPath.Append(fileName); |
|
201 |
PodcastUtils::EnsureProperPathName(relPath); |
|
202 |
||
203 |
// complete file path is base dir + rel path |
|
204 |
filePath.Append(relPath); |
|
205 |
info->SetFileNameL(filePath); |
|
206 |
||
111 | 207 |
User::LeaveIfError(iShowClient->GetL(info->Url(), filePath)); |
2 | 208 |
} |
209 |
||
111 | 210 |
EXPORT_C void CShowEngine::AddShowL(const CShowInfo& aItem) |
2 | 211 |
{ |
212 |
DP1("CShowEngine::AddShowL, title=%S", &aItem.Title()); |
|
213 |
CShowInfo *showInfo = DBGetShowByUidL(aItem.Uid()); |
|
214 |
||
215 |
if (showInfo == NULL) |
|
216 |
{ |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
217 |
DBAddShowL(aItem); |
2 | 218 |
} |
219 |
else |
|
220 |
{ |
|
221 |
delete showInfo; |
|
111 | 222 |
User::Leave(KErrAlreadyExists); |
2 | 223 |
} |
224 |
} |
|
225 |
||
226 |
EXPORT_C void CShowEngine::AddObserver(MShowEngineObserver *observer) |
|
227 |
{ |
|
228 |
iObservers.Append(observer); |
|
229 |
} |
|
230 |
||
231 |
EXPORT_C void CShowEngine::RemoveObserver(MShowEngineObserver *observer) |
|
232 |
{ |
|
233 |
TInt index = iObservers.Find(observer); |
|
234 |
||
235 |
if (index > KErrNotFound) |
|
236 |
{ |
|
237 |
iObservers.Remove(index); |
|
238 |
} |
|
239 |
} |
|
240 |
||
126 | 241 |
void CShowEngine::AddShowToMpxCollection(CShowInfo &aShowInfo) |
2 | 242 |
{ |
200
79076725bab9
Added #define to enable/disable MPX integration, since it requires capabilities that can't be granted when self signed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
243 |
#ifdef ENABLE_MPX_INTEGRATION |
126 | 244 |
if (!iCollectionHelper) |
245 |
iCollectionHelper = CMPXCollectionHelperFactory::NewCollectionHelperL(); |
|
2 | 246 |
|
126 | 247 |
// if this leaves, not much we can do anyway |
248 |
TRAP_IGNORE(iCollectionHelper->AddL(aShowInfo.FileName(), this)); |
|
200
79076725bab9
Added #define to enable/disable MPX integration, since it requires capabilities that can't be granted when self signed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
249 |
#endif |
2 | 250 |
} |
251 |
||
252 |
void CShowEngine::CompleteL(CHttpClient* /*aHttpClient*/, TInt aError) |
|
253 |
{ |
|
254 |
if (iShowDownloading != NULL) |
|
255 |
{ |
|
115
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
112
diff
changeset
|
256 |
DP2("CShowEngine::CompleteL file=%S, aError=%d", &iShowDownloading->FileName(), aError); |
2 | 257 |
if(aError != KErrCouldNotConnect) |
258 |
{ |
|
6 | 259 |
if(aError == KErrDisconnected && iPodcastModel.SettingsEngine().DownloadSuspended()) |
260 |
{ |
|
2 | 261 |
// no error if disconnect happened because of suspended downloading |
6 | 262 |
} |
263 |
else |
|
264 |
{ |
|
2 | 265 |
iShowDownloading->SetLastError(aError); |
6 | 266 |
} |
2 | 267 |
|
268 |
if (aError == KErrNone) |
|
269 |
{ |
|
270 |
TBuf<KMimeBufLength> mimeType; |
|
271 |
GetMimeType(iShowDownloading->FileName(), mimeType); |
|
272 |
_LIT(KMimeAudio,"audio"); |
|
273 |
_LIT(KMimeVideo,"video"); |
|
274 |
if (mimeType.Left(5) == KMimeAudio) |
|
275 |
{ |
|
276 |
iShowDownloading->SetShowType(EAudioPodcast); |
|
277 |
} |
|
278 |
else if (mimeType.Left(5) == KMimeVideo) |
|
279 |
{ |
|
280 |
iShowDownloading->SetShowType(EVideoPodcast); |
|
281 |
} |
|
282 |
||
283 |
iShowDownloading->SetDownloadState(EDownloaded); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
284 |
DBUpdateShowL(*iShowDownloading); |
111 | 285 |
DBRemoveDownloadL(iShowDownloading->Uid()); |
2 | 286 |
AddShowToMpxCollection(*iShowDownloading); |
287 |
NotifyShowFinishedL(aError); |
|
15
93d9f66bf50b
Cleaning description better for second line in search results
teknolog
parents:
6
diff
changeset
|
288 |
iDownloadErrors = 0; |
2 | 289 |
delete iShowDownloading; |
290 |
iShowDownloading = NULL; |
|
291 |
} |
|
292 |
else |
|
293 |
{ |
|
294 |
// 400 and 500 series errors are serious errors on which probably another download will fail |
|
295 |
if(aError >= HTTPStatus::EBadRequest && aError <= HTTPStatus::EBadRequest+200) |
|
296 |
{ |
|
297 |
iShowDownloading->SetDownloadState(EFailedDownload); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
298 |
DBUpdateShowL(*iShowDownloading); |
111 | 299 |
DBRemoveDownloadL(iShowDownloading->Uid()); |
2 | 300 |
NotifyShowFinishedL(aError); |
301 |
||
302 |
delete iShowDownloading; |
|
303 |
iShowDownloading = NULL; |
|
304 |
} |
|
115
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
112
diff
changeset
|
305 |
else if (aError == KErrDiskFull) |
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
112
diff
changeset
|
306 |
{ |
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
112
diff
changeset
|
307 |
// stop downloading immediately if disk is full |
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
112
diff
changeset
|
308 |
iShowDownloading->SetDownloadState(EQueued); |
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
112
diff
changeset
|
309 |
DBUpdateShowL(*iShowDownloading); |
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
112
diff
changeset
|
310 |
iDownloadErrors = KMaxDownloadErrors; |
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
112
diff
changeset
|
311 |
} |
2 | 312 |
else // other kind of error, missing network etc, reque this show |
313 |
{ |
|
314 |
iShowDownloading->SetDownloadState(EQueued); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
315 |
DBUpdateShowL(*iShowDownloading); |
2 | 316 |
} |
317 |
||
115
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
112
diff
changeset
|
318 |
NotifyDownloadQueueUpdatedL(); |
2 | 319 |
iDownloadErrors++; |
117
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
116
diff
changeset
|
320 |
if (iDownloadErrors >= KMaxDownloadErrors) |
2 | 321 |
{ |
322 |
DP("Too many downloading errors, suspending downloads"); |
|
323 |
iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue); |
|
324 |
NotifyShowFinishedL(aError); |
|
325 |
} |
|
326 |
} |
|
327 |
DownloadNextShowL(); |
|
328 |
} |
|
329 |
||
330 |
else |
|
331 |
{ |
|
332 |
// Connection error |
|
333 |
if(iShowDownloading) |
|
334 |
{ |
|
335 |
iShowDownloading->SetDownloadState(EQueued); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
336 |
DBUpdateShowL(*iShowDownloading); |
2 | 337 |
} |
338 |
iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue); |
|
339 |
NotifyShowFinishedL(aError); |
|
340 |
} |
|
341 |
} |
|
342 |
} |
|
343 |
||
344 |
EXPORT_C CShowInfo* CShowEngine::ShowDownloading() |
|
345 |
{ |
|
346 |
return iShowDownloading; |
|
347 |
} |
|
348 |
||
349 |
EXPORT_C CShowInfo* CShowEngine::GetShowByUidL(TUint aShowUid) |
|
350 |
{ |
|
351 |
return DBGetShowByUidL(aShowUid); |
|
352 |
} |
|
353 |
CShowInfo* CShowEngine::DBGetShowByUidL(TUint aUid) |
|
354 |
{ |
|
355 |
DP("CShowEngine::DBGetShowByUid"); |
|
356 |
CShowInfo *showInfo = NULL; |
|
357 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows where uid=%u"); |
|
358 |
iSqlBuffer.Format(KSqlStatement, aUid); |
|
359 |
||
360 |
sqlite3_stmt *st; |
|
361 |
||
362 |
//DP1("SQL: %S", &iSqlBuffer.Left(KSqlDPLen)); |
|
363 |
||
364 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
365 |
&st, (const void**) NULL); |
|
366 |
||
367 |
if (rc == SQLITE_OK) |
|
368 |
{ |
|
369 |
rc = sqlite3_step(st); |
|
370 |
Cleanup_sqlite3_finalize_PushL(st); |
|
371 |
if (rc == SQLITE_ROW) |
|
372 |
{ |
|
373 |
showInfo = CShowInfo::NewLC(); |
|
374 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
375 |
CleanupStack::Pop(showInfo); |
|
376 |
} |
|
377 |
CleanupStack::PopAndDestroy();//st |
|
378 |
} |
|
379 |
||
380 |
return showInfo; |
|
381 |
} |
|
382 |
||
383 |
EXPORT_C CShowInfo* CShowEngine::DBGetShowByFileNameL(TFileName aFileName) |
|
384 |
{ |
|
385 |
DP("CShowEngine::DBGetShowByUid"); |
|
386 |
CShowInfo *showInfo = NULL; |
|
387 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows where filename=\"%S\""); |
|
388 |
iSqlBuffer.Format(KSqlStatement, &aFileName); |
|
389 |
||
390 |
sqlite3_stmt *st; |
|
391 |
||
392 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
393 |
&st, (const void**) NULL); |
|
394 |
||
395 |
if (rc == SQLITE_OK) |
|
396 |
{ |
|
397 |
rc = sqlite3_step(st); |
|
398 |
Cleanup_sqlite3_finalize_PushL(st); |
|
399 |
if (rc == SQLITE_ROW) |
|
400 |
{ |
|
401 |
showInfo = CShowInfo::NewLC(); |
|
402 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
403 |
CleanupStack::Pop(showInfo); |
|
404 |
} |
|
405 |
CleanupStack::PopAndDestroy();//st |
|
406 |
} |
|
407 |
||
408 |
return showInfo; |
|
409 |
} |
|
410 |
||
411 |
void CShowEngine::DBGetAllShowsL(RShowInfoArray& aShowArray) |
|
412 |
{ |
|
413 |
DP("CShowEngine::DBGetAllShows"); |
|
414 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows"); |
|
415 |
iSqlBuffer.Format(KSqlStatement); |
|
416 |
||
417 |
sqlite3_stmt *st; |
|
418 |
||
419 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
420 |
&st, (const void**) NULL); |
|
421 |
||
422 |
if (rc == SQLITE_OK) |
|
423 |
{ |
|
424 |
rc = sqlite3_step(st); |
|
425 |
Cleanup_sqlite3_finalize_PushL(st); |
|
426 |
while (rc == SQLITE_ROW) |
|
427 |
{ |
|
428 |
CShowInfo* showInfo = CShowInfo::NewLC(); |
|
429 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
430 |
aShowArray.Append(showInfo); |
|
431 |
CleanupStack::Pop(showInfo); |
|
432 |
rc = sqlite3_step(st); |
|
433 |
} |
|
434 |
CleanupStack::PopAndDestroy();//st |
|
435 |
} |
|
436 |
||
437 |
} |
|
438 |
||
439 |
void CShowEngine::DBGetAllDownloadsL(RShowInfoArray& aShowArray) |
|
440 |
{ |
|
441 |
DP("CShowEngine::DBGetAllDownloads"); |
|
442 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, shows.uid, showsize, trackno, pubdate, showtype, lasterror from downloads, shows where downloads.uid=shows.uid"); |
|
443 |
iSqlBuffer.Format(KSqlStatement); |
|
444 |
||
445 |
#ifndef DONT_SORT_SQL |
|
446 |
_LIT(KSqlSort, " order by dl_index"); |
|
447 |
iSqlBuffer.Append(KSqlSort); |
|
448 |
#endif |
|
449 |
sqlite3_stmt *st; |
|
450 |
||
451 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
452 |
&st, (const void**) NULL); |
|
453 |
||
454 |
if (rc == SQLITE_OK) |
|
455 |
{ |
|
456 |
rc = sqlite3_step(st); |
|
457 |
Cleanup_sqlite3_finalize_PushL(st); |
|
458 |
while (rc == SQLITE_ROW) |
|
459 |
{ |
|
460 |
CShowInfo* showInfo = CShowInfo::NewLC(); |
|
461 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
462 |
aShowArray.Append(showInfo); |
|
463 |
CleanupStack::Pop(showInfo); |
|
464 |
rc = sqlite3_step(st); |
|
465 |
} |
|
466 |
CleanupStack::PopAndDestroy();//st |
|
467 |
} |
|
111 | 468 |
else |
469 |
{ |
|
470 |
User::Leave(KErrCorrupt); |
|
471 |
} |
|
2 | 472 |
|
473 |
// delete downloads that don't have a show |
|
474 |
||
475 |
_LIT(KSqlStatement2, "delete from downloads where uid not in (select downloads.uid from shows, downloads where shows.uid=downloads.uid)"); |
|
476 |
iSqlBuffer.Format(KSqlStatement2); |
|
477 |
||
478 |
rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, &st, (const void**) NULL); |
|
479 |
||
480 |
if (rc == SQLITE_OK) |
|
481 |
{ |
|
111 | 482 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 483 |
rc = sqlite3_step(st); |
111 | 484 |
CleanupStack::PopAndDestroy(); // st |
485 |
} |
|
486 |
else |
|
487 |
{ |
|
488 |
User::Leave(KErrCorrupt); |
|
2 | 489 |
} |
490 |
} |
|
491 |
||
492 |
CShowInfo* CShowEngine::DBGetNextDownloadL() |
|
493 |
{ |
|
494 |
DP("CShowEngine::DBGetNextDownload"); |
|
495 |
CShowInfo *showInfo = NULL; |
|
496 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, shows.uid, showsize, trackno, pubdate, showtype, lasterror from downloads, shows where downloads.uid=shows.uid"); |
|
497 |
iSqlBuffer.Format(KSqlStatement); |
|
498 |
||
499 |
#ifdef DONT_SORT_SQL |
|
500 |
_LIT(KSqlSort, " limit 1"); |
|
501 |
iSqlBuffer.Append(KSqlSort); |
|
502 |
#else |
|
503 |
_LIT(KSqlNoSort, " order by dl_index limit 1"); |
|
504 |
iSqlBuffer.Append(KSqlNoSort); |
|
505 |
#endif |
|
506 |
||
507 |
sqlite3_stmt *st; |
|
508 |
||
509 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
510 |
&st, (const void**) NULL); |
|
511 |
||
512 |
if (rc == SQLITE_OK) |
|
513 |
{ |
|
514 |
rc = sqlite3_step(st); |
|
515 |
Cleanup_sqlite3_finalize_PushL(st); |
|
516 |
if (rc == SQLITE_ROW) |
|
517 |
{ |
|
518 |
showInfo = CShowInfo::NewLC(); |
|
519 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
520 |
CleanupStack::Pop(showInfo); |
|
521 |
} |
|
111 | 522 |
else |
523 |
{ |
|
524 |
User::Leave(KErrUnknown); |
|
525 |
} |
|
2 | 526 |
CleanupStack::PopAndDestroy();//st |
527 |
} |
|
111 | 528 |
else |
529 |
{ |
|
530 |
User::Leave(KErrCorrupt); |
|
531 |
} |
|
2 | 532 |
|
533 |
return showInfo; |
|
534 |
} |
|
535 |
||
536 |
void CShowEngine::DBGetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid) |
|
537 |
{ |
|
538 |
DP1("CShowEngine::DBGetShowsByFeed BEGIN, feedUid=%u", aFeedUid); |
|
539 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where feeduid=%u"); |
|
540 |
iSqlBuffer.Format(KSqlStatement, aFeedUid); |
|
541 |
||
542 |
#ifndef DONT_SORT_SQL |
|
543 |
_LIT(KSqlOrderByDate, " order by pubdate desc"); |
|
544 |
iSqlBuffer.Append(KSqlOrderByDate); |
|
545 |
#endif |
|
546 |
||
547 |
sqlite3_stmt *st; |
|
548 |
||
549 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
550 |
&st, (const void**) NULL); |
|
551 |
||
552 |
if (rc == SQLITE_OK) |
|
553 |
{ |
|
554 |
rc = sqlite3_step(st); |
|
555 |
Cleanup_sqlite3_finalize_PushL(st); |
|
556 |
while (rc == SQLITE_ROW) |
|
557 |
{ |
|
558 |
CShowInfo* showInfo = CShowInfo::NewLC(); |
|
559 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
560 |
aShowArray.Append(showInfo); |
|
561 |
CleanupStack::Pop(showInfo); |
|
562 |
rc = sqlite3_step(st); |
|
563 |
} |
|
564 |
CleanupStack::PopAndDestroy();//st |
|
565 |
} |
|
111 | 566 |
else |
567 |
{ |
|
568 |
User::Leave(KErrCorrupt); |
|
569 |
} |
|
2 | 570 |
DP("CShowEngine::DBGetShowsByFeed END"); |
571 |
} |
|
572 |
||
111 | 573 |
TUint CShowEngine::DBGetDownloadsCountL() |
2 | 574 |
{ |
575 |
DP("CShowEngine::DBGetDownloadsCount"); |
|
576 |
||
577 |
_LIT(KSqlStatement, "select count(*) from downloads"); |
|
578 |
iSqlBuffer.Format(KSqlStatement); |
|
579 |
||
580 |
sqlite3_stmt *st; |
|
581 |
TUint count = 0; |
|
582 |
||
583 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
584 |
&st, (const void**) NULL); |
|
585 |
||
586 |
if (rc == SQLITE_OK) |
|
587 |
{ |
|
111 | 588 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 589 |
rc = sqlite3_step(st); |
590 |
||
591 |
if (rc == SQLITE_ROW) |
|
592 |
{ |
|
593 |
count = sqlite3_column_int(st, 0); |
|
594 |
} |
|
111 | 595 |
else |
596 |
{ |
|
597 |
User::Leave(KErrUnknown); |
|
598 |
} |
|
599 |
||
600 |
CleanupStack::PopAndDestroy(); //st |
|
601 |
} |
|
602 |
else |
|
603 |
{ |
|
604 |
User::Leave(KErrCorrupt); |
|
2 | 605 |
} |
606 |
return count; |
|
607 |
} |
|
608 |
||
609 |
void CShowEngine::DBGetDownloadedShowsL(RShowInfoArray& aShowArray) |
|
610 |
{ |
|
611 |
DP("CShowEngine::DBGetDownloadedShows"); |
|
612 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where downloadstate=%u"); |
|
613 |
iSqlBuffer.Format(KSqlStatement, EDownloaded); |
|
614 |
||
615 |
#ifndef DONT_SORT_SQL |
|
616 |
_LIT(KSqlSort, " order by title"); |
|
617 |
iSqlBuffer.Append(KSqlSort); |
|
618 |
#endif |
|
619 |
||
620 |
sqlite3_stmt *st; |
|
621 |
||
622 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
623 |
&st, (const void**) NULL); |
|
624 |
||
625 |
if (rc == SQLITE_OK) |
|
626 |
{ |
|
627 |
rc = sqlite3_step(st); |
|
628 |
Cleanup_sqlite3_finalize_PushL(st); |
|
629 |
while (rc == SQLITE_ROW) |
|
630 |
{ |
|
631 |
CShowInfo* showInfo = CShowInfo::NewLC(); |
|
632 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
633 |
aShowArray.Append(showInfo); |
|
634 |
CleanupStack::Pop(showInfo); |
|
635 |
rc = sqlite3_step(st); |
|
636 |
} |
|
637 |
CleanupStack::PopAndDestroy();//st |
|
638 |
} |
|
111 | 639 |
else |
640 |
{ |
|
641 |
User::Leave(KErrCorrupt); |
|
642 |
} |
|
2 | 643 |
} |
644 |
||
645 |
void CShowEngine::DBGetNewShowsL(RShowInfoArray& aShowArray) |
|
646 |
{ |
|
647 |
DP("CShowEngine::DBGetNewShows"); |
|
648 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where playstate=%u"); |
|
649 |
iSqlBuffer.Format(KSqlStatement, ENeverPlayed); |
|
650 |
||
651 |
sqlite3_stmt *st; |
|
652 |
||
653 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
654 |
&st, (const void**) NULL); |
|
655 |
||
656 |
if (rc == SQLITE_OK) |
|
657 |
{ |
|
658 |
rc = sqlite3_step(st); |
|
659 |
Cleanup_sqlite3_finalize_PushL(st); |
|
660 |
while (rc == SQLITE_ROW) |
|
661 |
{ |
|
662 |
CShowInfo* showInfo = CShowInfo::NewLC(); |
|
663 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
664 |
aShowArray.Append(showInfo); |
|
665 |
CleanupStack::Pop(showInfo); |
|
666 |
rc = sqlite3_step(st); |
|
667 |
} |
|
668 |
CleanupStack::PopAndDestroy();//st |
|
669 |
} |
|
111 | 670 |
else |
671 |
{ |
|
672 |
User::Leave(KErrCorrupt); |
|
673 |
} |
|
2 | 674 |
} |
675 |
||
111 | 676 |
void CShowEngine::DBDeleteOldShowsByFeedL(TUint aFeedUid) |
2 | 677 |
{ |
678 |
DP("CShowEngine::DBDeleteOldShows"); |
|
679 |
||
680 |
// what we do: |
|
681 |
// 1. sort shows by pubdate |
|
682 |
// 2. select the first MaxListItems shows |
|
683 |
// 3. delete the rest if downloadstate is ENotDownloaded |
|
684 |
||
126 | 685 |
_LIT(KSqlStatement,"delete from shows where feeduid=%u and downloadstate=0 and uid not in (select uid from shows where feeduid=%u order by pubdate desc limit %u)"); |
2 | 686 |
iSqlBuffer.Format(KSqlStatement, aFeedUid, aFeedUid, iPodcastModel.SettingsEngine().MaxListItems()); |
687 |
||
688 |
sqlite3_stmt *st; |
|
689 |
||
690 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
691 |
&st, (const void**) NULL); |
|
692 |
||
693 |
if (rc == SQLITE_OK) |
|
694 |
{ |
|
695 |
rc = sqlite3_step(st); |
|
696 |
sqlite3_finalize(st); |
|
697 |
} |
|
111 | 698 |
else |
699 |
{ |
|
700 |
User::Leave(KErrCorrupt); |
|
701 |
} |
|
2 | 702 |
|
703 |
_LIT(KSqlStatement2, "delete from downloads where uid not in (select downloads.uid from shows, downloads where shows.uid=downloads.uid)"); |
|
704 |
iSqlBuffer.Format(KSqlStatement2); |
|
705 |
||
706 |
rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, &st, (const void**) NULL); |
|
707 |
||
708 |
if (rc == SQLITE_OK) |
|
709 |
{ |
|
710 |
rc = sqlite3_step(st); |
|
711 |
sqlite3_finalize(st); |
|
712 |
} |
|
111 | 713 |
else |
714 |
{ |
|
715 |
User::Leave(KErrCorrupt); |
|
716 |
} |
|
2 | 717 |
} |
718 |
||
719 |
void CShowEngine::DBFillShowInfoFromStmtL(sqlite3_stmt *st, CShowInfo* showInfo) |
|
720 |
{ |
|
721 |
const void *urlz = sqlite3_column_text16(st, 0); |
|
722 |
TPtrC16 url((const TUint16*) urlz); |
|
723 |
showInfo->SetUrlL(url); |
|
724 |
||
725 |
const void *titlez = sqlite3_column_text16(st, 1); |
|
726 |
TPtrC16 title((const TUint16*) titlez); |
|
727 |
showInfo->SetTitleL(title); |
|
728 |
||
729 |
const void *descz = sqlite3_column_text16(st, 2); |
|
730 |
TPtrC16 desc((const TUint16*) descz); |
|
731 |
showInfo->SetDescriptionL(desc); |
|
732 |
||
733 |
const void *filez = sqlite3_column_text16(st, 3); |
|
734 |
TPtrC16 file((const TUint16*) filez); |
|
735 |
showInfo->SetFileNameL(file); |
|
736 |
||
737 |
sqlite3_int64 pos = sqlite3_column_int64(st, 4); |
|
738 |
TTimeIntervalMicroSeconds position(pos); |
|
739 |
showInfo->SetPosition(position); |
|
740 |
||
741 |
TUint playtime = sqlite3_column_int(st, 5); |
|
742 |
showInfo->SetPlayTime(playtime); |
|
743 |
||
744 |
TUint playstate = sqlite3_column_int(st, 6); |
|
745 |
showInfo->SetPlayState((TPlayState) playstate); |
|
746 |
||
747 |
TUint downloadstate = sqlite3_column_int(st, 7); |
|
748 |
showInfo->SetDownloadState((TDownloadState) downloadstate); |
|
749 |
||
750 |
TUint feeduid = sqlite3_column_int(st, 8); |
|
751 |
showInfo->SetFeedUid(feeduid); |
|
752 |
||
753 |
TUint uid = sqlite3_column_int(st, 9); |
|
754 |
showInfo->SetUid(uid); |
|
755 |
||
756 |
TUint showsize = sqlite3_column_int(st, 10); |
|
757 |
showInfo->SetShowSize(showsize); |
|
758 |
||
759 |
TUint trackno = sqlite3_column_int(st, 11); |
|
760 |
showInfo->SetTrackNo((TShowType) trackno); |
|
761 |
||
762 |
sqlite3_int64 pubdate = sqlite3_column_int64(st, 12); |
|
763 |
TTime timepubdate(pubdate); |
|
764 |
showInfo->SetPubDate(timepubdate); |
|
765 |
||
766 |
TUint showtype = sqlite3_column_int(st, 13); |
|
767 |
showInfo->SetShowType((TShowType) showtype); |
|
768 |
||
769 |
TInt lasterror = sqlite3_column_int(st, 14); |
|
770 |
showInfo->SetLastError(lasterror); |
|
771 |
} |
|
772 |
||
111 | 773 |
void CShowEngine::DBAddShowL(const CShowInfo& aItem) |
2 | 774 |
{ |
775 |
DP2("CShowEngine::DBAddShow, title=%S, URL=%S", &aItem.Title(), &aItem.Url()); |
|
776 |
||
21 | 777 |
HBufC* titleBuf = HBufC::NewLC(KMaxLineLength); |
778 |
TPtr titlePtr(titleBuf->Des()); |
|
779 |
titlePtr.Copy(aItem.Title()); |
|
780 |
PodcastUtils::SQLEncode(titlePtr); |
|
781 |
||
782 |
HBufC* descBuf = HBufC::NewLC(KMaxLineLength); |
|
783 |
TPtr descPtr(descBuf->Des()); |
|
784 |
descPtr.Copy(aItem.Description()); |
|
785 |
PodcastUtils::SQLEncode(descPtr); |
|
786 |
||
126 | 787 |
_LIT(KSqlStatement, "insert into shows (url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype) values (\"%S\",\"%S\", \"%S\", \"%S\", \"%Lu\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%Lu\", \"%d\")"); |
21 | 788 |
|
789 |
iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr, |
|
2 | 790 |
&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(), |
791 |
aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(), |
|
792 |
aItem.Uid(), aItem.ShowSize(), aItem.TrackNo(), |
|
793 |
aItem.PubDate().Int64(), aItem.ShowType()); |
|
794 |
||
21 | 795 |
CleanupStack::PopAndDestroy(descBuf); |
796 |
CleanupStack::PopAndDestroy(titleBuf); |
|
797 |
||
2 | 798 |
sqlite3_stmt *st; |
799 |
||
800 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
801 |
&st, (const void**) NULL); |
|
111 | 802 |
|
2 | 803 |
if (rc == SQLITE_OK) |
804 |
{ |
|
111 | 805 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 806 |
rc = sqlite3_step(st); |
111 | 807 |
if (rc != SQLITE_DONE) |
2 | 808 |
{ |
111 | 809 |
User::Leave(KErrAlreadyExists); |
2 | 810 |
} |
111 | 811 |
CleanupStack::PopAndDestroy(); // st |
2 | 812 |
} |
813 |
else |
|
814 |
{ |
|
111 | 815 |
User::Leave(KErrCorrupt); |
2 | 816 |
} |
817 |
} |
|
818 |
||
111 | 819 |
void CShowEngine::DBAddDownloadL(TUint aUid) |
2 | 820 |
{ |
821 |
DP1("CShowEngine::DBAddDownload, aUid=%u", aUid); |
|
822 |
||
823 |
_LIT(KSqlStatement, "insert into downloads (uid) values (%u)"); |
|
824 |
iSqlBuffer.Format(KSqlStatement, aUid); |
|
825 |
sqlite3_stmt *st; |
|
826 |
||
827 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
828 |
&st, (const void**) NULL); |
|
829 |
||
830 |
if (rc == SQLITE_OK) |
|
831 |
{ |
|
111 | 832 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 833 |
rc = sqlite3_step(st); |
116 | 834 |
if (rc != SQLITE_DONE) |
111 | 835 |
{ |
836 |
User::Leave(KErrUnknown); |
|
837 |
} |
|
838 |
CleanupStack::PopAndDestroy(); // st |
|
2 | 839 |
} |
111 | 840 |
else |
841 |
{ |
|
842 |
User::Leave(KErrCorrupt); |
|
843 |
} |
|
2 | 844 |
} |
845 |
||
111 | 846 |
void CShowEngine::DBUpdateShowL(CShowInfo& aItem) |
2 | 847 |
{ |
848 |
DP1("CShowEngine::DBUpdateShow, title='%S'", &aItem.Title()); |
|
849 |
||
30
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
850 |
HBufC* titleBuf = HBufC::NewLC(KMaxLineLength); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
851 |
TPtr titlePtr(titleBuf->Des()); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
852 |
titlePtr.Copy(aItem.Title()); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
853 |
PodcastUtils::SQLEncode(titlePtr); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
854 |
|
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
855 |
HBufC* descBuf = HBufC::NewLC(KMaxLineLength); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
856 |
TPtr descPtr(descBuf->Des()); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
857 |
descPtr.Copy(aItem.Description()); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
858 |
PodcastUtils::SQLEncode(descPtr); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
859 |
|
134
46baf9a7cadd
Fix for KErrCorrupted bug in ShowEngine; Capabilities added to allow interaction with music player and MPXCollection
teknolog
parents:
126
diff
changeset
|
860 |
_LIT(KSqlStatement, "update shows set url=\"%S\", title=\"%S\", description=\"%S\", filename=\"%S\", position=\"%Lu\", playtime=\"%u\", playstate=\"%u\", downloadstate=\"%u\", feeduid=\"%u\", showsize=\"%u\", trackno=\"%u\",pubdate=\"%Lu\", showtype=\"%d\", lasterror=\"%d\" where uid=\"%u\""); |
30
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
861 |
iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr, |
2 | 862 |
&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(), |
863 |
aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(), |
|
864 |
aItem.ShowSize(), aItem.TrackNo(), aItem.PubDate().Int64(), |
|
865 |
aItem.ShowType(), aItem.LastError(), aItem.Uid()); |
|
866 |
||
30
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
867 |
CleanupStack::PopAndDestroy(descBuf); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
868 |
CleanupStack::PopAndDestroy(titleBuf); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
869 |
|
2 | 870 |
sqlite3_stmt *st; |
871 |
||
872 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
873 |
&st, (const void**) NULL); |
|
874 |
||
875 |
if (rc == SQLITE_OK) |
|
876 |
{ |
|
111 | 877 |
Cleanup_sqlite3_finalize_PushL(st); |
878 |
rc = sqlite3_step(st); |
|
2 | 879 |
|
116 | 880 |
if (rc != SQLITE_DONE) |
2 | 881 |
{ |
111 | 882 |
User::Leave(KErrUnknown); |
2 | 883 |
} |
111 | 884 |
CleanupStack::PopAndDestroy(); // st |
2 | 885 |
} |
886 |
else |
|
887 |
{ |
|
111 | 888 |
User::Leave(KErrCorrupt); |
2 | 889 |
} |
890 |
} |
|
891 |
||
111 | 892 |
void CShowEngine::DBDeleteShowL(TUint aUid) |
2 | 893 |
{ |
894 |
DP("CShowEngine::DBDeleteShow"); |
|
895 |
||
896 |
_LIT(KSqlStatement, "delete from shows where uid=%u"); |
|
897 |
iSqlBuffer.Format(KSqlStatement, aUid); |
|
898 |
||
899 |
sqlite3_stmt *st; |
|
900 |
||
901 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
902 |
&st, (const void**) NULL); |
|
903 |
||
904 |
if (rc == SQLITE_OK) |
|
905 |
{ |
|
111 | 906 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 907 |
rc = sqlite3_step(st); |
908 |
||
116 | 909 |
if (rc != SQLITE_DONE) |
2 | 910 |
{ |
111 | 911 |
User::Leave(KErrUnknown); |
2 | 912 |
} |
111 | 913 |
CleanupStack::PopAndDestroy(); // st |
2 | 914 |
} |
915 |
else |
|
916 |
{ |
|
111 | 917 |
User::Leave(KErrCorrupt); |
2 | 918 |
} |
919 |
} |
|
920 |
||
111 | 921 |
void CShowEngine::DBDeleteAllShowsByFeedL(TUint aFeedUid) |
2 | 922 |
{ |
923 |
DP("CShowEngine::DBDeleteAllShowsByFeed"); |
|
924 |
||
925 |
_LIT(KSqlStatement, "delete from shows where feeduid=%u"); |
|
926 |
iSqlBuffer.Format(KSqlStatement, aFeedUid); |
|
927 |
||
928 |
sqlite3_stmt *st; |
|
929 |
||
930 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
931 |
&st, (const void**) NULL); |
|
932 |
||
933 |
if (rc == SQLITE_OK) |
|
934 |
{ |
|
111 | 935 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 936 |
rc = sqlite3_step(st); |
937 |
||
116 | 938 |
if (rc != SQLITE_DONE) |
2 | 939 |
{ |
111 | 940 |
User::Leave(KErrUnknown); |
2 | 941 |
} |
111 | 942 |
CleanupStack::PopAndDestroy(); // st |
2 | 943 |
} |
944 |
else |
|
945 |
{ |
|
111 | 946 |
User::Leave(KErrCorrupt); |
2 | 947 |
} |
948 |
} |
|
949 |
||
111 | 950 |
void CShowEngine::DBRemoveAllDownloadsL() |
2 | 951 |
{ |
952 |
DP("CShowEngine::DBRemoveAllDownloads"); |
|
953 |
||
954 |
_LIT(KSqlStatement, "delete from downloads"); |
|
955 |
iSqlBuffer.Format(KSqlStatement); |
|
956 |
||
957 |
sqlite3_stmt *st; |
|
958 |
||
959 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
960 |
&st, (const void**) NULL); |
|
961 |
||
962 |
if (rc == SQLITE_OK) |
|
963 |
{ |
|
964 |
rc = sqlite3_step(st); |
|
965 |
sqlite3_finalize(st); |
|
966 |
} |
|
111 | 967 |
else |
968 |
{ |
|
969 |
User::Leave(KErrCorrupt); |
|
970 |
} |
|
2 | 971 |
|
972 |
_LIT(KSqlStatement2, "update shows set downloadstate=0 where downloadstate=1"); |
|
973 |
iSqlBuffer.Format(KSqlStatement2); |
|
974 |
||
975 |
rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, &st, |
|
976 |
(const void**) NULL); |
|
977 |
||
978 |
if (rc == SQLITE_OK) |
|
979 |
{ |
|
111 | 980 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 981 |
rc = sqlite3_step(st); |
116 | 982 |
if (rc != SQLITE_DONE) |
111 | 983 |
{ |
984 |
User::Leave(KErrUnknown); |
|
985 |
} |
|
986 |
CleanupStack::PopAndDestroy(); // st |
|
987 |
} |
|
988 |
else |
|
989 |
{ |
|
990 |
User::Leave(KErrCorrupt); |
|
2 | 991 |
} |
992 |
||
993 |
} |
|
994 |
||
111 | 995 |
void CShowEngine::DBRemoveDownloadL(TUint aUid) |
2 | 996 |
{ |
997 |
DP("CShowEngine::DBRemoveDownload"); |
|
998 |
||
999 |
_LIT(KSqlStatement, "delete from downloads where uid=%u"); |
|
1000 |
iSqlBuffer.Format(KSqlStatement, aUid); |
|
1001 |
||
1002 |
sqlite3_stmt *st; |
|
1003 |
||
1004 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
1005 |
&st, (const void**) NULL); |
|
1006 |
||
1007 |
if (rc == SQLITE_OK) |
|
1008 |
{ |
|
111 | 1009 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 1010 |
rc = sqlite3_step(st); |
116 | 1011 |
if (rc != SQLITE_DONE) |
111 | 1012 |
{ |
1013 |
User::Leave(KErrUnknown); |
|
1014 |
} |
|
1015 |
CleanupStack::PopAndDestroy(); // st |
|
1016 |
} |
|
1017 |
else |
|
1018 |
{ |
|
1019 |
User::Leave(KErrCorrupt); |
|
2 | 1020 |
} |
1021 |
} |
|
1022 |
||
151 | 1023 |
void CShowEngine::DBSwapDownloadsL(TDownload aFirstDL, TDownload aSecondDL) |
1024 |
{ |
|
1025 |
DP("CShowEngine::DBSwapDownloadsL"); |
|
1026 |
_LIT(KSqlStatement, "update downloads set uid=%u where dl_index=%d"); |
|
1027 |
||
1028 |
iSqlBuffer.Format(KSqlStatement, aFirstDL.iUid, aSecondDL.iIndex); |
|
1029 |
sqlite3_stmt *st; |
|
1030 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
1031 |
&st, (const void**) NULL); |
|
1032 |
||
1033 |
if (rc == SQLITE_OK) |
|
1034 |
{ |
|
1035 |
Cleanup_sqlite3_finalize_PushL(st); |
|
1036 |
rc = sqlite3_step(st); |
|
1037 |
if (rc != SQLITE_DONE) |
|
1038 |
{ |
|
1039 |
User::Leave(KErrUnknown); |
|
1040 |
} |
|
1041 |
CleanupStack::PopAndDestroy(); // st |
|
1042 |
} |
|
1043 |
else |
|
1044 |
{ |
|
1045 |
User::Leave(KErrCorrupt); |
|
1046 |
} |
|
1047 |
||
1048 |
iSqlBuffer.Format(KSqlStatement, aSecondDL.iUid, aFirstDL.iIndex); |
|
1049 |
||
1050 |
rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
1051 |
&st, (const void**) NULL); |
|
1052 |
||
1053 |
if (rc == SQLITE_OK) |
|
1054 |
{ |
|
1055 |
Cleanup_sqlite3_finalize_PushL(st); |
|
1056 |
rc = sqlite3_step(st); |
|
1057 |
if (rc != SQLITE_DONE) |
|
1058 |
{ |
|
1059 |
User::Leave(KErrUnknown); |
|
1060 |
} |
|
1061 |
CleanupStack::PopAndDestroy(); // st |
|
1062 |
} |
|
1063 |
else |
|
1064 |
{ |
|
1065 |
User::Leave(KErrCorrupt); |
|
1066 |
} |
|
1067 |
} |
|
1068 |
||
2 | 1069 |
EXPORT_C CShowInfo* CShowEngine::GetNextShowByTrackL(CShowInfo* aShowInfo) |
1070 |
{ |
|
1071 |
CShowInfo* nextShow = NULL; |
|
1072 |
RShowInfoArray array; |
|
1073 |
DBGetShowsByFeedL(array, aShowInfo->FeedUid()); |
|
1074 |
TUint diff = KMaxTInt; |
|
1075 |
for (TInt loop = 0; loop < array.Count(); loop++) |
|
1076 |
{ |
|
1077 |
if (aShowInfo->TrackNo() < array[loop]->TrackNo()) |
|
1078 |
{ |
|
1079 |
if ((array[loop]->TrackNo() - aShowInfo->TrackNo()) < diff) |
|
1080 |
{ |
|
1081 |
diff = array[loop]->TrackNo() - aShowInfo->TrackNo(); |
|
1082 |
nextShow = array[loop]; |
|
1083 |
} |
|
1084 |
} |
|
1085 |
} |
|
1086 |
array.ResetAndDestroy(); |
|
1087 |
return nextShow; |
|
1088 |
} |
|
1089 |
||
1090 |
TBool CShowEngine::CompareShowsByUid(const CShowInfo &a, const CShowInfo &b) |
|
1091 |
{ |
|
1092 |
return a.Uid() == b.Uid(); |
|
1093 |
} |
|
1094 |
||
1095 |
TInt CShowEngine::CompareShowsByDate(const CShowInfo &a, const CShowInfo &b) |
|
1096 |
{ |
|
1097 |
if (a.PubDate() > b.PubDate()) |
|
1098 |
{ |
|
1099 |
// DP2("Sorting %S less than %S", &a.iTitle, &b.iTitle); |
|
1100 |
return -1; |
|
1101 |
} |
|
1102 |
else if (a.PubDate() == b.PubDate()) |
|
1103 |
{ |
|
1104 |
// DP2("Sorting %S equal to %S", &a.iTitle, &b.iTitle); |
|
1105 |
return 0; |
|
1106 |
} |
|
1107 |
else |
|
1108 |
{ |
|
1109 |
// DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle); |
|
1110 |
return 1; |
|
1111 |
} |
|
1112 |
} |
|
1113 |
||
1114 |
TInt CShowEngine::CompareShowsByTrackNo(const CShowInfo &a, const CShowInfo &b) |
|
1115 |
{ |
|
1116 |
if (a.TrackNo() < b.TrackNo()) |
|
1117 |
{ |
|
1118 |
return -1; |
|
1119 |
} |
|
1120 |
else if (a.TrackNo() == b.TrackNo()) |
|
1121 |
{ |
|
1122 |
return 0; |
|
1123 |
} |
|
1124 |
else |
|
1125 |
{ |
|
1126 |
return 1; |
|
1127 |
} |
|
1128 |
} |
|
1129 |
||
1130 |
TInt CShowEngine::CompareShowsByTitle(const CShowInfo &a, const CShowInfo &b) |
|
1131 |
{ |
|
1132 |
if (a.Title() < b.Title()) |
|
1133 |
{ |
|
1134 |
// DP2("Sorting %S less than %S", &a.iTitle, &b.iTitle); |
|
1135 |
return -1; |
|
1136 |
} |
|
1137 |
else if (a.Title() == b.Title()) |
|
1138 |
{ |
|
1139 |
// DP2("Sorting %S equal to %S", &a.iTitle, &b.iTitle); |
|
1140 |
return 0; |
|
1141 |
} |
|
1142 |
else |
|
1143 |
{ |
|
1144 |
// DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle); |
|
1145 |
return 1; |
|
1146 |
} |
|
1147 |
} |
|
1148 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1149 |
EXPORT_C void CShowEngine::DeletePlayedShowsL(RShowInfoArray &aShowInfoArray) |
2 | 1150 |
{ |
1151 |
for (TInt i = 0; i < aShowInfoArray.Count(); i++) |
|
1152 |
{ |
|
1153 |
if (aShowInfoArray[i]->PlayState() == EPlayed |
|
1154 |
&& aShowInfoArray[i]->FileName().Length() > 0) |
|
1155 |
{ |
|
1156 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(), aShowInfoArray[i]->FileName()); |
|
1157 |
aShowInfoArray[i]->SetDownloadState(ENotDownloaded); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1158 |
DBUpdateShowL(*aShowInfoArray[i]); |
2 | 1159 |
} |
1160 |
} |
|
1161 |
} |
|
1162 |
||
1163 |
EXPORT_C void CShowEngine::DeleteAllShowsByFeedL(TUint aFeedUid, TBool aDeleteFiles) |
|
1164 |
{ |
|
1165 |
RShowInfoArray array; |
|
1166 |
DBGetShowsByFeedL(array, aFeedUid); |
|
1167 |
||
1168 |
const TInt count = array.Count(); |
|
1169 |
||
1170 |
for (TInt i = count - 1; i >= 0; i--) |
|
1171 |
{ |
|
53 | 1172 |
if (iShowDownloading && iShowDownloading->Uid() == array[i]->Uid()) |
1173 |
{ |
|
1174 |
// trying to delete the active download |
|
1175 |
RemoveDownloadL(iShowDownloading->Uid()); |
|
1176 |
} |
|
1177 |
||
1178 |
// delete downloaded file |
|
2 | 1179 |
if (array[i]->FileName().Length() > 0) |
1180 |
{ |
|
1181 |
if (aDeleteFiles) |
|
1182 |
{ |
|
1183 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(), array[i]->FileName()); |
|
1184 |
} |
|
1185 |
} |
|
1186 |
} |
|
1187 |
array.ResetAndDestroy(); |
|
53 | 1188 |
|
1189 |
// delete all shows from DB |
|
111 | 1190 |
DBDeleteAllShowsByFeedL(aFeedUid); |
53 | 1191 |
|
1192 |
// this will clear out deleted shows from the download queue |
|
1193 |
DBGetAllDownloadsL(array); |
|
1194 |
array.ResetAndDestroy(); |
|
1195 |
||
1196 |
NotifyDownloadQueueUpdatedL(); |
|
2 | 1197 |
} |
1198 |
||
111 | 1199 |
EXPORT_C void CShowEngine::DeleteOldShowsByFeedL(TUint aFeedUid) |
2 | 1200 |
{ |
111 | 1201 |
DBDeleteOldShowsByFeedL(aFeedUid); |
2 | 1202 |
} |
1203 |
||
1204 |
EXPORT_C void CShowEngine::DeleteShowL(TUint aShowUid, TBool aRemoveFile) |
|
1205 |
{ |
|
1206 |
||
1207 |
CShowInfo *info = DBGetShowByUidL(aShowUid); |
|
1208 |
||
1209 |
if (info != NULL) |
|
1210 |
{ |
|
1211 |
if (info->FileName().Length() > 0 && aRemoveFile) |
|
1212 |
{ |
|
1213 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(), info->FileName()); |
|
1214 |
} |
|
1215 |
||
1216 |
info->SetDownloadState(ENotDownloaded); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1217 |
DBUpdateShowL(*info); |
2 | 1218 |
delete info; |
1219 |
} |
|
1220 |
} |
|
1221 |
||
1222 |
EXPORT_C void CShowEngine::GetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid) |
|
1223 |
{ |
|
1224 |
DP("CShowEngine::GetShowsByFeed"); |
|
1225 |
DBGetShowsByFeedL(aShowArray, aFeedUid); |
|
1226 |
} |
|
1227 |
||
1228 |
EXPORT_C void CShowEngine::GetAllShowsL(RShowInfoArray &aArray) |
|
1229 |
{ |
|
1230 |
DP("CShowEngine::GetAllShows"); |
|
1231 |
DBGetAllShowsL(aArray); |
|
1232 |
} |
|
1233 |
||
1234 |
EXPORT_C void CShowEngine::GetShowsDownloadedL(RShowInfoArray &aArray) |
|
1235 |
{ |
|
1236 |
DP("CShowEngine::GetShowsDownloaded"); |
|
1237 |
DBGetDownloadedShowsL(aArray); |
|
1238 |
} |
|
1239 |
||
1240 |
EXPORT_C void CShowEngine::GetNewShowsL(RShowInfoArray &aArray) |
|
1241 |
{ |
|
1242 |
DP("CShowEngine::GetNewShows"); |
|
1243 |
DBGetNewShowsL(aArray); |
|
1244 |
} |
|
1245 |
||
1246 |
EXPORT_C void CShowEngine::GetShowsDownloadingL(RShowInfoArray &aArray) |
|
1247 |
{ |
|
1248 |
DP("CShowEngine::GetShowsDownloading"); |
|
1249 |
DBGetAllDownloadsL(aArray); |
|
1250 |
} |
|
1251 |
||
1252 |
EXPORT_C TInt CShowEngine::GetNumDownloadingShows() |
|
1253 |
{ |
|
116 | 1254 |
TUint count = 0; |
111 | 1255 |
TRAP_IGNORE(count = DBGetDownloadsCountL()); |
1256 |
||
1257 |
return (const TInt) count; |
|
2 | 1258 |
} |
1259 |
||
1260 |
EXPORT_C void CShowEngine::AddDownloadL(CShowInfo& aInfo) |
|
1261 |
{ |
|
1262 |
aInfo.SetDownloadState(EQueued); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1263 |
DBUpdateShowL(aInfo); |
111 | 1264 |
DBAddDownloadL(aInfo.Uid()); |
2 | 1265 |
DownloadNextShowL(); |
1266 |
} |
|
1267 |
||
1268 |
void CShowEngine::DownloadNextShowL() |
|
1269 |
{ |
|
1270 |
DP("CShowEngine::DownloadNextShowL BEGIN"); |
|
1271 |
// Check if we have anything in the download queue |
|
111 | 1272 |
const TInt count = DBGetDownloadsCountL(); |
2 | 1273 |
DP("CShowEngine::DownloadNextShow\tTrying to start new download");DP1("CShowEngine::DownloadNextShow\tShows in download queue %d", count); |
1274 |
||
1275 |
if (count > 0) |
|
1276 |
{ |
|
1277 |
if (iPodcastModel.SettingsEngine().DownloadSuspended()) |
|
1278 |
{ |
|
1279 |
DP("CShowEngine::DownloadNextShow\tDownload process is suspended, ABORTING"); |
|
34 | 1280 |
// Inform the observers |
1281 |
NotifyDownloadQueueUpdatedL(); |
|
2 | 1282 |
return; |
1283 |
} |
|
1284 |
else if (iShowClient->IsActive()) |
|
1285 |
{ |
|
1286 |
DP("CShowEngine::DownloadNextShow\tDownload process is already active."); |
|
34 | 1287 |
// Inform the observers |
1288 |
NotifyDownloadQueueUpdatedL(); |
|
2 | 1289 |
return; |
1290 |
} |
|
1291 |
else |
|
1292 |
{ |
|
116 | 1293 |
if (iShowDownloading) { |
1294 |
delete iShowDownloading; |
|
1295 |
} |
|
1296 |
||
2 | 1297 |
// Start the download |
116 | 1298 |
iShowDownloading = DBGetNextDownloadL(); |
1299 |
||
1300 |
while(iShowDownloading != NULL) |
|
2 | 1301 |
{ |
116 | 1302 |
DP1("CShowEngine::DownloadNextShow\tDownloading: %S", &(iShowDownloading->Title())); |
1303 |
iShowDownloading->SetDownloadState(EDownloading); |
|
1304 |
iShowDownloading->SetLastError(KErrNone); |
|
1305 |
DBUpdateShowL(*iShowDownloading); |
|
34 | 1306 |
// Inform the observers |
1307 |
// important to do this after we change download state |
|
1308 |
NotifyDownloadQueueUpdatedL(); |
|
1309 |
||
116 | 1310 |
TRAPD(error,GetShowL(iShowDownloading)); |
1311 |
if (error == KErrNone) |
|
2 | 1312 |
{ |
1313 |
break; |
|
1314 |
} |
|
116 | 1315 |
else |
1316 |
{ |
|
1317 |
iShowDownloading->SetDownloadState(EFailedDownload); |
|
1318 |
DBRemoveDownloadL(iShowDownloading->Uid()); |
|
1319 |
DBUpdateShowL(*iShowDownloading); |
|
1320 |
CleanupStack::PopAndDestroy(iShowDownloading); |
|
1321 |
||
1322 |
iShowDownloading = DBGetNextDownloadL(); |
|
1323 |
if(iShowDownloading == NULL) |
|
1324 |
{ |
|
1325 |
iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue); |
|
1326 |
} |
|
1327 |
} |
|
2 | 1328 |
} |
1329 |
} |
|
1330 |
} |
|
1331 |
else |
|
1332 |
{ |
|
34 | 1333 |
// Inform the observers |
1334 |
NotifyDownloadQueueUpdatedL(); |
|
2 | 1335 |
iShowDownloading = NULL;DP("CShowEngine::DownloadNextShow\tNothing to download"); |
1336 |
} |
|
1337 |
DP("CShowEngine::DownloadNextShowL END"); |
|
1338 |
} |
|
1339 |
||
1340 |
void CShowEngine::NotifyDownloadQueueUpdatedL() |
|
1341 |
{ |
|
1342 |
const TInt count = iObservers.Count(); |
|
1343 |
for (TInt i = 0; i < count; i++) |
|
1344 |
{ |
|
111 | 1345 |
iObservers[i]->DownloadQueueUpdatedL(1, DBGetDownloadsCountL() - 1); |
2 | 1346 |
} |
1347 |
} |
|
1348 |
||
1349 |
void CShowEngine::NotifyShowDownloadUpdatedL(TInt aBytesOfCurrentDownload, TInt aBytesTotal) |
|
1350 |
{ |
|
1351 |
const TInt count = iObservers.Count(); |
|
1352 |
for (TInt i = 0; i < count; i++) |
|
1353 |
{ |
|
1354 |
iObservers[i]->ShowDownloadUpdatedL(aBytesOfCurrentDownload, aBytesTotal); |
|
1355 |
} |
|
1356 |
} |
|
1357 |
||
1358 |
void CShowEngine::NotifyShowFinishedL(TInt aError) |
|
1359 |
{ |
|
1360 |
const TInt count = iObservers.Count(); |
|
1361 |
for (TInt i = 0; i < count; i++) |
|
1362 |
{ |
|
1363 |
iObservers[i]->ShowDownloadFinishedL(iShowDownloading?iShowDownloading->Uid():0, aError); |
|
1364 |
} |
|
1365 |
} |
|
1366 |
||
1367 |
EXPORT_C void CShowEngine::NotifyShowListUpdatedL() |
|
1368 |
{ |
|
1369 |
for (TInt i = 0; i < iObservers.Count(); i++) |
|
1370 |
{ |
|
1371 |
iObservers[i]->ShowListUpdatedL(); |
|
1372 |
} |
|
1373 |
} |
|
1374 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1375 |
void CShowEngine::ReadMetaDataL(CShowInfo& aShowInfo) |
2 | 1376 |
{ |
1377 |
//DP1("Read %S", &(aShowInfo->Title())); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1378 |
DBUpdateShowL(aShowInfo); |
2 | 1379 |
} |
1380 |
||
1381 |
void CShowEngine::ReadMetaDataCompleteL() |
|
1382 |
{ |
|
1383 |
NotifyShowListUpdatedL(); |
|
1384 |
MetaDataReader().SetIgnoreTrackNo(EFalse); |
|
1385 |
} |
|
1386 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1387 |
EXPORT_C void CShowEngine::UpdateShowL(CShowInfo& aInfo) |
2 | 1388 |
{ |
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1389 |
DBUpdateShowL(aInfo); |
2 | 1390 |
} |
1391 |
||
1392 |
EXPORT_C CMetaDataReader& CShowEngine::MetaDataReader() |
|
1393 |
{ |
|
1394 |
return *iMetaDataReader; |
|
1395 |
} |
|
1396 |
||
1397 |
void CShowEngine::FileError(TUint /*aError*/) |
|
1398 |
{ |
|
1399 |
iDownloadErrors = KMaxDownloadErrors; |
|
1400 |
} |
|
118
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1401 |
|
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1402 |
EXPORT_C void CShowEngine::CheckForDeletedShows(TUint aFeedUid) |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1403 |
{ |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1404 |
RShowInfoArray shows; |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1405 |
|
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1406 |
TRAPD(err, DBGetShowsByFeedL(shows, aFeedUid)); |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1407 |
|
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1408 |
if (err != KErrNone) |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1409 |
{ |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1410 |
// probably a catastrophic error, but it doesn't |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1411 |
// matter for this method |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1412 |
return; |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1413 |
} |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1414 |
|
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1415 |
for (int i=0;i<shows.Count();i++) |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1416 |
{ |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1417 |
if (shows[i]->DownloadState() == EDownloaded && shows[i]->FileName() != KNullDesC) |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1418 |
{ |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1419 |
if(!BaflUtils::FileExists(iPodcastModel.FsSession(),shows[i]->FileName())) |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1420 |
{ |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1421 |
// file doesn't exist anymore, assume it was deleted from outside |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1422 |
DP1("Show %S does not exist on disk, flagging as non downloaded", &shows[i]->FileName()); |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1423 |
shows[i]->SetDownloadState(ENotDownloaded); |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1424 |
shows[i]->SetPlayState(EPlayed); |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1425 |
TRAP_IGNORE(DBUpdateShowL(*shows[i])); |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1426 |
} |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1427 |
} |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1428 |
} |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1429 |
} |
b03018fb3418
Added method that checks for deleted downloaded files and updates DB accordingly
teknolog
parents:
117
diff
changeset
|
1430 |
|
151 | 1431 |
EXPORT_C void CShowEngine::MoveDownloadUpL(TUint aUid) |
1432 |
{ |
|
1433 |
DP("CShowEngine::MoveDownLoadUpL"); |
|
1434 |
_LIT(KSqlStatement, "select * from downloads"); |
|
1435 |
iSqlBuffer.Format(KSqlStatement); |
|
1436 |
||
1437 |
sqlite3_stmt *st; |
|
1438 |
||
1439 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
1440 |
&st, (const void**) NULL); |
|
1441 |
||
1442 |
if (rc == SQLITE_OK) |
|
1443 |
{ |
|
1444 |
RArray<TDownload> downloads; |
|
1445 |
CleanupClosePushL(downloads); |
|
1446 |
||
1447 |
rc = sqlite3_step(st); |
|
1448 |
Cleanup_sqlite3_finalize_PushL(st); |
|
1449 |
||
1450 |
TInt selectedIdx = -1; |
|
1451 |
while (rc == SQLITE_ROW && selectedIdx == -1) |
|
1452 |
{ |
|
1453 |
TDownload download; |
|
1454 |
||
1455 |
download.iIndex = sqlite3_column_int(st, 0); |
|
1456 |
download.iUid = sqlite3_column_int(st, 1); |
|
1457 |
||
1458 |
downloads.Append(download); |
|
1459 |
||
1460 |
if (download.iUid == aUid) |
|
1461 |
{ |
|
1462 |
selectedIdx = downloads.Count()-1; |
|
1463 |
} |
|
1464 |
||
1465 |
rc = sqlite3_step(st); |
|
1466 |
} |
|
1467 |
CleanupStack::PopAndDestroy();//st, downloads |
|
1468 |
||
1469 |
// If the selected download was found in the database |
|
1470 |
if (selectedIdx != -1) |
|
1471 |
{ |
|
1472 |
// Swap the specified download with the one above it |
|
1473 |
TDownload selectedDownload = downloads[selectedIdx]; |
|
1474 |
TDownload previousDownload = downloads[selectedIdx - 1]; |
|
1475 |
||
1476 |
// SQL - Update index (with index of selected download) where uid is of previous download |
|
1477 |
// and update index (with index of previous download) where uid if of selected download |
|
1478 |
DBSwapDownloadsL(selectedDownload, previousDownload); |
|
1479 |
} |
|
1480 |
else |
|
1481 |
{ |
|
1482 |
User::Leave(KErrNotFound); |
|
1483 |
} |
|
1484 |
||
1485 |
CleanupStack::PopAndDestroy(); // downloads |
|
1486 |
} |
|
1487 |
else |
|
1488 |
{ |
|
1489 |
User::Leave(KErrCorrupt); |
|
1490 |
} |
|
1491 |
} |
|
1492 |
||
1493 |
EXPORT_C void CShowEngine::MoveDownloadDownL(TUint aUid) |
|
1494 |
{ |
|
1495 |
DP("CShowEngine::MoveDownLoadDownL"); |
|
1496 |
||
1497 |
// An upside-down list will result in the download moving down |
|
1498 |
_LIT(KSqlStatement, "select * from downloads order by dl_index desc"); |
|
1499 |
iSqlBuffer.Format(KSqlStatement); |
|
1500 |
||
1501 |
sqlite3_stmt *st; |
|
1502 |
||
1503 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
1504 |
&st, (const void**) NULL); |
|
1505 |
||
1506 |
if (rc == SQLITE_OK) |
|
1507 |
{ |
|
1508 |
RArray<TDownload> downloads; |
|
1509 |
CleanupClosePushL(downloads); |
|
1510 |
||
1511 |
rc = sqlite3_step(st); |
|
1512 |
Cleanup_sqlite3_finalize_PushL(st); |
|
1513 |
||
1514 |
TInt selectedIdx = -1; |
|
1515 |
while (rc == SQLITE_ROW && selectedIdx == -1) |
|
1516 |
{ |
|
1517 |
TDownload download; |
|
1518 |
||
1519 |
download.iIndex = sqlite3_column_int(st, 0); |
|
1520 |
download.iUid = sqlite3_column_int(st, 1); |
|
1521 |
||
1522 |
downloads.Append(download); |
|
1523 |
||
1524 |
if (download.iUid == aUid) |
|
1525 |
{ |
|
1526 |
selectedIdx = downloads.Count()-1; |
|
1527 |
} |
|
1528 |
||
1529 |
rc = sqlite3_step(st); |
|
1530 |
} |
|
1531 |
CleanupStack::PopAndDestroy();//st, downloads |
|
1532 |
||
1533 |
// If the selected download was found in the database |
|
1534 |
if (selectedIdx != -1) |
|
1535 |
{ |
|
1536 |
// Swap the specified download with the one above it |
|
1537 |
TDownload selectedDownload = downloads[selectedIdx]; |
|
1538 |
TDownload previousDownload = downloads[selectedIdx - 1]; |
|
1539 |
||
1540 |
// SQL - Update index (with index of selected download) where uid is of previous download |
|
1541 |
// and update index (with index of previous download) where uid if of selected download |
|
1542 |
DBSwapDownloadsL(selectedDownload, previousDownload); |
|
1543 |
} |
|
1544 |
else |
|
1545 |
{ |
|
1546 |
User::Leave(KErrNotFound); |
|
1547 |
} |
|
1548 |
||
1549 |
CleanupStack::PopAndDestroy(); // downloads |
|
1550 |
} |
|
1551 |
else |
|
1552 |
{ |
|
1553 |
User::Leave(KErrCorrupt); |
|
1554 |
} |
|
165
d886725e4499
Fix for 2608 - Title is sometimes not reset to "Podcatcher" after leaving ShowsView
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
151
diff
changeset
|
1555 |
} |