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 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
55 Cu.import(
"resource://app/jsmodules/WindowUtils.jsm");
82 MEDIA_TYPES_IN_TAB_DISPLAY_ORDER: [
"audio",
"video",
"image",
"none"],
88 _deviceErrorMonitor :
null,
91 _lastUpdateTimeout:
null,
93 _debug :
Application.prefs.getValue(
"songbird.device.errorInfoPanel.debug",
95 _log :
function DIPW__log(aMsg) {
97 dump(
"deviceInfoPanel-" + aMsg +
"\n");
107 initialize:
function DIPW__initialize(aWidget) {
108 this.
_log(
"initialize");
110 this._widget = aWidget;
113 this._panelBar = this._getElement(
"device_info_panel_bar");
116 document.addEventListener(
"sbDeviceProgress-ok-button-enter",
121 this._deviceID = this._widget.deviceID;
122 this._device = this._widget.device;
125 this._removePanels =
true;
128 this._deviceInitialize();
132 this._deviceErrorMonitor =
133 Cc[
"@songbirdnest.com/device/error-monitor-service;1"]
134 .getService(Ci.sbIDeviceErrorMonitor);
138 "@songbirdnest.com/Songbird/DataRemote;1",
154 finalize:
function DIPW_finalize() {
155 this.
_log(
"finalize");
157 if (this._deviceErrorMonitor) {
158 this._deviceErrorMonitor =
null;
161 this._deviceFinalize();
165 this._deviceID =
null;
166 this._panelBar =
null;
167 this._itemType =
null;
168 this._operationDR =
null;
184 _getCopyingState:
function DIPW__getCopyingState() {
185 if (this._itemType.intValue & TYPE.MUSIC)
186 return Ci.sbIDevice.STATE_COPYING_MUSIC;
187 else if (this._itemType.intValue & TYPE.VIDEO)
188 return Ci.sbIDevice.STATE_COPYING_VIDEO;
189 else if (this._itemType.intValue & TYPE.IMAGE)
190 return Ci.sbIDevice.STATE_COPYING_IMAGE;
192 return Ci.sbIDevice.STATE_IDLE;
204 _getDeviceState:
function DIPW__getDeviceState() {
206 var deviceState = this._device.state;
207 var substate = this._device.currentStatus.currentSubState;
208 var state = deviceState;
209 if (deviceState == Ci.sbIDevice.STATE_SYNCING) {
210 if (substate == Ci.sbIDevice.STATE_SYNCING_TYPE ||
211 substate == Ci.sbIDevice.STATE_COPY_PREPARING ||
212 substate == Ci.sbIDevice.STATE_SYNC_PLAYLIST ||
213 substate == Ci.sbIDevice.STATE_UPDATING ||
214 substate == Ci.sbIDevice.STATE_IDLE) {
217 else if (substate == Ci.sbIDevice.STATE_COPYING ||
218 substate == Ci.sbIDevice.STATE_DELETING ||
219 substate == Ci.sbIDevice.STATE_TRANSCODE) {
220 state = this._getCopyingState();
223 else if (deviceState == Ci.sbIDevice.STATE_TRANSCODE) {
224 state = this._getCopyingState();
228 else if (deviceState == Ci.sbIDevice.STATE_COPYING &&
229 substate == Ci.sbIDevice.STATE_IDLE) {
230 if (this._itemType.intValue == TYPE.NONE) {
231 state = Ci.sbIDevice.STATE_COPYING;
234 state = this._getCopyingState();
244 _supportsVideo:
function DIPW__supportsVideo() {
245 var capabilities = this._device.capabilities;
246 var sbIDC = Ci.sbIDeviceCapabilities;
248 if (capabilities.supportsContent(sbIDC.FUNCTION_VIDEO_PLAYBACK,
249 sbIDC.CONTENT_VIDEO)) {
263 _updateOperation:
function DIPW__updateOperation(aMediaType,
aState, aDirection) {
264 if (this._lastOperation !=
aState ||
265 this._lastDirection != aDirection) {
266 this._updateMediaInfoPanelState(aMediaType,
268 Ci.sbIDevice.STATE_SYNCING,
272 let panel = this._findMediaInfoPanel(aMediaType);
273 if (panel && panel.index != 0) {
274 this._removeMediaInfoPanelsAfter(aMediaType, aDirection);
275 this._updateMediaInfoPanelState(aMediaType,
277 Ci.sbIDevice.STATE_SYNCING,
282 for each (let type
in this.MEDIA_TYPES_IN_TAB_DISPLAY_ORDER) {
285 if (aMediaType == type) {
291 if (this._findMediaInfoPanel(type)) {
292 this._updateMediaInfoPanelState(type,
294 Ci.sbIDevice.STATE_IDLE,
298 this._lastOperation =
aState;
299 this._lastDirection = aDirection;
301 if (!this._panelBar.isShown)
302 this._panelBar.animateIn();
322 _update:
function DIPW__update() {
323 this.
_log(
"deviceInfoPanel._update");
324 var deviceType = this._device.parameters.getProperty(
"DeviceType");
325 var state = Ci.sbIDevice.STATE_IDLE;
326 if ((deviceType ==
"WPD") ||
327 (deviceType ==
"MTP") ||
328 (deviceType ==
"MSCUSB")) {
329 state = this._getDeviceState();
331 if (state != Ci.sbIDevice.STATE_IDLE &&
332 this._lastUpdateTimeout) {
333 clearTimeout(this._lastUpdateTimeout);
334 this._lastUpdateTimeout =
null;
338 var direction = this._operationDR.stringValue ==
"reading" ?
339 Ci.sbIDeviceStatus.IMPORT : Ci.sbIDeviceStatus.EXPORT;
340 this.
_log(
"state=" + state +
341 ", lastOperation=" + this._lastOperation +
342 ", direction=" + direction);
344 case Ci.sbIDevice.STATE_COPYING:
345 case Ci.sbIDevice.STATE_COPY_PREPARING:
346 case Ci.sbIDevice.STATE_SYNCING_TYPE:
349 case Ci.sbIDevice.STATE_SYNC_PREPARING:
351 this._panelBar.removeAllPanels();
352 if (this._panelBar.isShown)
353 this._panelBar.animateOut();
354 this._lastOperation = state;
355 this._lastDirection = direction;
358 case Ci.sbIDevice.STATE_IMAGESYNC_PREPARING:
359 this._lastOperation = state;
360 this._lastDirection = direction;
363 case Ci.sbIDevice.STATE_UPDATING:
364 case Ci.sbIDevice.STATE_DELETING:
365 var active = state == Ci.sbIDevice.STATE_UPDATING ||
366 state == Ci.sbIDevice.STATE_DELETING;
371 this._deviceErrorMonitor.clearErrorsForDevice(this._device);
375 if (this._removePanels) {
376 this._panelBar.removeAllPanels();
377 this._removePanels =
false;
381 if (this._itemType.intValue &&
382 !
this._panelBar.isShown)
383 this._panelBar.animateIn();
385 var completeAudio, completeVideo;
387 if ((this._itemType.intValue & TYPE.MUSIC) &&
388 !
this._findMediaInfoPanel(
"audio")) {
389 this._updateMediaInfoPanel(
"audio",
390 Ci.sbIDeviceStatus.EXPORT,
391 SBString(
"device.infoPanel.audio_sync"),
395 this._updateMediaInfoPanelState(
"audio",
396 Ci.sbIDeviceStatus.EXPORT,
397 Ci.sbIDevice.STATE_SYNCING,
402 if ((this._itemType.intValue & TYPE.VIDEO) &&
403 this._supportsVideo() &&
404 !this._findMediaInfoPanel(
"video")) {
405 this._updateMediaInfoPanel(
"video",
406 Ci.sbIDeviceStatus.EXPORT,
407 SBString(
"device.infoPanel.video_sync"),
411 this._updateMediaInfoPanelState(
"video",
412 Ci.sbIDeviceStatus.EXPORT,
413 Ci.sbIDevice.STATE_SYNCING,
416 completeAudio =
true;
418 if ((this._itemType.intValue & TYPE.IMAGE) &&
419 !
this._findMediaInfoPanel(
"image")) {
420 this._updateMediaInfoPanel(
"image",
421 Ci.sbIDeviceStatus.EXPORT,
422 SBString(
"device.infoPanel.image_sync"),
426 this._updateMediaInfoPanelState(
"image",
427 Ci.sbIDeviceStatus.EXPORT,
428 Ci.sbIDevice.STATE_SYNCING,
431 completeAudio =
true;
432 completeVideo =
true;
436 if (this._findMediaInfoPanel(
"audio")) {
437 this._updateMediaInfoPanelState(
"audio",
438 Ci.sbIDeviceStatus.EXPORT,
439 Ci.sbIDevice.STATE_IDLE,
444 if (this._findMediaInfoPanel(
"audio")) {
445 this._updateMediaInfoPanelState(
"audio",
446 Ci.sbIDeviceStatus.EXPORT,
447 Ci.sbIDevice.STATE_IDLE,
455 if (!this._itemType.intValue) {
456 this._lastOperation = state;
457 this._lastDirection = direction;
461 case Ci.sbIDevice.STATE_COPYING_MUSIC:
462 this._updateOperation(
"audio", state, direction);
465 case Ci.sbIDevice.STATE_COPYING_VIDEO:
466 this._updateOperation(
"video", state, direction);
469 case Ci.sbIDevice.STATE_SYNC_PLAYLIST:
471 this._lastOperation = state;
472 this._lastDirection = direction;
475 case Ci.sbIDevice.STATE_COPYING_IMAGE:
476 this._updateOperation(
"image", state, direction);
479 case Ci.sbIDevice.STATE_IDLE:
485 switch (this._lastOperation) {
486 case Ci.sbIDevice.STATE_SYNC_PLAYLIST:
487 case Ci.sbIDevice.STATE_IMAGESYNC_PREPARING:
488 case Ci.sbIDevice.STATE_COPYING_IMAGE:
489 case Ci.sbIDevice.STATE_COPYING_MUSIC:
490 case Ci.sbIDevice.STATE_COPYING_VIDEO:
491 case Ci.sbIDevice.STATE_SYNCING_TYPE:
492 case Ci.sbIDevice.STATE_COPY_PREPARING:
493 case Ci.sbIDevice.STATE_UPDATING:
494 case Ci.sbIDevice.STATE_DELETING:
497 for each (let type
in [
"audio",
"video",
"image",
"none"]) {
498 if (this._checkForDeviceErrors(type, Ci.sbIDeviceStatus.EXPORT)) {
499 this.
_log(
"Export errors for " + type);
500 this._updateMediaInfoPanelState(type,
501 Ci.sbIDeviceStatus.EXPORT,
505 if (!this._panelBar.isShown)
506 this._panelBar.animateIn();
508 if (this._checkForDeviceErrors(type, Ci.sbIDeviceStatus.IMPORT)) {
509 this.
_log(
"Import errors for " + type);
510 this._updateMediaInfoPanelState(type,
511 Ci.sbIDeviceStatus.IMPORT,
515 if (!this._panelBar.isShown)
516 this._panelBar.animateIn();
518 if (this._checkForDeviceErrors(type, 0)) {
519 this.
_log(
"Other errors for " + type);
520 this._updateMediaInfoPanelState(type,
525 if (!this._panelBar.isShown)
526 this._panelBar.animateIn();
532 case Ci.sbIDevice.STATE_CANCEL:
534 if (this._lastUpdateTimeout)
537 var _onLastUpdate =
function(
self) {
541 if (
self._findMediaInfoPanel(
"video")) {
542 self._updateMediaInfoPanelState(
"video",
544 Ci.sbIDevice.STATE_IDLE,
547 if (
self._findMediaInfoPanel(
"audio")) {
548 self._updateMediaInfoPanelState(
"audio",
550 Ci.sbIDevice.STATE_IDLE,
553 if (
self._findMediaInfoPanel(
"image")) {
554 self._updateMediaInfoPanelState(
"image",
556 Ci.sbIDevice.STATE_IDLE,
561 self._updateMediaInfoPanel(
"complete",
563 SBString(
"device.status.progress_complete"),
568 self._removePanels =
true;
570 self._lastOperation = state;
573 this._lastUpdateTimeout =
setTimeout(_onLastUpdate, 1000,
this);
578 this._lastOperation =
null;
579 this._lastDirection =
null;
580 if (this._panelBar.isShown)
581 this._panelBar.animateOut();
594 _removeMediaInfoPanel:
function DIPW__removeMediaInfoPanel(aMediaType,
597 while ((mediaPanel = this._findMediaInfoPanel(aMediaType)) !=
null) {
598 var index = mediaPanel.index;
599 this._panelBar.removePanelAt(index);
609 _removeMediaInfoPanelsAfter:
function DIPW__removeMediaInfoPanelAfter(
612 let panelCount = this._panelBar.panelCount;
613 for (var index = 0; index < panelCount; index++) {
614 var aPanel = this._panelBar.getPanelAtIndex(index);
616 aPanel.getAttribute(
"mediatype") == aMediaType &&
617 aPanel.getAttribute(
"direction") == aDirection) {
618 while (++index < panelCount) {
619 this._panelBar.removePanelAt(index);
635 _updateMediaInfoPanelState:
function DIPW__updateMediaInfoPanelState(
640 this.
_log(
"_updateMediaInfoPanelState(" + aMediaType +
643 ", " + aIsActive +
")");
645 var direction =
"sync";
646 if (aDirection == Ci.sbIDeviceStatus.IMPORT) {
647 direction =
"import";
649 var baseString =
"device.infoPanel." + aMediaType;
650 var hasErrors =
false;
652 case Ci.sbIDevice.STATE_IDLE:
653 hasErrors = this._checkForDeviceErrors(aMediaType);
654 this.
_log(
"hasErrors=" + hasErrors);
656 var mediaPanel = this._updateMediaInfoPanel(
662 mediaPanel.addEventListener(
"sbInfoPanel-icon-click",
665 mediaPanel.setAttribute(
"icon-clickable",
true);
668 var mediaPanel = this._updateMediaInfoPanel(
677 case Ci.sbIDevice.STATE_SYNCING:
678 var mediaPanel = this._updateMediaInfoPanel(
681 SBString(baseString +
"_" + direction +
"_progress"),
700 _updateMediaInfoPanel:
function DIPW__updateMediaInfoPanel(aMediaType,
705 this.
_log(
"_updateMediaInfoPanel(" + aMediaType +
", " +
710 var mediaPanel = this._findMediaInfoPanel(aMediaType);
711 if (mediaPanel ==
null) {
712 this.
_log(
"New panel");
713 mediaPanel = this._panelBar.appendPanel(aMediaLabel,
"", aIsActive);
714 mediaPanel.setAttribute(
"mediatype", aMediaType);
715 mediaPanel.setAttribute(
"direction", aDirection);
718 this.
_log(
"Existing panel: " + mediaPanel.label);
719 mediaPanel.label = aMediaLabel;
720 mediaPanel.active = aIsActive;
724 mediaPanel.setAttribute(
"state", aSyncState);
726 mediaPanel.removeAttribute(
"state");
729 mediaPanel.removeAttribute(
"icon-clickable");
740 _findMediaInfoPanel:
function DIPW__findMediaInfoPanel(aMediaType) {
741 var panelCount = this._panelBar.panelCount;
742 for (var index = 0; index < panelCount; index++) {
743 var aPanel = this._panelBar.getPanelAtIndex(index);
745 aPanel.getAttribute(
"mediatype") == aMediaType)
758 handleEvent:
function DIPW_handleEvent(aEvent) {
760 if (aEvent.type ==
"sbInfoPanel-icon-click") {
761 var
target = aEvent.target
763 if (target.hasAttribute(
"mediatype")) {
764 let mediaType = target.getAttribute(
"mediatype");
765 let direction = target.getAttribute(
"direction");
766 this.
_log(
"handleEvent: mediaType=" + mediaType +
", directionType=" + direction);
767 if (this._checkForDeviceErrors(mediaType, direction)) {
769 this._deviceErrorMonitor.getDeviceErrors(this._device,
772 WindowUtils.openDialog
774 "chrome://songbird/content/xul/device/deviceErrorDialog.xul",
775 "device_error_dialog",
776 "chrome,centerscreen",
778 [
"", this._device, errorItems, direction != Ci.sbIDeviceStatus.IMPORT ?
"syncing" :
"importing"],
782 aEvent.stopPropagation();
783 aEvent.preventDefault();
787 else if (aEvent.type ==
"sbDeviceProgress-ok-button-enter") {
788 this._panelBar.removeAllPanels();
789 if (this._panelBar.isShown)
790 this._panelBar.animateOut();
809 _getElement:
function DIPW__getElement(aElementID) {
810 return document.getAnonymousElementByAttribute(this._widget,
839 _deviceInitialize:
function DIPW__deviceInitialize() {
842 var deviceEventTarget = this._device;
843 deviceEventTarget.QueryInterface(Ci.sbIDeviceEventTarget);
844 deviceEventTarget.addEventListener(
this);
852 _deviceFinalize:
function DIPW__deviceFinalize() {
855 var deviceEventTarget = this._device;
856 deviceEventTarget.QueryInterface(Ci.sbIDeviceEventTarget);
857 deviceEventTarget.removeEventListener(
this);
866 _checkForDeviceErrors:
function DIPW__checkForDeviceErrors(aMediaType,
869 let hasErrors =
false;
871 hasErrors = this._deviceErrorMonitor.deviceHasErrors(this._device,
880 let hasImportErrors =
false;
881 let hasExportErrors =
false;
883 hasImportErrors = this._deviceErrorMonitor.deviceHasErrors
886 Ci.sbIDeviceStatus.IMPORT);
887 hasExportErrors = this._deviceErrorMonitor.deviceHasErrors
890 Ci.sbIDeviceStatus.EXPORT);
894 return (hasImportErrors || hasExportErrors);
904 onDeviceEvent :
function DIPW_onDeviceEvent(aEvent) {
905 switch (aEvent.type) {
906 case Ci.sbIDeviceEvent.EVENT_DEVICE_STATE_CHANGED:
907 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_WRITE_START:
908 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSFER_START:
function SBString(aKey, aDefault, aStringBundle)
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
function _log(aMsg, aMenuID)