Bug 490464 Update the download pref pane for use with toolkit download manager r=mcsmurf a=KaiRo

This commit is contained in:
Neil Rashbrook 2009-07-08 10:54:12 +01:00
Родитель 4b38708ec8
Коммит 7b4a1cf7f4
5 изменённых файлов: 210 добавлений и 105 удалений

Просмотреть файл

@ -84,7 +84,7 @@ pref("browser.toolbars.showbutton.search", true);
pref("browser.download.finished_download_sound", false);
pref("browser.download.finished_sound_url", "");
pref("browser.download.useDownloadDir", false);
pref("browser.download.folderList", 2);
pref("browser.download.folderList", 1);
pref("browser.download.manager.showAlertOnComplete", true);
pref("browser.download.manager.showAlertInterval", 2000);

Просмотреть файл

@ -38,68 +38,177 @@
*
* ***** END LICENSE BLOCK ***** */
const kDesktop = 0;
const kDownloads = 1;
const kUserDir = 2;
var gFPHandler;
function Startup()
{
var pAutoDL = document.getElementById("browser.download.autoDownload");
SetAutoDLEnabled(pAutoDL.value);
var pDLSound = document.getElementById("browser.download.finished_download_sound");
SetSoundEnabled(pDLSound.value);
// Define globals
gFPHandler = Components.classes["@mozilla.org/network/protocol;1?name=file"]
.getService(Components.interfaces.nsIFileProtocolHandler);
gFPHandler = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.getProtocolHandler("file")
.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
// if we don't have the alert service, hide the pref UI for using alerts to
// notify on download completion
// see bug #158711
/* XXX: sound is to be reintroduced with bug 490467
var downloadDoneNotificationAlertUI = document.getElementById("finishedNotificationAlert");
downloadDoneNotificationAlertUI.hidden = !("@mozilla.org/alerts-service;1" in Components.classes);
*/
}
function SetAutoDLEnabled(aEnable)
/**
* Enables/disables the folder field and Browse button based on whether a
* default download directory is being used.
*/
function ReadUseDownloadDir()
{
EnableElementById("downloadLocation", !aEnable, false);
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;
}
/**
* 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.
*/
function ChooseFolder()
{
const nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
var prefutilitiesBundle = document.getElementById("bundle_prefutilities");
var title = prefutilitiesBundle.getString("downloadfolder");
fp.init(window, title, nsIFilePicker.modeGetFolder);
fp.appendFilters(nsIFilePicker.filterAll);
var folderListPref = document.getElementById("browser.download.folderList");
fp.displayDirectory = IndexToFolder(folderListPref.value); // file
if (fp.show() == nsIFilePicker.returnOK) {
var currentDirPref = document.getElementById("browser.download.dir");
currentDirPref.value = fp.file;
folderListPref.value = FolderToIndex(fp.file);
// 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.
}
}
/**
* Initializes the download folder display settings based on the user's
* preferences.
*/
function DisplayDownloadDirPref()
{
var folderListPref = document.getElementById("browser.download.folderList");
var currentDirPref = IndexToFolder(folderListPref.value); // file
var prefutilitiesBundle = document.getElementById("bundle_prefutilities");
var iconUrlSpec = gFPHandler.getURLSpecFromFile(currentDirPref);
var downloadFolder = document.getElementById("downloadFolder");
downloadFolder.image = "moz-icon://" + iconUrlSpec + "?size=16";
// Display a 'pretty' label or the path in the UI.
switch (FolderToIndex(currentDirPref)) {
case kDesktop:
downloadFolder.label = prefutilitiesBundle.getString("desktopFolderName");
break;
case kDownloads:
downloadFolder.label = prefutilitiesBundle.getString("downloadsFolderName");
break;
default:
downloadFolder.label = currentDirPref ? currentDirPref.path : "";
break;
}
}
/**
* Returns the Desktop folder.
*/
function GetDesktopFolder()
{
return Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("Desk", Components.interfaces.nsILocalFile);
}
/**
* Returns the Downloads folder as determined by the XPCOM directory service
* via the download manager's attribute defaultDownloadsDirectory.
*/
function GetDownloadsFolder()
{
return Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager)
.defaultDownloadsDirectory;
}
/**
* Determines the type of the given folder.
*
* @param aFolder
* the folder whose type is to be determined
* @returns integer
* kDesktop if aFolder is the Desktop or is unspecified,
* kDownloads if aFolder is the Downloads folder,
* kUserDir otherwise
*/
function FolderToIndex(aFolder)
{
if (!aFolder || aFolder.equals(GetDesktopFolder()))
return kDesktop;
if (aFolder.equals(GetDownloadsFolder()))
return kDownloads;
return kUserDir;
}
/**
* Converts an integer into the corresponding folder.
*
* @param aIndex
* an integer
* @returns the Desktop folder if aIndex == kDesktop,
* the Downloads folder if aIndex == kDownloads,
* the folder stored in browser.download.dir
*/
function IndexToFolder(aIndex)
{
var folder;
switch (aIndex) {
default:
folder = document.getElementById("browser.download.dir").value;
if (folder && folder.exists())
return folder;
case kDownloads:
folder = GetDownloadsFolder();
if (folder && folder.exists())
return folder;
case kDesktop:
return GetDesktopFolder();
}
}
/* XXX: sound is to be reintroduced with bug 490467
function SetSoundEnabled(aEnable)
{
EnableElementById("downloadSndURL", aEnable, false);
document.getElementById("downloadSndPreview").disabled = !aEnable;
}
function ReadDLFolder(aField)
{
var file = document.getElementById("browser.download.dir").value;
if (file)
{
aField.file = file;
aField.label = (/Mac/.test(navigator.platform)) ? file.leafName : file.path;
}
}
function DownloadSelectFolder()
{
var pref = document.getElementById("browser.download.dir");
const nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
var prefutilitiesBundle = document.getElementById("bundle_prefutilities");
var title = prefutilitiesBundle.getString("downloadfolder");
fp.init(window, title, nsIFilePicker.modeGetFolder);
fp.displayDirectory = pref.value;
fp.appendFilters(nsIFilePicker.filterAll);
if (fp.show() == nsIFilePicker.returnOK)
pref.value = fp.file;
}
function BrowseSound()
{
var pref = document.getElementById("browser.download.finished_sound_url");
const nsIFilePicker = Components.interfaces.nsIFilePicker;
const nsILocalFile = Components.interfaces.nsILocalFile;
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
var prefutilitiesBundle = document.getElementById("bundle_prefutilities");
@ -144,3 +253,4 @@ function ReadSndFile(aField)
aField.label = (/Mac/.test(navigator.platform)) ? file.leafName : file.path;
}
}
*/

