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