Bug 665603 - Centralise sound preferences r=mnyromyr
This commit is contained in:
Родитель
f5eda416e4
Коммит
260c4bfcc3
|
@ -42,13 +42,14 @@ const kDesktop = 0;
|
|||
const kDownloads = 1;
|
||||
const kUserDir = 2;
|
||||
var gFPHandler;
|
||||
var gSoundUrlPref;
|
||||
|
||||
function Startup()
|
||||
{
|
||||
// Define globals
|
||||
gFPHandler = Services.io.getProtocolHandler("file")
|
||||
.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
|
||||
|
||||
gSoundUrlPref = document.getElementById("browser.download.finished_sound_url");
|
||||
SetSoundEnabled(document.getElementById("browser.download.finished_download_sound").value);
|
||||
|
||||
// if we don't have the alert service, hide the pref UI for using alerts to
|
||||
|
@ -189,54 +190,3 @@ function SetSoundEnabled(aEnable)
|
|||
EnableElementById("downloadSndURL", aEnable, false);
|
||||
document.getElementById("downloadSndPlay").disabled = !aEnable;
|
||||
}
|
||||
|
||||
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");
|
||||
var title = prefutilitiesBundle.getString("choosesound");
|
||||
fp.init(window, title, nsIFilePicker.modeOpen);
|
||||
|
||||
if (pref.value)
|
||||
fp.displayDirectory = gFPHandler.getFileFromURLSpec(pref.value)
|
||||
.parent.QueryInterface(nsILocalFile);
|
||||
|
||||
var ftype = prefutilitiesBundle.getString("SoundFiles");
|
||||
fp.appendFilter(ftype, "*.wav; *.wave");
|
||||
fp.appendFilters(nsIFilePicker.filterAll);
|
||||
|
||||
if (fp.show() == nsIFilePicker.returnOK)
|
||||
pref.value = fp.fileURL.spec;
|
||||
}
|
||||
|
||||
function PlaySound()
|
||||
{
|
||||
var pref = document.getElementById("browser.download.finished_sound_url");
|
||||
var sound = Components.classes["@mozilla.org/sound;1"]
|
||||
.createInstance(Components.interfaces.nsISound);
|
||||
|
||||
if (pref.value)
|
||||
{
|
||||
var ioservice = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
sound.play(ioservice.newURI(pref.value, null, null));
|
||||
}
|
||||
else
|
||||
sound.beep();
|
||||
}
|
||||
|
||||
function ReadSndFile(aField)
|
||||
{
|
||||
var pref = document.getElementById("browser.download.finished_sound_url");
|
||||
if (pref.value)
|
||||
{
|
||||
var file = gFPHandler.getFileFromURLSpec(pref.value);
|
||||
aField.file = file;
|
||||
aField.label = (/Mac/.test(navigator.platform)) ? file.leafName : file.path;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,18 +164,18 @@
|
|||
flex="1"
|
||||
preference="browser.download.finished_sound_url"
|
||||
preference-editable="true"
|
||||
onsyncfrompreference="return document.getElementById('download_pane').ReadSndFile(this);"/>
|
||||
onsyncfrompreference="return WriteSoundField(this, document.getElementById('download_pane').gSoundUrlPref.value);"/>
|
||||
<hbox align="center">
|
||||
<button id="downloadSndBrowse"
|
||||
label="&browse.label;"
|
||||
accesskey="&browse.accesskey;"
|
||||
oncommand="BrowseSound();">
|
||||
oncommand="SelectSound(gSoundUrlPref);">
|
||||
<observes element="downloadSndURL" attribute="disabled"/>
|
||||
</button>
|
||||
<button id="downloadSndPlay"
|
||||
label="&playButton.label;"
|
||||
accesskey="&playButton.accesskey;"
|
||||
oncommand="PlaySound();"/>
|
||||
oncommand="PlaySound(gSoundUrlPref.value, false);"/>
|
||||
</hbox>
|
||||
</hbox>
|
||||
</groupbox>
|
||||
|
|
|
@ -35,23 +35,11 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const nsIFileProtocolHandler = Components.interfaces.nsIFileProtocolHandler;
|
||||
|
||||
var gSoundUrlPref;
|
||||
var gSelectSound;
|
||||
|
||||
var gIOService;
|
||||
var gFileHandler;
|
||||
|
||||
function Startup()
|
||||
{
|
||||
gSoundUrlPref = document.getElementById("privacy.popups.sound_url");
|
||||
gSelectSound = document.getElementById("selectSound");
|
||||
|
||||
gIOService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
gFileHandler = gIOService.getProtocolHandler("file")
|
||||
.QueryInterface(nsIFileProtocolHandler);
|
||||
|
||||
SetLists();
|
||||
|
||||
|
@ -141,45 +129,6 @@ function EnableSoundRadio(aSoundChecked)
|
|||
function EnableSoundUrl(aCustomSelected)
|
||||
{
|
||||
EnableElementById("playSoundUrl", aCustomSelected, false);
|
||||
EnableElement(gSelectSound, aCustomSelected, false);
|
||||
EnableElementById("selectSound", aCustomSelected, false);
|
||||
EnableElementById("playSoundButton", aCustomSelected, false);
|
||||
}
|
||||
|
||||
function ReadSoundLocation(aElement)
|
||||
{
|
||||
aElement.value = gSoundUrlPref.value;
|
||||
if (aElement.value)
|
||||
aElement.file = gFileHandler.getFileFromURLSpec(aElement.value);
|
||||
}
|
||||
|
||||
function SelectSound()
|
||||
{
|
||||
const nsILocalFile = Components.interfaces.nsILocalFile;
|
||||
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||
var filepicker = Components.classes["@mozilla.org/filepicker;1"]
|
||||
.createInstance(nsIFilePicker);
|
||||
|
||||
filepicker.init(window,
|
||||
gSelectSound.getAttribute("filepickertitle"),
|
||||
nsIFilePicker.modeOpen);
|
||||
if (gSoundUrlPref.value)
|
||||
filepicker.displayDirectory = gFileHandler.getFileFromURLSpec(gSoundUrlPref.value).parent;
|
||||
|
||||
filepicker.appendFilter(gSelectSound.getAttribute("filepickerfilter"),
|
||||
"*.wav; *.wave");
|
||||
filepicker.appendFilters(nsIFilePicker.filterAll);
|
||||
|
||||
if (filepicker.show() == nsIFilePicker.returnOK)
|
||||
gSoundUrlPref.value = filepicker.fileURL.spec;
|
||||
}
|
||||
|
||||
function PlaySound()
|
||||
{
|
||||
var soundUrl = gSoundUrlPref.value;
|
||||
var sound = Components.classes["@mozilla.org/sound;1"]
|
||||
.createInstance(Components.interfaces.nsISound);
|
||||
if (soundUrl)
|
||||
sound.play(gIOService.newURI(soundUrl, null, null));
|
||||
else
|
||||
sound.beep();
|
||||
}
|
||||
|
|
|
@ -135,20 +135,18 @@
|
|||
flex="1"
|
||||
preference="privacy.popups.sound_url"
|
||||
preference-editable="true"
|
||||
onsyncfrompreference="return document.getElementById('popups_pane').ReadSoundLocation(this);"
|
||||
onsyncfrompreference="return WriteSoundField(this, document.getElementById('popups_pane').gSoundUrlPref.value);"
|
||||
aria-labelledby="popupCustomSound"/>
|
||||
<button id="selectSound"
|
||||
label="&selectSound.label;"
|
||||
accesskey="&selectSound.accesskey;"
|
||||
preference="pref.advanced.popups.disable_button.select_sound"
|
||||
filepickertitle="&selectSound.title;"
|
||||
filepickerfilter="&selectSound.filter;"
|
||||
oncommand="SelectSound();"/>
|
||||
oncommand="SelectSound(gSoundUrlPref);"/>
|
||||
<button id="playSoundButton"
|
||||
label="&playSoundButton.label;"
|
||||
accesskey="&playSoundButton.accesskey;"
|
||||
preference="pref.advanced.popups.disable_button.preview_sound"
|
||||
oncommand="PlaySound();"/>
|
||||
oncommand="PlaySound(gSoundUrlPref.value, false);"/>
|
||||
</hbox>
|
||||
<hbox>
|
||||
<checkbox id="displayIcon"
|
||||
|
|
|
@ -54,3 +54,51 @@ function EnableElement(aElement, aEnable, aFocus)
|
|||
if (enabled && aFocus)
|
||||
aElement.focus();
|
||||
}
|
||||
|
||||
function WriteSoundField(aField, aValue)
|
||||
{
|
||||
var file = GetFileFromString(aValue);
|
||||
if (file)
|
||||
{
|
||||
aField.file = file;
|
||||
aField.label = (/Mac/.test(navigator.platform)) ? file.leafName : file.path;
|
||||
}
|
||||
}
|
||||
|
||||
function SelectSound(aSoundUrlPref)
|
||||
{
|
||||
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
||||
.createInstance(nsIFilePicker);
|
||||
var prefutilitiesBundle = document.getElementById("bundle_prefutilities");
|
||||
fp.init(window, prefutilitiesBundle.getString("choosesound"),
|
||||
nsIFilePicker.modeOpen);
|
||||
|
||||
var file = GetFileFromString(aSoundUrlPref.value);
|
||||
if (file && file.parent && file.parent.exists())
|
||||
fp.displayDirectory = file.parent;
|
||||
|
||||
var filterExts = "*.wav; *.wave";
|
||||
// On Mac, allow AIFF files too.
|
||||
if (/Mac/.test(navigator.platform))
|
||||
filterExts += "; *.aif; *.aiff";
|
||||
fp.appendFilter(prefutilitiesBundle.getString("SoundFiles"), filterExts);
|
||||
fp.appendFilters(nsIFilePicker.filterAll);
|
||||
|
||||
if (fp.show() == nsIFilePicker.returnOK)
|
||||
aSoundUrlPref.value = fp.fileURL.spec;
|
||||
}
|
||||
|
||||
function PlaySound(aValue, aMail)
|
||||
{
|
||||
const nsISound = Components.interfaces.nsISound;
|
||||
var sound = Components.classes["@mozilla.org/sound;1"]
|
||||
.createInstance(nsISound);
|
||||
|
||||
if (aValue)
|
||||
sound.play(Services.io.newURI(aValue, null, null));
|
||||
else if (aMail && !/Mac/.test(navigator.platform))
|
||||
sound.playEventSound(nsISound.EVENT_NEW_MAIL_RECEIVED);
|
||||
else
|
||||
sound.beep();
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
<!ENTITY selectSound.accesskey "o">
|
||||
<!ENTITY playSoundButton.label "Play">
|
||||
<!ENTITY playSoundButton.accesskey "l">
|
||||
<!ENTITY selectSound.title "Select Popup Block Sound">
|
||||
<!ENTITY selectSound.filter "Sounds">
|
||||
|
||||
<!ENTITY displayIcon.label "Display an icon in the browser status bar">
|
||||
<!ENTITY displayIcon.accesskey "D">
|
||||
|
|
|
@ -38,11 +38,7 @@
|
|||
// The contents of this file will be loaded into the scope of the object
|
||||
// <prefpane id="notifications_pane">!
|
||||
|
||||
const nsIFileProtocolHandler = Components.interfaces.nsIFileProtocolHandler;
|
||||
|
||||
var gSound = null;
|
||||
var gSoundUrlPref = null;
|
||||
var gFileHandler = null;
|
||||
|
||||
function Startup()
|
||||
{
|
||||
|
@ -56,8 +52,6 @@ function Startup()
|
|||
var newMailNotificationTrayIconPref = document.getElementById("newMailNotificationTrayIcon");
|
||||
newMailNotificationTrayIconPref.hidden = !/^Win/.test(navigator.platform);
|
||||
|
||||
gFileHandler = Services.io.getProtocolHandler("file")
|
||||
.QueryInterface(nsIFileProtocolHandler);
|
||||
gSoundUrlPref = document.getElementById("mail.biff.play_sound.url");
|
||||
|
||||
PlaySoundCheck(document.getElementById("mail.biff.play_sound").value);
|
||||
|
@ -75,45 +69,3 @@ function EnableSoundURL(aEnable)
|
|||
{
|
||||
EnableElementById("mailnewsSoundFileUrl", aEnable, false);
|
||||
}
|
||||
|
||||
function SelectSound()
|
||||
{
|
||||
var prefBundle = document.getElementById("bundle_prefutilities");
|
||||
|
||||
var nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
||||
.createInstance(nsIFilePicker);
|
||||
|
||||
fp.init(window, prefBundle.getString("choosesound"), nsIFilePicker.modeOpen);
|
||||
|
||||
if (gSoundUrlPref.value != "")
|
||||
fp.displayDirectory = gFileHandler.getFileFromURLSpec(gSoundUrlPref.value).parent;
|
||||
|
||||
fp.appendFilter(prefBundle.getString("SoundFiles"), "*.wav; *.wave");
|
||||
fp.appendFilters(nsIFilePicker.filterAll);
|
||||
|
||||
if (fp.show() == nsIFilePicker.returnOK)
|
||||
gSoundUrlPref.value = fp.fileURL.spec;
|
||||
}
|
||||
|
||||
function ReadSoundLocation(aElement)
|
||||
{
|
||||
aElement.value = gSoundUrlPref.value;
|
||||
if (aElement.value)
|
||||
aElement.file = gFileHandler.getFileFromURLSpec(aElement.value);
|
||||
}
|
||||
|
||||
function PlaySound()
|
||||
{
|
||||
const nsISound = Components.interfaces.nsISound;
|
||||
if (!gSound)
|
||||
gSound = Components.classes["@mozilla.org/sound;1"]
|
||||
.createInstance(nsISound);
|
||||
var soundURL = gSoundUrlPref.value;
|
||||
if (soundURL)
|
||||
gSound.play(Services.io.newURI(soundURL, null, null));
|
||||
else if (/Mac/.test(navigator.platform))
|
||||
gSound.beep();
|
||||
else
|
||||
gSound.playEventSound(nsISound.EVENT_NEW_MAIL_RECEIVED);
|
||||
}
|
||||
|
|
|
@ -120,20 +120,20 @@
|
|||
flex="1"
|
||||
preference="mail.biff.play_sound.url"
|
||||
preference-editable="true"
|
||||
onsyncfrompreference="return document.getElementById('notifications_pane').ReadSoundLocation(this);"
|
||||
onsyncfrompreference="return WriteSoundField(this, document.getElementById('notifications_pane').gSoundUrlPref.value);"
|
||||
aria-labelledby="custom"/>
|
||||
<hbox align="center">
|
||||
<button id="browse"
|
||||
label="&browse.label;"
|
||||
filepickertitle="&browse.title;"
|
||||
accesskey="&browse.accesskey;"
|
||||
oncommand="SelectSound();">
|
||||
oncommand="SelectSound(gSoundUrlPref);">
|
||||
<observes element="mailnewsSoundFileUrl" attribute="disabled"/>
|
||||
</button>
|
||||
<button id="playButton"
|
||||
label="&playButton.label;"
|
||||
accesskey="&playButton.accesskey;"
|
||||
oncommand="PlaySound();">
|
||||
oncommand="PlaySound(gSoundUrlPref.value, true);">
|
||||
<observes element="mailnewsSoundFileUrl" attribute="disabled"/>
|
||||
</button>
|
||||
</hbox>
|
||||
|
|
Загрузка…
Ссылка в новой задаче