Bug 694047 - Turn off the locale picker (revert to a simple menulist) [r=mfinkle a=Cww]
authorWes Johnston <wjohnston@mozilla.com
Tue, 18 Oct 2011 14:05:28 -0400
changeset 78300 97645f2bcf5d276b89652e169a077d3dfe57f9b1
parent 78299 6ddc1d746bca6947ef92f853598c7cc3e35d7545
child 78301 2c16b0af8373efb964e75d71d8d933a19d6040b6
push id465
push usermbrubeck@mozilla.com
push dateMon, 24 Oct 2011 18:21:19 +0000
treeherdermozilla-aurora@97645f2bcf5d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, Cww
bugs694047
milestone9.0a2
Bug 694047 - Turn off the locale picker (revert to a simple menulist) [r=mfinkle a=Cww]
mobile/app/mobile.js
mobile/chrome/content/browser.xul
mobile/chrome/content/preferences.js
mobile/components/BrowserCLH.js
--- a/mobile/app/mobile.js
+++ b/mobile/app/mobile.js
@@ -659,17 +659,17 @@ pref("urlclassifier.confirm-age", 2700);
 pref("urlclassifier.updatecachemax", 4194304);
 
 // URL for checking the reason for a malware warning.
 pref("browser.safebrowsing.malware.reportURL", "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?client=%NAME%&hl=%LOCALE%&site=");
 #endif
 
 // True if this is the first time we are showing about:firstrun
 pref("browser.firstrun.show.uidiscovery", true);
-pref("browser.firstrun.show.localepicker", true);
+pref("browser.firstrun.show.localepicker", false);
 
 // True if you always want dump() to work
 //
 // On Android, you also need to do the following for the output
 // to show up in logcat:
 //
 // $ adb shell stop
 // $ adb shell setprop log.redirect-stdio true
--- a/mobile/chrome/content/browser.xul
+++ b/mobile/chrome/content/browser.xul
@@ -458,17 +458,21 @@
 # these two point to the same page, this just matters for what shows up in the
 # URL bar
                             oncommand="BrowserUI.newTab('about:firefox', Browser.selectedTab);"/>
 #else
                             oncommand="BrowserUI.newTab('about:fennec', Browser.selectedTab);"/>
 #endif
                   </setting>
                   <setting id="prefs-uilanguage" title="&language.title;" type="control">
-                    <button id="prefs-uilanguage-button" label="&language.title;" onclick="PreferencesView.showLocalePicker();"/>
+                    <menulist id="prefs-languages" oncommand="PreferencesView.updateLocale();">
+                      <menupopup>
+                        <menuitem id="prefs-languages-auto" label="&language.auto;" value="auto"/>
+                      </menupopup>
+                    </menulist>
                   </setting>
                   <setting id="prefs-homepage" title="&homepage.title;" type="menulist">
                     <menulist id="prefs-homepage-options" oncommand="PreferencesView.updateHomePage();">
                       <menupopup onpopupshowing="PreferencesView.updateHomePageList();">
                         <menuitem id="prefs-homepage-default" label="&homepage.default;" value="default"/>
                         <menuitem id="prefs-homepage-none" label="&homepage.none;" value="none"/>
                         <menuitem id="prefs-homepage-currentpage" label="&homepage.currentpage;" value="currentpage"/>
                       </menupopup>
