25 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
26 Components.utils.import(
"resource://app/jsmodules/SBDataRemoteUtils.jsm");
27 Components.utils.import(
"resource://app/jsmodules/SBTimer.jsm");
28 Components.utils.import(
"resource://app/jsmodules/SBUtils.jsm");
29 Components.utils.import(
"resource://app/jsmodules/StringUtils.jsm");
30 Components.utils.import(
"resource://app/jsmodules/WindowUtils.jsm");
32 const Ci = Components.interfaces;
33 const Cc = Components.classes;
34 const Cr = Components.results;
35 const Cu = Components.utils;
50 if (typeof(x) ==
"undefined") {
52 }
else if (x ==
null) {
54 }
else if (typeof x ==
'function') {
55 return x.name+
'(...)';
56 }
else if (typeof x ==
'string') {
57 return x.toSource().match(/^\(
new String\((.*)\)\)$/)[1];
58 }
else if (typeof x ==
'number') {
59 return x.toSource().match(/^\(
new Number\((.*)\)\)$/)[1];
60 }
else if (typeof x ==
'object' && x instanceof
Array) {
62 for (var
i=0;
i<x.length;
i++) {
63 if (
i) value = value +
', ';
64 value = value + repr(x[
i]);
67 }
else if (x instanceof
Ci.nsISupports) {
73 var fullMsg =
'sbDeviceFirmwareAutocheckForUpdate:: '+
DEBUG.caller.name;
74 if (typeof(
msg) ==
"undefined") {
77 for (var
i=0;
i<
DEBUG.caller.length;
i++) {
78 if (
i) fullMsg +=
', ';
79 fullMsg += repr(
DEBUG.caller.arguments[
i]);
84 if (typeof
msg !=
'object' ||
msg instanceof
Array) {
87 fullMsg +=
msg.toSource();
92 Cu.reportError(fullMsg);
99 var obs =
Cc[
"@mozilla.org/observer-service;1"]
100 .getService(
Ci.nsIObserverService);
122 'Songbird Device Firmware Auto Check For Update';
124 Components.ID(
"{2137a87f-2ade-448b-a093-bad4f6649fa3}");
126 '@songbirdnest.com/Songbird/Device/Firmware/AutoCheckForUpdate;1';
129 [
Ci.nsISupports,
Ci.nsIClassInfo,
Ci.nsIObserver,
Ci.sbIDeviceEventListener];
132 function sbDeviceFirmwareAutoCheckForUpdate_getInterfaces(
count) {
141 function sbDeviceFirmwareAutoCheckForUpdate_observe(subject,
topic,
data) {
144 var obs =
Cc[
"@mozilla.org/observer-service;1"]
145 .getService(
Ci.nsIObserverService);
152 Cc[
'@songbirdnest.com/Songbird/Device/Firmware/Updater;1']
153 .getService(
Ci.sbIDeviceFirmwareUpdater);
156 Cc[
'@songbirdnest.com/Songbird/DeviceManager;2']
157 .getService(
Ci.sbIDeviceManager2);
175 this._unregisterTimer(
id);
184 DEBUG(this.
_queue.length +
" items, top is " +
this._queueItem);
189 let device = this.
_queue[0];
192 if (device.getPreference(
"firmware.update.enabled")) {
210 let
wm =
Cc[
"@mozilla.org/appshell/window-mediator;1"]
211 .getService(
Ci.nsIWindowMediator);
212 let parent = wm.getMostRecentWindow(
"Songbird:Main");
214 WindowUtils.openModalDialog
216 "chrome://songbird/content/xul/device/deviceFirmwareWizard.xul",
217 "device_firmware_dialog",
219 [
"",
"defaultDevice=false", this.
_queueItem ],
226 else if(!this.
_queue.length &&
236 function sbDeviceFirmwareAutoCheckForUpdate_notify(aDevice) {
240 this.
_timer =
Cc[
'@mozilla.org/timer;1'].createInstance(
Ci.nsITimer);
241 this.
_timer.init(
this, 15000,
Ci.nsITimer.TYPE_REPEATING_SLACK);
243 if (this.
_queue.indexOf(aDevice) < 0) {
244 this.
_queue.push(aDevice);
250 function sbDeviceFirmwareAutoCheckForUpdate_onDeviceEvent(aEvent) {
254 switch(aEvent.type) {
255 case Ci.sbIDeviceEvent.EVENT_DEVICE_ADDED: {
256 device = aEvent.data.QueryInterface(
Ci.sbIDevice);
257 if (device.getPreference(
"firmware.update.enabled")) {
258 this._registerTimer(device);
275 var recoveryMode =
false;
278 handler.bind(device,
null);
279 recoveryMode = handler.recoveryMode;
283 if (device.getPreference(
"firstTime") &&
286 this.
_queue.indexOf(device) < 0) {
287 device.setPreference(
"firmware.update.enabled",
true);
293 this.
_timer =
Cc[
'@mozilla.org/timer;1'].createInstance(
Ci.nsITimer);
294 this.
_timer.init(
this, 15000,
Ci.nsITimer.TYPE_REPEATING_SLACK);
330 case Ci.sbIDeviceEvent.EVENT_DEVICE_REMOVED: {
332 device = aEvent.data.QueryInterface(
Ci.sbIDevice);
333 this._unregisterTimer(device);
334 let index = this.
_queue.indexOf(device);
338 this.
_queue.splice(index, 1);
348 case Ci.sbIDeviceEvent.EVENT_DEVICE_PREFS_CHANGED: {
349 device = aEvent.origin.QueryInterface(
Ci.sbIDevice);
350 if (device.getPreference(
"firmware.update.enabled")) {
351 this._registerTimer(device);
353 this._unregisterTimer(device);
358 case Ci.sbIDeviceEvent.EVENT_FIRMWARE_CFU_END: {
363 case Ci.sbIDeviceEvent.EVENT_FIRMWARE_CFU_ERROR: {
365 device = aEvent.origin.QueryInterface(
Ci.sbIDevice);
366 let index = this.
_queue.indexOf(device);
370 this.
_queue.splice(index, 1);
386 function sbDeviceFirmwareAutoCheckForUpdate__registerTimer(aDevice) {
390 .getService(
Ci.nsIUpdateTimerManager);
394 self.notify(aDevice);
396 let interval = aDevice.getPreference(
"firmware.update.interval");
398 var
prefs =
Cc[
"@mozilla.org/fuel/application;1"]
399 .getService(
Ci.fuelIApplication)
404 DEBUG(
"Using default interval for firmware update check: " +
416 function sbDeviceFirmwareAutoCheckForUpdate__unregisterTimer(aDevice) {
419 if (
"id" in aDevice) {
437 function sbDeviceFirmwareAutoCheckForUpdate__promptForRepair(aDevice) {
438 var windowMediator =
Cc[
"@mozilla.org/appshell/window-mediator;1"]
439 .getService(
Ci.nsIWindowMediator);
440 var songbirdWindow = windowMediator.getMostRecentWindow(
"Songbird:Main");
442 var prompter =
Cc[
'@songbirdnest.com/Songbird/Prompter;1']
443 .getService(Components.interfaces.sbIPrompter);
445 prompter.confirm(songbirdWindow,
446 SBString(
'device.firmware.corrupt.title'),
450 WindowUtils.openModalDialog
452 "chrome://songbird/content/xul/device/deviceFirmwareWizard.xul",
453 "device_firmware_dialog",
455 [
"mode=repair",
"defaultDevice=false", aDevice ],
464 function(aCompMgr, aFileSpec, aLocation) {
465 XPCOMUtils.categoryManager.addCategoryEntry(
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
sbDeviceFirmwareAutoCheckForUpdate prototype _registeredDevices
const SB_FINAL_UI_STARTUP_TOPIC
sbDeviceFirmwareAutoCheckForUpdate prototype _deviceManager
const NS_QUIT_APPLICATION_GRANTED_TOPIC
function SBString(aKey, aDefault, aStringBundle)
sbDeviceFirmwareAutoCheckForUpdate prototype _timer
const FIRMWARE_UPDATE_INTERVAL
function sbDeviceFirmwareAutoCheckForUpdate()
const NS_TIMER_CALLBACK_TOPIC
sbDeviceFirmwareAutoCheckForUpdate prototype _queue
const FIRMWARE_WIZARD_ACTIVE_DATAREMOTE
sbDeviceFirmwareAutoCheckForUpdate prototype _queueItemSuccess
sbDeviceFirmwareAutoCheckForUpdate prototype _timerManager
const SB_TIMER_MANAGER_PREFIX
sbDeviceFirmwareAutoCheckForUpdate prototype interfaces
_getSelectedPageStyle s i
sbDeviceFirmwareAutoCheckForUpdate prototype _deviceFirmwareUpdater
sbDeviceFirmwareAutoCheckForUpdate prototype _queueItem