deviceSummarySettings.js
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  *=BEGIN SONGBIRD GPL
4  *
5  * This file is part of the Songbird web player.
6  *
7  * Copyright(c) 2005-2010 POTI, Inc.
8  * http://www.songbirdnest.com
9  *
10  * This file may be licensed under the terms of of the
11  * GNU General Public License Version 2 (the ``GPL'').
12  *
13  * Software distributed under the License is distributed
14  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
15  * express or implied. See the GPL for the specific language
16  * governing rights and limitations.
17  *
18  * You should have received a copy of the GPL along with this
19  * program. If not, go to http://www.gnu.org/licenses/gpl.html
20  * or write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  *=END SONGBIRD GPL
24  */
25 
31 //------------------------------------------------------------------------------
32 //------------------------------------------------------------------------------
33 //
34 // Device summary settings widget.
35 //
36 //------------------------------------------------------------------------------
37 //------------------------------------------------------------------------------
38 
39 //------------------------------------------------------------------------------
40 //
41 // Device summary settings defs.
42 //
43 //------------------------------------------------------------------------------
44 
45 // Component manager defs.
46 if (typeof(Cc) == "undefined")
47  var Cc = Components.classes;
48 if (typeof(Ci) == "undefined")
49  var Ci = Components.interfaces;
50 if (typeof(Cr) == "undefined")
51  var Cr = Components.results;
52 if (typeof(Cu) == "undefined")
53  var Cu = Components.utils;
54 
55 Cu.import("resource://app/jsmodules/sbLibraryUtils.jsm");
56 Cu.import("resource://app/jsmodules/sbProperties.jsm");
57 Cu.import("resource://app/jsmodules/sbProperties.jsm");
58 Cu.import("resource://app/jsmodules/ArrayConverter.jsm");
59 Cu.import("resource://app/jsmodules/DOMUtils.jsm");
60 
61 if (typeof(XUL_NS) == "undefined")
62  var XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
63 
65  //
66  // Device Sync Tabs object fields.
67  //
68  // _widget Device sync tabs widget.
69  // _device sbIDevice object.
70  // _settingsChanged Whether the settings have been changed.
71  // _saveButton The save button of the settings box
72  // _cancelButton The cancel button of the settings box
73  // _deviceMgmtSettings The device management settings box
74  // _deviceGeneralSettings The device general settings box
75  // _domEventListenerSet Set of DOM event listeners.
76  //
77 
78  _widget: null,
79  _device: null,
80  _settingsChanged: false,
81  _saveButton: null,
82  _cancelButton: null,
83  _deviceMgmtSettings: null,
84  _deviceGeneralSettings: null,
85  _domEventListenerSet: null,
86 
94  initialize: function DeviceSummarySettings_initialize(aWidget) {
95  // Get the device widget.
96  this._widget = aWidget;
97 
98  // Initialize object fields.
99  this._device = this._widget.device;
100 
101  if ((this._device && this._device.defaultLibrary) ||
102  !this._getElement("device_general_settings").hidden) {
103  this._widget.removeAttribute("disabledTab");
104  }
105  else {
106  this._widget.setAttribute("disabledTab", "true");
107  }
108 
109  // Listen for device events.
110  var deviceEventTarget =
111  this._device.QueryInterface(Ci.sbIDeviceEventTarget);
112  deviceEventTarget.addEventListener(this);
113 
114  this._saveButton = this._getElement("device_settings_button_save");
115  this._cancelButton = this._getElement("device_settings_button_cancel");
116  this._deviceMgmtSettings = this._getElement("device_management_settings");
117  this._deviceGeneralSettings = this._getElement("device_general_settings");
118 
119  this._saveButton.setAttribute("disabled", "true");
120  this._cancelButton.setAttribute("disabled", "true");
121 
122  // Create a DOM event listener set.
123  this._domEventListenerSet = new DOMEventListenerSet();
124 
125  // Listen for sync settings management change events.
126  var self = this;
127  var func = function(aEvent) { self._onSettingsChangeEvent(); };
128  this._domEventListenerSet.add(document,
129  "settings-changed",
130  func,
131  false,
132  false);
133 
134  this.updateBusyState();
135  },
136 
141  finalize: function DeviceSummarySettings_finalize() {
142  // Remove DOM event listeners.
143  if (this._domEventListenerSet) {
144  this._domEventListenerSet.removeAll();
145  this._domEventListenerSet = null;
146  }
147 
148  // Stop listening for device events.
149  if (this._device) {
150  var deviceEventTarget =
151  this._device.QueryInterface(Ci.sbIDeviceEventTarget);
152  deviceEventTarget.removeEventListener(this);
153  }
154 
155  this._widget = null;
156  this._device = null;
157  this._settingsChanged = false;
158  this._saveButton = null;
159  this._cancelButton = null;
160  this._deviceMgmtSettings = null;
161  this._deviceGeneralSettings = null;
162  },
163 
167  updateBusyState: function DeviceSummarySettings_updateBusyState() {
168  let isBusy = this._device && this._device.isBusy;
169  if (isBusy || !this._settingsChanged) {
170  this._saveButton.setAttribute("disabled", "true");
171  this._cancelButton.setAttribute("disabled", "true");
172  }
173  else {
174  this._saveButton.removeAttribute("disabled");
175  this._cancelButton.removeAttribute("disabled");
176  }
177 
178  if (isBusy) {
179  this._deviceMgmtSettings.setAttribute("disabled", "true");
180  this._deviceGeneralSettings.setAttribute("disabled", "true");
181  }
182  else {
183  this._deviceMgmtSettings.removeAttribute("disabled");
184  this._deviceGeneralSettings.removeAttribute("disabled");
185  }
186  },
187 
192  // Currently we save every setting (transcode, and diskmgmt). Since both
193  // of those settings are settings where the default is the same as 'unset',
194  // this happens to work nicely (e.g. for transcode it's "automatic", and
195  // diskmgmt it's "disabled"). If we ever add a setting here where the
196  // default setting is not the same as "explicitly unset" for the device,
197  // then we should make sure we only save the settings that aren't in the
198  // 'hide' list.
199  save: function DeviceSummarySettings_save() {
200  this._settingsChanged = false;
201  this._saveButton.setAttribute("disabled", "true");
202  this._cancelButton.setAttribute("disabled", "true");
203  this._deviceMgmtSettings.save();
204  if (!this._deviceGeneralSettings.hidden)
205  this._deviceGeneralSettings.save();
206  },
207 
212  reset: function DeviceSummarySettings_reset() {
213  this._settingsChanged = false;
214  this._saveButton.setAttribute("disabled", "true");
215  this._cancelButton.setAttribute("disabled", "true");
216  this._deviceMgmtSettings.reset();
217  if (!this._deviceGeneralSettings.hidden)
218  this._deviceGeneralSettings.reset();
219  },
220 
221  //---------------------------------------------------------------------------- //
222  // Device sync sbIDeviceEventListener services.
223  //
224  //----------------------------------------------------------------------------
231  onDeviceEvent: function DeviceSummarySettings_onDeviceEvent(aEvent) {
232  // Dispatch processing of the event.
233  switch(aEvent.type)
234  {
235  case Ci.sbIDeviceEvent.EVENT_DEVICE_STATE_CHANGED:
236  this.updateBusyState();
237  break;
238 
239  default :
240  break;
241  }
242  },
243 
244  //----------------------------------------------------------------------------
245  //
246  // Device summary settings XUL services.
247  //
248  //----------------------------------------------------------------------------
249 
253  _onSettingsChangeEvent:
254  function DeviceSummarySettings__onSettingsChangeEvent(aEvent) {
255  this._settingsChanged = true;
256  this._saveButton.removeAttribute("disabled");
257  this._cancelButton.removeAttribute("disabled");
258  },
259 
269  _getElement: function DeviceSummarySettings__getElement(aElementID) {
270  return document.getAnonymousElementByAttribute(this._widget,
271  "sbid",
272  aElementID);
273  }
274 };
const Cu
function Fx prototype initialize
const Cc
const XUL_NS
Definition: FeedWriter.js:83
function DOMEventListenerSet()
Definition: DOMUtils.jsm:766
return null
Definition: FeedWriter.js:1143
const Cr
const Ci
var DeviceSummarySettings