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_download_sound", false);
pref("browser.download.finished_sound_url", ""); pref("browser.download.finished_sound_url", "");
pref("browser.download.useDownloadDir", false); 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.showAlertOnComplete", true);
pref("browser.download.manager.showAlertInterval", 2000); pref("browser.download.manager.showAlertInterval", 2000);

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

@ -38,68 +38,177 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
const kDesktop = 0;
const kDownloads = 1;
const kUserDir = 2;
var gFPHandler; var gFPHandler;
function Startup() 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 // Define globals
gFPHandler = Components.classes["@mozilla.org/network/protocol;1?name=file"] gFPHandler = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIFileProtocolHandler); .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 // if we don't have the alert service, hide the pref UI for using alerts to
// notify on download completion // notify on download completion
// see bug #158711 // see bug #158711
/* XXX: sound is to be reintroduced with bug 490467
var downloadDoneNotificationAlertUI = document.getElementById("finishedNotificationAlert"); var downloadDoneNotificationAlertUI = document.getElementById("finishedNotificationAlert");
downloadDoneNotificationAlertUI.hidden = !("@mozilla.org/alerts-service;1" in Components.classes); 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) function SetSoundEnabled(aEnable)
{ {
EnableElementById("downloadSndURL", aEnable, false); EnableElementById("downloadSndURL", aEnable, false);
document.getElementById("downloadSndPreview").disabled = !aEnable; 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() function BrowseSound()
{ {
var pref = document.getElementById("browser.download.finished_sound_url"); var pref = document.getElementById("browser.download.finished_sound_url");
const nsIFilePicker = Components.interfaces.nsIFilePicker; const nsIFilePicker = Components.interfaces.nsIFilePicker;
const nsILocalFile = Components.interfaces.nsILocalFile;
var fp = Components.classes["@mozilla.org/filepicker;1"] var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker); .createInstance(nsIFilePicker);
var prefutilitiesBundle = document.getElementById("bundle_prefutilities"); var prefutilitiesBundle = document.getElementById("bundle_prefutilities");
@ -144,3 +253,4 @@ function ReadSndFile(aField)
aField.label = (/Mac/.test(navigator.platform)) ? file.leafName : file.path; aField.label = (/Mac/.test(navigator.platform)) ? file.leafName : file.path;
} }
} }
*/

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

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

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

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

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

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