47 if (typeof(
Cc) ==
"undefined")
48 var
Cc = Components.classes;
49 if (typeof(
Ci) ==
"undefined")
50 var
Ci = Components.interfaces;
51 if (typeof(
Cr) ==
"undefined")
52 var
Cr = Components.results;
53 if (typeof(
Cu) ==
"undefined")
54 var
Cu = Components.utils;
92 _updateInterval:
null,
96 _panelElements: [
"device-cap-bar-music-box",
97 "device-cap-bar-video-box",
98 "device-cap-bar-image-box",
99 "device-capacity-legend-music",
100 "device-capacity-legend-video",
101 "device-capacity-legend-image"
111 initialize:
function DCW__initialize(aWidget) {
113 this._widget = aWidget;
116 this._deviceLibrary = this._widget.devLib;
120 this._capacityBar = this._getElement(
"device-capacity-bar");
121 this._capacityLegend = this._getElement(
"device-cap-legend-box");
124 var hideListAttr = this._widget.getAttribute(
"hidelist");
126 var hideList = this._widget.getAttribute(
"hidelist").split(
",");
129 for (var
i = 0;
i < hideList.length;
i++) {
130 var
element = this._getHideElement(hideList[
i]);
131 element.hidden =
true;
136 var panelId = this._widget.getAttribute(
"panel");
137 this._panel = document.getElementById(this._widget.getAttribute(
"panel"));
138 for each (var elId
in this._panelElements) {
139 var el = this._getElement(elId);
141 el.addEventListener(
"click", this._openCapacityPanel,
false);
149 var func =
function() { _this._update(); }
150 this._updateInterval =
window.setInterval(func, this._cfg.updatePeriod);
158 finalize:
function DCW_finalize() {
160 if (this._updateInterval) {
161 window.clearInterval(this._updateInterval);
162 this._updateInterval =
null;
166 for each (var elId
in this._panelElements) {
167 var el = this._getElement(elId);
169 el.removeEventListener(
"click", this._openCapacityPanel,
false);
172 dump(
"Failed to remove event listener: " + e +
"\n");
177 this._deviceLibrary =
null;
185 _openCapacityPanel:
function DIW__openCapacityPanel(aEvent) {
186 DCW._panel.openPopup(aEvent.target);
197 _getHideElement:
function DIW__getHideElement(aHideID) {
198 return document.getAnonymousElementByAttribute(this._widget,
218 _getElement:
function DCW__getElement(aElementID) {
219 return document.getAnonymousElementByAttribute(this._widget,
236 _update:
function DCW__update() {
238 var capTable = this._getDeviceCapacity();
241 var needsUpdate =
false;
243 for (var cap in capTable) {
244 if (capTable[cap] != this._capTable[cap]) {
252 if (!this._deviceLibrary)
253 this._capacityBar.setAttribute(
"disabled",
"true");
255 this._capacityBar.removeAttribute(
"disabled");
258 this._capTable = capTable;
259 if (!this._capacityBar.hidden)
260 this._updateCapBars();
261 if (!this._capacityLegend.hidden)
262 this._updateCapLegends();
271 _updateCapBars:
function DCW__updateCapBars() {
273 var capTotal = this._capTable[
"total"];
276 var barBox = this._getElement(
"device-cap-bar-box");
277 var childList = barBox.childNodes;
278 for (var
i = 0;
i < childList.length;
i++) {
280 var child = childList[
i];
281 var barType = child.getAttribute(
"type");
286 var
value = this._capTable[barType];
289 value = Math.round((value / capTotal) * 10000);
292 child.setAttribute(
"flex", value);
302 _updateCapLegends:
function DCW__updateCapLegends() {
304 var legendBox = this._getElement(
"device-cap-legend-box");
305 var childList = legendBox.childNodes;
306 for (var
i = 0;
i < childList.length;
i++) {
308 var child = childList[
i];
309 var legendType = child.getAttribute(
"type");
314 var
value = this._capTable[legendType];
320 let storageConverter =
321 Cc[
"@songbirdnest.com/Songbird/Properties/UnitConverter/Storage;1"]
322 .createInstance(Ci.sbIPropertyUnitConverter);
323 child.setAttribute(
"value", storageConverter.autoFormat(value, -1, 1));
324 child.hidden =
false;
350 _getDevLibProperty:
function DIW__getDevLibProperty(aPropertyName, aDefault) {
352 if (this._deviceLibrary)
353 return this._deviceLibrary.getProperty(aPropertyName);
369 _getDeviceCapacity:
function DCW__getDeviceCapacity() {
371 var freeSpace = parseInt(this._getDevLibProperty
372 (
"http://songbirdnest.com/device/1.0#freeSpace", 0));
373 var musicSpace = parseInt(this._getDevLibProperty
374 (
"http://songbirdnest.com/device/1.0#musicUsedSpace", 0));
375 var videoSpace = parseInt(this._getDevLibProperty
376 (
"http://songbirdnest.com/device/1.0#videoUsedSpace", 0));
377 var imageSpace = parseInt(this._getDevLibProperty
378 (
"http://songbirdnest.com/device/1.0#imageUsedSpace", 0));
379 var usedSpace = parseInt(this._getDevLibProperty
380 (
"http://songbirdnest.com/device/1.0#totalUsedSpace", 0));
381 var totalSpace = usedSpace + freeSpace;
382 var otherSpace = usedSpace - musicSpace - videoSpace - imageSpace;
386 capTable.total = Math.max(0, totalSpace);
387 capTable.free = Math.max(0, freeSpace);
388 capTable.music = Math.max(0, musicSpace);
389 capTable.video = Math.max(0, videoSpace);
390 capTable.image = Math.max(0, imageSpace);
391 capTable.other = Math.max(0, otherSpace);
_getSelectedPageStyle s i