Bug 16498 Finished Downloading sounds

patch by cst@andrew.cmu.edu r=varga sr=bz
This commit is contained in:
timeless%mozdev.org 2003-10-31 01:58:56 +00:00
parent 28372ff680
commit 43ee8e9f0b
2 changed files with 32 additions and 0 deletions

View File

@ -43,6 +43,8 @@ REQUIRES = xpcom \
appshell \ appshell \
dom \ dom \
profile \ profile \
widget \
pref \
$(NULL) $(NULL)
CPPSRCS = \ CPPSRCS = \
nsDownloadManager.cpp \ nsDownloadManager.cpp \

View File

@ -59,6 +59,9 @@
#include "nsIPromptService.h" #include "nsIPromptService.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsIProfileChangeStatus.h" #include "nsIProfileChangeStatus.h"
#include "nsISound.h"
#include "nsIPrefService.h"
#include "nsIURL.h"
/* Outstanding issues/todo: /* Outstanding issues/todo:
* 1. Implement pause/resume. * 1. Implement pause/resume.
@ -1216,6 +1219,33 @@ nsDownload::OnStateChange(nsIWebProgress* aWebProgress,
mCurrBytes = mMaxBytes; mCurrBytes = mMaxBytes;
mPercentComplete = 100; mPercentComplete = 100;
//Play a sound when the download finishes
nsXPIDLCString soundStr;
nsCOMPtr<nsIPrefService> prefs = do_GetService("@mozilla.org/preferences-service;1");
if (prefs) {
nsCOMPtr<nsIPrefBranch> prefBranch;
prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
if (prefBranch)
prefBranch->GetCharPref("browser.download.finished_sound_url", getter_Copies(soundStr));
}
//only continue if it isn't blank
if (!soundStr.IsEmpty()) {
nsCOMPtr<nsISound> snd = do_GetService("@mozilla.org/sound;1");
if (snd) { //hopefully we got it
nsCOMPtr<nsIURI> soundURI;
NS_NewURI(getter_AddRefs(soundURI), soundStr);
nsCOMPtr<nsIURL> soundURL(do_QueryInterface(soundURI));
if (soundURL)
snd->Play(soundURL);
else
snd->Beep();
}
}
nsAutoString path; nsAutoString path;
rv = mTarget->GetPath(path); rv = mTarget->GetPath(path);
// can't do an early return; have to break reference cycle below // can't do an early return; have to break reference cycle below