2009-09-22 07:21:15 -07:00
|
|
|
// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Mobile Browser.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Mark Finkle <mfinkle@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* 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,
|
2010-03-26 08:11:03 -07:00
|
|
|
_languages: null,
|
2009-09-22 07:21:15 -07:00
|
|
|
_msg: null,
|
|
|
|
_restartCount: 0,
|
|
|
|
|
2011-01-27 09:36:22 -08:00
|
|
|
_messageActions: function pv__messageActions(aData) {
|
2009-09-22 07:21:15 -07:00
|
|
|
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);
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
|
2009-09-22 07:21:15 -07:00
|
|
|
|
|
|
|
// If nothing aborted, quit the app
|
|
|
|
if (cancelQuit.data == false) {
|
|
|
|
let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
|
|
|
|
appStartup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
showMessage: function ev_showMessage(aMsg, aValue, aButtonLabel, aShowCloseButton, aNotifyData) {
|
|
|
|
let notification = this._msg.getNotificationWithValue(aValue);
|
|
|
|
if (notification)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
let buttons = null;
|
|
|
|
if (aButtonLabel) {
|
|
|
|
buttons = [ {
|
|
|
|
label: aButtonLabel,
|
|
|
|
accessKey: "",
|
|
|
|
data: aNotifyData,
|
|
|
|
callback: function(aNotification, aButton) {
|
|
|
|
self._messageActions(aButton.data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} ];
|
|
|
|
}
|
|
|
|
|
|
|
|
this._msg.appendNotification(aMsg, aValue, "", this._msg.PRIORITY_WARNING_LOW, buttons).hideclose = !aShowCloseButton;
|
|
|
|
},
|
|
|
|
|
|
|
|
showRestart: function ev_showRestart() {
|
|
|
|
// Increment the count in case the view is not completely initialized
|
|
|
|
this._restartCount++;
|
|
|
|
|
|
|
|
if (this._msg) {
|
2011-01-03 12:07:41 -08:00
|
|
|
let strings = Strings.browser;
|
|
|
|
this.showMessage(strings.GetStringFromName("notificationRestart.normal"), "restart-app",
|
|
|
|
strings.GetStringFromName("notificationRestart.button"), false, "prefs-restart-app");
|
2009-09-22 07:21:15 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
hideRestart: function ev_hideRestart() {
|
|
|
|
this._restartCount--;
|
|
|
|
if (this._restartCount == 0 && this._msg) {
|
|
|
|
let notification = this._msg.getNotificationWithValue("restart-app");
|
|
|
|
if (notification)
|
|
|
|
notification.close();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-02-17 13:25:59 -08:00
|
|
|
delayedInit: function pv__delayedInit() {
|
2010-03-26 08:11:03 -07:00
|
|
|
if (this._languages)
|
2009-09-22 07:21:15 -07:00
|
|
|
return;
|
|
|
|
|
2011-02-17 13:25:59 -08:00
|
|
|
this._msg = document.getElementById("prefs-messages");
|
2010-03-26 08:11:03 -07:00
|
|
|
this._languages = document.getElementById("prefs-languages");
|
2009-09-22 07:21:15 -07:00
|
|
|
this._loadLocales();
|
2010-03-26 08:11:03 -07:00
|
|
|
|
|
|
|
this._loadHomePage();
|
2009-09-22 07:21:15 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_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");
|
|
|
|
let availableLocales = chrome.getLocalesForPackage("browser");
|
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
let strings = Services.strings.createBundle("chrome://browser/content/languages.properties");
|
2009-09-22 07:21:15 -07:00
|
|
|
|
|
|
|
// Render locale menulist by iterating through the query result from getLocalesForPackage()
|
|
|
|
let selectedItem = null;
|
|
|
|
let localeCount = 0;
|
|
|
|
while (availableLocales.hasMore()) {
|
|
|
|
let locale = availableLocales.getNext();
|
|
|
|
try {
|
|
|
|
var label = strings.GetStringFromName(locale);
|
|
|
|
} catch (e) {
|
|
|
|
label = locale;
|
|
|
|
}
|
2010-03-26 08:11:03 -07:00
|
|
|
let item = this._languages.appendItem(label, locale);
|
2009-09-22 07:21:15 -07:00
|
|
|
if (locale == selectedLocale) {
|
|
|
|
this._currentLocale = locale;
|
|
|
|
selectedItem = item;
|
|
|
|
}
|
|
|
|
localeCount++;
|
|
|
|
}
|
2009-11-04 14:34:37 -08:00
|
|
|
|
|
|
|
// Are we using auto-detection?
|
|
|
|
let autoDetect = false;
|
|
|
|
try {
|
2010-07-13 07:36:09 -07:00
|
|
|
autoDetect = Services.prefs.getBoolPref("intl.locale.matchOS");
|
2009-11-04 14:34:37 -08:00
|
|
|
}
|
|
|
|
catch (e) {}
|
|
|
|
|
|
|
|
// Highlight current locale (or auto-detect entry)
|
2010-10-13 06:44:31 -07:00
|
|
|
if (autoDetect) {
|
2010-03-26 08:11:03 -07:00
|
|
|
this._languages.selectedItem = document.getElementById("prefs-languages-auto");
|
2010-10-13 06:44:31 -07:00
|
|
|
this._currentLocale = "auto";
|
|
|
|
} else {
|
2010-03-26 08:11:03 -07:00
|
|
|
this._languages.selectedItem = selectedItem;
|
2010-10-13 06:44:31 -07:00
|
|
|
}
|
2009-09-22 07:21:15 -07:00
|
|
|
|
|
|
|
// Hide the setting if we only have one locale
|
|
|
|
if (localeCount == 1)
|
|
|
|
document.getElementById("prefs-uilanguage").hidden = true;
|
|
|
|
},
|
2010-11-05 07:10:00 -07:00
|
|
|
|
2009-09-22 07:21:15 -07:00
|
|
|
updateLocale: function updateLocale() {
|
|
|
|
// Which locale did the user select?
|
2010-03-26 08:11:03 -07:00
|
|
|
let newLocale = this._languages.selectedItem.value;
|
2010-07-13 07:36:09 -07:00
|
|
|
let prefs = Services.prefs;
|
2010-10-13 06:44:31 -07:00
|
|
|
|
2009-09-22 07:21:15 -07:00
|
|
|
if (newLocale == "auto") {
|
2010-07-13 07:36:09 -07:00
|
|
|
if (prefs.prefHasUserValue("general.useragent.locale"))
|
|
|
|
prefs.clearUserPref("general.useragent.locale");
|
|
|
|
prefs.setBoolPref("intl.locale.matchOS", true);
|
2009-09-22 07:21:15 -07:00
|
|
|
} else {
|
2010-07-13 07:36:09 -07:00
|
|
|
prefs.setBoolPref("intl.locale.matchOS", false);
|
|
|
|
prefs.setCharPref("general.useragent.locale", newLocale);
|
2009-09-22 07:21:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Show the restart notification, if needed
|
|
|
|
if (this._currentLocale == newLocale)
|
|
|
|
this.hideRestart();
|
|
|
|
else
|
|
|
|
this.showRestart();
|
2010-03-26 08:11:03 -07:00
|
|
|
},
|
|
|
|
|
2010-03-30 10:27:03 -07:00
|
|
|
_showHomePageHint: function _showHomePageHint(aHint) {
|
|
|
|
if (aHint)
|
|
|
|
document.getElementById("prefs-homepage").setAttribute("desc", aHint);
|
|
|
|
else
|
|
|
|
document.getElementById("prefs-homepage").removeAttribute("desc");
|
|
|
|
},
|
|
|
|
|
2010-03-26 08:11:03 -07:00
|
|
|
_loadHomePage: function _loadHomePage() {
|
|
|
|
let url = Browser.getHomePage();
|
|
|
|
let value = "default";
|
|
|
|
let display = url;
|
2010-03-30 10:27:03 -07:00
|
|
|
try {
|
2010-07-13 07:36:09 -07:00
|
|
|
display = Services.prefs.getComplexValue("browser.startup.homepage.title", Ci.nsIPrefLocalizedString).data;
|
2010-03-30 10:27:03 -07:00
|
|
|
} catch (e) { }
|
2010-03-26 08:11:03 -07:00
|
|
|
|
|
|
|
switch (url) {
|
2010-08-31 12:49:40 -07:00
|
|
|
case "about:empty":
|
2010-03-26 08:11:03 -07:00
|
|
|
value = "none";
|
2010-03-30 10:27:03 -07:00
|
|
|
display = null;
|
2010-03-26 08:11:03 -07:00
|
|
|
break;
|
|
|
|
case "about:home":
|
|
|
|
value = "default";
|
2010-03-30 10:27:03 -07:00
|
|
|
display = null;
|
2010-03-26 08:11:03 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
value = "custom";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-03-30 10:27:03 -07:00
|
|
|
// Show or hide the title or URL of the custom homepage
|
|
|
|
this._showHomePageHint(display);
|
2010-11-05 07:10:00 -07:00
|
|
|
|
2010-03-30 10:27:03 -07:00
|
|
|
// Add the helper "Custom Page" item in the menulist, if needed
|
2010-03-26 08:11:03 -07:00
|
|
|
let options = document.getElementById("prefs-homepage-options");
|
|
|
|
if (value == "custom") {
|
|
|
|
// Make sure nothing is selected and just use a label to show the state
|
2011-01-03 12:07:41 -08:00
|
|
|
options.appendItem(Strings.browser.GetStringFromName("homepage.custom2"), "custom");
|
2010-03-26 08:11:03 -07:00
|
|
|
}
|
2010-03-30 10:27:03 -07:00
|
|
|
|
|
|
|
// Select the right menulist item
|
|
|
|
options.value = value;
|
2010-03-26 08:11:03 -07:00
|
|
|
},
|
|
|
|
|
2010-11-05 07:10:00 -07:00
|
|
|
updateHomePageList: function updateHomePageMenuList() {
|
|
|
|
// Update the "Use Current Page" item in the menulist by disabling it if
|
|
|
|
// the current page is already the user homepage
|
|
|
|
let currentUrl = Browser.selectedBrowser.currentURI.spec;
|
|
|
|
let currentHomepage = Browser.getHomePage();
|
|
|
|
let isHomepage = (currentHomepage == currentUrl);
|
|
|
|
let itemRow = document.getElementById("prefs-homepage-currentpage");
|
|
|
|
if (currentHomepage == "about:home") {
|
|
|
|
itemRow.disabled = isHomepage;
|
|
|
|
itemRow.hidden = false;
|
|
|
|
} else {
|
|
|
|
itemRow.hidden = isHomepage;
|
|
|
|
itemRow.disabled = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-03-26 08:11:03 -07:00
|
|
|
updateHomePage: function updateHomePage() {
|
|
|
|
let options = document.getElementById("prefs-homepage-options");
|
|
|
|
let value = options.selectedItem.value;
|
2010-03-30 10:27:03 -07:00
|
|
|
|
|
|
|
let url = "about:home";
|
|
|
|
let display = null;
|
2010-03-26 08:11:03 -07:00
|
|
|
|
|
|
|
switch (value) {
|
|
|
|
case "none":
|
2010-08-31 12:49:40 -07:00
|
|
|
url = "about:empty";
|
2010-03-26 08:11:03 -07:00
|
|
|
break;
|
|
|
|
case "default":
|
|
|
|
url = "about:home";
|
|
|
|
break;
|
2010-03-30 10:27:03 -07:00
|
|
|
case "currentpage":
|
2010-11-05 07:10:00 -07:00
|
|
|
// If the selected page is the about:home page, emulate the default case
|
|
|
|
let currentURL = Browser.selectedBrowser.currentURI.spec;
|
|
|
|
if (currentURL == "about:home") {
|
|
|
|
value = "default";
|
|
|
|
} else {
|
|
|
|
url = currentURL;
|
|
|
|
display = Browser.selectedBrowser.contentTitle || currentURL;
|
|
|
|
}
|
2010-03-26 08:11:03 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-03-30 10:27:03 -07:00
|
|
|
// Show or hide the title or URL of the custom homepage
|
|
|
|
this._showHomePageHint(display);
|
2010-03-26 08:11:03 -07:00
|
|
|
|
2010-03-30 10:27:03 -07:00
|
|
|
// Is the helper already in the list
|
|
|
|
let helper = null;
|
|
|
|
let items = options.menupopup.getElementsByAttribute("value", "custom");
|
|
|
|
if (items && items.length)
|
|
|
|
helper = items[0];
|
|
|
|
|
|
|
|
// Update the helper "Custom Page" item in the menulist
|
|
|
|
if (value == "currentpage") {
|
|
|
|
// If the helper item is not already in the list, we need to put it there
|
|
|
|
// (this can happen when changing from one custom page to another)
|
|
|
|
if (!helper)
|
2011-01-03 12:07:41 -08:00
|
|
|
helper = options.appendItem(Strings.browser.GetStringFromName("homepage.custom2"), "custom");
|
2010-03-30 10:27:03 -07:00
|
|
|
|
|
|
|
options.selectedItem = helper;
|
2010-11-05 07:10:00 -07:00
|
|
|
} else {
|
|
|
|
if (helper)
|
|
|
|
options.menupopup.removeChild(helper);
|
|
|
|
|
|
|
|
options.selectedItem = options.menupopup.getElementsByAttribute("value", value)[0];
|
2010-03-26 08:11:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save the homepage URL to a preference
|
|
|
|
let pls = Cc["@mozilla.org/pref-localizedstring;1"].createInstance(Ci.nsIPrefLocalizedString);
|
|
|
|
pls.data = url;
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.prefs.setComplexValue("browser.startup.homepage", Ci.nsIPrefLocalizedString, pls);
|
2010-03-30 10:27:03 -07:00
|
|
|
|
|
|
|
// Save the homepage title to a preference
|
|
|
|
pls.data = display;
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.prefs.setComplexValue("browser.startup.homepage.title", Ci.nsIPrefLocalizedString, pls);
|
2010-03-26 08:11:03 -07:00
|
|
|
}
|
2009-09-22 07:21:15 -07:00
|
|
|
};
|