1 if (typeof(
Cc) ==
"undefined")
2 var
Cc = Components.classes;
3 if (typeof(
Ci) ==
"undefined")
4 var
Ci = Components.interfaces;
5 if (typeof(
Cu) ==
"undefined")
6 var
Cu = Components.utils;
8 Cu.import(
"resource://shoutcast-radio/Utils.jsm");
10 if (typeof(songbirdMainWindow) ==
"undefined")
11 var songbirdMainWindow = Cc[
"@mozilla.org/appshell/window-mediator;1"]
12 .getService(Ci.nsIWindowMediator)
13 .getMostRecentWindow(
"Songbird:Main").window;
15 if (typeof(gBrowser) ==
"undefined")
16 var gBrowser = Cc[
"@mozilla.org/appshell/window-mediator;1"]
17 .getService(Ci.nsIWindowMediator)
18 .getMostRecentWindow(
"Songbird:Main").window.gBrowser;
21 var
ioService = Cc[
"@mozilla.org/network/io-service;1"]
22 .getService(Ci.nsIIOService);
24 #ifdef METRICS_ENABLED
25 if (typeof(gMetrics) ==
"undefined")
26 var gMetrics = Cc[
"@songbirdnest.com/Songbird/Metrics;1"]
27 .createInstance(Ci.sbIMetrics);
40 if (typeof(kPlaylistCommands) ==
"undefined") {
41 Cu.import(
"resource://app/components/kPlaylistCommands.jsm");
42 if (!kPlaylistCommands)
43 throw new Error(
"Import of kPlaylistCommands module failed!");
46 if (typeof(SBProperties) ==
"undefined") {
47 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
49 throw new Error(
"Import of sbProperties module failed");
53 Cu.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
55 throw new Error(
"Import of sbLibraryUtils module failed");
58 var RadioDirectory = {
67 var servicePaneStrings = Cc[
"@mozilla.org/intl/stringbundle;1"]
68 .getService(Ci.nsIStringBundleService)
69 .createBundle(
"chrome://shoutcast-radio/locale/overlay.properties");
71 document.title = servicePaneStrings.GetStringFromName(
"radioTabTitle");
73 #ifdef METRICS_ENABLED
77 gMetrics.metricsInc(
"shoutcast",
"directory",
"loaded");
81 this._strings = document.getElementById(
"shoutcast-radio-strings");
91 var menulist = document.getElementById(
"shoutcast-genre-menulist");
92 var
strings = Cc[
"@mozilla.org/intl/stringbundle;1"]
93 .getService(Ci.nsIStringBundleService)
94 .createBundle(
"chrome://shoutcast-radio/locale/genres.properties");
95 var genres = this.getGenres(strings);
98 menulist.appendItem(strings.GetStringFromName(
"genreTOP"),
"sbITop");
99 menulist.menupopup.appendChild(document.createElementNS(
100 "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
106 var thisgenre = genres[
i];
107 var el = menulist.appendItem(thisgenre.label, thisgenre.value);
108 if (genre == thisgenre.value) {
109 menulist.selectedItem = el;
114 menulist.selectedIndex = 0;
116 this.favouriteIDs = [];
122 this.playlist = document.getElementById(
"shoutcast-directory");
123 var
libraryManager = Cc[
'@songbirdnest.com/Songbird/library/Manager;1']
124 .getService(Ci.sbILibraryManager);
125 this.playlist.bind(this.radioLib.createView());
128 var playlistcolumns = this.playlist.tree.columns;
129 var columnbinds = [];
130 for (var
i = 0;
i < playlistcolumns.length;
i++)
134 playlistcolumns.getColumnAt(
i).element.getAttribute(
"bind"));
145 this.radioLib.setProperty(SBProperties.defaultColumnSpec, colSpec);
146 this.playlist.clearColumns();
149 this.playlist.appendColumn(
SC_comment,
"240");
151 this.playlist.appendColumn(SC_bookmark,
"55");
154 var ldtv = this.playlist.tree.view
155 .QueryInterface(Ci.sbILocalDatabaseTreeView);
158 this.playlist.addEventListener(
"PlaylistCellClick",
159 onPlaylistCellClick,
false);
160 this.playlist.addEventListener(
"Play", onPlay,
false);
163 this.loadTable(genre);
167 "extensions.shoutcast-radio.filter",
"");
168 if (filterValue !=
"") {
169 document.getElementById(
"filter").value = filterValue;
170 this.setFilter(filterValue);
174 getGenres :
function(
strings) {
177 var strings = Cc[
"@mozilla.org/intl/stringbundle;1"]
178 .getService(Ci.nsIStringBundleService).createBundle(
179 "chrome://shoutcast-radio/locale/genres.properties");
181 var iter = strings.getSimpleEnumeration();
182 var genres =
new Array();
183 while (iter.hasMoreElements()) {
184 var genreProp = iter.getNext()
185 .QueryInterface(Ci.nsIPropertyElement);
186 var genreValue = genreProp.key.substr(5);
187 var genreLabel = genreProp.value;
188 if (genreValue ==
"TOP")
190 genres.push({
value:genreValue,
label:genreLabel});
195 "extensions.shoutcast-radio.custom-genres",
"").split(
",");
196 for (
i in customGenres) {
197 if (customGenres[
i].length > 0) {
198 var custom = customGenres[
i];
199 custom = custom.replace(/^\s*/,
'').replace(/\s*$/,
'');
205 genres.sort(
function(a,b) {
206 return (a.label.toUpperCase() > b.label.toUpperCase());
213 RadioDirectory.playlist.removeEventListener(
"PlaylistCellClick",
214 onPlaylistCellClick,
false);
215 RadioDirectory.playlist.removeEventListener(
"Play", onPlay,
false);
217 getLibraries :
function() {
218 var libraryManager = Cc[
"@songbirdnest.com/Songbird/library/Manager;1"]
219 .getService(Ci.sbILibraryManager);
224 this.radioLib = libraryManager.getLibrary(libGuid);
235 this.radioLib.name =
"SHOUTcast Radio";
236 this.radioLib.setProperty(SBProperties.hidden,
"1");
237 dump(
"*** Created SHOUTcast Radio library, GUID: " +
239 libraryManager.registerLibrary(this.radioLib,
true);
247 this.tempLib = libraryManager.getLibrary(libGuid);
257 var a = this.tempLib.getItemsByProperty(
258 SBProperties.customType,
"radio_favouritesList");
259 this.favesList = a.queryElementAt(0, Ci.sbIMediaList);
260 a = this.tempLib.getItemsByProperty(
261 SBProperties.customType,
"radio_tempStreamList");
262 this.streamList = a.queryElementAt(0, Ci.sbIMediaList);
270 this.tempLib.name =
"Temporary Library";
271 this.tempLib.setProperty(SBProperties.hidden,
"1");
272 this.tempLib.setProperty(SBProperties.isReadOnly,
"1");
273 dump(
"*** Created SHOUTcast Temporary Radio library, GUID: " +
275 libraryManager.registerLibrary(this.tempLib,
true);
281 var propExists =
true;
284 a = this.tempLib.getItemsByProperty(
285 SBProperties.customType,
"radio_favouritesList");
289 if (propExists && a.length > 0) {
290 this.favesList = a.queryElementAt(0, Ci.sbIMediaList);
294 this.favesList = this.tempLib.createMediaList(
"simple");
295 this.favesList.setProperty(SBProperties.hidden,
"1");
296 this.favesList.setProperty(SBProperties.isReadOnly,
"1");
300 this.favesList.name = this._strings.getString(
"favourites");
304 this.favesList.setProperty(SBProperties.columnSpec, colSpec);
305 this.favesList.setProperty(SBProperties.defaultColumnSpec,colSpec);
308 var mpManager = Cc[
"@songbirdnest.com/Songbird/MediaPageManager;1"]
309 .getService(Ci.sbIMediaPageManager);
310 var
pages = mpManager.getAvailablePages(this.favesList);
312 while (pages.hasMoreElements()) {
313 var pageInfo = pages.getNext();
314 pageInfo.QueryInterface(Ci.sbIMediaPageInfo);
315 if (pageInfo.contentUrl ==
316 "chrome://songbird/content/mediapages/playlistPage.xul")
320 mpManager.setPage(this.favesList, listView)
326 a = this.tempLib.getItemsByProperty(
327 SBProperties.customType,
"radio_tempStreamList");
331 if (propExists && a.length > 0) {
332 this.streamList = a.queryElementAt(0, Ci.sbIMediaList);
334 this.streamList = this.tempLib.createMediaList(
"simple");
335 this.streamList.setProperty(SBProperties.hidden,
"1");
336 this.streamList.setProperty(SBProperties.isReadOnly,
"1");
340 this.favesList.setProperty(SBProperties.customType,
341 "radio_favouritesList");
342 this.streamList.setProperty(SBProperties.customType,
343 "radio_tempStreamList");
347 for (var
i=0;
i<this.favesList.length;
i++) {
348 var item = this.favesList.getItemByIndex(
i);
349 var
id = item.getProperty(
SC_id);
350 this.favouriteIDs.push(
id);
354 changeGenre :
function(menulist) {
355 var deck = document.getElementById(
"loading-deck");
356 deck.selectedIndex = 0;
358 var genre = menulist.selectedItem.value;
362 RadioDirectory.loadTable(genre)
366 loadTable :
function(genre) {
368 this.radioLib.clear();
371 var el = songbirdMainWindow.document
372 .getElementById(
"sb-status-bar-status-progressmeter");
373 el.mode =
"undetermined";
378 var stationList = ShoutcastRadio.getStationList(genre);
388 var trackArray = Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
389 .createInstance(Ci.nsIMutableArray);
390 var propertiesArray = Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
391 .createInstance(Ci.nsIMutableArray);
392 for (var
i=0;
i<stationList.length;
i++) {
393 var station = stationList[
i];
394 var
name = station.name;
396 var bitrate = parseInt(station.bitrate);
397 var currentTrack = station.currentTrack;
398 var numListeners = station.numListeners;
399 var genres = station.genre;
402 if (checkListeners && numListeners < minLC)
406 if (checkBitRate && bitrate < minBR)
410 "@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
411 .createInstance(Ci.sbIMutablePropertyArray);
414 if (RadioDirectory.favouriteIDs.indexOf(
id) != -1) {
415 heartSrc =
"chrome://shoutcast-radio/skin/heart-active.png";
417 heartSrc =
"chrome://shoutcast-radio/skin/invis-16x16.png";
420 props.appendProperty(SBProperties.bitRate, bitrate);
421 props.appendProperty(SBProperties.genre, genres);
422 props.appendProperty(SBProperties.comment, currentTrack);
423 props.appendProperty(SBProperties.contentType,
"audio");
425 props.appendProperty(
SC_id, parseInt(
id));
426 props.appendProperty(SC_bookmark, heartSrc);
427 propertiesArray.appendElement(props,
false);
429 trackArray.appendElement(
430 ioService.newURI(ShoutcastRadio.getListenURL(
id),
null,
null),
435 var customProps = Cc[
436 "@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
437 .createInstance(Ci.sbIMutablePropertyArray);
438 customProps.appendProperty(
SC_id, -1);
439 dump(
"Looking for custom stations in genre: " + genre +
"\n");
440 customProps.appendProperty(SBProperties.genre, genre);
444 RadioDirectory.favesList.getItemsByProperties(customProps);
445 dump(
"Custom stations found: " + customStations.length +
"\n");
446 for (var
i=0;
i<customStations.length;
i++) {
447 var station = customStations.queryElementAt(
i,
449 station.setProperty(SC_bookmark,
450 "chrome://shoutcast-radio/skin/heart-active.png");
452 station.setProperty(SBProperties.storageGUID,
454 var
url = station.getProperty(SBProperties.contentURL);
455 var props = station.getProperties();
456 propertiesArray.appendElement(props,
false);
457 trackArray.appendElement(
458 ioService.newURI(url,
null,
null),
false);
462 if (e.result != Components.results.NS_ERROR_NOT_AVAILABLE)
463 dump(
"exception: " + e +
"\n");
466 RadioDirectory.radioLib.batchCreateMediaItemsAsync(libListener,
467 trackArray, propertiesArray,
false);
469 var deck = document.getElementById(
"loading-deck");
470 deck.selectedIndex = 1;
474 inputFilter :
function(
event) {
476 var
value =
event.target.value.toLowerCase();
481 this.setFilter(value);
484 setFilter :
function(
value) {
485 document.getElementById(
"clearFilter").disabled = value.length == 0;
486 var srch =
LibraryUtils.createConstraint([[[
"*",[value]]]]);
487 var view = this.playlist.getListView();
488 view.searchConstraint = srch;
489 Application.prefs.setValue(
"extensions.shoutcast-radio.filter", value);
492 clearFilter :
function() {
493 document.getElementById(
"clearFilter").disabled =
true;
494 document.getElementById(
"filter").value =
"";
495 this.playlist.getListView().searchConstraint =
null;
496 Application.prefs.setValue(
"extensions.shoutcast-radio.filter",
"");
499 addStation :
function() {
507 "chrome://shoutcast-radio/content/addFavourite.xul",
508 "add-station",
"chrome,modal", retVals);
510 dump(
"name: " + retVals.name +
"\n");
511 dump(
"url: " + retVals.url +
"\n");
512 dump(
"genre: " + retVals.genre +
"\n");
513 if (retVals.name && retVals.url && retVals.genre) {
516 "@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
517 .createInstance(Ci.sbIMutablePropertyArray);
519 props.appendProperty(SBProperties.bitRate, 0);
520 props.appendProperty(SBProperties.genre, retVals.genre);
521 props.appendProperty(SBProperties.contentType,
"audio");
524 props.appendProperty(
SC_id, -1);
525 props.appendProperty(SC_bookmark,
526 "chrome://shoutcast-radio/skin/heart-active.png");
527 var
uri = ioService.newURI(retVals.url,
null,
null);
528 var item = this.radioLib.createMediaItem(uri, props);
529 RadioDirectory.favesList.add(item);
530 #ifdef METRICS_ENABLED
531 gMetrics.metricsInc(
"shoutcast",
"custom",
"added");
538 if (typeof(
init) ==
"undefined")
542 if (databaseLocation) {
543 directory = databaseLocation.QueryInterface(Ci.nsIFileURL).file;
546 directory = Cc[
"@mozilla.org/file/directory_service;1"].
548 get(
"ProfD", Ci.nsIFile);
549 directory.append(
"db");
552 var
file = directory.clone();
553 file.append(databaseGuid +
".db");
555 Cc[
"@songbirdnest.com/Songbird/Library/LocalDatabase/LibraryFactory;1"]
556 .getService(Ci.sbILibraryFactory);
557 var hashBag = Cc[
"@mozilla.org/hash-property-bag;1"].
559 hashBag.setPropertyAsInterface(
"databaseFile", file);
560 var library = libraryFactory.createLibrary(hashBag);
570 loadData(databaseGuid, databaseLocation);
576 onProgress:
function(
i) {},
579 var el = songbirdMainWindow.document
580 .getElementById(
"sb-status-bar-status-progressmeter");
584 RadioDirectory._strings.getString(
"stationsFound"));
588 function onPlaylistCellClick(e) {
590 var item = e.getData(
"item");
592 var
id = item.getProperty(
SC_id);
593 var idx = RadioDirectory.favouriteIDs.indexOf(
id);
598 var faveGuid = item.getProperty(SBProperties.storageGUID);
600 #ifdef METRICS_ENABLED
602 gMetrics.metricsInc(
"shoutcast",
"custom",
"removed");
604 RadioDirectory.radioLib.remove(item);
606 var faveItem = RadioDirectory.favesList.getItemByGuid(faveGuid);
607 RadioDirectory.favesList.remove(faveItem);
611 #ifdef METRICS_ENABLED
613 gMetrics.metricsInc(
"shoutcast",
"favourites",
"removed");
617 RadioDirectory.favouriteIDs.splice(idx, 1);
618 item.setProperty(SC_bookmark,
619 "chrome://shoutcast-radio/skin/invis-16x16.png");
620 var tree = document.getElementById(
"sb-playlist-tree");
621 tree.treeBoxObject.clearStyleAndImageCaches();
622 tree.treeBoxObject.invalidate();
623 for (var
i=0;
i<RadioDirectory.favesList.length;
i++) {
624 var item = RadioDirectory.favesList.getItemByIndex(
i);
625 var thatId = item.getProperty(
SC_id);
627 RadioDirectory.favesList.remove(item);
630 #ifdef METRICS_ENABLED
632 gMetrics.metricsInc(
"shoutcast",
"favourites",
"added");
637 document.getElementById(
'shoutcast-genre-menulist').label;
639 document.getElementById(
'shoutcast-genre-menulist').value;
640 if (genreValue !=
"sbITop")
641 item.setProperty(SBProperties.genre, genreLabel);
642 RadioDirectory.favouriteIDs.push(
id);
643 item.setProperty(SC_bookmark,
644 "chrome://shoutcast-radio/skin/heart-active.png");
645 RadioDirectory.favesList.add(item);
649 Utils.ensureFavouritesNode();
654 var item = RadioDirectory.playlist.mediaListView.selection.currentMediaItem;
655 var
id = item.getProperty(
SC_id);
656 var plsURL = ShoutcastRadio.getListenURL(
id);
657 var plsMgr = Cc[
"@songbirdnest.com/Songbird/PlaylistReaderManager;1"]
658 .getService(Ci.sbIPlaylistReaderManager);
659 var
listener = Cc[
"@songbirdnest.com/Songbird/PlaylistReaderListener;1"]
660 .createInstance(Ci.sbIPlaylistReaderListener);
661 var ioService = Cc[
"@mozilla.org/network/io-service;1"]
662 .getService(Ci.nsIIOService);
665 RadioDirectory.streamList.clear();
667 listener.playWhenLoaded =
true;
668 listener.observer = {
670 if (aTopic ==
"success") {
673 for (var
i=0;
i<list.length;
i++) {
674 var listItem = list.getItemByIndex(
i);
676 listItem.setProperty(
SC_id,
id);
677 listItem.setProperty(SBProperties.outerGUID, item.guid);
686 #ifdef METRICS_ENABLED
688 gMetrics.metricsInc(
"shoutcast",
"station",
"total.played");
691 gMetrics.metricsInc(
"shoutcast",
"station",
"played." +
id.toString());
694 var genre = item.getProperty(SBProperties.genre);
695 gMetrics.metricsInc(
"shoutcast",
"genre",
"played." + genre);
699 plsURL = item.getProperty(SBProperties.contentURL);
701 var uri = ioService.newURI(plsURL,
null,
null);
702 plsMgr.loadPlaylist(uri, RadioDirectory.streamList,
null,
false, listener);
function loadData(databaseGuid, databaseLocation)
const shoutcastCheckListeners
const shoutcastCheckBitRate
const shoutcastLibraryGuid
const shoutcastMinBitRate
const shoutcastMinListeners
const shoutcastPlaylistInit
getService(Ci.sbIFaceplateManager)
const shoutcastTempLibGuid
this _contentSandbox label
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
function createLibrary(databaseGuid, databaseLocation)
Javascript wrappers for common library tasks.
function SBDataSetStringValue(aKey, aStringValue)
Set a string value. Changes the value of the data remote to the boolean passed in, regardless of its value before.
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe