46 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
47 Components.utils.import(
"resource://app/jsmodules/ArrayConverter.jsm");
48 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
57 if (typeof(
Cc) ==
"undefined")
58 var
Cc = Components.classes;
59 if (typeof(
Ci) ==
"undefined")
60 var
Ci = Components.interfaces;
61 if (typeof(
Cr) ==
"undefined")
62 var
Cr = Components.results;
65 const IPODSP_NS =
"http://songbirdnest.com/rdf/ipod-servicepane#";
95 className:
"Songbird iPod Device Service Pane Service",
96 cid: Components.ID(
"{EC76F798-AB27-4B85-A2AD-0D794E0232F9}"),
97 contractID:
"@songbirdnest.com/servicepane/IPodDevice;1",
98 ifList: [ Ci.sbIServicePaneModule,
100 Ci.sbIDeviceEventListener ],
104 category:
"service-pane",
109 localeBundlePath:
"chrome://ipod/locale/IPodDevice.properties",
111 devURNPrefix:
"urn:device:",
112 libURNPrefix:
"urn:library:",
113 itemURNPrefix:
"urn:item:",
115 devImgURL:
"chrome://ipod/skin/icon_ipod_16x16.png",
116 devBusyImgURL:
"chrome://songbird/skin/icons/icon-busy.png",
117 devMgrURL:
"chrome://ipod/content/xul/iPodDeviceSummaryPage.xul"
168 _servicePaneSvc:
null,
169 _devServicePaneSvc:
null,
170 _libServicePaneSvc:
null,
187 servicePaneInit:
function IPD_SPS_servicePaneInit(aServicePaneService) {
189 this._servicePaneSvc = aServicePaneService;
202 fillContextMenu:
function IPD_SPS_fillContextMenu(aNode,
213 fillNewItemMenu:
function IPD_SPS_fillNewItemMenu(aNode,
223 onSelectionChanged:
function IPD_SPS_onSelectionChanged(aNode,
231 canDrop:
function IPD_SPS_canDrop(aNode,
240 onDrop:
function IPD_SPS_onDrop(aNode, aDragSession, aOrientation, aWindow) {
247 onDragGesture:
function IPD_SPS_onDragGesture(aNode, aDataTransfer) { },
254 onBeforeRename:
function IPD_SPS_onBeforeRename(aNode) {
265 onRename:
function IPD_SPS_onRename(aNode, aNewName) {
267 var deviceID = aNode.getAttributeNS(
IPODSP_NS,
"device-id");
270 var deviceInfo = this._devInfoList[deviceID];
273 var device = deviceInfo.device;
278 device.properties.friendlyName = aNewName;
284 shutdown:
function IPD_SPS_shutdown() {
299 onDeviceEvent:
function IPD_SPS_onDeviceEvent(aEvent) {
301 switch(aEvent.type) {
302 case Ci.sbIDeviceEvent.EVENT_DEVICE_ADDED :
303 this._addDevice(aEvent.data.QueryInterface(Ci.sbIDevice));
306 case Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED :
307 this._removeDevice(aEvent.data.QueryInterface(Ci.sbIDevice));
310 case Ci.sbIDeviceEvent.EVENT_DEVICE_STATE_CHANGED :
311 this._updateDevState(aEvent.origin.QueryInterface(Ci.sbIDevice));
314 case Ci.sbIDeviceEvent.EVENT_DEVICE_INFO_CHANGED :
315 this._updateDevInfo(aEvent.origin.QueryInterface(Ci.sbIDevice));
336 _rescanListMap:
null,
343 _sbIMLL_Initialize:
function IPD_SPS__sbIMLL_Initialize() {
344 this._inBatchMap = { };
345 this._rescanListMap = { };
353 _sbIMLL_Finalize:
function IPD_SPS__sbIMLL_Finalize() {
354 this._inBatchMap =
null;
355 this._rescanListMap =
null;
368 onItemAdded:
function IPD_SPS_onItemAdded(aMediaList, aMediaItem, aIndex) {
369 var returnVal =
false;
370 try { returnVal = this._onItemAdded(aMediaList, aMediaItem); }
371 catch (ex) { dump(
"onItemAdded exception: " + ex +
"\n"); }
375 _onItemAdded:
function IPD_SPS__onItemAdded(aMediaList, aMediaItem) {
376 var noFurtherNotifications =
false;
380 if (this._inBatchMap[aMediaList.guid]) {
381 this._rescanListMap[aMediaList.guid] =
true;
382 noFurtherNotifications =
true;
384 if (aMediaItem instanceof Components.interfaces.sbIMediaList)
385 this._addDevPlaylist(aMediaItem);
388 return noFurtherNotifications;
401 onBeforeItemRemoved:
function IPD_SPS_onBeforeItemRemoved(aMediaList,
404 var noFurtherNotifications =
false;
408 if (this._inBatchMap[aMediaList.guid]) {
409 this._rescanListMap[aMediaList.guid] =
true;
410 noFurtherNotifications =
true;
412 if (aMediaItem instanceof Components.interfaces.sbIMediaList)
413 this._removeDevPlaylist(aMediaItem);
416 return noFurtherNotifications;
429 onAfterItemRemoved:
function IPD_SPS_onAfterItemRemoved(aMediaList,
447 onItemUpdated:
function IPD_SPS_onItemUpdated(aMediaList,
464 onBeforeListCleared:
function IPD_SPS_onBeforeListCleared(aMediaList,
479 onListCleared:
function IPD_SPS_onListCleared(aMediaList,
481 var noFurtherNotifications =
false;
485 if (this._inBatchMap[aMediaList.guid]) {
486 this._rescanListMap[aMediaList.guid] =
true;
487 noFurtherNotifications =
true;
489 this._updateDevPlaylists(aMediaList);
492 return noFurtherNotifications;
507 onBatchBegin:
function IPD_SPS_onBatchBegin(aMediaList) {
509 this._inBatchMap[aMediaList.guid] =
true;
524 onBatchEnd:
function(aMediaList) {
526 delete this._inBatchMap[aMediaList.guid];
529 if (this._rescanListMap[aMediaList.guid]) {
530 this._updateDevPlaylists(aMediaList);
531 delete(this._rescanListMap[aMediaList.guid]);
550 observe:
function IPD_SPS_observe(aSubject, aTopic,
aData) {
551 try { this._observe(aSubject, aTopic,
aData); }
552 catch (ex) { dump(
"observe exception: " + ex +
"\n"); }
555 _observe:
function IPD_SPS__observe(aSubject, aTopic,
aData) {
558 case "quit-application" :
559 this._handleAppQuit();
584 _handleAppQuit:
function IPD_SPS__handleAppQuit() {
600 _initialize:
function IPD_SPS__initialize() {
602 this._devInfoList = {};
605 var stringBundleSvc = Cc[
"@mozilla.org/intl/stringbundle;1"]
606 .getService(Ci.nsIStringBundleService);
607 this._locale = stringBundleSvc.createBundle(this._cfg.localeBundlePath);
610 this._observerSvc = Cc[
"@mozilla.org/observer-service;1"]
611 .getService(Ci.nsIObserverService);
612 this._observerSvc.addObserver(
this,
"quit-application",
false);
615 this._libMgr = Cc[
"@songbirdnest.com/Songbird/library/Manager;1"]
616 .getService(Ci.sbILibraryManager);
619 this._devMgr = Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
620 .getService(Ci.sbIDeviceManager2);
621 this._devServicePaneSvc = Cc[
"@songbirdnest.com/servicepane/device;1"]
622 .getService(Ci.sbIDeviceServicePaneService);
623 this._libServicePaneSvc = Cc[
"@songbirdnest.com/servicepane/library;1"]
624 .getService(Ci.sbILibraryServicePaneService);
627 this._sbIMLL_Initialize();
630 this._devMgr.addEventListener(
this);
633 this._addAllConnectedDevices();
641 _finalize:
function IPD_SPS__finalize() {
643 this._observerSvc.removeObserver(
this,
"quit-application");
646 this._devMgr.removeEventListener(
this);
649 this._sbIMLL_Finalize();
652 this._removeAllDevices();
655 this._devInfoList =
null;
658 this._observerSvc =
null;
660 this._servicePaneSvc =
null;
661 this._libServicePaneSvc =
null;
669 _findDevInfoForDevLib :
function sbMSC_SPS_servicePaneInit(aDevLibId) {
670 for (prop in this._devInfoList) {
671 var devInfo = this._devInfoList[prop];
672 if (devInfo && devInfo.devLibId == aDevLibId) {
685 _addDevice:
function IPD_SPS__addDevice(aDevice) {
687 var deviceID = aDevice.id;
688 if (this._devInfoList[deviceID])
692 if (aDevice.parameters.getProperty(
"DeviceType") !=
"iPod")
696 if (!aDevice.connected)
700 this._devInfoList[deviceID] = {};
701 this._devInfoList[deviceID].playlistList = {};
702 this._devInfoList[deviceID].device = aDevice;
705 var devNode = this._devServicePaneSvc.createNodeForDevice2(aDevice,
true);
706 devNode.setAttributeNS(
IPODSP_NS,
"device-id", deviceID);
707 devNode.contractid = this._cfg.contractID;
708 devNode.name = aDevice.properties.friendlyName;
709 devNode.image = this._cfg.devImgURL;
710 devNode.hidden =
false;
711 devNode.url = this._cfg.devMgrURL +
"?device-id=" + deviceID;
712 devNode.editable =
true;
713 this._devInfoList[deviceID].svcPaneNode = devNode;
716 this._devServicePaneSvc.setFillDefaultContextMenu(devNode,
true);
724 devLib = aDevice.content.libraries.queryElementAt(0, Ci.sbILibrary);
725 devLib = this._libMgr.getLibrary(devLib.guid);
728 this._addDevLib(devLib, aDevice);
732 this._updateDevPlaylists(devLib);
742 _removeDevice:
function IPD_SPS__removeDevice(aDevice) {
744 var device = aDevice.QueryInterface(Ci.sbIDevice);
745 var deviceID = device.id;
746 var devInfo = this._devInfoList[deviceID];
751 if (devInfo.devLibId)
752 this._removeDevLib(aDevInfo);
755 if (devInfo.svcPaneNode) {
756 this._servicePaneSvc.removeNode(devInfo.svcPaneNode);
760 delete this._devInfoList[deviceID];
768 _addAllConnectedDevices:
function IPD_SPS__addAllConnectedDevices() {
769 var deviceList = ArrayConverter.JSArray(this._devMgr.devices);
770 for each (device
in deviceList) {
771 this._addDevice(device.QueryInterface(Ci.sbIDevice));
780 _removeAllDevices:
function IPD_SPS__removeAllDevices() {
782 for (var deviceID in this._devInfoList)
783 this._removeDevice(this._devInfoList[deviceID].device);
795 _addDevLib:
function IPD_SPS__addDevLib(aLibrary, aDevice) {
797 var deviceID = aDevice.id;
800 this._devInfoList[deviceID].devLibId = aLibrary.guid;
803 var devLibNode = this._devServicePaneSvc
804 .createLibraryNodeForDevice(aDevice, aLibrary);
805 this._devInfoList[deviceID].devLibNode = devLibNode;
808 this._devServicePaneSvc.setFillDefaultContextMenu(devLibNode,
true);
811 this._setNodeReadOnly(aDevice, devLibNode);
814 aLibrary.addListener(
this,
816 Ci.sbIMediaList.LISTENER_FLAGS_ALL &
817 ~Ci.sbIMediaList.LISTENER_FLAGS_ITEMUPDATED);
828 _removeDevLib:
function IPD_SPS__removeDevLib(aDevInfo) {
834 library = this._libMgr.getLibrary(aDevInfo.devLibId);
837 library.removeListener(
this);
850 _addDevPlaylist:
function IPD_SPS__addDevPlaylist(aMediaList) {
852 var devInfo = this._findDevInfoForDevLib(aMediaList.library.guid);
853 var playlistURN = this._cfg.itemURNPrefix + aMediaList.guid;
855 var device = devInfo.device;
858 if (devInfo.playlistList[playlistURN])
862 var playlistNode = this._libServicePaneSvc
863 .getNodeForLibraryResource(aMediaList);
865 playlistNode = this._servicePaneSvc.addNode(playlistURN,
866 this._servicePaneSvc.root,
871 this._setNodeReadOnly(device, playlistNode);
875 devInfo.svcPaneNode.appendChild(playlistNode);
878 devInfo.playlistList[playlistURN] = playlistNode;
889 _removeDevPlaylist:
function IPD_SPS__removeDevPlaylist(aMediaList) {
891 var devInfo = this._findDevInfoForDevLib(aMediaList.library.guid);
892 var playlistURN = this._cfg.itemURNPrefix + aMediaList.guid;
893 delete devInfo.playlistList[playlistURN];
904 _updateDevState:
function IPD_SPS__updateDevState(aDevice) {
906 if (!this._devInfoList[aDevice.id])
908 var devNode = this._devInfoList[aDevice.id].svcPaneNode;
911 devNodePropList = devNode.properties.split(
" ");
914 devNodePropList = devNodePropList.filter
915 (
function(aProperty) {
return aProperty !=
"busy"; });
916 if (aDevice.state != Ci.sbIDevice.STATE_IDLE)
917 devNodePropList.push(
"busy");
920 var deviceProperties = aDevice.properties.properties;
921 var accessCompatibility = deviceProperties.getPropertyAsAString(
922 "http://songbirdnest.com/device/1.0#accessCompatibility");
923 if (accessCompatibility ==
"ro") {
924 devNodePropList = devNodePropList.filter
925 (
function(aProperty) {
return aProperty !=
"read-only"; });
926 devNodePropList.push(
"read-only");
930 if (aDevice.state == Ci.sbIDevice.STATE_IDLE)
931 devNode.image = this._cfg.devImgURL;
933 devNode.image =
null;
936 devNode.properties = devNodePropList.join(
" ");
947 _updateDevInfo:
function IPD_SPS__updateDevInfo(aDevice) {
949 var devInfo = this._devInfoList[aDevice.id];
956 devInfo.svcPaneNode.name = aDevice.properties.friendlyName;
967 _updateDevPlaylists:
function IPD_SPS__updateDevPlaylists(aMediaList) {
971 onEnumerationBegin:
function() { },
972 onEnumerationEnd:
function() { },
973 onEnumeratedItem:
function(aList, aItem) {
974 this.itemList.push(aItem);
979 aMediaList.enumerateItemsByProperty(SBProperties.isList,
"1", enumListener);
982 var length = enumListener.itemList.length;
983 for (var
i = 0;
i < length;
i++) {
984 this._addDevPlaylist(enumListener.itemList[
i]);
998 _setNodeReadOnly:
function IPD_SPS__setNodeReadOnly(aDevice, aNode) {
1011 return XPCOMUtils.generateModule([
IPD_SPS]);
sbLibraryImporterManagerCfg categoryList
sbOSDControlService prototype className
function NSGetModule(compMgr, fileSpec)
function IPD_SPS()
Construct an iPod device service pane services object.
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
sbDownloadDeviceServicePaneModule prototype shutdown
sbDeviceServicePane prototype servicePaneInit
sbDeviceFirmwareAutoCheckForUpdate prototype classID
sbWindowsAutoPlayServiceCfg _xpcom_categories
const TYPE_X_SB_TRANSFER_MEDIA_LIST
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe