deviceController.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2009 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 var Cc = Components.classes;
26 var Ci = Components.interfaces;
27 var Cu = Components.utils;
28 
29 const CONNECT_BUTTON_LABEL = "Add and Connect Mock Device";
30 const DISCONNECT_BUTTON_LABEL = "Remove and Disconnect Mock Device";
31 
32 const BUSY_BUTTON_LABEL = "Make Mock Device Busy";
33 const IDLE_BUTTON_LABEL = "Make Mock Device Idle";
34 
35 const CFU_FAIL_LABEL = "Enable Fail on CheckForUpdatedFirmware";
36 const CFU_SUCCESS_LABEL = "Disable Fail on CheckForUpdatedFirmware";
37 
38 //const DOWNLOAD_FAIL_LABEL = "Enable Fail on DownloadNewFirmware";
39 //const DOWNLOAD_SUCCESS_LABEL = "Disable Fail on DownloadNewFirmware";
40 
41 const WRITE_FAIL_LABEL = "Enable Fail on WritingNewFirmware";
42 const WRITE_SUCCESS_LABEL = "Disable Fail on WritingNewFirmware";
43 
44 const INSTALL_FAIL_LABEL = "Enable Fail on InstallNewFirmware";
45 const INSTALL_SUCCESS_LABEL = "Disable Fail on InstallNewFirmware";
46 
47 const RECOVERY_ENABLE_LABEL = "Enable RecoveryModeRequired on Device";
48 const RECOVERY_DISABLE_LABEL = "Disable RecoveryModeRequired on Device";
49 
50 const MOCK_DEVICE_ID = Components.ID("{3572E6FC-4954-4458-AFE7-0D0A65BF5F55}");
51 
52 const PREF_MOCK_DEVICE_CFU_FAIL = "testing.firmware.cfu.fail";
53 const PREF_MOCK_DEVICE_DOWNLOAD_FAIL = "testing.firmware.download.fail";
54 const PREF_MOCK_DEVICE_WRITE_FAIL = "testing.firmware.write.fail";
55 const PREF_MOCK_DEVICE_INSTALL_FAIL = "testing.firmware.update.fail";
56 const PREF_MOCK_DEVICE_BUSY = "testing.busy";
57 
58 const PREF_MOCK_DEVICE_NEED_RECOVERY = "testing.firmware.needRecoveryMode";
59 
61 {
62  _device: null,
63  _deviceId: null,
64 
65  // XUL Elements
66  _buttonMockDeviceConnect: null,
67  _buttonMockDeviceCfu: null,
68  _buttonMockDeviceDownload: null,
69  _buttonMockDeviceWrite: null,
70  _buttonMockDeviceInstall: null,
71  _buttonMockDeviceBusy: null,
72 
73  onDialogLoad: function()
74  {
75  this._buttonMockDeviceConnect =
76  document.getElementById("mock-device-connect-button");
77 
78  this._buttonMockDeviceCfu =
79  document.getElementById("mock-device-cfu-button");
80 
81  /*
82  this._buttonMockDeviceDownload =
83  document.getElementById("mock-device-download-button");
84  */
85 
86  this._buttonMockDeviceWrite =
87  document.getElementById("mock-device-write-button");
88 
89  this._buttonMockDeviceInstall =
90  document.getElementById("mock-device-install-button");
91 
92  this._buttonMockDeviceRecovery =
93  document.getElementById("mock-device-recovery-button");
94 
95  this._buttonMockDeviceBusy =
96  document.getElementById("mock-device-busy-button");
97 
98  this._update();
99  },
100 
101  onMockDeviceCheckForUpdateButton: function()
102  {
103  if(!this._device)
104  return;
105 
106  var cfuFail =
107  this._device.getPreference(PREF_MOCK_DEVICE_CFU_FAIL);
108 
109  if(cfuFail) {
110  this._device.setPreference(PREF_MOCK_DEVICE_CFU_FAIL, false);
111  this._buttonMockDeviceCfu.label = CFU_FAIL_LABEL;
112  }
113  else {
114  this._device.setPreference(PREF_MOCK_DEVICE_CFU_FAIL, true);
115  this._buttonMockDeviceCfu.label = CFU_SUCCESS_LABEL;
116  }
117  },
118 
119  onMockDeviceDownloadButton: function()
120  {
121  if(!this._device)
122  return;
123 
124  var downloadFail =
125  this._device.getPreference(PREF_MOCK_DEVICE_DOWNLOAD_FAIL);
126 
127  if(downloadFail) {
128  this._device.setPreference(PREF_MOCK_DEVICE_DOWNLOAD_FAIL, false);
129  this._buttonMockDeviceDownload.label = DOWNLOAD_FAIL_LABEL;
130  }
131  else {
132  this._device.setPreference(PREF_MOCK_DEVICE_DOWNLOAD_FAIL, true);
133  this._buttonMockDeviceDownload.label = DOWNLOAD_SUCCESS_LABEL;
134  }
135  },
136 
137  onMockDeviceWriteButton: function()
138  {
139  if(!this._device)
140  return;
141 
142  var writeFail =
143  this._device.getPreference(PREF_MOCK_DEVICE_WRITE_FAIL);
144 
145  if(writeFail) {
146  this._device.setPreference(PREF_MOCK_DEVICE_WRITE_FAIL, false);
147  this._buttonMockDeviceWrite.label = WRITE_FAIL_LABEL;
148  }
149  else {
150  this._device.setPreference(PREF_MOCK_DEVICE_WRITE_FAIL, true);
151  this._buttonMockDeviceWrite.label = WRITE_SUCCESS_LABEL;
152  }
153  },
154 
155  onMockDeviceInstallButton: function()
156  {
157  if(!this._device)
158  return;
159 
160  var installFail =
161  this._device.getPreference(PREF_MOCK_DEVICE_INSTALL_FAIL);
162 
163  if(installFail) {
164  this._device.setPreference(PREF_MOCK_DEVICE_INSTALL_FAIL, false);
165  this._buttonMockDeviceInstall.label = INSTALL_FAIL_LABEL;
166  }
167  else {
168  this._device.setPreference(PREF_MOCK_DEVICE_INSTALL_FAIL, true);
169  this._buttonMockDeviceInstall.label = INSTALL_SUCCESS_LABEL;
170  }
171  },
172 
173  onMockDeviceRecoveryButton: function()
174  {
175  if(!this._device)
176  return;
177 
178  var recoveryMode =
179  this._device.getPreference(PREF_MOCK_DEVICE_NEED_RECOVERY);
180 
181  if(recoveryMode) {
182  this._device.setPreference(PREF_MOCK_DEVICE_NEED_RECOVERY, false);
183  this._buttonMockDeviceRecovery.label = RECOVERY_ENABLE_LABEL;
184  }
185  else {
186  this._device.setPreference(PREF_MOCK_DEVICE_NEED_RECOVERY, true);
187  this._buttonMockDeviceRecovery.label = RECOVERY_DISABLE_LABEL;
188  }
189  },
190 
191  onMockDeviceBusyButton: function()
192  {
193  if(!this._device)
194  return;
195 
196  var deviceBusy =
197  this._device.getPreference(PREF_MOCK_DEVICE_BUSY);
198 
199  if(deviceBusy) {
200  this._device.setPreference(PREF_MOCK_DEVICE_BUSY, false);
201  this._buttonMockDeviceBusy.label = BUSY_BUTTON_LABEL;
202  }
203  else {
204  this._device.setPreference(PREF_MOCK_DEVICE_BUSY, true);
205  this._buttonMockDeviceBusy.label = IDLE_BUTTON_LABEL;
206  }
207  },
208 
209  onMockDeviceConnectButton: function()
210  {
211  if(this._device == null) {
212  this._createMockDevice();
213  }
214  else {
215  this._destroyMockDevice();
216  }
217  },
218 
219  _update: function()
220  {
221  var device = null;
222  var devMan = this._getDevMan();
223 
224  try {
225  device = devMan.getDevice(MOCK_DEVICE_ID);
226  } catch(e) {}
227 
228  if(device) {
229  this._device = device;
230  this._deviceId = device.id;
231 
232  this._buttonMockDeviceConnect.label = DISCONNECT_BUTTON_LABEL;
233 
234  var cfuFail = device.getPreference(PREF_MOCK_DEVICE_CFU_FAIL);
235  if(cfuFail) {
236  this._buttonMockDeviceCfu.label = CFU_SUCCESS_LABEL;
237  }
238 
239  /*
240  var downloadFail = device.getPreference(PREF_MOCK_DEVICE_DOWNLOAD_FAIL);
241  if(downloadFail) {
242  this._buttonMockDeviceDownload.label = DOWNLOAD_SUCCESS_LABEL;
243  }
244  else {
245  this._buttonMockDeviceDownload.label = DOWNLOAD_FAIL_LABEL;
246  }
247  */
248 
249  var writeFail = device.getPreference(PREF_MOCK_DEVICE_WRITE_FAIL);
250  if(writeFail) {
251  this._buttonMockDeviceWrite.label = WRITE_SUCCESS_LABEL;
252  }
253  else {
254  this._buttonMockDeviceWrite.label = WRITE_FAIL_LABEL;
255  }
256 
257  var installFail = device.getPreference(PREF_MOCK_DEVICE_INSTALL_FAIL);
258  if(installFail) {
259  this._buttonMockDeviceInstall.label = INSTALL_SUCCESS_LABEL;
260  }
261  else {
262  this._buttonMockDeviceInstall.label = INSTALL_FAIL_LABEL;
263  }
264 
265  var recoveryMode = device.getPreference(PREF_MOCK_DEVICE_NEED_RECOVERY);
266  if(recoveryMode) {
267  this._buttonMockDeviceRecovery.label = RECOVERY_DISABLE_LABEL;
268  }
269  else {
270  this._buttonMockDeviceRecovery.label = RECOVERY_ENABLE_LABEL;
271  }
272 
273  var deviceBusy = device.getPreference(PREF_MOCK_DEVICE_BUSY);
274  if(deviceBusy) {
275  this._buttonMockDeviceBusy.label = IDLE_BUTTON_LABEL;
276  }
277  }
278  else {
279  this._buttonMockDeviceCfu.disabled = true;
280  //this._buttonMockDeviceDownload.disabled = true;
281  this._buttonMockDeviceWrite.disabled = true;
282  this._buttonMockDeviceInstall.disabled = true;
283  this._buttonMockDeviceRecovery.disabled = true;
284  this._buttonMockDeviceBusy.disabled = true;
285  }
286  },
287 
288  _createMockDevice: function()
289  {
290  var device =
291  Cc["@songbirdnest.com/Songbird/Device/DeviceTester/MockDevice;1"]
292  .createInstance(Ci.sbIDevice);
293 
294  var devMan =
295  Cc["@songbirdnest.com/Songbird/DeviceManager;2"]
296  .getService(Ci.sbIDeviceManager2);
297  devMan.registerDevice(device);
298 
299  var data =
300  Cc["@songbirdnest.com/Songbird/Variant;1"]
301  .createInstance(Ci.nsIWritableVariant);
302  data.setAsISupports(device.QueryInterface(Components.interfaces.nsISupports));
303 
304  var ev =
305  devMan.createEvent(Ci.sbIDeviceEvent.EVENT_DEVICE_ADDED, device);
306  devMan.dispatchEvent(ev);
307 
308  device.setPreference("testing.busy", false);
309 
310  this._device = device;
311  this._deviceId = device.id;
312 
313  this._buttonMockDeviceConnect.label = DISCONNECT_BUTTON_LABEL;
314 
315  this._buttonMockDeviceCfu.disabled = false;
316  //this._buttonMockDeviceDownload.disabled = false;
317  this._buttonMockDeviceWrite.disabled = false;
318  this._buttonMockDeviceInstall.disabled = false;
319  this._buttonMockDeviceRecovery.disabled = false;
320  this._buttonMockDeviceBusy.disabled = false;
321  },
322 
323  _destroyMockDevice: function()
324  {
325  var devMan = this._getDevMan();
326 
327  var data =
328  Cc["@songbirdnest.com/Songbird/Variant;1"]
329  .createInstance(Ci.nsIWritableVariant);
330  data.setAsISupports(this._device.QueryInterface(Ci.nsISupports));
331 
332  var ev =
333  devMan.createEvent(Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED, this._device);
334  devMan.dispatchEvent(ev);
335 
336  devMan.unregisterDevice(this._device);
337 
338  this._device = null;
339  this._deviceId = null;
340 
341  this._buttonMockDeviceConnect.label = CONNECT_BUTTON_LABEL;
342 
343  this._buttonMockDeviceCfu.disabled = true;
344  //this._buttonMockDeviceDownload.disabled = true;
345  this._buttonMockDeviceWrite.disabled = true;
346  this._buttonMockDeviceInstall.disabled = true;
347  this._buttonMockDeviceRecovery.disabled = true;
348  this._buttonMockDeviceBusy.disabled = true;
349  },
350 
351  _getDevMan: function()
352  {
353  var devMan =
354  Cc["@songbirdnest.com/Songbird/DeviceManager;2"]
355  .getService(Ci.sbIDeviceManager2);
356  return devMan;
357  }
358 };
359 
const PREF_MOCK_DEVICE_BUSY
const DISCONNECT_BUTTON_LABEL
const PREF_MOCK_DEVICE_CFU_FAIL
var DeviceDialogController
const CFU_SUCCESS_LABEL
var Cu
const WRITE_SUCCESS_LABEL
const MOCK_DEVICE_ID
const PREF_MOCK_DEVICE_WRITE_FAIL
const RECOVERY_ENABLE_LABEL
const RECOVERY_DISABLE_LABEL
const PREF_MOCK_DEVICE_NEED_RECOVERY
const CFU_FAIL_LABEL
const PREF_MOCK_DEVICE_DOWNLOAD_FAIL
return null
Definition: FeedWriter.js:1143
const PREF_MOCK_DEVICE_INSTALL_FAIL
const IDLE_BUTTON_LABEL
const INSTALL_FAIL_LABEL
var Ci
const INSTALL_SUCCESS_LABEL
const CONNECT_BUTTON_LABEL
observe data
Definition: FeedWriter.js:1329
var Cc
const WRITE_FAIL_LABEL
const BUSY_BUTTON_LABEL