firstRunInstallAddOns.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 
35 //------------------------------------------------------------------------------
36 //------------------------------------------------------------------------------
37 //
38 // First-run wizard install add-ons widget services.
39 //
40 //------------------------------------------------------------------------------
41 //------------------------------------------------------------------------------
42 
43 //------------------------------------------------------------------------------
44 //
45 // First-run wizard install add-ons widget imported services.
46 //
47 //------------------------------------------------------------------------------
48 
49 // Songbird imports.
50 Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
51 Components.utils.import("resource://app/jsmodules/DOMUtils.jsm");
52 Components.utils.import("resource://app/jsmodules/StringUtils.jsm");
53 
54 
55 //------------------------------------------------------------------------------
56 //
57 // First-run wizard install add-ons widget services defs.
58 //
59 //------------------------------------------------------------------------------
60 
61 // Component manager defs.
62 if (typeof(Cc) == "undefined")
63  var Cc = Components.classes;
64 if (typeof(Ci) == "undefined")
65  var Ci = Components.interfaces;
66 if (typeof(Cr) == "undefined")
67  var Cr = Components.results;
68 if (typeof(Cu) == "undefined")
69  var Cu = Components.utils;
70 
71 
72 //------------------------------------------------------------------------------
73 //
74 // First-run wizard install add-ons widget services.
75 //
76 //------------------------------------------------------------------------------
77 
85 function firstRunInstallAddOnsSvc(aWidget) {
86  this._widget = aWidget;
87 }
88 
89 // Define the object.
90 firstRunInstallAddOnsSvc.prototype = {
91  // Set the constructor.
93 
94  //
95  // Widget services fields.
96  //
97  // _widget First-run wizard install add-ons widget.
98  // _domEventListenerSet Set of DOM event listeners.
99  // _wizardElem First-run wizard element.
100  // _wizardPageElem First-run install add-ons wizard page element.
101  // _addOnBundleInstallerElem
102  // Add-on bundle installer element.
103  //
104 
105  _widget: null,
106  _domEventListenerSet: null,
107  _wizardElem: null,
108  _wizardPageElem: null,
109  _addOnBundleInstallerElem: null,
110 
111 
112  //----------------------------------------------------------------------------
113  //
114  // Widget services.
115  //
116  //----------------------------------------------------------------------------
117 
122  initialize: function firstRunInstallAddOnsSvc_initialize() {
123  var _this = this;
124  var func;
125 
126  // Create a DOM event listener set.
127  this._domEventListenerSet = new DOMEventListenerSet();
128 
129  // Get the first-run wizard and wizard page elements.
130  this._wizardPageElem = this._widget.parentNode;
131  this._wizardElem = this._wizardPageElem.parentNode;
132 
133  // Get the add-on bundle installer element.
134  this._addOnBundleInstallerElem =
135  this._getElement("add_on_bundle_installer");
136 
137  // Listen for page show and hide events.
138  func = function() { _this._doPageShow(); };
139  this._domEventListenerSet.add(this._wizardPageElem,
140  "pageshow",
141  func,
142  false);
143  func = function() { _this._doPageHide(); };
144  this._domEventListenerSet.add(this._wizardPageElem,
145  "pagehide",
146  func,
147  false);
148 
149  // Listen for add-on bundle installer completion events.
150  func = function(aEvent) { return _this._doInstallComplete(aEvent); };
151  this._domEventListenerSet.add(this._addOnBundleInstallerElem,
152  "complete",
153  func,
154  false);
155  },
156 
157 
162  finalize: function firstRunInstallAddOnsSvc_finalize() {
163  // Remove DOM event listeners.
164  if (this._domEventListenerSet) {
165  this._domEventListenerSet.removeAll();
166  }
167  this._domEventListenerSet = null;
168 
169  // Cancel any add-on download in progress.
170  if (this._addOnBundleInstallerElem)
171  this._addOnBundleInstallerElem.cancel();
172 
173  // Clear object fields.
174  this._widget = null;
175  this._wizardElem = null;
176  this._addOnBundleInstallerElem = null;
177  },
178 
179 
180  //----------------------------------------------------------------------------
181  //
182  // Widget event handling services.
183  //
184  //----------------------------------------------------------------------------
185 
190  _doPageShow: function firstRunInstallAddOnsSvc__doPageShow() {
191  // Get the add-on bundle object.
192  var addOnsID = this._widget.getAttribute("addonsid");
193  var addOnBundleProperty =
194  this._widget.getAttribute("addonbundleproperty");
195  var addOnsElem = document.getElementById(addOnsID);
196  var addOnBundle = addOnsElem[addOnBundleProperty];
197 
198  // If an add-on bundle is available, start add-on bundle installation.
199  // Otherwise, advance the wizard.
200  if (addOnBundle) {
201  this._addOnBundleInstallerElem.install(addOnBundle);
202  } else {
203  this._wizardElem.canAdvance = true;
204  this._wizardElem.advance();
205  }
206  },
207 
208 
213  _doPageHide: function firstRunInstallAddOnsSvc__doPageHide() {
214  // Cancel any add-on installation in progress.
215  this._addOnBundleInstallerElem.cancel();
216  },
217 
218 
225  _doInstallComplete:
226  function firstRunInstallAddOnsSvc__doInstallComplete(aEvent) {
227  // Mark first-run wizard for application restart if required.
228  if (this._addOnBundleInstallerElem.restartRequired)
229  firstRunWizard.restartApp = true;
230 
231  // If installation completed successfully, advance wizard. Otherwise, allow
232  // user to view errors.
233  if (this._addOnBundleInstallerElem.errorCount == 0) {
234  // Advance wizard.
235  this._wizardElem.canAdvance = true;
236  this._wizardElem.advance();
237  } else {
238  // Change the next button to an OK button.
239  var okButton = this._wizardElem.getButton("next");
240  okButton.label = SBString("first_run.ok.label");
241  okButton.accessKey = SBString("first_run.ok.accesskey");
242 
243  // Hide the cancel button and show the OK button.
244  this._wizardPageElem.setAttribute("hidecancel", "true");
245  this._wizardPageElem.setAttribute("shownext", "true");
246  }
247  },
248 
249 
250  //----------------------------------------------------------------------------
251  //
252  // Internal widget services.
253  //
254  //----------------------------------------------------------------------------
255 
265  _getElement: function firstRunInstallAddOnsSvc__getElement(aElementID) {
266  return document.getAnonymousElementByAttribute(this._widget,
267  "anonid",
268  aElementID);
269  }
270 }
271 
const Cu
function Fx prototype initialize
const Cc
function DOMEventListenerSet()
Definition: DOMUtils.jsm:766
function SBString(aKey, aDefault, aStringBundle)
Definition: StringUtils.jsm:93
DataRemote prototype constructor
var _this
return null
Definition: FeedWriter.js:1143
const Cr
const Ci
function firstRunInstallAddOnsSvc(aWidget)