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
Родитель 00721180c3
Коммит 3e5f5ab75d
2 изменённых файлов: 32 добавлений и 0 удалений

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

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

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

@ -59,6 +59,9 @@
#include "nsIPromptService.h"
#include "nsIObserverService.h"
#include "nsIProfileChangeStatus.h"
#include "nsISound.h"
#include "nsIPrefService.h"
#include "nsIURL.h"
/* Outstanding issues/todo:
* 1. Implement pause/resume.
@ -1216,6 +1219,33 @@ nsDownload::OnStateChange(nsIWebProgress* aWebProgress,
mCurrBytes = mMaxBytes;
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;
rv = mTarget->GetPath(path);
// can't do an early return; have to break reference cycle below