45 if (typeof(
Cc) ==
"undefined")
46 var
Cc = Components.classes;
47 if (typeof(
Ci) ==
"undefined")
48 var
Ci = Components.interfaces;
49 if (typeof(
Cr) ==
"undefined")
50 var
Cr = Components.results;
51 if (typeof(
Cu) ==
"undefined")
52 var
Cu = Components.utils;
54 if (typeof(
XUL_NS) ==
"undefined")
55 var
XUL_NS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
57 var DeviceMediaManagementServices = {
75 initialize:
function DeviceMediaManagementServices__initialize(aWidget) {
80 this._widget = aWidget;
83 this._device = this._widget.device;
86 var deviceEventTarget =
87 this._device.QueryInterface(Ci.sbIDeviceEventTarget);
88 deviceEventTarget.addEventListener(
this);
91 this.musicManagementPrefsInitialize();
99 finalize:
function DeviceMediaManagementServices_finalize() {
100 this.musicManagementPrefsFinalize();
104 var deviceEventTarget =
105 this._device.QueryInterface(Ci.sbIDeviceEventTarget);
106 deviceEventTarget.removeEventListener(
this);
114 savePreferences:
function DeviceMediaManagementServices_savePreferences() {
119 this._transcodeModeManual =
120 this._getElement(
"transcoding-mode-manual").selected;
121 this.musicManagementPrefsWrite();
125 this.resetPreferences();
128 resetPreferences:
function DeviceMediaManagementServices_resetPreferences() {
133 this.musicManagementPrefsRead();
134 this.musicManagementPrefsApply();
137 _updateNotchDisabledState:
138 function DeviceMediaManagementServices__updateNotchDisabledState() {
139 var notchHbox = this._getElement(
"notch-hbox");
140 var spaceLimitScale = this._getElement(
"space_limit");
141 var zeroPercentDescription = this._getElement(
"notch-0percent-description");
142 var hundredPercentDescription =
143 this._getElement(
"notch-100percent-description");
146 for (var
i = 0;
i < notchHbox.childNodes.length;
i++) {
147 var curChildNode = notchHbox.childNodes.item(
i);
148 if (spaceLimitScale.disabled) {
149 curChildNode.setAttribute(
"disabled",
"true");
152 curChildNode.removeAttribute(
"disabled");
157 if (spaceLimitScale.disabled) {
158 zeroPercentDescription.setAttribute(
"disabled",
"true");
159 hundredPercentDescription.setAttribute(
"disabled",
"true");
162 zeroPercentDescription.removeAttribute(
"disabled");
163 hundredPercentDescription.removeAttribute(
"disabled");
170 _updateBusyState:
function DeviceMediaManagementServices__updateBusyState() {
171 var isBusy = this._device && this._device.isBusy;
173 if (this._transcodeModeManual && !isBusy) {
174 this._transcodeSettings.disabled =
false;
177 this._transcodeSettings.disabled =
true;
180 var spaceLimitToggle = this._getElement(
"space_limit_enable");
181 var spaceLimitScale = this._getElement(
"space_limit");
182 if (!isBusy && spaceLimitToggle.checked) {
183 spaceLimitScale.removeAttribute(
"disabled");
186 spaceLimitScale.setAttribute(
"disabled",
"true");
189 this._updateNotchDisabledState();
192 onUIPrefChange:
function DeviceMediaManagementServices_onUIPrefChange() {
194 this._transcodeModeManual =
195 this._getElement(
"transcoding-mode-manual").selected;
196 this.musicManagementPrefsApply();
198 this.dispatchSettingsChangeEvent();
205 dispatchSettingsChangeEvent:
206 function DeviceMediaManagementServices_dispatchSettingsChangeEvent() {
207 let
event = document.createEvent(
"UIEvents");
208 event.initUIEvent(
"settings-changed",
false,
false,
window,
null);
209 document.dispatchEvent(
event);
225 function DeviceMediaManagementServices_onDeviceEvent(aEvent) {
229 case Ci.sbIDeviceEvent.EVENT_DEVICE_STATE_CHANGED:
230 this._updateBusyState();
253 _getElement:
function DeviceMediaManagementServices__getElement(aElementID) {
254 return document.getAnonymousElementByAttribute(this._widget,
266 _selectRadio :
function DeviceMediaManagementServices__selectRadio(aRadioID)
271 radioElem = this._getElement(aRadioID);
274 radioElem.radioGroup.selectedItem = radioElem;
288 _transcodeSettings :
null,
296 musicManagementPrefsInitialize:
297 function DeviceMediaManagementServices_musicManagementPrefsInitialize()
300 this.musicManagementPrefsInitPrefs();
303 this.musicManagementPrefsInitUI();
313 musicManagementPrefsFinalize:
314 function DeviceMediaManagementServices_musicManagementPrefsFinalize()
317 this._transcodeSettings =
null;
330 musicManagementPrefsInitPrefs:
331 function DeviceMediaManagementServices_musicManagementPrefsInitPrefs()
333 this._transcodeModeManual =
false;
335 this._transcodeSettings = this._getElement(
"transcode-settings");
337 var transcodeManager =
338 Cc[
"@songbirdnest.com/Songbird/Mediacore/TranscodeManager;1"]
339 .getService(Ci.sbITranscodeManager);
341 var supportedProfiles = [];
342 var profiles = transcodeManager.getTranscodeProfiles(
343 Ci.sbITranscodeProfile.TRANSCODE_TYPE_AUDIO);
344 var deviceCaps = this._device.capabilities;
345 var formatMimeTypes = deviceCaps.getSupportedMimeTypes(
346 Ci.sbIDeviceCapabilities.CONTENT_AUDIO, {});
348 for (formatMimeTypeIndex in formatMimeTypes) {
349 var formats = deviceCaps.
350 getFormatTypes(Ci.sbIDeviceCapabilities.CONTENT_AUDIO,
351 formatMimeTypes[formatMimeTypeIndex], {});
352 for (formatIndex in formats) {
353 var format = formats[formatIndex];
354 var container = format.containerFormat;
355 var audioCodec = format.audioCodec;
357 for (var
i = 0;
i < profiles.length;
i++) {
358 var profile = profiles.queryElementAt(
i, Ci.sbITranscodeProfile);
360 if (profile.type == Ci.sbITranscodeProfile.TRANSCODE_TYPE_AUDIO &&
361 profile.containerFormat == container &&
362 profile.audioCodec == audioCodec)
364 supportedProfiles.push(profile);
370 this._transcodeSettings.profiles = supportedProfiles;
382 musicManagementPrefsInitUI:
383 function DeviceMediaManagementServices_musicManagementPrefsInitUI() {
385 var profiles = this._transcodeSettings.profiles;
389 var transcodingSettingsDeckElem =
390 this._getElement(
"transcoding_settings_deck");
391 if (profiles.length > 0) {
392 transcodingSettingsDeckElem.selectedPanel =
393 this._getElement(
"transcoding_preferences");
396 transcodingSettingsDeckElem.selectedPanel =
397 this._getElement(
"no_encoders_available_description");
410 musicManagementPrefsRead:
411 function DeviceMediaManagementServices_musicManagementPrefsRead(aPrefs)
413 var profileId = this._device.getPreference(
"transcode_profile.profile_id");
417 this._transcodeModeManual =
true;
418 this._transcodeSettings.transcodeBitrate =
419 this._device.getPreference(
420 "transcode_profile.audio_properties.bitrate");
421 this._transcodeSettings.transcodeProfileId = profileId;
426 this._transcodeModeManual =
false;
430 "songbird.device.transcode_profile.profile_id",
null);
432 this._transcodeSettings.transcodeBitrate =
434 "songbird.device.transcode_profile.audio_properties.bitrate",
436 this._transcodeSettings.transcodeProfileId = gProfileId;
438 this._transcodeSettings.transcodeProfile =
null;
439 this._transcodeSettings.transcodeBitrate =
null;
452 musicManagementPrefsWrite:
453 function DeviceMediaManagementServices_musicManagementPrefsWrite()
455 if (this._transcodeModeManual) {
456 this._device.setPreference(
"transcode_profile.profile_id",
457 this._transcodeSettings.transcodeProfileId);
458 this._device.setPreference(
"transcode_profile.audio_properties.bitrate",
459 this._transcodeSettings.transcodeBitrate);
461 this._device.setPreference(
"transcode_profile.profile_id",
"");
463 this._transcodeSettings.transcodeProfileId =
"";
474 musicManagementPrefsApply:
475 function DeviceMediaManagementServices_musicManagementPrefsApply()
477 if (this._transcodeModeManual)
478 this._selectRadio(
"transcoding-mode-manual");
480 this._selectRadio(
"transcoding-mode-auto");
483 return this._updateBusyState();
_getSelectedPageStyle s i