}
QString XdxfPlugin::search(QString key) {
+ if(_settings->value("cached") == "true")
+ return searchCache(key);
+ return searchFile(key);
+}
+
+
+
+QString XdxfPlugin::searchCache(QString key) {
+ qDebug() << "search cache";
+ QString result;
+ QString cacheFilePath = _settings->value("cache_path");
+ db.setDatabaseName(cacheFilePath);
+
+ if(!db.open()) {
+ qDebug() << "Database error" << db.lastError().text() << endl;
+ return searchFile(key);
+ }
+
+ QSqlQuery cur(db);
+ cur.prepare("select translation from dict where word like ? limit 1");
+ cur.addBindValue(key);
+ cur.exec();
+ if(cur.next())
+ result = cur.value(0).toString();
+ return result;
+
+}
+
+
+
+
+QString XdxfPlugin::searchFile(QString key) {
QFile dictionaryFile(path);
QString resultString("");
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
QSqlQuery cur(db);
cur.exec("PRAGMA synchronous = 0");
cur.exec("drop table dict");
- cur.exec("create table dict(word text ,transl text)");
+ cur.exec("create table dict(word text ,translation text)");
int counter = 0;
cur.exec("BEGIN;");
QList<Translation*> searchWordListCache(QString word, int limit=0);
QList<Translation*> searchWordListFile(QString word, int limit=0);
+ QString searchFile(QString key);
+ QString searchCache(QString key);
int countWords();
bool makeCache(QString dir);