25 if (typeof(
Cc) ==
"undefined")
26 var
Cc = Components.classes;
27 if (typeof(
Ci) ==
"undefined")
28 var
Ci = Components.interfaces;
29 if (typeof(
Cr) ==
"undefined")
30 var
Cr = Components.results;
31 if (typeof(
Cu) ==
"undefined")
32 var
Cu = Components.utils;
34 Cu.import(
"resource://gre/modules/XPCOMUtils.jsm");
35 Cu.import(
"resource://app/jsmodules/ArrayConverter.jsm");
36 Cu.import(
"resource://app/jsmodules/DOMUtils.jsm");
37 Cu.import(
"resource://app/jsmodules/PlatformUtils.jsm");
38 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
40 const CDRIPNS =
'http://songbirdnest.com/rdf/servicepane/cdrip#';
41 const SPNS =
'http://songbirdnest.com/rdf/servicepane#';
45 const CDDEVICEMARSHALLNAME =
"sbCDDeviceMarshall";
48 className:
"Songbird CD Rip Device Support Module",
49 cid: Components.ID(
"{9925b565-5c19-4feb-87a8-413d86570cd9}"),
50 contractID:
"@songbirdnest.com/servicepane/cdDevice;1",
52 ifList: [ Ci.sbIServicePaneModule,
58 category:
"service-pane",
63 devCatName:
"CD Rip Device",
65 appQuitTopic:
"quit-application",
67 devMgrURL:
"chrome://songbird/content/mediapages/cdripMediaView.xul"
69 if (
"sbIWindowsAutoPlayActionHandler" in Ci) {
70 sbCDRipServicePaneServiceConfig.ifList.push(Ci.sbIWindowsAutoPlayActionHandler);
81 classID: sbCDRipServicePaneServiceConfig.cid,
82 contractID: sbCDRipServicePaneServiceConfig.contractID,
88 _deviceManagerSvc:
null,
89 _deviceServicePaneSvc:
null,
91 _servicePaneSvc:
null,
95 _deviceScanInProgress:
false,
100 servicePaneInit:
function sbCDRipServicePaneService_servicePaneInit(aServicePaneService) {
101 this._servicePaneSvc = aServicePaneService;
105 fillContextMenu:
function sbCDRipServicePaneService_fillContextMenu(aNode,
109 var deviceID = aNode.getAttributeNS(
CDRIPNS,
"DeviceId");
114 var deviceNodeType = aNode.getAttributeNS(
CDRIPNS,
"deviceNodeType");
117 if (deviceNodeType ==
"cd-device") {
118 DOMUtils.importChildElements(aContextMenu,
119 this._deviceContextMenuDoc,
120 "cddevice_context_menu_items",
121 {
"device-id": deviceID,
122 "service_pane_node_id": aNode.id });
126 fillNewItemMenu:
function sbCDRipServicePaneService_fillNewItemMenu(aNode,
131 onSelectionChanged:
function sbCDRipServicePaneService_onSelectionChanged(aNode,
136 canDrop:
function sbCDRipServicePaneService_canDrop(aNode,
144 onDrop:
function sbCDRipServicePaneService_onDrop(aNode,
151 onDragGesture:
function sbCDRipServicePaneService_onDragGesture(aNode,
156 onBeforeRename:
function sbCDRipServicePaneService_onBeforeRename(aNode) {
160 onRename:
function sbCDRipServicePaneService_onRename(aNode,
165 shutdown:
function sbCDRipServicePaneService_shutdown() {
172 observe:
function sbCDRipServicePaneService_observe(aSubject,
176 case this._cfg.appQuitTopic :
186 QueryInterface: XPCOMUtils.generateQI(sbCDRipServicePaneServiceConfig.ifList),
195 _initialize:
function sbCDRipServicePaneService_initialize() {
196 this._observerSvc = Cc[
"@mozilla.org/observer-service;1"]
197 .getService(Ci.nsIObserverService);
199 this._observerSvc.addObserver(
this, this._cfg.appQuitTopic,
false);
201 this._deviceServicePaneSvc = Cc[
"@songbirdnest.com/servicepane/device;1"]
202 .getService(Ci.sbIDeviceServicePaneService);
204 this._deviceManagerSvc = Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
205 .getService(Ci.sbIDeviceManager2);
208 var deviceEventListener = {
209 cdDeviceServicePaneSvc:
this,
211 onDeviceEvent:
function deviceEventListener_onDeviceEvent(aDeviceEvent) {
212 this.cdDeviceServicePaneSvc._processDeviceManagerEvent(aDeviceEvent);
216 this._deviceEventListener = deviceEventListener;
217 this._deviceManagerSvc.addEventListener(deviceEventListener);
220 this._deviceContextMenuDoc =
221 DOMUtils.loadDocument
222 (
"chrome://songbird/content/xul/device/deviceContextMenu.xul");
224 if (PlatformUtils.platformString ==
"Windows_NT") {
226 var autoPlayActionHandler = {
227 cdDeviceServicePaneSvc:
this,
229 handleAction:
function autoPlayActionHandler_handleAction(aAction, aActionArg) {
230 return this.cdDeviceServicePaneSvc._processAutoPlayAction(aAction);
233 QueryInterface: XPCOMUtils.generateQI([Ci.sbIWindowsAutoPlayActionHandler])
236 this._autoPlayActionHandler = autoPlayActionHandler;
237 var windowsAutoPlayService =
238 Cc[
"@songbirdnest.com/Songbird/WindowsAutoPlayService;1"]
239 .getService(Ci.sbIWindowsAutoPlayService);
240 windowsAutoPlayService.addActionHandler
241 (autoPlayActionHandler,
242 Ci.sbIWindowsAutoPlayService.ACTION_CD_RIP);
249 _shutdown:
function sbCDRipServicePaneService_shutdown() {
250 this._observerSvc.removeObserver(
this, this._cfg.appQuitTopic);
252 this._deviceManagerSvc.removeEventListener(this._deviceEventListener);
253 this._deviceEventListener =
null;
255 if (PlatformUtils.platformString ==
"Windows_NT") {
257 var windowsAutoPlayService =
258 Cc[
"@songbirdnest.com/Songbird/WindowsAutoPlayService;1"]
259 .getService(Ci.sbIWindowsAutoPlayService);
260 windowsAutoPlayService.removeActionHandler
261 (this._autoPlayActionHandler,
262 Ci.sbIWindowsAutoPlayService.ACTION_CD_RIP);
263 this._autoPlayActionHandler =
null;
267 this._deviceInfoList = [];
269 this._deviceManagerSvc =
null;
270 this._deviceServicePaneSvc =
null;
271 this._servicePaneSvc =
null;
272 this._observerSvc =
null;
279 _processDeviceManagerEvent:
280 function sbCDRipServicePaneService_processDeviceManagerEvent(aDeviceEvent) {
282 switch(aDeviceEvent.type) {
283 case Ci.sbIDeviceEvent.EVENT_DEVICE_SCAN_START:
284 var marshall = aDeviceEvent.origin.QueryInterface(Ci.sbIDeviceMarshall);
285 if (marshall.name == CDDEVICEMARSHALLNAME)
286 this._deviceScanInProgress =
true;
289 case Ci.sbIDeviceEvent.EVENT_DEVICE_SCAN_END:
290 var marshall = aDeviceEvent.origin.QueryInterface(Ci.sbIDeviceMarshall);
291 if (marshall.name == CDDEVICEMARSHALLNAME)
292 this._deviceScanInProgress =
false;
295 case Ci.sbIDeviceEvent.EVENT_DEVICE_ADDED:
296 var result = this._addDeviceFromEvent(aDeviceEvent);
302 this._loadCDViewFromEvent(aDeviceEvent);
305 case Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED:
306 this._removeDeviceFromEvent(aDeviceEvent);
309 case Ci.sbICDDeviceEvent.EVENT_CDLOOKUP_INITIATED:
310 this._updateState(aDeviceEvent,
true);
313 case Ci.sbICDDeviceEvent.EVENT_CDLOOKUP_COMPLETED:
314 this._updateState(aDeviceEvent,
false);
317 case Ci.sbICDDeviceEvent.EVENT_CDLOOKUP_METADATA_COMPLETE:
318 this._updateState(aDeviceEvent,
false);
321 case Ci.sbIDeviceEvent.EVENT_DEVICE_STATE_CHANGED:
322 this._updateState(aDeviceEvent,
false);
334 _processAutoPlayAction:
335 function sbCDRipServicePaneService_processAutoPlayAction(aAction) {
338 case Ci.sbIWindowsAutoPlayService.ACTION_CD_RIP:
341 var deviceNode =
null;
342 for each (let deviceInfo
in this._deviceInfoList) {
343 deviceNode = deviceInfo.svcPaneNode;
347 Cc[
'@mozilla.org/appshell/window-mediator;1']
348 .getService(Ci.nsIWindowMediator)
349 .getMostRecentWindow(
'Songbird:Main').gBrowser
368 _loadCDViewFromEvent:
369 function sbCDRipServicePaneService_loadCDViewFromEvent(aDeviceEvent) {
373 if (this._deviceScanInProgress)
376 var device = aDeviceEvent.data.QueryInterface(Ci.sbIDevice);
377 var
url = this._cfg.devMgrURL +
"?device-id=" + device.id;
378 Cc[
'@mozilla.org/appshell/window-mediator;1']
379 .getService(Ci.nsIWindowMediator)
380 .getMostRecentWindow(
'Songbird:Main').gBrowser
388 _updateState:
function sbCDRipServicePaneService__updateState(aDeviceEvent,
391 var device = aDeviceEvent.origin.QueryInterface(Ci.sbIDevice);
392 var deviceId = device.id;
393 var deviceType = device.parameters.getProperty(
"DeviceType");
396 if (deviceType !=
"CD")
399 if (device.state == Ci.sbIDevice.STATE_TRANSCODE) {
400 this._toggleReadOnly(
true, device);
402 else if (device.state == Ci.sbIDevice.STATE_IDLE) {
403 this._toggleReadOnly(
false, device);
406 if (typeof(this._deviceInfoList[deviceId]) !=
'undefined') {
407 var devNode = this._deviceInfoList[deviceId].svcPaneNode;
410 if (devNode.name != device.properties.friendlyName) {
411 devNode.name = device.properties.friendlyName;
415 devProperties = devNode.className.split(
" ");
416 devProperties = devProperties.filter(
function(aProperty) {
417 return aProperty !=
"busy";
421 if ((device.state != Ci.sbIDevice.STATE_CANCEL) &&
422 (aForceBusy || device.state != Ci.sbIDevice.STATE_IDLE)) {
424 devProperties = devProperties.filter(
function(aProperty) {
425 return aProperty !=
"successful" &&
426 aProperty !=
"unsuccessful";
428 devProperties.push(
"busy");
430 if (devNode.hasAttributeNS(
CDRIPNS,
"LastState")) {
431 var lastState = devNode.getAttributeNS(
CDRIPNS,
"LastState");
432 if (lastState == Ci.sbIDevice.STATE_TRANSCODE) {
433 if (this._checkErrors(device)) {
434 devProperties.push(
"unsuccessful");
435 }
else if (this._checkSuccess(device)){
436 devProperties.push(
"successful");
443 devNode.setAttributeNS(
CDRIPNS,
"LastState", device.state);
446 devNode.className = devProperties.join(
" ");
454 _getDeviceLibrary:
function sbCDRipServicePaneService__getDeviceLibrary(aDevice) {
456 var libraries = aDevice.content.libraries;
457 if (libraries.length < 1) {
459 Cu.reportError(
"Device " + aDevice.id +
" has no libraries!");
464 var deviceLibrary = libraries.queryElementAt(0, Ci.sbIMediaList);
465 if (!deviceLibrary) {
466 Cu.reportError(
"Unable to get library for device: " + aDevice.id);
470 return deviceLibrary;
479 _toggleReadOnly:
function sbCDRipServicePaneService__toggleReadOnly(aReadOnly,
481 var deviceLibrary = this._getDeviceLibrary(aDevice);
483 deviceLibrary.setProperty(SBProperties.isReadOnly,
484 (aReadOnly ?
"1" :
"0"));
492 _checkErrors:
function sbCDRipServicePaneService__checkErrors(aDevice) {
494 var deviceLibrary = this._getDeviceLibrary(aDevice);
500 Cc[
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
501 .createInstance(Ci.sbIMutablePropertyArray);
502 propArray.appendProperty(SBProperties.cdRipStatus,
"3|100");
503 propArray.appendProperty(SBProperties.shouldRip,
"1");
505 var rippedItems = deviceLibrary.getItemsByProperties(propArray);
506 errorCount = rippedItems.length;
508 catch (err
if err.result == Cr.NS_ERROR_NOT_AVAILABLE) {
514 Cu.reportError(
"ERROR GETTING TRANSCODE ERROR COUNT " + err);
517 return (errorCount > 0);
525 _checkSuccess:
function sbCDRipServicePaneService__checkErrors(aDevice) {
527 var deviceLibrary = this._getDeviceLibrary(aDevice);
528 var successCount = 0;
531 var propArray = Cc[
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
532 .createInstance(Ci.sbIMutablePropertyArray);
533 propArray.appendProperty(SBProperties.cdRipStatus,
"2|100");
534 propArray.appendProperty(SBProperties.shouldRip,
"1");
536 var rippedItems = deviceLibrary.getItemsByProperties(propArray);
537 successCount = rippedItems.length;
539 catch (err
if err.result == Cr.NS_ERROR_NOT_AVAILABLE) {
545 Cu.reportError(
"ERROR GETTING TRANSCODE SUCCESS COUNT " + err);
548 return (successCount > 0);
556 function sbCDRipServicePaneService_addDeviceFromEvent(aDeviceEvent) {
558 var device = aDeviceEvent.data.QueryInterface(Ci.sbIDevice);
559 var deviceType = device.parameters.getProperty(
"DeviceType");
562 if (deviceType !=
"CD")
566 this._addDevice(device);
579 _removeDeviceFromEvent:
580 function sbCDRipServicePaneService_removeDeviceFromEvent(aDeviceEvent) {
582 var device = aDeviceEvent.data.QueryInterface(Ci.sbIDevice);
583 var deviceType = device.parameters.getProperty(
"DeviceType");
586 if (deviceType !=
"CD")
590 this._removeDevice(device);
602 _addDevice:
function sbCDRipServicePaneService_addDevice(aDevice) {
603 var device = aDevice.QueryInterface(Ci.sbIDevice);
604 var devId = device.id;
607 var deviceType = device.parameters.getProperty(
"DeviceType");
608 if (deviceType !=
"CD") {
613 var devNode = this._deviceServicePaneSvc.createNodeForDevice2(device,
true);
614 devNode.setAttributeNS(
CDRIPNS,
"DeviceId", devId);
615 devNode.setAttributeNS(
CDRIPNS,
"deviceNodeType",
"cd-device");
616 devNode.className =
"cd-device";
617 devNode.contractid = this._cfg.contractID;
618 devNode.url = this._cfg.devMgrURL +
"?device-id=" + devId;
619 devNode.editable =
false;
620 devNode.name = device.properties.friendlyName;
622 this._deviceInfoList[devId] = {svcPaneNode: devNode};
629 _removeDevice:
function sbCDRipServicePaneService_removeDevice(aDevice) {
630 var device = aDevice.QueryInterface(Ci.sbIDevice);
631 var devId = device.id;
633 var devInfo = this._deviceInfoList[devId];
639 devInfo.svcPaneNode.parentNode.removeChild(devInfo.svcPaneNode);
642 delete this._deviceInfoList[devId];
sbLibraryImporterManagerCfg categoryList
sbOSDControlService prototype className
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
function sbCDRipServicePaneService()
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
var sbCDRipServicePaneServiceConfig
sbDownloadDeviceServicePaneModule prototype shutdown
sbDeviceServicePane prototype servicePaneInit
sbDeviceFirmwareAutoCheckForUpdate prototype classID
sbWindowsAutoPlayServiceCfg _xpcom_categories
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe
function NSGetModule(compMgr, fileSpec)