_type(tr("xdxf")), _infoNote(tr("")) {
_wordsCount = -1;
_settings = new Settings();
- _dictDialog = new XdxfDictDialog(this, this);
- cachingDialog = new XdxfCachingDialog(this);
+ _dictDialog = new XdxfDictDialog(this);
+ cachingDialog = new XdxfCachingDialog();
connect(cachingDialog, SIGNAL(cancelCaching()),
this, SLOT(stop()));
+ connect(this, SIGNAL(updateCachingProgress(int,int)),
+ cachingDialog, SLOT(updateCachingProgress(int,int)));
+
_settings->setValue("type","xdxf");
stopped = false;
word = word.toLower();
word = word.replace("*", "%");
word = word.replace("?", "_");
- word = removeAccents(word);
QSqlQuery cur(db);
if(limit !=0)
if(limit !=0)
cur.addBindValue(limit);
cur.exec();
+ bool in = false;
while(cur.next()){
+ in = true;
bool ok=true;
Translation *tran;
foreach(tran,translations) {
cur.value(0).toString().toLower(),
_infoNote, this));
}
+ if(!in) {
+
+ QSqlQuery cur(db);
+ if(limit !=0)
+ cur.prepare("select word from dict where normalized like ? limit ?");
+ else
+ cur.prepare("select word from dict where normalized like ?");
+ cur.addBindValue(word);
+ if(limit !=0)
+ cur.addBindValue(limit);
+ cur.exec();
+ while(cur.next()){
+ bool ok=true;
+ Translation *tran;
+ foreach(tran,translations) {
+ if(tran->key().toLower()==cur.value(0).toString().toLower())
+ ok=false;
+ }
+ if(ok) /*add key word to list*/
+ translations.insert(new TranslationXdxf(
+ cur.value(0).toString().toLower(),
+ _infoNote, this));
+ }
+ }
db.close();
return translations.toList();
}
QList<Translation*> XdxfPlugin::searchWordListFile(QString word, int limit) {
+ QTime time;
+ time.start();
QSet<Translation*> translations;
QFile dictionaryFile(path);
word = word.toLower();
- word = removeAccents(word);
+ //word = removeAccents(word);
stopped = false;
QRegExp regWord(word);
QXmlStreamReader reader(&dictionaryFile);
/*search words list*/
QString a;
+ QRegExp regexp(removeAccents(a), Qt::CaseInsensitive, QRegExp::Wildcard);
+ regexp.setMinimal(true);
+
int i=0;
while(!reader.atEnd() && !stopped){
reader.readNextStartElement();
reader.readNextStartElement();
if(!reader.atEnd())
a = reader.readElementText();
- if(regWord.exactMatch(removeAccents(a)) && (i<limit || limit==0)) {
+ regexp.setPattern(a);
+ if((regWord.exactMatch(a) || regexp.exactMatch(
+ word.left(word.size()-1))) &&
+ (i<limit || limit==0)) {
bool ok=true;
Translation *tran;
foreach(tran,translations) {
}
stopped=false;
dictionaryFile.close();
+ qDebug() << time.elapsed();
return translations.toList();
}
dictionaryFile.close();
}
-QString XdxfPlugin::removeAccents(QString string) {
- string = string.replace(QString::fromUtf8("ł"), "l", Qt::CaseInsensitive);
- QString normalized = string.normalized(QString::NormalizationForm_D);
- normalized = normalized;
+QString XdxfPlugin::removeAccents(QString string, QChar wildcard) {
+ QString normalized = string.toLower();
for(int i=0; i<normalized.size(); i++) {
- if( !normalized[i].isLetterOrNumber() &&
- !normalized[i].isSpace() &&
- !normalized[i].isDigit() &&
- normalized[i] != '*' &&
- normalized[i] != '%' &&
- normalized[i] != '_' &&
- normalized[i] != '?' ) {
- normalized.remove(i,1);
- }
+ if(normalized[i].isLetterOrNumber() && ((normalized.at(1) < QChar('a'))
+ || (normalized.at(i) > QChar('z'))))
+ normalized[i] = wildcard;
}
return normalized;
}
.arg(name()));
return 0;
}
-
QXmlStreamReader reader(&dictionaryFile);
db.setDatabaseName(cachePathN);
cur.exec("PRAGMA synchronous = 0");
cur.exec("drop table dict");
QCoreApplication::processEvents();
- cur.exec("create table dict(word text ,translation text)");
+ cur.exec("create table dict(word text, normalized text ,translation text)");
int counter = 0;
cur.exec("BEGIN;");
temp.remove(0,1);
temp=tr("<key>") + a + tr("</key>") + tr("<t>") + temp+ tr("</t>");
match=false;
- cur.prepare("insert into dict values(?,?)");
+ cur.prepare("insert into dict values(?,?,?)");
cur.addBindValue(a);
+ cur.addBindValue(removeAccents(a,'_'));
cur.addBindValue(temp);
cur.exec();
counter++;
int prog = counter*100/_wordsCount;
if(prog % 5 == 0 && lastProg != prog) {
+ qDebug() << prog;
Q_EMIT updateCachingProgress(prog,
timer.restart());
lastProg = prog;