User Tools

Site Tools


Creating & Showing a Filtered View

Since the library is just a mediaList underneath, we can create a new mediaListView of it, and adjust its filter to be some value - thus creating a filtered view. We can then load it into the media tab (the first tab in the tabbrowser). This is useful if we want to show a filtered view of the user's main library for a given property key & value:

const Cu = Components.utils;
const Ci = Components.interfaces;
const Cc = Components.classes;

// import our JSMs for shortcuts cause i'm lazy

// get a pointer to the global tab browser
if (typeof(gBrowser) == "undefined")
    var gBrowser =  Cc[";1"]

// create a new view from the main library
var view = LibraryUtils.mainLibrary.createView();

// setup our filters to expose. we only care about setting the artist name, so that's
// the only index i'll save for now
var propIndex = view.cascadeFilterSet.appendFilter(SBProperties.artistName);

// set it to something useful.
view.cascadeFilterSet.set(propIndex, ["Weezer"], 1);

// now go load the view in the tabbrowser
gBrowser.loadMediaList(view.mediaList, null, null, view,
developer_center/recipe_book/extensions_and_core/media_library/creating_and_showing_a_filtered_view.txt · Last modified: 2013/12/28 09:06 by geekshadow