2012-05-21 15:12:37 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2010-08-03 03:37:56 +04:00
|
|
|
|
2013-09-04 03:11:46 +04:00
|
|
|
// gSyncUI handles updating the tools menu and displaying notifications.
|
2010-08-03 03:37:56 +04:00
|
|
|
let gSyncUI = {
|
2013-09-04 03:11:46 +04:00
|
|
|
DEFAULT_EOL_URL: "https://www.mozilla.org/firefox/?utm_source=synceol",
|
|
|
|
|
2011-08-27 01:01:35 +04:00
|
|
|
_obs: ["weave:service:sync:start",
|
2011-07-30 05:48:15 +04:00
|
|
|
"weave:service:sync:delayed",
|
|
|
|
"weave:service:quota:remaining",
|
|
|
|
"weave:service:setup-complete",
|
|
|
|
"weave:service:login:start",
|
|
|
|
"weave:service:login:finish",
|
|
|
|
"weave:service:logout:finish",
|
2011-08-27 01:01:35 +04:00
|
|
|
"weave:service:start-over",
|
|
|
|
"weave:ui:login:error",
|
|
|
|
"weave:ui:sync:error",
|
2011-08-31 02:38:31 +04:00
|
|
|
"weave:ui:sync:finish",
|
2012-06-23 09:28:23 +04:00
|
|
|
"weave:ui:clear-error",
|
2013-09-04 03:11:46 +04:00
|
|
|
"weave:eol",
|
2012-06-23 09:28:23 +04:00
|
|
|
],
|
2011-07-30 05:48:15 +04:00
|
|
|
|
|
|
|
_unloaded: false,
|
|
|
|
|
2013-09-04 03:11:46 +04:00
|
|
|
init: function () {
|
|
|
|
Cu.import("resource://services-common/stringbundle.js");
|
|
|
|
|
2011-02-18 01:05:41 +03:00
|
|
|
// Proceed to set up the UI if Sync has already started up.
|
|
|
|
// Otherwise we'll do it when Sync is firing up.
|
2013-01-30 19:05:12 +04:00
|
|
|
let xps = Components.classes["@mozilla.org/weave/service;1"]
|
|
|
|
.getService(Components.interfaces.nsISupports)
|
|
|
|
.wrappedJSObject;
|
|
|
|
if (xps.ready) {
|
2011-02-18 01:05:41 +03:00
|
|
|
this.initUI();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-12 05:28:27 +04:00
|
|
|
Services.obs.addObserver(this, "weave:service:ready", true);
|
2010-08-29 00:42:29 +04:00
|
|
|
|
|
|
|
// Remove the observer if the window is closed before the observer
|
|
|
|
// was triggered.
|
2011-07-30 05:48:15 +04:00
|
|
|
window.addEventListener("unload", function onUnload() {
|
|
|
|
gSyncUI._unloaded = true;
|
|
|
|
window.removeEventListener("unload", onUnload, false);
|
2010-08-29 00:42:29 +04:00
|
|
|
Services.obs.removeObserver(gSyncUI, "weave:service:ready");
|
2011-07-30 05:48:15 +04:00
|
|
|
|
|
|
|
if (Weave.Status.ready) {
|
|
|
|
gSyncUI._obs.forEach(function(topic) {
|
|
|
|
Services.obs.removeObserver(gSyncUI, topic);
|
|
|
|
});
|
|
|
|
}
|
2010-08-29 00:42:29 +04:00
|
|
|
}, false);
|
2010-08-12 05:28:27 +04:00
|
|
|
},
|
2011-02-18 01:05:41 +03:00
|
|
|
|
2010-08-12 05:28:27 +04:00
|
|
|
initUI: function SUI_initUI() {
|
2010-08-03 03:37:56 +04:00
|
|
|
// If this is a browser window?
|
|
|
|
if (gBrowser) {
|
2011-07-30 05:48:15 +04:00
|
|
|
this._obs.push("weave:notification:added");
|
2010-08-03 03:37:56 +04:00
|
|
|
}
|
|
|
|
|
2011-07-30 05:48:15 +04:00
|
|
|
this._obs.forEach(function(topic) {
|
2011-02-18 01:06:00 +03:00
|
|
|
Services.obs.addObserver(this, topic, true);
|
|
|
|
}, this);
|
2010-08-03 03:37:56 +04:00
|
|
|
|
2012-01-14 15:28:45 +04:00
|
|
|
if (gBrowser && Weave.Notifications.notifications.length) {
|
|
|
|
this.initNotifications();
|
2010-08-03 03:37:56 +04:00
|
|
|
}
|
|
|
|
this.updateUI();
|
|
|
|
},
|
2011-07-30 05:48:15 +04:00
|
|
|
|
2010-09-10 21:47:57 +04:00
|
|
|
initNotifications: function SUI_initNotifications() {
|
|
|
|
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
let notificationbox = document.createElementNS(XULNS, "notificationbox");
|
|
|
|
notificationbox.id = "sync-notifications";
|
|
|
|
notificationbox.setAttribute("flex", "1");
|
|
|
|
|
|
|
|
let bottombox = document.getElementById("browser-bottombox");
|
2010-09-23 20:09:55 +04:00
|
|
|
bottombox.insertBefore(notificationbox, bottombox.firstChild);
|
2010-09-10 21:47:57 +04:00
|
|
|
|
|
|
|
// Force a style flush to ensure that our binding is attached.
|
|
|
|
notificationbox.clientTop;
|
|
|
|
|
|
|
|
// notificationbox will listen to observers from now on.
|
|
|
|
Services.obs.removeObserver(this, "weave:notification:added");
|
|
|
|
},
|
2010-08-03 03:37:56 +04:00
|
|
|
|
|
|
|
_wasDelayed: false,
|
|
|
|
|
|
|
|
_needsSetup: function SUI__needsSetup() {
|
|
|
|
let firstSync = "";
|
|
|
|
try {
|
|
|
|
firstSync = Services.prefs.getCharPref("services.sync.firstSync");
|
|
|
|
} catch (e) { }
|
2010-09-08 05:37:46 +04:00
|
|
|
return Weave.Status.checkSetup() == Weave.CLIENT_NOT_CONFIGURED ||
|
2010-08-03 03:37:56 +04:00
|
|
|
firstSync == "notReady";
|
|
|
|
},
|
|
|
|
|
|
|
|
updateUI: function SUI_updateUI() {
|
|
|
|
let needsSetup = this._needsSetup();
|
2010-09-15 22:26:27 +04:00
|
|
|
document.getElementById("sync-setup-state").hidden = !needsSetup;
|
|
|
|
document.getElementById("sync-syncnow-state").hidden = needsSetup;
|
2010-08-03 03:37:56 +04:00
|
|
|
|
2010-09-16 06:24:10 +04:00
|
|
|
if (!gBrowser)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let button = document.getElementById("sync-button");
|
|
|
|
if (!button)
|
|
|
|
return;
|
|
|
|
|
|
|
|
button.removeAttribute("status");
|
|
|
|
this._updateLastSyncTime();
|
|
|
|
if (needsSetup)
|
|
|
|
button.removeAttribute("tooltiptext");
|
2010-08-03 03:37:56 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// Functions called by observers
|
|
|
|
onActivityStart: function SUI_onActivityStart() {
|
2010-09-16 06:24:10 +04:00
|
|
|
if (!gBrowser)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let button = document.getElementById("sync-button");
|
|
|
|
if (!button)
|
|
|
|
return;
|
|
|
|
|
|
|
|
button.setAttribute("status", "active");
|
2010-08-03 03:37:56 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
onSyncDelay: function SUI_onSyncDelay() {
|
|
|
|
// basically, we want to just inform users that stuff is going to take a while
|
|
|
|
let title = this._stringBundle.GetStringFromName("error.sync.no_node_found.title");
|
|
|
|
let description = this._stringBundle.GetStringFromName("error.sync.no_node_found");
|
2010-09-24 02:19:42 +04:00
|
|
|
let buttons = [new Weave.NotificationButton(
|
|
|
|
this._stringBundle.GetStringFromName("error.sync.serverStatusButton.label"),
|
|
|
|
this._stringBundle.GetStringFromName("error.sync.serverStatusButton.accesskey"),
|
2010-10-08 19:57:04 +04:00
|
|
|
function() { gSyncUI.openServerStatus(); return true; }
|
2010-09-24 02:19:42 +04:00
|
|
|
)];
|
|
|
|
let notification = new Weave.Notification(
|
|
|
|
title, description, null, Weave.Notifications.PRIORITY_INFO, buttons);
|
2010-08-03 03:37:56 +04:00
|
|
|
Weave.Notifications.replaceTitle(notification);
|
|
|
|
this._wasDelayed = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onLoginFinish: function SUI_onLoginFinish() {
|
|
|
|
// Clear out any login failure notifications
|
|
|
|
let title = this._stringBundle.GetStringFromName("error.login.title");
|
2011-08-31 02:38:31 +04:00
|
|
|
this.clearError(title);
|
2010-08-03 03:37:56 +04:00
|
|
|
},
|
|
|
|
|
2011-10-27 05:26:53 +04:00
|
|
|
onSetupComplete: function SUI_onSetupComplete() {
|
2012-07-10 02:17:00 +04:00
|
|
|
this.onLoginFinish();
|
2011-10-27 05:26:53 +04:00
|
|
|
},
|
|
|
|
|
2010-08-03 03:37:56 +04:00
|
|
|
onLoginError: function SUI_onLoginError() {
|
|
|
|
// if login fails, any other notifications are essentially moot
|
|
|
|
Weave.Notifications.removeAll();
|
|
|
|
|
|
|
|
// if we haven't set up the client, don't show errors
|
2011-08-27 01:01:35 +04:00
|
|
|
if (this._needsSetup()) {
|
2010-08-03 03:37:56 +04:00
|
|
|
this.updateUI();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let title = this._stringBundle.GetStringFromName("error.login.title");
|
2011-08-27 01:01:35 +04:00
|
|
|
|
|
|
|
let description;
|
|
|
|
if (Weave.Status.sync == Weave.PROLONGED_SYNC_FAILURE) {
|
|
|
|
// Convert to days
|
|
|
|
let lastSync =
|
|
|
|
Services.prefs.getIntPref("services.sync.errorhandler.networkFailureReportTimeout") / 86400;
|
|
|
|
description =
|
|
|
|
this._stringBundle.formatStringFromName("error.sync.prolonged_failure", [lastSync], 1);
|
|
|
|
} else {
|
|
|
|
let reason = Weave.Utils.getErrorString(Weave.Status.login);
|
|
|
|
description =
|
|
|
|
this._stringBundle.formatStringFromName("error.sync.description", [reason], 1);
|
|
|
|
}
|
|
|
|
|
2010-08-03 03:37:56 +04:00
|
|
|
let buttons = [];
|
|
|
|
buttons.push(new Weave.NotificationButton(
|
|
|
|
this._stringBundle.GetStringFromName("error.login.prefs.label"),
|
|
|
|
this._stringBundle.GetStringFromName("error.login.prefs.accesskey"),
|
|
|
|
function() { gSyncUI.openPrefs(); return true; }
|
|
|
|
));
|
|
|
|
|
|
|
|
let notification = new Weave.Notification(title, description, null,
|
|
|
|
Weave.Notifications.PRIORITY_WARNING, buttons);
|
|
|
|
Weave.Notifications.replaceTitle(notification);
|
|
|
|
this.updateUI();
|
|
|
|
},
|
|
|
|
|
|
|
|
onLogout: function SUI_onLogout() {
|
|
|
|
this.updateUI();
|
|
|
|
},
|
|
|
|
|
|
|
|
onStartOver: function SUI_onStartOver() {
|
2011-08-31 02:38:31 +04:00
|
|
|
this.clearError();
|
2010-08-03 03:37:56 +04:00
|
|
|
},
|
|
|
|
|
2010-09-15 17:55:04 +04:00
|
|
|
onQuotaNotice: function onQuotaNotice(subject, data) {
|
|
|
|
let title = this._stringBundle.GetStringFromName("warning.sync.quota.label");
|
|
|
|
let description = this._stringBundle.GetStringFromName("warning.sync.quota.description");
|
|
|
|
let buttons = [];
|
|
|
|
buttons.push(new Weave.NotificationButton(
|
|
|
|
this._stringBundle.GetStringFromName("error.sync.viewQuotaButton.label"),
|
|
|
|
this._stringBundle.GetStringFromName("error.sync.viewQuotaButton.accesskey"),
|
|
|
|
function() { gSyncUI.openQuotaDialog(); return true; }
|
|
|
|
));
|
|
|
|
|
|
|
|
let notification = new Weave.Notification(
|
|
|
|
title, description, null, Weave.Notifications.PRIORITY_WARNING, buttons);
|
|
|
|
Weave.Notifications.replaceTitle(notification);
|
|
|
|
},
|
|
|
|
|
2013-09-04 03:11:46 +04:00
|
|
|
_getAppName: function () {
|
|
|
|
try {
|
|
|
|
let syncStrings = new StringBundle("chrome://browser/locale/sync.properties");
|
|
|
|
return syncStrings.getFormattedString("sync.defaultAccountApplication", [brandName]);
|
|
|
|
} catch (ex) {}
|
|
|
|
let brand = new StringBundle("chrome://branding/locale/brand.properties");
|
|
|
|
return brand.get("brandShortName");
|
|
|
|
},
|
|
|
|
|
|
|
|
onEOLNotice: function (data) {
|
|
|
|
let code = data.code;
|
|
|
|
let kind = (code == "hard-eol") ? "error" : "warning";
|
|
|
|
let url = data.url || gSyncUI.DEFAULT_EOL_URL;
|
|
|
|
|
|
|
|
let title = this._stringBundle.GetStringFromName(kind + ".sync.eol.label");
|
|
|
|
let description = this._stringBundle.formatStringFromName(kind + ".sync.eol.description",
|
|
|
|
[this._getAppName()],
|
|
|
|
1);
|
|
|
|
|
|
|
|
let buttons = [];
|
|
|
|
buttons.push(new Weave.NotificationButton(
|
|
|
|
this._stringBundle.GetStringFromName("sync.eol.learnMore.label"),
|
|
|
|
this._stringBundle.GetStringFromName("sync.eol.learnMore.accesskey"),
|
|
|
|
function() {
|
|
|
|
window.openUILinkIn(url, "tab");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
let priority = (kind == "error") ? Weave.Notifications.PRIORITY_WARNING :
|
|
|
|
Weave.Notifications.PRIORITY_INFO;
|
|
|
|
let notification = new Weave.Notification(title, description, null, priority, buttons);
|
|
|
|
Weave.Notifications.replaceTitle(notification);
|
|
|
|
},
|
|
|
|
|
2010-09-24 02:19:42 +04:00
|
|
|
openServerStatus: function () {
|
|
|
|
let statusURL = Services.prefs.getCharPref("services.sync.statusURL");
|
|
|
|
window.openUILinkIn(statusURL, "tab");
|
|
|
|
},
|
|
|
|
|
2010-08-03 03:37:56 +04:00
|
|
|
// Commands
|
|
|
|
doSync: function SUI_doSync() {
|
2012-08-30 01:43:40 +04:00
|
|
|
setTimeout(function() Weave.Service.errorHandler.syncAndReportErrors(), 0);
|
2010-08-03 03:37:56 +04:00
|
|
|
},
|
|
|
|
|
2010-09-10 21:00:55 +04:00
|
|
|
handleToolbarButton: function SUI_handleStatusbarButton() {
|
2010-09-15 22:26:27 +04:00
|
|
|
if (this._needsSetup())
|
2010-08-03 03:37:56 +04:00
|
|
|
this.openSetup();
|
|
|
|
else
|
2010-09-15 22:26:27 +04:00
|
|
|
this.doSync();
|
2010-08-03 03:37:56 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
//XXXzpao should be part of syncCommon.js - which we might want to make a module...
|
|
|
|
// To be fixed in a followup (bug 583366)
|
2011-10-27 05:26:51 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoke the Sync setup wizard.
|
|
|
|
*
|
|
|
|
* @param wizardType
|
|
|
|
* Indicates type of wizard to launch:
|
|
|
|
* null -- regular set up wizard
|
|
|
|
* "pair" -- pair a device first
|
|
|
|
* "reset" -- reset sync
|
|
|
|
*/
|
|
|
|
|
|
|
|
openSetup: function SUI_openSetup(wizardType) {
|
2010-08-03 03:37:56 +04:00
|
|
|
let win = Services.wm.getMostRecentWindow("Weave:AccountSetup");
|
|
|
|
if (win)
|
|
|
|
win.focus();
|
|
|
|
else {
|
2012-02-28 20:03:35 +04:00
|
|
|
window.openDialog("chrome://browser/content/sync/setup.xul",
|
2011-10-27 05:26:51 +04:00
|
|
|
"weaveSetup", "centerscreen,chrome,resizable=no",
|
|
|
|
wizardType);
|
2010-08-03 03:37:56 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-10-27 05:26:51 +04:00
|
|
|
openAddDevice: function () {
|
|
|
|
if (!Weave.Utils.ensureMPUnlocked())
|
|
|
|
return;
|
|
|
|
|
|
|
|
let win = Services.wm.getMostRecentWindow("Sync:AddDevice");
|
|
|
|
if (win)
|
|
|
|
win.focus();
|
|
|
|
else
|
2012-02-28 20:03:35 +04:00
|
|
|
window.openDialog("chrome://browser/content/sync/addDevice.xul",
|
2011-10-27 05:26:51 +04:00
|
|
|
"syncAddDevice", "centerscreen,chrome,resizable=no");
|
|
|
|
},
|
|
|
|
|
2010-09-15 17:55:04 +04:00
|
|
|
openQuotaDialog: function SUI_openQuotaDialog() {
|
|
|
|
let win = Services.wm.getMostRecentWindow("Sync:ViewQuota");
|
|
|
|
if (win)
|
|
|
|
win.focus();
|
2011-07-30 05:48:15 +04:00
|
|
|
else
|
2010-09-15 17:55:04 +04:00
|
|
|
Services.ww.activeWindow.openDialog(
|
2012-02-28 20:03:35 +04:00
|
|
|
"chrome://browser/content/sync/quota.xul", "",
|
2010-09-15 17:55:04 +04:00
|
|
|
"centerscreen,chrome,dialog,modal");
|
|
|
|
},
|
|
|
|
|
2010-08-03 03:37:56 +04:00
|
|
|
openPrefs: function SUI_openPrefs() {
|
|
|
|
openPreferences("paneSync");
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// Helpers
|
2010-09-15 22:26:27 +04:00
|
|
|
_updateLastSyncTime: function SUI__updateLastSyncTime() {
|
|
|
|
if (!gBrowser)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let syncButton = document.getElementById("sync-button");
|
2010-09-16 06:24:10 +04:00
|
|
|
if (!syncButton)
|
|
|
|
return;
|
|
|
|
|
2010-08-03 03:37:56 +04:00
|
|
|
let lastSync;
|
|
|
|
try {
|
2010-08-29 00:42:29 +04:00
|
|
|
lastSync = Services.prefs.getCharPref("services.sync.lastSync");
|
2010-08-03 03:37:56 +04:00
|
|
|
}
|
|
|
|
catch (e) { };
|
2010-09-15 22:26:27 +04:00
|
|
|
if (!lastSync || this._needsSetup()) {
|
|
|
|
syncButton.removeAttribute("tooltiptext");
|
2010-08-03 03:37:56 +04:00
|
|
|
return;
|
2010-09-15 22:26:27 +04:00
|
|
|
}
|
2010-08-03 03:37:56 +04:00
|
|
|
|
|
|
|
// Show the day-of-week and time (HH:MM) of last sync
|
|
|
|
let lastSyncDate = new Date(lastSync).toLocaleFormat("%a %H:%M");
|
|
|
|
let lastSyncLabel =
|
2011-05-30 23:51:34 +04:00
|
|
|
this._stringBundle.formatStringFromName("lastSync2.label", [lastSyncDate], 1);
|
2010-08-03 03:37:56 +04:00
|
|
|
|
2010-09-15 22:26:27 +04:00
|
|
|
syncButton.setAttribute("tooltiptext", lastSyncLabel);
|
2010-08-03 03:37:56 +04:00
|
|
|
},
|
|
|
|
|
2011-08-31 02:38:31 +04:00
|
|
|
clearError: function SUI_clearError(errorString) {
|
|
|
|
Weave.Notifications.removeAll(errorString);
|
|
|
|
this.updateUI();
|
|
|
|
},
|
|
|
|
|
2011-08-27 01:01:35 +04:00
|
|
|
onSyncFinish: function SUI_onSyncFinish() {
|
2010-08-03 03:37:56 +04:00
|
|
|
let title = this._stringBundle.GetStringFromName("error.sync.title");
|
2011-02-03 21:54:00 +03:00
|
|
|
|
2011-08-27 01:01:35 +04:00
|
|
|
// Clear out sync failures on a successful sync
|
2011-08-31 02:38:31 +04:00
|
|
|
this.clearError(title);
|
2011-08-27 01:01:35 +04:00
|
|
|
|
|
|
|
if (this._wasDelayed && Weave.Status.sync != Weave.NO_SYNC_NODE_FOUND) {
|
|
|
|
title = this._stringBundle.GetStringFromName("error.sync.no_node_found.title");
|
2011-08-31 02:38:31 +04:00
|
|
|
this.clearError(title);
|
2011-08-27 01:01:35 +04:00
|
|
|
this._wasDelayed = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onSyncError: function SUI_onSyncError() {
|
|
|
|
let title = this._stringBundle.GetStringFromName("error.sync.title");
|
|
|
|
|
|
|
|
if (Weave.Status.login != Weave.LOGIN_SUCCEEDED) {
|
|
|
|
this.onLoginError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let description;
|
|
|
|
if (Weave.Status.sync == Weave.PROLONGED_SYNC_FAILURE) {
|
|
|
|
// Convert to days
|
|
|
|
let lastSync =
|
|
|
|
Services.prefs.getIntPref("services.sync.errorhandler.networkFailureReportTimeout") / 86400;
|
|
|
|
description =
|
|
|
|
this._stringBundle.formatStringFromName("error.sync.prolonged_failure", [lastSync], 1);
|
|
|
|
} else {
|
2010-08-03 03:37:56 +04:00
|
|
|
let error = Weave.Utils.getErrorString(Weave.Status.sync);
|
2011-08-27 01:01:35 +04:00
|
|
|
description =
|
2010-08-03 03:37:56 +04:00
|
|
|
this._stringBundle.formatStringFromName("error.sync.description", [error], 1);
|
2011-08-27 01:01:35 +04:00
|
|
|
}
|
|
|
|
let priority = Weave.Notifications.PRIORITY_WARNING;
|
|
|
|
let buttons = [];
|
2010-08-03 03:37:56 +04:00
|
|
|
|
2011-08-27 01:01:35 +04:00
|
|
|
// Check if the client is outdated in some way
|
|
|
|
let outdated = Weave.Status.sync == Weave.VERSION_OUT_OF_DATE;
|
|
|
|
for (let [engine, reason] in Iterator(Weave.Status.engines))
|
|
|
|
outdated = outdated || reason == Weave.VERSION_OUT_OF_DATE;
|
|
|
|
|
|
|
|
if (outdated) {
|
|
|
|
description = this._stringBundle.GetStringFromName(
|
|
|
|
"error.sync.needUpdate.description");
|
|
|
|
buttons.push(new Weave.NotificationButton(
|
|
|
|
this._stringBundle.GetStringFromName("error.sync.needUpdate.label"),
|
|
|
|
this._stringBundle.GetStringFromName("error.sync.needUpdate.accesskey"),
|
|
|
|
function() { window.openUILinkIn("https://services.mozilla.com/update/", "tab"); return true; }
|
|
|
|
));
|
|
|
|
}
|
|
|
|
else if (Weave.Status.sync == Weave.OVER_QUOTA) {
|
|
|
|
description = this._stringBundle.GetStringFromName(
|
|
|
|
"error.sync.quota.description");
|
|
|
|
buttons.push(new Weave.NotificationButton(
|
|
|
|
this._stringBundle.GetStringFromName(
|
|
|
|
"error.sync.viewQuotaButton.label"),
|
|
|
|
this._stringBundle.GetStringFromName(
|
|
|
|
"error.sync.viewQuotaButton.accesskey"),
|
|
|
|
function() { gSyncUI.openQuotaDialog(); return true; } )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (Weave.Status.enforceBackoff) {
|
|
|
|
priority = Weave.Notifications.PRIORITY_INFO;
|
|
|
|
buttons.push(new Weave.NotificationButton(
|
|
|
|
this._stringBundle.GetStringFromName("error.sync.serverStatusButton.label"),
|
|
|
|
this._stringBundle.GetStringFromName("error.sync.serverStatusButton.accesskey"),
|
|
|
|
function() { gSyncUI.openServerStatus(); return true; }
|
|
|
|
));
|
2010-08-03 03:37:56 +04:00
|
|
|
}
|
|
|
|
else {
|
2011-08-27 01:01:35 +04:00
|
|
|
priority = Weave.Notifications.PRIORITY_INFO;
|
|
|
|
buttons.push(new Weave.NotificationButton(
|
|
|
|
this._stringBundle.GetStringFromName("error.sync.tryAgainButton.label"),
|
|
|
|
this._stringBundle.GetStringFromName("error.sync.tryAgainButton.accesskey"),
|
|
|
|
function() { gSyncUI.doSync(); return true; }
|
|
|
|
));
|
2010-08-03 03:37:56 +04:00
|
|
|
}
|
|
|
|
|
2011-08-27 01:01:35 +04:00
|
|
|
let notification =
|
|
|
|
new Weave.Notification(title, description, null, priority, buttons);
|
|
|
|
Weave.Notifications.replaceTitle(notification);
|
|
|
|
|
2010-08-03 03:37:56 +04:00
|
|
|
if (this._wasDelayed && Weave.Status.sync != Weave.NO_SYNC_NODE_FOUND) {
|
|
|
|
title = this._stringBundle.GetStringFromName("error.sync.no_node_found.title");
|
|
|
|
Weave.Notifications.removeAll(title);
|
|
|
|
this._wasDelayed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateUI();
|
2010-08-12 05:28:27 +04:00
|
|
|
},
|
2011-07-30 05:48:15 +04:00
|
|
|
|
2010-08-12 05:28:27 +04:00
|
|
|
observe: function SUI_observe(subject, topic, data) {
|
2011-07-30 05:48:15 +04:00
|
|
|
if (this._unloaded) {
|
|
|
|
Cu.reportError("SyncUI observer called after unload: " + topic);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-04 03:11:46 +04:00
|
|
|
// Unwrap, just like Svc.Obs, but without pulling in that dependency.
|
|
|
|
if (subject && typeof subject == "object" &&
|
|
|
|
("wrappedJSObject" in subject) &&
|
|
|
|
("observersModuleSubjectWrapper" in subject.wrappedJSObject)) {
|
|
|
|
subject = subject.wrappedJSObject.object;
|
|
|
|
}
|
|
|
|
|
2010-08-12 05:28:27 +04:00
|
|
|
switch (topic) {
|
|
|
|
case "weave:service:sync:start":
|
|
|
|
this.onActivityStart();
|
|
|
|
break;
|
2011-08-27 01:01:35 +04:00
|
|
|
case "weave:ui:sync:finish":
|
2010-08-12 05:28:27 +04:00
|
|
|
this.onSyncFinish();
|
|
|
|
break;
|
2011-08-27 01:01:35 +04:00
|
|
|
case "weave:ui:sync:error":
|
2010-08-12 05:28:27 +04:00
|
|
|
this.onSyncError();
|
|
|
|
break;
|
|
|
|
case "weave:service:sync:delayed":
|
|
|
|
this.onSyncDelay();
|
|
|
|
break;
|
2010-09-15 17:55:04 +04:00
|
|
|
case "weave:service:quota:remaining":
|
|
|
|
this.onQuotaNotice();
|
|
|
|
break;
|
2010-08-12 05:28:27 +04:00
|
|
|
case "weave:service:setup-complete":
|
2011-10-27 05:26:53 +04:00
|
|
|
this.onSetupComplete();
|
2010-08-12 05:28:27 +04:00
|
|
|
break;
|
|
|
|
case "weave:service:login:start":
|
|
|
|
this.onActivityStart();
|
|
|
|
break;
|
|
|
|
case "weave:service:login:finish":
|
|
|
|
this.onLoginFinish();
|
|
|
|
break;
|
2011-08-27 01:01:35 +04:00
|
|
|
case "weave:ui:login:error":
|
2010-08-12 05:28:27 +04:00
|
|
|
this.onLoginError();
|
|
|
|
break;
|
|
|
|
case "weave:service:logout:finish":
|
|
|
|
this.onLogout();
|
|
|
|
break;
|
|
|
|
case "weave:service:start-over":
|
|
|
|
this.onStartOver();
|
|
|
|
break;
|
|
|
|
case "weave:service:ready":
|
|
|
|
this.initUI();
|
|
|
|
break;
|
2010-08-29 00:42:04 +04:00
|
|
|
case "weave:notification:added":
|
2010-09-10 21:47:57 +04:00
|
|
|
this.initNotifications();
|
2010-08-29 00:42:04 +04:00
|
|
|
break;
|
2011-08-31 02:38:31 +04:00
|
|
|
case "weave:ui:clear-error":
|
|
|
|
this.clearError();
|
|
|
|
break;
|
2013-09-04 03:11:46 +04:00
|
|
|
case "weave:eol":
|
|
|
|
this.onEOLNotice(subject);
|
|
|
|
break;
|
2010-08-12 05:28:27 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
|
|
|
Ci.nsIObserver,
|
|
|
|
Ci.nsISupportsWeakReference
|
|
|
|
])
|
2010-08-03 03:37:56 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(gSyncUI, "_stringBundle", function() {
|
|
|
|
//XXXzpao these strings should probably be moved from /services to /browser... (bug 583381)
|
|
|
|
// but for now just make it work
|
|
|
|
return Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService).
|
|
|
|
createBundle("chrome://weave/locale/services/sync.properties");
|
|
|
|
});
|
|
|
|
|