engine/src/FeedEngine.cpp
author Sebastian Brannstrom <sebastianb@symbian.org>
Sat, 23 Oct 2010 16:38:32 +0100
branchRCL_3
changeset 274 03285b1fc18d
parent 255 a13c58ace598
child 328 75a70f4a4f6d
permissions -rw-r--r--
Updated SIS, version 1.00.5
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>
114
27f6f5827e5d Cleaned up panic handling
teknolog
parents: 111
diff changeset
    29
#include "Podcatcher.pan"
187
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
    30
#include <centralrepository.h>
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
    31
#include <ProfileEngineSDKCRKeys.h>
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
    32
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
108
554d9980157f Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents: 107
diff changeset
    34
_LIT(KFeedParseStorePath, "feeds\\");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
187
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
    36
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
CFeedEngine* CFeedEngine::NewL(CPodcastModel& aPodcastModel)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
	CFeedEngine* self = new (ELeave) CFeedEngine(aPodcastModel);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
	CleanupStack::PushL(self);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    41
	self->ConstructL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
	CleanupStack::Pop(self);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
	return self;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
void CFeedEngine::ConstructL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
	iParser = new (ELeave) CFeedParser(*this, iPodcastModel.FsSession());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
	iFeedClient = CHttpClient::NewL(iPodcastModel, *this);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
	iFeedTimer.ConstructL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
	
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    53
	TInt err = KErrNone;
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    54
	TInt feedCount = 0;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
	
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    56
	TRAP(err, feedCount = DBGetFeedCountL());
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    57
    if (err == KErrNone && feedCount > 0)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
    	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
		DP("Loading feeds from DB");
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    60
		TRAP(err, DBLoadFeedsL());
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    61
    	}		
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    62
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
    
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    64
	if (err != KErrNone || iPodcastModel.IsFirstStartup()) {
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
		TFileName defaultFile = iPodcastModel.SettingsEngine().DefaultFeedsFileName();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
		DP1("Loading default feeds from %S", &defaultFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
		if (BaflUtils::FileExists(iPodcastModel.FsSession(), defaultFile)) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
			ImportFeedsL(defaultFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    69
		}
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    70
	} 
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    71
	
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    72
	// clean out feeds temp directory
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    73
	TFileName feedTempPath;
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    74
	feedTempPath.Copy (iPodcastModel.SettingsEngine().PrivatePath ());
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    75
	feedTempPath.Append(KFeedParseStorePath);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    76
	feedTempPath.Append(_L("*"));
108
554d9980157f Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents: 107
diff changeset
    77
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    78
	BaflUtils::EnsurePathExistsL(iPodcastModel.FsSession(), feedTempPath);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    79
	BaflUtils::DeleteFile(iPodcastModel.FsSession(),feedTempPath);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
    
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
    TFileName importFile = iPodcastModel.SettingsEngine().ImportFeedsFileName();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
    if (BaflUtils::FileExists(iPodcastModel.FsSession(), importFile)) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
    	DP("Importing feeds");
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    84
    	TRAP_IGNORE(ImportFeedsL(importFile));
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
		}
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    86
    
187
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
    87
    
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
    88
    // offline profile support
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
    89
    iRepository = CRepository::NewL( KCRUidProfileEngine );
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
    90
    
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
    91
	RunFeedTimer();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
CFeedEngine::CFeedEngine(CPodcastModel& aPodcastModel)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
		: iClientState(EIdle),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
		  iFeedTimer(this),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
		  iPodcastModel(aPodcastModel),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
		  iDB(*aPodcastModel.DB())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
CFeedEngine::~CFeedEngine()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
	iObservers.Close();
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
	iFeedsUpdating.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
	iSortedFeeds.ResetAndDestroy();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
	iSearchResults.ResetAndDestroy();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
	delete iParser;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
	delete iFeedClient;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
	delete iOpmlParser;
187
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   113
	//
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   114
	delete iRepository;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
/**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
 * Returns the current internal state of the feed engine4
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   120
EXPORT_C TClientState CFeedEngine::ClientState()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   121
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   122
	return iClientState;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   123
	}
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
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
 * Returns the current updating client UID if clientstate is != ENotUpdateing
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
 * @return TUint
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
EXPORT_C TUint CFeedEngine::ActiveClientUid()
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(iActiveFeed != NULL)
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
		return iActiveFeed->Uid();
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
	return 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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
void CFeedEngine::RunFeedTimer()
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
	iFeedTimer.Cancel();
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
	if (iPodcastModel.SettingsEngine().UpdateAutomatically() != EAutoUpdateOff)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   145
		TInt interval = iPodcastModel.SettingsEngine().UpdateFeedInterval();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   146
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
		if (interval != 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
			iFeedTimer.SetPeriod(interval);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
			iFeedTimer.RunPeriodically();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   152
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
EXPORT_C void CFeedEngine::UpdateAllFeedsL(TBool aAutoUpdate)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
	{
126
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   157
	if (iClientState != EIdle)
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   158
		{
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   159
		User::Leave(KErrInUse);
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   160
		}
187
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   161
	// check for offline profile, done by polling here, perhpas CenRep notifier woudl be better
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   162
	TInt currentProfileId = 0; // general profile
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   163
	TBool isOfflineProfile = EFalse;
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   164
	// Get ID of current profile
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   165
	if(KErrNone == iRepository->Get( KProEngActiveProfile, currentProfileId ) ) // better to assume online then leave if CRep fails
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   166
		{
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   167
		// Check value to determine the active profile if no error
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   168
		if ( 5 == currentProfileId)
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   169
			{
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   170
			// current profile is the offline profile
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   171
			isOfflineProfile = ETrue;
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   172
			}
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   173
	    }
45e21fd808cd Fix for bug 2716
jakl.martin@cell-telecom.com
parents: 172
diff changeset
   174
	//
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
	iAutoUpdatedInitiator = aAutoUpdate;
220
cc381e129dd5 Fix for bug 3709
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 187
diff changeset
   176
	if ((iFeedsUpdating.Count() > 0) || (isOfflineProfile && aAutoUpdate)) 
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   178
		DP("Cancelling update");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
		iFeedClient->Stop();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
		iFeedsUpdating.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
		return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
	TInt cnt = iSortedFeeds.Count();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   185
	for (int i=0;i<cnt;i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   186
		{
102
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   187
		iFeedsUpdating.Append(iSortedFeeds[i]->Uid());
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   188
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   189
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   190
	UpdateNextFeedL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
EXPORT_C void CFeedEngine::CancelUpdateAllFeeds()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   195
	if(iClientState != EIdle)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
		{
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   197
		iCancelRequested = ETrue;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   198
		iFeedsUpdating.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   199
		iFeedClient->Stop();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   200
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   202
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   203
void CFeedEngine::UpdateNextFeedL()
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
	DP1("UpdateNextFeed. %d feeds left to update", iFeedsUpdating.Count());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
	
126
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   207
	if (iClientState != EIdle)
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   208
		{
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   209
		User::Leave(KErrInUse);
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   210
		}
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   211
	
102
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   212
	// reset active feed, will be set again in UpdateFeedL if needed
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   213
	iActiveFeed = NULL;
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   214
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
	if (iFeedsUpdating.Count() > 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
		{
102
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   217
		CFeedInfo *info = GetFeedInfoByUid(iFeedsUpdating[0]);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   218
		iFeedsUpdating.Remove(0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
		
102
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   220
		if (info == NULL)
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   221
			{
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   222
			UpdateNextFeedL();
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   223
			}
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   224
		else
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   225
			{
102
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   226
			TBool result = EFalse;
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   227
			//DP2("** UpdateNextFeed: %S, ID: %u", &(info->Url()), info->Uid());
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   228
			TRAPD(error, result = UpdateFeedL(info->Uid()));
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   229
			
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   230
			if (error != KErrNone || !result)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
				{
102
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   232
				DP("Error while updating all feeds");
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   233
				for (TInt i=0;i<iObservers.Count();i++) 
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   234
					{
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   235
					TRAP_IGNORE(iObservers[i]->FeedUpdateAllCompleteL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate));
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   236
					}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
		iClientState = EIdle;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
		for (TInt i=0;i<iObservers.Count();i++) 
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
			TRAP_IGNORE(iObservers[i]->FeedUpdateAllCompleteL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
EXPORT_C TBool CFeedEngine::UpdateFeedL(TUint aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
	DP("FeedEngine::UpdateFeedL BEGIN");
102
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   253
	
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   254
	if (iActiveFeed)
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   255
		{
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   256
		User::Leave(KErrInUse);
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   257
		}
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   258
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
	iActiveFeed = GetFeedInfoByUid(aFeedUid);
106
83752b9e3cb6 Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents: 102
diff changeset
   260
	
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   261
	iCancelRequested = EFalse;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   263
	if (iActiveFeed->LastUpdated() == 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   264
		{
126
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   265
		newFeed = ETrue;	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
		}
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   267
	
126
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   268
	showsAdded = 0;
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   269
	
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   270
	iActiveFeed->SetLastError(KErrNone);
36
e010fc411ddc Merge, plus minor fix to CFeedEngine
Brendan Donegan <brendand@symbian.org>
parents: 35 32
diff changeset
   271
	DBUpdateFeedL(*iActiveFeed);
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   272
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
	iUpdatingFeedFileName.Copy (iPodcastModel.SettingsEngine().PrivatePath ());
108
554d9980157f Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents: 107
diff changeset
   274
	iUpdatingFeedFileName.Append(KFeedParseStorePath);
554d9980157f Moved temporary feed parser files to subdirectory under private dir, and added cleanup of this directory on startup.
teknolog
parents: 107
diff changeset
   275
	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: 107
diff changeset
   276
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
	_LIT(KFileNameFormat, "%lu.xml");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
	iUpdatingFeedFileName.AppendFormat(KFileNameFormat, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
	
117
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   280
	iClientState = EUpdatingFeed;
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   281
			
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   282
	for (TInt i=0;i<iObservers.Count();i++)
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   283
		{
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   284
		TRAP_IGNORE(iObservers[i]->FeedDownloadStartedL(iAutoUpdatedInitiator?MFeedEngineObserver::EFeedAutoUpdate:MFeedEngineObserver::EFeedManualUpdate, iActiveFeed->Uid()));
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   285
		}
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   286
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
	if(iFeedClient->GetL(iActiveFeed->Url(), iUpdatingFeedFileName, iPodcastModel.SettingsEngine().SpecificIAP()))
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
		DP("FeedEngine::UpdateFeedL END, return ETrue");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
		return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
		DP("FeedEngine::UpdateFeedL END, return EFalse");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
		return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   298
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   299
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   300
void CFeedEngine::NewShowL(CShowInfo& aItem)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
	{
255
a13c58ace598 Merged fix for bug 3797
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 220
diff changeset
   302
	DP1("NewShowL, aItem.Title()=%S", &aItem.Title());
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
	HBufC* description = HBufC::NewLC(KMaxDescriptionLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
	TPtr ptr(description->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
	ptr.Copy(aItem.Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   306
	PodcastUtils::CleanHtmlL(ptr);
8
aab3aa4acdd6 Checked all TRAP_IGNORE
teknolog
parents: 7
diff changeset
   307
aab3aa4acdd6 Checked all TRAP_IGNORE
teknolog
parents: 7
diff changeset
   308
	aItem.SetDescriptionL(*description);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   309
	CleanupStack::PopAndDestroy(description);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   310
126
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   311
	if (newFeed) {
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   312
		// for new feeds, set all shows played
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   313
		aItem.SetPlayState(EPlayed);
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   314
		// except the first one
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   315
		if (showsAdded == 0) {
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   316
			aItem.SetPlayState(ENeverPlayed);	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   317
		}
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
	
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 110
diff changeset
   320
	TRAPD(err, iPodcastModel.ShowEngine().AddShowL(aItem));
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   321
111
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 110
diff changeset
   322
	if (err == KErrNone && aItem.PlayState() == ENeverPlayed && 
12c59f14a031 DB robustness improved also for ShowEngine
teknolog
parents: 110
diff changeset
   323
			iPodcastModel.SettingsEngine().DownloadAutomatically()) 
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   324
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   325
		iPodcastModel.ShowEngine().AddDownloadL(aItem);
126
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   326
		}
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   327
	
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   328
	showsAdded++;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   329
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   330
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   331
void CFeedEngine::GetFeedImageL(CFeedInfo *aFeedInfo)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   332
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   333
	DP("GetFeedImage");
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
	TFileName filePath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   336
	filePath.Copy(iPodcastModel.SettingsEngine().BaseDir());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   337
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   338
	// create relative file name
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   339
	TFileName relPath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   340
	relPath.Copy(aFeedInfo->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   341
	relPath.Append('\\');
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
	TFileName fileName;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   344
	PodcastUtils::FileNameFromUrl(aFeedInfo->ImageUrl(), fileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   345
	relPath.Append(fileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   346
	PodcastUtils::EnsureProperPathName(relPath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   347
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   348
	// complete file path is base dir + rel path
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   349
	filePath.Append(relPath);
100
e0fc52a5df4d Update to keep features from merge.
Lars Persson <lars.persson@embeddev.se>
parents: 99
diff changeset
   350
	aFeedInfo->SetImageFileNameL(filePath, NULL);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   351
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   352
	if(iFeedClient->GetL(aFeedInfo->ImageUrl(), filePath, ETrue))
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
			iClientState = EUpdatingImage;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   355
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   356
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   357
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   358
EXPORT_C TBool CFeedEngine::AddFeedL(const CFeedInfo&aItem) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   359
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   360
	DP2("CFeedEngine::AddFeed, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   361
	for (TInt i=0;i<iSortedFeeds.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   362
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   363
		if (iSortedFeeds[i]->Uid() == aItem.Uid()) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   364
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   365
			DP1("Already have feed %S, discarding", &aItem.Url());			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   366
			return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   367
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   368
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   369
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   370
	TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   371
	CFeedInfo* newItem = aItem.CopyL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   372
	CleanupStack::PushL(newItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   373
	User::LeaveIfError(iSortedFeeds.InsertInOrder(newItem, sortOrder));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   374
	CleanupStack::Pop(newItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   375
	
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
	// Save the feeds into DB
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   378
	DBAddFeedL(aItem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   379
	return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   380
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   381
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   382
void CFeedEngine::DBAddFeedL(const CFeedInfo& aItem)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   383
	{
152
3402b2e2a66a A bit more debugging output in FeedEngine
teknolog
parents: 141
diff changeset
   384
	DP2("CFeedEngine::DBAddFeed BEGIN, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   385
	
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   386
	CFeedInfo *info;
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   387
	
116
a2e43aa1ad11 Fixed DEF files. Tested with Qt SQLite.
teknolog
parents: 114
diff changeset
   388
	TRAPD(err, info = DBGetFeedInfoByUidL(aItem.Uid()));
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   389
	
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   390
	if (err == KErrNone && info) {
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   391
		delete info;
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   392
		User::Leave(KErrAlreadyExists);
2
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   395
	HBufC* titleBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   396
	TPtr titlePtr(titleBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   397
	titlePtr.Copy(aItem.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   398
	PodcastUtils::SQLEncode(titlePtr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   399
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   400
	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   401
	TPtr descPtr(descBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   402
	descPtr.Copy(aItem.Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   403
	PodcastUtils::SQLEncode(descPtr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   404
	
141
ee650bbb958e Fix for bug 2836 - split string literals causing RVCT compile to fail
teknolog
parents: 126
diff changeset
   405
	_LIT(KSqlStatement, "insert into feeds (url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror) values (\"%S\",\"%S\", \"%S\", \"%S\", \"%S\", \"%S\", \"%Ld\", \"%Ld\", \"%u\", \"%u\", \"%u\", \"%d\")");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   406
	iSqlBuffer.Format(KSqlStatement,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   407
			&aItem.Url(), titleBuf, descBuf, &aItem.ImageUrl(), &aItem.ImageFileName(), &aItem.Link(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   408
			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
   409
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   410
	CleanupStack::PopAndDestroy(descBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   411
	CleanupStack::PopAndDestroy(titleBuf);
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
	sqlite3_stmt *st;
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
	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
   416
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   417
	if (rc==SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   418
		{
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   419
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   420
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   421
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   422
		if (rc != SQLITE_DONE)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   423
			{
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   424
			User::Leave(KErrCorrupt);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   425
			}
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   426
		CleanupStack::PopAndDestroy(); // st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   427
		}
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   428
	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   429
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   430
		User::Leave(KErrCorrupt);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   431
		}
152
3402b2e2a66a A bit more debugging output in FeedEngine
teknolog
parents: 141
diff changeset
   432
	DP("CFeedEngine::DBAddFeed END");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   433
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   434
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   435
EXPORT_C void CFeedEngine::RemoveFeedL(TUint aUid) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   436
	{
102
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   437
	if (iActiveFeed && iActiveFeed->Uid() == aUid)
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   438
		{
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   439
		User::Leave(KErrInUse);
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   440
		}
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   441
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   442
	for (int i=0;i<iSortedFeeds.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   443
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   444
		if (iSortedFeeds[i]->Uid() == aUid) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   445
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   446
			iPodcastModel.ShowEngine().DeleteAllShowsByFeedL(aUid);
53
b778853e60a7 Fix for bug 2217
teknolog
parents: 36
diff changeset
   447
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   448
			CFeedInfo* feedToRemove = iSortedFeeds[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   449
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   450
			//delete the image file if it exists
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   451
			if ((feedToRemove->ImageFileName().Length() >0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   452
					&& BaflUtils::FileExists(iPodcastModel.FsSession(), feedToRemove->ImageFileName()))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   453
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   454
				iPodcastModel.FsSession().Delete(feedToRemove->ImageFileName());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   455
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   456
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   457
			//delete the folder. It has the same name as the title.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   458
			TFileName filePath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   459
			filePath.Copy(iPodcastModel.SettingsEngine().BaseDir());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   460
			filePath.Append(feedToRemove->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   461
			filePath.Append('\\');
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   462
			iPodcastModel.FsSession().RmDir(filePath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   463
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   464
			iSortedFeeds.Remove(i);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   465
			delete feedToRemove;
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
			DP("Removed feed from array");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   468
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   469
			// now remove it from DB
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   470
			DBRemoveFeedL(aUid);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   471
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   472
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   473
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   474
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   475
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   476
void CFeedEngine::DBRemoveFeedL(TUint aUid)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   477
	{
152
3402b2e2a66a A bit more debugging output in FeedEngine
teknolog
parents: 141
diff changeset
   478
	DP("CFeedEngine::DBRemoveFeed BEGIN");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   479
	_LIT(KSqlStatement, "delete from feeds where uid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   480
	iSqlBuffer.Format(KSqlStatement, aUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   481
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   482
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   483
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   484
	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
   485
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   486
	if (rc==SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   487
		{
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   488
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   489
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   490
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   491
		if (rc != SQLITE_DONE)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   492
			{
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   493
			User::Leave(KErrNotFound);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   494
			}
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   495
		
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   496
		CleanupStack::PopAndDestroy(); //st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   497
		}
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   498
	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   499
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   500
		User::Leave(KErrCorrupt);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   501
		}
152
3402b2e2a66a A bit more debugging output in FeedEngine
teknolog
parents: 141
diff changeset
   502
	DP("CFeedEngine::DBRemoveFeed END");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   503
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   504
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   505
void CFeedEngine::DBUpdateFeedL(const CFeedInfo &aItem)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   506
	{
152
3402b2e2a66a A bit more debugging output in FeedEngine
teknolog
parents: 141
diff changeset
   507
	DP2("CFeedEngine::DBUpdateFeed BEGIN, title=%S, URL=%S", &aItem.Title(), &aItem.Url());
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   508
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   509
	HBufC* titleBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   510
	TPtr titlePtr(titleBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   511
	titlePtr.Copy(aItem.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   512
	PodcastUtils::SQLEncode(titlePtr);
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
	HBufC* descBuf = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   515
	TPtr descPtr(descBuf->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   516
	descPtr.Copy(aItem.Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   517
	PodcastUtils::SQLEncode(descPtr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   518
	
141
ee650bbb958e Fix for bug 2836 - split string literals causing RVCT compile to fail
teknolog
parents: 126
diff changeset
   519
	_LIT(KSqlStatement, "update feeds set url=\"%S\", title=\"%S\", description=\"%S\", imageurl=\"%S\", imagefile=\"%S\", link=\"%S\", built=\"%Lu\", lastupdated=\"%Lu\", feedtype=\"%u\", customtitle=\"%u\", lasterror=\"%d\" where uid=\"%u\"");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   520
	iSqlBuffer.Format(KSqlStatement,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   521
			&aItem.Url(), titleBuf, descBuf, &aItem.ImageUrl(), &aItem.ImageFileName(), &aItem.Link(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   522
			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
   523
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   524
	CleanupStack::PopAndDestroy(descBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   525
	CleanupStack::PopAndDestroy(titleBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   526
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   527
	sqlite3_stmt *st;
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
	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
   530
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   531
	if (rc==SQLITE_OK)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   532
		{
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   533
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   534
		rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   535
		
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   536
		if (rc != SQLITE_DONE)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   537
			{
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   538
			User::Leave(KErrNotFound);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   539
			}
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   540
		CleanupStack::PopAndDestroy(); //st
2
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
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   543
		{
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   544
		User::Leave(KErrCorrupt);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   545
		}
152
3402b2e2a66a A bit more debugging output in FeedEngine
teknolog
parents: 141
diff changeset
   546
	DP("CFeedEngine::DBUpdateFeed END");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   547
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   548
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   549
void CFeedEngine::ParsingCompleteL(CFeedInfo *item)
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
	TBuf<KMaxLineLength> title;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   552
	title.Copy(item->Title());
8
aab3aa4acdd6 Checked all TRAP_IGNORE
teknolog
parents: 7
diff changeset
   553
	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
   554
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   555
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   556
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   557
EXPORT_C void CFeedEngine::AddObserver(MFeedEngineObserver *observer)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   558
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   559
	iObservers.Append(observer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   560
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   561
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   562
EXPORT_C void CFeedEngine::RemoveObserver(MFeedEngineObserver *observer)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   563
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   564
	TInt index = iObservers.Find(observer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   565
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   566
	if (index > KErrNotFound)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   567
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   568
		iObservers.Remove(index);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   569
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   570
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   571
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   572
void CFeedEngine::Connected(CHttpClient* /*aClient*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   573
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   574
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   575
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   576
void CFeedEngine::Progress(CHttpClient* /*aHttpClient*/, TInt /*aBytes*/, TInt /*aTotalBytes*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   577
	{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   578
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   579
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   580
void CFeedEngine::CompleteL(CHttpClient* /*aClient*/, TInt aError)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   581
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   582
	DP2("CFeedEngine::CompleteL BEGIN, iClientState=%d, aSuccessful=%d", iClientState, aError);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   583
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   584
	switch(iClientState)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   585
		{		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   586
		case EUpdatingFeed: 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   587
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   588
		iClientState = EIdle;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   589
		switch (aError)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   590
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   591
			case KErrCancel:						
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   592
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   593
				iFeedsUpdating.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   594
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   595
				break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   596
			case KErrCouldNotConnect:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   597
				iFeedsUpdating.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   598
				break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   599
			default:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   600
				{
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   601
				if (!iCancelRequested) {
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   602
					iActiveFeed->SetLastError(aError);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   603
					TTime time;
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   604
					time.HomeTime();
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   605
					iActiveFeed->SetLastUpdated(time);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   606
	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   607
					if( aError == KErrNone)
106
83752b9e3cb6 Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents: 102
diff changeset
   608
						{
83752b9e3cb6 Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents: 102
diff changeset
   609
						// 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: 102
diff changeset
   610
						// 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: 102
diff changeset
   611
						// 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
   612
						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
   613
	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   614
						if(parserErr)
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   615
							{
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   616
							// 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
   617
							iActiveFeed->SetLastError(parserErr);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   618
							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
   619
							}
126
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 117
diff changeset
   620
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   621
						// 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
   622
						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
   623
	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   624
						// 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
   625
						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
   626
							{
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   627
							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
   628
									(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
   629
											!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
   630
													iActiveFeed->ImageFileName()) )
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   631
							)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   632
								{
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   633
								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
   634
								if (error)
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   635
									{
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   636
									// 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
   637
									// 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
   638
									iActiveFeed->SetLastError(parserErr);
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   639
									iClientState = EIdle;							
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   640
									}
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   641
								}	
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   642
							}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   643
						}
117
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   644
					else
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   645
						{
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   646
						// even if it fails, this will allow us to move on
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   647
						iClientState = EIdle;
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   648
						}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   649
					}
32
26a3f2dfba08 Fix for bug where we always load the feed icon a large number of times
teknolog
parents: 8
diff changeset
   650
				iCancelRequested = EFalse;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   651
				}break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   652
			}
107
af6475fdf8d6 Improved error handling; Implemented support for more than 2 flash drives also for import/export feeds
teknolog
parents: 106
diff changeset
   653
			DBUpdateFeedL(*iActiveFeed);
96
a8538f50e2ba Merge with lars' fixes
teknolog
parents: 53 93
diff changeset
   654
			NotifyFeedUpdateComplete(iActiveFeed->Uid(), aError);
a8538f50e2ba Merge with lars' fixes
teknolog
parents: 53 93
diff changeset
   655
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   656
			// 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
   657
			if (iClientState == EIdle)
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   658
				{
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   659
				UpdateNextFeedL();	
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   660
				}
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   661
			}break;
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   662
		case EUpdatingImage:
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   663
			{
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   664
			// change client state to not updating
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   665
			iClientState = EIdle;
91
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   666
			if(aError == KErrNone)
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   667
				{
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   668
				// now the image has been downloaded, so we set it again in the FeedInfo to start
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   669
				// converting it
110
403412eb5292 Added "Reset database" option in settings. Further robustness fixes for Feeds.
teknolog
parents: 109
diff changeset
   670
				HBufC *fileNameCopy = iActiveFeed->ImageFileName().AllocLC();
403412eb5292 Added "Reset database" option in settings. Further robustness fixes for Feeds.
teknolog
parents: 109
diff changeset
   671
				TRAP_IGNORE(iActiveFeed->SetImageFileNameL(*fileNameCopy, &iPodcastModel));
403412eb5292 Added "Reset database" option in settings. Further robustness fixes for Feeds.
teknolog
parents: 109
diff changeset
   672
				CleanupStack::PopAndDestroy(fileNameCopy);
91
87cb33beeae2 Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents: 32
diff changeset
   673
				}
106
83752b9e3cb6 Fix for regression in icon handling. Minor fix for trailing backslash in podcast dir in settings pane. New udeb SISs.
teknolog
parents: 102
diff changeset
   674
			DBUpdateFeedL(*iActiveFeed);
96
a8538f50e2ba Merge with lars' fixes
teknolog
parents: 53 93
diff changeset
   675
			NotifyFeedUpdateComplete(iActiveFeed->Uid(), aError);
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   676
			UpdateNextFeedL();
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   677
			}break;
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   678
		case ESearching: 
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   679
			{
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   680
			iClientState = EIdle;
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   681
	
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   682
			DP2("Search complete, results in %S with error %d", &iSearchResultsFileName, aError);
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   683
			if(aError == KErrNone)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   684
				{
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   685
				if (!iOpmlParser) 
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   686
					{
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   687
					iOpmlParser = new COpmlParser(*this, iPodcastModel.FsSession());
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   688
					}
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   689
	
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   690
				DP("Parsing OPML");
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   691
				iOpmlParser->ParseOpmlL(iSearchResultsFileName, ETrue);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   692
				}
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   693
			else
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   694
				{
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
   695
				NotifyOpmlParsingCompleteL(aError, 0);
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   696
				}
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   697
			
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   698
			BaflUtils::DeleteFile(iPodcastModel.FsSession(), iSearchResultsFileName);
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
   699
			}break;
