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 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
58 Cu.import(
"resource://app/jsmodules/WindowUtils.jsm");
85 initialize:
function DTSW__initialize(aWidget) {
87 this._widget = aWidget;
90 var disabled = this._widget.getAttribute(
"disabled");
92 this._disabled =
true;
94 this._showDescription();
103 finalize:
function DTSW_finalize() {
105 this._disabled =
null;
118 _update:
function DTSW__update() {
119 var modeDetailsBox = this._getElement(
"transcoding-mode-details");
120 var children = modeDetailsBox.childNodes;
121 for (let
i = 0;
i < children.length;
i++) {
122 let currChild = children.item(
i);
123 if (this._disabled) {
124 currChild.setAttribute(
"disabled",
true);
126 currChild.removeAttribute(
"disabled");
135 _showDescription:
function DTSW__showDescription() {
136 var showDesc = this._widget.getAttribute(
"showDesc");
137 var qualityLabel = this._getElement(
"transcoding-quality-desc");
139 qualityLabel.removeAttribute(
"hidden");
141 qualityLabel.setAttribute(
"hidden",
true);
155 _addBitrate:
function DTSW__addBitrate(aBitrate, aSelected) {
156 var bitrateEntry = this._getElement(
"transcoding-bitrate-kbps");
157 var bitrateList = this._getElement(
"transcoding-bitrate-list");
158 var bitrateMenuItem = document.createElementNS(XUL_NS,
"menuitem");
159 bitrateMenuItem.setAttribute(
"label", aBitrate);
160 bitrateMenuItem.setAttribute(
"value", aBitrate);
161 bitrateList.appendChild(bitrateMenuItem);
163 if (aSelected == aBitrate) {
164 bitrateMenuItem.setAttribute(
"selected",
"true");
165 bitrateEntry.selectedItem = bitrateMenuItem;
167 bitrateMenuItem.setAttribute(
"selected",
"false");
180 _rebuildProfiles:
function DTSW__rebuildProfiles(aProfiles) {
181 this._profiles = aProfiles;
184 var profilesMenu = this._getElement(
"encoding-format-menu");
185 var profilesMenuList = this._getElement(
"encoding-format-list");
188 while (profilesMenuList.firstChild)
189 profilesMenuList.removeChild(profilesMenuList.firstChild);
192 for (let
i = 0;
i < this._profiles.length;
i++) {
193 var profile = this._profiles[
i];
194 var readableName = profile.description;
195 var
menuItem = document.createElementNS(XUL_NS,
"menuitem");
196 menuItem.setAttribute(
"label", readableName);
197 menuItem.setAttribute(
"value", profile.id);
199 profilesMenuList.appendChild(menuItem);
211 _activateProfileById:
function DTSW__activateProfileById(aId) {
212 var profile = this._getProfileFromProfileId(aId);
213 this._activateProfile(profile);
225 _activateProfile:
function DTSW__activateProfile(aProfile) {
226 var defaulted =
false;
229 aProfile = this._getDefaultProfile();
233 var formatList = this._getElement(
"encoding-format-list");
234 for (var
i = 0;
i < formatList.childNodes.length;
i++) {
235 var formatMenuItem = formatList.childNodes.item(
i);
236 if (formatMenuItem.value == aProfile.id) {
237 formatMenuItem.setAttribute(
"selected",
"true");
238 this._getElement(
"encoding-format-menu").selectedItem = formatMenuItem;
239 this._selectedProfile = aProfile;
241 formatMenuItem.setAttribute(
"selected",
"false");
246 this._updateBitrates(aProfile, defaulted);
256 _updateBitrates:
function DTSW__updateBitrates(aProfile, aDefaulted) {
258 var foundBitrate =
false;
259 var propertiesArray = aProfile.audioProperties;
260 if (propertiesArray) {
261 for (var
i = 0;
i < propertiesArray.length;
i++) {
262 var
property = propertiesArray.queryElementAt(
i,
263 Ci.sbITranscodeProfileProperty);
264 if (property.propertyName ==
"bitrate") {
266 var bitrateEntry = this._getElement(
"transcoding-bitrate-kbps");
267 var bitrateList = this._getElement(
"transcoding-bitrate-list");
268 var brIndex = bitrateEntry.selectedIndex;
269 var selected = bitrateEntry.value;
271 while (bitrateList.firstChild)
272 bitrateList.removeChild(bitrateList.firstChild);
274 var defaultBitrate = parseInt(property.value) / 1000;
277 if (this._selectedBitrate && !aDefaulted) {
278 selected = parseInt(this._selectedBitrate) / 1000;
280 selected = defaultBitrate;
283 var bitrate = parseInt(property.valueMin) / 1000;
284 var maxBitrate = parseInt(property.valueMax) / 1000;
285 var increment = parseInt(bitrateEntry.getAttribute(
"increment"));
286 var bitrateArray = [];
289 while (bitrate < maxBitrate) {
290 bitrateArray.push(this._addBitrate(bitrate, selected));
292 bitrate += increment;
293 var mod = bitrate % increment;
295 bitrate += increment - mod;
300 bitrateArray.push(this._addBitrate(maxBitrate, selected));
304 if (bitrateArray.indexOf(parseInt(bitrateEntry.value)) == -1) {
305 if (brIndex >= bitrateArray.length) {
306 bitrateEntry.selectedItem = bitrateList.lastChild;
307 }
else if (brIndex >= 0) {
308 bitrateEntry.selectedIndex = brIndex;
310 bitrateEntry.selectedIndex = bitrateArray.indexOf(defaultBitrate);
315 this._selectedBitrate = parseInt(bitrateEntry.value) * 1000;
320 var bitrateBox = this._getElement(
"transcoding-bitrate");
322 bitrateBox.removeAttribute(
"hidden");
325 bitrateBox.setAttribute(
"hidden",
"true");
337 _getProfileFromProfileId:
function DTSW__getProfileFromProfileId(aId) {
338 for (var
i = 0;
i < this._profiles.length;
i++) {
339 var profile = this._profiles[
i];
340 if (profile.id == aId)
352 _getDefaultProfile:
function DTSW__getDefaultProfile() {
353 return this._profiles.reduce(
function(high,
next) {
354 return high.priority >
next.priority ? high :
next;
367 _getElement:
function DTSW__getElement(aElementID) {
368 return document.getAnonymousElementByAttribute(this._widget,
_getSelectedPageStyle s i