42
|
1 |
///////////////////////////////////////////////////////////////////////////////
|
|
2 |
// RSS Reader from WRTKit examples, modified for Symbian.org
|
|
3 |
|
|
4 |
// RSS reader class
|
|
5 |
|
|
6 |
function RssReader(aFeedName, aFeedUrl, aFeedPresenter, aParent, aResponseParser){
|
|
7 |
this.responseParser = aResponseParser;
|
|
8 |
this.feedUpdateBroker = null;
|
|
9 |
this.feedUpdateBrokerActive = false;
|
|
10 |
this.feedName = aFeedName;
|
|
11 |
this.feedURL = aFeedUrl;
|
|
12 |
this.feedUpdateForced = false;
|
|
13 |
this.feedItemControls = [];
|
|
14 |
this.feedLastModified = 0;
|
|
15 |
this.ignoreContent = false;
|
|
16 |
this.hasData = false;
|
|
17 |
this.startFromItem = 0;
|
|
18 |
this.maxItems = 0;
|
|
19 |
this.UpdateButton = null;
|
|
20 |
this.ButtonText = null;
|
|
21 |
|
|
22 |
var caption = createCaption(aFeedName);
|
|
23 |
|
|
24 |
ListView.prototype.init.call(this, null, caption);
|
|
25 |
this.previousView = aParent;
|
|
26 |
if (aFeedPresenter != null) {
|
|
27 |
this.feedPresenter = aFeedPresenter;
|
|
28 |
this.feedPresenter.init(this);
|
|
29 |
} else {
|
|
30 |
this.feedPresenter = new HtmlFeedPresenter(this);
|
|
31 |
}
|
|
32 |
|
|
33 |
// add pre-amble items (latest posts, new thread, reply etc)
|
|
34 |
this.feedPresenter.addPreambleItems();
|
|
35 |
}
|
|
36 |
|
|
37 |
RssReader.prototype = new ListView(null, null);
|
|
38 |
|
|
39 |
// Callback function that gets called when a feed update has completed.
|
|
40 |
RssReader.prototype.feedUpdateCompleted = function(event){
|
|
41 |
// remove cancel button
|
|
42 |
this.setupSoftKeys();
|
|
43 |
if (event.status == "ok") {
|
|
44 |
// if there aren't any feed items yet, we'll hide the progress dialog
|
|
45 |
|
|
46 |
// check if the feed has updated
|
|
47 |
if (event.lastModified != this.feedLastModified) {
|
|
48 |
// remember the last modified timestamp
|
|
49 |
this.feedLastModified = event.lastModified;
|
|
50 |
|
|
51 |
// feed fetched and parsed successfully
|
|
52 |
this.setFeedItems(event.items);
|
|
53 |
|
|
54 |
// focus the first feed item control
|
|
55 |
// (but only if we are in the main view)
|
|
56 |
if (this.feedItemControls.length > 0 ) {
|
|
57 |
this.feedItemControls[0].setFocused(true);
|
|
58 |
}
|
|
59 |
this.feedPresenter.addFooterItems();
|
|
60 |
}
|
|
61 |
uiManager.hideNotification();
|
|
62 |
//code to update feeds
|
|
63 |
if (this.UpdateButton) {
|
|
64 |
this.UpdateButton.setText( this.ButtonText + " (" + this.feedItemControls.length + ")");
|
|
65 |
}
|
|
66 |
}
|
|
67 |
else if (event.status != "cancelled") {
|
|
68 |
// show error message
|
|
69 |
uiManager.showNotification(3000, "warning", "Error while updating feed!");
|
|
70 |
}
|
|
71 |
|
|
72 |
// reset the broker
|
|
73 |
this.feedUpdateBroker = null;
|
|
74 |
this.feedUpdateBrokerActive = false;
|
|
75 |
|
|
76 |
// reset commanded feed update flag
|
|
77 |
this.feedUpdateForced = false;
|
|
78 |
}
|
|
79 |
|
|
80 |
// Removes feed items.
|
|
81 |
RssReader.prototype.removeFeedItems = function (){
|
|
82 |
// remove all current feed items from the main view
|
|
83 |
for (var i = 0; i < this.feedItemControls.length; i++) {
|
|
84 |
this.removeControl(this.feedItemControls[i]);
|
|
85 |
}
|
|
86 |
|
|
87 |
// reset feed item control array
|
|
88 |
this.feedItemControls = [];
|
|
89 |
}
|
|
90 |
|
|
91 |
|
|
92 |
// Sets feed items.
|
|
93 |
RssReader.prototype.setFeedItems = function (items){
|
|
94 |
// start by removing all current feed items
|
|
95 |
this.removeFeedItems();
|
|
96 |
|
|
97 |
if (items.length == 0) {
|
|
98 |
this.feedPresenter.showNoItems();
|
|
99 |
}
|
|
100 |
else {
|
|
101 |
// create new feed items and add them to the main view
|
|
102 |
// use feed item pool to recycle controls
|
|
103 |
for (var i = 0; i < items.length; i++) {
|
|
104 |
var item = items[i];
|
|
105 |
this.feedPresenter.show(item);
|
|
106 |
}
|
|
107 |
|
|
108 |
}
|
|
109 |
this.hasData = true;
|
|
110 |
}
|
|
111 |
|
|
112 |
|
|
113 |
// Update feed
|
|
114 |
RssReader.prototype.update = function(forceFeedUpdate){
|
|
115 |
if ( this.hasData && !forceFeedUpdate ) {
|
|
116 |
return;
|
|
117 |
}
|
|
118 |
this.feedUpdateForced = forceFeedUpdate;
|
|
119 |
|
|
120 |
// check if a feed update has been scheduled, if it's time to update now,
|
|
121 |
// and if there's no update currently in progress and if we're in the main view
|
|
122 |
if ((this.feedURL != null) && (!this.feedUpdateBrokerActive) ) { //&& (uiManager.getView() == this) ) {
|
|
123 |
// fetch the feed from the specified URL
|
|
124 |
this.feedUpdateBrokerActive = true;
|
|
125 |
this.feedUpdateBroker = new FeedUpdateBroker();
|
|
126 |
this.feedUpdateBroker.startFromItem = this.startFromItem;
|
|
127 |
this.feedUpdateBroker.maxItems = this.maxItems;
|
|
128 |
|
|
129 |
if ( this.responseParser != null ) {
|
|
130 |
this.feedUpdateBroker.responseParser = this.responseParser;
|
|
131 |
}
|
|
132 |
this.feedUpdateBroker.ignoreContent = this.ignoreContent;
|
|
133 |
this.feedUpdateBroker.fetchFeed(this.feedURL, this);
|
|
134 |
// allow cancelling
|
|
135 |
if (window.widget) {
|
|
136 |
var self = this;
|
|
137 |
menu.setRightSoftkeyLabel("Cancel", function(){
|
|
138 |
self.feedUpdateBroker.cancel(); self.setupSoftKeys();
|
|
139 |
uiManager.hideNotification();
|
|
140 |
});
|
|
141 |
}
|
|
142 |
uiManager.showNotification(-1, "wait", "Loading feed...", -1);
|
|
143 |
}
|
|
144 |
}
|
|
145 |
|
|
146 |
RssReader.prototype.updatebugs = function(forceFeedUpdate){
|
|
147 |
this.update(forceFeedUpdate);
|
|
148 |
} |