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