Bug 463209 No sound when message box is opened (alert/confirm) r=roc+neil, sr=roc, ui=jboriss

This commit is contained in:
Masayuki Nakano 2008-12-05 16:29:17 +09:00
Родитель 140c6c1955
Коммит e3e2bd2e60
12 изменённых файлов: 98 добавлений и 24 удалений

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

@ -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_ALERT_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_ALERT_DIALOG.get());
rv = DoDialog(parent, block, kPromptURL);
if (NS_FAILED(rv))
@ -228,7 +231,8 @@ nsPromptService::Confirm(nsIDOMWindow *parent,
NS_ConvertASCIItoUTF16 styleClass(kQuestionIconClass);
block->SetString(eIconClass, styleClass.get());
block->SetString(eOpeningSound, NS_SYSSOUND_CONFIRM_DIALOG.get());
rv = DoDialog(parent, block, kPromptURL);
if (NS_FAILED(rv))
return 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_CONFIRM_DIALOG.get());
rv = DoDialog(parent, block, kPromptURL);
if (NS_FAILED(rv))
@ -376,8 +381,9 @@ nsPromptService::ConfirmEx(nsIDOMWindow *parent,
buttonFlags >>= 8;
}
block->SetInt(eNumberButtons, numberButtons);
block->SetString(eIconClass, NS_ConvertASCIItoUTF16(kQuestionIconClass).get());
block->SetString(eOpeningSound, NS_SYSSOUND_CONFIRM_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_PROMPT_DIALOG.get());
rv = DoDialog(parent, block, kPromptURL);
if (NS_FAILED(rv))
@ -528,7 +535,8 @@ nsPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
block->SetString(eCheckboxMsg, checkMsg);
block->SetInt(eCheckboxState, *checkValue);
}
block->SetString(eOpeningSound, NS_SYSSOUND_PROMPT_DIALOG.get());
rv = DoDialog(parent, block, kPromptURL);
if (NS_FAILED(rv))
return rv;
@ -607,6 +615,7 @@ NS_IMETHODIMP nsPromptService::PromptPassword(nsIDOMWindow *parent,
block->SetString(eCheckboxMsg, checkMsg);
block->SetInt(eCheckboxState, *checkValue);
}
block->SetString(eOpeningSound, NS_SYSSOUND_PROMPT_DIALOG.get());
rv = DoDialog(parent, block, kPromptURL);
if (NS_FAILED(rv))
@ -737,10 +746,11 @@ nsPromptService::ShowNonBlockingAlert(nsIDOMWindow *aParent,
if (!paramBlock)
return NS_ERROR_FAILURE;
paramBlock->SetInt(nsPIPromptService::eNumberButtons, 1);
paramBlock->SetString(nsPIPromptService::eIconClass, NS_LITERAL_STRING("alert-icon").get());
paramBlock->SetString(nsPIPromptService::eDialogTitle, aDialogTitle);
paramBlock->SetString(nsPIPromptService::eMsg, aText);
paramBlock->SetInt(eNumberButtons, 1);
paramBlock->SetString(eIconClass, NS_LITERAL_STRING("alert-icon").get());
paramBlock->SetString(eDialogTitle, aDialogTitle);
paramBlock->SetString(eMsg, aText);
paramBlock->SetString(eOpeningSound, NS_SYSSOUND_ALERT_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) {
Components.classes["@mozilla.org/sound;1"]
.createInstance(Components.interfaces.nsISound)
.playSystemSound(sound);
}
} catch (e) { }
}
var gDelayExpired = false;

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

