/* For general Scribus (>=1.3.2) copyright and licensing information please refer to the COPYING file provided with the program. Following this notice may exist a copyright and/or license notice that predates the release of Scribus 1.3.2 for which a new license (GPL+exception) is in place. */ #include "hunspellpluginimpl.h" #include "hunspelldialog.h" #include "pageitem.h" #include "pageitem_textframe.h" #include "selection.h" #include "scpaths.h" #include "scribusdoc.h" #include "scribus.h" #include "text/specialchars.h" #include "util.h" #include #include #include #include #ifdef Q_OS_WIN32 #include #include #endif // Initialize members here, if any HunspellPluginImpl::HunspellPluginImpl() : QObject(0) { hspellers=NULL; numDicts=0; } HunspellPluginImpl::~HunspellPluginImpl() { if (hspellers) { for (int i = 0; i < numDicts; ++i) { delete hspellers[i]; hspellers[i] = NULL; } delete[] hspellers; } hspellers = NULL; numDicts = 0; } bool HunspellPluginImpl::run(const QString & target, ScribusDoc* doc) { m_doc=doc; bool initOk=initHunspell(); qDebug()<<"Hunspell Init Ok:"<m_Selection->count(); ++i ) { frameToCheck = m_doc->m_Selection->itemAt(i); parseTextFrame(frameToCheck); openGUIForTextFrame(frameToCheck); m_doc->view()->DrawNew(); } return true; } bool HunspellPluginImpl::parseTextFrame(PageItem *frameToCheck) { StoryText *iText=&frameToCheck->itemText; int len=iText->length(); QString text=iText->text(0,len); // qDebug()<nextWord(currPos); currPos=wordPos; int eoWord=wordPos; while(eoWord < len) { if (iText->text(eoWord).isLetterOrNumber()) ++eoWord; else break; } QString word=iText->text(wordPos,eoWord-wordPos); ++wordCount; ++wordNo; QStringList replacements; if (hspellers[0]->spell(word.toUtf8().constData())==0) { // qDebug()<suggest(&sugglist, word.toUtf8().constData()); for (int j=0; j < suggCount; ++j) { // qDebug()<<"Suggestion "<free_list(&sugglist, suggCount); struct WordsFound wf; wf.start=currPos; wf.end=eoWord; wf.w=word; wf.replacements=replacements; wf.changed=false; wf.ignore=false; wf.changeOffset=0; wordsToCorrect.append(wf); } } // qDebug()<<"Errors found:"<scMW(), m_doc, frameToCheck); hsDialog.set(&dictEntries, hspellers, &wordsToCorrect); hsDialog.exec(); if (hsDialog.docChanged()) m_doc->changed(); return true; }