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;
56 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
57 Cu.import(
"resource://app/jsmodules/WindowUtils.jsm");
58 Cu.import(
"resource://app/jsmodules/sbTimeFormatter.jsm");
90 state: Ci.sbIDevice.STATE_IDLE,
97 state: Ci.sbIDevice.STATE_SYNCING,
98 localeSuffix:
"syncing",
99 progressMeterDetermined:
true,
100 canBeCompleted:
true,
101 showIdleMessage:
true,
104 preparingOnIdle:
true,
105 operationCanceled:
false
110 state: Ci.sbIDevice.STATE_SYNC_PREPARING,
111 localeSuffix:
"sync_preparing",
112 progressMeterUndetermined:
true,
113 canBeCompleted:
true,
114 showIdleMessage:
true,
117 operationCanceled:
false
122 state: Ci.sbIDevice.STATE_IMAGESYNC_PREPARING,
123 localeSuffix:
"imagesync_preparing",
124 progressMeterUndetermined:
true,
125 canBeCompleted:
true,
126 showIdleMessage:
true,
129 operationCanceled:
false
134 state: Ci.sbIDevice.STATE_COPYING,
135 localeSuffix:
"copying",
136 progressMeterDetermined:
true,
137 canBeCompleted:
true,
138 showIdleMessage:
true,
141 operationCanceled:
false
146 state: Ci.sbIDevice.STATE_DELETING,
147 localeSuffix:
"deleting",
148 progressMeterDetermined:
true,
149 canBeCompleted:
true,
150 showIdleMessage:
true,
153 operationCanceled:
false
158 state: Ci.sbIDevice.STATE_UPDATING,
159 localeSuffix:
"updating",
160 progressMeterDetermined:
true,
161 canBeCompleted:
true,
162 showIdleMessage:
true,
165 operationCanceled:
false
170 state: Ci.sbIDevice.STATE_MOUNTING,
171 localeSuffix:
"mounting",
172 progressMeterUndetermined:
true,
173 canBeCompleted:
true,
174 showIdleMessage:
false,
177 operationCanceled:
false
182 state: Ci.sbIDevice.STATE_DOWNLOADING,
183 localeSuffix:
"downloading",
184 progressMeterDetermined:
true,
185 canBeCompleted:
true,
186 showIdleMessage:
true,
189 operationCanceled:
false
194 state: Ci.sbIDevice.STATE_CANCEL,
195 localeSuffix:
"cancelling",
196 progressMeterUndetermined:
true,
197 canBeCompleted:
true,
198 showIdleMessage:
true,
201 operationCanceled:
true
206 state: Ci.sbIDevice.STATE_TRANSCODE,
207 localeSuffix:
"transcoding",
208 progressMeterDetermined:
true,
209 canBeCompleted:
true,
210 showIdleMessage:
true,
213 operationCanceled:
false
218 state: Ci.sbIDevice.STATE_FORMATTING,
219 localeSuffix:
"formatting",
220 progressMeterUndetermined:
true,
221 canBeCompleted:
true,
222 showIdleMessage:
true,
225 operationCanceled:
false
284 _deviceErrorMonitor :
null,
286 _deviceLibrary:
null,
289 _operationInfoTable:
null,
290 _lastIsTranscoding:
false,
291 _lastEventOperation: Ci.sbIDevice.STATE_IDLE,
292 _lastCompletedEventOperation: Ci.sbIDevice.STATE_IDLE,
293 _operationCanceled:
false,
294 _showProgress:
false,
296 _progressInfoBox:
null,
298 _cancelButtonBox:
null,
300 _progressMeter:
null,
301 _progressTextLabel:
null,
303 _idleErrorsLabel:
null,
308 _firstCopying:
false,
310 _transcodingStart: 0,
322 initialize:
function DPW__initialize(aWidget) {
324 this._widget = aWidget;
326 this._deviceErrorMonitor =
327 Cc[
"@songbirdnest.com/device/error-monitor-service;1"]
328 .getService(Ci.sbIDeviceErrorMonitor);
331 this._operationInfoTable = {};
332 for (var
i = 0;
i < this._cfg.operationInfoList.length;
i++) {
333 var operationInfo = this._cfg.operationInfoList[
i];
334 this._operationInfoTable[operationInfo.state] = operationInfo;
338 this._progressInfoBox = this._getElement(
"progress_information_box");
339 this._syncButton = this._getElement(
"sync_operation_button");
340 this._cancelButtonBox = this._getElement(
"cancel_operation_box");
341 this._finishButton = this._getElement(
"finish_progress_button");
342 this._progressMeter = this._getElement(
"progress_meter");
343 this._progressTextLabel = this._getElement(
"progress_text_label");
344 this._subProgressTextLabel = this._getElement(
"sub_progress_text_label")
345 this._idleBox = this._getElement(
"progress_idle_box");
347 this._finishButton.addEventListener(
"click", this._onButtonEvent,
false);
348 this._finishButton.addEventListener(
"keypress", this._onButtonEvent,
false);
351 this._deviceID = this._widget.deviceID;
352 this._device = this._widget.device;
353 this._deviceLibrary = this._widget.devLib;
357 if (this._deviceLibrary) {
358 this._deviceLibrary.addDeviceLibraryListener(
this);
359 this._deviceSyncSettings = this._deviceLibrary.syncSettings;
362 this._syncButton.setAttribute(
"disabled",
"true");
366 this._deviceInitialize();
370 "@songbirdnest.com/Songbird/DataRemote;1",
374 this._deviceID +
".status.totalcount",
null);
376 this._deviceID +
".status.workcount",
null);
378 this._deviceID +
".status.progress",
null);
380 this._deviceID +
".status.type",
null);
383 this._lastCompletedEventOperation = this._device.previousState;
386 var prefService = Cc[
'@mozilla.org/preferences-service;1']
387 .getService(Ci.nsIPrefBranch);
388 if (!this._device.isDirectTranscoding) {
390 let
key =
"device.transcoding.transfer.ratio";
391 this._ratio = prefService.getIntPref(key);
397 this._handleStateChanged({
data: this._device.state });
406 finalize:
function DPW_finalize() {
408 this._deviceFinalize();
411 if (this._deviceLibrary)
412 this._deviceLibrary.removeDeviceLibraryListener(
this);
418 this._deviceErrorMonitor =
null;
419 this._deviceID =
null;
420 this._deviceLibrary =
null;
421 this._operationInfoTable =
null;
422 this._progressInfoBox =
null;
423 this._idleBox =
null;
424 this._syncButton =
null;
425 this._cancelButtonBox =
null;
426 this._finishButton =
null;
427 this._progressMeter =
null;
428 this._progressTextLabel =
null;
429 this._idleLabel =
null;
430 this._idleErrorLabel =
null;
444 _update:
function DPW__update() {
446 var deviceState = this._device.state;
449 var deviceStateOperationInfo = this._getOperationInfo(deviceState);
450 if (deviceStateOperationInfo.updateBusy)
451 this._updateProgressBusy();
452 else if (deviceStateOperationInfo.updateIdle)
453 this._updateProgressIdle();
456 var cancelButtonHidden;
457 var finishButtonHidden;
458 if (deviceState == Ci.sbIDevice.STATE_CANCEL) {
460 cancelButtonHidden =
true;
461 finishButtonHidden =
true;
463 else if (deviceState == Ci.sbIDevice.STATE_IDLE) {
464 cancelButtonHidden =
true;
465 finishButtonHidden =
false;
467 cancelButtonHidden =
false;
468 finishButtonHidden =
true;
472 var hideProgress = !this._showProgress;
473 this._progressInfoBox.hidden = hideProgress;
474 this._idleBox.hidden = !hideProgress;
476 cancelButtonHidden =
true;
477 finishButtonHidden =
true;
484 this._cancelButtonBox.hidden = cancelButtonHidden;
485 this._finishButton.hidden = finishButtonHidden;
488 this._syncButton.hidden = this._showProgress;
493 if (!this._device.defaultLibrary) {
494 this._syncButton.setAttribute(
"disabled",
"true");
500 var disableSyncButton =
true;
501 for (var currMediaType = Ci.sbIDeviceLibrary.MEDIATYPE_AUDIO;
502 currMediaType < Ci.sbIDeviceLibrary.MEDIATYPE_COUNT;
504 var currMediaSettings = this._deviceSyncSettings
505 .getMediaSettings(currMediaType);
509 if (currMediaSettings.import ||
510 (currMediaSettings.mgmtType !=
511 Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_NONE)) {
512 disableSyncButton =
false;
517 if (disableSyncButton) {
518 this._syncButton.setAttribute(
"disabled",
"true");
521 this._syncButton.removeAttribute(
"disabled");
530 _updateProgressIdle:
function DPW__updateProgressIdle() {
531 this._lastProgress = 0;
532 this._lastIsTranscoding =
false;
535 var prefService = Cc[
'@mozilla.org/preferences-service;1']
536 .getService(Ci.nsIPrefBranch);
537 if (!this._device.isDirectTranscoding) {
538 let
key =
"device.transcoding.transfer.ratio";
539 prefService.setIntPref(key, this._ratio);
542 var oInfo = this._getOperationInfo(this._lastCompletedEventOperation);
549 if (oInfo.showIdleMessage) {
552 var
key =
"device.status.progress_completed";
555 var hasErrors = this._checkForDeviceErrors(
"");
556 if (this._operationCanceled) {
557 key =
"device.status.progress_aborted";
559 else if (hasErrors) {
565 this._progressTextLabel.value =
SBString(key,
"");
567 else if (this._lastCompletedEventOperation != Ci.sbIDevice.STATE_IDLE) {
569 this._lastCompletedEventOperation = Ci.sbIDevice.STATE_IDLE;
573 this._progressMeter.hidden =
true;
574 this._subProgressTextLabel.hidden =
true;
576 this._startTimestamp =
null;
577 this._lastTimeLeft = Infinity;
585 _getItemType:
function DPW__getItemType() {
586 if (this._itemType.intValue == 1)
588 else if (this._itemType.intValue == 2)
590 else if (this._itemType.intValue == 4)
601 _updateProgressBusy:
function DPW__updateProgressBusy() {
602 var localeKey, subLocaleKey;
605 var deviceStatus = this._device.currentStatus;
606 var operation = deviceStatus.currentState;
607 var substate = deviceStatus.currentSubState;
608 var curItemIndex = this._curItemIndex.intValue;
609 var totalItems = this._totalItems.intValue;
610 var
duration = deviceStatus.elapsedTime;
613 var operationInfo = this._getOperationInfo(operation);
614 var operationLocaleSuffix = operationInfo.localeSuffix;
617 this._progressMeter.hidden =
false;
618 this._subProgressTextLabel.hidden =
false;
620 if (!this._startTimestamp) {
621 this._startTimestamp =
new Date();
622 this._lastTimeLeft = Infinity;
625 if (deviceStatus.isNewBatch)
628 deviceStatus.isNewBatch =
false;
634 if (operationInfo.progressMeterDetermined) {
637 if ((totalItems > 0) &&
638 (curItemIndex > 0) &&
639 (curItemIndex <= totalItems))
641 progress = (curItemIndex - 1) / totalItems;
646 if (curItemIndex != 0) {
647 let increase = (this._itemProgress.intValue / 100) / totalItems;
651 if (!this._device.isDirectTranscoding) {
656 if (operation == Ci.sbIDevice.STATE_TRANSCODE ||
657 substate == Ci.sbIDevice.STATE_TRANSCODE) {
658 if (this._itemProgress.intValue == 0) {
659 this._lastIsTranscoding =
true;
660 this._firstCopying =
true;
664 if (curItemIndex > 1) {
666 let transcodingDuration =
667 this._transcodingEnd - this._transcodingStart;
668 let copyingDuration =
669 this._copyingEnd - this._copyingStart;
672 if (curItemIndex == 2) {
673 this._ratio = transcodingDuration / copyingDuration + 0.5;
674 if (!this._ratio) this._ratio = 1;
678 this._ratio = this._ratio * (curItemIndex - 2) + 0.5 +
679 transcodingDuration / copyingDuration;
680 this._ratio /= (curItemIndex - 1);
681 if (!this._ratio) this._ratio = 1;
687 let divisor = totalItems * (1 / this._ratio + 1);
688 increase = (this._itemProgress.intValue / 100) / divisor;
690 else if (this._lastIsTranscoding &&
691 (operation == Ci.sbIDevice.STATE_COPYING ||
692 substate == Ci.sbIDevice.STATE_COPYING)) {
693 if (this._itemProgress.intValue == 0) {
698 let divisor = totalItems * (this._ratio + 1);
704 if (this._firstCopying) {
705 this._firstCopying =
false;
706 increase = this._ratio / divisor;
710 (this._itemProgress.intValue / 100 + this._ratio) / divisor;
715 progress += increase;
722 if (progress > this._lastProgress)
723 this._lastProgress = progress;
725 progress = this._lastProgress;
727 eta = (duration / progress) - duration;
728 etaString = TimeFormatter.formatHMS(eta / 1000);
731 this._lastProgress = progress;
734 this._progressMeter.setAttribute(
"mode",
"determined");
736 this._progressMeter.value = Math.round(progress * 100);
737 }
else if (operationInfo.progressMeterUndetermined) {
738 this._progressMeter.setAttribute(
"mode",
"undetermined");
739 this._progressMeter.value = 0;
741 this._progressMeter.setAttribute(
"mode",
"determined");
742 this._progressMeter.value = 0;
756 var itemType = this._getItemType();
758 var isPlaylist = deviceStatus.mediaItem instanceof Ci.sbIMediaList;
762 if (operationInfo.preparingOnIdle && (substate == Ci.sbIDevice.STATE_IDLE))
764 localeKey =
"device.status.progress_header_" + operationLocaleSuffix;
766 localeKey = localeKey +
"." + itemType;
767 subLocaleKey =
"device.status.progress_preparing_" + operationLocaleSuffix;
768 }
else if (operation == Ci.sbIDevice.STATE_TRANSCODE ||
769 substate == Ci.sbIDevice.STATE_TRANSCODE) {
770 localeKey =
"device.status.progress_header_transcoding";
772 localeKey = localeKey +
"." + itemType;
773 }
else if (operation == Ci.sbIDevice.STATE_SYNCING &&
774 substate == Ci.sbIDevice.STATE_DELETING) {
777 localeKey =
"device.status.progress_header_deleting";
780 localeKey =
"device.status.progress_header_syncing";
781 subLocaleKey =
"device.status.progress_footer_syncing_finishing";
783 }
else if (operation == Ci.sbIDevice.STATE_CANCEL) {
784 localeKey =
"device.status.progress_header_cancelling";
785 }
else if (operation == Ci.sbIDevice.STATE_SYNCING &&
786 substate == Ci.sbIDevice.STATE_SYNC_PLAYLIST) {
787 localeKey =
"device.status.progress_header_" + operationLocaleSuffix;
788 subLocaleKey =
"device.status.progress_footer_syncing_finishing";
789 this._progressMeter.setAttribute(
"mode",
"undetermined");
790 }
else if (operation == Ci.sbIDevice.STATE_COPYING ||
791 substate == Ci.sbIDevice.STATE_COPYING) {
792 localeKey =
"device.status.progress_header_copying";
794 localeKey = localeKey +
"." + itemType;
796 localeKey =
"device.status.progress_header_" + operationLocaleSuffix;
800 subLocaleKey = etaString ?
"device.status.progress_detail"
801 :
"device.status.progress_item_index";
805 this._progressTextLabel.value =
SBString(localeKey,
"");
806 if (curItemIndex > 0 && curItemIndex <= totalItems &&
807 operation != Ci.sbIDevice.STATE_MOUNTING &&
808 operation != Ci.sbIDevice.STATE_CANCEL &&
809 substate != Ci.sbIDevice.STATE_SYNCING &&
810 substate != Ci.sbIDevice.STATE_COPY_PREPARING &&
811 substate != Ci.sbIDevice.STATE_UPDATING &&
812 substate != Ci.sbIDevice.STATE_SYNCING_TYPE) {
813 let params = [curItemIndex, totalItems, etaString];
814 this._subProgressTextLabel.value =
817 this._subProgressTextLabel.value =
null;
834 onAction:
function DPW_onAction(aEvent) {
836 switch (aEvent.target.getAttribute(
"action")) {
854 _onButtonEvent:
function DPW__onButtonEvent(aEvent) {
856 if ((aEvent.type ==
"click" && aEvent.button == 0) ||
857 (aEvent.type ==
"keypress" &&
858 (aEvent.keyCode == KeyEvent.DOM_VK_ENTER ||
859 aEvent.keyCode == KeyEvent.DOM_VK_RETURN))) {
860 var newEvent = document.createEvent(
"Events");
861 newEvent.initEvent(
"sbDeviceProgress-ok-button-enter",
false,
true);
862 document.dispatchEvent(newEvent);
872 onBatchBegin:
function DeviceSyncWidget_onBatchBegin(aMediaList) {},
873 onBatchEnd:
function DeviceSyncWidget_onBatchEnd(aMediaList) {},
874 onItemAdded:
function DeviceSyncWidget_onItemAdded(aMediaList, aMediaItem, aIndex) {
return true; },
875 onBeforeItemRemoved:
function DeviceSyncWidget_onBeforeItemRemoved(aMediaList, aMediaItem, aIndex) {
return true; },
876 onAfterItemRemoved:
function DeviceSyncWidget_onAfterItemRemoved(aMediaList, aMediaItem, aIndex) {
return true; },
877 onBeforeListCleared:
function DeviceSyncWidget_onBeforeListCleared(aMediaList, aExcludeLists) {
return true; },
878 onListCleared:
function DeviceSyncWidget_onListCleared(aMediaList, aExcludeLists) {
return true; },
879 onItemUpdated:
function DeviceSyncWidget_onItemUpdated(aMediaList, aMediaItem, aProperties) {
return true; },
880 onItemMoved:
function DeviceSyncWidget_onItemMoved(aMediaList, aFromIndex, aToIndex) {
return true; },
881 onItemCopied:
function DeviceSyncWidget_onItemCopied(aSourceItem, aDestItem) {
return true; },
882 onBeforeCreateMediaItem:
function DeviceSyncWidget_onBeforeCreateMediaItem(aContentUri, aProperties, aAllowDuplicates) {
return true; },
883 onBeforeCreateMediaList:
function DeviceSyncWidget_onBeforeCreateMediaList(aType, aProperties) {
return true; },
884 onBeforeAdd:
function DeviceSyncWidget_onBeforeAdd(aMediaItem) {
return true; },
885 onBeforeAddAll:
function DeviceSyncWidget_onBeforeAddAll(aMediaList) {
return true; },
886 onBeforeAddSome:
function DeviceSyncWidget_onBeforeAddSome(aMediaItems) {
return true; },
887 onBeforeClear:
function DeviceSyncWidget_onBeforeClear() {
return true; },
902 _handleStateChanged:
function DPW__handleStateChanged(aEvent) {
904 var prevLastEventOperation = this._lastEventOperation;
905 this._lastEventOperation = aEvent.data;
908 var lastEventOperationInfo = this._getOperationInfo
909 (this._lastEventOperation);
910 var prevLastEventOperationInfo = this._getOperationInfo
911 (prevLastEventOperation);
914 if (lastEventOperationInfo.showProgress)
915 this._showProgress =
true;
918 if (
"operationCanceled" in lastEventOperationInfo)
919 this._operationCanceled = lastEventOperationInfo.operationCanceled;
922 if (prevLastEventOperationInfo.canBeCompleted)
923 this._lastCompletedEventOperation = prevLastEventOperation;
945 _getElement:
function DIW__getElement(aElementID) {
946 return document.getAnonymousElementByAttribute(this._widget,
962 _finish:
function DPW__finish() {
964 this._showProgress =
false;
979 _getOperationInfo:
function DPW__getOperationInfo(aOperation) {
980 var operationInfo = this._operationInfoTable[aOperation];
983 return operationInfo;
1002 _deviceInitialize:
function DPW__deviceInitialize() {
1005 var deviceEventTarget = this._device;
1006 deviceEventTarget.QueryInterface(Ci.sbIDeviceEventTarget);
1007 deviceEventTarget.addEventListener(
this);
1015 _deviceFinalize:
function DPW__deviceFinalize() {
1018 var currentState = this._device.currentStatus.currentState;
1020 var deviceEventTarget = this._device;
1021 deviceEventTarget.QueryInterface(Ci.sbIDeviceEventTarget);
1022 deviceEventTarget.removeEventListener(
this);
1024 this._device =
null;
1036 _getPrefValue :
function DPW__getPrefValue(aPrefID, aDefaultValue) {
1037 var prefService = Cc[
'@mozilla.org/preferences-service;1']
1038 .getService(Ci.nsIPrefBranch);
1040 return prefService.getCharPref(aPrefID);
1042 return aDefaultValue;
1052 onDeviceEvent :
function DPW_onDeviceEvent(aEvent) {
1053 switch (aEvent.type) {
1054 case Ci.sbIDeviceEvent.EVENT_DEVICE_STATE_CHANGED:
1055 this._handleStateChanged(aEvent);
1058 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSFER_START:
1059 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSFER_PROGRESS:
1060 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSFER_END:
1061 case Ci.sbIDeviceEvent.EVENT_DEVICE_MOUNTING_START:
1062 case Ci.sbIDeviceEvent.EVENT_DEVICE_MOUNTING_PROGRESS:
1063 case Ci.sbIDeviceEvent.EVENT_DEVICE_MOUNTING_END:
1064 case Ci.sbIDeviceEvent.EVENT_DEVICE_PREFS_CHANGED:
1065 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSCODE_START:
1066 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSCODE_PROGRESS:
1067 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSCODE_END:
1068 case Ci.sbIDeviceEvent.EVENT_DEVICE_FORMATTING_START:
1069 case Ci.sbIDeviceEvent.EVENT_DEVICE_FORMATTING_PROGRESS:
1070 case Ci.sbIDeviceEvent.EVENT_DEVICE_FORMATTING_END:
1071 case Ci.sbIDeviceEvent.EVENT_DEVICE_DOWNLOAD_START:
1072 case Ci.sbIDeviceEvent.EVENT_DEVICE_DOWNLOAD_PROGRESS:
1073 case Ci.sbIDeviceEvent.EVENT_DEVICE_DOWNLOAD_END:
1086 _deviceGetStatusDRPrefix:
function DPW__deviceGetStatusDRPrefix() {
1087 return "device." + this._deviceID +
".status";
1097 _deviceIsIdle:
function DPW__deviceIsIdle() {
1098 return this._isIdle;
1104 _deviceIsSyncing:
function DPW__deviceIsSyncing() {
1105 return this._isSyncing;
1111 _checkForDeviceErrors:
function DIPW__checkForDeviceErrors() {
1112 var hasErrors =
false;
1114 hasErrors = this._deviceErrorMonitor.deviceHasErrors(this._device,
1118 Cu.reportError(err);
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
function SBString(aKey, aDefault, aStringBundle)
_getSelectedPageStyle s i