Bug 182953: Clean up IMAP prefs usage to use nsIPrefBranch and friends

r=timeless sr=bienvenu
This commit is contained in:
caillon%returnzero.com 2002-12-04 02:09:11 +00:00
parent 0f9a81eb48
commit 2b0254ddd4
5 changed files with 93 additions and 95 deletions

View File

@ -42,11 +42,10 @@
#include "nsHashtable.h"
#include "nsMimeTypes.h"
#include "nsIPref.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsITransport.h"
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
// need to talk to Rich about this...
#define IMAP_EXTERNAL_CONTENT_HEADER "X-Mozilla-IMAP-Part"
@ -78,14 +77,14 @@ static PRInt32 gMaxDepth = 0; // Maximum depth that we will descend before marki
nsIMAPBodyShell::nsIMAPBodyShell(nsImapProtocol *protocolConnection, const char *buf, PRUint32 UID, const char *folderName)
{
if (gMaxDepth == 0)
{
nsresult rv;
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &rv));
if (NS_SUCCEEDED(rv) && prefs)
// one-time initialization
prefs->GetIntPref("mail.imap.mime_parts_on_demand_max_depth", &gMaxDepth);
}
if (gMaxDepth == 0)
{
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefBranch) {
// one-time initialization
prefBranch->GetIntPref("mail.imap.mime_parts_on_demand_max_depth", &gMaxDepth);
}
}
m_isValid = PR_FALSE;
m_isBeingGenerated = PR_FALSE;

View File

