author | Sebastian Brannstrom <sebastianb@symbian.org> |
Fri, 09 Jul 2010 11:34:00 +0100 | |
branch | asynchparser |
changeset 171 | cc1be3797632 |
parent 83 | daef3a71bac5 |
permissions | -rw-r--r-- |
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 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" |
|
60 | 31 |
#include <sqlite3.h> |
2 | 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 |
||
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
83
diff
changeset
|
50 |
enum TFeedEngineState { |
2 | 51 |
EIdle, |
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
83
diff
changeset
|
52 |
EDownloadingFeed, |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
83
diff
changeset
|
53 |
EParsingFeed, |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
83
diff
changeset
|
54 |
EDownloadingImage, |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
83
diff
changeset
|
55 |
ESearching, |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
83
diff
changeset
|
56 |
EParsingOpml |
2 | 57 |
}; |
58 |
||
59 |
class CFeedEngine : public CBase, public MHttpClientObserver, public MFeedParserObserver |
|
60 |
{ |
|
61 |
public: |
|
62 |
static CFeedEngine* NewL(CPodcastModel& aPodcastModel); |
|
63 |
virtual ~CFeedEngine(); |
|
64 |
||
65 |
public: |
|
66 |
IMPORT_C TBool AddFeedL(const CFeedInfo& item); |
|
67 |
IMPORT_C void ImportFeedsL(const TDesC& aFile); |
|
68 |
IMPORT_C TBool ExportFeedsL(TFileName& aFile); |
|
69 |
IMPORT_C void RemoveFeedL(TUint aUid); |
|
70 |
IMPORT_C TBool UpdateFeedL(TUint aFeedUid); |
|
71 |
IMPORT_C void UpdateAllFeedsL(TBool aAutoUpdate = EFalse); |
|
72 |
IMPORT_C void CancelUpdateAllFeeds(); |
|
73 |
IMPORT_C const RFeedInfoArray& GetSortedFeeds(); |
|
74 |
IMPORT_C CFeedInfo* GetFeedInfoByUid(TUint aFeedUid); |
|
60 | 75 |
IMPORT_C void GetStatsByFeedL(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed); |
2 | 76 |
|
77 |
IMPORT_C void AddObserver(MFeedEngineObserver *observer); |
|
78 |
IMPORT_C void RemoveObserver(MFeedEngineObserver *observer); |
|
79 |
||
80 |
void RunFeedTimer(); |
|
81 |
||
60 | 82 |
IMPORT_C void UpdateFeedInfoL(CFeedInfo *aItem); |
2 | 83 |
/** |
84 |
* Returns the current internal state of the feed engine4 |
|
85 |
*/ |
|
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
83
diff
changeset
|
86 |
IMPORT_C TFeedEngineState ClientState(); |
2 | 87 |
|
88 |
/** |
|
89 |
* Returns the current updating client UID if clientstate is != ENotUpdateing |
|
90 |
* @return TUint |
|
91 |
*/ |
|
92 |
IMPORT_C TUint ActiveClientUid(); |
|
93 |
||
94 |
IMPORT_C void SearchForFeedL(TDesC& aSearchString); |
|
95 |
IMPORT_C void AddSearchResultL(CFeedInfo *item); |
|
96 |
IMPORT_C const RFeedInfoArray& GetSearchResults(); |
|
97 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
7
diff
changeset
|
98 |
IMPORT_C void OpmlParsingCompleteL(TInt aError, TUint aNumFeedsAdded); |
60 | 99 |
void NotifyFeedUpdateComplete(TInt aFeedUid, TInt aError); |
2 | 100 |
protected: |
101 |
||
102 |
static TInt CompareFeedsByTitle(const CFeedInfo &a, const CFeedInfo &b); |
|
103 |
||
104 |
private: |
|
105 |
void ConstructL(); |
|
106 |
CFeedEngine(CPodcastModel& aPodcastModel); |
|
107 |
||
108 |
// from HttpClientObserver |
|
109 |
void Connected(CHttpClient* aClient); |
|
110 |
void Disconnected(CHttpClient* aClient); |
|
111 |
void Progress(CHttpClient* aHttpClient, TInt aBytes, TInt aTotalBytes); |
|
112 |
void DownloadInfo(CHttpClient* aClient, TInt aSize); |
|
113 |
void CompleteL(CHttpClient* aClient, TInt aError); |
|
114 |
void FileError(TUint /*aError*/) { } |
|
115 |
// from FeedParser |
|
116 |
void NewShowL(CShowInfo& aItem); |
|
117 |
void ParsingCompleteL(CFeedInfo *aItem); |
|
118 |
||
119 |
void GetFeedImageL(CFeedInfo *aFeedInfo); |
|
120 |
||
121 |
void UpdateNextFeedL(); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
7
diff
changeset
|
122 |
void NotifyOpmlParsingCompleteL(TInt aError, TUint aNumFeedsAdded); |
2 | 123 |
|
124 |
private: |
|
125 |
void DBLoadFeedsL(); |
|
60 | 126 |
void DBRemoveFeedL(TUint aUid); |
127 |
void DBAddFeedL(const CFeedInfo& aTtem); |
|
2 | 128 |
CFeedInfo* DBGetFeedInfoByUidL(TUint aFeedUid); |
60 | 129 |
TUint DBGetFeedCountL(); |
130 |
void DBUpdateFeedL(const CFeedInfo& aItem); |
|
131 |
void DBGetStatsByFeedL(TUint aFeedUid, TUint &aNumShows, TUint &aNumUnplayed); |
|
2 | 132 |
|
133 |
||
134 |
private: |
|
135 |
CHttpClient* iFeedClient; |
|
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
83
diff
changeset
|
136 |
TFeedEngineState iEngineState; |
2 | 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; |
|
60 | 150 |
RArray<TUint> iFeedsUpdating; |
2 | 151 |
|
152 |
// observers that will receive callbacks, not owning |
|
153 |
RArray<MFeedEngineObserver*> iObservers; |
|
154 |
||
83
daef3a71bac5
Attempted fix for bug 2434; added KErrInUse leaves if update called when engine is in use
teknolog
parents:
65
diff
changeset
|
155 |
// new feeds only add one show to download list when auto downloading |
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
83
diff
changeset
|
156 |
TBool iNewFeed; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
83
diff
changeset
|
157 |
TUint iShowsAdded; |
2 | 158 |
|
159 |
sqlite3& iDB; |
|
160 |
||
161 |
TBuf<KDefaultSQLDataBufferLength> iSqlBuffer; |
|
162 |
||
163 |
COpmlParser* iOpmlParser; |
|
164 |
RFeedInfoArray iSearchResults; |
|
165 |
TBool iAutoUpdatedInitiator; |
|
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
7
diff
changeset
|
166 |
TBool iCancelRequested; |
2 | 167 |
}; |
168 |
#endif /*FEEDENGINE_H_*/ |
|
169 |