1 # -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
15 # The Original Code is the Firefox Preferences System.
17 # The Initial Developer of the Original Code is
18 # Jeff Walden <jwalden+code@mit.edu>.
19 # Portions created by the Initial Developer are Copyright (C) 2006
20 # the Initial Developer. All Rights Reserved.
23 # Ben Goodger <ben@mozilla.org>
24 # Asaf Romano <mozilla.mano@sent.com>
25 # Ehsan Akhgari <ehsan.akhgari@gmail.com>
27 # Alternatively, the contents of this file may be used under the terms of
28 # either the GNU General Public License Version 2 or later (the "GPL"), or
29 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 # in which case the provisions of the GPL or the LGPL are applicable instead
31 # of those above. If you wish to allow use of your version of this file only
32 # under the terms of either the GPL or the LGPL, and not to allow others to
33 # use your version of this file under the terms of the MPL, indicate your
34 # decision by deleting the provisions above and replace them with the notice
35 # and other provisions required by the GPL or the LGPL. If you do not delete
36 # the provisions above, a recipient may use your version of this file under
37 # the terms of any one of the MPL, the GPL or the LGPL.
39 # ***** END LICENSE BLOCK *****
49 this._pane = document.getElementById(
"paneMain");
52 this._updateUseCurrentButton();
53 window.addEventListener(
"focus", this._updateUseCurrentButton,
false);
82 setHomePageToCurrent:
function ()
85 if (document.documentElement.instantApply) {
87 var
wm = Components.classes[
"@mozilla.org/appshell/window-mediator;1"]
88 .getService(Components.interfaces.nsIWindowMediator);
89 win = wm.getMostRecentWindow(
"Songbird:Main");
95 var homePage = document.getElementById(
"browser.startup.homepage");
96 var
browser = win.document.getElementById(
"content");
106 var newVal = browser.currentURI.spec;
108 homePage.value = newVal;
117 setHomePageToBookmark:
function ()
119 var rv = { urls:
null, names:
null };
120 document.documentElement.openSubDialog(
"chrome://browser/content/preferences/selectBookmark.xul",
122 if (rv.urls && rv.names) {
123 var homePage = document.getElementById(
"browser.startup.homepage");
126 homePage.value = rv.urls.join(
"|");
134 _updateUseCurrentButton:
function () {
135 var useCurrent = document.getElementById(
"useCurrent");
139 if (document.documentElement.instantApply) {
140 const Cc = Components.classes,
Ci = Components.interfaces;
142 var
wm =
Cc[
"@mozilla.org/appshell/window-mediator;1"]
143 .getService(
Ci.nsIWindowMediator);
144 win = wm.getMostRecentWindow(
"Songbird:Main");
149 if (win && win.document.documentElement
150 .getAttribute(
"windowtype") ==
"Songbird:Main") {
151 windowIsPresent =
true;
153 var
tabbrowser = win.document.getElementById(
"content");
159 useCurrent.label = useCurrent.getAttribute(
"label1");
162 windowIsPresent =
false;
163 useCurrent.label = useCurrent.getAttribute(
"label1");
167 if (document.getElementById
168 (
"pref.browser.homepage.disable_button.current_page").locked)
171 useCurrent.disabled = !windowIsPresent;
177 restoreDefaultHomePage:
function ()
179 var homePage = document.getElementById(
"browser.startup.homepage");
180 homePage.value = homePage.defaultValue;
226 readShowDownloadsWhenStarting:
function ()
228 this.showDownloadsWhenStartingPrefChanged();
238 showDownloadsWhenStartingPrefChanged:
function ()
240 var showWhenStartingPref = document.getElementById(
"browser.download.manager.showWhenStarting");
241 var closeWhenDonePref = document.getElementById(
"browser.download.manager.closeWhenDone");
242 closeWhenDonePref.disabled = !showWhenStartingPref.value;
249 readUseDownloadDir:
function ()
251 var downloadFolder = document.getElementById(
"downloadFolder");
252 var chooseFolder = document.getElementById(
"chooseFolder");
253 var preference = document.getElementById(
"browser.download.useDownloadDir");
254 downloadFolder.disabled = !preference.value;
255 chooseFolder.disabled = !preference.value;
266 chooseFolder:
function ()
269 const nsILocalFile = Components.interfaces.nsILocalFile;
271 var fp = Components.classes[
"@mozilla.org/filepicker;1"]
273 var bundlePreferences = document.getElementById(
"bundlePreferences");
274 var title = bundlePreferences.getString(
"chooseDownloadFolderTitle");
278 var folderListPref = document.getElementById(
"browser.download.folderList");
279 var currentDirPref = this._indexToFolder(folderListPref.value);
280 var defDownloads = this._indexToFolder(1);
283 if (currentDirPref && currentDirPref.exists()) {
284 fp.displayDirectory = currentDirPref;
286 else if (defDownloads && defDownloads.exists()) {
287 fp.displayDirectory = defDownloads;
290 fp.displayDirectory = this._indexToFolder(0);
294 var
file = fp.file.QueryInterface(nsILocalFile);
295 var currentDirPref = document.getElementById(
"browser.download.dir");
296 currentDirPref.value =
file;
297 var folderListPref = document.getElementById(
"browser.download.folderList");
298 folderListPref.value = this._folderToIndex(file);
310 displayDownloadDirPref:
function ()
312 var folderListPref = document.getElementById(
"browser.download.folderList");
313 var bundlePreferences = document.getElementById(
"bundlePreferences");
314 var downloadFolder = document.getElementById(
"downloadFolder");
315 var currentDirPref = document.getElementById(
"browser.download.dir");
322 var fileLocator = Components.classes[
"@mozilla.org/file/directory_service;1"]
323 .getService(Components.interfaces.nsIProperties);
324 var desk = fileLocator.get(
"Desk", Components.interfaces.nsILocalFile);
325 var dnldMgr = Components.classes[
"@mozilla.org/download-manager;1"]
326 .getService(Components.interfaces.nsIDownloadManager);
327 var supportDownloadLabel = !dnldMgr.defaultDownloadsDirectory.equals(desk);
330 var
ios = Components.classes[
"@mozilla.org/network/io-service;1"]
331 .getService(Components.interfaces.nsIIOService);
332 var fph = ios.getProtocolHandler(
"file")
333 .QueryInterface(Components.interfaces.nsIFileProtocolHandler);
337 if (folderListPref.value == 2) {
339 downloadFolder.label = this._getDisplayNameOfFile(currentDirPref.value);
340 iconUrlSpec = fph.getURLSpecFromFile(currentDirPref.value);
341 }
else if (folderListPref.value == 1 && supportDownloadLabel) {
352 downloadFolder.label = bundlePreferences.getString(
"downloadsFolderName");
353 iconUrlSpec = fph.getURLSpecFromFile(this._indexToFolder(1));
356 downloadFolder.label = bundlePreferences.getString(
"desktopFolderName");
357 iconUrlSpec = fph.getURLSpecFromFile(desk);
359 downloadFolder.image =
"moz-icon://" + iconUrlSpec +
"?size=16";
368 _getDisplayNameOfFile:
function (aFolder)
372 return aFolder ? aFolder.path :
"";
384 _getDownloadsFolder:
function (aFolder)
389 var fileLoc = Components.classes[
"@mozilla.org/file/directory_service;1"]
390 .getService(Components.interfaces.nsIProperties);
391 return fileLoc.get(
"Desk", Components.interfaces.nsILocalFile);
394 var dnldMgr = Components.classes[
"@mozilla.org/download-manager;1"]
395 .getService(Components.interfaces.nsIDownloadManager);
396 return dnldMgr.defaultDownloadsDirectory;
399 throw "ASSERTION FAILED: folder type should be 'Desktop' or 'Downloads'";
412 _folderToIndex:
function (aFolder)
414 if (!aFolder || aFolder.equals(
this._getDownloadsFolder(
"Desktop")))
416 else if (aFolder.equals(
this._getDownloadsFolder(
"Downloads")))
430 _indexToFolder:
function (aIndex)
434 return this._getDownloadsFolder(
"Desktop");
436 return this._getDownloadsFolder(
"Downloads");
438 var currentDirPref = document.getElementById(
"browser.download.dir");
439 return currentDirPref.value;
445 getFolderListPref:
function ()
447 var folderListPref = document.getElementById(
"browser.download.folderList");
448 switch(folderListPref.value) {
451 return folderListPref.value;
454 var currentDirPref = document.getElementById(
"browser.download.dir");
455 if (currentDirPref.value) {
458 return this._folderToIndex(currentDirPref.value);
468 showAddonsMgr:
function ()
470 const EMTYPE =
"Extension:Manager";
471 var
wm = Components.classes[
"@mozilla.org/appshell/window-mediator;1"]
472 .getService(Components.interfaces.nsIWindowMediator);
473 var theEM = wm.getMostRecentWindow(EMTYPE);
476 theEM.showView(
"extensions");
480 const EMURL =
"chrome://mozapps/content/extensions/extensions.xul";
481 const EMFEATURES =
"chrome,menubar,extra-chrome,toolbar,dialog=no,resizable";
482 window.openDialog(EMURL,
"", EMFEATURES,
"extensions");