User Tools

Site Tools


developer_center:recipe_book:extensions_and_core:media_library:creating_and_showing_a_filtered_view

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
Cu.import("resource://app/jsmodules/sbLibraryUtils.jsm");
Cu.import("resource://app/jsmodules/sbProperties.jsm");

// get a pointer to the global tab browser
if (typeof(gBrowser) == "undefined")
    var gBrowser =  Cc["@mozilla.org/appshell/window-mediator;1"]
            .getService(Ci.nsIWindowMediator)
            .getMostRecentWindow("Songbird:Main").window.gBrowser;

// 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
view.cascadeFilterSet.appendFilter(SBProperties.genre);
var propIndex = view.cascadeFilterSet.appendFilter(SBProperties.artistName);
view.cascadeFilterSet.appendFilter(SBProperties.albumName);

// 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,
   "chrome://songbird/content/mediapages/filtersPage.xul");
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