engine/src/FeedEngine.cpp
author teknolog
Sun, 04 Apr 2010 18:06:31 +0100
changeset 78 12c59f14a031
parent 77 403412eb5292
child 81 27f6f5827e5d
permissions -rw-r--r--
DB robustness improved also for ShowEngine
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
75
554d9980157f Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents: 74
diff changeset
    30
_LIT(KFeedParseStorePath, "feeds\\");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
CFeedEngine* CFeedEngine::NewL(CPodcastModel& aPodcastModel)
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
	CFeedEngine* self = new (ELeave) CFeedEngine(aPodcastModel);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
	CleanupStack::PushL(self);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
	self->ConstructL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
	CleanupStack::Pop(self);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
	return self;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
	}
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
void CFeedEngine::ConstructL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
	iParser = new (ELeave) CFeedParser(*this, iPodcastModel.FsSession());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
	iFeedClient = CHttpClient::NewL(iPodcastModel, *this);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
	iFeedTimer.ConstructL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
	
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    48
	TInt err = KErrNone;
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    49
	TInt feedCount = 0;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
	
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    51
	TRAP(err, feedCount = DBGetFeedCountL());
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    52
    if (err == KErrNone && feedCount > 0)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
    	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    54
		DP("Loading feeds from DB");
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    55
		TRAP(err, DBLoadFeedsL());
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    56
    	}		
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    57
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
    
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    59
	if (err != KErrNone || iPodcastModel.IsFirstStartup()) {
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    60
		TFileName defaultFile = iPodcastModel.SettingsEngine().DefaultFeedsFileName();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    61
		DP1("Loading default feeds from %S", &defaultFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
		if (BaflUtils::FileExists(iPodcastModel.FsSession(), defaultFile)) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
			ImportFeedsL(defaultFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
		}
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    65
	} 
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    66
	
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    67
	// clean out feeds temp directory
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    68
	TFileName feedTempPath;
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    69
	feedTempPath.Copy (iPodcastModel.SettingsEngine().PrivatePath ());
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    70
	feedTempPath.Append(KFeedParseStorePath);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    71
	feedTempPath.Append(_L("*"));
75
554d9980157f Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents: 74
diff changeset
    72
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    73
	BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), feedTempPath);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    74
	BaflUtils::DeleteFile(iPodcastModel.FsSession(),feedTempPath);
2
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
    TFileName importFile = iPodcastModel.SettingsEngine().ImportFeedsFileName();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
    if (BaflUtils::FileExists(iPodcastModel.FsSession(), importFile)) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
    	DP("Importing feeds");
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    79
    	TRAP_IGNORE(ImportFeedsL(importFile));
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
		}
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    81
    
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
    82
	RunFeedTimer();
2
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
CFeedEngine::CFeedEngine(CPodcastModel& aPodcastModel)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
		: iClientState(EIdle),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
		  iFeedTimer(this),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
		  iPodcastModel(aPodcastModel),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
		  iDB(*aPodcastModel.DB())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
