Bug 260818 Pop up an alert when a download finishes

patch by cst@andrew.cmu.edu r=timeless sr=jag
This commit is contained in:
timeless%mozdev.org 2006-05-17 02:39:16 +00:00
Родитель eed1414396
Коммит a035c0e29d
3 изменённых файлов: 55 добавлений и 18 удалений

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

@ -2,23 +2,21 @@ function Startup()
{
PlaySoundCheck();
// if we don't have the alert service, hide the pref UI for using alerts to notify on new mail
// if we don't have the alert service, hide the pref UI for using alerts to notify on download completion
// see bug #158711
var newMailNotificationAlertUI = document.getElementById("newMailNotificationAlert");
newMailNotificationAlertUI.hidden = !("@mozilla.org/alerts-service;1" in Components.classes);
var downloadDoneNotificationAlertUI = document.getElementById("finishedNotificationAlert");
downloadDoneNotificationAlertUI.hidden = !("@mozilla.org/alerts-service;1" in Components.classes);
}
function PlaySoundCheck()
{
var playSound = document.getElementById("newMailNotification").checked;
var playSoundType = document.getElementById("newMailNotificationType");
playSoundType.disabled = !playSound;
var playSound = document.getElementById("finishedNotificationSound").checked;
var disableCustomUI = !(playSound && playSoundType.value == 1);
var mailnewsSoundFileUrl = document.getElementById("mailnewsSoundFileUrl");
var disableCustomUI = !playSound;
var finishedSoundUrl = document.getElementById("finishedSoundUrl");
mailnewsSoundFileUrl.disabled = disableCustomUI
document.getElementById("preview").disabled = disableCustomUI || (mailnewsSoundFileUrl.value == "");
finishedSoundUrl.disabled = disableCustomUI;
document.getElementById("preview").disabled = disableCustomUI || (finishedSoundUrl.value == "");
document.getElementById("browse").disabled = disableCustomUI;
}
@ -27,7 +25,7 @@ const nsIFilePicker = Components.interfaces.nsIFilePicker;
function Browse()
{
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
.createInstance(nsIFilePicker);
// XXX todo, persist the last sound directory and pass it in
// XXX todo filter by .wav
@ -36,19 +34,20 @@ function Browse()
var ret = fp.show();
if (ret == nsIFilePicker.returnOK) {
var mailnewsSoundFileUrl = document.getElementById("mailnewsSoundFileUrl");
var soundUrl = document.getElementById("finishedSoundUrl");
// convert the nsILocalFile into a nsIFile url
mailnewsSoundFileUrl.value = fp.fileURL.spec;
soundUrl.value = fp.fileURL.spec;
}
document.getElementById("preview").disabled = (document.getElementById("mailnewsSoundFileUrl").value == "");
document.getElementById("preview").disabled =
(document.getElementById("finishedSoundUrl").value == "");
}
var gSound = null;
function PreviewSound()
{
var soundURL = document.getElementById("mailnewsSoundFileUrl").value;
var soundURL = document.getElementById("finishedSoundUrl").value;
if (!gSound)
gSound = Components.classes["@mozilla.org/sound;1"].createInstance(Components.interfaces.nsISound);
@ -60,7 +59,7 @@ function PreviewSound()
}
else {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
.getService(Components.interfaces.nsIIOService);
var url = ioService.newURI(soundURL, null, null);
gSound.play(url)
}

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

@ -45,12 +45,14 @@
onload="parent.initPanel('chrome://communicator/content/pref/pref-download.xul');"
headertitle="&lHeader;">
<script type="application/x-javascript" src="chrome://communicator/content/pref/pref-download.js"/>
<script type="application/x-javascript">
<![CDATA[
var _elementIDs = ["downloadBehavior"];
var _elementIDs = ["downloadBehavior", "finishedNotificationAlert",
"finishedNotificationSound", "finishedSoundUrl"];
]]>
</script>browser.downloadmanager.behavior
<groupbox>
<caption label="&downloadBehavior.label;"/>
<radiogroup id="downloadBehavior" prefstring="browser.downloadmanager.behavior">
@ -58,7 +60,31 @@
<radio value="1" label="&openProgressDialog.label;" accesskey="&openProgressDialog.accesskey;"/>
<radio value="2" label="&doNothing.label;" accesskey="&doNothing.accesskey;"/>
</radiogroup>
</groupbox>
<groupbox>
<caption label="&finishedBehavior.label;"/>
<vbox align="start">
<checkbox id="finishedNotificationAlert" label="&showAlert.label;"
prefstring="browser.download.finished_download_alert"
accesskey="&showAlert.accesskey;"/>
<checkbox id="finishedNotificationSound" label="&playSound.label;"
prefstring="browser.download.finished_download_sound"
accesskey="&playSound.accesskey;"
oncommand="PlaySoundCheck()"/>
</vbox>
<hbox align="center" class="indent">
<textbox readonly="true" flex="1" id="finishedSoundUrl" preftype="string"
prefstring="browser.download.finished_sound_url"/>
<hbox align="center">
<button id="browse" label="&browse.label;" filepickertitle="&browse.title;"
accesskey="&browse.accesskey;" oncommand="Browse()"/>
<button id="preview" label="&preview.label;"
accesskey="&preview.accesskey;" oncommand="PreviewSound()"/>
</hbox>
</hbox>
</groupbox>
</page>

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

@ -1,8 +1,20 @@
<!ENTITY lHeader "Downloads">
<!ENTITY downloadBehavior.label "When starting a download">
<!ENTITY finishedBehavior.label "When a download completes">
<!ENTITY openDM.label "Open the download manager">
<!ENTITY openDM.accesskey "m">
<!ENTITY openProgressDialog.label "Open a progress dialog">
<!ENTITY openProgressDialog.accesskey "p">
<!ENTITY doNothing.label "Don't open anything">
<!ENTITY doNothing.accesskey "D">
<!ENTITY playSound.label "Play a sound">
<!ENTITY playSound.accesskey "S">
<!ENTITY showAlert.label "Show an alert">
<!ENTITY showAlert.accesskey "A">
<!ENTITY browse.label "Browse...">
<!ENTITY browse.accesskey "B">
<!ENTITY browse.title "Choose a sound">
<!ENTITY preview.label "Preview">
<!ENTITY preview.accesskey "v">
<!ENTITY soundURL.label "Sound URL:">
<!ENTITY soundURL.accesskey "U">