Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==PREPROCESSOR==
- // @name "Library Browser"
- // @version "0.6 - alpha 1"
- // @author "r0k"
- // @import"%fb2k_profile_path%user-components\foo_WSH_browser\Constructors.js"
- // @import"%fb2k_profile_path%user-components\foo_WSH_browser\Helpers.js"
- // ==/PREPROCESSOR==
- /* =========================================== IMPORTANT ============================================
- You need to install files Constructors.js and Helpers.js in your user-components\foo_WSH_browser
- folder for this script to work.
- If you want graphical genre buttons, you can download plenty of images at this web page
- http://www.flickr.com/groups/itunesgenres/pool/
- Add them to user-components\foo_WSH_browser\artwork\ or change the path in the panel properties.
- The final "\" is required in the path. Will be fixed for final release.
- ================================================================================================== */
- /* ****************************************** Get Options *******************************************
- * Load the properties or use the default values if no custom properties are defined.
- */
- void window.GetProperty("Options _________________________", "_________________________________________");
- $options = {}; $views = [{}, {}, {}, {}, {}];
- $options.artworkPath = window.GetProperty("options.artworkPath",
- fb.ProfilePath + "user-components\\foo_WSH_browser\\artwork\\");
- $options.playlistName = window.GetProperty("options.playlistName", "@WSH_Browser_View");
- $options.playlistID = window.GetProperty("options.playlistID", 0);
- $options.playingName = window.GetProperty("options.playingPlaylistName", "@Now_Playing");
- $options.playingID = window.GetProperty("options.playingPlaylistID", 1);
- $options.fontName = window.GetProperty("options.fontName", "");
- $options.fontSize = window.GetProperty("options.fontSize", "");
- void window.GetProperty("Views ___________________________", "_________________________________________");
- $views[0].name = window.GetProperty("views.0._name", "Alphabetic");
- $views[0].groupKey = window.GetProperty("views.0.groupKey", "$cut(%album artist%,1)%album artist%%album%");
- $views[0].sortKey = window.GetProperty("views.0.sortKey", "%album artist%%album%[%disc%]%tracknumber%");
- $views[0].filter = window.GetProperty("views.0.filter", ".");
- $views[1].name = window.GetProperty("views.1._name", "Genre");
- $views[1].groupKey = window.GetProperty("views.1.groupKey", "%genre%%album artist%%album%");
- $views[1].sortKey = window.GetProperty("views.1.sortKey", "%album artist%%album%[%disc%]%tracknumber%");
- $views[1].filter = window.GetProperty("views.1.filter", ".");
- $views[2].name = window.GetProperty("views.2._name", "");
- $views[2].groupKey = window.GetProperty("views.2.groupKey", "");
- $views[2].sortKey = window.GetProperty("views.2.sortKey", "");
- $views[2].filter = window.GetProperty("views.2.filter", "");
- $views[3].name = window.GetProperty("views.3._name", "");
- $views[3].groupKey = window.GetProperty("views.3.groupKey", "");
- $views[3].sortKey = window.GetProperty("views.3.sortKey", "");
- $views[3].filter = window.GetProperty("views.3.filter", "");
- $views[4].name = window.GetProperty("views.4._name", "");
- $views[4].groupKey = window.GetProperty("views.4.groupKey", "");
- $views[4].sortKey = window.GetProperty("views.4.sortKey", "");
- $views[4].filter = window.GetProperty("views.4.filter", "");
- /* **************************************** Declare Objects *****************************************
- * Declare the objects that will be used later by the script.
- */
- var ƒplaylist = new PlayListObject($options.playlistID, $options.playlistName, 0, false);
- var ƒplayingPl = new PlayListObject($options.playingID, $options.playingName, 0, false);
- var ƒlibrary = new MetaDBObject("ƒlibrary");
- var ƒcontrol = new ToolbarObject("ƒcontrol");
- var ƒview = new ToolbarObject("ƒview","grid|img",30,0,0,150,150);
- var $system = {scriptName : "foo_WSH_browser 0.6", toolbars : [ƒcontrol,ƒview], is_resizing : false};
- /* ************************************** Functions Definition **************************************
- * Define functions used by the script.
- */
- function on_init() { // Will run once at start.
- //--Add the buttons on the control toolbar
- if ($views[0].name) ƒcontrol.addButton($views[0].name, function () {setMasterView(0);});
- if ($views[1].name) ƒcontrol.addButton($views[1].name, function () {setMasterView(1);});
- if ($views[2].name) ƒcontrol.addButton($views[2].name, function () {setMasterView(2);});
- if ($views[3].name) ƒcontrol.addButton($views[3].name, function () {setMasterView(3);});
- if ($views[4].name) ƒcontrol.addButton($views[4].name, function () {setMasterView(4);});
- //ƒcontrol.addButton("Configure", function () {window.ShowConfigure()});
- //ƒcontrol.addButton("Console", function () {fb.ShowConsole()});
- //--Format colors and fonts -> Should be move to first block.
- if ($options.fontName) {
- $options.font = gdi.Font($options.fontName, $options.fontSize);
- delete $options.fontName; delete $options.fontSize;
- } else {
- $options.font = getFont("item");
- delete $options.fontName; delete $options.fontSize;
- }
- $options.colorBack = getColor("background");
- $options.colorSel = getColor("select");
- //--Initialise objects
- ƒplaylist.doCreate();
- ƒlibrary.doListHandles($views[0].filter,$views[0].sortKey);
- //--Set system(panel) settings to a working state.
- $system.themeButton = window.CreateThemeManager("Button");
- $system.activeToolbar = null; $system.activeButton = null;
- $system.groupBy = doSplitTitleFormatString($views[0].groupKey); $system.groupLevel = 0;
- $system.is_resizing = false;
- $system.imgPath = $options.artworkPath;
- $system.currentView = 0;
- $system.initDone = true;
- doPrint("Panel initilised","on_init");
- //--Update toolbars size to fit the panel.
- ƒcontrol.width = $system.panelW;
- ƒview.width = $system.panelW; ƒview.updateHeight($system.panelH - 30);
- //--Call setMasterView to initialise default view.
- setMasterView(0);
- }
- function setMasterView(_viewNb) {
- $system.currentView = _viewNb;
- $system.groupBy = doSplitTitleFormatString($views[_viewNb].groupKey);
- $system.groupLevel = 0
- //ƒlibrary.doResetHandles();
- ƒlibrary.doListHandles($views[_viewNb].filter,$views[_viewNb].sortKey);
- ƒlibrary.doGroups($system.groupBy[$system.groupLevel]);
- __groupsArray = ƒlibrary.getGroups();
- ƒview.doClear();
- for (var i=0; i<__groupsArray.length; i++) {
- ƒview.addButton(__groupsArray[i], function () {doFilterView(this.args)}, __groupsArray[i]);
- }
- ƒplaylist.setContent(ƒlibrary.hndList);
- window.Repaint();
- }
- function doFilterView(filter) {
- $system.groupLevel++;
- ƒlibrary.doFilterHandles(filter);
- if ($system.groupLevel < $system.groupBy.length) {
- ƒplaylist.setContent(ƒlibrary.hndList);
- ƒlibrary.doGroups($system.groupBy[$system.groupLevel]);
- __groupsArray = ƒlibrary.getGroups();
- ƒview.doClear();
- for (var i=0; i<__groupsArray.length; i++) {
- ƒview.addButton(__groupsArray[i], function () {doFilterView(this.args)}, __groupsArray[i]);
- }
- window.Repaint();
- } else {
- ƒplayingPl.doCreate();
- ƒplayingPl.setContent(ƒlibrary.hndList);
- ƒplayingPl.doPlay();
- }
- }
- // ******************************************* Callbacks ********************************************
- function on_size_done() {
- $system.is_resizing = false;
- $system.panelW = window.Width; $system.panelH = window.Height;
- doPrint("New size : "+$system.panelW+"/"+$system.panelH,"on_size_done");
- ƒcontrol.doRecalculateLayout($system.panelW,false);
- ƒview.doRecalculateLayout($system.panelW,$system.panelH-ƒcontrol.height);
- window.Repaint();
- }
- function on_size() { // on_size will also run once when the script first starts.
- if (!($system.is_resizing)) {
- $system.is_resizing = true
- is_resizing(function() {on_size_done();});
- } // && ($system.panelW != window.Width || $system.panelH != window.Height))
- }
- function on_paint(gr) { // runs when the panel, or part of the panel is painted by using window.Repaint();
- ƒcontrol.drawButtons(gr);
- ƒview.drawButtons(gr);
- }
- //--------------- Mouse actions callbacks
- function on_mouse_move(x, y) {
- for (var i in $system.toolbars) {
- if ($system.toolbars[i].getActiveStatus(y)) $system.activeButton = $system.toolbars[i].getActiveButton(x, y);
- }
- }
- function on_mouse_lbtn_down(x, y) {
- if ($system.activeButton) $system.activeButton.onClick();
- }
- function on_mouse_wheel(delta) {
- if ((delta<0) || (ƒview.visible.row1>0)) {
- ƒview.visible.row1 -= delta;
- ƒview.doRecalculateLayout();
- window.Repaint();
- }
- }
- /* ***************************** Script Body (unconditional statements) *****************************
- * Initialise the panel when everything else has been loaded.
- * The delay allows initial callbacks to resolve and data to load. Without delay the panel will crash.
- */
- window.SetTimeout(on_init, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement