27 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
28 Components.utils.import(
"resource://app/jsmodules/DropHelper.jsm");
29 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
31 const Ci = Components.interfaces;
32 const Cc = Components.classes;
33 const Cr = Components.results;
53 "SBPlaylistCommand_AddToPlaylist",
54 "SBPlaylistCommand_DownloadToPlaylist" ];
64 var unwrapper =
Cc[
"@songbirdnest.com/Songbird/Library/EnumeratorWrapper;1"]
65 .createInstance(
Ci.sbIMediaListEnumeratorWrapper);
66 unwrapper.initialize(aSelection);
81 m_addToPlaylist:
null,
100 m_Tooltips:
new Array
110 m_Keycodes:
new Array
115 m_Enableds:
new Array
120 m_Modifiers:
new Array
125 m_PlaylistCommands:
new Array
131 _getMenu:
function(aSubMenu)
135 cmds = this.m_addToPlaylist.handleGetMenu(aSubMenu);
136 if (cmds)
return cmds;
146 getVisible:
function(
aHost )
151 getNumCommands:
function( aSubMenu,
aHost )
153 var cmds = this._getMenu(aSubMenu);
154 return cmds.m_Ids.length;
157 getCommandId:
function( aSubMenu, aIndex,
aHost )
159 var cmds = this._getMenu(aSubMenu);
160 if ( aIndex >= cmds.m_Ids.length )
return "";
161 return cmds.m_Ids[ aIndex ];
164 getCommandType:
function( aSubMenu, aIndex,
aHost )
166 var cmds = this._getMenu(aSubMenu);
167 if ( aIndex >= cmds.m_Ids.length )
return "";
168 return cmds.m_Types[ aIndex ];
171 getCommandText:
function( aSubMenu, aIndex,
aHost )
173 var cmds = this._getMenu(aSubMenu);
174 if ( aIndex >= cmds.m_Names.length )
return "";
175 return cmds.m_Names[ aIndex ];
178 getCommandFlex:
function( aSubMenu, aIndex,
aHost )
180 var cmds = this._getMenu(aSubMenu);
181 if ( cmds.m_Types[ aIndex ] ==
"separator" )
return 1;
185 getCommandToolTipText:
function( aSubMenu, aIndex,
aHost )
187 var cmds = this._getMenu(aSubMenu);
188 if ( aIndex >= cmds.m_Tooltips.length )
return "";
189 return cmds.m_Tooltips[ aIndex ];
192 getCommandValue:
function( aSubMenu, aIndex,
aHost )
201 refreshCustomCommand:
function( aElement, aId,
aHost )
205 getCommandVisible:
function( aSubMenu, aIndex,
aHost )
210 getCommandFlag:
function( aSubmenu, aIndex,
aHost )
215 getCommandChoiceItem:
function( aChoiceMenu,
aHost )
220 getCommandEnabled:
function( aSubMenu, aIndex,
aHost )
222 if (this.m_Context.m_Playlist.mediaListView.selection.count == 0)
224 var cmds = this._getMenu(aSubMenu);
225 return (aIndex in cmds.m_Enableds) && cmds.m_Enableds[ aIndex ];
228 getCommandShortcutModifiers:
function ( aSubMenu, aIndex,
aHost )
230 var cmds = this._getMenu(aSubMenu);
231 if ( aIndex >= cmds.m_Modifiers.length )
return "";
232 return cmds.m_Modifiers[ aIndex ];
235 getCommandShortcutKey:
function ( aSubMenu, aIndex,
aHost )
237 var cmds = this._getMenu(aSubMenu);
238 if ( aIndex >= cmds.m_Keys.length )
return "";
239 return cmds.m_Keys[ aIndex ];
242 getCommandShortcutKeycode:
function ( aSubMenu, aIndex,
aHost )
244 var cmds = this._getMenu(aSubMenu);
245 if ( aIndex >= cmds.m_Keycodes.length )
return "";
246 return cmds.m_Keycodes[ aIndex ];
249 getCommandShortcutLocal:
function ( aSubMenu, aIndex,
aHost )
254 getCommandSubObject:
function ( aSubMenu, aIndex,
aHost )
256 var cmds = this._getMenu(aSubMenu);
257 if ( aIndex >= cmds.m_PlaylistCommands.length )
return null;
258 return cmds.m_PlaylistCommands[ aIndex ];
261 onCommand:
function( aSubMenu, aIndex,
aHost,
id,
value )
266 if (this.m_addToPlaylist.handleCommand(
id))
return;
275 dupObject:
function (obj) {
284 duplicate:
function()
286 var obj = this.dupObject(
this);
287 obj.m_Context = this.dupObject(this.m_Context);
291 initCommands:
function(
aHost) {
292 if (!this.m_addToPlaylist) {
294 this.m_addToPlaylist.init(
this);
298 shutdownCommands:
function() {
299 if (!this.m_addToPlaylist) {
300 dump(
"this.m_addToPlaylist is null in SBPlaylistCommand_AddToPlaylist ?!!\n");
303 this.m_addToPlaylist.shutdown();
304 this.m_addToPlaylist =
null;
305 this.m_Context =
null;
308 setContext:
function( context )
310 var playlist = context.playlist;
311 var
window = context.window;
315 if ( playlist && playlist.wrappedJSObject )
316 playlist = playlist.wrappedJSObject;
318 if ( window && window.wrappedJSObject )
319 window = window.wrappedJSObject;
321 this.m_Context.m_Playlist = playlist;
322 this.m_Context.m_Window =
window;
327 if (!aIID.equals(Components.interfaces.sbIPlaylistCommands) &&
328 !aIID.equals(Components.interfaces.nsISupportsWeakReference) &&
329 !aIID.equals(Components.interfaces.nsISupports))
331 throw Components.results.NS_ERROR_NO_INTERFACE;
340 SBPlaylistCommand_DownloadToPlaylist.m_root_commands = {
356 m_Tooltips:
new Array
366 m_Keycodes:
new Array
371 m_Enableds:
new Array
376 m_Modifiers:
new Array
381 m_PlaylistCommands:
new Array
394 m_listofplaylists:
null,
397 m_libraryManager:
null,
400 var consoleService = Components.classes[
'@mozilla.org/consoleservice;1']
401 .getService(Components.interfaces.nsIConsoleService);
402 consoleService.logStringMessage(
str);
404 init:
function(aCommands) {
405 this.m_libraryManager = Components.classes[
"@songbirdnest.com/Songbird/library/Manager;1"]
406 .getService(Components.interfaces.sbILibraryManager);
407 this.m_libraryManager.addListener(
this);
408 this.m_commands = aCommands;
409 this.makeListOfPlaylists();
413 this.m_libraryManager.removeListener(
this);
414 this.removeLibraryListeners();
415 this.m_libraryManager =
null;
418 removeLibraryListeners:
function() {
419 if (this.m_reglist) {
420 for (var
i in this.m_reglist) {
421 this.m_reglist[
i].removeListener(
this);
424 this.m_reglist =
new Array();
427 makeListOfPlaylists:
function( ) {
429 this.removeLibraryListeners();
432 var typearray =
new Array(
'simple');
434 this.m_listofplaylists = {};
435 this.m_listofplaylists.m_Types =
new Array();
436 this.m_listofplaylists.m_Ids =
new Array();
437 this.m_listofplaylists.m_Names =
new Array();
438 this.m_listofplaylists.m_Tooltips =
new Array();
439 this.m_listofplaylists.m_Enableds =
new Array();
440 this.m_listofplaylists.m_Modifiers =
new Array();
441 this.m_listofplaylists.m_Keys =
new Array();
442 this.m_listofplaylists.m_Keycodes =
new Array();
443 this.m_listofplaylists.m_PlaylistCommands =
new Array();
445 var libs = this.m_libraryManager.getLibraries();
446 while (libs.hasMoreElements()) {
447 var library = libs.getNext().QueryInterface(
448 Components.interfaces.sbILibrary);
449 library.addListener(
this,
false);
450 this.m_reglist.push(library);
451 this.makePlaylistsForLibrary(library, typearray);
454 if (this.m_listofplaylists.m_Types.length == 0) {
455 this.m_listofplaylists.m_Types.push(
"action");
456 this.m_listofplaylists.m_Ids.push(
"noplaylist");
457 this.m_listofplaylists.m_Names.push(
"&command.addtoplaylist.noexistingplaylist");
458 this.m_listofplaylists.m_Tooltips.push(
"&command.tooltip.addtoplaylist.noexistingplaylist");
459 this.m_listofplaylists.m_Enableds.push(
false);
460 this.m_listofplaylists.m_Modifiers.push(
"");
461 this.m_listofplaylists.m_Keys.push(
"");
462 this.m_listofplaylists.m_Keycodes.push(
"");
463 this.m_listofplaylists.m_PlaylistCommands.push(
null);
466 this.m_listofplaylists.m_Types.push(
"separator");
467 this.m_listofplaylists.m_Ids.push(
"separator");
468 this.m_listofplaylists.m_Names.push(
"separator");
469 this.m_listofplaylists.m_Tooltips.push(
"separator");
470 this.m_listofplaylists.m_Enableds.push(
true);
471 this.m_listofplaylists.m_Modifiers.push(
"");
472 this.m_listofplaylists.m_Keys.push(
"");
473 this.m_listofplaylists.m_Keycodes.push(
"");
474 this.m_listofplaylists.m_PlaylistCommands.push(
null);
476 this.m_listofplaylists.m_Types.push(
"action");
478 this.m_listofplaylists.m_Names.push(
"&command.addtoplaylist.createnew");
479 this.m_listofplaylists.m_Tooltips.push(
"&command.addtoplaylist.createnew");
480 this.m_listofplaylists.m_Enableds.push(
true);
481 this.m_listofplaylists.m_Modifiers.push(
"");
482 this.m_listofplaylists.m_Keys.push(
"");
483 this.m_listofplaylists.m_Keycodes.push(
"");
484 this.m_listofplaylists.m_PlaylistCommands.push(
null);
487 makePlaylistsForLibrary:
function(aLibrary, typearray) {
488 this._makingList =
true;
492 _downloadListGUID:
null,
493 onEnumerationBegin:
function() {
495 Components.classes[
"@songbirdnest.com/Songbird/DownloadDeviceHelper;1"]
496 .getService(Components.interfaces.sbIDownloadDeviceHelper);
497 var downloadMediaList = ddh.getDownloadMediaList();
498 if (downloadMediaList)
499 this._downloadListGUID = downloadMediaList.guid;
501 this._libraryServicePane =
502 Components.classes[
'@songbirdnest.com/servicepane/library;1']
503 .getService(Components.interfaces.sbILibraryServicePaneService);
505 onEnumerationEnd:
function() { },
506 onEnumeratedItem:
function(list, item) {
507 var
hidden = item.getProperty(
"http://songbirdnest.com/data/1.0#hidden");
509 return Components.interfaces.sbIMediaListEnumerationListener.CONTINUE;
511 var goodtype =
false;
512 for (var
i in typearray) {
513 if (typearray[
i] == item.type) {
519 return Components.interfaces.sbIMediaListEnumerationListener.CONTINUE;
526 if (item.guid ==
this._downloadListGUID) {
527 return Components.interfaces.sbIMediaListEnumerationListener.CONTINUE;
537 function isHidden(
node) {
539 if (
node.hidden)
return true;
544 var
node = this._libraryServicePane.getNodeForLibraryResource(item);
545 if (!node || isHidden(node)) {
546 return Components.interfaces.sbIMediaListEnumerationListener.CONTINUE;
549 this.obj.m_listofplaylists.m_Types.push(
"action");
551 this.obj.m_listofplaylists.m_Names.push(item.name ? item.name :
"Unnamed Playlist");
552 this.obj.m_listofplaylists.m_Tooltips.push(item.name ? item.name :
"Unnamed Playlist");
553 this.obj.m_listofplaylists.m_Enableds.push(item.userEditable);
554 this.obj.m_listofplaylists.m_Modifiers.push(
"");
555 this.obj.m_listofplaylists.m_Keys.push(
"");
556 this.obj.m_listofplaylists.m_Keycodes.push(
"");
557 this.obj.m_listofplaylists.m_PlaylistCommands.push(
null);
559 return Components.interfaces.sbIMediaListEnumerationListener.CONTINUE;
566 aLibrary.enumerateItemsByProperty(
"http://songbirdnest.com/data/1.0#isList",
"1",
573 this._makingList =
false;
576 handleGetMenu:
function(aSubMenu) {
577 if (this.m_listofplaylists ==
null) {
581 throw Components.results.NS_ERROR_FAILURE;
587 handleCommand:
function(
id) {
589 var context = this.m_commands.m_Context;
591 var newMediaList = context.m_Window.makeNewPlaylist(
"simple");
592 this.addToPlaylist(newMediaList.library.guid, newMediaList.guid, context.m_Playlist);
596 if (
id.slice(0, addtoplstr.length) == addtoplstr) {
597 var r =
id.slice(addtoplstr.length);
598 var guids = r.split(
';');
599 if (guids.length >= 2) {
600 var libraryguid = guids[0];
601 var playlistguid = guids[1];
603 this.addToPlaylist(libraryguid, playlistguid, context.m_Playlist);
609 Components.utils.reportError(e);
614 addToPlaylist:
function(libraryguid, playlistguid, sourceplaylist) {
615 var library = this.m_libraryManager.getLibrary(libraryguid);
617 if (libraryguid == playlistguid)
620 medialist = library.getMediaItem(playlistguid);
624 var oldLength = medialist.length;
625 var selection = sourceplaylist.mediaListView.selection.selectedIndexedMediaItems;
632 var asyncListener = {
633 onProgress:
function(aItemsProcessed, aComplete) {
634 DNDUtils.reportAddedTracks(aItemsProcessed,
639 onItemAdded:
function(aMediaItem) {},
644 medialist.addMediaItems(unwrapper, asyncListener,
true);
650 _deferredevent :
false,
653 refreshCommands:
function() {
659 function ensureRefreshExists() {
662 return (
self.m_commands &&
663 self.m_commands.m_Context &&
664 self.m_commands.m_Context.m_Playlist &&
665 self.m_commands.m_Context.m_Playlist.refreshCommands) ?
678 if (ensureRefreshExists()) {
679 this.makeListOfPlaylists();
682 if (ensureRefreshExists()) {
683 this.m_commands.m_Context.m_Playlist.refreshCommands();
688 onUpdateEvent:
function(item) {
689 if (this._makingList)
return;
690 if (item instanceof Components.interfaces.sbIMediaList) {
693 this._deferredevent =
true;
696 this.refreshCommands();
702 if (!iid.equals(Components.interfaces.sbIMediaListListener) &&
703 !iid.equals(Components.interfaces.sbILibraryManagerListener) &&
704 !iid.equals(Components.interfaces.nsISupports))
705 throw Components.results.NS_ERROR_NO_INTERFACE;
709 onItemAdded:
function onItemAdded(list, item, index) {
711 if (!this._inbatch) {
712 this.onUpdateEvent(item);
717 onBeforeItemRemoved:
function onBeforeItemRemoved(list, item, index) {
721 onAfterItemRemoved:
function onAfterItemRemoved(list, item, index) {
723 if (!this._inbatch) {
724 this.onUpdateEvent(item);
729 onItemUpdated:
function onItemUpdated(list, item, properties) {
731 if (!this._inbatch) {
732 this.onUpdateEvent(item);
737 onItemMoved:
function onItemMoved(list, fromIndex, toIndex) {
742 onBeforeListCleared:
function onBeforeListCleared(list, excludeLists) {
746 onListCleared:
function onListCleared(list, excludeLists) {
748 if (!this._inbatch) {
749 this.onUpdateEvent(list);
754 onBatchBegin:
function onBatchBegin(list) {
756 this._inbatch =
true;
757 this._deferredevent =
false;
760 onBatchEnd:
function onBatchEnd(list) {
762 this._inbatch =
false;
764 if (this._deferredevent) {
766 this.onUpdateEvent(list);
768 this._deferredevent =
false;
771 onLibraryRegistered:
function onLibraryRegistered(library) {
772 this.onUpdateEvent(library);
775 onLibraryUnregistered:
function onLibraryUnregistered(library) {
776 this.onUpdateEvent(library);
var SBPlaylistCommand_DownloadToPlaylist
const ADDTOPLAYLIST_MENU_KEY
const DOWNLOADTOPLAYLIST_MENU_KEY
const ADDTOPLAYLIST_MENU_ID
function createUnwrapper(aSelection)
Creates a new unwrapper helper object which ensures downloadStatusTarget is always set when adding it...
var SBPlaylistCommand_AddToPlaylist
sbOSDControlService prototype QueryInterface
const ADDTOPLAYLIST_NEWPLAYLIST_COMMAND_ID
sbDownloadDeviceServicePaneModule prototype shutdown
const ADDTOPLAYLIST_MENU_KEYCODE
function addToPlaylistHelper()
_collectFormDataForFrame aDocument
const DOWNLOADTOPLAYLIST_MENU_NAME
const DOWNLOADTOPLAYLIST_MENU_TOOLTIP
const ADDTOPLAYLIST_MENU_NAME
const DOWNLOADTOPLAYLIST_MENU_MODIFIERS
const ADDTOPLAYLIST_MENU_TYPE
const DOWNLOADTOPLAYLIST_MENU_KEYCODE
SBPlaylistCommand_DownloadToPlaylist m_root_commands
const ADDTOPLAYLIST_MENU_MODIFIERS
const ADDTOPLAYLIST_MENU_TOOLTIP
_getSelectedPageStyle s i
const ADDTOPLAYLIST_COMMAND_ID