147662 - adding option to remove free web mail in account manager - r=sspitzer, sr=bienvenu
git-svn-id: svn://10.0.0.236/trunk@122307 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -401,44 +401,55 @@ function onSetDefault(event) {
|
||||
}
|
||||
|
||||
function onRemoveAccount(event) {
|
||||
//dump("onRemoveAccount\n");
|
||||
//dump("onRemoveAccount\n");
|
||||
|
||||
if (event.target.getAttribute("disabled") == "true") return;
|
||||
if (event.target.getAttribute("disabled") == "true") return;
|
||||
|
||||
var result = getServerIdAndPageIdFromTree(accounttree);
|
||||
if (!result) return;
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
var account = getAccountFromServerId(result.serverId);
|
||||
if (!account) return;
|
||||
if (result.serverId == "http://home.netscape.com/NC-rdf#PageTitleFakeAccount") {
|
||||
nsPrefBranch.setBoolPref("mailnews.fakeaccount.show", false);
|
||||
|
||||
var server = account.incomingServer;
|
||||
var type = server.type;
|
||||
// select the default account
|
||||
selectServer(null, null);
|
||||
}
|
||||
|
||||
var protocolinfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + type].getService(Components.interfaces.nsIMsgProtocolInfo);
|
||||
var canDelete = protocolinfo.canDelete;
|
||||
if (!canDelete) {
|
||||
canDelete = server.canDelete;
|
||||
}
|
||||
if (!canDelete) return;
|
||||
var account = getAccountFromServerId(result.serverId);
|
||||
if (!account)
|
||||
return;
|
||||
|
||||
var confirmRemoveAccount =
|
||||
gPrefsBundle.getString("confirmRemoveAccount");
|
||||
if (!window.confirm(confirmRemoveAccount)) return;
|
||||
var server = account.incomingServer;
|
||||
var type = server.type;
|
||||
|
||||
try {
|
||||
// clear cached data out of the account array
|
||||
if (accountArray[result.serverId])
|
||||
accountArray[result.serverId] = null;
|
||||
currentServerId = currentPageId = null;
|
||||
var protocolinfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + type].getService(Components.interfaces.nsIMsgProtocolInfo);
|
||||
var canDelete = protocolinfo.canDelete;
|
||||
if (!canDelete) {
|
||||
canDelete = server.canDelete;
|
||||
}
|
||||
if (!canDelete)
|
||||
return;
|
||||
|
||||
accountManager.removeAccount(account);
|
||||
selectServer(null);
|
||||
}
|
||||
catch (ex) {
|
||||
dump("failure to remove account: " + ex + "\n");
|
||||
var alertText = gPrefsBundle.getString("failedRemoveAccount");
|
||||
window.alert(alertText);
|
||||
}
|
||||
var confirmRemoveAccount =
|
||||
gPrefsBundle.getString("confirmRemoveAccount");
|
||||
if (!window.confirm(confirmRemoveAccount))
|
||||
return;
|
||||
|
||||
try {
|
||||
// clear cached data out of the account array
|
||||
if (accountArray[result.serverId])
|
||||
accountArray[result.serverId] = null;
|
||||
currentServerId = currentPageId = null;
|
||||
|
||||
accountManager.removeAccount(account);
|
||||
selectServer(null, null);
|
||||
}
|
||||
catch (ex) {
|
||||
dump("failure to remove account: " + ex + "\n");
|
||||
var alertText = gPrefsBundle.getString("failedRemoveAccount");
|
||||
window.alert(alertText);
|
||||
}
|
||||
}
|
||||
|
||||
function saveAccount(accountValues, account)
|
||||
@@ -539,15 +550,15 @@ function updateButtons(tree,serverId) {
|
||||
//dump("account = " + account + "\n");
|
||||
|
||||
if (account) {
|
||||
var server = account.incomingServer;
|
||||
var type = server.type;
|
||||
var server = account.incomingServer;
|
||||
var type = server.type;
|
||||
|
||||
if (account.identities.Count() < 1)
|
||||
canSetDefault = false;
|
||||
|
||||
//dump("servertype = " + type + "\n");
|
||||
//dump("servertype = " + type + "\n");
|
||||
|
||||
var protocolinfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + type].getService(Components.interfaces.nsIMsgProtocolInfo);
|
||||
var protocolinfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + type].getService(Components.interfaces.nsIMsgProtocolInfo);
|
||||
canDuplicate = protocolinfo.canDuplicate;
|
||||
canDelete = protocolinfo.canDelete;
|
||||
if (!canDelete) {
|
||||
@@ -555,12 +566,13 @@ function updateButtons(tree,serverId) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
// HACK
|
||||
// if account is null, we have either selected a SMTP server, or there is a problem
|
||||
// either way, we don't want the user to be able to delete it or duplicate it
|
||||
// HACK
|
||||
// if account is null, we have either selected a SMTP server, or there is a problem
|
||||
// either way, we don't want the user to be able to delete it or duplicate it
|
||||
|
||||
canSetDefault = false;
|
||||
canDelete = false;
|
||||
canDuplicate = false;
|
||||
canDelete = (serverId == "http://home.netscape.com/NC-rdf#PageTitleFakeAccount");
|
||||
canDuplicate = false;
|
||||
}
|
||||
|
||||
if (tree.treeBoxObject.selection.count < 1)
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranchInternal.h"
|
||||
|
||||
// turn this on to see useful output
|
||||
#undef DEBUG_amds
|
||||
@@ -79,6 +80,8 @@
|
||||
|
||||
#define NC_RDF_ACCOUNTROOT "msgaccounts:/"
|
||||
|
||||
#define PREF_SHOW_FAKE_ACCOUNT "mailnews.fakeaccount.show"
|
||||
|
||||
typedef struct _serverCreationParams {
|
||||
nsISupportsArray *serverArray;
|
||||
nsIRDFService *rdfService;
|
||||
@@ -186,7 +189,18 @@ nsMsgAccountManagerDataSource::nsMsgAccountManagerDataSource()
|
||||
getRDFService()->GetResource(NC_RDF_SETTINGS, &kNC_Settings);
|
||||
|
||||
kDefaultServerAtom = NS_NewAtom("DefaultServer");
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrefBranchInternal> prefBranchInternal;
|
||||
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
|
||||
if (prefBranch) {
|
||||
prefBranchInternal = do_QueryInterface(prefBranch);
|
||||
prefBranchInternal->AddObserver(PREF_SHOW_FAKE_ACCOUNT, this, PR_FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsMsgAccountManagerDataSource::~nsMsgAccountManagerDataSource()
|
||||
@@ -331,14 +345,15 @@ nsMsgAccountManagerDataSource::GetTarget(nsIRDFResource *source,
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
|
||||
PRBool showFakeAccount;
|
||||
rv = prefBranch->GetBoolPref("mailnews.fakeaccount.show", &showFakeAccount);
|
||||
rv = prefBranch->GetBoolPref(PREF_SHOW_FAKE_ACCOUNT, &showFakeAccount);
|
||||
if (showFakeAccount) {
|
||||
nsCOMPtr<nsIStringBundleService> strBundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIStringBundle> bundle;
|
||||
rv = strBundleService->CreateBundle("chrome://messenger/locale/fakeAccount.properties",
|
||||
getter_AddRefs(mStringBundle));
|
||||
getter_AddRefs(bundle));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mStringBundle->GetStringFromName(NS_LITERAL_STRING("prefPanel-fake-account").get(),
|
||||
bundle->GetStringFromName(NS_LITERAL_STRING("prefPanel-fake-account").get(),
|
||||
getter_Copies(pageTitle));
|
||||
}
|
||||
}
|
||||
@@ -402,6 +417,8 @@ nsMsgAccountManagerDataSource::GetTarget(nsIRDFResource *source,
|
||||
str = NS_LITERAL_STRING("am-advanced.xul");
|
||||
else if (source == kNC_PageTitleSMTP)
|
||||
str = NS_LITERAL_STRING("am-smtp.xul");
|
||||
else if (source == kNC_PageTitleFakeAccount)
|
||||
str = NS_LITERAL_STRING("am-fakeaccount.xul");
|
||||
else {
|
||||
nsCOMPtr<nsIMsgFolder> folder = do_QueryInterface(source, &rv);
|
||||
if (NS_SUCCEEDED(rv) && folder) {
|
||||
@@ -609,6 +626,8 @@ nsMsgAccountManagerDataSource::createRootResources(nsIRDFResource *property,
|
||||
// for the "settings" arc, we also want to do an SMTP tag
|
||||
if (property == kNC_Settings) {
|
||||
aNodeArray->AppendElement(kNC_PageTitleSMTP);
|
||||
if (IsFakeAccountRequired())
|
||||
aNodeArray->AppendElement(kNC_PageTitleFakeAccount);
|
||||
}
|
||||
else if (property == kNC_Child && IsFakeAccountRequired()) {
|
||||
aNodeArray->AppendElement(kNC_PageTitleFakeAccount);
|
||||
@@ -1174,9 +1193,11 @@ nsMsgAccountManagerDataSource::OnServerLoaded(nsIMsgIncomingServer* aServer)
|
||||
PRBool fakeAccountServer;
|
||||
IsIncomingServerForFakeAccount(aServer, &fakeAccountServer);
|
||||
|
||||
if (fakeAccountServer)
|
||||
if (fakeAccountServer) {
|
||||
NotifyObservers(kNC_AccountRoot, kNC_Child, kNC_PageTitleFakeAccount, PR_FALSE, PR_FALSE);
|
||||
|
||||
NotifyObservers(kNC_AccountRoot, kNC_Settings, kNC_PageTitleFakeAccount, PR_FALSE, PR_FALSE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -1289,7 +1310,7 @@ nsMsgAccountManagerDataSource::IsFakeAccountRequired()
|
||||
rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
|
||||
|
||||
PRBool showFakeAccount;
|
||||
rv = prefBranch->GetBoolPref("mailnews.fakeaccount.show", &showFakeAccount);
|
||||
rv = prefBranch->GetBoolPref(PREF_SHOW_FAKE_ACCOUNT, &showFakeAccount);
|
||||
|
||||
if (!showFakeAccount)
|
||||
return PR_FALSE;
|
||||
@@ -1351,3 +1372,31 @@ nsMsgAccountManagerDataSource::GetFakeAccountHostName(char **aHostName)
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgAccountManagerDataSource::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
|
||||
{
|
||||
nsMsgRDFDataSource::Observe(aSubject, aTopic, aData);
|
||||
|
||||
if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
||||
nsDependentString prefName(aData);
|
||||
if (prefName.Equals(NS_LITERAL_STRING(PREF_SHOW_FAKE_ACCOUNT))) {
|
||||
NotifyObservers(kNC_AccountRoot, kNC_Child, kNC_PageTitleFakeAccount, PR_FALSE, PR_FALSE);
|
||||
NotifyObservers(kNC_AccountRoot, kNC_Settings, kNC_PageTitleFakeAccount, PR_FALSE, PR_FALSE);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||
nsCOMPtr<nsIPrefBranchInternal> prefBranchInternal;
|
||||
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
|
||||
if (prefBranch) {
|
||||
prefBranchInternal = do_QueryInterface(prefBranch);
|
||||
prefBranchInternal->RemoveObserver(PREF_SHOW_FAKE_ACCOUNT, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIFOLDERLISTENER
|
||||
NS_DECL_NSIINCOMINGSERVERLISTENER
|
||||
NS_DECL_NSIOBSERVER
|
||||
// RDF datasource methods
|
||||
|
||||
/* nsIRDFNode GetTarget (in nsIRDFResource aSource, in nsIRDFResource property, in boolean aTruthValue); */
|
||||
|
||||
@@ -323,8 +323,10 @@ nsMsgRDFDataSource::DoCommand(nsISupportsArray *aSources, nsIRDFResource *aComma
|
||||
NS_IMETHODIMP
|
||||
nsMsgRDFDataSource::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData )
|
||||
{
|
||||
m_shuttingDown = PR_TRUE;
|
||||
Cleanup();
|
||||
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||
m_shuttingDown = PR_TRUE;
|
||||
Cleanup();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user