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