CFeedEngine::~CFeedEngine()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
	iObservers.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
	iFeedsUpdating.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
	iSortedFeeds.ResetAndDestroy();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
	iSearchResults.ResetAndDestroy();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
	delete iParser;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
	delete iFeedClient;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
	delete iOpmlParser;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
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
 * Returns the current internal state of the feed engine4
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
EXPORT_C TClientState CFeedEngine::ClientState()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
	return iClientState;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
	}
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
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
 * Returns the current updating client UID if clientstate is != ENotUpdateing
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
 * @return TUint
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
EXPORT_C TUint CFeedEngine::ActiveClientUid()
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
	if(iActiveFeed != NULL)
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
		return iActiveFeed->Uid();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   125
	return 0;	
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
void CFeedEngine::RunFeedTimer()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   129
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   130
	iFeedTimer.Cancel();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
	if (iPodcastModel.SettingsEngine().UpdateAutomatically() != EAutoUpdateOff)
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
		TInt interval = iPodcastModel.SettingsEngine().UpdateFeedInterval();
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
		if (interval != 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   137
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
			iFeedTimer.SetPeriod(interval);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
			iFeedTimer.RunPeriodically();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   140
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   141
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
EXPORT_C void CFeedEngine::UpdateAllFeedsL(TBool aAutoUpdate)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   145
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   146
	iAutoUpdatedInitiator = aAutoUpdate;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
	if (iFeedsUpdating.Count() > 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   148
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   149
		DP("Cancelling update");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
		iFeedClient->Stop();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
		iFeedsUpdating.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   152
		return;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
	TInt cnt = iSortedFeeds.Count();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
	for (int i=0;i<cnt;i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   157
		{
69
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   158
		iFeedsUpdating.Append(iSortedFeeds[i]->Uid());
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   159
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   160
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   161
	UpdateNextFeedL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   163
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   164
EXPORT_C void CFeedEngine::CancelUpdateAllFeeds()
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
	if(iClientState != EIdle)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
		{
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   168
		iCancelRequested = ETrue;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
		iFeedsUpdating.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   170
		iFeedClient->Stop();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   171
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
void CFeedEngine::UpdateNextFeedL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
	DP1("UpdateNextFeed. %d feeds left to update", iFeedsUpdating.Count());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
	
69
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   178
	// reset active feed, will be set again in UpdateFeedL if needed
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   179
	iActiveFeed = NULL;
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   180
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
	if (iFeedsUpdating.Count() > 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
		{
69
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   183
		CFeedInfo *info = GetFeedInfoByUid(iFeedsUpdating[0]);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
		iFeedsUpdating.Remove(0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   185
		
69
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   186
		if (info == NULL)
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   187
			{
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   188
			UpdateNextFeedL();
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   189
			}
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   190
		else
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
			{
69
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   192
			TBool result = EFalse;
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   193
			//DP2("** UpdateNextFeed: %S, ID: %u", &(info->Url()), info->Uid());
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   194
			TRAPD(error, result = UpdateFeedL(info->Uid()));
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   195
			
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   196
			if (error != KErrNone || !result)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
				{
69
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   198
				DP("Error while updating all feeds");
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   199
				for (TInt i=0;i<iObservers.Count();i++) 
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   200
					{
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   201
					TRAP_IGNORE(iObservers[i]->FeedUpdateAllCompleteL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate));
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   202
					}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   203
				}
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
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   207
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
		iClientState = EIdle;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
		for (TInt i=0;i<iObservers.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   210
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   211
			TRAP_IGNORE(iObservers[i]->FeedUpdateAllCompleteL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   212
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
EXPORT_C TBool CFeedEngine::UpdateFeedL(TUint aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   217
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   218
	DP("FeedEngine::UpdateFeedL BEGIN");
69
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   219
	
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   220
	if (iActiveFeed)
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   221
		{
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   222
		User::Leave(KErrInUse);
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   223
		}
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   224
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   225
	iActiveFeed = GetFeedInfoByUid(aFeedUid);
73
83752b9e3cb6 Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents: 69
diff changeset
   226
	
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   227
	iCancelRequested = EFalse;
2
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
	if (iActiveFeed->LastUpdated() == 0)
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
		iCatchupMode = ETrue;
73
83752b9e3cb6 Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents: 69
diff changeset
   232
		iCatchupCounter = 0;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
		}
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   234
	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   235
	iActiveFeed->SetLastError(KErrNone);
36
e010fc411ddc Merge, plus minor fix to CFeedEngine
Brendan Donegan <brendand@symbian.org>
parents: 35 32
diff changeset
   236
	DBUpdateFeedL(*iActiveFeed);
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   237
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
	iUpdatingFeedFileName.Copy (iPodcastModel.SettingsEngine().PrivatePath ());
75
554d9980157f Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents: 74
diff changeset
   239
	iUpdatingFeedFileName.Append(KFeedParseStorePath);
554d9980157f Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents: 74
diff changeset
   240
	BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), iUpdatingFeedFileName);
554d9980157f Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents: 74
diff changeset
   241
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
	_LIT(KFileNameFormat, "%lu.xml");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
	iUpdatingFeedFileName.AppendFormat(KFileNameFormat, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
	if(iFeedClient->GetL(iActiveFeed->Url(), iUpdatingFeedFileName, iPodcastModel.SettingsEngine().SpecificIAP()))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
		iClientState = EUpdatingFeed;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
		for (TInt i=0;i<iObservers.Count();i++)
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
			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
   252
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   254
		DP("FeedEngine::UpdateFeedL END, return ETrue");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
		return ETrue;
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
	else
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
		DP("FeedEngine::UpdateFeedL END, return EFalse");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
		return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   263
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   264
void CFeedEngine::NewShowL(CShowInfo& aItem)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
	HBufC* description = HBufC::NewLC(KMaxDescriptionLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   267
	TPtr ptr(description->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   268
	ptr.Copy(aItem.Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
	PodcastUtils::CleanHtmlL(ptr);
8
aab3aa4acdd6 Checked all TRAP_IGNORE
teknolog
parents: 7
diff changeset
   270
aab3aa4acdd6 Checked all TRAP_IGNORE
teknolog
parents: 7
diff changeset
   271
	aItem.SetDescriptionL(*description);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
	CleanupStack::PopAndDestroy(description);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
	if (iCatchupMode) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
		// in catchup mode, we let one show be unplayed
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
		if (++iCatchupCounter > 1) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
			aItem.SetPlayState(EPlayed);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   280
	
78
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 77
diff changeset
   281
	TRAPD(err, iPodcastModel.ShowEngine().AddShowL(aItem));
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
78
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 77
diff changeset
   283
	if (err == KErrNone && aItem.PlayState() == ENeverPlayed && 
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 77
diff changeset
   284
			iPodcastModel.SettingsEngine().DownloadAutomatically()) 
2
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
		iPodcastModel.ShowEngine().AddDownloadL(aItem);
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
	}
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
void CFeedEngine::GetFeedImageL(CFeedInfo *aFeedInfo)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
	DP("GetFeedImage");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
	TFileName filePath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
	filePath.Copy(iPodcastModel.SettingsEngine().BaseDir());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
	// create relative file name
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   298
	TFileName relPath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   299
	relPath.Copy(aFeedInfo->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   300
	relPath.Append('\\');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
	TFileName fileName;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
	PodcastUtils::FileNameFromUrl(aFeedInfo->ImageUrl(), fileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
	relPath.Append(fileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
	PodcastUtils::EnsureProperPathName(relPath);
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
	// complete file path is base dir + rel path
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   308
	filePath.Append(relPath);
67
e0fc52a5df4d Update to keep features from merge.
Lars Persson <lars.persson@embeddev.se>
parents: 66
diff changeset
   309
	aFeedInfo->SetImageFileNameL(filePath, NULL);
2
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
	if(iFeedClient->GetL(aFeedInfo->ImageUrl(), filePath, ETrue))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   312
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   313
			iClientState = EUpdatingImage;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   314
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   315
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   316
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   317
EXPORT_C TBool CFeedEngine::AddFeedL(const CFeedInfo&aItem) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   318
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   319
	DP2("CFeedEngine::AddFeed, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   320
	for (TInt i=0;i<iSortedFeeds.Count();i++) 
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
		if (iSortedFeeds[i]->Uid() == aItem.Uid()) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   323
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   324
			DP1("Already have feed %S, discarding", &aItem.Url());			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   325
			return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   326
			}
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
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   329
	TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   330
	CFeedInfo* newItem = aItem.CopyL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   331
	CleanupStack::PushL(newItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   332
	User::LeaveIfError(iSortedFeeds.InsertInOrder(newItem, sortOrder));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   333
	CleanupStack::Pop(newItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   334
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   335
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   336
	// Save the feeds into DB
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   337
	DBAddFeedL(aItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   338
	return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   339
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   340
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   341
void CFeedEngine::DBAddFeedL(const CFeedInfo& aItem)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   342
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   343
	DP2("CFeedEngine::DBAddFeed, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   344
	
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   345
	CFeedInfo *info;
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   346
	
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   347
	TRAPD(err, DBGetFeedInfoByUidL(aItem.Uid()));
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   348
	
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   349
	if (err == KErrNone && info) {
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   350
		delete info;
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   351
		User::Leave(KErrAlreadyExists);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   352
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   353
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   354
	HBufC* titleBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   355
	TPtr titlePtr(titleBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   356
	titlePtr.Copy(aItem.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   357
	PodcastUtils::SQLEncode(titlePtr);
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
	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   360
	TPtr descPtr(descBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   361
	descPtr.Copy(aItem.Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   362
	PodcastUtils::SQLEncode(descPtr);
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
	_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
   365
			" 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
   366
	iSqlBuffer.Format(KSqlStatement,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   367
			&aItem.Url(), titleBuf, descBuf, &aItem.ImageUrl(), &aItem.ImageFileName(), &aItem.Link(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   368
			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
   369
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   370
	CleanupStack::PopAndDestroy(descBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   371
	CleanupStack::PopAndDestroy(titleBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   372
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   373
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   374
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   375
	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
   376
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   377
	if (rc==SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   378
		{
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   379
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   380
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   381
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   382
		if (rc != SQLITE_DONE)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   383
			{
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   384
			User::Leave(KErrCorrupt);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   385
			}
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   386
		CleanupStack::PopAndDestroy(); // st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   387
		}
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   388
	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   389
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   390
		User::Leave(KErrCorrupt);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   391
		}
2
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   394
EXPORT_C void CFeedEngine::RemoveFeedL(TUint aUid) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   395
	{
69
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   396
	if (iActiveFeed && iActiveFeed->Uid() == aUid)
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   397
		{
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   398
		User::Leave(KErrInUse);
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   399
		}
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   400
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   401
	for (int i=0;i<iSortedFeeds.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   402
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   403
		if (iSortedFeeds[i]->Uid() == aUid) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   404
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   405
			iPodcastModel.ShowEngine().DeleteAllShowsByFeedL(aUid);
52
b778853e60a7 Fix for bug 2217
teknolog
parents: 36
diff changeset
   406
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   407
			CFeedInfo* feedToRemove = iSortedFeeds[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   408
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   409
			//delete the image file if it exists
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   410
			if ((feedToRemove->ImageFileName().Length() >0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   411
					&& BaflUtils::FileExists(iPodcastModel.FsSession(), feedToRemove->ImageFileName()))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   412
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   413
				iPodcastModel.FsSession().Delete(feedToRemove->ImageFileName());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   414
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   415
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   416
			//delete the folder. It has the same name as the title.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   417
			TFileName filePath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   418
			filePath.Copy(iPodcastModel.SettingsEngine().BaseDir());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   419
			filePath.Append(feedToRemove->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   420
			filePath.Append('\\');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   421
			iPodcastModel.FsSession().RmDir(filePath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   422
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   423
			iSortedFeeds.Remove(i);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   424
			delete feedToRemove;
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
			DP("Removed feed from array");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   427
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   428
			// now remove it from DB
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   429
			DBRemoveFeedL(aUid);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   430
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   431
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   432
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   433
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   434
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   435
void CFeedEngine::DBRemoveFeedL(TUint aUid)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   436
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   437
	DP("CFeedEngine::DBRemoveFeed");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   438
	_LIT(KSqlStatement, "delete from feeds where uid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   439
	iSqlBuffer.Format(KSqlStatement, aUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   440
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   441
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   442
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   443
	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
   444
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   445
	if (rc==SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   446
		{
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   447
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   448
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   449
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   450
		if (rc != SQLITE_DONE)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   451
			{
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   452
			User::Leave(KErrNotFound);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   453
			}
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   454
		
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   455
		CleanupStack::PopAndDestroy(); //st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   456
		}
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   457
	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   458
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   459
		User::Leave(KErrCorrupt);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   460
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   461
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   462
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   463
void CFeedEngine::DBUpdateFeedL(const CFeedInfo &aItem)
2
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
	DP2("CFeedEngine::DBUpdateFeed, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
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
	HBufC* titleBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   468
	TPtr titlePtr(titleBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   469
	titlePtr.Copy(aItem.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   470
	PodcastUtils::SQLEncode(titlePtr);
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
	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   473
	TPtr descPtr(descBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   474
	descPtr.Copy(aItem.Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   475
	PodcastUtils::SQLEncode(descPtr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   476
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   477
	_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
   478
			"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
   479
	iSqlBuffer.Format(KSqlStatement,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   480
			&aItem.Url(), titleBuf, descBuf, &aItem.ImageUrl(), &aItem.ImageFileName(), &aItem.Link(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   481
			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
   482
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   483
	CleanupStack::PopAndDestroy(descBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   484
	CleanupStack::PopAndDestroy(titleBuf);
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
	sqlite3_stmt *st;
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
	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
   489
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   490
	if (rc==SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   491
		{
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   492
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   493
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   494
		
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   495
		if (rc != SQLITE_DONE)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   496
			{
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   497
			User::Leave(KErrNotFound);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   498
			}
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   499
		CleanupStack::PopAndDestroy(); //st
2
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
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   502
		{
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   503
		User::Leave(KErrCorrupt);
2
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::ParsingCompleteL(CFeedInfo *item)
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
	TBuf<KMaxLineLength> title;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   510
	title.Copy(item->Title());
8
aab3aa4acdd6 Checked all TRAP_IGNORE
teknolog
parents: 7
diff changeset
   511
	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
   512
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   513
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   514
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   515
EXPORT_C void CFeedEngine::AddObserver(MFeedEngineObserver *observer)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   516
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   517
	iObservers.Append(observer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   518
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   519
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   520
EXPORT_C void CFeedEngine::RemoveObserver(MFeedEngineObserver *observer)
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
	TInt index = iObservers.Find(observer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   523
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   524
	if (index > KErrNotFound)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   525
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   526
		iObservers.Remove(index);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   527
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   528
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   529
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   530
void CFeedEngine::Connected(CHttpClient* /*aClient*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   531
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   532
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   533
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   534
void CFeedEngine::Progress(CHttpClient* /*aHttpClient*/, TInt /*aBytes*/, TInt /*aTotalBytes*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   535
	{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   536
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   537
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   538
void CFeedEngine::CompleteL(CHttpClient* /*aClient*/, TInt aError)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   539
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   540
	DP2("CFeedEngine::CompleteL BEGIN, iClientState=%d, aSuccessful=%d", iClientState, aError);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   541
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   542
	switch(iClientState)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   543
		{		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   544
		case EUpdatingFeed: 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   545
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   546
		iClientState = EIdle;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   547
		switch (aError)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   548
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   549
			case KErrCancel:						
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   550
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   551
				iFeedsUpdating.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   552
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   553
				break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   554
			case KErrCouldNotConnect:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   555
				iFeedsUpdating.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   556
				break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   557
			default:
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
				if (!iCancelRequested) {
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   560
					iActiveFeed->SetLastError(aError);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   561
					TTime time;
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   562
					time.HomeTime();
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   563
					iActiveFeed->SetLastUpdated(time);
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( aError == KErrNone)
73
83752b9e3cb6 Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents: 69
diff changeset
   566
						{
83752b9e3cb6 Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents: 69
diff changeset
   567
						// Parse the feed. We need to trap this call since it could leave and then
83752b9e3cb6 Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents: 69
diff changeset
   568
						// the whole update chain will be broken
83752b9e3cb6 Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents: 69
diff changeset
   569
						// change client state
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   570
						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
   571
	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   572
						if(parserErr)
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   573
							{
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   574
							// 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
   575
							iActiveFeed->SetLastError(parserErr);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   576
							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
   577
							}
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   578
						else
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   579
							{
78
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 77
diff changeset
   580
							iPodcastModel.ShowEngine().DeleteOldShowsByFeedL(iActiveFeed->Uid());
32
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
						// 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
   584
						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
   585
	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   586
						// 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
   587
						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
   588
							{
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   589
							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
   590
									(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
   591
											!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
   592
													iActiveFeed->ImageFileName()) )
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   593
							)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   594
								{
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   595
								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
   596
								if (error)
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   597
									{
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   598
									// 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
   599
									// 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
   600
									iActiveFeed->SetLastError(parserErr);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   601
									iClientState = EIdle;							
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   602
									}
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   603
								}	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   604
							}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   605
						}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   606
					}
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   607
				iCancelRequested = EFalse;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   608
				}break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   609
			}
74
af6475fdf8d6 Improved error handling; Implemented support for more than 2 flash drives also for import/export feeds
teknolog
parents: 73
diff changeset
   610
			DBUpdateFeedL(*iActiveFeed);
63
a8538f50e2ba Merge with lars' fixes
teknolog
parents: 52 60
diff changeset
   611
			NotifyFeedUpdateComplete(iActiveFeed->Uid(), aError);
a8538f50e2ba Merge with lars' fixes
teknolog
parents: 52 60
diff changeset
   612
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   613
			// 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
   614
			if (iClientState == EIdle)
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   615
				{
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   616
				UpdateNextFeedL();	
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   617
				}
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   618
			}break;
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   619
		case EUpdatingImage:
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   620
			{
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   621
			// change client state to not updating
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   622
			iClientState = EIdle;
58
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   623
			if(aError == KErrNone)
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   624
				{
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   625
				// now the image has been downloaded, so we set it again in the FeedInfo to start
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   626
				// converting it
77
403412eb5292 Added "Reset database" option in settings. Further robustness fixes for Feeds.
teknolog
parents: 76
diff changeset
   627
				HBufC *fileNameCopy = iActiveFeed->ImageFileName().AllocLC();
403412eb5292 Added "Reset database" option in settings. Further robustness fixes for Feeds.
teknolog
parents: 76
diff changeset
   628
				TRAP_IGNORE(iActiveFeed->SetImageFileNameL(*fileNameCopy, &iPodcastModel));
403412eb5292 Added "Reset database" option in settings. Further robustness fixes for Feeds.
teknolog
parents: 76
diff changeset
   629
				CleanupStack::PopAndDestroy(fileNameCopy);
58
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   630
				}
73
83752b9e3cb6 Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents: 69
diff changeset
   631
			DBUpdateFeedL(*iActiveFeed);
63
a8538f50e2ba Merge with lars' fixes
teknolog
parents: 52 60
diff changeset
   632
			NotifyFeedUpdateComplete(iActiveFeed->Uid(), aError);
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   633
			UpdateNextFeedL();
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   634
			}break;
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   635
		case ESearching: 
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   636
			{
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   637
			iClientState = EIdle;
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   638
	
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   639
			DP2("Search complete, results in %S with error %d", &iSearchResultsFileName, aError);
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   640
			if(aError == KErrNone)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   641
				{
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   642
				if (!iOpmlParser) 
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   643
					{
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   644
					iOpmlParser = new COpmlParser(*this, iPodcastModel.FsSession());
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   645
					}
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   646
	
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   647
				DP("Parsing OPML");
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   648
				iOpmlParser->ParseOpmlL(iSearchResultsFileName, ETrue);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   649
				}
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   650
			else
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   651
				{
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
   652
				NotifyOpmlParsingCompleteL(aError, 0);
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   653
				}
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   654
			
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   655
			BaflUtils::DeleteFile(iPodcastModel.FsSession(), iSearchResultsFileName);
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   656
			}break;
69
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   657
		default:
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   658
			User::Panic(_L("FeedEngine"), KErrUnknown);
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
   659
			break;
2
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
	DP("CFeedEngine::CompleteL END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   662
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   663
60
bbf5c5204844 We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents: 58
diff changeset
   664
void CFeedEngine::NotifyFeedUpdateComplete(TInt aFeedUid, TInt aError)
bbf5c5204844 We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents: 58
diff changeset
   665
	{
bbf5c5204844 We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents: 58
diff changeset
   666
	DP("CFeedEngine::NotifyFeedUpdateComplete");	
bbf5c5204844 We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents: 58
diff changeset
   667
	for (TInt i=0;i<iObservers.Count();i++) 
bbf5c5204844 We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents: 58
diff changeset
   668
		{
bbf5c5204844 We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents: 58
diff changeset
   669
		TRAP_IGNORE(iObservers[i]->FeedDownloadFinishedL(MFeedEngineObserver::EFeedAutoUpdate, aFeedUid, aError));
bbf5c5204844 We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents: 58
diff changeset
   670
		}
bbf5c5204844 We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents: 58
diff changeset
   671
	}
bbf5c5204844 We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents: 58
diff changeset
   672
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   673
void CFeedEngine::Disconnected(CHttpClient* /*aClient*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   674
	{
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   677
void CFeedEngine::DownloadInfo(CHttpClient* /*aHttpClient */, int /*aTotalBytes*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   678
	{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   679
	/*DP1("About to download %d bytes", aTotalBytes);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   680
	if(aHttpClient == iShowClient && iShowDownloading != NULL && aTotalBytes != -1) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   681
		iShowDownloading->iShowSize = aTotalBytes;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   682
		}*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   683
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   684
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   685
EXPORT_C void CFeedEngine::ImportFeedsL(const TDesC& aFile)
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
	TFileName opmlPath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   688
	opmlPath.Copy(aFile);
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
	if (!iOpmlParser) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   691
		iOpmlParser = new COpmlParser(*this, iPodcastModel.FsSession());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   692
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   693
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   694
	iOpmlParser->ParseOpmlL(opmlPath, EFalse);
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   697
EXPORT_C TBool CFeedEngine::ExportFeedsL(TFileName& aFile)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   698
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   699
	RFile rfile;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   700
	TFileName privatePath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   701
	iPodcastModel.FsSession().PrivatePath(privatePath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   702
	TInt error = rfile.Temp(iPodcastModel.FsSession(), privatePath, aFile, EFileWrite);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   703
	if (error != KErrNone) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   704
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   705
		DP("CFeedEngine::ExportFeedsL()\tFailed to open file");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   706
		return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   707
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   708
	CleanupClosePushL(rfile);
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
	HBufC* templ = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   711
	templ->Des().Copy(KOpmlFeed());
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
	HBufC* line = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   714
	HBufC* xmlUrl = HBufC::NewLC(KMaxURLLength);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   715
	HBufC* htmlUrl = HBufC::NewLC(KMaxURLLength);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   716
	HBufC* desc = HBufC::NewLC(KMaxDescriptionLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   717
	HBufC* title = HBufC::NewLC(KMaxTitleLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   718
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   719
	HBufC8* utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(KOpmlHeader());
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
	rfile.Write(*utf8line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   722
	delete utf8line;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   723
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   724
	for (int i=0; i<iSortedFeeds.Count(); i++)
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
		CFeedInfo *info = iSortedFeeds[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   727
		DP1("Exporting feed '%S'", &iSortedFeeds[i]->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   728
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   729
	// XML URL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   730
		TPtr ptrXml(xmlUrl->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   731
		if (info->Url() != KNullDesC)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   732
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   733
			ptrXml.Copy(info->Url());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   734
			PodcastUtils::XMLEncode(ptrXml);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   735
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   736
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   737
	// Description	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   738
		TPtr ptrDesc(desc->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   739
		ptrDesc.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   740
		if (info->Description() != KNullDesC) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   741
			ptrDesc.Copy(info->Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   742
			PodcastUtils::XMLEncode(ptrDesc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   743
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   744
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   745
	// Title	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   746
		TPtr ptrTitle(title->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   747
		ptrTitle.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   748
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   749
		if (info->Title() != KNullDesC) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   750
			ptrTitle.Copy(info->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   751
			PodcastUtils::XMLEncode(ptrTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   752
		}
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
	// HTML URL	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   755
		TPtr ptrHtmlUrl(htmlUrl->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   756
		ptrHtmlUrl.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   757
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   758
		if (info->Link() != KNullDesC) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   759
			ptrHtmlUrl.Copy(info->Link());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   760
			PodcastUtils::XMLEncode(ptrHtmlUrl);
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
	// Write line to OPML file
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   763
		line->Des().Format(*templ, title, desc, xmlUrl, htmlUrl);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   764
		utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(*line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   765
		rfile.Write(*utf8line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   766
		delete utf8line;
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
	utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(KOpmlFooter());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   770
	rfile.Write(*utf8line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   771
	delete utf8line;
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
	CleanupStack::PopAndDestroy(7);//destroy 6 bufs & close rfile
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   774
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   775
	return ETrue;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   778
EXPORT_C CFeedInfo* CFeedEngine::GetFeedInfoByUid(TUint aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   779
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   780
	TInt cnt = iSortedFeeds.Count();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   781
	for (TInt i=0;i<cnt;i++)
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
		if (iSortedFeeds[i]->Uid() == aFeedUid)
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
			return iSortedFeeds[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   786
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   787
		}
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
	return NULL;
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
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   792
EXPORT_C const RFeedInfoArray& CFeedEngine::GetSortedFeeds()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   793
{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   794
	TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
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
	iSortedFeeds.Sort(sortOrder);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   797
	return iSortedFeeds;
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
TInt CFeedEngine::CompareFeedsByTitle(const CFeedInfo &a, const CFeedInfo &b)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   801
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   802
		//DP2("Comparing %S to %S", &a.Title(), &b.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   803
		return a.Title().CompareF(b.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   804
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   805
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   806
EXPORT_C void CFeedEngine::GetStatsByFeedL(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   807
	{
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   808
	//DP1("CFeedEngine::GetStatsByFeed, aFeedUid=%u", aFeedUid);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   809
	DBGetStatsByFeedL(aFeedUid, aNumShows, aNumUnplayed);
2
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
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   812
void CFeedEngine::DBGetStatsByFeedL(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   813
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   814
	//DP1("CFeedEngine::DBGetStatsByFeed, feedUid=%u", aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   815
	_LIT(KSqlStatement, "select count(*) from shows where feeduid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   816
	iSqlBuffer.Format(KSqlStatement, aFeedUid);
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
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   819
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   820
	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
   821
	
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   822
	if( rc==SQLITE_OK)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   823
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   824
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   825
	  	rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   826
	  	
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   827
	  	if (rc == SQLITE_ROW)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   828
	  		{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   829
	  		aNumShows = sqlite3_column_int(st, 0);
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   830
	  		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   831
	  	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   832
	  		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   833
			User::Leave(KErrNotFound);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   834
	  		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   835
	  	CleanupStack::PopAndDestroy(); // st
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   836
		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   837
	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   838
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   839
		User::Leave(KErrCorrupt);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   840
		}
2
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
	_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
   843
	iSqlBuffer.Format(KSqlStatement2, aFeedUid);
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
	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
   846
		
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   847
	if(rc==SQLITE_OK)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   848
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   849
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   850
	  	rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   851
	  	
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   852
	  	if (rc == SQLITE_ROW)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   853
	  		{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   854
	  		aNumUnplayed = sqlite3_column_int(st, 0);
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   855
	  		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   856
	  	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   857
	  		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   858
			User::Leave(KErrNotFound);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   859
	  		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   860
	  	CleanupStack::PopAndDestroy(); // st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   861
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   862
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   863
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   864
TUint CFeedEngine::DBGetFeedCountL()
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   865
	{
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   866
	DP("DBGetFeedCount BEGIN");
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   867
	sqlite3_stmt *st;
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   868
	int rc = sqlite3_prepare_v2(&iDB,"select count(*) from feeds" , -1, &st, (const char**) NULL);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   869
	TUint size = 0;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   870
	 
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   871
	if( rc==SQLITE_OK )
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   872
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   873
		Cleanup_sqlite3_finalize_PushL(st);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   874
		rc = sqlite3_step(st);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   875
			
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   876
		if (rc == SQLITE_ROW)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   877
			{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   878
	  		size = sqlite3_column_int(st, 0);
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   879
	  		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   880
		else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   881
			{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   882
	  		User::Leave(KErrCorrupt);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   883
	  		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   884
		CleanupStack::PopAndDestroy(); // st
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   885
		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   886
	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   887
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   888
		User::Leave(KErrCorrupt);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   889
		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   890
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   891
	DP1("DBGetFeedCount END=%d", size);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   892
	return size;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   893
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   894
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   895
void CFeedEngine::DBLoadFeedsL()
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
	DP("DBLoadFeeds BEGIN");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   898
	iSortedFeeds.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   899
	CFeedInfo *feedInfo = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   900
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   901
	_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
   902
	iSqlBuffer.Format(KSqlStatement);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   903
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   904
	sqlite3_stmt *st;
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
	TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   907
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   908
	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
   909
	
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   910
	if (rc==SQLITE_OK)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   911
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   912
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   913
		rc = sqlite3_step(st);
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   914
		while(rc == SQLITE_ROW) 
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   915
			{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   916
			feedInfo = CFeedInfo::NewLC();
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 *urlz = sqlite3_column_text16(st, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   919
			TPtrC16 url((const TUint16*)urlz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   920
			feedInfo->SetUrlL(url);
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 *titlez = sqlite3_column_text16(st, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   923
			TPtrC16 title((const TUint16*)titlez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   924
			feedInfo->SetTitleL(title);
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
			const void *descz = sqlite3_column_text16(st, 2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   927
			TPtrC16 desc((const TUint16*)descz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   928
			feedInfo->SetDescriptionL(desc);
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
			const void *imagez = sqlite3_column_text16(st, 3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   931
			TPtrC16 image((const TUint16*)imagez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   932
			feedInfo->SetImageUrlL(image);
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
			const void *imagefilez = sqlite3_column_text16(st, 4);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   935
			TPtrC16 imagefile((const TUint16*)imagefilez);
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   936
			if (imagefile.Length() > 0)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   937
				{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   938
				feedInfo->SetImageFileNameL(imagefile, &iPodcastModel);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   939
				}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   940
			
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   941
			const void *linkz = sqlite3_column_text16(st, 5);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   942
			TPtrC16 link((const TUint16*)linkz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   943
			feedInfo->SetDescriptionL(link);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   944
					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   945
			sqlite3_int64 built = sqlite3_column_int64(st, 6);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   946
			TTime buildtime(built);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   947
			feedInfo->SetBuildDate(buildtime);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   948
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   949
			sqlite3_int64 lastupdated = sqlite3_column_int64(st, 7);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   950
			TTime lastupdatedtime(lastupdated);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   951
			feedInfo->SetLastUpdated(lastupdatedtime);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   952
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   953
			sqlite3_int64 customtitle = sqlite3_column_int64(st, 10);
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   954
			if (customtitle)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   955
				{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   956
				feedInfo->SetCustomTitle();
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   957
				}
2
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
			TInt lasterror = sqlite3_column_int(st, 11);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   960
			feedInfo->SetLastError(lasterror);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   961
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   962
			TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
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
			iSortedFeeds.InsertInOrder(feedInfo, sortOrder);
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
			CleanupStack::Pop(feedInfo);
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
			rc = sqlite3_step(st);
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   969
			}	
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   970
		CleanupStack::PopAndDestroy();//st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   971
		}
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   972
	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   973
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   974
		User::Leave(KErrCorrupt);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   975
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   976
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   977
	DP("DBLoadFeeds END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   978
	}
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
CFeedInfo* CFeedEngine::DBGetFeedInfoByUidL(TUint aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   981
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   982
	DP("CFeedEngine::DBGetFeedInfoByUid");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   983
	CFeedInfo *feedInfo = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   984
	_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
   985
	iSqlBuffer.Format(KSqlStatement, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   986
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   987
	sqlite3_stmt *st;
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   988
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   989
	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
   990
	
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   991
	if (rc==SQLITE_OK)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   992
		{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   993
		Cleanup_sqlite3_finalize_PushL(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   994
		rc = sqlite3_step(st);
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   995
		if (rc == SQLITE_ROW)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
   996
			{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   997
			feedInfo = CFeedInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   998
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   999
			const void *urlz = sqlite3_column_text16(st, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1000
			TPtrC16 url((const TUint16*)urlz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1001
			feedInfo->SetUrlL(url);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1002
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1003
			const void *titlez = sqlite3_column_text16(st, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1004
			TPtrC16 title((const TUint16*)titlez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1005
			feedInfo->SetTitleL(title);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1006
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1007
			const void *descz = sqlite3_column_text16(st, 2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1008
			TPtrC16 desc((const TUint16*)descz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1009
			feedInfo->SetDescriptionL(desc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1010
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1011
			const void *imagez = sqlite3_column_text16(st, 3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1012
			TPtrC16 image((const TUint16*)imagez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1013
			feedInfo->SetImageUrlL(image);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1014
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1015
			const void *imagefilez = sqlite3_column_text16(st, 4);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1016
			TPtrC16 imagefile((const TUint16*)imagefilez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1017
			feedInfo->SetDescriptionL(imagefile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1018
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1019
			const void *linkz = sqlite3_column_text16(st, 5);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1020
			TPtrC16 link((const TUint16*)linkz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1021
			feedInfo->SetDescriptionL(link);
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
			sqlite3_int64 built = sqlite3_column_int64(st, 6);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1024
			TTime buildtime(built);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1025
			feedInfo->SetBuildDate(buildtime);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1026
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1027
			sqlite3_int64 lastupdated = sqlite3_column_int64(st, 7);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1028
			TTime lastupdatedtime(lastupdated);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1029
			feedInfo->SetLastUpdated(lastupdatedtime);
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
			sqlite3_int64 customtitle = sqlite3_column_int64(st, 10);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1032
			if (customtitle) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1033
				feedInfo->SetCustomTitle();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1034
			}
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
			TInt lasterror = sqlite3_column_int(st, 11);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1037
			feedInfo->SetLastError(lasterror);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1038
						
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1039
			CleanupStack::Pop(feedInfo);
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
  1040
			}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
  1041
		else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
  1042
			{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
  1043
			User::Leave(KErrNotFound);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
  1044
			}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1045
		CleanupStack::PopAndDestroy();//st	
76
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
  1046
		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
  1047
	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
  1048
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
  1049
		User::Leave(KErrNotFound);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 75
diff changeset
  1050
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1051
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1052
	return feedInfo;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1053
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1054
69
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
  1055
EXPORT_C void CFeedEngine::UpdateFeedInfoL(CFeedInfo *aItem)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1056
	{
69
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
  1057
	if (iActiveFeed && iActiveFeed->Uid() == aItem->Uid())
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
  1058
		{
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
  1059
		User::Leave(KErrInUse);
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
  1060
		}
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 67
diff changeset
  1061
	
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
  1062
	DBUpdateFeedL(*aItem);
2
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1065
EXPORT_C void CFeedEngine::SearchForFeedL(TDesC& aSearchString)
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
	DP1("FeedEngine::SearchForFeedL BEGIN, aSearchString=%S", &aSearchString);
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
	if (iClientState != EIdle) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1070
		User::Leave(KErrInUse);
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
	TBuf<KMaxURLLength> ssBuf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1073
	ssBuf.Copy(aSearchString);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1074
	PodcastUtils::ReplaceString(ssBuf, _L(" "), _L("%20"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1075
	// prepare search URL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1076
	HBufC* templ = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1077
	templ->Des().Copy(KSearchUrl());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1078
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1079
	HBufC* url = HBufC::NewLC(KMaxURLLength);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1080
	url->Des().Format(*templ, &ssBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1081
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1082
	DP1("SearchURL: %S", url);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1083
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1084
	// crate path to store OPML search results
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1085
	iPodcastModel.FsSession().PrivatePath(iSearchResultsFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1086
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1087
	iSearchResultsFileName.Append(KSearchResultsFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1088
	iSearchResults.ResetAndDestroy();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1089
	// run search
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1090
	if(iFeedClient->GetL(*url, iSearchResultsFileName, iPodcastModel.SettingsEngine().SpecificIAP()))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1091
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1092
		iClientState = ESearching;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1093
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1094
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1095
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1096
		iClientState = EIdle;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1097
		User::Leave(KErrAbort);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1098
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1099
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1100
	CleanupStack::PopAndDestroy(url);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1101
	CleanupStack::PopAndDestroy(templ);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1102
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1103
	DP("FeedEngine::SearchForFeedL END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1104
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1105
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1106
EXPORT_C void CFeedEngine::AddSearchResultL(CFeedInfo *item)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1107
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1108
	DP1("CFeedEngine::AddSearchResultL, item->Title()=%S", &(item->Title()));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1109
	iSearchResults.AppendL(item);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1110
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1111
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1112
EXPORT_C const RFeedInfoArray& CFeedEngine::GetSearchResults()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1113
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1114
	return iSearchResults;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1115
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1116
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1117
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
  1118
EXPORT_C void CFeedEngine::OpmlParsingCompleteL(TInt aError, TUint aNumFeedsAdded)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1119
	{
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
  1120
	NotifyOpmlParsingCompleteL(aError, aNumFeedsAdded);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1121
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1122
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
  1123
void CFeedEngine::NotifyOpmlParsingCompleteL(TInt aError, TUint aNumFeedsAdded)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1124
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1125
	for (TInt i=0;i<iObservers.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1126
		{
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
  1127
		iObservers[i]->OpmlParsingComplete(aError, aNumFeedsAdded);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1128
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1129
	}