engine/src/PodcastModel.cpp
changeset 99 41d00e97e2f7
parent 96 a8538f50e2ba
child 109 223f270fa7ff
equal deleted inserted replaced
98:523e04129df6 99:41d00e97e2f7
    17 */
    17 */
    18 
    18 
    19 #include <commdb.h>
    19 #include <commdb.h>
    20 #include "PodcastModel.h"
    20 #include "PodcastModel.h"
    21 #include "FeedEngine.h"
    21 #include "FeedEngine.h"
    22 #include "SoundEngine.h"
       
    23 #include "SettingsEngine.h"
    22 #include "SettingsEngine.h"
    24 #include "ShowEngine.h"
    23 #include "ShowEngine.h"
    25 #include "connectionengine.h"
    24 #include "connectionengine.h"
    26 
    25 
    27 #include <cmdestination.h>
    26 #include <cmdestination.h>
    43 
    42 
    44 CPodcastModel::~CPodcastModel()
    43 CPodcastModel::~CPodcastModel()
    45 {
    44 {
    46 	
    45 	
    47 	delete iFeedEngine;
    46 	delete iFeedEngine;
    48 	delete iSoundEngine;
       
    49 	delete iSettingsEngine;
    47 	delete iSettingsEngine;
    50 	delete iShowEngine;
    48 	delete iShowEngine;
    51 
    49 
    52 	delete iIapNameArray;
    50 	delete iIapNameArray;
    53 	iIapIdArray.Close();
    51 	iIapIdArray.Close();
    87 	iConnectionEngine = CConnectionEngine::NewL(*this);	
    85 	iConnectionEngine = CConnectionEngine::NewL(*this);	
    88 	
    86 	
    89 	iFeedEngine = CFeedEngine::NewL(*this);
    87 	iFeedEngine = CFeedEngine::NewL(*this);
    90 	iShowEngine = CShowEngine::NewL(*this);
    88 	iShowEngine = CShowEngine::NewL(*this);
    91 
    89 
    92 	iSoundEngine = CSoundEngine::NewL(*this);	
       
    93 	DP("CPodcastModel::ConstructL END");
    90 	DP("CPodcastModel::ConstructL END");
    94 }
    91 }
    95 
    92 
    96 
    93 
    97 
    94 
   197 EXPORT_C CShowEngine& CPodcastModel::ShowEngine()
   194 EXPORT_C CShowEngine& CPodcastModel::ShowEngine()
   198 {
   195 {
   199 	return *iShowEngine;
   196 	return *iShowEngine;
   200 }
   197 }
   201 
   198 
   202 EXPORT_C CSoundEngine& CPodcastModel::SoundEngine()
       
   203 {
       
   204 	return *iSoundEngine;
       
   205 }
       
   206 
       
   207 EXPORT_C CSettingsEngine& CPodcastModel::SettingsEngine()
   199 EXPORT_C CSettingsEngine& CPodcastModel::SettingsEngine()
   208 {
   200 {
   209 	return *iSettingsEngine;
   201 	return *iSettingsEngine;
   210 }
   202 }
   211 
   203 
   214 	return *iConnectionEngine;
   206 	return *iConnectionEngine;
   215 }
   207 }
   216 
   208 
   217 EXPORT_C void CPodcastModel::PlayPausePodcastL(CShowInfo* aPodcast, TBool aPlayOnInit) 
   209 EXPORT_C void CPodcastModel::PlayPausePodcastL(CShowInfo* aPodcast, TBool aPlayOnInit) 
   218 	{
   210 	{
   219 	
   211 	// TODO: interact with MPX
   220 	// special treatment if this podcast is already active
   212 	}
   221 	if (iPlayingPodcast->Uid() == aPodcast->Uid() && SoundEngine().State() > ESoundEngineOpening ) {
       
   222 		if (aPodcast->PlayState() == EPlaying) {
       
   223 			SoundEngine().Pause();
       
   224 			aPodcast->SetPosition(iSoundEngine->Position());
       
   225 			aPodcast->SetPlayState(EPlayed);
       
   226 			aPodcast->SetPlayState(EPlayed);
       
   227 		} else {
       
   228 			iSoundEngine->Play();
       
   229 		}
       
   230 	} else {
       
   231 		// switching file, so save position
       
   232 		iSoundEngine->Pause();
       
   233 		if (iPlayingPodcast != NULL) {
       
   234 			iPlayingPodcast->SetPosition(iSoundEngine->Position());
       
   235 		}
       
   236 		
       
   237 		iSoundEngine->Stop(EFalse);
       
   238 
       
   239 		// we play video podcasts through the external player
       
   240 		if(aPodcast != NULL && aPodcast->ShowType() != EVideoPodcast) {
       
   241 			DP1("Starting: %S", &(aPodcast->FileName()));
       
   242 			TRAPD( error, iSoundEngine->OpenFileL(aPodcast->FileName(), aPlayOnInit) );
       
   243 			if (error != KErrNone) {
       
   244 				DP1("Error: %d", error);
       
   245 			} else {
       
   246 				iSoundEngine->SetPosition(aPodcast->Position().Int64() / 1000000);
       
   247 			}
       
   248 		}
       
   249 
       
   250 		iPlayingPodcast = aPodcast;		
       
   251 	}
       
   252 }
       
   253 
   213 
   254 EXPORT_C CFeedInfo* CPodcastModel::ActiveFeedInfo()
   214 EXPORT_C CFeedInfo* CPodcastModel::ActiveFeedInfo()
   255 {
   215 {
   256 	return iActiveFeed;
   216 	return iActiveFeed;
   257 }
   217 }
   277 	}
   237 	}
   278 }
   238 }
   279 
   239 
   280 sqlite3* CPodcastModel::DB()
   240 sqlite3* CPodcastModel::DB()
   281 {
   241 {
       
   242 	DP("CPodcastModel::DB BEGIN");
   282 	if (iDB == NULL) {		
   243 	if (iDB == NULL) {		
   283 		TFileName dbFileName;
   244 		TFileName dbFileName;
   284 		dbFileName.Copy(iSettingsEngine->PrivatePath());
   245 		dbFileName.Copy(iSettingsEngine->PrivatePath());
   285 		//iFsSession.PrivatePath(dbFileName);
   246 		//iFsSession.PrivatePath(dbFileName);
   286 		dbFileName.Append(KDBFileName);
   247 		dbFileName.Append(KDBFileName);
   296 			iIsFirstStartup = ETrue;
   257 			iIsFirstStartup = ETrue;
   297 		}
   258 		}
   298 		
   259 		
   299 		TBuf8<KMaxFileName> filename8;
   260 		TBuf8<KMaxFileName> filename8;
   300 		filename8.Copy(dbFileName);
   261 		filename8.Copy(dbFileName);
   301 		int rc = rc = sqlite3_open((const char*) filename8.PtrZ(), &iDB);
   262 		DP("Before sqlite3_open");
       
   263 		int rc = sqlite3_open((const char*) filename8.PtrZ(), &iDB);
   302 		if( rc != SQLITE_OK){
   264 		if( rc != SQLITE_OK){
   303 			DP("Error loading DB");
   265 			DP("Error loading DB");
   304 			User::Panic(_L("Podcatcher"), 10);
   266 			User::Panic(_L("Podcatcher"), 10);
   305 		}
   267 		}
   306 
   268 
   307 
   269 
   308 	}
   270 	}
       
   271 	DP("CPodcastModel::DB END");
   309 	return iDB;
   272 	return iDB;
   310 }
   273 }
   311 
   274 
   312 void CPodcastModel::SetProxyUsageIfNeededL(RHTTPSession& aSession)
   275 void CPodcastModel::SetProxyUsageIfNeededL(RHTTPSession& aSession)
   313 	{
   276 	{
   408 	{
   371 	{
   409 	iActiveShowList.ResetAndDestroy();
   372 	iActiveShowList.ResetAndDestroy();
   410 	iShowEngine->GetShowsByFeedL(iActiveShowList, aFeedUid);
   373 	iShowEngine->GetShowsByFeedL(iActiveShowList, aFeedUid);
   411 	}
   374 	}
   412 
   375 
   413 EXPORT_C void CPodcastModel::MarkSelectionPlayed()
   376 EXPORT_C void CPodcastModel::MarkSelectionPlayedL()
   414 	{
   377 	{
   415 	for (int i=0;i<iActiveShowList.Count();i++) {
   378 	for (int i=0;i<iActiveShowList.Count();i++) {
   416 		if(iActiveShowList[i]->PlayState() != EPlayed) {
   379 		if(iActiveShowList[i]->PlayState() != EPlayed) {
   417 			iActiveShowList[i]->SetPlayState(EPlayed);
   380 			iActiveShowList[i]->SetPlayState(EPlayed);
   418 			iShowEngine->UpdateShow(*iActiveShowList[i]);
   381 			iShowEngine->UpdateShowL(*iActiveShowList[i]);
   419 		}
   382 		}
   420 	}
   383 	}
   421 	}
   384 	}
   422 
   385 
   423 TInt CPodcastModel::FindActiveShowByUid(TUint aUid)
   386 TInt CPodcastModel::FindActiveShowByUid(TUint aUid)