engine/src/ShowEngine.cpp
author teknolog
Sun, 04 Apr 2010 21:47:56 +0100
changeset 115 d87e984bd8b8
parent 112 0bd6b9a3f027
child 116 a2e43aa1ad11
permissions -rw-r--r--
Even more robustness improvements for HTTP client - specifically disk full problems
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"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    29
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
//#include <mpxmedia.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
//#include <mpxattribute.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
//#include <mpxmediageneraldefs.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
const TUint KMaxDownloadErrors = 3;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
const TInt KMimeBufLength = 100;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
CShowEngine::CShowEngine(CPodcastModel& aPodcastModel) :
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
	iPodcastModel(aPodcastModel),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
	iDB(*aPodcastModel.DB())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
	{
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
EXPORT_C CShowEngine::~CShowEngine()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
	{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
	delete iShowClient;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
	iObservers.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
	delete iShowDownloading;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
	delete iMetaDataReader;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
	iApaSession.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
EXPORT_C CShowEngine* CShowEngine::NewL(CPodcastModel& aPodcastModel)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    54
	CShowEngine* self = new (ELeave) CShowEngine(aPodcastModel);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
	CleanupStack::PushL(self);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
	self->ConstructL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
	CleanupStack::Pop(self);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
	return self;
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 void CShowEngine::GetMimeType(const TDesC& aFileName, TDes& aMimeType)
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
	aMimeType.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
	RFile file;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
	if (file.Open(iPodcastModel.FsSession(), aFileName, 0) == KErrNone)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
		if (file.Read(iRecogBuffer) == KErrNone)
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
			TDataRecognitionResult result;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    70
			if (iApaSession.RecognizeData(aFileName, iRecogBuffer, result)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    71
					== KErrNone)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    72
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    73
				aMimeType.Copy(result.iDataType.Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    74
				}
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
			}
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
	file.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
void CShowEngine::ConstructL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
	{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
	iShowClient = CHttpClient::NewL(iPodcastModel, *this);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    84
	iShowClient->SetResumeEnabled(ETrue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
	iMetaDataReader = new (ELeave) CMetaDataReader(*this, iPodcastModel.FsSession());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
	iMetaDataReader->ConstructL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
	User::LeaveIfError(iApaSession.Connect());
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
EXPORT_C void CShowEngine::SuspendDownloads()
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
	iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
	iShowClient->Stop();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
EXPORT_C void CShowEngine::ResumeDownloadsL()
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
	DP("CShowEngine::ResumeDownloadsL BEGIN");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
	if (iPodcastModel.SettingsEngine().DownloadSuspended())
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(EFalse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
		iDownloadErrors = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
		DownloadNextShowL();
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
	DP("CShowEngine::ResumeDownloadsL END");
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
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
   108
EXPORT_C void CShowEngine::RemoveAllDownloadsL()
2
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
	if (!iPodcastModel.SettingsEngine().DownloadSuspended())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
		SuspendDownloads();
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
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   115
	DBRemoveAllDownloadsL();
22
3243c9461520 Clear download queue now notifies UI
teknolog
parents: 21
diff changeset
   116
	NotifyDownloadQueueUpdatedL();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   119
EXPORT_C void CShowEngine::RemoveDownloadL(TUint aUid)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   120
	{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   121
	DP("CShowEngine::RemoveDownloadL BEGIN");
2
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
	TBool resumeAfterRemove = EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
	// if trying to remove the present download, we first stop it
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   125
	if (!iPodcastModel.SettingsEngine().DownloadSuspended() && iShowDownloading != NULL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   126
			&& iShowDownloading->Uid() == aUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   127
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
		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
   129
		SuspendDownloads();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   130
		resumeAfterRemove = ETrue;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   133
	CShowInfo *info = DBGetShowByUidL(aUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   134
	if (info != NULL)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
		info->SetDownloadState(ENotDownloaded);
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
   137
		DBUpdateShowL(*info);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
		delete info;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
		}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   140
	
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   141
	DBRemoveDownloadL(aUid);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
	// partial downloads should be removed
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
	if (iShowDownloading)
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
		BaflUtils::DeleteFile(iPodcastModel.FsSession(), iShowDownloading->FileName());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
		}
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
	NotifyShowDownloadUpdatedL(-1, -1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
	NotifyDownloadQueueUpdatedL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   152
	if (resumeAfterRemove) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
		ResumeDownloadsL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
	DownloadNextShowL();
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   157
	DP("CShowEngine::RemoveDownloadL END");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   159
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   160
void CShowEngine::Connected(CHttpClient* /*aClient*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   161
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   163
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   164
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   165
void CShowEngine::Progress(CHttpClient* /*aHttpClient */, TInt aBytes,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   166
		TInt aTotalBytes)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
	{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   168
	iShowDownloading->SetShowSize(aTotalBytes);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
	TRAP_IGNORE(NotifyShowDownloadUpdatedL(aBytes, aTotalBytes));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   170
	}
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
void CShowEngine::Disconnected(CHttpClient* /*aClient */)
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
void CShowEngine::DownloadInfo(CHttpClient* aHttpClient, TInt aTotalBytes)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   178
	DP1("About to download %d bytes", aTotalBytes);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
	if (aHttpClient == iShowClient && iShowDownloading != NULL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
			&& aTotalBytes != -1)
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
		iShowDownloading->SetShowSize(aTotalBytes);
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
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   186
void CShowEngine::GetShowL(CShowInfo *info)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   187
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   188
	CFeedInfo *feedInfo = iPodcastModel.FeedEngine().GetFeedInfoByUid(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   189
			info->FeedUid());
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   190
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
	TFileName filePath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
	filePath.Copy(iPodcastModel.SettingsEngine().BaseDir());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
	TFileName relPath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   195
	relPath.Copy(feedInfo->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
	relPath.Append('\\');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   198
	TFileName fileName;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   199
	PodcastUtils::FileNameFromUrl(info->Url(), fileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   200
	relPath.Append(fileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
	PodcastUtils::EnsureProperPathName(relPath);
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
	// complete file path is base dir + rel path
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   204
	filePath.Append(relPath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   205
	info->SetFileNameL(filePath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   207
	User::LeaveIfError(iShowClient->GetL(info->Url(), filePath));
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   210
EXPORT_C void CShowEngine::AddShowL(const CShowInfo& aItem)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   211
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   212
	DP1("CShowEngine::AddShowL, title=%S", &aItem.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
	CShowInfo *showInfo = DBGetShowByUidL(aItem.Uid());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
	if (showInfo == NULL)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
		{
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
   217
		DBAddShowL(aItem);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   218
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
		delete showInfo;	
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   222
		User::Leave(KErrAlreadyExists);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   223
		}	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   224
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   225
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   226
EXPORT_C void CShowEngine::AddObserver(MShowEngineObserver *observer)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
	iObservers.Append(observer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
EXPORT_C void CShowEngine::RemoveObserver(MShowEngineObserver *observer)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
	TInt index = iObservers.Find(observer);
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
	if (index > KErrNotFound)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   236
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
		iObservers.Remove(index);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
	}
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
void CShowEngine::AddShowToMpxCollection(CShowInfo &/*aShowInfo*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
/*	RArray<TInt> contentIDs;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
	contentIDs.AppendL( KMPXMediaIdGeneral );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
	CMPXMedia* media = CMPXMedia::NewL( contentIDs.Array() );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
	CleanupStack::PushL( media );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
	contentIDs.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
	CleanupStack::PopAndDestroy(media);   */
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
void CShowEngine::CompleteL(CHttpClient* /*aHttpClient*/, TInt aError)
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
	if (iShowDownloading != NULL)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
		{
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
   256
		DP2("CShowEngine::CompleteL file=%S, aError=%d", &iShowDownloading->FileName(), aError);		
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
		if(aError != KErrCouldNotConnect)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   258
			{
6
e211a78d3037 Fix for incorrect error handling of show downloads
teknolog
parents: 2
diff changeset
   259
			if(aError == KErrDisconnected && iPodcastModel.SettingsEngine().DownloadSuspended())
e211a78d3037 Fix for incorrect error handling of show downloads
teknolog
parents: 2
diff changeset
   260
				{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
				// no error if disconnect happened because of suspended downloading
6
e211a78d3037 Fix for incorrect error handling of show downloads
teknolog
parents: 2
diff changeset
   262
				}
e211a78d3037 Fix for incorrect error handling of show downloads
teknolog
parents: 2
diff changeset
   263
			else
e211a78d3037 Fix for incorrect error handling of show downloads
teknolog
parents: 2
diff changeset
   264
				{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
				iShowDownloading->SetLastError(aError);
6
e211a78d3037 Fix for incorrect error handling of show downloads
teknolog
parents: 2
diff changeset
   266
				}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   267
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   268
			if (aError == KErrNone)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
				TBuf<KMimeBufLength> mimeType;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
				GetMimeType(iShowDownloading->FileName(), mimeType);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
				_LIT(KMimeAudio,"audio");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
				_LIT(KMimeVideo,"video");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
				if (mimeType.Left(5) == KMimeAudio)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
					{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
					iShowDownloading->SetShowType(EAudioPodcast);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
					}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
				else if (mimeType.Left(5) == KMimeVideo)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
					{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   280
					iShowDownloading->SetShowType(EVideoPodcast);
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   283
				iShowDownloading->SetDownloadState(EDownloaded);
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
   284
				DBUpdateShowL(*iShowDownloading);
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   285
				DBRemoveDownloadL(iShowDownloading->Uid());
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   286
				AddShowToMpxCollection(*iShowDownloading);				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
				NotifyShowFinishedL(aError);
15
93d9f66bf50b Cleaning description better for second line in search results
teknolog
parents: 6
diff changeset
   288
				iDownloadErrors = 0;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   289
				delete iShowDownloading;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   290
				iShowDownloading = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
			else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
				// 400 and 500 series errors are serious errors on which probably another download will fail
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
				if(aError >= HTTPStatus::EBadRequest && aError <= HTTPStatus::EBadRequest+200)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
					{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
					iShowDownloading->SetDownloadState(EFailedDownload);
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
   298
					DBUpdateShowL(*iShowDownloading);
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   299
					DBRemoveDownloadL(iShowDownloading->Uid());
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   300
					NotifyShowFinishedL(aError);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
					delete iShowDownloading;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
					iShowDownloading = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
					}
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
   305
				else if (aError == KErrDiskFull)
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
   306
					{
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
   307
					// stop downloading immediately if disk is full
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
   308
					iShowDownloading->SetDownloadState(EQueued);
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
   309
					DBUpdateShowL(*iShowDownloading);
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
   310
					iDownloadErrors = KMaxDownloadErrors;
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
   311
					}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   312
				else // other kind of error, missing network etc, reque this show
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   313
					{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   314
					iShowDownloading->SetDownloadState(EQueued);
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
   315
					DBUpdateShowL(*iShowDownloading);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   316
					}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   317
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
   318
				NotifyDownloadQueueUpdatedL();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   319
				iDownloadErrors++;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   320
				if (iDownloadErrors > KMaxDownloadErrors)
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
					DP("Too many downloading errors, suspending downloads");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   323
					iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   324
					NotifyShowFinishedL(aError);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   325
					}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   326
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   327
			DownloadNextShowL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   328
			}		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   329
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   330
		else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   331
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   332
			// Connection error
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   333
			if(iShowDownloading)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   334
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   335
				iShowDownloading->SetDownloadState(EQueued);
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
   336
				DBUpdateShowL(*iShowDownloading);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   337
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   338
			iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   339
			NotifyShowFinishedL(aError);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   340
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   341
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   342
	}
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
EXPORT_C CShowInfo* CShowEngine::ShowDownloading()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   345
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   346
	return iShowDownloading;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   347
	}
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
EXPORT_C CShowInfo* CShowEngine::GetShowByUidL(TUint aShowUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   350
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   351
	return DBGetShowByUidL(aShowUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   352
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   353
CShowInfo* CShowEngine::DBGetShowByUidL(TUint aUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   354
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   355
	DP("CShowEngine::DBGetShowByUid");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   356
	CShowInfo *showInfo = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   357
	_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows where uid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   358
	iSqlBuffer.Format(KSqlStatement, aUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   359
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   360
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   361
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   362
	//DP1("SQL: %S", &iSqlBuffer.Left(KSqlDPLen));
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
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   365
			&st, (const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   366
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   367
	if (rc == SQLITE_OK)
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
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   370
		Cleanup_sqlite3_finalize_PushL(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   371
		if (rc == SQLITE_ROW)
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
			showInfo = CShowInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   374
			DBFillShowInfoFromStmtL(st, showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   375
			CleanupStack::Pop(showInfo);
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
		CleanupStack::PopAndDestroy();//st
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   380
	return showInfo;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   383
EXPORT_C CShowInfo* CShowEngine::DBGetShowByFileNameL(TFileName aFileName)
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
	DP("CShowEngine::DBGetShowByUid");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   386
	CShowInfo *showInfo = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   387
	_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows where filename=\"%S\"");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   388
	iSqlBuffer.Format(KSqlStatement, &aFileName);
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
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   391
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   392
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   393
			&st, (const void**) NULL);
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
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   396
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   397
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   398
		Cleanup_sqlite3_finalize_PushL(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   399
		if (rc == SQLITE_ROW)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   400
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   401
			showInfo = CShowInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   402
			DBFillShowInfoFromStmtL(st, showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   403
			CleanupStack::Pop(showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   404
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   405
		CleanupStack::PopAndDestroy();//st
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   406
		}
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
	return showInfo;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   411
void CShowEngine::DBGetAllShowsL(RShowInfoArray& aShowArray)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   412
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   413
	DP("CShowEngine::DBGetAllShows");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   414
	_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype from shows");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   415
	iSqlBuffer.Format(KSqlStatement);
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
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   418
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   419
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   420
			&st, (const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   421
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   422
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   423
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   424
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   425
		Cleanup_sqlite3_finalize_PushL(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   426
		while (rc == SQLITE_ROW)
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
			CShowInfo* showInfo = CShowInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   429
			DBFillShowInfoFromStmtL(st, showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   430
			aShowArray.Append(showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   431
			CleanupStack::Pop(showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   432
			rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   433
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   434
		CleanupStack::PopAndDestroy();//st
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   435
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   436
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   439
void CShowEngine::DBGetAllDownloadsL(RShowInfoArray& aShowArray)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   440
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   441
	DP("CShowEngine::DBGetAllDownloads");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   442
	_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, shows.uid, showsize, trackno, pubdate, showtype, lasterror from downloads, shows where downloads.uid=shows.uid");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   443
	iSqlBuffer.Format(KSqlStatement);
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
#ifndef DONT_SORT_SQL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   446
	_LIT(KSqlSort, " order by dl_index");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   447
	iSqlBuffer.Append(KSqlSort);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   448
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   449
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   450
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   451
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   452
			&st, (const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   453
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   454
	if (rc == SQLITE_OK)
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
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   457
		Cleanup_sqlite3_finalize_PushL(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   458
		while (rc == SQLITE_ROW)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   459
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   460
			CShowInfo* showInfo = CShowInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   461
			DBFillShowInfoFromStmtL(st, showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   462
			aShowArray.Append(showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   463
			CleanupStack::Pop(showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   464
			rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   465
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   466
		CleanupStack::PopAndDestroy();//st
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   467
		}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   468
	else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   469
		{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   470
		User::Leave(KErrCorrupt);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   471
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   472
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   473
	// delete downloads that don't have a show
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   474
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   475
	_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
   476
	iSqlBuffer.Format(KSqlStatement2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   477
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   478
	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
   479
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   480
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   481
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   482
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   483
		rc = sqlite3_step(st);
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   484
		CleanupStack::PopAndDestroy(); // st
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   485
		}
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   486
	else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   487
		{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   488
		User::Leave(KErrCorrupt);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   489
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   490
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   491
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   492
CShowInfo* CShowEngine::DBGetNextDownloadL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   493
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   494
	DP("CShowEngine::DBGetNextDownload");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   495
	CShowInfo *showInfo = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   496
	_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, shows.uid, showsize, trackno, pubdate, showtype, lasterror from downloads, shows where downloads.uid=shows.uid");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   497
	iSqlBuffer.Format(KSqlStatement);
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
#ifdef DONT_SORT_SQL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   500
	_LIT(KSqlSort, " limit 1");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   501
	iSqlBuffer.Append(KSqlSort);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   502
#else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   503
	_LIT(KSqlNoSort, " order by dl_index limit 1");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   504
	iSqlBuffer.Append(KSqlNoSort);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   505
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   506
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   507
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   508
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   509
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   510
			&st, (const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   511
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   512
	if (rc == SQLITE_OK)
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
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   515
		Cleanup_sqlite3_finalize_PushL(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   516
		if (rc == SQLITE_ROW)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   517
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   518
			showInfo = CShowInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   519
			DBFillShowInfoFromStmtL(st, showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   520
			CleanupStack::Pop(showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   521
			}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   522
		else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   523
			{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   524
			User::Leave(KErrUnknown);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   525
			}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   526
		CleanupStack::PopAndDestroy();//st
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   527
		}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   528
	else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   529
		{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   530
		User::Leave(KErrCorrupt);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   531
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   532
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   533
	return showInfo;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   534
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   535
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   536
void CShowEngine::DBGetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid)
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
	DP1("CShowEngine::DBGetShowsByFeed BEGIN, feedUid=%u", aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   539
	_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where feeduid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   540
	iSqlBuffer.Format(KSqlStatement, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   541
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   542
#ifndef DONT_SORT_SQL	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   543
	_LIT(KSqlOrderByDate, " order by pubdate desc");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   544
	iSqlBuffer.Append(KSqlOrderByDate);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   545
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   546
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   547
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   548
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   549
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   550
			&st, (const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   551
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   552
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   553
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   554
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   555
		Cleanup_sqlite3_finalize_PushL(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   556
		while (rc == SQLITE_ROW)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   557
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   558
			CShowInfo* showInfo = CShowInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   559
			DBFillShowInfoFromStmtL(st, showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   560
			aShowArray.Append(showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   561
			CleanupStack::Pop(showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   562
			rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   563
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   564
		CleanupStack::PopAndDestroy();//st
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   565
		}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   566
	else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   567
		{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   568
		User::Leave(KErrCorrupt);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   569
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   570
	DP("CShowEngine::DBGetShowsByFeed END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   571
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   572
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   573
TUint CShowEngine::DBGetDownloadsCountL()
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   574
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   575
	DP("CShowEngine::DBGetDownloadsCount");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   576
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   577
	_LIT(KSqlStatement, "select count(*) from downloads");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   578
	iSqlBuffer.Format(KSqlStatement);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   579
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   580
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   581
	TUint count = 0;
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
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   584
			&st, (const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   585
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   586
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   587
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   588
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   589
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   590
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   591
		if (rc == SQLITE_ROW)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   592
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   593
			count = sqlite3_column_int(st, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   594
			}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   595
		else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   596
			{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   597
			User::Leave(KErrUnknown);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   598
			}
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   599
		
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   600
		CleanupStack::PopAndDestroy(); //st
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   601
		}
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   602
	else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   603
		{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   604
		User::Leave(KErrCorrupt);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   605
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   606
	return count;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   607
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   608
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   609
void CShowEngine::DBGetDownloadedShowsL(RShowInfoArray& aShowArray)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   610
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   611
	DP("CShowEngine::DBGetDownloadedShows");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   612
	_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where downloadstate=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   613
	iSqlBuffer.Format(KSqlStatement, EDownloaded);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   614
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   615
#ifndef DONT_SORT_SQL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   616
	_LIT(KSqlSort, " order by title");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   617
	iSqlBuffer.Append(KSqlSort);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   618
#endif	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   619
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   620
	sqlite3_stmt *st;
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
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   623
			&st, (const void**) NULL);
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
	if (rc == SQLITE_OK)
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
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   628
		Cleanup_sqlite3_finalize_PushL(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   629
		while (rc == SQLITE_ROW)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   630
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   631
			CShowInfo* showInfo = CShowInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   632
			DBFillShowInfoFromStmtL(st, showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   633
			aShowArray.Append(showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   634
			CleanupStack::Pop(showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   635
			rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   636
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   637
		CleanupStack::PopAndDestroy();//st
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   638
		}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   639
	else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   640
		{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   641
		User::Leave(KErrCorrupt);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   642
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   643
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   644
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   645
void CShowEngine::DBGetNewShowsL(RShowInfoArray& aShowArray)
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
	DP("CShowEngine::DBGetNewShows");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   648
	_LIT(KSqlStatement, "select url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype, lasterror from shows where playstate=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   649
	iSqlBuffer.Format(KSqlStatement, ENeverPlayed);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   650
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   651
	sqlite3_stmt *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
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   654
			&st, (const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   655
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   656
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   657
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   658
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   659
		Cleanup_sqlite3_finalize_PushL(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   660
		while (rc == SQLITE_ROW)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   661
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   662
			CShowInfo* showInfo = CShowInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   663
			DBFillShowInfoFromStmtL(st, showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   664
			aShowArray.Append(showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   665
			CleanupStack::Pop(showInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   666
			rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   667
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   668
		CleanupStack::PopAndDestroy();//st
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   669
		}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   670
	else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   671
		{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   672
		User::Leave(KErrCorrupt);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   673
		}
2
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
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   676
void CShowEngine::DBDeleteOldShowsByFeedL(TUint aFeedUid)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   677
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   678
	DP("CShowEngine::DBDeleteOldShows");
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
	// what we do:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   681
	// 1. sort shows by pubdate
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   682
	// 2. select the first MaxListItems shows
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   683
	// 3. delete the rest if downloadstate is ENotDownloaded
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   684
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   685
	_LIT(KSqlStatement,"delete from shows where feeduid=%u and downloadstate=0 and uid not in " \
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   686
			"(select uid from shows where feeduid=%u order by pubdate desc limit %u)");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   687
	iSqlBuffer.Format(KSqlStatement, aFeedUid, aFeedUid, iPodcastModel.SettingsEngine().MaxListItems());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   688
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   689
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   690
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   691
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   692
			&st, (const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   693
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   694
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   695
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   696
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   697
		sqlite3_finalize(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   698
		}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   699
	else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   700
		{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   701
		User::Leave(KErrCorrupt);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   702
		}
2
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
	_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
   705
	iSqlBuffer.Format(KSqlStatement2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   706
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   707
	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
   708
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   709
	if (rc == SQLITE_OK)
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
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   712
		sqlite3_finalize(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   713
		}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   714
	else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   715
		{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   716
		User::Leave(KErrCorrupt);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   717
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   718
	}
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
void CShowEngine::DBFillShowInfoFromStmtL(sqlite3_stmt *st, CShowInfo* showInfo)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   721
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   722
	const void *urlz = sqlite3_column_text16(st, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   723
	TPtrC16 url((const TUint16*) urlz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   724
	showInfo->SetUrlL(url);
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
	const void *titlez = sqlite3_column_text16(st, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   727
	TPtrC16 title((const TUint16*) titlez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   728
	showInfo->SetTitleL(title);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   729
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   730
	const void *descz = sqlite3_column_text16(st, 2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   731
	TPtrC16 desc((const TUint16*) descz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   732
	showInfo->SetDescriptionL(desc);
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
	const void *filez = sqlite3_column_text16(st, 3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   735
	TPtrC16 file((const TUint16*) filez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   736
	showInfo->SetFileNameL(file);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   737
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   738
	sqlite3_int64 pos = sqlite3_column_int64(st, 4);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   739
	TTimeIntervalMicroSeconds position(pos);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   740
	showInfo->SetPosition(position);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   741
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   742
	TUint playtime = sqlite3_column_int(st, 5);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   743
	showInfo->SetPlayTime(playtime);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   744
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   745
	TUint playstate = sqlite3_column_int(st, 6);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   746
	showInfo->SetPlayState((TPlayState) playstate);
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
	TUint downloadstate = sqlite3_column_int(st, 7);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   749
	showInfo->SetDownloadState((TDownloadState) downloadstate);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   750
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   751
	TUint feeduid = sqlite3_column_int(st, 8);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   752
	showInfo->SetFeedUid(feeduid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   753
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   754
	TUint uid = sqlite3_column_int(st, 9);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   755
	showInfo->SetUid(uid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   756
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   757
	TUint showsize = sqlite3_column_int(st, 10);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   758
	showInfo->SetShowSize(showsize);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   759
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   760
	TUint trackno = sqlite3_column_int(st, 11);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   761
	showInfo->SetTrackNo((TShowType) trackno);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   762
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   763
	sqlite3_int64 pubdate = sqlite3_column_int64(st, 12);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   764
	TTime timepubdate(pubdate);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   765
	showInfo->SetPubDate(timepubdate);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   766
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   767
	TUint showtype = sqlite3_column_int(st, 13);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   768
	showInfo->SetShowType((TShowType) showtype);
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
	TInt lasterror = sqlite3_column_int(st, 14);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   771
	showInfo->SetLastError(lasterror);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   772
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   773
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   774
void CShowEngine::DBAddShowL(const CShowInfo& aItem)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   775
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   776
	DP2("CShowEngine::DBAddShow, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   777
21
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   778
	HBufC* titleBuf = HBufC::NewLC(KMaxLineLength);
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   779
	TPtr titlePtr(titleBuf->Des());
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   780
	titlePtr.Copy(aItem.Title());
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   781
	PodcastUtils::SQLEncode(titlePtr);
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   782
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   783
	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   784
	TPtr descPtr(descBuf->Des());
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   785
	descPtr.Copy(aItem.Description());
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   786
	PodcastUtils::SQLEncode(descPtr);
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   787
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   788
	_LIT(KSqlStatement, "insert into shows (url, title, description, filename, position, playtime, playstate, downloadstate, feeduid, uid, showsize, trackno, pubdate, showtype)"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   789
			" values (\"%S\",\"%S\", \"%S\", \"%S\", \"%Lu\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%u\", \"%Lu\", \"%d\")");
21
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   790
	
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   791
	iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr,
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   792
			&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   793
			aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   794
			aItem.Uid(), aItem.ShowSize(), aItem.TrackNo(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   795
			aItem.PubDate().Int64(), aItem.ShowType());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   796
21
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   797
	CleanupStack::PopAndDestroy(descBuf);
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   798
	CleanupStack::PopAndDestroy(titleBuf);
420a1b4930da SQLEncoding for showinfo added
teknolog
parents: 15
diff changeset
   799
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   800
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   801
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   802
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   803
			&st, (const void**) NULL);
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   804
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   805
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   806
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   807
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   808
		rc = sqlite3_step(st);
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   809
		if (rc != SQLITE_DONE)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   810
			{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   811
			User::Leave(KErrAlreadyExists);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   812
			}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   813
		CleanupStack::PopAndDestroy(); // st
2
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
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   816
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   817
		User::Leave(KErrCorrupt);
2
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
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   820
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   821
void CShowEngine::DBAddDownloadL(TUint aUid)
2
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
	DP1("CShowEngine::DBAddDownload, aUid=%u", aUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   824
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   825
	_LIT(KSqlStatement, "insert into downloads (uid) values (%u)");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   826
	iSqlBuffer.Format(KSqlStatement, aUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   827
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   828
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   829
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   830
			&st, (const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   831
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   832
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   833
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   834
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   835
		rc = sqlite3_step(st);
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   836
		if (rc =! SQLITE_DONE)
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   837
			{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   838
			User::Leave(KErrUnknown);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   839
			}
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   840
		CleanupStack::PopAndDestroy(); // st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   841
		}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   842
	else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   843
		{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   844
		User::Leave(KErrCorrupt);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   845
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   846
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   847
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   848
void CShowEngine::DBUpdateShowL(CShowInfo& aItem)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   849
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   850
	DP1("CShowEngine::DBUpdateShow, title='%S'", &aItem.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   851
30
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   852
	HBufC* titleBuf = HBufC::NewLC(KMaxLineLength);
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   853
	TPtr titlePtr(titleBuf->Des());
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   854
	titlePtr.Copy(aItem.Title());
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   855
	PodcastUtils::SQLEncode(titlePtr);
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   856
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   857
	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   858
	TPtr descPtr(descBuf->Des());
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   859
	descPtr.Copy(aItem.Description());
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   860
	PodcastUtils::SQLEncode(descPtr);
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   861
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   862
	_LIT(KSqlStatement, "update shows set url=\"%S\", title=\"%S\", description=\"%S\", filename=\"%S\", position=\"%Lu\","
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   863
			"playtime=\"%u\", playstate=\"%u\", downloadstate=\"%u\", feeduid=\"%u\", showsize=\"%u\", trackno=\"%u\","
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   864
			"pubdate=\"%Lu\", showtype=\"%d\", lasterror=\"%d\" where uid=\"%u\"");
30
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   865
	iSqlBuffer.Format(KSqlStatement, &aItem.Url(), &titlePtr, &descPtr,
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   866
			&aItem.FileName(), aItem.Position().Int64(), aItem.PlayTime(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   867
			aItem.PlayState(), aItem.DownloadState(), aItem.FeedUid(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   868
			aItem.ShowSize(), aItem.TrackNo(), aItem.PubDate().Int64(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   869
			aItem.ShowType(), aItem.LastError(), aItem.Uid());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   870
30
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   871
	CleanupStack::PopAndDestroy(descBuf);
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   872
	CleanupStack::PopAndDestroy(titleBuf);
7bca37ba5fa9 Added SQLEncoding for update of showinfo. Removed ABLD.BAT from repo
teknolog
parents: 22
diff changeset
   873
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   874
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   875
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   876
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   877
			&st, (const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   878
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   879
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   880
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   881
		Cleanup_sqlite3_finalize_PushL(st);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   882
		rc = sqlite3_step(st);		
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   883
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   884
		if (rc =! SQLITE_DONE)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   885
			{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   886
			User::Leave(KErrUnknown);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   887
			}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   888
		CleanupStack::PopAndDestroy(); // st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   889
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   890
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   891
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   892
		User::Leave(KErrCorrupt);
2
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
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   895
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   896
void CShowEngine::DBDeleteShowL(TUint aUid)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   897
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   898
	DP("CShowEngine::DBDeleteShow");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   899
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   900
	_LIT(KSqlStatement, "delete from shows where uid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   901
	iSqlBuffer.Format(KSqlStatement, aUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   902
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   903
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   904
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   905
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   906
			&st, (const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   907
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   908
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   909
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   910
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   911
		rc = sqlite3_step(st);
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
		if (rc =! SQLITE_DONE)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   914
			{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   915
			User::Leave(KErrUnknown);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   916
			}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   917
		CleanupStack::PopAndDestroy(); // st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   918
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   919
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   920
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   921
		User::Leave(KErrCorrupt);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   922
		}
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
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   925
void CShowEngine::DBDeleteAllShowsByFeedL(TUint aFeedUid)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   926
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   927
	DP("CShowEngine::DBDeleteAllShowsByFeed");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   928
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   929
	_LIT(KSqlStatement, "delete from shows where feeduid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   930
	iSqlBuffer.Format(KSqlStatement, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   931
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   932
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   933
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   934
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   935
			&st, (const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   936
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   937
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   938
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   939
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   940
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   941
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   942
		if (rc =! SQLITE_DONE)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   943
			{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   944
			User::Leave(KErrUnknown);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   945
			}
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   946
		CleanupStack::PopAndDestroy(); // st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   947
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   948
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   949
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   950
		User::Leave(KErrCorrupt);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   951
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   952
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   953
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   954
void CShowEngine::DBRemoveAllDownloadsL()
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   955
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   956
	DP("CShowEngine::DBRemoveAllDownloads");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   957
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   958
	_LIT(KSqlStatement, "delete from downloads");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   959
	iSqlBuffer.Format(KSqlStatement);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   960
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   961
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   962
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   963
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   964
			&st, (const void**) NULL);
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
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   967
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   968
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   969
		sqlite3_finalize(st);
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
	else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   972
		{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   973
		User::Leave(KErrCorrupt);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   974
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   975
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   976
	_LIT(KSqlStatement2, "update shows set downloadstate=0 where downloadstate=1");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   977
	iSqlBuffer.Format(KSqlStatement2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   978
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   979
	rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, &st,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   980
			(const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   981
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   982
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   983
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   984
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   985
		rc = sqlite3_step(st);
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   986
		if (rc =! SQLITE_DONE)
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   987
			{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   988
			User::Leave(KErrUnknown);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   989
			}
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   990
		CleanupStack::PopAndDestroy(); // st
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   991
		}
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   992
	else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   993
		{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   994
		User::Leave(KErrCorrupt);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   995
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   996
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
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
   999
void CShowEngine::DBRemoveDownloadL(TUint aUid)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1000
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1001
	DP("CShowEngine::DBRemoveDownload");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1002
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1003
	_LIT(KSqlStatement, "delete from downloads where uid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1004
	iSqlBuffer.Format(KSqlStatement, aUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1005
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1006
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1007
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1008
	int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1009
			&st, (const void**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1010
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1011
	if (rc == SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1012
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1013
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1014
		rc = sqlite3_step(st);
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1015
		if (rc =! SQLITE_DONE)
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1016
			{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1017
			User::Leave(KErrUnknown);
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1018
			}
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1019
		CleanupStack::PopAndDestroy(); // st
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1020
		}
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1021
	else
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1022
		{
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1023
		User::Leave(KErrCorrupt);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1024
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1025
	}
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
EXPORT_C CShowInfo* CShowEngine::GetNextShowByTrackL(CShowInfo* aShowInfo)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1028
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1029
	CShowInfo* nextShow = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1030
	RShowInfoArray array;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1031
	DBGetShowsByFeedL(array, aShowInfo->FeedUid());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1032
	TUint diff = KMaxTInt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1033
	for (TInt loop = 0; loop < array.Count(); loop++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1034
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1035
		if (aShowInfo->TrackNo() < array[loop]->TrackNo())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1036
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1037
			if ((array[loop]->TrackNo() - aShowInfo->TrackNo()) < diff)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1038
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1039
				diff = array[loop]->TrackNo() - aShowInfo->TrackNo();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1040
				nextShow = array[loop];
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
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1044
	array.ResetAndDestroy();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1045
	return nextShow;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1046
	}
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
TBool CShowEngine::CompareShowsByUid(const CShowInfo &a, const CShowInfo &b)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1049
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1050
	return a.Uid() == b.Uid();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1051
	}
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
TInt CShowEngine::CompareShowsByDate(const CShowInfo &a, const CShowInfo &b)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1054
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1055
	if (a.PubDate() > b.PubDate())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1056
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1057
		//		DP2("Sorting %S less than %S", &a.iTitle, &b.iTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1058
		return -1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1059
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1060
	else if (a.PubDate() == b.PubDate())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1061
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1062
		//		DP2("Sorting %S equal to %S", &a.iTitle, &b.iTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1063
		return 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1064
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1065
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1066
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1067
		//		DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1068
		return 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1069
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1070
	}
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
TInt CShowEngine::CompareShowsByTrackNo(const CShowInfo &a, const CShowInfo &b)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1073
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1074
	if (a.TrackNo() < b.TrackNo())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1075
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1076
		return -1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1077
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1078
	else if (a.TrackNo() == b.TrackNo())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1079
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1080
		return 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1081
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1082
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1083
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1084
		return 1;
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
TInt CShowEngine::CompareShowsByTitle(const CShowInfo &a, const CShowInfo &b)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1089
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1090
	if (a.Title() < b.Title())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1091
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1092
		//		DP2("Sorting %S less than %S", &a.iTitle, &b.iTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1093
		return -1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1094
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1095
	else if (a.Title() == b.Title())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1096
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1097
		//		DP2("Sorting %S equal to %S", &a.iTitle, &b.iTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1098
		return 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1099
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1100
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1101
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1102
		//		DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1103
		return 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1104
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1105
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1106
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
  1107
EXPORT_C void CShowEngine::DeletePlayedShowsL(RShowInfoArray &aShowInfoArray)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1108
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1109
	for (TInt i = 0; i < aShowInfoArray.Count(); i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1110
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1111
		if (aShowInfoArray[i]->PlayState() == EPlayed
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1112
				&& aShowInfoArray[i]->FileName().Length() > 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1113
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1114
			BaflUtils::DeleteFile(iPodcastModel.FsSession(), aShowInfoArray[i]->FileName());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1115
			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
  1116
			DBUpdateShowL(*aShowInfoArray[i]);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1117
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1118
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1119
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1120
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1121
EXPORT_C void CShowEngine::DeleteAllShowsByFeedL(TUint aFeedUid, TBool aDeleteFiles)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1122
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1123
	RShowInfoArray array;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1124
	DBGetShowsByFeedL(array, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1125
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1126
	const TInt count = array.Count();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1127
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1128
	for (TInt i = count - 1; i >= 0; i--)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1129
		{
53
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1130
		if (iShowDownloading && iShowDownloading->Uid() == array[i]->Uid())
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1131
			{
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1132
			// trying to delete the active download
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1133
			RemoveDownloadL(iShowDownloading->Uid());
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1134
			}
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1135
		
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1136
		// delete downloaded file
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1137
		if (array[i]->FileName().Length() > 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1138
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1139
			if (aDeleteFiles)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1140
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1141
				BaflUtils::DeleteFile(iPodcastModel.FsSession(), array[i]->FileName());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1142
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1143
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1144
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1145
	array.ResetAndDestroy();
53
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1146
	
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1147
	// delete all shows from DB
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1148
	DBDeleteAllShowsByFeedL(aFeedUid);
53
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1149
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1150
	// this will clear out deleted shows from the download queue
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1151
	DBGetAllDownloadsL(array);
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1152
	array.ResetAndDestroy();
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1153
b778853e60a7 Fix for bug 2217
teknolog
parents: 44
diff changeset
  1154
	NotifyDownloadQueueUpdatedL();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1155
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1156
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1157
EXPORT_C void CShowEngine::DeleteOldShowsByFeedL(TUint aFeedUid)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1158
	{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1159
	DBDeleteOldShowsByFeedL(aFeedUid);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1160
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1161
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1162
EXPORT_C void CShowEngine::DeleteShowL(TUint aShowUid, TBool aRemoveFile)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1163
	{
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 *info = DBGetShowByUidL(aShowUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1166
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1167
	if (info != NULL)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1168
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1169
		if (info->FileName().Length() > 0 && aRemoveFile)
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
			BaflUtils::DeleteFile(iPodcastModel.FsSession(), info->FileName());
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
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1174
		info->SetDownloadState(ENotDownloaded);
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
  1175
		DBUpdateShowL(*info);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1176
		delete info;
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
EXPORT_C void CShowEngine::GetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1181
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1182
	DP("CShowEngine::GetShowsByFeed");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1183
	DBGetShowsByFeedL(aShowArray, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1184
	}
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
EXPORT_C void CShowEngine::GetAllShowsL(RShowInfoArray &aArray)
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
	DP("CShowEngine::GetAllShows");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1189
	DBGetAllShowsL(aArray);
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1192
EXPORT_C void CShowEngine::GetShowsDownloadedL(RShowInfoArray &aArray)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1193
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1194
	DP("CShowEngine::GetShowsDownloaded");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1195
	DBGetDownloadedShowsL(aArray);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1196
	}
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
EXPORT_C void CShowEngine::GetNewShowsL(RShowInfoArray &aArray)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1199
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1200
	DP("CShowEngine::GetNewShows");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1201
	DBGetNewShowsL(aArray);
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1204
EXPORT_C void CShowEngine::GetShowsDownloadingL(RShowInfoArray &aArray)
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
	DP("CShowEngine::GetShowsDownloading");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1207
	DBGetAllDownloadsL(aArray);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1208
	}
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
EXPORT_C TInt CShowEngine::GetNumDownloadingShows()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1211
	{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1212
	TUint count;
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1213
	TRAP_IGNORE(count = DBGetDownloadsCountL());
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1214
		
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1215
	return (const TInt) count;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1216
	}
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
EXPORT_C void CShowEngine::AddDownloadL(CShowInfo& aInfo)
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
	aInfo.SetDownloadState(EQueued);
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
  1221
	DBUpdateShowL(aInfo);
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1222
	DBAddDownloadL(aInfo.Uid());
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1223
	DownloadNextShowL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1224
	}
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
void CShowEngine::DownloadNextShowL()
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
	DP("CShowEngine::DownloadNextShowL BEGIN");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1229
	// Check if we have anything in the download queue
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1230
	const TInt count = DBGetDownloadsCountL();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1231
	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
  1232
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1233
	if (count > 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1234
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1235
		if (iPodcastModel.SettingsEngine().DownloadSuspended())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1236
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1237
			DP("CShowEngine::DownloadNextShow\tDownload process is suspended, ABORTING");
34
a6046405f1aa Fix for download icons not updating correctly
teknolog
parents: 30
diff changeset
  1238
			// Inform the observers
a6046405f1aa Fix for download icons not updating correctly
teknolog
parents: 30
diff changeset
  1239
			NotifyDownloadQueueUpdatedL();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1240
			return;
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
		else if (iShowClient->IsActive())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1243
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1244
			DP("CShowEngine::DownloadNextShow\tDownload process is already active.");
34
a6046405f1aa Fix for download icons not updating correctly
teknolog
parents: 30
diff changeset
  1245
			// Inform the observers
a6046405f1aa Fix for download icons not updating correctly
teknolog
parents: 30
diff changeset
  1246
			NotifyDownloadQueueUpdatedL();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1247
			return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1248
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1249
		else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1250
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1251
			// Start the download
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1252
			CShowInfo *info = DBGetNextDownloadL();
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
  1253
			CleanupStack::PushL(info);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1254
			while(info != NULL)
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
				DP1("CShowEngine::DownloadNextShow\tDownloading: %S", &(info->Title()));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1257
				info->SetDownloadState(EDownloading);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1258
				info->SetLastError(KErrNone);
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
  1259
				DBUpdateShowL(*info);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1260
				iShowDownloading = info;
34
a6046405f1aa Fix for download icons not updating correctly
teknolog
parents: 30
diff changeset
  1261
				// Inform the observers
a6046405f1aa Fix for download icons not updating correctly
teknolog
parents: 30
diff changeset
  1262
				// important to do this after we change download state
a6046405f1aa Fix for download icons not updating correctly
teknolog
parents: 30
diff changeset
  1263
				NotifyDownloadQueueUpdatedL();
a6046405f1aa Fix for download icons not updating correctly
teknolog
parents: 30
diff changeset
  1264
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1265
				TRAPD(error,GetShowL(info));
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1266
				if (error != KErrNone)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1267
					{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1268
					info->SetDownloadState(EFailedDownload);
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1269
					DBRemoveDownloadL(info->Uid());
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
  1270
					DBUpdateShowL(*info);
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
  1271
					CleanupStack::PopAndDestroy(info);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1272
					info = DBGetNextDownloadL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1273
					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1274
					if(info == NULL)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1275
						{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1276
						iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1277
						iShowDownloading = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1278
						}
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
  1279
					else
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
  1280
						{
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
  1281
						CleanupStack::PushL(info);
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
  1282
						}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1283
					}				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1284
				else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1285
					{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1286
					break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1287
					}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1288
				}
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 112
diff changeset
  1289
			CleanupStack::Pop(info); // lives on as iShowDownloading
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1290
			}
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
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1293
		{
34
a6046405f1aa Fix for download icons not updating correctly
teknolog
parents: 30
diff changeset
  1294
		// Inform the observers
a6046405f1aa Fix for download icons not updating correctly
teknolog
parents: 30
diff changeset
  1295
		NotifyDownloadQueueUpdatedL();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1296
		iShowDownloading = NULL;DP("CShowEngine::DownloadNextShow\tNothing to download");
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
	DP("CShowEngine::DownloadNextShowL END");
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
void CShowEngine::NotifyDownloadQueueUpdatedL()
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
	const TInt count = iObservers.Count();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1304
	for (TInt i = 0; i < count; i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1305
		{
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 109
diff changeset
  1306
		iObservers[i]->DownloadQueueUpdatedL(1, DBGetDownloadsCountL() - 1);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1307
		}
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
void CShowEngine::NotifyShowDownloadUpdatedL(TInt aBytesOfCurrentDownload, TInt aBytesTotal)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1311
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1312
	const TInt count = iObservers.Count();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1313
	for (TInt i = 0; i < count; i++)
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
			iObservers[i]->ShowDownloadUpdatedL(aBytesOfCurrentDownload, aBytesTotal);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1316
		}
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1319
void CShowEngine::NotifyShowFinishedL(TInt aError)
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
	const TInt count = iObservers.Count();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1322
		for (TInt i = 0; i < count; i++)
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
				iObservers[i]->ShowDownloadFinishedL(iShowDownloading?iShowDownloading->Uid():0, aError);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1325
			}
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::NotifyShowListUpdatedL()
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
	for (TInt i = 0; i < iObservers.Count(); i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1331
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1332
		iObservers[i]->ShowListUpdatedL();
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
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1335
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
  1336
void CShowEngine::ReadMetaDataL(CShowInfo& aShowInfo)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1337
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1338
	//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
  1339
	DBUpdateShowL(aShowInfo);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1340
	}
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
void CShowEngine::ReadMetaDataCompleteL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1343
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1344
	NotifyShowListUpdatedL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1345
	MetaDataReader().SetIgnoreTrackNo(EFalse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1346
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1347
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
  1348
EXPORT_C void CShowEngine::UpdateShowL(CShowInfo& aInfo)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1349
	{
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 30
diff changeset
  1350
	DBUpdateShowL(aInfo);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1351
	}
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
EXPORT_C CMetaDataReader& CShowEngine::MetaDataReader()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1354
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1355
	return *iMetaDataReader;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1356
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1357
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1358
void CShowEngine::FileError(TUint /*aError*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1359
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1360
	iDownloadErrors = KMaxDownloadErrors;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1361
	}