Bug 920801 - Port chat/ changes from Instantbird to comm-central - 6 - Bio 1827 - Add an easy way to copy an account specific debug log, UI part, r=fqueze.
authorFlorian Quèze <florian@instantbird.org>
Wed, 28 Nov 2012 01:18:38 +0100
changeset 17243 75e8768c941d7c8078c9483f37ed8dea47fbe0ef
parent 17242 1d7c27dcd3c08ce1115200b9a1da6a26d87068f0
child 17244 b52a6febc68de85a02cebc33685c1d5471cd3729
push id1103
push usermbanner@mozilla.com
push dateTue, 18 Mar 2014 07:44:06 +0000
treeherdercomm-beta@50c6279a0af0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfqueze
bugs920801
Bug 920801 - Port chat/ changes from Instantbird to comm-central - 6 - Bio 1827 - Add an easy way to copy an account specific debug log, UI part, r=fqueze.
mail/components/im/content/imAccounts.js
mail/components/im/content/imAccounts.xul
mail/locales/en-US/chrome/messenger/imAccounts.dtd
--- a/mail/components/im/content/imAccounts.js
+++ b/mail/components/im/content/imAccounts.js
@@ -1,13 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-const {interfaces: Ci, utils: Cu} = Components;
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 Cu.import("resource:///modules/imServices.jsm");
 Cu.import("resource:///modules/iteratorUtils.jsm");
 Cu.import("resource:///modules/mailServices.js");
 Cu.import("resource://gre/modules/DownloadUtils.jsm");
 
 // This is the list of notifications that the account manager window observes
 const events = [
   "prpl-quit",
@@ -206,16 +206,44 @@ var gAccountManager = {
   },
   disconnect: function am_disconnect() {
     let account = this.accountList.selectedItem.account;
     if (account.connected || account.connecting) {
       this.temporarilyDisableButtons();
       account.disconnect();
     }
   },
+  copyDebugLog: function am_copyDebugLog() {
+    let account = this.accountList.selectedItem.account;
+    let text = account.getDebugMessages().map(function(dbgMsg) {
+      let m = dbgMsg.message;
+      const dateServ = Cc["@mozilla.org/intl/scriptabledateformat;1"]
+                         .getService(Ci.nsIScriptableDateFormat);
+      let time = new Date(m.timeStamp);
+      time = dateServ.FormatDateTime("", dateServ.dateFormatShort,
+                                     dateServ.timeFormatSeconds,
+                                     time.getFullYear(), time.getMonth() + 1,
+                                     time.getDate(), time.getHours(),
+                                     time.getMinutes(), time.getSeconds());
+      let level = dbgMsg.logLevel;
+      if (level == dbgMsg.LEVEL_ERROR)
+        level = "ERROR";
+      else if (level == dbgMsg.LEVEL_WARNING)
+        level = "WARN.";
+      else if (level == dbgMsg.LEVEL_LOG)
+        level = "LOG  ";
+      else
+        level = "DEBUG"
+      return "[" + time + "] " + level + " (@ " + m.sourceLine +
+             " " + m.sourceName + ":" + m.lineNumber + ")\n" +
+             m.errorMessage;
+    }).join("\n");
+    Cc["@mozilla.org/widget/clipboardhelper;1"]
+      .getService(Ci.nsIClipboardHelper).copyString(text);
+  },
   updateConnectedLabels: function am_updateConnectedLabels() {
     for (let i = 0; i < gAccountManager.accountList.itemCount; ++i) {
       let item = gAccountManager.accountList.getItemAtIndex(i);
       if (item.account.connected)
         item.refreshConnectedLabel();
     }
   },
   /* This function disables the connect/disconnect buttons for
@@ -464,17 +492,17 @@ var gAccountManager = {
         label = bundle.getString("accountsManager.notification.crash.label");
         priority = box.PRIORITY_WARNING_MEDIUM;
         break;
 
       /* One or more accounts made the application crash during their connection.
          If none, this function has already returned */
       case as.AUTOLOGIN_ENABLED:
         if (!("PluralForm" in window))
-          Components.utils.import("resource://gre/modules/PluralForm.jsm");
+          Cu.import("resource://gre/modules/PluralForm.jsm");
         label = bundle.getString("accountsManager.notification.singleCrash.label");
         label = PluralForm.get(crashCount, label).replace("#1", crashCount);
         priority = box.PRIORITY_WARNING_MEDIUM;
         connectNowButton.callback = this.processCrashedAccountsLogin;
         break;
 
       default:
         label = bundle.getString("accountsManager.notification.other.label");
--- a/mail/components/im/content/imAccounts.xul
+++ b/mail/components/im/content/imAccounts.xul
@@ -40,16 +40,20 @@
    <command id="cmd_disconnect"
             label="&account.disconnect.label;"
             accesskey="&account.disconnect.accesskey;"
             oncommand="gAccountManager.disconnect()"/>
    <command id="cmd_cancelReconnection"
             label="&account.cancelReconnection.label;"
             accesskey="&account.cancelReconnection.accesskey;"
             oncommand="gAccountManager.cancelReconnection()"/>
+   <command id="cmd_copyDebugLog"
+            label="&account.copyDebugLog.label;"
+            accesskey="&account.copyDebugLog.accesskey;"
+            oncommand="gAccountManager.copyDebugLog();"/>
    <command id="cmd_moveup"
             label="&account.moveup.label;"
             oncommand="gAccountManager.moveCurrentItem(-1)"/>
    <command id="cmd_movedown"
             label="&account.movedown.label;"
             oncommand="gAccountManager.moveCurrentItem(1)"/>
    <command id="cmd_edit"
             label="&account.edit.label;"
@@ -82,16 +86,18 @@
              command="cmd_connect"
              observes="contextAccountsItems"/>
    <menuitem id="context_disconnect"
              command="cmd_disconnect"
              observes="contextAccountsItems"/>
    <menuitem id="context_cancelReconnection"
              command="cmd_cancelReconnection"
              observes="contextAccountsItems"/>
+   <menuitem id="context_copyDebugLog"
+             command="cmd_copyDebugLog"/>
    <menuseparator id="context_accountsItemsSeparator"
                   observes="contextAccountsItems"/>
    <menuitem command="cmd_new"/>
    <menuseparator observes="contextAccountsItems"/>
    <menuitem command="cmd_moveup" observes="contextAccountsItems"/>
    <menuitem command="cmd_movedown" observes="contextAccountsItems"/>
    <menuseparator observes="contextAccountsItems"/>
    <menuitem command="cmd_edit" observes="contextAccountsItems"/>
--- a/mail/locales/en-US/chrome/messenger/imAccounts.dtd
+++ b/mail/locales/en-US/chrome/messenger/imAccounts.dtd
@@ -20,11 +20,13 @@
 <!ENTITY account.disconnect.label     "Disconnect">
 <!ENTITY account.disconnect.accesskey "i">
 <!ENTITY account.edit.label           "Properties">
 <!ENTITY account.edit.accesskey       "P">
 <!ENTITY account.moveup.label         "Move up">
 <!ENTITY account.movedown.label       "Move down">
 <!ENTITY account.cancelReconnection.label         "Cancel reconnection">
 <!ENTITY account.cancelReconnection.accesskey     "a">
+<!ENTITY account.copyDebugLog.label     "Copy Debug Log">
+<!ENTITY account.copyDebugLog.accesskey "C">
 <!ENTITY account.connecting           "Connecting…">
 <!ENTITY account.disconnecting        "Disconnecting…">
 <!ENTITY account.disconnected         "Not Connected">