25 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
26 Components.utils.import(
"resource://app/jsmodules/DropHelper.jsm");
27 Components.utils.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
28 Components.utils.import(
"resource://app/jsmodules/SBUtils.jsm");
29 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
32 const Ci = Components.interfaces;
33 const Cc = Components.classes;
34 const Cr = Components.results;
37 "@songbirdnest.com/Songbird/Library/medialistduplicatefilter;1";
51 "SBPlaylistCommand_AddToDevice" ];
61 var unwrapper =
Cc[
"@songbirdnest.com/Songbird/Library/EnumeratorWrapper;1"]
62 .createInstance(
Ci.sbIMediaListEnumeratorWrapper);
63 unwrapper.initialize(aSelection);
107 m_Keycodes:
new Array
112 m_Enableds:
new Array
117 m_Modifiers:
new Array
122 m_PlaylistCommands:
new Array
127 m_DeviceIds:
new Array
133 _getMenu:
function(aSubMenu)
137 cmds = this.m_addToDevice.handleGetMenu(aSubMenu);
138 if (cmds)
return cmds;
148 getVisible:
function(
aHost )
150 return this.m_addToDevice.hasDevices();
153 getNumCommands:
function( aSubMenu,
aHost )
155 var cmds = this._getMenu(aSubMenu);
156 return cmds.m_Ids.length;
159 getCommandId:
function( aSubMenu, aIndex,
aHost )
161 var cmds = this._getMenu(aSubMenu);
162 if ( aIndex >= cmds.m_Ids.length )
return "";
163 return cmds.m_Ids[ aIndex ];
166 getCommandType:
function( aSubMenu, aIndex,
aHost )
168 var cmds = this._getMenu(aSubMenu);
169 if ( aIndex >= cmds.m_Ids.length )
return "";
170 return cmds.m_Types[ aIndex ];
173 getCommandText:
function( aSubMenu, aIndex,
aHost )
175 var cmds = this._getMenu(aSubMenu);
176 if ( aIndex >= cmds.m_Names.length )
return "";
177 return cmds.m_Names[ aIndex ];
180 getCommandFlex:
function( aSubMenu, aIndex,
aHost )
182 var cmds = this._getMenu(aSubMenu);
183 if ( cmds.m_Types[ aIndex ] ==
"separator" )
return 1;
187 getCommandToolTipText:
function( aSubMenu, aIndex,
aHost )
189 var cmds = this._getMenu(aSubMenu);
190 if ( aIndex >= cmds.m_Tooltips.length )
return "";
191 return cmds.m_Tooltips[ aIndex ];
194 getCommandValue:
function( aSubMenu, aIndex,
aHost )
203 refreshCustomCommand:
function( aElement, aId,
aHost )
207 getCommandVisible:
function( aSubMenu, aIndex,
aHost )
212 getCommandFlag:
function( aSubmenu, aIndex,
aHost )
217 getCommandChoiceItem:
function( aChoiceMenu,
aHost )
222 getCommandEnabled:
function( aSubMenu, aIndex,
aHost )
224 if (this.m_Context.m_Playlist.tree.currentIndex == -1)
return false;
226 var cmds = this._getMenu(aSubMenu);
228 var deviceRegistrar =
229 Components.classes[
"@songbirdnest.com/Songbird/DeviceManager;2"]
230 .getService(Components.interfaces.sbIDeviceRegistrar);
232 var device = deviceRegistrar.getDevice(cmds.m_DeviceIds[aIndex]);
233 if (device.state == Components.interfaces.sbIDevice.STATE_MOUNTING) {
240 return cmds.m_Enableds[ aIndex ];
243 getCommandShortcutModifiers:
function ( aSubMenu, aIndex,
aHost )
245 var cmds = this._getMenu(aSubMenu);
246 if ( aIndex >= cmds.m_Modifiers.length )
return "";
247 return cmds.m_Modifiers[ aIndex ];
250 getCommandShortcutKey:
function ( aSubMenu, aIndex,
aHost )
252 var cmds = this._getMenu(aSubMenu);
253 if ( aIndex >= cmds.m_Keys.length )
return "";
254 return cmds.m_Keys[ aIndex ];
257 getCommandShortcutKeycode:
function ( aSubMenu, aIndex,
aHost )
259 var cmds = this._getMenu(aSubMenu);
260 if ( aIndex >= cmds.m_Keycodes.length )
return "";
261 return cmds.m_Keycodes[ aIndex ];
264 getCommandShortcutLocal:
function ( aSubMenu, aIndex,
aHost )
269 getCommandSubObject:
function ( aSubMenu, aIndex,
aHost )
271 var cmds = this._getMenu(aSubMenu);
272 if ( aIndex >= cmds.m_PlaylistCommands.length )
return null;
273 return cmds.m_PlaylistCommands[ aIndex ];
276 onCommand:
function( aSubMenu, aIndex,
aHost,
id,
value )
281 if (this.m_addToDevice.handleCommand(
id))
return;
290 dupObject:
function (obj) {
299 duplicate:
function()
301 var obj = this.dupObject(
this);
302 obj.m_Context = this.dupObject(this.m_Context);
306 initCommands:
function(
aHost) {
307 if (!this.m_addToDevice) {
309 this.m_addToDevice.init(
this);
313 shutdownCommands:
function() {
314 if (!this.m_addToDevice) {
315 dump(
"this.m_addToDevice is null in SBPlaylistCommand_AddToDevice ?!!\n");
318 this.m_addToDevice.shutdown();
319 this.m_addToDevice =
null;
320 this.m_Context =
null;
323 setContext:
function( context )
325 var playlist = context.playlist;
326 var
window = context.window;
330 if ( playlist && playlist.wrappedJSObject )
331 playlist = playlist.wrappedJSObject;
333 if ( window && window.wrappedJSObject )
334 window = window.wrappedJSObject;
336 this.m_Context.m_Playlist = playlist;
337 this.m_Context.m_Window =
window;
342 if (!aIID.equals(Components.interfaces.sbIPlaylistCommands) &&
343 !aIID.equals(Components.interfaces.nsISupportsWeakReference) &&
344 !aIID.equals(Components.interfaces.nsISupports))
346 throw Components.results.NS_ERROR_NO_INTERFACE;
357 m_listofdevices:
null,
359 m_deviceManager:
null,
360 m_libraryManager:
null,
363 var consoleService = Components.classes[
'@mozilla.org/consoleservice;1']
364 .getService(Components.interfaces.nsIConsoleService);
365 consoleService.logStringMessage(
str);
368 init:
function addToDeviceHelper_init(aCommands) {
369 this.m_libraryManager =
370 Components.classes[
"@songbirdnest.com/Songbird/library/Manager;1"]
371 .getService(Components.interfaces.sbILibraryManager);
372 this.m_deviceManager =
373 Components.classes[
"@songbirdnest.com/Songbird/DeviceManager;2"]
374 .getService(Components.interfaces.sbIDeviceManager2);
376 this.m_deviceManager.QueryInterface(
377 Components.interfaces.sbIDeviceEventTarget
379 eventTarget.addEventListener(
this);
380 this.m_commands = aCommands;
381 this.makeListOfDevices();
384 shutdown:
function addToDeviceHelper_shutdown() {
386 this.m_deviceManager.QueryInterface(
387 Components.interfaces.sbIDeviceEventTarget
389 eventTarget.removeEventListener(
this);
390 this.m_deviceManager =
null;
396 hasDevices:
function addToDeviceHelper_hasDevices() {
397 return (this.m_listofdevices &&
398 this.m_listofdevices.m_Types &&
399 this.m_listofdevices.m_Types.length > 0);
404 makeListOfDevices:
function addToDeviceHelper_makeListOfDevices() {
405 this._makingList =
true;
407 this.m_listofdevices = {};
408 this.m_listofdevices.m_Types =
new Array();
409 this.m_listofdevices.m_Ids =
new Array();
410 this.m_listofdevices.m_Names =
new Array();
411 this.m_listofdevices.m_Tooltips =
new Array();
412 this.m_listofdevices.m_Enableds =
new Array();
413 this.m_listofdevices.m_Modifiers =
new Array();
414 this.m_listofdevices.m_Keys =
new Array();
415 this.m_listofdevices.m_Keycodes =
new Array();
416 this.m_listofdevices.m_PlaylistCommands =
new Array();
417 this.m_listofdevices.m_DeviceIds =
new Array();
421 this.m_deviceManager.QueryInterface(
422 Components.interfaces.sbIDeviceRegistrar
424 var devices =
Array();
426 for (var
i=0;
i<registrar.devices.length;
i++) {
427 var device = registrar.devices.queryElementAt
428 (
i, Components.interfaces.sbIDevice);
429 if (device && device.connected)
430 devices.push(device);
434 function deviceSorter(x,
y) {
437 if (x <
y)
return -1;
441 devices.sort(deviceSorter);
444 for (var
d in devices) {
446 var device = devices[
d];
447 var devicename = device.name;
450 var deviceProperties = device.properties.properties;
451 var accessCompatibility;
453 accessCompatibility = deviceProperties.getPropertyAsAString(
454 "http://songbirdnest.com/device/1.0#accessCompatibility");
456 if (accessCompatibility ==
"ro") {
460 var isEnabled =
false;
462 devicename =
"Unnamed Device";
463 var library = device.defaultLibrary;
465 isEnabled = library.userEditable;
466 libraryguid = library.guid;
470 this.m_listofdevices.m_Types.push(
"action");
474 this.m_listofdevices.m_Names.push(devicename);
475 this.m_listofdevices.m_Tooltips.push(devicename);
476 this.m_listofdevices.m_Enableds.push(isEnabled);
477 this.m_listofdevices.m_Modifiers.push(
"");
478 this.m_listofdevices.m_Keys.push(
"");
479 this.m_listofdevices.m_Keycodes.push(
"");
480 this.m_listofdevices.m_PlaylistCommands.push(
null);
481 this.m_listofdevices.m_DeviceIds.push(device.id);
484 this._makingList =
false;
487 handleGetMenu:
function addToDeviceHelper_handleGetMenu(aSubMenu) {
488 if (this.m_listofdevices ==
null) {
493 throw Components.results.NS_ERROR_FAILURE;
500 handleCommand:
function addToDeviceHelper_handleCommand(
id) {
502 var context = this.m_commands.m_Context;
504 if (
id.slice(0, addtodevicestr.length) == addtodevicestr) {
505 var r =
id.slice(addtodevicestr.length);
506 var parts = r.split(
';');
507 if (parts.length >= 2) {
508 var libraryguid = parts[0];
509 var devicename = parts[1];
510 this.addToDevice(libraryguid, context.m_Playlist, devicename);
515 Components.utils.reportError(e);
520 _getDeviceLibraryForLibrary:
function(aDevice, aLibrary) {
521 var libs = aDevice.content.libraries;
522 for (var
i = 0;
i < libs.length;
i++) {
523 var devLib = libs.queryElementAt(
i,
Ci.sbIDeviceLibrary);
524 if (devLib.equals(aLibrary))
531 _itemsFromEnumerator:
function(aItemEnum) {
532 var items =
Cc[
"@mozilla.org/array;1"].createInstance(
Ci.nsIMutableArray);
534 while (aItemEnum.hasMoreElements())
535 items.appendElement(aItemEnum.getNext(),
false);
541 addToDevice:
function addToDeviceHelper_addToDevice(
545 var library = this.m_libraryManager.getLibrary(devicelibraryguid);
548 sourceplaylist.mediaListView.selection.selectedMediaItems;
549 var items = this._itemsFromEnumerator(selection);
551 var deviceManager =
Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
552 .getService(
Ci.sbIDeviceManager2);
553 var device = deviceManager.getDeviceForItem(library);
554 var deviceLibrary = this._getDeviceLibraryForLibrary(device, library);
557 Cc[
"@songbirdnest.com/Songbird/Device/DeviceLibrarySyncDiff;1"]
558 .createInstance(
Ci.sbIDeviceLibrarySyncDiff);
562 differ.generateDropLists(sourceplaylist.library,
569 device.exportToDevice(deviceLibrary, changeset.value);
571 DNDUtils.reportAddedTracks(changeset.value.changes.length,
586 refreshCommands:
function addToDeviceHelper_refreshCommands() {
592 function ensureRefreshExists() {
595 return (
self.m_commands &&
596 self.m_commands.m_Context &&
597 self.m_commands.m_Context.m_Playlist &&
598 self.m_commands.m_Context.m_Playlist.refreshCommands) ?
611 if (ensureRefreshExists()) {
612 this.makeListOfDevices();
615 if (ensureRefreshExists()) {
616 this.m_commands.m_Context.m_Playlist.refreshCommands();
621 onUpdateEvent:
function addToDeviceHelper_onUpdateEvent() {
622 if (this._makingList)
return;
623 this.refreshCommands();
627 if (!iid.equals(Components.interfaces.sbIDeviceEventListener) &&
628 !iid.equals(Components.interfaces.nsISupports))
629 throw Components.results.NS_ERROR_NO_INTERFACE;
637 onDeviceEvent:
function addToDeviceHelper_onDeviceEvent(aEvent) {
638 if (aEvent.type == Components.interfaces.sbIDeviceEvent.EVENT_DEVICE_LIBRARY_ADDED ||
639 aEvent.type == Components.interfaces.sbIDeviceEvent.EVENT_DEVICE_LIBRARY_REMOVED ||
640 aEvent.type == Components.interfaces.sbIDeviceEvent.EVENT_DEVICE_MOUNTING_END) {
641 this.onUpdateEvent();
const ADDTODEVICE_MENU_MODIFIERS
const ADDTODEVICE_MENU_KEY
const ADDTODEVICE_MENU_KEYCODE
function addToDeviceHelper()
sbOSDControlService prototype QueryInterface
const ADDTODEVICE_MENU_NAME
sbDownloadDeviceServicePaneModule prototype shutdown
_collectFormDataForFrame aDocument
function createUnwrapper(aSelection)
Creates a new unwrapper helper object which ensures downloadStatusTarget is always set when adding it...
const ADDTODEVICE_MENU_TYPE
const SB_MEDIALISTDUPLICATEFILTER_CONTRACTID
const ADDTODEVICE_COMMAND_ID
var SBPlaylistCommand_AddToDevice
SBPlaylistCommand_DownloadToPlaylist m_root_commands
const ADDTODEVICE_MENU_TOOLTIP
_getSelectedPageStyle s i
const ADDTODEVICE_MENU_ID