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