mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 21:00:50 +00:00
Bug 463209 No sound when message box is opened (alert/confirm/prompt/etc...) r+sr=roc, ui-jboriss, a=beltzner
This commit is contained in:
parent
a03e3f42a1
commit
e0b35ba86e
@ -50,7 +50,7 @@ interface nsPIPromptService : nsISupports
|
||||
enum {eMsg=0, eCheckboxMsg=1, eIconClass=2, eTitleMessage=3, eEditfield1Msg=4,
|
||||
eEditfield2Msg=5, eEditfield1Value=6, eEditfield2Value=7,
|
||||
eButton0Text=8, eButton1Text=9, eButton2Text=10, eButton3Text=11,
|
||||
eDialogTitle=12};
|
||||
eDialogTitle=12, eOpeningSound=13};
|
||||
enum {eButtonPressed=0, eCheckboxState=1, eNumberButtons=2,
|
||||
eNumberEditfields=3, eEditField1Password=4, eDefaultButton=5,
|
||||
eDelayButtonEnable=6};
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include "nsString.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsISound.h"
|
||||
|
||||
static const char kPromptURL[] = "chrome://global/content/commonDialog.xul";
|
||||
static const char kSelectPromptURL[] = "chrome://global/content/selectDialog.xul";
|
||||
@ -139,6 +140,7 @@ nsPromptService::Alert(nsIDOMWindow *parent,
|
||||
nsString url;
|
||||
NS_ConvertASCIItoUTF16 styleClass(kAlertIconClass);
|
||||
block->SetString(eIconClass, styleClass.get());
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_WARNING_DIALOG.get());
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
|
||||
@ -183,6 +185,7 @@ nsPromptService::AlertCheck(nsIDOMWindow *parent,
|
||||
block->SetString(eIconClass, styleClass.get());
|
||||
block->SetString(eCheckboxMsg, checkMsg);
|
||||
block->SetInt(eCheckboxState, *checkValue);
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_WARNING_DIALOG.get());
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
if (NS_FAILED(rv))
|
||||
@ -228,6 +231,7 @@ nsPromptService::Confirm(nsIDOMWindow *parent,
|
||||
|
||||
NS_ConvertASCIItoUTF16 styleClass(kQuestionIconClass);
|
||||
block->SetString(eIconClass, styleClass.get());
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_QUESTION_DIALOG.get());
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
if (NS_FAILED(rv))
|
||||
@ -277,6 +281,7 @@ nsPromptService::ConfirmCheck(nsIDOMWindow *parent,
|
||||
block->SetString(eIconClass, styleClass.get());
|
||||
block->SetString(eCheckboxMsg, checkMsg);
|
||||
block->SetInt(eCheckboxState, *checkValue);
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_QUESTION_DIALOG.get());
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
if (NS_FAILED(rv))
|
||||
@ -378,6 +383,7 @@ nsPromptService::ConfirmEx(nsIDOMWindow *parent,
|
||||
block->SetInt(eNumberButtons, numberButtons);
|
||||
|
||||
block->SetString(eIconClass, NS_ConvertASCIItoUTF16(kQuestionIconClass).get());
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_QUESTION_DIALOG.get());
|
||||
|
||||
if (checkMsg && checkValue) {
|
||||
block->SetString(eCheckboxMsg, checkMsg);
|
||||
@ -453,6 +459,7 @@ nsPromptService::Prompt(nsIDOMWindow *parent,
|
||||
block->SetString(eCheckboxMsg, checkMsg);
|
||||
block->SetInt(eCheckboxState, *checkValue);
|
||||
}
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_QUESTION_DIALOG.get());
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
if (NS_FAILED(rv))
|
||||
@ -528,6 +535,7 @@ nsPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
|
||||
block->SetString(eCheckboxMsg, checkMsg);
|
||||
block->SetInt(eCheckboxState, *checkValue);
|
||||
}
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_QUESTION_DIALOG.get());
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
if (NS_FAILED(rv))
|
||||
@ -607,6 +615,7 @@ NS_IMETHODIMP nsPromptService::PromptPassword(nsIDOMWindow *parent,
|
||||
block->SetString(eCheckboxMsg, checkMsg);
|
||||
block->SetInt(eCheckboxState, *checkValue);
|
||||
}
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_QUESTION_DIALOG.get());
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
if (NS_FAILED(rv))
|
||||
@ -698,14 +707,15 @@ nsPromptService::Select(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
block->SetNumberStrings(count + 2);
|
||||
block->SetNumberStrings(count + 3);
|
||||
if (dialogTitle)
|
||||
block->SetString(0, dialogTitle);
|
||||
|
||||
block->SetString(1, text);
|
||||
block->SetString(2, NS_SYSSOUND_QUESTION_DIALOG.get());
|
||||
block->SetInt(eSelection, count);
|
||||
for (PRUint32 i = 2; i <= count+1; i++) {
|
||||
nsAutoString temp(selectList[i-2]);
|
||||
for (PRUint32 i = 3; i <= count+2; i++) {
|
||||
nsAutoString temp(selectList[i-3]);
|
||||
const PRUnichar* text = temp.get();
|
||||
block->SetString(i, text);
|
||||
}
|
||||
@ -741,6 +751,7 @@ nsPromptService::ShowNonBlockingAlert(nsIDOMWindow *aParent,
|
||||
paramBlock->SetString(nsPIPromptService::eIconClass, NS_LITERAL_STRING("alert-icon").get());
|
||||
paramBlock->SetString(nsPIPromptService::eDialogTitle, aDialogTitle);
|
||||
paramBlock->SetString(nsPIPromptService::eMsg, aText);
|
||||
paramBlock->SetString(eOpeningSound, NS_SYSSOUND_WARNING_DIALOG.get());
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> dialog;
|
||||
mWatcher->OpenWindow(aParent, "chrome://global/content/commonDialog.xul",
|
||||
|
@ -195,6 +195,16 @@ function commonDialogOnLoad()
|
||||
}
|
||||
|
||||
getAttention();
|
||||
|
||||
// play sound
|
||||
try {
|
||||
var sound = gCommonDialogParam.GetString(13);
|
||||
if (sound) {
|
||||
var soundService = Components.classes["@mozilla.org/sound;1"].
|
||||
createInstance(Components.interfaces.nsISound);
|
||||
soundService.playSystemSound(sound);
|
||||
}
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
var gDelayExpired = false;
|
||||
|
@ -81,12 +81,12 @@ function selectDialogOnLoad() {
|
||||
numItems = param.GetInt( 2 );
|
||||
|
||||
var i;
|
||||
for ( i = 2; i <= numItems+1; i++ ) {
|
||||
for ( i = 3; i <= numItems+2; i++ ) {
|
||||
var newString = param.GetString( i );
|
||||
if (newString == "") {
|
||||
newString = "<>";
|
||||
}
|
||||
elements[i-2] = AppendStringToListbox(list, newString);
|
||||
elements[i-3] = AppendStringToListbox(list, newString);
|
||||
}
|
||||
list.selectItem(elements[0]);
|
||||
list.focus();
|
||||
@ -98,6 +98,16 @@ function selectDialogOnLoad() {
|
||||
moveToAlertPosition();
|
||||
param.SetInt(0, 1 );
|
||||
centerWindowOnScreen();
|
||||
|
||||
// play sound
|
||||
try {
|
||||
var sound = param.GetString(2);
|
||||
if (sound) {
|
||||
var soundService = Components.classes["@mozilla.org/sound;1"].
|
||||
createInstance(Components.interfaces.nsISound);
|
||||
soundService.playSystemSound(sound);
|
||||
}
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
function commonDialogOnOK() {
|
||||
|
@ -57,3 +57,21 @@ interface nsISound : nsISupports
|
||||
*/
|
||||
void init();
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
#include "nsString.h"
|
||||
|
||||
#define NS_SYSSOUND_PREFIX NS_LITERAL_STRING("_moz_")
|
||||
#define NS_SYSSOUND_MAIL_BEEP NS_LITERAL_STRING("_moz_mailbeep")
|
||||
#define NS_SYSSOUND_ERROR_DIALOG NS_LITERAL_STRING("_moz_errordialog")
|
||||
#define NS_SYSSOUND_INFO_DIALOG NS_LITERAL_STRING("_moz_infodialog")
|
||||
#define NS_SYSSOUND_QUESTION_DIALOG NS_LITERAL_STRING("_moz_questiondialog")
|
||||
#define NS_SYSSOUND_WARNING_DIALOG NS_LITERAL_STRING("_moz_warningdialog")
|
||||
|
||||
static PRBool NS_IsMozAliasSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
return StringBeginsWith(aSoundAlias, NS_SYSSOUND_PREFIX);
|
||||
}
|
||||
|
||||
%}
|
||||
|
@ -153,8 +153,11 @@ NS_METHOD nsSound::Play(nsIURL *aURL)
|
||||
NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
if (aSoundAlias.EqualsLiteral("_moz_mailbeep"))
|
||||
if (NS_IsMozAliasSound(aSoundAlias)) {
|
||||
if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
|
||||
return Beep();
|
||||
return NS_OK;
|
||||
}
|
||||
nsCOMPtr <nsIURI> fileURI;
|
||||
// create a nsILocalFile and then a nsIFileURL from that
|
||||
nsCOMPtr <nsILocalFile> soundFile;
|
||||
|
@ -366,8 +366,10 @@ NS_METHOD nsSound::Play(nsIURL *aURL)
|
||||
|
||||
NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
if (aSoundAlias.EqualsLiteral("_moz_mailbeep")) {
|
||||
if (NS_IsMozAliasSound(aSoundAlias)) {
|
||||
if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
|
||||
return Beep();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
|
@ -480,12 +480,22 @@ NS_IMETHODIMP nsSound::Init()
|
||||
|
||||
NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
// We don't have a default mail sound on OS/2, so just beep.
|
||||
// Also just beep if MMPM isn't installed.
|
||||
if (aSoundAlias.EqualsLiteral("_moz_mailbeep") || (!sMMPMInstalled)) {
|
||||
// Just beep if MMPM isn't installed.
|
||||
if (!sMMPMInstalled) {
|
||||
Beep();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (NS_IsMozAliasSound(aSoundAlias)) {
|
||||
// We don't have a default mail sound on OS/2, so just beep.
|
||||
if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
|
||||
Beep();
|
||||
// XXX Should we call Beep() for NS_SYSSOUND_INFO_DIALOG,
|
||||
// NS_SYSSOUND_QUESTION_DIALOG and NS_SYSSOUND_WARNING_DIALOG?
|
||||
// And also should we call WinAlarm(HWND_DESKTOP, WA_ERROR) for
|
||||
// NS_SYSSOUND_ERROR_DIALOG?
|
||||
return NS_OK;
|
||||
}
|
||||
nsCAutoString nativeSoundAlias;
|
||||
NS_CopyUnicodeToNative(aSoundAlias, nativeSoundAlias);
|
||||
|
||||
|
@ -117,9 +117,12 @@ printf( "\n\n\nnsSound::PlaySystemSound aSoundAlias=%s\n\n",
|
||||
|
||||
const char *soundfile;
|
||||
|
||||
if( utf8SoundAlias.Equals("_moz_mailbeep") )
|
||||
if( NS_IsMozAliasSound(aSoundAlias) ) {
|
||||
if ( aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP) )
|
||||
soundfile = "/usr/share/mozilla/gotmail.wav";
|
||||
else {
|
||||
else
|
||||
return NS_OK;
|
||||
} else {
|
||||
/* the aSoundAlias is the fullpath to the soundfile */
|
||||
if( !access( utf8SoundAlias.get(), F_OK ) )
|
||||
soundfile = utf8SoundAlias.get();
|
||||
|
@ -377,8 +377,10 @@ NS_METHOD nsSound::Play(nsIURL *aURL)
|
||||
|
||||
NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
if (aSoundAlias.EqualsLiteral("_moz_mailbeep")) {
|
||||
if (NS_IsMozAliasSound(aSoundAlias)) {
|
||||
if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
|
||||
return Beep();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
|
@ -164,13 +164,27 @@ NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
PurgeLastSound();
|
||||
|
||||
if (aSoundAlias.EqualsLiteral("_moz_mailbeep")) {
|
||||
::PlaySoundW(L"MailBeep", nsnull, SND_ALIAS | SND_ASYNC);
|
||||
}
|
||||
else {
|
||||
::PlaySoundW(PromiseFlatString(aSoundAlias).get(), nsnull, SND_ALIAS | SND_ASYNC);
|
||||
if (!NS_IsMozAliasSound(aSoundAlias)) {
|
||||
::PlaySoundW(PromiseFlatString(aSoundAlias).get(), nsnull,
|
||||
SND_ALIAS | SND_ASYNC);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const wchar_t *sound = nsnull;
|
||||
if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
|
||||
sound = L"MailBeep";
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_ERROR_DIALOG))
|
||||
sound = L"SystemHand";
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_INFO_DIALOG))
|
||||
sound = L"SystemAsterisk";
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_QUESTION_DIALOG))
|
||||
sound = L"SystemQuestion";
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_WARNING_DIALOG))
|
||||
sound = L"SystemExclamation";
|
||||
|
||||
if (sound)
|
||||
::PlaySoundW(sound, nsnull, SND_ALIAS | SND_ASYNC);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user