Very basic activity manager support.
authorShawn Wilsher <me@shawnwilsher.com>
Fri, 30 Oct 2009 17:20:10 -0700
changeset 23 c975360db19914599e53f32c8011e8d5b7c6f824
parent 22 6b3e075d0bd837c10ca84e271e80ae8e85ce1ccb
child 24 3547b2d03992ad0356acede595e4b3db57d36a87
push id14
push usersdwilsh@shawnwilsher.com
push dateSat, 31 Oct 2009 02:13:27 +0000
Very basic activity manager support.
content/reply.js
resource/BugzillaHelper.jsm
--- a/content/reply.js
+++ b/content/reply.js
@@ -43,16 +43,17 @@ var ReplyDialog = {
     let comment = document.getElementById("comment").value;
     let isPrivate = document.getElementById("private").checked;
     let callback = Helper.commentCallback;
     let context = {
       bug: bugID,
       auth: auth,
       comment: comment,
       isPrivate: isPrivate,
+      activity: new CommentActivity(bugID),
     };
 
     BugzillaAPI.addComment(kServer, bugID, auth, comment, isPrivate, callback,
                            context);
     // TODO add to activity manager
     return true;
   },
 
--- a/resource/BugzillaHelper.jsm
+++ b/resource/BugzillaHelper.jsm
@@ -36,16 +36,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 Components.utils.import("resource://bugzilla-helper/BugzillaAPI.jsm");
 
 let EXPORTED_SYMBOLS = [
   "Helper",
+  "CommentActivity",
 ];
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Constants
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
@@ -54,38 +55,47 @@ const Cr = Components.results;
 const kBugzillaURI = "https://bugzilla-stage-tip.mozilla.org/";
 
 /*
 const kBugzillaURI = "https://bugzilla.mozilla.org/";
 */
 const kBugzillaRealm = "bugzilla-helper";
 
 ////////////////////////////////////////////////////////////////////////////////
+//// Globals
+
+this.__defineGetter__("activityManager", function() {
+  delete this.activityManager;
+  return this.activityManager = Cc["@mozilla.org/activity-manager;1"].
+                                getService(Ci.nsIActivityManager);
+});
+
+////////////////////////////////////////////////////////////////////////////////
 //// Dialog Controller
 
 const Helper = {
   commentCallback: function H_commentHandler(aResponseCode,
                                              aResponse,
                                              aContext)
   {
     if (aResponseCode == 200) {
+      aContext.activity.complete();
       if (store)
         Helper.storePassword(username, password);
       return;
     }
+    aContext.activity.error();
     // We had something unexpected.  Tell the user.
     // XXX dispatch to notification box (id="mail-notification-box" in parent)
     Components.utils.reportError("Got HTTP/" + aResponseCode + "\n" +
                                  aResponse + "\n for comment" + aContext.comment);
   },
 
   getLoginInformation: function H_getLoginInformation()
   {
-    // NOTE this isn't my actually password.  I changed it on the staging server
-    // to be something weak.
     let shouldStore = false;
     let [username, password] = Helper.getStoredPassword();
     if (!username || !password) {
       shouldStore = true;
       [username, password] = Helper.promptForPassword();
     }
 
     return [username, password, shouldStore];
@@ -130,8 +140,34 @@ const Helper = {
     l.init(kBugzillaURI, null, kBugzillaRealm, aUsername, aPassword, "", "");
 
     // And store it.
     let lm = Components.classes["@mozilla.org/login-manager;1"]
                        .getService(Components.interfaces.nsILoginManager);
     lm.addLogin(l);
   },
 };
+
+////////////////////////////////////////////////////////////////////////////////
+//// CommentActivity
+
+function CommentActivity(aBugNumber)
+{
+  let process = Cc["@mozilla.org/activity-process;1"].
+                createInstance(Ci.nsIActivityProcess);
+  process.init("Comment to bug " + aBugNumber, null);
+
+  // Add the process.
+  activityManager.addActivity(process);
+  this._process = process;
+}
+
+CommentActivity.prototype = {
+  complete: function CA_complete()
+  {
+    this._process.setProgress("Submitted", 1, 1);
+  },
+
+  error: function CA_error()
+  {
+    this._process.state = Ci.nsIActivityProcess.STATE_WAITINGFORRETRY;
+  },
+};