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