117
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   700
		case EIdle:
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   701
			UpdateNextFeedL();	
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   702
			break;
102
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   703
		default:
114
27f6f5827e5d Cleaned up panic handling
teknolog
parents: 111
diff changeset
   704
			Panic(EPodcatcherPanicFeedEngineState);
102
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
   705
			break;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   706
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   707
	DP("CFeedEngine::CompleteL END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   708
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   709
93
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: 91
diff changeset
   710
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: 91
diff changeset
   711
	{
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: 91
diff changeset
   712
	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: 91
diff changeset
   713
	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: 91
diff changeset
   714
		{
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: 91
diff changeset
   715
		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: 91
diff changeset
   716
		}
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: 91
diff changeset
   717
	}
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: 91
diff changeset
   718
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   719
void CFeedEngine::Disconnected(CHttpClient* /*aClient*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   720
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   721
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   722
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   723
void CFeedEngine::DownloadInfo(CHttpClient* /*aHttpClient */, int /*aTotalBytes*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   724
	{	
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   727
EXPORT_C void CFeedEngine::ImportFeedsL(const TDesC& aFile)
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
	TFileName opmlPath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   730
	opmlPath.Copy(aFile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   731
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   732
	if (!iOpmlParser) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   733
		iOpmlParser = new COpmlParser(*this, iPodcastModel.FsSession());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   734
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   735
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   736
	iOpmlParser->ParseOpmlL(opmlPath, EFalse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   737
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   738
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   739
EXPORT_C TBool CFeedEngine::ExportFeedsL(TFileName& aFile)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   740
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   741
	RFile rfile;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   742
	TFileName privatePath;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   743
	iPodcastModel.FsSession().PrivatePath(privatePath);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   744
	TInt error = rfile.Temp(iPodcastModel.FsSession(), privatePath, aFile, EFileWrite);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   745
	if (error != KErrNone) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   746
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   747
		DP("CFeedEngine::ExportFeedsL()\tFailed to open file");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   748
		return EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   749
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   750
	CleanupClosePushL(rfile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   751
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   752
	HBufC* templ = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   753
	templ->Des().Copy(KOpmlFeed());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   754
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   755
	HBufC* line = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   756
	HBufC* xmlUrl = HBufC::NewLC(KMaxURLLength);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   757
	HBufC* htmlUrl = HBufC::NewLC(KMaxURLLength);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   758
	HBufC* desc = HBufC::NewLC(KMaxDescriptionLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   759
	HBufC* title = HBufC::NewLC(KMaxTitleLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   760
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   761
	HBufC8* utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(KOpmlHeader());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   762
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   763
	rfile.Write(*utf8line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   764
	delete utf8line;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   765
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   766
	for (int i=0; i<iSortedFeeds.Count(); i++)
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
		CFeedInfo *info = iSortedFeeds[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   769
		DP1("Exporting feed '%S'", &iSortedFeeds[i]->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   770
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   771
	// XML URL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   772
		TPtr ptrXml(xmlUrl->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   773
		if (info->Url() != KNullDesC)
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
			ptrXml.Copy(info->Url());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   776
			PodcastUtils::XMLEncode(ptrXml);
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
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   779
	// Description	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   780
		TPtr ptrDesc(desc->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   781
		ptrDesc.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   782
		if (info->Description() != KNullDesC) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   783
			ptrDesc.Copy(info->Description());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   784
			PodcastUtils::XMLEncode(ptrDesc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   785
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   786
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   787
	// Title	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   788
		TPtr ptrTitle(title->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   789
		ptrTitle.Zero();
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
		if (info->Title() != KNullDesC) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   792
			ptrTitle.Copy(info->Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   793
			PodcastUtils::XMLEncode(ptrTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   794
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   795
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   796
	// HTML URL	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   797
		TPtr ptrHtmlUrl(htmlUrl->Des());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   798
		ptrHtmlUrl.Zero();
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
		if (info->Link() != KNullDesC) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   801
			ptrHtmlUrl.Copy(info->Link());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   802
			PodcastUtils::XMLEncode(ptrHtmlUrl);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   803
		}	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   804
	// Write line to OPML file
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   805
		line->Des().Format(*templ, title, desc, xmlUrl, htmlUrl);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   806
		utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(*line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   807
		rfile.Write(*utf8line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   808
		delete utf8line;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   809
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   810
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   811
	utf8line = CnvUtfConverter::ConvertFromUnicodeToUtf8L(KOpmlFooter());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   812
	rfile.Write(*utf8line);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   813
	delete utf8line;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   814
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   815
	CleanupStack::PopAndDestroy(7);//destroy 6 bufs & close rfile
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   816
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   817
	return ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   818
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   819
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   820
EXPORT_C CFeedInfo* CFeedEngine::GetFeedInfoByUid(TUint aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   821
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   822
	TInt cnt = iSortedFeeds.Count();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   823
	for (TInt i=0;i<cnt;i++)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   824
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   825
		if (iSortedFeeds[i]->Uid() == aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   826
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   827
			return iSortedFeeds[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   828
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   829
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   830
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   831
	return NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   832
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   833
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   834
EXPORT_C const RFeedInfoArray& CFeedEngine::GetSortedFeeds()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   835
{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   836
	TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   837
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   838
	iSortedFeeds.Sort(sortOrder);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   839
	return iSortedFeeds;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   840
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   841
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   842
TInt CFeedEngine::CompareFeedsByTitle(const CFeedInfo &a, const CFeedInfo &b)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   843
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   844
		//DP2("Comparing %S to %S", &a.Title(), &b.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   845
		return a.Title().CompareF(b.Title());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   846
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   847
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   848
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
   849
	{
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   850
	//DP1("CFeedEngine::GetStatsByFeed, aFeedUid=%u", aFeedUid);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   851
	DBGetStatsByFeedL(aFeedUid, aNumShows, aNumUnplayed);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   852
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   853
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   854
void CFeedEngine::DBGetStatsByFeedL(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   855
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   856
	//DP1("CFeedEngine::DBGetStatsByFeed, feedUid=%u", aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   857
	_LIT(KSqlStatement, "select count(*) from shows where feeduid=%u");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   858
	iSqlBuffer.Format(KSqlStatement, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   859
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   860
	sqlite3_stmt *st;
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
	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
   863
	
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   864
	if( rc==SQLITE_OK)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   865
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   866
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   867
	  	rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   868
	  	
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   869
	  	if (rc == SQLITE_ROW)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   870
	  		{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   871
	  		aNumShows = sqlite3_column_int(st, 0);
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   872
	  		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   873
	  	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   874
	  		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   875
			User::Leave(KErrNotFound);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   876
	  		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   877
	  	CleanupStack::PopAndDestroy(); // st
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   878
		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   879
	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   880
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   881
		User::Leave(KErrCorrupt);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   882
		}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   883
		  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   884
	_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
   885
	iSqlBuffer.Format(KSqlStatement2, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   886
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   887
	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
   888
		
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   889
	if(rc==SQLITE_OK)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   890
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   891
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   892
	  	rc = sqlite3_step(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   893
	  	
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   894
	  	if (rc == SQLITE_ROW)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   895
	  		{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   896
	  		aNumUnplayed = sqlite3_column_int(st, 0);
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   897
	  		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   898
	  	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   899
	  		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   900
			User::Leave(KErrNotFound);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   901
	  		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   902
	  	CleanupStack::PopAndDestroy(); // st
2
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
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   905
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   906
TUint CFeedEngine::DBGetFeedCountL()
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   907
	{
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   908
	DP("DBGetFeedCount BEGIN");
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   909
	sqlite3_stmt *st;
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   910
	int rc = sqlite3_prepare_v2(&iDB,"select count(*) from feeds" , -1, &st, (const char**) NULL);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   911
	TUint size = 0;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   912
	 
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   913
	if( rc==SQLITE_OK )
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   914
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   915
		Cleanup_sqlite3_finalize_PushL(st);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   916
		rc = sqlite3_step(st);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   917
			
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   918
		if (rc == SQLITE_ROW)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   919
			{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   920
	  		size = sqlite3_column_int(st, 0);
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   921
	  		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   922
		else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   923
			{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   924
	  		User::Leave(KErrCorrupt);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   925
	  		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   926
		CleanupStack::PopAndDestroy(); // st
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   927
		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   928
	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   929
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   930
		User::Leave(KErrCorrupt);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   931
		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   932
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   933
	DP1("DBGetFeedCount END=%d", size);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   934
	return size;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   935
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   936
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   937
void CFeedEngine::DBLoadFeedsL()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   938
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   939
	DP("DBLoadFeeds BEGIN");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   940
	iSortedFeeds.Reset();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   941
	CFeedInfo *feedInfo = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   942
	
117
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   943
	_LIT(KSqlStatement, "select url, title, description, imageurl, imagefile, link, built, lastupdated, uid, feedtype, customtitle, lasterror from feeds");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   944
	iSqlBuffer.Format(KSqlStatement);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   945
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   946
	sqlite3_stmt *st;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   947
	 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   948
	TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   949
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   950
	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
   951
	
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   952
	if (rc==SQLITE_OK)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   953
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   954
		Cleanup_sqlite3_finalize_PushL(st);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   955
		rc = sqlite3_step(st);
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   956
		while(rc == SQLITE_ROW) 
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   957
			{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   958
			feedInfo = CFeedInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   959
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   960
			const void *urlz = sqlite3_column_text16(st, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   961
			TPtrC16 url((const TUint16*)urlz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   962
			feedInfo->SetUrlL(url);
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
			const void *titlez = sqlite3_column_text16(st, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   965
			TPtrC16 title((const TUint16*)titlez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   966
			feedInfo->SetTitleL(title);
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
			const void *descz = sqlite3_column_text16(st, 2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   969
			TPtrC16 desc((const TUint16*)descz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   970
			feedInfo->SetDescriptionL(desc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   971
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   972
			const void *imagez = sqlite3_column_text16(st, 3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   973
			TPtrC16 image((const TUint16*)imagez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   974
			feedInfo->SetImageUrlL(image);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   975
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   976
			const void *imagefilez = sqlite3_column_text16(st, 4);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   977
			TPtrC16 imagefile((const TUint16*)imagefilez);
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   978
			if (imagefile.Length() > 0)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   979
				{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   980
				feedInfo->SetImageFileNameL(imagefile, &iPodcastModel);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   981
				}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   982
			
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   983
			const void *linkz = sqlite3_column_text16(st, 5);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   984
			TPtrC16 link((const TUint16*)linkz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   985
			feedInfo->SetDescriptionL(link);
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_int64 built = sqlite3_column_int64(st, 6);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   988
			TTime buildtime(built);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   989
			feedInfo->SetBuildDate(buildtime);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   990
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   991
			sqlite3_int64 lastupdated = sqlite3_column_int64(st, 7);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   992
			TTime lastupdatedtime(lastupdated);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   993
			feedInfo->SetLastUpdated(lastupdatedtime);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   994
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   995
			sqlite3_int64 customtitle = sqlite3_column_int64(st, 10);
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   996
			if (customtitle)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   997
				{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   998
				feedInfo->SetCustomTitle();
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
   999
				}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1000
			
117
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
  1001
			sqlite3_int64 lasterror = sqlite3_column_int(st, 11);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1002
			feedInfo->SetLastError(lasterror);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1003
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1004
			TLinearOrder<CFeedInfo> sortOrder( CFeedEngine::CompareFeedsByTitle);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1005
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1006
			iSortedFeeds.InsertInOrder(feedInfo, sortOrder);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1007
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1008
			CleanupStack::Pop(feedInfo);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1009
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1010
			rc = sqlite3_step(st);
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1011
			}	
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1012
		CleanupStack::PopAndDestroy();//st
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1013
		}
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1014
	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1015
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1016
		User::Leave(KErrCorrupt);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1017
		}
2
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
	DP("DBLoadFeeds END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1020
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1021
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1022
CFeedInfo* CFeedEngine::DBGetFeedInfoByUidL(TUint aFeedUid)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1023
	{
152
3402b2e2a66a A bit more debugging output in FeedEngine
teknolog
parents: 141
diff changeset
  1024
	DP("CFeedEngine::DBGetFeedInfoByUid BEGIN");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1025
	CFeedInfo *feedInfo = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1026
	_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
  1027
	iSqlBuffer.Format(KSqlStatement, aFeedUid);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1028
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1029
	sqlite3_stmt *st;
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1030
	
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1031
	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
  1032
	
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1033
	if (rc==SQLITE_OK)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1034
		{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1035
		Cleanup_sqlite3_finalize_PushL(st);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1036
		rc = sqlite3_step(st);
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1037
		if (rc == SQLITE_ROW)
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1038
			{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1039
			feedInfo = CFeedInfo::NewLC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1040
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1041
			const void *urlz = sqlite3_column_text16(st, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1042
			TPtrC16 url((const TUint16*)urlz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1043
			feedInfo->SetUrlL(url);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1044
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1045
			const void *titlez = sqlite3_column_text16(st, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1046
			TPtrC16 title((const TUint16*)titlez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1047
			feedInfo->SetTitleL(title);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1048
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1049
			const void *descz = sqlite3_column_text16(st, 2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1050
			TPtrC16 desc((const TUint16*)descz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1051
			feedInfo->SetDescriptionL(desc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1052
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1053
			const void *imagez = sqlite3_column_text16(st, 3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1054
			TPtrC16 image((const TUint16*)imagez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1055
			feedInfo->SetImageUrlL(image);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1056
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1057
			const void *imagefilez = sqlite3_column_text16(st, 4);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1058
			TPtrC16 imagefile((const TUint16*)imagefilez);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1059
			feedInfo->SetDescriptionL(imagefile);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1060
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1061
			const void *linkz = sqlite3_column_text16(st, 5);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1062
			TPtrC16 link((const TUint16*)linkz);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1063
			feedInfo->SetDescriptionL(link);
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
			sqlite3_int64 built = sqlite3_column_int64(st, 6);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1066
			TTime buildtime(built);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1067
			feedInfo->SetBuildDate(buildtime);
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
			sqlite3_int64 lastupdated = sqlite3_column_int64(st, 7);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1070
			TTime lastupdatedtime(lastupdated);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1071
			feedInfo->SetLastUpdated(lastupdatedtime);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1072
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1073
			sqlite3_int64 customtitle = sqlite3_column_int64(st, 10);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1074
			if (customtitle) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1075
				feedInfo->SetCustomTitle();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1076
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1077
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1078
			TInt lasterror = sqlite3_column_int(st, 11);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1079
			feedInfo->SetLastError(lasterror);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1080
						
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1081
			CleanupStack::Pop(feedInfo);
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1082
			}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1083
		else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1084
			{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1085
			User::Leave(KErrNotFound);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1086
			}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1087
		CleanupStack::PopAndDestroy();//st	
109
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1088
		}
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1089
	else
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1090
		{
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1091
		User::Leave(KErrNotFound);
223f270fa7ff Significantly improved database robustness
teknolog
parents: 108
diff changeset
  1092
		}
152
3402b2e2a66a A bit more debugging output in FeedEngine
teknolog
parents: 141
diff changeset
  1093
	DP("CFeedEngine::DBGetFeedInfoByUid END");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1094
	return feedInfo;
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
102
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
  1097
EXPORT_C void CFeedEngine::UpdateFeedInfoL(CFeedInfo *aItem)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1098
	{
102
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
  1099
	if (iActiveFeed && iActiveFeed->Uid() == aItem->Uid())
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
  1100
		{
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
  1101
		User::Leave(KErrInUse);
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
  1102
		}
04c6ccce8e7e Fix for bug 2408. Improved feed engine robustness.
teknolog
parents: 100
diff changeset
  1103
	
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
  1104
	DBUpdateFeedL(*aItem);
2
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1107
EXPORT_C void CFeedEngine::SearchForFeedL(TDesC& aSearchString)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1108
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1109
	DP1("FeedEngine::SearchForFeedL BEGIN, aSearchString=%S", &aSearchString);
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
	if (iClientState != EIdle) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1112
		User::Leave(KErrInUse);
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
	TBuf<KMaxURLLength> ssBuf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1115
	ssBuf.Copy(aSearchString);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1116
	PodcastUtils::ReplaceString(ssBuf, _L(" "), _L("%20"));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1117
	// prepare search URL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1118
	HBufC* templ = HBufC::NewLC(KMaxLineLength);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1119
	templ->Des().Copy(KSearchUrl());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1120
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1121
	HBufC* url = HBufC::NewLC(KMaxURLLength);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1122
	url->Des().Format(*templ, &ssBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1123
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1124
	DP1("SearchURL: %S", url);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1125
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1126
	// crate path to store OPML search results
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1127
	iPodcastModel.FsSession().PrivatePath(iSearchResultsFileName);
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
	iSearchResultsFileName.Append(KSearchResultsFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1130
	iSearchResults.ResetAndDestroy();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1131
	// run search
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1132
	if(iFeedClient->GetL(*url, iSearchResultsFileName, iPodcastModel.SettingsEngine().SpecificIAP()))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1133
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1134
		iClientState = ESearching;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1135
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1136
	else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1137
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1138
		iClientState = EIdle;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1139
		User::Leave(KErrAbort);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1140
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1141
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1142
	CleanupStack::PopAndDestroy(url);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1143
	CleanupStack::PopAndDestroy(templ);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1144
		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1145
	DP("FeedEngine::SearchForFeedL END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1146
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1147
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1148
EXPORT_C void CFeedEngine::AddSearchResultL(CFeedInfo *item)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1149
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1150
	DP1("CFeedEngine::AddSearchResultL, item->Title()=%S", &(item->Title()));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1151
	iSearchResults.AppendL(item);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1152
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1153
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1154
EXPORT_C const RFeedInfoArray& CFeedEngine::GetSearchResults()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1155
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1156
	return iSearchResults;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1157
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1158
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1159
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
  1160
EXPORT_C void CFeedEngine::OpmlParsingCompleteL(TInt aError, TUint aNumFeedsAdded)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1161
	{
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
  1162
	NotifyOpmlParsingCompleteL(aError, aNumFeedsAdded);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1163
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1164
35
66c5303f3610 A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents: 8
diff changeset
  1165
void CFeedEngine::NotifyOpmlParsingCompleteL(TInt aError, TUint aNumFeedsAdded)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1166
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1167
	for (TInt i=0;i<iObservers.Count();i++) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1168
		{
7
a7a43293ae56 Added error handling for searching
teknolog
parents: 2
diff changeset
  1169
		iObservers[i]->OpmlParsingComplete(aError, aNumFeedsAdded);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1170
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1171
	}