summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
authorKitty Barnett <develop@catznip.com>2012-02-14 21:48:22 +0100
committerKitty Barnett <develop@catznip.com>2012-02-14 21:48:22 +0100
commit60e39343b17f29c65e8a60a415f7ed83ff069a12 (patch)
tree895a454b02b2685bfa91a994d67bb9eea139c1cc /indra/llui
parent2114e88cd1291ef1dba4b79bcdcca4b2d134262f (diff)
STORM-276 Reworked the spell check preferences to be more robust and less error-prone
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llspellcheck.cpp20
-rw-r--r--indra/llui/llspellcheck.h14
2 files changed, 24 insertions, 10 deletions
diff --git a/indra/llui/llspellcheck.cpp b/indra/llui/llspellcheck.cpp
index 65207144f8..46df44cdba 100644
--- a/indra/llui/llspellcheck.cpp
+++ b/indra/llui/llspellcheck.cpp
@@ -41,6 +41,7 @@ static const std::string DICT_DIR = "dictionaries";
static const std::string DICT_CUSTOM_SUFFIX = "_custom";
static const std::string DICT_IGNORE_SUFFIX = "_ignore";
+LLSD LLSpellChecker::sDictMap;
LLSpellChecker::settings_change_signal_t LLSpellChecker::sSettingsChangeSignal;
LLSpellChecker::LLSpellChecker()
@@ -86,9 +87,10 @@ S32 LLSpellChecker::getSuggestions(const std::string& word, std::vector<std::str
return suggestions.size();
}
-const LLSD LLSpellChecker::getDictionaryData(const std::string& dict_name) const
+// static
+const LLSD LLSpellChecker::getDictionaryData(const std::string& dict_name)
{
- for (LLSD::array_const_iterator it = mDictMap.beginArray(); it != mDictMap.endArray(); ++it)
+ for (LLSD::array_const_iterator it = sDictMap.beginArray(); it != sDictMap.endArray(); ++it)
{
const LLSD& dict_entry = *it;
if (dict_name == dict_entry["language"].asString())
@@ -97,6 +99,7 @@ const LLSD LLSpellChecker::getDictionaryData(const std::string& dict_name) const
return LLSD();
}
+// static
void LLSpellChecker::refreshDictionaryMap()
{
const std::string app_path = getDictionaryAppPath();
@@ -104,16 +107,16 @@ void LLSpellChecker::refreshDictionaryMap()
// Load dictionary information (file name, friendly name, ...)
llifstream user_map(user_path + "dictionaries.xml", std::ios::binary);
- if ( (!user_map.is_open()) || (0 == LLSDSerialize::fromXMLDocument(mDictMap, user_map)) || (0 == mDictMap.size()) )
+ if ( (!user_map.is_open()) || (0 == LLSDSerialize::fromXMLDocument(sDictMap, user_map)) || (0 == sDictMap.size()) )
{
llifstream app_map(app_path + "dictionaries.xml", std::ios::binary);
- if ( (!app_map.is_open()) || (0 == LLSDSerialize::fromXMLDocument(mDictMap, app_map)) || (0 == mDictMap.size()) )
+ if ( (!app_map.is_open()) || (0 == LLSDSerialize::fromXMLDocument(sDictMap, app_map)) || (0 == sDictMap.size()) )
return;
}
// Look for installed dictionaries
std::string tmp_app_path, tmp_user_path;
- for (LLSD::array_iterator it = mDictMap.beginArray(); it != mDictMap.endArray(); ++it)
+ for (LLSD::array_iterator it = sDictMap.beginArray(); it != sDictMap.endArray(); ++it)
{
LLSD& sdDict = *it;
tmp_app_path = (sdDict.has("name")) ? app_path + sdDict["name"].asString() : LLStringUtil::null;
@@ -343,3 +346,10 @@ void LLSpellChecker::setUseSpellCheck(const std::string& dict_name)
LLSpellChecker::instance().initHunspell(dict_name);
}
}
+
+// static
+void LLSpellChecker::initClass()
+{
+ if (sDictMap.isUndefined())
+ refreshDictionaryMap();
+}
diff --git a/indra/llui/llspellcheck.h b/indra/llui/llspellcheck.h
index 8351655b49..d736a7f082 100644
--- a/indra/llui/llspellcheck.h
+++ b/indra/llui/llspellcheck.h
@@ -28,13 +28,15 @@
#define LLSPELLCHECK_H
#include "llsingleton.h"
+#include "llui.h"
#include <boost/signals2.hpp>
class Hunspell;
-class LLSpellChecker : public LLSingleton<LLSpellChecker>
+class LLSpellChecker : public LLSingleton<LLSpellChecker>, public LLInitClass<LLSpellChecker>
{
friend class LLSingleton<LLSpellChecker>;
+ friend class LLInitClass<LLSpellChecker>;
protected:
LLSpellChecker();
~LLSpellChecker();
@@ -52,28 +54,30 @@ public:
typedef std::list<std::string> dict_list_t;
const std::string& getActiveDictionary() const { return mDictName; }
- const LLSD getDictionaryData(const std::string& dict_name) const;
- const LLSD& getDictionaryMap() const { return mDictMap; }
const dict_list_t& getSecondaryDictionaries() const { return mDictSecondary; }
- void refreshDictionaryMap();
void setSecondaryDictionaries(dict_list_t dict_list);
static const std::string getDictionaryAppPath();
static const std::string getDictionaryUserPath();
+ static const LLSD getDictionaryData(const std::string& dict_name);
+ static const LLSD& getDictionaryMap() { return sDictMap; }
static bool getUseSpellCheck();
+ static void refreshDictionaryMap();
static void setUseSpellCheck(const std::string& dict_name);
typedef boost::signals2::signal<void()> settings_change_signal_t;
static boost::signals2::connection setSettingsChangeCallback(const settings_change_signal_t::slot_type& cb);
+protected:
+ static void initClass();
protected:
Hunspell* mHunspell;
std::string mDictName;
std::string mDictFile;
- LLSD mDictMap;
dict_list_t mDictSecondary;
std::vector<std::string> mIgnoreList;
+ static LLSD sDictMap;
static settings_change_signal_t sSettingsChangeSignal;
};