--- a/mobile/chrome/content/preferences.js
+++ b/mobile/chrome/content/preferences.js
@@ -32,16 +32,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 var PreferencesView = {
   _currentLocale: null,
+  _languages: null,
   _msg: null,
 
   _messageActions: function pv__messageActions(aData) {
     if (aData == "prefs-restart-app") {
       // Notify all windows that an application quit has been requested
       var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
       Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
 
@@ -91,69 +92,93 @@ var PreferencesView = {
     }
   },
 
   delayedInit: function pv__delayedInit() {
     if (this._msg)
       return;
 
     this._msg = document.getElementById("prefs-messages");
+    this._languages = document.getElementById("prefs-languages");
     this._loadLocales();
 
     this._loadHomePage();
 
     MasterPasswordUI.updatePreference();
     WeaveGlue.init();
-
-    Services.prefs.addObserver("general.useragent.locale", this, false);
-  },
-
-  observe: function(aSubject, aTopic, aData) {
-    if (aData == "general.useragent.locale") {
-      this.showRestart();
-      this._loadLocales();
-    }
   },
 
   _loadLocales: function _loadLocales() {
     // Query available and selected locales
     let chrome = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry);
     chrome.QueryInterface(Ci.nsIToolkitChromeRegistry);
 
     let selectedLocale = chrome.getSelectedLocale("browser");
 
-    // the chrome locale may not have updated yet if the user is installing a new
-    // locale. if the pref has a user set value, use it instead
-    if (Services.prefs.prefHasUserValue("general.useragent.locale"))
-      selectedLocale = Services.prefs.getCharPref("general.useragent.locale");
-
     let availableLocales = chrome.getLocalesForPackage("browser");
 
     let strings = Services.strings.createBundle("chrome://browser/content/languages.properties");
 
+    // Render locale menulist by iterating through the query result from getLocalesForPackage()
     let selectedItem = null;
-    let selectedLabel = selectedLocale;
+    let localeCount = 0;
     while (availableLocales.hasMore()) {
       let locale = availableLocales.getNext();
       try {
         var label = strings.GetStringFromName(locale);
       } catch (e) {
         label = locale;
       }
+      let item = this._languages.appendItem(label, locale);
       if (locale == selectedLocale) {
-        selectedLabel = label;
         this._currentLocale = locale;
-        break;
+        selectedItem = item;
       }
+      localeCount++;
     }
-    document.getElementById("prefs-uilanguage-button").setAttribute("label", selectedLabel);
+
+    // Are we using auto-detection?
+    let autoDetect = false;
+    try {
+      autoDetect = Services.prefs.getBoolPref("intl.locale.matchOS");
+    }
+    catch (e) {}
+
+    // Highlight current locale (or auto-detect entry)
+    if (autoDetect) {
+      this._languages.selectedItem = document.getElementById("prefs-languages-auto");
+      this._currentLocale = "auto";
+    } else {
+      this._languages.selectedItem = selectedItem;
+    }
+
+    // Hide the setting if we only have one locale
+    if (localeCount == 1)
+      document.getElementById("prefs-uilanguage").hidden = true;
   },
 
-  showLocalePicker: function showLocalePicker() {
-    Services.ww.openWindow(window, "chrome://browser/content/localePicker.xul", "_browser", "chrome,dialog=no,all", null);
+  updateLocale: function updateLocale() {
+    // Which locale did the user select?
+    let newLocale = this._languages.selectedItem.value;
+    let prefs = Services.prefs;
+
+    if (newLocale == "auto") {
+      if (prefs.prefHasUserValue("general.useragent.locale"))
+        prefs.clearUserPref("general.useragent.locale");
+      prefs.setBoolPref("intl.locale.matchOS", true);
+    } else {
+      prefs.setBoolPref("intl.locale.matchOS", false);
+      prefs.setCharPref("general.useragent.locale", newLocale);
+    }
+
+    // Show the restart notification, if needed
+    if (this._currentLocale == newLocale)
+      this.hideRestart();
+    else
+      this.showRestart();
   },
 
   _showHomePageHint: function _showHomePageHint(aHint) {
     if (aHint)
       document.getElementById("prefs-homepage").setAttribute("desc", aHint);
     else
       document.getElementById("prefs-homepage").removeAttribute("desc");
   },
--- a/mobile/components/BrowserCLH.js
+++ b/mobile/components/BrowserCLH.js
@@ -241,18 +241,18 @@ BrowserCLH.prototype = {
 
         // Override the default if we have a URL passed on command line
         if (uris.length > 0) {
           defaultURL = uris[0].spec;
           uris = uris.slice(1);
         }
 
         // Show the locale selector if we have a new profile, or if the selected locale is no longer compatible
-        let showLocalePicker = Services.prefs.getBoolPref("browser.firstrun.show.localepicker")
-        if ((needHomepageOverride() == "new profile" && showLocalePicker && !haveSystemLocale()) || !checkCurrentLocale()) {
+        let showLocalePicker = Services.prefs.getBoolPref("browser.firstrun.show.localepicker");
+        if ((needHomepageOverride() == "new profile" && showLocalePicker && !haveSystemLocale())) { // || !checkCurrentLocale()) {
           browserWin = openWindow(null, "chrome://browser/content/localePicker.xul", "_blank", "chrome,dialog=no,all", defaultURL);
           aCmdLine.preventDefault = true;
           return;
         }
 
         browserWin = openWindow(null, "chrome://browser/content/browser.xul", "_blank", "chrome,dialog=no,all", defaultURL);
       }