engine/src/FeedEngine.cpp
author Sebastian Brannstrom <sebastianb@symbian.org>
Fri, 09 Jul 2010 11:34:00 +0100
branchasynchparser
changeset 171 cc1be3797632
parent 167 4bfc2fcec5f6
permissions -rw-r--r--
First implementation of asynchronous feed parser
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 "FeedEngine.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    20
#include <f32file.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    21
#include <bautils.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    22
#include <s32file.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
#include "SettingsEngine.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
#include "ShowEngine.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 "OpmlParser.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    27
#include "PodcastUtils.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    28
#include <utf.h>
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    29
#include "Podcatcher.pan"
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    31
_LIT(KFeedParseStorePath, "feeds\\");
2
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
CFeedEngine* CFeedEngine::NewL(CPodcastModel& aPodcastModel)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
	CFeedEngine* self = new (ELeave) CFeedEngine(aPodcastModel);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
	CleanupStack::PushL(self);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
	self->ConstructL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
	CleanupStack::Pop(self);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
	return self;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    41
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
void CFeedEngine::ConstructL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
	{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
    44
	iParser = CFeedParser::NewLC(*this, iPodcastModel.FsSession());
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
	iFeedClient = CHttpClient::NewL(iPodcastModel, *this);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
	iFeedTimer.ConstructL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
	
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    49
	TInt err = KErrNone;
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    50
	TInt feedCount = 0;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
	
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    52
	TRAP(err, feedCount = DBGetFeedCountL());
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    53
    if (err == KErrNone && feedCount > 0)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    54
    	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
		DP("Loading feeds from DB");
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    56
		TRAP(err, DBLoadFeedsL());
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    57
    	}		
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    58
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
    
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    60
	if (err != KErrNone || iPodcastModel.IsFirstStartup()) {
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    61
		TFileName defaultFile = iPodcastModel.SettingsEngine().DefaultFeedsFileName();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
		DP1("Loading default feeds from %S", &defaultFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
		if (BaflUtils::FileExists(iPodcastModel.FsSession(), defaultFile)) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
			ImportFeedsL(defaultFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
		}
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    66
	} 
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    67
	
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    68
	// clean out feeds temp directory
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    69
	TFileName feedTempPath;
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    70
	feedTempPath.Copy (iPodcastModel.SettingsEngine().PrivatePath ());
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    71
	feedTempPath.Append(KFeedParseStorePath);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    72
	feedTempPath.Append(_L("*"));
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    73
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    74
	BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), feedTempPath);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    75
	BaflUtils::DeleteFile(iPodcastModel.FsSession(),feedTempPath);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    76
    
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
    TFileName importFile = iPodcastModel.SettingsEngine().ImportFeedsFileName();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
    if (BaflUtils::FileExists(iPodcastModel.FsSession(), importFile)) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
    	DP("Importing feeds");
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    80
    	TRAP_IGNORE(ImportFeedsL(importFile));
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
		}
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    82
    
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
    83
	CleanupStack::Pop(iParser);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
    84
	RunFeedTimer();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
CFeedEngine::CFeedEngine(CPodcastModel& aPodcastModel)
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
    88
		: iEngineState(EIdle),
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
		  iFeedTimer(this),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
		  iPodcastModel(aPodcastModel),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
		  iDB(*aPodcastModel.DB())
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
CFeedEngine::~CFeedEngine()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
	iObservers.Close();
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
	iFeedsUpdating.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
	iSortedFeeds.ResetAndDestroy();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
	iSearchResults.ResetAndDestroy();
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
	delete iParser;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
	delete iFeedClient;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
	delete iOpmlParser;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
/**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
 * Returns the current internal state of the feed engine4
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
 */
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   111
EXPORT_C TFeedEngineState CFeedEngine::ClientState()
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
	{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   113
	return iEngineState;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
/**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
 * Returns the current updating client UID if clientstate is != ENotUpdateing
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
 * @return TUint
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
EXPORT_C TUint CFeedEngine::ActiveClientUid()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   122
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   123
	if(iActiveFeed != NULL)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   125
		return iActiveFeed->Uid();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   126
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   127
	return 0;	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   129
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   130
void CFeedEngine::RunFeedTimer()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
	iFeedTimer.Cancel();
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
	if (iPodcastModel.SettingsEngine().UpdateAutomatically() != EAutoUpdateOff)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
		TInt interval = iPodcastModel.SettingsEngine().UpdateFeedInterval();
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
		if (interval != 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   140
			iFeedTimer.SetPeriod(interval);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   141
			iFeedTimer.RunPeriodically();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   145
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   146
EXPORT_C void CFeedEngine::UpdateAllFeedsL(TBool aAutoUpdate)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
	{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   148
	if (iEngineState != EIdle)
83
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   149
		{
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   150
		User::Leave(KErrInUse);
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   151
		}
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   152
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
	iAutoUpdatedInitiator = aAutoUpdate;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
	if (iFeedsUpdating.Count() > 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
		DP("Cancelling update");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   157
		iFeedClient->Stop();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
		iFeedsUpdating.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   159
		return;
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
	TInt cnt = iSortedFeeds.Count();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   163
	for (int i=0;i<cnt;i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   164
		{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   165
		iFeedsUpdating.Append(iSortedFeeds[i]->Uid());
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   166
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   168
	UpdateNextFeedL();
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
EXPORT_C void CFeedEngine::CancelUpdateAllFeeds()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
	{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   173
	if(iEngineState != EIdle)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
		{
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   175
		iCancelRequested = ETrue;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
		iFeedsUpdating.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
		iFeedClient->Stop();
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
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
void CFeedEngine::UpdateNextFeedL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
	DP1("UpdateNextFeed. %d feeds left to update", iFeedsUpdating.Count());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
	
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   185
	if (iEngineState != EIdle)
83
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   186
		{
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   187
		User::Leave(KErrInUse);
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   188
		}
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   189
	
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   190
	// reset active feed, will be set again in UpdateFeedL if needed
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   191
	iActiveFeed = NULL;
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   192
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
	if (iFeedsUpdating.Count() > 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
		{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   195
		CFeedInfo *info = GetFeedInfoByUid(iFeedsUpdating[0]);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
		iFeedsUpdating.Remove(0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
		
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   198
		if (info == NULL)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   199
			{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   200
			UpdateNextFeedL();
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   201
			}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   202
		else
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   203
			{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   204
			TBool result = EFalse;
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   205
			//DP2("** UpdateNextFeed: %S, ID: %u", &(info->Url()), info->Uid());
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   206
			TRAPD(error, result = UpdateFeedL(info->Uid()));
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   207
			
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   208
			if (error != KErrNone || !result)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
				{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   210
				DP("Error while updating all feeds");
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   211
				for (TInt i=0;i<iObservers.Count();i++) 
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   212
					{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   213
					TRAP_IGNORE(iObservers[i]->FeedUpdateAllCompleteL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate));
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   214
					}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
			}
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
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
		{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   220
		iEngineState = EIdle;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
		for (TInt i=0;i<iObservers.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   222
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   223
			TRAP_IGNORE(iObservers[i]->FeedUpdateAllCompleteL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   224
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   225
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   226
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
EXPORT_C TBool CFeedEngine::UpdateFeedL(TUint aFeedUid)
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
	DP("FeedEngine::UpdateFeedL BEGIN");
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   231
	
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   232
	if (iActiveFeed)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   233
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   234
		User::Leave(KErrInUse);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   235
		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   236
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
	iActiveFeed = GetFeedInfoByUid(aFeedUid);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   238
	
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   239
	iCancelRequested = EFalse;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
	if (iActiveFeed->LastUpdated() == 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
		{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   243
		iNewFeed = ETrue;	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
		}
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   245
	
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   246
	iShowsAdded = 0;
83
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   247
	
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   248
	iActiveFeed->SetLastError(KErrNone);
36
e010fc411ddc Merge, plus minor fix to CFeedEngine
Brendan Donegan <brendand@symbian.org>
parents: 35 32
diff changeset
   249
	DBUpdateFeedL(*iActiveFeed);
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   250
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
	iUpdatingFeedFileName.Copy (iPodcastModel.SettingsEngine().PrivatePath ());
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   252
	iUpdatingFeedFileName.Append(KFeedParseStorePath);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   253
	BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), iUpdatingFeedFileName);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   254
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
	_LIT(KFileNameFormat, "%lu.xml");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
	iUpdatingFeedFileName.AppendFormat(KFileNameFormat, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
	
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   258
	iEngineState = EDownloadingFeed;
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   259
			
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   260
	for (TInt i=0;i<iObservers.Count();i++)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   261
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   262
		TRAP_IGNORE(iObservers[i]->FeedDownloadStartedL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate, iActiveFeed->Uid()));
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   263
		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   264
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
	if(iFeedClient->GetL(iActiveFeed->Url(), iUpdatingFeedFileName, iPodcastModel.SettingsEngine().SpecificIAP()))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   267
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   268
		DP("FeedEngine::UpdateFeedL END, return ETrue");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
		return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
		DP("FeedEngine::UpdateFeedL END, return EFalse");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
		return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
	}
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
void CFeedEngine::NewShowL(CShowInfo& aItem)
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
	HBufC* description = HBufC::NewLC(KMaxDescriptionLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   281
	TPtr ptr(description->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
	ptr.Copy(aItem.Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   283
	PodcastUtils::CleanHtmlL(ptr);
8
aab3aa4acdd6 Checked all TRAP_IGNORE
teknolog
parents: 7
diff changeset
   284
aab3aa4acdd6 Checked all TRAP_IGNORE
teknolog
parents: 7
diff changeset
   285
	aItem.SetDescriptionL(*description);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   286
	CleanupStack::PopAndDestroy(description);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   288
	if (iNewFeed) {
83
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   289
		// for new feeds, set all shows played
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   290
		aItem.SetPlayState(EPlayed);
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   291
		// except the first one
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   292
		if (iShowsAdded == 0) {
83
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   293
			aItem.SetPlayState(ENeverPlayed);	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
	
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   297
	TRAPD(err, iPodcastModel.ShowEngine().AddShowL(aItem));
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   298
	
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   299
	if (err == KErrNone && aItem.PlayState() == ENeverPlayed && 
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   300
			iPodcastModel.SettingsEngine().DownloadAutomatically()) 
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
		iPodcastModel.ShowEngine().AddDownloadL(aItem);
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   303
		iShowsAdded++;
83
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   304
		}
daef3a71bac5 Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents: 67
diff changeset
   305
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   306
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   307
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   308
void CFeedEngine::GetFeedImageL(CFeedInfo *aFeedInfo)
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
	DP("GetFeedImage");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   311
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   312
	TFileName filePath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   313
	filePath.Copy(iPodcastModel.SettingsEngine().BaseDir());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   314
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   315
	// create relative file name
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   316
	TFileName relPath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   317
	relPath.Copy(aFeedInfo->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   318
	relPath.Append('\\');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   319
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   320
	TFileName fileName;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   321
	PodcastUtils::FileNameFromUrl(aFeedInfo->ImageUrl(), fileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   322
	relPath.Append(fileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   323
	PodcastUtils::EnsureProperPathName(relPath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   324
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   325
	// complete file path is base dir + rel path
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   326
	filePath.Append(relPath);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   327
	aFeedInfo->SetImageFileNameL(filePath, NULL);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   328
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   329
	if(iFeedClient->GetL(aFeedInfo->ImageUrl(), filePath, ETrue))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   330
		{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   331
			iEngineState = EDownloadingImage;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   332
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   333
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   334
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   335
EXPORT_C TBool CFeedEngine::AddFeedL(const CFeedInfo&aItem) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   336
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   337
	DP2("CFeedEngine::AddFeed, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   338
	for (TInt i=0;i<iSortedFeeds.Count();i++) 
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
		if (iSortedFeeds[i]->Uid() == aItem.Uid()) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   341
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   342
			DP1("Already have feed %S, discarding", &aItem.Url());			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   343
			return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   344
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   345
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   346
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   347
	TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   348
	CFeedInfo* newItem = aItem.CopyL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   349
	CleanupStack::PushL(newItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   350
	User::LeaveIfError(iSortedFeeds.InsertInOrder(newItem, sortOrder));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   351
	CleanupStack::Pop(newItem);
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   354
	// Save the feeds into DB
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   355
	DBAddFeedL(aItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   356
	return ETrue;
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
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   359
void CFeedEngine::DBAddFeedL(const CFeedInfo& aItem)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   360
	{
164
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 130
diff changeset
   361
	DP2("CFeedEngine::DBAddFeed BEGIN, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   362
	
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   363
	CFeedInfo *info;
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   364
	
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   365
	TRAPD(err, info = DBGetFeedInfoByUidL(aItem.Uid()));
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   366
	
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   367
	if (err == KErrNone && info) {
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   368
		delete info;
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   369
		User::Leave(KErrAlreadyExists);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   370
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   371
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   372
	HBufC* titleBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   373
	TPtr titlePtr(titleBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   374
	titlePtr.Copy(aItem.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   375
	PodcastUtils::SQLEncode(titlePtr);
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
	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   378
	TPtr descPtr(descBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   379
	descPtr.Copy(aItem.Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   380
	PodcastUtils::SQLEncode(descPtr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   381
	
164
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 130
diff changeset
   382
	_LIT(KSqlStatement, "insert into feeds (url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror) values (\"%S\",\"%S\", \"%S\", \"%S\", \"%S\", \"%S\", \"%Ld\", \"%Ld\", \"%u\", \"%u\", \"%u\", \"%d\")");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   383
	iSqlBuffer.Format(KSqlStatement,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   384
			&aItem.Url(), titleBuf, descBuf, &aItem.ImageUrl(), &aItem.ImageFileName(), &aItem.Link(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   385
			aItem.BuildDate().Int64(), aItem.LastUpdated().Int64(), aItem.Uid(), EAudioPodcast, aItem.CustomTitle(), aItem.LastError());
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
	CleanupStack::PopAndDestroy(descBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   388
	CleanupStack::PopAndDestroy(titleBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   389
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   390
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   391
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   392
	int rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &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
		{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   396
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   397
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   398
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   399
		if (rc != SQLITE_DONE)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   400
			{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   401
			User::Leave(KErrCorrupt);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   402
			}
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   403
		CleanupStack::PopAndDestroy(); // st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   404
		}
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   405
	else
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   406
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   407
		User::Leave(KErrCorrupt);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   408
		}
164
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 130
diff changeset
   409
	DP("CFeedEngine::DBAddFeed END");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   410
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   411
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   412
EXPORT_C void CFeedEngine::RemoveFeedL(TUint aUid) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   413
	{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   414
	if (iActiveFeed && iActiveFeed->Uid() == aUid)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   415
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   416
		User::Leave(KErrInUse);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   417
		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   418
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   419
	for (int i=0;i<iSortedFeeds.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   420
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   421
		if (iSortedFeeds[i]->Uid() == aUid) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   422
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   423
			iPodcastModel.ShowEngine().DeleteAllShowsByFeedL(aUid);
53
b778853e60a7 Fix for bug 2217
teknolog
parents: 36
diff changeset
   424
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   425
			CFeedInfo* feedToRemove = iSortedFeeds[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   426
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   427
			//delete the image file if it exists
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   428
			if ((feedToRemove->ImageFileName().Length() >0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   429
					&& BaflUtils::FileExists(iPodcastModel.FsSession(), feedToRemove->ImageFileName()))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   430
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   431
				iPodcastModel.FsSession().Delete(feedToRemove->ImageFileName());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   432
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   433
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   434
			//delete the folder. It has the same name as the title.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   435
			TFileName filePath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   436
			filePath.Copy(iPodcastModel.SettingsEngine().BaseDir());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   437
			filePath.Append(feedToRemove->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   438
			filePath.Append('\\');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   439
			iPodcastModel.FsSession().RmDir(filePath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   440
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   441
			iSortedFeeds.Remove(i);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   442
			delete feedToRemove;
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
			DP("Removed feed from array");
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
			// now remove it from DB
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   447
			DBRemoveFeedL(aUid);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   448
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   449
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   450
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   451
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   452
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   453
void CFeedEngine::DBRemoveFeedL(TUint aUid)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   454
	{
164
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 130
diff changeset
   455
	DP("CFeedEngine::DBRemoveFeed BEGIN");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   456
	_LIT(KSqlStatement, "delete from feeds where uid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   457
	iSqlBuffer.Format(KSqlStatement, aUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   458
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   459
	sqlite3_stmt *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
	int 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
   462
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   463
	if (rc==SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   464
		{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   465
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   466
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   467
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   468
		if (rc != SQLITE_DONE)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   469
			{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   470
			User::Leave(KErrNotFound);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   471
			}
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   472
		
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   473
		CleanupStack::PopAndDestroy(); //st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   474
		}
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   475
	else
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   476
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   477
		User::Leave(KErrCorrupt);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   478
		}
164
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 130
diff changeset
   479
	DP("CFeedEngine::DBRemoveFeed END");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   480
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   481
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   482
void CFeedEngine::DBUpdateFeedL(const CFeedInfo &aItem)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   483
	{
164
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 130
diff changeset
   484
	DP2("CFeedEngine::DBUpdateFeed BEGIN, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   485
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   486
	HBufC* titleBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   487
	TPtr titlePtr(titleBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   488
	titlePtr.Copy(aItem.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   489
	PodcastUtils::SQLEncode(titlePtr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   490
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   491
	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   492
	TPtr descPtr(descBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   493
	descPtr.Copy(aItem.Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   494
	PodcastUtils::SQLEncode(descPtr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   495
	
164
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 130
diff changeset
   496
	_LIT(KSqlStatement, "update feeds set url=\"%S\", title=\"%S\", description=\"%S\", imageurl=\"%S\", imagefile=\"%S\", link=\"%S\", built=\"%Lu\", lastupdated=\"%Lu\", feedtype=\"%u\", customtitle=\"%u\", lasterror=\"%d\" where uid=\"%u\"");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   497
	iSqlBuffer.Format(KSqlStatement,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   498
			&aItem.Url(), titleBuf, descBuf, &aItem.ImageUrl(), &aItem.ImageFileName(), &aItem.Link(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   499
			aItem.BuildDate().Int64(), aItem.LastUpdated().Int64(), EAudioPodcast, aItem.CustomTitle(), aItem.LastError(), aItem.Uid());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   500
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   501
	CleanupStack::PopAndDestroy(descBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   502
	CleanupStack::PopAndDestroy(titleBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   503
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   504
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   505
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   506
	int 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
   507
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   508
	if (rc==SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   509
		{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   510
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   511
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   512
		
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   513
		if (rc != SQLITE_DONE)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   514
			{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   515
			User::Leave(KErrNotFound);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   516
			}
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   517
		CleanupStack::PopAndDestroy(); //st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   518
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   519
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   520
		{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   521
		User::Leave(KErrCorrupt);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   522
		}
164
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 130
diff changeset
   523
	DP("CFeedEngine::DBUpdateFeed END");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   524
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   525
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   526
void CFeedEngine::ParsingCompleteL(CFeedInfo *item)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   527
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   528
	TBuf<KMaxLineLength> title;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   529
	title.Copy(item->Title());
8
aab3aa4acdd6 Checked all TRAP_IGNORE
teknolog
parents: 7
diff changeset
   530
	item->SetTitleL(title); // if this leaves we are out of memory
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   531
	CompleteL(NULL, KErrNone);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   532
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   533
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   534
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   535
EXPORT_C void CFeedEngine::AddObserver(MFeedEngineObserver *observer)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   536
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   537
	iObservers.Append(observer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   538
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   539
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   540
EXPORT_C void CFeedEngine::RemoveObserver(MFeedEngineObserver *observer)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   541
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   542
	TInt index = iObservers.Find(observer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   543
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   544
	if (index > KErrNotFound)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   545
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   546
		iObservers.Remove(index);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   547
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   548
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   549
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   550
void CFeedEngine::Connected(CHttpClient* /*aClient*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   551
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   552
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   553
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   554
void CFeedEngine::Progress(CHttpClient* /*aHttpClient*/, TInt /*aBytes*/, TInt /*aTotalBytes*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   555
	{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   556
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   557
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   558
void CFeedEngine::CompleteL(CHttpClient* /*aClient*/, TInt aError)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   559
	{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   560
	DP2("CFeedEngine::CompleteL BEGIN, iEngineState=%d, aSuccessful=%d", iEngineState, aError);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   561
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   562
	switch(iEngineState)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   563
		{		
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   564
		case EDownloadingFeed: 
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   565
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   566
		switch (aError)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   567
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   568
			case KErrCancel:						
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   569
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   570
				iFeedsUpdating.Reset();
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   571
				iEngineState = EIdle;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   572
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   573
				break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   574
			case KErrCouldNotConnect:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   575
				iFeedsUpdating.Reset();
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   576
				iEngineState = EIdle;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   577
				break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   578
			default:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   579
				{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   580
				if (iCancelRequested)
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   581
					{
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   582
					iEngineState = EIdle;
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   583
					}
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   584
				else
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   585
					{
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   586
					iActiveFeed->SetLastError(aError);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   587
					TTime time;
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   588
					time.HomeTime();
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   589
					iActiveFeed->SetLastUpdated(time);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   590
	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   591
					if( aError == KErrNone)
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   592
						{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   593
						// Parse the feed. We need to trap this call since it could leave and then
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   594
						// the whole update chain will be broken
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   595
						// change client state
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   596
						TRAPD(parserErr, iParser->ParseFeedAoL(iUpdatingFeedFileName, iActiveFeed, iPodcastModel.SettingsEngine().MaxListItems()));
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   597
	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   598
						if(parserErr)
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   599
							{
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   600
							// we do not need to any special action on this error.
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   601
							iActiveFeed->SetLastError(parserErr);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   602
							DP1("CFeedEngine::Complete()\t Failed to parse feed. Leave with error code=%d", parserErr);
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   603
							iEngineState = EIdle;
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   604
							}
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   605
						else 
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   606
							{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   607
							iEngineState = EParsingFeed;
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   608
							}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   609
						}
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   610
					else
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   611
						{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   612
						// even if it fails, this will allow us to move on
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   613
						iEngineState = EIdle;
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   614
						}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   615
					}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   616
				}break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   617
			}
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   618
			NotifyFeedUpdateComplete(iActiveFeed->Uid(), aError);
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   619
			}
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   620
		break;
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   621
		case EParsingFeed: 
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   622
			{
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   623
			// if the feed has specified a image url. download it if we dont already have it
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   624
			if((iActiveFeed->ImageUrl().Length() > 0))
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   625
				{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   626
				if ( (iActiveFeed->ImageFileName().Length() == 0) || 
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   627
						(iActiveFeed->ImageFileName().Length() > 0 && 
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   628
								!BaflUtils::FileExists(iPodcastModel.FsSession(), 
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   629
										iActiveFeed->ImageFileName()) )
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   630
				)
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   631
					{
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   632
					TRAPD(error, GetFeedImageL(iActiveFeed));
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   633
					if (error)
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   634
						{
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   635
						// we have failed in a very early stage to fetch the image.
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   636
						// continue with next Feed update	
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   637
						iActiveFeed->SetLastError(error);
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   638
						iEngineState = EIdle;
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   639
						NotifyFeedUpdateComplete(iActiveFeed->Uid(), error);
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   640
						}
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   641
					}
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   642
				else
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   643
					{
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   644
					iEngineState = EIdle;
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   645
					NotifyFeedUpdateComplete(iActiveFeed->Uid(), aError);
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   646
					}
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   647
				}
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   648
			}
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   649
			break;
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   650
		case EDownloadingImage:
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   651
			{
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   652
			// change client state to not updating
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   653
			iEngineState = EIdle;
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   654
			if(aError == KErrNone)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   655
				{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   656
				// now the image has been downloaded, so we set it again in the FeedInfo to start
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   657
				// converting it
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   658
				HBufC *fileNameCopy = iActiveFeed->ImageFileName().AllocLC();
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   659
				TRAP_IGNORE(iActiveFeed->SetImageFileNameL(*fileNameCopy, &iPodcastModel));
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   660
				CleanupStack::PopAndDestroy(fileNameCopy);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   661
				}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   662
			NotifyFeedUpdateComplete(iActiveFeed->Uid(), aError);
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   663
			}break;
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   664
		case ESearching: 
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   665
			{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   666
			iEngineState = EIdle;
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   667
	
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   668
			DP2("Search complete, results in %S with error %d", &iSearchResultsFileName, aError);
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   669
			if(aError == KErrNone)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   670
				{
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   671
				if (!iOpmlParser) 
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   672
					{
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   673
					iOpmlParser = new COpmlParser(*this, iPodcastModel.FsSession());
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   674
					}
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   675
	
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   676
				DP("Parsing OPML");
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   677
				iOpmlParser->ParseOpmlL(iSearchResultsFileName, ETrue);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   678
				}
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   679
			else
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   680
				{
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
   681
				NotifyOpmlParsingCompleteL(aError, 0);
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   682
				}
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   683
			
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   684
			BaflUtils::DeleteFile(iPodcastModel.FsSession(), iSearchResultsFileName);
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   685
			}break;
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   686
		case EIdle:
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   687
			UpdateNextFeedL();	
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   688
			break;
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   689
		default:
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   690
			Panic(EPodcatcherPanicFeedEngineState);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   691
			break;
