albumArtwork.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
30 if (typeof(Cc) == "undefined")
31  var Cc = Components.classes;
32 if (typeof(Ci) == "undefined")
33  var Ci = Components.interfaces;
34 if (typeof(Cr) == "undefined")
35  var Cr = Components.results;
36 if (typeof(Cu) == "undefined")
37  var Cu = Components.utils;
38 
39 Cu.import("resource://app/jsmodules/ArrayConverter.jsm");
40 
41 var Fetchers = {
42 
47  doPaneLoad: function() {
48  var self = this;
49 
50  function forceCheck(event) {
51  const instantApply =
52  Application.prefs.getValue("browser.preferences.instantApply", true);
53  if (event.type == "dialogcancel" && !instantApply) {
54  // cancel dialog, don't do anything
55  return;
56  }
57 
58  // We need to manually save all the fetcher data since it is complicated
59  // preferences.
60  self.applyFetcherPreferences();
61  }
62 
63  window.addEventListener('dialogaccept', forceCheck, false);
64  window.addEventListener('dialogcancel', forceCheck, false);
65 
66  // Set up the fetcher data from preferences
67  this.resetFetcherPreferences();
68  },
69 
74  moveFetcher: function(offset) {
75  var fetcherBox = document.getElementById("fetcherListBox");
76  var currentFetcher = fetcherBox.getSelectedItem(0);
77  if (currentFetcher) {
78  var fetcherIndex = fetcherBox.getIndexOfItem(currentFetcher);
79  var fLabel = currentFetcher.getAttribute("label");
80  var fValue = currentFetcher.value;
81  var fEnabled = currentFetcher.checked;
82  if ( (fetcherIndex > 0) || (offset > 0) ) {
83  fetcherBox.removeItemAt(fetcherIndex);
84  if (fetcherIndex <= fetcherBox.getRowCount()) {
85  newFetcher = fetcherBox.insertItemAt((fetcherIndex + offset),
86  fLabel,
87  fValue);
88  } else {
89  newFetcher = fetcherBox.appendItem(fLabel, fValue);
90  }
91  newFetcher.setAttribute("type", "checkbox");
92  newFetcher.setAttribute("checked", fEnabled);
93  fetcherBox.selectItem(newFetcher);
94  }
95  }
96  },
97 
102  resetFetcherPreferences: function() {
103  var fetcherBox = document.getElementById("fetcherListBox");
104 
105  // Remove any existing ones
106  while(fetcherBox.getRowCount() > 0) {
107  fetcherBox.removeItemAt(0);
108  }
109 
110  var albumArtService = Cc["@songbirdnest.com/Songbird/album-art-service;1"]
111  .getService(Ci.sbIAlbumArtService);
112  var fetchList = albumArtService.getFetcherList(
113  Ci.sbIAlbumArtFetcherSet.TYPE_ALL,
114  true);
115 
116  for (var fIndex = 0; fIndex < fetchList.length; fIndex++) {
117  // Add a list item entry for each one
118  try {
119  var fetcherCid = fetchList.queryElementAt(fIndex, Ci.nsIVariant);
120  var cFetcher = Cc[fetcherCid].createInstance(Ci.sbIAlbumArtFetcher);
121  var fLabel = cFetcher.name + " (" + cFetcher.description + ")";
122  var newFetcher = fetcherBox.appendItem(fLabel, fetcherCid);
123  newFetcher.setAttribute("type", "checkbox");
124  newFetcher.setAttribute("checked", cFetcher.isEnabled);
125  } catch (err) {
126  Cu.reportError("Unable to find fetcher: " + err);
127  }
128  }
129  },
130 
135  applyFetcherPreferences: function() {
136  var fetcherBox = document.getElementById("fetcherListBox");
137 
138  var fetcherCount = fetcherBox.getRowCount();
139  var fPref = "songbird.albumart.";
140 
141  for (var fIndex = 0; fIndex < fetcherCount; fIndex++) {
142  var fetcherItem = fetcherBox.getItemAtIndex(fIndex);
143  if (fetcherItem) {
144  try {
145  var fetcherCid = fetcherItem.value;
146  var cFetcher = Cc[fetcherCid].createInstance(Ci.sbIAlbumArtFetcher);
147  cFetcher.priority = fIndex;
148  cFetcher.isEnabled = fetcherItem.checked;
149  } catch (err) {
150  Cu.reportError("Unable to update fetcher: " + err);
151  }
152  }
153  }
154 
155  return true;
156  }
157 };
const Cu
const Cc
var Application
Definition: sbAboutDRM.js:37
var event
var Fetchers
Definition: albumArtwork.js:41
let window
PRUint32 & offset
const Cr
const Ci