51 Components.utils.import(
"resource://app/jsmodules/ArrayConverter.jsm");
52 Components.utils.import(
"resource://app/jsmodules/StringUtils.jsm");
53 Components.utils.import(
"resource://app/jsmodules/WindowUtils.jsm");
54 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
63 if (typeof(
Cc) ==
"undefined")
64 var
Cc = Components.classes;
65 if (typeof(
Ci) ==
"undefined")
66 var
Ci = Components.interfaces;
67 if (typeof(
Cr) ==
"undefined")
68 var
Cr = Components.results;
88 className:
"Songbird iPod Device Event Handler Service",
89 cid: Components.ID(
"{adb505cb-75d9-4526-84df-5b69d6c571e9}"),
90 contractID:
"@songbirdnest.com/Songbird/IPDEventHandler;1",
91 ifList: [ Ci.nsIObserver, Ci.sbIDeviceEventListener ],
94 localeBundlePath:
"chrome://ipod/locale/IPodDevice.properties"
142 classID: sbIPDEventHandlerCfg.cid,
152 _eventQueueBusy:
false,
165 onDeviceEvent:
function sbIPDEventHandler_onDeviceEvent(aEvent) {
166 try { this._onDeviceEvent(aEvent); }
167 catch (ex) { dump(
"onDeviceEvent exception: " + ex +
168 " at " + ex.fileName +
169 ", line " + ex.lineNumber +
"\n"); }
172 _onDeviceEvent:
function sbIPDEventHandler__onDeviceEvent(aEvent) {
174 this._eventQueue.push(aEvent);
175 this._processEventQueue();
193 observe:
function sbIPDEventHandler_observe(aSubject, aTopic,
aData) {
194 try { this._observe(aSubject, aTopic,
aData); }
195 catch (ex) { dump(
"observe exception: " + ex +
"\n"); }
198 _observe:
function sbIPDEventHandler__observe(aSubject, aTopic,
aData) {
201 case "quit-application" :
202 this._handleAppQuit();
217 QueryInterface: XPCOMUtils.generateQI(sbIPDEventHandlerCfg.ifList),
230 _handleAppQuit:
function sbIPDEventHandler__handleAppQuit() {
240 _processEventQueue:
function sbIPDEventHandler__processEventQueue() {
242 if (this._eventQueueBusy)
246 this._eventQueueBusy =
true;
247 while (this._eventQueue.length > 0) {
248 var
event = this._eventQueue.shift();
251 this._eventQueueBusy =
false;
261 _handleEvent:
function sbIPDEventHandler__handleEvent(aEvent) {
263 switch(aEvent.type) {
264 case Ci.sbIDeviceEvent.EVENT_DEVICE_ADDED :
265 this._addDevice(aEvent.data.QueryInterface(Ci.sbIDevice));
268 case Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED :
269 this._removeDevice(aEvent.data.QueryInterface(Ci.sbIDevice));
272 case Ci.sbIIPDDeviceEvent.EVENT_IPOD_FAIRPLAY_NOT_AUTHORIZED :
273 this._handleFairPlayNotAuthorized(aEvent);
276 case Ci.sbIIPDDeviceEvent.EVENT_IPOD_NOT_INITIALIZED:
277 this._handleIPodNotInitialized(aEvent);
280 case Ci.sbIIPDDeviceEvent.EVENT_IPOD_UNSUPPORTED_FILE_SYSTEM:
281 this._handleIPodUnsupportedFileSystem(aEvent);
284 case Ci.sbIIPDDeviceEvent.EVENT_IPOD_HFSPLUS_READ_ONLY:
285 this._handleIPodHFSPlusReadOnly(aEvent);
288 case Ci.sbIDeviceEvent.EVENT_DEVICE_MOUNTING_END :
289 case Ci.sbIDeviceEvent.EVENT_DEVICE_MEDIA_WRITE_END :
290 this._processEventInfo(aEvent.origin.QueryInterface(Ci.sbIDevice));
305 _handleFairPlayNotAuthorized:
306 function sbIPDEventHandler__handleFairPlayNotAuthorized(aEvent) {
308 var device = aEvent.origin.QueryInterface(Ci.sbIDevice);
309 var fairPlayEvent = aEvent.QueryInterface(Ci.sbIIPDFairPlayEvent);
312 var devInfo = this._devInfoList[device.id];
315 if (!devInfo.fairPlayNotAuthorizedInfoList)
316 devInfo.fairPlayNotAuthorizedInfoList = [];
317 fairPlayNotAuthorizedInfoList = devInfo.fairPlayNotAuthorizedInfoList;
320 var fairPlayNotAuthorizedInfo =
322 userID: fairPlayEvent.userID,
323 accountName: fairPlayEvent.accountName,
324 userName: fairPlayEvent.userName,
325 mediaItem: fairPlayEvent.mediaItem
327 fairPlayNotAuthorizedInfoList.push(fairPlayNotAuthorizedInfo);
337 _handleIPodNotInitialized:
338 function sbIPDEventHandler__handleIPodNotInitialized(aEvent) {
339 function promptForDeviceName(aWindow) {
340 var stringBundle = Cc[
"@mozilla.org/intl/stringbundle;1"]
341 .getService(Ci.nsIStringBundleService)
342 .createBundle(
'chrome://ipod/locale/IPodDevice.properties');
344 var deviceName = {
value:
345 stringBundle.GetStringFromName(
'initialize.default_device_name') };
347 var
promptService = Cc[
"@songbirdnest.com/Songbird/Prompter;1"]
348 .getService(Ci.nsIPromptService);
349 var accept = promptService.prompt(aWindow,
350 stringBundle.GetStringFromName(
'initialize.title'),
351 stringBundle.GetStringFromName(
'initialize.prompt'),
352 deviceName,
null, {});
354 aEvent.data.QueryInterface(Ci.sbIDevice).properties.friendlyName
358 var
sbWindowWatcher = Cc[
"@songbirdnest.com/Songbird/window-watcher;1"]
359 .getService(Ci.sbIWindowWatcher);
360 sbWindowWatcher.
callWithWindow(
"Songbird:Main", promptForDeviceName,
false);
370 _handleIPodUnsupportedFileSystem:
371 function sbIPDEventHandler__handleIPodUnsupportedFileSystem(aEvent) {
373 var title =
SBString(
"ipod.dialog.unsupported_file_system.title",
376 var
msg =
SBString(
"ipod.dialog.unsupported_file_system.msg",
382 var dialogFunc =
function(aWindow) {
383 var prompter = Cc[
"@songbirdnest.com/Songbird/Prompter;1"]
384 .getService(Ci.nsIPromptService);
385 prompter.alert(aWindow, title, msg);
387 var
sbWindowWatcher = Cc[
"@songbirdnest.com/Songbird/window-watcher;1"]
388 .getService(Ci.sbIWindowWatcher);
389 sbWindowWatcher.
callWithWindow(
"Songbird:Main", dialogFunc,
false);
399 _handleIPodHFSPlusReadOnly:
400 function sbIPDEventHandler__handleIPodUnsupportedFileSystem(aEvent) {
402 var title =
SBString(
"ipod.dialog.hfsplus_read_only.title",
405 var
msg =
SBString(
"ipod.dialog.hfsplus_read_only.msg",
411 var dialogFunc =
function(aWindow) {
412 var prompter = Cc[
"@songbirdnest.com/Songbird/Prompter;1"]
413 .getService(Ci.nsIPromptService);
414 prompter.alert(aWindow, title, msg);
416 var
sbWindowWatcher = Cc[
"@songbirdnest.com/Songbird/window-watcher;1"]
417 .getService(Ci.sbIWindowWatcher);
418 sbWindowWatcher.
callWithWindow(
"Songbird:Main", dialogFunc,
false);
429 _processEventInfo:
function sbIPDEventHandler__processEventInfo(aDevice) {
431 this._processFairPlayNotAuthorizedEventInfo(aDevice);
442 _processFairPlayNotAuthorizedEventInfo:
443 function sbIPDEventHandler__processFairPlayNotAuthorizedEventInfo(aDevice) {
445 var devInfo = this._devInfoList[aDevice.id];
451 fairPlayNotAuthorizedInfoList = devInfo.fairPlayNotAuthorizedInfoList;
452 if (!fairPlayNotAuthorizedInfoList)
456 var trackInfoList = Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
457 .createInstance(Ci.nsIMutableArray);
458 for (var
i = 0;
i < fairPlayNotAuthorizedInfoList.length;
i++) {
460 var fairPlayNotAuthorizedInfo = fairPlayNotAuthorizedInfoList[
i];
461 var trackContentURL = fairPlayNotAuthorizedInfo
462 .mediaItem.contentSrc.QueryInterface(Ci.nsIURL);
465 var trackInfo = Cc[
"@mozilla.org/supports-string;1"]
466 .createInstance(Ci.nsISupportsString);
467 trackInfo.data = fairPlayNotAuthorizedInfo.accountName;
468 trackInfo.data +=
": " + decodeURIComponent(trackContentURL.fileName);
471 trackInfoList.appendElement(trackInfo,
false);
475 devInfo.fairPlayNotAuthorizedInfoList =
null;
478 var title =
SBString(
"ipod.dialog.fair_play_not_authorized_transfer.title",
483 [ aDevice.properties.friendlyName ],
488 (
"ipod.dialog.fair_play_not_authorized_transfer.list_label",
489 fairPlayNotAuthorizedInfoList.length,
496 var dialogFunc =
function(aWindow) {
497 WindowUtils.openModalDialog
499 "chrome://songbird/content/xul/device/deviceErrorDialog.xul",
500 "device_error_dialog",
502 [
"windowTitle=" + title +
503 ",listLabel=" + listLabel +
504 ",errorMsg=" + errorMsg,
510 var
sbWindowWatcher = Cc[
"@songbirdnest.com/Songbird/window-watcher;1"]
511 .getService(Ci.sbIWindowWatcher);
512 sbWindowWatcher.
callWithWindow(
"Songbird:Main", dialogFunc,
false);
526 _initialize:
function sbIPDEventHandler__initialize() {
528 this._devInfoList = {};
531 var stringBundleSvc = Cc[
"@mozilla.org/intl/stringbundle;1"]
532 .getService(Ci.nsIStringBundleService);
533 this._locale = stringBundleSvc.createBundle(this._cfg.localeBundlePath);
536 this._observerSvc = Cc[
"@mozilla.org/observer-service;1"]
537 .getService(Ci.nsIObserverService);
538 this._observerSvc.addObserver(
this,
"quit-application",
false);
541 this._devMgr = Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
542 .getService(Ci.sbIDeviceManager2);
545 this._devMgr.addEventListener(
this);
548 this._addAllConnectedDevices();
556 _finalize:
function sbIPDEventHandler__finalize() {
559 this._observerSvc.removeObserver(
this,
"quit-application");
563 this._devMgr.removeEventListener(
this);
566 this._removeAllDevices();
569 this._devInfoList =
null;
572 this._observerSvc =
null;
583 _addDevice:
function sbIPDEventHandler__addDevice(aDevice) {
585 var deviceID = aDevice.id;
586 if (this._devInfoList[deviceID])
590 if (aDevice.parameters.getProperty(
"DeviceType") !=
"iPod")
594 if (!aDevice.connected)
598 this._devInfoList[deviceID] = { device: aDevice };
608 _removeDevice:
function sbIPDEventHandler__removeDevice(aDevice) {
610 var deviceID = aDevice.id;
611 var devInfo = this._devInfoList[deviceID];
616 delete this._devInfoList[deviceID];
624 _addAllConnectedDevices:
function
625 sbIPDEventHandler__addAllConnectedDevices() {
626 var deviceList = ArrayConverter.JSArray(this._devMgr.devices);
627 for each (device
in deviceList) {
628 this._addDevice(device.QueryInterface(Ci.sbIDevice));
637 _removeAllDevices:
function sbIPDEventHandler__removeAllDevices() {
639 for (var deviceID in this._devInfoList)
640 this._removeDevice(this._devInfoList[deviceID].device);
sbLibraryImporterManagerCfg categoryList
function _handleEvent(aEvent)
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
sbOSDControlService prototype className
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function SBString(aKey, aDefault, aStringBundle)
function SBFormattedCountString(aKeyBase, aCount, aParams, aDefault, aStringBundle)
void callWithWindow(in AString aWindowType, in sbICallWithWindowCallback aCallback, [optional] in boolean aWait)
Call callback specified by aCallback with a window of the type specified by aWindowType. Wait until a window of the specified type is available or until shutdown. Call callback with null window on shutdown. Call callback on main thread. If aWait is true, don't return until callback is called.
sbDeviceFirmwareAutoCheckForUpdate prototype classID
sbWindowsAutoPlayServiceCfg _xpcom_categories
function sbIPDEventHandler()
_getSelectedPageStyle s i
function NSGetModule(compMgr, fileSpec)
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe