summaryrefslogtreecommitdiff
path: root/xptoolkit/components/preferences/content/preferences.js
blob: 511d3c03962c6aed0e6526d5fe2da1b003f502ee (plain)
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
/* -*- 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!

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;

  if (document.getElementById("advancedChildren").childElementCount == 0) {
    document.getElementById("advancedItem").setAttribute("open", false);
    document.getElementById("advancedItem").setAttribute("container", false);
  }
}

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 = (/Mac/.test(navigator.platform)) ? file.leafName : file.path;
  }
}

function SelectSound(aSoundUrlPref)
{
  const nsIFilePicker = Components.interfaces.nsIFilePicker;
  var fp = Components.classes["@mozilla.org/filepicker;1"]
                     .createInstance(nsIFilePicker);
  var prefutilitiesBundle = document.getElementById("bundle_prefutilities");
  fp.init(window, prefutilitiesBundle.getString("choosesound"),
          nsIFilePicker.modeOpen);

  var file = GetFileFromString(aSoundUrlPref.value);
  if (file && file.parent && file.parent.exists())
    fp.displayDirectory = file.parent;

  var filterExts = "*.wav; *.wave";
  // On Mac, allow AIFF and CAF files too.
  if (/Mac/.test(navigator.platform))
    filterExts += "; *.aif; *.aiff; *.caf";
  fp.appendFilter(prefutilitiesBundle.getString("SoundFiles"), filterExts);
  fp.appendFilters(nsIFilePicker.filterAll);

  if (fp.show() == nsIFilePicker.returnOK)
    aSoundUrlPref.value = fp.fileURL.spec;
}

function PlaySound(aValue, aMail)
{
  const nsISound = Components.interfaces.nsISound;
  var sound = Components.classes["@mozilla.org/sound;1"]
                        .createInstance(nsISound);

  if (aValue)
    sound.play(Services.io.newURI(aValue, null, null));
  else if (aMail && !/Mac/.test(navigator.platform))
    sound.playEventSound(nsISound.EVENT_NEW_MAIL_RECEIVED);
  else
    sound.beep();
}