if(loadDialog.exec()==QDialog::Accepted) {
settings->setValue("path", loadDialog.dicitonaryFilePath());
if(loadDialog.generateCache()) {
- settings->setValue("cache", "true");
+ settings->setValue("cached", "true");
}
else {
- settings->setValue("cache", "false");
+ settings->setValue("cached", "false");
}
return settings;
qDebug() << "search cache";
QSet<Translation*> translations;
QString cacheFilePath = _settings->value("cache_path");
- QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(cacheFilePath);
if(!db.open()) {
- qDebug() << "Database error" << endl;
+ qDebug() << "Database error" << db.lastError().text() << endl;
return searchWordListFile(word, limit);
}
word+="%";
word = word.replace("*", "%");
- QSqlQuery cur;
+ QSqlQuery cur(db);
cur.prepare("select word from dict where word like ? limit ?");
cur.addBindValue(word);
cur.addBindValue(limit);
QStringList list = settings->keys();
foreach(QString key, list)
plugin->settings()->setValue(key, settings->value(key));
- if(plugin->settings()->value("cached") != "true")
- plugin->makeCache("");
+ //if(plugin->settings()->value("cached") != "true")
+ plugin->db_name = plugin->_settings->value("type")
+ + plugin->_settings->value("path");
+ plugin->db = QSqlDatabase::addDatabase("QSQLITE", plugin->db_name);
+ plugin->makeCache("");
}
return plugin;
}
bool XdxfPlugin::makeCache(QString dir) {
QFileInfo dictFileN(_settings->value("path"));
QString cachePathN;
- cachePathN = dictFileN.dir().absolutePath() + "/"
+ cachePathN = QDir::homePath() + "/.mdictionary/"
+ dictFileN.completeBaseName() + ".cache";
QFile dictionaryFile(dictFileN.filePath());
QXmlStreamReader reader(&dictionaryFile);
- QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(cachePathN);
if(!db.open()) {
qDebug() << "Database error" << endl;
return false;
}
- QSqlQuery cur;
+ QSqlQuery cur(db);
cur.exec("PRAGMA synchronous = 0");
cur.exec("drop table dict");
cur.exec("create table dict(word text ,transl text)");
qDebug()<<counter;
cur.exec("END;");
cur.exec("select count(*) from dict");
- if(!cur.next() || countWords() != cur.value(0).toInt()) {
- qDebug() << countWords() << " " << cur.value(0).toInt();
- qDebug() << "ŻLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE";
+ if(!cur.next() || countWords() != cur.value(0).toInt())
return false;
- }
_settings->setValue("cache_path", cachePathN);
_settings->setValue("cached", "true");
return true;