| 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 | #ifndef SHOWENGINE_H_
 | 
|  |     20 | #define SHOWENGINE_H_
 | 
|  |     21 | 
 | 
|  |     22 | #include <e32base.h>
 | 
|  |     23 | #include <APGCLI.H>
 | 
|  |     24 | #include "constants.h"
 | 
|  |     25 | #include "ShowInfo.h"
 | 
|  |     26 | #include "PodcastModel.h"
 | 
|  |     27 | #include "HttpClient.h"
 | 
|  |     28 | #include "ShowEngineObserver.h"
 | 
|  |     29 | #include "MetaDataReader.h"
 | 
| 60 |     30 | #include <sqlite3.h>
 | 
| 2 |     31 | 
 | 
|  |     32 | class CShowEngine : public CBase, public MHttpClientObserver, public MMetaDataReaderObserver
 | 
|  |     33 | {
 | 
|  |     34 | public:
 | 
|  |     35 | 	IMPORT_C static CShowEngine* NewL(CPodcastModel& aPodcastModel);
 | 
|  |     36 | 	IMPORT_C virtual ~CShowEngine();
 | 
|  |     37 | 	
 | 
|  |     38 | public:
 | 
|  |     39 | 	IMPORT_C void AddDownloadL(CShowInfo& info);
 | 
| 60 |     40 | 	IMPORT_C void RemoveDownloadL(TUint aUid);
 | 
|  |     41 | 	IMPORT_C void RemoveAllDownloadsL();
 | 
| 2 |     42 | 
 | 
|  |     43 | 	IMPORT_C void SuspendDownloads();
 | 
|  |     44 | 	IMPORT_C void ResumeDownloadsL();
 | 
|  |     45 | 
 | 
|  |     46 | 	IMPORT_C TInt GetNumDownloadingShows();
 | 
|  |     47 | 	IMPORT_C CShowInfo* ShowDownloading();
 | 
|  |     48 | 	IMPORT_C CShowInfo* GetShowByUidL(TUint aShowUid);
 | 
|  |     49 | 	IMPORT_C CShowInfo* GetNextShowByTrackL(CShowInfo* aShowInfo);
 | 
|  |     50 | 	
 | 
|  |     51 | 	// show access methods
 | 
|  |     52 | 	IMPORT_C void GetAllShowsL(RShowInfoArray &aArray);
 | 
|  |     53 | 	IMPORT_C void GetShowsByFeedL(RShowInfoArray &aArray, TUint aFeedUid);
 | 
|  |     54 | 	IMPORT_C void GetShowsDownloadedL(RShowInfoArray &aArray);
 | 
|  |     55 | 	IMPORT_C void GetNewShowsL(RShowInfoArray &aArray);
 | 
|  |     56 | 	IMPORT_C void GetShowsDownloadingL(RShowInfoArray &aArray);
 | 
|  |     57 | 	IMPORT_C CShowInfo* DBGetShowByFileNameL(TFileName aFileName);
 | 
|  |     58 | 	
 | 
| 60 |     59 | 	IMPORT_C void AddShowL(const CShowInfo& item);
 | 
|  |     60 | 	IMPORT_C void DeletePlayedShowsL(RShowInfoArray &aShowInfoArray);
 | 
| 2 |     61 | 	IMPORT_C void DeleteAllShowsByFeedL(TUint aFeedUid,TBool aDeleteFiles=ETrue);
 | 
|  |     62 | 	IMPORT_C void DeleteShowL(TUint aShowUid, TBool aRemoveFile=ETrue);
 | 
| 60 |     63 | 	IMPORT_C void DeleteOldShowsByFeedL(TUint aFeedUid);
 | 
| 2 |     64 | 	
 | 
|  |     65 | 	IMPORT_C void AddObserver(MShowEngineObserver *observer);
 | 
|  |     66 | 	IMPORT_C void RemoveObserver(MShowEngineObserver *observer);
 | 
|  |     67 | 
 | 
|  |     68 | 	IMPORT_C void NotifyShowListUpdatedL();
 | 
| 60 |     69 | 	IMPORT_C void UpdateShowL(CShowInfo& aInfo);
 | 
| 2 |     70 | 
 | 
|  |     71 | 	IMPORT_C void GetMimeType(const TDesC& aFileName, TDes& aMimeType);
 | 
|  |     72 | 
 | 
| 60 |     73 | 	IMPORT_C void CheckForDeletedShows(TUint aFeedUid);
 | 
| 2 |     74 | 	IMPORT_C CMetaDataReader& MetaDataReader();
 | 
|  |     75 | 
 | 
|  |     76 | private:
 | 
|  |     77 | 	// from HttpClientObserver, dont have to be public
 | 
|  |     78 | 	void Connected(CHttpClient* aClient);
 | 
|  |     79 | 	void Disconnected(CHttpClient* aClient);
 | 
|  |     80 | 	void CompleteL(CHttpClient* aClient, TInt aError);
 | 
|  |     81 | 	void Progress(CHttpClient* aHttpClient, int aBytes, int aTotalBytes);
 | 
|  |     82 | 	void DownloadInfo(CHttpClient* aClient, int aSize);
 | 
|  |     83 | 	void FileError(TUint aError);
 | 
|  |     84 | 	// from MetaDataReaderObserver
 | 
| 60 |     85 | 	void ReadMetaDataL(CShowInfo& aShowInfo);
 | 
| 2 |     86 | 	void ReadMetaDataCompleteL();
 | 
|  |     87 | 	
 | 
|  |     88 | private:
 | 
|  |     89 | 	CShowEngine(CPodcastModel& aPodcastModel);
 | 
|  |     90 | 	void ConstructL();
 | 
|  |     91 | 
 | 
| 60 |     92 | 	void GetShowL(CShowInfo *info);
 | 
| 2 |     93 | 
 | 
|  |     94 | 	void NotifyDownloadQueueUpdatedL();
 | 
|  |     95 | 	void NotifyShowDownloadUpdatedL(TInt aBytesOfCurrentDownload, TInt aBytesTotal);
 | 
|  |     96 | 	void NotifyShowFinishedL(TInt aError);
 | 
|  |     97 | 	void DownloadNextShowL();
 | 
|  |     98 | 
 | 
|  |     99 | 	static TInt CompareShowsByDate(const CShowInfo &a, const CShowInfo &b);
 | 
|  |    100 | 	static TBool CompareShowsByUid(const CShowInfo &a, const CShowInfo &b);
 | 
|  |    101 | 	static TInt CompareShowsByTitle(const CShowInfo &a, const CShowInfo &b);
 | 
|  |    102 | 	static TInt CompareShowsByTrackNo(const CShowInfo &a, const CShowInfo &b);
 | 
|  |    103 | 	
 | 
|  |    104 | 	void AddShowToMpxCollection(CShowInfo &aShowInfo);
 | 
|  |    105 | 
 | 
|  |    106 | private:
 | 
|  |    107 | 	// DB methods
 | 
|  |    108 | 	CShowInfo* DBGetShowByUidL(TUint aUid);
 | 
|  |    109 | 	void DBFillShowInfoFromStmtL(sqlite3_stmt *st, CShowInfo* showInfo);
 | 
| 60 |    110 | 	void DBAddShowL(const CShowInfo& aItem);
 | 
|  |    111 | 	void DBUpdateShowL(CShowInfo& aItem);
 | 
| 2 |    112 | 	void DBGetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid);
 | 
