From d3a5d3d229bcd7846ec05774eaa6b05f66c0589c Mon Sep 17 00:00:00 2001 From: Prathyush Thota Date: Sat, 28 Mar 2009 05:02:59 +0530 Subject: [PATCH] Refactor player.js & Changed the install maxVersion to 1.2.0pre --- common/content/completion.js | 6 +- xulmus/content/player.js | 200 ++++++++++++++++++----------------- xulmus/install.rdf | 2 +- 3 files changed, 107 insertions(+), 101 deletions(-) diff --git a/common/content/completion.js b/common/content/completion.js index 0494759b..c5ee7a1a 100644 --- a/common/content/completion.js +++ b/common/content/completion.js @@ -1395,17 +1395,17 @@ function Completion() //{{{ if (args.completeArg == 0) { context.title = ["Artists"]; - context.completions = getArtists(); + context.completions = player.getArtists(); } else if (args.completeArg == 1) { context.title = ["Albums by " + args[0]]; - context.completions = getAlbums(args[0]); + context.completions = player.getAlbums(args[0]); } else if (args.completeArg == 2) { context.title = ["Tracks from " + args[1] + " by " + args[0]]; - context.completions = getTracks(args[0], args[1]); + context.completions = player.getTracks(args[0], args[1]); } }, diff --git a/xulmus/content/player.js b/xulmus/content/player.js index 4b22e0a2..2d8b3c0d 100755 --- a/xulmus/content/player.js +++ b/xulmus/content/player.js @@ -1,6 +1,6 @@ // Import Artist List as this can be huge -var artists = getArtistsArray(); + function Player() // {{{ { @@ -11,10 +11,53 @@ function Player() // {{{ let lastSearchString = ""; let lastSearchIndex = 0; let lastSearchView = _SBGetCurrentView(); - + // Get the focus to the visible playlist first //window._SBShowMainLibrary(); + + + function getArtistsArray() + { + var list = LibraryUtils.mainLibrary; + // Create an enumeration listener to count each item + var listener = { + count: 0, + onEnumerationBegin: function (aMediaList) { + this.count = 0; + }, + onEnumeratedItem: function (aMediaList, aMediaItem) { + this.count++; + }, + onEnumerationEnd: function (aMediaList, aStatusCode) {} + }; + + var artistCounts = {}; + var artists = list.getDistinctValuesForProperty(SBProperties.artistName); + var artist; + var artistArray = []; + var i = 0; + // Count the number of media items for each distinct artist + while (artists.hasMore()) + { + artist = artists.getNext(); + artistArray[i] = [artist, artist]; + list.enumerateItemsByProperty(SBProperties.artistName, + artist, + listener, + Ci.sbIMediaList.ENUMERATIONTYPE_LOCKING); + artistCounts[artist] = listener.count; + i++; + } + + //liberator.dump("Count : "+artistCounts.toSource()); + return artistArray; + } + + // Get the artist names before hand. + + let artists = getArtistsArray(); + const pageService = Components.classes["@songbirdnest.com/Songbird/MediaPageManager;1"] .getService(Components.interfaces.sbIMediaPageManager); // Register Callbacks for searching. @@ -550,7 +593,6 @@ function Player() // {{{ let mediaItemList = currentView.mediaList; let search = _getSearchString(currentView); let searchString = ""; - let index = 0; if (search != "") searchString = args + " " + search; @@ -565,7 +607,7 @@ function Player() // {{{ { lastSearchView = mySearchView; lastSearchIndex = 0; - focusTrack(mySearchView.getItemByIndex(index)); + focusTrack(mySearchView.getItemByIndex(lastSearchIndex)); } else { @@ -651,103 +693,67 @@ function Player() // {{{ { if (gMM.sequencer.currentItem) gMM.sequencer.currentItem.setProperty(SBProperties.rating, rating); + }, + + getArtists: function getArtists() + { + return artists; + }, + + getAlbums: function getAlbums(artist) + { + var list = LibraryUtils.mainLibrary; + var albumArray = [], returnArray = []; + var items = list.getItemsByProperty(SBProperties.artistName, artist).enumerate(); + var i = 0, j = 0; + + + while (items.hasMoreElements()) + { + album = items.getNext().getProperty(SBProperties.albumName); + albumArray[i] = [album, album]; + + if (i == 0) + { + returnArray[j] = albumArray[i]; + j++; + } + else if (albumArray[i-1].toString() != albumArray[i].toString()) + { + returnArray[i] = albumArray[i]; + j++; + } + i++; + } + + return returnArray; + }, + + getTracks: function getTracks(artist, album) + { + var list = LibraryUtils.mainLibrary; + var tracksArray = []; + var pa = Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"] + .createInstance(Ci.sbIMutablePropertyArray); + var i = 0; + + pa.appendProperty(SBProperties.artistName, artist.toString()); + pa.appendProperty(SBProperties.albumName, album.toString()); + var items = list.getItemsByProperties(pa).enumerate(); + + while (items.hasMoreElements()) + { + track = items.getNext().getProperty(SBProperties.trackName); + tracksArray[i] = [track, track]; + i++; + } + + return tracksArray; } + }; //}}} } // }}} -function getArtists() -{ - return this.artists; -} - -function getArtistsArray() -{ - var list = LibraryUtils.mainLibrary; - - // Create an enumeration listener to count each item - var listener = { - count: 0, - onEnumerationBegin: function (aMediaList) { - this.count = 0; - }, - onEnumeratedItem: function (aMediaList, aMediaItem) { - this.count++; - }, - onEnumerationEnd: function (aMediaList, aStatusCode) {} - }; - - var artistCounts = {}; - var artists = list.getDistinctValuesForProperty(SBProperties.artistName); - var artist; - var artistArray = []; - var i = 0; - // Count the number of media items for each distinct artist - while (artists.hasMore()) - { - artist = artists.getNext(); - artistArray[i] = [artist, artist]; - list.enumerateItemsByProperty(SBProperties.artistName, - artist, - listener, - Ci.sbIMediaList.ENUMERATIONTYPE_LOCKING); - artistCounts[artist] = listener.count; - i++; - } - - //liberator.dump("Count : "+artistCounts.toSource()); - return artistArray; -} - -function getAlbums(artist) -{ - var list = LibraryUtils.mainLibrary; - var albumArray = [], returnArray = []; - var items = list.getItemsByProperty(SBProperties.artistName, artist).enumerate(); - var i = 0, j = 0; - - - while (items.hasMoreElements()) - { - album = items.getNext().getProperty(SBProperties.albumName); - albumArray[i] = [album, album]; - - if (i == 0) - { - returnArray[j] = albumArray[i]; - j++; - } - else if (albumArray[i-1].toString() != albumArray[i].toString()) - { - returnArray[i] = albumArray[i]; - j++; - } - i++; - } - - return returnArray; -} - -function getTracks(artist, album) -{ - var list = LibraryUtils.mainLibrary; - var tracksArray = []; - var pa = Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"] - .createInstance(Ci.sbIMutablePropertyArray); - var i = 0; - - pa.appendProperty(SBProperties.artistName, artist.toString()); - pa.appendProperty(SBProperties.albumName, album.toString()); - var items = list.getItemsByProperties(pa).enumerate(); - - while (items.hasMoreElements()) - { - track = items.getNext().getProperty(SBProperties.trackName); - tracksArray[i] = [track, track]; - i++; - } - - return tracksArray; -} // vim: set fdm=marker sw=4 ts=4 et: diff --git a/xulmus/install.rdf b/xulmus/install.rdf index 7dccc3a8..3851c0af 100755 --- a/xulmus/install.rdf +++ b/xulmus/install.rdf @@ -12,7 +12,7 @@ songbird@songbirdnest.com 0.8.0pre - 1.1.0pre + 1.2.0pre