Ejemplo n.º 1
0
void SpellCheck::setDictionary(const QString &name, bool forceReplace)
{
    // See if we are already using a hunspell object for this language.
    if (!forceReplace && m_dictionaryName == name && m_hunspell) {
        return;
    }

    // Delete the current hunspell object.
    if (m_hunspell) {
        delete m_hunspell;
        m_hunspell = 0;
    }

    // Save the dictionary name for use later.
    m_dictionaryName = name;

    // If we don't have a dictionary we cannot continue.
    if (name.isEmpty() || !m_dictionaries.contains(name)) {
        return;
    }

    // Dictionary files to use.
    QString aff = QString("%1%2.aff").arg(m_dictionaries.value(name)).arg(name);
    QString dic = QString("%1%2.dic").arg(m_dictionaries.value(name)).arg(name);
    // Create a new hunspell object.
    m_hunspell = new Hunspell(aff.toLocal8Bit().constData(), dic.toLocal8Bit().constData());

    // Note: these are encoded hyphenation dictionaries and their entries are not
    // meaningful words in and of themselves.
    // So the following makes no sense and is not accompishing anything.
    // That said, look into getting the raw hyphenation lists that were used
    // to generate these hyph_dic files for libhyphen

    // QString hyph_dic = QString("%1hyph_%2.dic").arg(m_dictionaries.value(name)).arg(name);
    // Load the hyphenation dictionary if it exists.
    // if (QFile::exists(hyph_dic)) {
    //    m_hunspell->add_dic(hyph_dic.toLocal8Bit().constData());
    //}

    // Get the encoding for the text in the dictionary.
    m_codec = QTextCodec::codecForName(m_hunspell->get_dic_encoding());

    if (m_codec == 0) {
        m_codec = QTextCodec::codecForName("UTF-8");
    }

    // Get the extra wordchars used for tokenization
    m_wordchars = m_codec->toUnicode(m_hunspell->get_wordchars());

    // Load in the words from the user dictionaries.
    foreach(QString word, allUserDictionaryWords()) {
        ignoreWordInDictionary(word);
    }
Ejemplo n.º 2
0
void SpellCheck::setDictionary(const QString &name, bool forceReplace)
{
    // See if we are already using a hunspell object for this language.
    if (!forceReplace && m_dictionaryName == name && m_hunspell) {
        return;
    }

    // Delete the current hunspell object.
    if (m_hunspell) {
        delete m_hunspell;
        m_hunspell = 0;
    }

    // Save the dictionary name for use later.
    m_dictionaryName = name;

    // If we don't have a dictionary we cannot continue.
    if (name.isEmpty() || !m_dictionaries.contains(name)) {
        return;
    }

    // Dictionary files to use.
    QString aff = QString("%1%2.aff").arg(m_dictionaries.value(name)).arg(name);
    QString dic = QString("%1%2.dic").arg(m_dictionaries.value(name)).arg(name);
    QString hyph_dic = QString("%1hyph_%2.dic").arg(m_dictionaries.value(name)).arg(name);
    // Create a new hunspell object.
    m_hunspell = new Hunspell(aff.toLocal8Bit().constData(), dic.toLocal8Bit().constData());

    // Load the hyphenation dictionary if it exists.
    if (QFile::exists(hyph_dic)) {
        m_hunspell->add_dic(hyph_dic.toLocal8Bit().constData());
    }

    // Get the encoding for the text in the dictionary.
    m_codec = QTextCodec::codecForName(m_hunspell->get_dic_encoding());

    if (m_codec == 0) {
        m_codec = QTextCodec::codecForName("UTF-8");
    }

    // Get the extra wordchars used for tokenization
    m_wordchars = m_codec->toUnicode(m_hunspell->get_wordchars());

    // Load in the words from the user dictionaries.
    foreach(QString word, allUserDictionaryWords()) {
        ignoreWordInDictionary(word);
    }
Ejemplo n.º 3
0
 // Reload the words in the "Ignored" dictionary.
 foreach(QString word, m_ignoredWords) {
     ignoreWordInDictionary(word);
 }
Ejemplo n.º 4
0
void SpellCheck::ignoreWord(const QString &word)
{
    ignoreWordInDictionary(word);

    m_ignoredWords.append(word);
}