firstRunConnection.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-2009 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 // First-run wizard connection widget services.
38 //
39 //------------------------------------------------------------------------------
40 //------------------------------------------------------------------------------
41 
42 //------------------------------------------------------------------------------
43 //
44 // First-run wizard EULA widget imported services.
45 //
46 //------------------------------------------------------------------------------
47 
48 // Songbird imports.
49 Components.utils.import("resource://app/jsmodules/DOMUtils.jsm");
50 Components.utils.import("resource://app/jsmodules/WindowUtils.jsm");
51 
52 
53 //------------------------------------------------------------------------------
54 //
55 // First-run wizard connection widget services.
56 //
57 //------------------------------------------------------------------------------
58 
66 function firstRunConnectionSvc(aWidget) {
67  this._widget = aWidget;
68 }
69 
70 // Define the object.
71 firstRunConnectionSvc.prototype = {
72  // Set the constructor.
74 
75  //
76  // Widget services fields.
77  //
78  // _widget First-run wizard connection widget.
79  // _domEventListenerSet Set of DOM event listeners.
80  // _wizardPageElem First-run wizard EULA widget wizard page element.
81  //
82 
83  _widget: null,
84  _domEventListenerSet: null,
85  _wizardPageElem: null,
86 
87 
88  //----------------------------------------------------------------------------
89  //
90  // Widget services.
91  //
92  //----------------------------------------------------------------------------
93 
98  initialize: function firstRunConnectionSvc_initialize() {
99  // Get the first-run wizard page element.
100  this._wizardPageElem = this._widget.parentNode;
101 
102  // Listen for page advanced events.
103  this._domEventListenerSet = new DOMEventListenerSet();
104  var _this = this;
105  var func = function(aEvent) { return _this._doPageAdvanced(aEvent); };
106  this._domEventListenerSet.add(this._wizardPageElem,
107  "pageadvanced",
108  func,
109  false);
110  },
111 
112 
117  finalize: function firstRunConnectionSvc_finalize() {
118  // Remove DOM event listeners.
119  if (this._domEventListenerSet) {
120  this._domEventListenerSet.removeAll();
121  }
122  this._domEventListenerSet = null;
123 
124  // Clear object fields.
125  this._widget = null;
126  this._wizardPageElem = null;
127  },
128 
129 
130  //----------------------------------------------------------------------------
131  //
132  // Widget event handling services.
133  //
134  //----------------------------------------------------------------------------
135 
142  doCommand: function firstRunConnectionSvc_doCommand(aEvent) {
143  // Dispatch processing of the command.
144  var action = aEvent.target.getAttribute("action");
145  switch (action) {
146  case "doConnectionSettings" :
147  this._doConnectionSettings();
148  break;
149 
150  default :
151  break;
152  }
153  },
154 
155 
162  _doPageAdvanced: function firstRunConnectionSvc__doPageAdvanced(aEvent) {
163  // Rewind back to the wizard page that encountered a connection error.
164  // Advance is enabled so that the wizard next button is displayed, but
165  // rewind is used so that the wizard connection page isn't in the wizard
166  // page history.
167  firstRunWizard.wizardElem.rewind();
168 
169  // Prevent advancing.
170  aEvent.preventDefault();
171  return false;
172  },
173 
174 
175  //----------------------------------------------------------------------------
176  //
177  // Internal widget services.
178  //
179  //----------------------------------------------------------------------------
180 
186  _doConnectionSettings:
187  function firstRunConnectionSvc__doConnectionSettings() {
188  // Get the preference services.
189  var prefService = Cc["@mozilla.org/preferences-service;1"]
190  .getService(Ci.nsIPrefService);
191  prefService = prefService.QueryInterface(Ci.nsIPrefBranch);
192 
193  // Switch instant apply to true.
194  // It doesnt actually make it apply the settings instantly unless you're on
195  // a Mac, but it makes clicking 'ok' apply the changes on all platforms
196  // (because the code for the prefwindow has no provision for child
197  // prefwindows running standalone when they are not instantApply).
198  var prevInstantApply =
199  prefService.getBoolPref("browser.preferences.instantApply");
200  prefService.setBoolPref("browser.preferences.instantApply", true);
201 
202  // Open the connection settings dialog.
203  var accepted = WindowUtils.openModalDialog
204  (window,
205  "chrome://browser/content/preferences/connection.xul",
206  "Connections",
207  "chrome,modal=yes,centerscreen",
208  null,
209  null);
210 
211  // Switch back to previous instant apply.
212  prefService.setBoolPref("browser.preferences.instantApply",
213  prevInstantApply);
214 
215  // Flush settings to disk.
216  prefService.savePrefFile(null);
217 
218  // Send connection reset event and advance out of first-run connection page
219  // if the connection settings were accepted.
220  if (accepted) {
221  // Send a connection reset event.
222  var event = document.createEvent("Events");
223  event.initEvent("firstRunConnectionReset", true, true);
224  this._widget.dispatchEvent(event);
225 
226  // Advance out of first-run connection page.
227  firstRunWizard.wizardElem.advance();
228  }
229  }
230 }
231 
function Fx prototype initialize
const Cc
var event
function DOMEventListenerSet()
Definition: DOMUtils.jsm:766
let window
DataRemote prototype constructor
var _this
return null
Definition: FeedWriter.js:1143
const Ci
function firstRunConnectionSvc(aWidget)