// static bool LLSpellChecker::canRemoveDictionary(const std::string& dict_language) { // Only user-installed inactive dictionaries can be removed const LLSD dict_info = getDictionaryData(dict_language); return (dict_info["user_installed"].asBoolean()) && ( (!getUseSpellCheck()) || (!LLSpellChecker::instance().isActiveDictionary(dict_language)) ); }
void LLSpellChecker::setSecondaryDictionaries(dict_list_t dict_list) { if (!getUseSpellCheck()) { return; } // Check if we're only adding secondary dictionaries, or removing them dict_list_t dict_add(llmax(dict_list.size(), mDictSecondary.size())), dict_rem(llmax(dict_list.size(), mDictSecondary.size())); dict_list.sort(); mDictSecondary.sort(); dict_list_t::iterator end_added = std::set_difference(dict_list.begin(), dict_list.end(), mDictSecondary.begin(), mDictSecondary.end(), dict_add.begin()); dict_list_t::iterator end_removed = std::set_difference(mDictSecondary.begin(), mDictSecondary.end(), dict_list.begin(), dict_list.end(), dict_rem.begin()); if (end_removed != dict_rem.begin()) // We can't remove secondary dictionaries so we need to recreate the Hunspell instance { mDictSecondary = dict_list; std::string dict_language = mDictLanguage; initHunspell(dict_language); } else if (end_added != dict_add.begin()) // Add the new secondary dictionaries one by one { const std::string app_path = getDictionaryAppPath(); const std::string user_path = getDictionaryUserPath(); for (dict_list_t::const_iterator it_added = dict_add.begin(); it_added != end_added; ++it_added) { const LLSD dict_entry = getDictionaryData(*it_added); if ( (!dict_entry.isDefined()) || (!dict_entry["installed"].asBoolean()) ) { continue; } const std::string strFileDic = dict_entry["name"].asString() + ".dic"; if (gDirUtilp->fileExists(user_path + strFileDic)) { mHunspell->add_dic((user_path + strFileDic).c_str()); } else if (gDirUtilp->fileExists(app_path + strFileDic)) { mHunspell->add_dic((app_path + strFileDic).c_str()); } } mDictSecondary = dict_list; sSettingsChangeSignal(); } }
void LLSpellChecker::initHunspell(const std::string& dict_name) { if (mHunspell) { delete mHunspell; mHunspell = NULL; mDictName.clear(); mDictFile.clear(); mIgnoreList.clear(); } const LLSD dict_entry = (!dict_name.empty()) ? getDictionaryData(dict_name) : LLSD(); if ( (!dict_entry.isDefined()) || (!dict_entry["installed"].asBoolean()) || (!dict_entry["is_primary"].asBoolean())) { sSettingsChangeSignal(); return; } const std::string app_path = getDictionaryAppPath(); const std::string user_path = getDictionaryUserPath(); if (dict_entry.has("name")) { const std::string filename_aff = dict_entry["name"].asString() + ".aff"; const std::string filename_dic = dict_entry["name"].asString() + ".dic"; if ( (gDirUtilp->fileExists(user_path + filename_aff)) && (gDirUtilp->fileExists(user_path + filename_dic)) ) mHunspell = new Hunspell((user_path + filename_aff).c_str(), (user_path + filename_dic).c_str()); else if ( (gDirUtilp->fileExists(app_path + filename_aff)) && (gDirUtilp->fileExists(app_path + filename_dic)) ) mHunspell = new Hunspell((app_path + filename_aff).c_str(), (app_path + filename_dic).c_str()); if (!mHunspell) return; mDictName = dict_name; mDictFile = dict_entry["name"].asString(); if (dict_entry["has_custom"].asBoolean()) { const std::string filename_dic = user_path + mDictFile + DICT_CUSTOM_SUFFIX + ".dic"; mHunspell->add_dic(filename_dic.c_str()); } if (dict_entry["has_ignore"].asBoolean()) { llifstream file_in(user_path + mDictFile + DICT_IGNORE_SUFFIX + ".dic", std::ios::in); if (file_in.is_open()) { std::string word; int idxLine = 0; while (getline(file_in, word)) { // Skip over the first line since that's just a line count if (0 != idxLine) { LLStringUtil::toLower(word); mIgnoreList.push_back(word); } idxLine++; } } } for (dict_list_t::const_iterator it = mDictSecondary.begin(); it != mDictSecondary.end(); ++it) { const LLSD dict_entry = getDictionaryData(*it); if ( (!dict_entry.isDefined()) || (!dict_entry["installed"].asBoolean()) ) continue; const std::string filename_dic = dict_entry["name"].asString() + ".dic"; if (gDirUtilp->fileExists(user_path + filename_dic)) mHunspell->add_dic((user_path + filename_dic).c_str()); else if (gDirUtilp->fileExists(app_path + filename_dic)) mHunspell->add_dic((app_path + filename_dic).c_str()); } } sSettingsChangeSignal(); }
// static bool LLSpellChecker::hasDictionary(const std::string& dict_language, bool check_installed) { const LLSD dict_info = getDictionaryData(dict_language); return dict_info.has("language") && ( (!check_installed) || (dict_info["installed"].asBoolean()) ); }