Просмотреть файл

@ -48,17 +48,24 @@
script="chrome://communicator/content/pref/pref-download.js">
<preferences>
<preference id="browser.downloadmanager.behavior"
name="browser.downloadmanager.behavior"
<preference id="browser.download.manager.focusWhenStarting"
name="browser.download.manager.focusWhenStarting"
type="bool" inverted="true"/>
<preference id="browser.download.manager.behavior"
name="browser.download.manager.behavior"
type="int"/>
<preference id="browser.download.autoDownload"
name="browser.download.autoDownload"
type="bool"
onchange="SetAutoDLEnabled(this.value);"/>
<preference id="browser.download.lastLocation"
name="browser.download.lastLocation"
<preference id="browser.download.useDownloadDir"
name="browser.download.useDownloadDir"
type="bool"/>
<preference id="browser.download.finished_download_sound"
<preference id="browser.download.dir"
name="browser.download.dir"
type="file"/>
<preference id="browser.download.folderList"
name="browser.download.folderList"
type="int"
onchange="DisplayDownloadDirPref();"/>
<!-- XXX: to be reintroduced with bug 490467
preference id="browser.download.finished_download_sound"
name="browser.download.finished_download_sound"
type="bool"
onchange="SetSoundEnabled(this.value);"/>
@ -67,16 +74,18 @@
type="bool"/>
<preference id="browser.download.finished_sound_url"
name="browser.download.finished_sound_url"
type="string"/>
<preference id="browser.download.dir"
name="browser.download.dir"
type="file"/>
type="string"/ -->
</preferences>
<groupbox>
<caption label="&downloadBehavior.label;"/>
<checkbox id="focusWhenStarting"
label="&focusWhenStarting.label;"
preference="browser.download.manager.focusWhenStarting"
accesskey="&focusWhenStarting.accesskey;"/>
<radiogroup id="downloadBehavior"
preference="browser.downloadmanager.behavior">
class="indent"
preference="browser.download.manager.behavior">
<radio value="0"
label="&openDM.label;"
accesskey="&openDM.accesskey;"/>
@ -91,57 +100,41 @@
<groupbox>
<caption label="&downloadLocation.label;"/>
<radiogroup id="autoDownload"
preference="browser.download.autoDownload">
<radio value="false"
label="&promptDownload.label;"
accesskey="&promptDownload.accesskey;"/>
<radiogroup id="downloadLocation"
class="indent"
preference="browser.download.lastLocation">
<radio value="true"
label="&lastLocation.label;"
accesskey="&lastLocation.accesskey;"/>
<radio value="false"
label="&specifiedLocation.label;"
accesskey="&specifiedLocation.accesskey;"/>
</radiogroup>
<radio value="true"
label="&autoDownload.label;"
accesskey="&autoDownload.accesskey;"/>
</radiogroup>
<separator class="thin"/>
<vbox>
<label value="&downloadFolder.label;"/>
<hbox align="center">
<filefield id="downloadFolder"
flex="1"
<radiogroup id="saveWhere"
preference="browser.download.useDownloadDir"
onsyncfrompreference="return document.getElementById('download_pane').ReadUseDownloadDir();">
<hbox id="saveToRow">
<radio id="saveTo" value="true"
label="&saveTo.label;"
accesskey="&saveTo.accesskey;"
aria-labelledby="saveTo downloadFolder"/>
<filefield id="downloadFolder" flex="1"
preference="browser.download.dir"
preference-editable="true"
onsyncfrompreference="return document.getElementById('download_pane').ReadDLFolder(this);"/>
<button id="chooseDownloadFolder"
aria-labelledby="saveTo"
onsyncfrompreference="document.getElementById('download_pane').DisplayDownloadDirPref();"/>
<button id="chooseFolder" oncommand="ChooseFolder();"
label="&chooseDownloadFolder.label;"
accesskey="&chooseDownloadFolder.accesskey;"
oncommand="DownloadSelectFolder();">
<observes element="downloadFolder" attribute="disabled"/>
</button>
accesskey="&chooseDownloadFolder.accesskey;"/>
</hbox>
</vbox>
<radio id="alwaysAsk" value="false"
label="&alwaysAsk.label;"
accesskey="&alwaysAsk.accesskey;"/>
</radiogroup>
</groupbox>
<groupbox>
<!-- XXX: to be reintroduced with bug 490467
groupbox>
<caption label="&finishedBehavior.label;"/>
<hbox align="center">
<checkbox id="finishedNotificationSound"
<checkbox id="finishedNotificationSound"
label="&playSound.label;"
preference="browser.download.finished_download_sound"
accesskey="&playSound.accesskey;"/>
<checkbox id="finishedNotificationAlert"
preference="browser.download.finished_download_sound"
accesskey="&playSound.accesskey;"/>
<checkbox id="finishedNotificationAlert"
label="&showAlert.label;"
preference="browser.download.finished_download_alert"
accesskey="&showAlert.accesskey;"/>
preference="browser.download.finished_download_alert"
accesskey="&showAlert.accesskey;"/>
</hbox>
<hbox align="center" class="indent">
@ -163,6 +156,6 @@
oncommand="PreviewSound();"/>
</hbox>
</hbox>
</groupbox>
</groupbox -->
</prefpane>
</overlay>

Просмотреть файл

@ -1,29 +1,29 @@
<!ENTITY pref.download.title "Downloads">
<!ENTITY downloadBehavior.label "When starting a download">
<!ENTITY downloadLocation.label "When saving a file">
<!ENTITY finishedBehavior.label "When a download completes">
<!ENTITY focusWhenStarting.label "Flash the download manager if it is already open, otherwise:">
<!ENTITY focusWhenStarting.accesskey "F">
<!ENTITY openDM.label "Open the download manager">
<!ENTITY openDM.accesskey "m">
<!ENTITY openProgressDialog.label "Open a progress dialog">
<!ENTITY openProgressDialog.accesskey "O">
<!ENTITY doNothing.label "Don't open anything">
<!ENTITY doNothing.accesskey "D">
<!ENTITY promptDownload.label "Prompt for download location and default to">
<!ENTITY promptDownload.accesskey "P">
<!ENTITY lastLocation.label "Last download folder">
<!ENTITY lastLocation.accesskey "L">
<!ENTITY specifiedLocation.label "Specified download folder">
<!ENTITY specifiedLocation.accesskey "e">
<!ENTITY autoDownload.label "Automatically download files to specified download folder">
<!ENTITY autoDownload.accesskey "A">
<!ENTITY downloadFolder.label "Current Download Folder:">
<!ENTITY downloadLocation.label "When saving a file">
<!ENTITY saveTo.label "Save files to">
<!ENTITY saveTo.accesskey "v">
<!ENTITY chooseDownloadFolder.label "Choose Folder…">
<!ENTITY chooseDownloadFolder.accesskey "C">
<!ENTITY alwaysAsk.label "Always ask me where to save files">
<!ENTITY alwaysAsk.accesskey "A">
<!ENTITY finishedBehavior.label "When a download completes">
<!ENTITY playSound.label "Play a sound">
<!ENTITY playSound.accesskey "s">
<!ENTITY showAlert.label "Show an alert">
<!ENTITY showAlert.accesskey "n">
<!ENTITY showAlert.accesskey "a">
<!ENTITY browse.label "Browse…">
<!ENTITY browse.accesskey "B">
<!ENTITY preview.label "Preview">
<!ENTITY preview.accesskey "v">
<!ENTITY preview.accesskey "e">

Просмотреть файл

@ -1,6 +1,8 @@
cachefolder=Choose Cache Folder
choosehomepage=Choose Home Page
downloadfolder=Choose a Download Folder
desktopFolderName=Desktop
downloadsFolderName=Downloads
choosesound=Choose a sound
SoundFiles=Sounds