*******************************************************************************/
/*! \file xdxfplugin.cpp
+\author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
*/
#include "xdxfplugin.h"
-XdxfPlugin::~XdxfPlugin()
-{
-// QString connection(db.connectionName());
-// db.close();
-// QSqlDatabase::removeDatabase(connection);
-
+XdxfPlugin::~XdxfPlugin() {
delete _settings;
}
-void XdxfPlugin::initAccents() {
- letters['a'] = QRegExp("[ÀàÁáÂÂâÃãÄäÅåæÆĀāĂ㥹]", Qt::CaseInsensitive);
- letters['c'] = QRegExp("[ÇçÈçŒĆćĈĉĊċČč]", Qt::CaseInsensitive);
- letters['d'] = QRegExp("[ÐĐđĎď]", Qt::CaseInsensitive);
- letters['e'] = QRegExp("[ÈéèÉÊêËëĒēĔĕĖėĘęĚěē]", Qt::CaseInsensitive);
- letters['f'] = QRegExp("[ſ]", Qt::CaseInsensitive);
- letters['g'] = QRegExp("[ĠġĢģĜĝĞğ]", Qt::CaseInsensitive);
- letters['h'] = QRegExp("[ħĤĥĦ]", Qt::CaseInsensitive);
- letters['i'] = QRegExp("[ÌìÍíÎîÏïİijĨĩĪīĬĭĮį]", Qt::CaseInsensitive);
- letters['j'] = QRegExp("[Ĵĵ]", Qt::CaseInsensitive);
- letters['k'] = QRegExp("[Ķķĸ]", Qt::CaseInsensitive);
- letters['l'] = QRegExp("[ŀŁłĹĺĻļĽľĿ]", Qt::CaseInsensitive);
- letters['n'] = QRegExp("[ÑñŃńŅņŇňʼnŊŋ]", Qt::CaseInsensitive);
- letters['o'] = QRegExp("[ÒòÓóÔÕõÖöØøŐőœŌōŎŏ]", Qt::CaseInsensitive);
- letters['r'] = QRegExp("[ŕŖŖŗŘř]", Qt::CaseInsensitive);
- letters['s'] = QRegExp("[ߊšŚśŜŝŞş]", Qt::CaseInsensitive);
- letters['t'] = QRegExp("[ŢţŤťŦŧ]", Qt::CaseInsensitive);
- letters['u'] = QRegExp("[ÙùÚúÛûÜüŰűŲųŨũŪūŬŮů]", Qt::CaseInsensitive);
- letters['w'] = QRegExp("[Ŵŵ]", Qt::CaseInsensitive);
- letters['y'] = QRegExp("[ÿÝýŶŷŸ]", Qt::CaseInsensitive);
- letters['z'] = QRegExp("[ŹźŻżŽž]", Qt::CaseInsensitive);
- noLetter = QRegExp("[^a-z ]", Qt::CaseInsensitive);
-}
QString XdxfPlugin::langFrom() const {
return _langFrom;
}
QString XdxfPlugin::type() const {
-// return _settings->value("type");
return _type;
}
QSqlQuery cur(db);
if(limit !=0)
- cur.prepare("select word from dict where word like ? limit ?");
+ cur.prepare("select word from dict where word like ? or normalized like ? limit ?");
else
- cur.prepare("select word from dict where word like ?");
+ cur.prepare("select word from dict where word like ? or normalized like ?");
+ cur.addBindValue(word);
cur.addBindValue(word);
if(limit !=0)
cur.addBindValue(limit);
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();
}
CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
XdxfPlugin *plugin = new XdxfPlugin();
- static int a=0;
if(settings){
plugin->setPath(settings->value("path"));
QStringList list = settings->keys();
- foreach(QString key, list)
- plugin->settings()->setValue(key, settings->value(key));
- a=a+1;
plugin->db_name = plugin->_settings->value("type")
+ plugin->_settings->value("path");
plugin->db = QSqlDatabase::addDatabase("QSQLITE", plugin->db_name);
settings->value("generateCache") == "true") {
plugin->makeCache("");
}
+ foreach(QString key, list)
+ if(key != "generateCache")
+ plugin->settings()->setValue(key, settings->value(key));
delete settings;
}
plugin->getDictionaryInfo();
return true;
}
+
+
void XdxfPlugin::setHash(uint _hash) {
this->_hash=_hash;
}
+
+
uint XdxfPlugin::hash() const {
return _hash;
}
+
+
Settings* XdxfPlugin::settings() {
return _settings;
}
+
+
bool XdxfPlugin::isCached() {
if(_settings->value("cached") == "true")
return true;
return false;
}
+
+
void XdxfPlugin::setSettings(Settings *settings) {
QString oldPath = _settings->value("path");
setPath(settings->value("path"));
}
+ foreach(QString key, settings->keys())
+ if(key != "generateCache")
+ _settings->setValue(key, settings->value(key));
+
if((_settings->value("cached") == "false" ||
- _settings->value("cached").isEmpty()) &&
- settings->value("generateCache") == "true") {
+ _settings->value("cached").isEmpty()) &&
+ settings->value("generateCache") == "true") {
makeCache("");
}
- else {
+ else if (settings->value("generateCache") != "true") {
_settings->setValue("cached", "false");
}
+
+
delete settings;
- emit settingsChanged();
+ Q_EMIT settingsChanged();
}
+
+
void XdxfPlugin::getDictionaryInfo() {
QFile dictionaryFile(path);
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
QString format = "png";
QString initialPath = QDir::currentPath() + tr("/xdxf.") + format;
- _infoNote="path=\""+initialPath+"\">"+"\n" + _name + " [" + _langFrom +
- "-" + _langTo + "] "+ "(" + _type + ")";
-
+ _infoNote="path=\""+initialPath+"\"> \n" + _name + " [" + _langFrom + "-" + _langTo + "] (" + _type + ")";
dictionaryFile.close();
}
-QString XdxfPlugin::removeAccents(QString string) {
- string = string.toLower();
- QString normalized = string.normalized(QString::NormalizationForm_KD);
- foreach(QChar let, letters.keys())
- normalized.replace(letters[let], QString(let));
-
- normalized.replace(noLetter, "");
- //qDebug() << "NORMALIZED: " << normalized;
- return normalized;
- return string;
-}
-
-
-
QIcon* XdxfPlugin::icon() {
return &_icon;
}
}
QXmlStreamReader reader(&dictionaryFile);
+
db.setDatabaseName(cachePathN);
if(!db.open()) {
qDebug() << "Database error" << db.lastError().text() << endl;
int lastProg = -1;
+ QString stripAcc = settings()->value("strip_accents");
+ settings()->setValue("strip_accents", "true");
+
counter=0;
while (!reader.atEnd() && !stopped) {
counter++;
int prog = counter*100/_wordsCount;
if(prog % 5 == 0 && lastProg != prog) {
- qDebug() << prog;
Q_EMIT updateCachingProgress(prog,
timer.restart());
lastProg = prog;
cur.exec("END;");
cur.exec("select count(*) from dict");
+ settings()->setValue("strip_accents", stripAcc);
countWords();
cachingDialog->setVisible(false);