diff --git a/mozilla/mailnews/base/public/nsIMsgMailSession.idl b/mozilla/mailnews/base/public/nsIMsgMailSession.idl index e4bb2e1789c..56ad06c4070 100644 --- a/mozilla/mailnews/base/public/nsIMsgMailSession.idl +++ b/mozilla/mailnews/base/public/nsIMsgMailSession.idl @@ -53,6 +53,7 @@ #include "nsIAtom.idl" interface nsIMsgWindow; +interface nsIFile; [scriptable, uuid(D5124440-D59E-11d2-806A-006008128C4E)] interface nsIMsgMailSession : nsISupports { @@ -67,5 +68,6 @@ interface nsIMsgMailSession : nsISupports { boolean IsFolderOpenInWindow(in nsIMsgFolder folder); string ConvertMsgURIToMsgURL(in string aURI, in nsIMsgWindow aMsgWindow); + nsIFile getDataFilesDir(in string dirName); }; diff --git a/mozilla/mailnews/base/src/nsMsgMailSession.cpp b/mozilla/mailnews/base/src/nsMsgMailSession.cpp index 116c2295717..4f09d48d999 100644 --- a/mozilla/mailnews/base/src/nsMsgMailSession.cpp +++ b/mozilla/mailnews/base/src/nsMsgMailSession.cpp @@ -46,6 +46,9 @@ #include "nsIURI.h" #include "nsXPIDLString.h" #include "nsIMsgAccountManager.h" +#include "nsIChromeRegistry.h" +#include "nsIDirectoryService.h" +#include "nsAppDirectoryServiceDefs.h" NS_IMPL_THREADSAFE_ADDREF(nsMsgMailSession) NS_IMPL_THREADSAFE_RELEASE(nsMsgMailSession) @@ -452,3 +455,77 @@ nsMsgMailSession::ConvertMsgURIToMsgURL(const char *aURI, nsIMsgWindow *aMsgWind } return rv; } + +//---------------------------------------------------------------------------------------- +// GetSelectedLocaleDataDir - If a locale is selected, appends the selected locale to the +// defaults data dir and returns that new defaults data dir +//---------------------------------------------------------------------------------------- +nsresult +nsMsgMailSession::GetSelectedLocaleDataDir(nsIFile *defaultsDir) +{ + NS_ENSURE_ARG_POINTER(defaultsDir); + + nsresult rv; + PRBool baseDirExists = PR_FALSE; + rv = defaultsDir->Exists(&baseDirExists); + NS_ENSURE_SUCCESS(rv,rv); + + if (baseDirExists) { + nsCOMPtr chromeRegistry = do_GetService("@mozilla.org/chrome/chrome-registry;1", &rv); + if (NS_SUCCEEDED(rv)) { + nsXPIDLString localeName; + rv = chromeRegistry->GetSelectedLocale(NS_LITERAL_STRING("global-region").get(), getter_Copies(localeName)); + + if (NS_SUCCEEDED(rv) && !localeName.IsEmpty()) { + PRBool localeDirExists = PR_FALSE; + nsCOMPtr localeDataDir; + + rv = defaultsDir->Clone(getter_AddRefs(localeDataDir)); + NS_ENSURE_SUCCESS(rv,rv); + + rv = localeDataDir->AppendUnicode(localeName); + NS_ENSURE_SUCCESS(rv,rv); + + rv = localeDataDir->Exists(&localeDirExists); + NS_ENSURE_SUCCESS(rv,rv); + + if (localeDirExists) { + // use locale provider instead + rv = defaultsDir->AppendUnicode(localeName); + NS_ENSURE_SUCCESS(rv,rv); + } + } + } + } + return NS_OK; +} + +//---------------------------------------------------------------------------------------- +// GetDataFilesDir - Gets the application's default folder and then appends the +// subdirectory named passed in as param dirName. If there is a seleccted +// locale, will append that to the dir path before returning the value +//---------------------------------------------------------------------------------------- +NS_IMETHODIMP +nsMsgMailSession::GetDataFilesDir(const char* dirName, nsIFile **dataFilesDir) +{ + NS_ENSURE_ARG_POINTER(dataFilesDir); + + nsresult rv; + nsCOMPtr directoryService = + do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv,rv); + + nsCOMPtr defaultsDir; + rv = directoryService->Get(NS_APP_DEFAULTS_50_DIR, + NS_GET_IID(nsIFile), + getter_AddRefs(defaultsDir)); + NS_ENSURE_SUCCESS(rv,rv); + + rv = defaultsDir->Append(dirName); + if (NS_SUCCEEDED(rv)) + rv = GetSelectedLocaleDataDir(defaultsDir); + + NS_IF_ADDREF(*dataFilesDir = defaultsDir); + + return rv; +} diff --git a/mozilla/mailnews/base/src/nsMsgMailSession.h b/mozilla/mailnews/base/src/nsMsgMailSession.h index f8bdd8847ca..524031d5886 100644 --- a/mozilla/mailnews/base/src/nsMsgMailSession.h +++ b/mozilla/mailnews/base/src/nsMsgMailSession.h @@ -66,6 +66,8 @@ public: NS_DECL_NSIFOLDERLISTENER nsresult Init(); + nsresult GetSelectedLocaleDataDir(nsIFile *defaultsDir); + protected: nsCOMPtr mListeners; nsUInt32Array mListenerNotifyFlags; diff --git a/mozilla/mailnews/base/src/nsMsgServiceProvider.cpp b/mozilla/mailnews/base/src/nsMsgServiceProvider.cpp index dff2249d4f1..96918b342d5 100644 --- a/mozilla/mailnews/base/src/nsMsgServiceProvider.cpp +++ b/mozilla/mailnews/base/src/nsMsgServiceProvider.cpp @@ -45,16 +45,15 @@ #include "nsIRDFService.h" #include "nsIRDFRemoteDataSource.h" -#include "nsIChromeRegistry.h" // for chrome registry #include "nsIFileChannel.h" #include "nsIFileSpec.h" -#include "nsAppDirectoryServiceDefs.h" #include "nsNetUtil.h" +#include "nsIMsgMailSession.h" +#include "nsMsgBaseCID.h" static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID); static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID); -static NS_DEFINE_CID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID); nsMsgServiceProviderService::nsMsgServiceProviderService() { @@ -79,11 +78,13 @@ nsMsgServiceProviderService::Init() mInnerDataSource = do_CreateInstance(kRDFCompositeDataSourceCID, &rv); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr dataFilesDir; - rv = NS_GetSpecialDirectory(NS_APP_DEFAULTS_50_DIR, getter_AddRefs(dataFilesDir)); - NS_ENSURE_SUCCESS(rv,rv); + nsCOMPtr mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); - rv = dataFilesDir->Append("isp"); + // Get defaults directory for isp files. MailSession service appends 'isp' to the + // the app defaults folder and returns it. Locale will be added to the path, if there is one. + nsCOMPtr dataFilesDir; + rv = mailSession->GetDataFilesDir("isp", getter_AddRefs(dataFilesDir)); NS_ENSURE_SUCCESS(rv,rv); // test if there is a locale provider @@ -91,27 +92,6 @@ nsMsgServiceProviderService::Init() rv = dataFilesDir->Exists(&isexists); NS_ENSURE_SUCCESS(rv,rv); if (isexists) { - nsCOMPtr chromeRegistry = do_GetService(kChromeRegistryCID, &rv); - if (NS_SUCCEEDED(rv)) { - nsXPIDLString lc_name; - rv = chromeRegistry->GetSelectedLocale(NS_LITERAL_STRING("global-region").get(), getter_Copies(lc_name)); - if (NS_SUCCEEDED(rv) && (const PRUnichar *)lc_name && nsCRT::strlen((const PRUnichar *)lc_name)) { - - nsCOMPtr tmpdataFilesDir; - rv = dataFilesDir->Clone(getter_AddRefs(tmpdataFilesDir)); - NS_ENSURE_SUCCESS(rv,rv); - rv = tmpdataFilesDir->AppendUnicode(lc_name); - NS_ENSURE_SUCCESS(rv,rv); - rv = tmpdataFilesDir->Exists(&isexists); - NS_ENSURE_SUCCESS(rv,rv); - if (isexists) { - // use locale provider instead - rv = dataFilesDir->AppendUnicode(lc_name); - NS_ENSURE_SUCCESS(rv,rv); - } - } - } - // now enumerate every file in the directory, and suck it into the datasource PRBool hasMore = PR_FALSE; nsCOMPtr dirIterator; diff --git a/mozilla/mailnews/local/src/nsNoIncomingServer.cpp b/mozilla/mailnews/local/src/nsNoIncomingServer.cpp index 816230e7fd0..3d941678950 100644 --- a/mozilla/mailnews/local/src/nsNoIncomingServer.cpp +++ b/mozilla/mailnews/local/src/nsNoIncomingServer.cpp @@ -50,11 +50,8 @@ #include "nsMsgLocalCID.h" #include "nsMsgFolderFlags.h" #include "nsIMsgLocalMailFolder.h" -#include "nsIChromeRegistry.h" -#include "nsIDirectoryService.h" -#include "nsAppDirectoryServiceDefs.h" - -static NS_DEFINE_CID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID); +#include "nsIMsgMailSession.h" +#include "nsMsgBaseCID.h" NS_IMPL_ISUPPORTS_INHERITED2(nsNoIncomingServer, nsMsgIncomingServer, @@ -108,48 +105,14 @@ NS_IMETHODIMP nsNoIncomingServer::CopyDefaultMessages(const char *folderNameOnDi PRBool exists; if (!folderNameOnDisk || !parentDir) return NS_ERROR_NULL_POINTER; - nsCOMPtr defaultMessagesFile; - rv = NS_GetSpecialDirectory(NS_APP_DEFAULTS_50_DIR, getter_AddRefs(defaultMessagesFile)); - if (NS_FAILED(rv)) return rv; + nsCOMPtr mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); - // bin/defaults better exist - rv = defaultMessagesFile->Exists(&exists); - if (NS_FAILED(rv)) return rv; - if (!exists) return NS_ERROR_FAILURE; - - // bin/defaults/messenger doesn't have to exist - // if not, return. - rv = defaultMessagesFile->Append("messenger"); - if (NS_FAILED(rv)) return rv; - rv = defaultMessagesFile->Exists(&exists); - if (NS_FAILED(rv)) return rv; - if (!exists) return NS_OK; - - // test if there is a locale provider - // this code stolen from nsMsgServiceProvider.cpp - nsCOMPtr chromeRegistry = do_GetService(kChromeRegistryCID, &rv); - if (NS_SUCCEEDED(rv)) { - nsXPIDLString lc_name; - nsAutoString tmpstr(NS_LITERAL_STRING("global-region")); - rv = chromeRegistry->GetSelectedLocale(tmpstr.get(), getter_Copies(lc_name)); - if (NS_SUCCEEDED(rv)) { - nsAutoString localeStr(lc_name); - if (!localeStr.IsEmpty()) { - nsCOMPtr tmpdataFilesDir; - rv = defaultMessagesFile->Clone(getter_AddRefs(tmpdataFilesDir)); - NS_ENSURE_SUCCESS(rv,rv); - rv = tmpdataFilesDir->AppendUnicode(lc_name); - NS_ENSURE_SUCCESS(rv,rv); - rv = tmpdataFilesDir->Exists(&exists); - NS_ENSURE_SUCCESS(rv,rv); - if (exists && (const PRUnichar *)lc_name) { - // use locale provider instead - rv = defaultMessagesFile->AppendUnicode(lc_name); - NS_ENSURE_SUCCESS(rv,rv); - } - } - } - } + // Get defaults directory for messenger files. MailSession service appends 'messenger' to the + // the app defaults folder and returns it. Locale will be added to the path, if there is one. + nsCOMPtr defaultMessagesFile; + rv = mailSession->GetDataFilesDir("messenger", getter_AddRefs(defaultMessagesFile)); + NS_ENSURE_SUCCESS(rv,rv); // check if bin/defaults/messenger/ // (or bin/defaults/messenger// if we had a locale provide) exists.