2012-05-31 15:00:27 +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/. */
|
2008-06-02 03:44:22 +04:00
|
|
|
|
2012-11-28 04:18:38 +04:00
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
2011-12-08 17:41:10 +04:00
|
|
|
Cu.import("resource:///modules/imServices.jsm");
|
|
|
|
Cu.import("resource://gre/modules/DownloadUtils.jsm");
|
2008-10-31 00:02:38 +03:00
|
|
|
|
2008-06-02 03:44:22 +04:00
|
|
|
// This is the list of notifications that the account manager window observes
|
|
|
|
const events = [
|
2011-11-09 04:16:17 +04:00
|
|
|
"prpl-quit",
|
2009-08-28 00:28:41 +04:00
|
|
|
"account-list-updated",
|
2008-06-02 03:44:22 +04:00
|
|
|
"account-added",
|
|
|
|
"account-updated",
|
|
|
|
"account-removed",
|
|
|
|
"account-connected",
|
|
|
|
"account-connecting",
|
|
|
|
"account-disconnected",
|
|
|
|
"account-disconnecting",
|
|
|
|
"account-connect-progress",
|
2008-10-09 05:57:12 +04:00
|
|
|
"account-connect-error",
|
2009-08-07 05:39:12 +04:00
|
|
|
"autologin-processed",
|
2010-02-18 01:59:57 +03:00
|
|
|
"status-changed",
|
2009-08-07 05:39:12 +04:00
|
|
|
"network:offline-status-changed"
|
2008-06-02 03:44:22 +04:00
|
|
|
];
|
|
|
|
|
|
|
|
var gAccountManager = {
|
2009-08-16 05:59:10 +04:00
|
|
|
// Sets the delay after connect() or disconnect() during which
|
|
|
|
// it is impossible to perform disconnect() and connect()
|
|
|
|
_disabledDelay: 500,
|
|
|
|
disableTimerID: 0,
|
2011-11-30 04:15:45 +04:00
|
|
|
_connectedLabelInterval: 0,
|
2008-06-02 03:44:22 +04:00
|
|
|
load: function am_load() {
|
2014-11-21 17:38:13 +03:00
|
|
|
// Wait until the password service is ready before offering anything.
|
|
|
|
Services.logins.initializationPromise.then(() => {
|
|
|
|
this.accountList = document.getElementById("accountlist");
|
|
|
|
let defaultID;
|
|
|
|
for (let acc in this.getAccounts()) {
|
|
|
|
var elt = document.createElement("richlistitem");
|
|
|
|
this.accountList.appendChild(elt);
|
|
|
|
elt.build(acc);
|
|
|
|
if (!defaultID && acc.firstConnectionState == acc.FIRST_CONNECTION_CRASHED)
|
|
|
|
defaultID = acc.id;
|
|
|
|
}
|
|
|
|
for each (let event in events)
|
|
|
|
Services.obs.addObserver(this, event, false);
|
|
|
|
if (!this.accountList.getRowCount())
|
|
|
|
// This is horrible, but it works. Otherwise (at least on mac)
|
|
|
|
// the wizard is not centered relatively to the account manager
|
|
|
|
setTimeout(function() { gAccountManager.new(); }, 0);
|
|
|
|
else {
|
|
|
|
// we have accounts, show the list
|
|
|
|
document.getElementById("accountsDesk").selectedIndex = 1;
|
2009-08-26 19:25:05 +04:00
|
|
|
|
2014-11-21 17:38:13 +03:00
|
|
|
// ensure an account is selected
|
|
|
|
if (defaultID)
|
|
|
|
this.selectAccount(defaultID);
|
|
|
|
else
|
|
|
|
this.accountList.selectedIndex = 0;
|
|
|
|
}
|
2008-10-09 05:57:12 +04:00
|
|
|
|
2014-11-21 17:38:13 +03:00
|
|
|
this.setAutoLoginNotification();
|
2008-10-09 05:57:12 +04:00
|
|
|
|
2014-11-21 17:38:13 +03:00
|
|
|
this.accountList.addEventListener("keypress", this.onKeyPress, true);
|
|
|
|
window.addEventListener("unload", this.unload.bind(this));
|
|
|
|
this._connectedLabelInterval = setInterval(this.updateConnectedLabels, 60000);
|
|
|
|
}, () => {
|
|
|
|
this.close();
|
|
|
|
});
|
2008-06-02 03:44:22 +04:00
|
|
|
},
|
|
|
|
unload: function am_unload() {
|
2009-09-03 00:41:10 +04:00
|
|
|
clearInterval(this._connectedLabelInterval);
|
2011-12-08 17:41:10 +04:00
|
|
|
for each (let event in events)
|
|
|
|
Services.obs.removeObserver(this, event);
|
2008-06-02 03:44:22 +04:00
|
|
|
},
|
2010-08-10 20:19:07 +04:00
|
|
|
_updateAccountList: function am__updateAccountList() {
|
2009-08-28 00:28:41 +04:00
|
|
|
let accountList = this.accountList;
|
|
|
|
let i = 0;
|
2010-08-10 20:19:07 +04:00
|
|
|
for (let acc in this.getAccounts()) {
|
2009-08-28 00:28:41 +04:00
|
|
|
let oldItem = accountList.getItemAtIndex(i);
|
|
|
|
if (oldItem.id != acc.id) {
|
|
|
|
let accElt = document.getElementById(acc.id);
|
|
|
|
accountList.insertBefore(accElt, oldItem);
|
|
|
|
accElt.restoreItems();
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2010-09-14 14:22:33 +04:00
|
|
|
if (accountList.itemCount == 0) {
|
|
|
|
// Focus the "New Account" button if there are no accounts left.
|
|
|
|
document.getElementById("newaccount").focus();
|
|
|
|
// Return early, otherwise we'll run into an 'undefined property' strict
|
|
|
|
// warning when trying to focus the buttons. Fixes bug 408.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-28 00:28:41 +04:00
|
|
|
// The selected item is still selected
|
|
|
|
accountList.selectedItem.buttons.setFocus();
|
|
|
|
accountList.ensureSelectedElementIsVisible();
|
|
|
|
|
|
|
|
// We need to refresh the disabled menu items
|
|
|
|
this.disableCommandItems();
|
|
|
|
},
|
2008-06-02 03:44:22 +04:00
|
|
|
observe: function am_observe(aObject, aTopic, aData) {
|
2011-11-09 04:16:17 +04:00
|
|
|
if (aTopic == "prpl-quit") {
|
2008-06-02 03:44:22 +04:00
|
|
|
// libpurple is being uninitialized. We don't need the account
|
|
|
|
// manager window anymore, close it.
|
|
|
|
this.close();
|
|
|
|
return;
|
|
|
|
}
|
2008-10-09 05:57:12 +04:00
|
|
|
else if (aTopic == "autologin-processed") {
|
|
|
|
var notification = document.getElementById("accountsNotificationBox")
|
|
|
|
.getNotificationWithValue("autoLoginStatus");
|
|
|
|
if (notification)
|
|
|
|
notification.close();
|
|
|
|
return;
|
|
|
|
}
|
2009-08-07 05:39:12 +04:00
|
|
|
else if (aTopic == "network:offline-status-changed") {
|
|
|
|
this.setOffline(aData == "offline");
|
|
|
|
return;
|
|
|
|
}
|
2010-02-18 01:59:57 +03:00
|
|
|
else if (aTopic == "status-changed") {
|
2011-11-09 04:16:17 +04:00
|
|
|
this.setOffline(aObject.statusType == Ci.imIStatusInfo.STATUS_OFFLINE);
|
2010-02-18 01:59:57 +03:00
|
|
|
return;
|
|
|
|
}
|
2009-08-28 00:28:41 +04:00
|
|
|
else if (aTopic == "account-list-updated") {
|
2010-08-10 20:19:07 +04:00
|
|
|
this._updateAccountList();
|
2009-08-28 00:28:41 +04:00
|
|
|
return;
|
|
|
|
}
|
2008-06-02 03:44:22 +04:00
|
|
|
|
2011-11-09 04:16:17 +04:00
|
|
|
// The following notification handlers need an account.
|
|
|
|
aObject.QueryInterface(Ci.imIAccount);
|
2008-06-02 03:44:22 +04:00
|
|
|
|
|
|
|
if (aTopic == "account-added") {
|
2009-08-26 19:25:05 +04:00
|
|
|
document.getElementById("accountsDesk").selectedIndex = 1;
|
2008-06-02 03:44:22 +04:00
|
|
|
var elt = document.createElement("richlistitem");
|
|
|
|
this.accountList.appendChild(elt);
|
|
|
|
elt.build(aObject);
|
|
|
|
if (this.accountList.getRowCount() == 1)
|
2008-10-09 05:57:12 +04:00
|
|
|
this.accountList.selectedIndex = 0;
|
2008-06-02 03:44:22 +04:00
|
|
|
}
|
|
|
|
else if (aTopic == "account-removed") {
|
|
|
|
var elt = document.getElementById(aObject.id);
|
2010-09-14 21:48:53 +04:00
|
|
|
elt.destroy();
|
2008-06-02 03:44:22 +04:00
|
|
|
if (!elt.selected) {
|
2014-02-25 17:52:37 +04:00
|
|
|
elt.remove();
|
2008-10-09 05:57:12 +04:00
|
|
|
return;
|
2008-06-02 03:44:22 +04:00
|
|
|
}
|
|
|
|
// The currently selected element is removed,
|
|
|
|
// ensure another element gets selected (if the list is not empty)
|
|
|
|
var selectedIndex = this.accountList.selectedIndex;
|
2009-08-16 05:59:10 +04:00
|
|
|
// Prevent errors if the timer is active and the account deleted
|
|
|
|
clearTimeout(this.disableTimerID);
|
2011-11-30 04:15:45 +04:00
|
|
|
this.disableTimerID = 0;
|
2014-02-25 17:52:37 +04:00
|
|
|
elt.remove();
|
2008-06-02 03:44:22 +04:00
|
|
|
var count = this.accountList.getRowCount();
|
2009-08-26 19:25:05 +04:00
|
|
|
if (!count) {
|
|
|
|
document.getElementById("accountsDesk").selectedIndex = 0;
|
2008-10-09 05:57:12 +04:00
|
|
|
return;
|
2009-08-26 19:25:05 +04:00
|
|
|
}
|
2008-06-02 03:44:22 +04:00
|
|
|
if (selectedIndex == count)
|
2008-10-09 05:57:12 +04:00
|
|
|
--selectedIndex;
|
2008-06-02 03:44:22 +04:00
|
|
|
this.accountList.selectedIndex = selectedIndex;
|
|
|
|
}
|
2010-03-05 01:52:15 +03:00
|
|
|
else if (aTopic == "account-updated") {
|
2009-08-16 05:59:10 +04:00
|
|
|
document.getElementById(aObject.id).build(aObject);
|
2010-03-05 01:52:15 +03:00
|
|
|
this.disableCommandItems();
|
|
|
|
}
|
2009-08-16 05:59:10 +04:00
|
|
|
else if (aTopic == "account-connect-progress")
|
|
|
|
document.getElementById(aObject.id).updateConnectionState();
|
|
|
|
else if (aTopic == "account-connect-error")
|
|
|
|
document.getElementById(aObject.id).updateConnectionError();
|
2008-10-29 14:08:53 +03:00
|
|
|
else {
|
2009-08-16 05:59:10 +04:00
|
|
|
const stateEvents = {
|
|
|
|
"account-connected": "connected",
|
|
|
|
"account-connecting": "connecting",
|
|
|
|
"account-disconnected": "disconnected",
|
|
|
|
"account-disconnecting": "disconnecting"
|
|
|
|
};
|
|
|
|
if (aTopic in stateEvents) {
|
|
|
|
let elt = document.getElementById(aObject.id);
|
2011-11-09 04:16:17 +04:00
|
|
|
if (!elt)
|
|
|
|
return; // probably disconnecting a removed account.
|
|
|
|
|
2009-08-16 05:59:10 +04:00
|
|
|
if (aTopic == "account-connecting") {
|
|
|
|
elt.removeAttribute("error");
|
|
|
|
elt.updateConnectionState();
|
|
|
|
}
|
2009-09-03 00:41:10 +04:00
|
|
|
else {
|
|
|
|
if (aTopic == "account-connected")
|
|
|
|
elt.refreshConnectedLabel();
|
|
|
|
}
|
2009-08-16 05:59:10 +04:00
|
|
|
|
|
|
|
elt.setAttribute("state", stateEvents[aTopic]);
|
|
|
|
}
|
2008-10-09 05:57:12 +04:00
|
|
|
}
|
2008-06-02 03:44:22 +04:00
|
|
|
},
|
2009-08-17 05:55:25 +04:00
|
|
|
cancelReconnection: function am_cancelReconnection() {
|
|
|
|
this.accountList.selectedItem.cancelReconnection();
|
|
|
|
},
|
2008-06-02 03:44:22 +04:00
|
|
|
connect: function am_connect() {
|
2009-08-16 05:59:10 +04:00
|
|
|
let account = this.accountList.selectedItem.account;
|
|
|
|
if (account.disconnected) {
|
2012-08-03 21:40:42 +04:00
|
|
|
this.temporarilyDisableButtons();
|
2009-08-16 05:59:10 +04:00
|
|
|
account.connect();
|
|
|
|
}
|
2008-06-02 03:44:22 +04:00
|
|
|
},
|
|
|
|
disconnect: function am_disconnect() {
|
2009-08-16 05:59:10 +04:00
|
|
|
let account = this.accountList.selectedItem.account;
|
|
|
|
if (account.connected || account.connecting) {
|
2012-08-03 21:40:42 +04:00
|
|
|
this.temporarilyDisableButtons();
|
2009-08-16 05:59:10 +04:00
|
|
|
account.disconnect();
|
|
|
|
}
|
|
|
|
},
|
2013-04-11 06:49:24 +04:00
|
|
|
addException: function am_addException() {
|
|
|
|
let account = this.accountList.selectedItem.account;
|
2014-08-27 00:56:35 +04:00
|
|
|
let prplAccount = account.prplAccount;
|
|
|
|
if (!account.disconnected || !prplAccount.connectionTarget)
|
2013-04-11 06:49:24 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Open the Gecko SSL exception dialog.
|
2014-08-27 00:56:35 +04:00
|
|
|
let params = {
|
|
|
|
exceptionAdded: false,
|
|
|
|
sslStatus: prplAccount.sslStatus,
|
|
|
|
prefetchCert: true,
|
|
|
|
location: prplAccount.connectionTarget
|
|
|
|
};
|
2013-04-11 06:49:24 +04:00
|
|
|
window.openDialog("chrome://pippki/content/exceptionDialog.xul", "",
|
|
|
|
"chrome,centerscreen,modal", params);
|
|
|
|
// Reconnect the account if an exception was added.
|
|
|
|
if (params.exceptionAdded)
|
|
|
|
account.connect();
|
|
|
|
},
|
2012-11-28 04:18:38 +04:00
|
|
|
copyDebugLog: function am_copyDebugLog() {
|
|
|
|
let account = this.accountList.selectedItem.account;
|
|
|
|
let text = account.getDebugMessages().map(function(dbgMsg) {
|
|
|
|
let m = dbgMsg.message;
|
|
|
|
const dateServ = Cc["@mozilla.org/intl/scriptabledateformat;1"]
|
|
|
|
.getService(Ci.nsIScriptableDateFormat);
|
|
|
|
let time = new Date(m.timeStamp);
|
|
|
|
time = dateServ.FormatDateTime("", dateServ.dateFormatShort,
|
|
|
|
dateServ.timeFormatSeconds,
|
|
|
|
time.getFullYear(), time.getMonth() + 1,
|
|
|
|
time.getDate(), time.getHours(),
|
|
|
|
time.getMinutes(), time.getSeconds());
|
|
|
|
let level = dbgMsg.logLevel;
|
2013-03-24 21:33:41 +04:00
|
|
|
if (!level)
|
|
|
|
return "(" + m.errorMessage + ")";
|
2012-11-28 04:18:38 +04:00
|
|
|
if (level == dbgMsg.LEVEL_ERROR)
|
|
|
|
level = "ERROR";
|
|
|
|
else if (level == dbgMsg.LEVEL_WARNING)
|
|
|
|
level = "WARN.";
|
|
|
|
else if (level == dbgMsg.LEVEL_LOG)
|
|
|
|
level = "LOG ";
|
|
|
|
else
|
|
|
|
level = "DEBUG"
|
|
|
|
return "[" + time + "] " + level + " (@ " + m.sourceLine +
|
|
|
|
" " + m.sourceName + ":" + m.lineNumber + ")\n" +
|
|
|
|
m.errorMessage;
|
|
|
|
}).join("\n");
|
|
|
|
Cc["@mozilla.org/widget/clipboardhelper;1"]
|
|
|
|
.getService(Ci.nsIClipboardHelper).copyString(text);
|
|
|
|
},
|
2014-02-21 02:04:29 +04:00
|
|
|
showDebugLog: function am_showDebugLog() {
|
2014-11-21 16:04:55 +03:00
|
|
|
if (!("Core" in window))
|
2014-02-21 02:04:29 +04:00
|
|
|
Cu.import("resource:///modules/ibCore.jsm");
|
|
|
|
Core.showDebugLog(this.accountList.selectedItem.account.id);
|
|
|
|
},
|
2009-09-03 00:41:10 +04:00
|
|
|
updateConnectedLabels: function am_updateConnectedLabels() {
|
|
|
|
for (let i = 0; i < gAccountManager.accountList.itemCount; ++i) {
|
|
|
|
let item = gAccountManager.accountList.getItemAtIndex(i);
|
|
|
|
if (item.account.connected)
|
|
|
|
item.refreshConnectedLabel();
|
|
|
|
}
|
|
|
|
},
|
2012-08-03 21:40:42 +04:00
|
|
|
/* This function disables the connect/disconnect buttons for
|
|
|
|
* `this._disabledDelay` ms before calling disableCommandItems to restore
|
|
|
|
* the state of the buttons.
|
|
|
|
*/
|
|
|
|
temporarilyDisableButtons: function am_temporarilyDisableButtons() {
|
|
|
|
document.getElementById("cmd_disconnect").setAttribute("disabled", "true");
|
|
|
|
document.getElementById("cmd_connect").setAttribute("disabled", "true");
|
2009-08-16 05:59:10 +04:00
|
|
|
clearTimeout(this.disableTimerID);
|
|
|
|
this.accountList.focus();
|
|
|
|
this.disableTimerID = setTimeout(function(aItem) {
|
2011-11-30 04:15:45 +04:00
|
|
|
gAccountManager.disableTimerID = 0;
|
2009-08-16 05:59:10 +04:00
|
|
|
gAccountManager.disableCommandItems();
|
|
|
|
aItem.buttons.setFocus();
|
|
|
|
}, this._disabledDelay, this.accountList.selectedItem);
|
2008-06-02 03:44:22 +04:00
|
|
|
},
|
2009-08-16 05:59:10 +04:00
|
|
|
|
2008-06-02 03:44:22 +04:00
|
|
|
delete: function am_delete() {
|
2009-08-28 00:28:41 +04:00
|
|
|
var selectedItem = this.accountList.selectedItem;
|
|
|
|
if (!selectedItem)
|
|
|
|
return;
|
|
|
|
|
2010-11-05 17:03:08 +03:00
|
|
|
var showPrompt =
|
|
|
|
Services.prefs.getBoolPref("messenger.accounts.promptOnDelete");
|
2009-08-16 05:59:10 +04:00
|
|
|
if (showPrompt) {
|
2010-11-05 17:03:08 +03:00
|
|
|
var prompts = Services.prompt;
|
2009-08-16 05:59:10 +04:00
|
|
|
var bundle = document.getElementById("accountsBundle");
|
|
|
|
var promptTitle = bundle.getString("account.deletePrompt.title");
|
|
|
|
var promptMessage = bundle.getString("account.deletePrompt.message");
|
|
|
|
var promptCheckbox = bundle.getString("account.deletePrompt.checkbox");
|
|
|
|
var deleteButton = bundle.getString("account.deletePrompt.button");
|
|
|
|
|
|
|
|
var checkbox = {};
|
|
|
|
var flags = prompts.BUTTON_TITLE_IS_STRING * prompts.BUTTON_POS_0 +
|
|
|
|
prompts.BUTTON_TITLE_CANCEL * prompts.BUTTON_POS_1 +
|
|
|
|
prompts.BUTTON_POS_1_DEFAULT;
|
|
|
|
if (prompts.confirmEx(window, promptTitle, promptMessage, flags,
|
|
|
|
deleteButton, null, null, promptCheckbox, checkbox))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (checkbox.value)
|
2010-11-05 17:03:08 +03:00
|
|
|
Services.prefs.setBoolPref("messenger.accounts.promptOnDelete", false);
|
2009-08-16 05:59:10 +04:00
|
|
|
}
|
|
|
|
|
2011-11-09 04:16:17 +04:00
|
|
|
Services.accounts.deleteAccount(selectedItem.id);
|
2008-06-02 03:44:22 +04:00
|
|
|
},
|
|
|
|
new: function am_new() {
|
|
|
|
this.openDialog("chrome://instantbird/content/accountWizard.xul");
|
|
|
|
},
|
|
|
|
edit: function am_edit() {
|
|
|
|
this.openDialog("chrome://instantbird/content/account.xul",
|
|
|
|
this.accountList.selectedItem.account);
|
|
|
|
},
|
|
|
|
autologin: function am_autologin() {
|
|
|
|
var elt = this.accountList.selectedItem;
|
|
|
|
elt.autoLogin = !elt.autoLogin;
|
|
|
|
},
|
|
|
|
close: function am_close() {
|
2008-07-24 03:10:59 +04:00
|
|
|
// If a modal dialog is opened, we can't close this window now
|
|
|
|
if (this.modalDialog)
|
|
|
|
setTimeout(function() { window.close();}, 0);
|
|
|
|
else
|
|
|
|
window.close();
|
2008-06-02 03:44:22 +04:00
|
|
|
},
|
|
|
|
|
2009-08-16 05:59:10 +04:00
|
|
|
/* This function disables or enables the currently selected button and
|
|
|
|
the corresponding context menu item */
|
|
|
|
disableCommandItems: function am_disableCommandItems() {
|
2009-08-28 00:28:41 +04:00
|
|
|
let accountList = this.accountList;
|
|
|
|
let selectedItem = accountList.selectedItem;
|
2009-08-17 05:55:25 +04:00
|
|
|
// When opening the account manager, if accounts have errors, we
|
|
|
|
// can be called during build(), before any item is selected.
|
|
|
|
// In this case, just return early.
|
|
|
|
if (!selectedItem)
|
|
|
|
return;
|
|
|
|
|
2009-08-25 05:30:56 +04:00
|
|
|
// If the timer that disables the button (for a short time) already exists,
|
|
|
|
// we don't want to interfere and set the button as enabled.
|
|
|
|
if (this.disableTimerID)
|
|
|
|
return;
|
|
|
|
|
2009-08-17 05:55:25 +04:00
|
|
|
let account = selectedItem.account;
|
2009-08-28 00:28:41 +04:00
|
|
|
let isCommandDisabled =
|
|
|
|
(this.isOffline ||
|
|
|
|
(account.disconnected &&
|
2012-01-25 18:25:58 +04:00
|
|
|
account.connectionErrorReason == Ci.imIAccount.ERROR_UNKNOWN_PRPL));
|
2012-08-21 17:37:03 +04:00
|
|
|
let disabledItems = {
|
|
|
|
connect: isCommandDisabled,
|
|
|
|
disconnect: isCommandDisabled,
|
|
|
|
moveup: accountList.selectedIndex == 0,
|
|
|
|
movedown: accountList.selectedIndex == accountList.itemCount - 1
|
|
|
|
};
|
|
|
|
for each (let [name, state] in Iterator(disabledItems)) {
|
2012-08-03 21:40:42 +04:00
|
|
|
let elt = document.getElementById("cmd_" + name);
|
2009-08-28 00:28:41 +04:00
|
|
|
if (state)
|
|
|
|
elt.setAttribute("disabled", "true");
|
|
|
|
else
|
|
|
|
elt.removeAttribute("disabled");
|
2012-08-21 17:37:03 +04:00
|
|
|
}
|
2009-08-16 05:59:10 +04:00
|
|
|
},
|
|
|
|
onContextMenuShowing: function am_onContextMenuShowing() {
|
|
|
|
let targetElt = document.popupNode;
|
|
|
|
let isAccount = targetElt instanceof Ci.nsIDOMXULSelectControlItemElement;
|
|
|
|
document.getElementById("contextAccountsItems").hidden = !isAccount;
|
|
|
|
if (isAccount) {
|
2012-08-03 21:40:42 +04:00
|
|
|
let account = targetElt.account;
|
|
|
|
let hiddenItems = {
|
|
|
|
connect: !account.disconnected,
|
|
|
|
disconnect: account.disconnected || account.disconnecting,
|
|
|
|
cancelReconnection: !targetElt.hasAttribute("reconnectPending"),
|
|
|
|
accountsItemsSeparator: account.disconnecting
|
|
|
|
};
|
|
|
|
for (let name in hiddenItems)
|
|
|
|
document.getElementById("context_" + name).hidden = hiddenItems[name];
|
2009-08-16 05:59:10 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-06-02 03:44:22 +04:00
|
|
|
selectAccount: function am_selectAccount(aAccountId) {
|
|
|
|
this.accountList.selectedItem = document.getElementById(aAccountId);
|
|
|
|
},
|
2009-08-03 01:42:23 +04:00
|
|
|
onAccountSelect: function am_onAccountSelect() {
|
2009-08-16 05:59:10 +04:00
|
|
|
clearTimeout(this.disableTimerID);
|
2011-11-30 04:15:45 +04:00
|
|
|
this.disableTimerID = 0;
|
2009-08-16 05:59:10 +04:00
|
|
|
this.disableCommandItems();
|
2013-03-22 04:05:14 +04:00
|
|
|
let selectedItem = this.accountList.selectedItem;
|
|
|
|
selectedItem.clientHeight; // force synchronous binding attachment
|
|
|
|
selectedItem.buttons.setFocus();
|
2013-04-18 02:13:42 +04:00
|
|
|
// Without the following, the account manager is scrolled to the first
|
|
|
|
// (dis)connect button when being opened.
|
|
|
|
this.accountList.ensureSelectedElementIsVisible();
|
2009-08-03 01:42:23 +04:00
|
|
|
},
|
2008-06-02 03:44:22 +04:00
|
|
|
|
2009-08-03 01:47:05 +04:00
|
|
|
onKeyPress: function am_onKeyPress(event) {
|
2009-08-28 00:28:41 +04:00
|
|
|
if (!this.selectedItem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.shiftKey &&
|
|
|
|
(event.keyCode == event.DOM_VK_DOWN || event.keyCode == event.DOM_VK_UP)) {
|
|
|
|
let offset = event.keyCode == event.DOM_VK_DOWN ? 1 : -1;
|
|
|
|
gAccountManager.moveCurrentItem(offset);
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-03 01:47:05 +04:00
|
|
|
// As we stop propagation, the default action applies to the richlistbox
|
|
|
|
// so that the selected account is changed with this default action
|
|
|
|
if (event.keyCode == event.DOM_VK_DOWN) {
|
|
|
|
if (this.selectedIndex < this.itemCount - 1)
|
|
|
|
this.ensureIndexIsVisible(this.selectedIndex + 1);
|
|
|
|
event.stopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.keyCode == event.DOM_VK_UP) {
|
|
|
|
if (this.selectedIndex > 0)
|
|
|
|
this.ensureIndexIsVisible(this.selectedIndex - 1);
|
|
|
|
event.stopPropagation();
|
2009-08-05 03:02:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.keyCode == event.DOM_VK_RETURN) {
|
|
|
|
let target = event.originalTarget;
|
|
|
|
if (target.localName != "checkbox" &&
|
|
|
|
(target.localName != "button" ||
|
|
|
|
/^(dis)?connect$/.test(target.getAttribute("anonid"))))
|
2009-08-16 05:59:10 +04:00
|
|
|
this.selectedItem.buttons.proceedDefaultAction();
|
|
|
|
return;
|
2009-08-03 01:47:05 +04:00
|
|
|
}
|
2009-08-16 05:59:10 +04:00
|
|
|
|
|
|
|
if (event.keyCode == event.DOM_VK_DELETE)
|
|
|
|
document.getElementById("cmd_delete").doCommand();
|
2009-08-03 01:47:05 +04:00
|
|
|
},
|
|
|
|
|
2009-08-28 00:28:41 +04:00
|
|
|
moveCurrentItem: function am_moveCurrentItem(aOffset) {
|
|
|
|
let accountList = this.accountList;
|
|
|
|
if (!aOffset || !accountList.selectedItem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Create the new preference value from the richlistbox list
|
|
|
|
let items = accountList.children;
|
|
|
|
let selectedID = accountList.selectedItem.id;
|
|
|
|
let array = [];
|
|
|
|
for (let i in items)
|
|
|
|
if (items[i].id != selectedID)
|
|
|
|
array.push(items[i].id);
|
|
|
|
|
|
|
|
let newIndex = accountList.selectedIndex + aOffset;
|
|
|
|
if (newIndex < 0)
|
|
|
|
newIndex = 0;
|
|
|
|
else if (newIndex >= accountList.itemCount)
|
|
|
|
newIndex = accountList.itemCount - 1;
|
|
|
|
array.splice(newIndex, 0, selectedID);
|
|
|
|
|
2010-11-05 17:03:08 +03:00
|
|
|
Services.prefs.setCharPref("messenger.accounts", array.join(","));
|
2009-08-28 00:28:41 +04:00
|
|
|
},
|
|
|
|
|
2011-12-08 17:41:10 +04:00
|
|
|
getAccounts: function am_getAccounts() {
|
|
|
|
let accounts = Services.accounts.getAccounts();
|
|
|
|
while (accounts.hasMoreElements())
|
|
|
|
yield accounts.getNext();
|
|
|
|
},
|
2008-06-02 03:44:22 +04:00
|
|
|
|
|
|
|
openDialog: function am_openDialog(aUrl, aArgs) {
|
2008-07-24 03:10:59 +04:00
|
|
|
this.modalDialog = true;
|
2009-08-16 05:59:10 +04:00
|
|
|
window.openDialog(aUrl, "", "chrome,modal,titlebar,centerscreen", aArgs);
|
2008-07-24 03:10:59 +04:00
|
|
|
this.modalDialog = false;
|
2008-10-09 05:57:12 +04:00
|
|
|
},
|
|
|
|
setAutoLoginNotification: function am_setAutoLoginNotification() {
|
2011-11-09 04:16:17 +04:00
|
|
|
var as = Services.accounts;
|
|
|
|
var autoLoginStatus = as.autoLoginStatus;
|
2009-08-14 05:18:24 +04:00
|
|
|
let isOffline = false;
|
2009-08-24 03:19:35 +04:00
|
|
|
let crashCount = 0;
|
|
|
|
for (let acc in this.getAccounts())
|
|
|
|
if (acc.autoLogin && acc.firstConnectionState == acc.FIRST_CONNECTION_CRASHED)
|
|
|
|
++crashCount;
|
2008-10-09 05:57:12 +04:00
|
|
|
|
2011-11-09 04:16:17 +04:00
|
|
|
if (autoLoginStatus == as.AUTOLOGIN_ENABLED && crashCount == 0) {
|
|
|
|
let status = Services.core.globalUserStatus.statusType;
|
|
|
|
this.setOffline(isOffline || status == Ci.imIStatusInfo.STATUS_OFFLINE);
|
2008-10-09 05:57:12 +04:00
|
|
|
return;
|
2009-08-14 05:18:24 +04:00
|
|
|
}
|
2008-10-09 05:57:12 +04:00
|
|
|
|
|
|
|
var bundle = document.getElementById("accountsBundle");
|
|
|
|
var box = document.getElementById("accountsNotificationBox");
|
|
|
|
var priority = box.PRIORITY_INFO_HIGH;
|
2009-08-24 03:19:35 +04:00
|
|
|
var connectNowButton = {
|
|
|
|
accessKey: bundle.getString("accountsManager.notification.button.accessKey"),
|
|
|
|
callback: this.processAutoLogin,
|
|
|
|
label: bundle.getString("accountsManager.notification.button.label")
|
|
|
|
};
|
2008-10-09 05:57:12 +04:00
|
|
|
var label;
|
|
|
|
|
|
|
|
switch (autoLoginStatus) {
|
2011-11-09 04:16:17 +04:00
|
|
|
case as.AUTOLOGIN_USER_DISABLED:
|
2008-10-09 05:57:12 +04:00
|
|
|
label = bundle.getString("accountsManager.notification.userDisabled.label");
|
|
|
|
break;
|
|
|
|
|
2011-11-09 04:16:17 +04:00
|
|
|
case as.AUTOLOGIN_SAFE_MODE:
|
2008-10-09 05:57:12 +04:00
|
|
|
label = bundle.getString("accountsManager.notification.safeMode.label");
|
|
|
|
break;
|
|
|
|
|
2011-11-09 04:16:17 +04:00
|
|
|
case as.AUTOLOGIN_START_OFFLINE:
|
2008-10-17 05:13:51 +04:00
|
|
|
label = bundle.getString("accountsManager.notification.startOffline.label");
|
2009-08-07 05:39:12 +04:00
|
|
|
isOffline = true;
|
2008-10-17 05:13:51 +04:00
|
|
|
break;
|
|
|
|
|
2011-11-09 04:16:17 +04:00
|
|
|
case as.AUTOLOGIN_CRASH:
|
2008-10-09 05:57:12 +04:00
|
|
|
label = bundle.getString("accountsManager.notification.crash.label");
|
|
|
|
priority = box.PRIORITY_WARNING_MEDIUM;
|
|
|
|
break;
|
|
|
|
|
2009-08-24 03:19:35 +04:00
|
|
|
/* One or more accounts made the application crash during their connection.
|
|
|
|
If none, this function has already returned */
|
2011-11-09 04:16:17 +04:00
|
|
|
case as.AUTOLOGIN_ENABLED:
|
2009-08-24 03:19:35 +04:00
|
|
|
if (!("PluralForm" in window))
|
2012-11-28 04:18:38 +04:00
|
|
|
Cu.import("resource://gre/modules/PluralForm.jsm");
|
2009-08-24 03:19:35 +04:00
|
|
|
label = bundle.getString("accountsManager.notification.singleCrash.label");
|
|
|
|
label = PluralForm.get(crashCount, label).replace("#1", crashCount);
|
|
|
|
priority = box.PRIORITY_WARNING_MEDIUM;
|
|
|
|
connectNowButton.callback = this.processCrashedAccountsLogin;
|
|
|
|
break;
|
|
|
|
|
2008-10-09 05:57:12 +04:00
|
|
|
default:
|
|
|
|
label = bundle.getString("accountsManager.notification.other.label");
|
|
|
|
}
|
2011-11-09 04:16:17 +04:00
|
|
|
let status = Services.core.globalUserStatus.statusType;
|
|
|
|
this.setOffline(isOffline || status == Ci.imIStatusInfo.STATUS_OFFLINE);
|
2008-10-09 05:57:12 +04:00
|
|
|
|
|
|
|
box.appendNotification(label, "autologinStatus", null, priority, [connectNowButton]);
|
|
|
|
},
|
|
|
|
processAutoLogin: function am_processAutoLogin() {
|
2010-11-05 17:03:08 +03:00
|
|
|
var ioService = Services.io;
|
2008-10-17 05:13:51 +04:00
|
|
|
if (ioService.offline) {
|
|
|
|
ioService.manageOfflineStatus = false;
|
|
|
|
ioService.offline = false;
|
|
|
|
}
|
|
|
|
|
2011-11-09 04:16:17 +04:00
|
|
|
Services.accounts.processAutoLogin();
|
2009-08-24 03:19:35 +04:00
|
|
|
|
|
|
|
gAccountManager.accountList.selectedItem.buttons.setFocus();
|
|
|
|
},
|
|
|
|
processCrashedAccountsLogin: function am_processCrashedAccountsLogin() {
|
|
|
|
for (let acc in gAccountManager.getAccounts())
|
|
|
|
if (acc.disconnected && acc.autoLogin &&
|
|
|
|
acc.firstConnectionState == acc.FIRST_CONNECTION_CRASHED)
|
|
|
|
acc.connect();
|
|
|
|
|
|
|
|
let notification = document.getElementById("accountsNotificationBox")
|
|
|
|
.getNotificationWithValue("autoLoginStatus");
|
|
|
|
if (notification)
|
|
|
|
notification.close();
|
|
|
|
|
|
|
|
gAccountManager.accountList.selectedItem.buttons.setFocus();
|
2009-08-07 05:39:12 +04:00
|
|
|
},
|
|
|
|
setOffline: function am_setOffline(aState) {
|
|
|
|
this.isOffline = aState;
|
2009-08-16 05:59:10 +04:00
|
|
|
if (aState)
|
|
|
|
this.accountList.setAttribute("offline", "true");
|
|
|
|
else
|
|
|
|
this.accountList.removeAttribute("offline");
|
|
|
|
this.disableCommandItems();
|
2008-06-02 03:44:22 +04:00
|
|
|
}
|
|
|
|
};
|
2009-08-28 00:28:41 +04:00
|
|
|
|
|
|
|
|
|
|
|
let gAMDragAndDrop = {
|
|
|
|
ACCOUNT_MIME_TYPE: "application/x-moz-richlistitem",
|
|
|
|
// Size of the scroll zone on the top and on the bottom of the account list
|
|
|
|
MAGIC_SCROLL_HEIGHT: 20,
|
|
|
|
|
|
|
|
// A preference already exists to define scroll speed, let's use it.
|
|
|
|
get SCROLL_SPEED() {
|
|
|
|
delete this.SCROLL_SPEED;
|
|
|
|
try {
|
2010-11-05 17:03:08 +03:00
|
|
|
this.SCROLL_SPEED =
|
|
|
|
Services.prefs.getIntPref("toolkit.scrollbox.scrollIncrement");
|
2009-08-28 00:28:41 +04:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
this.SCROLL_SPEED = 20;
|
|
|
|
}
|
|
|
|
return this.SCROLL_SPEED;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragStart: function amdnd_onDragStart(aEvent, aTransferData, aAction) {
|
|
|
|
let accountElement = aEvent.explicitOriginalTarget;
|
|
|
|
// This stops the dragging session.
|
|
|
|
if (!(accountElement instanceof Ci.nsIDOMXULSelectControlItemElement))
|
|
|
|
throw "Element is not draggable!";
|
|
|
|
if (gAccountManager.accountList.itemCount == 1)
|
|
|
|
throw "Can't drag while there is only one account!";
|
|
|
|
|
|
|
|
// Transferdata is never used, but we need to transfer something.
|
|
|
|
aTransferData.data = new TransferData();
|
|
|
|
aTransferData.data.addDataForFlavour(this.ACCOUNT_MIME_TYPE, accountElement);
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragOver: function amdnd_onDragOver(aEvent, aFlavour, aSession) {
|
|
|
|
let accountElement = aEvent.explicitOriginalTarget;
|
|
|
|
// We are dragging over the account manager, consider it is the same as
|
|
|
|
// the last element.
|
|
|
|
if (accountElement == gAccountManager.accountList)
|
|
|
|
accountElement = gAccountManager.accountList.lastChild;
|
|
|
|
|
|
|
|
// Auto scroll the account list if we are dragging at the top/bottom
|
|
|
|
this.checkForMagicScroll(aEvent.clientY);
|
|
|
|
|
|
|
|
// The hovered element has changed, change the border too
|
2011-11-30 04:15:45 +04:00
|
|
|
if (("_accountElement" in this) && this._accountElement != accountElement)
|
2009-08-28 00:28:41 +04:00
|
|
|
this.cleanBorders();
|
|
|
|
|
|
|
|
if (!aSession.canDrop) {
|
|
|
|
aEvent.dataTransfer.dropEffect = "none";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aEvent.dataTransfer.dropEffect = "move";
|
|
|
|
|
|
|
|
if (aEvent.clientY < accountElement.getBoundingClientRect().top +
|
|
|
|
accountElement.clientHeight / 2) {
|
|
|
|
// we don't want the previous item to show its default bottom-border
|
|
|
|
let previousItem = accountElement.previousSibling;
|
|
|
|
if (previousItem)
|
|
|
|
previousItem.style.borderBottom = "none";
|
|
|
|
accountElement.setAttribute("dragover", "up");
|
|
|
|
}
|
|
|
|
else {
|
2011-11-30 04:15:45 +04:00
|
|
|
if (("_accountElement" in this) &&
|
|
|
|
this._accountElement == accountElement &&
|
2009-08-28 00:28:41 +04:00
|
|
|
accountElement.getAttribute("dragover") == "up")
|
|
|
|
this.cleanBorders();
|
|
|
|
accountElement.setAttribute("dragover", "down");
|
|
|
|
}
|
|
|
|
|
|
|
|
this._accountElement = accountElement;
|
|
|
|
},
|
|
|
|
|
|
|
|
cleanBorders: function amdnd_cleanBorders(aIsEnd) {
|
|
|
|
if (!this._accountElement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._accountElement.removeAttribute("dragover");
|
|
|
|
// reset the border of the previous element
|
|
|
|
let previousItem = this._accountElement.previousSibling;
|
|
|
|
if (previousItem) {
|
2009-10-30 13:57:50 +03:00
|
|
|
if (aIsEnd && !previousItem.style.borderBottom && previousItem.previousSibling)
|
2009-08-28 00:28:41 +04:00
|
|
|
previousItem = previousItem.previousSibling;
|
|
|
|
previousItem.style.borderBottom = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsEnd)
|
|
|
|
delete this._accountElement;
|
|
|
|
},
|
|
|
|
|
|
|
|
canDrop: function amdnd_canDrop(aEvent, aSession) {
|
|
|
|
let accountElement = aEvent.explicitOriginalTarget;
|
|
|
|
if (accountElement == gAccountManager.accountList)
|
|
|
|
accountElement = gAccountManager.accountList.lastChild;
|
|
|
|
return (accountElement != gAccountManager.accountList.selectedItem);
|
|
|
|
},
|
|
|
|
|
|
|
|
checkForMagicScroll: function amdnd_checkForMagicScroll(aClientY) {
|
|
|
|
let accountList = gAccountManager.accountList;
|
|
|
|
let listSize = accountList.getBoundingClientRect();
|
|
|
|
let direction = 1;
|
|
|
|
if (aClientY < listSize.top + this.MAGIC_SCROLL_HEIGHT)
|
|
|
|
direction = -1;
|
|
|
|
else if (aClientY < listSize.bottom - this.MAGIC_SCROLL_HEIGHT)
|
|
|
|
// We are not on a scroll zone
|
|
|
|
return;
|
|
|
|
|
|
|
|
accountList._scrollbox.scrollTop += direction * this.SCROLL_SPEED;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDrop: function amdnd_onDrop(aEvent, aTransferData, aSession) {
|
|
|
|
let accountElement = aEvent.explicitOriginalTarget;
|
|
|
|
if (accountElement == gAccountManager.accountList)
|
|
|
|
accountElement = gAccountManager.accountList.lastChild;
|
|
|
|
|
|
|
|
if (!aSession.canDrop)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// compute the destination
|
|
|
|
let accountList = gAccountManager.accountList;
|
|
|
|
let offset = accountList.getIndexOfItem(accountElement) -
|
|
|
|
accountList.selectedIndex;
|
|
|
|
let isDroppingAbove =
|
|
|
|
aEvent.clientY < accountElement.getBoundingClientRect().top +
|
|
|
|
accountElement.clientHeight / 2;
|
|
|
|
if (offset > 0)
|
|
|
|
offset -= isDroppingAbove;
|
|
|
|
else
|
|
|
|
offset += !isDroppingAbove;
|
|
|
|
gAccountManager.moveCurrentItem(offset);
|
|
|
|
},
|
|
|
|
|
|
|
|
getSupportedFlavours: function amdnd_getSupportedFlavours() {
|
|
|
|
var flavours = new FlavourSet();
|
|
|
|
flavours.appendFlavour(this.ACCOUNT_MIME_TYPE,
|
|
|
|
"nsIDOMXULSelectControlItemElement");
|
|
|
|
return flavours;
|
|
|
|
}
|
|
|
|
};
|