engine/inc/ShowEngine.h
changeset 2 29cda98b007e
child 35 66c5303f3610
equal deleted inserted replaced
1:5f8e5adbbed9 2:29cda98b007e
       
     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"
       
    30 #include "sqlite3.h"
       
    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);
       
    40 	IMPORT_C TBool RemoveDownloadL(TUint aUid);
       
    41 	IMPORT_C void RemoveAllDownloads();
       
    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 	
       
    59 	IMPORT_C TBool AddShowL(const CShowInfo& item);
       
    60 	IMPORT_C void DeletePlayedShows(RShowInfoArray &aShowInfoArray);
       
    61 	IMPORT_C void DeleteAllShowsByFeedL(TUint aFeedUid,TBool aDeleteFiles=ETrue);
       
    62 	IMPORT_C void DeleteShowL(TUint aShowUid, TBool aRemoveFile=ETrue);
       
    63 	IMPORT_C void DeleteOldShowsByFeed(TUint aFeedUid);
       
    64 	
       
    65 	IMPORT_C void AddObserver(MShowEngineObserver *observer);
       
    66 	IMPORT_C void RemoveObserver(MShowEngineObserver *observer);
       
    67 
       
    68 	IMPORT_C void NotifyShowListUpdatedL();
       
    69 	IMPORT_C void UpdateShow(CShowInfo& aInfo);
       
    70 
       
    71 	IMPORT_C void GetMimeType(const TDesC& aFileName, TDes& aMimeType);
       
    72 
       
    73 	IMPORT_C CMetaDataReader& MetaDataReader();
       
    74 
       
    75 private:
       
    76 	// from HttpClientObserver, dont have to be public
       
    77 	void Connected(CHttpClient* aClient);
       
    78 	void Disconnected(CHttpClient* aClient);
       
    79 	void CompleteL(CHttpClient* aClient, TInt aError);
       
    80 	void Progress(CHttpClient* aHttpClient, int aBytes, int aTotalBytes);
       
    81 	void DownloadInfo(CHttpClient* aClient, int aSize);
       
    82 	void FileError(TUint aError);
       
    83 	// from MetaDataReaderObserver
       
    84 	void ReadMetaData(CShowInfo& aShowInfo);
       
    85 	void ReadMetaDataCompleteL();
       
    86 	
       
    87 private:
       
    88 	CShowEngine(CPodcastModel& aPodcastModel);
       
    89 	void ConstructL();
       
    90 
       
    91 	TBool GetShowL(CShowInfo *info);
       
    92 
       
    93 	void NotifyDownloadQueueUpdatedL();
       
    94 	void NotifyShowDownloadUpdatedL(TInt aBytesOfCurrentDownload, TInt aBytesTotal);
       
    95 	void NotifyShowFinishedL(TInt aError);
       
    96 	void DownloadNextShowL();
       
    97 
       
    98 	static TInt CompareShowsByDate(const CShowInfo &a, const CShowInfo &b);
       
    99 	static TBool CompareShowsByUid(const CShowInfo &a, const CShowInfo &b);
       
   100 	static TInt CompareShowsByTitle(const CShowInfo &a, const CShowInfo &b);
       
   101 	static TInt CompareShowsByTrackNo(const CShowInfo &a, const CShowInfo &b);
       
   102 	
       
   103 	void AddShowToMpxCollection(CShowInfo &aShowInfo);
       
   104 
       
   105 private:
       
   106 	// DB methods
       
   107 	CShowInfo* DBGetShowByUidL(TUint aUid);
       
   108 	void DBFillShowInfoFromStmtL(sqlite3_stmt *st, CShowInfo* showInfo);
       
   109 	TBool DBAddShow(const CShowInfo& aItem);
       
   110 	TBool DBUpdateShow(CShowInfo& aItem);
       
   111 	void DBGetShowsByFeedL(RShowInfoArray& aShowArray, TUint aFeedUid);
       
   112 	void DBGetAllShowsL(RShowInfoArray& aShowArray);
       
   113 	void DBGetNewShowsL(RShowInfoArray& aShowArray);
       
   114 	void DBGetDownloadedShowsL(RShowInfoArray& aShowArray);
       
   115 	TBool DBDeleteAllShowsByFeed(TUint aFeedUid);
       
   116 	void DBDeleteOldShowsByFeed(TUint aFeedUid);
       
   117 	TBool DBDeleteShow(TUint aUid);
       
   118 	void DBRemoveAllDownloads();
       
   119 	void DBRemoveDownload(TUint aUid);
       
   120 	void DBGetAllDownloadsL(RShowInfoArray& aShowArray);
       
   121 	TUint DBGetDownloadsCount();
       
   122 	void DBAddDownload(TUint aUid);
       
   123 	CShowInfo* DBGetNextDownloadL();
       
   124 	
       
   125 private:
       
   126 	CHttpClient* iShowClient;			
       
   127 		
       
   128 	CPodcastModel& iPodcastModel;
       
   129 
       
   130 	// observers that will receive callbacks
       
   131     RArray<MShowEngineObserver*> iObservers;
       
   132 
       
   133 	// The show we are currently downloading
       
   134 	CShowInfo* iShowDownloading;
       
   135     TUint iDownloadErrors;
       
   136     
       
   137     CMetaDataReader* iMetaDataReader;
       
   138     
       
   139     RApaLsSession iApaSession;
       
   140 	TBuf8<512> iRecogBuffer;
       
   141 	
       
   142 	sqlite3& iDB;
       
   143     TBuf<KDefaultSQLDataBufferLength> iSqlBuffer;
       
   144 };
       
   145 
       
   146 #endif /*SHOWENGINE_H_*/
       
   147