central.js
Go to the documentation of this file.
1 /* central.js
2  * This will be loaded into the main window, and manage all global Playlist
3  * Folder related tasks.
4  */
5 // Make a namespace.
6 if (typeof playlistfolders == 'undefined') {
7  var playlistfolders = {};
8 };
9 
10 /* Central controller
11  * Controller for central issues, like startup and shutdown.
12  */
13 playlistfolders.central={
14  // Startup code for the central controller
15  onLoad: function(e){
16  this.logEvent("central", "Central controller initialisation started.", 5);
17  try {
18  // Load localisation
19  var sbSvc = Cc["@mozilla.org/intl/stringbundle;1"].
20  getService(Ci.nsIStringBundleService);
21  var stringBundle = sbSvc.createBundle("chrome://songbird/locale/" +
22  "songbird.properties");
23  document.getElementById("menuitem_file_folder").
24  setAttribute("label",
25  stringBundle.GetStringFromName("menu.servicepane." +
26  "file.folder"));
27  document.getElementById("menuitem_file_folder").
28  setAttribute("accesskey",
29  stringBundle.GetStringFromName("menu.servicepane." +
30  "file.folder." +
31  "accesskey"));
32 
33  // Load the other global controllers
34  playlistfolders.preferences.onLoad(e);
35  playlistfolders.servicepane.onLoad(e);
36  // We're done!
37  this.logEvent("central", "Central controller started.", 4);
38  } catch (e){
39  this.logEvent("central", "Startup of Central controller failed:\n\n" + e,
40  1, "chrome://playlistfolders/content/central.js",
41  e.lineNumber);
42  }
43  },
44 
45  // Shutdown code for the central controller
46  onUnload: function(e){
47  this.logEvent("central", "Central controller shutdown started.", 5);
48  // Unload other global controllers
49  playlistfolders.preferences.onUnload(e);
50  playlistfolders.servicepane.onUnload(e);
51  // We're done!
52  this.logEvent("central", "Central controller stopped.", 4);
53  },
54 
55  /* Post event in error console, if logging of event type is turned on
56  * module (string): what module caused the event (for example: "central")
57  * msg (string): more detailed description what happened
58  * type (int): What event type the error is:
59  * 1: fatal error
60  * 2: error
61  * 3: warning
62  * 4: essential debug message (for example startup/shutdown of controllers)
63  * 5: debug message (for example renaming of a folder)
64  * srcFile (string): The source file's URL, or null (errors and warnings)
65  * srcLine (int): The event's line number, or null (errors and warnings)
66  */
67  logEvent: function(module, msg, type, srcFile, srcLine){
68  // Drop messages for that logging is disabled
69  if (playlistfolders.preferences.getEvtLogLevel() < type)
70  return;
71  // Parse message
72  var msgStr = "Playlist Folders: Event raised in '" + module + "':\n" + msg;
73  // Post message
74  var consoleService = Components.classes["@mozilla.org/consoleservice;1"].
75  getService(Components.interfaces.nsIConsoleService);
76  switch (type){
77  case 1:
78  case 2:
79  case 3:
80  var message = Components.classes["@mozilla.org/scripterror;1"].
81  createInstance(Components.interfaces.nsIScriptError);
82  message.init(msgStr,
83  srcFile,
84  null,
85  srcLine == 0 ? null : srcLine,
86  null,
87  type != 3 ? 0x0 /*errorFlag*/ : 0x1 /*warningFlag*/,
88  null);
89  consoleService.logMessage(message);
90  break;
91  default:
92  consoleService.logStringMessage(msgStr);
93  }
94  },
95 
96  /* Deletes given Playlist without asking user, returns true if succeed
97  * playlist (string): GUID of the playlist to delete
98  */
99  removePlaylist: function(playlist){
100  this.logEvent("central", "Delete Playlist " + playlist, 5);
101  var library = Cc["@songbirdnest.com/Songbird/library/Manager;1"].
102  getService(Ci.sbILibraryManager).mainLibrary;
103  var pl = library.getItemByGuid(playlist);
104  if (pl){
105  library.remove(pl);
106  return true;
107  }
108  this.logEvent("central", "Could not delete Playlist " + playlist + "\n\n" +
109  "Playlist not found in library", 2,
110  "chrome://playlistfolders/content/central.js");
111  return true; // if we didn't find a playlist, continue deleting
112  },
113 };
114 
115 // load / unload central controller with window
116 window.addEventListener("load",
117  function(e){
118  playlistfolders.central.onLoad(e);
119  },
120  false);
121 window.addEventListener("unload",
122  function(e){
123  playlistfolders.central.onUnload(e);
124  },
125  false);
const Cc
sidebarFactory createInstance
Definition: nsSidebar.js:351
getService(Ci.sbIFaceplateManager)
let window
const module
Definition: httpd.js:4659
Lastfm onLoad
Definition: mini.js:36
GstMessage * message
return null
Definition: FeedWriter.js:1143
menuItem setAttribute("handlerType","client")
const Ci
function msg
function onUnload()
onUnload - called when the cover preview window unloads.
Definition: coverPreview.js:36