Bug 934492 Port language preference pane changes from bug 910192 r=IanN a=IanN
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Wed, 20 Aug 2014 00:28:38 +0100
changeset 20292 ca5ec1a2966ff4a5b06007a6142626012fc76674
parent 20291 3327fcf349aa6762f7ac93ac814be9a714bbdff7
child 20293 94246e4447ccd9540227ba1d4451293599c34638
child 20295 5888f603ab38e3784b12836131381afec80ca6f3
push id1199
push userneil@parkwaycc.co.uk
push dateTue, 19 Aug 2014 23:29:02 +0000
treeherdercomm-beta@ca5ec1a2966f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN, IanN
bugs934492, 910192
Bug 934492 Port language preference pane changes from bug 910192 r=IanN a=IanN
suite/common/pref/pref-languages.js
suite/common/pref/pref-languages.xul
suite/common/pref/preferences.js
suite/common/pref/preferences.xul
suite/mailnews/prefs/pref-character_encoding.js
suite/mailnews/prefs/pref-character_encoding.xul
--- a/suite/common/pref/pref-languages.js
+++ b/suite/common/pref/pref-languages.js
@@ -5,27 +5,24 @@
 
 var gActiveLanguages;
 var gLanguages;
 var gLanguageNames = [];
 var gLanguageTitles = {};
 
 function Startup()
 {
-  Services.obs.notifyObservers(null, "charsetmenu-selected", "other");
-
-  var defaultCharsetList = document.getElementById("defaultCharsetList");
-  defaultCharsetList.setAttribute("ref", "NC:DecodersRoot");
-
   gActiveLanguages = document.getElementById("activeLanguages");
   // gLanguages stores the ordered list of languages, due to the nature
   // of childNodes it is live and updates automatically.
   gLanguages = gActiveLanguages.childNodes;
 
   ReadAvailableLanguages();
+
+  LoadEncodingLabels("defaultCharsetList");
 }
 
 function AddLanguage()
 {
   document.documentElement.openSubDialog("chrome://communicator/content/pref/pref-languages-add.xul", "addlangwindow", gLanguageNames);
 }
 
 function ReadAvailableLanguages()
--- a/suite/common/pref/pref-languages.xul
+++ b/suite/common/pref/pref-languages.xul
@@ -23,19 +23,19 @@
                   name="pref.browser.language.disable_button.down"
                   type="bool"/>
       <preference id="pref.browser.language.disable_button.add"
                   name="pref.browser.language.disable_button.add"
                   type="bool"/>
       <preference id="pref.browser.language.disable_button.remove"
                   name="pref.browser.language.disable_button.remove"
                   type="bool"/>
-      <preference id="intl.charset.default"
-                  name="intl.charset.default"
-                  type="wstring"/>
+      <preference id="intl.charset.fallback.override"
+                  name="intl.charset.fallback.override"
+                  type="string"/>
     </preferences>
 
     <stringbundleset id="langBundleset">
       <stringbundle id="acceptedBundle"
                     src="resource://gre/res/language.properties"/>
       <stringbundle id="prefLangBundle"
                     src="chrome://communicator/locale/pref/pref-languages.properties"/>
     </stringbundleset>
@@ -87,26 +87,35 @@
     </groupbox>
 
     <groupbox align="start">
       <caption label="&languages.customize.Fallback.grouplabel;"/>
       <description>&languages.customize.Fallback.desc;</description>
       <hbox align="center">
         <label value="&languages.customize.Fallback.label;"
                accesskey="&languages.customize.Fallback.accesskey;"
-               control="DefaultCharsetList"/>
+               control="defaultCharsetList"/>
         <menulist id="defaultCharsetList"
-                  ref=""
-                  datasources="rdf:charset-menu"
-                  preference="intl.charset.default">
-          <template>
-            <menupopup>
-              <menuitem label="rdf:http://home.netscape.com/NC-rdf#Name"
-                        value="..."
-                        uri="..."/>
-            </menupopup>
-          </template>
-        </menulist> 
+                  preference="intl.charset.fallback.override">
+          <menupopup>
+            <menuitem value=""/>
+            <menuitem value="windows-1256"/>
+            <menuitem value="windows-1257"/>
+            <menuitem value="ISO-8859-2"/>
+            <menuitem value="windows-1250"/>
+            <menuitem value="gbk"/>
+            <menuitem value="Big5"/>
+            <menuitem value="windows-1251"/>
+            <menuitem value="ISO-8859-7"/>
+            <menuitem value="windows-1255"/>
+            <menuitem value="Shift_JIS"/>
+            <menuitem value="EUC-KR"/>
+            <menuitem value="windows-874"/>
+            <menuitem value="windows-1254"/>
+            <menuitem value="windows-1258"/>
+            <menuitem value="windows-1252"/>
+          </menupopup>
+        </menulist>
       </hbox>
     </groupbox>
 
   </prefpane>
 </overlay>
--- a/suite/common/pref/preferences.js
+++ b/suite/common/pref/preferences.js
@@ -64,8 +64,58 @@ function PlaySound(aValue, aMail)
 
   if (aValue)
     sound.play(Services.io.newURI(aValue, null, null));
   else if (aMail && !/Mac/.test(navigator.platform))
     sound.playEventSound(nsISound.EVENT_NEW_MAIL_RECEIVED);
   else
     sound.beep();
 }
+
+function LoadEncodingLabels(aMenulist, aPref)
+{
+  var bundle = document.getElementById("bundle_prefutilities");
+  var defaultLabel = bundle.getString("labelDefaultFont");
+  var list = document.getElementById(aMenulist);
+  var encoding = aPref ? document.getElementById(aPref).defaultValue :
+    GuessDefaultEncoding();
+  bundle = document.getElementById("charsetTitlesBundle");
+  encoding = bundle.getString(encoding.toLowerCase() + ".title")
+                   .replace(/.*\(|\).*/g, "");
+  var item = list.firstChild.firstChild;
+  item.setAttribute("label", defaultLabel.replace("%font_family%", encoding));
+  while ((item = item.nextSibling))
+    item.setAttribute("label", bundle.getString(item.getAttribute("value").toLowerCase() + ".title"));
+}
+
+function GuessDefaultEncoding()
+{
+  switch (Components.classes["@mozilla.org/chrome/chrome-registry;1"]
+                    .getService(Components.interfaces.nsIXULChromeRegistry)
+                    .getSelectedLocale("global").split("-")[0]) {
+    case "ar": case "fa":
+      return "windows-1256";
+    case "ba": case "be": case "bg": case "kk": case "ky": case "mk":
+    case "ru": case "sah": case "sr": case "tg": case "tt": case "uk":
+      return "windows-1251";
+    case "cs": case "hr": case "sk":
+      return "windows-1250";
+    case "el":
+      return "iso-8859-7";
+    case "et": case "lt": case "lv":
+      return "windows-1257";
+    case "he":
+      return "windows-1255";
+    case "hu": case "pl": case "sl":
+      return "iso-8859-2";
+    case "ko":
+      return "euc-kr";
+    case "ku": case "tr":
+      return "windows-1254";
+    case "th":
+      return "windows-874";
+    case "vi":
+      return "windows-1258";
+    case "zh":
+      return "gbk";
+  }
+  return "windows-1252";
+}
--- a/suite/common/pref/preferences.xul
+++ b/suite/common/pref/preferences.xul
@@ -30,16 +30,18 @@
 
   <stringbundleset id="prefBundleset">
     <stringbundle id="bundle_prefutilities"
                   src="chrome://communicator/locale/pref/prefutilities.properties"/>
     <stringbundle id="languageNamesBundle"
                   src="chrome://global/locale/languageNames.properties"/>
     <stringbundle id="regionNamesBundle"
                   src="chrome://global/locale/regionNames.properties"/>
+    <stringbundle id="charsetTitlesBundle"
+                  src="chrome://messenger/locale/charsetTitles.properties"/>
   </stringbundleset>
 
   <tree id="prefsTree"
         style="width: 13em;"
         seltype="single"
         hidecolumnpicker="true"
         hidden="true"
         flex="1">
--- a/suite/mailnews/prefs/pref-character_encoding.js
+++ b/suite/mailnews/prefs/pref-character_encoding.js
@@ -1,26 +1,44 @@
 /* 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/. */
 
 // The contents of this file will be loaded into the scope of the object
 // <prefpane id="character_encoding_pane">!
 
+var updatingPref = false;
+
 function Startup ()
 {
-  Services.obs.notifyObservers(null, "charsetmenu-selected", "other");
-  Services.obs.notifyObservers(null, "charsetmenu-selected", "mailedit");
+  PrefChanged(document.getElementById('mailnews.view_default_charset'));
+  PrefChanged(document.getElementById('mailnews.send_default_charset'));
+
+  LoadEncodingLabels("viewDefaultCharsetList", "mailnews.view_default_charset");
+  LoadEncodingLabels("sendDefaultCharsetList", "mailnews.send_default_charset")
+}
+
+function PrefChanged(aPref)
+{
+  if (updatingPref)
+    return;
 
-  var viewCharsetList = document.getElementById("viewDefaultCharsetList");
-  // Need to set ref attribute once overlay has loaded.
-  viewCharsetList.setAttribute("ref", "NC:DecodersRoot");
-  // Since the menulist starts off empty it has no selected item
-  // so try and set it to the preference value.
-  viewCharsetList.value = document.getElementById("mailnews.view_default_charset").value;
+  var id = aPref.id.substr(9, 4) + "DefaultCharsetList";
+  var menulist = document.getElementById(id);
+  if (!aPref.hasUserValue)
+    menulist.selectedIndex = 0;
+  else {
+    var bundle = document.getElementById("charsetBundle");
+    menulist.value = bundle.getString(aPref.value.toLowerCase());
+  }
+}
 
