Advertisement
r0k

foo_WSH_browser

r0k
Jun 3rd, 2012
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==PREPROCESSOR==
  2. // @name "Library Browser"
  3. // @version "0.6 - alpha 1"
  4. // @author "r0k"
  5. // @import"%fb2k_profile_path%user-components\foo_WSH_browser\Constructors.js"
  6. // @import"%fb2k_profile_path%user-components\foo_WSH_browser\Helpers.js"
  7. // ==/PREPROCESSOR==
  8.  
  9. /* =========================================== IMPORTANT ============================================
  10.    You need to install files Constructors.js and Helpers.js in your user-components\foo_WSH_browser
  11.    folder for this script to work.
  12.    If you want graphical genre buttons, you can download plenty of images at this web page
  13.    http://www.flickr.com/groups/itunesgenres/pool/
  14.    Add them to user-components\foo_WSH_browser\artwork\ or change the path in the panel properties.
  15.    The final "\" is required in the path. Will be fixed for final release.
  16.    ================================================================================================== */
  17.  
  18. /* ****************************************** Get Options *******************************************
  19.  * Load the properties or use the default values if no custom properties are defined.
  20.  */
  21. void window.GetProperty("Options _________________________", "_________________________________________");
  22. $options = {}; $views = [{}, {},  {}, {}, {}];
  23. $options.artworkPath = window.GetProperty("options.artworkPath",
  24.                         fb.ProfilePath + "user-components\\foo_WSH_browser\\artwork\\");
  25. $options.playlistName = window.GetProperty("options.playlistName", "@WSH_Browser_View");
  26. $options.playlistID = window.GetProperty("options.playlistID", 0);
  27. $options.playingName = window.GetProperty("options.playingPlaylistName", "@Now_Playing");
  28. $options.playingID = window.GetProperty("options.playingPlaylistID", 1);
  29. $options.fontName = window.GetProperty("options.fontName", "");
  30. $options.fontSize = window.GetProperty("options.fontSize", "");
  31. void window.GetProperty("Views ___________________________", "_________________________________________");
  32. $views[0].name = window.GetProperty("views.0._name", "Alphabetic");
  33. $views[0].groupKey = window.GetProperty("views.0.groupKey", "$cut(%album artist%,1)%album artist%%album%");
  34. $views[0].sortKey = window.GetProperty("views.0.sortKey", "%album artist%%album%[%disc%]%tracknumber%");
  35. $views[0].filter = window.GetProperty("views.0.filter", ".");
  36. $views[1].name = window.GetProperty("views.1._name", "Genre");
  37. $views[1].groupKey = window.GetProperty("views.1.groupKey", "%genre%%album artist%%album%");
  38. $views[1].sortKey = window.GetProperty("views.1.sortKey", "%album artist%%album%[%disc%]%tracknumber%");
  39. $views[1].filter = window.GetProperty("views.1.filter", ".");
  40. $views[2].name = window.GetProperty("views.2._name", "");
  41. $views[2].groupKey = window.GetProperty("views.2.groupKey", "");
  42. $views[2].sortKey = window.GetProperty("views.2.sortKey", "");
  43. $views[2].filter = window.GetProperty("views.2.filter", "");
  44. $views[3].name = window.GetProperty("views.3._name", "");
  45. $views[3].groupKey = window.GetProperty("views.3.groupKey", "");
  46. $views[3].sortKey = window.GetProperty("views.3.sortKey", "");
  47. $views[3].filter = window.GetProperty("views.3.filter", "");
  48. $views[4].name = window.GetProperty("views.4._name", "");
  49. $views[4].groupKey = window.GetProperty("views.4.groupKey", "");
  50. $views[4].sortKey = window.GetProperty("views.4.sortKey", "");
  51. $views[4].filter = window.GetProperty("views.4.filter", "");
  52.  
  53. /* **************************************** Declare Objects *****************************************
  54.  * Declare the objects that will be used later by the script.
  55.  */
  56. var ƒplaylist = new PlayListObject($options.playlistID, $options.playlistName, 0, false);
  57. var ƒplayingPl = new PlayListObject($options.playingID, $options.playingName, 0, false);
  58. var ƒlibrary = new MetaDBObject("ƒlibrary");
  59. var ƒcontrol = new ToolbarObject("ƒcontrol");
  60. var ƒview = new ToolbarObject("ƒview","grid|img",30,0,0,150,150);
  61. var $system = {scriptName : "foo_WSH_browser 0.6", toolbars : [ƒcontrol,ƒview], is_resizing : false};
  62.  
  63. /* ************************************** Functions Definition **************************************
  64.  * Define functions used by the script.
  65.  */
  66. function on_init() { // Will run once at start.
  67. //--Add the buttons on the control toolbar
  68.     if ($views[0].name) ƒcontrol.addButton($views[0].name, function () {setMasterView(0);});
  69.     if ($views[1].name) ƒcontrol.addButton($views[1].name, function () {setMasterView(1);});
  70.     if ($views[2].name) ƒcontrol.addButton($views[2].name, function () {setMasterView(2);});
  71.     if ($views[3].name) ƒcontrol.addButton($views[3].name, function () {setMasterView(3);});
  72.     if ($views[4].name) ƒcontrol.addButton($views[4].name, function () {setMasterView(4);});
  73.   //ƒcontrol.addButton("Configure", function () {window.ShowConfigure()});
  74.   //ƒcontrol.addButton("Console", function () {fb.ShowConsole()});
  75. //--Format colors and fonts -> Should be move to first block.
  76.     if ($options.fontName) {
  77.         $options.font = gdi.Font($options.fontName, $options.fontSize);
  78.         delete $options.fontName; delete $options.fontSize;
  79.     } else {
  80.         $options.font = getFont("item");
  81.         delete $options.fontName; delete $options.fontSize;
  82.     }
  83.     $options.colorBack = getColor("background");
  84.     $options.colorSel = getColor("select");
  85. //--Initialise objects
  86.     ƒplaylist.doCreate();
  87.     ƒlibrary.doListHandles($views[0].filter,$views[0].sortKey);
  88. //--Set system(panel) settings to a working state.
  89.     $system.themeButton = window.CreateThemeManager("Button");
  90.     $system.activeToolbar = null; $system.activeButton = null;
  91.     $system.groupBy = doSplitTitleFormatString($views[0].groupKey); $system.groupLevel = 0;
  92.     $system.is_resizing = false;
  93.     $system.imgPath = $options.artworkPath;
  94.     $system.currentView = 0;
  95.     $system.initDone = true;
  96.     doPrint("Panel initilised","on_init");
  97. //--Update toolbars size to fit the panel.
  98.     ƒcontrol.width = $system.panelW;
  99.     ƒview.width = $system.panelW; ƒview.updateHeight($system.panelH - 30);
  100. //--Call setMasterView to initialise default view.
  101.     setMasterView(0);
  102. }
  103.  
  104. function setMasterView(_viewNb) {
  105.     $system.currentView = _viewNb;
  106.     $system.groupBy = doSplitTitleFormatString($views[_viewNb].groupKey);
  107.     $system.groupLevel = 0
  108.     //ƒlibrary.doResetHandles();
  109.     ƒlibrary.doListHandles($views[_viewNb].filter,$views[_viewNb].sortKey);
  110.     ƒlibrary.doGroups($system.groupBy[$system.groupLevel]);
  111.     __groupsArray = ƒlibrary.getGroups();
  112.     ƒview.doClear();
  113.     for (var i=0; i<__groupsArray.length; i++) {
  114.         ƒview.addButton(__groupsArray[i], function () {doFilterView(this.args)}, __groupsArray[i]);
  115.     }
  116.     ƒplaylist.setContent(ƒlibrary.hndList);
  117.     window.Repaint();
  118. }
  119.  
  120. function doFilterView(filter) {
  121.     $system.groupLevel++;
  122.     ƒlibrary.doFilterHandles(filter);
  123.     if ($system.groupLevel < $system.groupBy.length) {
  124.         ƒplaylist.setContent(ƒlibrary.hndList);
  125.         ƒlibrary.doGroups($system.groupBy[$system.groupLevel]);
  126.         __groupsArray = ƒlibrary.getGroups();
  127.         ƒview.doClear();
  128.         for (var i=0; i<__groupsArray.length; i++) {
  129.             ƒview.addButton(__groupsArray[i], function () {doFilterView(this.args)}, __groupsArray[i]);
  130.         }
  131.         window.Repaint();
  132.     } else {
  133.         ƒplayingPl.doCreate();
  134.         ƒplayingPl.setContent(ƒlibrary.hndList);
  135.         ƒplayingPl.doPlay();
  136.     }
  137. }
  138.  
  139. // ******************************************* Callbacks ********************************************
  140.  
  141. function on_size_done() {
  142.     $system.is_resizing = false;
  143.     $system.panelW = window.Width; $system.panelH = window.Height;
  144.     doPrint("New size : "+$system.panelW+"/"+$system.panelH,"on_size_done");
  145.     ƒcontrol.doRecalculateLayout($system.panelW,false);
  146.     ƒview.doRecalculateLayout($system.panelW,$system.panelH-ƒcontrol.height);
  147.     window.Repaint();
  148. }
  149.  
  150. function on_size() { // on_size will also run once when the script first starts.
  151.     if (!($system.is_resizing)) {
  152.         $system.is_resizing = true
  153.         is_resizing(function() {on_size_done();});
  154.     } // && ($system.panelW != window.Width || $system.panelH != window.Height))
  155. }
  156.  
  157. function on_paint(gr) { // runs when the panel, or part of the panel is painted by using window.Repaint();
  158.     ƒcontrol.drawButtons(gr);
  159.     ƒview.drawButtons(gr);
  160. }
  161.  
  162. //--------------- Mouse actions callbacks
  163. function on_mouse_move(x, y) {
  164.     for (var i in $system.toolbars) {
  165.         if ($system.toolbars[i].getActiveStatus(y)) $system.activeButton = $system.toolbars[i].getActiveButton(x, y);
  166.     }
  167. }
  168.  
  169. function on_mouse_lbtn_down(x, y) {
  170.     if ($system.activeButton) $system.activeButton.onClick();
  171. }
  172.  
  173. function on_mouse_wheel(delta) {
  174.     if ((delta<0) || (ƒview.visible.row1>0)) {
  175.         ƒview.visible.row1 -= delta;
  176.         ƒview.doRecalculateLayout();
  177.         window.Repaint();
  178.     }
  179. }
  180. /* ***************************** Script Body (unconditional statements) *****************************
  181.  * Initialise the panel when everything else has been loaded.
  182.  * The delay allows initial callbacks to resolve and data to load. Without delay the panel will crash.
  183.  */
  184. window.SetTimeout(on_init, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement