47 var
Cc = Components.classes;
48 var
Ci = Components.interfaces;
49 var
Cr = Components.results;
50 var
Cu = Components.utils;
53 Cu.import(
"resource://app/jsmodules/DOMUtils.jsm");
54 Cu.import(
"resource://app/jsmodules/StringUtils.jsm");
64 var
XUL_NS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
84 _volumeSelectorDeck:
null,
94 initialize:
function deviceVolumeSelectorSvc_initialize(aWidget) {
96 this._widget = aWidget;
97 this._device = this._widget.device;
100 this._volumeSelectorDeck = this._getElement(
"volume_selector_deck");
103 var deviceEventTarget =
104 this._device.QueryInterface(
Ci.sbIDeviceEventTarget);
105 deviceEventTarget.addEventListener(
this);
116 finalize:
function deviceVolumeSelectorSvc_finalize() {
119 var deviceEventTarget =
120 this._device.QueryInterface(
Ci.sbIDeviceEventTarget);
121 deviceEventTarget.removeEventListener(
this);
127 this._volumeSelectorDeck =
null;
143 onDeviceEvent:
function deviceVolumeSelectorSvc_onDeviceEvent(aEvent) {
147 case Ci.sbIDeviceEvent.EVENT_DEVICE_LIBRARY_ADDED :
148 case Ci.sbIDeviceEvent.EVENT_DEVICE_LIBRARY_REMOVED :
149 case Ci.sbIDeviceEvent.EVENT_DEVICE_DEFAULT_LIBRARY_CHANGED :
169 _update:
function deviceVolumeSelectorSvc__update() {
171 var content = this._device.content;
172 var libraries = content.libraries;
173 if (libraries.length == 0)
174 this._updateNoVolumes();
175 else if (libraries.length == 1)
176 this._updateSingleVolume();
178 this._updateMultipleVolumes();
186 _updateNoVolumes:
function deviceVolumeSelectorSvc__updateNoVolumes() {
188 var volumeLabel = this._getElement(
"volume_label");
189 this._volumeSelectorDeck.selectedPanel = volumeLabel;
192 volumeLabel.value =
SBString(
"device.volume_selector.label.no_volumes");
200 _updateSingleVolume:
function deviceVolumeSelectorSvc__updateSingleVolume() {
202 var volumeLabel = this._getElement(
"volume_label");
203 this._volumeSelectorDeck.selectedPanel = volumeLabel;
206 var content = this._device.content;
207 var libraries = content.libraries;
208 var library = libraries.queryElementAt(0,
Ci.sbIDeviceLibrary);
211 volumeLabel.value = library.name;
219 _updateMultipleVolumes:
220 function deviceVolumeSelectorSvc__updateMultipleVolumes() {
222 var volumeMenuList = this._getElement(
"volume_menulist");
223 this._volumeSelectorDeck.selectedPanel = volumeMenuList;
226 var defaultLibrary = this._device.defaultLibrary;
228 volumeMenuList.value = defaultLibrary.guid;
230 volumeMenuList.selectedIndex = 0;
249 _getElement:
function deviceVolumeSelectorSvc__getElement(aElementID) {
250 return document.getAnonymousElementByAttribute(this._widget,
275 _addedElementList:
null,
276 _addedElementListenerSet:
null,
286 initialize:
function deviceVolumeMenuItemsSvc_initialize(aWidget) {
292 this._widget = aWidget;
293 this._device = this._widget.device;
296 var deviceEventTarget =
297 this._device.QueryInterface(
Ci.sbIDeviceEventTarget);
298 deviceEventTarget.addEventListener(
this);
309 finalize:
function deviceVolumeMenuItemsSvc_finalize() {
312 var deviceEventTarget =
313 this._device.QueryInterface(
Ci.sbIDeviceEventTarget);
314 deviceEventTarget.removeEventListener(
this);
318 this._removeAddedElements();
338 onDeviceEvent:
function deviceVolumeMenuItemsSvc_onDeviceEvent(aEvent) {
342 case Ci.sbIDeviceEvent.EVENT_DEVICE_LIBRARY_ADDED :
343 case Ci.sbIDeviceEvent.EVENT_DEVICE_LIBRARY_REMOVED :
344 case Ci.sbIDeviceEvent.EVENT_DEVICE_DEFAULT_LIBRARY_CHANGED :
364 _update:
function deviceVolumeMenuItemsSvc__update() {
366 this._removeAddedElements();
369 var minVolumeCount = 1;
370 if (this._widget.hasAttribute(
"minvolumes"))
371 minVolumeCount = parseInt(this._widget.getAttribute(
"minvolumes"));
375 var libraries = this._device.content.libraries;
376 var libraryCount = libraries.length;
377 if (libraryCount < minVolumeCount)
381 var checkDefault = this._widget.getAttribute(
"checkdefault") ==
"true";
384 this._addedElementList = [];
388 if (this._widget.getAttribute(
"addseparatorbefore") ==
"true") {
389 var separator = document.createElementNS(XUL_NS,
"menuseparator");
390 this._widget.parentNode.insertBefore(separator, this._widget);
391 this._addedElementList.push(separator);
395 for (var
i = 0;
i < libraryCount;
i++) {
397 var library = libraries.queryElementAt(
i,
Ci.sbIDeviceLibrary);
400 var
menuItem = document.createElementNS(XUL_NS,
"menuitem");
401 menuItem.setAttribute(
"label", library.name);
402 menuItem.setAttribute(
"value", library.guid);
405 if (checkDefault && (library.guid ==
this._device.defaultLibrary.guid))
406 menuItem.setAttribute(
"checked",
"true");
410 var func =
function(aEvent) {
return _this._onVolumeChange(aEvent); };
411 this._addedElementListenerSet.add(menuItem,
"command", func,
false);
414 this._widget.parentNode.insertBefore(menuItem, this._widget);
415 this._addedElementList.push(menuItem);
419 if (this._widget.getAttribute(
"addseparatorafter") ==
"true") {
420 var separator = document.createElementNS(XUL_NS,
"menuseparator");
421 this._widget.parentNode.insertBefore(separator, this._widget);
422 this._addedElementList.push(separator);
431 _removeAddedElements:
432 function deviceVolumeMenuItemsSvc__removeAddedElements() {
434 if (this._AddedElementListenerSet) {
435 this._addedElementListenerSet.removeAll();
436 this._addedElementListenerSet =
null;
440 if (this._addedElementList) {
441 for (var
i = 0;
i < this._addedElementList.length;
i++) {
442 var
element = this._addedElementList[
i];
443 if (element.parentNode)
444 element.parentNode.removeChild(element);
446 this._addedElementList =
null;
457 _onVolumeChange:
function deviceVolumeMenuItemsSvc__onVolumeChange(aEvent) {
459 var libraryGUID = aEvent.target.value;
462 var content = this._device.content;
463 var libraries = content.libraries;
464 libraryCount = libraries.length;
465 for (var
i = 0;
i < libraryCount;
i++) {
467 var library = libraries.queryElementAt(
i,
Ci.sbIDeviceLibrary);
470 if (library.guid == libraryGUID) {
471 this._device.defaultLibrary = library;
var deviceVolumeMenuItemsSvc
var deviceVolumeSelectorSvc
function DOMEventListenerSet()
function SBString(aKey, aDefault, aStringBundle)
_getSelectedPageStyle s i