deviceGeneralSettings.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  *=BEGIN SONGBIRD GPL
5  *
6  * This file is part of the Songbird web player.
7  *
8  * Copyright(c) 2005-2010 POTI, Inc.
9  * http://www.songbirdnest.com
10  *
11  * This file may be licensed under the terms of of the
12  * GNU General Public License Version 2 (the ``GPL'').
13  *
14  * Software distributed under the License is distributed
15  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
16  * express or implied. See the GPL for the specific language
17  * governing rights and limitations.
18  *
19  * You should have received a copy of the GPL along with this
20  * program. If not, go to http://www.gnu.org/licenses/gpl.html
21  * or write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  *=END SONGBIRD GPL
25  */
26 
32 //------------------------------------------------------------------------------
33 //------------------------------------------------------------------------------
34 //
35 // Device general settings widget services.
36 //
37 //------------------------------------------------------------------------------
38 //------------------------------------------------------------------------------
39 
40 //------------------------------------------------------------------------------
41 //
42 // Device general settings widget services defs.
43 //
44 //------------------------------------------------------------------------------
45 
46 // Component manager defs.
47 if (typeof(Cc) == "undefined")
48  var Cc = Components.classes;
49 if (typeof(Ci) == "undefined")
50  var Ci = Components.interfaces;
51 if (typeof(Cr) == "undefined")
52  var Cr = Components.results;
53 if (typeof(Cu) == "undefined")
54  var Cu = Components.utils;
55 
56 
57 //------------------------------------------------------------------------------
58 //
59 // Device general settings widget services.
60 //
61 //------------------------------------------------------------------------------
62 
70 function deviceGeneralSettingsSvc(aWidget) {
71  this._widget = aWidget;
72 }
73 
74 // Define the object.
75 deviceGeneralSettingsSvc.prototype = {
76  // Set the constructor.
78 
79  //
80  // Internal widget services fields.
81  //
82  // _widget Device general settings widget.
83  // _device Device bound to widget.
84  // _autoLaunchSupported True if device supports auto-launch.
85  // _autoFirmwareCheckSupported
86  // True if device supports auto-firmware checking.
87  //
88 
89  _widget: null,
90  _device: null,
91  _autoLaunchSupported: false,
92  _autoFirmwareCheckSupported: false,
93 
94 
95  //----------------------------------------------------------------------------
96  //
97  // Widget services.
98  //
99  //----------------------------------------------------------------------------
100 
105  initialize: function deviceGeneralSettingsSvc_initialize() {
106  // Get the bound device. Do nothing more if no device bound.
107  this._device = this._widget.device;
108  if (!this._device)
109  return;
110 
111  // Determine which settings are supported.
112  this._getSupportedSettings();
113 
114  // Hide device settings and do nothing more if no settings are supported.
115  if (!this._autoLaunchSupported && !this._autoFirmwareCheckSupported) {
116  this._widget.hidden = true;
117  return;
118  }
119 
120  // Initialize the UI.
121  this._initializeUI();
122  },
123 
124 
129  finalize: function deviceGeneralSettingsSvc_finalize() {
130  // Clear object fields.
131  this._device = null;
132  },
133 
134 
139  save: function deviceGeneralSettingsSvc_save() {
140  // Set the device settings to the current UI settings.
141  this._setDeviceSettingsFromUISettings();
142  },
143 
144 
149  reset: function deviceGeneralSettingsSvc_reset() {
150  // Reset the UI settings from the device settings.
151  this._setUISettingsFromDeviceSettings();
152  },
153 
154 
155  //----------------------------------------------------------------------------
156  //
157  // Internal widget services.
158  //
159  //----------------------------------------------------------------------------
160 
165  _getSupportedSettings:
166  function deviceGeneralSettingsSvc__getSupportedSettings() {
167  // Determine whether the device supports application auto-launch.
168  var propertyName = "http://songbirdnest.com/device/1.0#supportsAutoLaunch";
169  if (this._device.properties.properties.hasKey(propertyName)) {
170  this._autoLaunchSupported =
171  this._device.properties.properties.getProperty(propertyName);
172  }
173 
174  // Determine whether the device supports auto-firmware update checks.
175  var updater = Cc['@songbirdnest.com/Songbird/Device/Firmware/Updater;1']
176  .getService(Ci.sbIDeviceFirmwareUpdater);
177  this._autoFirmwareCheckSupported = updater.hasHandler(this._device, 0, 0);
178  },
179 
180 
185  _initializeUI: function deviceGeneralSettingsSvc__initializeUI() {
186  // Initialize auto-launch checkbox.
187  var autoLaunchCheckbox = this._getElement("auto_launch_checkbox");
188  autoLaunchCheckbox.hidden = !this._autoLaunchSupported;
189 
190  // Initialize auto-firmware check checkbox.
191  var autoFirmwareCheckCheckbox =
192  this._getElement("auto_firmware_check_checkbox");
193  autoFirmwareCheckCheckbox.hidden = !this._autoFirmwareCheckSupported;
194 
195  // Set UI settings from device settings.
196  this._setUISettingsFromDeviceSettings();
197  },
198 
199 
208  _setUISettingsFromDeviceSettings: function
209  deviceGeneralSettingsSvc__setUISettingsFromDeviceSettings(aSettingID) {
210  // Determine whether all settings are being set.
211  var allSettings = (aSettingID ? false : true);
212 
213  // Set the auto-launch setting.
214  if (this._autoLaunchSupported &&
215  (allSettings || (aSettingID == "auto_launch_checkbox"))) {
216  // Get the device auto-launch setting. Use a default if no setting set.
217  var autoLaunchEnabled = this._device.getPreference("auto_launch_enabled");
218  if (autoLaunchEnabled == null)
219  autoLaunchEnabled = true;
220 
221  // Set the UI setting.
222  var autoLaunchCheckbox = this._getElement("auto_launch_checkbox");
223  autoLaunchCheckbox.checked = autoLaunchEnabled;
224  }
225 
226  // Set the auto-firmware check setting.
227  if (this._autoFirmwareCheckSupported &&
228  (allSettings || (aSettingID == "auto_firmware_check_checkbox"))) {
229  // Get the device auto-firmware check setting. Use a default if no
230  // setting set. (no pref = null, defaults to true in the case)
231  var deviceAutoFirmwarePref =
232  this._device.getPreference("firmware.update.enabled");
233 
234  var autoFirmwareCheckEnabled =
235  (deviceAutoFirmwarePref == null) ? false : deviceAutoFirmwarePref;
236 
237  // Set the UI setting.
238  var autoFirmwareCheckCheckbox =
239  this._getElement("auto_firmware_check_checkbox");
240  autoFirmwareCheckCheckbox.checked = autoFirmwareCheckEnabled;
241  }
242  },
243 
244 
253  _setDeviceSettingsFromUISettings: function
254  deviceGeneralSettingsSvc__setDeviceSettingsFromUISettings(aSettingID) {
255  // Determine whether all settings are being set.
256  var allSettings = (aSettingID ? false : true);
257 
258  // Set the auto-launch setting.
259  if (this._autoLaunchSupported &&
260  (allSettings || (aSettingID == "auto_launch_checkbox"))) {
261  // Get the UI auto-launch setting.
262  var autoLaunchCheckbox = this._getElement("auto_launch_checkbox");
263  var autoLaunchEnabled = autoLaunchCheckbox.checked;
264 
265  // Set the device setting.
266  this._device.setPreference("auto_launch_enabled", autoLaunchEnabled);
267  }
268 
269  // Set the auto-firmware check setting.
270  if (this._autoFirmwareCheckSupported &&
271  (allSettings || (aSettingID == "auto_firmware_check_checkbox"))) {
272  // Get the UI auto-firmware check setting.
273  var autoFirmwareCheckCheckbox =
274  this._getElement("auto_firmware_check_checkbox");
275  var autoFirmwareCheckEnabled = autoFirmwareCheckCheckbox.checked;
276 
277  // Set the device setting.
278  this._device.setPreference("firmware.update.enabled",
279  autoFirmwareCheckEnabled);
280  }
281  },
282 
287  dispatchSettingsChangeEvent:
288  function deviceGeneralSettingsSvc_dispatchSettingsChangeEvent() {
289  let event = document.createEvent("UIEvents");
290  event.initUIEvent("settings-changed", false, false, window, null);
291  document.dispatchEvent(event);
292  },
293 
303  _getElement: function deviceGeneralSettingsSvc__getElement(aElementID) {
304  return document.getAnonymousElementByAttribute(this._widget,
305  "sbid",
306  aElementID);
307  }
308 }
309 
const Cu
function Fx prototype initialize
const Cc
var event
let window
DataRemote prototype constructor
return null
Definition: FeedWriter.js:1143
const Cr
const Ci
function deviceGeneralSettingsSvc(aWidget)