Utils.jsm
Go to the documentation of this file.
1 var EXPORTED_SYMBOLS = [ "Utils" ];
2 
3 const Cc = Components.classes;
4 const Ci = Components.interfaces;
5 const Cu = Components.utils;
6 
7 const SP_CONTRACTID = "@songbirdnest.com/servicepane/library;1";
8 
9 Cu.import("resource://app/jsmodules/sbProperties.jsm");
10 Cu.import("resource://app/jsmodules/StringUtils.jsm");
11 var Application = Cc["@mozilla.org/fuel/application;1"]
12  .getService(Ci.fuelIApplication);
13 
17 Utils = {
18  LS_NS: "http://songbirdnest.com/rdf/library-servicepane#",
19  SC_NS: "http://songbirdnest.com/rdf/shoutcast-servicepane#",
20 
21  ensureFavouritesNode: function() {
22  let SPS = Cc['@songbirdnest.com/servicepane/service;1']
23  .getService(Ci.sbIServicePaneService);
24 
25  // Don't do anything if node exists already
26  if (SPS.getNodesByAttributeNS(this.SC_NS, "SHOUTcast", "true").length > 0)
27  return;
28 
29  // Get favorites list
30  let libGuid = Application.prefs.getValue("extensions.shoutcast-radio.templib.guid", "");
31  if (libGuid == "")
32  return;
33 
34  let libraryManager =
35  Cc["@songbirdnest.com/Songbird/library/Manager;1"]
36  .getService(Ci.sbILibraryManager);
37  let tempLib;
38  try {
39  tempLib = libraryManager.getLibrary(libGuid);
40  } catch (e) {
41  // Library wasn't created yet - don't create a node
42  return;
43  }
44 
45  let array = tempLib.getItemsByProperty(SBProperties.customType,
46  "radio_favouritesList");
47  if (!array.length)
48  return;
49 
50  let favesList = array.queryElementAt(0, Ci.sbIMediaList);
51  if (!favesList.length) {
52  // Don't create a node if we don't have any favorites
53  return;
54  }
55 
56  // Get radio folder
57  let radioFolder = SPS.getNode("SB:RadioStations");
58  if (!radioFolder) {
59  Components.utils.reportError(new Exception("Unexpected: attempt to create SHOUTcast favorites node without radio folder being created first"));
60  return;
61  }
62 
63  // Create a node
64  let strings = new SBStringBundle("chrome://shoutcast-radio/locale/overlay.properties");
65  let node = SPS.createNode();
66  // The new service pane service needs the list guid in the id
67  node.id = "urn:item:" + favesList.guid;
68  node.className = "medialist-favorites medialist medialisttype-" + favesList.type;
69  node.name = strings.get("favourites", "Favorite Stations");
70  node.contractid = SP_CONTRACTID;
71  node.editable = false;
72  node.setAttributeNS(this.LS_NS, "ListType", favesList.type);
73  node.setAttributeNS(this.LS_NS, "ListGUID", favesList.guid);
74  node.setAttributeNS(this.LS_NS, "LibraryGUID", tempLib.guid);
75  node.setAttributeNS(this.LS_NS, "ListCustomType", favesList.getProperty(SBProperties.customType));
76  node.setAttributeNS(this.LS_NS, "LibraryCustomType", tempLib.getProperty(SBProperties.customType));
77  node.setAttributeNS(this.SC_NS, "SHOUTcast", "true"); // to be recognizeable
78  radioFolder.appendChild(node);
79  }
80 }
inArray array
const SC_NS
const Ci
Definition: Utils.jsm:4
const Cc
Definition: Utils.jsm:3
const SP_CONTRACTID
Definition: Utils.jsm:7
var strings
Definition: Info.js:46
var libraryManager
function SBStringBundle(aBundle)
const Cu
Definition: Utils.jsm:5
var EXPORTED_SYMBOLS
Definition: Utils.jsm:1
var Application
Definition: Utils.jsm:11
let node
Selectors Utils