author | teknolog |
Tue, 06 Jul 2010 10:34:42 +0100 | |
branch | symbian1 |
changeset 160 | 6477d22a5dca |
parent 149 | 70b2f592a460 |
child 164 | 000f9fc147b2 |
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 |
||
130
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
543 |
if (iShowFilter == ENewShows) |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
544 |
{ |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
545 |
_LIT(KSqlStatementNewShows, " and playstate = 0"); // ENeverPlayed |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
546 |
iSqlBuffer.Append(KSqlStatementNewShows); |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
547 |
} |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
548 |
else if (iShowFilter == EDownloadedShows) |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
549 |
{ |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
550 |
_LIT(KSqlStatementDownloadedShows, " and downloadstate = 4"); // EDownloaded |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
551 |
iSqlBuffer.Append(KSqlStatementDownloadedShows); |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
552 |
} |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
553 |
else if (iShowFilter == ENewAndDownloadedShows) |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
554 |
{ |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
555 |
_LIT(KSqlStatementDownloadedAndNewShows, " and (downloadstate = 4 or playstate = 0)"); // EDownloaded or ENeverPlayed |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
556 |
iSqlBuffer.Append(KSqlStatementDownloadedAndNewShows); |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
557 |
|
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
558 |
} |
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
559 |
|
2 | 560 |
#ifndef DONT_SORT_SQL |
561 |
_LIT(KSqlOrderByDate, " order by pubdate desc"); |
|
562 |
iSqlBuffer.Append(KSqlOrderByDate); |
|
563 |
#endif |
|
564 |
||
565 |
sqlite3_stmt *st; |
|
566 |
||
567 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
568 |
&st, (const void**) NULL); |
|
569 |
||
570 |
if (rc == SQLITE_OK) |
|
571 |
{ |
|
572 |
rc = sqlite3_step(st); |
|
573 |
Cleanup_sqlite3_finalize_PushL(st); |
|
574 |
while (rc == SQLITE_ROW) |
|
575 |
{ |
|
576 |
CShowInfo* showInfo = CShowInfo::NewLC(); |
|
577 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
578 |
aShowArray.Append(showInfo); |
|
579 |
CleanupStack::Pop(showInfo); |
|
580 |
rc = sqlite3_step(st); |
|
581 |
} |
|
582 |
CleanupStack::PopAndDestroy();//st |
|
583 |
} |
|
60 | 584 |
else |
585 |
{ |
|
586 |
User::Leave(KErrCorrupt); |
|
587 |
} |
|
2 | 588 |
DP("CShowEngine::DBGetShowsByFeed END"); |
589 |
} |
|
590 |
||
60 | 591 |
TUint CShowEngine::DBGetDownloadsCountL() |
2 | 592 |
{ |
593 |
DP("CShowEngine::DBGetDownloadsCount"); |
|
594 |
||
595 |
_LIT(KSqlStatement, "select count(*) from downloads"); |
|
596 |
iSqlBuffer.Format(KSqlStatement); |
|
597 |
||
598 |
sqlite3_stmt *st; |
|
599 |
TUint count = 0; |
|
600 |
||
601 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
602 |
&st, (const void**) NULL); |
|
603 |
||
604 |
if (rc == SQLITE_OK) |
|
605 |
{ |
|
60 | 606 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 607 |
rc = sqlite3_step(st); |
608 |
||
609 |
if (rc == SQLITE_ROW) |
|
610 |
{ |
|
611 |
count = sqlite3_column_int(st, 0); |
|
612 |
} |
|
60 | 613 |
else |
614 |
{ |
|
615 |
User::Leave(KErrUnknown); |
|
616 |
} |
|
617 |
||
618 |
CleanupStack::PopAndDestroy(); //st |
|
619 |
} |
|
620 |
else |
|
621 |
{ |
|
622 |
User::Leave(KErrCorrupt); |
|
2 | 623 |
} |
624 |
return count; |
|
625 |
} |
|
626 |
||
627 |
void CShowEngine::DBGetDownloadedShowsL(RShowInfoArray& aShowArray) |
|
628 |
{ |
|
629 |
DP("CShowEngine::DBGetDownloadedShows"); |
|
630 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where downloadstate=%u"); |
|
631 |
iSqlBuffer.Format(KSqlStatement, EDownloaded); |
|
632 |
||
633 |
#ifndef DONT_SORT_SQL |
|
634 |
_LIT(KSqlSort, " order by title"); |
|
635 |
iSqlBuffer.Append(KSqlSort); |
|
636 |
#endif |
|
637 |
||
638 |
sqlite3_stmt *st; |
|
639 |
||
640 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
641 |
&st, (const void**) NULL); |
|
642 |
||
643 |
if (rc == SQLITE_OK) |
|
644 |
{ |
|
645 |
rc = sqlite3_step(st); |
|
646 |
Cleanup_sqlite3_finalize_PushL(st); |
|
647 |
while (rc == SQLITE_ROW) |
|
648 |
{ |
|
649 |
CShowInfo* showInfo = CShowInfo::NewLC(); |
|
650 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
651 |
aShowArray.Append(showInfo); |
|
652 |
CleanupStack::Pop(showInfo); |
|
653 |
rc = sqlite3_step(st); |
|
654 |
} |
|
655 |
CleanupStack::PopAndDestroy();//st |
|
656 |
} |
|
60 | 657 |
else |
658 |
{ |
|
659 |
User::Leave(KErrCorrupt); |
|
660 |
} |
|
2 | 661 |
} |
662 |
||
663 |
void CShowEngine::DBGetNewShowsL(RShowInfoArray& aShowArray) |
|
664 |
{ |
|
665 |
DP("CShowEngine::DBGetNewShows"); |
|
666 |
_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where playstate=%u"); |
|
667 |
iSqlBuffer.Format(KSqlStatement, ENeverPlayed); |
|
668 |
||
669 |
sqlite3_stmt *st; |
|
670 |
||
671 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
672 |
&st, (const void**) NULL); |
|
673 |
||
674 |
if (rc == SQLITE_OK) |
|
675 |
{ |
|
676 |
rc = sqlite3_step(st); |
|
677 |
Cleanup_sqlite3_finalize_PushL(st); |
|
678 |
while (rc == SQLITE_ROW) |
|
679 |
{ |
|
680 |
CShowInfo* showInfo = CShowInfo::NewLC(); |
|
681 |
DBFillShowInfoFromStmtL(st, showInfo); |
|
682 |
aShowArray.Append(showInfo); |
|
683 |
CleanupStack::Pop(showInfo); |
|
684 |
rc = sqlite3_step(st); |
|
685 |
} |
|
686 |
CleanupStack::PopAndDestroy();//st |
|
687 |
} |
|
60 | 688 |
else |
689 |
{ |
|
690 |
User::Leave(KErrCorrupt); |
|
691 |
} |
|
2 | 692 |
} |
693 |
||
60 | 694 |
void CShowEngine::DBDeleteOldShowsByFeedL(TUint aFeedUid) |
2 | 695 |
{ |
696 |
DP("CShowEngine::DBDeleteOldShows"); |
|
697 |
||
698 |
// what we do: |
|
699 |
// 1. sort shows by pubdate |
|
700 |
// 2. select the first MaxListItems shows |
|
701 |
// 3. delete the rest if downloadstate is ENotDownloaded |
|
702 |
||
703 |
_LIT(KSqlStatement,"delete from shows where feeduid=%u and downloadstate=0 and uid not in " \ |
|
704 |
"(select uid from shows where feeduid=%u order by pubdate desc limit %u)"); |
|
705 |
iSqlBuffer.Format(KSqlStatement, aFeedUid, aFeedUid, iPodcastModel.SettingsEngine().MaxListItems()); |
|
706 |
||
707 |
sqlite3_stmt *st; |
|
708 |
||
709 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
710 |
&st, (const void**) NULL); |
|
711 |
||
712 |
if (rc == SQLITE_OK) |
|
713 |
{ |
|
714 |
rc = sqlite3_step(st); |
|
715 |
sqlite3_finalize(st); |
|
716 |
} |
|
60 | 717 |
else |
718 |
{ |
|
719 |
User::Leave(KErrCorrupt); |
|
720 |
} |
|
2 | 721 |
|
722 |
_LIT(KSqlStatement2, "delete from downloads where uid not in (select downloads.uid from shows, downloads where shows.uid=downloads.uid)"); |
|
723 |
iSqlBuffer.Format(KSqlStatement2); |
|
724 |
||
725 |
rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, &st, (const void**) NULL); |
|
726 |
||
727 |
if (rc == SQLITE_OK) |
|
728 |
{ |
|
729 |
rc = sqlite3_step(st); |
|
730 |
sqlite3_finalize(st); |
|
731 |
} |
|
60 | 732 |
else |
733 |
{ |
|
734 |
User::Leave(KErrCorrupt); |
|
735 |
} |
|
2 | 736 |
} |
737 |
||
738 |
void CShowEngine::DBFillShowInfoFromStmtL(sqlite3_stmt *st, CShowInfo* showInfo) |
|
739 |
{ |
|
740 |
const void *urlz = sqlite3_column_text16(st, 0); |
|
741 |
TPtrC16 url((const TUint16*) urlz); |
|
742 |
showInfo->SetUrlL(url); |
|
743 |
||
744 |
const void *titlez = sqlite3_column_text16(st, 1); |
|
745 |
TPtrC16 title((const TUint16*) titlez); |
|
746 |
showInfo->SetTitleL(title); |
|
747 |
||
748 |
const void *descz = sqlite3_column_text16(st, 2); |
|
749 |
TPtrC16 desc((const TUint16*) descz); |
|
750 |
showInfo->SetDescriptionL(desc); |
|
751 |
||
752 |
const void *filez = sqlite3_column_text16(st, 3); |
|
753 |
TPtrC16 file((const TUint16*) filez); |
|
754 |
showInfo->SetFileNameL(file); |
|
755 |
||
756 |
sqlite3_int64 pos = sqlite3_column_int64(st, 4); |
|
757 |
TTimeIntervalMicroSeconds position(pos); |
|
758 |
showInfo->SetPosition(position); |
|
759 |
||
760 |
TUint playtime = sqlite3_column_int(st, 5); |
|
761 |
showInfo->SetPlayTime(playtime); |
|
762 |
||
763 |
TUint playstate = sqlite3_column_int(st, 6); |
|
764 |
showInfo->SetPlayState((TPlayState) playstate); |
|
765 |
||
766 |
TUint downloadstate = sqlite3_column_int(st, 7); |
|
767 |
showInfo->SetDownloadState((TDownloadState) downloadstate); |
|
768 |
||
769 |
TUint feeduid = sqlite3_column_int(st, 8); |
|
770 |
showInfo->SetFeedUid(feeduid); |
|
771 |
||
772 |
TUint uid = sqlite3_column_int(st, 9); |
|
773 |
showInfo->SetUid(uid); |
|
774 |
||
775 |
TUint showsize = sqlite3_column_int(st, 10); |
|
776 |
showInfo->SetShowSize(showsize); |
|
777 |
||
778 |
TUint trackno = sqlite3_column_int(st, 11); |
|
779 |
showInfo->SetTrackNo((TShowType) trackno); |
|
780 |
||
781 |
sqlite3_int64 pubdate = sqlite3_column_int64(st, 12); |
|
782 |
TTime timepubdate(pubdate); |
|
783 |
showInfo->SetPubDate(timepubdate); |
|
784 |
||
785 |
TUint showtype = sqlite3_column_int(st, 13); |
|
786 |
showInfo->SetShowType((TShowType) showtype); |
|
787 |
||
788 |
TInt lasterror = sqlite3_column_int(st, 14); |
|
789 |
showInfo->SetLastError(lasterror); |
|
790 |
} |
|
791 |
||
60 | 792 |
void CShowEngine::DBAddShowL(const CShowInfo& aItem) |
2 | 793 |
{ |
794 |
DP2("CShowEngine::DBAddShow, title=%S, URL=%S", &aItem.Title(), &aItem.Url()); |
|
795 |
||
21 | 796 |
HBufC* titleBuf = HBufC::NewLC(KMaxLineLength); |
797 |
TPtr titlePtr(titleBuf->Des()); |
|
798 |
titlePtr.Copy(aItem.Title()); |
|
799 |
PodcastUtils::SQLEncode(titlePtr); |
|
800 |
||
801 |
HBufC* descBuf = HBufC::NewLC(KMaxLineLength); |
|
802 |
TPtr descPtr(descBuf->Des()); |
|
803 |
descPtr.Copy(aItem.Description()); |
|
804 |
PodcastUtils::SQLEncode(descPtr); |
|
805 |
||
2 | 806 |
_LIT(KSqlStatement, "insert into shows (url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype)" |
807 |
" values (\"%S\",\"%S\", \"%S\", \"%S\", \"%Lu\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%Lu\", \"%d\")"); |
|
21 | 808 |
|
809 |
iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr, |
|
2 | 810 |
&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(), |
811 |
aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(), |
|
812 |
aItem.Uid(), aItem.ShowSize(), aItem.TrackNo(), |
|
813 |
aItem.PubDate().Int64(), aItem.ShowType()); |
|
814 |
||
21 | 815 |
CleanupStack::PopAndDestroy(descBuf); |
816 |
CleanupStack::PopAndDestroy(titleBuf); |
|
817 |
||
2 | 818 |
sqlite3_stmt *st; |
819 |
||
820 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
821 |
&st, (const void**) NULL); |
|
60 | 822 |
|
2 | 823 |
if (rc == SQLITE_OK) |
824 |
{ |
|
60 | 825 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 826 |
rc = sqlite3_step(st); |
60 | 827 |
if (rc != SQLITE_DONE) |
2 | 828 |
{ |
60 | 829 |
User::Leave(KErrAlreadyExists); |
2 | 830 |
} |
60 | 831 |
CleanupStack::PopAndDestroy(); // st |
2 | 832 |
} |
833 |
else |
|
834 |
{ |
|
60 | 835 |
User::Leave(KErrCorrupt); |
2 | 836 |
} |
837 |
} |
|
838 |
||
60 | 839 |
void CShowEngine::DBAddDownloadL(TUint aUid) |
2 | 840 |
{ |
841 |
DP1("CShowEngine::DBAddDownload, aUid=%u", aUid); |
|
842 |
||
843 |
_LIT(KSqlStatement, "insert into downloads (uid) values (%u)"); |
|
844 |
iSqlBuffer.Format(KSqlStatement, aUid); |
|
845 |
sqlite3_stmt *st; |
|
846 |
||
847 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
848 |
&st, (const void**) NULL); |
|
849 |
||
850 |
if (rc == SQLITE_OK) |
|
851 |
{ |
|
60 | 852 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 853 |
rc = sqlite3_step(st); |
60 | 854 |
if (rc != SQLITE_DONE) |
855 |
{ |
|
856 |
User::Leave(KErrUnknown); |
|
857 |
} |
|
858 |
CleanupStack::PopAndDestroy(); // st |
|
2 | 859 |
} |
60 | 860 |
else |
861 |
{ |
|
862 |
User::Leave(KErrCorrupt); |
|
863 |
} |
|
2 | 864 |
} |
865 |
||
60 | 866 |
void CShowEngine::DBUpdateShowL(CShowInfo& aItem) |
2 | 867 |
{ |
868 |
DP1("CShowEngine::DBUpdateShow, title='%S'", &aItem.Title()); |
|
869 |
||
30
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
870 |
HBufC* titleBuf = HBufC::NewLC(KMaxLineLength); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
871 |
TPtr titlePtr(titleBuf->Des()); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
872 |
titlePtr.Copy(aItem.Title()); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
873 |
PodcastUtils::SQLEncode(titlePtr); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
874 |
|
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
875 |
HBufC* descBuf = HBufC::NewLC(KMaxLineLength); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
876 |
TPtr descPtr(descBuf->Des()); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
877 |
descPtr.Copy(aItem.Description()); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
878 |
PodcastUtils::SQLEncode(descPtr); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
879 |
|
2 | 880 |
_LIT(KSqlStatement, "update shows set url=\"%S\", title=\"%S\", description=\"%S\", filename=\"%S\", position=\"%Lu\"," |
881 |
"playtime=\"%u\", playstate=\"%u\", downloadstate=\"%u\", feeduid=\"%u\", showsize=\"%u\", trackno=\"%u\"," |
|
882 |
"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
|
883 |
iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr, |
2 | 884 |
&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(), |
885 |
aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(), |
|
886 |
aItem.ShowSize(), aItem.TrackNo(), aItem.PubDate().Int64(), |
|
887 |
aItem.ShowType(), aItem.LastError(), aItem.Uid()); |
|
888 |
||
30
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
889 |
CleanupStack::PopAndDestroy(descBuf); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
890 |
CleanupStack::PopAndDestroy(titleBuf); |
7bca37ba5fa9
Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents:
22
diff
changeset
|
891 |
|
2 | 892 |
sqlite3_stmt *st; |
893 |
||
894 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
895 |
&st, (const void**) NULL); |
|
896 |
||
897 |
if (rc == SQLITE_OK) |
|
898 |
{ |
|
60 | 899 |
Cleanup_sqlite3_finalize_PushL(st); |
900 |
rc = sqlite3_step(st); |
|
2 | 901 |
|
60 | 902 |
if (rc != SQLITE_DONE) |
2 | 903 |
{ |
60 | 904 |
User::Leave(KErrUnknown); |
2 | 905 |
} |
60 | 906 |
CleanupStack::PopAndDestroy(); // st |
2 | 907 |
} |
908 |
else |
|
909 |
{ |
|
60 | 910 |
User::Leave(KErrCorrupt); |
2 | 911 |
} |
912 |
} |
|
913 |
||
60 | 914 |
void CShowEngine::DBDeleteShowL(TUint aUid) |
2 | 915 |
{ |
916 |
DP("CShowEngine::DBDeleteShow"); |
|
917 |
||
918 |
_LIT(KSqlStatement, "delete from shows where uid=%u"); |
|
919 |
iSqlBuffer.Format(KSqlStatement, aUid); |
|
920 |
||
921 |
sqlite3_stmt *st; |
|
922 |
||
923 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
924 |
&st, (const void**) NULL); |
|
925 |
||
926 |
if (rc == SQLITE_OK) |
|
927 |
{ |
|
60 | 928 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 929 |
rc = sqlite3_step(st); |
930 |
||
60 | 931 |
if (rc != SQLITE_DONE) |
2 | 932 |
{ |
60 | 933 |
User::Leave(KErrUnknown); |
2 | 934 |
} |
60 | 935 |
CleanupStack::PopAndDestroy(); // st |
2 | 936 |
} |
937 |
else |
|
938 |
{ |
|
60 | 939 |
User::Leave(KErrCorrupt); |
2 | 940 |
} |
941 |
} |
|
942 |
||
60 | 943 |
void CShowEngine::DBDeleteAllShowsByFeedL(TUint aFeedUid) |
2 | 944 |
{ |
945 |
DP("CShowEngine::DBDeleteAllShowsByFeed"); |
|
946 |
||
947 |
_LIT(KSqlStatement, "delete from shows where feeduid=%u"); |
|
948 |
iSqlBuffer.Format(KSqlStatement, aFeedUid); |
|
949 |
||
950 |
sqlite3_stmt *st; |
|
951 |
||
952 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
953 |
&st, (const void**) NULL); |
|
954 |
||
955 |
if (rc == SQLITE_OK) |
|
956 |
{ |
|
60 | 957 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 958 |
rc = sqlite3_step(st); |
959 |
||
60 | 960 |
if (rc != SQLITE_DONE) |
2 | 961 |
{ |
60 | 962 |
User::Leave(KErrUnknown); |
2 | 963 |
} |
60 | 964 |
CleanupStack::PopAndDestroy(); // st |
2 | 965 |
} |
966 |
else |
|
967 |
{ |
|
60 | 968 |
User::Leave(KErrCorrupt); |
2 | 969 |
} |
970 |
} |
|
971 |
||
60 | 972 |
void CShowEngine::DBRemoveAllDownloadsL() |
2 | 973 |
{ |
974 |
DP("CShowEngine::DBRemoveAllDownloads"); |
|
975 |
||
976 |
_LIT(KSqlStatement, "delete from downloads"); |
|
977 |
iSqlBuffer.Format(KSqlStatement); |
|
978 |
||
979 |
sqlite3_stmt *st; |
|
980 |
||
981 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
982 |
&st, (const void**) NULL); |
|
983 |
||
984 |
if (rc == SQLITE_OK) |
|
985 |
{ |
|
986 |
rc = sqlite3_step(st); |
|
987 |
sqlite3_finalize(st); |
|
988 |
} |
|
60 | 989 |
else |
990 |
{ |
|
991 |
User::Leave(KErrCorrupt); |
|
992 |
} |
|
2 | 993 |
|
994 |
_LIT(KSqlStatement2, "update shows set downloadstate=0 where downloadstate=1"); |
|
995 |
iSqlBuffer.Format(KSqlStatement2); |
|
996 |
||
997 |
rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, &st, |
|
998 |
(const void**) NULL); |
|
999 |
||
1000 |
if (rc == SQLITE_OK) |
|
1001 |
{ |
|
60 | 1002 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 1003 |
rc = sqlite3_step(st); |
60 | 1004 |
if (rc != SQLITE_DONE) |
1005 |
{ |
|
1006 |
User::Leave(KErrUnknown); |
|
1007 |
} |
|
1008 |
CleanupStack::PopAndDestroy(); // st |
|
1009 |
} |
|
1010 |
else |
|
1011 |
{ |
|
1012 |
User::Leave(KErrCorrupt); |
|
2 | 1013 |
} |
1014 |
||
1015 |
} |
|
1016 |
||
60 | 1017 |
void CShowEngine::DBRemoveDownloadL(TUint aUid) |
2 | 1018 |
{ |
1019 |
DP("CShowEngine::DBRemoveDownload"); |
|
1020 |
||
1021 |
_LIT(KSqlStatement, "delete from downloads where uid=%u"); |
|
1022 |
iSqlBuffer.Format(KSqlStatement, aUid); |
|
1023 |
||
1024 |
sqlite3_stmt *st; |
|
1025 |
||
1026 |
int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
1027 |
&st, (const void**) NULL); |
|
1028 |
||
1029 |
if (rc == SQLITE_OK) |
|
1030 |
{ |
|
60 | 1031 |
Cleanup_sqlite3_finalize_PushL(st); |
2 | 1032 |
rc = sqlite3_step(st); |
60 | 1033 |
if (rc != SQLITE_DONE) |
1034 |
{ |
|
1035 |
User::Leave(KErrUnknown); |
|
1036 |
} |
|
1037 |
CleanupStack::PopAndDestroy(); // st |
|
1038 |
} |
|
1039 |
else |
|
1040 |
{ |
|
1041 |
User::Leave(KErrCorrupt); |
|
2 | 1042 |
} |
1043 |
} |
|
1044 |
||
145
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1045 |
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
|
1046 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1047 |
DP("CShowEngine::DBSwapDownloadsL"); |
149
70b2f592a460
Enabled Brendan's download queue operations; Fixed minor bug in queue swapping method
teknolog
parents:
148
diff
changeset
|
1048 |
_LIT(KSqlStatement, "update downloads set uid=%u where dl_index=%d"); |
145
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 |
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
|
1051 |
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
|
1052 |
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
|
1053 |
&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
|
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 |
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
|
1056 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1057 |
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
|
1058 |
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
|
1059 |
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
|
1060 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1061 |
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
|
1062 |
} |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1063 |
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
|
1064 |
} |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1065 |
else |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1066 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1067 |
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
|
1068 |
} |
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 |
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
|
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 |
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
|
1073 |
&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
|
1074 |
|
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1075 |
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
|
1076 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1077 |
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
|
1078 |
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
|
1079 |
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
|
1080 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1081 |
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
|
1082 |
} |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1083 |
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
|
1084 |
} |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1085 |
else |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1086 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1087 |
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
|
1088 |
} |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1089 |
} |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1090 |
|
2 | 1091 |
EXPORT_C CShowInfo* CShowEngine::GetNextShowByTrackL(CShowInfo* aShowInfo) |
1092 |
{ |
|
1093 |
CShowInfo* nextShow = NULL; |
|
1094 |
RShowInfoArray array; |
|
1095 |
DBGetShowsByFeedL(array, aShowInfo->FeedUid()); |
|
1096 |
TUint diff = KMaxTInt; |
|
1097 |
for (TInt loop = 0; loop < array.Count(); loop++) |
|
1098 |
{ |
|
1099 |
if (aShowInfo->TrackNo() < array[loop]->TrackNo()) |
|
1100 |
{ |
|
1101 |
if ((array[loop]->TrackNo() - aShowInfo->TrackNo()) < diff) |
|
1102 |
{ |
|
1103 |
diff = array[loop]->TrackNo() - aShowInfo->TrackNo(); |
|
1104 |
nextShow = array[loop]; |
|
1105 |
} |
|
1106 |
} |
|
1107 |
} |
|
1108 |
array.ResetAndDestroy(); |
|
1109 |
return nextShow; |
|
1110 |
} |
|
1111 |
||
1112 |
TBool CShowEngine::CompareShowsByUid(const CShowInfo &a, const CShowInfo &b) |
|
1113 |
{ |
|
1114 |
return a.Uid() == b.Uid(); |
|
1115 |
} |
|
1116 |
||
1117 |
TInt CShowEngine::CompareShowsByDate(const CShowInfo &a, const CShowInfo &b) |
|
1118 |
{ |
|
1119 |
if (a.PubDate() > b.PubDate()) |
|
1120 |
{ |
|
1121 |
// DP2("Sorting %S less than %S", &a.iTitle, &b.iTitle); |
|
1122 |
return -1; |
|
1123 |
} |
|
1124 |
else if (a.PubDate() == b.PubDate()) |
|
1125 |
{ |
|
1126 |
// DP2("Sorting %S equal to %S", &a.iTitle, &b.iTitle); |
|
1127 |
return 0; |
|
1128 |
} |
|
1129 |
else |
|
1130 |
{ |
|
1131 |
// DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle); |
|
1132 |
return 1; |
|
1133 |
} |
|
1134 |
} |
|
1135 |
||
1136 |
TInt CShowEngine::CompareShowsByTrackNo(const CShowInfo &a, const CShowInfo &b) |
|
1137 |
{ |
|
1138 |
if (a.TrackNo() < b.TrackNo()) |
|
1139 |
{ |
|
1140 |
return -1; |
|
1141 |
} |
|
1142 |
else if (a.TrackNo() == b.TrackNo()) |
|
1143 |
{ |
|
1144 |
return 0; |
|
1145 |
} |
|
1146 |
else |
|
1147 |
{ |
|
1148 |
return 1; |
|
1149 |
} |
|
1150 |
} |
|
1151 |
||
1152 |
TInt CShowEngine::CompareShowsByTitle(const CShowInfo &a, const CShowInfo &b) |
|
1153 |
{ |
|
1154 |
if (a.Title() < b.Title()) |
|
1155 |
{ |
|
1156 |
// DP2("Sorting %S less than %S", &a.iTitle, &b.iTitle); |
|
1157 |
return -1; |
|
1158 |
} |
|
1159 |
else if (a.Title() == b.Title()) |
|
1160 |
{ |
|
1161 |
// DP2("Sorting %S equal to %S", &a.iTitle, &b.iTitle); |
|
1162 |
return 0; |
|
1163 |
} |
|
1164 |
else |
|
1165 |
{ |
|
1166 |
// DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle); |
|
1167 |
return 1; |
|
1168 |
} |
|
1169 |
} |
|
1170 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1171 |
EXPORT_C void CShowEngine::DeletePlayedShowsL(RShowInfoArray &aShowInfoArray) |
2 | 1172 |
{ |
1173 |
for (TInt i = 0; i < aShowInfoArray.Count(); i++) |
|
1174 |
{ |
|
1175 |
if (aShowInfoArray[i]->PlayState() == EPlayed |
|
1176 |
&& aShowInfoArray[i]->FileName().Length() > 0) |
|
1177 |
{ |
|
1178 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(), aShowInfoArray[i]->FileName()); |
|
1179 |
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
|
1180 |
DBUpdateShowL(*aShowInfoArray[i]); |
2 | 1181 |
} |
1182 |
} |
|
1183 |
} |
|
1184 |
||
1185 |
EXPORT_C void CShowEngine::DeleteAllShowsByFeedL(TUint aFeedUid, TBool aDeleteFiles) |
|
1186 |
{ |
|
1187 |
RShowInfoArray array; |
|
1188 |
DBGetShowsByFeedL(array, aFeedUid); |
|
1189 |
||
1190 |
const TInt count = array.Count(); |
|
1191 |
||
1192 |
for (TInt i = count - 1; i >= 0; i--) |
|
1193 |
{ |
|
53 | 1194 |
if (iShowDownloading && iShowDownloading->Uid() == array[i]->Uid()) |
1195 |
{ |
|
1196 |
// trying to delete the active download |
|
1197 |
RemoveDownloadL(iShowDownloading->Uid()); |
|
1198 |
} |
|
1199 |
||
1200 |
// delete downloaded file |
|
2 | 1201 |
if (array[i]->FileName().Length() > 0) |
1202 |
{ |
|
1203 |
if (aDeleteFiles) |
|
1204 |
{ |
|
1205 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(), array[i]->FileName()); |
|
1206 |
} |
|
1207 |
} |
|
1208 |
} |
|
1209 |
array.ResetAndDestroy(); |
|
53 | 1210 |
|
1211 |
// delete all shows from DB |
|
60 | 1212 |
DBDeleteAllShowsByFeedL(aFeedUid); |
53 | 1213 |
|
1214 |
// this will clear out deleted shows from the download queue |
|
1215 |
DBGetAllDownloadsL(array); |
|
1216 |
array.ResetAndDestroy(); |
|
1217 |
||
1218 |
NotifyDownloadQueueUpdatedL(); |
|
2 | 1219 |
} |
1220 |
||
60 | 1221 |
EXPORT_C void CShowEngine::DeleteOldShowsByFeedL(TUint aFeedUid) |
2 | 1222 |
{ |
60 | 1223 |
DBDeleteOldShowsByFeedL(aFeedUid); |
2 | 1224 |
} |
1225 |
||
1226 |
EXPORT_C void CShowEngine::DeleteShowL(TUint aShowUid, TBool aRemoveFile) |
|
1227 |
{ |
|
1228 |
||
1229 |
CShowInfo *info = DBGetShowByUidL(aShowUid); |
|
1230 |
||
1231 |
if (info != NULL) |
|
1232 |
{ |
|
1233 |
if (info->FileName().Length() > 0 && aRemoveFile) |
|
1234 |
{ |
|
1235 |
BaflUtils::DeleteFile(iPodcastModel.FsSession(), info->FileName()); |
|
1236 |
} |
|
1237 |
||
1238 |
info->SetDownloadState(ENotDownloaded); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1239 |
DBUpdateShowL(*info); |
2 | 1240 |
delete info; |
1241 |
} |
|
1242 |
} |
|
1243 |
||
1244 |
EXPORT_C void CShowEngine::GetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid) |
|
1245 |
{ |
|
1246 |
DP("CShowEngine::GetShowsByFeed"); |
|
1247 |
DBGetShowsByFeedL(aShowArray, aFeedUid); |
|
1248 |
} |
|
1249 |
||
1250 |
EXPORT_C void CShowEngine::GetAllShowsL(RShowInfoArray &aArray) |
|
1251 |
{ |
|
1252 |
DP("CShowEngine::GetAllShows"); |
|
1253 |
DBGetAllShowsL(aArray); |
|
1254 |
} |
|
1255 |
||
1256 |
EXPORT_C void CShowEngine::GetShowsDownloadedL(RShowInfoArray &aArray) |
|
1257 |
{ |
|
1258 |
DP("CShowEngine::GetShowsDownloaded"); |
|
1259 |
DBGetDownloadedShowsL(aArray); |
|
1260 |
} |
|
1261 |
||
1262 |
EXPORT_C void CShowEngine::GetNewShowsL(RShowInfoArray &aArray) |
|
1263 |
{ |
|
1264 |
DP("CShowEngine::GetNewShows"); |
|
1265 |
DBGetNewShowsL(aArray); |
|
1266 |
} |
|
1267 |
||
1268 |
EXPORT_C void CShowEngine::GetShowsDownloadingL(RShowInfoArray &aArray) |
|
1269 |
{ |
|
1270 |
DP("CShowEngine::GetShowsDownloading"); |
|
1271 |
DBGetAllDownloadsL(aArray); |
|
1272 |
} |
|
1273 |
||
1274 |
EXPORT_C TInt CShowEngine::GetNumDownloadingShows() |
|
1275 |
{ |
|
60 | 1276 |
TUint count = 0; |
1277 |
TRAP_IGNORE(count = DBGetDownloadsCountL()); |
|
1278 |
||
1279 |
return (const TInt) count; |
|
2 | 1280 |
} |
1281 |
||
1282 |
EXPORT_C void CShowEngine::AddDownloadL(CShowInfo& aInfo) |
|
1283 |
{ |
|
1284 |
aInfo.SetDownloadState(EQueued); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1285 |
DBUpdateShowL(aInfo); |
60 | 1286 |
DBAddDownloadL(aInfo.Uid()); |
2 | 1287 |
DownloadNextShowL(); |
1288 |
} |
|
1289 |
||
1290 |
void CShowEngine::DownloadNextShowL() |
|
1291 |
{ |
|
1292 |
DP("CShowEngine::DownloadNextShowL BEGIN"); |
|
1293 |
// Check if we have anything in the download queue |
|
60 | 1294 |
const TInt count = DBGetDownloadsCountL(); |
2 | 1295 |
DP("CShowEngine::DownloadNextShow\tTrying to start new download");DP1("CShowEngine::DownloadNextShow\tShows in download queue %d", count); |
1296 |
||
1297 |
if (count > 0) |
|
1298 |
{ |
|
1299 |
if (iPodcastModel.SettingsEngine().DownloadSuspended()) |
|
1300 |
{ |
|
1301 |
DP("CShowEngine::DownloadNextShow\tDownload process is suspended, ABORTING"); |
|
34 | 1302 |
// Inform the observers |
1303 |
NotifyDownloadQueueUpdatedL(); |
|
2 | 1304 |
return; |
1305 |
} |
|
1306 |
else if (iShowClient->IsActive()) |
|
1307 |
{ |
|
1308 |
DP("CShowEngine::DownloadNextShow\tDownload process is already active."); |
|
34 | 1309 |
// Inform the observers |
1310 |
NotifyDownloadQueueUpdatedL(); |
|
2 | 1311 |
return; |
1312 |
} |
|
1313 |
else |
|
1314 |
{ |
|
60 | 1315 |
if (iShowDownloading) { |
1316 |
delete iShowDownloading; |
|
1317 |
} |
|
2 | 1318 |
|
60 | 1319 |
// Start the download |
1320 |
iShowDownloading = DBGetNextDownloadL(); |
|
2 | 1321 |
|
60 | 1322 |
while(iShowDownloading != NULL) |
2 | 1323 |
{ |
60 | 1324 |
DP1("CShowEngine::DownloadNextShow\tDownloading: %S", &(iShowDownloading->Title())); |
1325 |
iShowDownloading->SetDownloadState(EDownloading); |
|
1326 |
iShowDownloading->SetLastError(KErrNone); |
|
1327 |
DBUpdateShowL(*iShowDownloading); |
|
34 | 1328 |
// Inform the observers |
1329 |
// important to do this after we change download state |
|
1330 |
NotifyDownloadQueueUpdatedL(); |
|
1331 |
||
60 | 1332 |
TRAPD(error,GetShowL(iShowDownloading)); |
1333 |
if (error == KErrNone) |
|
2 | 1334 |
{ |
1335 |
break; |
|
1336 |
} |
|
60 | 1337 |
else |
1338 |
{ |
|
1339 |
iShowDownloading->SetDownloadState(EFailedDownload); |
|
1340 |
DBRemoveDownloadL(iShowDownloading->Uid()); |
|
1341 |
DBUpdateShowL(*iShowDownloading); |
|
1342 |
CleanupStack::PopAndDestroy(iShowDownloading); |
|
1343 |
||
1344 |
iShowDownloading = DBGetNextDownloadL(); |
|
1345 |
if(iShowDownloading == NULL) |
|
1346 |
{ |
|
1347 |
iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue); |
|
1348 |
} |
|
1349 |
} |
|
2 | 1350 |
} |
1351 |
} |
|
1352 |
} |
|
1353 |
else |
|
1354 |
{ |
|
34 | 1355 |
// Inform the observers |
1356 |
NotifyDownloadQueueUpdatedL(); |
|
2 | 1357 |
iShowDownloading = NULL;DP("CShowEngine::DownloadNextShow\tNothing to download"); |
1358 |
} |
|
1359 |
DP("CShowEngine::DownloadNextShowL END"); |
|
1360 |
} |
|
1361 |
||
1362 |
void CShowEngine::NotifyDownloadQueueUpdatedL() |
|
1363 |
{ |
|
1364 |
const TInt count = iObservers.Count(); |
|
1365 |
for (TInt i = 0; i < count; i++) |
|
1366 |
{ |
|
60 | 1367 |
iObservers[i]->DownloadQueueUpdatedL(1, DBGetDownloadsCountL() - 1); |
2 | 1368 |
} |
1369 |
} |
|
1370 |
||
1371 |
void CShowEngine::NotifyShowDownloadUpdatedL(TInt aBytesOfCurrentDownload, TInt aBytesTotal) |
|
1372 |
{ |
|
1373 |
const TInt count = iObservers.Count(); |
|
1374 |
for (TInt i = 0; i < count; i++) |
|
1375 |
{ |
|
1376 |
iObservers[i]->ShowDownloadUpdatedL(aBytesOfCurrentDownload, aBytesTotal); |
|
1377 |
} |
|
1378 |
} |
|
1379 |
||
1380 |
void CShowEngine::NotifyShowFinishedL(TInt aError) |
|
1381 |
{ |
|
1382 |
const TInt count = iObservers.Count(); |
|
1383 |
for (TInt i = 0; i < count; i++) |
|
1384 |
{ |
|
1385 |
iObservers[i]->ShowDownloadFinishedL(iShowDownloading?iShowDownloading->Uid():0, aError); |
|
1386 |
} |
|
1387 |
} |
|
1388 |
||
1389 |
EXPORT_C void CShowEngine::NotifyShowListUpdatedL() |
|
1390 |
{ |
|
1391 |
for (TInt i = 0; i < iObservers.Count(); i++) |
|
1392 |
{ |
|
1393 |
iObservers[i]->ShowListUpdatedL(); |
|
1394 |
} |
|
1395 |
} |
|
1396 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1397 |
void CShowEngine::ReadMetaDataL(CShowInfo& aShowInfo) |
2 | 1398 |
{ |
1399 |
//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
|
1400 |
DBUpdateShowL(aShowInfo); |
2 | 1401 |
} |
1402 |
||
1403 |
void CShowEngine::ReadMetaDataCompleteL() |
|
1404 |
{ |
|
1405 |
NotifyShowListUpdatedL(); |
|
1406 |
MetaDataReader().SetIgnoreTrackNo(EFalse); |
|
1407 |
} |
|
1408 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1409 |
EXPORT_C void CShowEngine::UpdateShowL(CShowInfo& aInfo) |
2 | 1410 |
{ |
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
30
diff
changeset
|
1411 |
DBUpdateShowL(aInfo); |
2 | 1412 |
} |
1413 |
||
1414 |
EXPORT_C CMetaDataReader& CShowEngine::MetaDataReader() |
|
1415 |
{ |
|
1416 |
return *iMetaDataReader; |
|
1417 |
} |
|
1418 |
||
1419 |
void CShowEngine::FileError(TUint /*aError*/) |
|
1420 |
{ |
|
1421 |
iDownloadErrors = KMaxDownloadErrors; |
|
1422 |
} |
|
60 | 1423 |
|
1424 |
EXPORT_C void CShowEngine::CheckForDeletedShows(TUint aFeedUid) |
|
1425 |
{ |
|
1426 |
RShowInfoArray shows; |
|
1427 |
||
1428 |
TRAPD(err, DBGetShowsByFeedL(shows, aFeedUid)); |
|
1429 |
||
1430 |
if (err != KErrNone) |
|
1431 |
{ |
|
1432 |
// probably a catastrophic error, but it doesn't |
|
1433 |
// matter for this method |
|
1434 |
return; |
|
1435 |
} |
|
1436 |
||
1437 |
for (int i=0;i<shows.Count();i++) |
|
1438 |
{ |
|
1439 |
if (shows[i]->DownloadState() == EDownloaded && shows[i]->FileName() != KNullDesC) |
|
1440 |
{ |
|
1441 |
if(!BaflUtils::FileExists(iPodcastModel.FsSession(),shows[i]->FileName())) |
|
1442 |
{ |
|
1443 |
// file doesn't exist anymore, assume it was deleted from outside |
|
1444 |
DP1("Show %S does not exist on disk, flagging as non downloaded", &shows[i]->FileName()); |
|
1445 |
shows[i]->SetDownloadState(ENotDownloaded); |
|
1446 |
shows[i]->SetPlayState(EPlayed); |
|
1447 |
TRAP_IGNORE(DBUpdateShowL(*shows[i])); |
|
1448 |
} |
|
1449 |
} |
|
1450 |
} |
|
1451 |
} |
|
1452 |
||
148
e3f9b65d6910
Cleanup from the merge
Brendan Donegan <brendand@symbian.org>
parents:
147
diff
changeset
|
1453 |
EXPORT_C void CShowEngine::SetShowFilter(TShowFilter aFilter) |
e3f9b65d6910
Cleanup from the merge
Brendan Donegan <brendand@symbian.org>
parents:
147
diff
changeset
|
1454 |
{ |
e3f9b65d6910
Cleanup from the merge
Brendan Donegan <brendand@symbian.org>
parents:
147
diff
changeset
|
1455 |
iShowFilter = aFilter; |
e3f9b65d6910
Cleanup from the merge
Brendan Donegan <brendand@symbian.org>
parents:
147
diff
changeset
|
1456 |
} |
e3f9b65d6910
Cleanup from the merge
Brendan Donegan <brendand@symbian.org>
parents:
147
diff
changeset
|
1457 |
|
145
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1458 |
EXPORT_C void CShowEngine::MoveDownloadUpL(TUint aUid) |
130
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
1459 |
{ |
145
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1460 |
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
|
1461 |
_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
|
1462 |
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
|
1463 |
|
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1464 |
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
|
1465 |
|
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1466 |
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
|
1467 |
&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
|
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 |
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
|
1470 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1471 |
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
|
1472 |
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
|
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 |
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
|
1475 |
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
|
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 |
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
|
1478 |
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
|
1479 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1480 |
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
|
1481 |
|
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1482 |
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
|
1483 |
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
|
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 |
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
|
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 |
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
|
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 |
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
|
1490 |
} |
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 |
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
|
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 |
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
|
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 |
// 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
|
1497 |
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
|
1498 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1499 |
// 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
|
1500 |
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
|
1501 |
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
|
1502 |
|
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1503 |
// 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
|
1504 |
// 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
|
1505 |
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
|
1506 |
} |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1507 |
else |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1508 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1509 |
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
|
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 |
|
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1512 |
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
|
1513 |
} |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1514 |
else |
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 |
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
|
1517 |
} |
130
92572a695a1d
Added new experimental feature to show only new and downloaded shows; Updated SIS files
teknolog
parents:
67
diff
changeset
|
1518 |
} |
145
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1519 |
|
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1520 |
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
|
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 |
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
|
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 |
// 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
|
1525 |
_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
|
1526 |
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
|
1527 |
|
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1528 |
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
|
1529 |
|
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1530 |
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
|
1531 |
&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
|
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 |
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
|
1534 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1535 |
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
|
1536 |
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
|
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 |
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
|
1539 |
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
|
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 |
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
|
1542 |
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
|
1543 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1544 |
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
|
1545 |
|
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1546 |
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
|
1547 |
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
|
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 |
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
|
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 |
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
|
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 |
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
|
1554 |
} |
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 |
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
|
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 |
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
|
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 |
// 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
|
1561 |
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
|
1562 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1563 |
// 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
|
1564 |
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
|
1565 |
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
|
1566 |
|
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1567 |
// 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
|
1568 |
// 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
|
1569 |
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
|
1570 |
} |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1571 |
else |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1572 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1573 |
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
|
1574 |
} |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1575 |
|
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1576 |
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
|
1577 |
} |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1578 |
else |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1579 |
{ |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1580 |
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
|
1581 |
} |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1582 |
} |
cc0182a5da39
Fix for Bug 2604 and bulk of the work towards implementing Bug 2737
Brendan Donegan <brendand@symbian.org>
parents:
67
diff
changeset
|
1583 |