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