@ -62,7 +62,8 @@
#include "nsVoidArray.h"
#include "nsCOMPtr.h"
#include "nsImapStringBundle.h"
#include "nsIPref.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsMsgFolderFlags.h"
#include "prmem.h"
#include "plstr.h"
@ -1455,14 +1456,14 @@ NS_IMETHODIMP nsImapIncomingServer::GetTrashFolderByRedirectorType(char **specia
if (NS_FAILED(rv))
return NS_OK; // return if no redirector type
nsCOMPtr <nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
rv = prefs->GetCharPref(prefName.get(), specialTrashName);
rv = prefBranch->GetCharPref(prefName.get(), specialTrashName);
if (NS_SUCCEEDED(rv) && ((!*specialTrashName) || (!**specialTrashName)))
return NS_ERROR_FAILURE;
else
return rv;
return rv;
}
NS_IMETHODIMP nsImapIncomingServer::AllowFolderConversion(PRBool *allowConversion)
@ -1480,11 +1481,11 @@ NS_IMETHODIMP nsImapIncomingServer::AllowFolderConversion(PRBool *allowConversio
if (NS_FAILED(rv))
return NS_OK; // return if no redirector type
nsCOMPtr <nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
// In case this pref is not set we need to return NS_OK.
rv = prefs->GetBoolPref(prefName.get(), allowConversion);
prefBranch->GetBoolPref(prefName.get(), allowConversion);
return NS_OK;
}
@ -1495,9 +1496,6 @@ NS_IMETHODIMP nsImapIncomingServer::ConvertFolderName(const char *originalName,
nsresult rv = NS_OK;
*convertedName = nsnull;
nsCOMPtr <nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
// See if the redirector type allows folder name conversion.
PRBool allowConversion;
rv = AllowFolderConversion(&allowConversion);
@ -1544,12 +1542,12 @@ NS_IMETHODIMP nsImapIncomingServer::HideFolderName(const char *folderName, PRBoo
if (NS_FAILED(rv))
return NS_OK; // return if no redirector type
nsCOMPtr <nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
prefName.Append(folderName);
// In case this pref is not set we need to return NS_OK.
prefs->GetBoolPref(prefName.get(), hideFolder);
prefBranch->GetBoolPref(prefName.get(), hideFolder);
return NS_OK;
}
@ -1876,13 +1874,14 @@ NS_IMETHODIMP nsImapIncomingServer::DiscoveryDone()
nsresult nsImapIncomingServer::DeleteNonVerifiedFolders(nsIFolder *curFolder)
{
PRBool autoUnsubscribeFromNoSelectFolders = PR_TRUE;
nsresult rv;
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if(NS_SUCCEEDED(rv))
{
rv = prefs->GetBoolPref("mail.imap.auto_unsubscribe_from_noselect_folders", &autoUnsubscribeFromNoSelectFolders);
}
PRBool autoUnsubscribeFromNoSelectFolders = PR_TRUE;
nsresult rv;
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
{
prefBranch->GetBoolPref("mail.imap.auto_unsubscribe_from_noselect_folders", &autoUnsubscribeFromNoSelectFolders);
}
// return rv;
nsCOMPtr<nsIEnumerator> subFolders;
@ -2448,11 +2447,7 @@ NS_IMETHODIMP nsImapIncomingServer::PromptForPassword(char ** aPassword,
nsresult rv = CreatePrefNameWithRedirectorType(".hide_hostname_for_password", prefName);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr <nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
PRBool hideHostnameForPassword = PR_FALSE;
@ -3332,9 +3327,9 @@ nsImapIncomingServer::GetSupportsDiskSpace(PRBool *aSupportsDiskSpace)
nsresult rv = CreateHostSpecificPrefName("default_supports_diskspace", prefName);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if(NS_SUCCEEDED(rv)) {
rv = prefs->GetBoolPref(prefName.get(), aSupportsDiskSpace);
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && prefBranch) {
rv = prefBranch->GetBoolPref(prefName.get(), aSupportsDiskSpace);
}
// Couldn't get the default value with the hostname.
@ -3416,9 +3411,9 @@ nsImapIncomingServer::GetOfflineSupportLevel(PRInt32 *aSupportLevel)
rv = CreateHostSpecificPrefName("default_offline_support_level", prefName);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if(NS_SUCCEEDED(rv)) {
rv = prefs->GetIntPref(prefName.get(), aSupportLevel);
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && prefBranch) {
rv = prefBranch->GetIntPref(prefName.get(), aSupportLevel);
}
// Couldn't get the pref value with the hostname.
@ -3551,7 +3546,7 @@ nsImapIncomingServer::GetPrefForServerAttribute(const char *prefSuffix, PRBool *
NS_ENSURE_ARG_POINTER(prefSuffix);
nsresult rv;
nsCAutoString prefName;
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
nsXPIDLCString serverKey;
rv = GetKey(getter_Copies(serverKey));
@ -3561,7 +3556,7 @@ nsImapIncomingServer::GetPrefForServerAttribute(const char *prefSuffix, PRBool *
nsMsgIncomingServer::getPrefName(serverKey,
prefSuffix,
prefName);
rv = prefs->GetBoolPref(prefName.get(), prefValue);
rv = prefBranch->GetBoolPref(prefName.get(), prefValue);
// If the server pref is not set in then look at the
// pref set with redirector type
@ -3573,8 +3568,8 @@ nsImapIncomingServer::GetPrefForServerAttribute(const char *prefSuffix, PRBool *
rv = CreatePrefNameWithRedirectorType(redirectorType.get(), prefName);
if(NS_SUCCEEDED(rv))
rv = prefs->GetBoolPref(prefName.get(), prefValue);
if (NS_SUCCEEDED(rv))
rv = prefBranch->GetBoolPref(prefName.get(), prefValue);
}
return rv;
@ -3703,10 +3698,10 @@ nsImapIncomingServer::GetShowAttachmentsInline(PRBool *aResult)
*aResult = PR_TRUE; // true per default
nsresult rv;
nsCOMPtr <nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
rv = prefs->GetBoolPref("mail.inline_attachments", aResult);
prefBranch->GetBoolPref("mail.inline_attachments", aResult);
return NS_OK; // In case this pref is not set we need to return NS_OK.
}

View File

@ -67,7 +67,8 @@
#include "nsImapStringBundle.h"
#include "nsIMsgFolderCacheElement.h"
#include "nsTextFormatter.h"
#include "nsIPref.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsMsgUtf7Utils.h"
#include "nsICacheSession.h"
#include "nsEscape.h"
@ -2125,9 +2126,9 @@ nsImapMailFolder::DeleteSubFolders(nsISupportsArray* folders, nsIMsgWindow *msgW
if (!canHaveSubFoldersOfTrash)
deleteNoTrash = PR_TRUE;
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv))
prefs->GetBoolPref("mailnews.confirm.moveFoldersToTrash", &confirmDeletion);
prefBranch->GetBoolPref("mailnews.confirm.moveFoldersToTrash", &confirmDeletion);
}
if (confirmDeletion || deleteNoTrash) //let us alert the user if we are deleting folder immediately
{
@ -2215,17 +2216,12 @@ NS_IMETHODIMP nsImapMailFolder::GetNewMessages(nsIMsgWindow *aWindow, nsIUrlList
// Check preferences to see if we should check all folders for new
// messages, or just the inbox and marked ones
PRBool checkAllFolders = PR_FALSE;
nsCOMPtr <nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && prefs)
{
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
PRBool checkAllFolders = PR_FALSE;
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && prefBranch) {
// This pref might not exist, which is OK. We'll only check inbox and marked ones
if (NS_SUCCEEDED(rv) && prefBranch)
rv = prefBranch->GetBoolPref("mail.check_all_imap_folders_for_new", &checkAllFolders);
rv = prefBranch->GetBoolPref("mail.check_all_imap_folders_for_new", &checkAllFolders);
}
m_urlListener = aListener;

View File

@ -97,7 +97,9 @@ PRLogModuleInfo *IMAP;
#include "nsIStreamListener.h"
#include "nsIMsgIncomingServer.h"
#include "nsIImapIncomingServer.h"
#include "nsIPref.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIPrefLocalizedString.h"
#include "nsImapUtils.h"
#include "nsIProxyObjectManager.h"
#include "nsIStreamConverterService.h"
@ -315,27 +317,33 @@ static PRBool gUseEnvelopeCmd = PR_FALSE;
nsresult nsImapProtocol::GlobalInitialization()
{
nsresult rv;
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv) && prefs)
{
prefs->GetIntPref("mail.imap.chunk_fast", &gTooFastTime); // secs we read too little too fast
prefs->GetIntPref("mail.imap.chunk_ideal", &gIdealTime); // secs we read enough in good time
prefs->GetIntPref("mail.imap.chunk_add", &gChunkAddSize); // buffer size to add when wasting time
prefs->GetIntPref("mail.imap.chunk_size", &gChunkSize);
prefs->GetIntPref("mail.imap.min_chunk_size_threshold", &gChunkThreshold);
prefs->GetIntPref("mail.imap.max_chunk_size", &gMaxChunkSize);
prefs->GetBoolPref("mail.imap.hide_other_users",
&gHideOtherUsersFromList);
prefs->GetBoolPref("mail.imap.hide_unused_namespaces",
&gHideUnusedNamespaces);
prefs->GetIntPref("mail.imap.noop_check_count", &gPromoteNoopToCheckCount);
prefs->GetBoolPref("mail.imap.use_envelope_cmd",
&gUseEnvelopeCmd);
prefs->GetLocalizedUnicharPref("intl.accept_languages", getter_Copies(mAcceptLanguages));
}
gInitialized = PR_TRUE;
return rv;
gInitialized = PR_TRUE;
nsresult rv;
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
prefBranch->GetIntPref("mail.imap.chunk_fast", &gTooFastTime); // secs we read too little too fast
prefBranch->GetIntPref("mail.imap.chunk_ideal", &gIdealTime); // secs we read enough in good time
prefBranch->GetIntPref("mail.imap.chunk_add", &gChunkAddSize); // buffer size to add when wasting time
prefBranch->GetIntPref("mail.imap.chunk_size", &gChunkSize);
prefBranch->GetIntPref("mail.imap.min_chunk_size_threshold", &gChunkThreshold);
prefBranch->GetIntPref("mail.imap.max_chunk_size", &gMaxChunkSize);
prefBranch->GetBoolPref("mail.imap.hide_other_users",
&gHideOtherUsersFromList);
prefBranch->GetBoolPref("mail.imap.hide_unused_namespaces",
&gHideUnusedNamespaces);
prefBranch->GetIntPref("mail.imap.noop_check_count", &gPromoteNoopToCheckCount);
prefBranch->GetBoolPref("mail.imap.use_envelope_cmd",
&gUseEnvelopeCmd);
nsCOMPtr<nsIPrefLocalizedString> prefString;
prefBranch->GetComplexValue("intl.accept_languages",
NS_GET_IID(nsIPrefLocalizedString),
getter_AddRefs(prefString));
if (prefString) {
prefString->ToString(getter_Copies(mAcceptLanguages));
}
return NS_OK;
}
nsImapProtocol::nsImapProtocol() :
@ -7103,9 +7111,9 @@ PRBool nsImapProtocol::TryToLogon()
PRBool lastReportingErrors = GetServerStateParser().GetReportingErrors();
GetServerStateParser().SetReportingErrors(PR_FALSE); // turn off errors - we'll put up our own.
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv) && prefs)
prefs->GetBoolPref("mail.auth_login", &prefBool);
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv) && prefBranch)
prefBranch->GetBoolPref("mail.auth_login", &prefBool);
if (prefBool)
{

View File

@ -63,7 +63,8 @@
#include "nsRDFCID.h"
#include "nsEscape.h"
#include "nsIMsgStatusFeedback.h"
#include "nsIPref.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsILoadGroup.h"
#include "nsIMsgAccountManager.h"
#include "nsMsgBaseCID.h"
@ -102,7 +103,6 @@
#define PREF_MAIL_ROOT_IMAP "mail.root.imap"
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID);
@ -133,11 +133,11 @@ nsImapService::nsImapService()
if (!gInitialized)
{
nsresult rv;
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &rv));
if (NS_SUCCEEDED(rv) && prefs)
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv) && prefBranch)
{
prefs->GetBoolPref("mail.imap.mime_parts_on_demand", &gMIMEOnDemand);
prefs->GetIntPref("mail.imap.mime_parts_on_demand_threshold", &gMIMEOnDemandThreshold);
prefBranch->GetBoolPref("mail.imap.mime_parts_on_demand", &gMIMEOnDemand);
prefBranch->GetIntPref("mail.imap.mime_parts_on_demand_threshold", &gMIMEOnDemandThreshold);
}
gInitialized = PR_TRUE;
}
@ -3462,11 +3462,10 @@ NS_IMETHODIMP
nsImapService::SetDefaultLocalPath(nsIFileSpec *aPath)
{
nsresult rv;
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &rv));
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if (NS_FAILED(rv)) return rv;
rv = prefs->SetFilePref(PREF_MAIL_ROOT_IMAP, aPath, PR_FALSE /* set default */);
return rv;
return prefBranch->SetComplexValue(PREF_MAIL_ROOT_IMAP, NS_GET_IID(nsIFileSpec), aPath);
}
NS_IMETHODIMP
@ -3476,13 +3475,14 @@ nsImapService::GetDefaultLocalPath(nsIFileSpec ** aResult)
*aResult = nsnull;
nsresult rv;
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &rv));
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if (NS_FAILED(rv)) return rv;
PRBool havePref = PR_FALSE;
nsCOMPtr<nsILocalFile> prefLocal;
nsCOMPtr<nsIFile> localFile;
rv = prefs->GetFileXPref(PREF_MAIL_ROOT_IMAP, getter_AddRefs(prefLocal));
rv = prefBranch->GetComplexValue(PREF_MAIL_ROOT_IMAP, NS_GET_IID(nsILocalFile),
getter_AddRefs(prefLocal));
if (NS_SUCCEEDED(rv)) {
localFile = prefLocal;
havePref = PR_TRUE;