-  var sendCharsetList = document.getElementById("sendDefaultCharsetList");
-  // Need to set ref attribute once overlay has loaded.
-  sendCharsetList.setAttribute("ref", "NC:MaileditCharsetMenuRoot");
-  // Since the menulist starts off empty it has no selected item
-  // so try and set it to the preference value.
-  sendCharsetList.value = document.getElementById("mailnews.send_default_charset").value;
+function UpdatePref(aMenulist)
+{
+  updatingPref = true;
+  var id = "mailnews." + aMenulist.id.substr(0, 4) + "_default_charset";
+  var pref = document.getElementById(id);
+  if (aMenulist.selectedIndex)
+    pref.value = aMenulist.value;
+  else
+    pref.value = undefined; // reset to default
+  updatingPref = false;
 }
--- a/suite/mailnews/prefs/pref-character_encoding.xul
+++ b/suite/mailnews/prefs/pref-character_encoding.xul
@@ -10,45 +10,58 @@
 
 <overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <prefpane id="character_encoding_pane"
             label="&pref.character.encoding.title;"
             script="chrome://messenger/content/pref-character_encoding.js">
     <preferences id="character_encoding_preferences">
       <preference id="mailnews.view_default_charset"
                   name="mailnews.view_default_charset"
-                  type="wstring"/>
+                  type="wstring"
+                  onchange="PrefChanged(this);"/>
       <preference id="mail.strictly_mime"
                   name="mail.strictly_mime"
                   type="bool"/>
       <preference id="mailnews.send_default_charset"
                   name="mailnews.send_default_charset"
-                  type="wstring"/>
+                  type="wstring"
+                  onchange="PrefChanged(this);"/>
       <preference id="mailnews.reply_in_default_charset"
                   name="mailnews.reply_in_default_charset"
                   type="bool"/>
     </preferences>
 
+    <stringbundle id="charsetBundle"
+                  src="chrome://communicator/content/labelsencodings.properties"/>
     <groupbox align="start">
       <caption label="&messageDisplay.caption;"/>
       <hbox align="center">
         <label control="viewDefaultCharsetList"
                value="&viewFallbackCharset.label;"
                accesskey="&viewFallbackCharset.accesskey;"/>
         <menulist id="viewDefaultCharsetList"
-                  ref=""
-                  datasources="rdf:charset-menu"
-                  preference="mailnews.view_default_charset">
-          <template>
-            <menupopup>
-              <menuitem label="rdf:http://home.netscape.com/NC-rdf#Name"
-                        value="..."
-                        uri="..."/>
-            </menupopup>
-          </template>
+                  oncommand="UpdatePref(this);">
+          <menupopup>
+            <menuitem value=""/>
+            <menuitem value="windows-1256"/>
+            <menuitem value="windows-1257"/>
+            <menuitem value="ISO-8859-2"/>
+            <menuitem value="windows-1250"/>
+            <menuitem value="gbk"/>
+            <menuitem value="Big5"/>
+            <menuitem value="windows-1251"/>
+            <menuitem value="ISO-8859-7"/>
+            <menuitem value="windows-1255"/>
+            <menuitem value="Shift_JIS"/>
+            <menuitem value="EUC-KR"/>
+            <menuitem value="windows-874"/>
+            <menuitem value="windows-1254"/>
+            <menuitem value="windows-1258"/>
+            <menuitem value="windows-1252"/>
+          </menupopup>
         </menulist>
       </hbox>
       <description>&viewFallbackCharset.desc;</description>
     </groupbox>
 
     <!-- Composing Mail -->
     <groupbox align="start">
       <caption label="&composingMessages.caption;"/>
@@ -58,26 +71,35 @@
                 accesskey="&useMIME.accesskey;"
                 preference="mail.strictly_mime"/>
 
       <hbox align="center">
         <label value="&sendDefaultCharset.label;"
                accesskey="&sendDefaultCharset.accesskey;"
                control="sendDefaultCharsetList"/>
         <menulist id="sendDefaultCharsetList"
-                  ref=""
-                  datasources="rdf:charset-menu"
-                  preference="mailnews.send_default_charset">
-          <template>
-            <menupopup>
-              <menuitem label="rdf:http://home.netscape.com/NC-rdf#Name"
-                        value="..."
-                        uri="..."/>
-            </menupopup>
-          </template>
+                  oncommand="UpdatePref(this);">
+          <menupopup>
+            <menuitem value=""/>
+            <menuitem value="windows-1256"/>
+            <menuitem value="windows-1257"/>
+            <menuitem value="ISO-8859-2"/>
+            <menuitem value="windows-1250"/>
+            <menuitem value="gbk"/>
+            <menuitem value="Big5"/>
+            <menuitem value="windows-1251"/>
+            <menuitem value="ISO-8859-7"/>
+            <menuitem value="windows-1255"/>
+            <menuitem value="Shift_JIS"/>
+            <menuitem value="EUC-KR"/>
+            <menuitem value="windows-874"/>
+            <menuitem value="windows-1254"/>
+            <menuitem value="windows-1258"/>
+            <menuitem value="windows-1252"/>
+          </menupopup>
         </menulist>  
       </hbox>
       <checkbox id="replyInDefaultCharset"
                 label="&replyInDefaultCharset2.label;"
                 accesskey="&replyInDefaultCharset2.accesskey;"
                 preference="mailnews.reply_in_default_charset"/>
     </groupbox>
   </prefpane>