1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// The content of this file is loaded into the scope of the
// prefwindow and will be available to all prefpanes!
const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
function OnLoad()
{
// Make sure that the preferences window fits the screen.
let dialog = document.documentElement;
let curHeight = dialog.scrollHeight;
let curWidth = dialog.scrollWidth;
// Leave some space for desktop toolbar and window decoration.
let maxHeight = window.screen.availHeight - 48;
let maxWidth = window.screen.availWidth - 24;
// Trigger overflow situation within 40px for bug 868495 expansions.
let setHeight = curHeight > maxHeight - 40 ? maxHeight : curHeight;
let setWidth = curWidth > maxWidth ? maxWidth : curWidth;
if (setHeight == curHeight && setWidth == curWidth)
dialog.setAttribute("overflow", "visible");
window.innerHeight = setHeight;
window.innerWidth = setWidth;
}
function EnableElementById(aElementId, aEnable, aFocus)
{
EnableElement(document.getElementById(aElementId), aEnable, aFocus);
}
function EnableElement(aElement, aEnable, aFocus)
{
let pref = document.getElementById(aElement.getAttribute("preference"));
let enabled = aEnable && !pref.locked;
aElement.disabled = !enabled;
if (enabled && aFocus)
aElement.focus();
}
function WriteSoundField(aField, aValue)
{
var file = GetFileFromString(aValue);
if (file)
{
aField.file = file;
aField.label = (AppConstants.platform == "macosx") ? file.leafName : file.path;
}
}
function SelectSound(aSoundUrlPref)
{
var soundUrlPref = aSoundUrlPref;
let fp = Cc["@mozilla.org/filepicker;1"]
.createInstance(Ci.nsIFilePicker);
var prefutilitiesBundle = document.getElementById("bundle_prefutilities");
fp.init(window, prefutilitiesBundle.getString("choosesound"),
Ci.nsIFilePicker.modeOpen);
let file = GetFileFromString(soundUrlPref.value);
if (file && file.parent && file.parent.exists())
fp.displayDirectory = file.parent;
let filterExts = "*.wav; *.wave";
// On Mac, allow AIFF and CAF files too.
if (AppConstants.platform == "macosx") {
filterExts += "; *.aif; *.aiff; *.caf";
}
fp.appendFilter(prefutilitiesBundle.getString("SoundFiles"), filterExts);
fp.appendFilters(Ci.nsIFilePicker.filterAll);
fp.open(rv => {
if (rv == Ci.nsIFilePicker.returnOK && fp.fileURL.spec &&
fp.fileURL.spec.length > 0) {
soundUrlPref.value = fp.fileURL.spec;
}
});
}
function PlaySound(aValue, aMail)
{
const nsISound = Ci.nsISound;
var sound = Cc["@mozilla.org/sound;1"]
.createInstance(nsISound);
if (aValue)
sound.play(Services.io.newURI(aValue));
else if (aMail && (AppConstants.platform != "macosx"))
sound.playEventSound(nsISound.EVENT_NEW_MAIL_RECEIVED);
else
sound.beep();
}
|