From: Bartosz Szatkowski Date: Mon, 16 Aug 2010 10:37:24 +0000 (+0200) Subject: Merged with stashed state X-Git-Tag: 0.4~44^2~17^2~5 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=30ee8320903888c51c3df90f3a1f2848d5b5e8f8;p=mdictionary Merged with stashed state --- diff --git a/trunk/src/base/backbone/Bookmarks.cpp b/trunk/src/base/backbone/Bookmarks.cpp index 09516b7..bb78627 100644 --- a/trunk/src/base/backbone/Bookmarks.cpp +++ b/trunk/src/base/backbone/Bookmarks.cpp @@ -1,4 +1,117 @@ #include "Bookmarks.h" -Bookmarks::Bookmarks() -{ + + +Bookmarks::Bookmarks() { + dbName = QDir::homePath() + "/.mdictionary/" + + "history.db"; + db = QSqlDatabase::addDatabase("QSQLITE", "history"); + db.setDatabaseName(dbName); +} + + + +bool Bookmarks::checkAndCreateDb() { + stopped = false; + + if(!db.open()) { + qDebug() << "Database error: " << db.lastError().text() << endl; + return false; + } + QSqlQuery cur(db); + cur.exec("create table bookmarks(word text ,translation text)"); + + return true; +} + + + +void Bookmarks::clear() { + QSqlQuery cur(db); + cur.exec("drop table bookmarks"); + cur.exec("create table bookmarks(word text ,translation text)"); +} + + + +void Bookmarks::add(Translation* translation) { + QSqlQuery cur(db); + cur.prepare("insert into bookmarks values (?,?)"); + cur.addBindValue(translation->key(), translation->key()); + cur.exec(); +} + + + +void Bookmarks::remove(Translation* translation) { + QSqlQuery cur(db); + cur.prepare("delete from bookmarks where key=? and translation=?"); + cur.addBindValue(translation->key(), translation->key()); + cur.exec(); +} + + + +QList Bookmarks::list() { + QSqlQuery cur(db); + cur.exec("select key from bookmarks"); + QList res; + while(cur.next()) + res.append(new HistoryTranslation(cur.value(0).toString(), this)); + return res; +} + + + +QList Bookmarks::searchWordList(QString word) { + if(word.indexOf("*")==-1 && word.indexOf("?")== 0) + word+="%"; + word = word.replace("*", "%"); + word = word.replace("?", "_"); + word = removeAccents(word); + + QSqlQuery cur(db); + cur.prepare("select key from bookmarks where key=?"); + cur.addBindValue(word); + cur.exec(); + QList res; + while(cur.next()) + res.append(new HistoryTranslation(cur.value(0).toString(), this)); + return res; +} + + + +QList Bookmarks::search(QString word) { + QSqlQuery cur(db); + cur.prepare("select translation from bookmarks where word=? limit 1"); + cur.addBindValue(word); + cur.exec(); + if(cur.next()) + result = cur.value(0).toString(); + return result; +} + + + +void Bookmarks::clear() { + QSqlQuery cur(db); + cur.exec("drop table bookmarks"); + cur.exec("create table bookmarks(word text ,translation text)"); +} + + +QString Bookmarks::removeAccents(QString string) { + string = string.replace(QString::fromUtf8("ł"), "l", Qt::CaseInsensitive); + QString normalized = string.normalized(QString::NormalizationForm_D); + normalized = normalized; + for(int i=0; i +#include +#include +#include +#include +#include +#include +#include #include "../../includes/settings.h" #include "../../includes/translation.h" +#include "HistoryTranslation.h" /*! Bookmarks are way to store words that You think You will need to search for often. @@ -62,7 +71,7 @@ public: /*! search in bookmarks for given word (wildcards may apply '*' and '?') \param word to search for - \return list of matching translation object (word and translation) + \return list of matching Translation objects */ QList searchWordList(QString word); @@ -73,6 +82,17 @@ public: */ QStringList search(QString word); + + /*! clars bookmarks database */ + void clear(); + +private: + QString dbName; + QSqlDatabase db; + + bool checkAndCreateDb(); + QString removeAccents(); + }; #endif // BOOKMARKS_H diff --git a/trunk/src/plugins/xdxf/src/xdxfplugin.cpp b/trunk/src/plugins/xdxf/src/xdxfplugin.cpp index 5c75498..8497d1d 100644 --- a/trunk/src/plugins/xdxf/src/xdxfplugin.cpp +++ b/trunk/src/plugins/xdxf/src/xdxfplugin.cpp @@ -338,7 +338,6 @@ void XdxfPlugin::getDictionaryInfo() { } QString XdxfPlugin::removeAccents(QString string) { - string = string.replace(QString::fromUtf8("ł"), "l", Qt::CaseInsensitive); QString normalized = string.normalized(QString::NormalizationForm_D); normalized = normalized;