playbackPrefs.js
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4 //
5 // BEGIN SONGBIRD GPL
6 //
7 // This file is part of the Songbird web player.
8 //
9 // Copyright(c) 2005-2008 POTI, Inc.
10 // http://songbirdnest.com
11 //
12 // This file may be licensed under the terms of of the
13 // GNU General Public License Version 2 (the "GPL").
14 //
15 // Software distributed under the License is distributed
16 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
17 // express or implied. See the GPL for the specific language
18 // governing rights and limitations.
19 //
20 // You should have received a copy of the GPL along with this
21 // program. If not, go to http://www.gnu.org/licenses/gpl.html
22 // or write to the Free Software Foundation, Inc.,
23 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 // END SONGBIRD GPL
26 //
27  */
28 
34 Components.utils.import("resource://app/jsmodules/DOMUtils.jsm");
35 Components.utils.import("resource://app/jsmodules/SBJobUtils.jsm");
36 Components.utils.import("resource://app/jsmodules/StringUtils.jsm");
37 
38 if (typeof(Cc) == "undefined")
39  var Cc = Components.classes;
40 if (typeof(Ci) == "undefined")
41  var Ci = Components.interfaces;
42 if (typeof(Cr) == "undefined")
43  var Cr = Components.results;
44 if (typeof(Cu) == "undefined")
45  var Cu = Components.utils;
46 
47 var playbackPrefsUI = {
48  _outputBufferMin: 100,
49  _outputBufferMax: 10000,
50  _outputBufferMaxDigits: 5,
51 
52  _streamingBufferMin: 32,
53  _streamingBufferMax: 10240,
54  _streamingBufferMaxDigits: 5,
55 
56  _outputBufferTextbox: null,
57  _streamingBufferTextbox: null,
58 
59  initialize: function playbackPrefsUI_initialize() {
60  this._outputBufferTextbox = document.getElementById("playback_output_buffer_textbox");
61  this._streamingBufferTextbox = document.getElementById("playback_streaming_buffer_textbox");
62 
63  this._update();
64  },
65 
66  doOnOutputBufferChange: function playbackPrefsUI_doOnOutputBufferChange() {
67  var bufferVal = this._getPrefElemValue(this._getPrefElem("output_buffer_pref"));
68  this._verifyIntValueBounds(this._outputBufferTextbox,
69  bufferVal,
70  this._outputBufferMin,
71  this._outputBufferMax);
72  },
73 
74  doOnOutputBufferKeypress: function playbackPrefsUI_doOnOutputBufferKeypress(aEvent) {
75  this._verifyIntInputValue(aEvent,
76  this._outputBufferTextbox,
77  this._outputBufferMin,
78  this._outputBufferMax,
79  this._outputBufferMaxDigits);
80  },
81 
82  doOnStreamingBufferChange: function playbackPrefsUI_doOnStreamingBufferChange() {
83  var streamingVal = this._getPrefElemValue(this._getPrefElem("streaming_buffer_pref"));
84  this._verifyIntValueBounds(this._streamingBufferTextbox,
85  streamingVal,
86  this._streamingBufferMin,
87  this._streamingBufferMax);
88  },
89 
90  doOnStreamingBufferKeypress: function playbackPrefsUI_doOnStreamingBufferKeypress(aEvent) {
91  this._verifyIntInputValue(aEvent,
92  this._streamingBufferTextbox,
93  this._streamingBufferMin,
94  this._streamingBufferMax,
95  this._streamingBufferMaxDigits);
96  },
97 
98  doOnNormalizationEnabledChange:
99  function playbackPrefsUI_doOnNormalizationEnabledChange() {
100  var normalize =
101  !this._getPrefElemValue(this._getPrefElem("normalization_enabled_pref"));
102 
103  var normalizeList = document.getElementById("playback_normalization_preferred_gain_list");
104  var normalizeLabel = document.getElementById("playback_normalization_preferred_gain_label");
105 
106  normalizeList.setAttribute("disabled", normalize);
107  normalizeLabel.setAttribute("disabled", normalize);
108  },
109 
110  _update: function playbackPrefsUI__update() {
111  this.doOnOutputBufferChange();
112  this.doOnNormalizationEnabledChange();
113  },
114 
115 
124  _getPrefElem: function playback__getPrefElem(aPrefID) {
125  // Get the requested element.
126  var prefElemList = DOMUtils.getElementsByAttribute(document,
127  "prefid",
128  aPrefID);
129  if (!prefElemList || (prefElemList.length == 0))
130  return null;
131 
132  return prefElemList[0];
133  },
134 
135 
144  _getPrefElemValue: function playbackPrefsUI__getPrefElemValue(aElement) {
145  // Return the checked value for checkbox preferences.
146  if (aElement.localName == "checkbox")
147  return aElement.checked;
148 
149  return aElement.value;
150  },
151 
152  _verifyIntValueBounds: function playbackPrefsUI__verifyIntValueBounds(aElement,
153  aValue,
154  aMin,
155  aMax) {
156  if(aValue < aMin ||
157  aValue > aMax) {
158  aElement.setAttribute("invalid", true);
159  }
160  else if(aElement.hasAttribute("invalid")){
161  aElement.removeAttribute("invalid");
162  }
163  },
164 
165  _verifyIntInputValue: function playbackPrefsUI__verifyIntInputValue(aEvent,
166  aElement,
167  aMaxDigits) {
168  if (!aEvent.ctrlKey && !aEvent.metaKey && !aEvent.altKey && aEvent.charCode) {
169  if (aEvent.charCode < 48 || aEvent.charCode > 57) {
170  aEvent.preventDefault();
171  // If typing the key would make the value too long, prevent keypress
172  } else if (aElement.value.length + 1 > aMaxDigits &&
173  aElement.selectionStart == aElement.selectionEnd) {
174  aEvent.preventDefault();
175  }
176  }
177 
178 
179  }
180 }
181 
182 
183 //------------------------------------------------------------------------------
184 //------------------------------------------------------------------------------
185 //
186 // Playback preference pane services.
187 //
188 //------------------------------------------------------------------------------
189 //------------------------------------------------------------------------------
190 
191 var playbackPrefsPane = {
192  doPaneLoad: function playbackPrefsPane_doPaneLoad() {
193  playbackPrefsUI.initialize();
194  }
195 }
196 
const Cu
function Fx prototype initialize
const Cc
onPageChanged aValue
Definition: FeedWriter.js:1395
return null
Definition: FeedWriter.js:1143
const Cr
const Ci