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