2007-03-22 10:30:00 -07:00
|
|
|
# -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
# ***** 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 the Firefox Preferences System.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is
|
|
|
|
# Jeff Walden <jwalden+code@mit.edu>.
|
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
|
|
|
# Ben Goodger <ben@mozilla.org>
|
|
|
|
# Asaf Romano <mozilla.mano@sent.com>
|
2008-01-05 19:59:16 -08:00
|
|
|
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2007-03-22 10:30:00 -07:00
|
|
|
#
|
|
|
|
# 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 gMainPane = {
|
|
|
|
_pane: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialization of this.
|
|
|
|
*/
|
|
|
|
init: function ()
|
|
|
|
{
|
|
|
|
this._pane = document.getElementById("paneMain");
|
|
|
|
|
|
|
|
// set up the "use current page" label-changing listener
|
|
|
|
this._updateUseCurrentButton();
|
|
|
|
window.addEventListener("focus", this._updateUseCurrentButton, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
// HOME PAGE
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Preferences:
|
|
|
|
*
|
|
|
|
* browser.startup.homepage
|
|
|
|
* - the user's home page, as a string; if the home page is a set of tabs,
|
|
|
|
* this will be those URLs separated by the pipe character "|"
|
|
|
|
* browser.startup.page
|
|
|
|
* - what page(s) to show when the user starts the application, as an integer:
|
|
|
|
*
|
|
|
|
* 0: a blank page
|
|
|
|
* 1: the home page (as set by the browser.startup.homepage pref)
|
|
|
|
* 2: the last page the user visited (DEPRECATED)
|
|
|
|
* 3: windows and tabs from the last session (a.k.a. session restore)
|
|
|
|
*
|
|
|
|
* The deprecated option is not exposed in UI; however, if the user has it
|
|
|
|
* selected and doesn't change the UI for this preference, the deprecated
|
|
|
|
* option is preserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the home page to the current displayed page (or frontmost tab, if the
|
|
|
|
* most recent browser window contains multiple tabs), updating preference
|
|
|
|
* window UI to reflect this.
|
|
|
|
*/
|
|
|
|
setHomePageToCurrent: function ()
|
|
|
|
{
|
|
|
|
var win;
|
|
|
|
if (document.documentElement.instantApply) {
|
|
|
|
// If we're in instant-apply mode, use the most recent browser window
|
|
|
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
|
|
|
.getService(Components.interfaces.nsIWindowMediator);
|
|
|
|
win = wm.getMostRecentWindow("navigator:browser");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
win = window.opener;
|
|
|
|
|
|
|
|
if (win) {
|
|
|
|
var homePage = document.getElementById("browser.startup.homepage");
|
|
|
|
var browser = win.document.getElementById("content");
|
|
|
|
|
|
|
|
var newVal = browser.browsers[0].currentURI.spec;
|
|
|
|
if (browser.browsers.length > 1) {
|
|
|
|
// XXX using dangerous "|" joiner!
|
|
|
|
for (var i = 1; i < browser.browsers.length; i++)
|
|
|
|
newVal += "|" + browser.browsers[i].currentURI.spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
homePage.value = newVal;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a dialog in which the user can select a bookmark to use as home
|
|
|
|
* page. If the user selects a bookmark, that bookmark's name is displayed in
|
|
|
|
* UI and the bookmark's address is stored to the home page preference.
|
|
|
|
*/
|
|
|
|
setHomePageToBookmark: function ()
|
|
|
|
{
|
|
|
|
var rv = { urls: null, names: null };
|
|
|
|
document.documentElement.openSubDialog("chrome://browser/content/preferences/selectBookmark.xul",
|
|
|
|
"resizable", rv);
|
|
|
|
if (rv.urls && rv.names) {
|
|
|
|
var homePage = document.getElementById("browser.startup.homepage");
|
|
|
|
|
|
|
|
// XXX still using dangerous "|" joiner!
|
|
|
|
homePage.value = rv.urls.join("|");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switches the "Use Current Page" button between its singular and plural
|
|
|
|
* forms.
|
|
|
|
*/
|
|
|
|
_updateUseCurrentButton: function () {
|
|
|
|
var useCurrent = document.getElementById("useCurrent");
|
|
|
|
|
2008-02-12 11:19:26 -08:00
|
|
|
var windowIsPresent;
|
2007-03-22 10:30:00 -07:00
|
|
|
var win;
|
|
|
|
if (document.documentElement.instantApply) {
|
|
|
|
const Cc = Components.classes, Ci = Components.interfaces;
|
|
|
|
// If we're in instant-apply mode, use the most recent browser window
|
|
|
|
var wm = Cc["@mozilla.org/appshell/window-mediator;1"]
|
|
|
|
.getService(Ci.nsIWindowMediator);
|
|
|
|
win = wm.getMostRecentWindow("navigator:browser");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
win = window.opener;
|
|
|
|
|
|
|
|
if (win && win.document.documentElement
|
|
|
|
.getAttribute("windowtype") == "navigator:browser") {
|
2008-02-12 11:19:26 -08:00
|
|
|
windowIsPresent = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var tabbrowser = win.document.getElementById("content");
|
|
|
|
if (tabbrowser.browsers.length > 1)
|
|
|
|
useCurrent.label = useCurrent.getAttribute("label2");
|
|
|
|
else
|
|
|
|
useCurrent.label = useCurrent.getAttribute("label1");
|
|
|
|
}
|
|
|
|
else {
|
2008-02-12 11:19:26 -08:00
|
|
|
windowIsPresent = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
useCurrent.label = useCurrent.getAttribute("label1");
|
|
|
|
}
|
2008-02-12 11:19:26 -08:00
|
|
|
|
|
|
|
// In this case, the button's disabled state is set by preferences.xml.
|
|
|
|
if (document.getElementById
|
|
|
|
("pref.browser.homepage.disable_button.current_page").locked)
|
|
|
|
return;
|
|
|
|
|
|
|
|
useCurrent.disabled = !windowIsPresent;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores the default home page as the user's home page.
|
|
|
|
*/
|
|
|
|
restoreDefaultHomePage: function ()
|
|
|
|
{
|
|
|
|
var homePage = document.getElementById("browser.startup.homepage");
|
|
|
|
homePage.value = homePage.defaultValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
// DOWNLOADS
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Preferences:
|
|
|
|
*
|
2007-08-21 10:22:02 -07:00
|
|
|
* browser.download.showWhenStarting - bool
|
|
|
|
* True if the Download Manager should be opened when a download is
|
|
|
|
* started, false if it shouldn't be opened.
|
|
|
|
* browser.download.closeWhenDone - bool
|
|
|
|
* True if the Download Manager should be closed when all downloads
|
|
|
|
* complete, false if it should be left open.
|
|
|
|
* browser.download.useDownloadDir - bool
|
2007-09-04 09:21:34 -07:00
|
|
|
* True - Save files directly to the folder configured via the
|
|
|
|
* browser.download.folderList preference.
|
|
|
|
* False - Always ask the user where to save a file and default to
|
|
|
|
* browser.download.lastDir when displaying a folder picker dialog.
|
2007-08-28 11:59:49 -07:00
|
|
|
* browser.download.dir - local file handle
|
|
|
|
* A local folder the user may have selected for downloaded files to be
|
2007-08-21 10:22:02 -07:00
|
|
|
* saved. Migration of other browser settings may also set this path.
|
2007-08-28 11:59:49 -07:00
|
|
|
* This folder is enabled when folderList equals 2.
|
|
|
|
* browser.download.lastDir - local file handle
|
2007-08-21 10:22:02 -07:00
|
|
|
* May contain the last folder path accessed when the user browsed
|
|
|
|
* via the file save-as dialog. (see contentAreaUtils.js)
|
|
|
|
* browser.download.folderList - int
|
|
|
|
* Indicates the location users wish to save downloaded files too.
|
|
|
|
* It is also used to display special file labels when the default
|
|
|
|
* download location is either the Desktop or the Downloads folder.
|
|
|
|
* Values:
|
|
|
|
* 0 - The desktop is the default download location.
|
|
|
|
* 1 - The system's downloads folder is the default download location.
|
|
|
|
* 2 - The default download location is elsewhere as specified in
|
|
|
|
* browser.download.dir.
|
2007-03-22 10:30:00 -07:00
|
|
|
* browser.download.downloadDir
|
2007-08-21 10:22:02 -07:00
|
|
|
* depreciated.
|
2007-08-29 12:58:59 -07:00
|
|
|
* browser.download.defaultFolder
|
|
|
|
* depreciated.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates preferences which depend upon the value of the preference which
|
|
|
|
* determines whether the Downloads manager is opened at the start of a
|
|
|
|
* download.
|
|
|
|
*/
|
|
|
|
readShowDownloadsWhenStarting: function ()
|
|
|
|
{
|
|
|
|
this.showDownloadsWhenStartingPrefChanged();
|
|
|
|
|
|
|
|
// don't override the preference's value in UI
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables or disables the "close Downloads manager when downloads finished"
|
|
|
|
* preference element, consequently updating the associated UI.
|
|
|
|
*/
|
|
|
|
showDownloadsWhenStartingPrefChanged: function ()
|
|
|
|
{
|
|
|
|
var showWhenStartingPref = document.getElementById("browser.download.manager.showWhenStarting");
|
|
|
|
var closeWhenDonePref = document.getElementById("browser.download.manager.closeWhenDone");
|
|
|
|
closeWhenDonePref.disabled = !showWhenStartingPref.value;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables/disables the folder field and Browse button based on whether a
|
|
|
|
* default download directory is being used.
|
|
|
|
*/
|
|
|
|
readUseDownloadDir: function ()
|
|
|
|
{
|
|
|
|
var downloadFolder = document.getElementById("downloadFolder");
|
|
|
|
var chooseFolder = document.getElementById("chooseFolder");
|
|
|
|
var preference = document.getElementById("browser.download.useDownloadDir");
|
|
|
|
downloadFolder.disabled = !preference.value;
|
|
|
|
chooseFolder.disabled = !preference.value;
|
|
|
|
|
|
|
|
// don't override the preference's value in UI
|
|
|
|
return undefined;
|
|
|
|
},
|
2007-08-21 10:22:02 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Displays a file picker in which the user can choose the location where
|
|
|
|
* downloads are automatically saved, updating preferences and UI in
|
|
|
|
* response to the choice, if one is made.
|
|
|
|
*/
|
|
|
|
chooseFolder: function ()
|
|
|
|
{
|
|
|
|
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
2007-08-21 10:22:02 -07:00
|
|
|
const nsILocalFile = Components.interfaces.nsILocalFile;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
|
|
|
.createInstance(nsIFilePicker);
|
|
|
|
var bundlePreferences = document.getElementById("bundlePreferences");
|
|
|
|
var title = bundlePreferences.getString("chooseDownloadFolderTitle");
|
|
|
|
fp.init(window, title, nsIFilePicker.modeGetFolder);
|
|
|
|
fp.appendFilters(nsIFilePicker.filterAll);
|
2007-08-21 10:22:02 -07:00
|
|
|
|
|
|
|
var folderListPref = document.getElementById("browser.download.folderList");
|
|
|
|
var currentDirPref = this._indexToFolder(folderListPref.value); // file
|
|
|
|
var defDownloads = this._indexToFolder(1); // file
|
|
|
|
|
|
|
|
// First try to open what's currently configured
|
|
|
|
if (currentDirPref && currentDirPref.exists()) {
|
|
|
|
fp.displayDirectory = currentDirPref;
|
|
|
|
} // Try the system's download dir
|
|
|
|
else if (defDownloads && defDownloads.exists()) {
|
|
|
|
fp.displayDirectory = defDownloads;
|
|
|
|
} // Fall back to Desktop
|
|
|
|
else {
|
|
|
|
fp.displayDirectory = this._indexToFolder(0);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (fp.show() == nsIFilePicker.returnOK) {
|
|
|
|
var file = fp.file.QueryInterface(nsILocalFile);
|
2007-08-21 10:22:02 -07:00
|
|
|
var currentDirPref = document.getElementById("browser.download.dir");
|
|
|
|
currentDirPref.value = file;
|
2007-03-22 10:30:00 -07:00
|
|
|
var folderListPref = document.getElementById("browser.download.folderList");
|
|
|
|
folderListPref.value = this._folderToIndex(file);
|
2007-08-21 10:22:02 -07:00
|
|
|
// Note, the real prefs will not be updated yet, so dnld manager's
|
|
|
|
// userDownloadsDirectory may not return the right folder after
|
|
|
|
// this code executes. displayDownloadDirPref will be called on
|
|
|
|
// the assignment above to update the UI.
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-08-21 10:22:02 -07:00
|
|
|
* Initializes the download folder display settings based on the user's
|
2007-03-22 10:30:00 -07:00
|
|
|
* preferences.
|
|
|
|
*/
|
2007-08-21 10:22:02 -07:00
|
|
|
displayDownloadDirPref: function ()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
var folderListPref = document.getElementById("browser.download.folderList");
|
|
|
|
var bundlePreferences = document.getElementById("bundlePreferences");
|
|
|
|
var downloadFolder = document.getElementById("downloadFolder");
|
2007-08-21 10:22:02 -07:00
|
|
|
var currentDirPref = document.getElementById("browser.download.dir");
|
|
|
|
|
2007-08-29 12:58:59 -07:00
|
|
|
// The user's download folder is based on the preferences listed above.
|
|
|
|
// However, if the system does not support a download folder, the
|
|
|
|
// actual path returned will be the system's desktop or home folder.
|
|
|
|
// If this is the case, skip off displaying the Download label and
|
|
|
|
// display Desktop, even though folderList might be 1.
|
|
|
|
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
|
|
|
|
.getService(Components.interfaces.nsIProperties);
|
|
|
|
var desk = fileLocator.get("Desk", Components.interfaces.nsILocalFile);
|
|
|
|
var dnldMgr = Components.classes["@mozilla.org/download-manager;1"]
|
|
|
|
.getService(Components.interfaces.nsIDownloadManager);
|
|
|
|
var supportDownloadLabel = !dnldMgr.defaultDownloadsDirectory.equals(desk);
|
2007-08-21 10:22:02 -07:00
|
|
|
|
|
|
|
// Used in defining the correct path to the folder icon.
|
2007-03-22 10:30:00 -07:00
|
|
|
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
var fph = ios.getProtocolHandler("file")
|
|
|
|
.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
2007-08-21 10:22:02 -07:00
|
|
|
var iconUrlSpec;
|
|
|
|
|
|
|
|
// Display a 'pretty' label or the path in the UI.
|
|
|
|
if (folderListPref.value == 2) {
|
|
|
|
// Custom path selected and is configured
|
|
|
|
downloadFolder.label = this._getDisplayNameOfFile(currentDirPref.value);
|
|
|
|
iconUrlSpec = fph.getURLSpecFromFile(currentDirPref.value);
|
|
|
|
} else if (folderListPref.value == 1 && supportDownloadLabel) {
|
|
|
|
// 'Downloads'
|
|
|
|
// In 1.5, this pointed to a folder we created called 'My Downloads'
|
|
|
|
// and was available as an option in the 1.5 drop down. On XP this
|
|
|
|
// was in My Documents, on OSX it was in User Docs. In 2.0, we did
|
|
|
|
// away with the drop down option, although the special label was
|
|
|
|
// still supported for the folder if it existed. Because it was
|
|
|
|
// not exposed it was rarely used.
|
|
|
|
// With 3.0, a new desktop folder - 'Downloads' was introduced for
|
|
|
|
// platforms and versions that don't support a default system downloads
|
|
|
|
// folder. See nsDownloadManager for details.
|
|
|
|
downloadFolder.label = bundlePreferences.getString("downloadsFolderName");
|
|
|
|
iconUrlSpec = fph.getURLSpecFromFile(this._indexToFolder(1));
|
|
|
|
} else {
|
|
|
|
// 'Desktop'
|
|
|
|
downloadFolder.label = bundlePreferences.getString("desktopFolderName");
|
|
|
|
iconUrlSpec = fph.getURLSpecFromFile(desk);
|
|
|
|
}
|
|
|
|
downloadFolder.image = "moz-icon://" + iconUrlSpec + "?size=16";
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// don't override the preference's value in UI
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-08-21 10:22:02 -07:00
|
|
|
* Returns the textual path of a folder in readable form.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2007-08-21 10:22:02 -07:00
|
|
|
_getDisplayNameOfFile: function (aFolder)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-21 10:22:02 -07:00
|
|
|
// TODO: would like to add support for 'Downloads on Macintosh HD'
|
|
|
|
// for OS X users.
|
|
|
|
return aFolder ? aFolder.path : "";
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the Downloads folder. If aFolder is "Desktop", then the Downloads
|
|
|
|
* folder returned is the desktop folder; otherwise, it is a folder whose name
|
|
|
|
* indicates that it is a download folder and whose path is as determined by
|
2007-08-21 10:22:02 -07:00
|
|
|
* the XPCOM directory service via the download manager's attribute
|
|
|
|
* defaultDownloadsDirectory.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* @throws if aFolder is not "Desktop" or "Downloads"
|
|
|
|
*/
|
|
|
|
_getDownloadsFolder: function (aFolder)
|
|
|
|
{
|
2007-08-21 10:22:02 -07:00
|
|
|
switch(aFolder)
|
|
|
|
{
|
|
|
|
case "Desktop":
|
|
|
|
var fileLoc = Components.classes["@mozilla.org/file/directory_service;1"]
|
|
|
|
.getService(Components.interfaces.nsIProperties);
|
|
|
|
return fileLoc.get("Desk", Components.interfaces.nsILocalFile);
|
|
|
|
break;
|
|
|
|
case "Downloads":
|
|
|
|
var dnldMgr = Components.classes["@mozilla.org/download-manager;1"]
|
|
|
|
.getService(Components.interfaces.nsIDownloadManager);
|
|
|
|
return dnldMgr.defaultDownloadsDirectory;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
throw "ASSERTION FAILED: folder type should be 'Desktop' or 'Downloads'";
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-08-21 10:22:02 -07:00
|
|
|
* Determines the type of the given folder.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* @param aFolder
|
2007-08-21 10:22:02 -07:00
|
|
|
* the folder whose type is to be determined
|
|
|
|
* @returns integer
|
|
|
|
* 0 if aFolder is the Desktop or is unspecified,
|
|
|
|
* 1 if aFolder is the Downloads folder,
|
|
|
|
* 2 otherwise
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2007-08-21 10:22:02 -07:00
|
|
|
_folderToIndex: function (aFolder)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-21 10:22:02 -07:00
|
|
|
if (!aFolder || aFolder.equals(this._getDownloadsFolder("Desktop")))
|
|
|
|
return 0;
|
|
|
|
else if (aFolder.equals(this._getDownloadsFolder("Downloads")))
|
|
|
|
return 1;
|
|
|
|
return 2;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts an integer into the corresponding folder.
|
|
|
|
*
|
|
|
|
* @param aIndex
|
|
|
|
* an integer
|
|
|
|
* @returns the Desktop folder if aIndex == 0,
|
|
|
|
* the Downloads folder if aIndex == 1,
|
2007-08-21 10:22:02 -07:00
|
|
|
* the folder stored in browser.download.dir
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
_indexToFolder: function (aIndex)
|
|
|
|
{
|
|
|
|
switch (aIndex) {
|
|
|
|
case 0:
|
|
|
|
return this._getDownloadsFolder("Desktop");
|
|
|
|
case 1:
|
|
|
|
return this._getDownloadsFolder("Downloads");
|
|
|
|
}
|
2007-08-21 10:22:02 -07:00
|
|
|
var currentDirPref = document.getElementById("browser.download.dir");
|
|
|
|
return currentDirPref.value;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-08-21 10:22:02 -07:00
|
|
|
* Returns the value for the browser.download.folderList preference.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2007-08-21 10:22:02 -07:00
|
|
|
getFolderListPref: function ()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-21 10:22:02 -07:00
|
|
|
var folderListPref = document.getElementById("browser.download.folderList");
|
|
|
|
switch(folderListPref.value) {
|
|
|
|
case 0: // Desktop
|
|
|
|
case 1: // Downloads
|
|
|
|
return folderListPref.value;
|
|
|
|
break;
|
|
|
|
case 2: // Custom
|
|
|
|
var currentDirPref = document.getElementById("browser.download.dir");
|
|
|
|
if (currentDirPref.value) {
|
|
|
|
// Resolve to a known location if possible. We are writing out
|
|
|
|
// to prefs on this call, so now would be a good time to do it.
|
|
|
|
return this._folderToIndex(currentDirPref.value);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
2007-08-29 20:50:47 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the Add-ons Manager.
|
|
|
|
*/
|
|
|
|
showAddonsMgr: function ()
|
|
|
|
{
|
|
|
|
const EMTYPE = "Extension:Manager";
|
|
|
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
|
|
|
.getService(Components.interfaces.nsIWindowMediator);
|
|
|
|
var theEM = wm.getMostRecentWindow(EMTYPE);
|
|
|
|
if (theEM) {
|
|
|
|
theEM.focus();
|
2008-01-05 19:59:16 -08:00
|
|
|
theEM.showView("extensions");
|
2007-08-29 20:50:47 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const EMURL = "chrome://mozapps/content/extensions/extensions.xul";
|
|
|
|
const EMFEATURES = "chrome,menubar,extra-chrome,toolbar,dialog=no,resizable";
|
2008-01-05 19:59:16 -08:00
|
|
|
window.openDialog(EMURL, "", EMFEATURES, "extensions");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|