@ -98,6 +98,13 @@ function selectDialogOnLoad() {
moveToAlertPosition();
param.SetInt(0, 1 );
centerWindowOnScreen();
// play sound
try {
Components.classes["@mozilla.org/sound;1"]
.createInstance(Components.interfaces.nsISound)
.playSystemSound("_moz_selectdialog");
} catch (e) { }
}
function commonDialogOnOK() {

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

@ -57,3 +57,17 @@ interface nsISound : nsISupports
*/
void init();
};
%{C++
#define NS_SYSSOUND_PREFIX NS_LITERAL_STRING("_moz_")
#define NS_SYSSOUND_MAIL_BEEP NS_LITERAL_STRING("_moz_mailbeep")
#define NS_SYSSOUND_ALERT_DIALOG NS_LITERAL_STRING("_moz_alertdialog")
#define NS_SYSSOUND_CONFIRM_DIALOG NS_LITERAL_STRING("_moz_confirmdialog")
#define NS_SYSSOUND_PROMPT_DIALOG NS_LITERAL_STRING("_moz_promptdialog")
#define NS_SYSSOUND_SELECT_DIALOG NS_LITERAL_STRING("_moz_selectdialog")
#define NS_IsMozAliasSound(aSoundAlias) \
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"))
return Beep();
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;

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

@ -43,6 +43,7 @@
#include "nsNetUtil.h"
#include "nsCOMPtr.h"
#include "nsIURL.h"
#include "nsString.h"
#import <Cocoa/Cocoa.h>

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

@ -51,6 +51,7 @@
#include "nsNetUtil.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsString.h"
#include <stdio.h>
#include <unistd.h>
@ -366,8 +367,10 @@ NS_METHOD nsSound::Play(nsIURL *aURL)
NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias)
{
if (aSoundAlias.EqualsLiteral("_moz_mailbeep")) {
return Beep();
if (NS_IsMozAliasSound(aSoundAlias)) {
if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
return Beep();
return NS_OK;
}
nsresult rv;

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

@ -59,6 +59,7 @@
#include "nsSound.h"
#include "nsIURL.h"
#include "nsNetUtil.h"
#include "nsString.h"
#include "nsDirectoryServiceDefs.h"
@ -480,12 +481,18 @@ 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();
return NS_OK;
}
nsCAutoString nativeSoundAlias;
NS_CopyUnicodeToNative(aSoundAlias, nativeSoundAlias);

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

@ -42,6 +42,7 @@
#include "prlink.h"
#include "nsSound.h"
#include "nsString.h"
#include "nsIURL.h"
#include "nsNetUtil.h"
@ -117,9 +118,12 @@ printf( "\n\n\nnsSound::PlaySystemSound aSoundAlias=%s\n\n",
const char *soundfile;
if( utf8SoundAlias.Equals("_moz_mailbeep") )
soundfile = "/usr/share/mozilla/gotmail.wav";
else {
if( NS_IsMozAliasSound(aSoundAlias) ) {
if ( aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP) )
soundfile = "/usr/share/mozilla/gotmail.wav";
else
return NS_OK;
} else {
/* the aSoundAlias is the fullpath to the soundfile */
if( !access( utf8SoundAlias.get(), F_OK ) )
soundfile = utf8SoundAlias.get();

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

@ -43,6 +43,7 @@
#include "prlink.h"
#include "nsSound.h"
#include "nsString.h"
#include "nsIURL.h"
#include "nsIFileURL.h"
@ -377,8 +378,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,25 @@ 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_NODEFAULT | SND_ALIAS | SND_ASYNC);
return NS_OK;
}
// Win32 plays no sounds at NS_SYSSOUND_PROMPT_DIALOG and
// NS_SYSSOUND_SELECT_DIALOG.
const wchar_t *sound = nsnull;
if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
sound = L"MailBeep";
else if (aSoundAlias.Equals(NS_SYSSOUND_CONFIRM_DIALOG))
sound = L"SystemQuestion";
else if (aSoundAlias.Equals(NS_SYSSOUND_ALERT_DIALOG))
sound = L"SystemExclamation";
if (sound)
::PlaySoundW(sound, nsnull, SND_NODEFAULT | SND_ALIAS | SND_ASYNC);
return NS_OK;
}