From 57c9a2c3dabfbd5671433430fa47c245800b0146 Mon Sep 17 00:00:00 2001 From: "db48x%yahoo.com" Date: Sat, 15 Jan 2005 10:32:27 +0000 Subject: [PATCH] bug 226005: MailNews should use the newer nsIPrefService APIs instead of nsIPref patch by Mikael Parknert , r=niel, sr=darin --- .../addrbook/src/nsAbAddressCollecter.cpp | 37 +-- mailnews/addrbook/src/nsAbAddressCollecter.h | 6 +- .../addrbook/src/nsAbAutoCompleteSession.cpp | 29 +- .../addrbook/src/nsAbAutoCompleteSession.h | 6 +- mailnews/addrbook/src/nsAbLDAPDirectory.cpp | 14 +- .../base/search/src/nsMsgSearchAdapter.cpp | 44 +-- .../base/src/nsMessengerWinIntegration.cpp | 34 +-- mailnews/base/src/nsMessengerWinIntegration.h | 1 - mailnews/base/src/nsMsgContentPolicy.cpp | 45 ++- mailnews/base/src/nsStatusBarBiffManager.cpp | 5 +- mailnews/base/util/nsMsgUtils.cpp | 47 ++++ mailnews/base/util/nsMsgUtils.h | 11 + mailnews/compose/build/Makefile.in | 1 + mailnews/compose/src/nsMsgCompFields.cpp | 21 +- mailnews/compose/src/nsMsgCompUtils.cpp | 61 ++--- mailnews/compose/src/nsMsgCompose.cpp | 145 +++++----- mailnews/compose/src/nsMsgComposeService.cpp | 3 +- mailnews/compose/src/nsSmtpServer.cpp | 256 ++++++------------ mailnews/compose/src/nsSmtpServer.h | 11 +- mailnews/compose/src/nsSmtpService.cpp | 49 ++-- .../extensions/mdn/src/nsMsgMdnGenerator.cpp | 1 - .../extensions/palmsync/src/PalmSyncImp.cpp | 2 - .../import/eudora/src/nsEudoraCompose.cpp | 10 +- mailnews/import/oexpress/Makefile.in | 1 + .../import/outlook/src/nsOutlookCompose.cpp | 10 +- mailnews/import/text/src/nsTextImport.cpp | 13 +- mailnews/mapi/mapihook/src/msgMapiHook.cpp | 16 +- mailnews/mapi/mapihook/src/msgMapiSupport.cpp | 4 - mailnews/mime/src/comi18n.cpp | 33 +-- mailnews/mime/src/mimedrft.cpp | 37 ++- mailnews/mime/src/mimei.cpp | 22 +- mailnews/mime/src/mimemalt.cpp | 8 +- mailnews/mime/src/mimemoz2.cpp | 85 +++--- mailnews/mime/src/mimemoz2.h | 4 +- mailnews/mime/src/mimetext.cpp | 30 +- mailnews/mime/src/mimethsa.cpp | 9 +- mailnews/mime/src/mimetpfl.cpp | 16 +- mailnews/mime/src/mimetpla.cpp | 16 +- mailnews/mime/src/modlmime.h | 4 +- 39 files changed, 532 insertions(+), 615 deletions(-) diff --git a/mailnews/addrbook/src/nsAbAddressCollecter.cpp b/mailnews/addrbook/src/nsAbAddressCollecter.cpp index b9c6af29b96..f4e7e3a4bda 100644 --- a/mailnews/addrbook/src/nsAbAddressCollecter.cpp +++ b/mailnews/addrbook/src/nsAbAddressCollecter.cpp @@ -44,7 +44,8 @@ #include "nsIAbCard.h" #include "nsAbBaseCID.h" #include "nsAbAddressCollecter.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranchInternal.h" #include "nsIAddrBookSession.h" #include "nsIMsgHeaderParser.h" #include "nsIRDFService.h" @@ -54,7 +55,7 @@ #include "prmem.h" #include "nsIAddressBook.h" -NS_IMPL_ISUPPORTS1(nsAbAddressCollecter, nsIAbAddressCollecter) +NS_IMPL_ISUPPORTS2(nsAbAddressCollecter, nsIAbAddressCollecter, nsIObserver) #define PREF_MAIL_COLLECT_ADDRESSBOOK "mail.collect_addressbook" @@ -69,6 +70,11 @@ nsAbAddressCollecter::~nsAbAddressCollecter() m_database->Close(PR_FALSE); m_database = nsnull; } + + nsresult rv; + nsCOMPtr pPrefBranchInt(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + if(NS_SUCCEEDED(rv)) + pPrefBranchInt->RemoveObserver(PREF_MAIL_COLLECT_ADDRESSBOOK, this); } NS_IMETHODIMP nsAbAddressCollecter::CollectUnicodeAddress(const PRUnichar *aAddress, PRBool aCreateCard, PRUint32 aSendFormat) @@ -296,33 +302,30 @@ nsresult nsAbAddressCollecter::SplitFullName(const char *fullName, char **firstN return NS_OK; } -int PR_CALLBACK -nsAbAddressCollecter::collectAddressBookPrefChanged(const char *aNewpref, void *aData) +NS_IMETHODIMP nsAbAddressCollecter::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData) { - nsresult rv; - nsAbAddressCollecter *adCol = (nsAbAddressCollecter *) aData; - nsCOMPtr pPref = do_GetService(NS_PREF_CONTRACTID, &rv); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get prefs"); + nsCOMPtr pPrefBranchInt = do_QueryInterface(aSubject); + NS_ASSERTION(pPrefBranchInt, "failed to get prefs"); + nsresult rv; nsXPIDLCString prefVal; - rv = pPref->GetCharPref(PREF_MAIL_COLLECT_ADDRESSBOOK, getter_Copies(prefVal)); - rv = adCol->SetAbURI((NS_FAILED(rv) || prefVal.IsEmpty()) ? kPersonalAddressbookUri : prefVal.get()); + pPrefBranchInt->GetCharPref(PREF_MAIL_COLLECT_ADDRESSBOOK, getter_Copies(prefVal)); + rv = SetAbURI(prefVal.IsEmpty() ? kPersonalAddressbookUri : prefVal.get()); NS_ASSERTION(NS_SUCCEEDED(rv),"failed to change collected ab"); - return 0; + return NS_OK; } nsresult nsAbAddressCollecter::Init(void) { nsresult rv; - nsCOMPtr pPref = do_GetService(NS_PREF_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv,rv); - - rv = pPref->RegisterCallback(PREF_MAIL_COLLECT_ADDRESSBOOK, collectAddressBookPrefChanged, this); + nsCOMPtr pPrefBranchInt(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv,rv); + rv = pPrefBranchInt->AddObserver(PREF_MAIL_COLLECT_ADDRESSBOOK, this, PR_FALSE); + nsXPIDLCString prefVal; - rv = pPref->GetCharPref(PREF_MAIL_COLLECT_ADDRESSBOOK, getter_Copies(prefVal)); - rv = SetAbURI((NS_FAILED(rv) || prefVal.IsEmpty()) ? kPersonalAddressbookUri : prefVal.get()); + pPrefBranchInt->GetCharPref(PREF_MAIL_COLLECT_ADDRESSBOOK, getter_Copies(prefVal)); + rv = SetAbURI(prefVal.IsEmpty() ? kPersonalAddressbookUri : prefVal.get()); NS_ENSURE_SUCCESS(rv,rv); return NS_OK; } diff --git a/mailnews/addrbook/src/nsAbAddressCollecter.h b/mailnews/addrbook/src/nsAbAddressCollecter.h index 76eac5b1b50..e0356df97fb 100644 --- a/mailnews/addrbook/src/nsAbAddressCollecter.h +++ b/mailnews/addrbook/src/nsAbAddressCollecter.h @@ -44,8 +44,10 @@ #include "nsIAddrDatabase.h" #include "nsIAbDirectory.h" #include "nsIAbCard.h" +#include "nsIObserver.h" -class nsAbAddressCollecter : public nsIAbAddressCollecter +class nsAbAddressCollecter : public nsIAbAddressCollecter, + public nsIObserver { public: nsAbAddressCollecter(); @@ -53,11 +55,11 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIABADDRESSCOLLECTER + NS_DECL_NSIOBSERVER nsresult Init(); private: - static int PR_CALLBACK collectAddressBookPrefChanged(const char *newpref, void *data); nsresult AddCardToAddressBook(nsIAbCard *card); nsresult AutoCollectScreenName(nsIAbCard *aCard, const char *aEmail, PRBool *aModifiedCard); nsresult SetNamesForCard(nsIAbCard *senderCard, const char *fullName, PRBool *aModifiedCard); diff --git a/mailnews/addrbook/src/nsAbAutoCompleteSession.cpp b/mailnews/addrbook/src/nsAbAutoCompleteSession.cpp index 0dff05b568e..26bdec76fa6 100644 --- a/mailnews/addrbook/src/nsAbAutoCompleteSession.cpp +++ b/mailnews/addrbook/src/nsAbAutoCompleteSession.cpp @@ -52,7 +52,8 @@ #include "prmem.h" #include "nsNetCID.h" #include "nsIIOService.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" NS_IMPL_ISUPPORTS2(nsAbAutoCompleteSession, nsIAbAutoCompleteSession, nsIAutoCompleteSession) @@ -521,19 +522,8 @@ nsresult nsAbAutoCompleteSession::SearchCards(nsIAbDirectory* directory, nsAbAut return NS_OK; } -nsresult -nsAbAutoCompleteSession::NeedToSearchLocalDirectories(nsIPref *aPrefs, PRBool *aNeedToSearch) -{ - NS_ENSURE_ARG_POINTER(aPrefs); - NS_ENSURE_ARG_POINTER(aNeedToSearch); - - nsresult rv = aPrefs->GetBoolPref("mail.enable_autocomplete", aNeedToSearch); - NS_ENSURE_SUCCESS(rv,rv); - return NS_OK; -} - -nsresult -nsAbAutoCompleteSession::NeedToSearchReplicatedLDAPDirectories(nsIPref *aPrefs, PRBool *aNeedToSearch) +static nsresult +NeedToSearchReplicatedLDAPDirectories(nsIPrefBranch *aPrefs, PRBool *aNeedToSearch) { NS_ENSURE_ARG_POINTER(aPrefs); NS_ENSURE_ARG_POINTER(aNeedToSearch); @@ -556,12 +546,12 @@ nsAbAutoCompleteSession::NeedToSearchReplicatedLDAPDirectories(nsIPref *aPrefs, } nsresult -nsAbAutoCompleteSession::SearchReplicatedLDAPDirectories(nsIPref *aPref, nsAbAutoCompleteSearchString* searchStr, PRBool searchSubDirectory, nsIAutoCompleteResults* results) +nsAbAutoCompleteSession::SearchReplicatedLDAPDirectories(nsIPrefBranch *aPref, nsAbAutoCompleteSearchString* searchStr, PRBool searchSubDirectory, nsIAutoCompleteResults* results) { NS_ENSURE_ARG_POINTER(aPref); nsXPIDLCString prefName; - nsresult rv = aPref->CopyCharPref("ldap_2.autoComplete.directoryServer", getter_Copies(prefName)); + nsresult rv = aPref->GetCharPref("ldap_2.autoComplete.directoryServer", getter_Copies(prefName)); NS_ENSURE_SUCCESS(rv,rv); if (prefName.IsEmpty()) @@ -572,7 +562,7 @@ nsAbAutoCompleteSession::SearchReplicatedLDAPDirectories(nsIPref *aPref, nsAbAut fileNamePref = prefName + NS_LITERAL_CSTRING(".filename"); nsXPIDLCString fileName; - rv = aPref->CopyCharPref(fileNamePref.get(), getter_Copies(fileName)); + rv = aPref->GetCharPref(fileNamePref.get(), getter_Copies(fileName)); NS_ENSURE_SUCCESS(rv,rv); // if there is no fileName, bail out now. @@ -716,10 +706,11 @@ NS_IMETHODIMP nsAbAutoCompleteSession::OnStartLookup(const PRUnichar *uSearchStr PRBool enableLocalAutocomplete; PRBool enableReplicatedLDAPAutocomplete; - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); - rv = NeedToSearchLocalDirectories(prefs, &enableLocalAutocomplete); + // check if using autocomplete for local address books + rv = prefs->GetBoolPref("mail.enable_autocomplete", &enableLocalAutocomplete); NS_ENSURE_SUCCESS(rv,rv); rv = NeedToSearchReplicatedLDAPDirectories(prefs, &enableReplicatedLDAPAutocomplete); diff --git a/mailnews/addrbook/src/nsAbAutoCompleteSession.h b/mailnews/addrbook/src/nsAbAutoCompleteSession.h index 813983a773c..36bc710f972 100644 --- a/mailnews/addrbook/src/nsAbAutoCompleteSession.h +++ b/mailnews/addrbook/src/nsAbAutoCompleteSession.h @@ -45,7 +45,7 @@ #include "nsIAbDirectory.h" #include "nsIAbAutoCompleteSession.h" -class nsIPref; +class nsIPrefBranch; typedef struct { @@ -131,9 +131,7 @@ private: nsresult SearchDirectory(const nsACString& aURI, nsAbAutoCompleteSearchString* searchStr, PRBool searchSubDirectory, nsIAutoCompleteResults* results); nsresult SearchPreviousResults(nsAbAutoCompleteSearchString *uSearchString, nsIAutoCompleteResults *previousSearchResult, nsIAutoCompleteResults* results); - nsresult SearchReplicatedLDAPDirectories(nsIPref *aPrefs, nsAbAutoCompleteSearchString* searchStr, PRBool searchSubDirectory, nsIAutoCompleteResults* results); - nsresult NeedToSearchReplicatedLDAPDirectories(nsIPref *aPrefs, PRBool *aNeedToSearch); - nsresult NeedToSearchLocalDirectories(nsIPref *aPrefs, PRBool *aNeedToSearch); + nsresult SearchReplicatedLDAPDirectories(nsIPrefBranch *aPrefs, nsAbAutoCompleteSearchString* searchStr, PRBool searchSubDirectory, nsIAutoCompleteResults* results); }; diff --git a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp index 9d86b94049c..3e37ee8560e 100644 --- a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp +++ b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp @@ -52,9 +52,9 @@ #include "nsAutoLock.h" #include "nsNetCID.h" #include "nsIIOService.h" -#include "nsIPref.h" #include "nsXPCOM.h" #include "nsISupportsPrimitives.h" +#include "nsIPrefService.h" #include "nsIPrefBranch.h" #include "nsCOMArray.h" #include "nsArrayEnumerator.h" @@ -120,7 +120,7 @@ nsresult nsAbLDAPDirectory::InitiateConnection () mURL = do_CreateInstance(NS_LDAPURL_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); // use mURINoQuery to get a prefName @@ -129,7 +129,7 @@ nsresult nsAbLDAPDirectory::InitiateConnection () // turn moz-abldapdirectory://ldap_2.servers.nscpphonebook into -> "ldap_2.servers.nscpphonebook.uri" nsXPIDLCString URI; - rv = prefs->CopyCharPref(prefName.get(), getter_Copies(URI)); + rv = prefs->GetCharPref(prefName.get(), getter_Copies(URI)); if (NS_FAILED(rv)) { /* @@ -231,7 +231,7 @@ NS_IMETHODIMP nsAbLDAPDirectory::GetChildCards(nsIEnumerator** result) nsCOMPtr rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1",&rv); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); // use mURINoQuery to get a prefName @@ -239,7 +239,7 @@ NS_IMETHODIMP nsAbLDAPDirectory::GetChildCards(nsIEnumerator** result) prefName = nsDependentCString(mURINoQuery.get() + kLDAPDirectoryRootLen) + NS_LITERAL_CSTRING(".filename"); nsXPIDLCString fileName; - rv = prefs->CopyCharPref(prefName.get(), getter_Copies(fileName)); + rv = prefs->GetCharPref(prefName.get(), getter_Copies(fileName)); NS_ENSURE_SUCCESS(rv,rv); // if there is no fileName, bail out now. @@ -374,7 +374,7 @@ NS_IMETHODIMP nsAbLDAPDirectory::StartSearch () new nsAbDirSearchListener (this); queryListener = _queryListener; - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); // use mURINoQuery to get a prefName @@ -480,7 +480,7 @@ NS_IMETHODIMP nsAbLDAPDirectory::GetIsSecure(PRBool *aIsSecure) NS_ENSURE_ARG_POINTER(aIsSecure); nsresult rv; - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); // use mURINoQuery to get a prefName diff --git a/mailnews/base/search/src/nsMsgSearchAdapter.cpp b/mailnews/base/search/src/nsMsgSearchAdapter.cpp index 22ff418f20a..4d40220334c 100644 --- a/mailnews/base/search/src/nsMsgSearchAdapter.cpp +++ b/mailnews/base/search/src/nsMsgSearchAdapter.cpp @@ -41,7 +41,9 @@ #include "nsMsgSearchAdapter.h" #include "nsMsgSearchScopeTerm.h" #include "nsMsgI18N.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" +#include "nsIPrefLocalizedString.h" #include "nsXPIDLString.h" #include "nsReadableUtils.h" #include "nsMsgSearchTerm.h" @@ -326,22 +328,27 @@ nsresult nsMsgSearchAdapter::GetSearchCharsets(PRUnichar **srcCharset, PRUnichar **dstCharset) { nsresult rv; + nsAutoString destination; NS_ENSURE_ARG(srcCharset); NS_ENSURE_ARG(dstCharset); if (m_defaultCharset.IsEmpty()) { m_forceAsciiSearch = PR_FALSE; // set the default value in case of error - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { - rv = prefs->GetLocalizedUnicharPref("mailnews.view_default_charset", getter_Copies(m_defaultCharset)); - rv = prefs->GetBoolPref("mailnews.force_ascii_search", &m_forceAsciiSearch); + nsCOMPtr localizedstr; + rv = prefs->GetComplexValue("mailnews.view_default_charset", NS_GET_IID(nsIPrefLocalizedString), + getter_AddRefs(localizedstr)); + if (NS_SUCCEEDED(rv)) + localizedstr->GetData(getter_Copies(m_defaultCharset)); + + prefs->GetBoolPref("mailnews.force_ascii_search", &m_forceAsciiSearch); } } - *srcCharset = nsCRT::strdup(m_defaultCharset.IsEmpty() ? - NS_LITERAL_STRING("ISO-8859-1").get() : m_defaultCharset.get()); - *dstCharset = nsCRT::strdup(*srcCharset); + *srcCharset = m_defaultCharset.IsEmpty() ? + ToNewUnicode(NS_LITERAL_STRING("ISO-8859-1")) : ToNewUnicode(m_defaultCharset); if (m_scope) { @@ -355,10 +362,13 @@ nsMsgSearchAdapter::GetSearchCharsets(PRUnichar **srcCharset, PRUnichar **dstCha { nsXPIDLCString folderCharset; folder->GetCharset(getter_Copies(folderCharset)); - PR_Free(*dstCharset); - *dstCharset = ToNewUnicode(folderCharset); + AppendASCIItoUTF16(folderCharset, destination); } } + else + { + destination.Assign(*srcCharset); + } // If @@ -366,10 +376,9 @@ nsMsgSearchAdapter::GetSearchCharsets(PRUnichar **srcCharset, PRUnichar **dstCha // the source. (CS_DEFAULT is an indication that the charset // was undefined or unavailable.) // ### well, it's not really anymore. Is there an equivalent? - if (!nsCRT::strcmp(*dstCharset, m_defaultCharset.get())) + if (destination.Equals(m_defaultCharset)) { - PR_Free(*dstCharset); - *dstCharset = nsCRT::strdup(*srcCharset); + destination.Assign(*srcCharset); } if (m_forceAsciiSearch) @@ -381,9 +390,10 @@ nsMsgSearchAdapter::GetSearchCharsets(PRUnichar **srcCharset, PRUnichar **dstCha // If the dest csid is ISO Latin 1 or MacRoman, attempt to convert the // source text to US-ASCII. (Not for now.) // if ((dst_csid == CS_LATIN1) || (dst_csid == CS_MAC_ROMAN)) - PR_Free(*dstCharset); - *dstCharset = nsCRT::strdup(NS_LITERAL_STRING("us-ascii").get()); + destination.AssignLiteral("us-ascii"); } + + *dstCharset = ToNewUnicode(destination); return NS_OK; } @@ -1084,12 +1094,12 @@ NS_IMETHODIMP nsMsgSearchValidityManager::GetTable (int whichTable, nsIMsgSearch { NS_ENSURE_ARG_POINTER(ppOutTable); - nsresult rv = NS_OK; + nsresult rv; *ppOutTable = nsnull; - nsCOMPtr pref = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr pref(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); nsXPIDLCString customHeaders; - if (NS_SUCCEEDED(rv) && pref) + if (NS_SUCCEEDED(rv)) pref->GetCharPref(PREF_CUSTOM_HEADERS, getter_Copies(customHeaders)); switch (whichTable) diff --git a/mailnews/base/src/nsMessengerWinIntegration.cpp b/mailnews/base/src/nsMessengerWinIntegration.cpp index 8282fbfa145..f52ef211a68 100644 --- a/mailnews/base/src/nsMessengerWinIntegration.cpp +++ b/mailnews/base/src/nsMessengerWinIntegration.cpp @@ -68,6 +68,9 @@ #include "nsIWeakReference.h" #include "nsIStringBundle.h" #include "nsIAlertsService.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" +#include "nsISupportsPrimitives.h" #ifdef MOZ_THUNDERBIRD #define PROFILE_COMMANDLINE_ARG " -profile " @@ -328,13 +331,12 @@ nsMessengerWinIntegration::Init() nsresult rv; // get pref service - nsCOMPtr prefService; - prefService = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv,rv); // first check the timer value - PRInt32 timerInterval; - prefService->GetIntPref(TIMER_INTERVAL_PREF, &timerInterval); + PRInt32 timerInterval = 0; + prefBranch->GetIntPref(TIMER_INTERVAL_PREF, &timerInterval); // return if the timer value is negative or ZERO if (timerInterval > 0) @@ -472,12 +474,11 @@ nsresult nsMessengerWinIntegration::ShowAlertMessage(const PRUnichar * aAlertTit if (mAlertInProgress) return NS_OK; - nsCOMPtr prefService; - prefService = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); PRBool showAlert = PR_TRUE; - if (prefService) - prefService->GetBoolPref(SHOW_ALERT_PREF, &showAlert); + if (prefBranch) + prefBranch->GetBoolPref(SHOW_ALERT_PREF, &showAlert); if (showAlert) { @@ -1032,19 +1033,20 @@ nsMessengerWinIntegration::SetupInbox() providerPrefixPref.Append(".unreadMailCountRegistryKeyPrefix"); // get pref service - nsCOMPtr prefService; - prefService = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv,rv); - nsXPIDLString prefixValue; - prefService->CopyUnicharPref(providerPrefixPref.get(), getter_Copies(prefixValue)); - if (prefixValue.get()) - mEmailPrefix.Assign(prefixValue); + nsCOMPtr tmp; + rv = prefBranch->GetComplexValue(providerPrefixPref.get(), NS_GET_IID(nsISupportsString), + getter_AddRefs(tmp)); + + if (NS_SUCCEEDED(rv)) + tmp->GetData(mEmailPrefix); else - mEmailPrefix.Truncate(0); + mEmailPrefix.Truncate(); } else { - mEmailPrefix.Truncate(0); + mEmailPrefix.Truncate(); } // Get user's email address diff --git a/mailnews/base/src/nsMessengerWinIntegration.h b/mailnews/base/src/nsMessengerWinIntegration.h index 85881891400..cad34fd443d 100644 --- a/mailnews/base/src/nsMessengerWinIntegration.h +++ b/mailnews/base/src/nsMessengerWinIntegration.h @@ -53,7 +53,6 @@ #include "nsITimer.h" #include "nsCOMPtr.h" #include "nsString.h" -#include "nsIPref.h" #include "nsInt64.h" #include "nsISupportsArray.h" #include "nsIObserver.h" diff --git a/mailnews/base/src/nsMsgContentPolicy.cpp b/mailnews/base/src/nsMsgContentPolicy.cpp index 41226b6aaa8..933468e36cf 100644 --- a/mailnews/base/src/nsMsgContentPolicy.cpp +++ b/mailnews/base/src/nsMsgContentPolicy.cpp @@ -39,7 +39,6 @@ #include "nsMsgContentPolicy.h" #include "nsIServiceManager.h" #include "nsIPrefService.h" -#include "nsIPrefBranch.h" #include "nsIPrefBranchInternal.h" #include "nsIURI.h" #include "nsCOMPtr.h" @@ -96,18 +95,14 @@ nsMsgContentPolicy::nsMsgContentPolicy() nsMsgContentPolicy::~nsMsgContentPolicy() { // hey, we are going away...clean up after ourself....unregister our observer - nsresult rv = NS_OK; - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + nsresult rv; + nsCOMPtr prefInternal = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { - nsCOMPtr prefInternal = do_QueryInterface(prefBranch, &rv); - if (NS_SUCCEEDED(rv)) - { - prefInternal->RemoveObserver(kBlockRemoteImages, this); - prefInternal->RemoveObserver(kRemoteImagesUseWhiteList, this); - prefInternal->RemoveObserver(kRemoteImagesWhiteListURI, this); - prefInternal->RemoveObserver(kAllowPlugins, this); - } + prefInternal->RemoveObserver(kBlockRemoteImages, this); + prefInternal->RemoveObserver(kRemoteImagesUseWhiteList, this); + prefInternal->RemoveObserver(kRemoteImagesWhiteListURI, this); + prefInternal->RemoveObserver(kAllowPlugins, this); } } @@ -116,20 +111,18 @@ nsresult nsMsgContentPolicy::Init() nsresult rv; // register ourself as an observer on the mail preference to block remote images - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + nsCOMPtr prefInternal = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr prefInternal = do_QueryInterface(prefBranch, &rv); - NS_ENSURE_SUCCESS(rv, rv); prefInternal->AddObserver(kBlockRemoteImages, this, PR_TRUE); prefInternal->AddObserver(kRemoteImagesUseWhiteList, this, PR_TRUE); prefInternal->AddObserver(kRemoteImagesWhiteListURI, this, PR_TRUE); prefInternal->AddObserver(kAllowPlugins, this, PR_TRUE); - prefBranch->GetBoolPref(kAllowPlugins, &mAllowPlugins); - prefBranch->GetBoolPref(kRemoteImagesUseWhiteList, &mUseRemoteImageWhiteList); - prefBranch->GetCharPref(kRemoteImagesWhiteListURI, getter_Copies(mRemoteImageWhiteListURI)); - return prefBranch->GetBoolPref(kBlockRemoteImages, &mBlockRemoteImages); + prefInternal->GetBoolPref(kAllowPlugins, &mAllowPlugins); + prefInternal->GetBoolPref(kRemoteImagesUseWhiteList, &mUseRemoteImageWhiteList); + prefInternal->GetCharPref(kRemoteImagesWhiteListURI, getter_Copies(mRemoteImageWhiteListURI)); + return prefInternal->GetBoolPref(kBlockRemoteImages, &mBlockRemoteImages); } nsresult nsMsgContentPolicy::IsSenderInWhiteList(nsIMsgDBHdr * aMsgHdr, PRBool * aWhiteListed) @@ -299,21 +292,21 @@ nsMsgContentPolicy::ShouldProcess(PRUint32 aContentType, NS_IMETHODIMP nsMsgContentPolicy::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData) { - nsresult rv; - if (!nsCRT::strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic)) { - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - NS_LossyConvertUCS2toASCII pref(aData); + nsresult rv; + + nsCOMPtr prefBranchInt = do_QueryInterface(aSubject, &rv); + NS_ENSURE_SUCCESS(rv, rv); + if (pref.Equals(kBlockRemoteImages)) - rv = prefBranch->GetBoolPref(kBlockRemoteImages, &mBlockRemoteImages); + prefBranchInt->GetBoolPref(kBlockRemoteImages, &mBlockRemoteImages); else if (pref.Equals(kRemoteImagesUseWhiteList)) - prefBranch->GetBoolPref(kRemoteImagesUseWhiteList, &mUseRemoteImageWhiteList); + prefBranchInt->GetBoolPref(kRemoteImagesUseWhiteList, &mUseRemoteImageWhiteList); else if (pref.Equals(kRemoteImagesWhiteListURI)) - prefBranch->GetCharPref(kRemoteImagesWhiteListURI, getter_Copies(mRemoteImageWhiteListURI)); + prefBranchInt->GetCharPref(kRemoteImagesWhiteListURI, getter_Copies(mRemoteImageWhiteListURI)); } return NS_OK; diff --git a/mailnews/base/src/nsStatusBarBiffManager.cpp b/mailnews/base/src/nsStatusBarBiffManager.cpp index a9ca65cdf1c..dbca249a63a 100644 --- a/mailnews/base/src/nsStatusBarBiffManager.cpp +++ b/mailnews/base/src/nsStatusBarBiffManager.cpp @@ -52,7 +52,8 @@ #include "MailNewsTypes.h" #include "nsIMsgFolder.h" // TO include biffState enum. Change to bool later... #include "nsIFileChannel.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsXPIDLString.h" #include "nsIURL.h" #include "nsNetUtil.h" @@ -103,7 +104,7 @@ nsresult nsStatusBarBiffManager::Init() nsresult nsStatusBarBiffManager::PlayBiffSound() { nsresult rv; - nsCOMPtr pref = do_GetService(NS_PREF_CONTRACTID, &rv); + nsCOMPtr pref(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv,rv); PRBool playSoundOnBiff = PR_FALSE; diff --git a/mailnews/base/util/nsMsgUtils.cpp b/mailnews/base/util/nsMsgUtils.cpp index d43eb2622e1..da4dd7d0c38 100644 --- a/mailnews/base/util/nsMsgUtils.cpp +++ b/mailnews/base/util/nsMsgUtils.cpp @@ -60,6 +60,9 @@ #include "nsIMimeConverter.h" #include "nsMsgMimeCID.h" #include "nsIPrefService.h" +#include "nsIPrefBranch.h" +#include "nsISupportsPrimitives.h" +#include "nsIPrefLocalizedString.h" #include "nsIRelativeFilePref.h" #include "nsAppDirectoryServiceDefs.h" #include "nsICategoryManager.h" @@ -1029,3 +1032,47 @@ NS_MSG_BASE nsresult NS_SetPersistentFile(const char *relPrefName, return rv; } +NS_MSG_BASE nsresult NS_GetUnicharPreferenceWithDefault(nsIPrefBranch *prefBranch, //can be null, if so uses the root branch + const char *prefName, + const nsString& defValue, + nsString& prefValue) +{ + NS_ENSURE_ARG(prefName); + + nsCOMPtr pbr; + if(!prefBranch) { + pbr = do_GetService(NS_PREFSERVICE_CONTRACTID); + prefBranch = pbr; + } + nsCOMPtr str; + + nsresult rv = prefBranch->GetComplexValue(prefName, NS_GET_IID(nsISupportsString), getter_AddRefs(str)); + if (NS_SUCCEEDED(rv)) + return str->GetData(prefValue); + + prefValue = defValue; + return NS_OK; +} + +NS_MSG_BASE nsresult NS_GetLocalizedUnicharPreferenceWithDefault(nsIPrefBranch *prefBranch, //can be null, if so uses the root branch + const char *prefName, + const nsString& defValue, + nsXPIDLString& prefValue) +{ + NS_ENSURE_ARG(prefName); + + nsCOMPtr pbr; + if(!prefBranch) { + pbr = do_GetService(NS_PREFSERVICE_CONTRACTID); + prefBranch = pbr; + } + + nsCOMPtr str; + + nsresult rv = prefBranch->GetComplexValue(prefName, NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(str)); + if (NS_SUCCEEDED(rv)) + str->ToString(getter_Copies(prefValue)); + else + prefValue = defValue; + return NS_OK; +} diff --git a/mailnews/base/util/nsMsgUtils.h b/mailnews/base/util/nsMsgUtils.h index 53b6a0c335a..8f62dd029f6 100644 --- a/mailnews/base/util/nsMsgUtils.h +++ b/mailnews/base/util/nsMsgUtils.h @@ -47,6 +47,7 @@ #include "nsCOMPtr.h" class nsILocalFile; +class nsIPrefBranch; //These are utility functions that can used throughout the mailnews code @@ -100,6 +101,16 @@ NS_MSG_BASE nsresult CreateServicesForPasswordManager(); NS_MSG_BASE nsresult IsRFC822HeaderFieldName(const char *aHdr, PRBool *aResult); +NS_MSG_BASE nsresult NS_GetUnicharPreferenceWithDefault(nsIPrefBranch *prefBranch, //can be null, if so uses the root branch + const char *prefName, + const nsString& defValue, + nsString& prefValue); + +NS_MSG_BASE nsresult NS_GetLocalizedUnicharPreferenceWithDefault(nsIPrefBranch *prefBranch, //can be null, if so uses the root branch + const char *prefName, + const nsString& defValue, + nsXPIDLString& prefValue); + /** * this needs a listener, because we might have to create the folder * on the server, and that is asynchronous diff --git a/mailnews/compose/build/Makefile.in b/mailnews/compose/build/Makefile.in index 2dc253b4ad5..cb41defe305 100644 --- a/mailnews/compose/build/Makefile.in +++ b/mailnews/compose/build/Makefile.in @@ -70,6 +70,7 @@ REQUIRES = xpcom \ intl \ uconv \ mailnews \ + pref \ widget \ msgdb \ appshell \ diff --git a/mailnews/compose/src/nsMsgCompFields.cpp b/mailnews/compose/src/nsMsgCompFields.cpp index 4021df254b0..43d0b849f51 100644 --- a/mailnews/compose/src/nsMsgCompFields.cpp +++ b/mailnews/compose/src/nsMsgCompFields.cpp @@ -38,12 +38,12 @@ #include "nsMsgCompFields.h" #include "nsCRT.h" -#include "nsIPref.h" #include "nsMsgI18N.h" #include "nsMsgComposeStringBundle.h" #include "nsMsgRecipientArray.h" #include "nsIMsgHeaderParser.h" #include "nsMsgCompUtils.h" +#include "nsMsgUtils.h" #include "prmem.h" #include "nsIFileChannel.h" #include "nsReadableUtils.h" @@ -70,18 +70,13 @@ nsMsgCompFields::nsMsgCompFields() m_receiptHeaderType = nsIMsgMdnGenerator::eDntType; m_bodyIsAsciiOnly = PR_FALSE; - nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); - if (prefs) - { - // Get the default charset from pref, use this as a mail charset. - nsXPIDLString charset; - prefs->GetLocalizedUnicharPref("mailnews.send_default_charset", getter_Copies(charset)); - if (charset.IsEmpty()) - m_DefaultCharacterSet.Assign("ISO-8859-1"); - else - LossyCopyUTF16toASCII(charset, m_DefaultCharacterSet); // Charsets better be ASCII - SetCharacterSet(m_DefaultCharacterSet.get()); - } + // Get the default charset from pref, use this as a mail charset. + nsXPIDLString charset; + NS_GetLocalizedUnicharPreferenceWithDefault(nsnull, "mailnews.send_default_charset", + NS_LITERAL_STRING("ISO-8859-1"), charset); + + LossyCopyUTF16toASCII(charset, m_DefaultCharacterSet); // Charsets better be ASCII + SetCharacterSet(m_DefaultCharacterSet.get()); } nsMsgCompFields::~nsMsgCompFields() diff --git a/mailnews/compose/src/nsMsgCompUtils.cpp b/mailnews/compose/src/nsMsgCompUtils.cpp index 18e09e7b213..8612f5caf1d 100644 --- a/mailnews/compose/src/nsMsgCompUtils.cpp +++ b/mailnews/compose/src/nsMsgCompUtils.cpp @@ -37,8 +37,8 @@ #include "nsCOMPtr.h" #include "nsCRT.h" #include "nsMsgCompUtils.h" -#include "nsIPref.h" #include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "prmem.h" #include "nsEscape.h" #include "nsIFileSpec.h" @@ -64,7 +64,6 @@ #include "nsIMsgCompUtils.h" #include "nsIMsgMdnGenerator.h" -static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_CID(kHTTPHandlerCID, NS_HTTPPROTOCOLHANDLER_CID); @@ -172,9 +171,9 @@ nsMsgMIMESetConformToStandard (PRBool conform_p) mime_headers_use_quoted_printable_p = PR_TRUE; else { nsresult rv; - nsCOMPtr prefs(do_GetService(kPrefCID, &rv)); - if (NS_SUCCEEDED(rv) && prefs) { - rv = prefs->GetBoolPref("mail.strictly_mime_headers", &mime_headers_use_quoted_printable_p); + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv)) { + prefs->GetBoolPref("mail.strictly_mime_headers", &mime_headers_use_quoted_printable_p); } } } @@ -280,9 +279,9 @@ mime_generate_headers (nsMsgCompFields *fields, nsresult rv; *status = 0; - nsCOMPtr prefs(do_GetService(kPrefCID, &rv)); + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) { - *status = rv; + *status = rv; return nsnull; } @@ -1622,8 +1621,6 @@ msg_make_filename_qtext(const char *srcText, PRBool stripCRLFs) void msg_pick_real_name (nsMsgAttachmentHandler *attachment, const PRUnichar *proposedName, const char *charset) { - nsresult rv; - nsCOMPtr prefs(do_GetService(kPrefCID, &rv)); const char *s, *s2; char *s3; @@ -1670,7 +1667,10 @@ msg_pick_real_name (nsMsgAttachmentHandler *attachment, const PRUnichar *propose } PRInt32 parmFolding = 0; - if (NS_SUCCEEDED(rv) && prefs) + nsresult rv; + + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv)) prefs->GetIntPref("mail.strictly_mime.parm_folding", &parmFolding); if (parmFolding == 0 || parmFolding == 1) @@ -1965,10 +1965,10 @@ GetFolderURIFromUserPrefs(nsMsgDeliverMode aMode, nsIMsgIdentity* identity) if (aMode == nsIMsgSend::nsMsgQueueForLater) // QueueForLater (Outbox) { - nsCOMPtr prefs(do_GetService(kPrefCID, &rv)); - if (NS_FAILED(rv) || !prefs) + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + if (NS_FAILED(rv)) return nsnull; - rv = prefs->CopyCharPref("mail.default_sendlater_uri", &uri); + rv = prefs->GetCharPref("mail.default_sendlater_uri", &uri); if (NS_FAILED(rv) || !uri) { uri = PR_smprintf("%s", ANY_SERVER); @@ -2132,31 +2132,22 @@ PRBool UseFormatFlowed(const char *charset) PRBool disableForCertainCharsets = PR_TRUE; nsresult rv; - nsCOMPtr prefs(do_GetService(kPrefCID, &rv)); + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return PR_FALSE; - if(prefs) - { - - rv = prefs->GetBoolPref("mailnews.send_plaintext_flowed", &sendFlowed); - if (NS_SUCCEEDED(rv) && !sendFlowed) - return PR_FALSE; - - // If we shouldn't care about charset, then we are finished - // checking and can go on using format=flowed - if(!charset) - return PR_TRUE; - rv = prefs->GetBoolPref("mailnews.disable_format_flowed_for_cjk", - &disableForCertainCharsets); - if (NS_SUCCEEDED(rv) && !disableForCertainCharsets) - return PR_TRUE; - } - else - { - // No prefs service. Be careful. Don't use format=flowed. + rv = prefs->GetBoolPref("mailnews.send_plaintext_flowed", &sendFlowed); + if (NS_SUCCEEDED(rv) && !sendFlowed) return PR_FALSE; - } + + // If we shouldn't care about charset, then we are finished + // checking and can go on using format=flowed + if(!charset) + return PR_TRUE; + rv = prefs->GetBoolPref("mailnews.disable_format_flowed_for_cjk", + &disableForCertainCharsets); + if (NS_SUCCEEDED(rv) && !disableForCertainCharsets) + return PR_TRUE; // Just the check for charset left. @@ -2171,6 +2162,4 @@ PRBool UseFormatFlowed(const char *charset) return PR_FALSE; return PR_TRUE; - } - diff --git a/mailnews/compose/src/nsMsgCompose.cpp b/mailnews/compose/src/nsMsgCompose.cpp index c3a84691a3b..5a04d628a10 100644 --- a/mailnews/compose/src/nsMsgCompose.cpp +++ b/mailnews/compose/src/nsMsgCompose.cpp @@ -56,7 +56,8 @@ #include "nsICharsetConverterManager.h" #include "nsMsgCompCID.h" #include "nsMsgQuote.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsIDocumentEncoder.h" // for editor output flags #include "nsXPIDLString.h" #include "nsIMsgHeaderParser.h" @@ -123,47 +124,28 @@ // Defines.... static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID); -static nsresult GetReplyHeaderInfo(PRInt32* reply_header_type, - PRUnichar** reply_header_locale, - PRUnichar** reply_header_authorwrote, - PRUnichar** reply_header_ondate, - PRUnichar** reply_header_separator, - PRUnichar** reply_header_colon, - PRUnichar** reply_header_originalmessage) +static void GetReplyHeaderInfo(PRInt32* reply_header_type, + nsString& reply_header_locale, + nsXPIDLString& reply_header_authorwrote, + nsXPIDLString& reply_header_ondate, + nsString& reply_header_separator, + nsString& reply_header_colon, + nsXPIDLString& reply_header_originalmessage) { - nsresult rv = NS_ERROR_FAILURE; - - nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); - if (prefs) { - rv = prefs->GetIntPref("mailnews.reply_header_type", reply_header_type); - if (NS_FAILED(rv)) - *reply_header_type = 1; - - rv = prefs->CopyUnicharPref("mailnews.reply_header_locale", reply_header_locale); - if (NS_FAILED(rv) || !*reply_header_locale) - *reply_header_locale = nsCRT::strdup(EmptyString().get()); - - rv = prefs->GetLocalizedUnicharPref("mailnews.reply_header_authorwrote", reply_header_authorwrote); - if (NS_FAILED(rv) || !*reply_header_authorwrote) - *reply_header_authorwrote = nsCRT::strdup(NS_LITERAL_STRING("%s wrote").get()); - - rv = prefs->GetLocalizedUnicharPref("mailnews.reply_header_ondate", reply_header_ondate); - if (NS_FAILED(rv) || !*reply_header_ondate) - *reply_header_ondate = nsCRT::strdup(NS_LITERAL_STRING("On %s").get()); - - rv = prefs->CopyUnicharPref("mailnews.reply_header_separator", reply_header_separator); - if (NS_FAILED(rv) || !*reply_header_separator) - *reply_header_separator = nsCRT::strdup(NS_LITERAL_STRING(", ").get()); - - rv = prefs->CopyUnicharPref("mailnews.reply_header_colon", reply_header_colon); - if (NS_FAILED(rv) || !*reply_header_colon) - *reply_header_colon = nsCRT::strdup(NS_LITERAL_STRING(":").get()); - - rv = prefs->GetLocalizedUnicharPref("mailnews.reply_header_originalmessage", reply_header_originalmessage); - if (NS_FAILED(rv) || !*reply_header_originalmessage) - *reply_header_originalmessage = nsCRT::strdup(NS_LITERAL_STRING("--- Original Message ---").get()); + nsresult rv; + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + + *reply_header_type = 1; + if(NS_SUCCEEDED(rv)) { + prefBranch->GetIntPref("mailnews.reply_header_type", reply_header_type); + + NS_GetUnicharPreferenceWithDefault(prefBranch, "mailnews.reply_header_locale", EmptyString(), reply_header_locale); + NS_GetLocalizedUnicharPreferenceWithDefault(prefBranch, "mailnews.reply_header_authorwrote", NS_LITERAL_STRING("%s wrote"), reply_header_authorwrote); + NS_GetLocalizedUnicharPreferenceWithDefault(prefBranch, "mailnews.reply_header_ondate", NS_LITERAL_STRING("On %s"), reply_header_ondate); + NS_GetUnicharPreferenceWithDefault(prefBranch, "mailnews.reply_header_separator", NS_LITERAL_STRING(", "), reply_header_separator); + NS_GetUnicharPreferenceWithDefault(prefBranch, "mailnews.reply_header_colon", NS_LITERAL_STRING(":"), reply_header_colon); + NS_GetLocalizedUnicharPreferenceWithDefault(prefBranch, "mailnews.reply_header_originalmessage", NS_LITERAL_STRING("--- Original Message ---"), reply_header_originalmessage); } - return rv; } static nsresult RemoveDuplicateAddresses(const char * addresses, const char * anothersAddresses, PRBool removeAliasesToMe, char** newAddress) @@ -245,9 +227,9 @@ nsMsgCompose::nsMsgCompose() // For TagConvertible // Read and cache pref mConvertStructs = PR_FALSE; - nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); - if (prefs) - prefs->GetBoolPref("converter.html2txt.structs", &mConvertStructs); + nsCOMPtr prefBranch (do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) + prefBranch->GetBoolPref("converter.html2txt.structs", &mConvertStructs); m_composeHTML = PR_FALSE; mRecycledWindow = PR_TRUE; @@ -1025,10 +1007,10 @@ NS_IMETHODIMP nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode, nsIMsgIdentity m_compFields->GetSubject(msgSubject); PRBool showProgress = PR_FALSE; - nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); - if (prefs) + nsCOMPtr prefBranch (do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { - prefs->GetBoolPref("mailnews.show_send_progress", &showProgress); + prefBranch->GetBoolPref("mailnews.show_send_progress", &showProgress); if (showProgress) { nsCOMPtr params = do_CreateInstance(NS_MSGCOMPOSEPROGRESSPARAMS_CONTRACTID, &rv); @@ -1405,10 +1387,10 @@ NS_IMETHODIMP nsMsgCompose::GetComposeHTML(PRBool *aComposeHTML) nsresult nsMsgCompose::GetWrapLength(PRInt32 *aWrapLength) { nsresult rv; - nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID, &rv)); + nsCOMPtr prefBranch (do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - return prefs->GetIntPref("mailnews.wraplength", aWrapLength); + return prefBranch->GetIntPref("mailnews.wraplength", aWrapLength); } nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, @@ -1555,7 +1537,7 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, nsCAutoString originCharset(charset); // use send_default_charset if reply_in_default_charset is on. - nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); + nsCOMPtr prefs (do_GetService(NS_PREFSERVICE_CONTRACTID)); if (prefs) { PRBool replyInDefault = PR_FALSE; @@ -1563,9 +1545,9 @@ nsresult nsMsgCompose::CreateMessage(const char * originalMsgURI, &replyInDefault); if (replyInDefault) { nsXPIDLString str; - rv = prefs->GetLocalizedUnicharPref("mailnews.send_default_charset", - getter_Copies(str)); - if (NS_SUCCEEDED(rv) && !str.IsEmpty()) + NS_GetLocalizedUnicharPreferenceWithDefault(prefs, "mailnews.send_default_charset", + EmptyString(), str); + if (!str.IsEmpty()) LossyCopyUTF16toASCII(str, charset); } } @@ -1824,20 +1806,20 @@ QuotingOutputStreamListener::QuotingOutputStreamListener(const char * originalMs PRBool header, headerDate; PRInt32 replyHeaderType; - nsXPIDLString replyHeaderLocale; + nsAutoString replyHeaderLocale; nsXPIDLString replyHeaderAuthorwrote; nsXPIDLString replyHeaderOndate; - nsXPIDLString replyHeaderSeparator; - nsXPIDLString replyHeaderColon; + nsAutoString replyHeaderSeparator; + nsAutoString replyHeaderColon; // Get header type, locale and strings from pref. - rv = GetReplyHeaderInfo(&replyHeaderType, - getter_Copies(replyHeaderLocale), - getter_Copies(replyHeaderAuthorwrote), - getter_Copies(replyHeaderOndate), - getter_Copies(replyHeaderSeparator), - getter_Copies(replyHeaderColon), - getter_Copies(replyHeaderOriginalmessage)); + GetReplyHeaderInfo(&replyHeaderType, + replyHeaderLocale, + replyHeaderAuthorwrote, + replyHeaderOndate, + replyHeaderSeparator, + replyHeaderColon, + replyHeaderOriginalmessage); switch (replyHeaderType) { @@ -1963,22 +1945,22 @@ QuotingOutputStreamListener::QuotingOutputStreamListener(const char * originalMs if (mCitePrefix.IsEmpty()) { - if (!replyHeaderOriginalmessage) + if (replyHeaderOriginalmessage.IsEmpty()) { // This is not likely to happen but load the string if it's not done already. PRInt32 replyHeaderType; - nsXPIDLString replyHeaderLocale; + nsAutoString replyHeaderLocale; nsXPIDLString replyHeaderAuthorwrote; nsXPIDLString replyHeaderOndate; - nsXPIDLString replyHeaderSeparator; - nsXPIDLString replyHeaderColon; - rv = GetReplyHeaderInfo(&replyHeaderType, - getter_Copies(replyHeaderLocale), - getter_Copies(replyHeaderAuthorwrote), - getter_Copies(replyHeaderOndate), - getter_Copies(replyHeaderSeparator), - getter_Copies(replyHeaderColon), - getter_Copies(replyHeaderOriginalmessage)); + nsAutoString replyHeaderSeparator; + nsAutoString replyHeaderColon; + GetReplyHeaderInfo(&replyHeaderType, + replyHeaderLocale, + replyHeaderAuthorwrote, + replyHeaderOndate, + replyHeaderSeparator, + replyHeaderColon, + replyHeaderOriginalmessage); } mCitePrefix.AppendLiteral("\n\n"); mCitePrefix.Append(replyHeaderOriginalmessage); @@ -4085,18 +4067,17 @@ NS_IMETHODIMP nsMsgCompose::CheckAndPopulateRecipients(PRBool populateMailList, */ nsAutoString recipientsStr; nsAutoString nonHtmlRecipientsStr; - nsAutoString plaintextDomains; - nsAutoString htmlDomains; + nsXPIDLString plaintextDomains; + nsXPIDLString htmlDomains; nsAutoString domain; - nsCOMPtr prefs (do_GetService(NS_PREF_CONTRACTID)); - if (prefs) + nsCOMPtr prefBranch (do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { - nsXPIDLString str; - prefs->CopyUnicharPref("mailnews.plaintext_domains", getter_Copies(str)); - plaintextDomains = str; - prefs->CopyUnicharPref("mailnews.html_domains", getter_Copies(str)); - htmlDomains = str; + NS_GetLocalizedUnicharPreferenceWithDefault(prefBranch, "mailnews.plaintext_domains", EmptyString(), + plaintextDomains); + NS_GetLocalizedUnicharPreferenceWithDefault(prefBranch, "mailnews.html_domains", EmptyString(), + htmlDomains); } PRBool atLeastOneRecipientPrefersUnknown = PR_FALSE; diff --git a/mailnews/compose/src/nsMsgComposeService.cpp b/mailnews/compose/src/nsMsgComposeService.cpp index 59b6a3aedbd..c248c43929a 100644 --- a/mailnews/compose/src/nsMsgComposeService.cpp +++ b/mailnews/compose/src/nsMsgComposeService.cpp @@ -70,7 +70,8 @@ #include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeOwner.h" #include "nsIBaseWindow.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsIPrefBranchInternal.h" #include "nsMsgBaseCID.h" diff --git a/mailnews/compose/src/nsSmtpServer.cpp b/mailnews/compose/src/nsSmtpServer.cpp index c2e79340074..a6c7adf8e85 100644 --- a/mailnews/compose/src/nsSmtpServer.cpp +++ b/mailnews/compose/src/nsSmtpServer.cpp @@ -37,7 +37,8 @@ * ***** END LICENSE BLOCK ***** */ #include "nsIServiceManager.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsEscape.h" #include "nsSmtpServer.h" #include "nsIObserverService.h" @@ -59,9 +60,11 @@ NS_INTERFACE_MAP_BEGIN(nsSmtpServer) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISmtpServer) NS_INTERFACE_MAP_END -nsSmtpServer::nsSmtpServer() +nsSmtpServer::nsSmtpServer(): + mKey("") { - m_logonFailed = PR_FALSE; + m_logonFailed = PR_FALSE; + getPrefs(); } nsSmtpServer::~nsSmtpServer() @@ -82,7 +85,33 @@ nsSmtpServer::GetKey(char * *aKey) NS_IMETHODIMP nsSmtpServer::SetKey(const char * aKey) { + NS_ASSERTION(aKey, "Bad key pointer"); mKey = aKey; + return getPrefs(); +} + +nsresult nsSmtpServer::getPrefs() +{ + nsresult rv; + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + if (NS_FAILED(rv)) + return rv; + + nsCAutoString branchName; + branchName.AssignLiteral("mail.smtpserver."); + branchName += mKey; + branchName.Append('.'); + rv = prefs->GetBranch(branchName.get(), getter_AddRefs(mPrefBranch)); + if (NS_FAILED(rv)) + return rv; + + if(!mDefPrefBranch) { + branchName.AssignLiteral("mail.smtpserver.default."); + rv = prefs->GetBranch(branchName.get(), getter_AddRefs(mDefPrefBranch)); + if (NS_FAILED(rv)) + return rv; + } + return NS_OK; } @@ -90,13 +119,8 @@ NS_IMETHODIMP nsSmtpServer::GetHostname(char * *aHostname) { nsresult rv; - nsCAutoString pref; NS_ENSURE_ARG_POINTER(aHostname); - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - getPrefString("hostname", pref); - rv = prefs->CopyCharPref(pref.get(), aHostname); + rv = mPrefBranch->GetCharPref("hostname", aHostname); if (NS_FAILED(rv)) *aHostname=nsnull; return NS_OK; @@ -105,16 +129,10 @@ nsSmtpServer::GetHostname(char * *aHostname) NS_IMETHODIMP nsSmtpServer::SetHostname(const char * aHostname) { - nsresult rv; - nsCAutoString pref; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - getPrefString("hostname", pref); if (aHostname) - return prefs->SetCharPref(pref.get(), aHostname); + return mPrefBranch->SetCharPref("hostname", aHostname); else - prefs->ClearUserPref(pref.get()); + mPrefBranch->ClearUserPref("hostname"); return NS_OK; } @@ -123,13 +141,8 @@ NS_IMETHODIMP nsSmtpServer::GetPort(PRInt32 *aPort) { nsresult rv; - nsCAutoString pref; NS_ENSURE_ARG_POINTER(aPort); - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - getPrefString("port", pref); - rv = prefs->GetIntPref(pref.get(), aPort); + rv = mPrefBranch->GetIntPref("port", aPort); if (NS_FAILED(rv)) *aPort = 0; return NS_OK; @@ -138,16 +151,10 @@ nsSmtpServer::GetPort(PRInt32 *aPort) NS_IMETHODIMP nsSmtpServer::SetPort(PRInt32 aPort) { - nsresult rv; - nsCAutoString pref; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - getPrefString("port", pref); if (aPort) - return prefs->SetIntPref(pref.get(), aPort); + return mPrefBranch->SetIntPref("port", aPort); else - prefs->ClearUserPref(pref.get()); + mPrefBranch->ClearUserPref("port"); return NS_OK; } @@ -157,143 +164,89 @@ nsSmtpServer::GetDisplayname(char * *aDisplayname) nsresult rv; NS_ENSURE_ARG_POINTER(aDisplayname); - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - - nsCAutoString hpref; - getPrefString("hostname", hpref); - - nsCAutoString ppref; - getPrefString("port", ppref); - nsXPIDLCString hostname; - rv = prefs->CopyCharPref(hpref.get(), getter_Copies(hostname)); + rv = mPrefBranch->GetCharPref("hostname", getter_Copies(hostname)); if (NS_FAILED(rv)) { *aDisplayname=nsnull; return NS_OK; } PRInt32 port; - rv = prefs->GetIntPref(ppref.get(), &port); + rv = mPrefBranch->GetIntPref("port", &port); if (NS_FAILED(rv)) port = 0; if (port) { - nsCAutoString combined; - combined = hostname.get(); - combined += ":"; - combined.AppendInt(port); - *aDisplayname = ToNewCString(combined); + hostname.Append(':'); + hostname.AppendInt(port); } - else { - *aDisplayname = ToNewCString(hostname); - } - + + *aDisplayname = ToNewCString(hostname); return NS_OK; } NS_IMETHODIMP nsSmtpServer::GetTrySSL(PRInt32 *trySSL) { - nsresult rv; - nsCAutoString pref; NS_ENSURE_ARG_POINTER(trySSL); - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv)) return rv; - *trySSL= 0; - getPrefString("try_ssl", pref); - rv = prefs->GetIntPref(pref.get(), trySSL); - if (NS_FAILED(rv)) - getDefaultIntPref(prefs, 0, "try_ssl", trySSL); - return NS_OK; + return getIntPrefWithDefault("try_ssl", trySSL, 0); } NS_IMETHODIMP nsSmtpServer::SetTrySSL(PRInt32 trySSL) { - nsresult rv; - nsCAutoString pref; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - getPrefString("try_ssl", pref); - return prefs->SetIntPref(pref.get(), trySSL); + return mPrefBranch->SetIntPref("try_ssl", trySSL); } NS_IMETHODIMP nsSmtpServer::GetTrySecAuth(PRBool *trySecAuth) { nsresult rv; - nsCAutoString pref; NS_ENSURE_ARG_POINTER(trySecAuth); - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv)) return rv; *trySecAuth = PR_TRUE; - getPrefString("trySecAuth", pref); - rv = prefs->GetBoolPref(pref.get(), trySecAuth); + rv = mPrefBranch->GetBoolPref("trySecAuth", trySecAuth); if (NS_FAILED(rv)) - prefs->GetBoolPref("mail.smtpserver.default.trySecAuth", trySecAuth); + mDefPrefBranch->GetBoolPref("trySecAuth", trySecAuth); return NS_OK; } NS_IMETHODIMP nsSmtpServer::GetAuthMethod(PRInt32 *authMethod) { - nsresult rv; - nsCAutoString pref; NS_ENSURE_ARG_POINTER(authMethod); - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - *authMethod = 1; - getPrefString("auth_method", pref); - rv = prefs->GetIntPref(pref.get(), authMethod); - if (NS_FAILED(rv)) - rv = getDefaultIntPref(prefs, 1, "auth_method", authMethod); - return rv; + return getIntPrefWithDefault("auth_method", authMethod, 1); } nsresult -nsSmtpServer::getDefaultIntPref(nsIPref *prefs, - PRInt32 defVal, - const char *prefName, - PRInt32 *val) +nsSmtpServer::getIntPrefWithDefault(const char *prefName, + PRInt32 *val, + PRInt32 defVal) { - // mail.smtpserver.default. - nsCAutoString fullPrefName; - fullPrefName = "mail.smtpserver.default."; - fullPrefName.Append(prefName); - nsresult rv = prefs->GetIntPref(fullPrefName.get(), val); + nsresult rv = mPrefBranch->GetIntPref(prefName, val); + if (NS_SUCCEEDED(rv)) + return NS_OK; - if (NS_FAILED(rv)) - { // last resort - *val = defVal; - } - return NS_OK; + rv = mDefPrefBranch->GetIntPref(prefName, val); + + if (NS_FAILED(rv)) + { // last resort + *val = defVal; + } + + return NS_OK; } NS_IMETHODIMP nsSmtpServer::SetAuthMethod(PRInt32 authMethod) { - nsresult rv; - nsCAutoString pref; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv)) return rv; - getPrefString("auth_method", pref); - return prefs->SetIntPref(pref.get(), authMethod); + return mPrefBranch->SetIntPref("auth_method", authMethod); } NS_IMETHODIMP nsSmtpServer::GetUsername(char * *aUsername) { nsresult rv; - nsCAutoString pref; NS_ENSURE_ARG_POINTER(aUsername); - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - getPrefString("username", pref); - rv = prefs->CopyCharPref(pref.get(), aUsername); + rv = mPrefBranch->GetCharPref("username", aUsername); if (NS_FAILED(rv)) *aUsername = nsnull; return NS_OK; @@ -302,16 +255,10 @@ nsSmtpServer::GetUsername(char * *aUsername) NS_IMETHODIMP nsSmtpServer::SetUsername(const char * aUsername) { - nsresult rv; - nsCAutoString pref; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - getPrefString("username", pref); if (aUsername) - return prefs->SetCharPref(pref.get(), aUsername); + return mPrefBranch->SetCharPref("username", aUsername); else - prefs->ClearUserPref(pref.get()); + mPrefBranch->ClearUserPref("username"); return NS_OK; } @@ -336,15 +283,10 @@ nsSmtpServer::GetPassword(char * *aPassword) // is everything after the first '.' // user_pref("mail.smtp.useMatchingDomainServer", true); - nsresult rv; - nsCAutoString accountKeyPref; nsXPIDLCString accountKey; PRBool useMatchingHostNameServer = PR_FALSE; PRBool useMatchingDomainServer = PR_FALSE; - getPrefString("incomingAccount", accountKeyPref); - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS(rv, rv); - prefBranch->GetCharPref(accountKeyPref.get(), getter_Copies(accountKey)); + mPrefBranch->GetCharPref("incomingAccount", getter_Copies(accountKey)); nsCOMPtr accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID); nsCOMPtr incomingServerToUse; @@ -356,6 +298,9 @@ nsSmtpServer::GetPassword(char * *aPassword) } else { + nsresult rv; + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv,rv); prefBranch->GetBoolPref("mail.smtp.useMatchingHostNameServer", &useMatchingHostNameServer); prefBranch->GetBoolPref("mail.smtp.useMatchingDomainServer", &useMatchingDomainServer); if (useMatchingHostNameServer || useMatchingDomainServer) @@ -378,7 +323,7 @@ nsSmtpServer::GetPassword(char * *aPassword) { PRUint32 count = 0; allServers->Count(&count); - PRInt32 i; + PRUint32 i; for (i = 0; i < count; i++) { nsCOMPtr server = do_QueryElementAt(allServers, i); @@ -600,31 +545,14 @@ nsSmtpServer::GetServerURI(char **aResult) *aResult = ToNewCString(uri); return NS_OK; } - -nsresult -nsSmtpServer::getPrefString(const char *pref, nsCAutoString& result) -{ - result = "mail.smtpserver."; - result += mKey; - result += "."; - result += pref; - - return NS_OK; -} NS_IMETHODIMP nsSmtpServer::SetRedirectorType(const char *aRedirectorType) { - nsresult rv; - nsCAutoString pref; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - getPrefString("redirector_type", pref); if (aRedirectorType) - return prefs->SetCharPref(pref.get(), aRedirectorType); - else - prefs->ClearUserPref(pref.get()); + return mPrefBranch->SetCharPref("redirector_type", aRedirectorType); + + mPrefBranch->ClearUserPref("redirector_type"); return NS_OK; } @@ -632,17 +560,8 @@ NS_IMETHODIMP nsSmtpServer::GetRedirectorType(char **aResult) { nsresult rv; - nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv,rv); - - nsCOMPtr prefBranch; - rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch)); - NS_ENSURE_SUCCESS(rv,rv); - nsCAutoString prefName; - getPrefString("redirector_type", prefName); - - rv = prefBranch->GetCharPref(prefName.get(), aResult); + rv = mPrefBranch->GetCharPref("redirector_type", aResult); if (NS_FAILED(rv)) *aResult = nsnull; @@ -671,9 +590,12 @@ nsSmtpServer::GetRedirectorType(char **aResult) rv = GetHostname(getter_Copies(hostName)); NS_ENSURE_SUCCESS(rv,rv); - prefName.Assign("default_redirector_type.smtp."); + nsCAutoString prefName; + prefName.AssignLiteral("default_redirector_type.smtp."); prefName.Append(hostName); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv,rv); nsXPIDLCString defaultRedirectorType; rv = prefBranch->GetCharPref(prefName.get(), getter_Copies(defaultRedirectorType)); if (NS_SUCCEEDED(rv) && !defaultRedirectorType.IsEmpty()) @@ -690,21 +612,5 @@ nsSmtpServer::GetRedirectorType(char **aResult) NS_IMETHODIMP nsSmtpServer::ClearAllValues() { - nsresult rv = NS_OK; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCAutoString rootPref("mail.smtpserver."); - rootPref += mKey; - - rv = prefs->EnumerateChildren(rootPref.get(), clearPrefEnum, (void *)prefs.get()); - - return rv; -} - -void -nsSmtpServer::clearPrefEnum(const char *aPref, void *aClosure) -{ - nsIPref *prefs = (nsIPref *)aClosure; - prefs->ClearUserPref(aPref); + return mPrefBranch->DeleteBranch(""); } diff --git a/mailnews/compose/src/nsSmtpServer.h b/mailnews/compose/src/nsSmtpServer.h index 52b4f79fa98..e2cf66d0c7c 100644 --- a/mailnews/compose/src/nsSmtpServer.h +++ b/mailnews/compose/src/nsSmtpServer.h @@ -41,6 +41,7 @@ #include "nsString.h" #include "nsISmtpServer.h" +#include "nsIPrefBranch.h" #include "nsWeakReference.h" class nsSmtpServer : public nsISmtpServer, @@ -55,13 +56,13 @@ public: private: nsCString mKey; - - nsresult getPrefString(const char *pref, nsCAutoString& result); - nsresult getDefaultIntPref(nsIPref *prefs, PRInt32 defVal, const char *prefName, PRInt32 *val); + nsCOMPtr mPrefBranch; + nsCOMPtr mDefPrefBranch; + + nsresult getPrefs(); + nsresult getIntPrefWithDefault(const char *prefName, PRInt32 *val, PRInt32 defval); nsCString m_password; PRBool m_logonFailed; - static void clearPrefEnum(const char *aPref, void *aClosure); - }; #endif diff --git a/mailnews/compose/src/nsSmtpService.cpp b/mailnews/compose/src/nsSmtpService.cpp index 416b2a04847..602a13d0bee 100644 --- a/mailnews/compose/src/nsSmtpService.cpp +++ b/mailnews/compose/src/nsSmtpService.cpp @@ -39,7 +39,8 @@ #include "msgCore.h" // precompiled header... #include "nsXPIDLString.h" #include "nsReadableUtils.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsIIOService.h" #include "nsIPipe.h" #include "nsNetCID.h" @@ -68,6 +69,7 @@ #define MAIL_ROOT_PREF "mail." #define PREF_MAIL_SMTPSERVERS "mail.smtpservers" #define PREF_MAIL_SMTPSERVERS_APPEND_SERVERS "mail.smtpservers.appendsmtpservers" +#define PREF_MAIL_SMTP_DEFAULTSERVER "mail.smtp.defaultserver" typedef struct _findServerByKeyEntry { const char *key; @@ -383,12 +385,15 @@ nsSmtpService::loadSmtpServers() if (mSmtpServersLoaded) return NS_OK; nsresult rv; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); + nsCOMPtr prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + if (NS_FAILED(rv)) return rv; + nsCOMPtr prefRootBranch; + prefService->GetBranch(nsnull, getter_AddRefs(prefRootBranch)); if (NS_FAILED(rv)) return rv; nsXPIDLCString tempServerList; nsXPIDLCString serverList; - rv = prefs->CopyCharPref(PREF_MAIL_SMTPSERVERS, getter_Copies(tempServerList)); + rv = prefRootBranch->GetCharPref(PREF_MAIL_SMTPSERVERS, getter_Copies(tempServerList)); //Get the pref in a tempServerList and then parse it to see if it has dupes. //if so remove the dupes and then create the serverList. @@ -422,8 +427,7 @@ nsSmtpService::loadSmtpServers() // We need to check if we have any pre-configured smtp servers so that // those servers can be appended to the list. nsXPIDLCString appendServerList; - rv = prefs->CopyCharPref(PREF_MAIL_SMTPSERVERS_APPEND_SERVERS, - getter_Copies(appendServerList)); + rv = prefRootBranch->GetCharPref(PREF_MAIL_SMTPSERVERS_APPEND_SERVERS, getter_Copies(appendServerList)); // Get the list of smtp servers (either from regular pref i.e, mail.smtpservers or // from preconfigured pref mail.smtpservers.appendsmtpservers) and create a keyed @@ -438,18 +442,18 @@ nsSmtpService::loadSmtpServers() * is stored in mailnews.js file. If a given vendor needs to add more preconfigured * smtp servers, the default version number can be increased. Comparing version * number from user's prefs file and the default one from mailnews.js, we - * can add new smp servers and any other version level changes that need to be done. + * can add new smtp servers and any other version level changes that need to be done. * * 2. pref("mail.smtpservers.appendsmtpservers", ); * This pref contains the list of pre-configured smp servers that ISP/Vendor wants to * to add to the existing servers list. */ nsCOMPtr defaultsPrefBranch; - rv = prefs->GetDefaultBranch(MAIL_ROOT_PREF, getter_AddRefs(defaultsPrefBranch)); + rv = prefService->GetDefaultBranch(MAIL_ROOT_PREF, getter_AddRefs(defaultsPrefBranch)); NS_ENSURE_SUCCESS(rv,rv); nsCOMPtr prefBranch; - rv = prefs->GetBranch(MAIL_ROOT_PREF, getter_AddRefs(prefBranch)); + rv = prefService->GetBranch(MAIL_ROOT_PREF, getter_AddRefs(prefBranch)); NS_ENSURE_SUCCESS(rv,rv); PRInt32 appendSmtpServersCurrentVersion=0; @@ -527,10 +531,10 @@ nsresult nsSmtpService::saveKeyList() { nsresult rv; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - return prefs->SetCharPref(PREF_MAIL_SMTPSERVERS, mServerKeyList.get()); + return prefBranch->SetCharPref(PREF_MAIL_SMTPSERVERS, mServerKeyList.get()); } nsresult @@ -545,14 +549,11 @@ nsSmtpService::createKeyedServer(const char *key, nsISmtpServer** aResult) server->SetKey(key); mSmtpServers->AppendElement(server); - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv)) { - if (mServerKeyList.IsEmpty()) - mServerKeyList = key; - else { - mServerKeyList += ","; - mServerKeyList += key; - } + if (mServerKeyList.IsEmpty()) + mServerKeyList = key; + else { + mServerKeyList.Append(','); + mServerKeyList += key; } if (aResult) { @@ -594,13 +595,12 @@ nsSmtpService::GetDefaultServer(nsISmtpServer **aServer) *aServer = nsnull; // always returns NS_OK, just leaving *aServer at nsnull if (!mDefaultSmtpServer) { - nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID, &rv)); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; // try to get it from the prefs nsXPIDLCString defaultServerKey; - rv = pref->CopyCharPref("mail.smtp.defaultserver", - getter_Copies(defaultServerKey)); + rv = prefBranch->GetCharPref(PREF_MAIL_SMTP_DEFAULTSERVER, getter_Copies(defaultServerKey)); if (NS_SUCCEEDED(rv) && !defaultServerKey.IsEmpty()) { @@ -630,7 +630,7 @@ nsSmtpService::GetDefaultServer(nsISmtpServer **aServer) nsXPIDLCString serverKey; mDefaultSmtpServer->GetKey(getter_Copies(serverKey)); if (NS_SUCCEEDED(rv)) - pref->SetCharPref("mail.smtp.defaultserver", serverKey); + prefBranch->SetCharPref(PREF_MAIL_SMTP_DEFAULTSERVER, serverKey); } } @@ -655,8 +655,9 @@ nsSmtpService::SetDefaultServer(nsISmtpServer *aServer) nsresult rv = aServer->GetKey(getter_Copies(serverKey)); NS_ENSURE_SUCCESS(rv,rv); - nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID, &rv)); - pref->SetCharPref("mail.smtp.defaultserver", serverKey); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv,rv); + prefBranch->SetCharPref(PREF_MAIL_SMTP_DEFAULTSERVER, serverKey); return NS_OK; } diff --git a/mailnews/extensions/mdn/src/nsMsgMdnGenerator.cpp b/mailnews/extensions/mdn/src/nsMsgMdnGenerator.cpp index 30ec2829544..d6f917a101f 100644 --- a/mailnews/extensions/mdn/src/nsMsgMdnGenerator.cpp +++ b/mailnews/extensions/mdn/src/nsMsgMdnGenerator.cpp @@ -60,7 +60,6 @@ #include "nsIPrompt.h" #include "nsIMsgCompUtils.h" #include "nsIPrefService.h" -#include "nsIPrefBranchInternal.h" #include "nsIPrefBranch.h" #include "nsIStringBundle.h" diff --git a/mailnews/extensions/palmsync/src/PalmSyncImp.cpp b/mailnews/extensions/palmsync/src/PalmSyncImp.cpp index 04de63e4d93..6a2cae9e7b6 100644 --- a/mailnews/extensions/palmsync/src/PalmSyncImp.cpp +++ b/mailnews/extensions/palmsync/src/PalmSyncImp.cpp @@ -58,8 +58,6 @@ #include "nsIPrefService.h" #include "nsIPrefBranch.h" -#include "nsIPref.h" -#include "nsIPrefBranchInternal.h" #include "nspr.h" PRLogModuleInfo *PALMSYNC; diff --git a/mailnews/import/eudora/src/nsEudoraCompose.cpp b/mailnews/import/eudora/src/nsEudoraCompose.cpp index a136c836b12..e003cc9b103 100644 --- a/mailnews/import/eudora/src/nsEudoraCompose.cpp +++ b/mailnews/import/eudora/src/nsEudoraCompose.cpp @@ -68,7 +68,6 @@ #include "EudoraDebugLog.h" #include "nsMimeTypes.h" -#include "nsIPref.h" #include "nsMsgUtils.h" static NS_DEFINE_CID( kMsgSendCID, NS_MSGSEND_CID); @@ -619,7 +618,7 @@ nsresult nsEudoraCompose::SendTheMessage( nsIFileSpec *pMsg) ExtractCharset( headerVal); // Use platform charset as default if the msg doesn't specify one // (ie, no 'charset' param in the Content-Type: header). As the last - // resort we'll use the mail defaul charset. + // resort we'll use the mail default charset. if (headerVal.IsEmpty()) { headerVal.AssignWithConversion(nsMsgI18NFileSystemCharset()); @@ -628,10 +627,9 @@ nsresult nsEudoraCompose::SendTheMessage( nsIFileSpec *pMsg) if (m_defCharset.IsEmpty()) { nsXPIDLString defaultCharset; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv)) - rv = prefs->GetLocalizedUnicharPref("mailnews.view_default_charset", getter_Copies(defaultCharset)); - m_defCharset.Assign(defaultCharset ? defaultCharset.get() : NS_LITERAL_STRING("ISO-8859-1").get()); + NS_GetLocalizedUnicharPreferenceWithDefault(nsnull, "mailnews.view_default_charset", + NS_LITERAL_STRING("ISO-8859-1"), defaultCharset); + m_defCharset = defaultCharset; } headerVal = m_defCharset; } diff --git a/mailnews/import/oexpress/Makefile.in b/mailnews/import/oexpress/Makefile.in index a7413320699..77db4536b5e 100644 --- a/mailnews/import/oexpress/Makefile.in +++ b/mailnews/import/oexpress/Makefile.in @@ -66,6 +66,7 @@ REQUIRES = xpcom \ mork \ intl \ msgbase \ + pref \ mailnews \ necko \ msgdb \ diff --git a/mailnews/import/outlook/src/nsOutlookCompose.cpp b/mailnews/import/outlook/src/nsOutlookCompose.cpp index 1b80603c469..e90918df857 100644 --- a/mailnews/import/outlook/src/nsOutlookCompose.cpp +++ b/mailnews/import/outlook/src/nsOutlookCompose.cpp @@ -69,7 +69,6 @@ #include "OutlookDebugLog.h" #include "nsMimeTypes.h" -#include "nsIPref.h" #include "nsMsgUtils.h" static NS_DEFINE_CID( kMsgSendCID, NS_MSGSEND_CID); @@ -623,17 +622,16 @@ nsresult nsOutlookCompose::SendTheMessage( nsIFileSpec *pMsg, nsMsgDeliverMode m ExtractCharset( headerVal); // Use platform charset as default if the msg doesn't specify one // (ie, no 'charset' param in the Content-Type: header). As the last - // resort we'll use the mail defaul charset. + // resort we'll use the mail default charset. if (headerVal.IsEmpty()) { headerVal.AssignWithConversion(nsMsgI18NFileSystemCharset()); if (headerVal.IsEmpty()) { // last resort nsXPIDLString defaultCharset; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv)) - rv = prefs->GetLocalizedUnicharPref("mailnews.view_default_charset", getter_Copies(defaultCharset)); - headerVal.Assign(defaultCharset.IsEmpty() ? NS_LITERAL_STRING("ISO-8859-1").get() : defaultCharset.get()); + NS_GetLocalizedUnicharPreferenceWithDefault(nsnull, "mailnews.view_default_charset", + NS_LITERAL_STRING("ISO-8859-1"), defaultCharset); + headerVal = defaultCharset; } } m_pMsgFields->SetCharacterSet( NS_LossyConvertUTF16toASCII(headerVal).get() ); diff --git a/mailnews/import/text/src/nsTextImport.cpp b/mailnews/import/text/src/nsTextImport.cpp index 801495cdb92..b7f702fd732 100644 --- a/mailnews/import/text/src/nsTextImport.cpp +++ b/mailnews/import/text/src/nsTextImport.cpp @@ -67,7 +67,8 @@ #include "nsTextStringBundle.h" #include "nsIStringBundle.h" #include "nsTextAddress.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsXPIDLString.h" #include "nsProxiedService.h" #include "TextDebugLog.h" @@ -713,10 +714,10 @@ NS_IMETHODIMP ImportAddressImpl::InitFieldMap(nsIFileSpec *location, nsIImportFi // from the same file format. nsresult rv; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED( rv)) { nsXPIDLCString prefStr; - rv = prefs->CopyCharPref( "mailnews.import.text.fieldmap", getter_Copies(prefStr)); + rv = prefs->GetCharPref( "mailnews.import.text.fieldmap", getter_Copies(prefStr)); if (NS_SUCCEEDED( rv)) { const char *pStr = (const char *)prefStr; if (pStr) { @@ -791,12 +792,12 @@ void ImportAddressImpl::SaveFieldMap( nsIImportFieldMap *pMap) PRBool done = PR_FALSE; nsresult rv; - // NS_WITH_PROXIED_SERVICE( nsIPref, prefs, kPrefServiceCID, NS_UI_THREAD_EVENTQ, &rv); - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); + + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); if (NS_SUCCEEDED( rv)) { nsXPIDLCString prefStr; - rv = prefs->CopyCharPref( "mailnews.import.text.fieldmap", getter_Copies(prefStr)); + rv = prefs->GetCharPref( "mailnews.import.text.fieldmap", getter_Copies(prefStr)); if (NS_SUCCEEDED( rv)) { if (str.Equals(prefStr)) done = PR_TRUE; diff --git a/mailnews/mapi/mapihook/src/msgMapiHook.cpp b/mailnews/mapi/mapihook/src/msgMapiHook.cpp index d5b3a996e33..c11cfb69af0 100644 --- a/mailnews/mapi/mapihook/src/msgMapiHook.cpp +++ b/mailnews/mapi/mapihook/src/msgMapiHook.cpp @@ -65,7 +65,8 @@ #include "nsReadableUtils.h" #include "nsMsgBaseCID.h" #include "nsIStringBundle.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsString.h" #include "nsUnicharUtils.h" #include "nsIMsgAttachment.h" @@ -299,10 +300,10 @@ nsMapiHook::IsBlindSendAllowed() { PRBool enabled = PR_FALSE; PRBool warn = PR_TRUE; - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (prefs) { - prefs->GetBoolPref(PREF_MAPI_WARN_PRIOR_TO_BLIND_SEND,&warn); - prefs->GetBoolPref(PREF_MAPI_BLIND_SEND_ENABLED,&enabled); + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (prefBranch) { + prefBranch->GetBoolPref(PREF_MAPI_WARN_PRIOR_TO_BLIND_SEND, &warn); + prefBranch->GetBoolPref(PREF_MAPI_BLIND_SEND_ENABLED, &enabled); } if (!enabled) return PR_FALSE; @@ -335,11 +336,10 @@ nsMapiHook::IsBlindSendAllowed() PRBool okayToContinue = PR_FALSE; dlgService->ConfirmCheck(nsnull, nsnull, warningMsg, dontShowAgainMessage, &continueToWarn, &okayToContinue); - if (!continueToWarn && okayToContinue && prefs) - prefs->SetBoolPref(PREF_MAPI_WARN_PRIOR_TO_BLIND_SEND,PR_FALSE); + if (!continueToWarn && okayToContinue && prefBranch) + prefBranch->SetBoolPref(PREF_MAPI_WARN_PRIOR_TO_BLIND_SEND, PR_FALSE); return okayToContinue; - } // this is used for Send without UI diff --git a/mailnews/mapi/mapihook/src/msgMapiSupport.cpp b/mailnews/mapi/mapihook/src/msgMapiSupport.cpp index c2baaee9877..2cdb392bf55 100644 --- a/mailnews/mapi/mapihook/src/msgMapiSupport.cpp +++ b/mailnews/mapi/mapihook/src/msgMapiSupport.cpp @@ -46,10 +46,6 @@ #include "nsICategoryManager.h" #include "nsCRT.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" -#include "nsIPrefBranchInternal.h" - #include "msgMapiSupport.h" #include "nsMapiRegistryUtils.h" #include "nsMapiRegistry.h" diff --git a/mailnews/mime/src/comi18n.cpp b/mailnews/mime/src/comi18n.cpp index 3a331fba9d0..2b521037a1f 100644 --- a/mailnews/mime/src/comi18n.cpp +++ b/mailnews/mime/src/comi18n.cpp @@ -53,7 +53,9 @@ #include "comi18n.h" #include "nsIServiceManager.h" #include "nsIStringCharsetDetector.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" +#include "nsMsgUtils.h" #include "mimebuf.h" #include "nsMsgI18N.h" #include "nsMimeTypes.h" @@ -239,11 +241,10 @@ PRInt32 generate_encodedwords(char *pUTF8, const char *charset, char method, cha if (!nsCRT::strcasecmp("ISO-2022-JP", charset)) { static PRInt32 conv_kana = -1; if (conv_kana < 0) { - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (nsnull != prefs && NS_SUCCEEDED(rv)) { - PRBool val; - if (NS_FAILED(prefs->GetBoolPref("mailnews.send_hankaku_kana", &val))) - val = PR_FALSE; // no pref means need the mapping + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + if (NS_SUCCEEDED(rv)) { + PRBool val = PR_FALSE; // no pref means need the mapping + prefBranch->GetBoolPref("mailnews.send_hankaku_kana", &val); conv_kana = val ? 0 : 1; } } @@ -753,24 +754,18 @@ char * NextChar_UTF8(char *str) nsresult MIME_detect_charset(const char *aBuf, PRInt32 aLength, const char** aCharset) { - nsresult res; - char theBuffer[128]; - nsFixedCString detector_contractid(theBuffer, sizeof(theBuffer), 0); + nsresult res = NS_ERROR_UNEXPECTED; nsXPIDLString detector_name; - nsCOMPtr detector; *aCharset = nsnull; - detector_contractid.Assign(NS_STRCDETECTOR_CONTRACTID_BASE); + NS_GetLocalizedUnicharPreferenceWithDefault(nsnull, "intl.charset.detector", EmptyString(), detector_name); - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &res)); - if (NS_SUCCEEDED(res)) { - if (NS_SUCCEEDED(prefs->GetLocalizedUnicharPref("intl.charset.detector", getter_Copies(detector_name)))) { - AppendUTF16toUTF8(detector_name, detector_contractid); - } - } + if (!detector_name.IsEmpty()) { + nsCAutoString detector_contractid; + detector_contractid.AssignLiteral(NS_STRCDETECTOR_CONTRACTID_BASE); - if (detector_contractid.Length() > sizeof(NS_STRCDETECTOR_CONTRACTID_BASE)) { - detector = do_CreateInstance(detector_contractid.get(), &res); + AppendUTF16toUTF8(detector_name, detector_contractid); + nsCOMPtr detector = do_CreateInstance(detector_contractid.get(), &res); if (NS_SUCCEEDED(res)) { nsDetectionConfident oConfident; res = detector->DoIt(aBuf, aLength, aCharset, oConfident); diff --git a/mailnews/mime/src/mimedrft.cpp b/mailnews/mime/src/mimedrft.cpp index 87818fac396..e0d1f711a4f 100644 --- a/mailnews/mime/src/mimedrft.cpp +++ b/mailnews/mime/src/mimedrft.cpp @@ -56,7 +56,8 @@ #include "plstr.h" #include "prprf.h" #include "prio.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "msgCore.h" #include "nsCRT.h" #include "nsEscape.h" @@ -107,8 +108,6 @@ static NS_DEFINE_CID(kCMsgComposeServiceCID, NS_MSGCOMPOSESERVICE_CID); // THIS SHOULD ALL MOVE TO ANOTHER FILE AFTER LANDING! //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// -// Define CIDs... -static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); // safe filename for all OSes #define SAFE_TMP_FILENAME "nsmime.tmp" @@ -437,12 +436,12 @@ PRBool GetMailXlateionPreference(void) { nsresult res; - PRBool xlate = PR_FALSE; + PRBool xlate = PR_FALSE; + + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &res)); + if(NS_SUCCEEDED(res)) + prefBranch->GetBoolPref("mail.unknown", &xlate); - nsCOMPtr prefs(do_GetService(kPrefCID, &res)); - if (NS_SUCCEEDED(res) && prefs) - res = prefs->GetBoolPref("mail.unknown", &xlate); - return xlate; } @@ -454,9 +453,9 @@ GetMailSigningPreference(void) nsresult res; PRBool signit = PR_FALSE; - nsCOMPtr prefs(do_GetService(kPrefCID, &res)); - if (NS_SUCCEEDED(res) && prefs) - res = prefs->GetBoolPref("mail.unknown", &signit); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &res)); + if(NS_SUCCEEDED(res)) + prefBranch->GetBoolPref("mail.unknown", &signit); return signit; } @@ -1210,9 +1209,9 @@ mime_insert_forwarded_message_headers(char **body, PRInt32 show_headers = 0; nsresult res; - nsCOMPtr prefs(do_GetService(kPrefCID, &res)); - if (NS_SUCCEEDED(res) && prefs) - res = prefs->GetIntPref("mail.show_headers", &show_headers); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &res)); + if (NS_SUCCEEDED(res)) + prefBranch->GetIntPref("mail.show_headers", &show_headers); switch (show_headers) { @@ -1652,10 +1651,10 @@ mime_parse_stream_complete (nsMIMESession *stream) } PR_FREEIF(mdd->mailcharset); - // Release the prefs service - MimeObject *obj = (mdd ? mdd->obj : 0); - if ( (obj) && (obj->options) && (obj->options->prefs) ) - obj->options->prefs->Release(); + // Release the prefbranch + MimeObject *obj = (mdd ? mdd->obj : 0); + if ( (obj) && (obj->options)) + obj->options->m_prefBranch = 0; mdd->identity = nsnull; PR_Free(mdd->url_name); @@ -2107,7 +2106,7 @@ mime_bridge_create_draft_stream( mdd->options->decompose_file_output_fn = mime_decompose_file_output_fn; mdd->options->decompose_file_close_fn = mime_decompose_file_close_fn; - rv = CallGetService(kPrefCID, &(mdd->options->prefs)); + mdd->options->m_prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) goto FAIL; diff --git a/mailnews/mime/src/mimei.cpp b/mailnews/mime/src/mimei.cpp index d5f34b2b11f..904762f13e0 100644 --- a/mailnews/mime/src/mimei.cpp +++ b/mailnews/mime/src/mimei.cpp @@ -96,7 +96,7 @@ #include "nsMimeStringResources.h" #include "nsMimeTypes.h" #include "nsMsgUtils.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" #include "imgILoader.h" #ifdef MOZ_THUNDERBIRD @@ -431,7 +431,7 @@ mime_find_class (const char *content_type, MimeHeaders *hdrs, contentTypeHandlerInitStruct ctHandlerInfo; // Read some prefs - nsIPref *pref = GetPrefServiceManager(opts); + nsIPrefBranch *prefBranch = GetPrefBranch(opts); PRInt32 html_as = 0; // def. see below PRInt32 types_of_classes_to_disallow = 0; /* Let only a few libmime classes process incoming data. This protects from bugs (e.g. buffer overflows) @@ -448,11 +448,11 @@ mime_find_class (const char *content_type, MimeHeaders *hdrs, */ if (opts && opts->format_out != nsMimeOutput::nsMimeMessageFilterSniffer && opts->format_out != nsMimeOutput::nsMimeMessageDecrypt) - if (pref) + if (prefBranch) { - pref->GetIntPref("mailnews.display.html_as", &html_as); - pref->GetIntPref("mailnews.display.disallow_mime_handlers", - &types_of_classes_to_disallow); + prefBranch->GetIntPref("mailnews.display.html_as", &html_as); + prefBranch->GetIntPref("mailnews.display.disallow_mime_handlers", + &types_of_classes_to_disallow); if (types_of_classes_to_disallow > 0 && html_as == 0) // We have non-sensical prefs. Do some fixup. html_as = 1; @@ -466,8 +466,8 @@ mime_find_class (const char *content_type, MimeHeaders *hdrs, // it is faster to read the pref first then figure out the msg hdr for the current url only if we have to // XXX instead of reading this pref every time, part of mime should be an observer listening to this pref change // and updating internal state accordingly. But none of the other prefs in this file seem to be doing that...=( - if (pref) - pref->GetBoolPref("mailnews.display.sanitizeJunkMail", &sanitizeJunkMail); + if (prefBranch) + prefBranch->GetBoolPref("mailnews.display.sanitizeJunkMail", &sanitizeJunkMail); if (sanitizeJunkMail) { @@ -559,9 +559,9 @@ mime_find_class (const char *content_type, MimeHeaders *hdrs, if (opts && opts->format_out != nsMimeOutput::nsMimeMessageFilterSniffer) { PRBool disable_format_flowed = PR_FALSE; - if (pref) - pref->GetBoolPref("mailnews.display.disable_format_flowed_support", - &disable_format_flowed); + if (prefBranch) + prefBranch->GetBoolPref("mailnews.display.disable_format_flowed_support", + &disable_format_flowed); if(!disable_format_flowed) { diff --git a/mailnews/mime/src/mimemalt.cpp b/mailnews/mime/src/mimemalt.cpp index c5ec90f0ee2..2c9a0ad8ced 100644 --- a/mailnews/mime/src/mimemalt.cpp +++ b/mailnews/mime/src/mimemalt.cpp @@ -42,7 +42,7 @@ #include "prlog.h" #include "nsMimeTypes.h" #include "nsMimeStringResources.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" #include "mimemoz2.h" // for prefs #include "nsCRT.h" @@ -236,10 +236,10 @@ MimeMultipartAlternative_display_part_p(MimeObject *self, */ // prefer_plaintext pref - nsIPref *pref = GetPrefServiceManager(self->options); + nsIPrefBranch *prefBranch = GetPrefBranch(self->options); PRBool prefer_plaintext = PR_FALSE; - if (pref) - (void)pref->GetBoolPref("mailnews.display.prefer_plaintext", + if (prefBranch) + prefBranch->GetBoolPref("mailnews.display.prefer_plaintext", &prefer_plaintext); if (prefer_plaintext && self->options->format_out != nsMimeOutput::nsMimeMessageSaveAs diff --git a/mailnews/mime/src/mimemoz2.cpp b/mailnews/mime/src/mimemoz2.cpp index a434bb2dc9b..036af335926 100644 --- a/mailnews/mime/src/mimemoz2.cpp +++ b/mailnews/mime/src/mimemoz2.cpp @@ -55,7 +55,8 @@ #include "plstr.h" #include "prmem.h" #include "mimemoz2.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsIServiceManager.h" #include "nsFileSpec.h" #include "comi18n.h" @@ -100,7 +101,6 @@ // -static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); // static NS_DEFINE_CID(kParserCID, NS_PARSER_CID); @@ -954,9 +954,9 @@ mime_display_stream_complete (nsMIMESession *stream) int status; PRBool abortNow = PR_FALSE; - // Release the prefs service - if ( (obj->options) && (obj->options->prefs) ) - obj->options->prefs->Release(); + // Release the prefbranch + if ( (obj->options) ) + obj->options->m_prefBranch = 0; if ((obj->options) && (obj->options->headers == MimeHeadersOnly)) abortNow = PR_TRUE; @@ -1370,13 +1370,13 @@ PRBool MimeObjectChildIsMessageBody(MimeObject *obj, // // Get the connnection to prefs service manager -nsIPref * -GetPrefServiceManager(MimeDisplayOptions *opt) +nsIPrefBranch * +GetPrefBranch(MimeDisplayOptions *opt) { if (!opt) return nsnull; - return opt->prefs; + return opt->m_prefBranch; } // Get the text converter... @@ -1392,7 +1392,6 @@ GetTextConverter(MimeDisplayOptions *opt) MimeDisplayOptions::MimeDisplayOptions() { conv = nsnull; // For text conversion... - prefs = nsnull; /* Connnection to prefs service manager */ format_out = 0; // The format out type url = nsnull; @@ -1537,9 +1536,9 @@ mime_bridge_create_display_stream( // memset(msd->options, 0, sizeof(*msd->options)); msd->options->format_out = format_out; // output format - rv = CallGetService(kPrefCID, &(msd->options->prefs)); - if (! (msd->options->prefs && NS_SUCCEEDED(rv))) - { + msd->options->m_prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + if (NS_FAILED(rv)) + { PR_FREEIF(msd); return nsnull; } @@ -1547,8 +1546,8 @@ mime_bridge_create_display_stream( // Need the text converter... rv = CallCreateInstance(MOZ_TXTTOHTMLCONV_CONTRACTID, &(msd->options->conv)); if (NS_FAILED(rv)) - { - msd->options->prefs->Release(); + { + msd->options->m_prefBranch = 0; PR_FREEIF(msd); return nsnull; } @@ -1595,15 +1594,27 @@ mime_bridge_create_display_stream( // Now, get the libmime prefs... //////////////////////////////////////////////////////////// - /* This pref is written down in with the - opposite sense of what we like to use... */ MIME_WrapLongLines = PR_TRUE; - if (msd->options->prefs) - msd->options->prefs->GetBoolPref("mail.wrap_long_lines", &MIME_WrapLongLines); - MIME_VariableWidthPlaintext = PR_TRUE; - if (msd->options->prefs) - msd->options->prefs->GetBoolPref("mail.fixed_width_messages", &MIME_VariableWidthPlaintext); + msd->options->force_user_charset = PR_FALSE; + + if (msd->options->m_prefBranch) + { + msd->options->m_prefBranch->GetBoolPref("mail.wrap_long_lines", &MIME_WrapLongLines); + msd->options->m_prefBranch->GetBoolPref("mail.fixed_width_messages", &MIME_VariableWidthPlaintext); + // + // Charset overrides takes place here + // + // We have a bool pref (mail.force_user_charset) to deal with attachments. + // 1) If true - libmime does NO conversion and just passes it through to raptor + // 2) If false, then we try to use the charset of the part and if not available, + // the charset of the root message + // + msd->options->m_prefBranch->GetBoolPref("mail.force_user_charset", &(msd->options->force_user_charset)); + msd->options->m_prefBranch->GetBoolPref("mail.inline_attachments", &(msd->options->show_attachment_inline_p)); + } + /* This pref is written down in with the + opposite sense of what we like to use... */ MIME_VariableWidthPlaintext = !MIME_VariableWidthPlaintext; msd->options->wrap_long_lines_p = MIME_WrapLongLines; @@ -1644,27 +1655,11 @@ mime_bridge_create_display_stream( msd->options->variable_width_plaintext_p = MIME_VariableWidthPlaintext; - // - // Charset overrides takes place here - // - // We have a bool pref (mail.force_user_charset) to deal with attachments. - // 1) If true - libmime does NO conversion and just passes it through to raptor - // 2) If false, then we try to use the charset of the part and if not available, - // the charset of the root message - // - msd->options->force_user_charset = PR_FALSE; - - if (msd->options->prefs) - msd->options->prefs->GetBoolPref("mail.force_user_charset", &(msd->options->force_user_charset)); - // If this is a part, then we should emit the HTML to render the data // (i.e. embedded images) if (msd->options->part_to_load && msd->options->format_out != nsMimeOutput::nsMimeMessageBodyDisplay) msd->options->write_html_p = PR_FALSE; - if (msd->options->prefs) - msd->options->prefs->GetBoolPref("mail.inline_attachments", &(msd->options->show_attachment_inline_p)); - obj = mime_new ((MimeObjectClass *)&mimeMessageClass, (MimeHeaders *) NULL, MESSAGE_RFC822); if (!obj) { @@ -2089,8 +2084,8 @@ nsresult GetMailNewsFont(MimeObject *obj, PRBool styleFixed, PRInt32 *fontPixel { nsresult rv = NS_OK; - nsIPref *prefs = GetPrefServiceManager(obj->options); - if (prefs) { + nsIPrefBranch *prefBranch = GetPrefBranch(obj->options); + if (prefBranch) { MimeInlineText *text = (MimeInlineText *) obj; nsCAutoString charset; @@ -2124,13 +2119,21 @@ nsresult GetMailNewsFont(MimeObject *obj, PRBool styleFixed, PRInt32 *fontPixel // get a font size from pref prefStr.Assign(!styleFixed ? "font.size.variable." : "font.size.fixed."); prefStr.Append(fontLang); - rv = prefs->GetIntPref(prefStr.get(), fontPixelSize); + rv = prefBranch->GetIntPref(prefStr.get(), fontPixelSize); if (NS_FAILED(rv)) return rv; + nsCOMPtr prefDefBranch; + nsCOMPtr prefSvc(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + if(prefSvc) + rv = prefSvc->GetDefaultBranch("", getter_AddRefs(prefDefBranch)); + + if(!prefDefBranch) + return rv; + // get original font size PRInt32 originalSize; - rv = prefs->GetDefaultIntPref(prefStr.get(), &originalSize); + rv = prefDefBranch->GetIntPref(prefStr.get(), &originalSize); if (NS_FAILED(rv)) return rv; diff --git a/mailnews/mime/src/mimemoz2.h b/mailnews/mime/src/mimemoz2.h index 4b809101742..2a38afb28ca 100644 --- a/mailnews/mime/src/mimemoz2.h +++ b/mailnews/mime/src/mimemoz2.h @@ -62,7 +62,7 @@ class nsOutputFileStream; extern "C" { #endif /* __cplusplus */ -#include "nsIPref.h" +#include "nsIPrefBranch.h" typedef struct _nsMIMESession nsMIMESession; @@ -195,7 +195,7 @@ extern "C" nsresult mimeEmitterStartHeader(MimeDisplayOptions *opt, PRBool r extern "C" nsresult mimeEmitterUpdateCharacterSet(MimeDisplayOptions *opt, const char *aCharset); /* To Get the connnection to prefs service manager */ -extern "C" nsIPref *GetPrefServiceManager(MimeDisplayOptions *opt); +extern "C" nsIPrefBranch *GetPrefBranch(MimeDisplayOptions *opt); // Get the text converter... mozITXTToHTMLConv *GetTextConverter(MimeDisplayOptions *opt); diff --git a/mailnews/mime/src/mimetext.cpp b/mailnews/mime/src/mimetext.cpp index 20a8771f801..b7a9dd3dcb0 100644 --- a/mailnews/mime/src/mimetext.cpp +++ b/mailnews/mime/src/mimetext.cpp @@ -52,8 +52,11 @@ #include "prmem.h" #include "plstr.h" #include "nsCRT.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" #include "nsIServiceManager.h" +#include "nsIPrefLocalizedString.h" +#include "nsMsgUtils.h" #include "nsMimeTypes.h" #include "nsReadableUtils.h" @@ -88,8 +91,6 @@ MimeInlineTextClassInitialize(MimeInlineTextClass *clazz) return 0; } -static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); - static int MimeInlineText_initialize (MimeObject *obj) { @@ -140,13 +141,14 @@ static int MimeInlineText_initializeCharset(MimeObject *obj) if (!text->charset) { nsresult res; - nsXPIDLString detector_name; text->charsetOverridable = PR_TRUE; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &res)); - if (NS_SUCCEEDED(res)) { - if (NS_SUCCEEDED(prefs->GetLocalizedUnicharPref("intl.charset.detector", getter_Copies(detector_name)))) { + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &res)); + if (NS_SUCCEEDED(res)) + { + nsCOMPtr str; + if (NS_SUCCEEDED(prefBranch->GetComplexValue("intl.charset.detector", NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(str)))) { //only if we can get autodetector name correctly, do we set this to true text->inputAutodetect = PR_TRUE; } @@ -156,19 +158,13 @@ static int MimeInlineText_initializeCharset(MimeObject *obj) text->charset = nsCRT::strdup(obj->options->default_charset); else { - // New change for falling back to a default view charset - nsresult rv; - nsCOMPtr prefs(do_GetService(kPrefServiceCID, &rv)); - if ( NS_SUCCEEDED(rv) && prefs) + if (NS_SUCCEEDED(res)) { nsXPIDLString value; - rv = prefs->GetLocalizedUnicharPref("mailnews.view_default_charset", getter_Copies(value)); - if(NS_SUCCEEDED(rv)) { - text->charset = ToNewUTF8String(value); - } + NS_GetLocalizedUnicharPreferenceWithDefault(prefBranch, "mailnews.view_default_charset", EmptyString(), value); + text->charset = ToNewUTF8String(value); } - - if (!text->charset) + else text->charset = nsCRT::strdup(""); } } diff --git a/mailnews/mime/src/mimethsa.cpp b/mailnews/mime/src/mimethsa.cpp index 1d22833a074..0c9e29f740c 100644 --- a/mailnews/mime/src/mimethsa.cpp +++ b/mailnews/mime/src/mimethsa.cpp @@ -44,6 +44,7 @@ #include "prlog.h" #include "msgCore.h" #include "mimemoz2.h" +#include "nsIPrefBranch.h" #include "nsString.h" #include "nsReadableUtils.h" @@ -161,10 +162,10 @@ printf("buffer: -%s-\n", NS_LossyConvertUCS2toASCII(*textHTMLSan->complete_buffe #endif char* allowedTags = 0; - nsIPref *prefs = GetPrefServiceManager(obj->options); - if (prefs) - prefs->CopyCharPref("mailnews.display.html_sanitizer.allowed_tags", - &allowedTags); + nsIPrefBranch *prefBranch = GetPrefBranch(obj->options); + if (prefBranch) + prefBranch->GetCharPref("mailnews.display.html_sanitizer.allowed_tags", + &allowedTags); #ifdef DEBUG_BenB printf(" E2\n"); diff --git a/mailnews/mime/src/mimetpfl.cpp b/mailnews/mime/src/mimetpfl.cpp index bb67ded15a9..00ec878d5ce 100644 --- a/mailnews/mime/src/mimetpfl.cpp +++ b/mailnews/mime/src/mimetpfl.cpp @@ -44,7 +44,7 @@ #include "nsString.h" #include "nsReadableUtils.h" #include "nsMimeStringResources.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" #include "nsIServiceManager.h" #include "mimemoz2.h" #include "prprf.h" @@ -133,14 +133,14 @@ MimeInlineTextPlainFlowed_parse_begin (MimeObject *obj) text->mQuotedStyleSetting = 0; // mail.quoted_style text->mCitationColor = nsnull; // mail.citation_color - nsIPref *prefs = GetPrefServiceManager(obj->options); - if (prefs) + nsIPrefBranch *prefBranch = GetPrefBranch(obj->options); + if (prefBranch) { - prefs->GetIntPref("mail.quoted_size", &(text->mQuotedSizeSetting)); - prefs->GetIntPref("mail.quoted_style", &(text->mQuotedStyleSetting)); - prefs->CopyCharPref("mail.citation_color", &(text->mCitationColor)); - nsresult rv = prefs->GetBoolPref("mail.fixed_width_messages", - &(exdata->fixedwidthfont)); + prefBranch->GetIntPref("mail.quoted_size", &(text->mQuotedSizeSetting)); + prefBranch->GetIntPref("mail.quoted_style", &(text->mQuotedStyleSetting)); + prefBranch->GetCharPref("mail.citation_color", &(text->mCitationColor)); + nsresult rv = prefBranch->GetBoolPref("mail.fixed_width_messages", + &(exdata->fixedwidthfont)); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get pref"); // Check at least the success of one } diff --git a/mailnews/mime/src/mimetpla.cpp b/mailnews/mime/src/mimetpla.cpp index 9e0ed262222..2a81a3cf82a 100644 --- a/mailnews/mime/src/mimetpla.cpp +++ b/mailnews/mime/src/mimetpla.cpp @@ -49,7 +49,7 @@ #include "nsMimeStringResources.h" #include "mimemoz2.h" #include "nsIServiceManager.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" #include "prprf.h" #include "nsMsgI18N.h" @@ -151,14 +151,14 @@ MimeInlineTextPlain_parse_begin (MimeObject *obj) text->mCitationColor = nsnull; // mail.citation_color PRBool graphicalQuote = PR_TRUE; // mail.quoted_graphical - nsIPref *prefs = GetPrefServiceManager(obj->options); - if (prefs) + nsIPrefBranch *prefBranch = GetPrefBranch(obj->options); + if (prefBranch) { - prefs->GetIntPref("mail.quoted_size", &(text->mQuotedSizeSetting)); - prefs->GetIntPref("mail.quoted_style", &(text->mQuotedStyleSetting)); - prefs->CopyCharPref("mail.citation_color", &(text->mCitationColor)); - prefs->GetBoolPref("mail.quoted_graphical", &graphicalQuote); - prefs->GetBoolPref("mail.quoteasblock", &(text->mBlockquoting)); + prefBranch->GetIntPref("mail.quoted_size", &(text->mQuotedSizeSetting)); + prefBranch->GetIntPref("mail.quoted_style", &(text->mQuotedStyleSetting)); + prefBranch->GetCharPref("mail.citation_color", &(text->mCitationColor)); + prefBranch->GetBoolPref("mail.quoted_graphical", &graphicalQuote); + prefBranch->GetBoolPref("mail.quoteasblock", &(text->mBlockquoting)); } if (!rawPlainText) diff --git a/mailnews/mime/src/modlmime.h b/mailnews/mime/src/modlmime.h index e527f979fc0..4607dc2dc3c 100644 --- a/mailnews/mime/src/modlmime.h +++ b/mailnews/mime/src/modlmime.h @@ -48,7 +48,7 @@ #include "nsIMimeStreamConverter.h" #include "nsIUnicodeDecoder.h" #include "nsIUnicodeEncoder.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" #include "mozITXTToHTMLConv.h" #define MIME_DRAFTS @@ -166,7 +166,7 @@ public: MimeDisplayOptions(); virtual ~MimeDisplayOptions(); mozITXTToHTMLConv *conv; // For text conversion... - nsIPref *prefs; /* Connnection to prefs service manager */ + nsCOMPtr m_prefBranch; /* prefBranch-service */ nsMimeOutputType format_out; // The format out type nsCString charsetForCachedInputDecoder; nsCOMPtr m_inputCharsetToUnicodeDecoder;