25 if (typeof(
Ci) ==
"undefined")
26 var
Ci = Components.interfaces;
27 if (typeof(
Cc) ==
"undefined")
28 var
Cc = Components.classes;
29 if (typeof(
Cr) ==
"undefined")
30 var
Cr = Components.results;
31 if (typeof(
Cu) ==
"undefined")
32 var
Cu = Components.utils;
34 Cu.import(
"resource://app/jsmodules/ArrayConverter.jsm");
35 Cu.import(
"resource://app/jsmodules/sbCoverHelper.jsm");
36 Cu.import(
"resource://app/jsmodules/SBJobUtils.jsm");
37 Cu.import(
"resource://app/jsmodules/StringUtils.jsm");
38 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
39 Cu.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
40 Cu.import(
"resource://app/jsmodules/sbMetadataUtils.jsm");
41 Cu.import(
"resource://app/jsmodules/SBUtils.jsm");
42 Cu.import(
"resource://gre/modules/XPCOMUtils.jsm");
60 if (typeof(XLINK_NS) ==
"undefined")
61 const XLINK_NS =
"http://www.w3.org/1999/xlink";
76 dump(
"AlbumArt displaypane menu: unknown command: " + command +
"\n");
88 _mediacoreManager:
null,
92 _nowSelectedMediaItem:
null,
93 _nowSelectedMediaItemWatcher:
null,
94 _prevAutoFetchArtworkItem:
null,
96 _autoFetchTimeoutID:
null,
99 _stateInfo: [ { imageID:
"sb-albumart-selected",
102 defaultTitle:
"Now Selected"
104 { imageID:
"sb-albumart-playing",
107 defaultTitle:
"Now Playing"
112 _switchToNowPlaying:
function() {
115 _switchToNowSelected:
function() {
118 _populateMenuControl:
function AlbumArt_populateMenuControl(menupopup,
doc) {
120 var nowPlayingMenu =
doc.createElement(
"menuitem");
122 var npString =
SBString(
"albumart.displaypane.menu.show" +
123 titleInfo.titleID, titleInfo.defaultTitle);
124 nowPlayingMenu.setAttribute(
"label", npString);
125 nowPlayingMenu.setAttribute(
"type",
"radio");
126 nowPlayingMenu.addEventListener(
"command", AlbumArt._switchToNowPlaying,
128 menupopup.appendChild(nowPlayingMenu);
131 var nowSelectedMenu =
doc.createElement(
"menuitem");
133 var nsString =
SBString(
"albumart.displaypane.menu.show" +
134 titleInfo.titleID, titleInfo.defaultTitle);
135 nowSelectedMenu.setAttribute(
"label", nsString);
136 nowSelectedMenu.setAttribute(
"type",
"radio");
137 nowSelectedMenu.addEventListener(
"command",
138 AlbumArt._switchToNowSelected,
140 menupopup.appendChild(nowSelectedMenu);
143 nowPlayingMenu.setAttribute(
"selected",
"true");
145 nowSelectedMenu.setAttribute(
"selected",
"true");
147 AlbumArt._menuPopup = menupopup;
150 _destroyMenuControl:
function AlbumArt_destroyMenuControl() {
151 while (AlbumArt._menuPopup.firstChild) {
152 AlbumArt._menuPopup.removeChild(AlbumArt._menuPopup.firstChild);
161 onImageDblClick:
function AlbumArt_onImageDblClick(aEvent) {
163 var passImageParam =
null;
164 if (aEvent.button == 0) {
168 if (aEvent.target.id ==
'sb-albumart-selected') {
169 passImageParam = this.getCurrentStateItemImage();
172 var winMediator = Cc[
"@mozilla.org/appshell/window-mediator;1"]
173 .getService(Ci.nsIWindowMediator);
174 var mainWin = winMediator.getMostRecentWindow(
"Songbird:Main");
175 if (mainWin && mainWin.window) {
176 mainWin.openDialog(
"chrome://albumart/content/coverPreview.xul",
178 "chrome,centerscreen,resizeable=no",
188 setPaneTitle:
function AlbumArt_setPaneTitle() {
190 if (AlbumArt._currentState >= AlbumArt._stateInfo.length ||
191 AlbumArt._currentState < 0) {
195 var titleInfo = AlbumArt._stateInfo[AlbumArt._currentState];
196 var titleString =
SBString(
"albumart.displaypane.title." + titleInfo.titleID,
197 titleInfo.defaultTitle);
201 if (AlbumArt._displayPane) {
202 AlbumArt._displayPane.contentTitle = titleString;
212 switchState:
function AlbumArt_switchState(aNewState) {
213 AlbumArt._currentState = aNewState;
214 var albumArtDeck = document.getElementById(
'sb-albumart-deck');
215 albumArtDeck.selectedIndex = AlbumArt._currentState;
216 AlbumArt.setPaneTitle();
219 document.getElementById(
"showNowSelectedMenuItem")
220 .setAttribute(
"checked",
"false");
221 document.getElementById(
"showNowPlayingMenuItem")
222 .setAttribute(
"checked",
"true");
224 document.getElementById(
"showNowPlayingMenuItem")
225 .setAttribute(
"checked",
"false");
226 document.getElementById(
"showNowSelectedMenuItem")
227 .setAttribute(
"checked",
"true");
238 canEditItems:
function AlbumArt_canEditItems(aItemArray) {
239 for each (var item
in aItemArray) {
256 changeImage:
function AlbumArt_changeImage(aNewURL,
261 isPlayingOrSelected) {
263 if (!isPlayingOrSelected) {
267 aNotBox.hidden =
false;
270 aDragBox.hidden =
true;
275 aStack.className =
"artwork-none";
276 }
else if (!aNewURL) {
280 aDragBox.hidden =
false;
283 aNotBox.hidden =
true;
288 aStack.className =
"artwork-none";
293 aNotBox.hidden =
true;
296 aDragBox.hidden =
true;
298 aStack.className =
"artwork-found";
301 if (!
Application.prefs.getValue(
"songbird.albumart.autofetch.disabled",
304 AlbumArt.autoFetchArtwork();
307 var princely =
Application.prefs.getValue(
"songbird.purplerain.prince",
309 if ((princely ==
"1") && aNotBox.hidden)
310 aNewURL =
"chrome://songbird/skin/album-art/princeaa.jpg";
314 aImageElement.setAttributeNS(XLINK_NS,
"href", aNewURL);
319 var img =
new Image();
320 img.addEventListener(
"load",
function(e) {
321 AlbumArt.imageDimensions = {
324 aspectRatio: (img.height/img.width)
326 AlbumArt.onServicepaneResize();
327 img.removeEventListener(
"load",
arguments.callee,
false);
332 aImageElement.removeAttributeNS(XLINK_NS,
"href");
340 changeNowSelected:
function AlbumArt_changeNowSelected(aNewURL) {
342 var albumArtSelectedImage = document.getElementById(
'sb-albumart-selected');
343 var albumArtNotSelectedBox = document.getElementById(
'sb-albumart-not-selected');
344 var albumArtSelectedDragBox = document.getElementById(
'sb-albumart-select-drag');
345 var stack = document.getElementById(
'sb-albumart-nowselected-stack');
347 var isSelected =
false;
348 if (AlbumArt._mediaListView)
349 isSelected = AlbumArt._mediaListView.selection.count > 0;
350 this.changeImage(aNewURL,
351 albumArtSelectedImage,
352 albumArtNotSelectedBox,
353 albumArtSelectedDragBox,
362 changeNowPlaying:
function AlbumArt_changeNowPlaying(aNewURL) {
364 var albumArtPlayingImage = document.getElementById(
'sb-albumart-playing');
365 var albumArtNotPlayingBox = document.getElementById(
'sb-albumart-not-playing');
366 var albumArtPlayingDragBox = document.getElementById(
'sb-albumart-playing-drag');
367 var stack = document.getElementById(
'sb-albumart-nowplaying-stack');
369 this.changeImage(aNewURL,
370 albumArtPlayingImage,
371 albumArtNotPlayingBox,
372 albumArtPlayingDragBox,
374 (this.getNowPlayingItem() !=
null));
385 observe:
function AlbumArt_observe(aSubject, aTopic,
aData) {
387 if (aTopic !=
"metadata.imageURL") {
394 AlbumArt.changeNowPlaying(
aData);
401 toggleView:
function AlbumArt_toggleView() {
402 var newState = (AlbumArt._currentState + 1);
403 if (newState >= AlbumArt._stateInfo.length) {
407 AlbumArt.switchState(newState);
413 dpStateListener:
function AlbumArt_onDisplayPaneStateListener(e) {
414 if (!AlbumArt._displayPane)
418 if (e.target.getAttribute(
"state") ==
"open") {
420 AlbumArt._displayPane.contentTitle =
"";
422 AlbumArt.setPaneTitle();
429 onServicepaneResize:
function AlbumArt_onServicepaneResize(e) {
432 imgEl = AlbumArt._albumArtPlayingImage;
434 imgEl = AlbumArt._albumArtSelectedImage;
438 var svgWidth = imgEl.width.baseVal.value;
439 var svgHeight = parseInt(AlbumArt.imageDimensions.aspectRatio * svgWidth);
440 if (Math.abs(svgHeight - AlbumArt._displayPane.height) > 10) {
441 AlbumArt._animating =
true;
442 AlbumArt._finalAnimatedHeight = svgHeight;
443 AlbumArt.animateHeight(AlbumArt._displayPane.height);
445 if (!AlbumArt._animating)
446 AlbumArt._displayPane.height = svgHeight;
448 AlbumArt._finalAnimatedHeight = svgHeight;
452 animateHeight:
function AlbumArt_animateHeight(destHeight) {
453 destHeight = parseInt(destHeight);
454 AlbumArt._displayPane.height = destHeight;
456 if (destHeight == AlbumArt._finalAnimatedHeight) {
457 AlbumArt._animating =
false;
460 var delta = Math.abs(AlbumArt._finalAnimatedHeight - destHeight) / 2;
462 newHeight = AlbumArt._finalAnimatedHeight;
464 if (AlbumArt._finalAnimatedHeight > destHeight)
465 newHeight = destHeight + delta;
467 newHeight = destHeight - delta;
469 setTimeout(AlbumArt.animateHeight, 0, newHeight);
476 onLoad:
function AlbumArt_onLoad() {
478 window.removeEventListener(
"DOMContentLoaded", AlbumArt.onLoad,
false);
481 var displayPaneManager = Cc[
"@songbirdnest.com/Songbird/DisplayPane/Manager;1"]
482 .getService(Ci.sbIDisplayPaneManager);
483 var dpInstantiator = displayPaneManager.getInstantiatorForWindow(
window);
485 if (dpInstantiator) {
486 AlbumArt._displayPane = dpInstantiator.displayPane;
488 var splitter = AlbumArt._displayPane._splitter;
490 splitter.setAttribute(
"disabled",
"true");
491 splitter.addEventListener(
"displaypane-state", AlbumArt.dpStateListener,
495 AlbumArt._mediacoreManager =
496 Cc[
"@songbirdnest.com/Songbird/Mediacore/Manager;1"]
497 .getService(Ci.sbIMediacoreManager);
501 AlbumArt._currentState);
503 document.getElementById(
"showNowPlayingMenuItem")
504 .setAttribute(
"checked",
"true");
506 document.getElementById(
"showNowSelectedMenuItem")
507 .setAttribute(
"checked",
"true");
511 AlbumArt.switchState(AlbumArt._currentState);
515 "@songbirdnest.com/Songbird/DataRemote;1",
516 Components.interfaces.sbIDataRemote,
519 AlbumArt._coverBind.bindObserver(AlbumArt,
false);
522 document.getElementById(
'sb-albumart-select-drag').firstChild
523 .textContent =
SBString(
"albumart.displaypane.drag_artwork_here");
524 document.getElementById(
'sb-albumart-playing-drag').firstChild
525 .textContent =
SBString(
"albumart.displaypane.drag_artwork_here");
528 AlbumArt._mediacoreManager.addListener(AlbumArt);
530 var currentStatus = AlbumArt._mediacoreManager.status;
531 var
stopped = (currentStatus.state == currentStatus.STATUS_STOPPED ||
532 currentStatus.state == currentStatus.STATUS_UNKNOWN);
534 AlbumArt.changeNowPlaying(
null);
537 AlbumArt.changeNowSelected(
null);
540 AlbumArt.onTabContentChange();
542 AlbumArt._albumArtSelectedImage =
543 document.getElementById(
'sb-albumart-selected');
544 AlbumArt._albumArtPlayingImage =
545 document.getElementById(
'sb-albumart-playing');
546 var mainWindow =
window.QueryInterface(Ci.nsIInterfaceRequestor)
547 .getInterface(Ci.nsIWebNavigation)
548 .QueryInterface(Ci.nsIDocShellTreeItem)
550 .QueryInterface(Ci.nsIInterfaceRequestor)
551 .getInterface(Ci.nsIDOMWindow);
553 AlbumArt._servicePaneSplitter =
554 mainWindow.document.getElementById(
"servicepane_splitter");
555 AlbumArt._servicePaneSplitter.addEventListener(
"dragging",
556 AlbumArt.onServicepaneResize,
564 onUnload:
function AlbumArt_onUnload() {
566 window.removeEventListener(
"unload", AlbumArt.onUnload,
false);
567 AlbumArt._displayPane._splitter.removeEventListener(
"displaypane-state",
568 AlbumArt.dpStateListener,
false);
571 AlbumArt._servicePaneSplitter.removeEventListener(
"dragging",
572 AlbumArt.onServicepaneResize,
576 var splitter = AlbumArt._displayPane._splitter;
577 splitter.removeAttribute(
"hovergrippy");
578 splitter.removeAttribute(
"disabled");
581 if (this._autoFetchTimeoutID) {
582 clearTimeout(this._autoFetchTimeoutID)
583 this._autoFetchTimeoutID =
null;
587 AlbumArt.clearNowSelectedMediaItem();
592 AlbumArt._mediacoreManager.removeListener(AlbumArt);
593 AlbumArt._mediacoreManager =
null;
595 AlbumArt._coverBind.unbind();
596 AlbumArt._coverBind =
null;
599 if(AlbumArt._mediaListView) {
600 AlbumArt._mediaListView.selection.removeListener(AlbumArt);
602 if (AlbumArt._browser) {
603 AlbumArt._browser.removeEventListener(
"TabContentChange",
604 AlbumArt.onTabContentChange,
615 getMainBrowser:
function AlbumArt_getMainBrowser() {
618 var windowMediator = Components.classes[
"@mozilla.org/appshell/window-mediator;1"]
619 .getService(Components.interfaces.nsIWindowMediator);
621 var songbirdWindow = windowMediator.getMostRecentWindow(
"Songbird:Main");
623 AlbumArt._browser = songbirdWindow.gBrowser;
624 if (AlbumArt._browser) {
625 AlbumArt._browser.addEventListener(
"TabContentChange",
626 AlbumArt.onTabContentChange,
637 onTabContentChange:
function AlbumArt_onTabContentChange() {
639 if(AlbumArt._mediaListView) {
640 AlbumArt._mediaListView.selection.removeListener(AlbumArt);
644 if (!AlbumArt._browser) {
645 AlbumArt.getMainBrowser();
647 AlbumArt._mediaListView = AlbumArt._browser.currentMediaListView;
650 if (AlbumArt._mediaListView) {
651 AlbumArt._mediaListView.selection.addListener(AlbumArt);
655 AlbumArt.onSelectionChanged();
665 checkIsLocal:
function AlbumArt_checkIsLocal(aMediaItem) {
666 var contentURL = aMediaItem.getProperty(SBProperties.contentURL);
667 var
ioService = Cc[
"@mozilla.org/network/io-service;1"]
668 .getService(Ci.nsIIOService);
671 uri = ioService.newURI(contentURL,
null,
null);
673 Cu.reportError(
"AlbumArt: Unable to convert to URI: [" +
674 contentURL +
"] " + err);
678 return (uri instanceof Ci.nsIFileURL);
685 setNowPlayingCover:
function AlbumArt_setNowPlayingCover(aNewImageUrl) {
686 var aMediaItem = AlbumArt.getNowPlayingItem();
690 aMediaItem.setProperty(SBProperties.primaryImageURL, aNewImageUrl);
691 AlbumArt.changeNowPlaying(aNewImageUrl);
694 if (this.checkIsLocal(aMediaItem)) {
696 [SBProperties.primaryImageURL],
705 setSelectionsCover:
function AlbumArt_setSelectionsCover(aNewImageUrl) {
706 var selection = AlbumArt._mediaListView.selection;
707 var multipleItems =
false;
712 var itemEnum = selection.selectedMediaItems;
713 var oldAlbumName =
null;
714 var oldAlbumArtist =
null;
715 while (itemEnum.hasMoreElements()) {
716 var item = itemEnum.getNext();
717 var albumName = item.getProperty(SBProperties.albumName);
718 var albumArtist = item.getProperty(SBProperties.albumArtistName);
719 if (!albumArtist || albumArtist ==
"") {
720 albumArtist = item.getProperty(SBProperties.artistName);
723 if (oldAlbumArtist ==
null &&
724 oldAlbumName ==
null) {
725 oldAlbumName = albumName;
726 oldAlbumArtist = albumArtist;
727 }
else if (albumName != oldAlbumName ||
728 albumArtist != oldAlbumArtist) {
730 multipleItems =
true;
738 const BYPASSKEY =
"albumart.multiplewarning.bypass";
739 const STRINGROOT =
"albumart.multiplewarning.";
740 if (!
Application.prefs.getValue(BYPASSKEY,
false)) {
741 var
promptService = Cc[
"@mozilla.org/embedcomp/prompt-service;1"]
742 .getService(Ci.nsIPromptService);
745 var strTitle =
SBString(STRINGROOT +
"title");
746 var strMsg =
SBString(STRINGROOT +
"message");
747 var strCheck =
SBString(STRINGROOT +
"check");
749 var confirmOk = promptService.confirmCheck(
window,
757 if (check.value ==
true) {
765 var mediaItemArray = [];
766 itemEnum = selection.selectedMediaItems;
767 while (itemEnum.hasMoreElements()) {
768 var item = itemEnum.getNext();
769 var oldImage = item.getProperty(SBProperties.primaryImageURL);
770 if (oldImage != aNewImageUrl) {
771 item.setProperty(SBProperties.primaryImageURL, aNewImageUrl);
772 if (this.checkIsLocal(item)) {
773 mediaItemArray.push(item);
779 if (mediaItemArray.length > 0) {
781 [SBProperties.primaryImageURL],
790 setCurrentStateItemImage:
function AlbumArt_setCurrentSateItemImage(aNewImageUrl) {
792 AlbumArt.setSelectionsCover(aNewImageUrl);
794 AlbumArt.setNowPlayingCover(aNewImageUrl);
802 getCurrentStateItemImage:
function AlbumArt_getCurrentStateItemImage() {
805 imageNode = document.getElementById(
"sb-albumart-selected");
807 imageNode = document.getElementById(
"sb-albumart-playing");
809 return imageNode.getAttributeNS(XLINK_NS,
"href");
816 clearNowSelectedMediaItem:
function AlbumArt_clearNowSelectedMediaItem() {
818 if (AlbumArt._nowSelectedMediaItemWatcher) {
819 AlbumArt._nowSelectedMediaItemWatcher.cancel();
820 AlbumArt._nowSelectedMediaItemWatcher =
null;
824 AlbumArt._nowSelectedMediaItem =
null;
831 getNowPlayingItem:
function AlbumArt_getNowPlayingItem() {
833 var currentStatus = AlbumArt._mediacoreManager.status;
834 var
stopped = (currentStatus.state == currentStatus.STATUS_STOPPED ||
835 currentStatus.state == currentStatus.STATUS_UNKNOWN);
840 return AlbumArt._mediacoreManager.sequencer.currentItem;
852 getClipboardAlbumArt:
853 function AlbumArt_getClipboardAlbumArt(aMimeType,
857 var sbClipboard = Cc[
"@songbirdnest.com/moz/clipboard/helper;1"]
858 .createInstance(Ci.sbIClipboardHelper);
860 var imageData =
null;
862 imageData = sbClipboard.copyImageFromClipboard(mimeType, {});
864 Cu.reportError(
"Error checking for image data on the clipboard: " + err);
865 aMimeType.value =
null;
866 aImageData.value =
null;
867 aIsValidAlbumArt.value =
false;
870 mimeType = mimeType.value;
873 var isValidAlbumArt =
false;
874 if (imageData && (imageData.length > 0)) {
875 var artService = Cc[
"@songbirdnest.com/Songbird/album-art-service;1"]
876 .getService(Ci.sbIAlbumArtService);
877 isValidAlbumArt = artService.imageIsValidAlbumArt(mimeType,
881 if (!isValidAlbumArt) {
887 aMimeType.value = mimeType;
888 aImageData.value = imageData;
889 aIsValidAlbumArt.value = isValidAlbumArt;
895 onPopupShowing:
function AlbumArt_onPopupShowing() {
897 var curImageUrl = AlbumArt.getCurrentStateItemImage();
900 var cutElem = document.getElementById(
"cutMenuItem");
901 var copyElem = document.getElementById(
"copyMenuItem");
902 var clearElem = document.getElementById(
"clearMenuItem");
903 var pasteElem = document.getElementById(
"pasteMenuItem");
904 var getArtworkElem = document.getElementById(
"getArtworkMenuItem");
905 var getArtworkSeparatorElem = document.getElementById(
"getArtworkSeparator");
908 var shouldHideGetArtwork = AlbumArt.shouldHideGetArtworkCommand();
909 getArtworkSeparatorElem.hidden = shouldHideGetArtwork;
910 getArtworkElem.hidden = shouldHideGetArtwork;
913 getArtworkElem.disabled =
false;
916 var validAlbumArt = {};
917 AlbumArt.getClipboardAlbumArt({}, {}, validAlbumArt);
918 validAlbumArt = validAlbumArt.value;
922 cutElem.disabled =
true;
923 copyElem.disabled =
true
924 clearElem.disabled =
true;
927 cutElem.disabled = !curImageUrl;
928 copyElem.disabled = !curImageUrl;
929 clearElem.disabled = !curImageUrl;
934 pasteElem.disabled = !validAlbumArt || shouldHideGetArtwork;
938 shouldHideGetArtworkCommand:
function AlbumArt_shouldHideGetArtworkCommand() {
941 var items = AlbumArt._mediaListView.selection.selectedMediaItems;
942 while (items.hasMoreElements()) {
943 var item = items.getNext().QueryInterface(Ci.sbIMediaItem);
944 if (item.getProperty(SBProperties.contentType) ==
"audio") {
952 var item = AlbumArt.getNowPlayingItem();
953 if (item && item.getProperty(SBProperties.contentType) ==
"audio") {
964 autoFetchArtwork:
function AlbumArt_autoFetchArtwork() {
966 if (this._autoFetchTimeoutID) {
967 clearTimeout(this._autoFetchTimeoutID)
968 this._autoFetchTimeoutID =
null;
973 var func =
function() {
974 _this._autoFetchTimeoutID =
null;
975 _this._autoFetchArtwork();
977 this._autoFetchTimeoutID =
setTimeout(func, 1000);
980 _autoFetchArtwork:
function AlbumArt__autoFetchArtwork() {
984 item = this.getNowPlayingItem();
987 if (AlbumArt._mediaListView)
988 item = AlbumArt._mediaListView.selection.currentMediaItem;
992 if (item == AlbumArt._prevAutoFetchArtworkItem)
994 AlbumArt.prevAutoFetchArtworkItem = item;
1002 var primaryImageURL = item.getProperty(SBProperties.primaryImageURL);
1003 var attemptedRemoteArtFetch =
1004 item.getProperty(SBProperties.attemptedRemoteArtFetch);
1005 if (!primaryImageURL && !attemptedRemoteArtFetch) {
1006 var sip = Cc[
"@mozilla.org/supports-interface-pointer;1"]
1007 .createInstance(Ci.nsISupportsInterfacePointer);
1008 sip.data = ArrayConverter.nsIArray([item]);
1009 sbCoverHelper.getArtworkForItems(sip.data,
window, item.library,
true);
1021 getSupportedFlavours :
function AlbumArt_getSupportedFlavours() {
1023 var shouldHideGetArtwork = AlbumArt.shouldHideGetArtworkCommand();
1024 if (shouldHideGetArtwork)
1027 var flavours =
new FlavourSet();
1028 return sbCoverHelper.getFlavours(flavours);
1037 onDrop:
function AlbumArt_onDrop(aEvent, aDropData, aSession) {
1039 sbCoverHelper.handleDrop(
function (newFile) {
1041 self.setCurrentStateItemImage(newFile);
1052 onDragOver:
function AlbumArt_onDragOver(aEvent, aFlavour, aSesssion) {
1063 onDragStart:
function AlbumArt_onDragStart(aEvent, aTransferData, aAction) {
1064 var imageURL = AlbumArt.getCurrentStateItemImage();
1065 aTransferData.data =
new TransferData();
1066 sbCoverHelper.setupDragTransferData(aTransferData, imageURL);
1076 onPaste:
function AlbumArt_onPaste() {
1079 AlbumArt.getClipboardAlbumArt(mimeType, imageData, {});
1080 mimeType = mimeType.value;
1081 imageData = imageData.value;
1082 if (imageData && sbCoverHelper.isImageSizeValid(
null, imageData.length)) {
1083 var artService = Cc[
"@songbirdnest.com/Songbird/album-art-service;1"]
1084 .getService(Ci.sbIAlbumArtService);
1086 var
newURI = artService.cacheImage(mimeType,
1090 AlbumArt.setCurrentStateItemImage(newURI.spec);
1098 onCopy:
function AlbumArt_onCopy() {
1099 var sbClipboard = Cc[
"@songbirdnest.com/moz/clipboard/helper;1"]
1100 .createInstance(Ci.sbIClipboardHelper);
1101 var aImageURL = AlbumArt.getCurrentStateItemImage();
1102 var
ioService = Cc[
"@mozilla.org/network/io-service;1"]
1103 .getService(Ci.nsIIOService);
1104 var imageURI =
null;
1106 imageURI = ioService.newURI(aImageURL,
null,
null);
1108 Cu.reportError(
"albumArtPane: Unable to convert to URI: [" + aImageURL +
1114 if (imageURI instanceof Ci.nsIFileURL) {
1115 var imageFile = imageURI.file.QueryInterface(Ci.nsILocalFile);
1116 var imageData, mimeType;
1117 [imageData, mimeType] = sbCoverHelper.readImageData(imageFile);
1120 sbClipboard.pasteImageToClipboard(mimeType, imageData, imageData.length);
1123 Cu.reportError(
"albumArtPane: Unable to paste to the clipboard " + err);
1134 onCut:
function AlbumArt_onCut() {
1135 if (this.onCopy()) {
1143 onGetArtwork:
function AlbumArt_onGetArtwork() {
1146 var library = AlbumArt._mediaListView.mediaList.library;
1149 var isAudioItem =
function(aElement) {
1150 return aElement.getProperty(SBProperties.contentType) ==
"audio";
1153 AlbumArt._mediaListView.selection.selectedMediaItems,
1158 var sip = Cc[
"@mozilla.org/supports-interface-pointer;1"]
1159 .createInstance(Ci.nsISupportsInterfacePointer);
1160 sip.data = selectedAudioItems;
1161 selectedAudioItems = sip.data;
1163 sbCoverHelper.getArtworkForItems(selectedAudioItems,
1168 var item = AlbumArt.getNowPlayingItem();
1169 if (item.getProperty(SBProperties.contentType !=
"audio")) {
1170 Components.utils.reportError(
"albumArtPane.js::onGetArtwork: \n"+
1171 "shouldn't try to get album art for non-audio items.");
1177 var sip = Cc[
"@mozilla.org/supports-interface-pointer;1"]
1178 .createInstance(Ci.nsISupportsInterfacePointer);
1179 sip.data = ArrayConverter.nsIArray([item]);
1180 sbCoverHelper.getArtworkForItems(sip.data,
window, item.library);
1189 onClear:
function AlbumArt_onClear() {
1190 AlbumArt.setCurrentStateItemImage(
"");
1200 onSelectionChanged:
function AlbumArt_onSelectionChanged() {
1202 var selection = AlbumArt._mediaListView.selection;
1203 var curImageUrl =
null;
1204 var item = selection.currentMediaItem;
1207 AlbumArt.clearNowSelectedMediaItem();
1211 AlbumArt._nowSelectedMediaItem = item;
1212 AlbumArt._nowSelectedMediaItemWatcher =
1213 Cc[
"@songbirdnest.com/Songbird/Library/MediaItemWatcher;1"]
1214 .createInstance(Ci.sbIMediaItemWatcher);
1215 var
filter = SBProperties.createArray([ [ SBProperties.primaryImageURL,
1217 AlbumArt._nowSelectedMediaItemWatcher.watch(item,
this, filter);
1223 curImageUrl = item.getProperty(SBProperties.primaryImageURL);
1226 AlbumArt.changeNowSelected(curImageUrl);
1233 onCurrentIndexChanged:
function AlbumArt_onCurrentIndexChanged() {
1243 onItemRemoved:
function AlbumArt_onItemRemoved(aMediaItem) {
1250 onItemUpdated:
function AlbumArt_onItemUpdated(aMediaItem) {
1253 this._nowSelectedMediaItem.getProperty(SBProperties.primaryImageURL);
1254 AlbumArt.changeNowSelected(curImageUrl);
1260 onMediacoreEvent:
function AlbumArt_onMediacoreEvent(aEvent) {
1261 switch(aEvent.type) {
1262 case Ci.sbIMediacoreEvent.STREAM_END:
1263 case Ci.sbIMediacoreEvent.STREAM_STOP:
1267 case Ci.sbIMediacoreEvent.TRACK_CHANGE:
1268 AlbumArt.onBeforeTrackChange(aEvent.data);
1275 onStop:
function AlbumArt_onStop() {
1277 AlbumArt.changeNowPlaying(
null);
1283 onBeforeTrackChange:
function AlbumArt_onBeforeTrackChange(aItem) {
1284 var newImageURL = aItem.getProperty(SBProperties.primaryImageURL);
1285 AlbumArt.changeNowPlaying(newImageURL);
1290 onTrackIndexChange:
function AlbumArt_onTrackIndexChange(aItem, aView, aIndex) { },
1294 onBeforeViewChange:
function AlbumArt_onBeforeViewChange(aView) { },
1298 onViewChange:
function AlbumArt_onViewChange(aView) { },
1302 onTrackChange:
function AlbumArt_onTrackChange(aItem, aView, aIndex) { },
1307 QueryInterface: XPCOMUtils.generateQI([Ci.sbIMediacoreEventListener,
1308 Ci.sbIMediaListViewSelectionListener])
1313 window.addEventListener(
"DOMContentLoaded", AlbumArt.onLoad,
false);
1314 window.addEventListener(
"unload", AlbumArt.onUnload,
false);
function SBFilteredEnumerator(aEnumerator, aFilterFunc)
function onDisplayPaneMenuPopup(command, menupopup, doc)
function doc() browser.contentDocument
dndDefaultHandler_module onDragOver
sbOSDControlService prototype QueryInterface
const DISPLAY_PANE_CONTENTURL
function SBString(aKey, aDefault, aStringBundle)
function onStop(ch, cx, status, data)
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
function newURI(aURLString)
return!aWindow arguments!aWindow arguments[0]
Javascript wrappers for common library tasks.
function onUnload()
onUnload - called when the cover preview window unloads.
Array filter(tab.attributes, function(aAttr){return(_this.xulAttributes.indexOf(aAttr.name) >-1);}).forEach(tab.removeAttribute
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe