engine/src/FeedEngine.cpp
author Lars Persson <lars.persson@embeddev.se>
Wed, 31 Mar 2010 08:19:35 +0200
changeset 91 87cb33beeae2
parent 32 26a3f2dfba08
child 93 bbf5c5204844
permissions -rw-r--r--
Remove icon index. Start caching icons as mbms.
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>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    29
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
// Cleanup stack macro for SQLite3
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
// TODO Move this to some common place.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
static void Cleanup_sqlite3_finalize_wrapper(TAny* handle)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
	sqlite3_finalize(static_cast<sqlite3_stmt*>(handle));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
#define Cleanup_sqlite3_finalize_PushL(__handle) CleanupStack::PushL(TCleanupItem(&Cleanup_sqlite3_finalize_wrapper, __handle))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
CFeedEngine* CFeedEngine::NewL(CPodcastModel& aPodcastModel)
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
	CFeedEngine* self = new (ELeave) CFeedEngine(aPodcastModel);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
	CleanupStack::PushL(self);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
	self->ConstructL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
	CleanupStack::Pop(self);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
	return self;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
void CFeedEngine::ConstructL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
	iParser = new (ELeave) CFeedParser(*this, iPodcastModel.FsSession());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
	iFeedClient = CHttpClient::NewL(iPodcastModel, *this);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
	iFeedTimer.ConstructL();
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
	RunFeedTimer();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
    if (DBGetFeedCount() > 0) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
    	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
		DP("Loading feeds from DB");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    60
		DBLoadFeedsL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    61
		} 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
    
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
	if (iPodcastModel.IsFirstStartup()) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
		TFileName defaultFile = iPodcastModel.SettingsEngine().DefaultFeedsFileName();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
		DP1("Loading default feeds from %S", &defaultFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
		if (BaflUtils::FileExists(iPodcastModel.FsSession(), defaultFile)) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
			ImportFeedsL(defaultFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    69
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    70
    
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    71
    TFileName importFile = iPodcastModel.SettingsEngine().ImportFeedsFileName();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    72
    if (BaflUtils::FileExists(iPodcastModel.FsSession(), importFile)) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    73
    	DP("Importing feeds");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    74
    	ImportFeedsL(importFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    75
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    76
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
CFeedEngine::CFeedEngine(CPodcastModel& aPodcastModel)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
		: iClientState(EIdle),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
		  iFeedTimer(this),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
		  iPodcastModel(aPodcastModel),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
		  iDB(*aPodcastModel.DB())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    84
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
CFeedEngine::~CFeedEngine()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
	iObservers.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
	iFeedsUpdating.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
	iSortedFeeds.ResetAndDestroy();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
	iSearchResults.ResetAndDestroy();
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
	delete iParser;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
	delete iFeedClient;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
	delete iOpmlParser;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
/**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
 * Returns the current internal state of the feed engine4
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
EXPORT_C TClientState CFeedEngine::ClientState()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
	return iClientState;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
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 updating client UID if clientstate is != ENotUpdateing
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
 * @return TUint
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
EXPORT_C TUint CFeedEngine::ActiveClientUid()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
	if(iActiveFeed != NULL)
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
		return iActiveFeed->Uid();
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
	return 0;	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
	}
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
void CFeedEngine::RunFeedTimer()
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
	iFeedTimer.Cancel();
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
	if (iPodcastModel.SettingsEngine().UpdateAutomatically() != EAutoUpdateOff)
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
		TInt interval = iPodcastModel.SettingsEngine().UpdateFeedInterval();
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
		if (interval != 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   130
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
			iFeedTimer.SetPeriod(interval);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
			iFeedTimer.RunPeriodically();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   133
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   134
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   137
EXPORT_C void CFeedEngine::UpdateAllFeedsL(TBool aAutoUpdate)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
	iAutoUpdatedInitiator = aAutoUpdate;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   140
	if (iFeedsUpdating.Count() > 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   141
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
		DP("Cancelling update");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
		iFeedClient->Stop();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
		iFeedsUpdating.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   145
		return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   146
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   148
	TInt cnt = iSortedFeeds.Count();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   149
	for (int i=0;i<cnt;i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
		iFeedsUpdating.Append(iSortedFeeds[i]);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   152
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
	UpdateNextFeedL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   157
EXPORT_C void CFeedEngine::CancelUpdateAllFeeds()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   159
	if(iClientState != EIdle)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   160
		{
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   161
		iCancelRequested = ETrue;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
		iFeedsUpdating.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   163
		iFeedClient->Stop();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   164
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   165
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   166
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
void CFeedEngine::UpdateNextFeedL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   168
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
	DP1("UpdateNextFeed. %d feeds left to update", iFeedsUpdating.Count());
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
	if (iFeedsUpdating.Count() > 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
		CFeedInfo *info = iFeedsUpdating[0];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
		iFeedsUpdating.Remove(0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
		TBool result = EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
		//DP2("** UpdateNextFeed: %S, ID: %u", &(info->Url()), info->Uid());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
		TRAPD(error, result = UpdateFeedL(info->Uid()));
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
		if (error != KErrNone || !result)
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
			DP("Error while updating all feeds");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
			for (TInt i=0;i<iObservers.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
				TRAP_IGNORE(iObservers[i]->FeedUpdateAllCompleteL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   185
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   186
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   187
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   188
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   189
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   190
		iClientState = EIdle;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
		for (TInt i=0;i<iObservers.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
			TRAP_IGNORE(iObservers[i]->FeedUpdateAllCompleteL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   195
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   198
EXPORT_C TBool CFeedEngine::UpdateFeedL(TUint aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   199
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   200
	DP("FeedEngine::UpdateFeedL BEGIN");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
	iActiveFeed = GetFeedInfoByUid(aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   202
	iCatchupCounter = 0;
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   203
	iCancelRequested = EFalse;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   204
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   205
	if (iActiveFeed->LastUpdated() == 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   207
		iCatchupMode = ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
		}
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   209
	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   210
	iActiveFeed->SetLastError(KErrNone);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   211
	DBUpdateFeed(*iActiveFeed);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   212
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
	iUpdatingFeedFileName.Copy (iPodcastModel.SettingsEngine().PrivatePath ());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
	_LIT(KFileNameFormat, "%lu.xml");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
	iUpdatingFeedFileName.AppendFormat(KFileNameFormat, aFeedUid);
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
	if(iFeedClient->GetL(iActiveFeed->Url(), iUpdatingFeedFileName, iPodcastModel.SettingsEngine().SpecificIAP()))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   218
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
		iClientState = EUpdatingFeed;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
		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]->FeedDownloadStartedL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate, iActiveFeed->Uid()));
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
		DP("FeedEngine::UpdateFeedL END, return ETrue");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
		return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
		DP("FeedEngine::UpdateFeedL END, return EFalse");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
		return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   236
void CFeedEngine::NewShowL(CShowInfo& aItem)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
	HBufC* description = HBufC::NewLC(KMaxDescriptionLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
	TPtr ptr(description->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
	ptr.Copy(aItem.Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
	PodcastUtils::CleanHtmlL(ptr);
8
aab3aa4acdd6 Checked all TRAP_IGNORE
teknolog
parents: 7
diff changeset
   242
aab3aa4acdd6 Checked all TRAP_IGNORE
teknolog
parents: 7
diff changeset
   243
	aItem.SetDescriptionL(*description);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
	CleanupStack::PopAndDestroy(description);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
	if (iCatchupMode) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
		// in catchup mode, we let one show be unplayed
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
		if (++iCatchupCounter > 1) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
			aItem.SetPlayState(EPlayed);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
	TBool isShowAdded = iPodcastModel.ShowEngine().AddShowL(aItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   254
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
	if (aItem.PlayState() == ENeverPlayed && isShowAdded && iPodcastModel.SettingsEngine().DownloadAutomatically()) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
		iPodcastModel.ShowEngine().AddDownloadL(aItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   258
		}	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
void CFeedEngine::GetFeedImageL(CFeedInfo *aFeedInfo)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   263
	DP("GetFeedImage");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   264
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
	TFileName filePath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
	filePath.Copy(iPodcastModel.SettingsEngine().BaseDir());
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
	// create relative file name
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
	TFileName relPath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
	relPath.Copy(aFeedInfo->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
	relPath.Append('\\');
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
	TFileName fileName;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
	PodcastUtils::FileNameFromUrl(aFeedInfo->ImageUrl(), fileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
	relPath.Append(fileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
	PodcastUtils::EnsureProperPathName(relPath);
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
	// complete file path is base dir + rel path
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
	filePath.Append(relPath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   280
	aFeedInfo->SetImageFileNameL(filePath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   281
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
	if(iFeedClient->GetL(aFeedInfo->ImageUrl(), filePath, ETrue))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   283
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   284
			iClientState = EUpdatingImage;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   285
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   286
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   288
EXPORT_C TBool CFeedEngine::AddFeedL(const CFeedInfo&aItem) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   289
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   290
	DP2("CFeedEngine::AddFeed, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
	for (TInt i=0;i<iSortedFeeds.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
		if (iSortedFeeds[i]->Uid() == aItem.Uid()) 
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
			DP1("Already have feed %S, discarding", &aItem.Url());			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
			return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   298
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   299
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   300
	TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
	CFeedInfo* newItem = aItem.CopyL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
	CleanupStack::PushL(newItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
	User::LeaveIfError(iSortedFeeds.InsertInOrder(newItem, sortOrder));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
	CleanupStack::Pop(newItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
	
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
	// Save the feeds into DB
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   308
	DBAddFeedL(aItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   309
	return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   310
	}
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
TBool CFeedEngine::DBAddFeedL(const CFeedInfo& aItem)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   313
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   314
	DP2("CFeedEngine::DBAddFeed, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   315
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   316
	CFeedInfo *info = DBGetFeedInfoByUidL(aItem.Uid());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   317
	if (info) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   318
		DP("Feed already exists!");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   319
		delete info;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   320
		return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   321
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   322
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   323
	HBufC* titleBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   324
	TPtr titlePtr(titleBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   325
	titlePtr.Copy(aItem.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   326
	PodcastUtils::SQLEncode(titlePtr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   327
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   328
	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   329
	TPtr descPtr(descBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   330
	descPtr.Copy(aItem.Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   331
	PodcastUtils::SQLEncode(descPtr);
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
	_LIT(KSqlStatement, "insert into feeds (url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror)"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   334
			" values (\"%S\",\"%S\", \"%S\", \"%S\", \"%S\", \"%S\", \"%Ld\", \"%Ld\", \"%u\", \"%u\", \"%u\", \"%d\")");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   335
	iSqlBuffer.Format(KSqlStatement,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   336
			&aItem.Url(), titleBuf, descBuf, &aItem.ImageUrl(), &aItem.ImageFileName(), &aItem.Link(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   337
			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
   338
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   339
	CleanupStack::PopAndDestroy(descBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   340
	CleanupStack::PopAndDestroy(titleBuf);
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
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   343
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   344
	//DP1("SQL statement length=%d", iSqlBuffer.Length());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   345
	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
   346
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   347
	if (rc==SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   348
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   349
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   350
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   351
		if (rc == SQLITE_DONE)
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
			sqlite3_finalize(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   354
			return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   355
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   356
		else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   357
			sqlite3_finalize(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   358
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   359
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   360
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   361
	return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   362
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   363
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   364
EXPORT_C void CFeedEngine::RemoveFeedL(TUint aUid) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   365
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   366
	for (int i=0;i<iSortedFeeds.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   367
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   368
		if (iSortedFeeds[i]->Uid() == aUid) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   369
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   370
			iPodcastModel.ShowEngine().DeleteAllShowsByFeedL(aUid);
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
			CFeedInfo* feedToRemove = iSortedFeeds[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   373
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   374
			//delete the image file if it exists
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   375
			if ((feedToRemove->ImageFileName().Length() >0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   376
					&& BaflUtils::FileExists(iPodcastModel.FsSession(), feedToRemove->ImageFileName()))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   377
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   378
				iPodcastModel.FsSession().Delete(feedToRemove->ImageFileName());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   379
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   380
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   381
			//delete the folder. It has the same name as the title.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   382
			TFileName filePath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   383
			filePath.Copy(iPodcastModel.SettingsEngine().BaseDir());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   384
			filePath.Append(feedToRemove->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   385
			filePath.Append('\\');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   386
			iPodcastModel.FsSession().RmDir(filePath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   387
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   388
			iSortedFeeds.Remove(i);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   389
			delete feedToRemove;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   390
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   391
			DP("Removed feed from array");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   392
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   393
			// now remove it from DB
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   394
			DBRemoveFeed(aUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   395
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   396
			return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   397
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   398
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   399
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   400
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   401
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   402
TBool CFeedEngine::DBRemoveFeed(TUint aUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   403
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   404
	DP("CFeedEngine::DBRemoveFeed");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   405
	_LIT(KSqlStatement, "delete from feeds where uid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   406
	iSqlBuffer.Format(KSqlStatement, aUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   407
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   408
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   409
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   410
	int rc = sqlite3_prepare16_v2(&iDB, (const void*)iSqlBuffer.PtrZ() , -1, &st,	(const void**) NULL);
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
	if (rc==SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   413
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   414
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   415
		sqlite3_finalize(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   416
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   417
		if (rc == SQLITE_DONE)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   418
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   419
			DP("Feed removed from DB");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   420
			return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   421
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   422
		else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   423
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   424
			DP("Error when removing feed from DB");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   425
			}
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
	return EFalse;	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   428
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   429
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   430
TBool CFeedEngine::DBUpdateFeed(const CFeedInfo &aItem)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   431
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   432
	DP2("CFeedEngine::DBUpdateFeed, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
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
	HBufC* titleBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   435
	TPtr titlePtr(titleBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   436
	titlePtr.Copy(aItem.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   437
	PodcastUtils::SQLEncode(titlePtr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   438
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   439
	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   440
	TPtr descPtr(descBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   441
	descPtr.Copy(aItem.Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   442
	PodcastUtils::SQLEncode(descPtr);
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
	_LIT(KSqlStatement, "update feeds set url=\"%S\", title=\"%S\", description=\"%S\", imageurl=\"%S\", imagefile=\"%S\"," \
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   445
			"link=\"%S\", built=\"%Lu\", lastupdated=\"%Lu\", feedtype=\"%u\", customtitle=\"%u\", lasterror=\"%d\" where uid=\"%u\"");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   446
	iSqlBuffer.Format(KSqlStatement,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   447
			&aItem.Url(), titleBuf, descBuf, &aItem.ImageUrl(), &aItem.ImageFileName(), &aItem.Link(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   448
			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
   449
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   450
	CleanupStack::PopAndDestroy(descBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   451
	CleanupStack::PopAndDestroy(titleBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   452
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   453
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   454
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   455
	//DP1("SQL statement length=%d", iSqlBuffer.Length());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   456
	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
   457
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   458
	if (rc==SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   459
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   460
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   461
		sqlite3_finalize(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   462
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   463
		if (rc == SQLITE_DONE)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   464
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   465
			return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   466
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   467
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   468
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   469
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   470
		DP1("SQLite rc=%d", rc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   471
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   472
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   473
	return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   474
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   475
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   476
void CFeedEngine::ParsingCompleteL(CFeedInfo *item)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   477
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   478
	TBuf<KMaxLineLength> title;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   479
	title.Copy(item->Title());
8
aab3aa4acdd6 Checked all TRAP_IGNORE
teknolog
parents: 7
diff changeset
   480
	item->SetTitleL(title); // if this leaves we are out of memory
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   481
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   482
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   483
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   484
EXPORT_C void CFeedEngine::AddObserver(MFeedEngineObserver *observer)
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
	iObservers.Append(observer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   487
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   488
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   489
EXPORT_C void CFeedEngine::RemoveObserver(MFeedEngineObserver *observer)
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
	TInt index = iObservers.Find(observer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   492
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   493
	if (index > KErrNotFound)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   494
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   495
		iObservers.Remove(index);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   496
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   497
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   498
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   499
void CFeedEngine::Connected(CHttpClient* /*aClient*/)
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
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   502
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   503
void CFeedEngine::Progress(CHttpClient* /*aHttpClient*/, TInt /*aBytes*/, TInt /*aTotalBytes*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   504
	{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   505
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   506
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   507
void CFeedEngine::CompleteL(CHttpClient* /*aClient*/, TInt aError)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   508
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   509
	DP2("CFeedEngine::CompleteL BEGIN, iClientState=%d, aSuccessful=%d", iClientState, aError);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   510
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   511
	switch(iClientState)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   512
		{		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   513
		default:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   514
			if(iActiveFeed != NULL)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   515
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   516
				TTime time;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   517
				time.HomeTime();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   518
				iActiveFeed->SetLastUpdated(time);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   519
				iActiveFeed->SetLastError(aError);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   520
				NotifyFeedUpdateComplete(aError);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   521
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   522
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   523
		case EUpdatingFeed: 
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
		// Parse the feed. We need to trap this call since it could leave and then
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   526
		// the whole update chain will be broken
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   527
		// change client state
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   528
		iClientState = EIdle;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   529
		switch (aError)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   530
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   531
			case KErrCancel:						
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
				iFeedsUpdating.Reset();
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
				break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   536
			case KErrCouldNotConnect:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   537
				iFeedsUpdating.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   538
				break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   539
			default:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   540
				{
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   541
				if (!iCancelRequested) {
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   542
					iActiveFeed->SetLastError(aError);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   543
					TTime time;
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   544
					time.HomeTime();
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   545
					iActiveFeed->SetLastUpdated(time);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   546
	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   547
					if( aError == KErrNone)
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   548
						{			
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   549
						TRAPD(parserErr, iParser->ParseFeedL(iUpdatingFeedFileName, iActiveFeed, iPodcastModel.SettingsEngine().MaxListItems()));
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   550
	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   551
						if(parserErr)
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   552
							{
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   553
							// 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
   554
							iActiveFeed->SetLastError(parserErr);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   555
							DP1("CFeedEngine::Complete()\t Failed to parse feed. Leave with error code=%d", parserErr);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   556
							}
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   557
						else
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   558
							{
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   559
							iPodcastModel.ShowEngine().DeleteOldShowsByFeed(iActiveFeed->Uid());
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   560
							}
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   561
	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   562
						// delete the downloaded XML file as it is no longer needed
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   563
						BaflUtils::DeleteFile(iPodcastModel.FsSession(),iUpdatingFeedFileName);			
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   564
	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   565
						// if the feed has specified a image url. download it if we dont already have it
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   566
						if((iActiveFeed->ImageUrl().Length() > 0))
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   567
							{
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   568
							if ( (iActiveFeed->ImageFileName().Length() == 0) || 
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   569
									(iActiveFeed->ImageFileName().Length() > 0 && 
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   570
											!BaflUtils::FileExists(iPodcastModel.FsSession(), 
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   571
													iActiveFeed->ImageFileName()) )
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   572
							)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   573
								{
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   574
								TRAPD(error, GetFeedImageL(iActiveFeed));
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   575
								if (error)
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   576
									{
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   577
									// we have failed in a very early stage to fetch the image.
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   578
									// continue with next Feed update	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   579
									iActiveFeed->SetLastError(parserErr);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   580
									iClientState = EIdle;							
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   581
									}
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   582
								}	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   583
							}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   584
						}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   585
					}
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   586
				iCancelRequested = EFalse;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   587
				}break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   588
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   589
		
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   590
			NotifyFeedUpdateComplete(aError);
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   591
	
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   592
			// we will wait until the image has been downloaded to start the next feed update.
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   593
			if (iClientState == EIdle)
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   594
				{
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   595
				UpdateNextFeedL();	
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   596
				}
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   597
			}break;
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   598
		case EUpdatingImage:
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   599
			{
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   600
			// change client state to not updating
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   601
			iClientState = EIdle;
91
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   602
			if(aError == KErrNone)
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   603
				{
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   604
				if( BaflUtils::FileExists(CEikonEnv::Static()->FsSession(), iActiveFeed->ImageFileName() ))
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   605
					{
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   606
						// If this fails, no reason to worry
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   607
					TRAP_IGNORE(iPodcastModel.ImageHandler().LoadFileAndScaleL(iActiveFeed->FeedIcon(), iActiveFeed->ImageFileName(), TSize(64,56), *iActiveFeed, iActiveFeed->Uid()));
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   608
					}				
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   609
				}
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   610
			
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   611
			NotifyFeedUpdateComplete(aError);
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   612
			UpdateNextFeedL();
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   613
			}break;
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   614
		case ESearching: 
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   615
			{
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   616
			iClientState = EIdle;
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   617
	
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   618
			DP2("Search complete, results in %S with error %d", &iSearchResultsFileName, aError);
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   619
			if(aError == KErrNone)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   620
				{
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   621
				if (!iOpmlParser) 
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   622
					{
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   623
					iOpmlParser = new COpmlParser(*this, iPodcastModel.FsSession());
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   624
					}
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   625
	
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   626
				DP("Parsing OPML");
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   627
				iOpmlParser->ParseOpmlL(iSearchResultsFileName, ETrue);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   628
				}
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   629
			else
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   630
				{
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   631
				NotifyOpmlParsingComplete(aError, 0);
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   632
				}
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   633
			
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   634
			BaflUtils::DeleteFile(iPodcastModel.FsSession(), iSearchResultsFileName);
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   635
			}break;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   636
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   637
	DP("CFeedEngine::CompleteL END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   638
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   639
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   640
void CFeedEngine::NotifyFeedUpdateComplete(TInt aError)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   641
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   642
	DP("CFeedEngine::NotifyFeedUpdateComplete");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   643
	DBUpdateFeed(*iActiveFeed);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   644
	for (TInt i=0;i<iObservers.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   645
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   646
		TRAP_IGNORE(iObservers[i]->FeedDownloadFinishedL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate, iActiveFeed->Uid(), aError));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   647
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   648
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   649
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   650
void CFeedEngine::Disconnected(CHttpClient* /*aClient*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   651
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   652
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   653
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   654
void CFeedEngine::DownloadInfo(CHttpClient* /*aHttpClient */, int /*aTotalBytes*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   655
	{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   656
	/*DP1("About to download %d bytes", aTotalBytes);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   657
	if(aHttpClient == iShowClient && iShowDownloading != NULL && aTotalBytes != -1) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   658
		iShowDownloading->iShowSize = aTotalBytes;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   659
		}*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   660
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   661
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   662
EXPORT_C void CFeedEngine::ImportFeedsL(const TDesC& aFile)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   663
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   664
	TFileName opmlPath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   665
	opmlPath.Copy(aFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   666
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   667
	if (!iOpmlParser) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   668
		iOpmlParser = new COpmlParser(*this, iPodcastModel.FsSession());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   669
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   670
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   671
	iOpmlParser->ParseOpmlL(opmlPath, EFalse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   672
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   673
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   674
EXPORT_C TBool CFeedEngine::ExportFeedsL(TFileName& aFile)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   675
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   676
	RFile rfile;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   677
	TFileName privatePath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   678
	iPodcastModel.FsSession().PrivatePath(privatePath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   679
	TInt error = rfile.Temp(iPodcastModel.FsSession(), privatePath, aFile, EFileWrite);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   680
	if (error != KErrNone) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   681
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   682
		DP("CFeedEngine::ExportFeedsL()\tFailed to open file");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   683
		return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   684
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   685
	CleanupClosePushL(rfile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   686
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   687
	HBufC* templ = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   688
	templ->Des().Copy(KOpmlFeed());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   689
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   690
	HBufC* line = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   691
	HBufC* xmlUrl = HBufC::NewLC(KMaxURLLength);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   692
	HBufC* htmlUrl = HBufC::NewLC(KMaxURLLength);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   693
	HBufC* desc = HBufC::NewLC(KMaxDescriptionLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   694
	HBufC* title = HBufC::NewLC(KMaxTitleLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   695
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   696
	HBufC8* utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(KOpmlHeader());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   697
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   698
	rfile.Write(*utf8line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   699
	delete utf8line;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   700
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   701
	for (int i=0; i<iSortedFeeds.Count(); i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   702
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   703
		CFeedInfo *info = iSortedFeeds[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   704
		DP1("Exporting feed '%S'", &iSortedFeeds[i]->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   705
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   706
	// XML URL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   707
		TPtr ptrXml(xmlUrl->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   708
		if (info->Url() != KNullDesC)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   709
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   710
			ptrXml.Copy(info->Url());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   711
			PodcastUtils::XMLEncode(ptrXml);
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
	// Description	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   715
		TPtr ptrDesc(desc->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   716
		ptrDesc.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   717
		if (info->Description() != KNullDesC) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   718
			ptrDesc.Copy(info->Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   719
			PodcastUtils::XMLEncode(ptrDesc);
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
	// Title	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   723
		TPtr ptrTitle(title->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   724
		ptrTitle.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   725
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   726
		if (info->Title() != KNullDesC) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   727
			ptrTitle.Copy(info->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   728
			PodcastUtils::XMLEncode(ptrTitle);
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
	// HTML URL	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   732
		TPtr ptrHtmlUrl(htmlUrl->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   733
		ptrHtmlUrl.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   734
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   735
		if (info->Link() != KNullDesC) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   736
			ptrHtmlUrl.Copy(info->Link());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   737
			PodcastUtils::XMLEncode(ptrHtmlUrl);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   738
		}	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   739
	// Write line to OPML file
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   740
		line->Des().Format(*templ, title, desc, xmlUrl, htmlUrl);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   741
		utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(*line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   742
		rfile.Write(*utf8line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   743
		delete utf8line;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   746
	utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(KOpmlFooter());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   747
	rfile.Write(*utf8line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   748
	delete utf8line;
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
	CleanupStack::PopAndDestroy(7);//destroy 6 bufs & close rfile
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   751
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   752
	return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   753
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   754
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   755
EXPORT_C CFeedInfo* CFeedEngine::GetFeedInfoByUid(TUint aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   756
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   757
	TInt cnt = iSortedFeeds.Count();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   758
	for (TInt i=0;i<cnt;i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   759
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   760
		if (iSortedFeeds[i]->Uid() == aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   761
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   762
			return iSortedFeeds[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   763
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   764
		}
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
	return NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   767
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   768
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   769
EXPORT_C const RFeedInfoArray& CFeedEngine::GetSortedFeeds()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   770
{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   771
	TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
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
	iSortedFeeds.Sort(sortOrder);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   774
	return iSortedFeeds;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   775
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   776
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   777
TInt CFeedEngine::CompareFeedsByTitle(const CFeedInfo &a, const CFeedInfo &b)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   778
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   779
		//DP2("Comparing %S to %S", &a.Title(), &b.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   780
		return a.Title().CompareF(b.Title());
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   783
EXPORT_C void CFeedEngine::GetDownloadedStats(TUint &aNumShows, TUint &aNumUnplayed)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   784
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   785
	DP("CFeedEngine::GetDownloadedStats");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   786
	_LIT(KSqlStatement, "select count(*) from shows where downloadstate=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   787
	iSqlBuffer.Format(KSqlStatement, EDownloaded);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   788
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   789
	sqlite3_stmt *st;
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
	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
   792
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   793
	if( rc==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   794
	  	rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   795
	  	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   796
	  	if (rc == SQLITE_ROW) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   797
	  		aNumShows = sqlite3_column_int(st, 0);
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
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   800
		  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   801
	sqlite3_finalize(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   802
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   803
	_LIT(KSqlStatement2, "select count(*) from shows where downloadstate=%u and playstate=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   804
	iSqlBuffer.Format(KSqlStatement2, EDownloaded, ENeverPlayed);
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
	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
   807
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   808
	if( rc==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   809
	  	rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   810
	  	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   811
	  	if (rc == SQLITE_ROW) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   812
	  		aNumUnplayed = sqlite3_column_int(st, 0);
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
		  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   816
	sqlite3_finalize(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   817
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   818
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   819
EXPORT_C void CFeedEngine::GetStatsByFeed(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   820
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   821
	//DP1("CFeedEngine::GetStatsByFeed, aFeedUid=%u", aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   822
	DBGetStatsByFeed(aFeedUid, aNumShows, aNumUnplayed);
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
void CFeedEngine::DBGetStatsByFeed(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   826
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   827
	//DP1("CFeedEngine::DBGetStatsByFeed, feedUid=%u", aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   828
	_LIT(KSqlStatement, "select count(*) from shows where feeduid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   829
	iSqlBuffer.Format(KSqlStatement, aFeedUid);
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
	sqlite3_stmt *st;
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
	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
   834
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   835
	if( rc==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   836
	  	rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   837
	  	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   838
	  	if (rc == SQLITE_ROW) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   839
	  		aNumShows = sqlite3_column_int(st, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   840
	  	}
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
		  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   843
	sqlite3_finalize(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   844
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   845
	_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
   846
	iSqlBuffer.Format(KSqlStatement2, aFeedUid);
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
	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
   849
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   850
	if( rc==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   851
	  	rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   852
	  	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   853
	  	if (rc == SQLITE_ROW) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   854
	  		aNumUnplayed = sqlite3_column_int(st, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   855
	  	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   856
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   857
		  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   858
	sqlite3_finalize(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   859
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   860
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   861
TUint CFeedEngine::DBGetFeedCount()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   862
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   863
	 DP("DBGetFeedCount BEGIN");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   864
	 sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   865
	 int rc = sqlite3_prepare_v2(&iDB,"select count(*) from feeds" , -1, &st, (const char**) NULL);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   866
	 TUint size = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   867
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   868
	 if( rc==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   869
	  	rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   870
	  	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   871
	  	if (rc == SQLITE_ROW) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   872
	  		size = sqlite3_column_int(st, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   873
	  	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   874
	  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   875
	  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   876
	  sqlite3_finalize(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   877
	  DP1("DBGetFeedCount END=%d", size);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   878
	  return size;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   879
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   880
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   881
void CFeedEngine::DBLoadFeedsL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   882
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   883
	DP("DBLoadFeeds BEGIN");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   884
	iSortedFeeds.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   885
	CFeedInfo *feedInfo = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   886
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   887
	_LIT(KSqlStatement, "select url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle from feeds");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   888
	iSqlBuffer.Format(KSqlStatement);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   889
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   890
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   891
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   892
	TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   893
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   894
	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
   895
	Cleanup_sqlite3_finalize_PushL(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   896
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   897
	if (rc==SQLITE_OK) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   898
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   899
		while(rc == SQLITE_ROW) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   900
			feedInfo = CFeedInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   901
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   902
			const void *urlz = sqlite3_column_text16(st, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   903
			TPtrC16 url((const TUint16*)urlz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   904
			feedInfo->SetUrlL(url);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   905
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   906
			const void *titlez = sqlite3_column_text16(st, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   907
			TPtrC16 title((const TUint16*)titlez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   908
			feedInfo->SetTitleL(title);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   909
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   910
			const void *descz = sqlite3_column_text16(st, 2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   911
			TPtrC16 desc((const TUint16*)descz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   912
			feedInfo->SetDescriptionL(desc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   913
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   914
			const void *imagez = sqlite3_column_text16(st, 3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   915
			TPtrC16 image((const TUint16*)imagez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   916
			feedInfo->SetImageUrlL(image);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   917
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   918
			const void *imagefilez = sqlite3_column_text16(st, 4);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   919
			TPtrC16 imagefile((const TUint16*)imagefilez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   920
			feedInfo->SetImageFileNameL(imagefile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   921
						
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   922
			const void *linkz = sqlite3_column_text16(st, 5);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   923
			TPtrC16 link((const TUint16*)linkz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   924
			feedInfo->SetDescriptionL(link);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   925
					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   926
			sqlite3_int64 built = sqlite3_column_int64(st, 6);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   927
			TTime buildtime(built);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   928
			feedInfo->SetBuildDate(buildtime);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   929
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   930
			sqlite3_int64 lastupdated = sqlite3_column_int64(st, 7);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   931
			TTime lastupdatedtime(lastupdated);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   932
			feedInfo->SetLastUpdated(lastupdatedtime);
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
			sqlite3_int64 customtitle = sqlite3_column_int64(st, 10);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   935
			if (customtitle) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   936
				feedInfo->SetCustomTitle();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   937
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   938
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   939
			TInt lasterror = sqlite3_column_int(st, 11);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   940
			feedInfo->SetLastError(lasterror);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   941
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   942
			TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   943
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   944
			iSortedFeeds.InsertInOrder(feedInfo, sortOrder);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   945
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   946
			CleanupStack::Pop(feedInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   947
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   948
			rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   949
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   950
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   951
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   952
	CleanupStack::PopAndDestroy();//st
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   953
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   954
	DP("DBLoadFeeds END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   955
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   956
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   957
CFeedInfo* CFeedEngine::DBGetFeedInfoByUidL(TUint aFeedUid)
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
	DP("CFeedEngine::DBGetFeedInfoByUid");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   960
	CFeedInfo *feedInfo = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   961
	_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
   962
	iSqlBuffer.Format(KSqlStatement, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   963
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   964
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   965
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   966
	//DP1("SQL statement length=%d", iSqlBuffer.Length());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   967
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   968
	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
   969
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   970
	if (rc==SQLITE_OK) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   971
		Cleanup_sqlite3_finalize_PushL(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   972
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   973
		if (rc == SQLITE_ROW) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   974
			feedInfo = CFeedInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   975
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   976
			const void *urlz = sqlite3_column_text16(st, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   977
			TPtrC16 url((const TUint16*)urlz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   978
			feedInfo->SetUrlL(url);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   979
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   980
			const void *titlez = sqlite3_column_text16(st, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   981
			TPtrC16 title((const TUint16*)titlez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   982
			feedInfo->SetTitleL(title);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   983
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   984
			const void *descz = sqlite3_column_text16(st, 2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   985
			TPtrC16 desc((const TUint16*)descz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   986
			feedInfo->SetDescriptionL(desc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   987
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   988
			const void *imagez = sqlite3_column_text16(st, 3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   989
			TPtrC16 image((const TUint16*)imagez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   990
			feedInfo->SetImageUrlL(image);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   991
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   992
			const void *imagefilez = sqlite3_column_text16(st, 4);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   993
			TPtrC16 imagefile((const TUint16*)imagefilez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   994
			feedInfo->SetDescriptionL(imagefile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   995
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   996
			const void *linkz = sqlite3_column_text16(st, 5);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   997
			TPtrC16 link((const TUint16*)linkz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   998
			feedInfo->SetDescriptionL(link);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   999
					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1000
			sqlite3_int64 built = sqlite3_column_int64(st, 6);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1001
			TTime buildtime(built);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1002
			feedInfo->SetBuildDate(buildtime);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1003
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1004
			sqlite3_int64 lastupdated = sqlite3_column_int64(st, 7);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1005
			TTime lastupdatedtime(lastupdated);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1006
			feedInfo->SetLastUpdated(lastupdatedtime);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1007
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1008
			sqlite3_int64 customtitle = sqlite3_column_int64(st, 10);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1009
			if (customtitle) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1010
				feedInfo->SetCustomTitle();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1011
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1012
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1013
			TInt lasterror = sqlite3_column_int(st, 11);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1014
			feedInfo->SetLastError(lasterror);
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
			CleanupStack::Pop(feedInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1017
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1018
		CleanupStack::PopAndDestroy();//st	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1019
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1020
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1021
	return feedInfo;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1022
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1023
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1024
EXPORT_C void CFeedEngine::UpdateFeed(CFeedInfo *aItem)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1025
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1026
	DBUpdateFeed(*aItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1027
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1028
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1029
EXPORT_C void CFeedEngine::SearchForFeedL(TDesC& aSearchString)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1030
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1031
	DP1("FeedEngine::SearchForFeedL BEGIN, aSearchString=%S", &aSearchString);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1032
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1033
	if (iClientState != EIdle) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1034
		User::Leave(KErrInUse);
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
	TBuf<KMaxURLLength> ssBuf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1037
	ssBuf.Copy(aSearchString);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1038
	PodcastUtils::ReplaceString(ssBuf, _L(" "), _L("%20"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1039
	// prepare search URL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1040
	HBufC* templ = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1041
	templ->Des().Copy(KSearchUrl());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1042
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1043
	HBufC* url = HBufC::NewLC(KMaxURLLength);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1044
	url->Des().Format(*templ, &ssBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1045
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1046
	DP1("SearchURL: %S", url);
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
	// crate path to store OPML search results
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1049
	iPodcastModel.FsSession().PrivatePath(iSearchResultsFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1050
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1051
	iSearchResultsFileName.Append(KSearchResultsFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1052
	iSearchResults.ResetAndDestroy();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1053
	// run search
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1054
	if(iFeedClient->GetL(*url, iSearchResultsFileName, iPodcastModel.SettingsEngine().SpecificIAP()))
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
		iClientState = ESearching;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1057
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1058
	else
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
		iClientState = EIdle;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1061
		User::Leave(KErrAbort);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1062
		}
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
	CleanupStack::PopAndDestroy(url);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1065
	CleanupStack::PopAndDestroy(templ);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1066
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1067
	DP("FeedEngine::SearchForFeedL END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1068
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1069
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1070
EXPORT_C void CFeedEngine::AddSearchResultL(CFeedInfo *item)
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
	DP1("CFeedEngine::AddSearchResultL, item->Title()=%S", &(item->Title()));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1073
	iSearchResults.AppendL(item);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1074
	}
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
EXPORT_C const RFeedInfoArray& CFeedEngine::GetSearchResults()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1077
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1078
	return iSearchResults;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1079
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1080
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1081
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
  1082
EXPORT_C void CFeedEngine::OpmlParsingComplete(TInt aError, TUint aNumFeedsAdded)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1083
	{
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
  1084
	NotifyOpmlParsingComplete(aError, aNumFeedsAdded);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1085
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1086
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
  1087
void CFeedEngine::NotifyOpmlParsingComplete(TInt aError, TUint aNumFeedsAdded)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1088
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1089
	for (TInt i=0;i<iObservers.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1090
		{
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
  1091
		iObservers[i]->OpmlParsingComplete(aError, aNumFeedsAdded);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1092
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1093
	}