2
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
	DP("CFeedEngine::CompleteL END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   694
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   695
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   696
void CFeedEngine::NotifyFeedUpdateComplete(TInt aFeedUid, TInt aError)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   697
	{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   698
	DP("CFeedEngine::NotifyFeedUpdateComplete");
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   699
	
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   700
	DBUpdateFeedL(*iActiveFeed);
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   701
	
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   702
	// we will wait until the image has been downloaded to start the next feed update.
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   703
	if (iEngineState == EIdle)
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   704
		{
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   705
		UpdateNextFeedL();	
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   706
		}
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
   707
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   708
	for (TInt i=0;i<iObservers.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   709
		{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   710
		TRAP_IGNORE(iObservers[i]->FeedDownloadFinishedL(MFeedEngineObserver::EFeedAutoUpdate, aFeedUid, aError));
2
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
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   713
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   714
void CFeedEngine::Disconnected(CHttpClient* /*aClient*/)
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
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   717
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   718
void CFeedEngine::DownloadInfo(CHttpClient* /*aHttpClient */, int /*aTotalBytes*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   719
	{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   720
	}
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
EXPORT_C void CFeedEngine::ImportFeedsL(const TDesC& aFile)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   723
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   724
	TFileName opmlPath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   725
	opmlPath.Copy(aFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   726
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   727
	if (!iOpmlParser) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   728
		iOpmlParser = new COpmlParser(*this, iPodcastModel.FsSession());
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
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   731
	iOpmlParser->ParseOpmlL(opmlPath, EFalse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   732
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   733
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   734
EXPORT_C TBool CFeedEngine::ExportFeedsL(TFileName& aFile)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   735
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   736
	RFile rfile;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   737
	TFileName privatePath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   738
	iPodcastModel.FsSession().PrivatePath(privatePath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   739
	TInt error = rfile.Temp(iPodcastModel.FsSession(), privatePath, aFile, EFileWrite);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   740
	if (error != KErrNone) 
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
		DP("CFeedEngine::ExportFeedsL()\tFailed to open file");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   743
		return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   744
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   745
	CleanupClosePushL(rfile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   746
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   747
	HBufC* templ = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   748
	templ->Des().Copy(KOpmlFeed());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   749
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   750
	HBufC* line = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   751
	HBufC* xmlUrl = HBufC::NewLC(KMaxURLLength);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   752
	HBufC* htmlUrl = HBufC::NewLC(KMaxURLLength);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   753
	HBufC* desc = HBufC::NewLC(KMaxDescriptionLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   754
	HBufC* title = HBufC::NewLC(KMaxTitleLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   755
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   756
	HBufC8* utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(KOpmlHeader());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   757
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   758
	rfile.Write(*utf8line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   759
	delete utf8line;
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
	for (int i=0; i<iSortedFeeds.Count(); i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   762
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   763
		CFeedInfo *info = iSortedFeeds[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   764
		DP1("Exporting feed '%S'", &iSortedFeeds[i]->Title());
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
	// XML URL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   767
		TPtr ptrXml(xmlUrl->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   768
		if (info->Url() != KNullDesC)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   769
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   770
			ptrXml.Copy(info->Url());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   771
			PodcastUtils::XMLEncode(ptrXml);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   772
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   773
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   774
	// Description	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   775
		TPtr ptrDesc(desc->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   776
		ptrDesc.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   777
		if (info->Description() != KNullDesC) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   778
			ptrDesc.Copy(info->Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   779
			PodcastUtils::XMLEncode(ptrDesc);
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
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   782
	// Title	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   783
		TPtr ptrTitle(title->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   784
		ptrTitle.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   785
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   786
		if (info->Title() != KNullDesC) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   787
			ptrTitle.Copy(info->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   788
			PodcastUtils::XMLEncode(ptrTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   789
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   790
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   791
	// HTML URL	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   792
		TPtr ptrHtmlUrl(htmlUrl->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   793
		ptrHtmlUrl.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   794
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   795
		if (info->Link() != KNullDesC) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   796
			ptrHtmlUrl.Copy(info->Link());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   797
			PodcastUtils::XMLEncode(ptrHtmlUrl);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   798
		}	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   799
	// Write line to OPML file
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   800
		line->Des().Format(*templ, title, desc, xmlUrl, htmlUrl);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   801
		utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(*line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   802
		rfile.Write(*utf8line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   803
		delete utf8line;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   806
	utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(KOpmlFooter());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   807
	rfile.Write(*utf8line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   808
	delete utf8line;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   809
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   810
	CleanupStack::PopAndDestroy(7);//destroy 6 bufs & close rfile
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   811
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   812
	return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   813
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   814
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   815
EXPORT_C CFeedInfo* CFeedEngine::GetFeedInfoByUid(TUint aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   816
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   817
	TInt cnt = iSortedFeeds.Count();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   818
	for (TInt i=0;i<cnt;i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   819
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   820
		if (iSortedFeeds[i]->Uid() == aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   821
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   822
			return iSortedFeeds[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   823
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   824
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   825
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   826
	return NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   827
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   828
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   829
EXPORT_C const RFeedInfoArray& CFeedEngine::GetSortedFeeds()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   830
{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   831
	TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
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
	iSortedFeeds.Sort(sortOrder);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   834
	return iSortedFeeds;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   837
TInt CFeedEngine::CompareFeedsByTitle(const CFeedInfo &a, const CFeedInfo &b)
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
		//DP2("Comparing %S to %S", &a.Title(), &b.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   840
		return a.Title().CompareF(b.Title());
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
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   843
EXPORT_C void CFeedEngine::GetStatsByFeedL(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   844
	{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   845
	//DP1("CFeedEngine::GetStatsByFeed, aFeedUid=%u", aFeedUid);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   846
	DBGetStatsByFeedL(aFeedUid, aNumShows, aNumUnplayed);
2
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
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   849
void CFeedEngine::DBGetStatsByFeedL(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   850
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   851
	//DP1("CFeedEngine::DBGetStatsByFeed, feedUid=%u", aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   852
	_LIT(KSqlStatement, "select count(*) from shows where feeduid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   853
	iSqlBuffer.Format(KSqlStatement, aFeedUid);
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
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   856
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   857
	int 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
   858
	
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   859
	if( rc==SQLITE_OK)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   860
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   861
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   862
	  	rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   863
	  	
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   864
	  	if (rc == SQLITE_ROW)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   865
	  		{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   866
	  		aNumShows = sqlite3_column_int(st, 0);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   867
	  		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   868
	  	else
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   869
	  		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   870
			User::Leave(KErrNotFound);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   871
	  		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   872
	  	CleanupStack::PopAndDestroy(); // st
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   873
		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   874
	else
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   875
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   876
		User::Leave(KErrCorrupt);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   877
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   878
		  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   879
	_LIT(KSqlStatement2, "select count(*) from shows where feeduid=%u and playstate=0");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   880
	iSqlBuffer.Format(KSqlStatement2, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   881
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   882
	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
   883
		
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   884
	if(rc==SQLITE_OK)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   885
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   886
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   887
	  	rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   888
	  	
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   889
	  	if (rc == SQLITE_ROW)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   890
	  		{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   891
	  		aNumUnplayed = sqlite3_column_int(st, 0);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   892
	  		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   893
	  	else
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   894
	  		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   895
			User::Leave(KErrNotFound);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   896
	  		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   897
	  	CleanupStack::PopAndDestroy(); // st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   898
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   899
}
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: 32
diff changeset
   901
TUint CFeedEngine::DBGetFeedCountL()
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   902
	{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   903
	DP("DBGetFeedCount BEGIN");
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   904
	sqlite3_stmt *st;
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   905
	int rc = sqlite3_prepare_v2(&iDB,"select count(*) from feeds" , -1, &st, (const char**) NULL);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   906
	TUint size = 0;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   907
	 
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   908
	if( rc==SQLITE_OK )
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   909
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   910
		Cleanup_sqlite3_finalize_PushL(st);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   911
		rc = sqlite3_step(st);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   912
			
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   913
		if (rc == SQLITE_ROW)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   914
			{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   915
	  		size = sqlite3_column_int(st, 0);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   916
	  		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   917
		else
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   918
			{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   919
	  		User::Leave(KErrCorrupt);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   920
	  		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   921
		CleanupStack::PopAndDestroy(); // st
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   922
		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   923
	else
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   924
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   925
		User::Leave(KErrCorrupt);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   926
		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   927
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   928
	DP1("DBGetFeedCount END=%d", size);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   929
	return size;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   930
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   931
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   932
void CFeedEngine::DBLoadFeedsL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   933
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   934
	DP("DBLoadFeeds BEGIN");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   935
	iSortedFeeds.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   936
	CFeedInfo *feedInfo = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   937
	
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   938
	_LIT(KSqlStatement, "select url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror from feeds");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   939
	iSqlBuffer.Format(KSqlStatement);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   940
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   941
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   942
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   943
	TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   944
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   945
	int 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
   946
	
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   947
	if (rc==SQLITE_OK)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   948
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   949
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   950
		rc = sqlite3_step(st);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   951
		while(rc == SQLITE_ROW) 
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   952
			{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   953
			feedInfo = CFeedInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   954
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   955
			const void *urlz = sqlite3_column_text16(st, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   956
			TPtrC16 url((const TUint16*)urlz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   957
			feedInfo->SetUrlL(url);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   958
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   959
			const void *titlez = sqlite3_column_text16(st, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   960
			TPtrC16 title((const TUint16*)titlez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   961
			feedInfo->SetTitleL(title);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   962
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   963
			const void *descz = sqlite3_column_text16(st, 2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   964
			TPtrC16 desc((const TUint16*)descz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   965
			feedInfo->SetDescriptionL(desc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   966
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   967
			const void *imagez = sqlite3_column_text16(st, 3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   968
			TPtrC16 image((const TUint16*)imagez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   969
			feedInfo->SetImageUrlL(image);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   970
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   971
			const void *imagefilez = sqlite3_column_text16(st, 4);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   972
			TPtrC16 imagefile((const TUint16*)imagefilez);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   973
			if (imagefile.Length() > 0)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   974
				{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   975
				feedInfo->SetImageFileNameL(imagefile, &iPodcastModel);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   976
				}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   977
			
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   978
			const void *linkz = sqlite3_column_text16(st, 5);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   979
			TPtrC16 link((const TUint16*)linkz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   980
			feedInfo->SetDescriptionL(link);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   981
					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   982
			sqlite3_int64 built = sqlite3_column_int64(st, 6);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   983
			TTime buildtime(built);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   984
			feedInfo->SetBuildDate(buildtime);
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
			sqlite3_int64 lastupdated = sqlite3_column_int64(st, 7);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   987
			TTime lastupdatedtime(lastupdated);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   988
			feedInfo->SetLastUpdated(lastupdatedtime);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   989
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   990
			sqlite3_int64 customtitle = sqlite3_column_int64(st, 10);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   991
			if (customtitle)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   992
				{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   993
				feedInfo->SetCustomTitle();
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
   994
				}
2
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: 32
diff changeset
   996
			sqlite3_int64 lasterror = sqlite3_column_int(st, 11);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   997
			feedInfo->SetLastError(lasterror);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   998
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   999
			TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1000
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1001
			iSortedFeeds.InsertInOrder(feedInfo, sortOrder);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1002
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1003
			CleanupStack::Pop(feedInfo);
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
			rc = sqlite3_step(st);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1006
			}	
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1007
		CleanupStack::PopAndDestroy();//st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1008
		}
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1009
	else
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1010
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1011
		User::Leave(KErrCorrupt);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1012
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1013
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1014
	DP("DBLoadFeeds END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1015
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1016
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1017
CFeedInfo* CFeedEngine::DBGetFeedInfoByUidL(TUint aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1018
	{
164
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 130
diff changeset
  1019
	DP("CFeedEngine::DBGetFeedInfoByUid BEGIN");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1020
	CFeedInfo *feedInfo = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1021
	_LIT(KSqlStatement, "select url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror from feeds where uid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1022
	iSqlBuffer.Format(KSqlStatement, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1023
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1024
	sqlite3_stmt *st;
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1025
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1026
	int 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
  1027
	
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1028
	if (rc==SQLITE_OK)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1029
		{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1030
		Cleanup_sqlite3_finalize_PushL(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1031
		rc = sqlite3_step(st);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1032
		if (rc == SQLITE_ROW)
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1033
			{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1034
			feedInfo = CFeedInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1035
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1036
			const void *urlz = sqlite3_column_text16(st, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1037
			TPtrC16 url((const TUint16*)urlz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1038
			feedInfo->SetUrlL(url);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1039
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1040
			const void *titlez = sqlite3_column_text16(st, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1041
			TPtrC16 title((const TUint16*)titlez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1042
			feedInfo->SetTitleL(title);
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
			const void *descz = sqlite3_column_text16(st, 2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1045
			TPtrC16 desc((const TUint16*)descz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1046
			feedInfo->SetDescriptionL(desc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1047
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1048
			const void *imagez = sqlite3_column_text16(st, 3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1049
			TPtrC16 image((const TUint16*)imagez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1050
			feedInfo->SetImageUrlL(image);
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
			const void *imagefilez = sqlite3_column_text16(st, 4);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1053
			TPtrC16 imagefile((const TUint16*)imagefilez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1054
			feedInfo->SetDescriptionL(imagefile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1055
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1056
			const void *linkz = sqlite3_column_text16(st, 5);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1057
			TPtrC16 link((const TUint16*)linkz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1058
			feedInfo->SetDescriptionL(link);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1059
					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1060
			sqlite3_int64 built = sqlite3_column_int64(st, 6);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1061
			TTime buildtime(built);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1062
			feedInfo->SetBuildDate(buildtime);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1063
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1064
			sqlite3_int64 lastupdated = sqlite3_column_int64(st, 7);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1065
			TTime lastupdatedtime(lastupdated);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1066
			feedInfo->SetLastUpdated(lastupdatedtime);
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
			sqlite3_int64 customtitle = sqlite3_column_int64(st, 10);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1069
			if (customtitle) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1070
				feedInfo->SetCustomTitle();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1071
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1072
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1073
			TInt lasterror = sqlite3_column_int(st, 11);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1074
			feedInfo->SetLastError(lasterror);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1075
						
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1076
			CleanupStack::Pop(feedInfo);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1077
			}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1078
		else
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1079
			{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1080
			User::Leave(KErrNotFound);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1081
			}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1082
		CleanupStack::PopAndDestroy();//st	
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1083
		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1084
	else
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1085
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1086
		User::Leave(KErrNotFound);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1087
		}
164
000f9fc147b2 Catch up with default branch; New v 27 SIS
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 130
diff changeset
  1088
	DP("CFeedEngine::DBGetFeedInfoByUid END");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1089
	return feedInfo;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1090
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1091
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1092
EXPORT_C void CFeedEngine::UpdateFeedInfoL(CFeedInfo *aItem)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1093
	{
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1094
	if (iActiveFeed && iActiveFeed->Uid() == aItem->Uid())
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1095
		{
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1096
		User::Leave(KErrInUse);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1097
		}
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 32
diff changeset
  1098
	
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
  1099
	DBUpdateFeedL(*aItem);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1100
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1101
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1102
EXPORT_C void CFeedEngine::SearchForFeedL(TDesC& aSearchString)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1103
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1104
	DP1("FeedEngine::SearchForFeedL BEGIN, aSearchString=%S", &aSearchString);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1105
	
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
  1106
	if (iEngineState != EIdle) {
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1107
		User::Leave(KErrInUse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1108
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1109
	TBuf<KMaxURLLength> ssBuf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1110
	ssBuf.Copy(aSearchString);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1111
	PodcastUtils::ReplaceString(ssBuf, _L(" "), _L("%20"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1112
	// prepare search URL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1113
	HBufC* templ = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1114
	templ->Des().Copy(KSearchUrl());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1115
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1116
	HBufC* url = HBufC::NewLC(KMaxURLLength);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1117
	url->Des().Format(*templ, &ssBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1118
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1119
	DP1("SearchURL: %S", url);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1120
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1121
	// crate path to store OPML search results
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1122
	iPodcastModel.FsSession().PrivatePath(iSearchResultsFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1123
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1124
	iSearchResultsFileName.Append(KSearchResultsFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1125
	iSearchResults.ResetAndDestroy();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1126
	// run search
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1127
	if(iFeedClient->GetL(*url, iSearchResultsFileName, iPodcastModel.SettingsEngine().SpecificIAP()))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1128
		{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
  1129
		iEngineState = ESearching;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1130
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1131
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1132
		{
171
cc1be3797632 First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 167
diff changeset
  1133
		iEngineState = EIdle;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1134
		User::Leave(KErrAbort);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1135
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1136
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1137
	CleanupStack::PopAndDestroy(url);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1138
	CleanupStack::PopAndDestroy(templ);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1139
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1140
	DP("FeedEngine::SearchForFeedL END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1141
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1142
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1143
EXPORT_C void CFeedEngine::AddSearchResultL(CFeedInfo *item)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1144
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1145
	DP1("CFeedEngine::AddSearchResultL, item->Title()=%S", &(item->Title()));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1146
	iSearchResults.AppendL(item);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1147
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1148
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1149
EXPORT_C const RFeedInfoArray& CFeedEngine::GetSearchResults()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1150
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1151
	return iSearchResults;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1152
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1153
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1154
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
  1155
EXPORT_C void CFeedEngine::OpmlParsingCompleteL(TInt aError, TUint aNumFeedsAdded)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1156
	{
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
  1157
	NotifyOpmlParsingCompleteL(aError, aNumFeedsAdded);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1158
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1159
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
  1160
void CFeedEngine::NotifyOpmlParsingCompleteL(TInt aError, TUint aNumFeedsAdded)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1161
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1162
	for (TInt i=0;i<iObservers.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1163
		{
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
  1164
		iObservers[i]->OpmlParsingComplete(aError, aNumFeedsAdded);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1165
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1166
	}