addOnBundle.js
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4 //
5 // BEGIN SONGBIRD GPL
6 //
7 // This file is part of the Songbird web player.
8 //
9 // Copyright(c) 2005-2008 POTI, Inc.
10 // http://songbirdnest.com
11 //
12 // This file may be licensed under the terms of of the
13 // GNU General Public License Version 2 (the "GPL").
14 //
15 // Software distributed under the License is distributed
16 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
17 // express or implied. See the GPL for the specific language
18 // governing rights and limitations.
19 //
20 // You should have received a copy of the GPL along with this
21 // program. If not, go to http://www.gnu.org/licenses/gpl.html
22 // or write to the Free Software Foundation, Inc.,
23 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 // END SONGBIRD GPL
26 //
27  */
28 
34 //------------------------------------------------------------------------------
35 //------------------------------------------------------------------------------
36 //
37 // Add-on bundle widget services.
38 //
39 //------------------------------------------------------------------------------
40 //------------------------------------------------------------------------------
41 
42 //------------------------------------------------------------------------------
43 //
44 // Add-on bundle widget imported services.
45 //
46 //------------------------------------------------------------------------------
47 
48 // Songbird imports.
49 Components.utils.import("resource://app/jsmodules/DOMUtils.jsm");
50 
51 
52 //------------------------------------------------------------------------------
53 //
54 // Add-on bundle widget services defs.
55 //
56 //------------------------------------------------------------------------------
57 
58 // Component manager defs.
59 if (typeof(Cc) == "undefined")
60  var Cc = Components.classes;
61 if (typeof(Ci) == "undefined")
62  var Ci = Components.interfaces;
63 if (typeof(Cr) == "undefined")
64  var Cr = Components.results;
65 if (typeof(Cu) == "undefined")
66  var Cu = Components.utils;
67 
68 
69 //------------------------------------------------------------------------------
70 //
71 // Add-on bundle widget services.
72 //
73 //------------------------------------------------------------------------------
74 
82 function addOnBundleSvc(aWidget) {
83  this._widget = aWidget;
84 }
85 
86 // Define the object.
87 addOnBundleSvc.prototype = {
88  // Set the constructor.
90 
91  //
92  // Internal widget services fields.
93  //
94  // _widget First-run wizard add-ons widget.
95  // _domEventListenerSet Set of DOM event listeners.
96  // _addOnBundle Add-on bundle object.
97  // _addOnsTable Table of add-ons.
98  //
99 
100  _widget: null,
101  _domEventListenerSet: null,
102  _addOnBundle: null,
103  _addOnsTable: null,
104 
105 
106  //----------------------------------------------------------------------------
107  //
108  // Widget services.
109  //
110  //----------------------------------------------------------------------------
111 
116  initialize: function addOnBundleSvc_initialize() {
117  // Create a DOM event listener set.
118  this._domEventListenerSet = new DOMEventListenerSet();
119 
120  // Listen for add-on item changes.
121  var addOnsListElem = this._getElement("add_ons_list");
122  var _this = this;
123  var func = function(aEvent) { return _this._doCommand(aEvent); };
124  this._domEventListenerSet.add(addOnsListElem,
125  "command",
126  func,
127  false);
128 
129  // Update the add-on item list.
130  this._updateAddOnItemList();
131  },
132 
133 
138  finalize: function addOnBundleSvc_finalize() {
139  // Remove DOM event listeners.
140  if (this._domEventListenerSet) {
141  this._domEventListenerSet.removeAll();
142  }
143  this._domEventListenerSet = null;
144 
145  // Clear object fields.
146  this._widget = null;
147  this._addOnBundle = null;
148  this._addOnsTable = null;
149  },
150 
151 
152  /*
153  * Getters/setters.
154  */
155 
156  /*
157  * addOnBundle Add-on bundle object.
158  */
159 
160  get addOnBundle() {
161  return this._addOnBundle;
162  },
163 
164  set addOnBundle(aBundle) {
165  // Do nothing if bundle is not changing.
166  if (aBundle == this._addOnBundle)
167  return;
168 
169  // Set new bundle.
170  this._addOnBundle = aBundle;
171 
172  // Update the add-on item list.
173  this._updateAddOnItemList();
174  },
175 
176 
177  //----------------------------------------------------------------------------
178  //
179  // Widget event handling services.
180  //
181  //----------------------------------------------------------------------------
182 
187  _doCommand: function addOnBundleSvc__doCommand(aEvent) {
188  // Get the event target info.
189  var target = aEvent.target;
190  var localName = target.localName;
191 
192  // Dispatch event processing.
193  switch (localName) {
194  case "sb-add-on-bundle-item" :
195  this._doAddOnBundleItemChange(target);
196  break;
197 
198  default :
199  break;
200  }
201  },
202 
203 
210  _doAddOnBundleItemChange:
211  function addOnBundleSvc__doAddOnBundleItemChange(aElement) {
212  // Update the add-on bundle item install flag.
213  var index = aElement.getAttribute("index");
214  var install = aElement.install;
215  this.addOnBundle.setExtensionInstallFlag(index, install);
216  },
217 
218 
219  //----------------------------------------------------------------------------
220  //
221  // Widget add-ons bundle services.
222  //
223  //----------------------------------------------------------------------------
224 
232  _addAddOn: function addOnBundleSvc__addAddOn(aIndex) {
233  // Get the add-on ID. Use the name as an ID if the ID is not available.
234  var addOnID = this.addOnBundle.getExtensionAttribute(aIndex, "id");
235  if (!addOnID)
236  addOnID = this.addOnBundle.getExtensionAttribute(aIndex, "name");
237 
238  // Do nothing if add-on already added.
239  if (this._addOnsTable[addOnID])
240  return;
241 
242  // Get the add-on info.
243  var addOnInfo = {};
244  addOnInfo.index = aIndex;
245  addOnInfo.installFlag = this.addOnBundle.getExtensionInstallFlag(aIndex);
246  addOnInfo.addOnID = this.addOnBundle.getExtensionAttribute(aIndex, "id");
247  addOnInfo.addOnURL = this.addOnBundle.getExtensionAttribute(aIndex, "url");
248  addOnInfo.description =
249  this.addOnBundle.getExtensionAttribute(aIndex, "description");
250  addOnInfo.iconURL = this.addOnBundle.getExtensionAttribute(aIndex, "icon");
251  addOnInfo.name = this.addOnBundle.getExtensionAttribute(aIndex, "name");
252 
253  // Add the add-on element to the add-on list element.
254  addOnInfo.addOnItemElem = this._addAddOnElement(addOnInfo);
255 
256  // Add the add-on info to the add-ons table.
257  this._addOnsTable[addOnID] = addOnInfo;
258  },
259 
260 
270  _addAddOnElement: function addOnBundleSvc__addAddOnElement(aAddOnInfo) {
271  // Get the add-on list item template.
272  var listItemTemplateElem = this._getElement("list_item_template");
273 
274  // Create an add-on list item from the template.
275  var listItemElem = listItemTemplateElem.cloneNode(true);
276  listItemElem.hidden = false;
277 
278  // Set up the add-on item element.
279  var itemElem = DOMUtils.getElementsByAttribute(listItemElem,
280  "templateid",
281  "item")[0];
282  itemElem.setAttribute("addonid", aAddOnInfo.addOnID);
283  itemElem.setAttribute("addonurl", aAddOnInfo.addOnURL);
284  itemElem.setAttribute("defaultinstall", aAddOnInfo.installFlag);
285  itemElem.setAttribute("description", aAddOnInfo.description);
286  itemElem.setAttribute("icon", aAddOnInfo.iconURL);
287  itemElem.setAttribute("index", aAddOnInfo.index);
288  itemElem.setAttribute("name", aAddOnInfo.name);
289 
290  // Reclone element to force construction with new settings.
291  listItemElem = listItemElem.cloneNode(true);
292 
293  // Add the add-on list item to the add-on list.
294  var itemListElem = this._getElement("add_ons_list");
295  itemListElem.appendChild(listItemElem);
296 
297  // Get the add-on item element after it's been appended to get a fully
298  // functional element object.
299  itemElem = DOMUtils.getElementsByAttribute(listItemElem,
300  "templateid",
301  "item")[0];
302 
303  return itemElem;
304  },
305 
306 
307  //----------------------------------------------------------------------------
308  //
309  // Internal widget services.
310  //
311  //----------------------------------------------------------------------------
312 
317  _updateAddOnItemList: function addOnBundleSvc__updateAddOnItemList() {
318  // Clear the current add-on item list.
319  this._addOnsTable = {};
320  var itemListElem = this._getElement("add_ons_list");
321  while (itemListElem.firstChild)
322  itemListElem.removeChild(itemListElem.firstChild);
323 
324  // Add add-ons from bundle.
325  if (this.addOnBundle) {
326  var extensionCount = this.addOnBundle.bundleExtensionCount;
327  for (var i = 0; i < extensionCount; i++) {
328  this._addAddOn(i);
329  }
330  }
331  },
332 
333 
343  _getElement: function addOnBundleSvc__getElement(aElementID) {
344  return document.getAnonymousElementByAttribute(this._widget,
345  "anonid",
346  aElementID);
347  }
348 }
349 
const Cu
function Fx prototype initialize
function addOnBundleSvc(aWidget)
Definition: addOnBundle.js:82
const Cc
function DOMEventListenerSet()
Definition: DOMUtils.jsm:766
DataRemote prototype constructor
var _this
return null
Definition: FeedWriter.js:1143
const Cr
const Ci
_getSelectedPageStyle s i