Mercurial > snowl
changeset 137:447ad38415f8
show subscription progress in subscribe dialog
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Sun, 22 Jun 2008 19:11:02 -0700 |
parents | 97467b19d1d1 |
children | 58b04d16257c |
files | extension/content/sidebar.css extension/content/sidebar.js extension/content/sidebar.xul extension/modules/Preferences.js extension/modules/feed.js |
diffstat | 5 files changed, 75 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/extension/content/sidebar.css Mon Jun 16 02:09:03 2008 -0700 +++ b/extension/content/sidebar.css Sun Jun 22 19:11:02 2008 -0700 @@ -11,7 +11,7 @@ list-style-image: url("chrome://snowl/content/icons/asterisk_orange.png"); } -.statusBox[status="underway"] > .statusIcon { +.statusBox[status="active"] > .statusIcon { list-style-image: url("chrome://global/skin/icons/loading_16.png"); }
--- a/extension/content/sidebar.js Mon Jun 16 02:09:03 2008 -0700 +++ b/extension/content/sidebar.js Sun Jun 22 19:11:02 2008 -0700 @@ -9,6 +9,7 @@ Cu.import("resource://snowl/modules/source.js"); Cu.import("resource://snowl/modules/feed.js"); Cu.import("resource://snowl/modules/URI.js"); +Cu.import("resource://snowl/modules/Observers.js"); var gBrowserWindow = window.QueryInterface(Ci.nsIInterfaceRequestor). getInterface(Ci.nsIWebNavigation). @@ -70,7 +71,20 @@ //**************************************************************************// // Event Handlers - onCommandImportOPMLButton: function() { + doSubscribe: function() { + let uri = URI.get(document.getElementById("snowlLocationTextbox").value); + let feed = new SnowlFeed(null, null, uri); + Observers.add(SubscriptionListener, "snowl:subscribe:connect:start"); + Observers.add(SubscriptionListener, "snowl:subscribe:connect:end"); + Observers.add(SubscriptionListener, "snowl:subscribe:authenticate:start"); + Observers.add(SubscriptionListener, "snowl:subscribe:authenticate:end"); + Observers.add(SubscriptionListener, "snowl:subscribe:get:start"); + Observers.add(SubscriptionListener, "snowl:subscribe:get:progress"); + Observers.add(SubscriptionListener, "snowl:subscribe:get:end"); + feed.subscribe(); + }, + + doImportOPML: function() { let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker); fp.init(window, "Import OPML", Ci.nsIFilePicker.modeOpen); fp.appendFilter("OPML Files", "*.opml"); @@ -95,15 +109,10 @@ this._importOutline(outline); }, - onCommandCancelButton: function() { + doCancel: function() { this._subscribePanel.hidePopup(); }, - onCommandSubscribeButton: function() { - let uri = URI.get(document.getElementById("snowlLocationTextbox").value); - new SnowlFeed(null, null, uri).subscribe(); - this._subscribePanel.hidePopup(); - }, //**************************************************************************// // OPML Import @@ -261,4 +270,37 @@ }; +function SubscriptionListener(subject, topic, data) { + dump("SubscriptionListener: topic = " + topic + "\n"); + switch(topic) { + case "snowl:subscribe:connect:start": + document.getElementById("connectingBox").setAttribute("status", "active"); + break; + case "snowl:subscribe:connect:end": + document.getElementById("connectingBox").setAttribute("status", "complete"); + break; + case "snowl:subscribe:authenticate:start": + document.getElementById("authenticatingBox").setAttribute("status", "active"); + break; + case "snowl:subscribe:authenticate:end": + document.getElementById("authenticatingBox").setAttribute("status", "complete"); + break; + case "snowl:subscribe:get:start": + document.getElementById("gettingMessagesBox").setAttribute("status", "active"); + break; + case "snowl:subscribe:get:progress": + break; + case "snowl:subscribe:get:end": + document.getElementById("gettingMessagesBox").setAttribute("status", "complete"); + Observers.remove(SubscriptionListener, "snowl:subscribe:connect:start"); + Observers.remove(SubscriptionListener, "snowl:subscribe:connect:end"); + Observers.remove(SubscriptionListener, "snowl:subscribe:authenticate:start"); + Observers.remove(SubscriptionListener, "snowl:subscribe:authenticate:end"); + Observers.remove(SubscriptionListener, "snowl:subscribe:get:start"); + Observers.remove(SubscriptionListener, "snowl:subscribe:get:progress"); + Observers.remove(SubscriptionListener, "snowl:subscribe:get:end"); + break; + } +} + window.addEventListener("load", function() { SourcesView.init() }, false);
--- a/extension/content/sidebar.xul Mon Jun 16 02:09:03 2008 -0700 +++ b/extension/content/sidebar.xul Sun Jun 22 19:11:02 2008 -0700 @@ -49,31 +49,29 @@ <hbox align="center"> <label control="snowlLocationTextbox" value="Location:"/> <textbox id="snowlLocationTextbox" flex="1"/> - <button label="Subscribe" default="true" - oncommand="SourcesView.onCommandSubscribeButton(event)"/> + <button label="Subscribe" default="true" oncommand="SourcesView.doSubscribe(event)"/> </hbox> <hbox align="center"> + <label control="importOPMLButton" value="Or import an OPML list of feeds:"/> <spacer flex="1"/> - <button label="Import OPML..." - oncommand="SourcesView.onCommandImportOPMLButton(event)"/> + <button id="importOPMLButton" label="Import..." oncommand="SourcesView.doImportOPML(event)"/> </hbox> <vbox> - <hbox id="retrievingFeedBox" class="statusBox" align="center"> - <image id="retrievingFeedIcon" class="statusIcon"/> - <label value="Retrieving feed" disabled="true"/> + <hbox id="connectingBox" class="statusBox" align="center"> + <image id="connectingIcon" class="statusIcon"/> + <label value="Connecting to feed" disabled="true"/> </hbox> - <hbox id="authenticatingBox" class="statusBox" align="center" status="underway"> + <hbox id="authenticatingBox" class="statusBox" align="center"> <image id="authenticatingIcon" class="statusIcon"/> <label value="Authenticating (if necessary)" disabled="true"/> </hbox> - <hbox id="addingStoriesBox" class="statusBox" align="center" status="complete"> - <image id="addingStoriesIcon" class="statusIcon"/> - <label value="Adding stories" disabled="true"/> + <hbox id="gettingMessagesBox" class="statusBox" align="center"> + <image id="gettingMessagesIcon" class="statusIcon"/> + <label value="Getting stories" disabled="true"/> </hbox> </vbox> <hbox> - <button label="Cancel" - oncommand="SourcesView.onCommandCancelButton(event)"/> + <button label="Cancel" oncommand="SourcesView.doCancel(event)"/> <spacer flex="1"/> </hbox> </panel>
--- a/extension/modules/Preferences.js Mon Jun 16 02:09:03 2008 -0700 +++ b/extension/modules/Preferences.js Sun Jun 22 19:11:02 2008 -0700 @@ -18,6 +18,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Daniel Aquino <mr.danielaquino@gmail.com> * Myk Melez <myk@mozilla.org> * * Alternatively, the contents of this file may be used under the terms of @@ -34,7 +35,7 @@ * * ***** END LICENSE BLOCK ***** */ -EXPORTED_SYMBOLS = ["Preferences"]; +let EXPORTED_SYMBOLS = ["Preferences"]; const Cc = Components.classes; const Ci = Components.interfaces;
--- a/extension/modules/feed.js Mon Jun 16 02:09:03 2008 -0700 +++ b/extension/modules/feed.js Sun Jun 22 19:11:02 2008 -0700 @@ -11,6 +11,7 @@ Cu.import("resource://snowl/modules/datastore.js"); Cu.import("resource://snowl/modules/URI.js"); Cu.import("resource://snowl/modules/source.js"); +Cu.import("resource://snowl/modules/Observers.js"); // FIXME: factor this out into a common file. const PART_TYPE_CONTENT = 1; @@ -89,6 +90,8 @@ }, onRefreshResult: function(aResult) { + Observers.notify(this, "snowl:subscribe:get:start", null); + // Now that we know we successfully downloaded the feed and obtained // a result from it, update the "last refreshed" timestamp. this.lastRefreshed = new Date(); @@ -141,6 +144,8 @@ if (messagesChanged) this._obsSvc.notifyObservers(null, "messages:changed", null); + + Observers.notify(this, "snowl:subscribe:get:end", null); }, /** @@ -349,9 +354,9 @@ SnowlDatastore.insertMetadatum(aMessageID, attributeID, aValue); }, - // FIXME: make this accept a callback to which it reports on its progress - // so we can provide feedback to the user in subscription interfaces. subscribe: function() { + Observers.notify(this, "snowl:subscribe:connect:start", null); + this._log.info("subscribing to " + this.name + " <" + this.machineURI.spec + ">"); let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(); @@ -373,12 +378,17 @@ }, onSubscribeLoad: function(aEvent) { + Observers.notify(this, "snowl:subscribe:connect:end", null); + let request = aEvent.target; // XXX What's the right way to handle this? if (request.responseText.length == 0) throw("feed contains no data"); + Observers.notify(this, "snowl:subscribe:authenticate:start", null); + Observers.notify(this, "snowl:subscribe:authenticate:end", null); + let parser = Cc["@mozilla.org/feed-processor;1"]. createInstance(Ci.nsIFeedProcessor); parser.listener = { t: this, handleResult: function(r) { this.t.onSubscribeResult(r) } };