Bug 734547 - Use Services.prefs instead of getPref(), in SM MsgComposeCommands.js. r=frg
authoraceman <acelists@atlas.sk>
Sun, 25 Nov 2018 20:49:19 +0100
changeset 33777 6066121e0a2a10be4450569f2461f1c6dfc66b46
parent 33776 e43bbffbc0c32c80a84432467c161fb83eeae244
child 33778 b75abd6ba2b3388ef37fc54725c02cb4eff93571
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersfrg
bugs734547
Bug 734547 - Use Services.prefs instead of getPref(), in SM MsgComposeCommands.js. r=frg
suite/mailnews/compose/MsgComposeCommands.js
--- a/suite/mailnews/compose/MsgComposeCommands.js
+++ b/suite/mailnews/compose/MsgComposeCommands.js
@@ -1163,17 +1163,17 @@ function ComposeStartup(aParams)
     if (!params)
     {
       args = GetArgs(window.arguments[0]);
     }
   }
 
   // Set the document language to the preference as early as possible.
   document.documentElement
-          .setAttribute("lang", getPref("spellchecker.dictionary"));
+          .setAttribute("lang", Services.prefs.getCharPref("spellchecker.dictionary"));
 
   var identityList = GetMsgIdentityElement();
 
   document.addEventListener("paste", onPasteOrDrop);
   document.addEventListener("drop", onPasteOrDrop);
 
   if (identityList)
     FillIdentityList(identityList);
@@ -1292,17 +1292,17 @@ function ComposeStartup(aParams)
 
       document.getElementById("returnReceiptMenu")
               .setAttribute("checked", gMsgCompose.compFields.returnReceipt);
       document.getElementById("dsnMenu")
               .setAttribute('checked', gMsgCompose.compFields.DSN);
       document.getElementById("cmd_attachVCard")
               .setAttribute("checked", gMsgCompose.compFields.attachVCard);
       document.getElementById("menu_inlineSpellCheck")
-              .setAttribute("checked", getPref("mail.spellcheck.inline"));
+              .setAttribute("checked", Services.prefs.getBoolPref("mail.spellcheck.inline"));
 
       try {
         var editortype = gMsgCompose.composeHTML ? "htmlmail" : "textmail";
         editorElement.makeEditable(editortype, true);
       } catch (e) { dump(" FAILED TO START EDITOR: "+e+"\n"); }
 
       // setEditorType MUST be call before setContentWindow
       if (gMsgCompose.composeHTML)
@@ -1388,18 +1388,18 @@ function ComposeStartup(aParams)
                     (folder.flags & nsMsgFolderFlags.Drafts);
   }
   catch (ex) {
     gEditingDraft = false;
   }
 
   gAutoSaveKickedIn = false;
 
-  gAutoSaveInterval = getPref("mail.compose.autosave")
-    ? getPref("mail.compose.autosaveinterval") * 60000
+  gAutoSaveInterval = Services.prefs.getBoolPref("mail.compose.autosave")
+    ? Services.prefs.getIntPref("mail.compose.autosaveinterval") * 60000
     : 0;
 
   if (gAutoSaveInterval)
     gAutoSaveTimeout = setTimeout(AutoSave, gAutoSaveInterval);
 }
 
 // The new, nice, simple way of getting notified when a new editor has been created
 var gMsgEditorCreationObserver =
@@ -1443,17 +1443,17 @@ function WizCallback(state)
   }
 }
 
 function ComposeLoad()
 {
   sComposeMsgsBundle = document.getElementById("bundle_composeMsgs");
   sBrandBundle = document.getElementById("brandBundle");
 
-  var otherHeaders = getPref("mail.compose.other.header");
+  var otherHeaders = Services.prefs.getCharPref("mail.compose.other.header");
 
   sRDF = Cc['@mozilla.org/rdf/rdf-service;1']
            .getService(Ci.nsIRDFService);
   sNameProperty = sRDF.GetResource("http://home.netscape.com/NC-rdf#Name?sort=true");
 
   AddMessageComposeOfflineQuitObserver();
 
   if (gLogComposePerformance)
@@ -1573,17 +1573,17 @@ function GetCharsetUIString()
   }
 
   return "";
 }
 
 // Add-ons can override this to customize the behavior.
 function DoSpellCheckBeforeSend()
 {
-  return getPref("mail.SpellCheckBeforeSend");
+  return Services.prefs.getBoolPref("mail.SpellCheckBeforeSend");
 }
 
 function GenericSendMessage( msgType )
 {
   if (gMsgCompose != null)
   {
     var msgCompFields = gMsgCompose.compFields;
     if (msgCompFields)
@@ -1642,17 +1642,17 @@ function GenericSendMessage( msgType )
               "' has no matching account!";
         }
         var servertype = account.incomingServer.type;
 
         if (servertype != "nntp" && msgCompFields.newsgroups != "")
         {
           const kDontAskAgainPref = "mail.compose.dontWarnMail2Newsgroup";
           // default to ask user if the pref is not set
-          var dontAskAgain = getPref(kDontAskAgainPref);
+          var dontAskAgain = Services.prefs.getBoolPref(kDontAskAgainPref);
           if (!dontAskAgain)
           {
             var checkbox = {value:false};
             var okToProceed = Services.prompt.confirmCheck(
                                   window,
                                   sComposeMsgsBundle.getString("sendMsgTitle"),
                                   sComposeMsgsBundle.getString("recipientDlogMessage"),
                                   sComposeMsgsBundle.getString("CheckMsg"),
@@ -1729,22 +1729,18 @@ function GenericSendMessage( msgType )
         msgType == nsIMsgCompDeliverMode.AutoSaveAsDraft ||
         msgType == nsIMsgCompDeliverMode.SaveAsTemplate)
       {
         var fallbackCharset = new Object;
         // Check encoding, switch to UTF-8 if the default encoding doesn't fit
         // and disable_fallback_to_utf8 isn't set for this encoding.
         if (!gMsgCompose.checkCharsetConversion(getCurrentIdentity(), fallbackCharset))
         {
-          var disableFallback = false;
-          try
-          {
-            disableFallback = getPref("mailnews.disable_fallback_to_utf8." + originalCharset);
-          }
-          catch (e) {}
+          let disableFallback = Services.prefs
+            .getBoolPref("mailnews.disable_fallback_to_utf8." + originalCharset, false);
           if (disableFallback)
             msgCompFields.needToCheckCharset = false;
           else
             fallbackCharset.value = "UTF-8";
         }
 
         if (fallbackCharset &&
             fallbackCharset.value && fallbackCharset.value != "")
@@ -1837,17 +1833,17 @@ function SendMessage()
       sendInBackground = false;
   }
   GenericSendMessage(sendInBackground ? nsIMsgCompDeliverMode.Background
                                       : nsIMsgCompDeliverMode.Now);
 }
 
 function SendMessageWithCheck()
 {
-    var warn = getPref("mail.warn_on_send_accel_key");
+    var warn = Services.prefs.getBoolPref("mail.warn_on_send_accel_key");
 
     if (warn) {
         var checkValue = {value:false};
         var buttonPressed = Services.prompt.confirmEx(window,
               sComposeMsgsBundle.getString('sendMessageCheckWindowTitle'),
               sComposeMsgsBundle.getString('sendMessageCheckLabel'),
               (Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0) +
               (Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1),
@@ -2889,17 +2885,17 @@ function LoadIdentity(startup)
           } catch (ex) { dump("### Cannot change the identity: " + ex + "\n");}
 
           var event = document.createEvent('Events');
           event.initEvent('compose-from-changed', false, true);
           document.getElementById("msgcomposeWindow").dispatchEvent(event);
         }
 
       if (!startup) {
-          if (getPref("mail.autoComplete.highlightNonMatches"))
+          if (Services.prefs.getBoolPref("mail.autoComplete.highlightNonMatches"))
             document.getElementById('addressCol2#1').highlightNonMatches = true;
 
           // Only do this if we aren't starting up...
           // It gets done as part of startup already.
           addRecipientsToIgnoreList(gCurrentIdentity.fullAddress);
       }
     }
 }
@@ -2907,26 +2903,21 @@ function LoadIdentity(startup)
 function setupAutocomplete()
 {
   var autoCompleteWidget = document.getElementById("addressCol2#1");
 
   // if the pref is set to turn on the comment column, honor it here.
   // this element then gets cloned for subsequent rows, so they should
   // honor it as well
   //
-  try {
-      if (getPref("mail.autoComplete.highlightNonMatches"))
-        autoCompleteWidget.highlightNonMatches = true;
-
-      if (getPref("mail.autoComplete.commentColumn"))
-        autoCompleteWidget.showCommentColumn = true;
-  } catch (ex) {
-      // if we can't get this pref, then don't show the columns (which is
-      // what the XUL defaults to)
-  }
+  if (Services.prefs.getBoolPref("mail.autoComplete.highlightNonMatches"))
+    autoCompleteWidget.highlightNonMatches = true;
+
+  if (Services.prefs.getIntPref("mail.autoComplete.commentColumn", 0) != 0)
+    autoCompleteWidget.showCommentColumn = true;
 }
 
 function subjectKeyPress(event)
 {
   switch(event.keyCode) {
   case KeyEvent.DOM_VK_TAB:
     if (!event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey) {
       SetMsgBodyFrameFocus();
@@ -3247,51 +3238,42 @@ function SwitchElementFocus(event)
       SetMsgIdentityElementFocus();
     else
       SetMsgAddressingWidgetElementFocus();
   }
 }
 
 function loadHTMLMsgPrefs()
 {
-  var fontSize;
-  var textColor;
-  var bgColor;
-
   var fontFace = Services.prefs.getStringPref("msgcompose.font_face", "");
   doStatefulCommand("cmd_fontFace", fontFace);
 
-  try {
-    fontSize = getPref("msgcompose.font_size");
+  var fontSize = Services.prefs.getCharPref("msgcompose.font_size", "");
+  if (fontSize)
     EditorSetFontSize(fontSize);
-  } catch (e) {}
 
   var bodyElement = GetBodyElement();
 
-  try {
-    textColor = getPref("msgcompose.text_color");
-    if (!bodyElement.hasAttribute("text"))
-    {
-      bodyElement.setAttribute("text", textColor);
-      gDefaultTextColor = textColor;
-      document.getElementById("cmd_fontColor").setAttribute("state", textColor);
-      onFontColorChange();
-    }
-  } catch (e) {}
-
-  try {
-    bgColor = getPref("msgcompose.background_color");
-    if (!bodyElement.hasAttribute("bgcolor"))
-    {
-      bodyElement.setAttribute("bgcolor", bgColor);
-      gDefaultBackgroundColor = bgColor;
-      document.getElementById("cmd_backgroundColor").setAttribute("state", bgColor);
-      onBackgroundColorChange();
-    }
-  } catch (e) {}
+  var textColor = Services.prefs.getCharPref("msgcompose.text_color", "");
+  if (!bodyElement.hasAttribute("text") && textColor)
+  {
+    bodyElement.setAttribute("text", textColor);
+    gDefaultTextColor = textColor;
+    document.getElementById("cmd_fontColor").setAttribute("state", textColor);
+    onFontColorChange();
+  }
+
+  var bgColor = Services.prefs.getCharPref("msgcompose.background_color", "");
+  if (!bodyElement.hasAttribute("bgcolor") && bgColor)
+  {
+    bodyElement.setAttribute("bgcolor", bgColor);
+    gDefaultBackgroundColor = bgColor;
+    document.getElementById("cmd_backgroundColor").setAttribute("state", bgColor);
+    onBackgroundColorChange();
+  }
 }
 
 function AutoSave()
 {
   if (gMsgCompose.editor && (gContentChanged || gMsgCompose.bodyModified) &&
       !gSendOrSaveOperationInProgress)
   {
     GenericSendMessage(nsIMsgCompDeliverMode.AutoSaveAsDraft);
@@ -3341,17 +3323,17 @@ function InitEditor(editor)
     Services.prefs.getBoolPref("editor.CR_creates_new_p");
   editor.document.execCommand("defaultparagraphseparator", false,
     gMsgCompose.composeHTML &&
     Services.prefs.getBoolPref("mail.compose.default_to_paragraph") ?
                                "p" : "br");
 
   gMsgCompose.initEditor(editor, window.content);
   InlineSpellCheckerUI.init(editor);
-  EnableInlineSpellCheck(getPref("mail.spellcheck.inline"));
+  EnableInlineSpellCheck(Services.prefs.getBoolPref("mail.spellcheck.inline"));
   document.getElementById("menu_inlineSpellCheck").setAttribute("disabled", !InlineSpellCheckerUI.canSpellCheck);
 
   // Listen for spellchecker changes, set the document language to the
   // dictionary picked by the user via the right-click menu in the editor.
   document.addEventListener("spellcheck-changed", updateDocumentLanguage);
 
   // XXX: the error event fires twice for each load. Why??
   editor.document.body.addEventListener("error", function(event) {
@@ -3480,35 +3462,16 @@ function MailToolboxCustomizeDone(aToolb
   SetMsgBodyFrameFocus();
 }
 
 function MailToolboxCustomizeChange(aEvent)
 {
   toolboxCustomizeChange(getMailToolbox(), aEvent);
 }
 
-// Thunderbird compatibility function.
-function getPref(aPrefName, aIsComplex)
-{
-  if (aIsComplex)
-      return GetStringPref(aPrefName);
-
-  switch (Services.prefs.getPrefType(aPrefName))
-  {
-    case Ci.nsIPrefBranch.PREF_BOOL:
-      return Services.prefs.getBoolPref(aPrefName);
-    case Ci.nsIPrefBranch.PREF_INT:
-      return Services.prefs.getIntPref(aPrefName);
-    case Ci.nsIPrefBranch.PREF_STRING:
-      return Services.prefs.getCharPref(aPrefName);
-    default: // includes nsIPrefBranch.PREF_INVALID
-      return null;
-  }
-}
-
 /**
  * Object to handle message related notifications that are showing in a
  * notificationbox below the composed message content.
  */
 var gComposeNotificationBar = {
 
   get notificationBar() {
     delete this.notificationBar;