/branches/Version14x/Scribus/scribus/scpaths.cpp |
---|
266,7 → 266,6 |
QStringList spellDirs; |
spellDirs.append(m_shareDir + "dicts/spelling/"); |
#ifdef Q_OS_MAC |
//spellDirs.append(QDir::homePath() + "/Library/Fonts/"); |
d.setPath(macPortsPath); |
if (d.exists()) |
spellDirs.append(macPortsPath); |
274,11 → 273,9 |
if (d.exists()) |
spellDirs.append(finkPath); |
d.setPath(osxLibreOfficePath); |
if (d.exists()) |
{ |
QStringList dictDirFilters; |
dictDirFilters << "dict-*"; |
QStringList dictDirFilters("dict-*"); |
QStringList dictDirList(d.entryList(dictDirFilters, QDir::Dirs, QDir::Name)); |
QString dir; |
foreach (dir, dictDirList) |
287,8 → 284,7 |
d.setPath(osxUserLibreOfficePath); |
if (d.exists()) |
{ |
QStringList dictDirFilters; |
dictDirFilters << "dict-*"; |
QStringList dictDirFilters("dict-*"); |
QStringList dictDirList(d.entryList(dictDirFilters, QDir::Dirs, QDir::Name)); |
QString dir; |
foreach (dir, dictDirList) |
300,8 → 296,7 |
d.setPath(progFiles+windowsLOPath); |
if (d.exists()) |
{ |
QStringList dictDirFilters; |
dictDirFilters << "dict-*"; |
QStringList dictDirFilters("dict-*"); |
QStringList dictDirList(d.entryList(dictDirFilters, QDir::Dirs, QDir::Name)); |
QString dir; |
foreach (dir, dictDirList) |
/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h |
---|
22,7 → 22,7 |
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 |
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; |
/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h |
---|
44,9 → 44,7 |
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; |
/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp |
---|
21,19 → 21,19 |
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 |
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::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 |
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 |
/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp |
---|
31,7 → 31,7 |
// 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() |
{ |
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 |
{ |
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 |
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 |
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 |
} |
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 |
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::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 |
{ |
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; |