r17490 by craig - Bump hunspell some more, add it some real finding/use of dicts from common locations

scribus-commit scribus-commit at lists.scribus.net
Thu May 3 07:40:30 UTC 2012


Author: craig
Date: Thu May  3 07:40:30 2012
New Revision: 17490

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17490
Log:
Bump hunspell some more, add it some real finding/use of dicts from common locations

Modified:
    branches/Version14x/Scribus/scribus/langmgr.cpp
    branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp
    branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h
    branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
    branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h

Modified: branches/Version14x/Scribus/scribus/langmgr.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17490&path=/branches/Version14x/Scribus/scribus/langmgr.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/langmgr.cpp (original)
+++ branches/Version14x/Scribus/scribus/langmgr.cpp Thu May  3 07:40:30 2012
@@ -127,6 +127,7 @@
 	langList.insert("tr",       langPair("Turkish",             QObject::tr( "Turkish" )) );
 	langList.insert("tr_TR",    langPair("Turkish",             QObject::tr( "Turkish" )) );
 	langList.insert("uk",       langPair("Ukranian",            QObject::tr( "Ukranian" )) );
+	langList.insert("uk_UA",    langPair("Ukranian",            QObject::tr( "Ukranian" )) );
 	langList.insert("vi",       langPair("Vietnamese",          QObject::tr( "Vietnamese" )) );
 	langList.insert("cy",       langPair("Welsh",               QObject::tr( "Welsh" )) );
 }

Modified: branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17490&path=/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp (original)
+++ branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp Thu May  3 07:40:30 2012
@@ -30,15 +30,19 @@
 	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);

Modified: branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17490&path=/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h (original)
+++ branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h Thu May  3 07:40:30 2012
@@ -22,7 +22,7 @@
 	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 @@
 	private:
 		ScribusDoc* m_doc;
 		StoryText* m_Itext;
-		QStringList* m_dictEntries;
+		QMap<QString, QString>* m_dictionaryMap;
 		Hunspell **m_hspellers;
 		QList<WordsFound>* m_wfList;
 		WordsFound currWF;

Modified: branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17490&path=/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp (original)
+++ branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp Thu May  3 07:40:30 2012
@@ -6,6 +6,7 @@
 */
 #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::findDictionaries()
 {
-	QStringList dirs(ScPaths::instance().spellDirs());
-	if (dirs.count()==0)
-		return false;
-	//for development, just take the first for now
-	dictPath=dirs.first();
+	dictionaryPaths=ScPaths::instance().spellDirs();
+	if (dictionaryPaths.count()==0)
+		return false;
 	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())
-	{
-		dictName=dictListIterator.next();
-		if (!QFile::exists(dictPath+dictName+".aff"))
-			dictList.removeAll(dictName);
-	}
-	numAFFs=numDicts=dictList.count();
-	qDebug()<<"Number of dictionaries/AFFs found:"<<numDicts<<numAFFs;
-	if (numDicts==0)
-		++errorCount;
-	qDebug()<<dictList;
+	for (int i=0; i<dictionaryPaths.count(); ++i)
+	{
+		// 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();
+	}
+	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 @@
 				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::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 @@
 {
 	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;

Modified: branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17490&path=/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h (original)
+++ branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.h Thu May  3 07:40:30 2012
@@ -11,6 +11,7 @@
 #include "hunspellpluginstructs.h"
 
 #include <QObject>
+#include <QMap>
 #include <QString>
 #include <QStringList>
 
@@ -40,12 +41,12 @@
 		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;




More information about the scribus-commit mailing list