diff options
| author | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-05-03 07:40:30 +0000 |
|---|---|---|
| committer | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-05-03 07:40:30 +0000 |
| commit | 020a92a1d225b2a84feb5dfbb8aa126801571d26 (patch) | |
| tree | 4200f068a72fda5926d63c8a55ac032d688b503e /scribus/plugins/tools | |
| parent | c83b8f82137d7a071334cd8246b3b510374bf474 (diff) | |
| download | scribus-020a92a1d225b2a84feb5dfbb8aa126801571d26.tar.gz scribus-020a92a1d225b2a84feb5dfbb8aa126801571d26.tar.xz scribus-020a92a1d225b2a84feb5dfbb8aa126801571d26.zip | |
Bump hunspell some more, add it some real finding/use of dicts from common locations
git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17490 11d20701-8431-0410-a711-e3c959e3b870
Diffstat (limited to 'scribus/plugins/tools')
4 files changed, 79 insertions, 50 deletions
diff --git a/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp b/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp index 8322a0d..b10a56f 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp +++ b/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp @@ -30,15 +30,19 @@ HunspellDialog::HunspellDialog(QWidget *parent, ScribusDoc *doc, StoryText *iTex m_primaryLangIndex=0; } -void HunspellDialog::set(QStringList *dictEntries, Hunspell **hspellers, QList<WordsFound> *wfList) +void HunspellDialog::set(QMap<QString, QString>* dictionaryMap, Hunspell **hspellers, QList<WordsFound> *wfList) { - m_dictEntries=dictEntries; + m_dictionaryMap=dictionaryMap; m_hspellers=hspellers; m_wfList=wfList; bool b=languagesComboBox->blockSignals(true); languagesComboBox->clear(); - for(int i=0;i<dictEntries->count();++i) - languagesComboBox->addItem(LanguageManager::instance()->getLangFromAbbrev(dictEntries->at(i), true)); + QMap<QString, QString>::iterator it = m_dictionaryMap->begin(); + while (it != dictionaryMap->end()) + { + languagesComboBox->addItem(LanguageManager::instance()->getLangFromAbbrev(it.key(), true)); + ++it; + } languagesComboBox->setCurrentIndex(0); m_primaryLangIndex=0; languagesComboBox->blockSignals(b); diff --git a/scribus/plugins/tools/hunspellcheck/hunspelldialog.h b/scribus/plugins/tools/hunspellcheck/hunspelldialog.h index 85a7da1..178fbc2 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspelldialog.h +++ b/scribus/plugins/tools/hunspellcheck/hunspelldialog.h @@ -22,7 +22,7 @@ class PLUGIN_API HunspellDialog : public QDialog, private Ui::HunspellDialogBase public: HunspellDialog(QWidget* parent, ScribusDoc *doc, StoryText* iText); ~HunspellDialog() {}; - void set(QStringList* dictEntries, Hunspell **hspellers, QList<WordsFound>* wfList); + void set(QMap<QString, QString>* dictionaryMap, Hunspell **hspellers, QList<WordsFound>* wfList); bool docChanged() {return m_docChanged;} void updateSuggestions(QStringList& newSuggestions); @@ -37,7 +37,7 @@ class PLUGIN_API HunspellDialog : public QDialog, private Ui::HunspellDialogBase private: ScribusDoc* m_doc; StoryText* m_Itext; - QStringList* m_dictEntries; + QMap<QString, QString>* m_dictionaryMap; Hunspell **m_hspellers; QList<WordsFound>* m_wfList; WordsFound currWF; diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp index 8fff975..ee4ed23 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp +++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp @@ -6,6 +6,7 @@ for which a new license (GPL+exception) is in place. */ #include "hunspellpluginimpl.h" #include "hunspelldialog.h" +#include "langmgr.h" #include "pageitem.h" #include "pageitem_textframe.h" #include "selection.h" @@ -76,60 +77,62 @@ bool HunspellPluginImpl::run(const QString & target, ScribusDoc* doc) bool HunspellPluginImpl::findDictionaries() { - QStringList dirs(ScPaths::instance().spellDirs()); - if (dirs.count()==0) + dictionaryPaths=ScPaths::instance().spellDirs(); + if (dictionaryPaths.count()==0) return false; - //for development, just take the first for now - dictPath=dirs.first(); return true; } bool HunspellPluginImpl::initHunspell() { - int errorCount=0; bool dictPathFound=findDictionaries(); if (!dictPathFound) { qDebug()<<"No preinstalled dictonary paths found"; return false; } - else - qDebug()<<"Preinstalled dictionary path selected"<<dictPath; - - // Find the dic and aff files in the location - QDir dictLocation(dictPath); - QStringList dictFilters, affFilters; - dictFilters << "*.dic"; - affFilters << "*.aff"; - QStringList dictList(dictLocation.entryList(dictFilters, QDir::Files, QDir::Name)); - dictList.replaceInStrings(".dic",""); - QStringList affList; - - //Ensure we have aff+dic file pairs, remove any hyphenation dictionaries from the list - QString dictName; - QStringListIterator dictListIterator(dictList); - while (dictListIterator.hasNext()) + for (int i=0; i<dictionaryPaths.count(); ++i) { - dictName=dictListIterator.next(); - if (!QFile::exists(dictPath+dictName+".aff")) - dictList.removeAll(dictName); + // Find the dic and aff files in the location + QDir dictLocation(dictionaryPaths.at(i)); + QStringList dictFilters; + dictFilters << "*.dic"; + QStringList dictList(dictLocation.entryList(dictFilters, QDir::Files, QDir::Name)); + dictList.replaceInStrings(".dic",""); + + //Ensure we have aff+dic file pairs, remove any hyphenation dictionaries from the list + QString dictName; + QStringListIterator dictListIterator(dictList); + while (dictListIterator.hasNext()) + { + dictName=dictListIterator.next(); + if (!QFile::exists(dictionaryPaths.at(i)+dictName+".aff")) + dictList.removeAll(dictName); + else + { + if (!dictionaryMap.contains(dictName)) + dictionaryMap.insert(dictName, dictionaryPaths.at(i)+dictName); + } + } + qDebug()<<"Number of dictionaries/AFFs found in"<<dictionaryPaths.at(i)<<":"<<dictList.count(); } - numAFFs=numDicts=dictList.count(); - qDebug()<<"Number of dictionaries/AFFs found:"<<numDicts<<numAFFs; - if (numDicts==0) - ++errorCount; - qDebug()<<dictList; + numDicts=dictionaryMap.count(); + if (dictionaryMap.count()==0) + return false; //Initialise one hunspeller for each dictionary found //Maybe we only need the text language related one later on - dictEntries=dictList; - affEntries=affList; + int i=0; hspellers = new Hunspell* [numDicts]; - for (int i=0; i<numDicts; ++i) - hspellers[i] = new Hunspell((dictPath+dictList.at(i)+".aff").toLocal8Bit().constData(), - (dictPath+dictList.at(i)+".dic").toLocal8Bit().constData()); - - return errorCount==0; + QMap<QString, QString>::iterator it = dictionaryMap.begin(); + while (it != dictionaryMap.end()) + { + qDebug() << it.key()<< it.value(); + hspellers[i++] = new Hunspell((it.value()+".aff").toLocal8Bit().constData(), + (it.value()+".dic").toLocal8Bit().constData()); + ++it; + } + return true; } bool HunspellPluginImpl::checkWithHunspell() @@ -174,21 +177,42 @@ bool HunspellPluginImpl::parseTextFrame(StoryText *iText) break; } QString word=iText->text(wordPos,eoWord-wordPos); + QString wordLang=iText->charStyle(wordPos).language(); + //qDebug()<<word<<"is set to be in language"<<wordLang; + wordLang=LanguageManager::instance()->getAbbrevFromLang(wordLang, true); + if (wordLang=="en") + wordLang="en_GB"; + int spellerIndex=0; + if (!dictionaryMap.contains(wordLang)) + qDebug()<<"Spelling language to match style language not installed ("<<wordLang<<")"; + else + { + int i=0; + QMap<QString, QString>::iterator it = dictionaryMap.begin(); + while (it != dictionaryMap.end()) + { + if (it.key()==wordLang) + break; + ++i; + ++it; + } + spellerIndex=i; + } ++wordCount; ++wordNo; QStringList replacements; - if (hspellers[0]->spell(word.toUtf8().constData())==0) + if (hspellers[spellerIndex]->spell(word.toUtf8().constData())==0) { // qDebug()<<word; ++errorCount; char **sugglist = NULL; - int suggCount=hspellers[0]->suggest(&sugglist, word.toUtf8().constData()); + int suggCount=hspellers[spellerIndex]->suggest(&sugglist, word.toUtf8().constData()); for (int j=0; j < suggCount; ++j) { // qDebug()<<"Suggestion "<<j<<":"<<sugglist[j]; replacements << QString::fromUtf8(sugglist[j]); } - hspellers[0]->free_list(&sugglist, suggCount); + hspellers[spellerIndex]->free_list(&sugglist, suggCount); struct WordsFound wf; wf.start=currPos; @@ -208,7 +232,7 @@ bool HunspellPluginImpl::parseTextFrame(StoryText *iText) bool HunspellPluginImpl::openGUIForTextFrame(StoryText *iText) { HunspellDialog hsDialog(m_doc->scMW(), m_doc, iText); - hsDialog.set(&dictEntries, hspellers, &wordsToCorrect); + hsDialog.set(&dictionaryMap, hspellers, &wordsToCorrect); hsDialog.exec(); if (hsDialog.docChanged()) m_doc->changed(); @@ -219,7 +243,7 @@ bool HunspellPluginImpl::openGUIForStoryEditor(StoryText *iText) { m_SE->setSpellActive(true); HunspellDialog hsDialog(m_SE, m_doc, iText); - hsDialog.set(&dictEntries, hspellers, &wordsToCorrect); + hsDialog.set(&dictionaryMap, hspellers, &wordsToCorrect); hsDialog.exec(); m_SE->setSpellActive(false); return true; diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h index 0443c10..08ad225 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h +++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h @@ -11,6 +11,7 @@ for which a new license (GPL+exception) is in place. #include "hunspellpluginstructs.h" #include <QObject> +#include <QMap> #include <QString> #include <QStringList> @@ -40,12 +41,12 @@ class HunspellPluginImpl : public QObject QList<WordsFound> wordsToCorrect; protected: + QMap<QString, QString> dictionaryMap; QStringList dictionaryPaths; - QString dictPath, affPath; int numDicts, numAFFs; Hunspell **hspellers; - QStringList dictEntries; - QStringList affEntries; + //QStringList dictEntries; + //QStringList affEntries; ScribusDoc* m_doc; bool m_runningForSE; StoryEditor* m_SE; |
