Bug 226005 MailNews should use the newer nsIPrefService APIs instead of nsIPref (final part). r=bienvenu,sr=mscott

This commit is contained in:
bugzilla%standard8.demon.co.uk 2005-11-18 13:46:22 +00:00
Родитель d1e0ed389f
Коммит 458d96e474
2 изменённых файлов: 64 добавлений и 55 удалений

Просмотреть файл

@ -62,13 +62,11 @@
// lots of includes required for the nsPrefMigration.cpp code that we copied:
#include "nsICharsetConverterManager.h"
#include "nsIPlatformCharset.h"
#include "nsIPref.h"
#include "nsIFileSpec.h"
#include "nsFileSpec.h"
#include "nsFileStream.h"
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
#define MIGRATION_PROPERTIES_URL "chrome://messenger/locale/migration/migration.properties"
@ -320,7 +318,6 @@ NS_IMETHODIMP
nsDogbertProfileMigrator::Migrate(PRUint16 aItems, nsIProfileStartup* aStartup, const PRUnichar* aProfile)
{
nsresult rv = NS_OK;
PRBool aReplace = aStartup ? PR_TRUE : PR_FALSE;
if (!mTargetProfile) {
GetProfilePath(aStartup, mTargetProfile);
@ -545,7 +542,9 @@ nsresult nsDogbertProfileMigrator::CopyPreferences()
{
// Load the source pref file
mPrefs = do_GetService(kPrefServiceCID);
nsresult rv;
mPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString oldProfDirStr;
nsCAutoString newProfDirStr;
@ -637,11 +636,14 @@ nsDogbertProfileMigrator::ProcessPrefsCallback(const char* oldProfilePathStr, co
PRInt64 DriveID[MAX_DRIVES];
PRUint32 SpaceRequired[MAX_DRIVES];
#if defined(NS_DEBUG)
printf("*Entered Actual Migration routine*\n");
#endif
nsCOMPtr<nsIPrefService> prefService = do_QueryInterface(mPrefs, &rv);
NS_ENSURE_SUCCESS(rv, rv);
for (int i=0; i < MAX_DRIVES; i++)
{
DriveID[i] = LL_Zero();
@ -709,10 +711,10 @@ nsDogbertProfileMigrator::ProcessPrefsCallback(const char* oldProfilePathStr, co
if (NS_FAILED(rv)) return rv;
//Clear the prefs in case a previous set was read in.
mPrefs->ResetPrefs();
prefService->ResetPrefs();
//Now read the prefs from the prefs file in the system directory
mPrefs->ReadUserPrefs(m_prefsFile);
prefService->ReadUserPrefs(m_prefsFile);
// Start computing the sizes required for migration
//
@ -939,11 +941,11 @@ nsDogbertProfileMigrator::ProcessPrefsCallback(const char* oldProfilePathStr, co
NS_FileSpecToIFile(&newPOPMailPathSpec,
getter_AddRefs(newPOPMailPathFile));
rv = mPrefs->SetFileXPref(PREF_MAIL_DIRECTORY, newPOPMailPathFile);
rv = mPrefs->SetComplexValue(PREF_MAIL_DIRECTORY, NS_GET_IID(nsILocalFile), newPOPMailPathFile);
if (NS_FAILED(rv)) return rv;
}
mPrefs->CopyCharPref(PREF_NETWORK_HOSTS_POP_SERVER, &popServerName);
mPrefs->GetCharPref(PREF_NETWORK_HOSTS_POP_SERVER, &popServerName);
nsCAutoString popServerNamewithoutPort(popServerName);
PRInt32 colonPos = popServerNamewithoutPort.FindChar(':');
@ -994,7 +996,7 @@ nsDogbertProfileMigrator::ProcessPrefsCallback(const char* oldProfilePathStr, co
NS_FileSpecToIFile(&newIMAPLocalMailPathSpec,
getter_AddRefs(newIMAPLocalMailPathFile));
rv = mPrefs->SetFileXPref(PREF_MAIL_DIRECTORY, newIMAPLocalMailPathFile);
rv = mPrefs->SetComplexValue(PREF_MAIL_DIRECTORY, NS_GET_IID(nsILocalFile), newIMAPLocalMailPathFile);
if (NS_FAILED(rv)) return rv;
}
@ -1034,7 +1036,7 @@ nsDogbertProfileMigrator::ProcessPrefsCallback(const char* oldProfilePathStr, co
NS_FileSpecToIFile(&newIMAPMailPathSpec,
getter_AddRefs(newIMAPMailPathFile));
rv = mPrefs->SetFileXPref(PREF_MAIL_IMAP_ROOT_DIR, newIMAPMailPathFile);
rv = mPrefs->SetComplexValue(PREF_MAIL_IMAP_ROOT_DIR, NS_GET_IID(nsILocalFile), newIMAPMailPathFile);
if (NS_FAILED(rv)) return rv;
}
}
@ -1049,7 +1051,7 @@ nsDogbertProfileMigrator::ProcessPrefsCallback(const char* oldProfilePathStr, co
NS_FileSpecToIFile(&oldIMAPLocalMailPathSpec,
getter_AddRefs(oldIMAPLocalMailPathFile));
rv = mPrefs->SetFileXPref(PREF_MAIL_DIRECTORY, oldIMAPLocalMailPathFile);
rv = mPrefs->SetComplexValue(PREF_MAIL_DIRECTORY, NS_GET_IID(nsILocalFile), oldIMAPLocalMailPathFile);
if (NS_FAILED(rv)) return rv;
}
{
@ -1061,7 +1063,7 @@ nsDogbertProfileMigrator::ProcessPrefsCallback(const char* oldProfilePathStr, co
NS_FileSpecToIFile(&oldIMAPMailPathSpec,
getter_AddRefs(oldIMAPMailPathFile));
rv = mPrefs->SetFileXPref(PREF_MAIL_IMAP_ROOT_DIR, oldIMAPMailPathFile);
rv = mPrefs->SetComplexValue(PREF_MAIL_IMAP_ROOT_DIR, NS_GET_IID(nsILocalFile), oldIMAPMailPathFile);
if (NS_FAILED(rv)) return rv;
}
}
@ -1096,7 +1098,7 @@ nsDogbertProfileMigrator::ProcessPrefsCallback(const char* oldProfilePathStr, co
NS_FileSpecToIFile(&newMOVEMAILPathSpec,
getter_AddRefs(newMOVEMAILPathFile));
rv = mPrefs->SetFileXPref(PREF_MAIL_DIRECTORY, newMOVEMAILPathFile);
rv = mPrefs->SetComplexValue(PREF_MAIL_DIRECTORY, NS_GET_IID(nsILocalFile), newMOVEMAILPathFile);
if (NS_FAILED(rv)) return rv;
}
@ -1147,7 +1149,7 @@ nsDogbertProfileMigrator::ProcessPrefsCallback(const char* oldProfilePathStr, co
NS_FileSpecToIFile(&newNewsPathSpec,
getter_AddRefs(newNewsPathFile));
rv = mPrefs->SetFileXPref(PREF_NEWS_DIRECTORY, newNewsPathFile);
rv = mPrefs->SetComplexValue(PREF_NEWS_DIRECTORY, NS_GET_IID(nsILocalFile), newNewsPathFile);
if (NS_FAILED(rv)) return rv;
}
@ -1270,9 +1272,9 @@ nsDogbertProfileMigrator::ProcessPrefsCallback(const char* oldProfilePathStr, co
rv = newPrefsFile->AppendNative(NS_LITERAL_CSTRING(PREF_FILE_NAME_IN_5x));
if (NS_FAILED(rv)) return rv;
rv=mPrefs->SavePrefFile(newPrefsFile);
rv = prefService->SavePrefFile(newPrefsFile);
if (NS_FAILED(rv)) return rv;
rv=mPrefs->ResetPrefs();
rv = prefService->ResetPrefs();
if (NS_FAILED(rv)) return rv;
PRBool flagExists = PR_FALSE;
@ -1702,7 +1704,7 @@ nsresult nsDogbertProfileMigrator::RenameAndMove4xPopFile(nsIFileSpec * profileP
nsFileSpec migratedPopDirectory;
rv = profilePath->GetFileSpec(&migratedPopDirectory);
migratedPopDirectory += NEW_MAIL_DIR_NAME;
mPrefs->CopyCharPref(PREF_NETWORK_HOSTS_POP_SERVER, &popServerName);
mPrefs->GetCharPref(PREF_NETWORK_HOSTS_POP_SERVER, &popServerName);
migratedPopDirectory += popServerName;
PR_FREEIF(popServerName);
@ -1769,7 +1771,7 @@ nsresult nsDogbertProfileMigrator::RenameAndMove4xImapFilterFiles(nsIFileSpec *
nsresult rv;
char *hostList=nsnull;
rv = mPrefs->CopyCharPref(PREF_4X_NETWORK_HOSTS_IMAP_SERVER, &hostList);
rv = mPrefs->GetCharPref(PREF_4X_NETWORK_HOSTS_IMAP_SERVER, &hostList);
if (NS_FAILED(rv)) return rv;
if (!hostList || !*hostList) return NS_OK;
@ -1828,8 +1830,12 @@ nsresult nsDogbertProfileMigrator::GetPremigratedFilePref(const char *pref_name,
if (!pref_name) return NS_ERROR_FAILURE;
char premigration_pref[MAX_PREF_LEN];
PR_snprintf(premigration_pref,MAX_PREF_LEN,"%s%s",PREMIGRATION_PREFIX,pref_name);
rv = mPrefs->GetFilePref((const char *)premigration_pref, path);
return rv;
nsCOMPtr<nsILocalFile> preMigrationFile;
rv = mPrefs->GetComplexValue((const char *)premigration_pref, NS_GET_IID(nsILocalFile), getter_AddRefs(preMigrationFile));
NS_ENSURE_SUCCESS(rv, rv);
return NS_NewFileSpecFromIFile(preMigrationFile, path);;
}
#endif /* NEED_TO_COPY_AND_RENAME_NEWSRC_FILES */
@ -1963,7 +1969,7 @@ nsDogbertProfileMigrator::GetDirFromPref(nsIFileSpec * oldProfilePath, nsIFileSp
nsCOMPtr <nsIFileSpec> oldPrefPath;
nsXPIDLCString oldPrefPathStr;
rv = mPrefs->CopyCharPref(pref,getter_Copies(oldPrefPathStr));
rv = mPrefs->GetCharPref(pref, getter_Copies(oldPrefPathStr));
if (NS_FAILED(rv)) return rv;
// the default on the mac was "". doing GetFileXPref on that would return
@ -1974,7 +1980,7 @@ nsDogbertProfileMigrator::GetDirFromPref(nsIFileSpec * oldProfilePath, nsIFileSp
if (NS_FAILED(rv)) return rv;
nsCOMPtr <nsILocalFile> oldPrefPathFile;
rv = mPrefs->GetFileXPref(pref, getter_AddRefs(oldPrefPathFile));
rv = mPrefs->GetComplexValue(pref, NS_GET_IID(nsILocalFile), getter_AddRefs(oldPrefPathFile));
if (NS_FAILED(rv)) return rv;
// convert nsILocalFile to nsIFileSpec
@ -2078,7 +2084,7 @@ nsresult nsDogbertProfileMigrator::SetPremigratedFilePref(const char *pref_name,
NS_ASSERTION(exists, "the path does not exist. see bug #55444");
if (!exists) return NS_OK;
rv = mPrefs->SetFileXPref((const char *)premigration_pref, pathFile);
rv = mPrefs->SetComplexValue((const char *)premigration_pref, NS_GET_IID(nsILocalFile), pathFile);
return rv;
}
@ -2221,14 +2227,14 @@ static nsresult ConvertStringToUTF8(const char* aCharset, const char* inString,
return rv;
}
nsresult ConvertPrefToUTF8(const char *prefname, nsIPref *prefs, const char* charSet)
nsresult ConvertPrefToUTF8(const char *prefname, nsIPrefBranch *prefs, const char* charSet)
{
nsresult rv;
if (!prefname || !prefs) return NS_ERROR_FAILURE;
nsXPIDLCString prefval;
rv = prefs->CopyCharPref(prefname, getter_Copies(prefval));
rv = prefs->GetCharPref(prefname, getter_Copies(prefval));
if (NS_FAILED(rv)) return rv;
if (prefval.IsEmpty())
@ -2256,40 +2262,46 @@ static PRBool charEndsWith(const char *str, const char *endStr)
return PR_FALSE;
}
static void fontPrefEnumerationFunction(const char *name, void *data)
static void getFontPrefs(nsIPrefBranch *prefs, nsCStringArray *data)
{
nsCStringArray *arr;
arr = (nsCStringArray *)data;
if (charEndsWith(name,".fixed_font") || charEndsWith(name,".prop_font")) {
nsCString str(name);
arr->AppendCString(str);
PRUint32 count, i;
char** childPrefs;
prefs->GetChildList("intl.font", &count, &childPrefs);
for (i = 0; i < count; ++i)
{
if (charEndsWith(childPrefs[i], ".fixed_font") || charEndsWith(childPrefs[i], ".prop_font"))
data->AppendCString(nsDependentCString(childPrefs[i]));
}
}
static void ldapPrefEnumerationFunction(const char *name, void *data)
static void getLdapPrefs(nsIPrefBranch *prefs, nsCStringArray *data)
{
nsCStringArray *arr;
arr = (nsCStringArray *)data;
// we only want to convert "ldap_2.servers.*.description"
if (charEndsWith(name,".description")) {
nsCString str(name);
arr->AppendCString(str);
PRUint32 count, i;
char** childPrefs;
prefs->GetChildList("ldap_2.servers", &count, &childPrefs);
for (i = 0; i < count; ++i)
{
// we only want to convert "ldap_2.servers.*.description"
if (charEndsWith(childPrefs[i], ".description"))
data->AppendCString(nsDependentCString(childPrefs[i]));
}
}
static void vCardPrefEnumerationFunction(const char *name, void *data)
static void getVCardPrefs(nsIPrefBranch *prefs, nsCStringArray *data)
{
nsCStringArray *arr;
arr = (nsCStringArray *)data;
PRUint32 count, i;
char** childPrefs;
prefs->GetChildList("mail.identity.vcard", &count, &childPrefs);
// the 4.x vCard prefs might need converting
nsCString str(name);
arr->AppendCString(str);
for (i = 0; i < count; ++i)
data->AppendCString(nsDependentCString(childPrefs[i]));
}
typedef struct {
nsIPref *prefs;
nsIPrefBranch *prefs;
const char* charSet;
} PrefEnumerationClosure;
@ -2307,10 +2319,9 @@ nsresult nsPrefConverter::ConvertPrefsToUTF8()
nsresult rv;
nsCStringArray prefsToMigrate;
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID, &rv));
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if(NS_FAILED(rv)) return rv;
if (!prefs) return NS_ERROR_FAILURE;
nsCAutoString charSet;
rv = GetPlatformCharset(charSet);
@ -2322,9 +2333,9 @@ nsresult nsPrefConverter::ConvertPrefsToUTF8()
prefsToMigrate.AppendCString(prefnameStr);
}
prefs->EnumerateChildren("intl.font",fontPrefEnumerationFunction,(void *)(&prefsToMigrate));
prefs->EnumerateChildren("ldap_2.servers",ldapPrefEnumerationFunction,(void *)(&prefsToMigrate));
prefs->EnumerateChildren("mail.identity.vcard",vCardPrefEnumerationFunction,(void *)(&prefsToMigrate));
getFontPrefs(prefs, &prefsToMigrate);
getLdapPrefs(prefs, &prefsToMigrate);
getVCardPrefs(prefs, &prefsToMigrate);
PrefEnumerationClosure closure;

Просмотреть файл

@ -46,11 +46,9 @@
#include "nsString.h"
#include "nsITimer.h"
#include "nsIPref.h"
#include "nsIPrefBranch.h"
class nsIFile;
class nsIPrefBranch;
class nsIPrefService;
class nsIFileSpec;
class nsFileSpec;
@ -108,7 +106,7 @@ private:
PRInt64 mMaxProgress;
PRInt64 mCurrentProgress;
nsCOMPtr<nsIPref> mPrefs;
nsCOMPtr<nsIPrefBranch> mPrefs;
nsCOMPtr<nsILocalFile> m_prefsFile;
protected:
nsresult ProcessPrefsCallback(const char* oldProfilePathStr, const char * newProfilePathStr);