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