22 #include <bautils.h> |
22 #include <bautils.h> |
23 #include <s32file.h> |
23 #include <s32file.h> |
24 #include "SettingsEngine.h" |
24 #include "SettingsEngine.h" |
25 #include <e32hashtab.h> |
25 #include <e32hashtab.h> |
26 #include <httperr.h> |
26 #include <httperr.h> |
27 #include "SoundEngine.h" |
|
28 #include "debug.h" |
27 #include "debug.h" |
29 #include "PodcastUtils.h" |
28 #include "PodcastUtils.h" |
30 |
29 |
31 //#include <mpxmedia.h> |
30 //#include <mpxmedia.h> |
32 //#include <mpxattribute.h> |
31 //#include <mpxattribute.h> |
297 { |
296 { |
298 iShowDownloading->SetShowType(EVideoPodcast); |
297 iShowDownloading->SetShowType(EVideoPodcast); |
299 } |
298 } |
300 |
299 |
301 iShowDownloading->SetDownloadState(EDownloaded); |
300 iShowDownloading->SetDownloadState(EDownloaded); |
302 DBUpdateShow(*iShowDownloading); |
301 DBUpdateShowL(*iShowDownloading); |
303 DBRemoveDownload(iShowDownloading->Uid()); |
302 DBRemoveDownload(iShowDownloading->Uid()); |
304 AddShowToMpxCollection(*iShowDownloading); |
303 AddShowToMpxCollection(*iShowDownloading); |
305 NotifyShowFinishedL(aError); |
304 NotifyShowFinishedL(aError); |
306 iDownloadErrors = 0; |
305 iDownloadErrors = 0; |
307 delete iShowDownloading; |
306 delete iShowDownloading; |
311 { |
310 { |
312 // 400 and 500 series errors are serious errors on which probably another download will fail |
311 // 400 and 500 series errors are serious errors on which probably another download will fail |
313 if(aError >= HTTPStatus::EBadRequest && aError <= HTTPStatus::EBadRequest+200) |
312 if(aError >= HTTPStatus::EBadRequest && aError <= HTTPStatus::EBadRequest+200) |
314 { |
313 { |
315 iShowDownloading->SetDownloadState(EFailedDownload); |
314 iShowDownloading->SetDownloadState(EFailedDownload); |
316 DBUpdateShow(*iShowDownloading); |
315 DBUpdateShowL(*iShowDownloading); |
317 DBRemoveDownload(iShowDownloading->Uid()); |
316 DBRemoveDownload(iShowDownloading->Uid()); |
318 NotifyShowFinishedL(aError); |
317 NotifyShowFinishedL(aError); |
319 |
318 |
320 delete iShowDownloading; |
319 delete iShowDownloading; |
321 iShowDownloading = NULL; |
320 iShowDownloading = NULL; |
322 } |
321 } |
323 else // other kind of error, missing network etc, reque this show |
322 else // other kind of error, missing network etc, reque this show |
324 { |
323 { |
325 iShowDownloading->SetDownloadState(EQueued); |
324 iShowDownloading->SetDownloadState(EQueued); |
326 DBUpdateShow(*iShowDownloading); |
325 DBUpdateShowL(*iShowDownloading); |
327 } |
326 } |
328 |
327 |
329 iDownloadErrors++; |
328 iDownloadErrors++; |
330 if (iDownloadErrors > KMaxDownloadErrors) |
329 if (iDownloadErrors > KMaxDownloadErrors) |
331 { |
330 { |
732 |
731 |
733 TInt lasterror = sqlite3_column_int(st, 14); |
732 TInt lasterror = sqlite3_column_int(st, 14); |
734 showInfo->SetLastError(lasterror); |
733 showInfo->SetLastError(lasterror); |
735 } |
734 } |
736 |
735 |
737 TBool CShowEngine::DBAddShow(const CShowInfo& aItem) |
736 TBool CShowEngine::DBAddShowL(const CShowInfo& aItem) |
738 { |
737 { |
739 DP2("CShowEngine::DBAddShow, title=%S, URL=%S", &aItem.Title(), &aItem.Url()); |
738 DP2("CShowEngine::DBAddShow, title=%S, URL=%S", &aItem.Title(), &aItem.Url()); |
740 |
739 |
741 HBufC* titleBuf = HBufC::NewLC(KMaxLineLength); |
740 HBufC* titleBuf = HBufC::NewLC(KMaxLineLength); |
742 TPtr titlePtr(titleBuf->Des()); |
741 TPtr titlePtr(titleBuf->Des()); |
802 } |
801 } |
803 |
802 |
804 sqlite3_finalize(st); |
803 sqlite3_finalize(st); |
805 } |
804 } |
806 |
805 |
807 TBool CShowEngine::DBUpdateShow(CShowInfo& aItem) |
806 TBool CShowEngine::DBUpdateShowL(CShowInfo& aItem) |
808 { |
807 { |
809 DP1("CShowEngine::DBUpdateShow, title='%S'", &aItem.Title()); |
808 DP1("CShowEngine::DBUpdateShow, title='%S'", &aItem.Title()); |
810 |
809 |
811 HBufC* titleBuf = HBufC::NewLC(KMaxLineLength); |
810 HBufC* titleBuf = HBufC::NewLC(KMaxLineLength); |
812 TPtr titlePtr(titleBuf->Des()); |
811 TPtr titlePtr(titleBuf->Des()); |
1056 // DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle); |
1055 // DP2("Sorting %S greater than %S", &a.iTitle, &b.iTitle); |
1057 return 1; |
1056 return 1; |
1058 } |
1057 } |
1059 } |
1058 } |
1060 |
1059 |
1061 EXPORT_C void CShowEngine::DeletePlayedShows(RShowInfoArray &aShowInfoArray) |
1060 EXPORT_C void CShowEngine::DeletePlayedShowsL(RShowInfoArray &aShowInfoArray) |
1062 { |
1061 { |
1063 for (TInt i = 0; i < aShowInfoArray.Count(); i++) |
1062 for (TInt i = 0; i < aShowInfoArray.Count(); i++) |
1064 { |
1063 { |
1065 if (aShowInfoArray[i]->PlayState() == EPlayed |
1064 if (aShowInfoArray[i]->PlayState() == EPlayed |
1066 && aShowInfoArray[i]->FileName().Length() > 0) |
1065 && aShowInfoArray[i]->FileName().Length() > 0) |
1067 { |
1066 { |
1068 if (CompareShowsByUid(*(iPodcastModel.PlayingPodcast()), *(aShowInfoArray[i])) |
|
1069 && iPodcastModel.SoundEngine().State() != ESoundEngineNotInitialized) |
|
1070 { |
|
1071 iPodcastModel.SoundEngine().Stop(); |
|
1072 } |
|
1073 BaflUtils::DeleteFile(iPodcastModel.FsSession(), aShowInfoArray[i]->FileName()); |
1067 BaflUtils::DeleteFile(iPodcastModel.FsSession(), aShowInfoArray[i]->FileName()); |
1074 aShowInfoArray[i]->SetDownloadState(ENotDownloaded); |
1068 aShowInfoArray[i]->SetDownloadState(ENotDownloaded); |
1075 DBUpdateShow(*aShowInfoArray[i]); |
1069 DBUpdateShowL(*aShowInfoArray[i]); |
1076 } |
1070 } |
1077 } |
1071 } |
1078 } |
1072 } |
1079 |
1073 |
1080 EXPORT_C void CShowEngine::DeleteAllShowsByFeedL(TUint aFeedUid, TBool aDeleteFiles) |
1074 EXPORT_C void CShowEngine::DeleteAllShowsByFeedL(TUint aFeedUid, TBool aDeleteFiles) |
1114 { |
1108 { |
1115 BaflUtils::DeleteFile(iPodcastModel.FsSession(), info->FileName()); |
1109 BaflUtils::DeleteFile(iPodcastModel.FsSession(), info->FileName()); |
1116 } |
1110 } |
1117 |
1111 |
1118 info->SetDownloadState(ENotDownloaded); |
1112 info->SetDownloadState(ENotDownloaded); |
1119 DBUpdateShow(*info); |
1113 DBUpdateShowL(*info); |
1120 delete info; |
1114 delete info; |
1121 } |
1115 } |
1122 } |
1116 } |
1123 |
1117 |
1124 EXPORT_C void CShowEngine::GetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid) |
1118 EXPORT_C void CShowEngine::GetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid) |
1157 } |
1151 } |
1158 |
1152 |
1159 EXPORT_C void CShowEngine::AddDownloadL(CShowInfo& aInfo) |
1153 EXPORT_C void CShowEngine::AddDownloadL(CShowInfo& aInfo) |
1160 { |
1154 { |
1161 aInfo.SetDownloadState(EQueued); |
1155 aInfo.SetDownloadState(EQueued); |
1162 DBUpdateShow(aInfo); |
1156 DBUpdateShowL(aInfo); |
1163 DBAddDownload(aInfo.Uid()); |
1157 DBAddDownload(aInfo.Uid()); |
1164 DownloadNextShowL(); |
1158 DownloadNextShowL(); |
1165 } |
1159 } |
1166 |
1160 |
1167 void CShowEngine::DownloadNextShowL() |
1161 void CShowEngine::DownloadNextShowL() |
1198 { |
1192 { |
1199 TBool getOk = EFalse; |
1193 TBool getOk = EFalse; |
1200 DP1("CShowEngine::DownloadNextShow\tDownloading: %S", &(info->Title())); |
1194 DP1("CShowEngine::DownloadNextShow\tDownloading: %S", &(info->Title())); |
1201 info->SetDownloadState(EDownloading); |
1195 info->SetDownloadState(EDownloading); |
1202 info->SetLastError(KErrNone); |
1196 info->SetLastError(KErrNone); |
1203 DBUpdateShow(*info); |
1197 DBUpdateShowL(*info); |
1204 iShowDownloading = info; |
1198 iShowDownloading = info; |
1205 // Inform the observers |
1199 // Inform the observers |
1206 // important to do this after we change download state |
1200 // important to do this after we change download state |
1207 NotifyDownloadQueueUpdatedL(); |
1201 NotifyDownloadQueueUpdatedL(); |
1208 |
1202 |
1209 TRAPD(error,getOk = GetShowL(info)); |
1203 TRAPD(error,getOk = GetShowL(info)); |
1210 if (error != KErrNone || !getOk) |
1204 if (error != KErrNone || !getOk) |
1211 { |
1205 { |
1212 info->SetDownloadState(EFailedDownload); |
1206 info->SetDownloadState(EFailedDownload); |
1213 DBRemoveDownload(info->Uid()); |
1207 DBRemoveDownload(info->Uid()); |
1214 DBUpdateShow(*info); |
1208 DBUpdateShowL(*info); |
1215 info = DBGetNextDownloadL(); |
1209 info = DBGetNextDownloadL(); |
1216 |
1210 |
1217 if(info == NULL) |
1211 if(info == NULL) |
1218 { |
1212 { |
1219 iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue); |
1213 iPodcastModel.SettingsEngine().SetDownloadSuspended(ETrue); |
1269 { |
1263 { |
1270 iObservers[i]->ShowListUpdatedL(); |
1264 iObservers[i]->ShowListUpdatedL(); |
1271 } |
1265 } |
1272 } |
1266 } |
1273 |
1267 |
1274 void CShowEngine::ReadMetaData(CShowInfo& aShowInfo) |
1268 void CShowEngine::ReadMetaDataL(CShowInfo& aShowInfo) |
1275 { |
1269 { |
1276 //DP1("Read %S", &(aShowInfo->Title())); |
1270 //DP1("Read %S", &(aShowInfo->Title())); |
1277 DBUpdateShow(aShowInfo); |
1271 DBUpdateShowL(aShowInfo); |
1278 } |
1272 } |
1279 |
1273 |
1280 void CShowEngine::ReadMetaDataCompleteL() |
1274 void CShowEngine::ReadMetaDataCompleteL() |
1281 { |
1275 { |
1282 NotifyShowListUpdatedL(); |
1276 NotifyShowListUpdatedL(); |
1283 MetaDataReader().SetIgnoreTrackNo(EFalse); |
1277 MetaDataReader().SetIgnoreTrackNo(EFalse); |
1284 } |
1278 } |
1285 |
1279 |
1286 EXPORT_C void CShowEngine::UpdateShow(CShowInfo& aInfo) |
1280 EXPORT_C void CShowEngine::UpdateShowL(CShowInfo& aInfo) |
1287 { |
1281 { |
1288 DBUpdateShow(aInfo); |
1282 DBUpdateShowL(aInfo); |
1289 } |
1283 } |
1290 |
1284 |
1291 EXPORT_C CMetaDataReader& CShowEngine::MetaDataReader() |
1285 EXPORT_C CMetaDataReader& CShowEngine::MetaDataReader() |
1292 { |
1286 { |
1293 return *iMetaDataReader; |
1287 return *iMetaDataReader; |