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