cdripPrefs.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2009 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 //
26 // \file cdripPrefs.js
27 // \brief Javascript source for the CD Rip preferences UI.
28 //
29 
30 if (typeof(Cc) == "undefined")
31  var Cc = Components.classes;
32 if (typeof(Ci) == "undefined")
33  var Ci = Components.interfaces;
34 if (typeof(Cr) == "undefined")
35  var Cr = Components.results;
36 if (typeof(Cu) == "undefined")
37  var Cu = Components.utils;
38 
39 Cu.import("resource://app/jsmodules/ArrayConverter.jsm");
40 Cu.import("resource://app/jsmodules/StringUtils.jsm");
41 
42 
43 //------------------------------------------------------------------------------
44 //
45 // CD Rip preference pane services.
46 //
47 //------------------------------------------------------------------------------
48 
49 var CDRipPrefsPane =
50 {
51  transcodeSettings: null,
52 
56  doPaneLoad: function CDRipPrefsPane_doPaneLoad() {
57  this.transcodeSettings = document.getElementById("cd-transcode-settings");
58  // Initialize the transcoding options:
59  this.loadTranscodeSettings();
60 
61  // Initialize the list of metadatalookup providers
62  var provList = document.getElementById("provider-list");
63  var provPopup = document.getElementById("provider-popup");
64  var catMgr = Cc["@mozilla.org/categorymanager;1"]
65  .getService(Ci.nsICategoryManager);
66  var e = catMgr.enumerateCategory('metadata-lookup');
67  var defaultProvider =
68  Cc["@songbirdnest.com/Songbird/MetadataLookup/manager;1"]
69  .getService(Ci.sbIMetadataLookupManager)
70  .defaultProvider.name;
71 
72  this.providerDescriptions = new Array();
73  while (e.hasMoreElements()) {
74  var key = e.getNext().QueryInterface(Ci.nsISupportsCString);
75  var contract = catMgr.getCategoryEntry('metadata-lookup', key);
76  try {
77  var provider = Cc[contract].getService(Ci.sbIMetadataLookupProvider);
78  var provMenuItem = document.createElement("menuitem");
79  provMenuItem.setAttribute("label", provider.name);
80  provMenuItem.setAttribute("value", provider.name);
81  provPopup.appendChild(provMenuItem);
82  if (provider.name == defaultProvider) {
83  provList.selectedItem = provMenuItem;
84  this.setProviderDescription(provider.description);
85  }
86  this.providerDescriptions[provider.name] = provider.description;
87  } catch (e) {
88  dump("Exception in CD Rip prefs pane: " + e + "\n");
89  }
90  }
91 
92  // Check to see if a device is currently ripping and update the UI
93  if (this.isAnyCDDeviceTranscoding())
94  this.addNotification();
95 
96  // Setup listeners for the devices so we can notify the user when one is
97  // currently ripping.
98  this.setupListeners();
99 
100  window.addEventListener("unload", CDRipPrefsPane.doPaneUnload, true);
101  },
102 
106  doPaneUnload: function CDRipPrefsPane_doPaneUnload() {
107  this.transcodeSettings = null;
108  window.removeEventListener("unload", CDRipPrefsPane.doPaneUnload, true);
109  CDRipPrefsPane.shutdownListeners();
110  },
111 
116  addDeviceListener: function CDRipPrefPane_addDeviceListener(aDevice) {
117  var deviceType = aDevice.parameters.getProperty("DeviceType");
118  if (deviceType == "CD") {
119  var deviceEventTarget = aDevice.QueryInterface(Ci.sbIDeviceEventTarget);
120  deviceEventTarget.addEventListener(this);
121  }
122  },
123 
128  removeDeviceListener: function CDRipPrefPane_removeDeviceListener(aDevice) {
129  var deviceType = aDevice.parameters.getProperty("DeviceType");
130  if (deviceType == "CD") {
131  var deviceEventTarget = aDevice.QueryInterface(Ci.sbIDeviceEventTarget);
132  deviceEventTarget.removeEventListener(this);
133  }
134  },
135 
140  setupListeners: function CDRipPrefPane_setupListeners() {
141  var deviceMgr =
142  Cc["@songbirdnest.com/Songbird/DeviceManager;2"]
143  .getService(Ci.sbIDeviceManager2);
144  var registrar = deviceMgr.QueryInterface(Ci.sbIDeviceRegistrar);
145  for (var i=0; i<registrar.devices.length; i++) {
146  var device = registrar.devices.queryElementAt(i, Ci.sbIDevice);
147  this.addDeviceListener(device);
148  }
149 
150  // We also want to listen for devices being added/removed
151  deviceMgr.addEventListener(this);
152  },
153 
157  shutdownListeners: function CDRipPrefPane_setupListeners() {
158  var deviceMgr =
159  Cc["@songbirdnest.com/Songbird/DeviceManager;2"]
160  .getService(Ci.sbIDeviceManager2);
161  var registrar = deviceMgr.QueryInterface(Ci.sbIDeviceRegistrar);
162  for (var i=0; i<registrar.devices.length; i++) {
163  var device = registrar.devices.queryElementAt(i, Ci.sbIDevice);
164  this.removeDeviceListener(device);
165  }
166 
167  // Remove our device manager listener to clean up.
168  deviceMgr.removeEventListener(this);
169  },
170 
177  onDeviceEvent: function CDRipPrefsPane_onDeviceEvent(aEvent) {
178  switch (aEvent.type) {
179  case Ci.sbIDeviceEvent.EVENT_DEVICE_STATE_CHANGED:
180  var device = aEvent.origin.QueryInterface(Ci.sbIDevice);
181  if (device.state == Ci.sbIDevice.STATE_TRANSCODE) {
182  this.addNotification();
183  }
184  else if (!this.isAnyCDDeviceTranscoding()) {
185  // Remove the notifications if all cd devices are not busy
186  this.removeNotifications();
187  }
188  break;
189 
190  case Ci.sbIDeviceEvent.EVENT_DEVICE_ADDED:
191  var device = aEvent.origin.QueryInterface(Ci.sbIDevice);
192  this.addDeviceListener(device);
193  break;
194 
195  case Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED:
196  var device = aEvent.origin.QueryInterface(Ci.sbIDevice);
197  this.removeDeviceListener(device);
198  break;
199 
200  default:
201  break;
202  }
203  },
204 
208  removeNotifications: function CDRipPrefsPane_removeNotifications() {
209  // Get the current notification box for this window.
210  var notifBox = document.getElementById("cdrip_notification_box");
211  notifBox.removeAllNotifications(false);
212  },
213 
217  addNotification: function CDRipPrefsPane_addNotification() {
218  // Get the current notification box for this window.
219  var notifBox = document.getElementById("cdrip_notification_box");
220  if (notifBox.currentNotification) {
221  // Already one shown so abort
222  return;
223  }
224  notifBox.appendNotification(SBString("cdrip.prefpane.device_busy"),
225  "device_busy",
226  null,
227  notifBox["PRIORITY_WARNING_MEDIUM"],
228  []);
229  },
230 
236  isAnyCDDeviceTranscoding: function CDRipPrefsPane_isAnyCDDeviceTranscoding() {
237  // enumerate all devices and see if any of the cd ones are currently busy
238  var deviceMgr = Cc["@songbirdnest.com/Songbird/DeviceManager;2"]
239  .getService(Ci.sbIDeviceManager2);
240  var registrar = deviceMgr.QueryInterface(Ci.sbIDeviceRegistrar);
241  for (var i=0; i<registrar.devices.length; i++) {
242  var device = registrar.devices.queryElementAt(i, Ci.sbIDevice);
243  var deviceType = device.parameters.getProperty("DeviceType");
244  if (deviceType == "CD" && device.state == Ci.sbIDevice.STATE_TRANSCODE)
245  {
246  return true;
247  }
248  }
249  return false;
250  },
251 
257  providerChanged: function CDRipPrefsPane_providerChanged(aEvent) {
258  var provName = aEvent.target.value;
259  this.setProviderDescription(this.providerDescriptions[provName]);
260  },
261 
266  setProviderDescription:
267  function CDRipPrefsPane_setProviderDescription(aDescription) {
268  var provDescr = document.getElementById("provider-description");
269  while (provDescr.firstChild)
270  provDescr.removeChild(provDescr.firstChild);
271  provDescr.appendChild(document.createTextNode(aDescription));
272  },
273 
274  //----------------------------------------------------------------------------
275  // Transcoding and quality utils
276 
281  loadTranscodeSettings: function CDRipPrefsPane_loadTranscodeSettings() {
282  var transcodeManager =
283  Cc["@songbirdnest.com/Songbird/Mediacore/TranscodeManager;1"]
284  .getService(Ci.sbITranscodeManager);
285  var profiles = transcodeManager.getTranscodeProfiles(
286  Ci.sbITranscodeProfile.TRANSCODE_TYPE_AUDIO);
287 
288  var supportedProfiles = [];
289  for (let i = 0; i < profiles.length; i++) {
290  let profile = profiles.queryElementAt(i, Ci.sbITranscodeProfile);
291  supportedProfiles.push(profile);
292  }
293 
294  // Set the available transcode profiles.
295  this.transcodeSettings.profiles = supportedProfiles;
296 
297  // Get the current default transcode profile and bitrate.
298  var formatIdPref = document.getElementById("rip_format_pref");
299  var bitratePref = document.getElementById("rip_quality_pref");
300  var defaultTranscodeId =
301  Application.prefs.getValue(formatIdPref.getAttribute("name"), "");
302  var defaultBitrate =
303  Application.prefs.getValue(bitratePref.getAttribute("name"), "");
304 
305  // Set the selected transcode profile and bitrate.
306  this.transcodeSettings.transcodeBitrate = defaultBitrate;
307  this.transcodeSettings.transcodeProfileId = defaultTranscodeId;
308 
309  // In case invalid values were previously stored, write back to prefs
310  formatIdPref.value = this.transcodeSettings.transcodeProfileId;
311  bitratePref.value = this.transcodeSettings.transcodeBitrate;
312  },
313 
317  onUIPrefChanged: function CDRipPrefsPane_onUIPrefChanged() {
318  var profile = document.getElementById("rip_format_pref");
319  profile.value = this.transcodeSettings.transcodeProfileId;
320  var qualityPref = document.getElementById("rip_quality_pref");
321  qualityPref.value = this.transcodeSettings.transcodeBitrate;
322  }
323 }
const Cu
const Cc
var registrar
var Application
Definition: sbAboutDRM.js:37
function SBString(aKey, aDefault, aStringBundle)
Definition: StringUtils.jsm:93
let window
return null
Definition: FeedWriter.js:1143
const Cr
const Ci
_getSelectedPageStyle s i