49 var
Cc = Components.classes;
50 var
Ci = Components.interfaces;
51 var
Cr = Components.results;
52 var
Cu = Components.utils;
55 Cu.import(
"resource://app/jsmodules/ArrayConverter.jsm");
56 Cu.import(
"resource://app/jsmodules/DOMUtils.jsm");
57 Cu.import(
"resource://app/jsmodules/StringUtils.jsm");
76 volumeListStabilizationTime: 1000,
87 _deviceInfoTable:
null,
88 _domEventListenerSet:
null,
102 initialize:
function sbDeviceVolumeSupport_initialize() {
110 func =
function onUnload(aEvent) { _this.finalize(); };
111 this._domEventListenerSet.add(
window,
"unload", func,
false,
true);
114 func =
function onLoad(aEvent) { _this._initialize(); };
115 this._domEventListenerSet.add(
window,
"load", func,
false,
true);
118 _initialize:
function sbDeviceVolumeSupport__initialize() {
120 this._deviceInfoTable = {};
124 .getService(
Ci.sbIDeviceEventTarget)
125 .QueryInterface(
Ci.sbIDeviceRegistrar);
131 var deviceRegistrar =
Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
132 .getService(
Ci.sbIDeviceRegistrar);
133 for each (device
in ArrayConverter.JSEnum(deviceRegistrar.devices)) {
134 this._addDevice(device.QueryInterface(
Ci.sbIDevice));
143 finalize:
function sbDeviceVolumeSupport_finalize() {
149 if (this._domEventListenerSet) {
150 this._domEventListenerSet.removeAll();
154 this._removeAllDevices();
157 this._deviceInfoTable =
null;
158 this._domEventListenerSet =
null;
175 onDeviceEvent:
function deviceVolumeSupport_onDeviceEvent(aEvent) {
179 case Ci.sbIDeviceEvent.EVENT_DEVICE_ADDED :
180 this._addDevice(aEvent.data.QueryInterface(
Ci.sbIDevice));
183 case Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED :
184 this._removeDevice(aEvent.data.QueryInterface(
Ci.sbIDevice));
187 case Ci.sbIDeviceEvent.EVENT_DEVICE_DEFAULT_LIBRARY_CHANGED :
188 case Ci.sbIDeviceEvent.EVENT_DEVICE_LIBRARY_ADDED :
189 case Ci.sbIDeviceEvent.EVENT_DEVICE_LIBRARY_REMOVED :
190 this._monitorDeviceVolumes(aEvent.origin.QueryInterface(
Ci.sbIDevice));
212 _addDevice:
function sbDeviceVolumeSupport__addDevice(aDevice) {
214 if (aDevice.id in
this._deviceInfoTable)
218 var deviceInfo = { device: aDevice };
221 this._deviceInfoTable[aDevice.id] = deviceInfo;
224 this._monitorDeviceVolumes(deviceInfo);
236 _removeDevice:
function sbDeviceVolumeSupport__removeDevice(aDeviceSpec) {
240 if (aDeviceSpec instanceof
Ci.sbIDevice) {
241 deviceInfo = this._deviceInfoTable[aDeviceSpec.id];
244 deviceInfo = aDeviceSpec
250 delete this._deviceInfoTable[deviceInfo.device.id];
253 if (deviceInfo.monitorVolumesTimeout) {
254 clearTimeout(deviceInfo.monitorVolumesTimeout);
255 deviceInfo.monitorVolumesTimeout =
null;
259 if (deviceInfo.notification) {
260 deviceInfo.notification.close();
261 deviceInfo.notification =
null;
271 _removeAllDevices:
function sbDeviceVolumeSupport__removeAllDevices() {
273 var deviceInfoList = [];
274 for each (deviceInfo
in this._deviceInfoTable) {
275 deviceInfoList.push(deviceInfo);
277 for each (deviceInfo
in deviceInfoList) {
278 this._removeDevice(deviceInfo);
291 _monitorDeviceVolumes:
292 function sbDeviceVolumeSupport__monitorDeviceVolumes(aDeviceSpec) {
296 if (aDeviceSpec instanceof
Ci.sbIDevice) {
297 deviceInfo = this._deviceInfoTable[aDeviceSpec.id];
300 deviceInfo = aDeviceSpec
306 var stable = this._isDeviceVolumeListStable(deviceInfo);
312 if (deviceInfo.monitorVolumesTimeout)
313 clearTimeout(deviceInfo.monitorVolumesTimeout);
317 var func =
function _monitorDeviceVolumesWrapper() {
318 deviceInfo.monitorVolumesTimeout =
null;
319 _this._monitorDeviceVolumes(deviceInfo);
321 deviceInfo.monitorVolumesTimeout =
322 setTimeout(func, this.volumeListStabilizationTime);
328 this._updateNotification(deviceInfo);
331 this._updateServicePane(deviceInfo);
334 this._checkForNewVolumes(deviceInfo);
348 _isDeviceVolumeListStable:
349 function sbDeviceVolumeSupport__isDeviceVolumeListStable(aDeviceInfo) {
352 var libraries = aDeviceInfo.device.content.libraries;
353 for (var
i = 0;
i < libraries.length;
i++) {
354 var library = libraries.queryElementAt(
i,
Ci.sbIDeviceLibrary);
355 volumeList.push(library.guid);
360 var volumeListChanged =
false;
361 if (!aDeviceInfo.volumeList ||
362 (aDeviceInfo.volumeList.length != volumeList.length)) {
363 volumeListChanged =
true;
366 for (var
i = 0;
i < volumeList.length;
i++) {
367 if (aDeviceInfo.volumeList[
i] != volumeList[
i]) {
368 volumeListChanged =
true;
376 if (volumeListChanged) {
377 aDeviceInfo.volumeList = volumeList;
378 aDeviceInfo.volumeListTimeStamp = Date.now();
384 var currentTime = Date.now();
385 if ((currentTime - aDeviceInfo.volumeListTimeStamp) <
386 this.volumeListStabilizationTime) {
404 function sbDeviceVolumeSupport__checkForNewVolumes(aDeviceInfo) {
406 var device = aDeviceInfo.device;
409 var volumeLibraryList = ArrayConverter.JSArray(device.content.libraries);
413 if (volumeLibraryList.length == 0)
417 var lastVolumeGUIDList = device.getPreference(
"last_volume_list",
null);
418 if (lastVolumeGUIDList) {
419 lastVolumeGUIDList = lastVolumeGUIDList.split(
",");
422 lastVolumeGUIDList = [];
426 var newVolumeLibraryList = [];
427 for each (var library
in volumeLibraryList) {
428 if (lastVolumeGUIDList.indexOf(library.guid) < 0)
429 newVolumeLibraryList.push(library);
435 if (!aDeviceInfo.notification &&
436 (newVolumeLibraryList.length > 0) &&
437 (volumeLibraryList.length > 1)) {
439 var volumeLibrary = newVolumeLibraryList[0];
442 var capacity = volumeLibrary.getProperty
443 (
"http://songbirdnest.com/device/1.0#capacity");
447 Cc[
"@songbirdnest.com/Songbird/Properties/UnitConverter/Storage;1"]
448 .createInstance(
Ci.sbIPropertyUnitConverter);
450 (
"device.new_volume_notification.label",
451 [ storageConverter.autoFormat(capacity, -1, 1),
460 label:
SBString(
"device.new_volume_notification.manage_button.label"),
462 SBString(
"device.new_volume_notification.manage_button.accesskey"),
463 callback:
function buttonCallback(aNotification, aButton) {
464 _this._doManageVolumes(device);
470 var notificationBox = SBGetApplicationNotificationBox();
471 if (notificationBox) {
472 aDeviceInfo.notification = notificationBox.appendNotification
476 notificationBox.PRIORITY_INFO_LOW,
482 var volumeGUIDList = [];
483 for each (var library
in volumeLibraryList)
484 volumeGUIDList.push(library.guid);
485 device.setPreference(
"last_volume_list", volumeGUIDList.join(
","));
494 _doManageVolumes:
function sbDeviceVolumeSupport__doManageVolumes(aDevice) {
496 var dsps =
Cc[
"@songbirdnest.com/servicepane/device;1"]
497 .getService(
Ci.sbIDeviceServicePaneService);
498 var deviceNode = dsps.getNodeForDevice(aDevice);
504 { manageVolumes:
"true" });
517 function sbDeviceVolumeSupport__updateNotification(aDeviceInfo) {
522 if (aDeviceInfo.notification) {
524 let notificationBox = SBGetApplicationNotificationBox();
525 let allNotifications = notificationBox.allNotifications;
526 let notificationPresent =
false;
527 for (let
i = 0;
i < allNotifications.length;
i++) {
528 if (aDeviceInfo.notification == allNotifications[
i]) {
529 notificationPresent =
true;
535 if (!notificationPresent)
536 aDeviceInfo.notification =
null;
542 if (aDeviceInfo.notification &&
543 (aDeviceInfo.device.content.libraries.length < 2)) {
544 aDeviceInfo.notification.close();
545 aDeviceInfo.notification =
null;
558 function sbDeviceVolumeSupport__updateServicePane(aDeviceInfo)
561 let invisible =
true;
563 invisible =
StringSet.contains(selected.className,
564 "non-default-library-node");
568 var dsps =
Cc[
"@songbirdnest.com/servicepane/device;1"]
569 .getService(
Ci.sbIDeviceServicePaneService);
570 var deviceNode = dsps.getNodeForDevice(aDeviceInfo.device);
577 sbDeviceVolumeSupport.initialize();
592 Cu.import(
"resource://app/jsmodules/StringUtils.jsm");
593 Cu.import(
"resource://app/jsmodules/WindowUtils.jsm");
597 var devicesWithEvents = {};
600 var notificationTable = {};
602 function deviceManagerListener(
event) {
604 var device =
event.origin;
605 if (!(device instanceof
Ci.sbIDevice)) {
609 var
msg =
SBString(
"transcode.error.notification.label");
611 switch (
event.type) {
612 case Ci.sbIDeviceEvent.EVENT_DEVICE_TRANSCODE_ERROR: {
613 let bag =
event.data;
614 if (!bag || !(bag instanceof
Ci.nsIPropertyBag2)) {
618 if (bag.hasKey(
"transcode-error")) {
619 let error = bag.get(
"transcode-error");
620 if ((error instanceof
Ci.nsIScriptError) &&
621 (error instanceof
Ci.sbITranscodeError))
623 devicesWithEvents[device.id] =
true;
628 case Ci.sbIDeviceEvent.EVENT_DEVICE_NOT_ENOUGH_FREESPACE: {
629 devicesWithEvents[device.id] =
true;
638 if (!(device.id in devicesWithEvents)) {
645 delete devicesWithEvents[device.id];
646 var notificationBox = SBGetApplicationNotificationBox();
648 if (!notificationBox || notificationTable[device.id])
652 label:
SBString(
"transcode.error.notification.detail.label"),
653 accessKey:
SBString(
"transcode.error.notification.detail.accesskey"),
654 callback:
function(notification, button) {
656 Cc[
"@songbirdnest.com/device/error-monitor-service;1"]
657 .getService(
Ci.sbIDeviceErrorMonitor);
658 let errorItems = deviceErrorMonitor.getDeviceErrors(device);
659 WindowUtils.openDialog
661 "chrome://songbird/content/xul/device/deviceErrorDialog.xul",
662 "device_error_dialog",
663 "chrome,centerscreen",
665 [
"", device, errorItems,
"syncing" ],
667 deviceErrorMonitor.clearErrorsForDevice(device);
668 delete notificationTable[device.id];
673 var notification = notificationBox.appendNotification(
676 "chrome://songbird/skin/device/error.png",
677 notificationBox.PRIORITY_CRITICAL_MEDIUM,
679 notificationTable[device.id] = notification;
680 var onNotificationCommand =
function(
event) {
681 let classes =
event.originalTarget.className.split(/\s+/);
682 if (classes.indexOf(
"messageCloseButton") > -1) {
685 Cc[
"@songbirdnest.com/device/error-monitor-service;1"]
686 .getService(
Ci.sbIDeviceErrorMonitor);
687 deviceErrorMonitor.clearErrorsForDevice(device);
688 delete notificationTable[device.id];
691 notification.addEventListener(
"command", onNotificationCommand,
false);
695 var deviceManager =
Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
696 .getService(
Ci.sbIDeviceEventTarget);
697 deviceManager.addEventListener(deviceManagerListener);
702 deviceManager.removeEventListener(deviceManagerListener);
703 delete deviceManager;
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
handlersMenuPopup addEventListener("command", this, false)
sbDeviceFirmwareAutoCheckForUpdate prototype _deviceManager
function DOMEventListenerSet()
function SBString(aKey, aDefault, aStringBundle)
this _contentSandbox label
sbDeviceVolumeSupport initialize()
function deviceErrorMonitor()
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
function DeviceTranscodeSupport()
return!aWindow arguments!aWindow arguments[0]
var sbDeviceVolumeSupport
this removeEventListener("load", this.__SS_restore, true)
function onUnload()
onUnload - called when the cover preview window unloads.
_getSelectedPageStyle s i