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