From dc00b3cf664280feb7878e218551bf775c29bde3 Mon Sep 17 00:00:00 2001 From: "bienvenu%nventure.com" Date: Thu, 10 Jun 2004 14:04:32 +0000 Subject: [PATCH] add UI for global pop3 inbox in account wizard and account settings, r=mscott, sr=sspitzer, 243837 --- .../prefs/resources/content/AccountWizard.js | 48 +++++-- .../prefs/resources/content/AccountWizard.xul | 8 ++ .../resources/content/am-server-advanced.js | 131 ++++++++++++++++-- .../resources/content/am-server-advanced.xul | 36 +++++ .../base/prefs/resources/content/am-server.js | 22 ++- .../prefs/resources/content/am-server.xul | 11 ++ .../base/prefs/resources/content/aw-server.js | 12 ++ .../resources/locale/en-US/AccountWizard.dtd | 4 +- .../locale/en-US/am-server-advanced.dtd | 10 ++ .../resources/locale/en-US/prefs.properties | 3 + .../base/resources/content/folderPane.xul | 5 +- .../content/msgFolderPickerOverlay.xul | 25 ++++ .../locale/en-US/msgFolderPickerOverlay.dtd | 48 ------- mailnews/base/src/nsMsgAccount.cpp | 8 +- mailnews/base/src/nsMsgAccountManagerDS.cpp | 18 +-- mailnews/base/src/nsMsgFolderDataSource.cpp | 25 ++-- mailnews/base/src/nsMsgFolderDataSource.h | 7 +- mailnews/base/src/nsMsgRDFDataSource.cpp | 20 +-- mailnews/base/src/nsMsgRDFUtils.h | 3 +- mailnews/base/util/nsMsgDBFolder.cpp | 2 + mailnews/base/util/nsMsgDBFolder.h | 1 + mailnews/local/src/nsPop3IncomingServer.cpp | 98 ++++++++++++- mailnews/local/src/nsPop3IncomingServer.h | 1 + 23 files changed, 434 insertions(+), 112 deletions(-) diff --git a/mailnews/base/prefs/resources/content/AccountWizard.js b/mailnews/base/prefs/resources/content/AccountWizard.js index 3dce260fba6..fc6ff6693ab 100644 --- a/mailnews/base/prefs/resources/content/AccountWizard.js +++ b/mailnews/base/prefs/resources/content/AccountWizard.js @@ -208,6 +208,10 @@ function FinishAccount() accountData.smtpRequiresUsername = true; } + // we may need local folders before account is "Finished" + // if it's a pop3 account which defers to Local Folders. + verifyLocalFoldersAccount(gCurrentAccount); + PageDataToAccountData(pageData, accountData); FixupAccountDataForIsp(accountData); @@ -219,8 +223,6 @@ function FinishAccount() // transfer all attributes from the accountdata finishAccount(gCurrentAccount, accountData); - verifyLocalFoldersAccount(gCurrentAccount); - if (!serverIsNntp(pageData)) EnableCheckMailAtStartUpIfNeeded(gCurrentAccount); @@ -335,6 +337,8 @@ function PageDataToAccountData(pageData, accountData) accountData.incomingServer = new Object; if (!accountData.smtp) accountData.smtp = new Object; + if (!accountData.pop3) + accountData.pop3 = new Object; var identity = accountData.identity; var server = accountData.incomingServer; @@ -346,7 +350,19 @@ function PageDataToAccountData(pageData, accountData) server.type = getCurrentServerType(pageData); server.hostName = getCurrentHostname(pageData); - + if (getCurrentServerIsDeferred(pageData)) + { + try + { + var accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager); + var localFoldersServer = accountManager.localFoldersServer; + var localFoldersAccount = accountManager.FindAccountForServer(localFoldersServer); + accountData.pop3.deferredToAccount = localFoldersAccount.key; + accountData.pop3.deferGetNewMail = true; + server["ServerType-pop3"] = accountData.pop3; + } + catch (ex) {dump ("exception setting up deferred account" + ex);} + } if (serverIsNntp(pageData)) { // this stuff probably not relevant dump("not setting username/password/rememberpassword/etc\n"); @@ -409,7 +425,12 @@ function createAccount(accountData) dump("am.createAccount()\n"); var account = am.createAccount(); account.addIdentity(identity); + // we mark the server as invalid so that the account manager won't + // tell RDF about the new server - it's not quite finished getting + // set up yet, in particular, the deferred storage pref hasn't been set. + server.valid = false; account.incomingServer = server; + server.valid = true; return account; } @@ -440,6 +461,8 @@ function finishAccount(account, accountData) } } account.incomingServer.valid=true; + // hack to cause an account loaded notification now the server is valid + account.incomingServer = account.incomingServer; } // copy identity info @@ -556,16 +579,11 @@ function verifyLocalFoldersAccount(account) } try { - var server = account.incomingServer; - var identity = account.identities.QueryElementAt(0, Components.interfaces.nsIMsgIdentity); - - // for this server, do we default the folder prefs to this server, or to the "Local Folders" server - var defaultCopiesAndFoldersPrefsToServer = server.defaultCopiesAndFoldersPrefsToServer; if (!localMailServer) { // dump("Creating local mail account\n"); // creates a copy of the identity you pass in - messengerMigrator = Components.classes["@mozilla.org/messenger/migrator;1"].getService(Components.interfaces.nsIMessengerMigrator); + messengerMigrator = Components.classes["@mozilla.org/messenger/migrator;1"].getService(Components.interfaces.nsIMessengerMigrator); messengerMigrator.createLocalMailAccount(false /* false, since we are not migrating */); try { localMailServer = am.localFoldersServer; @@ -576,6 +594,11 @@ function verifyLocalFoldersAccount(account) } } + var server = account.incomingServer; + var identity = account.identities.QueryElementAt(0, Components.interfaces.nsIMsgIdentity); + // for this server, do we default the folder prefs to this server, or to the "Local Folders" server + var defaultCopiesAndFoldersPrefsToServer = server.defaultCopiesAndFoldersPrefsToServer; + var copiesAndFoldersServer = null; if (defaultCopiesAndFoldersPrefsToServer) { copiesAndFoldersServer = server; @@ -840,6 +863,13 @@ function getCurrentServerType(pageData) { return servertype; } +function getCurrentServerIsDeferred(pageData) { + var serverDeferred = false; + if (pageData.server && pageData.server.deferStorage) + serverDeferred = true; + return serverDeferred; +} + function getCurrentHostname(pageData) { if (serverIsNntp(pageData)) return pageData.newsserver.hostname.value; diff --git a/mailnews/base/prefs/resources/content/AccountWizard.xul b/mailnews/base/prefs/resources/content/AccountWizard.xul index 680d54ae936..9549ac177fd 100644 --- a/mailnews/base/prefs/resources/content/AccountWizard.xul +++ b/mailnews/base/prefs/resources/content/AccountWizard.xul @@ -160,6 +160,14 @@ accesskey="&incomingServerLabel.accesskey;" control="incomingServer"/> + + + + &deferStorageDesc.label; + + + diff --git a/mailnews/base/prefs/resources/content/am-server-advanced.js b/mailnews/base/prefs/resources/content/am-server-advanced.js index ae5a93a3f9b..22b63213599 100644 --- a/mailnews/base/prefs/resources/content/am-server-advanced.js +++ b/mailnews/base/prefs/resources/content/am-server-advanced.js @@ -21,6 +21,7 @@ * * Contributor(s): * Alec Flett + * David Bienvenu * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -37,11 +38,13 @@ * ***** END LICENSE BLOCK ***** */ // pull stuff out of window.arguments -var server = window.arguments[0]; +var gServerSettings = window.arguments[0]; var serverList; -// initialize the controls with the "server" argument +var gAccountManager; +var gFirstDeferredAccount; +// initialize the controls with the "gServerSettings" argument var gControls; function getControls() @@ -51,45 +54,149 @@ function getControls() return gControls; } +function getLocalFoldersAccount() +{ + var localFoldersServer = gAccountManager.localFoldersServer; + return gAccountManager.FindAccountForServer(localFoldersServer); +} + function onLoad() { - if (server.serverType == "imap") + if (gServerSettings.serverType == "imap") + { document.getElementById("tabbox").selectedTab = document.getElementById("imapTab"); + document.getElementById("pop3Tab").hidden = true; + // don't hide panel - it hides all subsequent panels + } + else if (gServerSettings.serverType == "pop3") + { + var radioGroup = document.getElementById("folderStorage"); + document.getElementById("tabbox").selectedTab = document.getElementById("pop3Tab"); + document.getElementById("imapTab").hidden = true; + // just hide the tab, don't hide panel - it hides all subsequent panels + gAccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager); + gFirstDeferredAccount = gServerSettings.deferredToAccount; + var localFoldersAccount = getLocalFoldersAccount(); + if (gFirstDeferredAccount.length) + { + var account = gAccountManager.getAccount(gFirstDeferredAccount); + if (account) + { + var thisServer = account.incomingServer; + SetFolderPicker(thisServer.serverURI, 'deferedServerFolderPicker'); + } + if (gFirstDeferredAccount == localFoldersAccount.key) + { + radioGroup.selectedItem = document.getElementById("globalInbox"); + SetFolderPicker(localFoldersAccount.incomingServer.serverURI, 'deferedServerFolderPicker'); + updateInboxAccount(false, true); + } + else + { + radioGroup.selectedItem = document.getElementById("deferToServer"); + SetFolderPicker(account.incomingServer.serverURI, 'deferedServerFolderPicker'); + updateInboxAccount(true, true); + } + } + else + { + radioGroup.selectedItem = document.getElementById("accountDirectory"); + + // we should find out if there's another pop3/movemail server to defer to, + // perhaps by checking the number of elements in the picker. For now, + // just use the local folders account + SetFolderPicker(localFoldersAccount.incomingServer.serverURI, 'deferedServerFolderPicker'); + + updateInboxAccount(false, false); + + } + } else { document.getElementById("imapTab").hidden = true; - document.getElementById("imapTabPanel").hidden = true; + document.getElementById("pop3Tab").hidden = true; } - var controls = getControls(); for (var i = 0; i < controls.length; i++) { var slot = controls[i].id; - if (slot in server) + if (slot in gServerSettings) { if (controls[i].localName == "checkbox") - controls[i].checked = server[slot]; + controls[i].checked = gServerSettings[slot]; else - controls[i].value = server[slot]; + controls[i].value = gServerSettings[slot]; } } } -// save the controls back to the "server" array +// save the controls back to the "gServerSettings" array function onOk() { var controls = getControls(); + radioGroup = document.getElementById("folderStorage"); + gPrefsBundle = document.getElementById("bundle_prefs"); + + // if this account wasn't deferred, and is now... + if (radioGroup.value != 1 && !gFirstDeferredAccount.length) + { + var confirmDeferAccount = + gPrefsBundle.getString("confirmDeferAccount"); + + var confirmTitle = gPrefsBundle.getString("confirmDeferAccountTitle"); + + var promptService = + Components.classes["@mozilla.org/embedcomp/prompt-service;1"]. + getService(Components.interfaces.nsIPromptService); + if (!promptService || + !promptService.confirm(window, confirmTitle, confirmDeferAccount)) + return; + } + switch (radioGroup.value) + { + case "0": + gServerSettings['deferredToAccount'] = getLocalFoldersAccount().key; + break; + case "1": + gServerSettings['deferredToAccount'] = ""; + break; + case "2": + picker = document.getElementById("deferedServerFolderPicker"); + var server = GetMsgFolderFromUri(picker.getAttribute("uri"), false).server; + var account = gAccountManager.FindAccountForServer(server); + gServerSettings['deferredToAccount'] = account.key; + break; + } + for (var i = 0; i < controls.length; i++) { var slot = controls[i].id; - if (slot in server) + if (slot in gServerSettings) { if (controls[i].localName == "checkbox") - server[slot] = controls[i].checked; + gServerSettings[slot] = controls[i].checked; else - server[slot] = controls[i].value; + gServerSettings[slot] = controls[i].value; } } } + + +// Set radio element choices and picker states +function updateInboxAccount(showPicker, showDeferGetNewMail, event) +{ + var picker = document.getElementById('deferedServerFolderPicker'); + if (showPicker) + { + picker.hidden = false; + picker.removeAttribute("disabled"); + } + else + { + picker.hidden = true; + } + var deferCheckbox = document.getElementById('deferGetNewMail'); + deferCheckbox.hidden = !showDeferGetNewMail; +} diff --git a/mailnews/base/prefs/resources/content/am-server-advanced.xul b/mailnews/base/prefs/resources/content/am-server-advanced.xul index 41cdaa5f4f5..29e9325caba 100644 --- a/mailnews/base/prefs/resources/content/am-server-advanced.xul +++ b/mailnews/base/prefs/resources/content/am-server-advanced.xul @@ -39,6 +39,8 @@ + +