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;
39 Cu.import(
"resource://app/jsmodules/ArrayConverter.jsm");
40 Cu.import(
"resource://app/jsmodules/StringUtils.jsm");
51 transcodeSettings:
null,
56 doPaneLoad:
function CDRipPrefsPane_doPaneLoad() {
57 this.transcodeSettings = document.getElementById(
"cd-transcode-settings");
59 this.loadTranscodeSettings();
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');
68 Cc[
"@songbirdnest.com/Songbird/MetadataLookup/manager;1"]
69 .getService(Ci.sbIMetadataLookupManager)
70 .defaultProvider.name;
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);
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);
86 this.providerDescriptions[provider.name] = provider.description;
88 dump(
"Exception in CD Rip prefs pane: " + e +
"\n");
93 if (this.isAnyCDDeviceTranscoding())
94 this.addNotification();
98 this.setupListeners();
100 window.addEventListener(
"unload", CDRipPrefsPane.doPaneUnload,
true);
106 doPaneUnload:
function CDRipPrefsPane_doPaneUnload() {
107 this.transcodeSettings =
null;
108 window.removeEventListener(
"unload", CDRipPrefsPane.doPaneUnload,
true);
109 CDRipPrefsPane.shutdownListeners();
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);
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);
140 setupListeners:
function CDRipPrefPane_setupListeners() {
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);
151 deviceMgr.addEventListener(
this);
157 shutdownListeners:
function CDRipPrefPane_setupListeners() {
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);
168 deviceMgr.removeEventListener(
this);
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();
184 else if (!this.isAnyCDDeviceTranscoding()) {
186 this.removeNotifications();
190 case Ci.sbIDeviceEvent.EVENT_DEVICE_ADDED:
191 var device = aEvent.origin.QueryInterface(Ci.sbIDevice);
192 this.addDeviceListener(device);
195 case Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED:
196 var device = aEvent.origin.QueryInterface(Ci.sbIDevice);
197 this.removeDeviceListener(device);
208 removeNotifications:
function CDRipPrefsPane_removeNotifications() {
210 var notifBox = document.getElementById(
"cdrip_notification_box");
211 notifBox.removeAllNotifications(
false);
217 addNotification:
function CDRipPrefsPane_addNotification() {
219 var notifBox = document.getElementById(
"cdrip_notification_box");
220 if (notifBox.currentNotification) {
224 notifBox.appendNotification(
SBString(
"cdrip.prefpane.device_busy"),
227 notifBox[
"PRIORITY_WARNING_MEDIUM"],
236 isAnyCDDeviceTranscoding:
function CDRipPrefsPane_isAnyCDDeviceTranscoding() {
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)
257 providerChanged:
function CDRipPrefsPane_providerChanged(aEvent) {
258 var provName = aEvent.target.value;
259 this.setProviderDescription(this.providerDescriptions[provName]);
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));
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);
288 var supportedProfiles = [];
289 for (let
i = 0;
i < profiles.length;
i++) {
290 let profile = profiles.queryElementAt(
i, Ci.sbITranscodeProfile);
291 supportedProfiles.push(profile);
295 this.transcodeSettings.profiles = supportedProfiles;
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"),
"");
303 Application.prefs.getValue(bitratePref.getAttribute(
"name"),
"");
306 this.transcodeSettings.transcodeBitrate = defaultBitrate;
307 this.transcodeSettings.transcodeProfileId = defaultTranscodeId;
310 formatIdPref.value = this.transcodeSettings.transcodeProfileId;
311 bitratePref.value = this.transcodeSettings.transcodeBitrate;
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;
function SBString(aKey, aDefault, aStringBundle)
_getSelectedPageStyle s i