# HG changeset patch # User Myk Melez # Date 1225829467 28800 # Node ID c00b3db58dcf6ad95e76ffcc6c262fefb84271a0 # Parent 1db123f46ed7ed1854243707e625201de9b502da add 'snowl' to all observer topics to avoid conflicts with other extensions/core code; use the Observers component everywhere diff -r 1db123f46ed7 -r c00b3db58dcf content/collections.js --- a/content/collections.js Mon Nov 03 18:02:27 2008 -0800 +++ b/content/collections.js Tue Nov 04 12:11:07 2008 -0800 @@ -34,12 +34,18 @@ * * ***** END LICENSE BLOCK ***** */ +// modules that come with Firefox + +// modules that are generic +Cu.import("resource://snowl/modules/log4moz.js"); +Cu.import("resource://snowl/modules/Observers.js"); +Cu.import("resource://snowl/modules/URI.js"); + +// modules that are Snowl-specific Cu.import("resource://snowl/modules/service.js"); Cu.import("resource://snowl/modules/datastore.js"); -Cu.import("resource://snowl/modules/log4moz.js"); 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/identity.js"); Cu.import("resource://snowl/modules/collection.js"); Cu.import("resource://snowl/modules/opml.js"); @@ -54,15 +60,6 @@ let CollectionsView = { _log: null, - // Observer Service - get _obsSvc() { - let obsSvc = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - delete this._obsSvc; - this._obsSvc = obsSvc; - return this._obsSvc; - }, - get _tree() { delete this._tree; return this._tree = document.getElementById("sourcesView"); @@ -80,7 +77,7 @@ init: function() { this._log = Log4Moz.Service.getLogger("Snowl.Sidebar"); - this._obsSvc.addObserver(this, "sources:changed", true); + Observers.add(this, "snowl:sources:changed"); this._getCollections(); this._buildCollectionTree(); @@ -229,22 +226,12 @@ //**************************************************************************// - // Misc XPCOM Interface Implementations - - // nsISupports - QueryInterface: function(aIID) { - if (aIID.equals(Ci.nsIObserver) || - aIID.equals(Ci.nsISupportsWeakReference) || - aIID.equals(Ci.nsISupports)) - return this; - - throw Cr.NS_ERROR_NO_INTERFACE; - }, + // Misc XPCOM Interfaces // nsIObserver observe: function(subject, topic, data) { switch (topic) { - case "sources:changed": + case "snowl:sources:changed": this._getCollections(); // Rebuild the view to reflect the new collection of messages. // Since the number of rows might have changed, we do this by reinitializing @@ -345,8 +332,8 @@ throw ex; } - this._obsSvc.notifyObservers(null, "sources:changed", null); - this._obsSvc.notifyObservers(null, "messages:changed", null); + Observers.notify(null, "snowl:sources:changed", null); + Observers.notify(null, "snowl:messages:changed", null); } }; diff -r 1db123f46ed7 -r c00b3db58dcf content/list.js --- a/content/list.js Mon Nov 03 18:02:27 2008 -0800 +++ b/content/list.js Tue Nov 04 12:11:07 2008 -0800 @@ -35,11 +35,18 @@ * * ***** END LICENSE BLOCK ***** */ -// FIXME: import these into an object to avoid name collisions. +// FIXME: import modules into an object to avoid name collisions, since this +// script gets loaded into the main browser window context. + +// modules that come with Firefox + +// modules that are generic Cu.import("resource://snowl/modules/log4moz.js"); +Cu.import("resource://snowl/modules/Observers.js"); +Cu.import("resource://snowl/modules/Preferences.js"); Cu.import("resource://snowl/modules/URI.js"); -Cu.import("resource://snowl/modules/Preferences.js"); +// modules that are Snowl-specific Cu.import("resource://snowl/modules/service.js"); Cu.import("resource://snowl/modules/datastore.js"); Cu.import("resource://snowl/modules/collection.js"); @@ -52,14 +59,6 @@ return this._log = Log4Moz.Service.getLogger("Snowl.ListView"); }, - // Observer Service - // FIXME: switch to using the Observers module. - get _obsSvc() { - delete this._obsSvc; - return this._obsSvc = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - }, - // Atom Service get _atomSvc() { delete this._atomSvc; @@ -194,7 +193,7 @@ }, show: function() { - this._obsSvc.addObserver(this, "messages:changed", true); + Observers.add(this, "snowl:messages:changed"); this._collection = new SnowlCollection(); this._sort(); @@ -213,27 +212,17 @@ // XXX Should we somehow destroy the view here (f.e. by setting // this._tree.view to null)? - this._obsSvc.removeObserver(this, "messages:changed"); + Observers.remove(this, "snowl:messages:changed"); }, //**************************************************************************// // Misc XPCOM Interfaces - // nsISupports - QueryInterface: function(aIID) { - if (aIID.equals(Ci.nsIObserver) || - aIID.equals(Ci.nsISupportsWeakReference) || - aIID.equals(Ci.nsISupports)) - return this; - - throw Cr.NS_ERROR_NO_INTERFACE; - }, - // nsIObserver observe: function(subject, topic, data) { switch (topic) { - case "messages:changed": + case "snowl:messages:changed": this._onMessagesChanged(); break; } diff -r 1db123f46ed7 -r c00b3db58dcf content/river.js --- a/content/river.js Mon Nov 03 18:02:27 2008 -0800 +++ b/content/river.js Tue Nov 04 12:11:07 2008 -0800 @@ -224,9 +224,8 @@ // Initialization init: function() { - // FIXME: use the Observers module to observe message change notifications - // and rebuild the view when they happen. Or does the collections view - // already do that for us? + // FIXME: use the Observers module to observe message change + // or message added notifications and rebuild the view when they happen. // FIXME: simplify the way the view gets built after the collections view // gets loaded to make this code less buggy and easier to hack. diff -r 1db123f46ed7 -r c00b3db58dcf content/stream.js --- a/content/stream.js Mon Nov 03 18:02:27 2008 -0800 +++ b/content/stream.js Tue Nov 04 12:11:07 2008 -0800 @@ -42,10 +42,10 @@ // modules that come with Firefox Cu.import("resource://gre/modules/XPCOMUtils.jsm"); -// modules that should come with Firefox +// modules that are generic Cu.import("resource://snowl/modules/log4moz.js"); +Cu.import("resource://snowl/modules/Observers.js"); Cu.import("resource://snowl/modules/URI.js"); -Cu.import("resource://snowl/modules/Observers.js"); // modules that are Snowl-specific Cu.import("resource://snowl/modules/datastore.js"); @@ -85,15 +85,6 @@ return this._faviconSvc; }, - // Observer Service - get _obsSvc() { - let obsSvc = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - delete this._obsSvc; - this._obsSvc = obsSvc; - return this._obsSvc; - }, - _window: null, _document: null, @@ -139,16 +130,13 @@ return this._linkifyRegex = regex; }, - // nsISupports - QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, - Ci.nsISupportsWeakReference]), - //**************************************************************************// // Initialization & Destruction onLoad: function() { Observers.add(this, "snowl:message:added"); + Observers.add(this, "snowl:sources:changed"); this.onResize(); @@ -198,6 +186,9 @@ case "snowl:message:added": this._onMessageAdded(subject); break; + case "snowl:sources:changed": + this._onSourcesChanged(); + break; } }, @@ -234,6 +225,10 @@ this._contentSandbox.messageBox = null; }, + _onSourcesChanged: function() { + this._rebuildView(); + }, + onToggleGroup: function(event) { event.target.nextSibling.style.display = event.target.checked ? "block" : "none"; }, diff -r 1db123f46ed7 -r c00b3db58dcf content/subscribe.js --- a/content/subscribe.js Mon Nov 03 18:02:27 2008 -0800 +++ b/content/subscribe.js Tue Nov 04 12:11:07 2008 -0800 @@ -42,10 +42,10 @@ // modules that come with Firefox Cu.import("resource://gre/modules/XPCOMUtils.jsm"); -// modules that should come with Firefox +// modules that are generic +Cu.import("resource://snowl/modules/log4moz.js"); Cu.import("resource://snowl/modules/Observers.js"); Cu.import("resource://snowl/modules/URI.js"); -Cu.import("resource://snowl/modules/log4moz.js"); // Snowl-specific modules Cu.import("resource://snowl/modules/service.js"); diff -r 1db123f46ed7 -r c00b3db58dcf modules/feed.js --- a/modules/feed.js Mon Nov 03 18:02:27 2008 -0800 +++ b/modules/feed.js Tue Nov 04 12:11:07 2008 -0800 @@ -93,14 +93,6 @@ // the request succeeds, at which point we store it with the login manager. _authInfo: null, - // Observer Service - get _obsSvc() { - let obsSvc = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - this.__defineGetter__("_obsSvc", function() { return obsSvc }); - return this._obsSvc; - }, - //**************************************************************************// // Class Composition Goo @@ -308,7 +300,7 @@ } if (messagesChanged) - this._obsSvc.notifyObservers(null, "messages:changed", null); + Observers.notify(null, "snowl:messages:changed", null); Observers.notify(this, "snowl:subscribe:get:end", null); }, @@ -598,7 +590,7 @@ this.persist(); // Let observers know about the new source. - this._obsSvc.notifyObservers(null, "sources:changed", null); + Observers.notify(null, "snowl:sources:changed", null); // Refresh the feed to import all its items. this.onRefreshResult(aResult); diff -r 1db123f46ed7 -r c00b3db58dcf modules/service.js --- a/modules/service.js Mon Nov 03 18:02:27 2008 -0800 +++ b/modules/service.js Tue Nov 04 12:11:07 2008 -0800 @@ -78,15 +78,6 @@ return this._prefSvc; }, - // Observer Service - get _obsSvc() { - let obsSvc = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - delete this._obsSvc; - this._obsSvc = obsSvc; - return this._obsSvc; - }, - get _dirSvc() { let dirSvc = Cc["@mozilla.org/file/directory_service;1"]. getService(Ci.nsIProperties); @@ -237,7 +228,6 @@ let type; try { type = eval(row.type); - this._log.info("got " + row.type + " for " + row.name); } catch(ex) { this._log.error("error getting " + row.name + ": " + ex); diff -r 1db123f46ed7 -r c00b3db58dcf modules/twitter.js --- a/modules/twitter.js Mon Nov 03 18:02:27 2008 -0800 +++ b/modules/twitter.js Tue Nov 04 12:11:07 2008 -0800 @@ -86,14 +86,6 @@ _log: Log4Moz.Service.getLogger("Snowl.Twitter"), - // Observer Service - get _obsSvc() { - let obsSvc = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - this.__defineGetter__("_obsSvc", function() { return obsSvc }); - return this._obsSvc; - }, - //**************************************************************************// // Class Composition Goo @@ -269,7 +261,7 @@ this.persist(); // Let observers know about the new source. - this._obsSvc.notifyObservers(null, "sources:changed", null); + Observers.notify(null, "snowl:sources:changed", null); this.refresh(); }, @@ -397,7 +389,7 @@ } if (messagesChanged) - this._obsSvc.notifyObservers(null, "messages:changed", null); + Observers.notify(null, "snowl:messages:changed", null); // FIXME: if we added people, refresh the collections view too.