recommendedAddOnsWizard.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 // Recommended add-ons wizard.
38 //
39 //------------------------------------------------------------------------------
40 //------------------------------------------------------------------------------
41 
42 //------------------------------------------------------------------------------
43 //
44 // Recommended add-ons wizard imported services.
45 //
46 //------------------------------------------------------------------------------
47 
48 Components.utils.import("resource://app/jsmodules/AddOnUtils.jsm");
49 Components.utils.import("resource://app/jsmodules/StringUtils.jsm");
50 
51 
52 //------------------------------------------------------------------------------
53 //
54 // Recommended add-ons wizard 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 // Recommended add-ons wizard services.
72 //
73 //------------------------------------------------------------------------------
74 
76  //
77  // Internal recommended add-ons wizard fields.
78  //
79  // _dialogParameterBlock Dialog parameter block.
80  // _addOnBundle Recommended add-on bundle.
81  // _domEventListenerSet Set of DOM event listeners.
82  // _wizardElem First-run wizard element.
83  // _addOnBundleInstallerElem
84  // Add-on bundle installer element.
85  // _restartRequired True if application needs to be restarted.
86  //
87 
88  _dialogParameterBlock: null,
89  _addOnBundle: null,
90  _domEventListenerSet: null,
91  _wizardElem: null,
92  _addOnBundleInstallerElem: null,
93  _restartRequired: false,
94 
95 
96  //----------------------------------------------------------------------------
97  //
98  // Event handling services.
99  //
100  //----------------------------------------------------------------------------
101 
106  doLoad: function recommendedAddOnsWizard_doLoad() {
107  // Initialize the services.
108  this._initialize();
109  },
110 
111 
116  doUnload: function recommendedAddOnsWizard_doUnload() {
117  // Indicate whether a restart is required.
118  if (this._dialogParameterBlock) {
119  if (this._restartRequired)
120  this._dialogParameterBlock.SetString(0, "true");
121  else
122  this._dialogParameterBlock.SetString(0, "false");
123  }
124 
125  // Finalize the services.
126  this._finalize();
127  },
128 
129 
134  doFinish: function recommendedAddOnsWizard_doFinish() {
135  // Add all add-ons in bundle to recommended add-ons blacklist.
136  if (this._addOnBundle) {
137  var extensionCount = this._addOnBundle.bundleExtensionCount;
138  for (var i = 0; i < extensionCount; i++) {
139  // Get the bundle add-on ID.
140  var addOnID = this._addOnBundle.getExtensionAttribute(i, "id");
141 
142  // Add add-on to blacklist.
143  AddOnBundleLoader.addAddOnToBlacklist(addOnID);
144  }
145  }
146  },
147 
148 
153  doShowAddOnBundleInstallPage:
154  function recommendedAddOnsWizard_doShowAddOnBundleInstallPage() {
155  // Check if add-on installation is required.
156  var installRequired = false;
157  var extensionCount = this._addOnBundle.bundleExtensionCount;
158  for (var i = 0; i < extensionCount; i++) {
159  if (this._addOnBundle.getExtensionInstallFlag(i)) {
160  installRequired = true;
161  break;
162  }
163  }
164 
165  // Install add-ons if required. Otherwise, advance the wizard.
166  if (installRequired) {
167  this._addOnBundleInstallerElem.install(this._addOnBundle);
168  } else {
169  this._wizardElem.canAdvance = true;
170  this._wizardElem.advance();
171  }
172  },
173 
174 
181  _doInstallComplete:
182  function recommendedAddOnsWizard__doInstallComplete(aEvent) {
183  // Set up for application restart if required.
184  this._restartRequired = this._addOnBundleInstallerElem.restartRequired;
185 
186  // If installation completed successfully, advance wizard. Otherwise, allow
187  // user to view errors.
188  if (this._addOnBundleInstallerElem.errorCount == 0) {
189  // Advance wizard.
190  this._wizardElem.canAdvance = true;
191  this._wizardElem.advance();
192  } else {
193  // Change the next button to an OK button.
194  var okButton = this._wizardElem.getButton("next");
195  okButton.label = SBString("recommended_add_ons.ok.label");
196  okButton.accessKey = SBString("recommended_add_ons.ok.accesskey");
197 
198  // Hide the cancel button and show the OK button.
199  var wizardPageElem =
200  document.getElementById("recommended_add_ons_installation_page");
201  wizardPageElem.setAttribute("hidecancel", "true");
202  wizardPageElem.setAttribute("shownext", "true");
203  }
204  },
205 
206 
207  //----------------------------------------------------------------------------
208  //
209  // Internal services.
210  //
211  //----------------------------------------------------------------------------
212 
217  _initialize: function recommendedAddOnsWizard__initialize() {
218  // Get the dialog parameters.
219  try {
220  this._dialogParameterBlock =
221  window.arguments[0].QueryInterface(Ci.nsIDialogParamBlock);
222  this._addOnBundle =
223  this._dialogParameterBlock.objects.queryElementAt(0, Ci.sbIBundle);
224  } catch (ex) {
225  Cu.reportError
226  ("Recommended add-ons wizard opened with invalid parameters.");
227  onExit();
228  return;
229  }
230 
231  // Get the recommended add-on bundle info.
232  var addOnCount = this._addOnBundle.bundleExtensionCount;
233 
234  // Set the add-on bundle object for the recommended add-on bundle widget.
235  var addOnBundleElem = document.getElementById("recommended_add_on_bundle");
236  addOnBundleElem.addOnBundle = this._addOnBundle;
237 
238  // Set the recommended add-ons wizard page header.
239  var headerElem = document.getElementById("recommended_add_ons_header");
240  headerElem.value = SBFormattedCountString
241  ("recommended_add_ons.header.label", addOnCount);
242 
243  // Set the recommended add-ons wizard page description.
244  var descriptionText =
245  SBFormattedCountString("recommended_add_ons.description", addOnCount);
246  var descriptionTextNode = document.createTextNode(descriptionText);
247  var descriptionElem =
248  document.getElementById("recommended_add_ons_description");
249  descriptionElem.appendChild(descriptionTextNode);
250 
251  // Get the wizard element.
252  this._wizardElem = document.getElementById
253  ("recommended_add_ons_update_wizard");
254 
255  // Create a DOM event listener set.
256  this._domEventListenerSet = new DOMEventListenerSet();
257 
258  // Listen for add-on bundle installer completion events.
259  var _this = this;
260  var func = function(aEvent) { return _this._doInstallComplete(aEvent); };
261  this._addOnBundleInstallerElem = document.getElementById
262  ("add_on_bundle_installer");
263  this._domEventListenerSet.add(this._addOnBundleInstallerElem,
264  "complete",
265  func,
266  false);
267  },
268 
269 
274  _finalize: function recommendedAddOnsWizard__finalize() {
275  // Remove DOM event listeners.
276  if (this._domEventListenerSet)
277  this._domEventListenerSet.removeAll();
278  this._domEventListenerSet = null;
279 
280  // Clear object fields.
281  this._dialogParameterBlock = null;
282  this._addOnBundle = null;
283  this._wizardElem = null;
284  this._addOnBundleInstallerElem = null;
285  }
286 };
287 
const Cu
function onExit(skipSave)
onExit handler, saves window size and position before closing the window.
Definition: windowUtils.js:355
const Cc
function doLoad()
function DOMEventListenerSet()
Definition: DOMUtils.jsm:766
function SBString(aKey, aDefault, aStringBundle)
Definition: StringUtils.jsm:93
let window
function SBFormattedCountString(aKeyBase, aCount, aParams, aDefault, aStringBundle)
var _this
return null
Definition: FeedWriter.js:1143
const Cr
const Ci
_getSelectedPageStyle s i
function AddOnBundleLoader()
Definition: AddOnUtils.jsm:93