diff options
| author | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-05-04 16:41:02 +0000 |
|---|---|---|
| committer | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-05-04 16:41:02 +0000 |
| commit | 03fe39844c1cdfb6cc4c13543ed8b220d87500f6 (patch) | |
| tree | acaa29f62115d1bbd029e6ceb808843864230366 /scribus/plugins | |
| parent | 1601800e7d74c192af89ee85c6110bd80a02453a (diff) | |
| download | scribus-03fe39844c1cdfb6cc4c13543ed8b220d87500f6.tar.gz scribus-03fe39844c1cdfb6cc4c13543ed8b220d87500f6.tar.xz scribus-03fe39844c1cdfb6cc4c13543ed8b220d87500f6.zip | |
Bump hunspell plugin, simplify and clean some more
git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17495 11d20701-8431-0410-a711-e3c959e3b870
Diffstat (limited to 'scribus/plugins')
4 files changed, 34 insertions, 57 deletions
diff --git a/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp b/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp index 6c9087a..a41a699 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp +++ b/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp @@ -21,19 +21,19 @@ HunspellDialog::HunspellDialog(QWidget *parent, ScribusDoc *doc, StoryText *iTex connect (ignoreAllPushButton, SIGNAL(clicked()), this, SLOT(ignoreAllWords())); connect (changePushButton, SIGNAL(clicked()), this, SLOT(changeWord())); connect (changeAllPushButton, SIGNAL(clicked()), this, SLOT(changeAllWords())); - connect (languagesComboBox, SIGNAL(currentIndexChanged (int)), this, SLOT(languageComboChanged(int))); + connect (languagesComboBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(languageComboChanged(const QString &))); m_doc=doc; m_docChanged=false; - m_Itext=iText; + m_iText=iText; m_returnToDefaultLang=false; m_primaryLangIndex=0; } -void HunspellDialog::set(QMap<QString, QString>* dictionaryMap, Hunspell **hspellers, QList<WordsFound> *wfList) +void HunspellDialog::set(QMap<QString, QString>* dictionaryMap, QMap<QString, Hunspell*> *hspellerMap, QList<WordsFound> *wfList) { m_dictionaryMap=dictionaryMap; - m_hspellers=hspellers; + m_hspellerMap=hspellerMap; m_wfList=wfList; bool b=languagesComboBox->blockSignals(true); languagesComboBox->clear(); @@ -91,7 +91,7 @@ void HunspellDialog::goToNextWord(int i) updateSuggestions(currWF.replacements); int sentencePos=0; - QString sentence(m_Itext->sentence(currWF.start, sentencePos)); + QString sentence(m_iText->sentence(currWF.start, sentencePos)); sentence.insert(currWF.end-sentencePos+currWF.changeOffset,"</b></font>"); sentence.insert(currWF.start-sentencePos+currWF.changeOffset,"<font color=red><b>"); sentenceTextEdit->setText(sentence); @@ -132,9 +132,8 @@ void HunspellDialog::changeAllWords() void HunspellDialog::replaceWord(int i) { //TODO: rehypenate after the replacement - //qDebug()<<"Replacing word"<<i<m_wfList->at(i).w<<m_wfList->at(i).start; QString newText(suggestionsListWidget->currentItem()->text()); - int lengthDiff=m_Itext->replaceWord(m_wfList->at(i).start+m_wfList->at(i).changeOffset, newText); + int lengthDiff=m_iText->replaceWord(m_wfList->at(i).start+m_wfList->at(i).changeOffset, newText); if (lengthDiff!=0) { for (int k=i; k<m_wfList->count();++k) @@ -144,28 +143,25 @@ void HunspellDialog::replaceWord(int i) m_docChanged=true; } -void HunspellDialog::languageComboChanged(int index) +void HunspellDialog::languageComboChanged(const QString &newLanguage) { m_returnToDefaultLang=true; - QString newLanguage=languagesComboBox->itemText(index); - QString wordToCheck=m_wfList->at(wfListIndex).w; -// qDebug()<<"You changed the language to:"<<newLanguage; - if (!m_hspellers[index]) + QString wordLang=LanguageManager::instance()->getAbbrevFromLang(newLanguage, true, false); + if (!m_hspellerMap->contains(wordLang) ) { - qDebug()<<"hspeller"<<index<<"does not exist"; + qDebug()<<"hspeller"<<wordLang<<"does not exist"; return; } - if (m_hspellers[index]->spell(wordToCheck.toUtf8().constData())==0) + + QString word=m_wfList->at(wfListIndex).w; + if ((*m_hspellerMap)[wordLang]->spell(word.toUtf8().constData())==0) { char **sugglist = NULL; - int suggCount=m_hspellers[index]->suggest(&sugglist, wordToCheck.toUtf8().constData()); + int suggCount=(*m_hspellerMap)[wordLang]->suggest(&sugglist, word.toUtf8().constData()); QStringList replacements; for (int j=0; j < suggCount; ++j) - { - //qDebug()<<"Suggestion "<<j<<":"<<sugglist[j]; replacements << QString::fromUtf8(sugglist[j]); - } - m_hspellers[index]->free_list(&sugglist, suggCount); + (*m_hspellerMap)[wordLang]->free_list(&sugglist, suggCount); updateSuggestions(replacements); } else diff --git a/scribus/plugins/tools/hunspellcheck/hunspelldialog.h b/scribus/plugins/tools/hunspellcheck/hunspelldialog.h index 245df6e..1a29661 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(QMap<QString, QString>* dictionaryMap, Hunspell **hspellers, QList<WordsFound>* wfList); + void set(QMap<QString, QString>* dictionaryMap, QMap<QString, Hunspell*> *hspellerMap, QList<WordsFound>* wfList); bool docChanged() {return m_docChanged;} void updateSuggestions(QStringList& newSuggestions); @@ -32,14 +32,14 @@ class PLUGIN_API HunspellDialog : public QDialog, private Ui::HunspellDialogBase void changeWord(); void changeAllWords(); void replaceWord(int i); - void languageComboChanged(int index); + void languageComboChanged(const QString &); void setLanguageCombo(const QString &newLangAbbrev); private: ScribusDoc* m_doc; - StoryText* m_Itext; + StoryText* m_iText; QMap<QString, QString>* m_dictionaryMap; - Hunspell **m_hspellers; + QMap<QString, Hunspell*> *m_hspellerMap; QList<WordsFound>* m_wfList; WordsFound currWF; int wfListIndex; 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:"<<initOk; if (!initOk) return false; bool spellCheckOk=false; if (m_runningForSE) - { - //qDebug()<<"Running for StoryEditor"; spellCheckOk=checkWithHunspellSE(); - } else - { - //qDebug()<<"Running for ScribusMainWindow"; spellCheckOk=checkWithHunspell(); - } - if (!spellCheckOk) - return false; - return true; + return spellCheckOk; } bool HunspellPluginImpl::findDictionaries() @@ -118,14 +105,11 @@ bool HunspellPluginImpl::initHunspell() return false; //Initialise one hunspeller for each dictionary found - //Maybe we only need the text language related one later on - int i=0; - hspellers = new Hunspell* [numDicts]; QMap<QString, QString>::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()<<word<<"is set to be in language"<<wordLang; - wordLang=LanguageManager::instance()->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; diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h index 08ad225..7963d4a 100644 --- a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h +++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h @@ -44,9 +44,7 @@ class HunspellPluginImpl : public QObject QMap<QString, QString> dictionaryMap; QStringList dictionaryPaths; int numDicts, numAFFs; - Hunspell **hspellers; - //QStringList dictEntries; - //QStringList affEntries; + QMap<QString, Hunspell*> hspellerMap; ScribusDoc* m_doc; bool m_runningForSE; StoryEditor* m_SE; |
