bool SpellerUtility::loadDictionary(QString dic,QString ignoreFilePrefix) {
	if (dic==currentDic) return true;
	else unload();
	QString base = dic.left(dic.length()-4);
	QString dicFile = base+".dic";
	QString affFile = base+".aff";
	if (!QFileInfo(dicFile).exists() || !QFileInfo(affFile).exists()) {
		emit reloadDictionary(); //remove spelling error marks from errors with previous dictionary (because these marks could lead to crashes if not removed)
		return false;
	}
	currentDic=dic;
	pChecker = new Hunspell(affFile.toLocal8Bit(),dicFile.toLocal8Bit());
	if (!pChecker) {
		currentDic="";
		ignoreListFileName="";
	}
	spell_encoding=QString(pChecker->get_dic_encoding());
	spellCodec = QTextCodec::codecForName(spell_encoding.toLatin1());
	if (spellCodec==0) {
		unload();
		emit reloadDictionary();
		return false;
	}

	checkCache.clear();
	ignoredWords.clear();
	ignoredWordList.clear();
	ignoredWordsModel.setStringList(QStringList());
	ignoreListFileName=base+".ign";
	if (!isFileRealWritable(ignoreListFileName))
		ignoreListFileName=ignoreFilePrefix+QFileInfo(dic).baseName()+".ign";
	if (!isFileRealWritable(ignoreListFileName)) {
		ignoreListFileName="";
		emit reloadDictionary();
		return true;
	}
	QFile f(ignoreListFileName);
	if (!f.open(QFile::ReadOnly)) {
		emit reloadDictionary();
		return true;
	}
	ignoredWordList=QTextCodec::codecForName("UTF-8")->toUnicode(f.readAll()).split("\n",QString::SkipEmptyParts);
	// add words in user dic
	QByteArray encodedString;
	QString spell_encoding=QString(pChecker->get_dic_encoding());
	QTextCodec *codec = QTextCodec::codecForName(spell_encoding.toLatin1());
	foreach(const QString elem,ignoredWordList){
		encodedString = codec->fromUnicode(elem);
		pChecker->add(encodedString.data());
	}
Exemple #2
0
DictionaryManager::DictionaryManager(QObject *parent) :
    QObject(parent)
{
    timerDictionaryChanged.setSingleShot(true);
    connect(&timerDictionaryChanged, SIGNAL(timeout()), this, SLOT(reloadDictionary()));
    connect(&watcher, SIGNAL(fileChanged(QString)), this, SLOT(dictionaryChanged(QString)));
}
Exemple #3
0
void SpellCheck::clearIgnoredWords()
{
    m_ignoredWords.clear();
    reloadDictionary();
}