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