mozHunspell.h (5252B)
1 /******* BEGIN LICENSE BLOCK ******* 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 3 * 4 * The contents of this file are subject to the Mozilla Public License Version 5 * 1.1 (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * http://www.mozilla.org/MPL/ 8 * 9 * Software distributed under the License is distributed on an "AS IS" basis, 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 11 * for the specific language governing rights and limitations under the 12 * License. 13 * 14 * The Initial Developers of the Original Code are Kevin Hendricks (MySpell) 15 * and László Németh (Hunspell). Portions created by the Initial Developers 16 * are Copyright (C) 2002-2005 the Initial Developers. All Rights Reserved. 17 * 18 * Contributor(s): Kevin Hendricks (kevin.hendricks@sympatico.ca) 19 * David Einstein (deinst@world.std.com) 20 * Michiel van Leeuwen (mvl@exedo.nl) 21 * Caolan McNamara (cmc@openoffice.org) 22 * László Németh (nemethl@gyorsposta.hu) 23 * Davide Prina 24 * Giuseppe Modugno 25 * Gianluca Turconi 26 * Simon Brouwer 27 * Noll Janos 28 * Biro Arpad 29 * Goldman Eleonora 30 * Sarlos Tamas 31 * Bencsath Boldizsar 32 * Halacsy Peter 33 * Dvornik Laszlo 34 * Gefferth Andras 35 * Nagy Viktor 36 * Varga Daniel 37 * Chris Halls 38 * Rene Engelhard 39 * Bram Moolenaar 40 * Dafydd Jones 41 * Harri Pitkanen 42 * Andras Timar 43 * Tor Lillqvist 44 * Jesper Kristensen (mail@jesperkristensen.dk) 45 * 46 * Alternatively, the contents of this file may be used under the terms of 47 * either the GNU General Public License Version 2 or later (the "GPL"), or 48 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 49 * in which case the provisions of the GPL or the LGPL are applicable instead 50 * of those above. If you wish to allow use of your version of this file only 51 * under the terms of either the GPL or the LGPL, and not to allow others to 52 * use your version of this file under the terms of the MPL, indicate your 53 * decision by deleting the provisions above and replace them with the notice 54 * and other provisions required by the GPL or the LGPL. If you do not delete 55 * the provisions above, a recipient may use your version of this file under 56 * the terms of any one of the MPL, the GPL or the LGPL. 57 * 58 ******* END LICENSE BLOCK *******/ 59 60 #ifndef mozHunspell_h__ 61 #define mozHunspell_h__ 62 63 #include "RLBoxHunspell.h" 64 #include "mozISpellCheckingEngine.h" 65 #include "mozIPersonalDictionary.h" 66 #include "nsString.h" 67 #include "nsCOMPtr.h" 68 #include "nsCOMArray.h" 69 #include "nsHashKeys.h" 70 #include "nsIMemoryReporter.h" 71 #include "nsIObserver.h" 72 #include "nsIURI.h" 73 #include "mozilla/Encoding.h" 74 #include "mozilla/UniquePtr.h" 75 #include "nsInterfaceHashtable.h" 76 #include "nsWeakReference.h" 77 #include "nsTHashMap.h" 78 #include "nsCycleCollectionParticipant.h" 79 #include "mozHunspellAllocator.h" 80 81 #define MOZ_HUNSPELL_CONTRACTID "@mozilla.org/spellchecker/engine;1" 82 #define MOZ_HUNSPELL_CID \ 83 /* 56c778e4-1bee-45f3-a689-886692a97fe7 */ \ 84 {0x56c778e4, 0x1bee, 0x45f3, {0xa6, 0x89, 0x88, 0x66, 0x92, 0xa9, 0x7f, 0xe7}} 85 86 class mozHunspell final : public mozISpellCheckingEngine, 87 public nsIObserver, 88 public nsSupportsWeakReference, 89 public nsIMemoryReporter { 90 public: 91 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 92 NS_DECL_MOZISPELLCHECKINGENGINE 93 NS_DECL_NSIOBSERVER 94 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(mozHunspell, mozISpellCheckingEngine) 95 96 mozHunspell(); 97 98 nsresult Init(); 99 100 void LoadDictionaryList(bool aNotifyChildProcesses); 101 102 NS_DECL_NSIMEMORYREPORTER 103 104 protected: 105 virtual ~mozHunspell(); 106 107 void DictionariesChanged(bool aNotifyChildProcesses); 108 109 nsCOMPtr<mozIPersonalDictionary> mPersonalDictionary; 110 111 // Hashtable matches dictionary name to .aff file 112 nsInterfaceHashtable<nsStringHashKey, nsIURI> mDictionaries; 113 114 // dynamic dirs used to search for dictionaries 115 nsCOMArray<nsIFile> mDynamicDirectories; 116 nsInterfaceHashtable<nsStringHashKey, nsIURI> mDynamicDictionaries; 117 118 struct DictionaryData { 119 // keep track of whether the dictionary is currently in use or not 120 bool mEnabled = true; 121 122 // keep track of whether we've failed loading this dictionary before. 123 // if set, we don't try loading it again. 124 bool mLoadFailed = false; 125 126 mozilla::UniquePtr<mozilla::Encoder> mEncoder; 127 mozilla::UniquePtr<mozilla::Decoder> mDecoder; 128 mozilla::UniquePtr<RLBoxHunspell> mHunspell; 129 nsCString mAffixFileName; 130 131 // helper method for converting a word to the charset of the dictionary 132 nsresult ConvertCharset(const nsAString& aStr, std::string& aDst); 133 134 // helper method to the load the dictionary if it is not already loaded 135 nsresult LoadIfNecessary(); 136 }; 137 138 nsTHashMap<nsCStringHashKey, DictionaryData> mHunspells; 139 }; 140 141 #endif