From 075702e1b757ae96327b0d075b5e0227513c73de Mon Sep 17 00:00:00 2001 From: Bartosz Szatkowski Date: Fri, 13 Aug 2010 10:22:24 +0200 Subject: [PATCH] Added searching for word list in cache --- trunk/src/plugins/xdxf/src/xdxfplugin.cpp | 30 ++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/trunk/src/plugins/xdxf/src/xdxfplugin.cpp b/trunk/src/plugins/xdxf/src/xdxfplugin.cpp index 2cc11cb..4cfe266 100644 --- a/trunk/src/plugins/xdxf/src/xdxfplugin.cpp +++ b/trunk/src/plugins/xdxf/src/xdxfplugin.cpp @@ -74,12 +74,37 @@ QList XdxfPlugin::searchWordList(QString word, int limit) { QList XdxfPlugin::searchWordListCache(QString word, int limit) { + qDebug() << "search cache"; + QSet translations; + QString cacheFilePath = _settings->value("cache_path"); + QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); + db.setDatabaseName(cacheFilePath); + if(!db.open()) { + qDebug() << "Database error" << endl; + return searchWordListFile(word, limit); + } + stopped = false; + word = removeAccents(word); + if(word.indexOf("*")==-1) + word+="%"; + word = word.replace("*", "%"); + + QSqlQuery cur; + cur.prepare("select word from dict where word like ? limit ?"); + cur.addBindValue(word); + cur.addBindValue(limit); + cur.exec(); + while(cur.next()) + translations.insert(new TranslationXdxf(cur.value(0).toString(), + _infoNote, this)); + return translations.toList(); } QList XdxfPlugin::searchWordListFile(QString word, int limit) { + qDebug() << "search file"; QSet translations; QFile dictionaryFile(path); @@ -196,7 +221,8 @@ CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const { QStringList list = settings->keys(); foreach(QString key, list) plugin->settings()->setValue(key, settings->value(key)); - plugin->makeCache(""); + if(plugin->settings()->value("cached") != "true") + plugin->makeCache(""); } return plugin; } @@ -385,6 +411,8 @@ bool XdxfPlugin::makeCache(QString dir) { qDebug() << "ŻLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"; return false; } + _settings->setValue("cache_path", cachePathN); + _settings->setValue("cached", "true"); return true; } -- 1.7.9.5