Added searching for final translation in cache
authorBartosz Szatkowski <bulislaw@linux.com>
Fri, 13 Aug 2010 09:25:00 +0000 (11:25 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Fri, 13 Aug 2010 09:25:00 +0000 (11:25 +0200)
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/src/plugins/xdxf/src/xdxfplugin.h

index f532019..24e3ad1 100644 (file)
@@ -157,6 +157,38 @@ QList<Translation*> XdxfPlugin::searchWordListFile(QString word, int limit) {
 }
 
 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)) {
@@ -362,7 +394,7 @@ bool XdxfPlugin::makeCache(QString dir) {
     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;");
 
index 1d609b1..0757b6a 100644 (file)
@@ -121,6 +121,8 @@ private:
 
     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);