1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/extensions/spellcheck/hunspell/src/mozHunspellDirProvider.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,140 @@ 1.4 +/******* BEGIN LICENSE BLOCK ******* 1.5 + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 1.6 + * 1.7 + * The contents of this file are subject to the Mozilla Public License Version 1.8 + * 1.1 (the "License"); you may not use this file except in compliance with 1.9 + * the License. You may obtain a copy of the License at 1.10 + * http://www.mozilla.org/MPL/ 1.11 + * 1.12 + * Software distributed under the License is distributed on an "AS IS" basis, 1.13 + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 1.14 + * for the specific language governing rights and limitations under the 1.15 + * License. 1.16 + * 1.17 + * The Initial Developers of the Original Code are Kevin Hendricks (MySpell) 1.18 + * and László Németh (Hunspell). Portions created by the Initial Developers 1.19 + * are Copyright (C) 2002-2005 the Initial Developers. All Rights Reserved. 1.20 + * 1.21 + * Contributor(s): Benjamin Smedberg (benjamin@smedbergs.us) (Original Code) 1.22 + * László Németh (nemethl@gyorsposta.hu) 1.23 + * Ryan VanderMeulen (ryanvm@gmail.com) 1.24 + * 1.25 + * Alternatively, the contents of this file may be used under the terms of 1.26 + * either the GNU General Public License Version 2 or later (the "GPL"), or 1.27 + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 1.28 + * in which case the provisions of the GPL or the LGPL are applicable instead 1.29 + * of those above. If you wish to allow use of your version of this file only 1.30 + * under the terms of either the GPL or the LGPL, and not to allow others to 1.31 + * use your version of this file under the terms of the MPL, indicate your 1.32 + * decision by deleting the provisions above and replace them with the notice 1.33 + * and other provisions required by the GPL or the LGPL. If you do not delete 1.34 + * the provisions above, a recipient may use your version of this file under 1.35 + * the terms of any one of the MPL, the GPL or the LGPL. 1.36 + * 1.37 + ******* END LICENSE BLOCK *******/ 1.38 + 1.39 +#include "mozHunspellDirProvider.h" 1.40 +#include "nsXULAppAPI.h" 1.41 +#include "nsString.h" 1.42 + 1.43 +#include "mozISpellCheckingEngine.h" 1.44 +#include "nsICategoryManager.h" 1.45 + 1.46 +NS_IMPL_ISUPPORTS(mozHunspellDirProvider, 1.47 + nsIDirectoryServiceProvider, 1.48 + nsIDirectoryServiceProvider2) 1.49 + 1.50 +NS_IMETHODIMP 1.51 +mozHunspellDirProvider::GetFile(const char *aKey, bool *aPersist, 1.52 + nsIFile* *aResult) 1.53 +{ 1.54 + return NS_ERROR_FAILURE; 1.55 +} 1.56 + 1.57 +NS_IMETHODIMP 1.58 +mozHunspellDirProvider::GetFiles(const char *aKey, 1.59 + nsISimpleEnumerator* *aResult) 1.60 +{ 1.61 + if (strcmp(aKey, DICTIONARY_SEARCH_DIRECTORY_LIST) != 0) { 1.62 + return NS_ERROR_FAILURE; 1.63 + } 1.64 + 1.65 + nsCOMPtr<nsIProperties> dirSvc = 1.66 + do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID); 1.67 + if (!dirSvc) 1.68 + return NS_ERROR_FAILURE; 1.69 + 1.70 + nsCOMPtr<nsISimpleEnumerator> list; 1.71 + nsresult rv = dirSvc->Get(XRE_EXTENSIONS_DIR_LIST, 1.72 + NS_GET_IID(nsISimpleEnumerator), 1.73 + getter_AddRefs(list)); 1.74 + if (NS_FAILED(rv)) 1.75 + return rv; 1.76 + 1.77 + nsCOMPtr<nsISimpleEnumerator> e = new AppendingEnumerator(list); 1.78 + if (!e) 1.79 + return NS_ERROR_OUT_OF_MEMORY; 1.80 + 1.81 + *aResult = nullptr; 1.82 + e.swap(*aResult); 1.83 + return NS_SUCCESS_AGGREGATE_RESULT; 1.84 +} 1.85 + 1.86 +NS_IMPL_ISUPPORTS(mozHunspellDirProvider::AppendingEnumerator, 1.87 + nsISimpleEnumerator) 1.88 + 1.89 +NS_IMETHODIMP 1.90 +mozHunspellDirProvider::AppendingEnumerator::HasMoreElements(bool *aResult) 1.91 +{ 1.92 + *aResult = mNext ? true : false; 1.93 + return NS_OK; 1.94 +} 1.95 + 1.96 +NS_IMETHODIMP 1.97 +mozHunspellDirProvider::AppendingEnumerator::GetNext(nsISupports* *aResult) 1.98 +{ 1.99 + if (aResult) 1.100 + NS_ADDREF(*aResult = mNext); 1.101 + 1.102 + mNext = nullptr; 1.103 + 1.104 + nsresult rv; 1.105 + 1.106 + // Ignore all errors 1.107 + 1.108 + bool more; 1.109 + while (NS_SUCCEEDED(mBase->HasMoreElements(&more)) && more) { 1.110 + nsCOMPtr<nsISupports> nextbasesupp; 1.111 + mBase->GetNext(getter_AddRefs(nextbasesupp)); 1.112 + 1.113 + nsCOMPtr<nsIFile> nextbase(do_QueryInterface(nextbasesupp)); 1.114 + if (!nextbase) 1.115 + continue; 1.116 + 1.117 + nextbase->Clone(getter_AddRefs(mNext)); 1.118 + if (!mNext) 1.119 + continue; 1.120 + 1.121 + mNext->AppendNative(NS_LITERAL_CSTRING("dictionaries")); 1.122 + 1.123 + bool exists; 1.124 + rv = mNext->Exists(&exists); 1.125 + if (NS_SUCCEEDED(rv) && exists) 1.126 + break; 1.127 + 1.128 + mNext = nullptr; 1.129 + } 1.130 + 1.131 + return NS_OK; 1.132 +} 1.133 + 1.134 +mozHunspellDirProvider::AppendingEnumerator::AppendingEnumerator 1.135 + (nsISimpleEnumerator* aBase) : 1.136 + mBase(aBase) 1.137 +{ 1.138 + // Initialize mNext to begin 1.139 + GetNext(nullptr); 1.140 +} 1.141 + 1.142 +char const *const 1.143 +mozHunspellDirProvider::kContractID = "@mozilla.org/spellcheck/dir-provider;1";