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