engine/inc/FeedEngine.h
changeset 2 29cda98b007e
child 7 a7a43293ae56
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 FEEDENGINE_H_
       
    20 #define FEEDENGINE_H_
       
    21 
       
    22 #include "HttpClientObserver.h"
       
    23 #include "HttpClient.h"
       
    24 #include "FeedParser.h"
       
    25 #include "FeedInfo.h"
       
    26 #include "ShowInfo.h"
       
    27 #include <e32cmn.h>
       
    28 #include "Constants.h"
       
    29 #include "FeedEngineObserver.h"
       
    30 #include "FeedTimer.h"
       
    31 #include "sqlite3.h"
       
    32 
       
    33 class CPodcastModel;
       
    34 class COpmlParser;
       
    35 
       
    36 _LIT(KOpmlFeed, "    <outline title=\"%S\" description=\"%S\" xmlUrl=\"%S\" htmlUrl=\"%S\"/>");
       
    37 _LIT(KOpmlHeader, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<opml version=\"1.1\" xmlns:podcastSearch=\"http://digitalpodcast.com/podcastsearchservice/output_specs.html\">\n<head>\n  <title>Podcast Feed List</title>\n</head>\n<body>\n  <outline>");
       
    38 _LIT(KOpmlFooter, "  </outline>\n</body>\n</opml>");
       
    39 
       
    40 _LIT(KSearchUrl, "http://www.digitalpodcast.com/podcastsearchservice/v2b/search/?appid=SymbianPodcatcher&keywords=%S&format=rssopml&sort=rel&searchsource=all&contentfilter=noadult&start=0&results=20");
       
    41 _LIT(KSearchResultsFileName, "searchresults.opml");
       
    42 
       
    43 const TInt KMaxUidBufLen = 20;
       
    44 const TInt KMaxTitleLength = 512;
       
    45 const TInt KMaxDescriptionLength = 1024;
       
    46 const TInt KMaxURLLength = 512;
       
    47 const TInt KMaxLineLength = 4096;
       
    48 const TInt KMaxSearchString = 30;
       
    49 
       
    50 enum TClientState {
       
    51 	EIdle,
       
    52 	EUpdatingFeed,
       
    53 	EUpdatingImage,
       
    54 	ESearching
       
    55 };
       
    56 
       
    57 class CFeedEngine : public CBase, public MHttpClientObserver, public MFeedParserObserver
       
    58 {
       
    59 public:
       
    60 	static CFeedEngine* NewL(CPodcastModel& aPodcastModel);
       
    61 	virtual ~CFeedEngine();
       
    62 	
       
    63 public:
       
    64 	IMPORT_C TBool AddFeedL(const CFeedInfo& item);
       
    65 	IMPORT_C void ImportFeedsL(const TDesC& aFile);
       
    66 	IMPORT_C TBool ExportFeedsL(TFileName& aFile);
       
    67 	IMPORT_C void RemoveFeedL(TUint aUid);
       
    68 	IMPORT_C TBool UpdateFeedL(TUint aFeedUid);
       
    69 	IMPORT_C void UpdateAllFeedsL(TBool aAutoUpdate = EFalse);
       
    70 	IMPORT_C void CancelUpdateAllFeeds();
       
    71 	IMPORT_C const RFeedInfoArray& GetSortedFeeds();
       
    72 	IMPORT_C CFeedInfo* GetFeedInfoByUid(TUint aFeedUid);	
       
    73 	IMPORT_C void GetStatsByFeed(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed);
       
    74 	IMPORT_C void GetDownloadedStats(TUint &aNumShows, TUint &aNumUnplayed);
       
    75 
       
    76 	IMPORT_C void AddObserver(MFeedEngineObserver *observer);
       
    77 	IMPORT_C void RemoveObserver(MFeedEngineObserver *observer);
       
    78 
       
    79 	void RunFeedTimer();
       
    80 	
       
    81 	IMPORT_C void UpdateFeed(CFeedInfo *aItem);
       
    82 	/**
       
    83 	 * Returns the current internal state of the feed engine4
       
    84 	 */
       
    85 	IMPORT_C TClientState ClientState();
       
    86 
       
    87 	/**
       
    88 	 * Returns the current updating client UID if clientstate is != ENotUpdateing
       
    89 	 * @return TUint
       
    90 	 */
       
    91 	IMPORT_C TUint ActiveClientUid();
       
    92 	
       
    93 	IMPORT_C void SearchForFeedL(TDesC& aSearchString);
       
    94 	IMPORT_C void AddSearchResultL(CFeedInfo *item);
       
    95 	IMPORT_C const RFeedInfoArray& GetSearchResults();
       
    96 
       
    97 	IMPORT_C void OpmlParsingComplete(TUint aNumFeedsAdded);
       
    98 protected:
       
    99 	
       
   100 	static TInt CompareFeedsByTitle(const CFeedInfo &a, const CFeedInfo &b);
       
   101 
       
   102 private:
       
   103 	void ConstructL();
       
   104 	CFeedEngine(CPodcastModel& aPodcastModel);
       
   105 
       
   106 	// from HttpClientObserver
       
   107 	void Connected(CHttpClient* aClient);
       
   108 	void Disconnected(CHttpClient* aClient);
       
   109 	void Progress(CHttpClient* aHttpClient, TInt aBytes, TInt aTotalBytes);
       
   110 	void DownloadInfo(CHttpClient* aClient, TInt aSize);
       
   111 	void CompleteL(CHttpClient* aClient, TInt aError);
       
   112 	void FileError(TUint /*aError*/) { }
       
   113 	// from FeedParser
       
   114 	void NewShowL(CShowInfo& aItem);
       
   115 	void ParsingCompleteL(CFeedInfo *aItem);
       
   116 
       
   117 	void GetFeedImageL(CFeedInfo *aFeedInfo);
       
   118 	
       
   119 	void UpdateNextFeedL();
       
   120 	void NotifyFeedUpdateComplete(TInt aError);
       
   121 	void NotifyOpmlParsingComplete(TUint aNumFeedsAdded);
       
   122 
       
   123 	
       
   124 private:
       
   125 	void DBLoadFeedsL();
       
   126 	TBool DBRemoveFeed(TUint aUid);
       
   127 	TBool DBAddFeedL(const CFeedInfo& aTtem);
       
   128 	CFeedInfo* DBGetFeedInfoByUidL(TUint aFeedUid);	
       
   129 	TUint DBGetFeedCount();
       
   130 	TBool DBUpdateFeed(const CFeedInfo& aItem);
       
   131 	void DBGetStatsByFeed(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed);
       
   132 
       
   133 		
       
   134 private:
       
   135 	CHttpClient* iFeedClient;
       
   136 	TClientState iClientState;
       
   137 	CFeedTimer iFeedTimer;
       
   138 
       
   139 	CPodcastModel& iPodcastModel;	
       
   140 	
       
   141 	// RSS parser
       
   142 	CFeedParser* iParser;
       
   143 	
       
   144 	// the list of feeds
       
   145 	RFeedInfoArray iSortedFeeds;
       
   146 
       
   147 	CFeedInfo *iActiveFeed;
       
   148 	TFileName iUpdatingFeedFileName;
       
   149 	TFileName iSearchResultsFileName;
       
   150 	RFeedInfoArray iFeedsUpdating;
       
   151 	
       
   152 	// observers that will receive callbacks, not owning
       
   153     RArray<MFeedEngineObserver*> iObservers;
       
   154     
       
   155     TBool iCatchupMode;
       
   156     TUint iCatchupCounter;
       
   157     
       
   158     sqlite3& iDB;
       
   159     
       
   160     TBuf<KDefaultSQLDataBufferLength> iSqlBuffer;
       
   161     
       
   162     COpmlParser* iOpmlParser;
       
   163 	RFeedInfoArray iSearchResults;
       
   164 	TBool iAutoUpdatedInitiator;
       
   165 };
       
   166 #endif /*FEEDENGINE_H_*/
       
   167