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/sbLibraryUtils.jsm");
57 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
58 Cu.import(
"resource://app/jsmodules/StringUtils.jsm");
60 if (typeof(
XUL_NS) ==
"undefined")
61 var
XUL_NS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
79 _deviceSyncSettings:
null,
80 _mediaSyncSettings:
null,
82 _ignoreDevicePrefChanges:
false,
91 initialize:
function DeviceSyncWidget__initialize(aWidget) {
93 this._widget = aWidget;
95 this._mediaType = this._widget.getAttribute(
"contenttype") ||
"audio";
98 var syncAllLabel = this._getElement(
"content_auto_sync_all_radio");
99 syncAllLabel.label =
SBString(
"device.sync.sync_all.label." +
101 var importHeaderCheckbox = this._getElement(
"import_header_checkbox");
102 importHeaderCheckbox.setAttribute(
"label",
103 SBString(
"device.import.header.label." +
106 var syncHeaderCheckbox = this._getElement(
"sync_header_checkbox");
107 syncHeaderCheckbox.setAttribute(
"label",
108 SBString(
"device.sync.header.label." +
112 this._device = this._widget.device;
113 this._deviceLibrary = this._widget.devLib;
118 if (!this._deviceLibrary) {
123 this._deviceSyncSettings = this._deviceLibrary.syncSettings;
124 var mediaType = this._getMediaType(this._mediaType);
125 this._mediaSyncSettings = this._deviceSyncSettings
126 .getMediaSettings(mediaType);
127 this._deviceLibrary.addDeviceLibraryListener(
this);
130 var deviceEventTarget =
131 this._device.QueryInterface(Ci.sbIDeviceEventTarget);
132 deviceEventTarget.addEventListener(
this);
138 Ci.sbIMediaList.LISTENER_FLAGS_ITEMADDED |
139 Ci.sbIMediaList.LISTENER_FLAGS_AFTERITEMREMOVED |
140 Ci.sbIMediaList.LISTENER_FLAGS_ITEMUPDATED);
151 finalize:
function DeviceSyncWidget_finalize() {
156 if (this._deviceLibrary)
157 this._deviceLibrary.removeDeviceLibraryListener(
this);
161 var deviceEventTarget =
162 this._device.QueryInterface(Ci.sbIDeviceEventTarget);
163 deviceEventTarget.removeEventListener(
this);
167 this._deviceFinalize();
179 update:
function DeviceSyncWidget_update() {
181 if (!this._widget || this._ignoreDevicePrefChanges)
186 if (!this._deviceLibrary || !this._mediaSyncSettings) {
187 this._widget.setAttribute(
"hidden",
"true");
190 this._widget.removeAttribute(
"hidden");
194 if (this._device.isBusy) {
195 this._widget.setAttribute(
"disabled",
true);
198 this._widget.removeAttribute(
"disabled");
202 var syncPlaylistListVideoHeader =
203 this._getElement(
"content_auto_sync_playlist_duration");
204 syncPlaylistListVideoHeader.hidden = (this._mediaType !=
"video");
207 var syncPlaylistChildren = this._getElement(
"content_auto_sync_playlist_children");
210 while (syncPlaylistChildren.firstChild)
211 syncPlaylistChildren.removeChild(syncPlaylistChildren.firstChild);
214 var syncPlayLists = this._mediaSyncSettings.syncPlaylists;
215 for (var listIndex = 0; listIndex < syncPlayLists.length; listIndex++) {
216 var mediaList = syncPlayLists.queryElementAt(listIndex, Ci.sbIMediaList);
219 var guid = mediaList.guid;
223 if (this._mediaType ==
"video")
224 duration = this._syncPrefsCalcDuration(mediaList);
228 Cc[
"@songbirdnest.com/Songbird/Properties/Info/Duration;1"]
229 .createInstance(Ci.sbIDurationPropertyInfo);
230 duration = durationInfo.format(duration);
233 duration =
SBString(
"device.sync.duration.unavailable");
237 var readableName = mediaList.name;
238 var listType = mediaList.getListContentType();
239 if (listType == Ci.sbIMediaList.CONTENTTYPE_MIX)
244 var treeItem = document.createElementNS(XUL_NS,
"treeitem");
245 var treeRow = document.createElementNS(XUL_NS,
"treerow");
246 var treeCellCheck = document.createElementNS(XUL_NS,
"treecell");
247 var treeCellTitle = document.createElementNS(XUL_NS,
"treecell");
248 var treeCellDuration = document.createElementNS(XUL_NS,
"treecell");
251 treeRow.value = guid;
255 var isSelected = this._mediaSyncSettings.getPlaylistSelected(mediaList);
256 treeCellCheck.setAttribute(
"value", isSelected);
257 treeCellCheck.setAttribute(
"sbid",
258 "content_sync_playlist_checkcell." + guid);
261 treeCellTitle.setAttribute(
"label", readableName);
262 treeCellTitle.setAttribute(
"editable",
"false");
265 treeCellDuration.setAttribute(
"label", duration);
266 treeCellDuration.setAttribute(
"editable",
"false");
269 treeRow.appendChild(treeCellCheck);
270 treeRow.appendChild(treeCellTitle);
271 treeRow.appendChild(treeCellDuration);
274 treeItem.appendChild(treeRow);
277 syncPlaylistChildren.appendChild(treeItem);
281 var syncRadioGroup = this._getElement(
"content_auto_sync_type_radio_group");
282 var syncPlaylistTree = this._getElement(
"content_auto_sync_playlist_tree");
283 var importEnabledCheckbox = this._getElement(
"import_header_checkbox");
284 var syncEnabledCheckbox = this._getElement(
"sync_header_checkbox");
285 var syncGroupbox = this._getElement(
"content_management_groupbox");
289 importEnabledCheckbox.checked = this._mediaSyncSettings.import;
291 switch (this._mediaSyncSettings.mgmtType) {
292 case Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_NONE:
293 syncEnabledCheckbox.checked =
false;
294 syncPlaylistTree.setAttribute(
"disabled",
true);
295 syncRadioGroup.setAttribute(
"disabled",
true);
296 syncGroupbox.setAttribute(
"disabled",
true);
297 syncRadioGroup.selectedItem =
null;
300 case Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_ALL:
301 syncEnabledCheckbox.checked =
true;
302 syncPlaylistTree.setAttribute(
"disabled",
true);
303 syncRadioGroup.removeAttribute(
"disabled");
304 syncGroupbox.removeAttribute(
"disabled");
305 syncRadioGroup.selectedItem = this._getElement
306 (
"content_auto_sync_all_radio");
309 case Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_PLAYLISTS:
310 syncEnabledCheckbox.checked =
true;
311 syncPlaylistTree.removeAttribute(
"disabled");
312 syncRadioGroup.removeAttribute(
"disabled");
313 syncGroupbox.removeAttribute(
"disabled");
314 syncRadioGroup.selectedItem = this._getElement
315 (
"content_auto_sync_selected_radio");
332 onUIPrefChange:
function DeviceSyncWidget_onUIPrefChange(aNeedUpdate) {
334 if (this._widget.hasAttribute(
"disabled"))
338 this._ignoreDevicePrefChanges =
true;
340 var syncRadioGroup = this._getElement(
"content_auto_sync_type_radio_group");
341 var importEnabledCheckbox = this._getElement(
"import_header_checkbox");
342 var syncEnabledCheckbox = this._getElement(
"sync_header_checkbox");
345 this._mediaSyncSettings.import = importEnabledCheckbox.checked;
349 var oldMgmtType = this._mediaSyncSettings.mgmtType;
350 var newMgmtType = Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_NONE;
353 if (syncEnabledCheckbox.checked) {
356 if ((this._mediaType ==
"video") ||
357 (syncRadioGroup.selectedItem ==
358 this._getElement(
"content_auto_sync_selected_radio"))) {
359 newMgmtType = Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_PLAYLISTS;
361 else if (syncRadioGroup.selectedItem ==
362 this._getElement(
"content_auto_sync_all_radio")) {
363 newMgmtType = Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_ALL;
368 newMgmtType = this._mediaSyncSettings.lastActiveMgmtType;
372 if (oldMgmtType != newMgmtType) {
373 this._mediaSyncSettings.mgmtType = newMgmtType;
376 if (this._mediaSyncSettings.mgmtType ==
377 Ci.sbIDeviceLibraryMediaSyncSettings.SYNC_MGMT_PLAYLISTS) {
379 this._mediaSyncSettings.clearSelectedPlaylists();
382 var syncPlayLists = this._mediaSyncSettings.syncPlaylists;
383 for (var listIndex = 0; listIndex < syncPlayLists.length; listIndex++) {
384 var mediaList = syncPlayLists.queryElementAt(listIndex,
387 var guid = mediaList.guid;
388 var treeCellCheck = this._getElement(
389 "content_sync_playlist_checkcell." + guid);
392 var isSelected = (treeCellCheck.getAttribute(
"value") ==
"true");
394 var oldSelected = this._mediaSyncSettings
395 .getPlaylistSelected(mediaList);
397 if (oldSelected != isSelected)
398 this._mediaSyncSettings.setPlaylistSelected(mediaList,
407 this._deviceSyncSettings.write(this._device);
409 this._ignoreDevicePrefChanges =
false;
426 onBeforeCreateMediaItem:
function DeviceSyncWidget_onBeforeCreateMediaItem(
433 onBeforeCreateMediaList:
function DeviceSyncWidget_onBeforeCreateMediaList(
439 onBeforeAdd:
function DeviceSyncWidget_onBeforeAdd(aMediaItem) {
443 onBeforeAddAll:
function DeviceSyncWidget_onBeforeAddAll(aMediaList) {
447 onBeforeAddSome:
function DeviceSyncWidget_onBeforeAddSome(aMediaItems) {
451 onBeforeClear:
function DeviceSyncWidget_onBeforeClear() {
467 onDeviceEvent:
function DeviceSyncWidget_onDeviceEvent(aEvent) {
471 case Ci.sbIDeviceEvent.EVENT_DEVICE_PREFS_CHANGED:
472 case Ci.sbIDeviceEvent.EVENT_DEVICE_STATE_CHANGED:
473 case Ci.sbIDeviceEvent.EVENT_DEVICE_MOUNTING_END:
498 onItemAdded:
function DeviceSyncWidget_onItemAdded(aMediaList,
502 if (aMediaItem.getProperty(SBProperties.isList) &&
503 !aMediaItem.getProperty(SBProperties.hidden)) {
520 onBeforeItemRemoved:
function DeviceSyncWidget_onBeforeItemRemoved
537 onAfterItemRemoved:
function DeviceSyncWidget_onAfterItemRemoved
542 if (aMediaItem.getProperty(SBProperties.isList))
560 onItemUpdated:
function DeviceSyncWidget_onItemUpdated(aMediaList,
564 if (aMediaItem instanceof Ci.sbIMediaList)
581 function DeviceSyncWidget_onBeforeListCleared(aMediaList,
596 onListCleared:
function DeviceSyncWidget_onListCleared(aMediaList,
617 onBatchBegin:
function DeviceSyncWidget_onBatchBegin(aMediaList) {},
631 onBatchEnd:
function DeviceSyncWidget_onBatchEnd(aMediaList) {},
649 _getElement:
function DeviceSyncWidget__getElement(aElementID) {
650 return document.getAnonymousElementByAttribute(this._widget,
662 _getMediaType:
function DeviceSyncWidget__getMediaType(aMediaType)
664 var mediaType = Ci.sbIDeviceLibrary.MEDIATYPE_UNKOWN;
665 if (aMediaType ==
"audio")
666 mediaType = Ci.sbIDeviceLibrary.MEDIATYPE_AUDIO;
667 else if (aMediaType ==
"video")
668 mediaType = Ci.sbIDeviceLibrary.MEDIATYPE_VIDEO;
680 _syncPrefsCalcDuration:
681 function DeviceSyncWidget__syncPrefsCalcDuration(aMediaList) {
684 var contentDuration = -1;
685 var durationCounter = {
686 onEnumerationBegin :
function(aMediaList) {
687 return Ci.sbIMediaListEnumerationListener.CONTINUE;
689 onEnumeratedItem :
function(aMediaList, aMediaItem) {
690 var
duration = aMediaItem.getProperty(SBProperties.duration);
691 if (duration !=
null) {
692 contentDuration += parseFloat(duration);
694 return Ci.sbIMediaListEnumerationListener.CONTINUE;
696 onEnumerationEnd :
function(aMediaList, aStatusCode) {
700 aMediaList.enumerateItemsByProperty(SBProperties.contentType,
704 .ENUMERATIONTYPE_SNAPSHOT);
706 return contentDuration;
732 _deviceFinalize:
function DeviceSyncWidget__deviceFinalize() {
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
function SBString(aKey, aDefault, aStringBundle)
Javascript wrappers for common library tasks.