From 4db91e56449ac8e97e7c23e39d2deda510a0de53 Mon Sep 17 00:00:00 2001 From: "ducarroz%netscape.com" Date: Thu, 1 Jul 1999 21:56:54 +0000 Subject: [PATCH] Look for the default value when a pref doesn't exist. Fix problem with actual code, we passed the wrong name to GetDefaultName. --- mailnews/base/util/nsMsgIdentity.cpp | 74 +++++++++++++++++++--- mailnews/base/util/nsMsgIdentity.h | 8 ++- mailnews/base/util/nsMsgIncomingServer.cpp | 6 +- 3 files changed, 74 insertions(+), 14 deletions(-) diff --git a/mailnews/base/util/nsMsgIdentity.cpp b/mailnews/base/util/nsMsgIdentity.cpp index 784f84389e1b..352b6f6228fe 100644 --- a/mailnews/base/util/nsMsgIdentity.cpp +++ b/mailnews/base/util/nsMsgIdentity.cpp @@ -59,6 +59,14 @@ nsMsgIdentity::getPrefName(const char *identityKey, return PR_smprintf("mail.identity.%s.%s", identityKey, prefName); } +// this will be slightly faster than the above, and allows +// the "default" identity preference root to be set in one place +char * +nsMsgIdentity::getDefaultPrefName(const char *fullPrefName) +{ + return PR_smprintf("mail.identity.default.%s", fullPrefName); +} + /* The following are equivalent to the nsIPref's Get/CopyXXXPref except they construct the preference name with the above function */ @@ -66,13 +74,28 @@ nsresult nsMsgIdentity::getBoolPref(const char *prefname, PRBool *val) { - char *prefName = getPrefName(m_identityKey, prefname); - nsresult rv = m_prefs->GetBoolPref(prefName, val); + char *fullPrefName = getPrefName(m_identityKey, prefname); + nsresult rv = m_prefs->GetBoolPref(fullPrefName, val); + PR_Free(fullPrefName); + + if (NS_FAILED(rv)) + rv = getDefaultBoolPref(prefname, val); + + return rv; +} + +nsresult +nsMsgIdentity::getDefaultBoolPref(const char *prefname, + PRBool *val) { + + char *fullPrefName = getDefaultPrefName(prefname); + nsresult rv = m_prefs->GetBoolPref(fullPrefName, val); + PR_Free(fullPrefName); + if (NS_FAILED(rv)) { *val = PR_FALSE; rv = NS_OK; } - PR_Free(prefName); return rv; } @@ -90,13 +113,28 @@ nsresult nsMsgIdentity::getCharPref(const char *prefname, char **val) { - char *prefName = getPrefName(m_identityKey, prefname); - nsresult rv = m_prefs->CopyCharPref(prefName, val); + char *fullPrefName = getPrefName(m_identityKey, prefname); + nsresult rv = m_prefs->CopyCharPref(fullPrefName, val); + PR_Free(fullPrefName); + + if (NS_FAILED(rv)) + rv = getDefaultCharPref(prefname, val); + + return rv; +} + +nsresult +nsMsgIdentity::getDefaultCharPref(const char *prefname, + char **val) { + + char *fullPrefName = getDefaultPrefName(prefname); + nsresult rv = m_prefs->CopyCharPref(fullPrefName, val); + PR_Free(fullPrefName); + if (NS_FAILED(rv)) { - *val=nsnull; + *val = nsnull; // null is ok to return here rv = NS_OK; } - PR_Free(prefName); return rv; } @@ -114,13 +152,29 @@ nsresult nsMsgIdentity::getIntPref(const char *prefname, PRInt32 *val) { - char *prefName = getPrefName(m_identityKey, prefname); - nsresult rv = m_prefs->GetIntPref(prefName, val); + char *fullPrefName = getPrefName(m_identityKey, prefname); + nsresult rv = m_prefs->GetIntPref(fullPrefName, val); + PR_Free(fullPrefName); + + if (NS_FAILED(rv)) + rv = getDefaultIntPref(prefname, val); + + return rv; +} + +nsresult +nsMsgIdentity::getDefaultIntPref(const char *prefname, + PRInt32 *val) { + + char *fullPrefName = getDefaultPrefName(prefname); + nsresult rv = m_prefs->GetIntPref(fullPrefName, val); + PR_Free(fullPrefName); + if (NS_FAILED(rv)) { *val = 0; rv = NS_OK; } - PR_Free(prefName); + return rv; } diff --git a/mailnews/base/util/nsMsgIdentity.h b/mailnews/base/util/nsMsgIdentity.h index 97ccc20e1b9e..4d84879d1168 100644 --- a/mailnews/base/util/nsMsgIdentity.h +++ b/mailnews/base/util/nsMsgIdentity.h @@ -98,12 +98,18 @@ private: nsIPref *m_prefs; protected: - static char *getPrefName(const char *identityKey, const char *pref); + char *getPrefName(const char *identityKey, const char *pref); + char *getDefaultPrefName(const char *pref); nsresult getCharPref(const char *pref, char **); + nsresult getDefaultCharPref(const char *pref, char **); nsresult setCharPref(const char *pref, char *); + nsresult getBoolPref(const char *pref, PRBool *); + nsresult getDefaultBoolPref(const char *pref, PRBool *); nsresult setBoolPref(const char *pref, PRBool); + nsresult getIntPref(const char *pref, PRInt32 *); + nsresult getDefaultIntPref(const char *pref, PRInt32 *); nsresult setIntPref(const char *pref, PRInt32); }; diff --git a/mailnews/base/util/nsMsgIncomingServer.cpp b/mailnews/base/util/nsMsgIncomingServer.cpp index fa65e9c31e6a..1d22f89aae7c 100644 --- a/mailnews/base/util/nsMsgIncomingServer.cpp +++ b/mailnews/base/util/nsMsgIncomingServer.cpp @@ -128,7 +128,7 @@ nsresult nsMsgIncomingServer::getDefaultBoolPref(const char *prefname, PRBool *val) { - char *fullPrefName = getDefaultPrefName(m_serverKey); + char *fullPrefName = getDefaultPrefName(prefname); nsresult rv = m_prefs->GetBoolPref(fullPrefName, val); PR_Free(fullPrefName); @@ -178,7 +178,7 @@ nsresult nsMsgIncomingServer::getDefaultIntPref(const char *prefname, PRInt32 *val) { - char *fullPrefName = getDefaultPrefName(m_serverKey); + char *fullPrefName = getDefaultPrefName(prefname); nsresult rv = m_prefs->GetIntPref(fullPrefName, val); PR_Free(fullPrefName); @@ -228,7 +228,7 @@ nsresult nsMsgIncomingServer::getDefaultCharPref(const char *prefname, char **val) { - char *fullPrefName = getDefaultPrefName(m_serverKey); + char *fullPrefName = getDefaultPrefName(prefname); nsresult rv = m_prefs->CopyCharPref(fullPrefName, val); PR_Free(fullPrefName);