From 03fe39844c1cdfb6cc4c13543ed8b220d87500f6 Mon Sep 17 00:00:00 2001 From: craig Date: Fri, 4 May 2012 16:41:02 +0000 Subject: Bump hunspell plugin, simplify and clean some more git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17495 11d20701-8431-0410-a711-e3c959e3b870 --- .../tools/hunspellcheck/hunspellpluginimpl.cpp | 45 +++++++--------------- 1 file changed, 14 insertions(+), 31 deletions(-) (limited to 'scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp') diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp index 18d1a47..be5cfda 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp +++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp @@ -31,7 +31,7 @@ for which a new license (GPL+exception) is in place. // Initialize members here, if any HunspellPluginImpl::HunspellPluginImpl() : QObject(0) { - hspellers=NULL; + //hspellers=NULL; numDicts=0; m_runningForSE=false; m_SE=NULL; @@ -39,16 +39,12 @@ HunspellPluginImpl::HunspellPluginImpl() : QObject(0) HunspellPluginImpl::~HunspellPluginImpl() { - if (hspellers) + foreach (Hunspell* h, hspellerMap) { - for (int i = 0; i < numDicts; ++i) - { - delete hspellers[i]; - hspellers[i] = NULL; - } - delete[] hspellers; + delete h; + h = NULL; } - hspellers = NULL; + hspellerMap.clear(); numDicts = 0; } @@ -56,23 +52,14 @@ bool HunspellPluginImpl::run(const QString & target, ScribusDoc* doc) { m_doc=doc; bool initOk=initHunspell(); - qDebug()<<"Hunspell Init Ok:"<::iterator it = dictionaryMap.begin(); while (it != dictionaryMap.end()) { - hspellers[i++] = new Hunspell((it.value()+".aff").toLocal8Bit().constData(), - (it.value()+".dic").toLocal8Bit().constData()); + hspellerMap.insert(it.key(), new Hunspell((it.value()+".aff").toLocal8Bit().constData(), + (it.value()+".dic").toLocal8Bit().constData())); ++it; } return true; @@ -166,8 +150,7 @@ bool HunspellPluginImpl::parseTextFrame(StoryText *iText) currPos=wordStart; QString word=iText->text(wordStart,wordEnd-wordStart); QString wordLang=iText->charStyle(wordStart).language(); - //qDebug()<getAbbrevFromLang(wordLang, true); + wordLang=LanguageManager::instance()->getAbbrevFromLang(wordLang, true, false); //A little hack as for some reason our en dictionary from the aspell plugin was not called en_GB or en_US but en, content was en_GB though. Meh. if (wordLang=="en") wordLang="en_GB"; @@ -187,7 +170,7 @@ bool HunspellPluginImpl::parseTextFrame(StoryText *iText) } spellerIndex=i; } - if (hspellers[spellerIndex]->spell(word.toUtf8().constData())==0) + if (hspellerMap.contains(wordLang) && hspellerMap[wordLang]->spell(word.toUtf8().constData())==0) { struct WordsFound wf; wf.start=currPos; @@ -199,10 +182,10 @@ bool HunspellPluginImpl::parseTextFrame(StoryText *iText) wf.lang=wordLang; wf.replacements.clear(); char **sugglist = NULL; - int suggCount=hspellers[spellerIndex]->suggest(&sugglist, word.toUtf8().constData()); + int suggCount=hspellerMap[wordLang]->suggest(&sugglist, word.toUtf8().constData()); for (int j=0; j < suggCount; ++j) wf.replacements << QString::fromUtf8(sugglist[j]); - hspellers[spellerIndex]->free_list(&sugglist, suggCount); + hspellerMap[wordLang]->free_list(&sugglist, suggCount); wordsToCorrect.append(wf); } } @@ -212,7 +195,7 @@ bool HunspellPluginImpl::parseTextFrame(StoryText *iText) bool HunspellPluginImpl::openGUIForTextFrame(StoryText *iText) { HunspellDialog hsDialog(m_doc->scMW(), m_doc, iText); - hsDialog.set(&dictionaryMap, hspellers, &wordsToCorrect); + hsDialog.set(&dictionaryMap, &hspellerMap, &wordsToCorrect); hsDialog.exec(); if (hsDialog.docChanged()) m_doc->changed(); @@ -223,7 +206,7 @@ bool HunspellPluginImpl::openGUIForStoryEditor(StoryText *iText) { m_SE->setSpellActive(true); HunspellDialog hsDialog(m_SE, m_doc, iText); - hsDialog.set(&dictionaryMap, hspellers, &wordsToCorrect); + hsDialog.set(&dictionaryMap, &hspellerMap, &wordsToCorrect); hsDialog.exec(); m_SE->setSpellActive(false); return true; -- cgit