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