|  |    113 | 	void DBGetAllShowsL(RShowInfoArray& aShowArray);
 | 
|  |    114 | 	void DBGetNewShowsL(RShowInfoArray& aShowArray);
 | 
|  |    115 | 	void DBGetDownloadedShowsL(RShowInfoArray& aShowArray);
 | 
| 60 |    116 | 	void DBDeleteAllShowsByFeedL(TUint aFeedUid);
 | 
|  |    117 | 	void DBDeleteOldShowsByFeedL(TUint aFeedUid);
 | 
|  |    118 | 	void DBDeleteShowL(TUint aUid);
 | 
|  |    119 | 	void DBRemoveAllDownloadsL();
 | 
|  |    120 | 	void DBRemoveDownloadL(TUint aUid);
 | 
| 2 |    121 | 	void DBGetAllDownloadsL(RShowInfoArray& aShowArray);
 | 
| 60 |    122 | 	TUint DBGetDownloadsCountL();
 | 
|  |    123 | 	void DBAddDownloadL(TUint aUid);
 | 
| 2 |    124 | 	CShowInfo* DBGetNextDownloadL();
 | 
|  |    125 | 	
 | 
|  |    126 | private:
 | 
|  |    127 | 	CHttpClient* iShowClient;			
 | 
|  |    128 | 		
 | 
|  |    129 | 	CPodcastModel& iPodcastModel;
 | 
|  |    130 | 
 | 
|  |    131 | 	// observers that will receive callbacks
 | 
|  |    132 |     RArray<MShowEngineObserver*> iObservers;
 | 
|  |    133 | 
 | 
|  |    134 | 	// The show we are currently downloading
 | 
|  |    135 | 	CShowInfo* iShowDownloading;
 | 
|  |    136 |     TUint iDownloadErrors;
 | 
|  |    137 |     
 | 
|  |    138 |     CMetaDataReader* iMetaDataReader;
 | 
|  |    139 |     
 | 
|  |    140 |     RApaLsSession iApaSession;
 | 
|  |    141 | 	TBuf8<512> iRecogBuffer;
 | 
|  |    142 | 	
 | 
|  |    143 | 	sqlite3& iDB;
 | 
|  |    144 |     TBuf<KDefaultSQLDataBufferLength> iSqlBuffer;
 | 
|  |    145 | };
 | 
|  |    146 | 
 | 
|  |    147 | #endif /*SHOWENGINE_H_*/
 | 
|  |    148 | 
 |