Bug 429023 - Use preference 'spellchecker.dictionary_path' to override loading internal dictionaries; r=ehsan,glandium
authorIan Stakenvicius <axs@gentoo.org>
Mon, 22 Apr 2013 13:20:24 -0400
changeset 129491 dfe59fafcaf0d9352244900d86d63f11d640003f
parent 129490 c2d4abcf30dfabfbda172d10be0c6ec01e4e80f3
child 129492 ce672182dedcaabb42bab7767e9269f8fe634665
push idunknown
push userunknown
push dateunknown
reviewersehsan, glandium
bugs429023
milestone23.0a1
Bug 429023 - Use preference 'spellchecker.dictionary_path' to override loading internal dictionaries; r=ehsan,glandium
extensions/spellcheck/hunspell/src/mozHunspell.cpp
--- a/extensions/spellcheck/hunspell/src/mozHunspell.cpp
+++ b/extensions/spellcheck/hunspell/src/mozHunspell.cpp
@@ -70,16 +70,18 @@
 #include "nsICharsetConverterManager.h"
 #include "nsUnicharUtilCIID.h"
 #include "nsUnicharUtils.h"
 #include "nsCRT.h"
 #include "mozInlineSpellChecker.h"
 #include "mozilla/Services.h"
 #include <stdlib.h>
 #include "nsIMemoryReporter.h"
+#include "nsIPrefService.h"
+#include "nsIPrefBranch.h"
 
 static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
 static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(mozHunspell)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(mozHunspell)
 
 NS_INTERFACE_MAP_BEGIN(mozHunspell)
@@ -367,21 +369,36 @@ mozHunspell::LoadDictionaryList()
 
   nsresult rv;
 
   nsCOMPtr<nsIProperties> dirSvc =
     do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID);
   if (!dirSvc)
     return;
 
-  // find built in dictionaries
+  // find built in dictionaries, or dictionaries specified in
+  // spellchecker.dictionary_path in prefs
   nsCOMPtr<nsIFile> dictDir;
-  rv = dirSvc->Get(DICTIONARY_SEARCH_DIRECTORY,
-                   NS_GET_IID(nsIFile), getter_AddRefs(dictDir));
-  if (NS_SUCCEEDED(rv)) {
+
+  // check preferences first
+  nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
+  if (prefs) {
+    nsCString extDictPath;
+    rv = prefs->GetCharPref("spellchecker.dictionary_path", getter_Copies(extDictPath));
+    if (NS_SUCCEEDED(rv)) {
+      // set the spellchecker.dictionary_path
+      rv = NS_NewNativeLocalFile(extDictPath, true, getter_AddRefs(dictDir));
+    }
+  }
+  if (!dictDir) {
+    // spellcheck.dictionary_path not found, set internal path
+    rv = dirSvc->Get(DICTIONARY_SEARCH_DIRECTORY,
+                     NS_GET_IID(nsIFile), getter_AddRefs(dictDir));
+  }
+  if (dictDir) {
     LoadDictionariesFromDir(dictDir);
   }
   else {
     // try to load gredir/dictionaries
     nsCOMPtr<nsIFile> greDir;
     rv = dirSvc->Get(NS_GRE_DIR,
                      NS_GET_IID(nsIFile), getter_AddRefs(greDir));
     if (NS_SUCCEEDED(rv)) {