diff extension/modules/feed.js @ 138:58b04d16257c

integrate subscription UI into a single page
author Myk Melez <myk@mozilla.org>
date Sun, 06 Jul 2008 00:05:45 -0700
parents 447ad38415f8
children 8763c90ce556
line wrap: on
line diff
--- a/extension/modules/feed.js	Sun Jun 22 19:11:02 2008 -0700
+++ b/extension/modules/feed.js	Sun Jul 06 00:05:45 2008 -0700
@@ -354,9 +354,11 @@
     SnowlDatastore.insertMetadatum(aMessageID, attributeID, aValue);
   },
 
-  subscribe: function() {
+  subscribe: function(callback) {
     Observers.notify(this, "snowl:subscribe:connect:start", null);
 
+    this._subscribeCallback = callback;
+
     this._log.info("subscribing to " + this.name + " <" + this.machineURI.spec + ">");
 
     let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
@@ -401,35 +403,44 @@
   },
 
   onSubscribeResult: function(aResult) {
-    let feed = aResult.doc.QueryInterface(Components.interfaces.nsIFeed);
-
-    // Extract the name (if we don't already have one) and human URI from the feed.
-    if (!this.name)
-      this.name = feed.title.plainText();
-    this.humanURI = feed.link;
+    try {
+      let feed = aResult.doc.QueryInterface(Components.interfaces.nsIFeed);
 
-    // Add the source to the database.
-    let statement =
-      SnowlDatastore.createStatement("INSERT INTO sources (name, machineURI, humanURI) " +
-                                     "VALUES (:name, :machineURI, :humanURI)");
-    try {
-      statement.params.name = this.name;
-      statement.params.machineURI = this.machineURI.spec;
-      statement.params.humanURI = this.humanURI.spec;
-      statement.step();
+      // Extract the name (if we don't already have one) and human URI from the feed.
+      if (!this.name)
+        this.name = feed.title.plainText();
+      this.humanURI = feed.link;
+  
+      // Add the source to the database.
+      let statement =
+        SnowlDatastore.createStatement("INSERT INTO sources (name, machineURI, humanURI) " +
+                                       "VALUES (:name, :machineURI, :humanURI)");
+      try {
+        statement.params.name = this.name;
+        statement.params.machineURI = this.machineURI.spec;
+        statement.params.humanURI = this.humanURI.spec;
+        statement.step();
+      }
+      finally {
+        statement.reset();
+      }
+  
+      // Extract the ID of the source from the newly-created database record.
+      this.id = SnowlDatastore.dbConnection.lastInsertRowID;
+  
+      // Let observers know about the new source.
+      this._obsSvc.notifyObservers(null, "sources:changed", null);
+  
+      // Refresh the feed to import all its items.
+      this.onRefreshResult(aResult);
+    }
+    catch(ex) {
+      dump("error on subscribe result: " + ex + "\n");
     }
     finally {
-      statement.reset();
+      if (this._subscribeCallback)
+        this._subscribeCallback();
     }
-
-    // Extract the ID of the source from the newly-created database record.
-    this.id = SnowlDatastore.dbConnection.lastInsertRowID;
-
-    // Let observers know about the new source.
-    this._obsSvc.notifyObservers(null, "sources:changed", null);
-
-    // Refresh the feed to import all its items.
-    this.onRefreshResult(aResult);
   }
 
 };